bondcemil

Untitled

Aug 28th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.19 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Resimler için Google XML Sitemap
  4. Plugin URI: http://www.yakuphoca.com/
  5. Description: Bu eklenti yazılarınıza eklediğiniz resimleri, NextGen Gallery eklentisi ile oluşturup, yazılarınıza [nggallery id=X] şeklinde eklediğiniz galerilerindeki resimleri kullanarak Resim Sitemap dosyası oluşturur. <a href="tools.php?page=image-sitemap-generate-page">Ayarlar</a>
  6. Author: Yakup Hoca
  7. Version: 1.0
  8. Author URI: http://www.yakuphoca.com/
  9. */
  10.  
  11. add_action('admin_menu', 'yakuphoca_image_sitemap_generate_page');
  12.  
  13. function yakuphoca_image_sitemap_generate_page() {
  14.     if(function_exists('add_submenu_page')) add_submenu_page('tools.php', 'Resimler Sitemap',
  15.         'Resimler Sitemap', 'manage_options', 'image-sitemap-generate-page', 'yakuphoca_image_sitemap_generate');
  16. }
  17.  
  18. /* @author  VJTD3 <http://www.VJTD3.com> */
  19. function yakuphoca_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 yakuphoca_EscapeXMLEntities($xml) {
  34.     return str_replace(array('&', '<', '>', '\'', '"'), array('&amp;', '&lt;', '&gt;', '&apos;', '&quot;'), $xml);
  35. }
  36.  
  37. function yakuphoca_image_sitemap_generate () {
  38.   if ($_POST ['yakuphoca-image-sitemap-submit']) {
  39.     $st = yakuphoca_image_sitemap_loop ();
  40.      if (!$st) {
  41. echo '<br /><div class="error"><h2>Uyarı!</h2><p>Sitemap başarıyla oluşturuldu fakat WordPress sitenizin ana klasörü olan <strong>' . $_SERVER["DOCUMENT_ROOT"] . '</strong> klasörüne kaydedilemedi.</p><p>Lütfen bu klasöre yazma izni veriniz.</p></div>';
  42. exit();
  43. }
  44. ?>
  45.  
  46. <div class="wrap">
  47.   <h2>Resimler için XML Sitemap</h2>
  48.   <?php $sitemapurl = get_bloginfo('url') . "/sitemap-image.xml"; ?>
  49.   <p><a target="_blank" href="<?php echo $sitemapurl; ?>">XML Sitemap</a> dosyası başarıyla oluşturuldu. Haritayı <a target="_blank" href="http://www.google.com/webmasters/sitemaps/ping?sitemap=<?php echo $sitemapurl; ?>">ping Google</a> bağlantısına tıklayarak, Google'a ping'leyebilirsiniz.</p>
  50.   <p>Bu WordPress eklentisi <a href="http://www.labnol.org/about/">Amit Agarwal</a> tarafından yazılmış, <a href="http://www.yakuphoca.com" title="Yakup Hoca - Bilişim Teknolojileri Hayatım">Yakup Hoca</a> tarafından geliştirilmiştir.</p>
  51. </div>
  52. <?php } else { ?>
  53. <div class="wrap">
  54.   <h2>Resimler İçin XML Sitemap</h2>
  55.   <p>Resim Sitemap dosyaları Google ve diğer arama motorlarına web sitesi yazıları ve resimleri hakkında bilgi verir. Bunların daha kolay indekslenmesini sağlar.</p>
  56.   <form id="options_form" method="post" action="">
  57.     <div class="submit">
  58.       <input type="submit" name="yakuphoca-image-sitemap-submit" id="yakuphoca-image-sitemap-submit" value="Resim Sitemap Dosyasını Oluştur" />
  59.     </div>
  60.   </form>
  61.   <p>Sitemap dosyasını oluşturmak için yukarıdaki düğmeye tıklayın. Bir kere oluşturduğunuzda sitemap dosyasını Google'a Webmaster Tools aracını kullanarak ulaştırabilirsiniz.</p>
  62. </div>
  63. <?php }
  64. }
  65.  
  66. function yakuphoca_image_sitemap_loop () {
  67.     global $wpdb;
  68.             $args = array(
  69.                 'posts_per_page'  => -1,
  70.                 'offset'          => 0,
  71.                 'category'        => '',
  72.                 'orderby'         => 'post_date',
  73.                 'order'           => 'DESC',
  74.                 'include'         => '',
  75.                 'exclude'         => '',
  76.                 'meta_key'        => '',
  77.                 'meta_value'      => '',
  78.                 'post_type'       => 'post',
  79.                 'post_mime_type'  => '',
  80.                 'post_parent'     => '',
  81.                 'post_status'     => 'publish',
  82.                 'suppress_filters' => true );
  83.     $posts = get_posts( $args );
  84.  
  85.     if ($posts) {
  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.           $homeurl = home_url();
  91.           foreach($posts as $post) {
  92.             $content = do_shortcode($post->post_content);
  93.             if(preg_match_all("/[\'\"](http:\/\/.[^\'\"]+\.(?:jpe?g|png|gif))[\'\"]/ui",$content , $matches, PREG_SET_ORDER)) {
  94.                    foreach($matches as $match) {
  95.                      if (strpos( $match[1], $homeurl) !== false) $images[$post->ID][] = $match[1];
  96.                    }
  97.                }
  98.          }
  99.          if ($images) {
  100.              foreach($images as $k => $v) {
  101.                 $permalink = get_permalink($k);
  102.                 if ( ! empty ( $permalink ) ) {
  103.                     $img = "\t<image:image><image:loc>".implode("</image:loc></image:image>\n\t<image:image><image:loc>", $v)."</image:loc></image:image>";
  104.                     $xml .= "\n<url><loc>" . yakuphoca_EscapeXMLEntities($permalink) . "</loc>\n" . $img . "\n</url>";
  105.                 }
  106.              }
  107.          }
  108.          $xml .= "\n</urlset>";
  109.        
  110.         $image_sitemap_url = yakuphoca_GetHomePath() .'sitemap-image.xml';
  111.         if(yakuphoca_IsImageSitemapWritable(yakuphoca_GetHomePath()) || yakuphoca_IsImageSitemapWritable($image_sitemap_url)) {
  112.             if(file_put_contents($image_sitemap_url, $xml)) {
  113.                    return true;
  114.             }
  115.         }
  116.         }
  117.    return false;
  118.  }
  119.  
  120. function yakuphoca_GetHomePath() {
  121.  
  122.         $res="";
  123.         //Check if we are in the admin area -> get_home_path() is avaiable
  124.         if(function_exists("get_home_path")) {
  125.             $res = get_home_path();
  126.         } else {
  127.             //get_home_path() is not available, but we can't include the admin
  128.             //libraries because many plugins check for the "check_admin_referer"
  129.             //function to detect if you are on an admin page. So we have to copy
  130.             //the get_home_path function in our own...
  131.             $home = get_option( 'home' );
  132.             if ( $home != '' && $home != get_option( 'url' ) ) {
  133.                 $home_path = parse_url( $home );
  134.                 $home_path = $home_path['path'];
  135.                 $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
  136.                 $home_path = trailingslashit( $root.$home_path );
  137.             } else {
  138.                 $home_path = ABSPATH;
  139.             }
  140.  
  141.             $res = $home_path;
  142.         }
  143.         return $res;
  144.     }
  145. ?>
Advertisement
Add Comment
Please, Sign In to add comment