/**
  * @return string
  */
 public function process()
 {
     if (isset($_POST['SourceURL'])) {
         $sourceURL = $_POST['SourceURL'];
         $bIsCloudinary = CloudinaryVideo::isCloudinary($sourceURL);
         $bIsYoutube = YoutubeVideo::is_youtube($sourceURL);
         $bIsVimeo = VimeoVideo::is_vimeo($sourceURL);
         $video = null;
         if ($bIsYoutube || $bIsVimeo || $bIsCloudinary) {
             if ($bIsCloudinary) {
                 $filterClass = 'CloudinaryVideo';
                 $fileType = 'video';
             } elseif ($bIsYoutube) {
                 $filterClass = 'YoutubeVideo';
                 $fileType = 'youtube';
             } else {
                 $filterClass = 'VimeoVideo';
                 $fileType = 'vimeo';
             }
             $funcForID = $bIsYoutube ? 'youtube_id_from_url' : 'vimeo_id_from_url';
             $funcForDetails = $bIsYoutube ? 'youtube_video_details' : 'vimeo_video_details';
             if ($bIsCloudinary) {
                 $arr = Config::inst()->get('CloudinaryConfigs', 'settings');
                 if (isset($arr['CloudName']) && !empty($arr['CloudName'])) {
                     $arrPieces = explode('/', $sourceURL);
                     $arrFileName = array_slice($arrPieces, 7);
                     $fileName = implode('/', $arrFileName);
                     $publicID = substr($fileName, 0, strrpos($fileName, '.'));
                     $video = $filterClass::get()->filterAny(array('URL' => $sourceURL, 'PublicID' => $publicID))->first();
                     if (!$video) {
                         $api = new \Cloudinary\Api();
                         $resource = $api->resource($publicID, array("resource_type" => "video"));
                         //qoogjqs9ksyez7ch8sh5
                         $json = json_encode($resource);
                         $arrResource = Convert::json2array($json);
                         $video = new $filterClass(array('Title' => $arrResource['public_id'] . '.' . $arrResource['format'], 'PublicID' => $arrResource['public_id'], 'Version' => $arrResource['version'], 'URL' => $arrResource['url'], 'SecureURL' => $arrResource['secure_url'], 'FileType' => $arrResource['resource_type'], 'FileSize' => $arrResource['bytes'], 'Format' => $arrResource['format'], 'Signature' => isset($arrResource['signature']) ? $arrResource['signature'] : ''));
                         $video->write();
                     }
                 }
             } else {
                 $video = $filterClass::get()->filter('URL', $sourceURL)->first();
                 if (!$video) {
                     $sourceID = $filterClass::$funcForID($sourceURL);
                     $details = $filterClass::$funcForDetails($sourceID);
                     $video = new $filterClass(array('Title' => $details['title'], 'Duration' => $details['duration'], 'URL' => $sourceURL, 'secure_url' => $sourceURL, 'PublicID' => $sourceID, 'FileType' => $fileType));
                     $video->write();
                 }
             }
             if ($video) {
                 $this->value = $iVideoID = $video->ID;
                 $file = $this->customiseCloudinaryFile($video);
                 return Convert::array2json(array('colorselect_url' => $file->UploadFieldImageURL, 'thumbnail_url' => $file->UploadFieldThumbnailURL, 'fieldname' => $this->getName(), 'id' => $file->ID, 'url' => $file->URL, 'buttons' => $file->UploadFieldFileButtons, 'more_files' => $this->canUploadMany(), 'field_id' => $this->ID()));
             }
         }
     }
     return Convert::array2json(array());
 }
 /**
  * Update or create the database entries for each element of the given videos array
  * @param $videos: Array with all videos to update
  */
 protected function updateVideoEntries($videos)
 {
     // Holder for all updated or newly created entries
     $processed = ArrayList::create();
     // Loop over the given videos fetched from the API
     foreach ($videos as $video) {
         // Get the entry or create new one
         if (!($yv = YoutubeVideo::get()->filter('PlaylistItemID', $video->id)->first())) {
             $yv = new YoutubeVideo();
             $yv->Title = $video->snippet->title;
             $yv->Description = $video->snippet->description;
         }
         $yv->PlaylistItemID = $video->id;
         $yv->VideoID = $video->contentDetails->videoId;
         $thumbs = $video->snippet->thumbnails->toMap();
         $yv->ThumbnailURL = end($thumbs)->url;
         // Write to the db and store as processed item
         $yv->write();
         $processed->push($yv);
     }
     /**
      * Loop over all video entries from the database
      * delete all entries, which are found in the db but not processed above
      */
     foreach (YoutubeVideo::get() as $video) {
         if (!$processed->find('ID', $video->ID)) {
             $video->delete();
         }
     }
 }
 public function getYoutubeVideos()
 {
     return YoutubeVideo::get()->filter('Visible', 1);
 }
Пример #4
0
<?php

defined('_JEXEC') or die('Direct Access Denied');
require_once dirname(__FILE__) . '/helper.php';
if (isset($_POST['my_youtube_btn'])) {
    $jinput = JFactory::getApplication()->input;
    $youtube_link = $jinput->get('yt_link');
    $helper = new YoutubeVideo($params);
    $youtube_duration =& $helper->youtube_duration($youtube_link);
    $youtube_title =& $helper->youtube_title($youtube_link);
    $youtube_description =& $helper->youtube_description($youtube_link);
    $youtube_publishedAt =& $helper->youtube_publishedAt($youtube_link);
    $youtube_statistics_dislikeCount =& $helper->youtube_statistics_dislikeCount($youtube_link);
    $youtube_statistics_likeCount =& $helper->youtube_statistics_likeCount($youtube_link);
    $youtube_statistics_viewCount =& $helper->youtube_statistics_viewCount($youtube_link);
    echo '<h1>' . $youtube_title . '</h1>';
    echo '<p>Opis: <br> ' . $youtube_description . '</p>';
    echo '<h3>Opublikowane: ' . $youtube_publishedAt . '</h3>';
    echo '<span>Czas trwania: ' . $youtube_duration . '</span>';
    echo '<p><span>Obejrzane: ' . $youtube_statistics_viewCount . '</span> | <span>Like:  ' . $youtube_statistics_likeCount . '</span> | <span>DisLike: ' . $youtube_statistics_dislikeCount . '</span></p>';
    echo '<iframe width="560" height="315" src="https://www.youtube.com/embed/' . $youtube_link . '" frameborder="0" allowfullscreen></iframe><br><hr>';
} else {
    require JModuleHelper::getLayoutPath('mod_youtubevideo');
}