Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 3c3d4b21c61b57603bd7069db48d5c27f35e1690 Cor van Noorloos committed Jul 29, 2012
Showing with 252 additions and 0 deletions.
  1. +22 −0 .gitattributes
  2. +163 −0 .gitignore
  3. +67 −0 google-sitemap-image.php
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
@@ -0,0 +1,163 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Rr]elease/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.vspscc
+.builds
+*.dotCover
+
+## TODO: If you have NuGet Package Restore enabled, uncomment this
+#packages/
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+*.Cache
+ClientBin
+stylecop.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+
+
+############
+## Windows
+############
+
+# Windows image file caches
+Thumbs.db
+
+# Folder config file
+Desktop.ini
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+# Mac crap
+.DS_Store
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Image XML Sitemap
+ *
+ * @author Cor van Noorloos
+ * @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
+ * @link https://github.com/corvannoorloos/google-sitemap-image
+ *
+ * @wordpress
+ * Plugin Name: Image XML Sitemap
+ * Plugin URI: https://github.com/corvannoorloos/google-sitemap-image
+ * Description: With image search, just as with web search, Google's goal is to provide the best and most relevant search results to our users. Following Google's <a href="http://www.google.com/support/webmasters/bin/answer.py?answer=35769">Webmaster Guidelines</a> and <a href="http://www.google.com/support/webmasters/bin/answer.py?answer=114016">best practices for publishing images</a> can increase the likelihood that your images will be returned in those search results. In addition, you can also use Google's image extensions for Sitemaps to give Google additional information about the images on your site's URLs.
+ * Author: Cor van Noorloos
+ * Version: 0.1.0
+ * Author URI: http://corvannoorloos.com/
+ */
+
+add_action( 'template_redirect', 'google_sitemap_image' );
+/**
+ * Image XML Sitemap
+ *
+ * @since 0.1.0
+ *
+ * @global type $wpdb
+ *
+ * @return type
+ */
+function google_sitemap_image() {
+ if ( ! preg_match( '/sitemap\-image\.xml$/', $_SERVER['REQUEST_URI'] ) ) {
+ return;
+ }
+ global $wpdb;
+ $posts = $wpdb->get_results( "SELECT ID, post_title, post_excerpt, post_content, post_parent
+ FROM $wpdb->posts
+ WHERE post_status = 'publish'
+ AND post_password = ''
+ AND ( post_type = 'post' OR post_type = 'page' OR post_type = 'post_type' )
+ ORDER BY post_type DESC, post_modified DESC
+ LIMIT 1000" );
+ header( 'X-Robots-Tag: noindex, follow', true );
+ header( 'Content-Type: text/xml' );
+ echo '<?xml version="1.0" encoding="' . get_bloginfo( 'charset' ) . '"?>' . "\n";
+ $xml = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n";
+ foreach ( $posts as $post ) {
+ preg_match( '/<img [^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/', $post->post_content, $img );
+ if ( ! array_key_exists( 1, $img ) )
+ continue;
+ $image_url = trim( $img[1] );
+ if ( $image_url ) {
+ $xml .= "<url>\n";
+ $xml .= "\t<loc>" . get_permalink( $post->ID ) . "</loc>\n";
+ $xml .= "\t<image:image>\n";
+ $xml .= "\t\t<image:loc>" . $img[1] . "</image:loc>\n";
+ if ( $post->post_title ) {
+ $xml .= "\t\t<image:title>" . htmlentities( $post->post_title ) . "</image:title>\n";
+ }
+ if ( $post->post_excerpt ) {
+ $xml .= "\t\t<image:caption>" . htmlentities( $post->post_excerpt ) . "</image:caption>\n";
+ }
+ $xml .= "\t</image:image>\n";
+ $xml .= '</url>' . "\n";
+ }
+ }
+ $xml .= '</urlset>';
+ echo ( "$xml" );
+ exit();
+}

0 comments on commit 3c3d4b2

Please sign in to comment.