Version Description
Download this release
Release Info
Developer | labnol |
Plugin | Google XML Sitemap for Videos |
Version | 2.5.1 |
Comparing to | |
See all releases |
Code changes from version 2.5 to 2.5.1
- readme.txt +1 -1
- video-sitemap.php +134 -134
- video-sitemap.xsl +10 -9
readme.txt
CHANGED
@@ -3,7 +3,7 @@ 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.3.1
|
6 |
-
Stable tag: 2.5
|
7 |
|
8 |
This plugin will help you generate Google Video Sitemaps (XML) for your WordPress blog.
|
9 |
|
3 |
Tags: youtube, xml sitemaps, google sitemaps, videos, seo, sitemaps, video sitemap
|
4 |
Requires at least: 2.9.2
|
5 |
Tested up to: 3.3.1
|
6 |
+
Stable tag: 2.5.1
|
7 |
|
8 |
This plugin will help you generate Google Video Sitemaps (XML) for your WordPress blog.
|
9 |
|
video-sitemap.php
CHANGED
@@ -4,54 +4,54 @@ 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.5
|
8 |
Author URI: http://www.labnol.org/
|
9 |
*/
|
10 |
|
11 |
add_action ('admin_menu', 'video_sitemap_generate_page');
|
12 |
|
13 |
function video_sitemap_generate_page () {
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
}
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
|
49 |
function video_sitemap_generate () {
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
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 |
|
@@ -83,113 +83,113 @@ exit();
|
|
83 |
</form>
|
84 |
<p>You can click the button above to generate a Video Sitemap for your website. Once you have created your Sitemap, you should submit it to Google using Webmaster Tools. </p>
|
85 |
<code>This WordPress plugin was developed by <a href="http://www.labnol.org/about/">Amit Agarwal</a> of <a href="http://www.labnol.org/">Digital Inspiration</a>.</code> </div>
|
86 |
-
<?php
|
87 |
}
|
88 |
|
89 |
function video_sitemap_loop () {
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
$c = 0;
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
if ($_POST['time'] == 1) {
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
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>';
|
174 |
-
|
175 |
}
|
176 |
|
177 |
# given a video id, get the duration.
|
178 |
# might give this a delay to avoid running into issues with YouTube.
|
179 |
function youtube_duration ($id) {
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
}
|
195 |
?>
|
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.5.1
|
8 |
Author URI: http://www.labnol.org/
|
9 |
*/
|
10 |
|
11 |
add_action ('admin_menu', 'video_sitemap_generate_page');
|
12 |
|
13 |
function video_sitemap_generate_page () {
|
14 |
+
if (function_exists ('add_submenu_page'))
|
15 |
+
add_submenu_page ('tools.php', __('Video Sitemap'), __('Video Sitemap'),
|
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 |
|
83 |
</form>
|
84 |
<p>You can click the button above to generate a Video Sitemap for your website. Once you have created your Sitemap, you should submit it to Google using Webmaster Tools. </p>
|
85 |
<code>This WordPress plugin was developed by <a href="http://www.labnol.org/about/">Amit Agarwal</a> of <a href="http://www.labnol.org/">Digital Inspiration</a>.</code> </div>
|
86 |
+
<?php }
|
87 |
}
|
88 |
|
89 |
function video_sitemap_loop () {
|
90 |
+
global $wpdb;
|
91 |
+
|
92 |
+
$posts = $wpdb->get_results ("SELECT id, post_title, post_content, post_date_gmt, post_excerpt
|
93 |
+
FROM $wpdb->posts WHERE post_status = 'publish'
|
94 |
+
AND (post_type = 'post' OR post_type = 'page')
|
95 |
+
AND post_content LIKE '%youtube.com%'
|
96 |
+
ORDER BY post_date DESC");
|
97 |
+
|
98 |
+
if (empty ($posts)) {
|
99 |
+
return false;
|
100 |
+
|
101 |
+
} else {
|
102 |
+
|
103 |
+
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
104 |
+
$xml .= '<!-- Created by (http://wordpress.org/extend/plugins/xml-sitemaps-for-videos/) -->' . "\n";
|
105 |
+
$xml .= '<!-- Generated-on="' . date("F j, Y, g:i a") .'" -->' . "\n";
|
106 |
+
$xml .= '<?xml-stylesheet type="text/xsl" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/xml-sitemaps-for-videos/video-sitemap.xsl"?>' . "\n" ;
|
107 |
+
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' . "\n";
|
108 |
+
|
109 |
+
$videos = array();
|
110 |
+
|
111 |
+
foreach ($posts as $post) {
|
112 |
$c = 0;
|
113 |
+
if (preg_match_all ("/youtube.com\/(v\/|watch\?v=|embed\/)([a-zA-Z0-9\-_]*)/", $post->post_content, $matches, PREG_SET_ORDER)) {
|
114 |
+
|
115 |
+
$excerpt = ($post->post_excerpt != "") ? $post->post_excerpt : $post->post_title ;
|
116 |
+
$permalink = get_permalink($post->id);
|
117 |
+
|
118 |
+
foreach ($matches as $match) {
|
119 |
+
|
120 |
+
$id = $match [2];
|
121 |
+
$fix = $c++==0?'':' [Video '. $c .'] ';
|
122 |
+
|
123 |
+
if (in_array($id, $videos))
|
124 |
+
continue;
|
125 |
+
|
126 |
+
array_push($videos, $id);
|
127 |
+
|
128 |
+
$xml .= "\n <url>\n";
|
129 |
+
$xml .= " <loc>$permalink</loc>\n";
|
130 |
+
$xml .= " <video:video>\n";
|
131 |
+
$xml .= " <video:player_loc allow_embed=\"yes\" autoplay=\"autoplay=1\">http://www.youtube.com/v/$id</video:player_loc>\n";
|
132 |
+
$xml .= " <video:thumbnail_loc>http://i.ytimg.com/vi/$id/hqdefault.jpg</video:thumbnail_loc>\n";
|
133 |
+
$xml .= " <video:title>" . htmlspecialchars($post->post_title) . $fix . "</video:title>\n";
|
134 |
+
$xml .= " <video:description>" . $fix . htmlspecialchars($excerpt) . "</video:description>\n";
|
135 |
+
|
136 |
if ($_POST['time'] == 1) {
|
137 |
+
$duration = youtube_duration ($id);
|
138 |
+
if ($duration != 0)
|
139 |
+
$xml .= " <video:duration>".youtube_duration ($id)."</video:duration>\n";
|
140 |
+
}
|
141 |
+
|
142 |
+
$xml .= " <video:publication_date>".date (DATE_W3C, strtotime ($post->post_date_gmt))."</video:publication_date>\n";
|
143 |
+
|
144 |
+
$posttags = get_the_tags($post->id); if ($posttags) {
|
145 |
+
$tagcount=0;
|
146 |
+
foreach ($posttags as $tag) {
|
147 |
+
if ($tagcount++ > 32) break;
|
148 |
+
$xml .= " <video:tag>$tag->name</video:tag>\n";
|
149 |
+
}
|
150 |
+
}
|
151 |
+
|
152 |
+
$postcats = get_the_category($post->id); if ($postcats) {
|
153 |
+
foreach ($postcats as $category) {
|
154 |
+
$xml .= " <video:category>$category->name</video:category>\n";
|
155 |
+
break;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
$xml .= " </video:video>\n </url>";
|
160 |
+
}
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
$xml .= "\n</urlset>";
|
165 |
+
}
|
166 |
+
|
167 |
+
$video_sitemap_url = $_SERVER["DOCUMENT_ROOT"] . '/sitemap-video.xml';
|
168 |
+
if (IsVideoSitemapWritable($_SERVER["DOCUMENT_ROOT"]) || IsVideoSitemapWritable($video_sitemap_url)) {
|
169 |
+
if (file_put_contents ($video_sitemap_url, $xml)) {
|
170 |
+
return true;
|
171 |
+
}
|
172 |
+
}
|
173 |
+
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>';
|
174 |
+
exit();
|
175 |
}
|
176 |
|
177 |
# given a video id, get the duration.
|
178 |
# might give this a delay to avoid running into issues with YouTube.
|
179 |
function youtube_duration ($id) {
|
180 |
+
try {
|
181 |
+
$ch = curl_init ();
|
182 |
+
curl_setopt ($ch, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos/$id");
|
183 |
+
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
184 |
+
$data = curl_exec ($ch);
|
185 |
+
curl_close ($ch);
|
186 |
+
|
187 |
+
preg_match ("/duration=['\"]([0-9]*)['\"]/", $data, $match);
|
188 |
+
return $match [1];
|
189 |
+
|
190 |
+
} catch (Exception $e) {
|
191 |
+
# returning 0 if the YouTube API fails for some reason.
|
192 |
+
return '0';
|
193 |
+
}
|
194 |
}
|
195 |
?>
|
video-sitemap.xsl
CHANGED
@@ -13,7 +13,7 @@
|
|
13 |
<style type="text/css">
|
14 |
body {
|
15 |
font-family:Georgia, "Times New Roman", Times, serif;
|
16 |
-
font-size:
|
17 |
background: url(http://img.labnol.org/files/qcpgwkr.png) repeat;
|
18 |
margin: 10px;
|
19 |
}
|
@@ -32,17 +32,18 @@ a:link {
|
|
32 |
}
|
33 |
p {
|
34 |
position: absolute;
|
35 |
-
top:
|
36 |
-
left: 5px;
|
37 |
width: 90%;
|
38 |
-
color: #
|
39 |
padding: 10px;
|
40 |
-
background
|
41 |
font-style: italic;
|
42 |
line-height: 18px;
|
|
|
|
|
43 |
}
|
44 |
p strong {
|
45 |
-
font-size:
|
46 |
color: #FFF;
|
47 |
line-height: 30px;
|
48 |
font-style: normal;
|
@@ -51,11 +52,11 @@ p strong {
|
|
51 |
</head>
|
52 |
<body>
|
53 |
<xsl:for-each select="sitemap:urlset/sitemap:url">
|
|
|
|
|
54 |
<a href="{$u}" target="_blank">
|
55 |
<div class="labnol"><img src="{$t}" width="480" height="360" />
|
56 |
-
<xsl:variable name="u"> <xsl:value-of select="sitemap:loc"/> </xsl:variable>
|
57 |
<p><strong><xsl:value-of select="video:video/video:title"/></strong><br />
|
58 |
-
<xsl:variable name="t"> <xsl:value-of select="video:video/video:thumbnail_loc"/> </xsl:variable>
|
59 |
<xsl:variable name="d"><xsl:value-of select="video:video/video:description"/> </xsl:variable>
|
60 |
<xsl:choose>
|
61 |
<xsl:when test="string-length($d) < 100">
|
@@ -72,4 +73,4 @@ p strong {
|
|
72 |
</body>
|
73 |
</html>
|
74 |
</xsl:template>
|
75 |
-
</xsl:stylesheet>
|
13 |
<style type="text/css">
|
14 |
body {
|
15 |
font-family:Georgia, "Times New Roman", Times, serif;
|
16 |
+
font-size:11px;
|
17 |
background: url(http://img.labnol.org/files/qcpgwkr.png) repeat;
|
18 |
margin: 10px;
|
19 |
}
|
32 |
}
|
33 |
p {
|
34 |
position: absolute;
|
35 |
+
top: 215px;
|
|
|
36 |
width: 90%;
|
37 |
+
color: #ddd;
|
38 |
padding: 10px;
|
39 |
+
background: #222;
|
40 |
font-style: italic;
|
41 |
line-height: 18px;
|
42 |
+
opacity:0.9;
|
43 |
+
filter:alpha(opacity=90);
|
44 |
}
|
45 |
p strong {
|
46 |
+
font-size: 16px;
|
47 |
color: #FFF;
|
48 |
line-height: 30px;
|
49 |
font-style: normal;
|
52 |
</head>
|
53 |
<body>
|
54 |
<xsl:for-each select="sitemap:urlset/sitemap:url">
|
55 |
+
<xsl:variable name="u"> <xsl:value-of select="sitemap:loc"/> </xsl:variable>
|
56 |
+
<xsl:variable name="t"> <xsl:value-of select="video:video/video:thumbnail_loc"/> </xsl:variable>
|
57 |
<a href="{$u}" target="_blank">
|
58 |
<div class="labnol"><img src="{$t}" width="480" height="360" />
|
|
|
59 |
<p><strong><xsl:value-of select="video:video/video:title"/></strong><br />
|
|
|
60 |
<xsl:variable name="d"><xsl:value-of select="video:video/video:description"/> </xsl:variable>
|
61 |
<xsl:choose>
|
62 |
<xsl:when test="string-length($d) < 100">
|
73 |
</body>
|
74 |
</html>
|
75 |
</xsl:template>
|
76 |
+
</xsl:stylesheet>
|