Version Description
Download this release
Release Info
Developer | labnol |
Plugin | Google XML Sitemap for Images |
Version | 2.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 2.0
- image-sitemap.php +81 -94
- readme.txt +14 -8
image-sitemap.php
CHANGED
@@ -4,131 +4,118 @@ Plugin Name: Google XML Sitemap for Images
|
|
4 |
Plugin URI: http://www.labnol.org/internet/google-image-sitemap-for-wordpress/14125/
|
5 |
Description: This plugin will generate a XML Image Sitemap for your WordPress blog. Open the <a href="tools.php?page=image-sitemap-generate-page">settings page</a> to create your image sitemap.
|
6 |
Author: Amit Agarwal
|
7 |
-
Version:
|
8 |
Author URI: http://www.labnol.org/
|
9 |
*/
|
10 |
|
11 |
-
add_action
|
12 |
|
13 |
-
function image_sitemap_generate_page
|
14 |
-
|
15 |
-
|
16 |
-
'manage_options', 'image-sitemap-generate-page', 'image_sitemap_generate');
|
17 |
}
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
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 |
function image_sitemap_generate () {
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
if (!$st) {
|
53 |
echo '<br /><div class="error"><h2>Oops!</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>.</p><p>Please ensure that the folder has appropriate <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">write permissions</a>.</p><p> You can either use the chmod command in Unix or use your FTP Manager to change the permission of the folder to 0666 and then try generating the sitemap again.</p><p>If the issue remains unresolved, please post the error message in this <a target="_blank" href="http://wordpress.org/tags/google-image-sitemap?forum_id=10#postform">WordPress forum</a>.</p></div>';
|
54 |
exit();
|
55 |
}
|
56 |
-
|
57 |
?>
|
58 |
|
59 |
<div class="wrap">
|
60 |
-
<
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
</div>
|
63 |
-
<h2>XML Sitemap for Images</h2>
|
64 |
-
<?php $sitemapurl = get_bloginfo('url') . "/sitemap-image.xml"; ?>
|
65 |
-
<p>The XML Sitemap was generated successfully. Please open the <a target="_blank" href="<?php echo $sitemapurl; ?>">Sitemap file</a> in your favorite web browser to confirm that there are no errors.</p>
|
66 |
-
<p>You can submit your Image XML Sitemap through <a href="http://www.google.com/webmasters/tools/" target="_blank">Webmaster Tools</a> or you can directly <a target="_blank" href="http://www.google.com/webmasters/sitemaps/ping?sitemap=<?php echo $sitemapurl; ?>">ping Google</a>.</p>
|
67 |
-
<h3>Suggestions?</h3>
|
68 |
-
<p>Please email your suggestions to Amit Agarwal at amit@labnol.org. You can also connect with <a href="http://www.labnol.org/" target="_blank">Digital Inspiration</a> on <a href="http://twitter.com/labnol" target="_blank">Twitter</a> and <a href="http://www.facebook.com/digital.inspiration" target="_blank">Facebook</a>. </p>
|
69 |
<?php } else { ?>
|
70 |
<div class="wrap">
|
|
|
|
|
71 |
<h2>XML Sitemap for Images</h2>
|
72 |
<p>Sitemaps are a way to tell Google and other search engines about web pages, images and video content on your site that they may otherwise not discover. </p>
|
73 |
-
<h3>Create Image Sitemap</h3>
|
74 |
<form id="options_form" method="post" action="">
|
75 |
<div class="submit">
|
76 |
<input type="submit" name="submit" id="sb_submit" value="Generate Image Sitemap" />
|
77 |
</div>
|
78 |
</form>
|
79 |
-
<p>
|
80 |
-
<
|
81 |
-
<p>
|
82 |
-
<p> You can also connect with <a href="http://www.labnol.org/" target="_blank">Digital Inspiration</a> on <a href="http://twitter.com/labnol" target="_blank">Twitter</a> and <a href="http://www.facebook.com/digital.inspiration" target="_blank">Facebook</a>. </p>
|
83 |
</div>
|
84 |
-
<?php
|
85 |
}
|
86 |
|
87 |
function image_sitemap_loop () {
|
88 |
global $wpdb;
|
89 |
|
90 |
-
$posts = $wpdb->get_results ("SELECT id, post_content FROM $wpdb->posts
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
94 |
|
95 |
if (empty ($posts)) {
|
96 |
-
|
97 |
-
|
98 |
} else {
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
}
|
134 |
-
?>
|
4 |
Plugin URI: http://www.labnol.org/internet/google-image-sitemap-for-wordpress/14125/
|
5 |
Description: This plugin will generate a XML Image Sitemap for your WordPress blog. Open the <a href="tools.php?page=image-sitemap-generate-page">settings page</a> to create your image sitemap.
|
6 |
Author: Amit Agarwal
|
7 |
+
Version: 2.0
|
8 |
Author URI: http://www.labnol.org/
|
9 |
*/
|
10 |
|
11 |
+
add_action('admin_menu', 'image_sitemap_generate_page');
|
12 |
|
13 |
+
function image_sitemap_generate_page() {
|
14 |
+
if(function_exists('add_submenu_page')) add_submenu_page('tools.php', __('Image Sitemap'),
|
15 |
+
__('Image Sitemap'), 'manage_options', 'image-sitemap-generate-page', 'image_sitemap_generate');
|
|
|
16 |
}
|
17 |
|
18 |
+
/* @author VJTD3 <http://www.VJTD3.com> */
|
19 |
+
function IsImageSitemapWritable($filename) {
|
20 |
+
if(!is_writable($filename)) {
|
21 |
+
if(!@chmod($filename, 0666)) {
|
22 |
+
$pathtofilename = dirname($filename);
|
23 |
+
if(!is_writable($pathtofilename)) {
|
24 |
+
if(!@chmod($pathtoffilename, 0666)) {
|
25 |
+
return false;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
}
|
29 |
+
}
|
30 |
+
return true;
|
31 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
function image_sitemap_generate () {
|
34 |
+
if ($_POST ['submit']) {
|
35 |
+
$st = image_sitemap_loop ();
|
36 |
+
if (!$st) {
|
|
|
37 |
echo '<br /><div class="error"><h2>Oops!</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>.</p><p>Please ensure that the folder has appropriate <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">write permissions</a>.</p><p> You can either use the chmod command in Unix or use your FTP Manager to change the permission of the folder to 0666 and then try generating the sitemap again.</p><p>If the issue remains unresolved, please post the error message in this <a target="_blank" href="http://wordpress.org/tags/google-image-sitemap?forum_id=10#postform">WordPress forum</a>.</p></div>';
|
38 |
exit();
|
39 |
}
|
|
|
40 |
?>
|
41 |
|
42 |
<div class="wrap">
|
43 |
+
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
|
44 |
+
if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
45 |
+
<div style="width:800px; padding:10px 20px; background-color:#eee; font-size:.95em; font-family:Georgia;margin:20px">
|
46 |
+
<h2>XML Sitemap for Images</h2>
|
47 |
+
<?php $sitemapurl = get_bloginfo('url') . "/sitemap-image.xml"; ?>
|
48 |
+
<p>The <a target="_blank" href="<?php echo $sitemapurl; ?>">XML Sitemap</a> was generated successfully and you can <a target="_blank" href="http://www.google.com/webmasters/sitemaps/ping?sitemap=<?php echo $sitemapurl; ?>">ping Google</a> to inform them about your updated sitemap.</p>
|
49 |
+
<p>This WordPress Plugin is written by <a href="http://www.labnol.org/about/">Amit Agarwal</a> of <a href="http://www.labnol.org/">Digital Inspiration</a>. For feedback or suggestions on improving this plugin, please send me an email at amit@labnol.org</p>
|
50 |
+
<p><a href="https://twitter.com/labnol" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow @labnol</a>
|
51 |
+
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fdigital.inspiration&send=false&layout=button_count&width=300&show_faces=false&action=recommend&colorscheme=light&font=arial&height=24&appId=197498283654348" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:20px;" allowTransparency="true"></iframe>
|
52 |
+
</p>
|
53 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
<?php } else { ?>
|
55 |
<div class="wrap">
|
56 |
+
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
57 |
+
<div style="width:800px; padding:10px 20px; background-color:#eee; font-size:.95em; font-family:Georgia;margin:20px">
|
58 |
<h2>XML Sitemap for Images</h2>
|
59 |
<p>Sitemaps are a way to tell Google and other search engines about web pages, images and video content on your site that they may otherwise not discover. </p>
|
|
|
60 |
<form id="options_form" method="post" action="">
|
61 |
<div class="submit">
|
62 |
<input type="submit" name="submit" id="sb_submit" value="Generate Image Sitemap" />
|
63 |
</div>
|
64 |
</form>
|
65 |
+
<p>Click the button above to generate a Image Sitemap for your website. Once you have created your Sitemap, you should submit it to Google using Webmaster Tools. </p>
|
66 |
+
<p>You may also want to create separate <a href="http://wordpress.org/extend/plugins/xml-sitemaps-for-videos/">Video Sitemap</a> and <a href="http://wordpress.org/extend/plugins/google-mobile-sitemap/">Mobile Sitemap</a> for improving your site's visibility in Google.</p>
|
67 |
+
<p>This WordPress Plugin is written by <a href="http://www.labnol.org/about/">Amit Agarwal</a> of <a href="http://www.labnol.org/">Digital Inspiration</a>. </p>
|
|
|
68 |
</div>
|
69 |
+
<?php }
|
70 |
}
|
71 |
|
72 |
function image_sitemap_loop () {
|
73 |
global $wpdb;
|
74 |
|
75 |
+
$posts = $wpdb->get_results ("SELECT id, post_parent, post_content, guid, post_type FROM $wpdb->posts wposts
|
76 |
+
WHERE ((wposts.post_type = 'post') and (wposts.post_status='publish'))
|
77 |
+
OR ((wposts.post_type = 'page') and (wposts.post_status='publish'))
|
78 |
+
OR ((wposts.post_type = 'attachment') and (wposts.post_status='inherit')
|
79 |
+
and ((wposts.post_mime_type = 'image/jpg') or (wposts.post_mime_type = 'image/gif')
|
80 |
+
or (wposts.post_mime_type = 'image/jpeg') or (wposts.post_mime_type = 'image/png')))
|
81 |
+
");
|
82 |
|
83 |
if (empty ($posts)) {
|
84 |
+
return false;
|
|
|
85 |
} else {
|
86 |
+
$xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
|
87 |
+
$xml .= '<!-- Created by (http://wordpress.org/extend/plugins/google-image-sitemap/) -->'."\n";
|
88 |
+
$xml .= '<!-- Generated-on="'.date("F j, Y, g:i a").'" -->'."\n";
|
89 |
+
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'."\n";
|
90 |
+
|
91 |
+
foreach($posts as $post) {
|
92 |
+
|
93 |
+
if($post->post_type == "attachment") {
|
94 |
+
if($post->post_parent != 0) {
|
95 |
+
$images[$post->post_parent][] = $post->guid;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
else if(preg_match_all("/[\'\"](http:\/\/.[^\'\"]+\.(?:jpe?g|png|gif))[\'\"]/ui", $post->post_content, $matches, PREG_SET_ORDER)) {
|
99 |
+
foreach($matches as $match) {
|
100 |
+
$images[$post->id][] = $match[1];
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
foreach($images as $k => $v) {
|
106 |
+
$permalink = get_permalink($k);
|
107 |
+
$img = "<image:image><image:loc>".implode("</image:loc></image:image><image:image><image:loc>", $v)."</image:loc></image:image>";
|
108 |
+
$xml .= "<url><loc>".$permalink."</loc>".$img."</url>";
|
109 |
+
}
|
110 |
+
$xml .= "\n</urlset>";
|
111 |
+
}
|
112 |
+
|
113 |
+
$image_sitemap_url = $_SERVER["DOCUMENT_ROOT"].'/sitemap-image.xml';
|
114 |
+
if(IsImageSitemapWritable($_SERVER["DOCUMENT_ROOT"]) || IsImageSitemapWritable($image_sitemap_url)) {
|
115 |
+
if(file_put_contents($image_sitemap_url, $xml)) {
|
116 |
+
return true;
|
117 |
+
}
|
118 |
+
}
|
119 |
+
return false;
|
120 |
}
|
121 |
+
?>
|
readme.txt
CHANGED
@@ -2,24 +2,30 @@
|
|
2 |
Contributors: labnol
|
3 |
Tags: xml sitemaps, google sitemaps, bing, images, seo, search engines, sitemap, pictures
|
4 |
Requires at least: 2.9.2
|
5 |
-
Tested up to: 3.
|
6 |
-
Stable tag:
|
7 |
|
8 |
-
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
-
Sitemaps are a way to tell Google, Bing and other search engines about web pages, images and video content on your site that they may otherwise not discover.
|
13 |
|
14 |
-
The Image Sitemap plugin will generate a sitemap for your WordPress blog with all the image URLs that are
|
15 |
|
16 |
-
|
|
|
|
|
17 |
|
18 |
* [Google XML Sitemap for Mobile](http://wordpress.org/extend/plugins/google-mobile-sitemap/)
|
19 |
* [Google XML Sitemap for Videos](http://wordpress.org/extend/plugins/xml-sitemaps-for-videos/)
|
20 |
-
* [Must have WordPress Plug-ins](http://www.labnol.org/software/must-have-wordpress-plugins/14034/) on [Digital Inspiration](http://www.labnol.org/ "Technology Blog")
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
== Installation ==
|
25 |
|
2 |
Contributors: labnol
|
3 |
Tags: xml sitemaps, google sitemaps, bing, images, seo, search engines, sitemap, pictures
|
4 |
Requires at least: 2.9.2
|
5 |
+
Tested up to: 3.4.1
|
6 |
+
Stable tag: 2.0
|
7 |
|
8 |
+
The Image Sitemap plugin will generate an XML Sitemap for Images that exist in your WordPress blog.
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
+
XML Sitemaps are a way to tell Google, Bing and other search engines about web pages, images and video content on your site that they may otherwise not discover.
|
13 |
|
14 |
+
The Image Sitemap plugin will generate a sitemap for your WordPress blog with all the image URLs that are attached to your blog posts and WordPress pages.
|
15 |
|
16 |
+
[New in v2.0] The plugin has been significantly improved and now includes all images including photo galleries, direct embeds and media attachments.
|
17 |
+
|
18 |
+
**Related WordPress plugins:**
|
19 |
|
20 |
* [Google XML Sitemap for Mobile](http://wordpress.org/extend/plugins/google-mobile-sitemap/)
|
21 |
* [Google XML Sitemap for Videos](http://wordpress.org/extend/plugins/xml-sitemaps-for-videos/)
|
|
|
22 |
|
23 |
+
**WordPress Resources:**
|
24 |
+
|
25 |
+
* [Must have WordPress Plug-ins](http://www.labnol.org/software/must-have-wordpress-plugins/14034/)
|
26 |
+
* [Improving WordPress Security](http://www.labnol.org/internet/improve-wordpress-security/24639/)
|
27 |
+
|
28 |
+
The Sitemap plugins are written by [Amit Agarwal](http://www.labnol.org/about/ "Amit Agarwal") of [Digital Inspiration](http://www.labnol.org/ "Tech Blog"). For support, you can leave a comment in the [WordPress forum](http://wordpress.org/support/plugin/google-image-sitemap) or send a tweet to [@labnol](http://twitter.com/labnol).
|
29 |
|
30 |
== Installation ==
|
31 |
|