A
A
Alexander Sokolov2015-10-08 11:28:16
PHP
Alexander Sokolov, 2015-10-08 11:28:16

How to add PHP code?

There is a site go2s.ru on it videos speared from YouTube. I want the video to open on a new page when you click on the link, and not like now.
The following function is responsible for parsing:

function get_youtube_video($key) {
 		$DEVELOPER_KEY = 'AIzaSyAgk6lKh5IKBDdH_fgBlVcT2hEsmAY5jQ8';

  	$client = new Google_Client();
  	$client->setDeveloperKey($DEVELOPER_KEY);

  	// Define an object that will be used to make all API requests.
  	$youtube = new Google_Service_YouTube($client);

    // Call the search.list method to retrieve results matching the specified
    // query term.
    $searchResponse = $youtube->search->listSearch('id,snippet', array(
      'q' => $key,
      'maxResults' => 50,
    ));

    $videos = '';
    $channels = '';
    $playlists = '';
  
    /*
    echo '<pre>';
    var_dump($searchResponse['items']);
    echo '</pre>';
    */
    
    
    echo '<div>';
    foreach($searchResponse['items'] as $searchResult) {
    		switch ($searchResult['id']['kind']) {
        		case 'youtube#video':
          		$videoId=$searchResult['id']['videoId'];
          		$title=$searchResult['snippet']['title'];
          		$desc=$searchResult['snippet']['description'];
          		
          		$img = 'https://i.ytimg.com/vi/'.$videoId.'/mqdefault.jpg';  //    [0, 1, 2, 3, default, mqdefault, hqdefault, maxresdefault] http://shpargalkablog.ru/2013/06/youtube.html
          		$a1='<a href="http://www.youtube.com/embed/'.$videoId.'?autoplay=1&autohide=1&border=0&egm=0&showinfo=0" class="lightview" data-lightview-type="iframe" data-lightview-options="width: 638,height: 360">';
          		$a2='</a>';
              echo '<div class="video">';
          		echo $a1.'<img style="float: left; margin: 15px;" src="'.$img.'" title="'.$title.'" alt="'.$title.'">'.$a2;
          		echo $a1.$title.$a2.'<br>';
          		echo $desc.'<br>';
          		echo '</div>';
          		echo '<div style="clear: both"></div>';
    		}
    }
    echo '</div>';	
}

Tell. what needs to be added/rewritten?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Kovalsky, 2015-10-08
@dmitryKovalskiy

If you mean a new tab, then you are coming from the wrong side, this is client logic, not server logic. For example, you can add target="_blank" to the link.

R
Rikcon, 2015-10-08
@Rikcon

$a1='<a href="http://www.youtube.com/embed/'.$videoId.'?autoplay=1&autohide=1&border=0&egm=0&showinfo=0" class="lightview" data-lightview-type="iframe" data-lightview-options="width: 638,height: 360" target="_blank">';

D
Dmitry Entelis, 2015-10-08
@DmitriyEntelis

<a href="http://www.youtube.com/embed/
replace

<a target="_blank" href="http://www.youtube.com/embed/

I
Ivanq, 2015-10-08
@Ivanq

If you want to
then you need to create a new page so that the video url is sent to it, insert a link to your page into the link, and embed it in the iframe on the new page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question