コード例 #1
0
ファイル: youtube.php プロジェクト: justangel/izap-videos
 *    This file is part of izap-videos plugin for Elgg.
 *
 *    izap-videos for Elgg is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    izap-videos for Elgg is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with izap-videos for Elgg.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Save YouTube videos
 * 
 * @version 5.0
 */
$youtube_data = array('title' => $this->title, 'description' => $this->description, 'youtube_cats' => $this->youtube_cats, 'tags' => $this->tags, 'container_guid' => $this->container_guid, 'access_id' => $this->access_id, 'tags' => $this->tags);
$_SESSION['youtube_attributes'] = $youtube_data;
$video = IzapGYoutube::getAuthSubHttpClient(get_input('token', false));
//get youtube api authorization via users application access.
if (!$video instanceof IzapGYoutube) {
    forward($video);
} else {
    // if we already have access token for youtube. than redirect user directly
    // on upload page.
    forward(izap_set_href(array('action' => 'upload', 'context' => GLOBAL_IZAP_VIDEOS_PAGEHANDLER)));
}
コード例 #2
0
ファイル: izap-videos.php プロジェクト: justangel/izap-videos
/**
 * Get page components to upload youtube video.
 * 
 * @param string  $page
 * @param integer $guid
 * @param string  $revision
 * 
 * @return array  array of content for YouTube video uploading
 * 
 * @version 5.0
 */
function izap_video_get_page_content_youtube_upload($page, $guid = 0, $revision = NULL)
{
    $return = array('filter' => '');
    $form_vars = array();
    $params = array();
    $video = IzapGYoutube::getAuthSubHttpClient(get_input('token', false));
    //get youtube api authorization via users application access.
    //	if (get_input('token')) {
    $video = IzapGYoutube::getAuthSubHttpClient(get_input('token', false));
    if ($video instanceof IzapGYoutube) {
        $yt = $video->YoutubeObject();
        $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
        $myVideoEntry->setVideoTitle($_SESSION['youtube_attributes']['title']);
        $description = strip_tags($_SESSION['youtube_attributes']['description']);
        $myVideoEntry->setVideoDescription($description);
        // Note that category must be a valid YouTube category
        $myVideoEntry->setVideoCategory($_SESSION['youtube_attributes']['youtube_cats']);
        $myVideoEntry->SetVideoTags($_SESSION['youtube_attributes']['tags']);
        $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
        try {
            $tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
        } catch (Exception $e) {
            if (preg_match("/<code>([a-z_]+)<\\/code>/", $e->getMessage(), $matches)) {
                register_error('YouTube Error: ' . $matches[1]);
            } else {
                register_error('YouTube Error: ' . $e->getMessage());
            }
            forward(izap_set_href(array('context' => GLOBAL_IZAP_VIDEOS_PAGEHANDLER, 'action' => 'add', 'page_owner' => elgg_get_logged_in_user_guid(), 'vars' => array('tab' => 'youtube'))));
        }
        $params['token'] = $tokenArray['token'];
        $params['action'] = $tokenArray['url'] . '?nexturl=' . elgg_get_site_url() . GLOBAL_IZAP_VIDEOS_PAGEHANDLER . '/next&scope=https://gdata.youtube.com&session=1&secure=0';
        elgg_push_breadcrumb(elgg_echo('upload'));
        $form_vars = array('enctype' => 'multipart/form-data', 'name' => 'video_upload', 'action' => $params['action'], 'id' => 'izap-video-form');
        $title = elgg_echo('Upload video with title: "' . $_SESSION['youtube_attributes']['title'] . '"');
        $content = elgg_view_form('izap-videos/youtube_upload', $form_vars, $params);
        $return['title'] = $title;
        $return['content'] = $content;
        return $return;
    } else {
        register_error('You must have to grant access for youtube upload');
        forward();
    }
}