Archive for 8月 15th, 2004

Blogtimes

星期日, 8月 15th, 2004

使用方法:将代码复制保存为:blogtimes.php放入plugins文件夹,active。在适当位置插入

HTML:
  1. <p align="center"><img src="http://antonioz.com/wp-images/blogtimes.png" alt="Blogtimes image" /></p>

图片可以从我这copy。:-)

PHP:
  1. <?php
  2.  
  3. /*
  4. Plugin Name: Blogtimes
  5. Plugin URI:
  6. Description: To generate a bar graph image showing when posts are made during a period of time. For this to work <code>wp-images/blogtimes.png must be writable by the web server. Original code by Sanjay Sheth of sastools.com.
  7. Author: Matt Mullenweg
  8. Author URI: http://photomatt.net
  9. Version: 0.1
  10. */
  11.  
  12.  
  13. // Main function to invoke to generate the bar graph pass it the width/height/padding/title that you want
  14. function updateBlogTimePNG($dummy = 'placeholder', $saveFile = '', $last_x_days = 30,
  15.                            $width = 480,$height = 65,$horzpadding = 5,$vertpadding = 5,
  16.                            $show_ticks = 1,
  17.                            $title = "Blog Post Times")
  18. {
  19.     if (!$saveFile) $saveFile = ABSPATH . 'wp-images/blogtimes.png';
  20.     // constants defining image
  21.     $fontheight = ImageFontHeight(2);
  22.     $fontwidth  = ImageFontWidth(2);
  23.     $monthtext = "Last $last_x_days days";
  24.     $unitname = "hour of day";
  25.     $show_units = 1;
  26.  
  27.     // create the basic image
  28.     $im = @ImageCreate ($width, $height)
  29.        or die ('Cannot create a new GD image.');
  30.  
  31.     // generate some colors, format: RED, GREEN, BLUE
  32.     $white      = ImageColorAllocate ($im, 255,255,255);
  33.     $black      = ImageColorAllocate ($im, 0,0,0);
  34.     $beige      = ImageColorAllocate ($im, 238,238,238);
  35.     $blue       = ImageColorAllocate ($im, 102,102,102);
  36.     $silver     = ImageColorAllocate ($im, 0xE0,0xE0,0xE0);
  37.  
  38.     // define what color to use where
  39.     $back_color = $white;    # this is background of entire image (text & all)
  40.     $box_color  = $beige;    # this is background of just the posts box
  41.     $text_color = $black;
  42.     $line_color = $blue;     # this is color of lines for each post
  43.     $border_color = $black;
  44.  
  45.     # query the db and build the list
  46.     $posttimes = getPostTimes(30);
  47.  
  48.     # calculate how many intervals to show
  49.     $intervals = floor( ($width / 40) );
  50.     if ($intervals>= 24) $i_mod = 1;
  51.     else if ($intervals>= 12) $i_mod = 2;
  52.     else if ($intervals>= 8) $i_mod = 3;
  53.     else if ($intervals>= 6) $i_mod = 4;
  54.     else if ($intervals>= 4) $i_mod = 6;
  55.     else if ($intervals>= 3) $i_mod = 8;
  56.     else if ($intervals>= 2) $i_mod = 16;
  57.     else $i_mod = 24;
  58.  
  59.     # fill the image with the background color
  60.     ImageFill($im, 0, 0, $back_color);
  61.  
  62.     # create a filled  rectangle with a solid border
  63.     $left = $horzpadding; $right = $width - $horzpadding;
  64.     $top = $fontheight + $vertpadding;
  65.     $bottom = $height - $vertpadding - $fontheight;
  66.  
  67.     if ($show_units)
  68.         $bottom -= $fontheight;
  69.  
  70.     ImageFilledRectangle($im, $left,$top,$right,$bottom, $box_color);
  71.     ImageRectangle($im, $left,$top,$right,$bottom, $border_color);
  72.  
  73.     # write title and monthtext
  74.     ImageString($im, 2, $left, 0, $title,$text_color);
  75.     $txtwidth = strlen($monthtext) * $fontwidth;
  76.     ImageString($im, 2, $right - $txtwidth, 0,$monthtext,$text_color);
  77.  
  78.     # add the legend on the bottom
  79.     for ($i = 0; $i <= 23; $i=$i+1)
  80.     {
  81.         if ($i % $i_mod == 0) {
  82.             $curX = $left + ($right - $left)/24 * $i;
  83.  
  84.             if ($i> 9) {$strX = $curX - 5;}
  85.             else        {$strX = $curX - 2;}
  86.  
  87.             ImageString($im, 2, $strX , $bottom, $i, $text_color);
  88.             if ($show_ticks)
  89.                 ImageLine($im, $curX, $bottom, $curX, $bottom - 5, $tick_color);
  90.         }
  91.     }
  92.     ImageString($im, 2, $right - 5, $bottom0, $text_color);
  93.     if ($show_units) {
  94.         $curX = ($right + $left) / 2 - ($fontwidth * strlen($unitname)/2);
  95.         $curY = $bottom + $fontheight + 2;
  96.         ImageString($im, 2, $curX, $curY, $unitname, $text_color);
  97.     }
  98.  
  99.     # now we draw the lines for each post
  100.     # the post times should be in terms of # of minutes since midnight
  101.     $arrcount = count($posttimes);
  102.     for ($i = 0; $i <$arrcount; $i++)
  103.     {
  104.         # make sure postTime is between 0 and 1439
  105.         $curPostTime = abs($posttimes[$i]) % 1440;
  106.        
  107.         # calculate the horz pos inside box             
  108.         $curX = $left + ($right - $left)/1440 * $curPostTime;    # 1440 minutes per day
  109.  
  110.         # draw the post line
  111.         ImageLine($im, $curX, $bottom, $curX, $top, $line_color);
  112.     }
  113.  
  114.     # save the file to disk in PNG format
  115.     ImagePNG ($im,$saveFile);
  116. }
  117.  
  118. # This function will query the db for all the posts in last x days
  119. # and build an array of # of minutes since midnight for each post
  120. function getPostTimes($last_x_days=30)
  121. {
  122. global $wpdb, $tableposts;
  123.  
  124.     $result = $wpdb->get_results("
  125.             SELECT HOUR(post_date)*60+MINUTE(post_date) AS totmins
  126.             FROM $tableposts
  127.             WHERE (TO_DAYS(CURRENT_DATE) - TO_DAYS(post_date)) <= $last_x_days
  128.             AND post_status = 'publish'
  129.             ORDER BY totmins ASC
  130.             ");
  131.  
  132.     foreach ($result as $row) {
  133.       $postTimes[] = $row->totmins;
  134.     }
  135.    
  136.     return $postTimes;
  137. }
  138.  
  139.  
  140. add_action('publish_post', 'updateBlogTimePNG');
  141. ?>

首页的分页-Page Navigation

星期日, 8月 15th, 2004

原下载地址:http://www.lesterchan.net/portfolio/programming.php

修正了程序里的一点小错误。
使用方法:将文件保存为:page-navi.php上传至plugins目录,active。
在index.php的适当位置加入:

PHP:
  1. <?php page_navigation(); ?>

PHP:
  1. <?php
  2. /*
  3. Plugin Name: Page Navigation
  4. Plugin URI: http://www.lesterchan.net/portfolio/programming.php
  5. Description: Adds A Page Navigation To Your WordPress. Please Make Sure Post Paged Is Turned On.
  6. Version: 1.2
  7. Author: GaMerZ
  8. Author URI: http://www.lesterchan.net
  9. */
  10.  
  11. function page_navigation($before='', $after='', $prelabel='&laquo;', $nxtlabel='&gt;') {
  12.     global $p, $what_to_show, $request, $posts_per_page, $wpdb;
  13.     global $HTTP_SERVER_VARS, $paged;
  14.     global $querystring_start, $querystring_equal, $querystring_separator;
  15.     if (empty($p) && ($what_to_show == 'paged')) {
  16.         $nxt_request = $request;
  17.         $whichpage = $_GET['paged'];
  18.         if(empty($whichpage))  $whichpage = 1;
  19.         $qstr = $HTTP_SERVER_VARS['QUERY_STRING'];
  20.         if (!empty($qstr)) {
  21.             $qstr = preg_replace("/&paged=d{0,}/","",$qstr);
  22.             $qstr = preg_replace("/paged=d{0,}/","",$qstr);
  23.          } elseif (stristr($HTTP_SERVER_VARS['REQUEST_URI'], $HTTP_SERVER_VARS['SCRIPT_NAME'] )) {
  24.             if ('' != $qstr = str_replace($HTTP_SERVER_VARS['SCRIPT_NAME'], '', $HTTP_SERVER_VARS['REQUEST_URI']) ) {
  25.                 $qstr = preg_replace("/^//", "", $qstr);
  26.                 $qstr = preg_replace("/paged/d{0,}//", "", $qstr);   
  27.                 $qstr = preg_replace("/paged/d{0,}/", "", $qstr);
  28.                 $qstr = preg_replace("//$/", "", $qstr);
  29.             }
  30.         }
  31.         if ($pos = strpos(strtoupper($request), 'LIMIT')) {
  32.             $nxt_request = substr($request, 0, $pos);
  33.         }
  34.         $nxt_result = $wpdb->query($nxt_request);
  35.         $numposts = $wpdb->num_rows;
  36.         $max_page = ceil($numposts / $posts_per_page) ;
  37.  
  38.         echo $before.'Pages ('.$max_page.') : <b>';
  39.         if ($whichpage>= 4)
  40.             echo '<a href="'.get_settings('siteurl').'/'.get_settings('blogfilename').$querystring_start.($qstr == '' ? '' : $qstr.$querystring_separator) .'paged'.$querystring_equal.'1">?First</a> ... ';
  41.         previous_posts_link($prelabel);
  42.         for($i = $whichpage - 2 ; $i  <= $whichpage +2; $i++) {
  43.             if ($i>= 1 && $i <= $max_page) {
  44.                 if($i == $whichpage)
  45.                     echo '['.$i.'] ';
  46.                 else
  47.                     echo '<a href="'.get_settings('siteurl').'/'.get_settings('blogfilename').$querystring_start.($qstr == '' ? '' : $qstr.$querystring_separator) .'paged'.$querystring_equal.$i.'">'.$i.' ';
  48.             }
  49.         }
  50.         next_posts_link($nxtlabel, $max_page);
  51.         if (($whichpage+2) <($max_page))
  52.             echo ' ... <a href="'.get_settings('siteurl').'/'.get_settings('blogfilename').$querystring_start.($qstr == '' ? '' : $qstr.$querystring_separator) .'paged'.$querystring_equal.$max_page.'">Last &raquo ';
  53.         echo '</b>'.$after;
  54.     }
  55. }
  56. ?>

自动连接-AutoLinker

星期日, 8月 15th, 2004

http://www.huddledmasses.org/ 制作发布。

使用:

CODE:
  1. if( empty($autolinker_array) ) { 
  2.       $autolinker_array = array(

下照模式添加需要加自动连接的地址。

PHP:
  1. <?php 
  2. /*
  3. Plugin Name: AutoLinker 
  4. Version: 1.3 
  5. Plugin URI: http://www.huddledmasses.org/ 
  6. Description: Makes links from predefined text 
  7. Author: Joel Bennett 
  8. Author URI: http://www.HuddledMasses.org 
  9. Copyright (c) 2003 
  10. Released under the GPL license 
  11. http://www.gnu.org/licenses/gpl.txt 
  12.     This file is part of WordPress. 
  13.     WordPress is free software; you can redistribute it and/or modify 
  14.     it under the terms of the GNU General Public License as published by 
  15.     the Free Software Foundation; either version 2 of the License, or 
  16.     (at your option) any later version. 
  17.     This program is distributed in the hope that it will be useful, 
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of 
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  20.     GNU General Public License for more details. 
  21.     You should have received a copy of the GNU General Public License 
  22.     along with this program; if not, write to the Free Software 
  23.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  24. */ 
  25.  
  26.  
  27.  
  28.  
  29.  
  30. function autolinker($text) { 
  31.    // First, we define all the things we're going to replace: 
  32.    // and we name it weird so nobody will mistakenly use it 
  33.    // each definition is in the form: // "text" => "url", 
  34.    // ESPECIALLY note that they all end with commas EXCEPT the last one 
  35.    global $autolinker_array
  36.  
  37.    if( empty($autolinker_array) ) { 
  38.       $autolinker_array = array( 
  39.          "my site" => "http://www.antonio.hostonnet.com/"
  40.          "Geo Docs" => "http://docs.GeoShell.org/"
  41.          "GeoShell" => "http://www.GeoShell.org/"
  42.          "W3C" => "http://www.w3.org",
  43.           "google" => "http://www.google.com",
  44.         "sohu" => "http://www.sohu.com",
  45.       )
  46.  
  47.    } 
  48.  
  49.    $text = " $text "
  50.    foreach($autolinker_array as $match => $url) { 
  51.    /*    For advanced users, there are several possible regular expressions here.... 
  52.    *    The safest, "default" one is at the top ... 
  53.    *    You (or I) may choose to use one of the others! 
  54.    *    Pick whichever you want, and make SURE there is only one that isn't preceded by slashes: // 
  55.    */ 
  56.    // DEFAULT 
  57.  
  58.  $text = preg_replace("|([^./]b)$match(b[^:])|msU" , "$1<a href="$url">$match</a>$2" , $text)
  59.  $text = preg_replace("|(<[A-Za-z]* [^>]*)<a href="$url">$match</a>([^<]*>)|msU" , "$1$match$2" , $text)
  60.  
  61.    // SAFER ALTERNATIVE: requires square brackets which will be stripped off matched text 
  62.  
  63.    // SAFER ALTERNATIVE: [GeoShell] would become <a href="http://www.geoshell.org/">GeoShell</a> 
  64.  
  65.    //    $text = preg_replace("|[$match]|msU" , "<a href="$url">$match</a>" , $text); 
  66.  
  67.    } 
  68.  
  69. return trim($text)
  70.  
  71. }
  72.  
  73. add_filter('the_content', 'autolinker', 7)
  74.  
  75. add_filter('comment_text', 'autolinker', 7)
  76.  
  77. ?>