| Total Complexity | 154 |
| Total Lines | 982 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| 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 |
||
| 46 | class Utility |
||
| 47 | { |
||
| 48 | use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
||
|
|
|||
| 49 | |||
| 50 | use Common\ServerStats; // getServerStats Trait |
||
| 51 | |||
| 52 | use Common\FilesManagement; // Files Management Trait |
||
| 53 | |||
| 54 | //--------------- Custom module methods ----------------------------- |
||
| 55 | |||
| 56 | public static function expireAd() |
||
| 57 | { |
||
| 58 | global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $meta; |
||
| 59 | |||
| 60 | $datenow = time(); |
||
| 61 | $message = ''; |
||
| 62 | |||
| 63 | $result5 = $xoopsDB->query('SELECT lid, title, expire, type, desctext, date, email, submitter, photo, valid, hits, comments, remind FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='Yes'"); |
||
| 64 | |||
| 65 | while (false !== (list($lids, $title, $expire, $type, $desctext, $dateann, $email, $submitter, $photo, $valid, $hits, $comments, $remind) = $xoopsDB->fetchRow($result5))) { |
||
| 66 | $title = $myts->htmlSpecialChars($title); |
||
| 67 | $expire = $myts->htmlSpecialChars($expire); |
||
| 68 | $type = $myts->htmlSpecialChars($type); |
||
| 69 | $desctext = &$myts->displayTarea($desctext, 1, 1, 1, 1, 1); |
||
| 70 | $submitter = $myts->htmlSpecialChars($submitter); |
||
| 71 | $remind = $myts->htmlSpecialChars($remind); |
||
| 72 | $supprdate = $dateann + ($expire * 86400); |
||
| 73 | $almost = $GLOBALS['xoopsModuleConfig']['adslight_almost']; |
||
| 74 | |||
| 75 | // give warning that add is about to expire |
||
| 76 | |||
| 77 | if ($almost > 0 && ($supprdate - $almost * 86400) < $datenow |
||
| 78 | && 'Yes' === $valid |
||
| 79 | && 0 == $remind) { |
||
| 80 | $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET remind='1' WHERE lid=$lids"); |
||
| 81 | |||
| 82 | if ($email) { |
||
| 83 | $tags = []; |
||
| 84 | $subject = '' . _ADSLIGHT_ALMOST . ''; |
||
| 85 | $tags['TITLE'] = $title; |
||
| 86 | $tags['HELLO'] = '' . _ADSLIGHT_HELLO . ''; |
||
| 87 | $tags['YOUR_AD_ON'] = '' . _ADSLIGHT_YOUR_AD_ON . ''; |
||
| 88 | $tags['VEDIT_AD'] = '' . _ADSLIGHT_VEDIT_AD . ''; |
||
| 89 | $tags['YOUR_AD'] = '' . _ADSLIGHT_YOUR_AD . ''; |
||
| 90 | $tags['SOON'] = '' . _ADSLIGHT_SOON . ''; |
||
| 91 | $tags['VIEWED'] = '' . _ADSLIGHT_VU . ''; |
||
| 92 | $tags['TIMES'] = '' . _ADSLIGHT_TIMES . ''; |
||
| 93 | $tags['WEBMASTER'] = '' . _ADSLIGHT_WEBMASTER . ''; |
||
| 94 | $tags['THANKS'] = '' . _ADSLIGHT_THANKS . ''; |
||
| 95 | $tags['TYPE'] = static::getNameType($type); |
||
| 96 | $tags['DESCTEXT'] = $desctext; |
||
| 97 | $tags['HITS'] = $hits; |
||
| 98 | $tags['META_TITLE'] = $meta['title']; |
||
| 99 | $tags['SUBMITTER'] = $submitter; |
||
| 100 | $tags['DURATION'] = $expire; |
||
| 101 | $tags['LINK_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?' . '&lid=' . $lids; |
||
| 102 | $mail = &getMailer(); |
||
| 103 | $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/'); |
||
| 104 | $mail->setTemplate('listing_expires.tpl'); |
||
| 105 | $mail->useMail(); |
||
| 106 | $mail->multimailer->isHTML(true); |
||
| 107 | $mail->setFromName($meta['title']); |
||
| 108 | $mail->setFromEmail($xoopsConfig['adminmail']); |
||
| 109 | $mail->setToEmails($email); |
||
| 110 | $mail->setSubject($subject); |
||
| 111 | $mail->assign($tags); |
||
| 112 | $mail->send(); |
||
| 113 | echo $mail->getErrors(); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | // expire ad |
||
| 118 | |||
| 119 | if ($supprdate < $datenow) { |
||
| 120 | if (0 != $photo) { |
||
| 121 | $result2 = $xoopsDB->query('SELECT url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE lid=' . $xoopsDB->escape($lids)); |
||
| 122 | |||
| 123 | while (false !== (list($url) = $xoopsDB->fetchRow($result2))) { |
||
| 124 | $destination = XOOPS_ROOT_PATH . '/uploads/adslight'; |
||
| 125 | $destination2 = XOOPS_ROOT_PATH . '/uploads/adslight/thumbs'; |
||
| 126 | $destination3 = XOOPS_ROOT_PATH . '/uploads/adslight/midsize'; |
||
| 127 | if (file_exists("$destination/$url")) { |
||
| 128 | unlink("$destination/$url"); |
||
| 129 | } |
||
| 130 | if (file_exists("$destination2/thumb_$url")) { |
||
| 131 | unlink("$destination2/thumb_$url"); |
||
| 132 | } |
||
| 133 | if (file_exists("$destination3/resized_$url")) { |
||
| 134 | unlink("$destination3/resized_$url"); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lids)); |
||
| 140 | |||
| 141 | // Specification for Japan: |
||
| 142 | // $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.""; |
||
| 143 | if ($email) { |
||
| 144 | $tags = []; |
||
| 145 | $subject = '' . _ADSLIGHT_STOP . ''; |
||
| 146 | $tags['TITLE'] = $title; |
||
| 147 | $tags['HELLO'] = '' . _ADSLIGHT_HELLO . ''; |
||
| 148 | $tags['TYPE'] = static::getNameType($type); |
||
| 149 | $tags['DESCTEXT'] = $desctext; |
||
| 150 | $tags['HITS'] = $hits; |
||
| 151 | $tags['META_TITLE'] = $meta['title']; |
||
| 152 | $tags['SUBMITTER'] = $submitter; |
||
| 153 | $tags['YOUR_AD_ON'] = '' . _ADSLIGHT_YOUR_AD_ON . ''; |
||
| 154 | $tags['EXPIRED'] = '' . _ADSLIGHT_EXPIRED . ''; |
||
| 155 | $tags['MESSTEXT'] = stripslashes($message); |
||
| 156 | $tags['OTHER'] = '' . _ADSLIGHT_OTHER . ''; |
||
| 157 | $tags['WEBMASTER'] = '' . _ADSLIGHT_WEBMASTER . ''; |
||
| 158 | $tags['THANKS'] = '' . _ADSLIGHT_THANKS . ''; |
||
| 159 | $tags['VIEWED'] = '' . _ADSLIGHT_VU . ''; |
||
| 160 | $tags['TIMES'] = '' . _ADSLIGHT_TIMES . ''; |
||
| 161 | $tags['TEAM'] = '' . _ADSLIGHT_TEAM . ''; |
||
| 162 | $tags['DURATION'] = $expire; |
||
| 163 | $tags['LINK_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?' . '&lid=' . $lids; |
||
| 164 | $mail = &getMailer(); |
||
| 165 | $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/'); |
||
| 166 | $mail->setTemplate('listing_expired.tpl'); |
||
| 167 | $mail->useMail(); |
||
| 168 | $mail->multimailer->isHTML(true); |
||
| 169 | $mail->setFromName($meta['title']); |
||
| 170 | $mail->setFromEmail($xoopsConfig['adminmail']); |
||
| 171 | $mail->setToEmails($email); |
||
| 172 | $mail->setSubject($subject); |
||
| 173 | $mail->assign($tags); |
||
| 174 | $mail->send(); |
||
| 175 | echo $mail->getErrors(); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | //updates rating data in itemtable for a given user |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param $sel_id |
||
| 185 | */ |
||
| 186 | public static function updateUserRating($sel_id) |
||
| 187 | { |
||
| 188 | global $xoopsDB; |
||
| 189 | |||
| 190 | $usid = Request::getInt('usid', 0, 'GET'); |
||
| 191 | |||
| 192 | $query = 'SELECT rating FROM ' . $xoopsDB->prefix('adslight_user_votedata') . ' WHERE usid=' . $xoopsDB->escape($sel_id) . ' '; |
||
| 193 | //echo $query; |
||
| 194 | $voteresult = $xoopsDB->query($query); |
||
| 195 | $votesDB = $xoopsDB->getRowsNum($voteresult); |
||
| 196 | $totalrating = 0; |
||
| 197 | while (false !== (list($rating) = $xoopsDB->fetchRow($voteresult))) { |
||
| 198 | $totalrating += $rating; |
||
| 199 | } |
||
| 200 | $finalrating = $totalrating / $votesDB; |
||
| 201 | $finalrating = number_format($finalrating, 4); |
||
| 202 | $query = 'UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET user_rating=$finalrating, user_votes=$votesDB WHERE usid=" . $xoopsDB->escape($sel_id) . ''; |
||
| 203 | //echo $query; |
||
| 204 | $xoopsDB->query($query) || exit(); |
||
| 205 | } |
||
| 206 | |||
| 207 | //updates rating data in itemtable for a given item |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param $sel_id |
||
| 211 | */ |
||
| 212 | public static function updateItemRating($sel_id) |
||
| 213 | { |
||
| 214 | global $xoopsDB; |
||
| 215 | |||
| 216 | $lid = Request::getInt('lid', 0, 'GET'); |
||
| 217 | |||
| 218 | $query = 'SELECT rating FROM ' . $xoopsDB->prefix('adslight_item_votedata') . ' WHERE lid=' . $xoopsDB->escape($sel_id) . ' '; |
||
| 219 | //echo $query; |
||
| 220 | $voteresult = $xoopsDB->query($query); |
||
| 221 | $votesDB = $xoopsDB->getRowsNum($voteresult); |
||
| 222 | $totalrating = 0; |
||
| 223 | while (false !== (list($rating) = $xoopsDB->fetchRow($voteresult))) { |
||
| 224 | $totalrating += $rating; |
||
| 225 | } |
||
| 226 | $finalrating = $totalrating / $votesDB; |
||
| 227 | $finalrating = number_format($finalrating, 4); |
||
| 228 | $query = 'UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET item_rating=$finalrating, item_votes=$votesDB WHERE lid=" . $xoopsDB->escape($sel_id) . ''; |
||
| 229 | //echo $query; |
||
| 230 | $xoopsDB->query($query) || exit(); |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @param $sel_id |
||
| 235 | * @param string $status |
||
| 236 | * |
||
| 237 | * @return int |
||
| 238 | */ |
||
| 239 | public static function getTotalItems($sel_id, $status = '') |
||
| 240 | { |
||
| 241 | global $xoopsDB, $mytree; |
||
| 242 | $categories = self::getMyItemIds('adslight_view'); |
||
| 243 | $count = 0; |
||
| 244 | $arr = []; |
||
| 245 | if (in_array($sel_id, $categories)) { |
||
| 246 | $query = 'SELECT SQL_CACHE count(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE cid=' . (int)$sel_id . " AND valid='Yes' AND status!='1'"; |
||
| 247 | |||
| 248 | $result = $xoopsDB->query($query); |
||
| 249 | list($thing) = $xoopsDB->fetchRow($result); |
||
| 250 | $count = $thing; |
||
| 251 | $arr = $mytree->getAllChildId($sel_id); |
||
| 252 | foreach ($arr as $iValue) { |
||
| 253 | if (in_array($iValue, $categories)) { |
||
| 254 | $query2 = 'SELECT SQL_CACHE count(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE cid=' . (int)$iValue . " AND valid='Yes' AND status!='1'"; |
||
| 255 | |||
| 256 | $result2 = $xoopsDB->query($query2); |
||
| 257 | list($thing) = $xoopsDB->fetchRow($result2); |
||
| 258 | $count += $thing; |
||
| 259 | } |
||
| 260 | } |
||
| 261 | } |
||
| 262 | |||
| 263 | return $count; |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @param $permtype |
||
| 268 | * |
||
| 269 | * @return mixed |
||
| 270 | */ |
||
| 271 | public static function getMyItemIds($permtype) |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Returns a module's option |
||
| 293 | * @param string $option module option's name |
||
| 294 | * @param string $repmodule |
||
| 295 | * |
||
| 296 | * @return bool|mixed option's value |
||
| 297 | */ |
||
| 298 | public static function getModuleOption($option, $repmodule = 'adslight') |
||
| 299 | { |
||
| 300 | global $xoopsModule; |
||
| 301 | /** @var \XoopsModules\Adslight\Helper $helper */ |
||
| 302 | $helper = \XoopsModules\Adslight\Helper::getInstance(); |
||
| 303 | static $tbloptions = []; |
||
| 304 | if (is_array($tbloptions) && array_key_exists($option, $tbloptions)) { |
||
| 305 | return $tbloptions[$option]; |
||
| 306 | } |
||
| 307 | |||
| 308 | $retval = false; |
||
| 309 | if (isset($GLOBALS['xoopsModuleConfig']) |
||
| 310 | && (is_object($xoopsModule) |
||
| 311 | && $xoopsModule->getVar('dirname') == $repmodule |
||
| 312 | && $xoopsModule->getVar('isactive'))) { |
||
| 313 | if (isset($GLOBALS['xoopsModuleConfig'][$option])) { |
||
| 314 | $retval = $GLOBALS['xoopsModuleConfig'][$option]; |
||
| 315 | } |
||
| 316 | } else { |
||
| 317 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 318 | $moduleHandler = xoops_getHandler('module'); |
||
| 319 | $module = $moduleHandler->getByDirname($repmodule); |
||
| 320 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 321 | $configHandler = xoops_getHandler('config'); |
||
| 322 | if ($module) { |
||
| 323 | $moduleConfig = $configHandler->getConfigsByCat(0, $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 324 | if (null !== $helper->getConfig($option)) { |
||
| 325 | $retval = $helper->getConfig($option); |
||
| 326 | } |
||
| 327 | } |
||
| 328 | } |
||
| 329 | $tbloptions[$option] = $retval; |
||
| 330 | |||
| 331 | return $retval; |
||
| 332 | } |
||
| 333 | |||
| 334 | public static function showImage() |
||
| 335 | { |
||
| 336 | echo "<script type=\"text/javascript\">\n"; |
||
| 337 | echo "<!--\n\n"; |
||
| 338 | echo "function showimage() {\n"; |
||
| 339 | echo "if (!document.images)\n"; |
||
| 340 | echo "return\n"; |
||
| 341 | echo "document.images.avatar.src=\n"; |
||
| 342 | echo "'" . XOOPS_URL . "/modules/adslight/assets/images/img_cat/' + document.imcat.img.options[document.imcat.img.selectedIndex].value\n"; |
||
| 343 | echo "}\n\n"; |
||
| 344 | echo "//-->\n"; |
||
| 345 | echo "</script>\n"; |
||
| 346 | } |
||
| 347 | |||
| 348 | //Reusable Link Sorting Functions |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param $orderby |
||
| 352 | * |
||
| 353 | * @return string |
||
| 354 | */ |
||
| 355 | public static function convertOrderByIn($orderby) |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @param $orderby |
||
| 390 | * |
||
| 391 | * @return string |
||
| 392 | */ |
||
| 393 | public static function convertOrderByTrans($orderby) |
||
| 394 | { |
||
| 395 | $orderbyTrans = ''; |
||
| 396 | if ('hits ASC' === $orderby) { |
||
| 397 | $orderbyTrans = '' . _ADSLIGHT_POPULARITYLTOM . ''; |
||
| 398 | } |
||
| 399 | if ('hits DESC' === $orderby) { |
||
| 400 | $orderbyTrans = '' . _ADSLIGHT_POPULARITYMTOL . ''; |
||
| 401 | } |
||
| 402 | if ('title ASC' === $orderby) { |
||
| 403 | $orderbyTrans = '' . _ADSLIGHT_TITLEATOZ . ''; |
||
| 404 | } |
||
| 405 | if ('title DESC' === $orderby) { |
||
| 406 | $orderbyTrans = '' . _ADSLIGHT_TITLEZTOA . ''; |
||
| 407 | } |
||
| 408 | if ('date ASC' === $orderby) { |
||
| 409 | $orderbyTrans = '' . _ADSLIGHT_DATEOLD . ''; |
||
| 410 | } |
||
| 411 | if ('date DESC' === $orderby) { |
||
| 412 | $orderbyTrans = '' . _ADSLIGHT_DATENEW . ''; |
||
| 413 | } |
||
| 414 | if ('price ASC' === $orderby) { |
||
| 415 | $orderbyTrans = _ADSLIGHT_PRICELTOH; |
||
| 416 | } |
||
| 417 | if ('price DESC' === $orderby) { |
||
| 418 | $orderbyTrans = '' . _ADSLIGHT_PRICEHTOL . ''; |
||
| 419 | } |
||
| 420 | |||
| 421 | return $orderbyTrans; |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @param $orderby |
||
| 426 | * |
||
| 427 | * @return string |
||
| 428 | */ |
||
| 429 | public static function convertOrderByOut($orderby) |
||
| 430 | { |
||
| 431 | if ('title ASC' === $orderby) { |
||
| 432 | $orderby = 'titleA'; |
||
| 433 | } |
||
| 434 | if ('date ASC' === $orderby) { |
||
| 435 | $orderby = 'dateA'; |
||
| 436 | } |
||
| 437 | if ('hits ASC' === $orderby) { |
||
| 438 | $orderby = 'hitsA'; |
||
| 439 | } |
||
| 440 | if ('price ASC' === $orderby) { |
||
| 441 | $orderby = 'priceA'; |
||
| 442 | } |
||
| 443 | if ('title DESC' === $orderby) { |
||
| 444 | $orderby = 'titleD'; |
||
| 445 | } |
||
| 446 | if ('date DESC' === $orderby) { |
||
| 447 | $orderby = 'dateD'; |
||
| 448 | } |
||
| 449 | if ('hits DESC' === $orderby) { |
||
| 450 | $orderby = 'hitsD'; |
||
| 451 | } |
||
| 452 | if ('price DESC' === $orderby) { |
||
| 453 | $orderby = 'priceD'; |
||
| 454 | } |
||
| 455 | |||
| 456 | return $orderby; |
||
| 457 | } |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @param string $caption |
||
| 461 | * @param string $name |
||
| 462 | * @param string $value |
||
| 463 | * @param string $width |
||
| 464 | * @param string $height |
||
| 465 | * @param string $supplemental |
||
| 466 | * |
||
| 467 | * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor |
||
| 468 | */ |
||
| 469 | public static function getEditor($caption, $name, $value = '', $width = '100%', $height = '300px', $supplemental = '') |
||
| 470 | { |
||
| 471 | global $xoopsModule; |
||
| 472 | $options = []; |
||
| 473 | $isAdmin = $GLOBALS['xoopsUser']->isAdmin($xoopsModule->getVar('mid')); |
||
| 474 | |||
| 475 | if (class_exists('XoopsFormEditor')) { |
||
| 476 | $options['name'] = $name; |
||
| 477 | $options['value'] = $value; |
||
| 478 | $options['rows'] = 20; |
||
| 479 | $options['cols'] = '100%'; |
||
| 480 | $options['width'] = $width; |
||
| 481 | $options['height'] = $height; |
||
| 482 | if ($isAdmin) { |
||
| 483 | $myEditor = new \XoopsFormEditor(ucfirst($name), $GLOBALS['xoopsModuleConfig']['adslightAdminUser'], $options, $nohtml = false, $onfailure = 'textarea'); |
||
| 484 | } else { |
||
| 485 | $myEditor = new \XoopsFormEditor(ucfirst($name), $GLOBALS['xoopsModuleConfig']['adslightEditorUser'], $options, $nohtml = false, $onfailure = 'textarea'); |
||
| 486 | } |
||
| 487 | } else { |
||
| 488 | $myEditor = new \XoopsFormDhtmlTextArea(ucfirst($name), $name, $value, '100%', '100%'); |
||
| 489 | } |
||
| 490 | |||
| 491 | // $form->addElement($descEditor); |
||
| 492 | |||
| 493 | return $myEditor; |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * @param $tablename |
||
| 498 | * |
||
| 499 | * @return bool |
||
| 500 | */ |
||
| 501 | public static function checkTableExists($tablename) |
||
| 502 | { |
||
| 503 | global $xoopsDB; |
||
| 504 | $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
||
| 505 | |||
| 506 | return ($xoopsDB->getRowsNum($result) > 0); |
||
| 507 | } |
||
| 508 | |||
| 509 | /** |
||
| 510 | * @param $fieldname |
||
| 511 | * @param $table |
||
| 512 | * |
||
| 513 | * @return bool |
||
| 514 | */ |
||
| 515 | public static function checkFieldExists($fieldname, $table) |
||
| 516 | { |
||
| 517 | global $xoopsDB; |
||
| 518 | $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
||
| 519 | |||
| 520 | return ($xoopsDB->getRowsNum($result) > 0); |
||
| 521 | } |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @param $field |
||
| 525 | * @param $table |
||
| 526 | * |
||
| 527 | * @return mixed |
||
| 528 | */ |
||
| 529 | public static function addField($field, $table) |
||
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * @param $cid |
||
| 539 | * |
||
| 540 | * @return bool |
||
| 541 | */ |
||
| 542 | public static function getCatNameFromId($cid) |
||
| 543 | { |
||
| 544 | global $xoopsDB, $myts; |
||
| 545 | |||
| 546 | $sql = 'SELECT SQL_CACHE title FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid = '$cid'"; |
||
| 547 | |||
| 548 | if (!$result = $xoopsDB->query($sql)) { |
||
| 549 | return false; |
||
| 550 | } |
||
| 551 | |||
| 552 | if (!$arr = $xoopsDB->fetchArray($result)) { |
||
| 553 | return false; |
||
| 554 | } |
||
| 555 | |||
| 556 | $title = $arr['title']; |
||
| 557 | |||
| 558 | return $title; |
||
| 559 | } |
||
| 560 | |||
| 561 | /** |
||
| 562 | * @return mixed |
||
| 563 | */ |
||
| 564 | public static function goCategory() |
||
| 575 | } |
||
| 576 | |||
| 577 | // ADSLIGHT Version 2 // |
||
| 578 | // Fonction rss.php RSS par categories |
||
| 579 | |||
| 580 | /** |
||
| 581 | * @return array |
||
| 582 | */ |
||
| 583 | public static function returnAllAdsRss() |
||
| 584 | { |
||
| 585 | global $xoopsDB; |
||
| 586 | |||
| 587 | $cid = Request::getInt('cid', null, 'GET'); |
||
| 588 | |||
| 589 | $result = []; |
||
| 590 | |||
| 591 | $sql = 'SELECT lid, title, price, date, town FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='yes' AND cid=" . $xoopsDB->escape($cid) . ' ORDER BY date DESC'; |
||
| 592 | |||
| 593 | $resultValues = $xoopsDB->query($sql); |
||
| 594 | while (false !== ($resultTemp = $xoopsDB->fetchBoth($resultValues))) { |
||
| 595 | $result[] = $resultTemp; |
||
| 596 | } |
||
| 597 | |||
| 598 | return $result; |
||
| 599 | } |
||
| 600 | |||
| 601 | // Fonction fluxrss.php RSS Global |
||
| 602 | |||
| 603 | /** |
||
| 604 | * @return array |
||
| 605 | */ |
||
| 606 | public static function returnAllAdsFluxRss() |
||
| 607 | { |
||
| 608 | global $xoopsDB; |
||
| 609 | |||
| 610 | $result = []; |
||
| 611 | |||
| 612 | $sql = 'SELECT lid, title, price, desctext, date, town FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='yes' ORDER BY date DESC LIMIT 0,15"; |
||
| 613 | |||
| 614 | $resultValues = $xoopsDB->query($sql); |
||
| 615 | while (false !== ($resultTemp = $xoopsDB->fetchBoth($resultValues))) { |
||
| 616 | $result[] = $resultTemp; |
||
| 617 | } |
||
| 618 | |||
| 619 | return $result; |
||
| 620 | } |
||
| 621 | |||
| 622 | /** |
||
| 623 | * @param $type |
||
| 624 | * |
||
| 625 | * @return mixed |
||
| 626 | */ |
||
| 627 | public static function getNameType($type) |
||
| 634 | } |
||
| 635 | |||
| 636 | /** |
||
| 637 | * @param $format |
||
| 638 | * @param $number |
||
| 639 | * |
||
| 640 | * @return mixed |
||
| 641 | */ |
||
| 642 | public static function getMoneyFormat($format, $number) |
||
| 643 | { |
||
| 644 | $regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?' . '(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/'; |
||
| 645 | if ('C' === setlocale(LC_MONETARY, 0)) { |
||
| 646 | setlocale(LC_MONETARY, ''); |
||
| 647 | } |
||
| 648 | |||
| 649 | //JJDai |
||
| 650 | // setlocale(LC_ALL, 'en_US'); |
||
| 651 | //setlocale(LC_ALL, 'fr_FR'); |
||
| 652 | //$symb = $helper->getConfig('adslight_currency_symbol'); |
||
| 653 | |||
| 654 | $locale = localeconv(); |
||
| 655 | preg_match_all($regex, $format, $matches, PREG_SET_ORDER); |
||
| 656 | foreach ($matches as $fmatch) { |
||
| 657 | $value = (float)$number; |
||
| 658 | $flags = [ |
||
| 659 | 'fillchar' => preg_match('/\=(.)/', $fmatch[1], $match) ? $match[1] : ' ', |
||
| 660 | 'nogroup' => preg_match('/\^/', $fmatch[1]) > 0, |
||
| 661 | 'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ? $match[0] : '+', |
||
| 662 | 'nosimbol' => preg_match('/\!/', $fmatch[1]) > 0, |
||
| 663 | 'isleft' => preg_match('/\-/', $fmatch[1]) > 0, |
||
| 664 | ]; |
||
| 665 | $width = trim($fmatch[2]) ? (int)$fmatch[2] : 0; |
||
| 666 | $left = trim($fmatch[3]) ? (int)$fmatch[3] : 0; |
||
| 667 | $right = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits']; |
||
| 668 | $conversion = $fmatch[5]; |
||
| 669 | |||
| 670 | $positive = true; |
||
| 671 | if ($value < 0) { |
||
| 672 | $positive = false; |
||
| 673 | $value *= -1; |
||
| 674 | } |
||
| 675 | $letter = $positive ? 'p' : 'n'; |
||
| 676 | |||
| 677 | $prefix = $suffix = $cprefix = $csuffix = $signal = ''; |
||
| 678 | |||
| 679 | $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign']; |
||
| 680 | switch (true) { |
||
| 681 | case 1 == $locale["{$letter}_sign_posn"] |
||
| 682 | && '+' == $flags['usesignal']: |
||
| 683 | $prefix = $signal; |
||
| 684 | break; |
||
| 685 | case 2 == $locale["{$letter}_sign_posn"] |
||
| 686 | && '+' == $flags['usesignal']: |
||
| 687 | $suffix = $signal; |
||
| 688 | break; |
||
| 689 | case 3 == $locale["{$letter}_sign_posn"] |
||
| 690 | && '+' == $flags['usesignal']: |
||
| 691 | $cprefix = $signal; |
||
| 692 | break; |
||
| 693 | case 4 == $locale["{$letter}_sign_posn"] |
||
| 694 | && '+' == $flags['usesignal']: |
||
| 695 | $csuffix = $signal; |
||
| 696 | break; |
||
| 697 | case '(' === $flags['usesignal']: |
||
| 698 | case 0 == $locale["{$letter}_sign_posn"]: |
||
| 699 | $prefix = '('; |
||
| 700 | $suffix = ')'; |
||
| 701 | break; |
||
| 702 | } |
||
| 703 | if (!$flags['nosimbol']) { |
||
| 704 | $currency = $cprefix . ('i' === $conversion ? $locale['int_curr_symbol'] : $locale['currency_symbol']) . $csuffix; |
||
| 705 | } else { |
||
| 706 | $currency = ''; |
||
| 707 | } |
||
| 708 | $space = $locale["{$letter}_sep_by_space"] ? ' ' : ''; |
||
| 709 | |||
| 710 | $value = number_format($value, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep']); |
||
| 711 | $value = @explode($locale['mon_decimal_point'], $value); |
||
| 712 | |||
| 713 | $n = mb_strlen($prefix) + mb_strlen($currency) + mb_strlen($value[0]); |
||
| 714 | if ($left > 0 && $left > $n) { |
||
| 715 | $value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0]; |
||
| 716 | } |
||
| 717 | $value = implode($locale['mon_decimal_point'], $value); |
||
| 718 | if ($locale["{$letter}_cs_precedes"]) { |
||
| 719 | $value = $prefix . $currency . $space . $value . $suffix; |
||
| 720 | } else { |
||
| 721 | $value = $prefix . $value . $space . $currency . $suffix; |
||
| 722 | } |
||
| 723 | if ($width > 0) { |
||
| 724 | $value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ? STR_PAD_RIGHT : STR_PAD_LEFT); |
||
| 725 | } |
||
| 726 | |||
| 727 | $format = str_replace($fmatch[0], $value, $format); |
||
| 728 | } |
||
| 729 | |||
| 730 | return $format; |
||
| 731 | } |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Saves permissions for the selected category |
||
| 735 | * |
||
| 736 | * saveCategory_Permissions() |
||
| 737 | * |
||
| 738 | * @param array $groups : group with granted permission |
||
| 739 | * @param $categoryId |
||
| 740 | * @param $permName |
||
| 741 | * @return bool : TRUE if the no errors occured |
||
| 742 | */ |
||
| 743 | public static function saveCategoryPermissions($groups, $categoryId, $permName) |
||
| 744 | { |
||
| 745 | global $xoopsModule; |
||
| 746 | /** @var \XoopsModules\Adslight\Helper $helper */ |
||
| 747 | $helper = \XoopsModules\Adslight\Helper::getInstance(); |
||
| 748 | |||
| 749 | $result = true; |
||
| 750 | // $xoopsModule = sf_getModuleInfo(); |
||
| 751 | // $moduleId = $helper->getModule()->getVar('mid'); |
||
| 752 | $moduleId = $xoopsModule->getVar('mid'); |
||
| 753 | |||
| 754 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 755 | // First, if the permissions are already there, delete them |
||
| 756 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 757 | $grouppermHandler->deleteByModule($moduleId, $permName, $categoryId); |
||
| 758 | // Save the new permissions |
||
| 759 | if (count($groups) > 0) { |
||
| 760 | foreach ($groups as $groupId) { |
||
| 761 | $grouppermHandler->addRight($permName, $categoryId, $groupId, $moduleId); |
||
| 762 | } |
||
| 763 | } |
||
| 764 | |||
| 765 | return $result; |
||
| 766 | } |
||
| 767 | |||
| 768 | |||
| 769 | //======================= NEW ======================== |
||
| 770 | //--------------- Custom module methods ----------------------------- |
||
| 771 | |||
| 772 | /** |
||
| 773 | * @param $text |
||
| 774 | * @param $form_sort |
||
| 775 | * @return string |
||
| 776 | */ |
||
| 777 | public static function selectSorting($text, $form_sort) |
||
| 778 | { |
||
| 779 | global $start, $order, $file_cat, $sort, $xoopsModule; |
||
| 780 | |||
| 781 | $select_view = ''; |
||
| 782 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 783 | /** @var Adslight\Helper $helper */ |
||
| 784 | $helper = Adslight\Helper::getInstance(); |
||
| 785 | |||
| 786 | $pathModIcon16 = XOOPS_URL . '/modules/' . $moduleDirName . '/' . $helper->getModule()->getInfo('modicons16'); |
||
| 787 | |||
| 788 | $select_view = '<form name="form_switch" id="form_switch" action="' . Request::getString('REQUEST_URI', '', 'SERVER') . '" method="post"><span style="font-weight: bold;">' . $text . '</span>'; |
||
| 789 | //$sorts = $sort == 'asc' ? 'desc' : 'asc'; |
||
| 790 | if ($form_sort == $sort) { |
||
| 791 | $sel1 = 'asc' === $order ? 'selasc.png' : 'asc.png'; |
||
| 792 | $sel2 = 'desc' === $order ? 'seldesc.png' : 'desc.png'; |
||
| 793 | } else { |
||
| 794 | $sel1 = 'asc.png'; |
||
| 795 | $sel2 = 'desc.png'; |
||
| 796 | } |
||
| 797 | $select_view .= ' <a href="' . Request::getString('PHP_SELF', '', 'SERVER') . '?start=' . $start . '&sort=' . $form_sort . '&order=asc"><img src="' . $pathModIcon16 . '/' . $sel1 . '" title="ASC" alt="ASC"></a>'; |
||
| 798 | $select_view .= '<a href="' . Request::getString('PHP_SELF', '', 'SERVER') . '?start=' . $start . '&sort=' . $form_sort . '&order=desc"><img src="' . $pathModIcon16 . '/' . $sel2 . '" title="DESC" alt="DESC"></a>'; |
||
| 799 | $select_view .= '</form>'; |
||
| 800 | |||
| 801 | return $select_view; |
||
| 802 | } |
||
| 803 | |||
| 804 | /***************Blocks***************/ |
||
| 805 | /** |
||
| 806 | * @param array $cats |
||
| 807 | * @return string |
||
| 808 | */ |
||
| 809 | public static function blockAddCatSelect($cats) |
||
| 822 | } |
||
| 823 | |||
| 824 | /** |
||
| 825 | * @param $content |
||
| 826 | */ |
||
| 827 | public static function metaKeywords($content) |
||
| 828 | { |
||
| 829 | global $xoopsTpl, $xoTheme; |
||
| 830 | $myts = \MyTextSanitizer::getInstance(); |
||
| 831 | $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
||
| 832 | if (null !== $xoTheme && is_object($xoTheme)) { |
||
| 833 | $xoTheme->addMeta('meta', 'keywords', strip_tags($content)); |
||
| 834 | } else { // Compatibility for old Xoops versions |
||
| 835 | $xoopsTpl->assign('xoops_metaKeywords', strip_tags($content)); |
||
| 836 | } |
||
| 837 | } |
||
| 838 | |||
| 839 | /** |
||
| 840 | * @param $content |
||
| 841 | */ |
||
| 842 | public static function metaDescription($content) |
||
| 843 | { |
||
| 844 | global $xoopsTpl, $xoTheme; |
||
| 845 | $myts = \MyTextSanitizer::getInstance(); |
||
| 846 | $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
||
| 847 | if (null !== $xoTheme && is_object($xoTheme)) { |
||
| 848 | $xoTheme->addMeta('meta', 'description', strip_tags($content)); |
||
| 849 | } else { // Compatibility for old Xoops versions |
||
| 850 | $xoopsTpl->assign('xoops_metaDescription', strip_tags($content)); |
||
| 851 | } |
||
| 852 | } |
||
| 853 | |||
| 854 | /** |
||
| 855 | * @param $tableName |
||
| 856 | * @param $columnName |
||
| 857 | * |
||
| 858 | * @return array |
||
| 859 | */ |
||
| 860 | public static function enumerate($tableName, $columnName) |
||
| 877 | } |
||
| 878 | |||
| 879 | /** |
||
| 880 | * @param array|string $tableName |
||
| 881 | * @param int $id_field |
||
| 882 | * @param int $id |
||
| 883 | * |
||
| 884 | * @return mixed |
||
| 885 | */ |
||
| 886 | public static function cloneRecord($tableName, $id_field, $id) |
||
| 902 | } |
||
| 903 | |||
| 904 | |||
| 905 | /** |
||
| 906 | * truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags |
||
| 907 | * www.gsdesign.ro/blog/cut-html-string-without-breaking-the-tags |
||
| 908 | * www.cakephp.org |
||
| 909 | * |
||
| 910 | * @param string $text String to truncate. |
||
| 911 | * @param integer $length Length of returned string, including ellipsis. |
||
| 912 | * @param string $ending Ending to be appended to the trimmed string. |
||
| 913 | * @param boolean $exact If false, $text will not be cut mid-word |
||
| 914 | * @param boolean $considerHtml If true, HTML tags would be handled correctly |
||
| 915 | * |
||
| 916 | * @return string Trimmed string. |
||
| 917 | */ |
||
| 918 | public static function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) |
||
| 1008 | } |
||
| 1009 | |||
| 1010 | /*********************************************************************** |
||
| 1011 | * $fldVersion : dossier version de fancybox |
||
| 1012 | ***********************************************************************/ |
||
| 1013 | public static function load_lib_js(){ |
||
| 1028 | //$xoTheme->addStyleSheet($fld . "/css/galery.css" type="text/css" media="screen"); |
||
| 1029 | |||
| 1085 |