1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Created by Gorlum 15.02.2017 10:08 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
use Core\GlobalContainer; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Design |
11
|
|
|
* |
12
|
|
|
* Describes design elements. For now it's a smileset and bbCodes |
13
|
|
|
* |
14
|
|
|
*/ |
15
|
|
|
class Design { |
16
|
|
|
/** |
17
|
|
|
* @var classConfig $gameConfig |
18
|
|
|
*/ |
19
|
|
|
protected $gameConfig; |
20
|
|
|
|
21
|
|
|
protected $smileList = array(); |
22
|
|
|
protected $smiles = array(); |
23
|
|
|
protected $bbCodes = array(); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Design constructor. |
27
|
|
|
* |
28
|
|
|
* @param GlobalContainer $gc |
29
|
|
|
*/ |
30
|
|
|
public function __construct(GlobalContainer $gc) { |
|
|
|
|
31
|
|
|
$this->gameConfig = SN::$gc->config; |
32
|
|
|
|
33
|
|
|
// Prefix faq:// resolves to FAQ's URL - if configured |
34
|
|
|
if (is_object($this->gameConfig) && !empty($this->gameConfig->url_faq)) { |
35
|
|
|
$this->addBbCodes(array( |
36
|
|
|
'#faq://#isU' => $this->gameConfig->url_faq, |
37
|
|
|
), AUTH_LEVEL_REGISTERED); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
global $sn_data_bbCodes, $sn_data_smiles; |
41
|
|
|
$this->addBbCodes($sn_data_bbCodes); |
42
|
|
|
$this->addSmiles($sn_data_smiles); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function detectElementsFormat($elements, $accessLevel = AUTH_LEVEL_REGISTERED) { |
46
|
|
|
$firstElement = reset($elements); |
47
|
|
|
if (!is_array($firstElement)) { |
48
|
|
|
// Plain element list - making access list |
49
|
|
|
$elements = array($accessLevel => $elements); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $elements; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param array $array |
57
|
|
|
* @param string[]|string[][] $elements <p>list of smiles. Can be:</p> |
58
|
|
|
* <p>- plain list of smiles in format ['text' => 'imageName',...], i.e. [':p:' => 'tongue']</p> |
59
|
|
|
* <p>- access list of plaint list of smiles in format [AUTH_LEVEL_xxx => ['text' => 'imageName',...], ...], i.e. [AUTH_LEVEL_REGISTERED => [':p:' => 'tongue']]</p> |
60
|
|
|
* <p>'text' can be a regex - otherwise it would be forcibly formatted to regex '#text#isU'</p> |
61
|
|
|
* @param int $accessLevel - access level for plain element list. Default - AUTH_LEVEL_REGISTERED |
62
|
|
|
*/ |
63
|
|
|
protected function addElements(&$array, $elements, $accessLevel = AUTH_LEVEL_REGISTERED) { |
64
|
|
|
if (!is_array($elements) || empty($elements)) { |
|
|
|
|
65
|
|
|
return; // TODO - Exception |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$elements = $this->detectElementsFormat($elements, $accessLevel); |
69
|
|
|
|
70
|
|
|
HelperArray::merge($array, $elements, HelperArray::MERGE_RECURSIVE_NUMERIC); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Add bbCodes to global collection |
75
|
|
|
* |
76
|
|
|
* @param string[]|string[][] $bbCodes <p>list of bbCodes formatted like in Design::addElements</p> |
77
|
|
|
* @param int $accessLevel - access level for plain element list. Default - AUTH_LEVEL_REGISTERED |
78
|
|
|
* |
79
|
|
|
* @see Design::addElements |
80
|
|
|
*/ |
81
|
|
|
public function addBbCodes($bbCodes, $accessLevel = AUTH_LEVEL_REGISTERED) { |
82
|
|
|
$this->addElements($this->bbCodes, $bbCodes, $accessLevel); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Add smiles to global collection |
87
|
|
|
* |
88
|
|
|
* @param string[]|string[][] $smiles <p>list of smiles formatted like in Design::addElements</p> |
89
|
|
|
* @param int $accessLevel - access level for plain element list. Default - AUTH_LEVEL_REGISTERED |
90
|
|
|
* |
91
|
|
|
* @see Design::addElements |
92
|
|
|
*/ |
93
|
|
|
public function addSmiles($smiles, $accessLevel = AUTH_LEVEL_REGISTERED) { |
94
|
|
|
$smiles = $this->detectElementsFormat($smiles, $accessLevel); |
95
|
|
|
|
96
|
|
|
// Detecting regexps or plain text - converting plain text to regexps |
97
|
|
|
// This is for back compatibility with Festival data |
98
|
|
|
foreach ($smiles as $elementAuth => &$elementList) { |
99
|
|
|
$surelyRegexps = array(); |
100
|
|
|
foreach ($elementList as $find => $replace) { |
101
|
|
|
// Caching smiles as-is for smile list generation |
102
|
|
|
$this->smileList[$elementAuth][$find] = $replace; |
103
|
|
|
|
104
|
|
|
// Now converting smile original data to preg_replace() params |
105
|
|
|
$replace = "<img src=\"design/images/smileys/" . $replace . ".gif\" align=\"absmiddle\" title=\"" . $find . "\" alt=\"" . $find . "\">"; |
106
|
|
|
|
107
|
|
|
// Check for regexp |
108
|
|
|
if (($firstChar = substr($find, 0, 1)) != '#' && $firstChar != '/') { |
109
|
|
|
$find = '#' . addcslashes($find, '()[]{}') . '#isU'; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// To maintain element order even when index change |
113
|
|
|
$surelyRegexps[$find] = $replace; |
114
|
|
|
} |
115
|
|
|
$elementList = $surelyRegexps; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->addElements($this->smiles, $smiles, $accessLevel); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
// Getters/Setters +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
122
|
|
|
public function getSmiles() { |
123
|
|
|
return $this->smiles; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function getBbCodes() { |
127
|
|
|
return $this->bbCodes; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Return smiles for making smile's list |
132
|
|
|
* |
133
|
|
|
* @return array |
134
|
|
|
*/ |
135
|
|
|
public function getSmilesList() { |
136
|
|
|
return $this->smileList; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.