示例#1
0
 /**
  * Function to generate xml sitemap for videos
  * 
  * @author Praveen Rajan
  */
 function xml_sitemap()
 {
     if (!CvgCore::ffmpegcommandExists()) {
         CvgCore::show_video_error('Google XML Video Sitemap cannot be created since <b>FFMPEG</b> library is not installed in server. FFMPEG is required to collect video duration information.');
         return true;
     }
     $cool_video_gallery = new CoolVideoGallery();
     $results = videoDB::get_all_videos_sitemap();
     $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">';
     $xml .= '<!-- Generated by (http://wordpress.org/extend/plugins/cool-video-gallery/), Authored by Praveen Rajan -->' . "\n";
     $xml .= '<url>';
     $xml .= '<loc>' . site_url() . '</loc>';
     foreach ($results as $result) {
         if ($result['meta_data'] != '') {
             $video_meta_data = unserialize($result['meta_data']);
             $seconds = date('s', strtotime($video_meta_data['videoDuration']));
             $minutes = date('i', strtotime($video_meta_data['videoDuration']));
             $hours = date('H', strtotime($video_meta_data['videoDuration']));
             $total_seconds = round($hours * 60 * 60 + $minutes * 60 + $seconds);
         } else {
             $total_seconds = 100;
         }
         $gallery_details = videoDB::get_gallery_sitemap($result['galleryid']);
         if ($result['video_type'] == $cool_video_gallery->video_type_upload) {
             $video_url = site_url() . '/' . $gallery_details[0]['path'] . '/' . $result['filename'];
             $thumb_url = site_url() . '/' . $gallery_details[0]['path'] . '/thumbs/' . $result['thumb_filename'];
         } else {
             if ($result['video_type'] == $cool_video_gallery->video_type_youtube) {
                 $video_url = $result['filename'];
                 $thumb_url = $result['thumb_filename'];
             } else {
                 if ($result['video_type'] == $cool_video_gallery->video_type_media) {
                     $video_url = $result['filename'];
                     $thumb_url = site_url() . '/' . $gallery_details[0]['path'] . '/thumbs/' . $result['thumb_filename'];
                 } else {
                     $video_url = site_url() . '/' . $gallery_details[0]['path'] . '/' . $result['filename'];
                     $thumb_url = site_url() . '/' . $gallery_details[0]['path'] . '/thumbs/' . $result['thumb_filename'];
                 }
             }
         }
         $xml .= '<video:video>';
         $xml .= '<video:thumbnail_loc>' . htmlspecialchars($thumb_url) . '</video:thumbnail_loc>';
         $xml .= '<video:title>' . htmlspecialchars($result['video_title']) . '</video:title>';
         $xml .= '<video:description>' . htmlspecialchars(stripcslashes($result['description'])) . '</video:description>';
         $xml .= '<video:content_loc>' . htmlspecialchars($video_url) . '</video:content_loc>';
         $xml .= '<video:duration>' . $total_seconds . '</video:duration>';
         $xml .= '</video:video> ';
     }
     $xml .= '</url>';
     $xml .= '</urlset>';
     $video_sitemap_url = ABSPATH . 'sitemap-video.xml';
     if (CvgCore::createFile($video_sitemap_url)) {
         if (file_put_contents($video_sitemap_url, $xml)) {
             CvgCore::show_video_message('Google XML Video Sitemap successfully created at location <b>' . $video_sitemap_url . '</b>');
             return true;
         }
     }
 }