Version Description
Download this release
Release Info
Developer | smashballoon |
Plugin | Custom Facebook Feed |
Version | 1.8.2.2 |
Comparing to | |
See all releases |
Code changes from version 1.8.2.1 to 1.8.2.2
- cff_autolink.php +0 -339
- custom-facebook-feed.php +324 -2
cff_autolink.php
DELETED
@@ -1,339 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
#
|
3 |
-
# A PHP auto-linking library
|
4 |
-
#
|
5 |
-
# https://github.com/iamcal/lib_autolink
|
6 |
-
#
|
7 |
-
# By Cal Henderson <cal@iamcal.com>
|
8 |
-
# This code is licensed under the MIT license
|
9 |
-
#
|
10 |
-
|
11 |
-
####################################################################
|
12 |
-
|
13 |
-
#
|
14 |
-
# These are global options. You can set them before calling the autolinking
|
15 |
-
# functions to change the output.
|
16 |
-
#
|
17 |
-
|
18 |
-
$GLOBALS['autolink_options'] = array(
|
19 |
-
|
20 |
-
# Should http:// be visibly stripped from the front
|
21 |
-
# of URLs?
|
22 |
-
'strip_protocols' => true,
|
23 |
-
|
24 |
-
);
|
25 |
-
|
26 |
-
####################################################################
|
27 |
-
|
28 |
-
function cff_autolink($text, $span_tag = false, $limit=100, $tagfill='class="cff-break-word"', $auto_title = true){
|
29 |
-
|
30 |
-
$text = cff_autolink_do($text, '![a-z][a-z-]+://!i', $limit, $tagfill, $auto_title, $span_tag);
|
31 |
-
$text = cff_autolink_do($text, '!(mailto|skype):!i', $limit, $tagfill, $auto_title, $span_tag);
|
32 |
-
$text = cff_autolink_do($text, '!www\\.!i', $limit, $tagfill, $auto_title, 'http://', $span_tag);
|
33 |
-
return $text;
|
34 |
-
}
|
35 |
-
|
36 |
-
####################################################################
|
37 |
-
|
38 |
-
function cff_autolink_do($text, $sub, $limit, $tagfill, $auto_title, $span_tag, $force_prefix=null){
|
39 |
-
|
40 |
-
$text_l = StrToLower($text);
|
41 |
-
$cursor = 0;
|
42 |
-
$loop = 1;
|
43 |
-
$buffer = '';
|
44 |
-
|
45 |
-
while (($cursor < strlen($text)) && $loop){
|
46 |
-
|
47 |
-
$ok = 1;
|
48 |
-
$matched = preg_match($sub, $text_l, $m, PREG_OFFSET_CAPTURE, $cursor);
|
49 |
-
|
50 |
-
if (!$matched){
|
51 |
-
|
52 |
-
$loop = 0;
|
53 |
-
$ok = 0;
|
54 |
-
|
55 |
-
}else{
|
56 |
-
|
57 |
-
$pos = $m[0][1];
|
58 |
-
$sub_len = strlen($m[0][0]);
|
59 |
-
|
60 |
-
$pre_hit = substr($text, $cursor, $pos-$cursor);
|
61 |
-
$hit = substr($text, $pos, $sub_len);
|
62 |
-
$pre = substr($text, 0, $pos);
|
63 |
-
$post = substr($text, $pos + $sub_len);
|
64 |
-
|
65 |
-
$fail_text = $pre_hit.$hit;
|
66 |
-
$fail_len = strlen($fail_text);
|
67 |
-
|
68 |
-
#
|
69 |
-
# substring found - first check to see if we're inside a link tag already...
|
70 |
-
#
|
71 |
-
|
72 |
-
$bits = preg_split("!</a>!i", $pre);
|
73 |
-
$last_bit = array_pop($bits);
|
74 |
-
if (preg_match("!<a\s!i", $last_bit)){
|
75 |
-
|
76 |
-
#echo "fail 1 at $cursor<br />\n";
|
77 |
-
|
78 |
-
$ok = 0;
|
79 |
-
$cursor += $fail_len;
|
80 |
-
$buffer .= $fail_text;
|
81 |
-
}
|
82 |
-
}
|
83 |
-
|
84 |
-
#
|
85 |
-
# looks like a nice spot to autolink from - check the pre
|
86 |
-
# to see if there was whitespace before this match
|
87 |
-
#
|
88 |
-
|
89 |
-
if ($ok){
|
90 |
-
|
91 |
-
if ($pre){
|
92 |
-
if (!preg_match('![\s\(\[\{>]$!s', $pre)){
|
93 |
-
|
94 |
-
#echo "fail 2 at $cursor ($pre)<br />\n";
|
95 |
-
|
96 |
-
$ok = 0;
|
97 |
-
$cursor += $fail_len;
|
98 |
-
$buffer .= $fail_text;
|
99 |
-
}
|
100 |
-
}
|
101 |
-
}
|
102 |
-
|
103 |
-
#
|
104 |
-
# we want to autolink here - find the extent of the url
|
105 |
-
#
|
106 |
-
|
107 |
-
if ($ok){
|
108 |
-
if (preg_match('/^([a-z0-9\-\.\/\-_%~!?=,:;&+*#@\(\)\$]+)/i', $post, $matches)){
|
109 |
-
|
110 |
-
$url = $hit.$matches[1];
|
111 |
-
|
112 |
-
$cursor += strlen($url) + strlen($pre_hit);
|
113 |
-
$buffer .= $pre_hit;
|
114 |
-
|
115 |
-
$url = html_entity_decode($url);
|
116 |
-
|
117 |
-
|
118 |
-
#
|
119 |
-
# remove trailing punctuation from url
|
120 |
-
#
|
121 |
-
|
122 |
-
while (preg_match('|[.,!;:?]$|', $url)){
|
123 |
-
$url = substr($url, 0, strlen($url)-1);
|
124 |
-
$cursor--;
|
125 |
-
}
|
126 |
-
foreach (array('()', '[]', '{}') as $pair){
|
127 |
-
$o = substr($pair, 0, 1);
|
128 |
-
$c = substr($pair, 1, 1);
|
129 |
-
if (preg_match("!^(\\$c|^)[^\\$o]+\\$c$!", $url)){
|
130 |
-
$url = substr($url, 0, strlen($url)-1);
|
131 |
-
$cursor--;
|
132 |
-
}
|
133 |
-
}
|
134 |
-
|
135 |
-
|
136 |
-
#
|
137 |
-
# nice-i-fy url here
|
138 |
-
#
|
139 |
-
|
140 |
-
$link_url = $url;
|
141 |
-
$display_url = $url;
|
142 |
-
|
143 |
-
if ($force_prefix) $link_url = $force_prefix.$link_url;
|
144 |
-
|
145 |
-
if ($GLOBALS['autolink_options']['strip_protocols']){
|
146 |
-
if (preg_match('!^(http|https)://!i', $display_url, $m)){
|
147 |
-
|
148 |
-
$display_url = substr($display_url, strlen($m[1])+3);
|
149 |
-
}
|
150 |
-
}
|
151 |
-
|
152 |
-
$display_url = cff_autolink_label($display_url, $limit);
|
153 |
-
|
154 |
-
|
155 |
-
#
|
156 |
-
# add the url
|
157 |
-
#
|
158 |
-
|
159 |
-
if ($display_url != $link_url && !preg_match('@title=@msi',$tagfill) && $auto_title) {
|
160 |
-
|
161 |
-
$display_quoted = preg_quote($display_url, '!');
|
162 |
-
|
163 |
-
if (!preg_match("!^(http|https)://{$display_quoted}$!i", $link_url)){
|
164 |
-
|
165 |
-
$tagfill .= ' title="'.$link_url.'"';
|
166 |
-
}
|
167 |
-
}
|
168 |
-
|
169 |
-
$link_url_enc = HtmlSpecialChars($link_url);
|
170 |
-
$display_url_enc = HtmlSpecialChars($display_url);
|
171 |
-
|
172 |
-
if($span_tag == true){
|
173 |
-
$buffer .= "<span $tagfill>{$display_url_enc}</span>";
|
174 |
-
} else {
|
175 |
-
$buffer .= "<a target='_blank' href=\"{$link_url_enc}\"$tagfill>{$display_url_enc}</a>";
|
176 |
-
}
|
177 |
-
|
178 |
-
|
179 |
-
}else{
|
180 |
-
#echo "fail 3 at $cursor<br />\n";
|
181 |
-
|
182 |
-
$ok = 0;
|
183 |
-
$cursor += $fail_len;
|
184 |
-
$buffer .= $fail_text;
|
185 |
-
}
|
186 |
-
}
|
187 |
-
|
188 |
-
}
|
189 |
-
|
190 |
-
#
|
191 |
-
# add everything from the cursor to the end onto the buffer.
|
192 |
-
#
|
193 |
-
|
194 |
-
$buffer .= substr($text, $cursor);
|
195 |
-
|
196 |
-
return $buffer;
|
197 |
-
}
|
198 |
-
|
199 |
-
####################################################################
|
200 |
-
|
201 |
-
function cff_autolink_label($text, $limit){
|
202 |
-
|
203 |
-
if (!$limit){ return $text; }
|
204 |
-
|
205 |
-
if (strlen($text) > $limit){
|
206 |
-
return substr($text, 0, $limit-3).'...';
|
207 |
-
}
|
208 |
-
|
209 |
-
return $text;
|
210 |
-
}
|
211 |
-
|
212 |
-
####################################################################
|
213 |
-
|
214 |
-
function cff_autolink_email($text, $tagfill=''){
|
215 |
-
|
216 |
-
$atom = '[^()<>@,;:\\\\".\\[\\]\\x00-\\x20\\x7f]+'; # from RFC822
|
217 |
-
|
218 |
-
#die($atom);
|
219 |
-
|
220 |
-
$text_l = StrToLower($text);
|
221 |
-
$cursor = 0;
|
222 |
-
$loop = 1;
|
223 |
-
$buffer = '';
|
224 |
-
|
225 |
-
while(($cursor < strlen($text)) && $loop){
|
226 |
-
|
227 |
-
#
|
228 |
-
# find an '@' symbol
|
229 |
-
#
|
230 |
-
|
231 |
-
$ok = 1;
|
232 |
-
$pos = strpos($text_l, '@', $cursor);
|
233 |
-
|
234 |
-
if ($pos === false){
|
235 |
-
|
236 |
-
$loop = 0;
|
237 |
-
$ok = 0;
|
238 |
-
|
239 |
-
}else{
|
240 |
-
|
241 |
-
$pre = substr($text, $cursor, $pos-$cursor);
|
242 |
-
$hit = substr($text, $pos, 1);
|
243 |
-
$post = substr($text, $pos + 1);
|
244 |
-
|
245 |
-
$fail_text = $pre.$hit;
|
246 |
-
$fail_len = strlen($fail_text);
|
247 |
-
|
248 |
-
#die("$pre::$hit::$post::$fail_text");
|
249 |
-
|
250 |
-
#
|
251 |
-
# substring found - first check to see if we're inside a link tag already...
|
252 |
-
#
|
253 |
-
|
254 |
-
$bits = preg_split("!</a>!i", $pre);
|
255 |
-
$last_bit = array_pop($bits);
|
256 |
-
if (preg_match("!<a\s!i", $last_bit)){
|
257 |
-
|
258 |
-
#echo "fail 1 at $cursor<br />\n";
|
259 |
-
|
260 |
-
$ok = 0;
|
261 |
-
$cursor += $fail_len;
|
262 |
-
$buffer .= $fail_text;
|
263 |
-
}
|
264 |
-
}
|
265 |
-
|
266 |
-
#
|
267 |
-
# check backwards
|
268 |
-
#
|
269 |
-
|
270 |
-
if ($ok){
|
271 |
-
if (preg_match("!($atom(\.$atom)*)\$!", $pre, $matches)){
|
272 |
-
|
273 |
-
# move matched part of address into $hit
|
274 |
-
|
275 |
-
$len = strlen($matches[1]);
|
276 |
-
$plen = strlen($pre);
|
277 |
-
|
278 |
-
$hit = substr($pre, $plen-$len).$hit;
|
279 |
-
$pre = substr($pre, 0, $plen-$len);
|
280 |
-
|
281 |
-
}else{
|
282 |
-
|
283 |
-
#echo "fail 2 at $cursor ($pre)<br />\n";
|
284 |
-
|
285 |
-
$ok = 0;
|
286 |
-
$cursor += $fail_len;
|
287 |
-
$buffer .= $fail_text;
|
288 |
-
}
|
289 |
-
}
|
290 |
-
|
291 |
-
#
|
292 |
-
# check forwards
|
293 |
-
#
|
294 |
-
|
295 |
-
if ($ok){
|
296 |
-
if (preg_match("!^($atom(\.$atom)*)!", $post, $matches)){
|
297 |
-
|
298 |
-
# move matched part of address into $hit
|
299 |
-
|
300 |
-
$len = strlen($matches[1]);
|
301 |
-
|
302 |
-
$hit .= substr($post, 0, $len);
|
303 |
-
$post = substr($post, $len);
|
304 |
-
|
305 |
-
}else{
|
306 |
-
#echo "fail 3 at $cursor ($post)<br />\n";
|
307 |
-
|
308 |
-
$ok = 0;
|
309 |
-
$cursor += $fail_len;
|
310 |
-
$buffer .= $fail_text;
|
311 |
-
}
|
312 |
-
}
|
313 |
-
|
314 |
-
#
|
315 |
-
# commit
|
316 |
-
#
|
317 |
-
|
318 |
-
if ($ok) {
|
319 |
-
|
320 |
-
$cursor += strlen($pre) + strlen($hit);
|
321 |
-
$buffer .= $pre;
|
322 |
-
$buffer .= "<a href=\"mailto:$hit\"$tagfill>$hit</a>";
|
323 |
-
|
324 |
-
}
|
325 |
-
|
326 |
-
}
|
327 |
-
|
328 |
-
#
|
329 |
-
# add everything from the cursor to the end onto the buffer.
|
330 |
-
#
|
331 |
-
|
332 |
-
$buffer .= substr($text, $cursor);
|
333 |
-
|
334 |
-
return $buffer;
|
335 |
-
}
|
336 |
-
|
337 |
-
####################################################################
|
338 |
-
|
339 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
custom-facebook-feed.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Custom Facebook Feed
|
4 |
Plugin URI: http://smashballoon.com/custom-facebook-feed
|
5 |
Description: Add a completely customizable Facebook feed to your WordPress site
|
6 |
-
Version: 1.8.2.
|
7 |
Author: Smash Balloon
|
8 |
Author URI: http://smashballoon.com/
|
9 |
License: GPLv2 or later
|
@@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
24 |
*/
|
25 |
//Include admin
|
26 |
include dirname( __FILE__ ) .'/custom-facebook-feed-admin.php';
|
27 |
-
include dirname( __FILE__ ) .'/cff_autolink.php';
|
28 |
|
29 |
// Add shortcodes
|
30 |
add_shortcode('custom-facebook-feed', 'display_cff');
|
@@ -1433,6 +1432,329 @@ function cff_js() {
|
|
1433 |
if( !empty($cff_custom_js) ) echo "\r\n";
|
1434 |
}
|
1435 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1436 |
//Comment out the line below to view errors
|
1437 |
error_reporting(0);
|
1438 |
?>
|
3 |
Plugin Name: Custom Facebook Feed
|
4 |
Plugin URI: http://smashballoon.com/custom-facebook-feed
|
5 |
Description: Add a completely customizable Facebook feed to your WordPress site
|
6 |
+
Version: 1.8.2.2
|
7 |
Author: Smash Balloon
|
8 |
Author URI: http://smashballoon.com/
|
9 |
License: GPLv2 or later
|
24 |
*/
|
25 |
//Include admin
|
26 |
include dirname( __FILE__ ) .'/custom-facebook-feed-admin.php';
|
|
|
27 |
|
28 |
// Add shortcodes
|
29 |
add_shortcode('custom-facebook-feed', 'display_cff');
|
1432 |
if( !empty($cff_custom_js) ) echo "\r\n";
|
1433 |
}
|
1434 |
|
1435 |
+
|
1436 |
+
$GLOBALS['autolink_options'] = array(
|
1437 |
+
|
1438 |
+
# Should http:// be visibly stripped from the front
|
1439 |
+
# of URLs?
|
1440 |
+
'strip_protocols' => true,
|
1441 |
+
|
1442 |
+
);
|
1443 |
+
|
1444 |
+
####################################################################
|
1445 |
+
|
1446 |
+
function cff_autolink($text, $span_tag = false, $limit=100, $tagfill='class="cff-break-word"', $auto_title = true){
|
1447 |
+
|
1448 |
+
$text = cff_autolink_do($text, '![a-z][a-z-]+://!i', $limit, $tagfill, $auto_title, $span_tag);
|
1449 |
+
$text = cff_autolink_do($text, '!(mailto|skype):!i', $limit, $tagfill, $auto_title, $span_tag);
|
1450 |
+
$text = cff_autolink_do($text, '!www\\.!i', $limit, $tagfill, $auto_title, 'http://', $span_tag);
|
1451 |
+
return $text;
|
1452 |
+
}
|
1453 |
+
|
1454 |
+
####################################################################
|
1455 |
+
|
1456 |
+
function cff_autolink_do($text, $sub, $limit, $tagfill, $auto_title, $span_tag, $force_prefix=null){
|
1457 |
+
|
1458 |
+
$text_l = StrToLower($text);
|
1459 |
+
$cursor = 0;
|
1460 |
+
$loop = 1;
|
1461 |
+
$buffer = '';
|
1462 |
+
|
1463 |
+
while (($cursor < strlen($text)) && $loop){
|
1464 |
+
|
1465 |
+
$ok = 1;
|
1466 |
+
$matched = preg_match($sub, $text_l, $m, PREG_OFFSET_CAPTURE, $cursor);
|
1467 |
+
|
1468 |
+
if (!$matched){
|
1469 |
+
|
1470 |
+
$loop = 0;
|
1471 |
+
$ok = 0;
|
1472 |
+
|
1473 |
+
}else{
|
1474 |
+
|
1475 |
+
$pos = $m[0][1];
|
1476 |
+
$sub_len = strlen($m[0][0]);
|
1477 |
+
|
1478 |
+
$pre_hit = substr($text, $cursor, $pos-$cursor);
|
1479 |
+
$hit = substr($text, $pos, $sub_len);
|
1480 |
+
$pre = substr($text, 0, $pos);
|
1481 |
+
$post = substr($text, $pos + $sub_len);
|
1482 |
+
|
1483 |
+
$fail_text = $pre_hit.$hit;
|
1484 |
+
$fail_len = strlen($fail_text);
|
1485 |
+
|
1486 |
+
#
|
1487 |
+
# substring found - first check to see if we're inside a link tag already...
|
1488 |
+
#
|
1489 |
+
|
1490 |
+
$bits = preg_split("!</a>!i", $pre);
|
1491 |
+
$last_bit = array_pop($bits);
|
1492 |
+
if (preg_match("!<a\s!i", $last_bit)){
|
1493 |
+
|
1494 |
+
#echo "fail 1 at $cursor<br />\n";
|
1495 |
+
|
1496 |
+
$ok = 0;
|
1497 |
+
$cursor += $fail_len;
|
1498 |
+
$buffer .= $fail_text;
|
1499 |
+
}
|
1500 |
+
}
|
1501 |
+
|
1502 |
+
#
|
1503 |
+
# looks like a nice spot to autolink from - check the pre
|
1504 |
+
# to see if there was whitespace before this match
|
1505 |
+
#
|
1506 |
+
|
1507 |
+
if ($ok){
|
1508 |
+
|
1509 |
+
if ($pre){
|
1510 |
+
if (!preg_match('![\s\(\[\{>]$!s', $pre)){
|
1511 |
+
|
1512 |
+
#echo "fail 2 at $cursor ($pre)<br />\n";
|
1513 |
+
|
1514 |
+
$ok = 0;
|
1515 |
+
$cursor += $fail_len;
|
1516 |
+
$buffer .= $fail_text;
|
1517 |
+
}
|
1518 |
+
}
|
1519 |
+
}
|
1520 |
+
|
1521 |
+
#
|
1522 |
+
# we want to autolink here - find the extent of the url
|
1523 |
+
#
|
1524 |
+
|
1525 |
+
if ($ok){
|
1526 |
+
if (preg_match('/^([a-z0-9\-\.\/\-_%~!?=,:;&+*#@\(\)\$]+)/i', $post, $matches)){
|
1527 |
+
|
1528 |
+
$url = $hit.$matches[1];
|
1529 |
+
|
1530 |
+
$cursor += strlen($url) + strlen($pre_hit);
|
1531 |
+
$buffer .= $pre_hit;
|
1532 |
+
|
1533 |
+
$url = html_entity_decode($url);
|
1534 |
+
|
1535 |
+
|
1536 |
+
#
|
1537 |
+
# remove trailing punctuation from url
|
1538 |
+
#
|
1539 |
+
|
1540 |
+
while (preg_match('|[.,!;:?]$|', $url)){
|
1541 |
+
$url = substr($url, 0, strlen($url)-1);
|
1542 |
+
$cursor--;
|
1543 |
+
}
|
1544 |
+
foreach (array('()', '[]', '{}') as $pair){
|
1545 |
+
$o = substr($pair, 0, 1);
|
1546 |
+
$c = substr($pair, 1, 1);
|
1547 |
+
if (preg_match("!^(\\$c|^)[^\\$o]+\\$c$!", $url)){
|
1548 |
+
$url = substr($url, 0, strlen($url)-1);
|
1549 |
+
$cursor--;
|
1550 |
+
}
|
1551 |
+
}
|
1552 |
+
|
1553 |
+
|
1554 |
+
#
|
1555 |
+
# nice-i-fy url here
|
1556 |
+
#
|
1557 |
+
|
1558 |
+
$link_url = $url;
|
1559 |
+
$display_url = $url;
|
1560 |
+
|
1561 |
+
if ($force_prefix) $link_url = $force_prefix.$link_url;
|
1562 |
+
|
1563 |
+
if ($GLOBALS['autolink_options']['strip_protocols']){
|
1564 |
+
if (preg_match('!^(http|https)://!i', $display_url, $m)){
|
1565 |
+
|
1566 |
+
$display_url = substr($display_url, strlen($m[1])+3);
|
1567 |
+
}
|
1568 |
+
}
|
1569 |
+
|
1570 |
+
$display_url = cff_autolink_label($display_url, $limit);
|
1571 |
+
|
1572 |
+
|
1573 |
+
#
|
1574 |
+
# add the url
|
1575 |
+
#
|
1576 |
+
|
1577 |
+
if ($display_url != $link_url && !preg_match('@title=@msi',$tagfill) && $auto_title) {
|
1578 |
+
|
1579 |
+
$display_quoted = preg_quote($display_url, '!');
|
1580 |
+
|
1581 |
+
if (!preg_match("!^(http|https)://{$display_quoted}$!i", $link_url)){
|
1582 |
+
|
1583 |
+
$tagfill .= ' title="'.$link_url.'"';
|
1584 |
+
}
|
1585 |
+
}
|
1586 |
+
|
1587 |
+
$link_url_enc = HtmlSpecialChars($link_url);
|
1588 |
+
$display_url_enc = HtmlSpecialChars($display_url);
|
1589 |
+
|
1590 |
+
if($span_tag == true){
|
1591 |
+
$buffer .= "<span $tagfill>{$display_url_enc}</span>";
|
1592 |
+
} else {
|
1593 |
+
$buffer .= "<a target='_blank' href=\"{$link_url_enc}\"$tagfill>{$display_url_enc}</a>";
|
1594 |
+
}
|
1595 |
+
|
1596 |
+
|
1597 |
+
}else{
|
1598 |
+
#echo "fail 3 at $cursor<br />\n";
|
1599 |
+
|
1600 |
+
$ok = 0;
|
1601 |
+
$cursor += $fail_len;
|
1602 |
+
$buffer .= $fail_text;
|
1603 |
+
}
|
1604 |
+
}
|
1605 |
+
|
1606 |
+
}
|
1607 |
+
|
1608 |
+
#
|
1609 |
+
# add everything from the cursor to the end onto the buffer.
|
1610 |
+
#
|
1611 |
+
|
1612 |
+
$buffer .= substr($text, $cursor);
|
1613 |
+
|
1614 |
+
return $buffer;
|
1615 |
+
}
|
1616 |
+
|
1617 |
+
####################################################################
|
1618 |
+
|
1619 |
+
function cff_autolink_label($text, $limit){
|
1620 |
+
|
1621 |
+
if (!$limit){ return $text; }
|
1622 |
+
|
1623 |
+
if (strlen($text) > $limit){
|
1624 |
+
return substr($text, 0, $limit-3).'...';
|
1625 |
+
}
|
1626 |
+
|
1627 |
+
return $text;
|
1628 |
+
}
|
1629 |
+
|
1630 |
+
####################################################################
|
1631 |
+
|
1632 |
+
function cff_autolink_email($text, $tagfill=''){
|
1633 |
+
|
1634 |
+
$atom = '[^()<>@,;:\\\\".\\[\\]\\x00-\\x20\\x7f]+'; # from RFC822
|
1635 |
+
|
1636 |
+
#die($atom);
|
1637 |
+
|
1638 |
+
$text_l = StrToLower($text);
|
1639 |
+
$cursor = 0;
|
1640 |
+
$loop = 1;
|
1641 |
+
$buffer = '';
|
1642 |
+
|
1643 |
+
while(($cursor < strlen($text)) && $loop){
|
1644 |
+
|
1645 |
+
#
|
1646 |
+
# find an '@' symbol
|
1647 |
+
#
|
1648 |
+
|
1649 |
+
$ok = 1;
|
1650 |
+
$pos = strpos($text_l, '@', $cursor);
|
1651 |
+
|
1652 |
+
if ($pos === false){
|
1653 |
+
|
1654 |
+
$loop = 0;
|
1655 |
+
$ok = 0;
|
1656 |
+
|
1657 |
+
}else{
|
1658 |
+
|
1659 |
+
$pre = substr($text, $cursor, $pos-$cursor);
|
1660 |
+
$hit = substr($text, $pos, 1);
|
1661 |
+
$post = substr($text, $pos + 1);
|
1662 |
+
|
1663 |
+
$fail_text = $pre.$hit;
|
1664 |
+
$fail_len = strlen($fail_text);
|
1665 |
+
|
1666 |
+
#die("$pre::$hit::$post::$fail_text");
|
1667 |
+
|
1668 |
+
#
|
1669 |
+
# substring found - first check to see if we're inside a link tag already...
|
1670 |
+
#
|
1671 |
+
|
1672 |
+
$bits = preg_split("!</a>!i", $pre);
|
1673 |
+
$last_bit = array_pop($bits);
|
1674 |
+
if (preg_match("!<a\s!i", $last_bit)){
|
1675 |
+
|
1676 |
+
#echo "fail 1 at $cursor<br />\n";
|
1677 |
+
|
1678 |
+
$ok = 0;
|
1679 |
+
$cursor += $fail_len;
|
1680 |
+
$buffer .= $fail_text;
|
1681 |
+
}
|
1682 |
+
}
|
1683 |
+
|
1684 |
+
#
|
1685 |
+
# check backwards
|
1686 |
+
#
|
1687 |
+
|
1688 |
+
if ($ok){
|
1689 |
+
if (preg_match("!($atom(\.$atom)*)\$!", $pre, $matches)){
|
1690 |
+
|
1691 |
+
# move matched part of address into $hit
|
1692 |
+
|
1693 |
+
$len = strlen($matches[1]);
|
1694 |
+
$plen = strlen($pre);
|
1695 |
+
|
1696 |
+
$hit = substr($pre, $plen-$len).$hit;
|
1697 |
+
$pre = substr($pre, 0, $plen-$len);
|
1698 |
+
|
1699 |
+
}else{
|
1700 |
+
|
1701 |
+
#echo "fail 2 at $cursor ($pre)<br />\n";
|
1702 |
+
|
1703 |
+
$ok = 0;
|
1704 |
+
$cursor += $fail_len;
|
1705 |
+
$buffer .= $fail_text;
|
1706 |
+
}
|
1707 |
+
}
|
1708 |
+
|
1709 |
+
#
|
1710 |
+
# check forwards
|
1711 |
+
#
|
1712 |
+
|
1713 |
+
if ($ok){
|
1714 |
+
if (preg_match("!^($atom(\.$atom)*)!", $post, $matches)){
|
1715 |
+
|
1716 |
+
# move matched part of address into $hit
|
1717 |
+
|
1718 |
+
$len = strlen($matches[1]);
|
1719 |
+
|
1720 |
+
$hit .= substr($post, 0, $len);
|
1721 |
+
$post = substr($post, $len);
|
1722 |
+
|
1723 |
+
}else{
|
1724 |
+
#echo "fail 3 at $cursor ($post)<br />\n";
|
1725 |
+
|
1726 |
+
$ok = 0;
|
1727 |
+
$cursor += $fail_len;
|
1728 |
+
$buffer .= $fail_text;
|
1729 |
+
}
|
1730 |
+
}
|
1731 |
+
|
1732 |
+
#
|
1733 |
+
# commit
|
1734 |
+
#
|
1735 |
+
|
1736 |
+
if ($ok) {
|
1737 |
+
|
1738 |
+
$cursor += strlen($pre) + strlen($hit);
|
1739 |
+
$buffer .= $pre;
|
1740 |
+
$buffer .= "<a href=\"mailto:$hit\"$tagfill>$hit</a>";
|
1741 |
+
|
1742 |
+
}
|
1743 |
+
|
1744 |
+
}
|
1745 |
+
|
1746 |
+
#
|
1747 |
+
# add everything from the cursor to the end onto the buffer.
|
1748 |
+
#
|
1749 |
+
|
1750 |
+
$buffer .= substr($text, $cursor);
|
1751 |
+
|
1752 |
+
return $buffer;
|
1753 |
+
}
|
1754 |
+
|
1755 |
+
####################################################################
|
1756 |
+
|
1757 |
+
|
1758 |
//Comment out the line below to view errors
|
1759 |
error_reporting(0);
|
1760 |
?>
|