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