Advertisement
bennyp

wp-tableofcontents.php

Apr 9th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.62 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: WP Table of Contents
  4. Plugin URI: http://rastider.com/wordpress-table-of-contents-plugin
  5. Description: WP Table of Contents plugin creates a "table of contents" of your post.
  6. Version: 1.1
  7. Author: Ahmet Kaya
  8. Author URI: http://rastider.com/
  9. */
  10.  
  11. /******************SETTINGS*****************/
  12. // If you don't know how to customize options, check this page http://rastider.com/wordpress-table-of-contents-plugin
  13.  
  14. $wp_icindekiler["jquery"] = 0;
  15.  
  16. $wp_icindekiler["jquery_file"] = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js';
  17.  
  18. $wp_icindekiler["show_hide"] = 0;
  19.  
  20. /* END OF THE SETTINGS */
  21.  
  22.  
  23. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('Bu sayfayý görüntüleme yetkiniz yok.'); }
  24. $output = '';
  25.  
  26. function wp_icindekiler_id_ekle( $content ) {
  27.     if ( is_single() ) {
  28.         return preg_replace (
  29.             "/(<h[2-6])([^>]*>)(.*?)(<\/h[2-6]>)/e",
  30.             "'\\1 id=\"'.wp_duzenle('\\3').'\"'.stripslashes('\\2').''.stripslashes('\\3').'\\4'",
  31.             $content
  32.         );
  33.     } else {
  34.         return $content;
  35.     }
  36. }
  37.  
  38. function wp_duzenle ( $content ) {
  39.     return sanitize_title_with_dashes($content);
  40. }
  41.  
  42. function wp_table_of_contents() {
  43.     global $output;
  44.     wp_icindekiler_ ( get_the_content(), 2 );
  45.     if ( $output != '' ) {
  46.         $output = "
  47.             <div class=\"wp_table_of_contents\" id=\"wp_icindekiler\">
  48.             <strong>Contents</strong> [<a class=\"goster_gizle\" onMouseOver=\"style.cursor='pointer'\" title=\"Show contents &amp; hide\"><small>show/hide</small></a>]
  49.             <div class=\"wp_icindekiler_icerik\">$output</div></div>
  50.         ";
  51.     }
  52.     echo $output;
  53. }
  54.  
  55. function wp_icindekiler_icerik ( $content, $tag ) {
  56.     $bicem = '/<'.$tag.'.*>(.*)<\/'.$tag.'>/Us';
  57.     return preg_split ( $bicem, $content );
  58. }
  59.  
  60. function wp_icindekiler_bol( $content, $tag ) {
  61.     if(substr_count($content, $tag)<1) return false;
  62.     $bicem = '/<'.$tag.'.*>(.*)<\/'.$tag.'>/Us';
  63.     preg_match_all($bicem, $content, $cikti);
  64.     return $cikti;
  65. }
  66.  
  67. function wp_icindekiler_( $content, $i ) {
  68.     global $output;
  69.     $x = 1;
  70.     $tag = 'h'.$i;
  71.     $icerik = 'h'.$i.'_icerik';
  72.     $y = $i + 1;
  73.     $sonraki_tag = 'h'.$y;
  74.     $sonraki_icerik = 'h'.$y.'_icerik';
  75.     if ( $wp_icindekiler[$tag] = wp_icindekiler_bol( $content, $tag ) ) {
  76.         $output .= '<ol>';
  77.         foreach ( $wp_icindekiler[$tag]["1"] as $baslik ) {
  78.             $output .= "<li><a href=\"#".wp_duzenle($baslik);
  79.             $baslik = htmlentities(trim(strip_tags($baslik)), ENT_QUOTES, "UTF-8");
  80.             $output .= "\" title=\"$baslik\"><small>$baslik</small></a>\n";
  81.             $wp_icindekiler[$icerik] = wp_icindekiler_icerik($content, $tag);
  82.             wp_icindekiler_($wp_icindekiler[$icerik][$x], $y);
  83.             $output .= '</li>';
  84.             $x++;
  85.         }
  86.         $output .= '</ol>';
  87.     }
  88. }
  89.  
  90. function wp_icindekiler_js() {
  91.     global $wp_icindekiler;
  92.     if( $wp_icindekiler["jquery"] == 1 ) {
  93.         echo '<script src="'.$wp_icindekiler["jquery_file"].'" type="text/javascript"></script>';
  94.     }
  95. ?>
  96. <script type="text/javascript">
  97. $(document).ready(function(){
  98. <?php if( $wp_icindekiler["show_hide"] == 0 ) : ?>
  99. $(".wp_icindekiler_icerik").hide();
  100. <?php endif; ?>
  101. $(".goster_gizle").show();
  102. $('.goster_gizle').click(function(){
  103. $(".wp_icindekiler_icerik").slideToggle();
  104. });
  105. });
  106. </script>
  107. <style type="text/css">
  108.     .wp_table_of_contents { background-color: #f1f2f3; border: 1px solid #ccc; padding: 5px; overflow: auto; float: left; margin: 0 5px 5px 0; }
  109.     .wp_table_of_contents ol { padding: 0 10px; margin-bottom: 2px; }
  110.     .wp_table_of_contents li { margin-bottom: 0px; }
  111.     .wp_icindekiler_icerik { padding: 0 5px; clear:both; width: 100%;
  112.     }
  113. </style>
  114. <?php
  115. }
  116.  
  117. add_filter('the_content', 'wp_icindekiler_id_ekle');
  118. add_filter('wp_head', 'wp_icindekiler_js');
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement