Ejemplo n.º 1
0
/**
 * @param $mod_reference
 * @param $module_params
 */
function module_youtube($mod_reference, $module_params)
{
    $smarty = TikiLib::lib('smarty');
    $data = array('urls' => array(), 'xhtml' => array());
    if (!empty($module_params['ids'])) {
        require_once 'lib/wiki-plugins/wikiplugin_youtube.php';
        $ids = explode(',', $module_params['ids']);
        $data['urls']['gdata'] = array();
        foreach ($ids as $id) {
            $data['urls']['gdata'][$id] = ZendGData\YouTube::VIDEO_URI . '/' . $id;
            $params = array('movie' => $id);
            if (isset($module_params['width'])) {
                $params['width'] = $module_params['width'];
            }
            if (isset($module_params['height'])) {
                $params['height'] = $module_params['height'];
            }
            $data['xhtml'][$id] = preg_replace('/~np~(.*)~\\/np~/', '$1', wikiplugin_youtube('', $params));
        }
    }
    if (!empty($module_params['user'])) {
        $data['urls']['user_home'] = 'http://www.youtube.com/user/' . $module_params['user'];
    }
    $smarty->assign_by_ref('data', $data);
    $smarty->assign('tpl_module_title', tra('Videos on YouTube'));
}
/**
 * @param $mod_reference
 * @param $module_params
 */
function module_last_youtube_playlist_videos($mod_reference, $module_params)
{
    global $smarty, $prefs;
    $tikilib = TikiLib::lib('tiki');
    $data = array();
    if (!empty($module_params['id'])) {
        $id = $module_params['id'];
        require_once 'lib/wiki-plugins/wikiplugin_youtube.php';
        if (!empty($module_params['orderby'])) {
            $orderby = $module_params['orderby'];
            $feedUrl = 'http://gdata.youtube.com/feeds/api/playlists/' . $id . '?orderby=' . $orderby;
        } else {
            $feedUrl = 'http://gdata.youtube.com/feeds/api/playlists/' . $id . '?orderby=position';
        }
        $yt = new Zend_Gdata_YouTube();
        $yt->setMajorProtocolVersion(2);
        $yt->setHttpClient($tikilib->get_http_client());
        try {
            $playlistVideoFeed = $yt->getPlaylistVideoFeed($feedUrl);
            $data[$id]['info']['title'] = $playlistVideoFeed->title->text;
            // Prepare params for video display
            $params = array();
            $params['width'] = isset($module_params['width']) ? $module_params['width'] : 425;
            $params['height'] = isset($module_params['height']) ? $module_params['height'] : 350;
            // Get information from all videos from playlist
            // Limit to $module_rows first videos if $module_rows is set
            $count_videos = 1;
            foreach ($playlistVideoFeed as $videoEntry) {
                $videoId = $videoEntry->getVideoId();
                $data[$id]['videos'][$videoId]['title'] = $videoEntry->getVideoTitle();
                $data[$id]['videos'][$videoId]['uploaded'] = $videoEntry->mediaGroup->uploaded->text;
                $data[$id]['videos'][$videoId]['description'] = $videoEntry->getVideoDescription();
                $params['movie'] = $videoId;
                $pluginstr = wikiplugin_youtube('', $params);
                $len = strlen($pluginstr);
                //need to take off the ~np~ and ~/np~ at the beginning and end of the string returned by wikiplugin_youtube
                $data[$id]['videos'][$videoId]['xhtml'] = substr($pluginstr, 4, $len - 4 - 5);
                if (isset($module_rows) && $module_rows > 0 && $count_videos >= $module_rows) {
                    break;
                }
                $count_videos++;
            }
        } catch (Exception $e) {
            $data[$id]['info']['title'] = tra('No Playlist found');
            $data[$id]['videos'][0]['title'] = $e->getMessage();
        }
    } else {
        $id = 0;
        $data[$id]['info']['title'] = tra('No Playlist found');
        $data[$id]['videos'][0]['title'] = tra('No Playlist ID was provided');
    }
    $smarty->assign('verbose', isset($module_params['verbose']) ? $module_params['verbose'] : 'y');
    $smarty->assign('link_url', isset($module_params['link_url']) ? $module_params['link_url'] : '');
    $smarty->assign('link_text', isset($module_params['link_text']) ? $module_params['link_text'] : 'More Videos');
    $smarty->assign_by_ref('data', $data[$id]);
}
Ejemplo n.º 3
0
 /**
  * @dataProvider provider
  */
 public function testWikiPluginCode($data, $expectedOutput, $params = array())
 {
     $this->markTestSkipped("As of 2013-09-30, this tesst is broken. Skipping it for now.");
     $this->assertEquals($expectedOutput, wikiplugin_youtube($data, $params));
 }
/**
 * @param $mod_reference
 * @param $module_params
 */
function module_last_youtube_playlist_videos($mod_reference, $module_params)
{
    global $prefs;
    $tikilib = TikiLib::lib('tiki');
    $data = array();
    $smarty = TikiLib::lib('smarty');
    if (!empty($module_params['id'])) {
        $id = $module_params['id'];
        require_once 'lib/wiki-plugins/wikiplugin_youtube.php';
        $client = new Google_Client();
        $client->setScopes('https://www.googleapis.com/auth/youtube');
        // TODO: Add "dev_key" to documentation, without key API uses public API call limit
        // and it is usually exceeded
        if (!empty($module_params['dev_key'])) {
            $client->setDeveloperKey($module_params['dev_key']);
        }
        // Define an object that will be used to make all API requests.
        $youtube = new Google_Service_YouTube($client);
        /*
         * TODO: orderby is not supported by V3 API, probably sort locally
        if (!empty($module_params['orderby'])) {
        	$orderby = $module_params['orderby'];
        	$feedUrl = 'http://gdata.youtube.com/feeds/api/playlists/' . $id . '?orderby='. $orderby;
        } else {
        	$feedUrl = 'http://gdata.youtube.com/feeds/api/playlists/' . $id . '?orderby=position';
        }
        */
        try {
            // Get playlist information
            // DOC: https://developers.google.com/youtube/v3/docs/playlists/list
            $playlists = $youtube->playlists->listPlaylists("snippet", array('id' => $module_params['id'], 'hl' => $prefs['language']));
            // Get playlist content
            // DOC: https://developers.google.com/youtube/v3/docs/playlistItems/list
            $playlistItems = $youtube->playlistItems->listPlaylistItems('snippet', array('playlistId' => $module_params['id'], 'maxResults' => 50));
            $data[$id]['info']['title'] = $playlists[0]["snippet"]["localized"]['title'];
            // Prepare params for video display
            $params = array();
            $params['width'] = isset($module_params['width']) ? $module_params['width'] : 425;
            $params['height'] = isset($module_params['height']) ? $module_params['height'] : 350;
            $params['allowFullScreen'] = isset($module_params['allowFullScreen']) ? $module_params['allowFullScreen'] : true;
            // Get information from all videos from playlist
            // Limit to $module_rows first videos if $module_rows is set
            $count_videos = 1;
            foreach ($playlistItems as $videoEntry) {
                $videoId = $videoEntry['snippet']['resourceId']['videoId'];
                $data[$id]['videos'][$videoId]['title'] = $videoEntry['snippet']['title'];
                $data[$id]['videos'][$videoId]['uploaded'] = $videoEntry['snippet']['publishedAt'];
                $data[$id]['videos'][$videoId]['description'] = $videoEntry['snippet']['description'];
                $params['movie'] = $videoId;
                $pluginstr = wikiplugin_youtube('', $params);
                $len = strlen($pluginstr);
                //need to take off the ~np~ and ~/np~ at the beginning and end of the string returned by wikiplugin_youtube
                $data[$id]['videos'][$videoId]['xhtml'] = substr($pluginstr, 4, $len - 4 - 5);
                if (isset($module_rows) && $module_rows > 0 && $count_videos >= $module_rows) {
                    break;
                }
                $count_videos++;
            }
        } catch (Exception $e) {
            $data[$id]['info']['title'] = tra('No Playlist found');
            $data[$id]['videos'][0]['title'] = $e->getMessage();
        }
    } else {
        $id = 0;
        $data[$id]['info']['title'] = tra('No Playlist found');
        $data[$id]['videos'][0]['title'] = tra('No Playlist ID was provided');
    }
    $smarty->assign('verbose', isset($module_params['verbose']) ? $module_params['verbose'] : 'y');
    $smarty->assign('link_url', isset($module_params['link_url']) ? $module_params['link_url'] : '');
    $smarty->assign('link_text', isset($module_params['link_text']) ? $module_params['link_text'] : 'More Videos');
    $smarty->assign_by_ref('data', $data[$id]);
}