Exemplo n.º 1
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)
 }