@@ -17,7 +17,6 @@ |
||
17 | 17 | use Fisharebest\Webtrees\Module\AbstractModule; |
18 | 18 | use Fisharebest\Webtrees\Module\ModuleConfigInterface; |
19 | 19 | use Fisharebest\Webtrees\Tree; |
20 | -use MyArtJaub\Webtrees\Functions\Functions; |
|
21 | 20 | use MyArtJaub\Webtrees\Globals; |
22 | 21 | use MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface; |
23 | 22 | use MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface; |
@@ -31,147 +31,147 @@ discard block |
||
31 | 31 | * Certificates Module. |
32 | 32 | */ |
33 | 33 | class CertificatesModule |
34 | - extends AbstractModule |
|
35 | - implements HookSubscriberInterface, ModuleConfigInterface, ModuleMenuItemInterface, FactSourceTextExtenderInterface, CustomSimpleTagManagerInterface, DependentInterface |
|
34 | + extends AbstractModule |
|
35 | + implements HookSubscriberInterface, ModuleConfigInterface, ModuleMenuItemInterface, FactSourceTextExtenderInterface, CustomSimpleTagManagerInterface, DependentInterface |
|
36 | 36 | { |
37 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
38 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
37 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
38 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Provider for Certificates |
|
42 | - * @var CertificateProviderInterface $provider |
|
43 | - */ |
|
44 | - protected $provider; |
|
40 | + /** |
|
41 | + * Provider for Certificates |
|
42 | + * @var CertificateProviderInterface $provider |
|
43 | + */ |
|
44 | + protected $provider; |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inhericDoc} |
|
48 | - */ |
|
49 | - public function getTitle() { |
|
50 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
51 | - } |
|
46 | + /** |
|
47 | + * {@inhericDoc} |
|
48 | + */ |
|
49 | + public function getTitle() { |
|
50 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * {@inhericDoc} |
|
55 | - */ |
|
56 | - public function getDescription() { |
|
57 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
58 | - } |
|
53 | + /** |
|
54 | + * {@inhericDoc} |
|
55 | + */ |
|
56 | + public function getDescription() { |
|
57 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inhericDoc} |
|
62 | - */ |
|
63 | - public function modAction($mod_action) { |
|
64 | - \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
65 | - } |
|
60 | + /** |
|
61 | + * {@inhericDoc} |
|
62 | + */ |
|
63 | + public function modAction($mod_action) { |
|
64 | + \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inheritDoc} |
|
69 | - * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
70 | - */ |
|
71 | - public function validatePrerequisites() { |
|
72 | - } |
|
67 | + /** |
|
68 | + * {@inheritDoc} |
|
69 | + * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
70 | + */ |
|
71 | + public function validatePrerequisites() { |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * {@inhericDoc} |
|
76 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
77 | - */ |
|
78 | - public function getConfigLink() { |
|
79 | - return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
80 | - } |
|
74 | + /** |
|
75 | + * {@inhericDoc} |
|
76 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
77 | + */ |
|
78 | + public function getConfigLink() { |
|
79 | + return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * {@inhericDoc} |
|
84 | - * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
85 | - */ |
|
86 | - public function getSubscribedHooks() { |
|
87 | - return array( |
|
88 | - 'hFactSourcePrepend' => 50, |
|
89 | - 'hGetExpectedTags' => 50, |
|
90 | - 'hHtmlSimpleTagDisplay#_ACT' => 50, |
|
91 | - 'hHtmlSimpleTagEditor#_ACT' => 50, |
|
92 | - 'hAddSimpleTag#SOUR' => 50, |
|
93 | - 'hHasHelpTextTag#_ACT' => 50, |
|
94 | - 'hGetHelpTextTag#_ACT' => 50 |
|
95 | - ); |
|
96 | - } |
|
82 | + /** |
|
83 | + * {@inhericDoc} |
|
84 | + * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
85 | + */ |
|
86 | + public function getSubscribedHooks() { |
|
87 | + return array( |
|
88 | + 'hFactSourcePrepend' => 50, |
|
89 | + 'hGetExpectedTags' => 50, |
|
90 | + 'hHtmlSimpleTagDisplay#_ACT' => 50, |
|
91 | + 'hHtmlSimpleTagEditor#_ACT' => 50, |
|
92 | + 'hAddSimpleTag#SOUR' => 50, |
|
93 | + 'hHasHelpTextTag#_ACT' => 50, |
|
94 | + 'hGetHelpTextTag#_ACT' => 50 |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * {@inhericDoc} |
|
100 | - * @see \MyArtJaub\Webtrees\Module\ModuleMenuItemInterface::getMenu() |
|
101 | - */ |
|
102 | - public function getMenu(Tree $tree, $reference = null) { |
|
103 | - $tree_url = $tree ? $tree->getNameUrl() : ''; |
|
104 | - return new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=Certificate@listAll&ged=' . $tree_url, 'menu-maj-list-certificate', array('rel' => 'nofollow')); |
|
105 | - } |
|
98 | + /** |
|
99 | + * {@inhericDoc} |
|
100 | + * @see \MyArtJaub\Webtrees\Module\ModuleMenuItemInterface::getMenu() |
|
101 | + */ |
|
102 | + public function getMenu(Tree $tree, $reference = null) { |
|
103 | + $tree_url = $tree ? $tree->getNameUrl() : ''; |
|
104 | + return new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=Certificate@listAll&ged=' . $tree_url, 'menu-maj-list-certificate', array('rel' => 'nofollow')); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * {@inhericDoc} |
|
109 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourcePrepend() |
|
110 | - */ |
|
111 | - public function hFactSourcePrepend($srec) { |
|
112 | - $wt_tree = Globals::getTree(); |
|
113 | - $html=''; |
|
114 | - $sid=null; |
|
107 | + /** |
|
108 | + * {@inhericDoc} |
|
109 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourcePrepend() |
|
110 | + */ |
|
111 | + public function hFactSourcePrepend($srec) { |
|
112 | + $wt_tree = Globals::getTree(); |
|
113 | + $html=''; |
|
114 | + $sid=null; |
|
115 | 115 | |
116 | - if($this->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($wt_tree)){ |
|
117 | - if (!$srec || strlen($srec) == 0) return $html; |
|
116 | + if($this->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($wt_tree)){ |
|
117 | + if (!$srec || strlen($srec) == 0) return $html; |
|
118 | 118 | |
119 | - $certificate = null; |
|
120 | - $subrecords = explode("\n", $srec); |
|
121 | - $levelSOUR = substr($subrecords[0], 0, 1); |
|
122 | - $match = null; |
|
123 | - if (preg_match('~^'.$levelSOUR.' SOUR @('.WT_REGEX_XREF.')@$~', $subrecords[0], $match)) { |
|
124 | - $sid=$match[1]; |
|
125 | - }; |
|
126 | - $nb_subrecords = count($subrecords); |
|
127 | - for ($i=0; $i < $nb_subrecords; $i++) { |
|
128 | - $subrecords[$i] = trim($subrecords[$i]); |
|
129 | - $tag = substr($subrecords[$i], 2, 4); |
|
130 | - $text = substr($subrecords[$i], 7); |
|
131 | - if($tag == '_ACT') $certificate= new Certificate($text, $wt_tree, $this->getProvider()); |
|
132 | - } |
|
119 | + $certificate = null; |
|
120 | + $subrecords = explode("\n", $srec); |
|
121 | + $levelSOUR = substr($subrecords[0], 0, 1); |
|
122 | + $match = null; |
|
123 | + if (preg_match('~^'.$levelSOUR.' SOUR @('.WT_REGEX_XREF.')@$~', $subrecords[0], $match)) { |
|
124 | + $sid=$match[1]; |
|
125 | + }; |
|
126 | + $nb_subrecords = count($subrecords); |
|
127 | + for ($i=0; $i < $nb_subrecords; $i++) { |
|
128 | + $subrecords[$i] = trim($subrecords[$i]); |
|
129 | + $tag = substr($subrecords[$i], 2, 4); |
|
130 | + $text = substr($subrecords[$i], 7); |
|
131 | + if($tag == '_ACT') $certificate= new Certificate($text, $wt_tree, $this->getProvider()); |
|
132 | + } |
|
133 | 133 | |
134 | - if($certificate && $certificate->canShow()) |
|
135 | - $html = $this->getDisplay_ACT($certificate, $sid); |
|
134 | + if($certificate && $certificate->canShow()) |
|
135 | + $html = $this->getDisplay_ACT($certificate, $sid); |
|
136 | 136 | |
137 | - } |
|
138 | - return $html; |
|
139 | - } |
|
137 | + } |
|
138 | + return $html; |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * {@inhericDoc} |
|
143 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourceAppend() |
|
144 | - */ |
|
145 | - public function hFactSourceAppend($srec) { } |
|
141 | + /** |
|
142 | + * {@inhericDoc} |
|
143 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourceAppend() |
|
144 | + */ |
|
145 | + public function hFactSourceAppend($srec) { } |
|
146 | 146 | |
147 | - /** |
|
148 | - * {@inhericDoc} |
|
149 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetExpectedTags() |
|
150 | - */ |
|
151 | - public function hGetExpectedTags() { |
|
152 | - return array('SOUR' => '_ACT'); |
|
153 | - } |
|
147 | + /** |
|
148 | + * {@inhericDoc} |
|
149 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetExpectedTags() |
|
150 | + */ |
|
151 | + public function hGetExpectedTags() { |
|
152 | + return array('SOUR' => '_ACT'); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * {@inhericDoc} |
|
157 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagDisplay() |
|
158 | - */ |
|
159 | - public function hHtmlSimpleTagDisplay($tag, $value, $context = null, $contextid = null) { |
|
160 | - $html = ''; |
|
161 | - switch($tag){ |
|
162 | - case '_ACT': |
|
163 | - if($context == 'SOUR') $html = $this->getDisplay_ACT($value, $contextid); |
|
164 | - break; |
|
165 | - } |
|
166 | - return $html; |
|
167 | - } |
|
155 | + /** |
|
156 | + * {@inhericDoc} |
|
157 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagDisplay() |
|
158 | + */ |
|
159 | + public function hHtmlSimpleTagDisplay($tag, $value, $context = null, $contextid = null) { |
|
160 | + $html = ''; |
|
161 | + switch($tag){ |
|
162 | + case '_ACT': |
|
163 | + if($context == 'SOUR') $html = $this->getDisplay_ACT($value, $contextid); |
|
164 | + break; |
|
165 | + } |
|
166 | + return $html; |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * {@inhericDoc} |
|
171 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagEditor() |
|
172 | - */ |
|
173 | - public function hHtmlSimpleTagEditor($tag, $value = null, $element_id = '', $element_name = '', $context = null, $contextid = null) { |
|
174 | - $html = ''; |
|
169 | + /** |
|
170 | + * {@inhericDoc} |
|
171 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagEditor() |
|
172 | + */ |
|
173 | + public function hHtmlSimpleTagEditor($tag, $value = null, $element_id = '', $element_name = '', $context = null, $contextid = null) { |
|
174 | + $html = ''; |
|
175 | 175 | |
176 | 176 | switch($tag){ |
177 | 177 | case '_ACT': |
@@ -199,75 +199,75 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | return $html; |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * {@inhericDoc} |
|
206 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hAddSimpleTag() |
|
207 | - */ |
|
208 | - public function hAddSimpleTag($context, $level) { |
|
209 | - switch($context){ |
|
210 | - case 'SOUR': |
|
211 | - FunctionsEdit::addSimpleTag($level.' _ACT'); |
|
212 | - break; |
|
213 | - } |
|
214 | - } |
|
204 | + /** |
|
205 | + * {@inhericDoc} |
|
206 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hAddSimpleTag() |
|
207 | + */ |
|
208 | + public function hAddSimpleTag($context, $level) { |
|
209 | + switch($context){ |
|
210 | + case 'SOUR': |
|
211 | + FunctionsEdit::addSimpleTag($level.' _ACT'); |
|
212 | + break; |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * {@inhericDoc} |
|
218 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHasHelpTextTag() |
|
219 | - */ |
|
220 | - public function hHasHelpTextTag($tag) { |
|
221 | - switch($tag){ |
|
216 | + /** |
|
217 | + * {@inhericDoc} |
|
218 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHasHelpTextTag() |
|
219 | + */ |
|
220 | + public function hHasHelpTextTag($tag) { |
|
221 | + switch($tag){ |
|
222 | 222 | case '_ACT': |
223 | 223 | return true; |
224 | 224 | } |
225 | 225 | return false; |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * {@inhericDoc} |
|
230 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetHelpTextTag() |
|
231 | - */ |
|
232 | - public function hGetHelpTextTag($tag) { |
|
233 | - switch($tag){ |
|
234 | - case '_ACT': |
|
235 | - return array( |
|
236 | - I18N::translate('Certificate'), |
|
237 | - '<p>'.I18N::translate('Path to a certificate linked to a source reference.').'</p>'); |
|
238 | - default: |
|
239 | - return null; |
|
240 | - } |
|
241 | - } |
|
228 | + /** |
|
229 | + * {@inhericDoc} |
|
230 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetHelpTextTag() |
|
231 | + */ |
|
232 | + public function hGetHelpTextTag($tag) { |
|
233 | + switch($tag){ |
|
234 | + case '_ACT': |
|
235 | + return array( |
|
236 | + I18N::translate('Certificate'), |
|
237 | + '<p>'.I18N::translate('Path to a certificate linked to a source reference.').'</p>'); |
|
238 | + default: |
|
239 | + return null; |
|
240 | + } |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Returns the default Certificate File Provider, as configured in the module |
|
245 | - * |
|
246 | - * @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface |
|
247 | - */ |
|
248 | - public function getProvider() { |
|
249 | - if(!$this->provider) { |
|
250 | - $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); |
|
251 | - $this->provider = new CertificateFileProvider($root_path, Globals::getTree()); |
|
252 | - } |
|
253 | - return $this->provider; |
|
254 | - } |
|
243 | + /** |
|
244 | + * Returns the default Certificate File Provider, as configured in the module |
|
245 | + * |
|
246 | + * @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface |
|
247 | + */ |
|
248 | + public function getProvider() { |
|
249 | + if(!$this->provider) { |
|
250 | + $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); |
|
251 | + $this->provider = new CertificateFileProvider($root_path, Globals::getTree()); |
|
252 | + } |
|
253 | + return $this->provider; |
|
254 | + } |
|
255 | 255 | |
256 | 256 | |
257 | - /** |
|
258 | - * Return the HTML code for custom simple tag _ACT |
|
259 | - * |
|
260 | - * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
261 | - * @param string|null $sid Linked Source ID, if it exists |
|
262 | - */ |
|
263 | - protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
|
264 | - $html = ''; |
|
265 | - if($certificate){ |
|
266 | - $certificate->setSource($sid); |
|
267 | - $html = $certificate->displayImage('icon'); |
|
268 | - } |
|
269 | - return $html; |
|
270 | - } |
|
257 | + /** |
|
258 | + * Return the HTML code for custom simple tag _ACT |
|
259 | + * |
|
260 | + * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
261 | + * @param string|null $sid Linked Source ID, if it exists |
|
262 | + */ |
|
263 | + protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
|
264 | + $html = ''; |
|
265 | + if($certificate){ |
|
266 | + $certificate->setSource($sid); |
|
267 | + $html = $certificate->displayImage('icon'); |
|
268 | + } |
|
269 | + return $html; |
|
270 | + } |
|
271 | 271 | |
272 | 272 | |
273 | 273 | } |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | * @return string Encryption key |
130 | 130 | */ |
131 | 131 | protected static function getBase64EncryptionKey() { |
132 | - $key = 'STANDARDKEYIFNOSERVER'; |
|
133 | - if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
134 | - $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
132 | + $key = 'STANDARDKEYIFNOSERVER'; |
|
133 | + if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
134 | + $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
135 | 135 | |
136 | - return $key; |
|
136 | + return $key; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -172,20 +172,20 @@ discard block |
||
172 | 172 | throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
173 | 173 | |
174 | 174 | if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) |
175 | - throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
175 | + throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
176 | 176 | |
177 | - $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); |
|
178 | - $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); |
|
177 | + $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); |
|
178 | + $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); |
|
179 | 179 | |
180 | - $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); |
|
180 | + $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); |
|
181 | 181 | |
182 | - if($decrypted === false) { |
|
183 | - throw new \InvalidArgumentException('The message has been tampered with in transit.'); |
|
184 | - } |
|
182 | + if($decrypted === false) { |
|
183 | + throw new \InvalidArgumentException('The message has been tampered with in transit.'); |
|
184 | + } |
|
185 | 185 | |
186 | - //sodium_memzero($encrypted); // Requires PHP 7.2 |
|
186 | + //sodium_memzero($encrypted); // Requires PHP 7.2 |
|
187 | 187 | |
188 | - return $decrypted; |
|
188 | + return $decrypted; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public static function encodeFileSystemToUtf8($string){ |
198 | 198 | if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
199 | - return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
199 | + return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
200 | 200 | } |
201 | 201 | return $string; |
202 | 202 | } |
@@ -261,20 +261,20 @@ discard block |
||
261 | 261 | * @return boolean|string Is supported? |
262 | 262 | */ |
263 | 263 | public static function isImageTypeSupported($reqtype) { |
264 | - $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
|
265 | - $reqtype = strtolower($reqtype); |
|
264 | + $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
|
265 | + $reqtype = strtolower($reqtype); |
|
266 | 266 | |
267 | - if (empty($supportByGD[$reqtype])) { |
|
268 | - return false; |
|
269 | - } |
|
267 | + if (empty($supportByGD[$reqtype])) { |
|
268 | + return false; |
|
269 | + } |
|
270 | 270 | |
271 | - $type = $supportByGD[$reqtype]; |
|
271 | + $type = $supportByGD[$reqtype]; |
|
272 | 272 | |
273 | - if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { |
|
274 | - return $type; |
|
275 | - } |
|
273 | + if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { |
|
274 | + return $type; |
|
275 | + } |
|
276 | 276 | |
277 | - return false; |
|
277 | + return false; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | } |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param string $text Text to display |
34 | 34 | */ |
35 | - static public function promptAlert($text){ |
|
35 | + static public function promptAlert($text) { |
|
36 | 36 | echo '<script>'; |
37 | - echo 'alert("',fw\Filter::escapeHtml($text),'")'; |
|
37 | + echo 'alert("', fw\Filter::escapeHtml($text), '")'; |
|
38 | 38 | echo '</script>'; |
39 | 39 | } |
40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return float Result of the safe division |
48 | 48 | */ |
49 | 49 | public static function safeDivision($num, $denom, $default = 0) { |
50 | - if($denom && $denom!=0){ |
|
50 | + if ($denom && $denom != 0) { |
|
51 | 51 | return $num / $denom; |
52 | 52 | } |
53 | 53 | return $default; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param float $default Default value if denominator null or 0 |
62 | 62 | * @return float Percentage |
63 | 63 | */ |
64 | - public static function getPercentage($num, $denom, $default = 0){ |
|
64 | + public static function getPercentage($num, $denom, $default = 0) { |
|
65 | 65 | return 100 * self::safeDivision($num, $denom, $default); |
66 | 66 | } |
67 | 67 | |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * @param int $target The final max width/height |
73 | 73 | * @return array array of ($width, $height). One of them must be $target |
74 | 74 | */ |
75 | - static public function getResizedImageSize($file, $target=25){ |
|
76 | - list($width, $height, , ) = getimagesize($file); |
|
75 | + static public function getResizedImageSize($file, $target = 25) { |
|
76 | + list($width, $height,,) = getimagesize($file); |
|
77 | 77 | $max = max($width, $height); |
78 | 78 | $rapp = $target / $max; |
79 | 79 | $width = intval($rapp * $width); |
@@ -103,21 +103,21 @@ discard block |
||
103 | 103 | * @param int $length Length of the token, default to 32 |
104 | 104 | * @return string Random token |
105 | 105 | */ |
106 | - public static function generateRandomToken($length=32) { |
|
106 | + public static function generateRandomToken($length = 32) { |
|
107 | 107 | $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); |
108 | 108 | $len_chars = count($chars); |
109 | 109 | $token = ''; |
110 | 110 | |
111 | 111 | for ($i = 0; $i < $length; $i++) |
112 | - $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
112 | + $token .= $chars[mt_rand(0, $len_chars - 1)]; |
|
113 | 113 | |
114 | 114 | # Number of 32 char chunks |
115 | - $chunks = ceil( strlen($token) / 32 ); |
|
115 | + $chunks = ceil(strlen($token) / 32); |
|
116 | 116 | $md5token = ''; |
117 | 117 | |
118 | 118 | # Run each chunk through md5 |
119 | - for ( $i=1; $i<=$chunks; $i++ ) |
|
120 | - $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
119 | + for ($i = 1; $i <= $chunks; $i++) |
|
120 | + $md5token .= md5(substr($token, $i * 32 - 32, 32)); |
|
121 | 121 | |
122 | 122 | # Trim the token |
123 | 123 | return substr($md5token, 0, $length); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | protected static function getBase64EncryptionKey() { |
132 | 132 | $key = 'STANDARDKEYIFNOSERVER'; |
133 | - if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
133 | + if (!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
134 | 134 | $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
135 | 135 | |
136 | 136 | return $key; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param string $data Text to encrypt |
144 | 144 | * @return string Encrypted and encoded text |
145 | 145 | */ |
146 | - public static function encryptToSafeBase64($data){ |
|
146 | + public static function encryptToSafeBase64($data) { |
|
147 | 147 | $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
148 | 148 | $id = sodium_crypto_secretbox($data, $nonce, self::getBase64EncryptionKey()); |
149 | 149 | $encrypted = base64_encode($nonce.$id); |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | * @param string $encrypted Text to decrypt |
164 | 164 | * @return string Decrypted text |
165 | 165 | */ |
166 | - public static function decryptFromSafeBase64($encrypted){ |
|
166 | + public static function decryptFromSafeBase64($encrypted) { |
|
167 | 167 | $encrypted = str_replace('-', '+', $encrypted); |
168 | 168 | $encrypted = str_replace('_', '/', $encrypted); |
169 | 169 | $encrypted = str_replace('*', '=', $encrypted); |
170 | 170 | $encrypted = base64_decode($encrypted); |
171 | - if($encrypted === false) |
|
171 | + if ($encrypted === false) |
|
172 | 172 | throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
173 | 173 | |
174 | 174 | if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); |
181 | 181 | |
182 | - if($decrypted === false) { |
|
182 | + if ($decrypted === false) { |
|
183 | 183 | throw new \InvalidArgumentException('The message has been tampered with in transit.'); |
184 | 184 | } |
185 | 185 | |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | * @param string $string Filesystem encoded string to encode |
195 | 195 | * @return string UTF-8 encoded string |
196 | 196 | */ |
197 | - public static function encodeFileSystemToUtf8($string){ |
|
197 | + public static function encodeFileSystemToUtf8($string) { |
|
198 | 198 | if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
199 | - return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
199 | + return iconv('cp1252', 'utf-8//IGNORE', $string); |
|
200 | 200 | } |
201 | 201 | return $string; |
202 | 202 | } |
@@ -207,9 +207,9 @@ discard block |
||
207 | 207 | * @param string $string UTF-8 encoded string to encode |
208 | 208 | * @return string Filesystem encoded string |
209 | 209 | */ |
210 | - public static function encodeUtf8ToFileSystem($string){ |
|
210 | + public static function encodeUtf8ToFileSystem($string) { |
|
211 | 211 | if (preg_match('//u', $string) && strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
212 | - return iconv('utf-8', 'cp1252//IGNORE' , $string); |
|
212 | + return iconv('utf-8', 'cp1252//IGNORE', $string); |
|
213 | 213 | } |
214 | 214 | return $string; |
215 | 215 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @return boolean True if path valid |
223 | 223 | */ |
224 | 224 | public static function isValidPath($filename, $acceptfolder = FALSE) { |
225 | - if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
225 | + if (strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @return array Array of month short names |
235 | 235 | */ |
236 | 236 | public static function getCalendarShortMonths($calendarId = 0) { |
237 | - if(!isset(self::$calendarShortMonths[$calendarId])) { |
|
237 | + if (!isset(self::$calendarShortMonths[$calendarId])) { |
|
238 | 238 | $calendar_info = cal_info($calendarId); |
239 | 239 | self::$calendarShortMonths[$calendarId] = $calendar_info['abbrevmonths']; |
240 | 240 | } |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | * @param int $sosa Sosa number |
248 | 248 | * @return number |
249 | 249 | */ |
250 | - public static function getGeneration($sosa){ |
|
251 | - return(int)log($sosa, 2)+1; |
|
250 | + public static function getGeneration($sosa) { |
|
251 | + return(int)log($sosa, 2) + 1; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 |
@@ -108,16 +108,18 @@ discard block |
||
108 | 108 | $len_chars = count($chars); |
109 | 109 | $token = ''; |
110 | 110 | |
111 | - for ($i = 0; $i < $length; $i++) |
|
112 | - $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
111 | + for ($i = 0; $i < $length; $i++) { |
|
112 | + $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
113 | + } |
|
113 | 114 | |
114 | 115 | # Number of 32 char chunks |
115 | 116 | $chunks = ceil( strlen($token) / 32 ); |
116 | 117 | $md5token = ''; |
117 | 118 | |
118 | 119 | # Run each chunk through md5 |
119 | - for ( $i=1; $i<=$chunks; $i++ ) |
|
120 | - $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
120 | + for ( $i=1; $i<=$chunks; $i++ ) { |
|
121 | + $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
122 | + } |
|
121 | 123 | |
122 | 124 | # Trim the token |
123 | 125 | return substr($md5token, 0, $length); |
@@ -130,8 +132,9 @@ discard block |
||
130 | 132 | */ |
131 | 133 | protected static function getBase64EncryptionKey() { |
132 | 134 | $key = 'STANDARDKEYIFNOSERVER'; |
133 | - if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
134 | - $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
135 | + if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) { |
|
136 | + $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
137 | + } |
|
135 | 138 | |
136 | 139 | return $key; |
137 | 140 | } |
@@ -168,11 +171,13 @@ discard block |
||
168 | 171 | $encrypted = str_replace('_', '/', $encrypted); |
169 | 172 | $encrypted = str_replace('*', '=', $encrypted); |
170 | 173 | $encrypted = base64_decode($encrypted); |
171 | - if($encrypted === false) |
|
172 | - throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
|
174 | + if($encrypted === false) { |
|
175 | + throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
|
176 | + } |
|
173 | 177 | |
174 | - if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) |
|
175 | - throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
178 | + if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) { |
|
179 | + throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
180 | + } |
|
176 | 181 | |
177 | 182 | $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); |
178 | 183 | $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); |
@@ -222,7 +227,9 @@ discard block |
||
222 | 227 | * @return boolean True if path valid |
223 | 228 | */ |
224 | 229 | public static function isValidPath($filename, $acceptfolder = FALSE) { |
225 | - if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
230 | + if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) { |
|
231 | + return true; |
|
232 | + } |
|
226 | 233 | return false; |
227 | 234 | } |
228 | 235 |