Ejemplo n.º 1
0
 function update_cache_table(&$videolist_row)
 {
     $videolist_array = $this->csv_explode("\n", $videolist_row->videolist, '"', true);
     $firstvideo = '';
     $videolist = $this->formVideoList($videolist_array, $firstvideo);
     $ListOfVideos = array();
     $db = JFactory::getDBO();
     $parent_id = 0;
     $parent_details = array();
     $this_is_a_list = false;
     $list_count_left = 0;
     foreach ($videolist as $g) {
         $g_title = str_replace('"', '"', $g['title']);
         $g_description = str_replace('"', '"', $g['description']);
         if (isset($g['custom_title'])) {
             $custom_g_title = str_replace('"', '"', $g['custom_title']);
         } else {
             $custom_g_title = '';
         }
         if (isset($g['custom_description'])) {
             $custom_g_description = str_replace('"', '"', $g['custom_description']);
         } else {
             $custom_g_description = '';
         }
         $fields = array();
         if ($g['videosource'] == 'youtubeuseruploads' or $g['videosource'] == 'youtubestandard' or $g['videosource'] == 'youtubeplaylist' or $g['videosource'] == 'youtubeuserfavorites' or $g['videosource'] == 'youtubesearch' or $g['videosource'] == 'vimeouservideos' or $g['videosource'] == 'vimeochannel' or $g['videosource'] == 'vimeoalbum' or $g['videosource'] == 'videolist' or $g['videosource'] == 'dailymotionplaylist') {
             //parent
             $parent_id = 0;
             $this_is_a_list = true;
             $list_count_left = (int) $g['count'];
         } else {
             $this_is_a_list = false;
         }
         $fields[] = '`listid`="' . $videolist_row->id . '"';
         $fields[] = '`parentid`="' . $parent_id . '"';
         $fields[] = '`videosource`="' . $g['videosource'] . '"';
         $fields[] = '`videoid`="' . $g['videoid'] . '"';
         if ($g['imageurl'] != '') {
             $fields[] = '`imageurl`="' . $g['imageurl'] . '"';
         }
         if ($g['title'] != '') {
             $fields[] = '`title`="' . $g_title . '"';
         }
         if ($g['description'] != '') {
             $fields[] = '`description`="' . $g_description . '"';
         }
         if (isset($g['custom_imageurl'])) {
             $fields[] = '`custom_imageurl`="' . $g['custom_imageurl'] . '"';
         } else {
             $fields[] = '`custom_imageurl`=""';
         }
         if ($g['title'] != '') {
             $fields[] = '`alias`="' . YouTubeGalleryMisc::get_alias($g_title, $g['videoid']) . '"';
         }
         $fields[] = '`custom_title`="' . $custom_g_title . '"';
         $fields[] = '`custom_description`="' . $custom_g_description . '"';
         if (isset($g['specialparams'])) {
             $fields[] = '`specialparams`="' . $g['specialparams'] . '"';
         } else {
             $fields[] = '`specialparams`=""';
         }
         if (isset($g['startsecond'])) {
             $fields[] = '`startsecond`="' . $g['startsecond'] . '"';
         } else {
             $fields[] = '`startsecond`="0"';
         }
         if (isset($g['endsecond'])) {
             $fields[] = '`endsecond`="' . $g['endsecond'] . '"';
         } else {
             $fields[] = '`endsecond`="0"';
         }
         $fields[] = '`link`="' . $g['link'] . '"';
         $fields[] = '`ordering`="' . $g['ordering'] . '"';
         if ($this_is_a_list) {
             $fields[] = '`lastupdate`="' . date('Y-m-d H:i:s') . '"';
         }
         $fields[] = '`isvideo`="' . ($this_is_a_list ? '0' : '1') . '"';
         if (isset($g['publisheddate'])) {
             $fields[] = '`publisheddate`="' . $g['publisheddate'] . '"';
         }
         //else
         //	$fields[]='`publisheddate`=""';
         if (isset($g['duration'])) {
             $fields[] = '`duration`="' . $g['duration'] . '"';
         }
         //else
         //	$fields[]='`duration`=0';
         if (isset($g['rating_average'])) {
             $fields[] = '`rating_average`="' . $g['rating_average'] . '"';
         }
         //else
         //	$fields[]='`rating_average`=0';
         if (isset($g['rating_max'])) {
             $fields[] = '`rating_max`="' . $g['rating_max'] . '"';
         }
         //else
         //	$fields[]='`rating_max`=0';
         if (isset($g['rating_min'])) {
             $fields[] = '`rating_min`="' . $g['rating_min'] . '"';
         }
         //else
         //	$fields[]='`rating_min`=0';
         if (isset($g['rating_numRaters'])) {
             $fields[] = '`rating_numRaters`="' . $g['rating_numRaters'] . '"';
         }
         //else
         //	$fields[]='`rating_numRaters`=0';
         if (isset($g['statistics_favoriteCount'])) {
             $fields[] = '`statistics_favoriteCount`="' . $g['statistics_favoriteCount'] . '"';
         }
         if (isset($g['statistics_viewCount'])) {
             $fields[] = '`statistics_viewCount`="' . $g['statistics_viewCount'] . '"';
         }
         if (isset($g['keywords'])) {
             $fields[] = '`keywords`="' . $g['keywords'] . '"';
         }
         if (isset($g['likes'])) {
             $fields[] = '`likes`="' . $g['likes'] . '"';
         }
         if (isset($g['dislikes'])) {
             $fields[] = '`dislikes`="' . $g['dislikes'] . '"';
         }
         if ($this_is_a_list) {
             $parent_details = $g;
         }
         if (isset($parent_details['channel_username'])) {
             $fields[] = '`channel_username`="' . $parent_details['channel_username'] . '"';
         }
         if (isset($parent_details['channel_title'])) {
             $fields[] = '`channel_title`="' . $parent_details['channel_title'] . '"';
         }
         if (isset($parent_details['channel_subscribers'])) {
             $fields[] = '`channel_subscribers`="' . $parent_details['channel_subscribers'] . '"';
         }
         if (isset($parent_details['channel_subscribed'])) {
             $fields[] = '`channel_subscribed`="' . $parent_details['channel_subscribed'] . '"';
         }
         if (isset($parent_details['channel_location'])) {
             $fields[] = '`channel_location`="' . $parent_details['channel_location'] . '"';
         }
         if (isset($parent_details['channel_commentcount'])) {
             $fields[] = '`channel_commentcount`="' . $parent_details['channel_commentcount'] . '"';
         }
         if (isset($parent_details['channel_viewcount'])) {
             $fields[] = '`channel_viewcount`="' . $parent_details['channel_viewcount'] . '"';
         }
         if (isset($parent_details['channel_videocount'])) {
             $fields[] = '`channel_videocount`="' . $parent_details['channel_videocount'] . '"';
         }
         if (isset($parent_details['channel_description'])) {
             $fields[] = '`channel_description`="' . $parent_details['channel_description'] . '"';
         }
         //if(isset($parent_details['channel_totaluploadviews']))
         //$fields[]='`channel_totaluploadviews`="'.$parent_details['channel_totaluploadviews'].'"';
         $record_id = $this->isVideo_record_exist($g['videosource'], $g['videoid'], $videolist_row->id);
         $query = '';
         if ($record_id == 0) {
             $query = "INSERT #__youtubegallery_videos SET " . implode(', ', $fields) . ', `allowupdates`="1"';
             $db->setQuery($query);
             if (!$db->query()) {
                 die($db->stderr());
             }
             $record_id_new = $this->isVideo_record_exist($g['videosource'], $g['videoid'], $videolist_row->id);
             $ListOfVideos[] = $record_id_new;
             if ($this_is_a_list) {
                 $parent_id = $record_id_new;
                 $parent_details = $g;
             }
         } elseif ($record_id > 0) {
             if ($g_title != '***Video not found***') {
                 //Don't update info, if cannot get the info
                 $query = "UPDATE #__youtubegallery_videos SET " . implode(', ', $fields) . ' WHERE id=' . $record_id;
                 $db->setQuery($query);
                 if (!$db->query()) {
                     die($db->stderr());
                 }
                 $ListOfVideos[] = $record_id;
                 if ($this_is_a_list) {
                     $parent_id = $record_id;
                     $parent_details = $g;
                 }
             }
         }
         if (!$this_is_a_list) {
             if ($list_count_left > 0) {
                 $list_count_left -= 1;
             }
             if ($list_count_left == 0) {
                 $parent_id = 0;
             }
         }
     }
     //Delete All videos of this gallery that has bee delete form the list but allowed for updates.
     $query = 'DELETE FROM #__youtubegallery_videos WHERE listid=' . $videolist_row->id . ' AND allowupdates';
     if (count($ListOfVideos) > 0) {
         $query .= ' AND id!=' . implode(' AND id!=', $ListOfVideos) . ' ';
     }
     $db->setQuery($query);
     if (!$db->query()) {
         die($db->stderr());
     }
 }
Ejemplo n.º 2
0
 function RefreshVideoData(&$gallery_list, $getinfomethod, $force_refresh = false)
 {
     $db = JFactory::getDBO();
     $count = count($gallery_list);
     for ($i = 0; $i < $count; $i++) {
         $listitem = $gallery_list[$i];
         if (!$force_refresh) {
             $start = strtotime($listitem['lastupdate']);
             $end = strtotime(date('Y-m-d H:i:s'));
             $days_diff = ($end - $start) / 86400;
             $updateperiod = $this->videolist_row->updateperiod;
         } else {
             $updateperiod = 0;
         }
         if ($updateperiod == 0) {
             $updateperiod = 1;
         }
         if ($getinfomethod == 'js' or $getinfomethod == 'jsmanual') {
             $rd = YouTubeGalleryMisc::getRawData($listitem['videoid']);
             //if($rd=='')
             //{
             //YouTubeGalleryMisc::setDelayedRequest($listitem['videoid'])
             //$days_dif=0;
             if ($rd == '*youtubegallery_request*') {
                 $days_dif = 0;
             }
         }
         if ($force_refresh or $listitem['status'] == 0 or $days_diff > $updateperiod) {
             $listitem_temp = array();
             $listitem_temp[] = $listitem['link'];
             $listitem_temp[] = $listitem['custom_title'];
             $listitem_temp[] = $listitem['custom_description'];
             $listitem_temp[] = $listitem['custom_imageurl'];
             $listitem_new = $this->GrabVideoData($listitem_temp, $listitem['videosource'], $listitem['videoid'], $getinfomethod);
             if ($listitem_new['title'] != '') {
                 $listitem['title'] = $listitem_new['title'];
             }
             if ($listitem_new['description'] != '') {
                 $listitem['description'] = $listitem_new['description'];
             }
             if ($listitem_new['imageurl'] != '') {
                 $listitem['imageurl'] = $listitem_new['imageurl'];
             }
             $fields = array();
             $fields[] = '`title`="' . $this->mysqlrealescapestring($listitem_new['title']) . '"';
             if ($listitem_new['title'] != '') {
                 $fields[] = '`alias`="' . YouTubeGalleryMisc::get_alias($listitem_new['title'], $listitem['videoid']) . '"';
             }
             $fields[] = '`description`="' . $this->mysqlrealescapestring($listitem_new['description']) . '"';
             $fields[] = '`imageurl`="' . $listitem_new['imageurl'] . '"';
             $fields[] = '`lastupdate`="' . date('Y-m-d H:i:s') . '"';
             $fields[] = '`status`="200"';
             if (isset($listitem_new['startsecond'])) {
                 $fields[] = '`startsecond`="' . $listitem['startsecond'] . '"';
             }
             if (isset($listitem_new['endsecond'])) {
                 $fields[] = '`endsecond`="' . $listitem['endsecond'] . '"';
             }
             if (isset($listitem_new['publisheddate'])) {
                 $fields[] = '`publisheddate`="' . $listitem_new['publisheddate'] . '"';
             }
             if (isset($listitem_new['duration'])) {
                 $fields[] = '`duration`="' . $listitem_new['duration'] . '"';
             }
             if (isset($listitem_new['rating_average'])) {
                 $fields[] = '`rating_average`="' . $listitem_new['rating_average'] . '"';
             }
             if (isset($listitem_new['rating_max'])) {
                 $fields[] = '`rating_max`="' . $listitem_new['rating_max'] . '"';
             }
             if (isset($listitem_new['rating_min'])) {
                 $fields[] = '`rating_min`="' . $listitem_new['rating_min'] . '"';
             }
             if (isset($listitem_new['rating_numRaters'])) {
                 $fields[] = '`rating_numRaters`="' . $listitem_new['rating_numRaters'] . '"';
             }
             if (isset($listitem_new['statistics_favoriteCount'])) {
                 $fields[] = '`statistics_favoriteCount`="' . $listitem_new['statistics_favoriteCount'] . '"';
             }
             if (isset($listitem_new['statistics_viewCount'])) {
                 $fields[] = '`statistics_viewCount`="' . $listitem_new['statistics_viewCount'] . '"';
             }
             if (isset($listitem_new['keywords'])) {
                 $fields[] = '`keywords`="' . str_replace('"', '&quot;', $listitem_new['keywords']) . '"';
             }
             if (isset($listitem_new['likes'])) {
                 $fields[] = '`likes`="' . $listitem_new['likes'] . '"';
             }
             if (isset($listitem_new['dislikes'])) {
                 $fields[] = '`dislikes`="' . $listitem_new['dislikes'] . '"';
             }
             if (isset($listitem_new['commentcount'])) {
                 $fields[] = '`commentcount`="' . $listitem_new['commentcount'] . '"';
             }
             $query = "UPDATE `#__youtubegallery_videos` SET " . implode(', ', $fields) . ' WHERE `id`=' . (int) $listitem['id'];
             $db->setQuery($query);
             if (!$db->query()) {
                 die($db->stderr());
             }
             $gallery_list[$i] = $listitem;
         }
     }
     //foreach($gallery_list as $listitem)
 }