@@ -132,10 +132,10 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @param object|XoopsDatabase $db {@link XoopsDatabase} |
| 134 | 134 | * object |
| 135 | - * @param $itemname |
|
| 135 | + * @param string $itemname |
|
| 136 | 136 | * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
| 137 | 137 | * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
| 138 | - * @param $summaryName |
|
| 138 | + * @param string $summaryName |
|
| 139 | 139 | * @param $modulename |
| 140 | 140 | * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
| 141 | 141 | * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | 193 | * @param $criteria |
| 194 | - * @param $perm_name |
|
| 194 | + * @param boolean $perm_name |
|
| 195 | 195 | * @return bool |
| 196 | 196 | */ |
| 197 | 197 | public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
| 378 | - * @param $sql |
|
| 378 | + * @param string $sql |
|
| 379 | 379 | * @param $criteria |
| 380 | 380 | * @param bool $force |
| 381 | 381 | * @param bool $debug |
@@ -25,970 +25,970 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class SmartPersistableObjectHandler extends XoopsObjectHandler |
| 27 | 27 | { |
| 28 | - public $_itemname; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Name of the table use to store this {@link SmartObject} |
|
| 32 | - * |
|
| 33 | - * Note that the name of the table needs to be free of the database prefix. |
|
| 34 | - * For example "smartsection_categories" |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - public $table; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Name of the table key that uniquely identify each {@link SmartObject} |
|
| 41 | - * |
|
| 42 | - * For example: "categoryid" |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - public $keyName; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Name of the class derived from {@link SmartObject} and which this handler is handling |
|
| 49 | - * |
|
| 50 | - * Note that this string needs to be lowercase |
|
| 51 | - * |
|
| 52 | - * For example: "smartsectioncategory" |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - public $className; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Name of the field which properly identify the {@link SmartObject} |
|
| 59 | - * |
|
| 60 | - * For example: "name" (this will be the category's name) |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $identifierName; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Name of the field which will be use as a summary for the object |
|
| 67 | - * |
|
| 68 | - * For example: "summary" |
|
| 69 | - * @var string |
|
| 70 | - */ |
|
| 71 | - public $summaryName; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Page name use to basically manage and display the {@link SmartObject} |
|
| 75 | - * |
|
| 76 | - * This page needs to be the same in user side and admin side |
|
| 77 | - * |
|
| 78 | - * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php |
|
| 79 | - * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page |
|
| 80 | - * @var string |
|
| 81 | - */ |
|
| 82 | - public $_page; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Full path of the module using this {@link SmartObject} |
|
| 86 | - * |
|
| 87 | - * <code>XOOPS_URL . "/modules/smartsection/"</code> |
|
| 88 | - * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name |
|
| 89 | - * @var string |
|
| 90 | - */ |
|
| 91 | - public $_modulePath; |
|
| 92 | - |
|
| 93 | - public $_moduleUrl; |
|
| 94 | - |
|
| 95 | - public $_moduleName; |
|
| 96 | - |
|
| 97 | - public $_uploadUrl; |
|
| 98 | - |
|
| 99 | - public $_uploadPath; |
|
| 100 | - |
|
| 101 | - public $_allowedMimeTypes = 0; |
|
| 102 | - |
|
| 103 | - public $_maxFileSize = 1000000; |
|
| 104 | - |
|
| 105 | - public $_maxWidth = 500; |
|
| 106 | - |
|
| 107 | - public $_maxHeight = 500; |
|
| 108 | - |
|
| 109 | - public $highlightFields = array(); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Array containing the events name and functions |
|
| 113 | - * |
|
| 114 | - * @var array |
|
| 115 | - */ |
|
| 116 | - public $eventArray = array(); |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Array containing the permissions that this handler will manage on the objects |
|
| 120 | - * |
|
| 121 | - * @var array |
|
| 122 | - */ |
|
| 123 | - public $permissionsArray = false; |
|
| 124 | - |
|
| 125 | - public $generalSQL = false; |
|
| 126 | - |
|
| 127 | - public $_eventHooks = array(); |
|
| 128 | - public $_disabledEvents = array(); |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Constructor - called from child classes |
|
| 132 | - * |
|
| 133 | - * @param object|XoopsDatabase $db {@link XoopsDatabase} |
|
| 134 | - * object |
|
| 135 | - * @param $itemname |
|
| 136 | - * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
| 137 | - * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
| 138 | - * @param $summaryName |
|
| 139 | - * @param $modulename |
|
| 140 | - * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 141 | - * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
| 142 | - * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 143 | - * @internal param string $moduleName name of the module |
|
| 144 | - */ |
|
| 145 | - public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
| 146 | - { |
|
| 147 | - parent::__construct($db); |
|
| 148 | - |
|
| 149 | - $this->_itemname = $itemname; |
|
| 150 | - $this->_moduleName = $modulename; |
|
| 151 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 152 | - $this->keyName = $keyname; |
|
| 153 | - $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 154 | - $this->identifierName = $idenfierName; |
|
| 155 | - $this->summaryName = $summaryName; |
|
| 156 | - $this->_page = $itemname . '.php'; |
|
| 157 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 158 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 159 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 160 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param $event |
|
| 165 | - * @param $method |
|
| 166 | - */ |
|
| 167 | - public function addEventHook($event, $method) |
|
| 168 | - { |
|
| 169 | - $this->_eventHooks[$event] = $method; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Add a permission that this handler will manage for its objects |
|
| 174 | - * |
|
| 175 | - * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
| 176 | - * |
|
| 177 | - * @param string $perm_name name of the permission |
|
| 178 | - * @param string $caption caption of the control that will be displayed in the form |
|
| 179 | - * @param bool|string $description description of the control that will be displayed in the form |
|
| 180 | - */ |
|
| 181 | - public function addPermission($perm_name, $caption, $description = false) |
|
| 182 | - { |
|
| 183 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'); |
|
| 184 | - |
|
| 185 | - $this->permissionsArray[] = array( |
|
| 186 | - 'perm_name' => $perm_name, |
|
| 187 | - 'caption' => $caption, |
|
| 188 | - 'description' => $description |
|
| 189 | - ); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @param $criteria |
|
| 194 | - * @param $perm_name |
|
| 195 | - * @return bool |
|
| 196 | - */ |
|
| 197 | - public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
|
| 198 | - { |
|
| 199 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
| 200 | - $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 201 | - if (count($grantedItems) > 0) { |
|
| 202 | - $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 203 | - |
|
| 204 | - return true; |
|
| 205 | - } else { |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param bool $_uploadPath |
|
| 212 | - * @param bool $_allowedMimeTypes |
|
| 213 | - * @param bool $_maxFileSize |
|
| 214 | - * @param bool $_maxWidth |
|
| 215 | - * @param bool $_maxHeight |
|
| 216 | - */ |
|
| 217 | - public function setUploaderConfig($_uploadPath = false, $_allowedMimeTypes = false, $_maxFileSize = false, $_maxWidth = false, $_maxHeight = false) |
|
| 218 | - { |
|
| 219 | - $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
| 220 | - $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
| 221 | - $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
| 222 | - $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
| 223 | - $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * create a new {@link SmartObject} |
|
| 228 | - * |
|
| 229 | - * @param bool $isNew Flag the new objects as "new"? |
|
| 230 | - * |
|
| 231 | - * @return object {@link SmartObject} |
|
| 232 | - */ |
|
| 233 | - public function &create($isNew = true) |
|
| 234 | - { |
|
| 235 | - $obj = new $this->className($this); |
|
| 236 | - $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
| 237 | - if (!$obj->handler) { |
|
| 238 | - $obj->handler =& $this; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - if ($isNew === true) { |
|
| 242 | - $obj->setNew(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return $obj; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function getImageUrl() |
|
| 252 | - { |
|
| 253 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @return string |
|
| 258 | - */ |
|
| 259 | - public function getImagePath() |
|
| 260 | - { |
|
| 261 | - $dir = $this->_uploadPath . $this->_itemname; |
|
| 262 | - if (!file_exists($dir)) { |
|
| 263 | - smart_admin_mkdir($dir); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $dir . '/'; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * retrieve a {@link SmartObject} |
|
| 271 | - * |
|
| 272 | - * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
| 273 | - * @param bool $as_object whether to return an object or an array |
|
| 274 | - * @param bool $debug |
|
| 275 | - * @param bool $criteria |
|
| 276 | - * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
| 277 | - * FALSE if failed |
|
| 278 | - */ |
|
| 279 | - public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
| 280 | - { |
|
| 281 | - if (!$criteria) { |
|
| 282 | - $criteria = new CriteriaCompo(); |
|
| 283 | - } |
|
| 284 | - if (is_array($this->keyName)) { |
|
| 285 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 286 | - /** |
|
| 287 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 288 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
| 289 | - */ |
|
| 290 | - //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
| 291 | - $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
| 292 | - } |
|
| 293 | - } else { |
|
| 294 | - //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
| 295 | - /** |
|
| 296 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 297 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
| 298 | - */ |
|
| 299 | - $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
| 300 | - } |
|
| 301 | - $criteria->setLimit(1); |
|
| 302 | - if ($debug) { |
|
| 303 | - $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
| 304 | - } else { |
|
| 305 | - $obj_array = $this->getObjects($criteria, false, $as_object); |
|
| 306 | - //patch: weird bug of indexing by id even if id_as_key = false; |
|
| 307 | - if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
| 308 | - $obj_array[0] = $obj_array[$id]; |
|
| 309 | - unset($obj_array[$id]); |
|
| 310 | - $obj_array[0]->unsetNew(); |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - if (count($obj_array) != 1) { |
|
| 315 | - $obj =& $this->create(); |
|
| 316 | - |
|
| 317 | - return $obj; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - return $obj_array[0]; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * retrieve a {@link SmartObject} |
|
| 325 | - * |
|
| 326 | - * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
| 327 | - * @param bool $as_object whether to return an object or an array |
|
| 328 | - * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
| 329 | - */ |
|
| 330 | - public function &getD($id, $as_object = true) |
|
| 331 | - { |
|
| 332 | - return $this->get($id, $as_object, true); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * retrieve objects from the database |
|
| 337 | - * |
|
| 338 | - * @param object $criteria {@link CriteriaElement} conditions to be met |
|
| 339 | - * @param bool $id_as_key use the ID as key for the array? |
|
| 340 | - * @param bool $as_object return an array of objects? |
|
| 341 | - * |
|
| 342 | - * @param bool $sql |
|
| 343 | - * @param bool $debug |
|
| 344 | - * @return array |
|
| 345 | - */ |
|
| 346 | - public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false) |
|
| 347 | - { |
|
| 348 | - $ret = array(); |
|
| 349 | - $limit = $start = 0; |
|
| 350 | - |
|
| 351 | - if ($this->generalSQL) { |
|
| 352 | - $sql = $this->generalSQL; |
|
| 353 | - } elseif (!$sql) { |
|
| 354 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 358 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 359 | - if ($criteria->getSort() != '') { |
|
| 360 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 361 | - } |
|
| 362 | - $limit = $criteria->getLimit(); |
|
| 363 | - $start = $criteria->getStart(); |
|
| 364 | - } |
|
| 365 | - if ($debug) { |
|
| 366 | - xoops_debug($sql); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $result = $this->db->query($sql, $limit, $start); |
|
| 370 | - if (!$result) { |
|
| 371 | - return $ret; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - return $this->convertResultSet($result, $id_as_key, $as_object); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @param $sql |
|
| 379 | - * @param $criteria |
|
| 380 | - * @param bool $force |
|
| 381 | - * @param bool $debug |
|
| 382 | - * @return array |
|
| 383 | - */ |
|
| 384 | - public function query($sql, $criteria, $force = false, $debug = false) |
|
| 385 | - { |
|
| 386 | - $ret = array(); |
|
| 387 | - |
|
| 388 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 389 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 390 | - if ($criteria->groupby) { |
|
| 391 | - $sql .= $criteria->getGroupby(); |
|
| 392 | - } |
|
| 393 | - if ($criteria->getSort() != '') { |
|
| 394 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - if ($debug) { |
|
| 398 | - xoops_debug($sql); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - if ($force) { |
|
| 402 | - $result = $this->db->queryF($sql); |
|
| 403 | - } else { |
|
| 404 | - $result = $this->db->query($sql); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - if (!$result) { |
|
| 408 | - return $ret; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - while ($myrow = $this->db->fetchArray($result)) { |
|
| 412 | - $ret[] = $myrow; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - return $ret; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * retrieve objects with debug mode - so will show the query |
|
| 420 | - * |
|
| 421 | - * @param object $criteria {@link CriteriaElement} conditions to be met |
|
| 422 | - * @param bool $id_as_key use the ID as key for the array? |
|
| 423 | - * @param bool $as_object return an array of objects? |
|
| 424 | - * |
|
| 425 | - * @param bool $sql |
|
| 426 | - * @return array |
|
| 427 | - */ |
|
| 428 | - public function getObjectsD($criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
| 429 | - { |
|
| 430 | - return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @param $arrayObjects |
|
| 435 | - * @return array|bool |
|
| 436 | - */ |
|
| 437 | - public function getObjectsAsArray($arrayObjects) |
|
| 438 | - { |
|
| 439 | - $ret = array(); |
|
| 440 | - foreach ($arrayObjects as $key => $object) { |
|
| 441 | - $ret[$key] = $object->toArray(); |
|
| 442 | - } |
|
| 443 | - if (count($ret > 0)) { |
|
| 444 | - return $ret; |
|
| 445 | - } else { |
|
| 446 | - return false; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Convert a database resultset to a returnable array |
|
| 452 | - * |
|
| 453 | - * @param object $result database resultset |
|
| 454 | - * @param bool $id_as_key - should NOT be used with joint keys |
|
| 455 | - * @param bool $as_object |
|
| 456 | - * |
|
| 457 | - * @return array |
|
| 458 | - */ |
|
| 459 | - public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
| 460 | - { |
|
| 461 | - $ret = array(); |
|
| 462 | - while ($myrow = $this->db->fetchArray($result)) { |
|
| 463 | - $obj =& $this->create(false); |
|
| 464 | - $obj->assignVars($myrow); |
|
| 465 | - if (!$id_as_key) { |
|
| 466 | - if ($as_object) { |
|
| 467 | - $ret[] =& $obj; |
|
| 468 | - } else { |
|
| 469 | - $ret[] = $obj->toArray(); |
|
| 470 | - } |
|
| 471 | - } else { |
|
| 472 | - if ($as_object) { |
|
| 473 | - $value =& $obj; |
|
| 474 | - } else { |
|
| 475 | - $value = $obj->toArray(); |
|
| 476 | - } |
|
| 477 | - if ($id_as_key === 'parentid') { |
|
| 478 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 479 | - } else { |
|
| 480 | - $ret[$obj->getVar($this->keyName)] = $value; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - unset($obj); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $ret; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @param null $criteria |
|
| 491 | - * @param int $limit |
|
| 492 | - * @param int $start |
|
| 493 | - * @return array |
|
| 494 | - */ |
|
| 495 | - public function getListD($criteria = null, $limit = 0, $start = 0) |
|
| 496 | - { |
|
| 497 | - return $this->getList($criteria, $limit, $start, true); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
| 502 | - * |
|
| 503 | - * @param object $criteria {@link CriteriaElement} conditions to be met |
|
| 504 | - * @param int $limit Max number of objects to fetch |
|
| 505 | - * @param int $start Which record to start at |
|
| 506 | - * |
|
| 507 | - * @param bool $debug |
|
| 508 | - * @return array |
|
| 509 | - */ |
|
| 510 | - public function getList($criteria = null, $limit = 0, $start = 0, $debug = false) |
|
| 511 | - { |
|
| 512 | - $ret = array(); |
|
| 513 | - if ($criteria == null) { |
|
| 514 | - $criteria = new CriteriaCompo(); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - if ($criteria->getSort() == '') { |
|
| 518 | - $criteria->setSort($this->getIdentifierName()); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 522 | - if (!empty($this->identifierName)) { |
|
| 523 | - $sql .= ', ' . $this->getIdentifierName(); |
|
| 524 | - } |
|
| 525 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 526 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 527 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 528 | - if ($criteria->getSort() != '') { |
|
| 529 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 530 | - } |
|
| 531 | - $limit = $criteria->getLimit(); |
|
| 532 | - $start = $criteria->getStart(); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - if ($debug) { |
|
| 536 | - xoops_debug($sql); |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - $result = $this->db->query($sql, $limit, $start); |
|
| 540 | - if (!$result) { |
|
| 541 | - return $ret; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - $myts = MyTextSanitizer::getInstance(); |
|
| 545 | - while ($myrow = $this->db->fetchArray($result)) { |
|
| 546 | - //identifiers should be textboxes, so sanitize them like that |
|
| 547 | - $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - return $ret; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * count objects matching a condition |
|
| 555 | - * |
|
| 556 | - * @param object $criteria {@link CriteriaElement} to match |
|
| 557 | - * @return int count of objects |
|
| 558 | - */ |
|
| 559 | - public function getCount($criteria = null) |
|
| 560 | - { |
|
| 561 | - $field = ''; |
|
| 562 | - $groupby = false; |
|
| 563 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 564 | - if ($criteria->groupby != '') { |
|
| 565 | - $groupby = true; |
|
| 566 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - /** |
|
| 570 | - * if we have a generalSQL, lets used this one. |
|
| 571 | - * This needs to be improved... |
|
| 572 | - */ |
|
| 573 | - if ($this->generalSQL) { |
|
| 574 | - $sql = $this->generalSQL; |
|
| 575 | - $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
| 576 | - } else { |
|
| 577 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 578 | - } |
|
| 579 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 580 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 581 | - if ($criteria->groupby != '') { |
|
| 582 | - $sql .= $criteria->getGroupby(); |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - $result = $this->db->query($sql); |
|
| 587 | - if (!$result) { |
|
| 588 | - return 0; |
|
| 589 | - } |
|
| 590 | - if ($groupby == false) { |
|
| 591 | - list($count) = $this->db->fetchRow($result); |
|
| 592 | - |
|
| 593 | - return $count; |
|
| 594 | - } else { |
|
| 595 | - $ret = array(); |
|
| 596 | - while (list($id, $count) = $this->db->fetchRow($result)) { |
|
| 597 | - $ret[$id] = $count; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - return $ret; |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * delete an object from the database |
|
| 606 | - * |
|
| 607 | - * @param XoopsObject $obj reference to the object to delete |
|
| 608 | - * @param bool $force |
|
| 609 | - * @return bool FALSE if failed. |
|
| 610 | - */ |
|
| 611 | - public function delete(XoopsObject $obj, $force = false) |
|
| 612 | - { |
|
| 613 | - $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
| 614 | - if (!$eventResult) { |
|
| 615 | - $obj->setErrors('An error occured during the BeforeDelete event'); |
|
| 616 | - |
|
| 617 | - return false; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - if (is_array($this->keyName)) { |
|
| 621 | - $clause = array(); |
|
| 622 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 623 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 624 | - } |
|
| 625 | - $whereclause = implode(' AND ', $clause); |
|
| 626 | - } else { |
|
| 627 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 628 | - } |
|
| 629 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 630 | - if (false != $force) { |
|
| 631 | - $result = $this->db->queryF($sql); |
|
| 632 | - } else { |
|
| 633 | - $result = $this->db->query($sql); |
|
| 634 | - } |
|
| 635 | - if (!$result) { |
|
| 636 | - return false; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - $eventResult = $this->executeEvent('afterDelete', $obj); |
|
| 640 | - if (!$eventResult) { |
|
| 641 | - $obj->setErrors('An error occured during the AfterDelete event'); |
|
| 642 | - |
|
| 643 | - return false; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - return true; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * @param $event |
|
| 651 | - */ |
|
| 652 | - public function disableEvent($event) |
|
| 653 | - { |
|
| 654 | - if (is_array($event)) { |
|
| 655 | - foreach ($event as $v) { |
|
| 656 | - $this->_disabledEvents[] = $v; |
|
| 657 | - } |
|
| 658 | - } else { |
|
| 659 | - $this->_disabledEvents[] = $event; |
|
| 660 | - } |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * @return array |
|
| 665 | - */ |
|
| 666 | - public function getPermissions() |
|
| 667 | - { |
|
| 668 | - return $this->permissionsArray; |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * insert a new object in the database |
|
| 673 | - * |
|
| 674 | - * @param XoopsObject $obj reference to the object |
|
| 675 | - * @param bool $force whether to force the query execution despite security settings |
|
| 676 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
| 677 | - * @param bool $debug |
|
| 678 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 679 | - */ |
|
| 680 | - public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
| 681 | - { |
|
| 682 | - if ($checkObject != false) { |
|
| 683 | - if (!is_object($obj)) { |
|
| 684 | - return false; |
|
| 685 | - } |
|
| 686 | - /** |
|
| 687 | - * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
| 688 | - */ |
|
| 689 | - if (!is_a($obj, $this->className)) { |
|
| 690 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 691 | - |
|
| 692 | - return false; |
|
| 693 | - } |
|
| 694 | - if (!$obj->isDirty()) { |
|
| 695 | - $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith |
|
| 696 | - |
|
| 697 | - return true; |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - if ($obj->seoEnabled) { |
|
| 702 | - // Auto create meta tags if empty |
|
| 703 | - $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
| 704 | - |
|
| 705 | - if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
| 706 | - if (!$obj->meta_keywords()) { |
|
| 707 | - $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - if (!$obj->meta_description()) { |
|
| 711 | - $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
| 712 | - } |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - // Auto create short_url if empty |
|
| 716 | - if (!$obj->short_url()) { |
|
| 717 | - $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - $eventResult = $this->executeEvent('beforeSave', $obj); |
|
| 722 | - if (!$eventResult) { |
|
| 723 | - $obj->setErrors('An error occured during the BeforeSave event'); |
|
| 724 | - |
|
| 725 | - return false; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - if ($obj->isNew()) { |
|
| 729 | - $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
| 730 | - if (!$eventResult) { |
|
| 731 | - $obj->setErrors('An error occured during the BeforeInsert event'); |
|
| 732 | - |
|
| 733 | - return false; |
|
| 734 | - } |
|
| 735 | - } else { |
|
| 736 | - $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
| 737 | - if (!$eventResult) { |
|
| 738 | - $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
| 739 | - |
|
| 740 | - return false; |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - if (!$obj->cleanVars()) { |
|
| 744 | - $obj->setErrors('Variables were not cleaned properly.'); |
|
| 745 | - |
|
| 746 | - return false; |
|
| 747 | - } |
|
| 748 | - $fieldsToStoreInDB = array(); |
|
| 749 | - foreach ($obj->cleanVars as $k => $v) { |
|
| 750 | - if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
| 751 | - $cleanvars[$k] = (int)$v; |
|
| 752 | - } elseif (is_array($v)) { |
|
| 753 | - $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
| 754 | - } else { |
|
| 755 | - $cleanvars[$k] = $this->db->quoteString($v); |
|
| 756 | - } |
|
| 757 | - if ($obj->vars[$k]['persistent']) { |
|
| 758 | - $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - if ($obj->isNew()) { |
|
| 762 | - if (!is_array($this->keyName)) { |
|
| 763 | - if ($cleanvars[$this->keyName] < 1) { |
|
| 764 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 769 | - } else { |
|
| 770 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 771 | - foreach ($fieldsToStoreInDB as $key => $value) { |
|
| 772 | - if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
|
| 773 | - continue; |
|
| 774 | - } |
|
| 775 | - if (isset($notfirst)) { |
|
| 776 | - $sql .= ','; |
|
| 777 | - } |
|
| 778 | - $sql .= ' ' . $key . ' = ' . $value; |
|
| 779 | - $notfirst = true; |
|
| 780 | - } |
|
| 781 | - if (is_array($this->keyName)) { |
|
| 782 | - $whereclause = ''; |
|
| 783 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 784 | - if ($i > 0) { |
|
| 785 | - $whereclause .= ' AND '; |
|
| 786 | - } |
|
| 787 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 788 | - } |
|
| 789 | - } else { |
|
| 790 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 791 | - } |
|
| 792 | - $sql .= ' WHERE ' . $whereclause; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - if ($debug) { |
|
| 796 | - xoops_debug($sql); |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - if (false != $force) { |
|
| 800 | - $result = $this->db->queryF($sql); |
|
| 801 | - } else { |
|
| 802 | - $result = $this->db->query($sql); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - if (!$result) { |
|
| 806 | - $obj->setErrors($this->db->error()); |
|
| 807 | - |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - if ($obj->isNew() && !is_array($this->keyName)) { |
|
| 812 | - $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
| 813 | - } |
|
| 814 | - $eventResult = $this->executeEvent('afterSave', $obj); |
|
| 815 | - if (!$eventResult) { |
|
| 816 | - $obj->setErrors('An error occured during the AfterSave event'); |
|
| 817 | - |
|
| 818 | - return false; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - if ($obj->isNew()) { |
|
| 822 | - $obj->unsetNew(); |
|
| 823 | - $eventResult = $this->executeEvent('afterInsert', $obj); |
|
| 824 | - if (!$eventResult) { |
|
| 825 | - $obj->setErrors('An error occured during the AfterInsert event'); |
|
| 826 | - |
|
| 827 | - return false; |
|
| 828 | - } |
|
| 829 | - } else { |
|
| 830 | - $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
| 831 | - if (!$eventResult) { |
|
| 832 | - $obj->setErrors('An error occured during the AfterUpdate event'); |
|
| 833 | - |
|
| 834 | - return false; |
|
| 835 | - } |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - return true; |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - /** |
|
| 842 | - * @param $obj |
|
| 843 | - * @param bool $force |
|
| 844 | - * @param bool $checkObject |
|
| 845 | - * @param bool $debug |
|
| 846 | - * @return bool |
|
| 847 | - */ |
|
| 848 | - public function insertD(&$obj, $force = false, $checkObject = true, $debug = false) |
|
| 849 | - { |
|
| 850 | - return $this->insert($obj, $force, $checkObject, true); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Change a value for objects with a certain criteria |
|
| 855 | - * |
|
| 856 | - * @param string $fieldname Name of the field |
|
| 857 | - * @param string $fieldvalue Value to write |
|
| 858 | - * @param object $criteria {@link CriteriaElement} |
|
| 859 | - * |
|
| 860 | - * @param bool $force |
|
| 861 | - * @return bool |
|
| 862 | - */ |
|
| 863 | - public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false) |
|
| 864 | - { |
|
| 865 | - $set_clause = $fieldname . ' = '; |
|
| 866 | - if (is_numeric($fieldvalue)) { |
|
| 867 | - $set_clause .= $fieldvalue; |
|
| 868 | - } elseif (is_array($fieldvalue)) { |
|
| 869 | - $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
| 870 | - } else { |
|
| 871 | - $set_clause .= $this->db->quoteString($fieldvalue); |
|
| 872 | - } |
|
| 873 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 874 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 875 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 876 | - } |
|
| 877 | - if (false != $force) { |
|
| 878 | - $result = $this->db->queryF($sql); |
|
| 879 | - } else { |
|
| 880 | - $result = $this->db->query($sql); |
|
| 881 | - } |
|
| 882 | - if (!$result) { |
|
| 883 | - return false; |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - return true; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - /** |
|
| 890 | - * delete all objects meeting the conditions |
|
| 891 | - * |
|
| 892 | - * @param object $criteria {@link CriteriaElement} with conditions to meet |
|
| 893 | - * @return bool |
|
| 894 | - */ |
|
| 895 | - |
|
| 896 | - public function deleteAll($criteria = null) |
|
| 897 | - { |
|
| 898 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 899 | - $sql = 'DELETE FROM ' . $this->table; |
|
| 900 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 901 | - if (!$this->db->query($sql)) { |
|
| 902 | - return false; |
|
| 903 | - } |
|
| 904 | - $rows = $this->db->getAffectedRows(); |
|
| 905 | - |
|
| 906 | - return $rows > 0 ? $rows : true; |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - return false; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * @return mixed |
|
| 914 | - */ |
|
| 915 | - public function getModuleInfo() |
|
| 916 | - { |
|
| 917 | - return smart_getModuleInfo($this->_moduleName); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * @return bool |
|
| 922 | - */ |
|
| 923 | - public function getModuleConfig() |
|
| 924 | - { |
|
| 925 | - return smart_getModuleConfig($this->_moduleName); |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * @return string |
|
| 930 | - */ |
|
| 931 | - public function getModuleItemString() |
|
| 932 | - { |
|
| 933 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 934 | - |
|
| 935 | - return $ret; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * @param $object |
|
| 940 | - */ |
|
| 941 | - public function updateCounter($object) |
|
| 942 | - { |
|
| 943 | - if (isset($object->vars['counter'])) { |
|
| 944 | - $new_counter = $object->getVar('counter') + 1; |
|
| 945 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 946 | - $this->query($sql, null, true); |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - /** |
|
| 951 | - * Execute the function associated with an event |
|
| 952 | - * This method will check if the function is available |
|
| 953 | - * |
|
| 954 | - * @param string $event name of the event |
|
| 955 | - * @param $executeEventObj |
|
| 956 | - * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
| 957 | - * @internal param object $obj $object on which is performed the event |
|
| 958 | - */ |
|
| 959 | - public function executeEvent($event, &$executeEventObj) |
|
| 960 | - { |
|
| 961 | - if (!in_array($event, $this->_disabledEvents)) { |
|
| 962 | - if (method_exists($this, $event)) { |
|
| 963 | - $ret = $this->$event($executeEventObj); |
|
| 964 | - } else { |
|
| 965 | - // check to see if there is a hook for this event |
|
| 966 | - if (isset($this->_eventHooks[$event])) { |
|
| 967 | - $method = $this->_eventHooks[$event]; |
|
| 968 | - // check to see if the method specified by this hook exists |
|
| 969 | - if (method_exists($this, $method)) { |
|
| 970 | - $ret = $this->$method($executeEventObj); |
|
| 971 | - } |
|
| 972 | - } |
|
| 973 | - $ret = true; |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - return $ret; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - return true; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * @param bool $withprefix |
|
| 984 | - * @return string |
|
| 985 | - */ |
|
| 986 | - public function getIdentifierName($withprefix = true) |
|
| 987 | - { |
|
| 988 | - if ($withprefix) { |
|
| 989 | - return $this->_itemname . '.' . $this->identifierName; |
|
| 990 | - } else { |
|
| 991 | - return $this->identifierName; |
|
| 992 | - } |
|
| 993 | - } |
|
| 28 | + public $_itemname; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Name of the table use to store this {@link SmartObject} |
|
| 32 | + * |
|
| 33 | + * Note that the name of the table needs to be free of the database prefix. |
|
| 34 | + * For example "smartsection_categories" |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + public $table; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Name of the table key that uniquely identify each {@link SmartObject} |
|
| 41 | + * |
|
| 42 | + * For example: "categoryid" |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + public $keyName; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Name of the class derived from {@link SmartObject} and which this handler is handling |
|
| 49 | + * |
|
| 50 | + * Note that this string needs to be lowercase |
|
| 51 | + * |
|
| 52 | + * For example: "smartsectioncategory" |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + public $className; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Name of the field which properly identify the {@link SmartObject} |
|
| 59 | + * |
|
| 60 | + * For example: "name" (this will be the category's name) |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $identifierName; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Name of the field which will be use as a summary for the object |
|
| 67 | + * |
|
| 68 | + * For example: "summary" |
|
| 69 | + * @var string |
|
| 70 | + */ |
|
| 71 | + public $summaryName; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Page name use to basically manage and display the {@link SmartObject} |
|
| 75 | + * |
|
| 76 | + * This page needs to be the same in user side and admin side |
|
| 77 | + * |
|
| 78 | + * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php |
|
| 79 | + * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page |
|
| 80 | + * @var string |
|
| 81 | + */ |
|
| 82 | + public $_page; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Full path of the module using this {@link SmartObject} |
|
| 86 | + * |
|
| 87 | + * <code>XOOPS_URL . "/modules/smartsection/"</code> |
|
| 88 | + * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name |
|
| 89 | + * @var string |
|
| 90 | + */ |
|
| 91 | + public $_modulePath; |
|
| 92 | + |
|
| 93 | + public $_moduleUrl; |
|
| 94 | + |
|
| 95 | + public $_moduleName; |
|
| 96 | + |
|
| 97 | + public $_uploadUrl; |
|
| 98 | + |
|
| 99 | + public $_uploadPath; |
|
| 100 | + |
|
| 101 | + public $_allowedMimeTypes = 0; |
|
| 102 | + |
|
| 103 | + public $_maxFileSize = 1000000; |
|
| 104 | + |
|
| 105 | + public $_maxWidth = 500; |
|
| 106 | + |
|
| 107 | + public $_maxHeight = 500; |
|
| 108 | + |
|
| 109 | + public $highlightFields = array(); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Array containing the events name and functions |
|
| 113 | + * |
|
| 114 | + * @var array |
|
| 115 | + */ |
|
| 116 | + public $eventArray = array(); |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Array containing the permissions that this handler will manage on the objects |
|
| 120 | + * |
|
| 121 | + * @var array |
|
| 122 | + */ |
|
| 123 | + public $permissionsArray = false; |
|
| 124 | + |
|
| 125 | + public $generalSQL = false; |
|
| 126 | + |
|
| 127 | + public $_eventHooks = array(); |
|
| 128 | + public $_disabledEvents = array(); |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Constructor - called from child classes |
|
| 132 | + * |
|
| 133 | + * @param object|XoopsDatabase $db {@link XoopsDatabase} |
|
| 134 | + * object |
|
| 135 | + * @param $itemname |
|
| 136 | + * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
| 137 | + * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
| 138 | + * @param $summaryName |
|
| 139 | + * @param $modulename |
|
| 140 | + * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 141 | + * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
| 142 | + * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 143 | + * @internal param string $moduleName name of the module |
|
| 144 | + */ |
|
| 145 | + public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
| 146 | + { |
|
| 147 | + parent::__construct($db); |
|
| 148 | + |
|
| 149 | + $this->_itemname = $itemname; |
|
| 150 | + $this->_moduleName = $modulename; |
|
| 151 | + $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 152 | + $this->keyName = $keyname; |
|
| 153 | + $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 154 | + $this->identifierName = $idenfierName; |
|
| 155 | + $this->summaryName = $summaryName; |
|
| 156 | + $this->_page = $itemname . '.php'; |
|
| 157 | + $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 158 | + $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 159 | + $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 160 | + $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param $event |
|
| 165 | + * @param $method |
|
| 166 | + */ |
|
| 167 | + public function addEventHook($event, $method) |
|
| 168 | + { |
|
| 169 | + $this->_eventHooks[$event] = $method; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Add a permission that this handler will manage for its objects |
|
| 174 | + * |
|
| 175 | + * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
| 176 | + * |
|
| 177 | + * @param string $perm_name name of the permission |
|
| 178 | + * @param string $caption caption of the control that will be displayed in the form |
|
| 179 | + * @param bool|string $description description of the control that will be displayed in the form |
|
| 180 | + */ |
|
| 181 | + public function addPermission($perm_name, $caption, $description = false) |
|
| 182 | + { |
|
| 183 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'); |
|
| 184 | + |
|
| 185 | + $this->permissionsArray[] = array( |
|
| 186 | + 'perm_name' => $perm_name, |
|
| 187 | + 'caption' => $caption, |
|
| 188 | + 'description' => $description |
|
| 189 | + ); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @param $criteria |
|
| 194 | + * @param $perm_name |
|
| 195 | + * @return bool |
|
| 196 | + */ |
|
| 197 | + public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
|
| 198 | + { |
|
| 199 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
| 200 | + $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 201 | + if (count($grantedItems) > 0) { |
|
| 202 | + $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 203 | + |
|
| 204 | + return true; |
|
| 205 | + } else { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param bool $_uploadPath |
|
| 212 | + * @param bool $_allowedMimeTypes |
|
| 213 | + * @param bool $_maxFileSize |
|
| 214 | + * @param bool $_maxWidth |
|
| 215 | + * @param bool $_maxHeight |
|
| 216 | + */ |
|
| 217 | + public function setUploaderConfig($_uploadPath = false, $_allowedMimeTypes = false, $_maxFileSize = false, $_maxWidth = false, $_maxHeight = false) |
|
| 218 | + { |
|
| 219 | + $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
| 220 | + $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
| 221 | + $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
| 222 | + $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
| 223 | + $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * create a new {@link SmartObject} |
|
| 228 | + * |
|
| 229 | + * @param bool $isNew Flag the new objects as "new"? |
|
| 230 | + * |
|
| 231 | + * @return object {@link SmartObject} |
|
| 232 | + */ |
|
| 233 | + public function &create($isNew = true) |
|
| 234 | + { |
|
| 235 | + $obj = new $this->className($this); |
|
| 236 | + $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
| 237 | + if (!$obj->handler) { |
|
| 238 | + $obj->handler =& $this; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + if ($isNew === true) { |
|
| 242 | + $obj->setNew(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return $obj; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function getImageUrl() |
|
| 252 | + { |
|
| 253 | + return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @return string |
|
| 258 | + */ |
|
| 259 | + public function getImagePath() |
|
| 260 | + { |
|
| 261 | + $dir = $this->_uploadPath . $this->_itemname; |
|
| 262 | + if (!file_exists($dir)) { |
|
| 263 | + smart_admin_mkdir($dir); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $dir . '/'; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * retrieve a {@link SmartObject} |
|
| 271 | + * |
|
| 272 | + * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
| 273 | + * @param bool $as_object whether to return an object or an array |
|
| 274 | + * @param bool $debug |
|
| 275 | + * @param bool $criteria |
|
| 276 | + * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
| 277 | + * FALSE if failed |
|
| 278 | + */ |
|
| 279 | + public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
| 280 | + { |
|
| 281 | + if (!$criteria) { |
|
| 282 | + $criteria = new CriteriaCompo(); |
|
| 283 | + } |
|
| 284 | + if (is_array($this->keyName)) { |
|
| 285 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 286 | + /** |
|
| 287 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 288 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
| 289 | + */ |
|
| 290 | + //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
| 291 | + $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
| 292 | + } |
|
| 293 | + } else { |
|
| 294 | + //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
| 295 | + /** |
|
| 296 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 297 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
| 298 | + */ |
|
| 299 | + $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
| 300 | + } |
|
| 301 | + $criteria->setLimit(1); |
|
| 302 | + if ($debug) { |
|
| 303 | + $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
| 304 | + } else { |
|
| 305 | + $obj_array = $this->getObjects($criteria, false, $as_object); |
|
| 306 | + //patch: weird bug of indexing by id even if id_as_key = false; |
|
| 307 | + if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
| 308 | + $obj_array[0] = $obj_array[$id]; |
|
| 309 | + unset($obj_array[$id]); |
|
| 310 | + $obj_array[0]->unsetNew(); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + if (count($obj_array) != 1) { |
|
| 315 | + $obj =& $this->create(); |
|
| 316 | + |
|
| 317 | + return $obj; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + return $obj_array[0]; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * retrieve a {@link SmartObject} |
|
| 325 | + * |
|
| 326 | + * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
| 327 | + * @param bool $as_object whether to return an object or an array |
|
| 328 | + * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
| 329 | + */ |
|
| 330 | + public function &getD($id, $as_object = true) |
|
| 331 | + { |
|
| 332 | + return $this->get($id, $as_object, true); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * retrieve objects from the database |
|
| 337 | + * |
|
| 338 | + * @param object $criteria {@link CriteriaElement} conditions to be met |
|
| 339 | + * @param bool $id_as_key use the ID as key for the array? |
|
| 340 | + * @param bool $as_object return an array of objects? |
|
| 341 | + * |
|
| 342 | + * @param bool $sql |
|
| 343 | + * @param bool $debug |
|
| 344 | + * @return array |
|
| 345 | + */ |
|
| 346 | + public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false) |
|
| 347 | + { |
|
| 348 | + $ret = array(); |
|
| 349 | + $limit = $start = 0; |
|
| 350 | + |
|
| 351 | + if ($this->generalSQL) { |
|
| 352 | + $sql = $this->generalSQL; |
|
| 353 | + } elseif (!$sql) { |
|
| 354 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 358 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 359 | + if ($criteria->getSort() != '') { |
|
| 360 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 361 | + } |
|
| 362 | + $limit = $criteria->getLimit(); |
|
| 363 | + $start = $criteria->getStart(); |
|
| 364 | + } |
|
| 365 | + if ($debug) { |
|
| 366 | + xoops_debug($sql); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $result = $this->db->query($sql, $limit, $start); |
|
| 370 | + if (!$result) { |
|
| 371 | + return $ret; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + return $this->convertResultSet($result, $id_as_key, $as_object); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @param $sql |
|
| 379 | + * @param $criteria |
|
| 380 | + * @param bool $force |
|
| 381 | + * @param bool $debug |
|
| 382 | + * @return array |
|
| 383 | + */ |
|
| 384 | + public function query($sql, $criteria, $force = false, $debug = false) |
|
| 385 | + { |
|
| 386 | + $ret = array(); |
|
| 387 | + |
|
| 388 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 389 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 390 | + if ($criteria->groupby) { |
|
| 391 | + $sql .= $criteria->getGroupby(); |
|
| 392 | + } |
|
| 393 | + if ($criteria->getSort() != '') { |
|
| 394 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + if ($debug) { |
|
| 398 | + xoops_debug($sql); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + if ($force) { |
|
| 402 | + $result = $this->db->queryF($sql); |
|
| 403 | + } else { |
|
| 404 | + $result = $this->db->query($sql); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + if (!$result) { |
|
| 408 | + return $ret; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + while ($myrow = $this->db->fetchArray($result)) { |
|
| 412 | + $ret[] = $myrow; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + return $ret; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * retrieve objects with debug mode - so will show the query |
|
| 420 | + * |
|
| 421 | + * @param object $criteria {@link CriteriaElement} conditions to be met |
|
| 422 | + * @param bool $id_as_key use the ID as key for the array? |
|
| 423 | + * @param bool $as_object return an array of objects? |
|
| 424 | + * |
|
| 425 | + * @param bool $sql |
|
| 426 | + * @return array |
|
| 427 | + */ |
|
| 428 | + public function getObjectsD($criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
| 429 | + { |
|
| 430 | + return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @param $arrayObjects |
|
| 435 | + * @return array|bool |
|
| 436 | + */ |
|
| 437 | + public function getObjectsAsArray($arrayObjects) |
|
| 438 | + { |
|
| 439 | + $ret = array(); |
|
| 440 | + foreach ($arrayObjects as $key => $object) { |
|
| 441 | + $ret[$key] = $object->toArray(); |
|
| 442 | + } |
|
| 443 | + if (count($ret > 0)) { |
|
| 444 | + return $ret; |
|
| 445 | + } else { |
|
| 446 | + return false; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Convert a database resultset to a returnable array |
|
| 452 | + * |
|
| 453 | + * @param object $result database resultset |
|
| 454 | + * @param bool $id_as_key - should NOT be used with joint keys |
|
| 455 | + * @param bool $as_object |
|
| 456 | + * |
|
| 457 | + * @return array |
|
| 458 | + */ |
|
| 459 | + public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
| 460 | + { |
|
| 461 | + $ret = array(); |
|
| 462 | + while ($myrow = $this->db->fetchArray($result)) { |
|
| 463 | + $obj =& $this->create(false); |
|
| 464 | + $obj->assignVars($myrow); |
|
| 465 | + if (!$id_as_key) { |
|
| 466 | + if ($as_object) { |
|
| 467 | + $ret[] =& $obj; |
|
| 468 | + } else { |
|
| 469 | + $ret[] = $obj->toArray(); |
|
| 470 | + } |
|
| 471 | + } else { |
|
| 472 | + if ($as_object) { |
|
| 473 | + $value =& $obj; |
|
| 474 | + } else { |
|
| 475 | + $value = $obj->toArray(); |
|
| 476 | + } |
|
| 477 | + if ($id_as_key === 'parentid') { |
|
| 478 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 479 | + } else { |
|
| 480 | + $ret[$obj->getVar($this->keyName)] = $value; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + unset($obj); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $ret; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @param null $criteria |
|
| 491 | + * @param int $limit |
|
| 492 | + * @param int $start |
|
| 493 | + * @return array |
|
| 494 | + */ |
|
| 495 | + public function getListD($criteria = null, $limit = 0, $start = 0) |
|
| 496 | + { |
|
| 497 | + return $this->getList($criteria, $limit, $start, true); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
| 502 | + * |
|
| 503 | + * @param object $criteria {@link CriteriaElement} conditions to be met |
|
| 504 | + * @param int $limit Max number of objects to fetch |
|
| 505 | + * @param int $start Which record to start at |
|
| 506 | + * |
|
| 507 | + * @param bool $debug |
|
| 508 | + * @return array |
|
| 509 | + */ |
|
| 510 | + public function getList($criteria = null, $limit = 0, $start = 0, $debug = false) |
|
| 511 | + { |
|
| 512 | + $ret = array(); |
|
| 513 | + if ($criteria == null) { |
|
| 514 | + $criteria = new CriteriaCompo(); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if ($criteria->getSort() == '') { |
|
| 518 | + $criteria->setSort($this->getIdentifierName()); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 522 | + if (!empty($this->identifierName)) { |
|
| 523 | + $sql .= ', ' . $this->getIdentifierName(); |
|
| 524 | + } |
|
| 525 | + $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 526 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 527 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 528 | + if ($criteria->getSort() != '') { |
|
| 529 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 530 | + } |
|
| 531 | + $limit = $criteria->getLimit(); |
|
| 532 | + $start = $criteria->getStart(); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + if ($debug) { |
|
| 536 | + xoops_debug($sql); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + $result = $this->db->query($sql, $limit, $start); |
|
| 540 | + if (!$result) { |
|
| 541 | + return $ret; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + $myts = MyTextSanitizer::getInstance(); |
|
| 545 | + while ($myrow = $this->db->fetchArray($result)) { |
|
| 546 | + //identifiers should be textboxes, so sanitize them like that |
|
| 547 | + $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + return $ret; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * count objects matching a condition |
|
| 555 | + * |
|
| 556 | + * @param object $criteria {@link CriteriaElement} to match |
|
| 557 | + * @return int count of objects |
|
| 558 | + */ |
|
| 559 | + public function getCount($criteria = null) |
|
| 560 | + { |
|
| 561 | + $field = ''; |
|
| 562 | + $groupby = false; |
|
| 563 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 564 | + if ($criteria->groupby != '') { |
|
| 565 | + $groupby = true; |
|
| 566 | + $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + /** |
|
| 570 | + * if we have a generalSQL, lets used this one. |
|
| 571 | + * This needs to be improved... |
|
| 572 | + */ |
|
| 573 | + if ($this->generalSQL) { |
|
| 574 | + $sql = $this->generalSQL; |
|
| 575 | + $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
| 576 | + } else { |
|
| 577 | + $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 578 | + } |
|
| 579 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 580 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 581 | + if ($criteria->groupby != '') { |
|
| 582 | + $sql .= $criteria->getGroupby(); |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + $result = $this->db->query($sql); |
|
| 587 | + if (!$result) { |
|
| 588 | + return 0; |
|
| 589 | + } |
|
| 590 | + if ($groupby == false) { |
|
| 591 | + list($count) = $this->db->fetchRow($result); |
|
| 592 | + |
|
| 593 | + return $count; |
|
| 594 | + } else { |
|
| 595 | + $ret = array(); |
|
| 596 | + while (list($id, $count) = $this->db->fetchRow($result)) { |
|
| 597 | + $ret[$id] = $count; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + return $ret; |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * delete an object from the database |
|
| 606 | + * |
|
| 607 | + * @param XoopsObject $obj reference to the object to delete |
|
| 608 | + * @param bool $force |
|
| 609 | + * @return bool FALSE if failed. |
|
| 610 | + */ |
|
| 611 | + public function delete(XoopsObject $obj, $force = false) |
|
| 612 | + { |
|
| 613 | + $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
| 614 | + if (!$eventResult) { |
|
| 615 | + $obj->setErrors('An error occured during the BeforeDelete event'); |
|
| 616 | + |
|
| 617 | + return false; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + if (is_array($this->keyName)) { |
|
| 621 | + $clause = array(); |
|
| 622 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 623 | + $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 624 | + } |
|
| 625 | + $whereclause = implode(' AND ', $clause); |
|
| 626 | + } else { |
|
| 627 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 628 | + } |
|
| 629 | + $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 630 | + if (false != $force) { |
|
| 631 | + $result = $this->db->queryF($sql); |
|
| 632 | + } else { |
|
| 633 | + $result = $this->db->query($sql); |
|
| 634 | + } |
|
| 635 | + if (!$result) { |
|
| 636 | + return false; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + $eventResult = $this->executeEvent('afterDelete', $obj); |
|
| 640 | + if (!$eventResult) { |
|
| 641 | + $obj->setErrors('An error occured during the AfterDelete event'); |
|
| 642 | + |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + return true; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * @param $event |
|
| 651 | + */ |
|
| 652 | + public function disableEvent($event) |
|
| 653 | + { |
|
| 654 | + if (is_array($event)) { |
|
| 655 | + foreach ($event as $v) { |
|
| 656 | + $this->_disabledEvents[] = $v; |
|
| 657 | + } |
|
| 658 | + } else { |
|
| 659 | + $this->_disabledEvents[] = $event; |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * @return array |
|
| 665 | + */ |
|
| 666 | + public function getPermissions() |
|
| 667 | + { |
|
| 668 | + return $this->permissionsArray; |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * insert a new object in the database |
|
| 673 | + * |
|
| 674 | + * @param XoopsObject $obj reference to the object |
|
| 675 | + * @param bool $force whether to force the query execution despite security settings |
|
| 676 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
| 677 | + * @param bool $debug |
|
| 678 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 679 | + */ |
|
| 680 | + public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
| 681 | + { |
|
| 682 | + if ($checkObject != false) { |
|
| 683 | + if (!is_object($obj)) { |
|
| 684 | + return false; |
|
| 685 | + } |
|
| 686 | + /** |
|
| 687 | + * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
| 688 | + */ |
|
| 689 | + if (!is_a($obj, $this->className)) { |
|
| 690 | + $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 691 | + |
|
| 692 | + return false; |
|
| 693 | + } |
|
| 694 | + if (!$obj->isDirty()) { |
|
| 695 | + $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith |
|
| 696 | + |
|
| 697 | + return true; |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + if ($obj->seoEnabled) { |
|
| 702 | + // Auto create meta tags if empty |
|
| 703 | + $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
| 704 | + |
|
| 705 | + if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
| 706 | + if (!$obj->meta_keywords()) { |
|
| 707 | + $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + if (!$obj->meta_description()) { |
|
| 711 | + $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
| 712 | + } |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + // Auto create short_url if empty |
|
| 716 | + if (!$obj->short_url()) { |
|
| 717 | + $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + $eventResult = $this->executeEvent('beforeSave', $obj); |
|
| 722 | + if (!$eventResult) { |
|
| 723 | + $obj->setErrors('An error occured during the BeforeSave event'); |
|
| 724 | + |
|
| 725 | + return false; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + if ($obj->isNew()) { |
|
| 729 | + $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
| 730 | + if (!$eventResult) { |
|
| 731 | + $obj->setErrors('An error occured during the BeforeInsert event'); |
|
| 732 | + |
|
| 733 | + return false; |
|
| 734 | + } |
|
| 735 | + } else { |
|
| 736 | + $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
| 737 | + if (!$eventResult) { |
|
| 738 | + $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
| 739 | + |
|
| 740 | + return false; |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + if (!$obj->cleanVars()) { |
|
| 744 | + $obj->setErrors('Variables were not cleaned properly.'); |
|
| 745 | + |
|
| 746 | + return false; |
|
| 747 | + } |
|
| 748 | + $fieldsToStoreInDB = array(); |
|
| 749 | + foreach ($obj->cleanVars as $k => $v) { |
|
| 750 | + if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
| 751 | + $cleanvars[$k] = (int)$v; |
|
| 752 | + } elseif (is_array($v)) { |
|
| 753 | + $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
| 754 | + } else { |
|
| 755 | + $cleanvars[$k] = $this->db->quoteString($v); |
|
| 756 | + } |
|
| 757 | + if ($obj->vars[$k]['persistent']) { |
|
| 758 | + $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + if ($obj->isNew()) { |
|
| 762 | + if (!is_array($this->keyName)) { |
|
| 763 | + if ($cleanvars[$this->keyName] < 1) { |
|
| 764 | + $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 769 | + } else { |
|
| 770 | + $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 771 | + foreach ($fieldsToStoreInDB as $key => $value) { |
|
| 772 | + if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
|
| 773 | + continue; |
|
| 774 | + } |
|
| 775 | + if (isset($notfirst)) { |
|
| 776 | + $sql .= ','; |
|
| 777 | + } |
|
| 778 | + $sql .= ' ' . $key . ' = ' . $value; |
|
| 779 | + $notfirst = true; |
|
| 780 | + } |
|
| 781 | + if (is_array($this->keyName)) { |
|
| 782 | + $whereclause = ''; |
|
| 783 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 784 | + if ($i > 0) { |
|
| 785 | + $whereclause .= ' AND '; |
|
| 786 | + } |
|
| 787 | + $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 788 | + } |
|
| 789 | + } else { |
|
| 790 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 791 | + } |
|
| 792 | + $sql .= ' WHERE ' . $whereclause; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + if ($debug) { |
|
| 796 | + xoops_debug($sql); |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + if (false != $force) { |
|
| 800 | + $result = $this->db->queryF($sql); |
|
| 801 | + } else { |
|
| 802 | + $result = $this->db->query($sql); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + if (!$result) { |
|
| 806 | + $obj->setErrors($this->db->error()); |
|
| 807 | + |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + if ($obj->isNew() && !is_array($this->keyName)) { |
|
| 812 | + $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
| 813 | + } |
|
| 814 | + $eventResult = $this->executeEvent('afterSave', $obj); |
|
| 815 | + if (!$eventResult) { |
|
| 816 | + $obj->setErrors('An error occured during the AfterSave event'); |
|
| 817 | + |
|
| 818 | + return false; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + if ($obj->isNew()) { |
|
| 822 | + $obj->unsetNew(); |
|
| 823 | + $eventResult = $this->executeEvent('afterInsert', $obj); |
|
| 824 | + if (!$eventResult) { |
|
| 825 | + $obj->setErrors('An error occured during the AfterInsert event'); |
|
| 826 | + |
|
| 827 | + return false; |
|
| 828 | + } |
|
| 829 | + } else { |
|
| 830 | + $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
| 831 | + if (!$eventResult) { |
|
| 832 | + $obj->setErrors('An error occured during the AfterUpdate event'); |
|
| 833 | + |
|
| 834 | + return false; |
|
| 835 | + } |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + return true; |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + /** |
|
| 842 | + * @param $obj |
|
| 843 | + * @param bool $force |
|
| 844 | + * @param bool $checkObject |
|
| 845 | + * @param bool $debug |
|
| 846 | + * @return bool |
|
| 847 | + */ |
|
| 848 | + public function insertD(&$obj, $force = false, $checkObject = true, $debug = false) |
|
| 849 | + { |
|
| 850 | + return $this->insert($obj, $force, $checkObject, true); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Change a value for objects with a certain criteria |
|
| 855 | + * |
|
| 856 | + * @param string $fieldname Name of the field |
|
| 857 | + * @param string $fieldvalue Value to write |
|
| 858 | + * @param object $criteria {@link CriteriaElement} |
|
| 859 | + * |
|
| 860 | + * @param bool $force |
|
| 861 | + * @return bool |
|
| 862 | + */ |
|
| 863 | + public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false) |
|
| 864 | + { |
|
| 865 | + $set_clause = $fieldname . ' = '; |
|
| 866 | + if (is_numeric($fieldvalue)) { |
|
| 867 | + $set_clause .= $fieldvalue; |
|
| 868 | + } elseif (is_array($fieldvalue)) { |
|
| 869 | + $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
| 870 | + } else { |
|
| 871 | + $set_clause .= $this->db->quoteString($fieldvalue); |
|
| 872 | + } |
|
| 873 | + $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 874 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 875 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 876 | + } |
|
| 877 | + if (false != $force) { |
|
| 878 | + $result = $this->db->queryF($sql); |
|
| 879 | + } else { |
|
| 880 | + $result = $this->db->query($sql); |
|
| 881 | + } |
|
| 882 | + if (!$result) { |
|
| 883 | + return false; |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + return true; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * delete all objects meeting the conditions |
|
| 891 | + * |
|
| 892 | + * @param object $criteria {@link CriteriaElement} with conditions to meet |
|
| 893 | + * @return bool |
|
| 894 | + */ |
|
| 895 | + |
|
| 896 | + public function deleteAll($criteria = null) |
|
| 897 | + { |
|
| 898 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 899 | + $sql = 'DELETE FROM ' . $this->table; |
|
| 900 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 901 | + if (!$this->db->query($sql)) { |
|
| 902 | + return false; |
|
| 903 | + } |
|
| 904 | + $rows = $this->db->getAffectedRows(); |
|
| 905 | + |
|
| 906 | + return $rows > 0 ? $rows : true; |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + return false; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * @return mixed |
|
| 914 | + */ |
|
| 915 | + public function getModuleInfo() |
|
| 916 | + { |
|
| 917 | + return smart_getModuleInfo($this->_moduleName); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * @return bool |
|
| 922 | + */ |
|
| 923 | + public function getModuleConfig() |
|
| 924 | + { |
|
| 925 | + return smart_getModuleConfig($this->_moduleName); |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * @return string |
|
| 930 | + */ |
|
| 931 | + public function getModuleItemString() |
|
| 932 | + { |
|
| 933 | + $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 934 | + |
|
| 935 | + return $ret; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * @param $object |
|
| 940 | + */ |
|
| 941 | + public function updateCounter($object) |
|
| 942 | + { |
|
| 943 | + if (isset($object->vars['counter'])) { |
|
| 944 | + $new_counter = $object->getVar('counter') + 1; |
|
| 945 | + $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 946 | + $this->query($sql, null, true); |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + /** |
|
| 951 | + * Execute the function associated with an event |
|
| 952 | + * This method will check if the function is available |
|
| 953 | + * |
|
| 954 | + * @param string $event name of the event |
|
| 955 | + * @param $executeEventObj |
|
| 956 | + * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
| 957 | + * @internal param object $obj $object on which is performed the event |
|
| 958 | + */ |
|
| 959 | + public function executeEvent($event, &$executeEventObj) |
|
| 960 | + { |
|
| 961 | + if (!in_array($event, $this->_disabledEvents)) { |
|
| 962 | + if (method_exists($this, $event)) { |
|
| 963 | + $ret = $this->$event($executeEventObj); |
|
| 964 | + } else { |
|
| 965 | + // check to see if there is a hook for this event |
|
| 966 | + if (isset($this->_eventHooks[$event])) { |
|
| 967 | + $method = $this->_eventHooks[$event]; |
|
| 968 | + // check to see if the method specified by this hook exists |
|
| 969 | + if (method_exists($this, $method)) { |
|
| 970 | + $ret = $this->$method($executeEventObj); |
|
| 971 | + } |
|
| 972 | + } |
|
| 973 | + $ret = true; |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + return $ret; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + return true; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * @param bool $withprefix |
|
| 984 | + * @return string |
|
| 985 | + */ |
|
| 986 | + public function getIdentifierName($withprefix = true) |
|
| 987 | + { |
|
| 988 | + if ($withprefix) { |
|
| 989 | + return $this->_itemname . '.' . $this->identifierName; |
|
| 990 | + } else { |
|
| 991 | + return $this->identifierName; |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | 994 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
| 198 | 198 | { |
| 199 | 199 | $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
| 200 | - $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 200 | + $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 201 | 201 | if (count($grantedItems) > 0) { |
| 202 | 202 | $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
| 203 | 203 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $obj = new $this->className($this); |
| 236 | 236 | $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
| 237 | 237 | if (!$obj->handler) { |
| 238 | - $obj->handler =& $this; |
|
| 238 | + $obj->handler = & $this; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | if ($isNew === true) { |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | if (count($obj_array) != 1) { |
| 315 | - $obj =& $this->create(); |
|
| 315 | + $obj = & $this->create(); |
|
| 316 | 316 | |
| 317 | 317 | return $obj; |
| 318 | 318 | } |
@@ -460,22 +460,22 @@ discard block |
||
| 460 | 460 | { |
| 461 | 461 | $ret = array(); |
| 462 | 462 | while ($myrow = $this->db->fetchArray($result)) { |
| 463 | - $obj =& $this->create(false); |
|
| 463 | + $obj = & $this->create(false); |
|
| 464 | 464 | $obj->assignVars($myrow); |
| 465 | 465 | if (!$id_as_key) { |
| 466 | 466 | if ($as_object) { |
| 467 | - $ret[] =& $obj; |
|
| 467 | + $ret[] = & $obj; |
|
| 468 | 468 | } else { |
| 469 | 469 | $ret[] = $obj->toArray(); |
| 470 | 470 | } |
| 471 | 471 | } else { |
| 472 | 472 | if ($as_object) { |
| 473 | - $value =& $obj; |
|
| 473 | + $value = & $obj; |
|
| 474 | 474 | } else { |
| 475 | 475 | $value = $obj->toArray(); |
| 476 | 476 | } |
| 477 | 477 | if ($id_as_key === 'parentid') { |
| 478 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 478 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value; |
|
| 479 | 479 | } else { |
| 480 | 480 | $ret[$obj->getVar($this->keyName)] = $value; |
| 481 | 481 | } |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | $fieldsToStoreInDB = array(); |
| 749 | 749 | foreach ($obj->cleanVars as $k => $v) { |
| 750 | 750 | if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
| 751 | - $cleanvars[$k] = (int)$v; |
|
| 751 | + $cleanvars[$k] = (int) $v; |
|
| 752 | 752 | } elseif (is_array($v)) { |
| 753 | 753 | $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
| 754 | 754 | } else { |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | * @access public |
| 62 | 62 | * @param string $key key of the object's variable to be returned |
| 63 | 63 | * @param string $format format to use for the output |
| 64 | - * @return mixed formatted value of the variable |
|
| 64 | + * @return integer formatted value of the variable |
|
| 65 | 65 | */ |
| 66 | 66 | public function getVar($key, $format = 's') |
| 67 | 67 | { |
@@ -35,154 +35,154 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class SmartobjectLink extends SmartObject |
| 37 | 37 | { |
| 38 | - /** |
|
| 39 | - * SmartobjectLink constructor. |
|
| 40 | - */ |
|
| 41 | - public function __construct() |
|
| 42 | - { |
|
| 43 | - $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
| 44 | - $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
| 45 | - $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
| 46 | - $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
| 47 | - $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
| 48 | - $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
| 49 | - $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
| 50 | - $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
| 51 | - $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
| 52 | - $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
| 53 | - $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
| 54 | - $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
| 55 | - $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * returns a specific variable for the object in a proper format |
|
| 60 | - * |
|
| 61 | - * @access public |
|
| 62 | - * @param string $key key of the object's variable to be returned |
|
| 63 | - * @param string $format format to use for the output |
|
| 64 | - * @return mixed formatted value of the variable |
|
| 65 | - */ |
|
| 66 | - public function getVar($key, $format = 's') |
|
| 67 | - { |
|
| 68 | - if ($format === 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) { |
|
| 69 | - // return call_user_func(array($this, $key)); |
|
| 70 | - return $this->{$key}(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return parent::getVar($key, $format); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public function from_uid() |
|
| 80 | - { |
|
| 81 | - $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
| 82 | - |
|
| 83 | - return $ret; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param bool $withContact |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function to_uid($withContact = false) |
|
| 91 | - { |
|
| 92 | - $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
| 93 | - |
|
| 94 | - return $ret; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function date() |
|
| 101 | - { |
|
| 102 | - $ret = formatTimestamp($this->getVar('date', 'e')); |
|
| 103 | - |
|
| 104 | - return $ret; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param bool $full |
|
| 109 | - * @return mixed|string |
|
| 110 | - */ |
|
| 111 | - public function link($full = false) |
|
| 112 | - { |
|
| 113 | - $ret = $this->getVar('link', 'e'); |
|
| 114 | - if ($full) { |
|
| 115 | - $myts = MyTextSanitizer::getInstance(); |
|
| 116 | - $ret = $myts->displayTarea($ret); |
|
| 117 | - |
|
| 118 | - return $ret; |
|
| 119 | - } else { |
|
| 120 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 121 | - |
|
| 122 | - return $ret; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function getViewItemLink() |
|
| 130 | - { |
|
| 131 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '" /></a>'; |
|
| 132 | - |
|
| 133 | - return $ret; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - public function getFromInfo() |
|
| 140 | - { |
|
| 141 | - // check if from_uid represent a user |
|
| 142 | - |
|
| 143 | - if ($this->getVar('from_uid')) { |
|
| 144 | - $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
| 145 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 146 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $user; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @return array |
|
| 157 | - */ |
|
| 158 | - public function toArray() |
|
| 159 | - { |
|
| 160 | - $ret = parent::toArray(); |
|
| 161 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
| 162 | - $ret['toInfo'] = $this->getToInfo(); |
|
| 163 | - $ret['fullLink'] = $this->link(true); |
|
| 164 | - |
|
| 165 | - return $ret; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 171 | - public function getToInfo() |
|
| 172 | - { |
|
| 173 | - // check if from_uid represent a user |
|
| 174 | - |
|
| 175 | - if ($this->getVar('to_uid')) { |
|
| 176 | - $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
| 177 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 178 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 179 | - } |
|
| 180 | - } else { |
|
| 181 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $user; |
|
| 185 | - } |
|
| 38 | + /** |
|
| 39 | + * SmartobjectLink constructor. |
|
| 40 | + */ |
|
| 41 | + public function __construct() |
|
| 42 | + { |
|
| 43 | + $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
| 44 | + $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
| 45 | + $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
| 46 | + $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
| 47 | + $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
| 48 | + $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
| 49 | + $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
| 50 | + $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
| 51 | + $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
| 52 | + $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
| 53 | + $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
| 54 | + $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
| 55 | + $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * returns a specific variable for the object in a proper format |
|
| 60 | + * |
|
| 61 | + * @access public |
|
| 62 | + * @param string $key key of the object's variable to be returned |
|
| 63 | + * @param string $format format to use for the output |
|
| 64 | + * @return mixed formatted value of the variable |
|
| 65 | + */ |
|
| 66 | + public function getVar($key, $format = 's') |
|
| 67 | + { |
|
| 68 | + if ($format === 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) { |
|
| 69 | + // return call_user_func(array($this, $key)); |
|
| 70 | + return $this->{$key}(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return parent::getVar($key, $format); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public function from_uid() |
|
| 80 | + { |
|
| 81 | + $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
| 82 | + |
|
| 83 | + return $ret; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param bool $withContact |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function to_uid($withContact = false) |
|
| 91 | + { |
|
| 92 | + $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
| 93 | + |
|
| 94 | + return $ret; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function date() |
|
| 101 | + { |
|
| 102 | + $ret = formatTimestamp($this->getVar('date', 'e')); |
|
| 103 | + |
|
| 104 | + return $ret; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param bool $full |
|
| 109 | + * @return mixed|string |
|
| 110 | + */ |
|
| 111 | + public function link($full = false) |
|
| 112 | + { |
|
| 113 | + $ret = $this->getVar('link', 'e'); |
|
| 114 | + if ($full) { |
|
| 115 | + $myts = MyTextSanitizer::getInstance(); |
|
| 116 | + $ret = $myts->displayTarea($ret); |
|
| 117 | + |
|
| 118 | + return $ret; |
|
| 119 | + } else { |
|
| 120 | + $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 121 | + |
|
| 122 | + return $ret; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function getViewItemLink() |
|
| 130 | + { |
|
| 131 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '" /></a>'; |
|
| 132 | + |
|
| 133 | + return $ret; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + public function getFromInfo() |
|
| 140 | + { |
|
| 141 | + // check if from_uid represent a user |
|
| 142 | + |
|
| 143 | + if ($this->getVar('from_uid')) { |
|
| 144 | + $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
| 145 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 146 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $user; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @return array |
|
| 157 | + */ |
|
| 158 | + public function toArray() |
|
| 159 | + { |
|
| 160 | + $ret = parent::toArray(); |
|
| 161 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
| 162 | + $ret['toInfo'] = $this->getToInfo(); |
|
| 163 | + $ret['fullLink'] = $this->link(true); |
|
| 164 | + |
|
| 165 | + return $ret; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | + public function getToInfo() |
|
| 172 | + { |
|
| 173 | + // check if from_uid represent a user |
|
| 174 | + |
|
| 175 | + if ($this->getVar('to_uid')) { |
|
| 176 | + $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
| 177 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 178 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 179 | + } |
|
| 180 | + } else { |
|
| 181 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $user; |
|
| 185 | + } |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | class SmartobjectLinkHandler extends SmartPersistableObjectHandler |
| 192 | 192 | { |
| 193 | - /** |
|
| 194 | - * SmartobjectLinkHandler constructor. |
|
| 195 | - * @param object|XoopsDatabase $db |
|
| 196 | - */ |
|
| 197 | - public function __construct($db) |
|
| 198 | - { |
|
| 199 | - parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
| 200 | - } |
|
| 193 | + /** |
|
| 194 | + * SmartobjectLinkHandler constructor. |
|
| 195 | + * @param object|XoopsDatabase $db |
|
| 196 | + */ |
|
| 197 | + public function __construct($db) |
|
| 198 | + { |
|
| 199 | + parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
| 200 | + } |
|
| 201 | 201 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | /** |
| 34 | 34 | * @param $gperm_name |
| 35 | - * @param null $id |
|
| 35 | + * @param integer $id |
|
| 36 | 36 | * @return array |
| 37 | 37 | */ |
| 38 | 38 | public function getGrantedGroups($gperm_name, $id = null) |
@@ -11,18 +11,18 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class SmartobjectPermissionHandler extends XoopsObjectHandler |
| 13 | 13 | { |
| 14 | - public $handler; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * SmartobjectPermissionHandler constructor. |
|
| 18 | - * @param XoopsDatabase $handler |
|
| 19 | - */ |
|
| 20 | - public function __construct($handler) |
|
| 21 | - { |
|
| 22 | - $this->handler = $handler; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /* |
|
| 14 | + public $handler; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * SmartobjectPermissionHandler constructor. |
|
| 18 | + * @param XoopsDatabase $handler |
|
| 19 | + */ |
|
| 20 | + public function __construct($handler) |
|
| 21 | + { |
|
| 22 | + $this->handler = $handler; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /* |
|
| 26 | 26 | * Returns permissions for a certain type |
| 27 | 27 | * |
| 28 | 28 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -30,73 +30,73 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return array |
| 32 | 32 | */ |
| 33 | - /** |
|
| 34 | - * @param $gperm_name |
|
| 35 | - * @param null $id |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 38 | - public function getGrantedGroups($gperm_name, $id = null) |
|
| 39 | - { |
|
| 40 | - static $groups; |
|
| 41 | - |
|
| 42 | - if (!isset($groups[$gperm_name]) || ($id != null && !isset($groups[$gperm_name][$id]))) { |
|
| 43 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 44 | - //Get group permissions handler |
|
| 45 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 46 | - |
|
| 47 | - //Get groups allowed for an item id |
|
| 48 | - $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 49 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
| 50 | - } |
|
| 51 | - //Return the permission array |
|
| 52 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param $item_ids_array |
|
| 57 | - * @param bool $gperm_name |
|
| 58 | - * @return array |
|
| 59 | - */ |
|
| 60 | - public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 61 | - { |
|
| 62 | - static $groups; |
|
| 63 | - |
|
| 64 | - if ($gperm_name) { |
|
| 65 | - if (isset($groups[$gperm_name])) { |
|
| 66 | - return $groups[$gperm_name]; |
|
| 67 | - } |
|
| 68 | - } else { |
|
| 69 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 70 | - return $groups; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 74 | - |
|
| 75 | - $criteria = new CriteriaCompo(); |
|
| 76 | - $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 77 | - |
|
| 78 | - if ($gperm_name) { |
|
| 79 | - $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - //Get group permissions handler |
|
| 83 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 84 | - |
|
| 85 | - $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 86 | - |
|
| 87 | - foreach ($permissionsObj as $permissionObj) { |
|
| 88 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - //Return the permission array |
|
| 92 | - if ($gperm_name) { |
|
| 93 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array(); |
|
| 94 | - } else { |
|
| 95 | - return isset($groups) ? $groups : array(); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /* |
|
| 33 | + /** |
|
| 34 | + * @param $gperm_name |
|
| 35 | + * @param null $id |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | + public function getGrantedGroups($gperm_name, $id = null) |
|
| 39 | + { |
|
| 40 | + static $groups; |
|
| 41 | + |
|
| 42 | + if (!isset($groups[$gperm_name]) || ($id != null && !isset($groups[$gperm_name][$id]))) { |
|
| 43 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 44 | + //Get group permissions handler |
|
| 45 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 46 | + |
|
| 47 | + //Get groups allowed for an item id |
|
| 48 | + $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 49 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
| 50 | + } |
|
| 51 | + //Return the permission array |
|
| 52 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param $item_ids_array |
|
| 57 | + * @param bool $gperm_name |
|
| 58 | + * @return array |
|
| 59 | + */ |
|
| 60 | + public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 61 | + { |
|
| 62 | + static $groups; |
|
| 63 | + |
|
| 64 | + if ($gperm_name) { |
|
| 65 | + if (isset($groups[$gperm_name])) { |
|
| 66 | + return $groups[$gperm_name]; |
|
| 67 | + } |
|
| 68 | + } else { |
|
| 69 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 70 | + return $groups; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 74 | + |
|
| 75 | + $criteria = new CriteriaCompo(); |
|
| 76 | + $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 77 | + |
|
| 78 | + if ($gperm_name) { |
|
| 79 | + $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + //Get group permissions handler |
|
| 83 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 84 | + |
|
| 85 | + $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 86 | + |
|
| 87 | + foreach ($permissionsObj as $permissionObj) { |
|
| 88 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + //Return the permission array |
|
| 92 | + if ($gperm_name) { |
|
| 93 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array(); |
|
| 94 | + } else { |
|
| 95 | + return isset($groups) ? $groups : array(); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /* |
|
| 100 | 100 | * Returns permissions for a certain type |
| 101 | 101 | * |
| 102 | 102 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -104,123 +104,123 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return array |
| 106 | 106 | */ |
| 107 | - /** |
|
| 108 | - * @param $gperm_name |
|
| 109 | - * @param null $id |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function getGrantedItems($gperm_name, $id = null) |
|
| 113 | - { |
|
| 114 | - global $xoopsUser; |
|
| 115 | - static $permissions; |
|
| 116 | - |
|
| 117 | - if (!isset($permissions[$gperm_name]) || ($id != null && !isset($permissions[$gperm_name][$id]))) { |
|
| 118 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 119 | - |
|
| 120 | - if (is_object($smartModule)) { |
|
| 121 | - |
|
| 122 | - //Get group permissions handler |
|
| 123 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 124 | - |
|
| 125 | - //Get user's groups |
|
| 126 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 127 | - |
|
| 128 | - //Get all allowed item ids in this module and for this user's groups |
|
| 129 | - $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 130 | - $permissions[$gperm_name] = $userpermissions; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - //Return the permission array |
|
| 134 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array(); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param $id |
|
| 139 | - */ |
|
| 140 | - public function storeAllPermissionsForId($id) |
|
| 141 | - { |
|
| 142 | - foreach ($this->handler->getPermissions() as $permission) { |
|
| 143 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Saves permissions for the selected category |
|
| 149 | - * |
|
| 150 | - * saveCategory_Permissions() |
|
| 151 | - * |
|
| 152 | - * @param array $groups : group with granted permission |
|
| 153 | - * @param $itemid |
|
| 154 | - * @param string $perm_name : name of the permission |
|
| 155 | - * @return bool : TRUE if the no errors occured |
|
| 156 | - * @internal param int $categoryID: categoryID on which we are setting permissions for Categories and Forums |
|
| 157 | - */ |
|
| 158 | - |
|
| 159 | - public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 160 | - { |
|
| 161 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 162 | - |
|
| 163 | - $result = true; |
|
| 164 | - $module_id = $smartModule->getVar('mid'); |
|
| 165 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 166 | - |
|
| 167 | - // First, if the permissions are already there, delete them |
|
| 168 | - $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 169 | - //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 170 | - //exit; |
|
| 171 | - // Save the new permissions |
|
| 172 | - |
|
| 173 | - if (count($groups) > 0) { |
|
| 174 | - foreach ($groups as $group_id) { |
|
| 175 | - $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $result; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Delete all permission for a specific item |
|
| 184 | - * |
|
| 185 | - * deletePermissions() |
|
| 186 | - * |
|
| 187 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
| 188 | - * @param $gperm_name |
|
| 189 | - * @return bool: TRUE if the no errors occured |
|
| 190 | - */ |
|
| 191 | - public function deletePermissions($itemid, $gperm_name) |
|
| 192 | - { |
|
| 193 | - global $xoopsModule; |
|
| 194 | - |
|
| 195 | - $smartModule =& smartsection_getModuleInfo(); |
|
| 196 | - |
|
| 197 | - $result = true; |
|
| 198 | - $module_id = $smartModule->getVar('mid'); |
|
| 199 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 200 | - |
|
| 201 | - $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 202 | - |
|
| 203 | - return $result; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Checks if the user has access to a specific permission on a given object |
|
| 208 | - * |
|
| 209 | - * @param string $gperm_name name of the permission to test |
|
| 210 | - * @param int $gperm_itemid id of the object to check |
|
| 211 | - * @return boolean: TRUE if user has access, FALSE if not |
|
| 212 | - **/ |
|
| 213 | - public function accessGranted($gperm_name, $gperm_itemid) |
|
| 214 | - { |
|
| 215 | - global $xoopsUser; |
|
| 216 | - |
|
| 217 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 218 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 219 | - $gperm_modid = $smartModule->getVar('mid'); |
|
| 220 | - |
|
| 221 | - //Get group permissions handler |
|
| 222 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 223 | - |
|
| 224 | - return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 225 | - } |
|
| 107 | + /** |
|
| 108 | + * @param $gperm_name |
|
| 109 | + * @param null $id |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function getGrantedItems($gperm_name, $id = null) |
|
| 113 | + { |
|
| 114 | + global $xoopsUser; |
|
| 115 | + static $permissions; |
|
| 116 | + |
|
| 117 | + if (!isset($permissions[$gperm_name]) || ($id != null && !isset($permissions[$gperm_name][$id]))) { |
|
| 118 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 119 | + |
|
| 120 | + if (is_object($smartModule)) { |
|
| 121 | + |
|
| 122 | + //Get group permissions handler |
|
| 123 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 124 | + |
|
| 125 | + //Get user's groups |
|
| 126 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 127 | + |
|
| 128 | + //Get all allowed item ids in this module and for this user's groups |
|
| 129 | + $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 130 | + $permissions[$gperm_name] = $userpermissions; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + //Return the permission array |
|
| 134 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array(); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param $id |
|
| 139 | + */ |
|
| 140 | + public function storeAllPermissionsForId($id) |
|
| 141 | + { |
|
| 142 | + foreach ($this->handler->getPermissions() as $permission) { |
|
| 143 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Saves permissions for the selected category |
|
| 149 | + * |
|
| 150 | + * saveCategory_Permissions() |
|
| 151 | + * |
|
| 152 | + * @param array $groups : group with granted permission |
|
| 153 | + * @param $itemid |
|
| 154 | + * @param string $perm_name : name of the permission |
|
| 155 | + * @return bool : TRUE if the no errors occured |
|
| 156 | + * @internal param int $categoryID: categoryID on which we are setting permissions for Categories and Forums |
|
| 157 | + */ |
|
| 158 | + |
|
| 159 | + public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 160 | + { |
|
| 161 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 162 | + |
|
| 163 | + $result = true; |
|
| 164 | + $module_id = $smartModule->getVar('mid'); |
|
| 165 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 166 | + |
|
| 167 | + // First, if the permissions are already there, delete them |
|
| 168 | + $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 169 | + //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 170 | + //exit; |
|
| 171 | + // Save the new permissions |
|
| 172 | + |
|
| 173 | + if (count($groups) > 0) { |
|
| 174 | + foreach ($groups as $group_id) { |
|
| 175 | + $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $result; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Delete all permission for a specific item |
|
| 184 | + * |
|
| 185 | + * deletePermissions() |
|
| 186 | + * |
|
| 187 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
| 188 | + * @param $gperm_name |
|
| 189 | + * @return bool: TRUE if the no errors occured |
|
| 190 | + */ |
|
| 191 | + public function deletePermissions($itemid, $gperm_name) |
|
| 192 | + { |
|
| 193 | + global $xoopsModule; |
|
| 194 | + |
|
| 195 | + $smartModule =& smartsection_getModuleInfo(); |
|
| 196 | + |
|
| 197 | + $result = true; |
|
| 198 | + $module_id = $smartModule->getVar('mid'); |
|
| 199 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 200 | + |
|
| 201 | + $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 202 | + |
|
| 203 | + return $result; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Checks if the user has access to a specific permission on a given object |
|
| 208 | + * |
|
| 209 | + * @param string $gperm_name name of the permission to test |
|
| 210 | + * @param int $gperm_itemid id of the object to check |
|
| 211 | + * @return boolean: TRUE if user has access, FALSE if not |
|
| 212 | + **/ |
|
| 213 | + public function accessGranted($gperm_name, $gperm_itemid) |
|
| 214 | + { |
|
| 215 | + global $xoopsUser; |
|
| 216 | + |
|
| 217 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 218 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 219 | + $gperm_modid = $smartModule->getVar('mid'); |
|
| 220 | + |
|
| 221 | + //Get group permissions handler |
|
| 222 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 223 | + |
|
| 224 | + return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -192,7 +192,7 @@ |
||
| 192 | 192 | { |
| 193 | 193 | global $xoopsModule; |
| 194 | 194 | |
| 195 | - $smartModule =& smartsection_getModuleInfo(); |
|
| 195 | + $smartModule = & smartsection_getModuleInfo(); |
|
| 196 | 196 | |
| 197 | 197 | $result = true; |
| 198 | 198 | $module_id = $smartModule->getVar('mid'); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * Constructor |
| 78 | - * @param $object |
|
| 78 | + * @param SmartObject $object |
|
| 79 | 79 | * @param bool $userSide |
| 80 | 80 | * @param array $actions |
| 81 | 81 | * @param bool $headerAsRow |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * @param $rowObj |
|
| 92 | + * @param SmartObjectRow $rowObj |
|
| 93 | 93 | */ |
| 94 | 94 | public function addRow($rowObj) |
| 95 | 95 | { |
@@ -20,39 +20,39 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class SmartObjectRow |
| 22 | 22 | { |
| 23 | - public $_keyname; |
|
| 24 | - public $_align; |
|
| 25 | - public $_customMethodForValue; |
|
| 26 | - public $_header; |
|
| 27 | - public $_class; |
|
| 23 | + public $_keyname; |
|
| 24 | + public $_align; |
|
| 25 | + public $_customMethodForValue; |
|
| 26 | + public $_header; |
|
| 27 | + public $_class; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * SmartObjectRow constructor. |
|
| 31 | - * @param $keyname |
|
| 32 | - * @param bool $customMethodForValue |
|
| 33 | - * @param bool $header |
|
| 34 | - * @param bool $class |
|
| 35 | - */ |
|
| 36 | - public function __construct($keyname, $customMethodForValue = false, $header = false, $class = false) |
|
| 37 | - { |
|
| 38 | - $this->_keyname = $keyname; |
|
| 39 | - $this->_customMethodForValue = $customMethodForValue; |
|
| 40 | - $this->_header = $header; |
|
| 41 | - $this->_class = $class; |
|
| 42 | - } |
|
| 29 | + /** |
|
| 30 | + * SmartObjectRow constructor. |
|
| 31 | + * @param $keyname |
|
| 32 | + * @param bool $customMethodForValue |
|
| 33 | + * @param bool $header |
|
| 34 | + * @param bool $class |
|
| 35 | + */ |
|
| 36 | + public function __construct($keyname, $customMethodForValue = false, $header = false, $class = false) |
|
| 37 | + { |
|
| 38 | + $this->_keyname = $keyname; |
|
| 39 | + $this->_customMethodForValue = $customMethodForValue; |
|
| 40 | + $this->_header = $header; |
|
| 41 | + $this->_class = $class; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function getKeyName() |
|
| 45 | - { |
|
| 46 | - return $this->_keyname; |
|
| 47 | - } |
|
| 44 | + public function getKeyName() |
|
| 45 | + { |
|
| 46 | + return $this->_keyname; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return bool |
|
| 51 | - */ |
|
| 52 | - public function isHeader() |
|
| 53 | - { |
|
| 54 | - return $this->_header; |
|
| 55 | - } |
|
| 49 | + /** |
|
| 50 | + * @return bool |
|
| 51 | + */ |
|
| 52 | + public function isHeader() |
|
| 53 | + { |
|
| 54 | + return $this->_header; |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -66,94 +66,94 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | class SmartObjectSingleView |
| 68 | 68 | { |
| 69 | - public $_object; |
|
| 70 | - public $_userSide; |
|
| 71 | - public $_tpl; |
|
| 72 | - public $_rows; |
|
| 73 | - public $_actions; |
|
| 74 | - public $_headerAsRow = true; |
|
| 69 | + public $_object; |
|
| 70 | + public $_userSide; |
|
| 71 | + public $_tpl; |
|
| 72 | + public $_rows; |
|
| 73 | + public $_actions; |
|
| 74 | + public $_headerAsRow = true; |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Constructor |
|
| 78 | - * @param $object |
|
| 79 | - * @param bool $userSide |
|
| 80 | - * @param array $actions |
|
| 81 | - * @param bool $headerAsRow |
|
| 82 | - */ |
|
| 83 | - public function __construct($object, $userSide = false, $actions = array(), $headerAsRow = true) |
|
| 84 | - { |
|
| 85 | - $this->_object = $object; |
|
| 86 | - $this->_userSide = $userSide; |
|
| 87 | - $this->_actions = $actions; |
|
| 88 | - $this->_headerAsRow = $headerAsRow; |
|
| 89 | - } |
|
| 76 | + /** |
|
| 77 | + * Constructor |
|
| 78 | + * @param $object |
|
| 79 | + * @param bool $userSide |
|
| 80 | + * @param array $actions |
|
| 81 | + * @param bool $headerAsRow |
|
| 82 | + */ |
|
| 83 | + public function __construct($object, $userSide = false, $actions = array(), $headerAsRow = true) |
|
| 84 | + { |
|
| 85 | + $this->_object = $object; |
|
| 86 | + $this->_userSide = $userSide; |
|
| 87 | + $this->_actions = $actions; |
|
| 88 | + $this->_headerAsRow = $headerAsRow; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @param $rowObj |
|
| 93 | - */ |
|
| 94 | - public function addRow($rowObj) |
|
| 95 | - { |
|
| 96 | - $this->_rows[] = $rowObj; |
|
| 97 | - } |
|
| 91 | + /** |
|
| 92 | + * @param $rowObj |
|
| 93 | + */ |
|
| 94 | + public function addRow($rowObj) |
|
| 95 | + { |
|
| 96 | + $this->_rows[] = $rowObj; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @param bool $fetchOnly |
|
| 101 | - * @param bool $debug |
|
| 102 | - * @return mixed|string|void |
|
| 103 | - */ |
|
| 104 | - public function render($fetchOnly = false, $debug = false) |
|
| 105 | - { |
|
| 106 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 99 | + /** |
|
| 100 | + * @param bool $fetchOnly |
|
| 101 | + * @param bool $debug |
|
| 102 | + * @return mixed|string|void |
|
| 103 | + */ |
|
| 104 | + public function render($fetchOnly = false, $debug = false) |
|
| 105 | + { |
|
| 106 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 107 | 107 | |
| 108 | - $this->_tpl = new XoopsTpl(); |
|
| 109 | - $vars = $this->_object->vars; |
|
| 110 | - $smartobjectObjectArray = array(); |
|
| 108 | + $this->_tpl = new XoopsTpl(); |
|
| 109 | + $vars = $this->_object->vars; |
|
| 110 | + $smartobjectObjectArray = array(); |
|
| 111 | 111 | |
| 112 | - foreach ($this->_rows as $row) { |
|
| 113 | - $key = $row->getKeyName(); |
|
| 114 | - if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
| 115 | - $method = $row->_customMethodForValue; |
|
| 116 | - $value = $this->_object->$method(); |
|
| 117 | - } else { |
|
| 118 | - $value = $this->_object->getVar($row->getKeyName()); |
|
| 119 | - } |
|
| 120 | - if ($row->isHeader()) { |
|
| 121 | - $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
| 122 | - $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
| 123 | - } else { |
|
| 124 | - $smartobjectObjectArray[$key]['value'] = $value; |
|
| 125 | - $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
| 126 | - $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - $action_row = ''; |
|
| 130 | - if (in_array('edit', $this->_actions)) { |
|
| 131 | - $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
| 132 | - } |
|
| 133 | - if (in_array('delete', $this->_actions)) { |
|
| 134 | - $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
| 135 | - } |
|
| 136 | - if ($action_row) { |
|
| 137 | - $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
| 138 | - $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
| 139 | - } |
|
| 112 | + foreach ($this->_rows as $row) { |
|
| 113 | + $key = $row->getKeyName(); |
|
| 114 | + if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
| 115 | + $method = $row->_customMethodForValue; |
|
| 116 | + $value = $this->_object->$method(); |
|
| 117 | + } else { |
|
| 118 | + $value = $this->_object->getVar($row->getKeyName()); |
|
| 119 | + } |
|
| 120 | + if ($row->isHeader()) { |
|
| 121 | + $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
| 122 | + $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
| 123 | + } else { |
|
| 124 | + $smartobjectObjectArray[$key]['value'] = $value; |
|
| 125 | + $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
| 126 | + $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + $action_row = ''; |
|
| 130 | + if (in_array('edit', $this->_actions)) { |
|
| 131 | + $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
| 132 | + } |
|
| 133 | + if (in_array('delete', $this->_actions)) { |
|
| 134 | + $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
| 135 | + } |
|
| 136 | + if ($action_row) { |
|
| 137 | + $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
| 138 | + $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
| 142 | - $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
| 141 | + $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
| 142 | + $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
| 143 | 143 | |
| 144 | - if ($fetchOnly) { |
|
| 145 | - return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
| 146 | - } else { |
|
| 147 | - $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
| 148 | - } |
|
| 149 | - } |
|
| 144 | + if ($fetchOnly) { |
|
| 145 | + return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
| 146 | + } else { |
|
| 147 | + $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * @param bool $debug |
|
| 153 | - * @return mixed|string|void |
|
| 154 | - */ |
|
| 155 | - public function fetch($debug = false) |
|
| 156 | - { |
|
| 157 | - return $this->render(true, $debug); |
|
| 158 | - } |
|
| 151 | + /** |
|
| 152 | + * @param bool $debug |
|
| 153 | + * @return mixed|string|void |
|
| 154 | + */ |
|
| 155 | + public function fetch($debug = false) |
|
| 156 | + { |
|
| 157 | + return $this->render(true, $debug); |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | /** |
| 19 | 19 | * Access the only instance of this class |
| 20 | 20 | * |
| 21 | - * @return object |
|
| 21 | + * @return SmartObjectsRegistry |
|
| 22 | 22 | * |
| 23 | 23 | * @static |
| 24 | 24 | * @staticvar object |
@@ -13,169 +13,169 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class SmartObjectsRegistry |
| 15 | 15 | { |
| 16 | - public $_registryArray; |
|
| 16 | + public $_registryArray; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Access the only instance of this class |
|
| 20 | - * |
|
| 21 | - * @return object |
|
| 22 | - * |
|
| 23 | - * @static |
|
| 24 | - * @staticvar object |
|
| 25 | - */ |
|
| 26 | - public function getInstance() |
|
| 27 | - { |
|
| 28 | - static $instance; |
|
| 29 | - if (!isset($instance)) { |
|
| 30 | - $instance = new SmartObjectsRegistry(); |
|
| 31 | - } |
|
| 18 | + /** |
|
| 19 | + * Access the only instance of this class |
|
| 20 | + * |
|
| 21 | + * @return object |
|
| 22 | + * |
|
| 23 | + * @static |
|
| 24 | + * @staticvar object |
|
| 25 | + */ |
|
| 26 | + public function getInstance() |
|
| 27 | + { |
|
| 28 | + static $instance; |
|
| 29 | + if (!isset($instance)) { |
|
| 30 | + $instance = new SmartObjectsRegistry(); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return $instance; |
|
| 34 | - } |
|
| 33 | + return $instance; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Adding objects to the registry |
|
| 38 | - * |
|
| 39 | - * @param SmartPersistableObjectHandler $handler of the objects to add |
|
| 40 | - * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 41 | - * @return FALSE if an error occured |
|
| 42 | - */ |
|
| 43 | - public function addObjectsFromHandler(&$handler, $criteria = false) |
|
| 44 | - { |
|
| 45 | - if (method_exists($handler, 'getObjects')) { |
|
| 46 | - $objects = $handler->getObjects($criteria, true); |
|
| 47 | - $this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects; |
|
| 36 | + /** |
|
| 37 | + * Adding objects to the registry |
|
| 38 | + * |
|
| 39 | + * @param SmartPersistableObjectHandler $handler of the objects to add |
|
| 40 | + * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 41 | + * @return FALSE if an error occured |
|
| 42 | + */ |
|
| 43 | + public function addObjectsFromHandler(&$handler, $criteria = false) |
|
| 44 | + { |
|
| 45 | + if (method_exists($handler, 'getObjects')) { |
|
| 46 | + $objects = $handler->getObjects($criteria, true); |
|
| 47 | + $this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects; |
|
| 48 | 48 | |
| 49 | - return $objects; |
|
| 50 | - } else { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - } |
|
| 49 | + return $objects; |
|
| 50 | + } else { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Adding objects to the registry from an item name |
|
| 57 | - * This method will fetch the handler of the item / module and call the addObjectsFromHandler |
|
| 58 | - * |
|
| 59 | - * @param string $item name of the item |
|
| 60 | - * @param bool|string $modulename name of the module |
|
| 61 | - * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 62 | - * @return FALSE if an error occured |
|
| 63 | - */ |
|
| 64 | - public function addObjectsFromItemName($item, $modulename = false, $criteria = false) |
|
| 65 | - { |
|
| 66 | - if (!$modulename) { |
|
| 67 | - global $xoopsModule; |
|
| 68 | - if (!is_object($xoopsModule)) { |
|
| 69 | - return false; |
|
| 70 | - } else { |
|
| 71 | - $modulename = $xoopsModule->dirname(); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - $objectHandler = xoops_getModuleHandler($item, $modulename); |
|
| 55 | + /** |
|
| 56 | + * Adding objects to the registry from an item name |
|
| 57 | + * This method will fetch the handler of the item / module and call the addObjectsFromHandler |
|
| 58 | + * |
|
| 59 | + * @param string $item name of the item |
|
| 60 | + * @param bool|string $modulename name of the module |
|
| 61 | + * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 62 | + * @return FALSE if an error occured |
|
| 63 | + */ |
|
| 64 | + public function addObjectsFromItemName($item, $modulename = false, $criteria = false) |
|
| 65 | + { |
|
| 66 | + if (!$modulename) { |
|
| 67 | + global $xoopsModule; |
|
| 68 | + if (!is_object($xoopsModule)) { |
|
| 69 | + return false; |
|
| 70 | + } else { |
|
| 71 | + $modulename = $xoopsModule->dirname(); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + $objectHandler = xoops_getModuleHandler($item, $modulename); |
|
| 75 | 75 | |
| 76 | - if (method_exists($objectHandler, 'getObjects')) { |
|
| 77 | - $objects = $objectHandler->getObjects($criteria, true); |
|
| 78 | - $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects; |
|
| 76 | + if (method_exists($objectHandler, 'getObjects')) { |
|
| 77 | + $objects = $objectHandler->getObjects($criteria, true); |
|
| 78 | + $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects; |
|
| 79 | 79 | |
| 80 | - return $objects; |
|
| 81 | - } else { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 84 | - } |
|
| 80 | + return $objects; |
|
| 81 | + } else { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Fetching objects from the registry |
|
| 88 | - * |
|
| 89 | - * @param string $itemname |
|
| 90 | - * @param string $modulename |
|
| 91 | - * |
|
| 92 | - * @return the requested objects or FALSE if they don't exists in the registry |
|
| 93 | - */ |
|
| 94 | - public function getObjects($itemname, $modulename) |
|
| 95 | - { |
|
| 96 | - if (!$modulename) { |
|
| 97 | - global $xoopsModule; |
|
| 98 | - if (!is_object($xoopsModule)) { |
|
| 99 | - return false; |
|
| 100 | - } else { |
|
| 101 | - $modulename = $xoopsModule->dirname(); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - if (isset($this->_registryArray['objects'][$modulename][$itemname])) { |
|
| 105 | - return $this->_registryArray['objects'][$modulename][$itemname]; |
|
| 106 | - } else { |
|
| 107 | - // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 108 | - $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 109 | - if (method_exists($moduleHandler, 'getObjects')) { |
|
| 110 | - $objects = $moduleHandler->getObjects(); |
|
| 111 | - } |
|
| 112 | - $this->_registryArray['objects'][$modulename][$itemname] = $objects; |
|
| 86 | + /** |
|
| 87 | + * Fetching objects from the registry |
|
| 88 | + * |
|
| 89 | + * @param string $itemname |
|
| 90 | + * @param string $modulename |
|
| 91 | + * |
|
| 92 | + * @return the requested objects or FALSE if they don't exists in the registry |
|
| 93 | + */ |
|
| 94 | + public function getObjects($itemname, $modulename) |
|
| 95 | + { |
|
| 96 | + if (!$modulename) { |
|
| 97 | + global $xoopsModule; |
|
| 98 | + if (!is_object($xoopsModule)) { |
|
| 99 | + return false; |
|
| 100 | + } else { |
|
| 101 | + $modulename = $xoopsModule->dirname(); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + if (isset($this->_registryArray['objects'][$modulename][$itemname])) { |
|
| 105 | + return $this->_registryArray['objects'][$modulename][$itemname]; |
|
| 106 | + } else { |
|
| 107 | + // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 108 | + $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 109 | + if (method_exists($moduleHandler, 'getObjects')) { |
|
| 110 | + $objects = $moduleHandler->getObjects(); |
|
| 111 | + } |
|
| 112 | + $this->_registryArray['objects'][$modulename][$itemname] = $objects; |
|
| 113 | 113 | |
| 114 | - return $objects; |
|
| 115 | - } |
|
| 116 | - } |
|
| 114 | + return $objects; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Fetching objects from the registry, as a list: objectid => identifier |
|
| 120 | - * |
|
| 121 | - * @param string $itemname |
|
| 122 | - * @param string $modulename |
|
| 123 | - * |
|
| 124 | - * @return the requested objects or FALSE if they don't exists in the registry |
|
| 125 | - */ |
|
| 126 | - public function getList($itemname, $modulename) |
|
| 127 | - { |
|
| 128 | - if (!$modulename) { |
|
| 129 | - global $xoopsModule; |
|
| 130 | - if (!is_object($xoopsModule)) { |
|
| 131 | - return false; |
|
| 132 | - } else { |
|
| 133 | - $modulename = $xoopsModule->dirname(); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - if (isset($this->_registryArray['list'][$modulename][$itemname])) { |
|
| 137 | - return $this->_registryArray['list'][$modulename][$itemname]; |
|
| 138 | - } else { |
|
| 139 | - // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 140 | - $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 141 | - if (method_exists($moduleHandler, 'getList')) { |
|
| 142 | - $objects = $moduleHandler->getList(); |
|
| 143 | - } |
|
| 144 | - $this->_registryArray['list'][$modulename][$itemname] = $objects; |
|
| 118 | + /** |
|
| 119 | + * Fetching objects from the registry, as a list: objectid => identifier |
|
| 120 | + * |
|
| 121 | + * @param string $itemname |
|
| 122 | + * @param string $modulename |
|
| 123 | + * |
|
| 124 | + * @return the requested objects or FALSE if they don't exists in the registry |
|
| 125 | + */ |
|
| 126 | + public function getList($itemname, $modulename) |
|
| 127 | + { |
|
| 128 | + if (!$modulename) { |
|
| 129 | + global $xoopsModule; |
|
| 130 | + if (!is_object($xoopsModule)) { |
|
| 131 | + return false; |
|
| 132 | + } else { |
|
| 133 | + $modulename = $xoopsModule->dirname(); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + if (isset($this->_registryArray['list'][$modulename][$itemname])) { |
|
| 137 | + return $this->_registryArray['list'][$modulename][$itemname]; |
|
| 138 | + } else { |
|
| 139 | + // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 140 | + $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 141 | + if (method_exists($moduleHandler, 'getList')) { |
|
| 142 | + $objects = $moduleHandler->getList(); |
|
| 143 | + } |
|
| 144 | + $this->_registryArray['list'][$modulename][$itemname] = $objects; |
|
| 145 | 145 | |
| 146 | - return $objects; |
|
| 147 | - } |
|
| 148 | - } |
|
| 146 | + return $objects; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Retreive a single object |
|
| 152 | - * |
|
| 153 | - * @param string $itemname |
|
| 154 | - * @param string $key |
|
| 155 | - * |
|
| 156 | - * @param bool $modulename |
|
| 157 | - * @return the requestd object or FALSE if they don't exists in the registry |
|
| 158 | - */ |
|
| 159 | - public function getSingleObject($itemname, $key, $modulename = false) |
|
| 160 | - { |
|
| 161 | - if (!$modulename) { |
|
| 162 | - global $xoopsModule; |
|
| 163 | - if (!is_object($xoopsModule)) { |
|
| 164 | - return false; |
|
| 165 | - } else { |
|
| 166 | - $modulename = $xoopsModule->dirname(); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) { |
|
| 170 | - return $this->_registryArray['objects'][$modulename][$itemname][$key]; |
|
| 171 | - } else { |
|
| 172 | - $objectHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 173 | - $object = $objectHandler->get($key); |
|
| 174 | - if (!$object->isNew()) { |
|
| 175 | - return $object; |
|
| 176 | - } else { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 150 | + /** |
|
| 151 | + * Retreive a single object |
|
| 152 | + * |
|
| 153 | + * @param string $itemname |
|
| 154 | + * @param string $key |
|
| 155 | + * |
|
| 156 | + * @param bool $modulename |
|
| 157 | + * @return the requestd object or FALSE if they don't exists in the registry |
|
| 158 | + */ |
|
| 159 | + public function getSingleObject($itemname, $key, $modulename = false) |
|
| 160 | + { |
|
| 161 | + if (!$modulename) { |
|
| 162 | + global $xoopsModule; |
|
| 163 | + if (!is_object($xoopsModule)) { |
|
| 164 | + return false; |
|
| 165 | + } else { |
|
| 166 | + $modulename = $xoopsModule->dirname(); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) { |
|
| 170 | + return $this->_registryArray['objects'][$modulename][$itemname][$key]; |
|
| 171 | + } else { |
|
| 172 | + $objectHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 173 | + $object = $objectHandler->get($key); |
|
| 174 | + if (!$object->isNew()) { |
|
| 175 | + return $object; |
|
| 176 | + } else { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | $objectHandler = xoops_getModuleHandler($item, $modulename); |
| 75 | 75 | |
| 76 | 76 | if (method_exists($objectHandler, 'getObjects')) { |
| 77 | - $objects = $objectHandler->getObjects($criteria, true); |
|
| 77 | + $objects = $objectHandler->getObjects($criteria, true); |
|
| 78 | 78 | $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects; |
| 79 | 79 | |
| 80 | 80 | return $objects; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * SmartObjectColumn constructor. |
| 34 | - * @param $keyname |
|
| 34 | + * @param string $keyname |
|
| 35 | 35 | * @param string $align |
| 36 | 36 | * @param bool $width |
| 37 | 37 | * @param bool $customMethodForValue |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * @param $columnObj |
|
| 186 | + * @param SmartObjectColumn $columnObj |
|
| 187 | 187 | */ |
| 188 | 188 | public function addColumn($columnObj) |
| 189 | 189 | { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | /** |
| 194 | 194 | * @param $name |
| 195 | - * @param $location |
|
| 195 | + * @param string $location |
|
| 196 | 196 | * @param $value |
| 197 | 197 | */ |
| 198 | 198 | public function addIntroButton($name, $location, $value) |
@@ -21,77 +21,77 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class SmartObjectColumn |
| 23 | 23 | { |
| 24 | - public $_keyname; |
|
| 25 | - public $_align; |
|
| 26 | - public $_width; |
|
| 27 | - public $_customMethodForValue; |
|
| 28 | - public $_extraParams; |
|
| 29 | - public $_sortable; |
|
| 30 | - public $_customCaption; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * SmartObjectColumn constructor. |
|
| 34 | - * @param $keyname |
|
| 35 | - * @param string $align |
|
| 36 | - * @param bool $width |
|
| 37 | - * @param bool $customMethodForValue |
|
| 38 | - * @param bool $param |
|
| 39 | - * @param bool $customCaption |
|
| 40 | - * @param bool $sortable |
|
| 41 | - */ |
|
| 42 | - public function __construct($keyname, $align = 'left', $width = false, $customMethodForValue = false, $param = false, $customCaption = false, $sortable = true) |
|
| 43 | - { |
|
| 44 | - $this->_keyname = $keyname; |
|
| 45 | - $this->_align = $align; |
|
| 46 | - $this->_width = $width; |
|
| 47 | - $this->_customMethodForValue = $customMethodForValue; |
|
| 48 | - $this->_sortable = $sortable; |
|
| 49 | - $this->_param = $param; |
|
| 50 | - $this->_customCaption = $customCaption; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function getKeyName() |
|
| 54 | - { |
|
| 55 | - return $this->_keyname; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function getAlign() |
|
| 62 | - { |
|
| 63 | - return $this->_align; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function isSortable() |
|
| 70 | - { |
|
| 71 | - return $this->_sortable; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return bool|string |
|
| 76 | - */ |
|
| 77 | - public function getWidth() |
|
| 78 | - { |
|
| 79 | - if ($this->_width) { |
|
| 80 | - $ret = $this->_width; |
|
| 81 | - } else { |
|
| 82 | - $ret = ''; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - return $ret; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function getCustomCaption() |
|
| 92 | - { |
|
| 93 | - return $this->_customCaption; |
|
| 94 | - } |
|
| 24 | + public $_keyname; |
|
| 25 | + public $_align; |
|
| 26 | + public $_width; |
|
| 27 | + public $_customMethodForValue; |
|
| 28 | + public $_extraParams; |
|
| 29 | + public $_sortable; |
|
| 30 | + public $_customCaption; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * SmartObjectColumn constructor. |
|
| 34 | + * @param $keyname |
|
| 35 | + * @param string $align |
|
| 36 | + * @param bool $width |
|
| 37 | + * @param bool $customMethodForValue |
|
| 38 | + * @param bool $param |
|
| 39 | + * @param bool $customCaption |
|
| 40 | + * @param bool $sortable |
|
| 41 | + */ |
|
| 42 | + public function __construct($keyname, $align = 'left', $width = false, $customMethodForValue = false, $param = false, $customCaption = false, $sortable = true) |
|
| 43 | + { |
|
| 44 | + $this->_keyname = $keyname; |
|
| 45 | + $this->_align = $align; |
|
| 46 | + $this->_width = $width; |
|
| 47 | + $this->_customMethodForValue = $customMethodForValue; |
|
| 48 | + $this->_sortable = $sortable; |
|
| 49 | + $this->_param = $param; |
|
| 50 | + $this->_customCaption = $customCaption; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function getKeyName() |
|
| 54 | + { |
|
| 55 | + return $this->_keyname; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function getAlign() |
|
| 62 | + { |
|
| 63 | + return $this->_align; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function isSortable() |
|
| 70 | + { |
|
| 71 | + return $this->_sortable; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return bool|string |
|
| 76 | + */ |
|
| 77 | + public function getWidth() |
|
| 78 | + { |
|
| 79 | + if ($this->_width) { |
|
| 80 | + $ret = $this->_width; |
|
| 81 | + } else { |
|
| 82 | + $ret = ''; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + return $ret; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function getCustomCaption() |
|
| 92 | + { |
|
| 93 | + return $this->_customCaption; |
|
| 94 | + } |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -105,778 +105,778 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | class SmartObjectTable |
| 107 | 107 | { |
| 108 | - public $_id; |
|
| 109 | - public $_objectHandler; |
|
| 110 | - public $_columns; |
|
| 111 | - public $_criteria; |
|
| 112 | - public $_actions; |
|
| 113 | - public $_objects = false; |
|
| 114 | - public $_aObjects; |
|
| 115 | - public $_custom_actions; |
|
| 116 | - public $_sortsel; |
|
| 117 | - public $_ordersel; |
|
| 118 | - public $_limitsel; |
|
| 119 | - public $_filtersel; |
|
| 120 | - public $_filterseloptions; |
|
| 121 | - public $_filtersel2; |
|
| 122 | - public $_filtersel2options; |
|
| 123 | - public $_filtersel2optionsDefault; |
|
| 124 | - |
|
| 125 | - public $_tempObject; |
|
| 126 | - public $_tpl; |
|
| 127 | - public $_introButtons; |
|
| 128 | - public $_quickSearch = false; |
|
| 129 | - public $_actionButtons = false; |
|
| 130 | - public $_head_css_class = 'bg3'; |
|
| 131 | - public $_hasActions = false; |
|
| 132 | - public $_userSide = false; |
|
| 133 | - public $_printerFriendlyPage = false; |
|
| 134 | - public $_tableHeader = false; |
|
| 135 | - public $_tableFooter = false; |
|
| 136 | - public $_showActionsColumnTitle = true; |
|
| 137 | - public $_isTree = false; |
|
| 138 | - public $_showFilterAndLimit = true; |
|
| 139 | - public $_enableColumnsSorting = true; |
|
| 140 | - public $_customTemplate = false; |
|
| 141 | - public $_withSelectedActions = array(); |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Constructor |
|
| 145 | - * |
|
| 146 | - * @param object $objectHandler {@link SmartPersistableObjectHandler} |
|
| 147 | - * @param bool|object $criteria |
|
| 148 | - * @param array $actions array representing the actions to offer |
|
| 149 | - * |
|
| 150 | - * @param bool $userSide |
|
| 151 | - * @internal param array $columns array representing the columns to display in the table |
|
| 152 | - */ |
|
| 153 | - public function __construct($objectHandler, $criteria = false, $actions = array('edit', 'delete'), $userSide = false) |
|
| 154 | - { |
|
| 155 | - $this->_id = $objectHandler->className; |
|
| 156 | - $this->_objectHandler = $objectHandler; |
|
| 157 | - |
|
| 158 | - if (!$criteria) { |
|
| 159 | - $criteria = new CriteriaCompo(); |
|
| 160 | - } |
|
| 161 | - $this->_criteria = $criteria; |
|
| 162 | - $this->_actions = $actions; |
|
| 163 | - $this->_custom_actions = array(); |
|
| 164 | - $this->_userSide = $userSide; |
|
| 165 | - if ($userSide) { |
|
| 166 | - $this->_head_css_class = 'head'; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param $op |
|
| 172 | - * @param bool $caption |
|
| 173 | - * @param bool $text |
|
| 174 | - */ |
|
| 175 | - public function addActionButton($op, $caption = false, $text = false) |
|
| 176 | - { |
|
| 177 | - $action = array( |
|
| 178 | - 'op' => $op, |
|
| 179 | - 'caption' => $caption, |
|
| 180 | - 'text' => $text |
|
| 181 | - ); |
|
| 182 | - $this->_actionButtons[] = $action; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @param $columnObj |
|
| 187 | - */ |
|
| 188 | - public function addColumn($columnObj) |
|
| 189 | - { |
|
| 190 | - $this->_columns[] = $columnObj; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @param $name |
|
| 195 | - * @param $location |
|
| 196 | - * @param $value |
|
| 197 | - */ |
|
| 198 | - public function addIntroButton($name, $location, $value) |
|
| 199 | - { |
|
| 200 | - $introButton = array(); |
|
| 201 | - $introButton['name'] = $name; |
|
| 202 | - $introButton['location'] = $location; |
|
| 203 | - $introButton['value'] = $value; |
|
| 204 | - $this->_introButtons[] = $introButton; |
|
| 205 | - unset($introButton); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - public function addPrinterFriendlyLink() |
|
| 209 | - { |
|
| 210 | - $current_urls = smart_getCurrentUrls(); |
|
| 211 | - $current_url = $current_urls['full']; |
|
| 212 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @param $fields |
|
| 217 | - * @param string $caption |
|
| 218 | - */ |
|
| 219 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 220 | - { |
|
| 221 | - $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @param $content |
|
| 226 | - */ |
|
| 227 | - public function addHeader($content) |
|
| 228 | - { |
|
| 229 | - $this->_tableHeader = $content; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @param $content |
|
| 234 | - */ |
|
| 235 | - public function addFooter($content) |
|
| 236 | - { |
|
| 237 | - $this->_tableFooter = $content; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param $caption |
|
| 242 | - */ |
|
| 243 | - public function addDefaultIntroButton($caption) |
|
| 244 | - { |
|
| 245 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @param $method |
|
| 250 | - */ |
|
| 251 | - public function addCustomAction($method) |
|
| 252 | - { |
|
| 253 | - $this->_custom_actions[] = $method; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @param $default_sort |
|
| 258 | - */ |
|
| 259 | - public function setDefaultSort($default_sort) |
|
| 260 | - { |
|
| 261 | - $this->_sortsel = $default_sort; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - public function getDefaultSort() |
|
| 268 | - { |
|
| 269 | - if ($this->_sortsel) { |
|
| 270 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 271 | - } else { |
|
| 272 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @param $default_order |
|
| 278 | - */ |
|
| 279 | - public function setDefaultOrder($default_order) |
|
| 280 | - { |
|
| 281 | - $this->_ordersel = $default_order; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @return string |
|
| 286 | - */ |
|
| 287 | - public function getDefaultOrder() |
|
| 288 | - { |
|
| 289 | - if ($this->_ordersel) { |
|
| 290 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 291 | - } else { |
|
| 292 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @param array $actions |
|
| 298 | - */ |
|
| 299 | - public function addWithSelectedActions($actions = array()) |
|
| 300 | - { |
|
| 301 | - $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 302 | - $this->_withSelectedActions = $actions; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Adding a filter in the table |
|
| 307 | - * |
|
| 308 | - * @param string $key key to the field that will be used for sorting |
|
| 309 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 310 | - * @param bool $default |
|
| 311 | - */ |
|
| 312 | - public function addFilter($key, $method, $default = false) |
|
| 313 | - { |
|
| 314 | - $this->_filterseloptions[$key] = $method; |
|
| 315 | - $this->_filtersel2optionsDefault = $default; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @param $default_filter |
|
| 320 | - */ |
|
| 321 | - public function setDefaultFilter($default_filter) |
|
| 322 | - { |
|
| 323 | - $this->_filtersel = $default_filter; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - public function isForUserSide() |
|
| 327 | - { |
|
| 328 | - $this->_userSide = true; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @param $template |
|
| 333 | - */ |
|
| 334 | - public function setCustomTemplate($template) |
|
| 335 | - { |
|
| 336 | - $this->_customTemplate = $template; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - public function setSortOrder() |
|
| 340 | - { |
|
| 341 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 342 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 343 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 344 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 345 | - |
|
| 346 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 347 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 348 | - } else { |
|
| 349 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 353 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 354 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 355 | - $ordersArray = $this->getOrdersArray(); |
|
| 356 | - $this->_criteria->setOrder($this->_ordersel); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * @param $id |
|
| 361 | - */ |
|
| 362 | - public function setTableId($id) |
|
| 363 | - { |
|
| 364 | - $this->_id = $id; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @param $objects |
|
| 369 | - */ |
|
| 370 | - public function setObjects($objects) |
|
| 371 | - { |
|
| 372 | - $this->_objects = $objects; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - public function createTableRows() |
|
| 376 | - { |
|
| 377 | - $this->_aObjects = array(); |
|
| 378 | - |
|
| 379 | - $doWeHaveActions = false; |
|
| 380 | - |
|
| 381 | - $objectclass = 'odd'; |
|
| 382 | - if (count($this->_objects) > 0) { |
|
| 383 | - foreach ($this->_objects as $object) { |
|
| 384 | - $aObject = array(); |
|
| 385 | - |
|
| 386 | - $i = 0; |
|
| 387 | - |
|
| 388 | - $aColumns = array(); |
|
| 389 | - |
|
| 390 | - foreach ($this->_columns as $column) { |
|
| 391 | - $aColumn = array(); |
|
| 392 | - |
|
| 393 | - if ($i == 0) { |
|
| 394 | - $class = 'head'; |
|
| 395 | - } elseif ($i % 2 == 0) { |
|
| 396 | - $class = 'even'; |
|
| 397 | - } else { |
|
| 398 | - $class = 'odd'; |
|
| 399 | - } |
|
| 400 | - if (method_exists($object, 'initiateCustomFields')) { |
|
| 401 | - //$object->initiateCustomFields(); |
|
| 402 | - } |
|
| 403 | - if ($column->_keyname === 'checked') { |
|
| 404 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '" />'; |
|
| 405 | - } elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
| 406 | - $method = $column->_customMethodForValue; |
|
| 407 | - if ($column->_param) { |
|
| 408 | - $value = $object->$method($column->_param); |
|
| 409 | - } else { |
|
| 410 | - $value = $object->$method(); |
|
| 411 | - } |
|
| 412 | - } else { |
|
| 413 | - /** |
|
| 414 | - * If the column is the identifier, then put a link on it |
|
| 415 | - */ |
|
| 416 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 417 | - $value = $object->getItemLink(); |
|
| 418 | - } else { |
|
| 419 | - $value = $object->getVar($column->getKeyName()); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - $aColumn['value'] = $value; |
|
| 424 | - $aColumn['class'] = $class; |
|
| 425 | - $aColumn['width'] = $column->getWidth(); |
|
| 426 | - $aColumn['align'] = $column->getAlign(); |
|
| 427 | - |
|
| 428 | - $aColumns[] = $aColumn; |
|
| 429 | - ++$i; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - $aObject['columns'] = $aColumns; |
|
| 433 | - $aObject['id'] = $object->id(); |
|
| 434 | - |
|
| 435 | - $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
| 436 | - |
|
| 437 | - $aObject['class'] = $objectclass; |
|
| 438 | - |
|
| 439 | - $actions = array(); |
|
| 440 | - |
|
| 441 | - // Adding the custom actions if any |
|
| 442 | - foreach ($this->_custom_actions as $action) { |
|
| 443 | - if (method_exists($object, $action)) { |
|
| 444 | - $actions[] = $object->$action(); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 449 | - $controller = new SmartObjectController($this->_objectHandler); |
|
| 450 | - |
|
| 451 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 452 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 453 | - } |
|
| 454 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 455 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 456 | - } |
|
| 457 | - $aObject['actions'] = $actions; |
|
| 458 | - |
|
| 459 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 460 | - |
|
| 461 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 462 | - |
|
| 463 | - $this->_aObjects[] = $aObject; |
|
| 464 | - } |
|
| 465 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 466 | - } else { |
|
| 467 | - $colspan = count($this->_columns) + 1; |
|
| 468 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 469 | - } |
|
| 470 | - $this->_hasActions = $doWeHaveActions; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * @param bool $debug |
|
| 475 | - * @return mixed |
|
| 476 | - */ |
|
| 477 | - public function fetchObjects($debug = false) |
|
| 478 | - { |
|
| 479 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - public function getDefaultFilter() |
|
| 486 | - { |
|
| 487 | - if ($this->_filtersel) { |
|
| 488 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 489 | - } else { |
|
| 490 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * @return array|bool |
|
| 496 | - */ |
|
| 497 | - public function getFiltersArray() |
|
| 498 | - { |
|
| 499 | - $ret = array(); |
|
| 500 | - $field = array(); |
|
| 501 | - $field['caption'] = _CO_OBJ_NONE; |
|
| 502 | - $field['selected'] = ''; |
|
| 503 | - $ret['default'] = $field; |
|
| 504 | - unset($field); |
|
| 505 | - |
|
| 506 | - if ($this->_filterseloptions) { |
|
| 507 | - foreach ($this->_filterseloptions as $key => $value) { |
|
| 508 | - $field = array(); |
|
| 509 | - if (is_array($value)) { |
|
| 510 | - $field['caption'] = $key; |
|
| 511 | - $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
| 512 | - } else { |
|
| 513 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 514 | - $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
| 515 | - } |
|
| 516 | - $ret[$key] = $field; |
|
| 517 | - unset($field); |
|
| 518 | - } |
|
| 519 | - } else { |
|
| 520 | - $ret = false; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - return $ret; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * @param $default_filter2 |
|
| 528 | - */ |
|
| 529 | - public function setDefaultFilter2($default_filter2) |
|
| 530 | - { |
|
| 531 | - $this->_filtersel2 = $default_filter2; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * @return string |
|
| 536 | - */ |
|
| 537 | - public function getDefaultFilter2() |
|
| 538 | - { |
|
| 539 | - if ($this->_filtersel2) { |
|
| 540 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 541 | - } else { |
|
| 542 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * @return array |
|
| 548 | - */ |
|
| 549 | - public function getFilters2Array() |
|
| 550 | - { |
|
| 551 | - $ret = array(); |
|
| 552 | - |
|
| 553 | - foreach ($this->_filtersel2options as $key => $value) { |
|
| 554 | - $field = array(); |
|
| 555 | - $field['caption'] = $value; |
|
| 556 | - $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : ''; |
|
| 557 | - $ret[$key] = $field; |
|
| 558 | - unset($field); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return $ret; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * @param $limitsArray |
|
| 566 | - * @param $params_of_the_options_sel |
|
| 567 | - */ |
|
| 568 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 569 | - { |
|
| 570 | - // Rendering the form to select options on the table |
|
| 571 | - $current_urls = smart_getCurrentUrls(); |
|
| 572 | - $current_url = $current_urls['full']; |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * What was $params_of_the_options_sel doing again ? |
|
| 576 | - */ |
|
| 577 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 578 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 579 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * @return array |
|
| 584 | - */ |
|
| 585 | - public function getLimitsArray() |
|
| 586 | - { |
|
| 587 | - $ret = array(); |
|
| 588 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 589 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? "selected='selected'" : ''; |
|
| 590 | - |
|
| 591 | - $ret['5']['caption'] = '5'; |
|
| 592 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 593 | - |
|
| 594 | - $ret['10']['caption'] = '10'; |
|
| 595 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 596 | - |
|
| 597 | - $ret['15']['caption'] = '15'; |
|
| 598 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 599 | - |
|
| 600 | - $ret['20']['caption'] = '20'; |
|
| 601 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 602 | - |
|
| 603 | - $ret['25']['caption'] = '25'; |
|
| 604 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 605 | - |
|
| 606 | - $ret['30']['caption'] = '30'; |
|
| 607 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 608 | - |
|
| 609 | - $ret['35']['caption'] = '35'; |
|
| 610 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 611 | - |
|
| 612 | - $ret['40']['caption'] = '40'; |
|
| 613 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 614 | - |
|
| 615 | - return $ret; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @return bool |
|
| 620 | - */ |
|
| 621 | - public function getObjects() |
|
| 622 | - { |
|
| 623 | - return $this->_objects; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - public function hideActionColumnTitle() |
|
| 627 | - { |
|
| 628 | - $this->_showActionsColumnTitle = false; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - public function hideFilterAndLimit() |
|
| 632 | - { |
|
| 633 | - $this->_showFilterAndLimit = false; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * @return array |
|
| 638 | - */ |
|
| 639 | - public function getOrdersArray() |
|
| 640 | - { |
|
| 641 | - $ret = array(); |
|
| 642 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 643 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
| 644 | - |
|
| 645 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 646 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
| 647 | - |
|
| 648 | - return $ret; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * @return mixed|string|void |
|
| 653 | - */ |
|
| 654 | - public function renderD() |
|
| 655 | - { |
|
| 656 | - return $this->render(false, true); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - public function renderForPrint() |
|
| 660 | - { |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * @param bool $fetchOnly |
|
| 665 | - * @param bool $debug |
|
| 666 | - * @return mixed|string|void |
|
| 667 | - */ |
|
| 668 | - public function render($fetchOnly = false, $debug = false) |
|
| 669 | - { |
|
| 670 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 671 | - |
|
| 672 | - $this->_tpl = new XoopsTpl(); |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 676 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 677 | - * and we will free it after |
|
| 678 | - */ |
|
| 679 | - $this->_tempObject = $this->_objectHandler->create(); |
|
| 680 | - |
|
| 681 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 682 | - |
|
| 683 | - $this->setSortOrder(); |
|
| 684 | - |
|
| 685 | - if (!$this->_isTree) { |
|
| 686 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 687 | - } else { |
|
| 688 | - $this->_limitsel = 'all'; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 692 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 693 | - $limitsArray = $this->getLimitsArray(); |
|
| 694 | - $this->_criteria->setLimit($this->_limitsel); |
|
| 695 | - |
|
| 696 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 697 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 698 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 699 | - $filtersArray = $this->getFiltersArray(); |
|
| 700 | - |
|
| 701 | - if ($filtersArray) { |
|
| 702 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 706 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 707 | - // check if method associate with this filter exists in the handler |
|
| 708 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 709 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 710 | - $this->_criteria->add($filter['criteria']); |
|
| 711 | - } else { |
|
| 712 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 713 | - |
|
| 714 | - // then we will create the selfilter2 options by calling this method |
|
| 715 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 716 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 717 | - |
|
| 718 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 719 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 720 | - |
|
| 721 | - $filters2Array = $this->getFilters2Array(); |
|
| 722 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 723 | - |
|
| 724 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 725 | - if ($this->_filtersel2 !== 'default') { |
|
| 726 | - $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - // Check if we have a quicksearch |
|
| 732 | - |
|
| 733 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
| 734 | - $quicksearch_criteria = new CriteriaCompo(); |
|
| 735 | - if (is_array($this->_quickSearch['fields'])) { |
|
| 736 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
| 737 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 738 | - } |
|
| 739 | - } else { |
|
| 740 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 741 | - } |
|
| 742 | - $this->_criteria->add($quicksearch_criteria); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - $this->_objects = $this->fetchObjects($debug); |
|
| 746 | - |
|
| 747 | - include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 748 | - if ($this->_criteria->getLimit() > 0) { |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * Geeting rid of the old params |
|
| 752 | - * $new_get_array is an array containing the new GET parameters |
|
| 753 | - */ |
|
| 754 | - $new_get_array = array(); |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 758 | - * but without the pagenave parameters. This array will be used in the |
|
| 759 | - * OptionsSelection |
|
| 760 | - */ |
|
| 761 | - $params_of_the_options_sel = array(); |
|
| 762 | - |
|
| 763 | - $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
| 764 | - foreach ($_GET as $k => $v) { |
|
| 765 | - if (!in_array($k, $not_needed_params)) { |
|
| 766 | - $new_get_array[] = "$k=$v"; |
|
| 767 | - $params_of_the_options_sel[] = "$k=$v"; |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * Adding the new params of the pagenav |
|
| 773 | - */ |
|
| 774 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 775 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 776 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 777 | - $otherParams = implode('&', $new_get_array); |
|
| 778 | - |
|
| 779 | - $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 780 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 781 | - } |
|
| 782 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 783 | - |
|
| 784 | - // retreive the current url and the query string |
|
| 785 | - $current_urls = smart_getCurrentUrls(); |
|
| 786 | - $current_url = $current_urls['full_phpself']; |
|
| 787 | - $query_string = $current_urls['querystring']; |
|
| 788 | - if ($query_string) { |
|
| 789 | - $query_string = str_replace('?', '', $query_string); |
|
| 790 | - } |
|
| 791 | - $query_stringArray = explode('&', $query_string); |
|
| 792 | - $new_query_stringArray = array(); |
|
| 793 | - foreach ($query_stringArray as $query_string) { |
|
| 794 | - if (strpos($query_string, 'sortsel') == false && strpos($query_string, 'ordersel') == false) { |
|
| 795 | - $new_query_stringArray[] = $query_string; |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - $new_query_string = implode('&', $new_query_stringArray); |
|
| 799 | - |
|
| 800 | - $orderArray = array(); |
|
| 801 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
| 802 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 803 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
| 804 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 805 | - |
|
| 806 | - $aColumns = array(); |
|
| 807 | - |
|
| 808 | - foreach ($this->_columns as $column) { |
|
| 809 | - $qs_param = ''; |
|
| 810 | - $aColumn = array(); |
|
| 811 | - $aColumn['width'] = $column->getWidth(); |
|
| 812 | - $aColumn['align'] = $column->getAlign(); |
|
| 813 | - $aColumn['key'] = $column->getKeyName(); |
|
| 814 | - if ($column->_keyname === 'checked') { |
|
| 815 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');" />'; |
|
| 816 | - } elseif ($column->getCustomCaption()) { |
|
| 817 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
| 818 | - } else { |
|
| 819 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 820 | - } |
|
| 821 | - // Are we doing a GET sort on this column ? |
|
| 822 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) || ($this->_sortsel == $column->getKeyName()); |
|
| 823 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 824 | - |
|
| 825 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
| 826 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 827 | - } |
|
| 828 | - if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
| 829 | - $aColumn['caption'] = $aColumn['caption']; |
|
| 830 | - } elseif ($getSort) { |
|
| 831 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=' . $orderArray[$order]['neworder'] . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . ' <img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . $orderArray[$order]['image'] . '" alt="ASC" /></a>'; |
|
| 832 | - } else { |
|
| 833 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 834 | - } |
|
| 835 | - $aColumns[] = $aColumn; |
|
| 836 | - } |
|
| 837 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 838 | - |
|
| 839 | - if ($this->_quickSearch) { |
|
| 840 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - $this->createTableRows(); |
|
| 844 | - |
|
| 845 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 846 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 847 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 848 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 849 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 850 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 851 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 852 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 853 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 854 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 855 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 856 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 857 | - if (!empty($this->_withSelectedActions)) { |
|
| 858 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 862 | - if ($fetchOnly) { |
|
| 863 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 864 | - } else { |
|
| 865 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - public function disableColumnsSorting() |
|
| 870 | - { |
|
| 871 | - $this->_enableColumnsSorting = false; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * @param bool $debug |
|
| 876 | - * @return mixed|string|void |
|
| 877 | - */ |
|
| 878 | - public function fetch($debug = false) |
|
| 879 | - { |
|
| 880 | - return $this->render(true, $debug); |
|
| 881 | - } |
|
| 108 | + public $_id; |
|
| 109 | + public $_objectHandler; |
|
| 110 | + public $_columns; |
|
| 111 | + public $_criteria; |
|
| 112 | + public $_actions; |
|
| 113 | + public $_objects = false; |
|
| 114 | + public $_aObjects; |
|
| 115 | + public $_custom_actions; |
|
| 116 | + public $_sortsel; |
|
| 117 | + public $_ordersel; |
|
| 118 | + public $_limitsel; |
|
| 119 | + public $_filtersel; |
|
| 120 | + public $_filterseloptions; |
|
| 121 | + public $_filtersel2; |
|
| 122 | + public $_filtersel2options; |
|
| 123 | + public $_filtersel2optionsDefault; |
|
| 124 | + |
|
| 125 | + public $_tempObject; |
|
| 126 | + public $_tpl; |
|
| 127 | + public $_introButtons; |
|
| 128 | + public $_quickSearch = false; |
|
| 129 | + public $_actionButtons = false; |
|
| 130 | + public $_head_css_class = 'bg3'; |
|
| 131 | + public $_hasActions = false; |
|
| 132 | + public $_userSide = false; |
|
| 133 | + public $_printerFriendlyPage = false; |
|
| 134 | + public $_tableHeader = false; |
|
| 135 | + public $_tableFooter = false; |
|
| 136 | + public $_showActionsColumnTitle = true; |
|
| 137 | + public $_isTree = false; |
|
| 138 | + public $_showFilterAndLimit = true; |
|
| 139 | + public $_enableColumnsSorting = true; |
|
| 140 | + public $_customTemplate = false; |
|
| 141 | + public $_withSelectedActions = array(); |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Constructor |
|
| 145 | + * |
|
| 146 | + * @param object $objectHandler {@link SmartPersistableObjectHandler} |
|
| 147 | + * @param bool|object $criteria |
|
| 148 | + * @param array $actions array representing the actions to offer |
|
| 149 | + * |
|
| 150 | + * @param bool $userSide |
|
| 151 | + * @internal param array $columns array representing the columns to display in the table |
|
| 152 | + */ |
|
| 153 | + public function __construct($objectHandler, $criteria = false, $actions = array('edit', 'delete'), $userSide = false) |
|
| 154 | + { |
|
| 155 | + $this->_id = $objectHandler->className; |
|
| 156 | + $this->_objectHandler = $objectHandler; |
|
| 157 | + |
|
| 158 | + if (!$criteria) { |
|
| 159 | + $criteria = new CriteriaCompo(); |
|
| 160 | + } |
|
| 161 | + $this->_criteria = $criteria; |
|
| 162 | + $this->_actions = $actions; |
|
| 163 | + $this->_custom_actions = array(); |
|
| 164 | + $this->_userSide = $userSide; |
|
| 165 | + if ($userSide) { |
|
| 166 | + $this->_head_css_class = 'head'; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param $op |
|
| 172 | + * @param bool $caption |
|
| 173 | + * @param bool $text |
|
| 174 | + */ |
|
| 175 | + public function addActionButton($op, $caption = false, $text = false) |
|
| 176 | + { |
|
| 177 | + $action = array( |
|
| 178 | + 'op' => $op, |
|
| 179 | + 'caption' => $caption, |
|
| 180 | + 'text' => $text |
|
| 181 | + ); |
|
| 182 | + $this->_actionButtons[] = $action; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @param $columnObj |
|
| 187 | + */ |
|
| 188 | + public function addColumn($columnObj) |
|
| 189 | + { |
|
| 190 | + $this->_columns[] = $columnObj; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @param $name |
|
| 195 | + * @param $location |
|
| 196 | + * @param $value |
|
| 197 | + */ |
|
| 198 | + public function addIntroButton($name, $location, $value) |
|
| 199 | + { |
|
| 200 | + $introButton = array(); |
|
| 201 | + $introButton['name'] = $name; |
|
| 202 | + $introButton['location'] = $location; |
|
| 203 | + $introButton['value'] = $value; |
|
| 204 | + $this->_introButtons[] = $introButton; |
|
| 205 | + unset($introButton); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + public function addPrinterFriendlyLink() |
|
| 209 | + { |
|
| 210 | + $current_urls = smart_getCurrentUrls(); |
|
| 211 | + $current_url = $current_urls['full']; |
|
| 212 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @param $fields |
|
| 217 | + * @param string $caption |
|
| 218 | + */ |
|
| 219 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 220 | + { |
|
| 221 | + $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @param $content |
|
| 226 | + */ |
|
| 227 | + public function addHeader($content) |
|
| 228 | + { |
|
| 229 | + $this->_tableHeader = $content; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @param $content |
|
| 234 | + */ |
|
| 235 | + public function addFooter($content) |
|
| 236 | + { |
|
| 237 | + $this->_tableFooter = $content; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param $caption |
|
| 242 | + */ |
|
| 243 | + public function addDefaultIntroButton($caption) |
|
| 244 | + { |
|
| 245 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @param $method |
|
| 250 | + */ |
|
| 251 | + public function addCustomAction($method) |
|
| 252 | + { |
|
| 253 | + $this->_custom_actions[] = $method; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @param $default_sort |
|
| 258 | + */ |
|
| 259 | + public function setDefaultSort($default_sort) |
|
| 260 | + { |
|
| 261 | + $this->_sortsel = $default_sort; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + public function getDefaultSort() |
|
| 268 | + { |
|
| 269 | + if ($this->_sortsel) { |
|
| 270 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 271 | + } else { |
|
| 272 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @param $default_order |
|
| 278 | + */ |
|
| 279 | + public function setDefaultOrder($default_order) |
|
| 280 | + { |
|
| 281 | + $this->_ordersel = $default_order; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @return string |
|
| 286 | + */ |
|
| 287 | + public function getDefaultOrder() |
|
| 288 | + { |
|
| 289 | + if ($this->_ordersel) { |
|
| 290 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 291 | + } else { |
|
| 292 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @param array $actions |
|
| 298 | + */ |
|
| 299 | + public function addWithSelectedActions($actions = array()) |
|
| 300 | + { |
|
| 301 | + $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 302 | + $this->_withSelectedActions = $actions; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Adding a filter in the table |
|
| 307 | + * |
|
| 308 | + * @param string $key key to the field that will be used for sorting |
|
| 309 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 310 | + * @param bool $default |
|
| 311 | + */ |
|
| 312 | + public function addFilter($key, $method, $default = false) |
|
| 313 | + { |
|
| 314 | + $this->_filterseloptions[$key] = $method; |
|
| 315 | + $this->_filtersel2optionsDefault = $default; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @param $default_filter |
|
| 320 | + */ |
|
| 321 | + public function setDefaultFilter($default_filter) |
|
| 322 | + { |
|
| 323 | + $this->_filtersel = $default_filter; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + public function isForUserSide() |
|
| 327 | + { |
|
| 328 | + $this->_userSide = true; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * @param $template |
|
| 333 | + */ |
|
| 334 | + public function setCustomTemplate($template) |
|
| 335 | + { |
|
| 336 | + $this->_customTemplate = $template; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + public function setSortOrder() |
|
| 340 | + { |
|
| 341 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 342 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 343 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 344 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 345 | + |
|
| 346 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 347 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 348 | + } else { |
|
| 349 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 353 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 354 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 355 | + $ordersArray = $this->getOrdersArray(); |
|
| 356 | + $this->_criteria->setOrder($this->_ordersel); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * @param $id |
|
| 361 | + */ |
|
| 362 | + public function setTableId($id) |
|
| 363 | + { |
|
| 364 | + $this->_id = $id; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @param $objects |
|
| 369 | + */ |
|
| 370 | + public function setObjects($objects) |
|
| 371 | + { |
|
| 372 | + $this->_objects = $objects; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + public function createTableRows() |
|
| 376 | + { |
|
| 377 | + $this->_aObjects = array(); |
|
| 378 | + |
|
| 379 | + $doWeHaveActions = false; |
|
| 380 | + |
|
| 381 | + $objectclass = 'odd'; |
|
| 382 | + if (count($this->_objects) > 0) { |
|
| 383 | + foreach ($this->_objects as $object) { |
|
| 384 | + $aObject = array(); |
|
| 385 | + |
|
| 386 | + $i = 0; |
|
| 387 | + |
|
| 388 | + $aColumns = array(); |
|
| 389 | + |
|
| 390 | + foreach ($this->_columns as $column) { |
|
| 391 | + $aColumn = array(); |
|
| 392 | + |
|
| 393 | + if ($i == 0) { |
|
| 394 | + $class = 'head'; |
|
| 395 | + } elseif ($i % 2 == 0) { |
|
| 396 | + $class = 'even'; |
|
| 397 | + } else { |
|
| 398 | + $class = 'odd'; |
|
| 399 | + } |
|
| 400 | + if (method_exists($object, 'initiateCustomFields')) { |
|
| 401 | + //$object->initiateCustomFields(); |
|
| 402 | + } |
|
| 403 | + if ($column->_keyname === 'checked') { |
|
| 404 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '" />'; |
|
| 405 | + } elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
| 406 | + $method = $column->_customMethodForValue; |
|
| 407 | + if ($column->_param) { |
|
| 408 | + $value = $object->$method($column->_param); |
|
| 409 | + } else { |
|
| 410 | + $value = $object->$method(); |
|
| 411 | + } |
|
| 412 | + } else { |
|
| 413 | + /** |
|
| 414 | + * If the column is the identifier, then put a link on it |
|
| 415 | + */ |
|
| 416 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 417 | + $value = $object->getItemLink(); |
|
| 418 | + } else { |
|
| 419 | + $value = $object->getVar($column->getKeyName()); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + $aColumn['value'] = $value; |
|
| 424 | + $aColumn['class'] = $class; |
|
| 425 | + $aColumn['width'] = $column->getWidth(); |
|
| 426 | + $aColumn['align'] = $column->getAlign(); |
|
| 427 | + |
|
| 428 | + $aColumns[] = $aColumn; |
|
| 429 | + ++$i; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + $aObject['columns'] = $aColumns; |
|
| 433 | + $aObject['id'] = $object->id(); |
|
| 434 | + |
|
| 435 | + $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
| 436 | + |
|
| 437 | + $aObject['class'] = $objectclass; |
|
| 438 | + |
|
| 439 | + $actions = array(); |
|
| 440 | + |
|
| 441 | + // Adding the custom actions if any |
|
| 442 | + foreach ($this->_custom_actions as $action) { |
|
| 443 | + if (method_exists($object, $action)) { |
|
| 444 | + $actions[] = $object->$action(); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 449 | + $controller = new SmartObjectController($this->_objectHandler); |
|
| 450 | + |
|
| 451 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 452 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 453 | + } |
|
| 454 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 455 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 456 | + } |
|
| 457 | + $aObject['actions'] = $actions; |
|
| 458 | + |
|
| 459 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 460 | + |
|
| 461 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 462 | + |
|
| 463 | + $this->_aObjects[] = $aObject; |
|
| 464 | + } |
|
| 465 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 466 | + } else { |
|
| 467 | + $colspan = count($this->_columns) + 1; |
|
| 468 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 469 | + } |
|
| 470 | + $this->_hasActions = $doWeHaveActions; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * @param bool $debug |
|
| 475 | + * @return mixed |
|
| 476 | + */ |
|
| 477 | + public function fetchObjects($debug = false) |
|
| 478 | + { |
|
| 479 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + public function getDefaultFilter() |
|
| 486 | + { |
|
| 487 | + if ($this->_filtersel) { |
|
| 488 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 489 | + } else { |
|
| 490 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * @return array|bool |
|
| 496 | + */ |
|
| 497 | + public function getFiltersArray() |
|
| 498 | + { |
|
| 499 | + $ret = array(); |
|
| 500 | + $field = array(); |
|
| 501 | + $field['caption'] = _CO_OBJ_NONE; |
|
| 502 | + $field['selected'] = ''; |
|
| 503 | + $ret['default'] = $field; |
|
| 504 | + unset($field); |
|
| 505 | + |
|
| 506 | + if ($this->_filterseloptions) { |
|
| 507 | + foreach ($this->_filterseloptions as $key => $value) { |
|
| 508 | + $field = array(); |
|
| 509 | + if (is_array($value)) { |
|
| 510 | + $field['caption'] = $key; |
|
| 511 | + $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
| 512 | + } else { |
|
| 513 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 514 | + $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
| 515 | + } |
|
| 516 | + $ret[$key] = $field; |
|
| 517 | + unset($field); |
|
| 518 | + } |
|
| 519 | + } else { |
|
| 520 | + $ret = false; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + return $ret; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * @param $default_filter2 |
|
| 528 | + */ |
|
| 529 | + public function setDefaultFilter2($default_filter2) |
|
| 530 | + { |
|
| 531 | + $this->_filtersel2 = $default_filter2; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * @return string |
|
| 536 | + */ |
|
| 537 | + public function getDefaultFilter2() |
|
| 538 | + { |
|
| 539 | + if ($this->_filtersel2) { |
|
| 540 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 541 | + } else { |
|
| 542 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * @return array |
|
| 548 | + */ |
|
| 549 | + public function getFilters2Array() |
|
| 550 | + { |
|
| 551 | + $ret = array(); |
|
| 552 | + |
|
| 553 | + foreach ($this->_filtersel2options as $key => $value) { |
|
| 554 | + $field = array(); |
|
| 555 | + $field['caption'] = $value; |
|
| 556 | + $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : ''; |
|
| 557 | + $ret[$key] = $field; |
|
| 558 | + unset($field); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return $ret; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * @param $limitsArray |
|
| 566 | + * @param $params_of_the_options_sel |
|
| 567 | + */ |
|
| 568 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 569 | + { |
|
| 570 | + // Rendering the form to select options on the table |
|
| 571 | + $current_urls = smart_getCurrentUrls(); |
|
| 572 | + $current_url = $current_urls['full']; |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * What was $params_of_the_options_sel doing again ? |
|
| 576 | + */ |
|
| 577 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 578 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 579 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * @return array |
|
| 584 | + */ |
|
| 585 | + public function getLimitsArray() |
|
| 586 | + { |
|
| 587 | + $ret = array(); |
|
| 588 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 589 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? "selected='selected'" : ''; |
|
| 590 | + |
|
| 591 | + $ret['5']['caption'] = '5'; |
|
| 592 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 593 | + |
|
| 594 | + $ret['10']['caption'] = '10'; |
|
| 595 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 596 | + |
|
| 597 | + $ret['15']['caption'] = '15'; |
|
| 598 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 599 | + |
|
| 600 | + $ret['20']['caption'] = '20'; |
|
| 601 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 602 | + |
|
| 603 | + $ret['25']['caption'] = '25'; |
|
| 604 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 605 | + |
|
| 606 | + $ret['30']['caption'] = '30'; |
|
| 607 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 608 | + |
|
| 609 | + $ret['35']['caption'] = '35'; |
|
| 610 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 611 | + |
|
| 612 | + $ret['40']['caption'] = '40'; |
|
| 613 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : ''; |
|
| 614 | + |
|
| 615 | + return $ret; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @return bool |
|
| 620 | + */ |
|
| 621 | + public function getObjects() |
|
| 622 | + { |
|
| 623 | + return $this->_objects; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + public function hideActionColumnTitle() |
|
| 627 | + { |
|
| 628 | + $this->_showActionsColumnTitle = false; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + public function hideFilterAndLimit() |
|
| 632 | + { |
|
| 633 | + $this->_showFilterAndLimit = false; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * @return array |
|
| 638 | + */ |
|
| 639 | + public function getOrdersArray() |
|
| 640 | + { |
|
| 641 | + $ret = array(); |
|
| 642 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 643 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
| 644 | + |
|
| 645 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 646 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
| 647 | + |
|
| 648 | + return $ret; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * @return mixed|string|void |
|
| 653 | + */ |
|
| 654 | + public function renderD() |
|
| 655 | + { |
|
| 656 | + return $this->render(false, true); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + public function renderForPrint() |
|
| 660 | + { |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * @param bool $fetchOnly |
|
| 665 | + * @param bool $debug |
|
| 666 | + * @return mixed|string|void |
|
| 667 | + */ |
|
| 668 | + public function render($fetchOnly = false, $debug = false) |
|
| 669 | + { |
|
| 670 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 671 | + |
|
| 672 | + $this->_tpl = new XoopsTpl(); |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 676 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 677 | + * and we will free it after |
|
| 678 | + */ |
|
| 679 | + $this->_tempObject = $this->_objectHandler->create(); |
|
| 680 | + |
|
| 681 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 682 | + |
|
| 683 | + $this->setSortOrder(); |
|
| 684 | + |
|
| 685 | + if (!$this->_isTree) { |
|
| 686 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 687 | + } else { |
|
| 688 | + $this->_limitsel = 'all'; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 692 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 693 | + $limitsArray = $this->getLimitsArray(); |
|
| 694 | + $this->_criteria->setLimit($this->_limitsel); |
|
| 695 | + |
|
| 696 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 697 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 698 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 699 | + $filtersArray = $this->getFiltersArray(); |
|
| 700 | + |
|
| 701 | + if ($filtersArray) { |
|
| 702 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 706 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 707 | + // check if method associate with this filter exists in the handler |
|
| 708 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 709 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 710 | + $this->_criteria->add($filter['criteria']); |
|
| 711 | + } else { |
|
| 712 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 713 | + |
|
| 714 | + // then we will create the selfilter2 options by calling this method |
|
| 715 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 716 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 717 | + |
|
| 718 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 719 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 720 | + |
|
| 721 | + $filters2Array = $this->getFilters2Array(); |
|
| 722 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 723 | + |
|
| 724 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 725 | + if ($this->_filtersel2 !== 'default') { |
|
| 726 | + $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + // Check if we have a quicksearch |
|
| 732 | + |
|
| 733 | + if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
| 734 | + $quicksearch_criteria = new CriteriaCompo(); |
|
| 735 | + if (is_array($this->_quickSearch['fields'])) { |
|
| 736 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
| 737 | + $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 738 | + } |
|
| 739 | + } else { |
|
| 740 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 741 | + } |
|
| 742 | + $this->_criteria->add($quicksearch_criteria); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + $this->_objects = $this->fetchObjects($debug); |
|
| 746 | + |
|
| 747 | + include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 748 | + if ($this->_criteria->getLimit() > 0) { |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * Geeting rid of the old params |
|
| 752 | + * $new_get_array is an array containing the new GET parameters |
|
| 753 | + */ |
|
| 754 | + $new_get_array = array(); |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 758 | + * but without the pagenave parameters. This array will be used in the |
|
| 759 | + * OptionsSelection |
|
| 760 | + */ |
|
| 761 | + $params_of_the_options_sel = array(); |
|
| 762 | + |
|
| 763 | + $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
| 764 | + foreach ($_GET as $k => $v) { |
|
| 765 | + if (!in_array($k, $not_needed_params)) { |
|
| 766 | + $new_get_array[] = "$k=$v"; |
|
| 767 | + $params_of_the_options_sel[] = "$k=$v"; |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * Adding the new params of the pagenav |
|
| 773 | + */ |
|
| 774 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 775 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 776 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 777 | + $otherParams = implode('&', $new_get_array); |
|
| 778 | + |
|
| 779 | + $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 780 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 781 | + } |
|
| 782 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 783 | + |
|
| 784 | + // retreive the current url and the query string |
|
| 785 | + $current_urls = smart_getCurrentUrls(); |
|
| 786 | + $current_url = $current_urls['full_phpself']; |
|
| 787 | + $query_string = $current_urls['querystring']; |
|
| 788 | + if ($query_string) { |
|
| 789 | + $query_string = str_replace('?', '', $query_string); |
|
| 790 | + } |
|
| 791 | + $query_stringArray = explode('&', $query_string); |
|
| 792 | + $new_query_stringArray = array(); |
|
| 793 | + foreach ($query_stringArray as $query_string) { |
|
| 794 | + if (strpos($query_string, 'sortsel') == false && strpos($query_string, 'ordersel') == false) { |
|
| 795 | + $new_query_stringArray[] = $query_string; |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + $new_query_string = implode('&', $new_query_stringArray); |
|
| 799 | + |
|
| 800 | + $orderArray = array(); |
|
| 801 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
| 802 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 803 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
| 804 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 805 | + |
|
| 806 | + $aColumns = array(); |
|
| 807 | + |
|
| 808 | + foreach ($this->_columns as $column) { |
|
| 809 | + $qs_param = ''; |
|
| 810 | + $aColumn = array(); |
|
| 811 | + $aColumn['width'] = $column->getWidth(); |
|
| 812 | + $aColumn['align'] = $column->getAlign(); |
|
| 813 | + $aColumn['key'] = $column->getKeyName(); |
|
| 814 | + if ($column->_keyname === 'checked') { |
|
| 815 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');" />'; |
|
| 816 | + } elseif ($column->getCustomCaption()) { |
|
| 817 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
| 818 | + } else { |
|
| 819 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 820 | + } |
|
| 821 | + // Are we doing a GET sort on this column ? |
|
| 822 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) || ($this->_sortsel == $column->getKeyName()); |
|
| 823 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 824 | + |
|
| 825 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
| 826 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 827 | + } |
|
| 828 | + if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
| 829 | + $aColumn['caption'] = $aColumn['caption']; |
|
| 830 | + } elseif ($getSort) { |
|
| 831 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=' . $orderArray[$order]['neworder'] . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . ' <img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . $orderArray[$order]['image'] . '" alt="ASC" /></a>'; |
|
| 832 | + } else { |
|
| 833 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 834 | + } |
|
| 835 | + $aColumns[] = $aColumn; |
|
| 836 | + } |
|
| 837 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 838 | + |
|
| 839 | + if ($this->_quickSearch) { |
|
| 840 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + $this->createTableRows(); |
|
| 844 | + |
|
| 845 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 846 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 847 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 848 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 849 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 850 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 851 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 852 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 853 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 854 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 855 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 856 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 857 | + if (!empty($this->_withSelectedActions)) { |
|
| 858 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 862 | + if ($fetchOnly) { |
|
| 863 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 864 | + } else { |
|
| 865 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 866 | + } |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + public function disableColumnsSorting() |
|
| 870 | + { |
|
| 871 | + $this->_enableColumnsSorting = false; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * @param bool $debug |
|
| 876 | + * @return mixed|string|void |
|
| 877 | + */ |
|
| 878 | + public function fetch($debug = false) |
|
| 879 | + { |
|
| 880 | + return $this->render(true, $debug); |
|
| 881 | + } |
|
| 882 | 882 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function addActionButton($op, $caption = false, $text = false) |
| 176 | 176 | { |
| 177 | - $action = array( |
|
| 177 | + $action = array( |
|
| 178 | 178 | 'op' => $op, |
| 179 | 179 | 'caption' => $caption, |
| 180 | 180 | 'text' => $text |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | */ |
| 679 | 679 | $this->_tempObject = $this->_objectHandler->create(); |
| 680 | 680 | |
| 681 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 681 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int) $_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 682 | 682 | |
| 683 | 683 | $this->setSortOrder(); |
| 684 | 684 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | - * @param $name |
|
| 192 | + * @param string $name |
|
| 193 | 193 | * @param string $extension |
| 194 | 194 | * @return array |
| 195 | 195 | */ |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | /** |
| 256 | 256 | * Return random background |
| 257 | 257 | * |
| 258 | - * @return array |
|
| 258 | + * @return string|null |
|
| 259 | 259 | */ |
| 260 | 260 | public function loadBackground() |
| 261 | 261 | { |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Image Creation script |
|
| 4 | - * |
|
| 5 | - * D.J. |
|
| 6 | - */ |
|
| 3 | + * Image Creation script |
|
| 4 | + * |
|
| 5 | + * D.J. |
|
| 6 | + */ |
|
| 7 | 7 | |
| 8 | 8 | include dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/mainfile.php'; |
| 9 | 9 | error_reporting(0); |
| 10 | 10 | $xoopsLogger->activated = false; |
| 11 | 11 | |
| 12 | 12 | if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', $_SERVER['HTTP_REFERER'])) { |
| 13 | - exit(); |
|
| 13 | + exit(); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -18,185 +18,185 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class XoopsCaptchaImageHandler |
| 20 | 20 | { |
| 21 | - public $config = array(); |
|
| 22 | - //var $mode = "gd"; // GD or bmp |
|
| 23 | - public $code; |
|
| 24 | - public $invalid = false; |
|
| 25 | - |
|
| 26 | - public $font; |
|
| 27 | - public $spacing; |
|
| 28 | - public $width; |
|
| 29 | - public $height; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * XoopsCaptchaImageHandler constructor. |
|
| 33 | - */ |
|
| 34 | - public function __construct() |
|
| 35 | - { |
|
| 36 | - if (empty($_SESSION['XoopsCaptcha_name'])) { |
|
| 37 | - $this->invalid = true; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (!extension_loaded('gd')) { |
|
| 41 | - $this->mode = 'bmp'; |
|
| 42 | - } else { |
|
| 43 | - $required_functions = array('imagecreatetruecolor', 'imagecolorallocate', 'imagefilledrectangle', 'imagejpeg', 'imagedestroy', 'imageftbbox'); |
|
| 44 | - foreach ($required_functions as $func) { |
|
| 45 | - if (!function_exists($func)) { |
|
| 46 | - $this->mode = 'bmp'; |
|
| 47 | - break; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Loading configs from CAPTCHA class |
|
| 55 | - * @param array $config |
|
| 56 | - */ |
|
| 57 | - public function setConfig($config = array()) |
|
| 58 | - { |
|
| 59 | - // Loading default preferences |
|
| 60 | - $this->config = $config; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function loadImage() |
|
| 64 | - { |
|
| 65 | - $this->createCode(); |
|
| 66 | - $this->setCode(); |
|
| 67 | - $this->createImage(); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Create Code |
|
| 72 | - */ |
|
| 73 | - public function createCode() |
|
| 74 | - { |
|
| 75 | - if ($this->invalid) { |
|
| 76 | - return; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ($this->mode === 'bmp') { |
|
| 80 | - $this->config['num_chars'] = 4; |
|
| 81 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
| 82 | - } else { |
|
| 83 | - $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
| 84 | - if (!$this->config['casesensitive']) { |
|
| 85 | - $this->code = strtoupper($this->code); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - public function setCode() |
|
| 91 | - { |
|
| 92 | - if ($this->invalid) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 97 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 98 | - |
|
| 99 | - // Increase the attempt records on refresh |
|
| 100 | - if (!empty($maxAttempts)) { |
|
| 101 | - $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
| 102 | - if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
| 103 | - $this->invalid = true; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $file |
|
| 110 | - * @return string|void |
|
| 111 | - */ |
|
| 112 | - public function createImage($file = '') |
|
| 113 | - { |
|
| 114 | - if ($this->invalid) { |
|
| 115 | - header('Content-type: image/gif'); |
|
| 116 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
| 117 | - |
|
| 118 | - return; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ($this->mode === 'bmp') { |
|
| 122 | - return $this->createImageBmp(); |
|
| 123 | - } else { |
|
| 124 | - return $this->createImageGd(); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Create CAPTCHA iamge with GD |
|
| 130 | - * Originated from DuGris' SecurityImage |
|
| 131 | - * @param string $file |
|
| 132 | - */ |
|
| 133 | - // --------------------------------------------------------------------------- // |
|
| 134 | - // Class: SecurityImage 1.5 // |
|
| 135 | - // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
| 136 | - // Email: [email protected] // |
|
| 137 | - // Licence: GNU // |
|
| 138 | - // Project: XOOPS Project // |
|
| 139 | - // --------------------------------------------------------------------------- // |
|
| 140 | - public function createImageGd($file = '') |
|
| 141 | - { |
|
| 142 | - $this->loadFont(); |
|
| 143 | - $this->setImageSize(); |
|
| 144 | - |
|
| 145 | - $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
| 146 | - $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
| 147 | - imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
| 148 | - |
|
| 149 | - switch ($this->config['background_type']) { |
|
| 150 | - default: |
|
| 151 | - case 0: |
|
| 152 | - $this->drawBars(); |
|
| 153 | - break; |
|
| 154 | - |
|
| 155 | - case 1: |
|
| 156 | - $this->drawCircles(); |
|
| 157 | - break; |
|
| 158 | - |
|
| 159 | - case 2: |
|
| 160 | - $this->drawLines(); |
|
| 161 | - break; |
|
| 162 | - |
|
| 163 | - case 3: |
|
| 164 | - $this->drawRectangles(); |
|
| 165 | - break; |
|
| 166 | - |
|
| 167 | - case 4: |
|
| 168 | - $this->drawEllipses(); |
|
| 169 | - break; |
|
| 170 | - |
|
| 171 | - case 5: |
|
| 172 | - $this->drawPolygons(); |
|
| 173 | - break; |
|
| 174 | - |
|
| 175 | - case 100: |
|
| 176 | - $this->createFromFile(); |
|
| 177 | - break; |
|
| 178 | - } |
|
| 179 | - $this->drawBorder(); |
|
| 180 | - $this->drawCode(); |
|
| 181 | - |
|
| 182 | - if (empty($file)) { |
|
| 183 | - header('Content-type: image/jpeg'); |
|
| 184 | - imagejpeg($this->oImage); |
|
| 185 | - } else { |
|
| 186 | - imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
| 187 | - } |
|
| 188 | - imagedestroy($this->oImage); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @param $name |
|
| 193 | - * @param string $extension |
|
| 194 | - * @return array |
|
| 195 | - */ |
|
| 196 | - public function _getList($name, $extension = '') |
|
| 197 | - { |
|
| 198 | - $items = array(); |
|
| 199 | - /* |
|
| 21 | + public $config = array(); |
|
| 22 | + //var $mode = "gd"; // GD or bmp |
|
| 23 | + public $code; |
|
| 24 | + public $invalid = false; |
|
| 25 | + |
|
| 26 | + public $font; |
|
| 27 | + public $spacing; |
|
| 28 | + public $width; |
|
| 29 | + public $height; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * XoopsCaptchaImageHandler constructor. |
|
| 33 | + */ |
|
| 34 | + public function __construct() |
|
| 35 | + { |
|
| 36 | + if (empty($_SESSION['XoopsCaptcha_name'])) { |
|
| 37 | + $this->invalid = true; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (!extension_loaded('gd')) { |
|
| 41 | + $this->mode = 'bmp'; |
|
| 42 | + } else { |
|
| 43 | + $required_functions = array('imagecreatetruecolor', 'imagecolorallocate', 'imagefilledrectangle', 'imagejpeg', 'imagedestroy', 'imageftbbox'); |
|
| 44 | + foreach ($required_functions as $func) { |
|
| 45 | + if (!function_exists($func)) { |
|
| 46 | + $this->mode = 'bmp'; |
|
| 47 | + break; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Loading configs from CAPTCHA class |
|
| 55 | + * @param array $config |
|
| 56 | + */ |
|
| 57 | + public function setConfig($config = array()) |
|
| 58 | + { |
|
| 59 | + // Loading default preferences |
|
| 60 | + $this->config = $config; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function loadImage() |
|
| 64 | + { |
|
| 65 | + $this->createCode(); |
|
| 66 | + $this->setCode(); |
|
| 67 | + $this->createImage(); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Create Code |
|
| 72 | + */ |
|
| 73 | + public function createCode() |
|
| 74 | + { |
|
| 75 | + if ($this->invalid) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ($this->mode === 'bmp') { |
|
| 80 | + $this->config['num_chars'] = 4; |
|
| 81 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
| 82 | + } else { |
|
| 83 | + $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
| 84 | + if (!$this->config['casesensitive']) { |
|
| 85 | + $this->code = strtoupper($this->code); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + public function setCode() |
|
| 91 | + { |
|
| 92 | + if ($this->invalid) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 97 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 98 | + |
|
| 99 | + // Increase the attempt records on refresh |
|
| 100 | + if (!empty($maxAttempts)) { |
|
| 101 | + $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
| 102 | + if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
| 103 | + $this->invalid = true; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $file |
|
| 110 | + * @return string|void |
|
| 111 | + */ |
|
| 112 | + public function createImage($file = '') |
|
| 113 | + { |
|
| 114 | + if ($this->invalid) { |
|
| 115 | + header('Content-type: image/gif'); |
|
| 116 | + readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
| 117 | + |
|
| 118 | + return; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ($this->mode === 'bmp') { |
|
| 122 | + return $this->createImageBmp(); |
|
| 123 | + } else { |
|
| 124 | + return $this->createImageGd(); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Create CAPTCHA iamge with GD |
|
| 130 | + * Originated from DuGris' SecurityImage |
|
| 131 | + * @param string $file |
|
| 132 | + */ |
|
| 133 | + // --------------------------------------------------------------------------- // |
|
| 134 | + // Class: SecurityImage 1.5 // |
|
| 135 | + // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
| 136 | + // Email: [email protected] // |
|
| 137 | + // Licence: GNU // |
|
| 138 | + // Project: XOOPS Project // |
|
| 139 | + // --------------------------------------------------------------------------- // |
|
| 140 | + public function createImageGd($file = '') |
|
| 141 | + { |
|
| 142 | + $this->loadFont(); |
|
| 143 | + $this->setImageSize(); |
|
| 144 | + |
|
| 145 | + $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
| 146 | + $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
| 147 | + imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
| 148 | + |
|
| 149 | + switch ($this->config['background_type']) { |
|
| 150 | + default: |
|
| 151 | + case 0: |
|
| 152 | + $this->drawBars(); |
|
| 153 | + break; |
|
| 154 | + |
|
| 155 | + case 1: |
|
| 156 | + $this->drawCircles(); |
|
| 157 | + break; |
|
| 158 | + |
|
| 159 | + case 2: |
|
| 160 | + $this->drawLines(); |
|
| 161 | + break; |
|
| 162 | + |
|
| 163 | + case 3: |
|
| 164 | + $this->drawRectangles(); |
|
| 165 | + break; |
|
| 166 | + |
|
| 167 | + case 4: |
|
| 168 | + $this->drawEllipses(); |
|
| 169 | + break; |
|
| 170 | + |
|
| 171 | + case 5: |
|
| 172 | + $this->drawPolygons(); |
|
| 173 | + break; |
|
| 174 | + |
|
| 175 | + case 100: |
|
| 176 | + $this->createFromFile(); |
|
| 177 | + break; |
|
| 178 | + } |
|
| 179 | + $this->drawBorder(); |
|
| 180 | + $this->drawCode(); |
|
| 181 | + |
|
| 182 | + if (empty($file)) { |
|
| 183 | + header('Content-type: image/jpeg'); |
|
| 184 | + imagejpeg($this->oImage); |
|
| 185 | + } else { |
|
| 186 | + imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
| 187 | + } |
|
| 188 | + imagedestroy($this->oImage); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @param $name |
|
| 193 | + * @param string $extension |
|
| 194 | + * @return array |
|
| 195 | + */ |
|
| 196 | + public function _getList($name, $extension = '') |
|
| 197 | + { |
|
| 198 | + $items = array(); |
|
| 199 | + /* |
|
| 200 | 200 | if (@ include_once XOOPS_ROOT_PATH."/Frameworks/art/functions.ini.php") { |
| 201 | 201 | load_functions("cache"); |
| 202 | 202 | if ($items = mod_loadCacheFile("captcha_{$name}", "captcha")) { |
@@ -204,231 +204,231 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | */ |
| 207 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 208 | - $file_path = $this->config['rootpath'] . "/{$name}"; |
|
| 209 | - $files = XoopsLists::getFileListAsArray($file_path); |
|
| 210 | - foreach ($files as $item) { |
|
| 211 | - if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
| 212 | - $items[] = $item; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - if (function_exists('mod_createCacheFile')) { |
|
| 216 | - mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - return $items; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - public function loadFont() |
|
| 223 | - { |
|
| 224 | - $fonts = $this->_getList('fonts', 'ttf'); |
|
| 225 | - $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - public function setImageSize() |
|
| 229 | - { |
|
| 230 | - $MaxCharWidth = 0; |
|
| 231 | - $MaxCharHeight = 0; |
|
| 232 | - $oImage = imagecreatetruecolor(100, 100); |
|
| 233 | - $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 234 | - $FontSize = $this->config['fontsize_max']; |
|
| 235 | - for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
| 236 | - for ($i = 65; $i <= 90; ++$i) { |
|
| 237 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), array()); |
|
| 238 | - $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
| 239 | - if ($_MaxCharWidth > $MaxCharWidth) { |
|
| 240 | - $MaxCharWidth = $_MaxCharWidth; |
|
| 241 | - } |
|
| 242 | - $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 243 | - if ($_MaxCharHeight > $MaxCharHeight) { |
|
| 244 | - $MaxCharHeight = $_MaxCharHeight; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - imagedestroy($oImage); |
|
| 249 | - |
|
| 250 | - $this->height = $MaxCharHeight + 2; |
|
| 251 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 252 | - $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Return random background |
|
| 257 | - * |
|
| 258 | - * @return array |
|
| 259 | - */ |
|
| 260 | - public function loadBackground() |
|
| 261 | - { |
|
| 262 | - $RandBackground = null; |
|
| 263 | - if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
| 264 | - $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return $RandBackground; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Draw Image background |
|
| 272 | - */ |
|
| 273 | - public function createFromFile() |
|
| 274 | - { |
|
| 275 | - if ($RandImage = $this->loadBackground()) { |
|
| 276 | - $ImageType = @getimagesize($RandImage); |
|
| 277 | - switch (@$ImageType[2]) { |
|
| 278 | - case 1: |
|
| 279 | - $BackgroundImage = imagecreatefromgif($RandImage); |
|
| 280 | - break; |
|
| 281 | - |
|
| 282 | - case 2: |
|
| 283 | - $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
| 284 | - break; |
|
| 285 | - |
|
| 286 | - case 3: |
|
| 287 | - $BackgroundImage = imagecreatefrompng($RandImage); |
|
| 288 | - break; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - if (!empty($BackgroundImage)) { |
|
| 292 | - imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
| 293 | - imagedestroy($BackgroundImage); |
|
| 294 | - } else { |
|
| 295 | - $this->drawBars(); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Draw Code |
|
| 301 | - */ |
|
| 302 | - public function drawCode() |
|
| 303 | - { |
|
| 304 | - for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
| 305 | - // select random greyscale colour |
|
| 306 | - $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 307 | - |
|
| 308 | - // write text to image |
|
| 309 | - $Angle = mt_rand(10, 30); |
|
| 310 | - if ($i % 2) { |
|
| 311 | - $Angle = mt_rand(-10, -30); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // select random font size |
|
| 315 | - $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
| 316 | - |
|
| 317 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], array()); |
|
| 318 | - $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 319 | - |
|
| 320 | - // calculate character starting coordinates |
|
| 321 | - $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
| 322 | - $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
| 323 | - |
|
| 324 | - imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()); |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Draw Border |
|
| 330 | - */ |
|
| 331 | - public function drawBorder() |
|
| 332 | - { |
|
| 333 | - $rgb = mt_rand(50, 150); |
|
| 334 | - $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
| 335 | - imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Draw Circles background |
|
| 340 | - */ |
|
| 341 | - public function drawCircles() |
|
| 342 | - { |
|
| 343 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 344 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 345 | - imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Draw Lines background |
|
| 351 | - */ |
|
| 352 | - public function drawLines() |
|
| 353 | - { |
|
| 354 | - for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
| 355 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 356 | - imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Draw Rectangles background |
|
| 362 | - */ |
|
| 363 | - public function drawRectangles() |
|
| 364 | - { |
|
| 365 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 366 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 367 | - imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Draw Bars background |
|
| 373 | - */ |
|
| 374 | - public function drawBars() |
|
| 375 | - { |
|
| 376 | - for ($i = 0; $i <= $this->height;) { |
|
| 377 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 378 | - imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
| 379 | - $i = $i + 2.5; |
|
| 380 | - } |
|
| 381 | - for ($i = 0; $i <= $this->width;) { |
|
| 382 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 383 | - imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
| 384 | - $i = $i + 2.5; |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Draw Ellipses background |
|
| 390 | - */ |
|
| 391 | - public function drawEllipses() |
|
| 392 | - { |
|
| 393 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 394 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 395 | - imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Draw polygons background |
|
| 401 | - */ |
|
| 402 | - public function drawPolygons() |
|
| 403 | - { |
|
| 404 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 405 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 406 | - $coords = array(); |
|
| 407 | - for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
| 408 | - $coords[] = mt_rand(0, $this->width); |
|
| 409 | - $coords[] = mt_rand(0, $this->height); |
|
| 410 | - } |
|
| 411 | - imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Create CAPTCHA iamge with BMP |
|
| 417 | - * TODO |
|
| 418 | - * @param string $file |
|
| 419 | - * @return string |
|
| 420 | - */ |
|
| 421 | - public function createImageBmp($file = '') |
|
| 422 | - { |
|
| 423 | - $image = ''; |
|
| 424 | - |
|
| 425 | - if (empty($file)) { |
|
| 426 | - header('Content-type: image/bmp'); |
|
| 427 | - echo $image; |
|
| 428 | - } else { |
|
| 429 | - return $image; |
|
| 430 | - } |
|
| 431 | - } |
|
| 207 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 208 | + $file_path = $this->config['rootpath'] . "/{$name}"; |
|
| 209 | + $files = XoopsLists::getFileListAsArray($file_path); |
|
| 210 | + foreach ($files as $item) { |
|
| 211 | + if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
| 212 | + $items[] = $item; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + if (function_exists('mod_createCacheFile')) { |
|
| 216 | + mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + return $items; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + public function loadFont() |
|
| 223 | + { |
|
| 224 | + $fonts = $this->_getList('fonts', 'ttf'); |
|
| 225 | + $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + public function setImageSize() |
|
| 229 | + { |
|
| 230 | + $MaxCharWidth = 0; |
|
| 231 | + $MaxCharHeight = 0; |
|
| 232 | + $oImage = imagecreatetruecolor(100, 100); |
|
| 233 | + $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 234 | + $FontSize = $this->config['fontsize_max']; |
|
| 235 | + for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
| 236 | + for ($i = 65; $i <= 90; ++$i) { |
|
| 237 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), array()); |
|
| 238 | + $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
| 239 | + if ($_MaxCharWidth > $MaxCharWidth) { |
|
| 240 | + $MaxCharWidth = $_MaxCharWidth; |
|
| 241 | + } |
|
| 242 | + $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 243 | + if ($_MaxCharHeight > $MaxCharHeight) { |
|
| 244 | + $MaxCharHeight = $_MaxCharHeight; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + imagedestroy($oImage); |
|
| 249 | + |
|
| 250 | + $this->height = $MaxCharHeight + 2; |
|
| 251 | + $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 252 | + $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Return random background |
|
| 257 | + * |
|
| 258 | + * @return array |
|
| 259 | + */ |
|
| 260 | + public function loadBackground() |
|
| 261 | + { |
|
| 262 | + $RandBackground = null; |
|
| 263 | + if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
| 264 | + $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return $RandBackground; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Draw Image background |
|
| 272 | + */ |
|
| 273 | + public function createFromFile() |
|
| 274 | + { |
|
| 275 | + if ($RandImage = $this->loadBackground()) { |
|
| 276 | + $ImageType = @getimagesize($RandImage); |
|
| 277 | + switch (@$ImageType[2]) { |
|
| 278 | + case 1: |
|
| 279 | + $BackgroundImage = imagecreatefromgif($RandImage); |
|
| 280 | + break; |
|
| 281 | + |
|
| 282 | + case 2: |
|
| 283 | + $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
| 284 | + break; |
|
| 285 | + |
|
| 286 | + case 3: |
|
| 287 | + $BackgroundImage = imagecreatefrompng($RandImage); |
|
| 288 | + break; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + if (!empty($BackgroundImage)) { |
|
| 292 | + imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
| 293 | + imagedestroy($BackgroundImage); |
|
| 294 | + } else { |
|
| 295 | + $this->drawBars(); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Draw Code |
|
| 301 | + */ |
|
| 302 | + public function drawCode() |
|
| 303 | + { |
|
| 304 | + for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
| 305 | + // select random greyscale colour |
|
| 306 | + $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 307 | + |
|
| 308 | + // write text to image |
|
| 309 | + $Angle = mt_rand(10, 30); |
|
| 310 | + if ($i % 2) { |
|
| 311 | + $Angle = mt_rand(-10, -30); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // select random font size |
|
| 315 | + $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
| 316 | + |
|
| 317 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], array()); |
|
| 318 | + $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 319 | + |
|
| 320 | + // calculate character starting coordinates |
|
| 321 | + $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
| 322 | + $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
| 323 | + |
|
| 324 | + imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()); |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Draw Border |
|
| 330 | + */ |
|
| 331 | + public function drawBorder() |
|
| 332 | + { |
|
| 333 | + $rgb = mt_rand(50, 150); |
|
| 334 | + $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
| 335 | + imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Draw Circles background |
|
| 340 | + */ |
|
| 341 | + public function drawCircles() |
|
| 342 | + { |
|
| 343 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 344 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 345 | + imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Draw Lines background |
|
| 351 | + */ |
|
| 352 | + public function drawLines() |
|
| 353 | + { |
|
| 354 | + for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
| 355 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 356 | + imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Draw Rectangles background |
|
| 362 | + */ |
|
| 363 | + public function drawRectangles() |
|
| 364 | + { |
|
| 365 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 366 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 367 | + imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Draw Bars background |
|
| 373 | + */ |
|
| 374 | + public function drawBars() |
|
| 375 | + { |
|
| 376 | + for ($i = 0; $i <= $this->height;) { |
|
| 377 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 378 | + imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
| 379 | + $i = $i + 2.5; |
|
| 380 | + } |
|
| 381 | + for ($i = 0; $i <= $this->width;) { |
|
| 382 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 383 | + imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
| 384 | + $i = $i + 2.5; |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Draw Ellipses background |
|
| 390 | + */ |
|
| 391 | + public function drawEllipses() |
|
| 392 | + { |
|
| 393 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 394 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 395 | + imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Draw polygons background |
|
| 401 | + */ |
|
| 402 | + public function drawPolygons() |
|
| 403 | + { |
|
| 404 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 405 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 406 | + $coords = array(); |
|
| 407 | + for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
| 408 | + $coords[] = mt_rand(0, $this->width); |
|
| 409 | + $coords[] = mt_rand(0, $this->height); |
|
| 410 | + } |
|
| 411 | + imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Create CAPTCHA iamge with BMP |
|
| 417 | + * TODO |
|
| 418 | + * @param string $file |
|
| 419 | + * @return string |
|
| 420 | + */ |
|
| 421 | + public function createImageBmp($file = '') |
|
| 422 | + { |
|
| 423 | + $image = ''; |
|
| 424 | + |
|
| 425 | + if (empty($file)) { |
|
| 426 | + header('Content-type: image/bmp'); |
|
| 427 | + echo $image; |
|
| 428 | + } else { |
|
| 429 | + return $image; |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | $config = @include '../config.php'; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | if ($this->mode === 'bmp') { |
| 80 | 80 | $this->config['num_chars'] = 4; |
| 81 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
| 81 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int) str_pad('9', $this->config['num_chars'], '9')); |
|
| 82 | 82 | } else { |
| 83 | 83 | $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
| 84 | 84 | if (!$this->config['casesensitive']) { |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 97 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 96 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string) $this->code; |
|
| 97 | + $maxAttempts = (int) (@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 98 | 98 | |
| 99 | 99 | // Increase the attempt records on refresh |
| 100 | 100 | if (!empty($maxAttempts)) { |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | imagedestroy($oImage); |
| 249 | 249 | |
| 250 | 250 | $this->height = $MaxCharHeight + 2; |
| 251 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 251 | + $this->spacing = (int) (($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 252 | 252 | $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | -$config = @include '../config.php'; |
|
| 434 | +$config = @include '../config.php'; |
|
| 435 | 435 | $imageHandler = new XoopsCaptchaImageHandler(); |
| 436 | 436 | $imageHandler->setConfig($config); |
| 437 | 437 | $imageHandler->loadImage(); |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
| 328 | - * @param $key |
|
| 328 | + * @param string $key |
|
| 329 | 329 | * @param bool $moduleName |
| 330 | 330 | * @param string $default |
| 331 | 331 | * @return null|string |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | /** |
| 389 | 389 | * Thanks to the NewBB2 Development Team |
| 390 | - * @param $target |
|
| 390 | + * @param string $target |
|
| 391 | 391 | * @return bool |
| 392 | 392 | */ |
| 393 | 393 | function smart_admin_mkdir($target) |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | |
| 541 | 541 | /** |
| 542 | 542 | * @param $dirname |
| 543 | - * @return bool |
|
| 543 | + * @return boolean|null |
|
| 544 | 544 | */ |
| 545 | 545 | function smart_deleteFile($dirname) |
| 546 | 546 | { |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | /** |
| 740 | - * @param $name |
|
| 740 | + * @param string $name |
|
| 741 | 741 | */ |
| 742 | 742 | function smart_close_collapsable($name) |
| 743 | 743 | { |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
| 750 | - * @param $name |
|
| 750 | + * @param string $name |
|
| 751 | 751 | * @param $value |
| 752 | 752 | * @param int $time |
| 753 | 753 | */ |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
| 764 | - * @param $name |
|
| 764 | + * @param string $name |
|
| 765 | 765 | * @param string $default |
| 766 | 766 | * @return string |
| 767 | 767 | */ |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | /** |
| 897 | - * @param $src |
|
| 897 | + * @param string $src |
|
| 898 | 898 | */ |
| 899 | 899 | function smart_addScript($src) |
| 900 | 900 | { |
@@ -1071,8 +1071,8 @@ discard block |
||
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | /** |
| 1074 | - * @param $module |
|
| 1075 | - * @param $file |
|
| 1074 | + * @param string $module |
|
| 1075 | + * @param string $file |
|
| 1076 | 1076 | */ |
| 1077 | 1077 | function smart_loadLanguageFile($module, $file) |
| 1078 | 1078 | { |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | * This function should be able to cover almost all floats that appear in an european environment. |
| 1189 | 1189 | * @param $str |
| 1190 | 1190 | * @param bool $set |
| 1191 | - * @return float|int |
|
| 1191 | + * @return double |
|
| 1192 | 1192 | */ |
| 1193 | 1193 | function smart_getfloat($str, $set = false) |
| 1194 | 1194 | { |
@@ -1223,7 +1223,7 @@ discard block |
||
| 1223 | 1223 | /** |
| 1224 | 1224 | * @param $var |
| 1225 | 1225 | * @param bool $currencyObj |
| 1226 | - * @return float|int|mixed|string |
|
| 1226 | + * @return string |
|
| 1227 | 1227 | */ |
| 1228 | 1228 | function smart_currency($var, $currencyObj = false) |
| 1229 | 1229 | { |
@@ -1251,7 +1251,7 @@ discard block |
||
| 1251 | 1251 | |
| 1252 | 1252 | /** |
| 1253 | 1253 | * @param $var |
| 1254 | - * @return float|int|mixed|string |
|
| 1254 | + * @return string |
|
| 1255 | 1255 | */ |
| 1256 | 1256 | function smart_float($var) |
| 1257 | 1257 | { |
@@ -1299,7 +1299,7 @@ discard block |
||
| 1299 | 1299 | /** |
| 1300 | 1300 | * @param $moduleName |
| 1301 | 1301 | * @param $items |
| 1302 | - * @return array |
|
| 1302 | + * @return string[] |
|
| 1303 | 1303 | */ |
| 1304 | 1304 | function smart_getTablesArray($moduleName, $items) |
| 1305 | 1305 | { |
@@ -11,9 +11,9 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | function smart_get_css_link($cssfile) |
| 13 | 13 | { |
| 14 | - $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '" />'; |
|
| 14 | + $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '" />'; |
|
| 15 | 15 | |
| 16 | - return $ret; |
|
| 16 | + return $ret; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -21,9 +21,9 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | function smart_get_page_before_form() |
| 23 | 23 | { |
| 24 | - global $smart_previous_page; |
|
| 24 | + global $smart_previous_page; |
|
| 25 | 25 | |
| 26 | - return isset($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page; |
|
| 26 | + return isset($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -34,29 +34,29 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function smart_userIsAdmin($module = false) |
| 36 | 36 | { |
| 37 | - global $xoopsUser; |
|
| 38 | - static $smart_isAdmin; |
|
| 39 | - if (!$module) { |
|
| 40 | - global $xoopsModule; |
|
| 41 | - $module = $xoopsModule->getVar('dirname'); |
|
| 42 | - } |
|
| 43 | - if (isset($smart_isAdmin[$module])) { |
|
| 44 | - return $smart_isAdmin[$module]; |
|
| 45 | - } |
|
| 46 | - if (!$xoopsUser) { |
|
| 47 | - $smart_isAdmin[$module] = false; |
|
| 48 | - |
|
| 49 | - return $smart_isAdmin[$module]; |
|
| 50 | - } |
|
| 51 | - $smart_isAdmin[$module] = false; |
|
| 52 | - $smartModule = smart_getModuleInfo($module); |
|
| 53 | - if (!is_object($smartModule)) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - $module_id = $smartModule->getVar('mid'); |
|
| 57 | - $smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id); |
|
| 58 | - |
|
| 59 | - return $smart_isAdmin[$module]; |
|
| 37 | + global $xoopsUser; |
|
| 38 | + static $smart_isAdmin; |
|
| 39 | + if (!$module) { |
|
| 40 | + global $xoopsModule; |
|
| 41 | + $module = $xoopsModule->getVar('dirname'); |
|
| 42 | + } |
|
| 43 | + if (isset($smart_isAdmin[$module])) { |
|
| 44 | + return $smart_isAdmin[$module]; |
|
| 45 | + } |
|
| 46 | + if (!$xoopsUser) { |
|
| 47 | + $smart_isAdmin[$module] = false; |
|
| 48 | + |
|
| 49 | + return $smart_isAdmin[$module]; |
|
| 50 | + } |
|
| 51 | + $smart_isAdmin[$module] = false; |
|
| 52 | + $smartModule = smart_getModuleInfo($module); |
|
| 53 | + if (!is_object($smartModule)) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + $module_id = $smartModule->getVar('mid'); |
|
| 57 | + $smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id); |
|
| 58 | + |
|
| 59 | + return $smart_isAdmin[$module]; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | function smart_isXoops22() |
| 66 | 66 | { |
| 67 | - $xoops22 = false; |
|
| 68 | - $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
|
| 69 | - if (substr($xv, 2, 1) == '2') { |
|
| 70 | - $xoops22 = true; |
|
| 71 | - } |
|
| 67 | + $xoops22 = false; |
|
| 68 | + $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
|
| 69 | + if (substr($xv, 2, 1) == '2') { |
|
| 70 | + $xoops22 = true; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - return $xoops22; |
|
| 73 | + return $xoops22; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -81,34 +81,34 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function smart_getModuleName($withLink = true, $forBreadCrumb = false, $moduleName = false) |
| 83 | 83 | { |
| 84 | - if (!$moduleName) { |
|
| 85 | - global $xoopsModule; |
|
| 86 | - $moduleName = $xoopsModule->getVar('dirname'); |
|
| 87 | - } |
|
| 88 | - $smartModule = smart_getModuleInfo($moduleName); |
|
| 89 | - $smartModuleConfig = smart_getModuleConfig($moduleName); |
|
| 90 | - if (!isset($smartModule)) { |
|
| 91 | - return ''; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if ($forBreadCrumb && (isset($smartModuleConfig['show_mod_name_breadcrumb']) && !$smartModuleConfig['show_mod_name_breadcrumb'])) { |
|
| 95 | - return ''; |
|
| 96 | - } |
|
| 97 | - if (!$withLink) { |
|
| 98 | - return $smartModule->getVar('name'); |
|
| 99 | - } else { |
|
| 100 | - $seoMode = smart_getModuleModeSEO($moduleName); |
|
| 101 | - if ($seoMode === 'rewrite') { |
|
| 102 | - $seoModuleName = smart_getModuleNameForSEO($moduleName); |
|
| 103 | - $ret = XOOPS_URL . '/' . $seoModuleName . '/'; |
|
| 104 | - } elseif ($seoMode === 'pathinfo') { |
|
| 105 | - $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/'; |
|
| 106 | - } else { |
|
| 107 | - $ret = XOOPS_URL . '/modules/' . $moduleName . '/'; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>'; |
|
| 111 | - } |
|
| 84 | + if (!$moduleName) { |
|
| 85 | + global $xoopsModule; |
|
| 86 | + $moduleName = $xoopsModule->getVar('dirname'); |
|
| 87 | + } |
|
| 88 | + $smartModule = smart_getModuleInfo($moduleName); |
|
| 89 | + $smartModuleConfig = smart_getModuleConfig($moduleName); |
|
| 90 | + if (!isset($smartModule)) { |
|
| 91 | + return ''; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if ($forBreadCrumb && (isset($smartModuleConfig['show_mod_name_breadcrumb']) && !$smartModuleConfig['show_mod_name_breadcrumb'])) { |
|
| 95 | + return ''; |
|
| 96 | + } |
|
| 97 | + if (!$withLink) { |
|
| 98 | + return $smartModule->getVar('name'); |
|
| 99 | + } else { |
|
| 100 | + $seoMode = smart_getModuleModeSEO($moduleName); |
|
| 101 | + if ($seoMode === 'rewrite') { |
|
| 102 | + $seoModuleName = smart_getModuleNameForSEO($moduleName); |
|
| 103 | + $ret = XOOPS_URL . '/' . $seoModuleName . '/'; |
|
| 104 | + } elseif ($seoMode === 'pathinfo') { |
|
| 105 | + $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/'; |
|
| 106 | + } else { |
|
| 107 | + $ret = XOOPS_URL . '/modules/' . $moduleName . '/'; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>'; |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | function smart_getModuleNameForSEO($moduleName = false) |
| 119 | 119 | { |
| 120 | - $smartModule = smart_getModuleInfo($moduleName); |
|
| 121 | - $smartModuleConfig = smart_getModuleConfig($moduleName); |
|
| 122 | - if (isset($smartModuleConfig['seo_module_name'])) { |
|
| 123 | - return $smartModuleConfig['seo_module_name']; |
|
| 124 | - } |
|
| 125 | - $ret = smart_getModuleName(false, false, $moduleName); |
|
| 126 | - |
|
| 127 | - return strtolower($ret); |
|
| 120 | + $smartModule = smart_getModuleInfo($moduleName); |
|
| 121 | + $smartModuleConfig = smart_getModuleConfig($moduleName); |
|
| 122 | + if (isset($smartModuleConfig['seo_module_name'])) { |
|
| 123 | + return $smartModuleConfig['seo_module_name']; |
|
| 124 | + } |
|
| 125 | + $ret = smart_getModuleName(false, false, $moduleName); |
|
| 126 | + |
|
| 127 | + return strtolower($ret); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | function smart_getModuleModeSEO($moduleName = false) |
| 135 | 135 | { |
| 136 | - $smartModule = smart_getModuleInfo($moduleName); |
|
| 137 | - $smartModuleConfig = smart_getModuleConfig($moduleName); |
|
| 136 | + $smartModule = smart_getModuleInfo($moduleName); |
|
| 137 | + $smartModuleConfig = smart_getModuleConfig($moduleName); |
|
| 138 | 138 | |
| 139 | - return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false; |
|
| 139 | + return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -145,10 +145,10 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | function smart_getModuleIncludeIdSEO($moduleName = false) |
| 147 | 147 | { |
| 148 | - $smartModule = smart_getModuleInfo($moduleName); |
|
| 149 | - $smartModuleConfig = smart_getModuleConfig($moduleName); |
|
| 148 | + $smartModule = smart_getModuleInfo($moduleName); |
|
| 149 | + $smartModuleConfig = smart_getModuleConfig($moduleName); |
|
| 150 | 150 | |
| 151 | - return !empty($smartModuleConfig['seo_inc_id']); |
|
| 151 | + return !empty($smartModuleConfig['seo_inc_id']); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -157,26 +157,26 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | function smart_getenv($key) |
| 159 | 159 | { |
| 160 | - $ret = ''; |
|
| 161 | - $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : ''); |
|
| 160 | + $ret = ''; |
|
| 161 | + $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : ''); |
|
| 162 | 162 | |
| 163 | - return $ret; |
|
| 163 | + return $ret; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | function smart_xoops_cp_header() |
| 167 | 167 | { |
| 168 | - xoops_cp_header(); |
|
| 169 | - global $xoopsModule, $xoopsConfig; |
|
| 170 | - /** |
|
| 171 | - * include SmartObject admin language file |
|
| 172 | - */ |
|
| 173 | - $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
| 174 | - if (file_exists($fileName)) { |
|
| 175 | - include_once $fileName; |
|
| 176 | - } else { |
|
| 177 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php'; |
|
| 178 | - } |
|
| 179 | - ?> |
|
| 168 | + xoops_cp_header(); |
|
| 169 | + global $xoopsModule, $xoopsConfig; |
|
| 170 | + /** |
|
| 171 | + * include SmartObject admin language file |
|
| 172 | + */ |
|
| 173 | + $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
| 174 | + if (file_exists($fileName)) { |
|
| 175 | + include_once $fileName; |
|
| 176 | + } else { |
|
| 177 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php'; |
|
| 178 | + } |
|
| 179 | + ?> |
|
| 180 | 180 | <script type='text/javascript'> |
| 181 | 181 | <!-- |
| 182 | 182 | var smart_url = '<?php echo SMARTOBJECT_URL ?>'; |
@@ -189,14 +189,14 @@ discard block |
||
| 189 | 189 | src='<?php echo SMARTOBJECT_URL ?>include/smart.js'></script> |
| 190 | 190 | <?php |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Include the admin language constants for the SmartObject Framework |
|
| 194 | - */ |
|
| 195 | - $admin_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/admin.php'; |
|
| 196 | - if (!file_exists($admin_file)) { |
|
| 197 | - $admin_file = SMARTOBJECT_ROOT_PATH . 'language/english/admin.php'; |
|
| 198 | - } |
|
| 199 | - include_once($admin_file); |
|
| 192 | + /** |
|
| 193 | + * Include the admin language constants for the SmartObject Framework |
|
| 194 | + */ |
|
| 195 | + $admin_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/admin.php'; |
|
| 196 | + if (!file_exists($admin_file)) { |
|
| 197 | + $admin_file = SMARTOBJECT_ROOT_PATH . 'language/english/admin.php'; |
|
| 198 | + } |
|
| 199 | + include_once($admin_file); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -210,21 +210,21 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | function smart_TableExists($table) |
| 212 | 212 | { |
| 213 | - $bRetVal = false; |
|
| 214 | - //Verifies that a MySQL table exists |
|
| 215 | - $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
|
| 216 | - $realname = $xoopsDB->prefix($table); |
|
| 217 | - $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
|
| 218 | - $ret = $xoopsDB->queryF($sql); |
|
| 219 | - while (list($m_table) = $xoopsDB->fetchRow($ret)) { |
|
| 220 | - if ($m_table == $realname) { |
|
| 221 | - $bRetVal = true; |
|
| 222 | - break; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - $xoopsDB->freeRecordSet($ret); |
|
| 226 | - |
|
| 227 | - return $bRetVal; |
|
| 213 | + $bRetVal = false; |
|
| 214 | + //Verifies that a MySQL table exists |
|
| 215 | + $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
|
| 216 | + $realname = $xoopsDB->prefix($table); |
|
| 217 | + $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
|
| 218 | + $ret = $xoopsDB->queryF($sql); |
|
| 219 | + while (list($m_table) = $xoopsDB->fetchRow($ret)) { |
|
| 220 | + if ($m_table == $realname) { |
|
| 221 | + $bRetVal = true; |
|
| 222 | + break; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + $xoopsDB->freeRecordSet($ret); |
|
| 226 | + |
|
| 227 | + return $bRetVal; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -239,19 +239,19 @@ discard block |
||
| 239 | 239 | */ |
| 240 | 240 | function smart_GetMeta($key, $moduleName = false) |
| 241 | 241 | { |
| 242 | - if (!$moduleName) { |
|
| 243 | - $moduleName = smart_getCurrentModuleName(); |
|
| 244 | - } |
|
| 245 | - $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
|
| 246 | - $sql = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key)); |
|
| 247 | - $ret = $xoopsDB->query($sql); |
|
| 248 | - if (!$ret) { |
|
| 249 | - $value = false; |
|
| 250 | - } else { |
|
| 251 | - list($value) = $xoopsDB->fetchRow($ret); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $value; |
|
| 242 | + if (!$moduleName) { |
|
| 243 | + $moduleName = smart_getCurrentModuleName(); |
|
| 244 | + } |
|
| 245 | + $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
|
| 246 | + $sql = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key)); |
|
| 247 | + $ret = $xoopsDB->query($sql); |
|
| 248 | + if (!$ret) { |
|
| 249 | + $value = false; |
|
| 250 | + } else { |
|
| 251 | + list($value) = $xoopsDB->fetchRow($ret); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $value; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -259,12 +259,12 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | function smart_getCurrentModuleName() |
| 261 | 261 | { |
| 262 | - global $xoopsModule; |
|
| 263 | - if (is_object($xoopsModule)) { |
|
| 264 | - return $xoopsModule->getVar('dirname'); |
|
| 265 | - } else { |
|
| 266 | - return false; |
|
| 267 | - } |
|
| 262 | + global $xoopsModule; |
|
| 263 | + if (is_object($xoopsModule)) { |
|
| 264 | + return $xoopsModule->getVar('dirname'); |
|
| 265 | + } else { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -280,22 +280,22 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | function smart_SetMeta($key, $value, $moduleName = false) |
| 282 | 282 | { |
| 283 | - if (!$moduleName) { |
|
| 284 | - $moduleName = smart_getCurrentModuleName(); |
|
| 285 | - } |
|
| 286 | - $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
|
| 287 | - $ret = smart_GetMeta($key, $moduleName); |
|
| 288 | - if ($ret === '0' || $ret > 0) { |
|
| 289 | - $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key)); |
|
| 290 | - } else { |
|
| 291 | - $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value)); |
|
| 292 | - } |
|
| 293 | - $ret = $xoopsDB->queryF($sql); |
|
| 294 | - if (!$ret) { |
|
| 295 | - return false; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return true; |
|
| 283 | + if (!$moduleName) { |
|
| 284 | + $moduleName = smart_getCurrentModuleName(); |
|
| 285 | + } |
|
| 286 | + $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
|
| 287 | + $ret = smart_GetMeta($key, $moduleName); |
|
| 288 | + if ($ret === '0' || $ret > 0) { |
|
| 289 | + $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key)); |
|
| 290 | + } else { |
|
| 291 | + $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value)); |
|
| 292 | + } |
|
| 293 | + $ret = $xoopsDB->queryF($sql); |
|
| 294 | + if (!$ret) { |
|
| 295 | + return false; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return true; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | // Thanks to Mithrandir:-) |
@@ -308,20 +308,20 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | function smart_substr($str, $start, $length, $trimmarker = '...') |
| 310 | 310 | { |
| 311 | - // if the string is empty, let's get out ;-) |
|
| 312 | - if ($str == '') { |
|
| 313 | - return $str; |
|
| 314 | - } |
|
| 315 | - // reverse a string that is shortened with '' as trimmarker |
|
| 316 | - $reversed_string = strrev(xoops_substr($str, $start, $length, '')); |
|
| 317 | - // find first space in reversed string |
|
| 318 | - $position_of_space = strpos($reversed_string, ' ', 0); |
|
| 319 | - // truncate the original string to a length of $length |
|
| 320 | - // minus the position of the last space |
|
| 321 | - // plus the length of the $trimmarker |
|
| 322 | - $truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker); |
|
| 323 | - |
|
| 324 | - return $truncated_string; |
|
| 311 | + // if the string is empty, let's get out ;-) |
|
| 312 | + if ($str == '') { |
|
| 313 | + return $str; |
|
| 314 | + } |
|
| 315 | + // reverse a string that is shortened with '' as trimmarker |
|
| 316 | + $reversed_string = strrev(xoops_substr($str, $start, $length, '')); |
|
| 317 | + // find first space in reversed string |
|
| 318 | + $position_of_space = strpos($reversed_string, ' ', 0); |
|
| 319 | + // truncate the original string to a length of $length |
|
| 320 | + // minus the position of the last space |
|
| 321 | + // plus the length of the $trimmarker |
|
| 322 | + $truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker); |
|
| 323 | + |
|
| 324 | + return $truncated_string; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -332,19 +332,19 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | function smart_getConfig($key, $moduleName = false, $default = 'default_is_undefined') |
| 334 | 334 | { |
| 335 | - if (!$moduleName) { |
|
| 336 | - $moduleName = smart_getCurrentModuleName(); |
|
| 337 | - } |
|
| 338 | - $configs = smart_getModuleConfig($moduleName); |
|
| 339 | - if (isset($configs[$key])) { |
|
| 340 | - return $configs[$key]; |
|
| 341 | - } else { |
|
| 342 | - if ($default === 'default_is_undefined') { |
|
| 343 | - return null; |
|
| 344 | - } else { |
|
| 345 | - return $default; |
|
| 346 | - } |
|
| 347 | - } |
|
| 335 | + if (!$moduleName) { |
|
| 336 | + $moduleName = smart_getCurrentModuleName(); |
|
| 337 | + } |
|
| 338 | + $configs = smart_getModuleConfig($moduleName); |
|
| 339 | + if (isset($configs[$key])) { |
|
| 340 | + return $configs[$key]; |
|
| 341 | + } else { |
|
| 342 | + if ($default === 'default_is_undefined') { |
|
| 343 | + return null; |
|
| 344 | + } else { |
|
| 345 | + return $default; |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -357,32 +357,32 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | function smart_copyr($source, $dest) |
| 359 | 359 | { |
| 360 | - // Simple copy for a file |
|
| 361 | - if (is_file($source)) { |
|
| 362 | - return copy($source, $dest); |
|
| 363 | - } |
|
| 364 | - // Make destination directory |
|
| 365 | - if (!is_dir($dest)) { |
|
| 366 | - mkdir($dest); |
|
| 367 | - } |
|
| 368 | - // Loop through the folder |
|
| 369 | - $dir = dir($source); |
|
| 370 | - while (false !== $entry = $dir->read()) { |
|
| 371 | - // Skip pointers |
|
| 372 | - if ($entry === '.' || $entry === '..') { |
|
| 373 | - continue; |
|
| 374 | - } |
|
| 375 | - // Deep copy directories |
|
| 376 | - if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) { |
|
| 377 | - copyr("$source/$entry", "$dest/$entry"); |
|
| 378 | - } else { |
|
| 379 | - copy("$source/$entry", "$dest/$entry"); |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - // Clean up |
|
| 383 | - $dir->close(); |
|
| 384 | - |
|
| 385 | - return true; |
|
| 360 | + // Simple copy for a file |
|
| 361 | + if (is_file($source)) { |
|
| 362 | + return copy($source, $dest); |
|
| 363 | + } |
|
| 364 | + // Make destination directory |
|
| 365 | + if (!is_dir($dest)) { |
|
| 366 | + mkdir($dest); |
|
| 367 | + } |
|
| 368 | + // Loop through the folder |
|
| 369 | + $dir = dir($source); |
|
| 370 | + while (false !== $entry = $dir->read()) { |
|
| 371 | + // Skip pointers |
|
| 372 | + if ($entry === '.' || $entry === '..') { |
|
| 373 | + continue; |
|
| 374 | + } |
|
| 375 | + // Deep copy directories |
|
| 376 | + if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) { |
|
| 377 | + copyr("$source/$entry", "$dest/$entry"); |
|
| 378 | + } else { |
|
| 379 | + copy("$source/$entry", "$dest/$entry"); |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + // Clean up |
|
| 383 | + $dir->close(); |
|
| 384 | + |
|
| 385 | + return true; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -392,26 +392,26 @@ discard block |
||
| 392 | 392 | */ |
| 393 | 393 | function smart_admin_mkdir($target) |
| 394 | 394 | { |
| 395 | - // http://www.php.net/manual/en/function.mkdir.php |
|
| 396 | - // saint at corenova.com |
|
| 397 | - // bart at cdasites dot com |
|
| 398 | - if (is_dir($target) || empty($target)) { |
|
| 399 | - return true; // best case check first |
|
| 400 | - } |
|
| 401 | - if (file_exists($target) && !is_dir($target)) { |
|
| 402 | - return false; |
|
| 403 | - } |
|
| 404 | - if (smart_admin_mkdir(substr($target, 0, strrpos($target, '/')))) { |
|
| 405 | - if (!file_exists($target)) { |
|
| 406 | - $res = mkdir($target, 0777); // crawl back up & create dir tree |
|
| 407 | - smart_admin_chmod($target); |
|
| 408 | - |
|
| 409 | - return $res; |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - $res = is_dir($target); |
|
| 413 | - |
|
| 414 | - return $res; |
|
| 395 | + // http://www.php.net/manual/en/function.mkdir.php |
|
| 396 | + // saint at corenova.com |
|
| 397 | + // bart at cdasites dot com |
|
| 398 | + if (is_dir($target) || empty($target)) { |
|
| 399 | + return true; // best case check first |
|
| 400 | + } |
|
| 401 | + if (file_exists($target) && !is_dir($target)) { |
|
| 402 | + return false; |
|
| 403 | + } |
|
| 404 | + if (smart_admin_mkdir(substr($target, 0, strrpos($target, '/')))) { |
|
| 405 | + if (!file_exists($target)) { |
|
| 406 | + $res = mkdir($target, 0777); // crawl back up & create dir tree |
|
| 407 | + smart_admin_chmod($target); |
|
| 408 | + |
|
| 409 | + return $res; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + $res = is_dir($target); |
|
| 413 | + |
|
| 414 | + return $res; |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | */ |
| 423 | 423 | function smart_admin_chmod($target, $mode = 0777) |
| 424 | 424 | { |
| 425 | - return @ chmod($target, $mode); |
|
| 425 | + return @ chmod($target, $mode); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -433,31 +433,31 @@ discard block |
||
| 433 | 433 | */ |
| 434 | 434 | function smart_imageResize($src, $maxWidth, $maxHeight) |
| 435 | 435 | { |
| 436 | - $width = ''; |
|
| 437 | - $height = ''; |
|
| 438 | - $type = ''; |
|
| 439 | - $attr = ''; |
|
| 440 | - if (file_exists($src)) { |
|
| 441 | - list($width, $height, $type, $attr) = getimagesize($src); |
|
| 442 | - if ($width > $maxWidth) { |
|
| 443 | - $originalWidth = $width; |
|
| 444 | - $width = $maxWidth; |
|
| 445 | - $height = $width * $height / $originalWidth; |
|
| 446 | - } |
|
| 447 | - if ($height > $maxHeight) { |
|
| 448 | - $originalHeight = $height; |
|
| 449 | - $height = $maxHeight; |
|
| 450 | - $width = $height * $width / $originalHeight; |
|
| 451 | - } |
|
| 452 | - $attr = " width='$width' height='$height'"; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - return array( |
|
| 456 | - $width, |
|
| 457 | - $height, |
|
| 458 | - $type, |
|
| 459 | - $attr |
|
| 460 | - ); |
|
| 436 | + $width = ''; |
|
| 437 | + $height = ''; |
|
| 438 | + $type = ''; |
|
| 439 | + $attr = ''; |
|
| 440 | + if (file_exists($src)) { |
|
| 441 | + list($width, $height, $type, $attr) = getimagesize($src); |
|
| 442 | + if ($width > $maxWidth) { |
|
| 443 | + $originalWidth = $width; |
|
| 444 | + $width = $maxWidth; |
|
| 445 | + $height = $width * $height / $originalWidth; |
|
| 446 | + } |
|
| 447 | + if ($height > $maxHeight) { |
|
| 448 | + $originalHeight = $height; |
|
| 449 | + $height = $maxHeight; |
|
| 450 | + $width = $height * $width / $originalHeight; |
|
| 451 | + } |
|
| 452 | + $attr = " width='$width' height='$height'"; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + return array( |
|
| 456 | + $width, |
|
| 457 | + $height, |
|
| 458 | + $type, |
|
| 459 | + $attr |
|
| 460 | + ); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
@@ -466,34 +466,34 @@ discard block |
||
| 466 | 466 | */ |
| 467 | 467 | function smart_getModuleInfo($moduleName = false) |
| 468 | 468 | { |
| 469 | - static $smartModules; |
|
| 470 | - if (isset($smartModules[$moduleName])) { |
|
| 471 | - $ret =& $smartModules[$moduleName]; |
|
| 472 | - |
|
| 473 | - return $ret; |
|
| 474 | - } |
|
| 475 | - global $xoopsModule; |
|
| 476 | - if (!$moduleName) { |
|
| 477 | - if (isset($xoopsModule) && is_object($xoopsModule)) { |
|
| 478 | - $smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule; |
|
| 479 | - |
|
| 480 | - return $smartModules[$xoopsModule->getVar('dirname')]; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - if (!isset($smartModules[$moduleName])) { |
|
| 484 | - if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
| 485 | - $smartModules[$moduleName] = $xoopsModule; |
|
| 486 | - } else { |
|
| 487 | - $hModule = xoops_getHandler('module'); |
|
| 488 | - if ($moduleName !== 'xoops') { |
|
| 489 | - $smartModules[$moduleName] = $hModule->getByDirname($moduleName); |
|
| 490 | - } else { |
|
| 491 | - $smartModules[$moduleName] = $hModule->getByDirname('system'); |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $smartModules[$moduleName]; |
|
| 469 | + static $smartModules; |
|
| 470 | + if (isset($smartModules[$moduleName])) { |
|
| 471 | + $ret =& $smartModules[$moduleName]; |
|
| 472 | + |
|
| 473 | + return $ret; |
|
| 474 | + } |
|
| 475 | + global $xoopsModule; |
|
| 476 | + if (!$moduleName) { |
|
| 477 | + if (isset($xoopsModule) && is_object($xoopsModule)) { |
|
| 478 | + $smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule; |
|
| 479 | + |
|
| 480 | + return $smartModules[$xoopsModule->getVar('dirname')]; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + if (!isset($smartModules[$moduleName])) { |
|
| 484 | + if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
| 485 | + $smartModules[$moduleName] = $xoopsModule; |
|
| 486 | + } else { |
|
| 487 | + $hModule = xoops_getHandler('module'); |
|
| 488 | + if ($moduleName !== 'xoops') { |
|
| 489 | + $smartModules[$moduleName] = $hModule->getByDirname($moduleName); |
|
| 490 | + } else { |
|
| 491 | + $smartModules[$moduleName] = $hModule->getByDirname('system'); |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $smartModules[$moduleName]; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -502,40 +502,40 @@ discard block |
||
| 502 | 502 | */ |
| 503 | 503 | function smart_getModuleConfig($moduleName = false) |
| 504 | 504 | { |
| 505 | - static $smartConfigs; |
|
| 506 | - if (isset($smartConfigs[$moduleName])) { |
|
| 507 | - $ret =& $smartConfigs[$moduleName]; |
|
| 508 | - |
|
| 509 | - return $ret; |
|
| 510 | - } |
|
| 511 | - global $xoopsModule, $xoopsModuleConfig; |
|
| 512 | - if (!$moduleName) { |
|
| 513 | - if (isset($xoopsModule) && is_object($xoopsModule)) { |
|
| 514 | - $smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig; |
|
| 515 | - |
|
| 516 | - return $smartConfigs[$xoopsModule->getVar('dirname')]; |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - // if we still did not found the xoopsModule, this is because there is none |
|
| 520 | - if (!$moduleName) { |
|
| 521 | - $ret = false; |
|
| 522 | - |
|
| 523 | - return $ret; |
|
| 524 | - } |
|
| 525 | - if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
| 526 | - $smartConfigs[$moduleName] = $xoopsModuleConfig; |
|
| 527 | - } else { |
|
| 528 | - $module = smart_getModuleInfo($moduleName); |
|
| 529 | - if (!is_object($module)) { |
|
| 530 | - $ret = false; |
|
| 531 | - |
|
| 532 | - return $ret; |
|
| 533 | - } |
|
| 534 | - $hModConfig = xoops_getHandler('config'); |
|
| 535 | - $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - return $smartConfigs[$moduleName]; |
|
| 505 | + static $smartConfigs; |
|
| 506 | + if (isset($smartConfigs[$moduleName])) { |
|
| 507 | + $ret =& $smartConfigs[$moduleName]; |
|
| 508 | + |
|
| 509 | + return $ret; |
|
| 510 | + } |
|
| 511 | + global $xoopsModule, $xoopsModuleConfig; |
|
| 512 | + if (!$moduleName) { |
|
| 513 | + if (isset($xoopsModule) && is_object($xoopsModule)) { |
|
| 514 | + $smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig; |
|
| 515 | + |
|
| 516 | + return $smartConfigs[$xoopsModule->getVar('dirname')]; |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + // if we still did not found the xoopsModule, this is because there is none |
|
| 520 | + if (!$moduleName) { |
|
| 521 | + $ret = false; |
|
| 522 | + |
|
| 523 | + return $ret; |
|
| 524 | + } |
|
| 525 | + if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
| 526 | + $smartConfigs[$moduleName] = $xoopsModuleConfig; |
|
| 527 | + } else { |
|
| 528 | + $module = smart_getModuleInfo($moduleName); |
|
| 529 | + if (!is_object($module)) { |
|
| 530 | + $ret = false; |
|
| 531 | + |
|
| 532 | + return $ret; |
|
| 533 | + } |
|
| 534 | + $hModConfig = xoops_getHandler('config'); |
|
| 535 | + $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + return $smartConfigs[$moduleName]; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -544,10 +544,10 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | function smart_deleteFile($dirname) |
| 546 | 546 | { |
| 547 | - // Simple delete for a file |
|
| 548 | - if (is_file($dirname)) { |
|
| 549 | - return unlink($dirname); |
|
| 550 | - } |
|
| 547 | + // Simple delete for a file |
|
| 548 | + if (is_file($dirname)) { |
|
| 549 | + return unlink($dirname); |
|
| 550 | + } |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -556,12 +556,12 @@ discard block |
||
| 556 | 556 | */ |
| 557 | 557 | function smart_formatErrors($errors = array()) |
| 558 | 558 | { |
| 559 | - $ret = ''; |
|
| 560 | - foreach ($errors as $key => $value) { |
|
| 561 | - $ret .= '<br /> - ' . $value; |
|
| 562 | - } |
|
| 559 | + $ret = ''; |
|
| 560 | + foreach ($errors as $key => $value) { |
|
| 561 | + $ret .= '<br /> - ' . $value; |
|
| 562 | + } |
|
| 563 | 563 | |
| 564 | - return $ret; |
|
| 564 | + return $ret; |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -575,46 +575,46 @@ discard block |
||
| 575 | 575 | */ |
| 576 | 576 | function smart_getLinkedUnameFromId($userid = 0, $name = 0, $users = array(), $withContact = false) |
| 577 | 577 | { |
| 578 | - if (!is_numeric($userid)) { |
|
| 579 | - return $userid; |
|
| 580 | - } |
|
| 581 | - $userid = (int)$userid; |
|
| 582 | - if ($userid > 0) { |
|
| 583 | - if ($users == array()) { |
|
| 584 | - //fetching users |
|
| 585 | - $memberHandler = xoops_getHandler('member'); |
|
| 586 | - $user =& $memberHandler->getUser($userid); |
|
| 587 | - } else { |
|
| 588 | - if (!isset($users[$userid])) { |
|
| 589 | - return $GLOBALS['xoopsConfig']['anonymous']; |
|
| 590 | - } |
|
| 591 | - $user =& $users[$userid]; |
|
| 592 | - } |
|
| 593 | - if (is_object($user)) { |
|
| 594 | - $ts = MyTextSanitizer:: getInstance(); |
|
| 595 | - $username = $user->getVar('uname'); |
|
| 596 | - $fullname = ''; |
|
| 597 | - $fullname2 = $user->getVar('name'); |
|
| 598 | - if ($name && !empty($fullname2)) { |
|
| 599 | - $fullname = $user->getVar('name'); |
|
| 600 | - } |
|
| 601 | - if (!empty($fullname)) { |
|
| 602 | - $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]'; |
|
| 603 | - } else { |
|
| 604 | - $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>'; |
|
| 605 | - } |
|
| 606 | - // add contact info: email + PM |
|
| 607 | - if ($withContact) { |
|
| 608 | - $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"/></a>'; |
|
| 609 | - $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);"; |
|
| 610 | - $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"/></a>'; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - return $linkeduser; |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $GLOBALS['xoopsConfig']['anonymous']; |
|
| 578 | + if (!is_numeric($userid)) { |
|
| 579 | + return $userid; |
|
| 580 | + } |
|
| 581 | + $userid = (int)$userid; |
|
| 582 | + if ($userid > 0) { |
|
| 583 | + if ($users == array()) { |
|
| 584 | + //fetching users |
|
| 585 | + $memberHandler = xoops_getHandler('member'); |
|
| 586 | + $user =& $memberHandler->getUser($userid); |
|
| 587 | + } else { |
|
| 588 | + if (!isset($users[$userid])) { |
|
| 589 | + return $GLOBALS['xoopsConfig']['anonymous']; |
|
| 590 | + } |
|
| 591 | + $user =& $users[$userid]; |
|
| 592 | + } |
|
| 593 | + if (is_object($user)) { |
|
| 594 | + $ts = MyTextSanitizer:: getInstance(); |
|
| 595 | + $username = $user->getVar('uname'); |
|
| 596 | + $fullname = ''; |
|
| 597 | + $fullname2 = $user->getVar('name'); |
|
| 598 | + if ($name && !empty($fullname2)) { |
|
| 599 | + $fullname = $user->getVar('name'); |
|
| 600 | + } |
|
| 601 | + if (!empty($fullname)) { |
|
| 602 | + $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]'; |
|
| 603 | + } else { |
|
| 604 | + $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>'; |
|
| 605 | + } |
|
| 606 | + // add contact info: email + PM |
|
| 607 | + if ($withContact) { |
|
| 608 | + $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"/></a>'; |
|
| 609 | + $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);"; |
|
| 610 | + $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"/></a>'; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + return $linkeduser; |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $GLOBALS['xoopsConfig']['anonymous']; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -625,33 +625,33 @@ discard block |
||
| 625 | 625 | */ |
| 626 | 626 | function smart_adminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1) |
| 627 | 627 | { |
| 628 | - global $xoopsModule, $xoopsConfig; |
|
| 629 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 630 | - if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) { |
|
| 631 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
|
| 632 | - } else { |
|
| 633 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
| 634 | - } |
|
| 635 | - if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) { |
|
| 636 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
| 637 | - } else { |
|
| 638 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php'; |
|
| 639 | - } |
|
| 640 | - $headermenu = array(); |
|
| 641 | - $adminmenu = array(); |
|
| 642 | - include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php'; |
|
| 643 | - $tpl = new XoopsTpl(); |
|
| 644 | - $tpl->assign(array( |
|
| 645 | - 'headermenu' => $headermenu, |
|
| 646 | - 'adminmenu' => $adminmenu, |
|
| 647 | - 'current' => $currentoption, |
|
| 648 | - 'breadcrumb' => $breadcrumb, |
|
| 649 | - 'headermenucount' => count($headermenu), |
|
| 650 | - 'submenus' => $submenus, |
|
| 651 | - 'currentsub' => $currentsub, |
|
| 652 | - 'submenuscount' => count($submenus) |
|
| 653 | - )); |
|
| 654 | - $tpl->display('db:smartobject_admin_menu.tpl'); |
|
| 628 | + global $xoopsModule, $xoopsConfig; |
|
| 629 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 630 | + if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) { |
|
| 631 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
|
| 632 | + } else { |
|
| 633 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
| 634 | + } |
|
| 635 | + if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) { |
|
| 636 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
| 637 | + } else { |
|
| 638 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php'; |
|
| 639 | + } |
|
| 640 | + $headermenu = array(); |
|
| 641 | + $adminmenu = array(); |
|
| 642 | + include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php'; |
|
| 643 | + $tpl = new XoopsTpl(); |
|
| 644 | + $tpl->assign(array( |
|
| 645 | + 'headermenu' => $headermenu, |
|
| 646 | + 'adminmenu' => $adminmenu, |
|
| 647 | + 'current' => $currentoption, |
|
| 648 | + 'breadcrumb' => $breadcrumb, |
|
| 649 | + 'headermenucount' => count($headermenu), |
|
| 650 | + 'submenus' => $submenus, |
|
| 651 | + 'currentsub' => $currentsub, |
|
| 652 | + 'submenuscount' => count($submenus) |
|
| 653 | + )); |
|
| 654 | + $tpl->display('db:smartobject_admin_menu.tpl'); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -661,13 +661,13 @@ discard block |
||
| 661 | 661 | */ |
| 662 | 662 | function smart_collapsableBar($id = '', $title = '', $dsc = '') |
| 663 | 663 | { |
| 664 | - global $xoopsModule; |
|
| 665 | - echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>"; |
|
| 666 | - echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a> " . $title . '</h3>'; |
|
| 667 | - echo "<div id='" . $id . "'>"; |
|
| 668 | - if ($dsc != '') { |
|
| 669 | - echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>'; |
|
| 670 | - } |
|
| 664 | + global $xoopsModule; |
|
| 665 | + echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>"; |
|
| 666 | + echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a> " . $title . '</h3>'; |
|
| 667 | + echo "<div id='" . $id . "'>"; |
|
| 668 | + if ($dsc != '') { |
|
| 669 | + echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>'; |
|
| 670 | + } |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
@@ -677,15 +677,15 @@ discard block |
||
| 677 | 677 | */ |
| 678 | 678 | function smart_ajaxCollapsableBar($id = '', $title = '', $dsc = '') |
| 679 | 679 | { |
| 680 | - global $xoopsModule; |
|
| 681 | - $onClick = "ajaxtogglecollapse('$id')"; |
|
| 682 | - //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')"; |
|
| 683 | - echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">'; |
|
| 684 | - echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a> " . $title . '</h3>'; |
|
| 685 | - echo "<div id='" . $id . "'>"; |
|
| 686 | - if ($dsc != '') { |
|
| 687 | - echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>'; |
|
| 688 | - } |
|
| 680 | + global $xoopsModule; |
|
| 681 | + $onClick = "ajaxtogglecollapse('$id')"; |
|
| 682 | + //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')"; |
|
| 683 | + echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">'; |
|
| 684 | + echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a> " . $title . '</h3>'; |
|
| 685 | + echo "<div id='" . $id . "'>"; |
|
| 686 | + if ($dsc != '') { |
|
| 687 | + echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>'; |
|
| 688 | + } |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -712,20 +712,20 @@ discard block |
||
| 712 | 712 | */ |
| 713 | 713 | function smart_openclose_collapsable($name) |
| 714 | 714 | { |
| 715 | - $urls = smart_getCurrentUrls(); |
|
| 716 | - $path = $urls['phpself']; |
|
| 717 | - $cookie_name = $path . '_smart_collaps_' . $name; |
|
| 718 | - $cookie_name = str_replace('.', '_', $cookie_name); |
|
| 719 | - $cookie = smart_getCookieVar($cookie_name, ''); |
|
| 720 | - if ($cookie === 'none') { |
|
| 721 | - echo ' |
|
| 715 | + $urls = smart_getCurrentUrls(); |
|
| 716 | + $path = $urls['phpself']; |
|
| 717 | + $cookie_name = $path . '_smart_collaps_' . $name; |
|
| 718 | + $cookie_name = str_replace('.', '_', $cookie_name); |
|
| 719 | + $cookie = smart_getCookieVar($cookie_name, ''); |
|
| 720 | + if ($cookie === 'none') { |
|
| 721 | + echo ' |
|
| 722 | 722 | <script type="text/javascript"><!-- |
| 723 | 723 | togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon"); |
| 724 | 724 | //--> |
| 725 | 725 | </script> |
| 726 | 726 | '; |
| 727 | - } |
|
| 728 | - /* if ($cookie == 'none') { |
|
| 727 | + } |
|
| 728 | + /* if ($cookie == 'none') { |
|
| 729 | 729 | echo ' |
| 730 | 730 | <script type="text/javascript"><!-- |
| 731 | 731 | hideElement("' . $name . '"); |
@@ -741,9 +741,9 @@ discard block |
||
| 741 | 741 | */ |
| 742 | 742 | function smart_close_collapsable($name) |
| 743 | 743 | { |
| 744 | - echo '</div>'; |
|
| 745 | - smart_openclose_collapsable($name); |
|
| 746 | - echo '<br />'; |
|
| 744 | + echo '</div>'; |
|
| 745 | + smart_openclose_collapsable($name); |
|
| 746 | + echo '<br />'; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -753,11 +753,11 @@ discard block |
||
| 753 | 753 | */ |
| 754 | 754 | function smart_setCookieVar($name, $value, $time = 0) |
| 755 | 755 | { |
| 756 | - if ($time == 0) { |
|
| 757 | - $time = time() + 3600 * 24 * 365; |
|
| 758 | - //$time = ''; |
|
| 759 | - } |
|
| 760 | - setcookie($name, $value, $time, '/'); |
|
| 756 | + if ($time == 0) { |
|
| 757 | + $time = time() + 3600 * 24 * 365; |
|
| 758 | + //$time = ''; |
|
| 759 | + } |
|
| 760 | + setcookie($name, $value, $time, '/'); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -767,12 +767,12 @@ discard block |
||
| 767 | 767 | */ |
| 768 | 768 | function smart_getCookieVar($name, $default = '') |
| 769 | 769 | { |
| 770 | - $name = str_replace('.', '_', $name); |
|
| 771 | - if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
|
| 772 | - return $_COOKIE[$name]; |
|
| 773 | - } else { |
|
| 774 | - return $default; |
|
| 775 | - } |
|
| 770 | + $name = str_replace('.', '_', $name); |
|
| 771 | + if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
|
| 772 | + return $_COOKIE[$name]; |
|
| 773 | + } else { |
|
| 774 | + return $default; |
|
| 775 | + } |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | /** |
@@ -780,25 +780,25 @@ discard block |
||
| 780 | 780 | */ |
| 781 | 781 | function smart_getCurrentUrls() |
| 782 | 782 | { |
| 783 | - $urls = array(); |
|
| 784 | - $http = (strpos(XOOPS_URL, 'https://') === false) ? 'http://' : 'https://'; |
|
| 785 | - $phpself = $_SERVER['PHP_SELF']; |
|
| 786 | - $httphost = $_SERVER['HTTP_HOST']; |
|
| 787 | - $querystring = $_SERVER['QUERY_STRING']; |
|
| 788 | - if ($querystring != '') { |
|
| 789 | - $querystring = '?' . $querystring; |
|
| 790 | - } |
|
| 791 | - $currenturl = $http . $httphost . $phpself . $querystring; |
|
| 792 | - $urls = array(); |
|
| 793 | - $urls['http'] = $http; |
|
| 794 | - $urls['httphost'] = $httphost; |
|
| 795 | - $urls['phpself'] = $phpself; |
|
| 796 | - $urls['querystring'] = $querystring; |
|
| 797 | - $urls['full_phpself'] = $http . $httphost . $phpself; |
|
| 798 | - $urls['full'] = $currenturl; |
|
| 799 | - $urls['isHomePage'] = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself); |
|
| 800 | - |
|
| 801 | - return $urls; |
|
| 783 | + $urls = array(); |
|
| 784 | + $http = (strpos(XOOPS_URL, 'https://') === false) ? 'http://' : 'https://'; |
|
| 785 | + $phpself = $_SERVER['PHP_SELF']; |
|
| 786 | + $httphost = $_SERVER['HTTP_HOST']; |
|
| 787 | + $querystring = $_SERVER['QUERY_STRING']; |
|
| 788 | + if ($querystring != '') { |
|
| 789 | + $querystring = '?' . $querystring; |
|
| 790 | + } |
|
| 791 | + $currenturl = $http . $httphost . $phpself . $querystring; |
|
| 792 | + $urls = array(); |
|
| 793 | + $urls['http'] = $http; |
|
| 794 | + $urls['httphost'] = $httphost; |
|
| 795 | + $urls['phpself'] = $phpself; |
|
| 796 | + $urls['querystring'] = $querystring; |
|
| 797 | + $urls['full_phpself'] = $http . $httphost . $phpself; |
|
| 798 | + $urls['full'] = $currenturl; |
|
| 799 | + $urls['isHomePage'] = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself); |
|
| 800 | + |
|
| 801 | + return $urls; |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
@@ -806,9 +806,9 @@ discard block |
||
| 806 | 806 | */ |
| 807 | 807 | function smart_getCurrentPage() |
| 808 | 808 | { |
| 809 | - $urls = smart_getCurrentUrls(); |
|
| 809 | + $urls = smart_getCurrentUrls(); |
|
| 810 | 810 | |
| 811 | - return $urls['full']; |
|
| 811 | + return $urls['full']; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -855,29 +855,29 @@ discard block |
||
| 855 | 855 | */ |
| 856 | 856 | function smart_modFooter() |
| 857 | 857 | { |
| 858 | - global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
|
| 859 | - |
|
| 860 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 861 | - $tpl = new XoopsTpl(); |
|
| 862 | - |
|
| 863 | - $hModule = xoops_getHandler('module'); |
|
| 864 | - $versioninfo =& $hModule->get($xoopsModule->getVar('mid')); |
|
| 865 | - $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . ''; |
|
| 866 | - $modfooter = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'/></a>"; |
|
| 867 | - $tpl->assign('modfooter', $modfooter); |
|
| 868 | - |
|
| 869 | - if (!defined('_AM_SOBJECT_XOOPS_PRO')) { |
|
| 870 | - define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br />Do you need new features not yet available?'); |
|
| 871 | - } |
|
| 872 | - $smartobjectConfig = smart_getModuleConfig('smartobject'); |
|
| 873 | - $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']); |
|
| 874 | - $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.html'); |
|
| 858 | + global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
|
| 859 | + |
|
| 860 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 861 | + $tpl = new XoopsTpl(); |
|
| 862 | + |
|
| 863 | + $hModule = xoops_getHandler('module'); |
|
| 864 | + $versioninfo =& $hModule->get($xoopsModule->getVar('mid')); |
|
| 865 | + $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . ''; |
|
| 866 | + $modfooter = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'/></a>"; |
|
| 867 | + $tpl->assign('modfooter', $modfooter); |
|
| 868 | + |
|
| 869 | + if (!defined('_AM_SOBJECT_XOOPS_PRO')) { |
|
| 870 | + define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br />Do you need new features not yet available?'); |
|
| 871 | + } |
|
| 872 | + $smartobjectConfig = smart_getModuleConfig('smartobject'); |
|
| 873 | + $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']); |
|
| 874 | + $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.html'); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | function smart_xoops_cp_footer() |
| 878 | 878 | { |
| 879 | - smart_modFooter(); |
|
| 880 | - xoops_cp_footer(); |
|
| 879 | + smart_modFooter(); |
|
| 880 | + xoops_cp_footer(); |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | /** |
@@ -886,11 +886,11 @@ discard block |
||
| 886 | 886 | */ |
| 887 | 887 | function smart_sanitizeForCommonTags($text) |
| 888 | 888 | { |
| 889 | - global $xoopsConfig; |
|
| 890 | - $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text); |
|
| 891 | - $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text); |
|
| 889 | + global $xoopsConfig; |
|
| 890 | + $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text); |
|
| 891 | + $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text); |
|
| 892 | 892 | |
| 893 | - return $text; |
|
| 893 | + return $text; |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | /** |
@@ -898,7 +898,7 @@ discard block |
||
| 898 | 898 | */ |
| 899 | 899 | function smart_addScript($src) |
| 900 | 900 | { |
| 901 | - echo '<script src="' . $src . '" type="text/javascript"></script>'; |
|
| 901 | + echo '<script src="' . $src . '" type="text/javascript"></script>'; |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | /** |
@@ -906,17 +906,17 @@ discard block |
||
| 906 | 906 | */ |
| 907 | 907 | function smart_addStyle($src) |
| 908 | 908 | { |
| 909 | - if ($src === 'smartobject') { |
|
| 910 | - $src = SMARTOBJECT_URL . 'assets/css/module.css'; |
|
| 911 | - } |
|
| 912 | - echo smart_get_css_link($src); |
|
| 909 | + if ($src === 'smartobject') { |
|
| 910 | + $src = SMARTOBJECT_URL . 'assets/css/module.css'; |
|
| 911 | + } |
|
| 912 | + echo smart_get_css_link($src); |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | function smart_addAdminAjaxSupport() |
| 916 | 916 | { |
| 917 | - smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js'); |
|
| 918 | - smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js'); |
|
| 919 | - smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js'); |
|
| 917 | + smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js'); |
|
| 918 | + smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js'); |
|
| 919 | + smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js'); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -925,11 +925,11 @@ discard block |
||
| 925 | 925 | */ |
| 926 | 926 | function smart_sanitizeForSmartpopupLink($text) |
| 927 | 927 | { |
| 928 | - $patterns[] = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU"; |
|
| 929 | - $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>"; |
|
| 930 | - $ret = preg_replace($patterns, $replacements, $text); |
|
| 928 | + $patterns[] = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU"; |
|
| 929 | + $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>"; |
|
| 930 | + $ret = preg_replace($patterns, $replacements, $text); |
|
| 931 | 931 | |
| 932 | - return $ret; |
|
| 932 | + return $ret; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | /** |
@@ -944,25 +944,25 @@ discard block |
||
| 944 | 944 | */ |
| 945 | 945 | function smart_getImageSize($url, & $width, & $height) |
| 946 | 946 | { |
| 947 | - if (empty($width) || empty($height)) { |
|
| 948 | - if (!$dimension = @ getimagesize($url)) { |
|
| 949 | - return false; |
|
| 950 | - } |
|
| 951 | - if (!empty($width)) { |
|
| 952 | - $height = $dimension[1] * $width / $dimension[0]; |
|
| 953 | - } elseif (!empty($height)) { |
|
| 954 | - $width = $dimension[0] * $height / $dimension[1]; |
|
| 955 | - } else { |
|
| 956 | - list($width, $height) = array( |
|
| 957 | - $dimension[0], |
|
| 958 | - $dimension[1] |
|
| 959 | - ); |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - return true; |
|
| 963 | - } else { |
|
| 964 | - return true; |
|
| 965 | - } |
|
| 947 | + if (empty($width) || empty($height)) { |
|
| 948 | + if (!$dimension = @ getimagesize($url)) { |
|
| 949 | + return false; |
|
| 950 | + } |
|
| 951 | + if (!empty($width)) { |
|
| 952 | + $height = $dimension[1] * $width / $dimension[0]; |
|
| 953 | + } elseif (!empty($height)) { |
|
| 954 | + $width = $dimension[0] * $height / $dimension[1]; |
|
| 955 | + } else { |
|
| 956 | + list($width, $height) = array( |
|
| 957 | + $dimension[0], |
|
| 958 | + $dimension[1] |
|
| 959 | + ); |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + return true; |
|
| 963 | + } else { |
|
| 964 | + return true; |
|
| 965 | + } |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | /** |
@@ -975,8 +975,8 @@ discard block |
||
| 975 | 975 | */ |
| 976 | 976 | function smart_htmlnumericentities($str) |
| 977 | 977 | { |
| 978 | - // return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); |
|
| 979 | - return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { return '&#' . ord($m[0]) . chr(59); }, $str); |
|
| 978 | + // return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); |
|
| 979 | + return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { return '&#' . ord($m[0]) . chr(59); }, $str); |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | /** |
@@ -986,24 +986,24 @@ discard block |
||
| 986 | 986 | */ |
| 987 | 987 | function smart_getcorehandler($name, $optional = false) |
| 988 | 988 | { |
| 989 | - static $handlers; |
|
| 990 | - $name = strtolower(trim($name)); |
|
| 991 | - if (!isset($handlers[$name])) { |
|
| 992 | - if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { |
|
| 993 | - require_once $hnd_file; |
|
| 994 | - } |
|
| 995 | - $class = 'Xoops' . ucfirst($name) . 'Handler'; |
|
| 996 | - if (class_exists($class)) { |
|
| 997 | - $handlers[$name] = new $class ($GLOBALS['xoopsDB'], 'xoops'); |
|
| 998 | - } |
|
| 999 | - } |
|
| 1000 | - if (!isset($handlers[$name]) && !$optional) { |
|
| 1001 | - trigger_error('Class <b>' . $class . '</b> does not exist<br />Handler Name: ' . $name, E_USER_ERROR); |
|
| 1002 | - } |
|
| 1003 | - if (isset($handlers[$name])) { |
|
| 1004 | - return $handlers[$name]; |
|
| 1005 | - } |
|
| 1006 | - $inst = false; |
|
| 989 | + static $handlers; |
|
| 990 | + $name = strtolower(trim($name)); |
|
| 991 | + if (!isset($handlers[$name])) { |
|
| 992 | + if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { |
|
| 993 | + require_once $hnd_file; |
|
| 994 | + } |
|
| 995 | + $class = 'Xoops' . ucfirst($name) . 'Handler'; |
|
| 996 | + if (class_exists($class)) { |
|
| 997 | + $handlers[$name] = new $class ($GLOBALS['xoopsDB'], 'xoops'); |
|
| 998 | + } |
|
| 999 | + } |
|
| 1000 | + if (!isset($handlers[$name]) && !$optional) { |
|
| 1001 | + trigger_error('Class <b>' . $class . '</b> does not exist<br />Handler Name: ' . $name, E_USER_ERROR); |
|
| 1002 | + } |
|
| 1003 | + if (isset($handlers[$name])) { |
|
| 1004 | + return $handlers[$name]; |
|
| 1005 | + } |
|
| 1006 | + $inst = false; |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | /** |
@@ -1012,15 +1012,15 @@ discard block |
||
| 1012 | 1012 | */ |
| 1013 | 1013 | function smart_sanitizeAdsenses_callback($matches) |
| 1014 | 1014 | { |
| 1015 | - global $smartobjectAdsenseHandler; |
|
| 1016 | - if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) { |
|
| 1017 | - $adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]]; |
|
| 1018 | - $ret = $adsenseObj->render(); |
|
| 1019 | - |
|
| 1020 | - return $ret; |
|
| 1021 | - } else { |
|
| 1022 | - return ''; |
|
| 1023 | - } |
|
| 1015 | + global $smartobjectAdsenseHandler; |
|
| 1016 | + if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) { |
|
| 1017 | + $adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]]; |
|
| 1018 | + $ret = $adsenseObj->render(); |
|
| 1019 | + |
|
| 1020 | + return $ret; |
|
| 1021 | + } else { |
|
| 1022 | + return ''; |
|
| 1023 | + } |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
@@ -1029,13 +1029,13 @@ discard block |
||
| 1029 | 1029 | */ |
| 1030 | 1030 | function smart_sanitizeAdsenses($text) |
| 1031 | 1031 | { |
| 1032 | - $patterns = array(); |
|
| 1033 | - $replacements = array(); |
|
| 1032 | + $patterns = array(); |
|
| 1033 | + $replacements = array(); |
|
| 1034 | 1034 | |
| 1035 | - $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU"; |
|
| 1036 | - $text = preg_replace_callback($patterns, 'smart_sanitizeAdsenses_callback', $text); |
|
| 1035 | + $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU"; |
|
| 1036 | + $text = preg_replace_callback($patterns, 'smart_sanitizeAdsenses_callback', $text); |
|
| 1037 | 1037 | |
| 1038 | - return $text; |
|
| 1038 | + return $text; |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
@@ -1044,15 +1044,15 @@ discard block |
||
| 1044 | 1044 | */ |
| 1045 | 1045 | function smart_sanitizeCustomtags_callback($matches) |
| 1046 | 1046 | { |
| 1047 | - global $smartobjectCustomtagHandler; |
|
| 1048 | - if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) { |
|
| 1049 | - $customObj = $smartobjectCustomtagHandler->objects[$matches[1]]; |
|
| 1050 | - $ret = $customObj->renderWithPhp(); |
|
| 1051 | - |
|
| 1052 | - return $ret; |
|
| 1053 | - } else { |
|
| 1054 | - return ''; |
|
| 1055 | - } |
|
| 1047 | + global $smartobjectCustomtagHandler; |
|
| 1048 | + if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) { |
|
| 1049 | + $customObj = $smartobjectCustomtagHandler->objects[$matches[1]]; |
|
| 1050 | + $ret = $customObj->renderWithPhp(); |
|
| 1051 | + |
|
| 1052 | + return $ret; |
|
| 1053 | + } else { |
|
| 1054 | + return ''; |
|
| 1055 | + } |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | /** |
@@ -1061,13 +1061,13 @@ discard block |
||
| 1061 | 1061 | */ |
| 1062 | 1062 | function smart_sanitizeCustomtags($text) |
| 1063 | 1063 | { |
| 1064 | - $patterns = array(); |
|
| 1065 | - $replacements = array(); |
|
| 1064 | + $patterns = array(); |
|
| 1065 | + $replacements = array(); |
|
| 1066 | 1066 | |
| 1067 | - $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU"; |
|
| 1068 | - $text = preg_replace_callback($patterns, 'smart_sanitizeCustomtags_callback', $text); |
|
| 1067 | + $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU"; |
|
| 1068 | + $text = preg_replace_callback($patterns, 'smart_sanitizeCustomtags_callback', $text); |
|
| 1069 | 1069 | |
| 1070 | - return $text; |
|
| 1070 | + return $text; |
|
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | /** |
@@ -1076,20 +1076,20 @@ discard block |
||
| 1076 | 1076 | */ |
| 1077 | 1077 | function smart_loadLanguageFile($module, $file) |
| 1078 | 1078 | { |
| 1079 | - global $xoopsConfig; |
|
| 1080 | - |
|
| 1081 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php'; |
|
| 1082 | - if (!file_exists($filename)) { |
|
| 1083 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php'; |
|
| 1084 | - } |
|
| 1085 | - if (file_exists($filename)) { |
|
| 1086 | - include_once($filename); |
|
| 1087 | - } |
|
| 1079 | + global $xoopsConfig; |
|
| 1080 | + |
|
| 1081 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php'; |
|
| 1082 | + if (!file_exists($filename)) { |
|
| 1083 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php'; |
|
| 1084 | + } |
|
| 1085 | + if (file_exists($filename)) { |
|
| 1086 | + include_once($filename); |
|
| 1087 | + } |
|
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | function smart_loadCommonLanguageFile() |
| 1091 | 1091 | { |
| 1092 | - smart_loadLanguageFile('smartobject', 'common'); |
|
| 1092 | + smart_loadLanguageFile('smartobject', 'common'); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1099,35 +1099,35 @@ discard block |
||
| 1099 | 1099 | */ |
| 1100 | 1100 | function smart_purifyText($text, $keyword = false) |
| 1101 | 1101 | { |
| 1102 | - global $myts; |
|
| 1103 | - $text = str_replace(' ', ' ', $text); |
|
| 1104 | - $text = str_replace('<br />', ' ', $text); |
|
| 1105 | - $text = str_replace('<br/>', ' ', $text); |
|
| 1106 | - $text = str_replace('<br', ' ', $text); |
|
| 1107 | - $text = strip_tags($text); |
|
| 1108 | - $text = html_entity_decode($text); |
|
| 1109 | - $text = $myts->undoHtmlSpecialChars($text); |
|
| 1110 | - $text = str_replace(')', ' ', $text); |
|
| 1111 | - $text = str_replace('(', ' ', $text); |
|
| 1112 | - $text = str_replace(':', ' ', $text); |
|
| 1113 | - $text = str_replace('&euro', ' euro ', $text); |
|
| 1114 | - $text = str_replace('&hellip', '...', $text); |
|
| 1115 | - $text = str_replace('&rsquo', ' ', $text); |
|
| 1116 | - $text = str_replace('!', ' ', $text); |
|
| 1117 | - $text = str_replace('?', ' ', $text); |
|
| 1118 | - $text = str_replace('"', ' ', $text); |
|
| 1119 | - $text = str_replace('-', ' ', $text); |
|
| 1120 | - $text = str_replace('\n', ' ', $text); |
|
| 1121 | - $text = str_replace('―', ' ', $text); |
|
| 1122 | - |
|
| 1123 | - if ($keyword) { |
|
| 1124 | - $text = str_replace('.', ' ', $text); |
|
| 1125 | - $text = str_replace(',', ' ', $text); |
|
| 1126 | - $text = str_replace('\'', ' ', $text); |
|
| 1127 | - } |
|
| 1128 | - $text = str_replace(';', ' ', $text); |
|
| 1129 | - |
|
| 1130 | - return $text; |
|
| 1102 | + global $myts; |
|
| 1103 | + $text = str_replace(' ', ' ', $text); |
|
| 1104 | + $text = str_replace('<br />', ' ', $text); |
|
| 1105 | + $text = str_replace('<br/>', ' ', $text); |
|
| 1106 | + $text = str_replace('<br', ' ', $text); |
|
| 1107 | + $text = strip_tags($text); |
|
| 1108 | + $text = html_entity_decode($text); |
|
| 1109 | + $text = $myts->undoHtmlSpecialChars($text); |
|
| 1110 | + $text = str_replace(')', ' ', $text); |
|
| 1111 | + $text = str_replace('(', ' ', $text); |
|
| 1112 | + $text = str_replace(':', ' ', $text); |
|
| 1113 | + $text = str_replace('&euro', ' euro ', $text); |
|
| 1114 | + $text = str_replace('&hellip', '...', $text); |
|
| 1115 | + $text = str_replace('&rsquo', ' ', $text); |
|
| 1116 | + $text = str_replace('!', ' ', $text); |
|
| 1117 | + $text = str_replace('?', ' ', $text); |
|
| 1118 | + $text = str_replace('"', ' ', $text); |
|
| 1119 | + $text = str_replace('-', ' ', $text); |
|
| 1120 | + $text = str_replace('\n', ' ', $text); |
|
| 1121 | + $text = str_replace('―', ' ', $text); |
|
| 1122 | + |
|
| 1123 | + if ($keyword) { |
|
| 1124 | + $text = str_replace('.', ' ', $text); |
|
| 1125 | + $text = str_replace(',', ' ', $text); |
|
| 1126 | + $text = str_replace('\'', ' ', $text); |
|
| 1127 | + } |
|
| 1128 | + $text = str_replace(';', ' ', $text); |
|
| 1129 | + |
|
| 1130 | + return $text; |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | /** |
@@ -1136,49 +1136,49 @@ discard block |
||
| 1136 | 1136 | */ |
| 1137 | 1137 | function smart_html2text($document) |
| 1138 | 1138 | { |
| 1139 | - // PHP Manual:: function preg_replace |
|
| 1140 | - // $document should contain an HTML document. |
|
| 1141 | - // This will remove HTML tags, javascript sections |
|
| 1142 | - // and white space. It will also convert some |
|
| 1143 | - // common HTML entities to their text equivalent. |
|
| 1144 | - // Credits: newbb2 |
|
| 1145 | - $search = array( |
|
| 1146 | - "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
|
| 1147 | - "'<img.*?/>'si", // Strip out img tags |
|
| 1148 | - "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
|
| 1149 | - "'([\r\n])[\s]+'", // Strip out white space |
|
| 1150 | - "'&(quot|#34);'i", // Replace HTML entities |
|
| 1151 | - "'&(amp|#38);'i", |
|
| 1152 | - "'&(lt|#60);'i", |
|
| 1153 | - "'&(gt|#62);'i", |
|
| 1154 | - "'&(nbsp|#160);'i", |
|
| 1155 | - "'&(iexcl|#161);'i", |
|
| 1156 | - "'&(cent|#162);'i", |
|
| 1157 | - "'&(pound|#163);'i", |
|
| 1158 | - "'&(copy|#169);'i", |
|
| 1159 | - "'&#(\d+);'e" |
|
| 1160 | - ); // evaluate as php |
|
| 1161 | - |
|
| 1162 | - $replace = array( |
|
| 1163 | - '', |
|
| 1164 | - '', |
|
| 1165 | - '', |
|
| 1166 | - "\\1", |
|
| 1167 | - "\"", |
|
| 1168 | - '&', |
|
| 1169 | - '<', |
|
| 1170 | - '>', |
|
| 1171 | - ' ', |
|
| 1172 | - chr(161), |
|
| 1173 | - chr(162), |
|
| 1174 | - chr(163), |
|
| 1175 | - chr(169), |
|
| 1176 | - "chr(\\1)" |
|
| 1177 | - ); |
|
| 1178 | - |
|
| 1179 | - $text = preg_replace($search, $replace, $document); |
|
| 1180 | - |
|
| 1181 | - return $text; |
|
| 1139 | + // PHP Manual:: function preg_replace |
|
| 1140 | + // $document should contain an HTML document. |
|
| 1141 | + // This will remove HTML tags, javascript sections |
|
| 1142 | + // and white space. It will also convert some |
|
| 1143 | + // common HTML entities to their text equivalent. |
|
| 1144 | + // Credits: newbb2 |
|
| 1145 | + $search = array( |
|
| 1146 | + "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
|
| 1147 | + "'<img.*?/>'si", // Strip out img tags |
|
| 1148 | + "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
|
| 1149 | + "'([\r\n])[\s]+'", // Strip out white space |
|
| 1150 | + "'&(quot|#34);'i", // Replace HTML entities |
|
| 1151 | + "'&(amp|#38);'i", |
|
| 1152 | + "'&(lt|#60);'i", |
|
| 1153 | + "'&(gt|#62);'i", |
|
| 1154 | + "'&(nbsp|#160);'i", |
|
| 1155 | + "'&(iexcl|#161);'i", |
|
| 1156 | + "'&(cent|#162);'i", |
|
| 1157 | + "'&(pound|#163);'i", |
|
| 1158 | + "'&(copy|#169);'i", |
|
| 1159 | + "'&#(\d+);'e" |
|
| 1160 | + ); // evaluate as php |
|
| 1161 | + |
|
| 1162 | + $replace = array( |
|
| 1163 | + '', |
|
| 1164 | + '', |
|
| 1165 | + '', |
|
| 1166 | + "\\1", |
|
| 1167 | + "\"", |
|
| 1168 | + '&', |
|
| 1169 | + '<', |
|
| 1170 | + '>', |
|
| 1171 | + ' ', |
|
| 1172 | + chr(161), |
|
| 1173 | + chr(162), |
|
| 1174 | + chr(163), |
|
| 1175 | + chr(169), |
|
| 1176 | + "chr(\\1)" |
|
| 1177 | + ); |
|
| 1178 | + |
|
| 1179 | + $text = preg_replace($search, $replace, $document); |
|
| 1180 | + |
|
| 1181 | + return $text; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1192,32 +1192,32 @@ discard block |
||
| 1192 | 1192 | */ |
| 1193 | 1193 | function smart_getfloat($str, $set = false) |
| 1194 | 1194 | { |
| 1195 | - if (preg_match("/([0-9\.,-]+)/", $str, $match)) { |
|
| 1196 | - // Found number in $str, so set $str that number |
|
| 1197 | - $str = $match[0]; |
|
| 1198 | - if (false !== strpos($str, ',')) { |
|
| 1199 | - // A comma exists, that makes it easy, cos we assume it separates the decimal part. |
|
| 1200 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
| 1201 | - $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
| 1202 | - |
|
| 1203 | - return (float)$str; |
|
| 1204 | - } else { |
|
| 1205 | - // No comma exists, so we have to decide, how a single dot shall be treated |
|
| 1206 | - if (preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) == true && $set['single_dot_as_decimal'] == true) { |
|
| 1207 | - // Treat single dot as decimal separator |
|
| 1208 | - return (float)$str; |
|
| 1209 | - } else { |
|
| 1210 | - //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br/><br/> "; |
|
| 1211 | - // Else, treat all dots as thousand seps |
|
| 1212 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
| 1213 | - |
|
| 1214 | - return (float)$str; |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - } else { |
|
| 1218 | - // No number found, return zero |
|
| 1219 | - return 0; |
|
| 1220 | - } |
|
| 1195 | + if (preg_match("/([0-9\.,-]+)/", $str, $match)) { |
|
| 1196 | + // Found number in $str, so set $str that number |
|
| 1197 | + $str = $match[0]; |
|
| 1198 | + if (false !== strpos($str, ',')) { |
|
| 1199 | + // A comma exists, that makes it easy, cos we assume it separates the decimal part. |
|
| 1200 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
| 1201 | + $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
| 1202 | + |
|
| 1203 | + return (float)$str; |
|
| 1204 | + } else { |
|
| 1205 | + // No comma exists, so we have to decide, how a single dot shall be treated |
|
| 1206 | + if (preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) == true && $set['single_dot_as_decimal'] == true) { |
|
| 1207 | + // Treat single dot as decimal separator |
|
| 1208 | + return (float)$str; |
|
| 1209 | + } else { |
|
| 1210 | + //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br/><br/> "; |
|
| 1211 | + // Else, treat all dots as thousand seps |
|
| 1212 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
| 1213 | + |
|
| 1214 | + return (float)$str; |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + } else { |
|
| 1218 | + // No number found, return zero |
|
| 1219 | + return 0; |
|
| 1220 | + } |
|
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | /** |
@@ -1227,26 +1227,26 @@ discard block |
||
| 1227 | 1227 | */ |
| 1228 | 1228 | function smart_currency($var, $currencyObj = false) |
| 1229 | 1229 | { |
| 1230 | - $ret = smart_getfloat($var, array('single_dot_as_decimal' => true)); |
|
| 1231 | - $ret = round($ret, 2); |
|
| 1232 | - // make sur we have at least .00 in the $var |
|
| 1233 | - $decimal_section_original = strstr($ret, '.'); |
|
| 1234 | - $decimal_section = $decimal_section_original; |
|
| 1235 | - if ($decimal_section) { |
|
| 1236 | - if (strlen($decimal_section) == 1) { |
|
| 1237 | - $decimal_section = '.00'; |
|
| 1238 | - } elseif (strlen($decimal_section) == 2) { |
|
| 1239 | - $decimal_section = $decimal_section . '0'; |
|
| 1240 | - } |
|
| 1241 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
| 1242 | - } else { |
|
| 1243 | - $ret = $ret . '.00'; |
|
| 1244 | - } |
|
| 1245 | - if ($currencyObj) { |
|
| 1246 | - $ret = $ret . ' ' . $currencyObj->getCode(); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - return $ret; |
|
| 1230 | + $ret = smart_getfloat($var, array('single_dot_as_decimal' => true)); |
|
| 1231 | + $ret = round($ret, 2); |
|
| 1232 | + // make sur we have at least .00 in the $var |
|
| 1233 | + $decimal_section_original = strstr($ret, '.'); |
|
| 1234 | + $decimal_section = $decimal_section_original; |
|
| 1235 | + if ($decimal_section) { |
|
| 1236 | + if (strlen($decimal_section) == 1) { |
|
| 1237 | + $decimal_section = '.00'; |
|
| 1238 | + } elseif (strlen($decimal_section) == 2) { |
|
| 1239 | + $decimal_section = $decimal_section . '0'; |
|
| 1240 | + } |
|
| 1241 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
| 1242 | + } else { |
|
| 1243 | + $ret = $ret . '.00'; |
|
| 1244 | + } |
|
| 1245 | + if ($currencyObj) { |
|
| 1246 | + $ret = $ret . ' ' . $currencyObj->getCode(); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + return $ret; |
|
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | 1252 | /** |
@@ -1255,7 +1255,7 @@ discard block |
||
| 1255 | 1255 | */ |
| 1256 | 1256 | function smart_float($var) |
| 1257 | 1257 | { |
| 1258 | - return smart_currency($var); |
|
| 1258 | + return smart_currency($var); |
|
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | 1261 | /** |
@@ -1264,16 +1264,16 @@ discard block |
||
| 1264 | 1264 | */ |
| 1265 | 1265 | function smart_getModuleAdminLink($moduleName = false) |
| 1266 | 1266 | { |
| 1267 | - global $xoopsModule; |
|
| 1268 | - if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) { |
|
| 1269 | - $moduleName = $xoopsModule->getVar('dirname'); |
|
| 1270 | - } |
|
| 1271 | - $ret = ''; |
|
| 1272 | - if ($moduleName) { |
|
| 1273 | - $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>'; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - return $ret; |
|
| 1267 | + global $xoopsModule; |
|
| 1268 | + if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) { |
|
| 1269 | + $moduleName = $xoopsModule->getVar('dirname'); |
|
| 1270 | + } |
|
| 1271 | + $ret = ''; |
|
| 1272 | + if ($moduleName) { |
|
| 1273 | + $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>'; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + return $ret; |
|
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | 1279 | /** |
@@ -1281,19 +1281,19 @@ discard block |
||
| 1281 | 1281 | */ |
| 1282 | 1282 | function smart_getEditors() |
| 1283 | 1283 | { |
| 1284 | - $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php'; |
|
| 1285 | - if (!file_exists($filename)) { |
|
| 1286 | - return false; |
|
| 1287 | - } |
|
| 1288 | - include_once $filename; |
|
| 1289 | - $xoopseditorHandler = XoopsEditorHandler::getInstance(); |
|
| 1290 | - $aList = $xoopseditorHandler->getList(); |
|
| 1291 | - $ret = array(); |
|
| 1292 | - foreach ($aList as $k => $v) { |
|
| 1293 | - $ret[$v] = $k; |
|
| 1294 | - } |
|
| 1295 | - |
|
| 1296 | - return $ret; |
|
| 1284 | + $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php'; |
|
| 1285 | + if (!file_exists($filename)) { |
|
| 1286 | + return false; |
|
| 1287 | + } |
|
| 1288 | + include_once $filename; |
|
| 1289 | + $xoopseditorHandler = XoopsEditorHandler::getInstance(); |
|
| 1290 | + $aList = $xoopseditorHandler->getList(); |
|
| 1291 | + $ret = array(); |
|
| 1292 | + foreach ($aList as $k => $v) { |
|
| 1293 | + $ret[$v] = $k; |
|
| 1294 | + } |
|
| 1295 | + |
|
| 1296 | + return $ret; |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | /** |
@@ -1303,11 +1303,11 @@ discard block |
||
| 1303 | 1303 | */ |
| 1304 | 1304 | function smart_getTablesArray($moduleName, $items) |
| 1305 | 1305 | { |
| 1306 | - $ret = array(); |
|
| 1307 | - foreach ($items as $item) { |
|
| 1308 | - $ret[] = $moduleName . '_' . $item; |
|
| 1309 | - } |
|
| 1310 | - $ret[] = $moduleName . '_meta'; |
|
| 1306 | + $ret = array(); |
|
| 1307 | + foreach ($items as $item) { |
|
| 1308 | + $ret[] = $moduleName . '_' . $item; |
|
| 1309 | + } |
|
| 1310 | + $ret[] = $moduleName . '_meta'; |
|
| 1311 | 1311 | |
| 1312 | - return $ret; |
|
| 1312 | + return $ret; |
|
| 1313 | 1313 | } |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | { |
| 469 | 469 | static $smartModules; |
| 470 | 470 | if (isset($smartModules[$moduleName])) { |
| 471 | - $ret =& $smartModules[$moduleName]; |
|
| 471 | + $ret = & $smartModules[$moduleName]; |
|
| 472 | 472 | |
| 473 | 473 | return $ret; |
| 474 | 474 | } |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | { |
| 505 | 505 | static $smartConfigs; |
| 506 | 506 | if (isset($smartConfigs[$moduleName])) { |
| 507 | - $ret =& $smartConfigs[$moduleName]; |
|
| 507 | + $ret = & $smartConfigs[$moduleName]; |
|
| 508 | 508 | |
| 509 | 509 | return $ret; |
| 510 | 510 | } |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | return $ret; |
| 533 | 533 | } |
| 534 | 534 | $hModConfig = xoops_getHandler('config'); |
| 535 | - $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
| 535 | + $smartConfigs[$moduleName] = & $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | return $smartConfigs[$moduleName]; |
@@ -578,17 +578,17 @@ discard block |
||
| 578 | 578 | if (!is_numeric($userid)) { |
| 579 | 579 | return $userid; |
| 580 | 580 | } |
| 581 | - $userid = (int)$userid; |
|
| 581 | + $userid = (int) $userid; |
|
| 582 | 582 | if ($userid > 0) { |
| 583 | 583 | if ($users == array()) { |
| 584 | 584 | //fetching users |
| 585 | 585 | $memberHandler = xoops_getHandler('member'); |
| 586 | - $user =& $memberHandler->getUser($userid); |
|
| 586 | + $user = & $memberHandler->getUser($userid); |
|
| 587 | 587 | } else { |
| 588 | 588 | if (!isset($users[$userid])) { |
| 589 | 589 | return $GLOBALS['xoopsConfig']['anonymous']; |
| 590 | 590 | } |
| 591 | - $user =& $users[$userid]; |
|
| 591 | + $user = & $users[$userid]; |
|
| 592 | 592 | } |
| 593 | 593 | if (is_object($user)) { |
| 594 | 594 | $ts = MyTextSanitizer:: getInstance(); |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | $tpl = new XoopsTpl(); |
| 862 | 862 | |
| 863 | 863 | $hModule = xoops_getHandler('module'); |
| 864 | - $versioninfo =& $hModule->get($xoopsModule->getVar('mid')); |
|
| 864 | + $versioninfo = & $hModule->get($xoopsModule->getVar('mid')); |
|
| 865 | 865 | $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . ''; |
| 866 | 866 | $modfooter = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'/></a>"; |
| 867 | 867 | $tpl->assign('modfooter', $modfooter); |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | function smart_htmlnumericentities($str) |
| 977 | 977 | { |
| 978 | 978 | // return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); |
| 979 | - return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { return '&#' . ord($m[0]) . chr(59); }, $str); |
|
| 979 | + return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function($m) { return '&#' . ord($m[0]) . chr(59); }, $str); |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | /** |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | } |
| 995 | 995 | $class = 'Xoops' . ucfirst($name) . 'Handler'; |
| 996 | 996 | if (class_exists($class)) { |
| 997 | - $handlers[$name] = new $class ($GLOBALS['xoopsDB'], 'xoops'); |
|
| 997 | + $handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops'); |
|
| 998 | 998 | } |
| 999 | 999 | } |
| 1000 | 1000 | if (!isset($handlers[$name]) && !$optional) { |
@@ -1143,11 +1143,11 @@ discard block |
||
| 1143 | 1143 | // common HTML entities to their text equivalent. |
| 1144 | 1144 | // Credits: newbb2 |
| 1145 | 1145 | $search = array( |
| 1146 | - "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
|
| 1147 | - "'<img.*?/>'si", // Strip out img tags |
|
| 1148 | - "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
|
| 1149 | - "'([\r\n])[\s]+'", // Strip out white space |
|
| 1150 | - "'&(quot|#34);'i", // Replace HTML entities |
|
| 1146 | + "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
|
| 1147 | + "'<img.*?/>'si", // Strip out img tags |
|
| 1148 | + "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
|
| 1149 | + "'([\r\n])[\s]+'", // Strip out white space |
|
| 1150 | + "'&(quot|#34);'i", // Replace HTML entities |
|
| 1151 | 1151 | "'&(amp|#38);'i", |
| 1152 | 1152 | "'&(lt|#60);'i", |
| 1153 | 1153 | "'&(gt|#62);'i", |
@@ -1157,7 +1157,7 @@ discard block |
||
| 1157 | 1157 | "'&(pound|#163);'i", |
| 1158 | 1158 | "'&(copy|#169);'i", |
| 1159 | 1159 | "'&#(\d+);'e" |
| 1160 | - ); // evaluate as php |
|
| 1160 | + ); // evaluate as php |
|
| 1161 | 1161 | |
| 1162 | 1162 | $replace = array( |
| 1163 | 1163 | '', |
@@ -1197,21 +1197,21 @@ discard block |
||
| 1197 | 1197 | $str = $match[0]; |
| 1198 | 1198 | if (false !== strpos($str, ',')) { |
| 1199 | 1199 | // A comma exists, that makes it easy, cos we assume it separates the decimal part. |
| 1200 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
| 1201 | - $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
| 1200 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
| 1201 | + $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
| 1202 | 1202 | |
| 1203 | - return (float)$str; |
|
| 1203 | + return (float) $str; |
|
| 1204 | 1204 | } else { |
| 1205 | 1205 | // No comma exists, so we have to decide, how a single dot shall be treated |
| 1206 | 1206 | if (preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) == true && $set['single_dot_as_decimal'] == true) { |
| 1207 | 1207 | // Treat single dot as decimal separator |
| 1208 | - return (float)$str; |
|
| 1208 | + return (float) $str; |
|
| 1209 | 1209 | } else { |
| 1210 | 1210 | //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br/><br/> "; |
| 1211 | 1211 | // Else, treat all dots as thousand seps |
| 1212 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
| 1212 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
| 1213 | 1213 | |
| 1214 | - return (float)$str; |
|
| 1214 | + return (float) $str; |
|
| 1215 | 1215 | } |
| 1216 | 1216 | } |
| 1217 | 1217 | } else { |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @param $javascript |
| 30 | - * @return mixed|string |
|
| 30 | + * @return string |
|
| 31 | 31 | */ |
| 32 | 32 | public function escape($javascript) |
| 33 | 33 | { |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @param $name |
| 51 | - * @param $function |
|
| 51 | + * @param string $function |
|
| 52 | 52 | * @param null $html_options |
| 53 | 53 | * @return string |
| 54 | 54 | */ |
@@ -15,90 +15,90 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class JavaScript |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param $name |
|
| 20 | - * @param null $function |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function button_to_function($name, $function = null) |
|
| 24 | - { |
|
| 25 | - return '<input type="button" value="' . $name . '" onclick="' . $function . '" />'; |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * @param $name |
|
| 20 | + * @param null $function |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function button_to_function($name, $function = null) |
|
| 24 | + { |
|
| 25 | + return '<input type="button" value="' . $name . '" onclick="' . $function . '" />'; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param $javascript |
|
| 30 | - * @return mixed|string |
|
| 31 | - */ |
|
| 32 | - public function escape($javascript) |
|
| 33 | - { |
|
| 34 | - $javascript = addslashes($javascript); |
|
| 35 | - $javascript = str_replace(array("\r\n", "\n", "\r"), array("\n"), $javascript); |
|
| 28 | + /** |
|
| 29 | + * @param $javascript |
|
| 30 | + * @return mixed|string |
|
| 31 | + */ |
|
| 32 | + public function escape($javascript) |
|
| 33 | + { |
|
| 34 | + $javascript = addslashes($javascript); |
|
| 35 | + $javascript = str_replace(array("\r\n", "\n", "\r"), array("\n"), $javascript); |
|
| 36 | 36 | |
| 37 | - return $javascript; |
|
| 38 | - } |
|
| 37 | + return $javascript; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param $content |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function tag($content) |
|
| 45 | - { |
|
| 46 | - return '<script type="text/javascript">' . $content . '</script>'; |
|
| 47 | - } |
|
| 40 | + /** |
|
| 41 | + * @param $content |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function tag($content) |
|
| 45 | + { |
|
| 46 | + return '<script type="text/javascript">' . $content . '</script>'; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param $name |
|
| 51 | - * @param $function |
|
| 52 | - * @param null $html_options |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - public function link_to_function($name, $function, $html_options = null) |
|
| 56 | - { |
|
| 57 | - return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;" />' . $name . '</a>'; |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * @param $name |
|
| 51 | + * @param $function |
|
| 52 | + * @param null $html_options |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + public function link_to_function($name, $function, $html_options = null) |
|
| 56 | + { |
|
| 57 | + return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;" />' . $name . '</a>'; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 61 | - // Private functions |
|
| 62 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 60 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 61 | + // Private functions |
|
| 62 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param $option |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function _array_or_string_for_javascript($option) |
|
| 69 | - { |
|
| 70 | - $return_val = ''; |
|
| 71 | - if (is_array($option)) { |
|
| 72 | - foreach ($option as $value) { |
|
| 73 | - if (!empty($return_val)) { |
|
| 74 | - $ret_val .= ', '; |
|
| 75 | - } |
|
| 76 | - $return_val .= $value; |
|
| 77 | - } |
|
| 64 | + /** |
|
| 65 | + * @param $option |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function _array_or_string_for_javascript($option) |
|
| 69 | + { |
|
| 70 | + $return_val = ''; |
|
| 71 | + if (is_array($option)) { |
|
| 72 | + foreach ($option as $value) { |
|
| 73 | + if (!empty($return_val)) { |
|
| 74 | + $ret_val .= ', '; |
|
| 75 | + } |
|
| 76 | + $return_val .= $value; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return '[' . $return_val . ']'; |
|
| 80 | - } |
|
| 79 | + return '[' . $return_val . ']'; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - return "'$option'"; |
|
| 83 | - } |
|
| 82 | + return "'$option'"; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param $options |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function _options_for_javascript($options) |
|
| 90 | - { |
|
| 91 | - $return_val = ''; |
|
| 85 | + /** |
|
| 86 | + * @param $options |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function _options_for_javascript($options) |
|
| 90 | + { |
|
| 91 | + $return_val = ''; |
|
| 92 | 92 | |
| 93 | - if (is_array($options)) { |
|
| 94 | - foreach ($options as $var => $val) { |
|
| 95 | - if (!empty($return_val)) { |
|
| 96 | - $return_val .= ', '; |
|
| 97 | - } |
|
| 98 | - $return_val .= "$var:$val"; |
|
| 99 | - } |
|
| 100 | - } |
|
| 93 | + if (is_array($options)) { |
|
| 94 | + foreach ($options as $var => $val) { |
|
| 95 | + if (!empty($return_val)) { |
|
| 96 | + $return_val .= ', '; |
|
| 97 | + } |
|
| 98 | + $return_val .= "$var:$val"; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return '{' . $return_val . '}'; |
|
| 103 | - } |
|
| 102 | + return '{' . $return_val . '}'; |
|
| 103 | + } |
|
| 104 | 104 | } |