forked from b2evolution/b2evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_texturize.plugin.php
More file actions
155 lines (135 loc) · 4.85 KB
/
_texturize.plugin.php
File metadata and controls
155 lines (135 loc) · 4.85 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?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('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
/**
* @package plugins
*/
class texturize_plugin extends Plugin
{
var $code = 'b2WPTxrz';
var $name = 'Texturize';
var $priority = 90;
var $version = '5.0.0';
var $group = 'rendering';
var $short_desc;
var $long_desc;
var $number_of_installs = 1;
/**
* Init
*/
function PluginInit( & $params )
{
$this->short_desc = T_('Smart quotes + additional typographic replacements.');
$this->long_desc = T_('This renderer will replace standard and double quotes with typographic quotes were appropriate.<br />
It will also perform the following replacements:
<ul>
<li>--- to —</li>
<li>-- to –</li>
<li>... to …</li>
</ul>' );
}
/**
* Define here default collection/blog settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::get_coll_setting_definitions()}.
*/
function get_coll_setting_definitions( & $params )
{
$default_params = array_merge( $params, array(
'default_post_rendering' => 'opt-in',
'default_comment_rendering' => 'stealth',
) );
return parent::get_coll_setting_definitions( $default_params );
}
/**
* Define here default message settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::GetDefaultSettings()}.
*/
function get_msg_setting_definitions( & $params )
{
// set params to allow rendering for messages by default
$default_params = array_merge( $params, array( 'default_msg_rendering' => 'stealth' ) );
return parent::get_msg_setting_definitions( $default_params );
}
/**
* Perform rendering
*
* @param array Associative array of parameters
* 'data': the data (by reference). You probably want to modify this.
* 'format': see {@link format_to_output()}. Only 'htmlbody' and 'entityencoded' will arrive here.
* @return boolean true if we can render something for the required output format
*/
function RenderItemAsHtml( & $params )
{
// texturize all content not in code/pre blocks
$params['data'] = callback_on_non_matching_blocks( $params['data'], '#<(pre|code)[\s\S]+?/\1>#i', array( $this, 'texturize_block' ) );
}
/**
* Texturize content
*
* @param string $content
* @return string texturized content
*/
function texturize_block( $content )
{
$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 $content;
}
/**
* The same as for HTML.
*
* @uses RenderItemAsHtml()
*/
function RenderItemAsXml( & $params )
{
$this->RenderItemAsHtml( $params );
}
}
?>