Google XML Sitemap for Videos - Version 2.0.2

Version Description

Download this release

Release Info

Developer labnol
Plugin Icon wp plugin Google XML Sitemap for Videos
Version 2.0.2
Comparing to
See all releases

Code changes from version 2.0.1 to 2.0.2

Files changed (2) hide show
  1. readme.txt +17 -4
  2. video-sitemap.php +50 -8
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Plugin Name ===
2
  Contributors: labnol
3
- Tags: youtube, xml sitemaps, google sitemaps, bing, videos, seo, search engines, sitemap
4
  Requires at least: 2.9.2
5
- Tested up to: 3.0
6
- Stable tag: 2.0.1
7
 
8
  This plugin will help you generate Google Video Sitemaps (XML) for your WordPress blog.
9
 
@@ -47,6 +47,10 @@ If you have a *small number of videos* on your website, you may check this optio
47
 
48
  You can find the sitemap-video.xml file in your blog's root folder.
49
 
 
 
 
 
50
  = Can I block search engines from indexing pages that are in the XML Sitemap file? =
51
 
52
  The Sitemaps protocol enables you to let search engines know what content you would like indexed. To tell search engines the content you don't want indexed, use a robots.txt file or add a robots meta tag to the web page that you would like to block.
@@ -54,4 +58,13 @@ The Sitemaps protocol enables you to let search engines know what content you wo
54
  == Screenshots ==
55
 
56
  1. Click the button to generate your video sitemap.
57
- 2. This is how the XML sitemap should look like in your web browser.
 
 
 
 
 
 
 
 
 
1
  === Plugin Name ===
2
  Contributors: labnol
3
+ Tags: youtube, xml sitemaps, google sitemaps, videos, seo, sitemaps, video sitemap
4
  Requires at least: 2.9.2
5
+ Tested up to: 3.0.1
6
+ Stable tag: 2.1.1
7
 
8
  This plugin will help you generate Google Video Sitemaps (XML) for your WordPress blog.
9
 
47
 
48
  You can find the sitemap-video.xml file in your blog's root folder.
49
 
50
+ = I am getting Permission Denied like errors =
51
+
52
+ It implies that you don't have write permissions on your blog's root folder. Please use chmod or your FTP manager to set the necessary permissions to 0666.
53
+
54
  = Can I block search engines from indexing pages that are in the XML Sitemap file? =
55
 
56
  The Sitemaps protocol enables you to let search engines know what content you would like indexed. To tell search engines the content you don't want indexed, use a robots.txt file or add a robots meta tag to the web page that you would like to block.
58
  == Screenshots ==
59
 
60
  1. Click the button to generate your video sitemap.
61
+ 2. This is how the XML sitemap should look like in your web browser.
62
+
63
+ == Changelog ==
64
+
65
+ = 2.1 =
66
+ * If the plugin is unable to create a sitemap file, it gives an option to manually create the file.
67
+ * More error handling included.
68
+
69
+ = 2.0.1 =
70
+ * Better Error Handline
video-sitemap.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Google XML Sitemap for Videos
4
  Plugin URI: http://www.labnol.org/software/xml-video-sitemaps-for-google/14085/
5
  Description: This plugin will generate a XML Video Sitemap for your WordPress blog. Open the <a href="tools.php?page=video-sitemap-generate-page">settings page</a> to create your video sitemap.
6
  Author: Amit Agarwal
7
- Version: 2.0.1
8
  Author URI: http://www.labnol.org/
9
  */
10
 
@@ -16,10 +16,45 @@ function video_sitemap_generate_page () {
16
  'manage_options', 'video-sitemap-generate-page', 'video_sitemap_generate');
17
  }
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  function video_sitemap_generate () {
20
 
21
  if ($_POST ['submit']) {
22
- video_sitemap_loop ();
 
 
 
 
 
23
  ?>
24
 
25
  <div class="wrap">
@@ -59,7 +94,7 @@ function video_sitemap_loop () {
59
  FROM $wpdb->posts
60
  WHERE post_status = 'publish'
61
  AND (post_type = 'post' OR post_type = 'page')
62
- AND post_content LIKE '%youtube.com%'
63
  ORDER BY post_date DESC");
64
 
65
  if (empty ($posts)) {
@@ -67,9 +102,11 @@ function video_sitemap_loop () {
67
 
68
  } else {
69
 
70
- $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
71
- $xml .= '<?xml-stylesheet type="text/xsl" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/xml-sitemaps-for-videos/video-sitemap.xsl"?>' . "\n" ;
72
- $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' . "\n";
 
 
73
 
74
  foreach ($posts as $post) {
75
  if (preg_match_all ("(<embed[^>]*src=['\"]http:\/\/www.youtube.com\/v\/([a-zA-Z0-9\-_]*)|youtube.com\/watch\?v=([a-zA-Z0-9\-_]*))",
@@ -120,8 +157,13 @@ function video_sitemap_loop () {
120
  }
121
 
122
  $video_sitemap_url = $_SERVER["DOCUMENT_ROOT"] . '/sitemap-video.xml';
123
- file_put_contents ($video_sitemap_url, $xml);
124
-
 
 
 
 
 
125
  }
126
 
127
  # given a video id, get the duration.
4
  Plugin URI: http://www.labnol.org/software/xml-video-sitemaps-for-google/14085/
5
  Description: This plugin will generate a XML Video Sitemap for your WordPress blog. Open the <a href="tools.php?page=video-sitemap-generate-page">settings page</a> to create your video sitemap.
6
  Author: Amit Agarwal
7
+ Version: 2.1.1
8
  Author URI: http://www.labnol.org/
9
  */
10
 
16
  'manage_options', 'video-sitemap-generate-page', 'video_sitemap_generate');
17
  }
18
 
19
+ /**
20
+ * Checks if a file is writable and tries to make it if not.
21
+ *
22
+ * @since 3.05b
23
+ * @access private
24
+ * @author VJTD3 <http://www.VJTD3.com>
25
+ * @return bool true if writable
26
+ */
27
+ function IsVideoSitemapWritable($filename) {
28
+ //can we write?
29
+ if(!is_writable($filename)) {
30
+ //no we can't.
31
+ if(!@chmod($filename, 0666)) {
32
+ $pathtofilename = dirname($filename);
33
+ //Lets check if parent directory is writable.
34
+ if(!is_writable($pathtofilename)) {
35
+ //it's not writeable too.
36
+ if(!@chmod($pathtoffilename, 0666)) {
37
+ //darn couldn't fix up parrent directory this hosting is foobar.
38
+ //Lets error because of the permissions problems.
39
+ return false;
40
+ }
41
+ }
42
+ }
43
+ }
44
+ //we can write, return 1/true/happy dance.
45
+ return true;
46
+ }
47
+
48
+
49
  function video_sitemap_generate () {
50
 
51
  if ($_POST ['submit']) {
52
+ $st = video_sitemap_loop ();
53
+ if (!$st) {
54
+ echo '<br /><div class="error"><h2>Oops!</h2><p>Looks like none of your blog posts contain YouTube videos. Please publish a test post containing a YouTube video and regnerate the video sitemap.</p><p>If the issue remains unresolved, please post the error message in this <a target="_blank" href="http://wordpress.org/tags/xml-sitemaps-for-videos?forum_id=10#postform">WordPress forum</a>.</p></div>';
55
+ exit();
56
+ }
57
+
58
  ?>
59
 
60
  <div class="wrap">
94
  FROM $wpdb->posts
95
  WHERE post_status = 'publish'
96
  AND (post_type = 'post' OR post_type = 'page')
97
+ AND post_content LIKE '%youtube.com%'
98
  ORDER BY post_date DESC");
99
 
100
  if (empty ($posts)) {
102
 
103
  } else {
104
 
105
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
106
+ $xml .= '<!-- Created by (http://wordpress.org/extend/plugins/xml-sitemaps-for-videos/) -->' . "\n";
107
+ $xml .= '<!-- Generated-on="' . date("F j, Y, g:i a") .'" -->' . "\n";
108
+ $xml .= '<?xml-stylesheet type="text/xsl" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/xml-sitemaps-for-videos/video-sitemap.xsl"?>' . "\n" ;
109
+ $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' . "\n";
110
 
111
  foreach ($posts as $post) {
112
  if (preg_match_all ("(<embed[^>]*src=['\"]http:\/\/www.youtube.com\/v\/([a-zA-Z0-9\-_]*)|youtube.com\/watch\?v=([a-zA-Z0-9\-_]*))",
157
  }
158
 
159
  $video_sitemap_url = $_SERVER["DOCUMENT_ROOT"] . '/sitemap-video.xml';
160
+ if (IsVideoSitemapWritable($_SERVER["DOCUMENT_ROOT"]) || IsVideoSitemapWritable($video_sitemap_url)) {
161
+ if (file_put_contents ($video_sitemap_url, $xml)) {
162
+ return true;
163
+ }
164
+ }
165
+ echo '<br /><div class="wrap"><h2>Error writing the file</h2><p>The XML sitemap was generated successfully but the plugin was unable to save the xml to your WordPress root folder at <strong>' . $_SERVER["DOCUMENT_ROOT"] . '</strong> probably because the folder doesn\'t have appropriate <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">write permissions</a>.</p><p>You can however manually copy-paste the following text into a file and save it as video-sitemap.xml in your WordPress root folder. </p><br /><textarea rows="30" cols="150" style="font-family:verdana; font-size:11px;color:#666;background-color:#f9f9f9;padding:5px;margin:5px">' . $xml . '</textarea></div>';
166
+ exit();
167
  }
168
 
169
  # given a video id, get the duration.