示例#1
0
 /**
  * displayRemoveVideoSubmit 
  * 
  * Remove video doesn't actually physically delete the video from FCMS, it 
  * just sets the video to in-active in the DB, which removes it from view.
  * 
  * We don't want to delete these entries from the db, because the cron importer
  * will just continue to import them.
  * 
  * @return void
  */
 function displayRemoveVideoSubmit()
 {
     if (!isset($_POST['id']) || !isset($_POST['source_id'])) {
         $this->displayHeader();
         echo '<div class="error_alert">' . T_('Can\'t remove video.  Missing video id.') . '</div>';
         $this->displayFooter();
         return;
     }
     $userId = (int) $_GET['u'];
     $id = (int) $_POST['id'];
     $sourceId = $_POST['source_id'];
     $sql = "UPDATE `fcms_video`\n                SET `active` = 0,\n                    `updated` = NOW(),\n                    `updated_id` = ?\n                WHERE `id` = ?";
     if (!$this->fcmsDatabase->update($sql, array($this->fcmsUser->id, $id))) {
         $this->displayFooter();
         $this->fcmsError->displayError();
         $this->displayFooter();
         return;
     }
     if (isset($_POST['delete_youtube'])) {
         $sessionToken = $this->getSessionToken($this->fcmsUser->id);
         $youtubeConfig = getYouTubeConfigData();
         $httpClient = getYouTubeAuthSubHttpClient($youtubeConfig['youtube_key'], $sessionToken);
         if ($httpClient === false) {
             // Error message was already displayed by getYouTubeAuthSubHttpClient()
             $this->displayFooter();
             return;
         }
         $youTubeService = new Zend_Gdata_YouTube($httpClient);
         $videoEntry = $youTubeService->getVideoEntry($sourceId);
         // Set message
         $_SESSION['message'] = 'delete_video_youtube';
         $youTubeService->delete($videoEntry);
     }
     // Set message
     if (!isset($_SESSION['message'])) {
         $_SESSION['message'] = 'remove_video';
     }
     // Send back to user's video listing
     header("Location: video.php?u={$userId}");
 }
示例#2
0
/**
 * runYouTubeJob 
 * 
 * Imports YouTube videos.
 * 
 * @return void
 */
function runYouTubeJob()
{
    global $file;
    require_once 'constants.php';
    require_once 'socialmedia.php';
    require_once 'datetime.php';
    require_once THIRDPARTY . 'gettext.inc';
    set_include_path(THIRDPARTY);
    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Gdata_YouTube');
    Zend_Loader::loadClass('Zend_Gdata_AuthSub');
    Zend_Loader::loadClass('Zend_Gdata_App_Exception');
    $fcmsError = FCMS_Error::getInstance();
    $fcmsDatabase = Database::getInstance($fcmsError);
    $existingIds = getExistingYouTubeIds();
    // Get user's session tokens
    $sql = "SELECT u.`id`, s.`youtube_session_token`\n            FROM `fcms_user_settings` AS s, `fcms_users` AS u\n            WHERE s.`user` = u.`id`\n            AND s.`youtube_session_token` IS NOT NULL";
    $rows = $fcmsDatabase->getRows($sql);
    if ($rows === false) {
        logError(__FILE__ . ' [' . __LINE__ . '] - Could not get youtube tokens.');
        die;
    }
    $sessionTokens = array();
    foreach ($rows as $row) {
        $sessionTokens[$row['id']] = $row['youtube_session_token'];
    }
    $youtubeConfig = getYouTubeConfigData();
    // Get videos for each user
    foreach ($sessionTokens as $userId => $token) {
        // Setup youtube api
        $httpClient = getYouTubeAuthSubHttpClient($youtubeConfig['youtube_key'], $token);
        $youTubeService = new Zend_Gdata_YouTube($httpClient);
        $feed = $youTubeService->getUserUploads('default');
        $values = '';
        $videoCount = 0;
        $params = array();
        foreach ($feed as $entry) {
            $id = $entry->getVideoId();
            if (isset($existingIds[$id])) {
                continue;
            }
            $title = htmlspecialchars($entry->getVideoTitle());
            $description = htmlspecialchars($entry->getVideoDescription());
            $created = formatDate('Y-m-d H:i:s', $entry->published);
            $duration = $entry->getVideoDuration();
            $height = '420';
            $width = '780';
            $thumbs = $entry->getVideoThumbnails();
            if (count($thumbs) > 0) {
                $height = $thumbs[0]['height'];
                $width = $thumbs[0]['width'];
            }
            $values .= "(?, ?, ?, 'youtube', ?, ?, ?, ?, NOW(), ?),";
            $params[] = $id;
            $params[] = $title;
            $params[] = $description;
            $params[] = $height;
            $params[] = $width;
            $params[] = $created;
            $params[] = $userId;
            $params[] = $userId;
            $videoCount++;
        }
        if ($videoCount > 0) {
            $values = substr($values, 0, -1);
            // remove comma
            $sql = "INSERT INTO `fcms_video`\n                        (`source_id`, `title`, `description`, `source`, `height`, `width`, `created`, `created_id`, `updated`, `updated_id`)\n                    VALUES {$values}";
            if (!$fcmsDatabase->insert($sql, $params)) {
                logError(__FILE__ . ' [' . __LINE__ . '] - Could not insert new video to db.');
                die;
            }
        }
    }
    // Update date we last ran this job
    updateLastRun(date('Y-m-d H:i:s'), 'youtube');
}
示例#3
0
 /**
  * displayEditYouTube 
  * 
  * @return void
  */
 function displayEditYouTube()
 {
     $this->displayHeader();
     $config = getYouTubeConfigData();
     $user = getYouTubeUserData($this->fcmsUser->id);
     // Setup url for callbacks
     $callbackUrl = getDomainAndDir();
     $callbackUrl .= 'settings.php?view=youtube';
     if (!empty($config['youtube_key'])) {
         if (!empty($user['youtube_session_token'])) {
             $httpClient = getYouTubeAuthSubHttpClient($config['youtube_key'], $user['youtube_session_token']);
             $youTubeService = new Zend_Gdata_YouTube($httpClient);
             $feed = $youTubeService->getUserProfile('default');
             if (!$feed instanceof Zend_Gdata_YouTube_UserProfileEntry) {
                 print '
         <div class="error-alert">' . T_('Could not get YouTube data for user.') . '</div>';
                 return;
             }
             $username = $feed->getUsername();
             $user = '******' . $username . '">' . $username . '</a>';
             $status = sprintf(T_('Currently connected as: %s'), $user);
             $link = '<a class="disconnect" href="?revoke=youtube">' . T_('Disconnect') . '</a>';
         } else {
             $url = Zend_Gdata_AuthSub::getAuthSubTokenUri($callbackUrl, 'http://gdata.youtube.com', false, true);
             $status = T_('Not Connected');
             $link = '<a href="' . $url . '">' . T_('Connect') . '</a>';
         }
     }
     echo '
     <div class="social-media-connect">
         <img class="icon" src="ui/img/youtube.png" alt="YouTube"/>
         <h2>YouTube</h2>
         <p>' . T_('YouTube allows users to discover, watch and share videos.') . '</p>
         <div class="status">' . $status . '</div>
         <div class="action">' . $link . '</div>
     </div>';
     $this->displayFooter();
 }