Google XML Sitemap for Images - Version 1.0.1

Version Description

Download this release

Release Info

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

Code changes from version 1.0 to 1.0.1

Files changed (3) hide show
  1. image-sitemap.php +45 -4
  2. readme.txt +8 -1
  3. screenshot-1.png +0 -0
image-sitemap.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /*
3
  Plugin Name: Google XML Sitemap for Images
4
- Plugin URI: http://www.labnol.org/software/xml-video-sitemaps-for-google/14085/
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: 1.0
8
  Author URI: http://www.labnol.org/
9
  */
10
 
@@ -16,10 +16,44 @@ function image_sitemap_generate_page () {
16
  'manage_options', 'image-sitemap-generate-page', 'image_sitemap_generate');
17
  }
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  function image_sitemap_generate () {
20
 
21
  if ($_POST ['submit']) {
22
- image_sitemap_loop ();
 
 
 
 
 
23
  ?>
24
 
25
  <div class="wrap">
@@ -64,6 +98,8 @@ function image_sitemap_loop () {
64
  } else {
65
 
66
  $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
 
 
67
  $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' . "\n";
68
 
69
  foreach ($posts as $post) {
@@ -88,6 +124,11 @@ function image_sitemap_loop () {
88
  }
89
 
90
  $image_sitemap_url = $_SERVER["DOCUMENT_ROOT"] . '/sitemap-image.xml';
91
- file_put_contents ($image_sitemap_url, $xml);
 
 
 
 
 
92
  }
93
  ?>
1
  <?php
2
  /*
3
  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: 1.0.1
8
  Author URI: http://www.labnol.org/
9
  */
10
 
16
  'manage_options', 'image-sitemap-generate-page', 'image_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 IsImageSitemapWritable($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
  function image_sitemap_generate () {
49
 
50
  if ($_POST ['submit']) {
51
+ $st = image_sitemap_loop ();
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">
98
  } else {
99
 
100
  $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
101
+ $xml .= '<!-- Created by (http://wordpress.org/extend/plugins/google-image-sitemap/) -->' . "\n";
102
+ $xml .= '<!-- Generated-on="' . date("F j, Y, g:i a") .'" -->' . "\n";
103
  $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' . "\n";
104
 
105
  foreach ($posts as $post) {
124
  }
125
 
126
  $image_sitemap_url = $_SERVER["DOCUMENT_ROOT"] . '/sitemap-image.xml';
127
+ if (IsImageSitemapWritable($_SERVER["DOCUMENT_ROOT"]) || IsImageSitemapWritable($image_sitemap_url)) {
128
+ if (file_put_contents ($image_sitemap_url, $xml)) {
129
+ return true;
130
+ }
131
+ }
132
+ return false;
133
  }
134
  ?>
readme.txt CHANGED
@@ -3,7 +3,7 @@ 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.0
6
- Stable tag: 1.0
7
 
8
  This plugin will help you generate Image Sitemaps (XML) for your WordPress blog.
9
 
@@ -41,3 +41,10 @@ Once you have created your Sitemap, you can submit it to Google using Webmaster
41
 
42
  You can find the sitemap-image.xml file in your blog's root folder.
43
 
 
 
 
 
 
 
 
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.0
6
+ Stable tag: 1.0.1
7
 
8
  This plugin will help you generate Image Sitemaps (XML) for your WordPress blog.
9
 
41
 
42
  You can find the sitemap-image.xml file in your blog's root folder.
43
 
44
+ = I am getting Permission Denied like errors =
45
+
46
+ 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.
47
+
48
+ == Screenshots ==
49
+
50
+ 1. Click the button to generate your mobile sitemap.
screenshot-1.png ADDED
Binary file