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