forked from b2evolution/b2evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_gmcode.plugin.php
More file actions
128 lines (112 loc) · 2.96 KB
/
_gmcode.plugin.php
File metadata and controls
128 lines (112 loc) · 2.96 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
<?php
/**
* This file implements the GMcode plugin for b2evolution
*
* GreyMatter style formatting
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/gnu-gpl-license}
* @copyright (c)2003-2015 by Francois Planque - {@link http://fplanque.com/}
*
* @package plugins
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
/**
* Replaces GreyMatter markup in HTML (not XML).
*
* @todo dh> Do not replace in tags, it matches e.g. the following for italic:
* """<img src="//url" /> [...] http://"""!
*
* @package plugins
*/
class gmcode_plugin extends Plugin
{
var $code = 'b2evGMco';
var $name = 'GM code';
var $priority = 45;
var $group = 'rendering';
var $short_desc;
var $long_desc;
var $version = '5.0.0';
var $number_of_installs = 1;
/**
* GreyMatter formatting search array
*
* @access private
*/
var $search = array(
'# \*\* (.+?) \*\* #x', // **bold**
'# \\\\ (.+?) \\\\ #x', // \\italics\\
'# (?<!:) \x2f\x2f (.+?) \x2f\x2f #x', // //italics// (not preceded by : as in http://)
'# __ (.+?) __ #x', // __underline__
'/ \#\# (.+?) \#\# /x', // ##tt##
'/ %%
( \s*? \n )? # Eat optional blank line after %%%
(.+?)
( \n \s*? )? # Eat optional blank line before %%%
%%
/sx' // %%codeblock%%
);
/**
* HTML replace array
*
* @access private
*/
var $replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<em>$1</em>',
'<span style="text-decoration:underline">$1</span>',
'<tt>$1</tt>',
'<div class="codeblock"><pre><code>$2</code></pre></div>'
);
/**
* Init
*/
function PluginInit( & $params )
{
$this->short_desc = T_('GreyMatter style formatting');
$this->long_desc = T_('**bold** \\\\italics\\\\ //italics// __underline__ ##tt## %%codeblock%%');
}
/**
* Perform rendering
*
* @see Plugin::RenderItemAsHtml()
*/
function RenderItemAsHtml( & $params )
{
$content = & $params['data'];
if( stristr( $content, '<code' ) !== false || stristr( $content, '<pre' ) !== false || strstr( $content, '`' ) !== false )
{ // Call replace_content() on everything outside code/pre:
$content = callback_on_non_matching_blocks( $content,
'~(`|<(code|pre)[^>]*>).*?(\1|</\2>)~is',
array( $this, 'replace_out_tags' ) );
}
else
{ // No code/pre blocks, replace on the whole thing
$content = $this->replace_out_tags( $content );
}
return true;
}
/**
* Replace text outside of html tags
*
* @param string
* @return string
*/
function replace_out_tags( $text )
{
return callback_on_non_matching_blocks( $text, '~<[^>]*>~s', array( $this, 'replace_callback' ) );
}
/**
* Replace callback
*
* @param string
* @return string
*/
function replace_callback( $text )
{
return preg_replace( $this->search, $this->replace, $text );
}
}
?>