1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
<?php
/**
* This file implements the Texturize plugin for b2evolution
*
* @author WordPress team - http://sourceforge.net/project/memberlist.php?group_id=51422
* b2evo: 1 notice fix.
*
* @package plugins
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
/**
* Includes:
*/
require_once dirname(__FILE__).'/../renderer.class.php';
/**
* @package plugins
*/
class texturize_Rendererplugin extends RendererPlugin
{
var $code = 'b2WPTxrz';
var $name = 'Texturize';
var $priority = 90;
var $apply_when = 'opt-in';
var $apply_to_html = true;
var $apply_to_xml = true;
var $short_desc;
var $long_desc;
/**
* Constructor
*
* {@internal texturize_Rendererplugin::texturize_Rendererplugin(-)}}
*/
function texturize_Rendererplugin()
{
$this->short_desc = 'Smart quotes and more';
$this->long_desc = 'No description available';
}
/**
* Perform rendering
*
* {@internal texturize_Rendererplugin::render(-)}}
*
* @param string content to render (by reference) / rendered content
* @param string Output format, see {@link format_to_output()}
* @return boolean true if we can render something for the required output format
*/
function render( & $content, $format )
{
if( ! parent::render( $content, $format ) )
{ // We cannot render the required format
return false;
}
$output = '';
$textarr = preg_split("/(<.*>)/Us", $content, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
$stop = count($textarr); $next = true; // loop stuff
for ($i = 0; $i < $stop; $i++) {
$curl = $textarr[$i];
if (strlen($curl) && '<' != $curl{0} && $next) { // If it's not a tag
$curl = str_replace('---', '—', $curl);
$curl = str_replace('--', '–', $curl);
$curl = str_replace("...", '…', $curl);
$curl = str_replace('``', '“', $curl);
// This is a hack, look at this more later. It works pretty well though.
$cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round");
$cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round");
$curl = str_replace($cockney, $cockneyreplace, $curl);
$curl = preg_replace("/'s/", '’s', $curl);
$curl = preg_replace("/'(\d\d(?:’|')?s)/", "’$1", $curl);
$curl = preg_replace('/(\s|\A|")\'/', '$1‘', $curl);
$curl = preg_replace('/(\d+)"/', '$1″', $curl);
$curl = preg_replace("/(\d+)'/", '$1′', $curl);
$curl = preg_replace("/(\S)'([^'\s])/", "$1’$2", $curl);
$curl = preg_replace('/(\s|\A)"(?!\s)/', '$1“$2', $curl);
$curl = preg_replace('/"(\s|\Z)/', '”$1', $curl);
$curl = preg_replace("/'([\s.]|\Z)/", '’$1', $curl);
$curl = preg_replace("/\(tm\)/i", '™', $curl);
$curl = preg_replace("/\(c\)/i", '©', $curl);
$curl = preg_replace("/\(r\)/i", '®', $curl);
$curl = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $curl);
$curl = str_replace("''", '”', $curl);
$curl = preg_replace('/(d+)x(\d+)/', "$1×$2", $curl);
} elseif (strstr($curl, '<code') || strstr($curl, '<pre') || strstr($curl, '<kbd' || strstr($curl, '<style') || strstr($curl, '<script'))) {
// strstr is fast
$next = false;
} else {
$next = true;
}
$output .= $curl;
}
$content = $output;
return true;
}
}
// Register the plugin:
$this->register( new texturize_Rendererplugin() );
?>
|