Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Resimler için Google XML Sitemap
- Plugin URI: http://www.yakuphoca.com/
- 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>
- Author: Yakup Hoca
- Version: 1.0
- Author URI: http://www.yakuphoca.com/
- */
- add_action('admin_menu', 'yakuphoca_image_sitemap_generate_page');
- function yakuphoca_image_sitemap_generate_page() {
- if(function_exists('add_submenu_page')) add_submenu_page('tools.php', 'Resimler Sitemap',
- 'Resimler Sitemap', 'manage_options', 'image-sitemap-generate-page', 'yakuphoca_image_sitemap_generate');
- }
- /* @author VJTD3 <http://www.VJTD3.com> */
- function yakuphoca_IsImageSitemapWritable($filename) {
- if(!is_writable($filename)) {
- if(!@chmod($filename, 0666)) {
- $pathtofilename = dirname($filename);
- if(!is_writable($pathtofilename)) {
- if(!@chmod($pathtoffilename, 0666)) {
- return false;
- }
- }
- }
- }
- return true;
- }
- function yakuphoca_EscapeXMLEntities($xml) {
- return str_replace(array('&', '<', '>', '\'', '"'), array('&', '<', '>', ''', '"'), $xml);
- }
- function yakuphoca_image_sitemap_generate () {
- if ($_POST ['yakuphoca-image-sitemap-submit']) {
- $st = yakuphoca_image_sitemap_loop ();
- if (!$st) {
- 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>';
- exit();
- }
- ?>
- <div class="wrap">
- <h2>Resimler için XML Sitemap</h2>
- <?php $sitemapurl = get_bloginfo('url') . "/sitemap-image.xml"; ?>
- <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>
- <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>
- </div>
- <?php } else { ?>
- <div class="wrap">
- <h2>Resimler İçin XML Sitemap</h2>
- <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>
- <form id="options_form" method="post" action="">
- <div class="submit">
- <input type="submit" name="yakuphoca-image-sitemap-submit" id="yakuphoca-image-sitemap-submit" value="Resim Sitemap Dosyasını Oluştur" />
- </div>
- </form>
- <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>
- </div>
- <?php }
- }
- function yakuphoca_image_sitemap_loop () {
- global $wpdb;
- $args = array(
- 'posts_per_page' => -1,
- 'offset' => 0,
- 'category' => '',
- 'orderby' => 'post_date',
- 'order' => 'DESC',
- 'include' => '',
- 'exclude' => '',
- 'meta_key' => '',
- 'meta_value' => '',
- 'post_type' => 'post',
- 'post_mime_type' => '',
- 'post_parent' => '',
- 'post_status' => 'publish',
- 'suppress_filters' => true );
- $posts = get_posts( $args );
- if ($posts) {
- $xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
- $xml .= '<!-- Created by (http://wordpress.org/extend/plugins/google-image-sitemap/) -->'."\n";
- $xml .= '<!-- Generated-on="'.date("F j, Y, g:i a").'" -->'."\n";
- $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'."\n";
- $homeurl = home_url();
- foreach($posts as $post) {
- $content = do_shortcode($post->post_content);
- if(preg_match_all("/[\'\"](http:\/\/.[^\'\"]+\.(?:jpe?g|png|gif))[\'\"]/ui",$content , $matches, PREG_SET_ORDER)) {
- foreach($matches as $match) {
- if (strpos( $match[1], $homeurl) !== false) $images[$post->ID][] = $match[1];
- }
- }
- }
- if ($images) {
- foreach($images as $k => $v) {
- $permalink = get_permalink($k);
- if ( ! empty ( $permalink ) ) {
- $img = "\t<image:image><image:loc>".implode("</image:loc></image:image>\n\t<image:image><image:loc>", $v)."</image:loc></image:image>";
- $xml .= "\n<url><loc>" . yakuphoca_EscapeXMLEntities($permalink) . "</loc>\n" . $img . "\n</url>";
- }
- }
- }
- $xml .= "\n</urlset>";
- $image_sitemap_url = yakuphoca_GetHomePath() .'sitemap-image.xml';
- if(yakuphoca_IsImageSitemapWritable(yakuphoca_GetHomePath()) || yakuphoca_IsImageSitemapWritable($image_sitemap_url)) {
- if(file_put_contents($image_sitemap_url, $xml)) {
- return true;
- }
- }
- }
- return false;
- }
- function yakuphoca_GetHomePath() {
- $res="";
- //Check if we are in the admin area -> get_home_path() is avaiable
- if(function_exists("get_home_path")) {
- $res = get_home_path();
- } else {
- //get_home_path() is not available, but we can't include the admin
- //libraries because many plugins check for the "check_admin_referer"
- //function to detect if you are on an admin page. So we have to copy
- //the get_home_path function in our own...
- $home = get_option( 'home' );
- if ( $home != '' && $home != get_option( 'url' ) ) {
- $home_path = parse_url( $home );
- $home_path = $home_path['path'];
- $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
- $home_path = trailingslashit( $root.$home_path );
- } else {
- $home_path = ABSPATH;
- }
- $res = $home_path;
- }
- return $res;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment