All pastes #820795 Raw Edit

Zeug

public php v1 · immutable
·published 2007-12-17 19:26 UTC
rendered paste body
<?php/*Plugin Name: nfoPlugin URI: http://blog.coolcode.cn/?p=24Description: display .nfo file content Version: 3.2Author: andot & legendAuthor URI: http://www.coolcode.cn*//*  Copyright 2005  andot & legend  (email : andot@ujn.edu.cn & legendsky@hotmail.com)     This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.     This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.     You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/class NFO {    var $conv_table = array(    /*  0*/ 0x0000, 0x263a, 0x263b, 0x2665, 0x2666,    /*  5*/ 0x2663, 0x2660, 0x2022, 0x25d8, 0x0000,    /* 10*/ 0x0000, 0x2642, 0x2640, 0x0000, 0x266b,    /* 15*/ 0x263c, 0x25ba, 0x25c4, 0x2195, 0x203c,    /* 20*/ 0x00b6, 0x00a7, 0x25ac, 0x21a8, 0x2191,    /* 25*/ 0x2193, 0x2192, 0x2190, 0x221f, 0x2194,    /* 30*/ 0x25b2, 0x25bc, 0x0000, 0x0000, 0x0022,    /* 35*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0027,    /* 40*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 45*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 50*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 55*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 60*/ 0x003c, 0x0000, 0x0000, 0x0000, 0x0000,    /* 65*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 70*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 75*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 80*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 85*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 90*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 95*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /*100*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /*105*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /*110*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /*115*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /*120*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /*125*/ 0x0000, 0x0000, 0x2302, 0x00c7, 0x00fc,    /*130*/ 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5,    /*135*/ 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef,    /*140*/ 0x00ee, 0x00ec, 0x00c4, 0x00c5, 0x00c9,    /*145*/ 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2,    /*150*/ 0x00fb, 0x00f9, 0x00ff, 0x00d6, 0x00dc,    /*155*/ 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,    /*160*/ 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1,    /*165*/ 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310,    /*170*/ 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab,    /*175*/ 0x00bb, 0x2591, 0x2592, 0x2593, 0x2502,    /*180*/ 0x2524, 0x2561, 0x2562, 0x2556, 0x2555,    /*185*/ 0x2563, 0x2551, 0x2557, 0x255d, 0x255c,    /*190*/ 0x255b, 0x2510, 0x2514, 0x2534, 0x252c,    /*195*/ 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,    /*200*/ 0x255a, 0x2554, 0x2569, 0x2566, 0x2560,    /*205*/ 0x2550, 0x256c, 0x2567, 0x2568, 0x2564,    /*210*/ 0x2565, 0x2559, 0x2558, 0x2552, 0x2553,    /*215*/ 0x256b, 0x256a, 0x2518, 0x250c, 0x2588,    /*220*/ 0x2584, 0x258c, 0x2590, 0x2580, 0x03b1,    /*225*/ 0x03b2, 0x0393, 0x03c0, 0x03a3, 0x03c3,    /*230*/ 0x03bc, 0x03c4, 0x03a6, 0x03b8, 0x2126,    /*235*/ 0x03b4, 0x221e, 0x00f8, 0x03b5, 0x2229,    /*240*/ 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320,    /*245*/ 0x2321, 0x00f7, 0x2248, 0x00b0, 0x00b7,    /*250*/ 0x02d9, 0x221a, 0x207f, 0x00b2, 0x25a0,    /*255*/ 0x00a0);    function nfo2html($str) {        $str = str_replace("&", "&#38;", $str);        for ($i = 0; $i < 256; $i++) {            if ($this->conv_table[$i] != 0) {                $str = str_replace(chr($i), "&#".$this->conv_table[$i].";", $str);            }        }        return $str;    }     function add_css() {        echo '<link rel="stylesheet" href="'            . get_settings('siteurl')            . "/wp-content/plugins/nfo/nfo.css\" />\n";    }                    function part_one($content) {        return preg_replace('#(\<nfo\s*src\s*=\s*(\"(.*?)\"|\'(.*?)\')\s*\/\>|\<nfo\>(.*?)\<\/nfo\>)#ise',            '$this->do_nfo(\'\\1\', \'\\3\', \'\\4\', \'\\5\');',            $content);    }    function part_two($content)    {        if (count($this->blocks)) {            $content = str_replace(array_keys($this->blocks), array_values($this->blocks), $content);            $this->blocks = array();        }        return $content;    }    function get_content($url) {        $url_parsed = parse_url($url);        $host = $url_parsed["host"];        if (!isset($url_parsed["port"])) {            $port = 80;        }        else {            $port = $url_parsed["port"];        }        $path = $url_parsed["path"];        if ($url_parsed["query"] != "") $path .= "?" . $url_parsed["query"];        $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";        $fp = fsockopen($host, $port, $errno, $errstr, 30);        fwrite($fp, $out);        $body = false;        $in = "";        while (!feof($fp)) {            $s = fgets($fp, 1024);            if ($body) $in .= $s;            if ($s == "\r\n") $body = true;        }        fclose($fp);        return $in;    }    function do_nfo($content, $url1, $url2, $txt) {        $blockID = $this->getBlockID($content);        if ($url1) {            $this->blocks[$blockID] = $this->get_content($url1);        } else if ($url2) {            $this->blocks[$blockID] = $this->get_content($url2);        } else {            $this->blocks[$blockID] = $txt;        }        $this->blocks[$blockID] = "<pre class=\"nfo\">"            . preg_replace("/(^|\s)(www\.\S+)|(^|\s)((http|ftp|https):\/\/\S+)/is",                " <a href='$2$4'>$2$4</a>",                $this->nfo2html($this->blocks[$blockID]))            . "</pre>";        return $blockID;    }    function getBlockID($content) {        static $num = 0;        // Just do a check to make sure the user        // hasn't (however unlikely) input block replacements        // as legit text        do        {            ++$num;            $blockID = "<p>++NFO_BLOCK_$num++</p>";        }        while(strpos($content, $blockID) !== false);        return $blockID;    }}$nfo = new NFO();// Showingadd_filter('the_content', array(&$nfo, 'part_one'), -100);add_filter('the_content', array(&$nfo, 'part_two'),  500);add_filter('the_excerpt', array(&$nfo, 'part_one'), -100);add_filter('the_excerpt', array(&$nfo, 'part_two'),  500);add_filter('comment_text', array(&$nfo, 'part_one'), -100);add_filter('comment_text', array(&$nfo, 'part_two'),  500);add_action('wp_head', array(&$nfo, 'add_css'));unset($nfo);?>