| Total Complexity | 115 |
| Total Lines | 729 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Utility often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Utility, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | class Utility extends Common\SysUtility |
||
| 37 | { |
||
| 38 | //--------------- Custom module methods ----------------------------- |
||
| 39 | |||
| 40 | public static function expireAd(): void |
||
| 41 | { |
||
| 42 | global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $meta; |
||
| 43 | |||
| 44 | $datenow = \time(); |
||
| 45 | $message = ''; |
||
| 46 | |||
| 47 | $result5 = $xoopsDB->query('SELECT lid, title, expire, type, desctext, date_created, email, submitter, photo, valid, hits, comments, remind FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='Yes'"); |
||
| 48 | |||
| 49 | while (false !== [$lids, $title, $expire, $type, $desctext, $dateann, $email, $submitter, $photo, $valid, $hits, $comments, $remind] = $xoopsDB->fetchRow($result5)) { |
||
| 50 | $title = \htmlspecialchars($title, \ENT_QUOTES | \ENT_HTML5); |
||
| 51 | $expire = \htmlspecialchars($expire, \ENT_QUOTES | \ENT_HTML5); |
||
| 52 | $type = \htmlspecialchars($type, \ENT_QUOTES | \ENT_HTML5); |
||
| 53 | $desctext = &$myts->displayTarea($desctext, 1, 1, 1, 1, 1); |
||
| 54 | $submitter = \htmlspecialchars($submitter, \ENT_QUOTES | \ENT_HTML5); |
||
| 55 | $remind = \htmlspecialchars($remind, \ENT_QUOTES | \ENT_HTML5); |
||
| 56 | $supprdate = $dateann + ($expire * 86400); |
||
| 57 | $almost = $GLOBALS['xoopsModuleConfig']['adslight_almost']; |
||
| 58 | |||
| 59 | // give warning that add is about to expire |
||
| 60 | |||
| 61 | if ($almost > 0 && ($supprdate - $almost * 86400) < $datenow |
||
| 62 | && 'Yes' === $valid |
||
| 63 | && 0 === $remind) { |
||
| 64 | $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET remind='1' WHERE lid=${lids}"); |
||
| 65 | |||
| 66 | if ($email) { |
||
| 67 | $tags = []; |
||
| 68 | $subject = '' . \_ADSLIGHT_ALMOST . ''; |
||
| 69 | $tags['TITLE'] = $title; |
||
| 70 | $tags['HELLO'] = '' . \_ADSLIGHT_HELLO . ''; |
||
| 71 | $tags['YOUR_AD_ON'] = '' . \_ADSLIGHT_YOUR_AD_ON . ''; |
||
| 72 | $tags['VEDIT_AD'] = '' . \_ADSLIGHT_VEDIT_AD . ''; |
||
| 73 | $tags['YOUR_AD'] = '' . \_ADSLIGHT_YOUR_AD . ''; |
||
| 74 | $tags['SOON'] = '' . \_ADSLIGHT_SOON . ''; |
||
| 75 | $tags['VIEWED'] = '' . \_ADSLIGHT_VU . ''; |
||
| 76 | $tags['TIMES'] = '' . \_ADSLIGHT_TIMES . ''; |
||
| 77 | $tags['WEBMASTER'] = '' . \_ADSLIGHT_WEBMASTER . ''; |
||
| 78 | $tags['THANKS'] = '' . \_ADSLIGHT_THANKS . ''; |
||
| 79 | $tags['TYPE'] = static::getNameType($type); |
||
| 80 | $tags['DESCTEXT'] = $desctext; |
||
| 81 | $tags['HITS'] = $hits; |
||
| 82 | $tags['META_TITLE'] = $meta['title']; |
||
| 83 | $tags['SUBMITTER'] = $submitter; |
||
| 84 | $tags['DURATION'] = $expire; |
||
| 85 | $tags['LINK_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?' . '&lid=' . $lids; |
||
| 86 | $mail = \getMailer(); |
||
| 87 | $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/'); |
||
| 88 | $mail->setTemplate('listing_expires.tpl'); |
||
| 89 | $mail->useMail(); |
||
| 90 | $mail->multimailer->isHTML(true); |
||
| 91 | $mail->setFromName($meta['title']); |
||
| 92 | $mail->setFromEmail($xoopsConfig['adminmail']); |
||
| 93 | $mail->setToEmails($email); |
||
| 94 | $mail->setSubject($subject); |
||
| 95 | $mail->assign($tags); |
||
| 96 | $mail->send(); |
||
| 97 | echo $mail->getErrors(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | // expire ad |
||
| 102 | |||
| 103 | if ($supprdate < $datenow) { |
||
| 104 | if (0 !== $photo) { |
||
| 105 | $result2 = $xoopsDB->query('SELECT url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE lid=' . $xoopsDB->escape($lids)); |
||
| 106 | |||
| 107 | while (false !== [$url] = $xoopsDB->fetchRow($result2)) { |
||
| 108 | $destination = XOOPS_ROOT_PATH . '/uploads/adslight'; |
||
| 109 | $destination2 = XOOPS_ROOT_PATH . '/uploads/adslight/thumbs'; |
||
| 110 | $destination3 = XOOPS_ROOT_PATH . '/uploads/adslight/midsize'; |
||
| 111 | if (\is_file("${destination}/${url}")) { |
||
| 112 | \unlink("${destination}/${url}"); |
||
| 113 | } |
||
| 114 | if (\is_file("${destination2}/thumb_${url}")) { |
||
| 115 | \unlink("${destination2}/thumb_${url}"); |
||
| 116 | } |
||
| 117 | if (\is_file("${destination3}/resized_${url}")) { |
||
| 118 | \unlink("${destination3}/resized_${url}"); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lids)); |
||
| 124 | |||
| 125 | // Specification for Japan: |
||
| 126 | // $message = ""._ADS_HELLO." $submitter,\n\n"._ADS_STOP2."\n $type : $title\n $desctext\n"._ADS_STOP3."\n\n"._ADS_VU." $lu "._ADS_VU2."\n\n"._ADS_OTHER." ".XOOPS_URL."/modules/myAds\n\n"._ADS_THANK."\n\n"._ADS_TEAM." ".$meta['title']."\n".XOOPS_URL.""; |
||
| 127 | if ($email) { |
||
| 128 | $tags = []; |
||
| 129 | $subject = '' . \_ADSLIGHT_STOP . ''; |
||
| 130 | $tags['TITLE'] = $title; |
||
| 131 | $tags['HELLO'] = '' . \_ADSLIGHT_HELLO . ''; |
||
| 132 | $tags['TYPE'] = static::getNameType($type); |
||
| 133 | $tags['DESCTEXT'] = $desctext; |
||
| 134 | $tags['HITS'] = $hits; |
||
| 135 | $tags['META_TITLE'] = $meta['title'] ?? ''; |
||
| 136 | $tags['SUBMITTER'] = $submitter; |
||
| 137 | $tags['YOUR_AD_ON'] = '' . \_ADSLIGHT_YOUR_AD_ON . ''; |
||
| 138 | $tags['EXPIRED'] = '' . \_ADSLIGHT_EXPIRED . ''; |
||
| 139 | $tags['MESSTEXT'] = \stripslashes($message); |
||
| 140 | $tags['OTHER'] = '' . \_ADSLIGHT_OTHER . ''; |
||
| 141 | $tags['WEBMASTER'] = '' . \_ADSLIGHT_WEBMASTER . ''; |
||
| 142 | $tags['THANKS'] = '' . \_ADSLIGHT_THANKS . ''; |
||
| 143 | $tags['VIEWED'] = '' . \_ADSLIGHT_VU . ''; |
||
| 144 | $tags['TIMES'] = '' . \_ADSLIGHT_TIMES . ''; |
||
| 145 | $tags['TEAM'] = '' . \_ADSLIGHT_TEAM . ''; |
||
| 146 | $tags['DURATION'] = $expire; |
||
| 147 | $tags['LINK_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?' . '&lid=' . $lids; |
||
| 148 | $mail = \getMailer(); |
||
| 149 | $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/'); |
||
| 150 | $mail->setTemplate('listing_expired.tpl'); |
||
| 151 | $mail->useMail(); |
||
| 152 | $mail->multimailer->isHTML(true); |
||
| 153 | $mail->setFromName($meta['title']); |
||
| 154 | $mail->setFromEmail($xoopsConfig['adminmail']); |
||
| 155 | $mail->setToEmails($email); |
||
| 156 | $mail->setSubject($subject); |
||
| 157 | $mail->assign($tags); |
||
| 158 | $mail->send(); |
||
| 159 | echo $mail->getErrors(); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | //updates rating data in itemtable for a given user |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @param $sel_id |
||
| 169 | */ |
||
| 170 | public static function updateUserRating($sel_id): void |
||
| 171 | { |
||
| 172 | global $xoopsDB; |
||
| 173 | |||
| 174 | $usid = Request::getInt('usid', 0, 'GET'); |
||
|
|
|||
| 175 | |||
| 176 | $query = 'SELECT rating FROM ' . $xoopsDB->prefix('adslight_user_votedata') . ' WHERE usid=' . $xoopsDB->escape($sel_id) . ' '; |
||
| 177 | //echo $query; |
||
| 178 | $voteresult = $xoopsDB->query($query); |
||
| 179 | $votesDB = $xoopsDB->getRowsNum($voteresult); |
||
| 180 | $totalrating = 0; |
||
| 181 | while (false !== [$rating] = $xoopsDB->fetchRow($voteresult)) { |
||
| 182 | $totalrating += $rating; |
||
| 183 | } |
||
| 184 | $finalrating = $totalrating / $votesDB; |
||
| 185 | $finalrating = \number_format($finalrating, 4); |
||
| 186 | $query = 'UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET user_rating=${finalrating}, user_votes=${votesDB} WHERE usid=" . $xoopsDB->escape($sel_id) . ''; |
||
| 187 | //echo $query; |
||
| 188 | $xoopsDB->query($query) || exit(); |
||
| 189 | } |
||
| 190 | |||
| 191 | //updates rating data in itemtable for a given item |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param $sel_id |
||
| 195 | */ |
||
| 196 | public static function updateItemRating($sel_id): void |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @param $sel_id |
||
| 219 | * @param string $status |
||
| 220 | */ |
||
| 221 | public static function getTotalItems($sel_id, $status = ''): int |
||
| 222 | { |
||
| 223 | global $xoopsDB, $mytree; |
||
| 224 | $categories = self::getMyItemIds('adslight_view'); |
||
| 225 | $count = 0; |
||
| 226 | $arr = []; |
||
| 227 | if (\in_array($sel_id, $categories, true)) { |
||
| 228 | $query = 'SELECT SQL_CACHE count(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE cid=' . (int)$sel_id . " AND valid='Yes' AND status!='1'"; |
||
| 229 | |||
| 230 | $result = $xoopsDB->query($query); |
||
| 231 | [$thing] = $xoopsDB->fetchRow($result); |
||
| 232 | $count = $thing; |
||
| 233 | $arr = $mytree->getAllChildId($sel_id); |
||
| 234 | foreach ($arr as $iValue) { |
||
| 235 | if (\in_array($iValue, $categories, true)) { |
||
| 236 | $query2 = 'SELECT SQL_CACHE count(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE cid=' . (int)$iValue . " AND valid='Yes' AND status!='1'"; |
||
| 237 | |||
| 238 | $result2 = $xoopsDB->query($query2); |
||
| 239 | [$thing] = $xoopsDB->fetchRow($result2); |
||
| 240 | $count += $thing; |
||
| 241 | } |
||
| 242 | } |
||
| 243 | } |
||
| 244 | |||
| 245 | return (int)$count; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @param $permtype |
||
| 250 | */ |
||
| 251 | public static function getMyItemIds($permtype) |
||
| 269 | } |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Returns a module's option |
||
| 273 | * @param string $option module option's name |
||
| 274 | * @param string $repmodule |
||
| 275 | * |
||
| 276 | * @return bool|mixed option's value |
||
| 277 | */ |
||
| 278 | public static function getModuleOption($option, $repmodule = 'adslight') |
||
| 279 | { |
||
| 280 | global $xoopsModule; |
||
| 281 | $helper = \XoopsModules\Adslight\Helper::getInstance(); |
||
| 282 | static $tbloptions = []; |
||
| 283 | if (\is_array($tbloptions) && \array_key_exists($option, $tbloptions)) { |
||
| 284 | return $tbloptions[$option]; |
||
| 285 | } |
||
| 286 | |||
| 287 | $retval = false; |
||
| 288 | if (isset($GLOBALS['xoopsModuleConfig']) |
||
| 289 | && (\is_object($xoopsModule) |
||
| 290 | && $xoopsModule->getVar('dirname') === $repmodule |
||
| 291 | && $xoopsModule->getVar('isactive'))) { |
||
| 292 | if (isset($GLOBALS['xoopsModuleConfig'][$option])) { |
||
| 293 | $retval = $GLOBALS['xoopsModuleConfig'][$option]; |
||
| 294 | } |
||
| 295 | } else { |
||
| 296 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 297 | $moduleHandler = \xoops_getHandler('module'); |
||
| 298 | $module = $moduleHandler->getByDirname($repmodule); |
||
| 299 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 300 | $configHandler = \xoops_getHandler('config'); |
||
| 301 | if ($module) { |
||
| 302 | $moduleConfig = $configHandler->getConfigsByCat(0, $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 303 | if (null !== $helper->getConfig($option)) { |
||
| 304 | $retval = $helper->getConfig($option); |
||
| 305 | } |
||
| 306 | } |
||
| 307 | } |
||
| 308 | $tbloptions[$option] = $retval; |
||
| 309 | |||
| 310 | return $retval; |
||
| 311 | } |
||
| 312 | |||
| 313 | public static function showImage(): void |
||
| 314 | { |
||
| 315 | echo "<script type=\"text/javascript\">\n"; |
||
| 316 | echo "<!--\n\n"; |
||
| 317 | echo "function showimage() {\n"; |
||
| 318 | echo "if (!document.images)\n"; |
||
| 319 | echo "return\n"; |
||
| 320 | echo "document.images.avatar.src=\n"; |
||
| 321 | echo "'" . XOOPS_URL . "/modules/adslight/assets/images/img_cat/' + document.imcat.img.options[document.imcat.img.selectedIndex].value\n"; |
||
| 322 | echo "}\n\n"; |
||
| 323 | echo "//-->\n"; |
||
| 324 | echo "</script>\n"; |
||
| 325 | } |
||
| 326 | |||
| 327 | //Reusable Link Sorting Functions |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @param $orderby |
||
| 331 | */ |
||
| 332 | public static function convertOrderByIn($orderby): string |
||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @param $orderby |
||
| 367 | */ |
||
| 368 | public static function convertOrderByTrans($orderby): string |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @param $orderby |
||
| 401 | */ |
||
| 402 | public static function convertOrderByOut($orderby): string |
||
| 403 | { |
||
| 404 | if ('title ASC' === $orderby) { |
||
| 405 | $orderby = 'titleA'; |
||
| 406 | } |
||
| 407 | if ('date_created ASC' === $orderby) { |
||
| 408 | $orderby = 'dateA'; |
||
| 409 | } |
||
| 410 | if ('hits ASC' === $orderby) { |
||
| 411 | $orderby = 'hitsA'; |
||
| 412 | } |
||
| 413 | if ('price ASC' === $orderby) { |
||
| 414 | $orderby = 'priceA'; |
||
| 415 | } |
||
| 416 | if ('title DESC' === $orderby) { |
||
| 417 | $orderby = 'titleD'; |
||
| 418 | } |
||
| 419 | if ('date_created DESC' === $orderby) { |
||
| 420 | $orderby = 'dateD'; |
||
| 421 | } |
||
| 422 | if ('hits DESC' === $orderby) { |
||
| 423 | $orderby = 'hitsD'; |
||
| 424 | } |
||
| 425 | if ('price DESC' === $orderby) { |
||
| 426 | $orderby = 'priceD'; |
||
| 427 | } |
||
| 428 | |||
| 429 | return $orderby; |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @param $tablename |
||
| 434 | */ |
||
| 435 | public static function checkTableExists($tablename): bool |
||
| 436 | { |
||
| 437 | global $xoopsDB; |
||
| 438 | $result = $xoopsDB->queryF("SHOW TABLES LIKE '${tablename}'"); |
||
| 439 | |||
| 440 | return $xoopsDB->getRowsNum($result) > 0; |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @param $fieldname |
||
| 445 | * @param $table |
||
| 446 | */ |
||
| 447 | public static function checkFieldExists($fieldname, $table): bool |
||
| 448 | { |
||
| 449 | global $xoopsDB; |
||
| 450 | $result = $xoopsDB->queryF("SHOW COLUMNS FROM ${table} LIKE '${fieldname}'"); |
||
| 451 | |||
| 452 | return $xoopsDB->getRowsNum($result) > 0; |
||
| 453 | } |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @param $cid |
||
| 457 | */ |
||
| 458 | public static function getCatNameFromId($cid): bool |
||
| 459 | { |
||
| 460 | global $xoopsDB, $myts; |
||
| 461 | |||
| 462 | $sql = 'SELECT SQL_CACHE title FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid = '${cid}'"; |
||
| 463 | |||
| 464 | if (!$result = $xoopsDB->query($sql)) { |
||
| 465 | return false; |
||
| 466 | } |
||
| 467 | |||
| 468 | if (!$arr = $xoopsDB->fetchArray($result)) { |
||
| 469 | return false; |
||
| 470 | } |
||
| 471 | |||
| 472 | return $arr['title']; |
||
| 473 | } |
||
| 474 | |||
| 475 | |||
| 476 | public static function goCategory(): array |
||
| 477 | { |
||
| 478 | global $xoopsDB; |
||
| 479 | |||
| 480 | $xoopsTree = new \XoopsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
||
| 481 | $jump = XOOPS_URL . '/modules/adslight/viewcats.php?cid='; |
||
| 482 | \ob_start(); |
||
| 483 | $xoopsTree->makeMySelBox('title', 'title', 0, 1, 'pid', 'location="' . $jump . '"+this.options[this.selectedIndex].value'); |
||
| 484 | $block['selectbox'] = \ob_get_clean(); |
||
| 485 | |||
| 486 | return $block; |
||
| 487 | } |
||
| 488 | |||
| 489 | // ADSLIGHT Version 2 // |
||
| 490 | // Fonction rss.php RSS par categories |
||
| 491 | |||
| 492 | |||
| 493 | public static function returnAllAdsRss(): array |
||
| 494 | { |
||
| 495 | global $xoopsDB; |
||
| 496 | |||
| 497 | $cid = Request::getInt('cid', null, 'GET'); |
||
| 498 | |||
| 499 | $result = []; |
||
| 500 | |||
| 501 | $sql = 'SELECT lid, title, price, date_created, town FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='yes' AND cid=" . $xoopsDB->escape($cid) . ' ORDER BY date_created DESC'; |
||
| 502 | |||
| 503 | $resultValues = $xoopsDB->query($sql); |
||
| 504 | while (false !== ($resultTemp = $xoopsDB->fetchBoth($resultValues))) { |
||
| 505 | $result[] = $resultTemp; |
||
| 506 | } |
||
| 507 | |||
| 508 | return $result; |
||
| 509 | } |
||
| 510 | |||
| 511 | // Fonction fluxrss.php RSS Global |
||
| 512 | |||
| 513 | |||
| 514 | public static function returnAllAdsFluxRss(): array |
||
| 515 | { |
||
| 516 | global $xoopsDB; |
||
| 517 | |||
| 518 | $result = []; |
||
| 519 | |||
| 520 | $sql = 'SELECT lid, title, price, desctext, date_created, town FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='yes' ORDER BY date_created DESC LIMIT 0,15"; |
||
| 521 | |||
| 522 | $resultValues = $xoopsDB->query($sql); |
||
| 523 | while (false !== ($resultTemp = $xoopsDB->fetchBoth($resultValues))) { |
||
| 524 | $result[] = $resultTemp; |
||
| 525 | } |
||
| 526 | |||
| 527 | return $result; |
||
| 528 | } |
||
| 529 | |||
| 530 | /** |
||
| 531 | * @param $type |
||
| 532 | */ |
||
| 533 | public static function getNameType($type) |
||
| 534 | { |
||
| 535 | global $xoopsDB; |
||
| 536 | $sql = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . " WHERE id_type='" . $xoopsDB->escape($type) . "'"); |
||
| 537 | [$nom_type] = $xoopsDB->fetchRow($sql); |
||
| 538 | |||
| 539 | return $nom_type; |
||
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * @param $format |
||
| 544 | * @param $number |
||
| 545 | */ |
||
| 546 | public static function getMoneyFormat( |
||
| 547 | $format, |
||
| 548 | $number |
||
| 549 | ) { |
||
| 550 | $regex = '/%((?:[\^!\-]|\+|\(|\=.)*)(\d+)?' . '(?:#(\d+))?(?:\.(\d+))?([in%])/'; |
||
| 551 | if ('C' === \setlocale(\LC_MONETARY, 0)) { |
||
| 552 | \setlocale(\LC_MONETARY, ''); |
||
| 553 | } |
||
| 554 | \setlocale(\LC_ALL, 'en_US'); |
||
| 555 | // setlocale(LC_ALL, 'fr_FR'); |
||
| 556 | $locale = \localeconv(); |
||
| 557 | \preg_match_all($regex, $format, $matches, \PREG_SET_ORDER); |
||
| 558 | foreach ($matches as $fmatch) { |
||
| 559 | $value = (float)$number; |
||
| 560 | $flags = [ |
||
| 561 | 'fillchar' => \preg_match('#\=(.)#', $fmatch[1], $match) ? $match[1] : ' ', |
||
| 562 | 'nogroup' => \preg_match('#\^#', $fmatch[1]) > 0, |
||
| 563 | 'usesignal' => \preg_match('/\+|\(/', $fmatch[1], $match) ? $match[0] : '+', |
||
| 564 | 'nosimbol' => \preg_match('#\!#', $fmatch[1]) > 0, |
||
| 565 | 'isleft' => \preg_match('#\-#', $fmatch[1]) > 0, |
||
| 566 | ]; |
||
| 567 | $width = \trim($fmatch[2]) ? (int)$fmatch[2] : 0; |
||
| 568 | $left = \trim($fmatch[3]) ? (int)$fmatch[3] : 0; |
||
| 569 | $right = \trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits']; |
||
| 570 | $conversion = $fmatch[5]; |
||
| 571 | $positive = true; |
||
| 572 | if ($value < 0) { |
||
| 573 | $positive = false; |
||
| 574 | $value *= -1; |
||
| 575 | } |
||
| 576 | $letter = $positive ? 'p' : 'n'; |
||
| 577 | $prefix = $suffix = $cprefix = $csuffix = $signal = ''; |
||
| 578 | $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign']; |
||
| 579 | switch (true) { |
||
| 580 | case 1 === $locale["{$letter}_sign_posn"] |
||
| 581 | && '+' === $flags['usesignal']: |
||
| 582 | $prefix = $signal; |
||
| 583 | break; |
||
| 584 | case 2 === $locale["{$letter}_sign_posn"] |
||
| 585 | && '+' === $flags['usesignal']: |
||
| 586 | $suffix = $signal; |
||
| 587 | break; |
||
| 588 | case 3 === $locale["{$letter}_sign_posn"] |
||
| 589 | && '+' === $flags['usesignal']: |
||
| 590 | $cprefix = $signal; |
||
| 591 | break; |
||
| 592 | case 4 === $locale["{$letter}_sign_posn"] |
||
| 593 | && '+' === $flags['usesignal']: |
||
| 594 | $csuffix = $signal; |
||
| 595 | break; |
||
| 596 | case '(' === $flags['usesignal']: |
||
| 597 | case 0 === $locale["{$letter}_sign_posn"]: |
||
| 598 | $prefix = '('; |
||
| 599 | $suffix = ')'; |
||
| 600 | break; |
||
| 601 | } |
||
| 602 | if ($flags['nosimbol']) { |
||
| 603 | $currency = ''; |
||
| 604 | } else { |
||
| 605 | $currency = $cprefix . ('i' === $conversion ? $locale['int_curr_symbol'] : $locale['currency_symbol']) . $csuffix; |
||
| 606 | } |
||
| 607 | $space = $locale["{$letter}_sep_by_space"] ? ' ' : ''; |
||
| 608 | $value = \number_format( |
||
| 609 | $value, |
||
| 610 | $right, |
||
| 611 | $locale['mon_decimal_point'], |
||
| 612 | $flags['nogroup'] ? '' : $locale['mon_thousands_sep'] |
||
| 613 | ); |
||
| 614 | $value = @\explode($locale['mon_decimal_point'], $value); |
||
| 615 | $n = \mb_strlen($prefix) + \mb_strlen($currency) + \mb_strlen($value[0]); |
||
| 616 | if ($left > 0 && $left > $n) { |
||
| 617 | $value[0] = \str_repeat($flags['fillchar'], $left - $n) . $value[0]; |
||
| 618 | } |
||
| 619 | $value = \implode($locale['mon_decimal_point'], $value); |
||
| 620 | if ($locale["{$letter}_cs_precedes"]) { |
||
| 621 | $value = $prefix . $currency . $space . $value . $suffix; |
||
| 622 | } else { |
||
| 623 | $value = $prefix . $value . $space . $currency . $suffix; |
||
| 624 | } |
||
| 625 | if ($width > 0) { |
||
| 626 | $value = \str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ? \STR_PAD_RIGHT : \STR_PAD_LEFT); |
||
| 627 | } |
||
| 628 | $format = \str_replace($fmatch[0], $value, $format); |
||
| 629 | } |
||
| 630 | return $format; |
||
| 631 | } |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Saves permissions for the selected category |
||
| 635 | * |
||
| 636 | * saveCategory_Permissions() |
||
| 637 | * |
||
| 638 | * @param array $groups : group with granted permission |
||
| 639 | * @param $categoryId |
||
| 640 | * @param $permName |
||
| 641 | * @return bool : TRUE if the no errors occured |
||
| 642 | */ |
||
| 643 | public static function saveCategoryPermissions($groups, $categoryId, $permName): bool |
||
| 665 | } |
||
| 666 | |||
| 667 | /*********************************************************************** |
||
| 668 | * $fldVersion : dossier version de fancybox |
||
| 669 | ***********************************************************************/ |
||
| 670 | public static function load_lib_js(): void |
||
| 671 | { |
||
| 672 | global $xoTheme, $xoopsModuleConfig; |
||
| 673 | |||
| 674 | $fld = XOOPS_URL . '/modules/adslight/' . 'assets/'; |
||
| 675 | |||
| 676 | if (1 === $GLOBALS['xoopsModuleConfig']['adslight_lightbox']) { |
||
| 677 | // $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/plugins/jquery.lightbox.js'); |
||
| 678 | // $xoTheme->addStyleSheet(XOOPS_URL . '/browse.php?Frameworks/jquery/plugins/jquery.lightbox.js'); |
||
| 679 | |||
| 680 | $xoTheme->addScript($fld . '/js/lightbox/js/lightbox.js'); |
||
| 681 | $xoTheme->addStyleSheet($fld . '/js/lightbox/css/lightbox.css'); |
||
| 682 | } |
||
| 683 | //$xoTheme->addStyleSheet($fld . "/css/galery.css" type="text/css" media="screen"); |
||
| 684 | |||
| 685 | |||
| 686 | /* |
||
| 687 | if (1 == $GLOBALS['xoopsModuleConfig']['adslight_lightbox']) { |
||
| 688 | $header_lightbox = '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" > |
||
| 689 | <script type="text/javascript" src="assets/lightbox/js/jquery-1.7.2.min.js"></script> |
||
| 690 | <script type="text/javascript" src="assets/lightbox/js/jquery-ui-1.8.18.custom.min"></script> |
||
| 691 | <script type="text/javascript" src="assets/lightbox/js/jquery.smooth-scroll.min.js"></script> |
||
| 692 | <script type="text/javascript" src="assets/lightbox/js/lightbox.js"></script> |
||
| 693 | |||
| 694 | <link rel="stylesheet" href="assets/css/galery.css" type="text/css" media="screen" > |
||
| 695 | <link rel="stylesheet" type="text/css" media="screen" href="assets/lightbox/css/lightbox.css"></link>'; |
||
| 696 | } else { |
||
| 697 | $header_lightbox = '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" > |
||
| 698 | <link rel="stylesheet" href="assets/css/galery.css" type="text/css" media="screen" >'; |
||
| 699 | } |
||
| 700 | |||
| 701 | |||
| 702 | $fldVersion = "fancybox_215"; |
||
| 703 | $fbFolder = XOOPS_URL . "/Frameworks/" . $fldVersion; |
||
| 704 | //$modFolder = "modules/" . $module_dirname; |
||
| 705 | $modFolder = "modules/" . 'mediatheque'; |
||
| 706 | |||
| 707 | //$xoTheme->addStyleSheet($fModule . '/css/style.css'); |
||
| 708 | $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
| 709 | |||
| 710 | //to-do : a remplacer par jquery.mousewheel-3.0.6.pack.js |
||
| 711 | $xoTheme->addScript($fbFolder . "/jquery.mousewheel-3.0.4.pack.js"); |
||
| 712 | |||
| 713 | $xoTheme->addStyleSheet($fbFolder . "/jquery.fancybox.css?v=2.1.5"); |
||
| 714 | $xoTheme->addScript($fbFolder . "/jquery.fancybox.js?v=2.1.5"); |
||
| 715 | |||
| 716 | //----------------------------------------- |
||
| 717 | // OPTIONAL |
||
| 718 | $xoTheme->addStyleSheet($fbFolder . "/helpers/jquery.fancybox-buttons.css?v=1.0.5"); |
||
| 719 | $xoTheme->addScript($fbFolder . "/helpers/jquery.fancybox-buttons.js?v=1.0.5"); |
||
| 720 | |||
| 721 | $xoTheme->addStyleSheet($fbFolder . "/helpers/jquery.fancybox-thumbs.css?v=1.0.7"); |
||
| 722 | $xoTheme->addScript($fbFolder . "/helpers/jquery.fancybox-thumbs.js?v=1.0.7"); |
||
| 723 | |||
| 724 | $xoTheme->addScript($fbFolder . "/helpers/jquery.fancybox-media.js?v=1.0.6"); |
||
| 725 | |||
| 726 | //----------------------------------------- |
||
| 727 | |||
| 728 | |||
| 729 | |||
| 730 | $xoTheme->addScript($modFolder . "/js/media.fancybox.js"); |
||
| 731 | |||
| 732 | */ |
||
| 733 | } |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Currency Format |
||
| 737 | * |
||
| 738 | * @param float $number |
||
| 739 | * @param string $currency The 3-letter ISO 4217 currency code indicating the currency to use. |
||
| 740 | * @param string $localeCode (local language code, e.g. en_US) |
||
| 741 | * @return string formatted currency value |
||
| 742 | */ |
||
| 743 | public static function formatCurrency($number, $currency = 'USD', $localeCode = ''): ?string |
||
| 748 | } |
||
| 749 | |||
| 750 | /** |
||
| 751 | * Currency Format (temporary) |
||
| 752 | * |
||
| 753 | * @param float $number |
||
| 754 | * @param string $currency The 3-letter ISO 4217 currency code indicating the currency to use. |
||
| 755 | * @param string $currencySymbol |
||
| 756 | * @param int $currencyPosition |
||
| 757 | * @return string formatted currency value |
||
| 758 | */ |
||
| 759 | public static function formatCurrencyTemp($number, $currency = 'USD', $currencySymbol = '$', $currencyPosition = 0): string |
||
| 765 | } |
||
| 766 | } |
||
| 767 |