-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.php
92 lines (71 loc) · 2.39 KB
/
helper.php
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
<?php
class blockinfoHelper
{
private static $p_instance;
private static $options;
private function __construct() {}
public static function getInstance()
{
if(!self::$p_instance)
{
self::$p_instance = new blockinfoHelper();
}
return self::$p_instance;
}
private static function getOverride($option, $obj)
{
if(isset(static::$options[$option]))
return static::$options[$option];
else
return $obj->getConf($option);
}
public function setOption($key, $value)
{
static::$options[$key] = $value;
}
public function getOption($key)
{
return static::$options[$key];
}
public function parseOutput($string, $type, $obj)
{
$do_formatting = true;
$uppercase_mode = self::getOverride($type.'_uppercase', $obj);
$parse = self::getOverride($type.'_parse', $obj);
$output = '';
if($parse)
{
$string = p_render('xhtml',p_get_instructions($string),$info);
if(!(self::getOverride($type.'_format_force', $obj)))
$do_formatting = false;
}
if($do_formatting)
{
//Strip all HTML from output
$string = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($string))))));
$words = explode(' ', $string);
foreach($words as $key => $word)
{
switch($uppercase_mode)
{
case 'first':
if($key == 0) $word = ucfirst(strtolower($word));
break;
case 'words':
$word = ucfirst(strtolower($word));
break;
case 'all':
$word = strtoupper($word);
break;
}
$output .= $word.' ';
}
}
else
{
$output = $string;
}
return trim($output);
}
}
?>