XoopsModules25x /
smartpartner
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | // |
||
| 3 | // ------------------------------------------------------------------------ // |
||
| 4 | // XOOPS - PHP Content Management System // |
||
| 5 | // Copyright (c) 2000-2016 XOOPS.org // |
||
| 6 | // <http://xoops.org/> // |
||
| 7 | // ------------------------------------------------------------------------ // |
||
| 8 | // This program is free software; you can redistribute it and/or modify // |
||
| 9 | // it under the terms of the GNU General Public License as published by // |
||
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
||
| 11 | // (at your option) any later version. // |
||
| 12 | |||
| 13 | // You may not change or alter any portion of this comment or credits // |
||
| 14 | // of supporting developers from this source code or any supporting // |
||
| 15 | // source code which is considered copyrighted (c) material of the // |
||
| 16 | // original comment or credit authors. // |
||
| 17 | // This program is distributed in the hope that it will be useful, // |
||
| 18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
| 19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
| 20 | // GNU General Public License for more details. // |
||
| 21 | |||
| 22 | // You should have received a copy of the GNU General Public License // |
||
| 23 | // along with this program; if not, write to the Free Software // |
||
| 24 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
| 25 | // ------------------------------------------------------------------------ // |
||
| 26 | // URL: http://xoops.org/ // |
||
| 27 | // Project: XOOPS Project // |
||
| 28 | // -------------------------------------------------------------------------// |
||
| 29 | |||
| 30 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
||
|
0 ignored issues
–
show
|
|||
| 31 | include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
||
| 32 | include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjecthandler.php'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Class SmartpartnerOffer |
||
| 36 | */ |
||
| 37 | class SmartpartnerOffer extends SmartObject |
||
| 38 | { |
||
| 39 | /** |
||
| 40 | * SmartpartnerOffer constructor. |
||
| 41 | */ |
||
| 42 | public function __construct() |
||
| 43 | { |
||
| 44 | $this->initVar('offerid', XOBJ_DTYPE_INT, '', true); |
||
| 45 | $this->initVar('partnerid', XOBJ_DTYPE_INT, '', true, 255, '', false, _CO_SPARTNER_OFFER_PARTNER, _CO_SPARTNER_OFFER_PARTNER_DSC, true); |
||
| 46 | $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SPARTNER_OFFER_TITLE, _CO_SPARTNER_OFFER_TITLE_DSC, true); |
||
| 47 | |||
| 48 | $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SPARTNER_OFFER_DESC, _CO_SPARTNER_OFFER_DESC_DSC); |
||
| 49 | $this->initVar('url', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SPARTNER_OFFER_URL, _CO_SPARTNER_OFFER_URL_DSC, true); |
||
| 50 | $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SPARTNER_OFFER_IMAGE, _CO_SPARTNER_OFFER_IMAGE_DSC); |
||
| 51 | |||
| 52 | $this->initVar('date_sub', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SPARTNER_OFFER_DATESUB, _CO_SPARTNER_OFFER_DATESUB_DSC, true); |
||
| 53 | $this->initVar('date_pub', XOBJ_DTYPE_INT, time() - 1000, false, null, '', false, _CO_SPARTNER_OFFER_DATE_START, _CO_SPARTNER_OFFER_DATE_START_DSC, true); |
||
| 54 | $this->initVar('date_end', XOBJ_DTYPE_INT, time() + 30 * 24 * 3600, false, null, '', false, _CO_SPARTNER_OFFER_DATE_END, _CO_SPARTNER_OFFER_DATE_END_DSC, true); |
||
| 55 | |||
| 56 | $this->initVar('status', XOBJ_DTYPE_INT, _SPARTNER_STATUS_ONLINE, false, null, '', false, _CO_SPARTNER_OFFER_STATUS, _CO_SPARTNER_OFFER_STATUS_DSC, true); |
||
| 57 | $this->initCommonVar('weight'); |
||
| 58 | $this->initCommonVar('dohtml', false); |
||
| 59 | |||
| 60 | $this->setControl('image', array('name' => 'image')); |
||
| 61 | |||
| 62 | $this->setControl('date_sub', array('name' => 'date_time')); |
||
| 63 | $this->setControl('date_pub', array('name' => 'date_time')); |
||
| 64 | $this->setControl('date_end', array('name' => 'date_time')); |
||
| 65 | |||
| 66 | $this->setControl('status', array( |
||
| 67 | 'name' => false, |
||
| 68 | 'itemHandler' => 'offer', |
||
| 69 | 'method' => 'getStatus', |
||
| 70 | 'module' => 'smartpartner' |
||
| 71 | )); |
||
| 72 | $this->setControl('partnerid', array( |
||
| 73 | 'itemHandler' => 'partner', |
||
| 74 | 'method' => 'getList', |
||
| 75 | 'module' => 'smartpartner' |
||
| 76 | )); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param string $key |
||
| 81 | * @param string $format |
||
| 82 | * @return mixed |
||
| 83 | */ |
||
| 84 | public function getVar($key, $format = 's') |
||
| 85 | { |
||
| 86 | if ($format === 's' && in_array($key, array('partnerid', 'status'))) { |
||
| 87 | // return call_user_func(array($this, $key)); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 88 | return $this->{$key}(); |
||
| 89 | } |
||
| 90 | |||
| 91 | return parent::getVar($key, $format); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @return mixed |
||
| 96 | */ |
||
| 97 | public function partnerid() |
||
| 98 | { |
||
| 99 | global $smartPartnerPartnerHandler; |
||
| 100 | if (!$smartPartnerPartnerHandler) { |
||
| 101 | $smartPartnerPartnerHandler = smartpartner_gethandler('partner'); |
||
| 102 | } |
||
| 103 | $ret = $this->getVar('partnerid', 'e'); |
||
| 104 | $partnerObj = $smartPartnerPartnerHandler->get($ret); |
||
| 105 | |||
| 106 | return $partnerObj->getVar('title'); |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @return mixed |
||
| 111 | */ |
||
| 112 | public function status() |
||
| 113 | { |
||
| 114 | global $statusArray; |
||
| 115 | $ret = $this->getVar('status', 'e'); |
||
| 116 | |||
| 117 | return $statusArray [$ret]; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param array $notifications |
||
| 122 | */ |
||
| 123 | public function sendNotifications($notifications = array()) |
||
| 124 | { |
||
| 125 | global $smartPartnerPartnerHandler; |
||
| 126 | $partnerObj = $smartPartnerPartnerHandler->get($this->getVar('partnerid', 'e')); |
||
| 127 | $smartModule =& smartpartner_getModuleInfo(); |
||
| 128 | $module_id = $smartModule->getVar('mid'); |
||
|
0 ignored issues
–
show
$module_id is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 129 | |||
| 130 | $myts = MyTextSanitizer::getInstance(); |
||
| 131 | $notificationHandler = xoops_getHandler('notification'); |
||
| 132 | |||
| 133 | $tags = array(); |
||
| 134 | $tags['MODULE_NAME'] = $myts->displayTarea($smartModule->getVar('name')); |
||
| 135 | $tags['PARTNER_NAME'] = $partnerObj->title(20); |
||
| 136 | $tags['OFFER_NAME'] = $this->title(20); |
||
| 137 | foreach ($notifications as $notification) { |
||
| 138 | switch ($notification) { |
||
| 139 | |||
| 140 | case _SPARTNER_NOT_OFFER_NEW: |
||
| 141 | $tags['OFFER_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/partner.php?id=' . $this->getVar('partnerid', 'e'); |
||
| 142 | $notificationHandler->triggerEvent('global_partner', 0, 'new_offer', $tags); |
||
| 143 | break; |
||
| 144 | case -1: |
||
| 145 | default: |
||
| 146 | break; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param string $format |
||
| 153 | * @return array |
||
| 154 | */ |
||
| 155 | public function toArray($format = 's') |
||
| 156 | { |
||
| 157 | global $myts; |
||
| 158 | if (!$myts) { |
||
| 159 | $myts = MyTextSanitizer::getInstance(); |
||
| 160 | } |
||
| 161 | $ret = parent::toArray(); |
||
| 162 | if ($format === 'e') { |
||
| 163 | $ret['partnerid'] = $this->getVar('partnerid', 'e'); |
||
| 164 | } |
||
| 165 | $ret['description'] = $myts->undoHtmlSpecialChars($ret['description']); |
||
| 166 | |||
| 167 | return $ret; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Class SmartpartnerOfferHandler |
||
| 173 | */ |
||
| 174 | class SmartpartnerOfferHandler extends SmartPersistableObjectHandler |
||
| 175 | { |
||
| 176 | /** |
||
| 177 | * SmartpartnerOfferHandler constructor. |
||
| 178 | * @param XoopsDatabase $db |
||
| 179 | */ |
||
| 180 | public function __construct(XoopsDatabase $db) |
||
| 181 | { |
||
| 182 | parent::__construct($db, 'offer', 'offerid', 'title', false, 'smartpartner'); |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @return array |
||
| 187 | */ |
||
| 188 | public function getStatus() |
||
| 189 | { |
||
| 190 | global $statusArray; |
||
| 191 | |||
| 192 | return $statusArray; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return array |
||
| 197 | */ |
||
| 198 | public function getObjectsForUserSide() |
||
| 199 | { |
||
| 200 | global $xoopsModuleConfig, $smartPartnerCategoryHandler, $smartPartnerPartnerHandler, $xoopsUser; |
||
| 201 | |||
| 202 | $criteria = new CriteriaCompo(); |
||
| 203 | $criteria->setSort($xoopsModuleConfig['offer_sort']); |
||
| 204 | $criteria->setOrder($xoopsModuleConfig['offer_order']); |
||
| 205 | $criteria->add(new Criteria('date_pub', time(), '<')); |
||
| 206 | $criteria->add(new Criteria('date_end', time(), '>')); |
||
| 207 | $criteria->add(new Criteria('status', _SPARTNER_STATUS_ONLINE)); |
||
| 208 | |||
| 209 | $offersObj = $this->getObjects($criteria); |
||
| 210 | foreach ($offersObj as $offerObj) { |
||
|
0 ignored issues
–
show
|
|||
| 211 | } |
||
| 212 | $catsObj = $smartPartnerCategoryHandler->getObjects(null, true); |
||
| 213 | $partnersObj = $smartPartnerPartnerHandler->getObjects(null, true); |
||
| 214 | |||
| 215 | include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectpermission.php'; |
||
| 216 | $smartPermissionsHandler = new SmartobjectPermissionHandler($smartPartnerPartnerHandler); |
||
| 217 | $userGroups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 218 | $grantedItems = $smartPermissionsHandler->getGrantedItems('full_view'); |
||
| 219 | $relevantCat = array(); |
||
| 220 | |||
| 221 | foreach ($offersObj as $offerObj) { |
||
| 222 | if (in_array($offerObj->getVar('partnerid', 'e'), $grantedItems)) { |
||
| 223 | $categId = $partnersObj[$offerObj->getVar('partnerid', 'e')]->categoryid(); |
||
| 224 | $parentCatArray = explode('|', $categId); |
||
| 225 | $relevantCat = array_merge($relevantCat, $parentCatArray); |
||
| 226 | foreach ($parentCatArray as $p_cat) { |
||
| 227 | $parentid = $p_cat; |
||
| 228 | while ($catsObj[$parentid]->parentid() != 0) { |
||
| 229 | $parentid = $catsObj[$parentid]->parentid(); |
||
| 230 | $relevantCat[] = $parentid; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 | } |
||
| 235 | $relevantCat = array_unique($relevantCat); |
||
| 236 | |||
| 237 | $partnersArray = array(); |
||
| 238 | foreach ($partnersObj as $partnerObj) { |
||
| 239 | $grantedGroups = $smartPermissionsHandler->getGrantedGroups('full_view', $partnerObj->id()); |
||
| 240 | if (array_intersect($userGroups, $grantedGroups)) { |
||
| 241 | $partnerArray = array(); |
||
| 242 | $partnerArray['name'] = $partnerObj->title(); |
||
| 243 | $partnerArray['offers'] = array(); |
||
| 244 | foreach ($offersObj as $offerObj) { |
||
| 245 | if ($offerObj->getVar('partnerid', 'e') == $partnerObj->id()) { |
||
| 246 | $partnerArray['offers'][] = $offerObj->toArray(); |
||
| 247 | } |
||
| 248 | } |
||
| 249 | $partnersArray[$partnerObj->id()] = $partnerArray; |
||
| 250 | unset($partnerArray); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | |||
| 254 | $categoriesArray = array(); |
||
| 255 | foreach ($catsObj as $catObj) { |
||
| 256 | if (in_array($catObj->categoryid(), $relevantCat)) { |
||
| 257 | $categoryArray = array(); |
||
| 258 | $categoryArray['parentid'] = $catObj->parentid(); |
||
| 259 | $categoryArray['categoryid'] = $catObj->categoryid(); |
||
| 260 | $categoryArray['name'] = $catObj->name(); |
||
| 261 | $categoryArray['partners'] = array(); |
||
| 262 | foreach ($partnersObj as $partnerObj) { |
||
| 263 | $catArray = explode('|', $partnerObj->categoryid()); |
||
| 264 | if (in_array($catObj->categoryid(), $catArray)) { |
||
| 265 | $categoryArray['partners'][$partnerObj->id()] = $partnersArray[$partnerObj->id()]; |
||
| 266 | } |
||
| 267 | } |
||
| 268 | $categoriesArray[] = $categoryArray; |
||
| 269 | unset($categoryArray); |
||
| 270 | } |
||
| 271 | } |
||
| 272 | |||
| 273 | return $this->hierarchize($categoriesArray); |
||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @param $categoriesArray |
||
| 278 | * @param int $parentid |
||
| 279 | * @return array |
||
| 280 | */ |
||
| 281 | public function hierarchize($categoriesArray, $parentid = 0) |
||
| 282 | { |
||
| 283 | $hierachizedArray = array(); |
||
| 284 | foreach ($categoriesArray as $cat) { |
||
| 285 | if ($cat['parentid'] == $parentid) { |
||
| 286 | $id = $cat['categoryid']; |
||
| 287 | $hierachizedArray[$id] = $cat; |
||
| 288 | $hierachizedArray[$id]['subcats'] = $this->hierarchize($categoriesArray, $cat['categoryid']); |
||
| 289 | } |
||
| 290 | } |
||
| 291 | |||
| 292 | return $hierachizedArray; |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @param $category |
||
| 297 | * @return bool |
||
| 298 | */ |
||
| 299 | public function hasOffer($category) |
||
| 300 | { |
||
| 301 | $partners = $category['partners']; |
||
| 302 | $subcats = $category['subcats']; |
||
| 303 | $hasoffer = false; |
||
| 304 | foreach ($partners as $partner) { |
||
| 305 | if (isset($partner['offers'])) { |
||
| 306 | $hasoffer = true; |
||
| 307 | } |
||
| 308 | } |
||
| 309 | if ((!$hasoffer || !$partners) && !$subcats) { |
||
| 310 | return false; |
||
| 311 | } |
||
| 312 | foreach ($partners as $partner) { |
||
| 313 | if ($partner['offers']) { |
||
| 314 | return true; |
||
| 315 | } |
||
| 316 | } |
||
| 317 | foreach ($subcats as $subcat) { |
||
| 318 | return hasOffer($subcat); |
||
| 319 | } |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return mixed |
||
| 324 | */ |
||
| 325 | public function getPartnerList() |
||
| 326 | { |
||
| 327 | global $smartPartnerPartnerHandler; |
||
| 328 | |||
| 329 | return $smartPartnerPartnerHandler->getList(); |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @return array |
||
| 334 | */ |
||
| 335 | public function getstatusList() |
||
| 336 | { |
||
| 337 | global $statusArray; |
||
| 338 | |||
| 339 | return $statusArray; |
||
| 340 | } |
||
| 341 | } |
||
| 342 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.