@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
| 20 | 20 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
| 21 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 21 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 22 | 22 | } |
| 23 | 23 | /** |
| 24 | 24 | * Include the language constants for the SmartObjectDBUpdater |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | global $xoopsConfig; |
| 27 | 27 | $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
| 28 | 28 | if (!file_exists($common_file)) { |
| 29 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 29 | + $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 30 | 30 | } |
| 31 | 31 | include $common_file; |
| 32 | 32 | |
@@ -35,503 +35,503 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class SmartDbTable |
| 37 | 37 | { |
| 38 | - /** |
|
| 39 | - * @var string $_name name of the table |
|
| 40 | - */ |
|
| 41 | - public $_name; |
|
| 42 | - /** |
|
| 43 | - * @var string $_structure structure of the table |
|
| 44 | - */ |
|
| 45 | - public $_structure; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var array $_data containing valued of each records to be added |
|
| 49 | - */ |
|
| 50 | - public $_data; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var array $_alteredFields containing fields to be altered |
|
| 54 | - */ |
|
| 55 | - public $_alteredFields; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var array $_newFields containing new fields to be added |
|
| 59 | - */ |
|
| 60 | - public $_newFields; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var array $_droppedFields containing fields to be dropped |
|
| 64 | - */ |
|
| 65 | - public $_droppedFields; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var array $_flagForDrop flag table to drop it |
|
| 69 | - */ |
|
| 70 | - public $_flagForDrop = false; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var array $_updatedFields containing fields which values will be updated |
|
| 74 | - */ |
|
| 75 | - public $_updatedFields; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var array $_updatedFields containing fields which values will be updated |
|
| 79 | - */ //felix |
|
| 80 | - public $_updatedWhere; |
|
| 81 | - |
|
| 82 | - public $_existingFieldsArray = false; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Constructor |
|
| 86 | - * |
|
| 87 | - * @param string $name name of the table |
|
| 88 | - * |
|
| 89 | - */ |
|
| 90 | - public function __construct($name) |
|
| 91 | - { |
|
| 92 | - $this->_name = $name; |
|
| 93 | - $this->_data = array(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Return the table name, prefixed with site table prefix |
|
| 98 | - * |
|
| 99 | - * @return string table name |
|
| 100 | - * |
|
| 101 | - */ |
|
| 102 | - public function name() |
|
| 103 | - { |
|
| 104 | - global $xoopsDB; |
|
| 105 | - |
|
| 106 | - return $xoopsDB->prefix($this->_name); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Checks if the table already exists in the database |
|
| 111 | - * |
|
| 112 | - * @return bool TRUE if it exists, FALSE if not |
|
| 113 | - * |
|
| 114 | - */ |
|
| 115 | - public function exists() |
|
| 116 | - { |
|
| 117 | - return smart_TableExists($this->_name); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return mixed |
|
| 122 | - */ |
|
| 123 | - public function getExistingFieldsArray() |
|
| 124 | - { |
|
| 125 | - global $xoopsDB; |
|
| 126 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 127 | - while ($existing_field = $xoopsDB->fetchArray($result)) { |
|
| 128 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 129 | - if ($existing_field['Null'] !== 'YES') { |
|
| 130 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 131 | - } |
|
| 132 | - if ($existing_field['Extra']) { |
|
| 133 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 134 | - } |
|
| 135 | - if (!($existing_field['Default'] === null) |
|
| 136 | - && ($existing_field['Default'] |
|
| 137 | - || $existing_field['Default'] === '' |
|
| 138 | - || $existing_field['Default'] == 0)) { |
|
| 139 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $fields; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param $field |
|
| 148 | - * @return bool |
|
| 149 | - */ |
|
| 150 | - public function fieldExists($field) |
|
| 151 | - { |
|
| 152 | - $existingFields = $this->getExistingFieldsArray(); |
|
| 153 | - |
|
| 154 | - return isset($existingFields[$field]); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Set the table structure |
|
| 159 | - * |
|
| 160 | - * Example: |
|
| 161 | - * |
|
| 162 | - * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
| 163 | - * `date` int(11) NOT NULL default '0', |
|
| 164 | - * `status` int(1) NOT NULL default '-1', |
|
| 165 | - * `itemid` int(11) NOT NULL default '0', |
|
| 166 | - * `uid` int(11) NOT NULL default '0', |
|
| 167 | - * `price` float NOT NULL default '0', |
|
| 168 | - * `currency` varchar(100) NOT NULL default '', |
|
| 169 | - * PRIMARY KEY (`transactionid`)"); |
|
| 170 | - * |
|
| 171 | - * @param string $structure table structure |
|
| 172 | - * |
|
| 173 | - */ |
|
| 174 | - public function setStructure($structure) |
|
| 175 | - { |
|
| 176 | - $this->_structure = $structure; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Return the table structure |
|
| 181 | - * |
|
| 182 | - * @return string table structure |
|
| 183 | - * |
|
| 184 | - */ |
|
| 185 | - public function getStructure() |
|
| 186 | - { |
|
| 187 | - return sprintf($this->_structure, $this->name()); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Add values of a record to be added |
|
| 192 | - * |
|
| 193 | - * @param string $data values of a record |
|
| 194 | - * |
|
| 195 | - */ |
|
| 196 | - public function setData($data) |
|
| 197 | - { |
|
| 198 | - $this->_data[] = $data; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Get the data array |
|
| 203 | - * |
|
| 204 | - * @return array containing the records values to be added |
|
| 205 | - * |
|
| 206 | - */ |
|
| 207 | - public function getData() |
|
| 208 | - { |
|
| 209 | - return $this->_data; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Use to insert data in a table |
|
| 214 | - * |
|
| 215 | - * @return bool true if success, false if an error occured |
|
| 216 | - * |
|
| 217 | - */ |
|
| 218 | - public function addData() |
|
| 219 | - { |
|
| 220 | - global $xoopsDB; |
|
| 221 | - foreach ($this->getData() as $data) { |
|
| 222 | - $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
| 223 | - $ret = $xoopsDB->query($query); |
|
| 224 | - if (!$ret) { |
|
| 225 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 226 | - } else { |
|
| 227 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - return $ret; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Add a field to be added |
|
| 236 | - * |
|
| 237 | - * @param string $name name of the field |
|
| 238 | - * @param string $properties properties of the field |
|
| 239 | - * @param bool $newname |
|
| 240 | - * @param bool $showerror |
|
| 241 | - */ |
|
| 242 | - public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
| 243 | - { |
|
| 244 | - $field['name'] = $name; |
|
| 245 | - $field['properties'] = $properties; |
|
| 246 | - $field['showerror'] = $showerror; |
|
| 247 | - $field['newname'] = $newname; |
|
| 248 | - $this->_alteredFields[] = $field; |
|
| 249 | - } |
|
| 250 | - /** |
|
| 251 | - * Invert values 0 to 1 and 1 to 0 |
|
| 252 | - * |
|
| 253 | - * @param string $name name of the field |
|
| 254 | - * @param $newValue |
|
| 255 | - * @param $oldValue |
|
| 256 | - * @internal param string $old old propertie |
|
| 257 | - * @internal param string $new new propertie |
|
| 258 | - */ //felix |
|
| 259 | - public function addUpdatedWhere($name, $newValue, $oldValue) |
|
| 260 | - { |
|
| 261 | - $field['name'] = $name; |
|
| 262 | - $field['value'] = $newValue; |
|
| 263 | - $field['where'] = $oldValue; |
|
| 264 | - $this->_updatedWhere[] = $field; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Add new field of a record to be added |
|
| 269 | - * |
|
| 270 | - * @param string $name name of the field |
|
| 271 | - * @param string $properties properties of the field |
|
| 272 | - * |
|
| 273 | - */ |
|
| 274 | - public function addNewField($name, $properties) |
|
| 275 | - { |
|
| 276 | - $field['name'] = $name; |
|
| 277 | - $field['properties'] = $properties; |
|
| 278 | - $this->_newFields[] = $field; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Get fields that need to be altered |
|
| 283 | - * |
|
| 284 | - * @return array fields that need to be altered |
|
| 285 | - * |
|
| 286 | - */ |
|
| 287 | - public function getAlteredFields() |
|
| 288 | - { |
|
| 289 | - return $this->_alteredFields; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Add field for which the value will be updated |
|
| 294 | - * |
|
| 295 | - * @param string $name name of the field |
|
| 296 | - * @param string $value value to be set |
|
| 297 | - * |
|
| 298 | - */ |
|
| 299 | - public function addUpdatedField($name, $value) |
|
| 300 | - { |
|
| 301 | - $field['name'] = $name; |
|
| 302 | - $field['value'] = $value; |
|
| 303 | - $this->_updatedFields[] = $field; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Get new fields to be added |
|
| 308 | - * |
|
| 309 | - * @return array fields to be added |
|
| 310 | - * |
|
| 311 | - */ |
|
| 312 | - public function getNewFields() |
|
| 313 | - { |
|
| 314 | - return $this->_newFields; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Get fields which values need to be updated |
|
| 319 | - * |
|
| 320 | - * @return array fields which values need to be updated |
|
| 321 | - * |
|
| 322 | - */ |
|
| 323 | - public function getUpdatedFields() |
|
| 324 | - { |
|
| 325 | - return $this->_updatedFields; |
|
| 326 | - } |
|
| 327 | - /** |
|
| 328 | - * Get fields which values need to be updated |
|
| 329 | - * |
|
| 330 | - * @return array fields which values need to be updated |
|
| 331 | - * |
|
| 332 | - */ //felix |
|
| 333 | - public function getUpdatedWhere() |
|
| 334 | - { |
|
| 335 | - return $this->_updatedWhere; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Add values of a record to be added |
|
| 340 | - * |
|
| 341 | - * @param string $name name of the field |
|
| 342 | - * |
|
| 343 | - */ |
|
| 344 | - public function addDroppedField($name) |
|
| 345 | - { |
|
| 346 | - $this->_droppedFields[] = $name; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Get fields that need to be dropped |
|
| 351 | - * |
|
| 352 | - * @return array fields that need to be dropped |
|
| 353 | - * |
|
| 354 | - */ |
|
| 355 | - public function getDroppedFields() |
|
| 356 | - { |
|
| 357 | - return $this->_droppedFields; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Set the flag to drop the table |
|
| 362 | - * |
|
| 363 | - */ |
|
| 364 | - public function setFlagForDrop() |
|
| 365 | - { |
|
| 366 | - $this->_flagForDrop = true; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Use to create a table |
|
| 371 | - * |
|
| 372 | - * @return bool true if success, false if an error occured |
|
| 373 | - * |
|
| 374 | - */ |
|
| 375 | - public function createTable() |
|
| 376 | - { |
|
| 377 | - global $xoopsDB; |
|
| 378 | - $query = $this->getStructure(); |
|
| 379 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 380 | - //xoops_debug($query); |
|
| 381 | - $ret = $xoopsDB->query($query); |
|
| 382 | - if (!$ret) { |
|
| 383 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 384 | - } else { |
|
| 385 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - return $ret; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Use to drop a table |
|
| 393 | - * |
|
| 394 | - * @return bool true if success, false if an error occured |
|
| 395 | - * |
|
| 396 | - */ |
|
| 397 | - public function dropTable() |
|
| 398 | - { |
|
| 399 | - global $xoopsDB; |
|
| 400 | - $query = sprintf('DROP TABLE %s', $this->name()); |
|
| 401 | - $ret = $xoopsDB->query($query); |
|
| 402 | - if (!$ret) { |
|
| 403 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 404 | - |
|
| 405 | - return false; |
|
| 406 | - } else { |
|
| 407 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 408 | - |
|
| 409 | - return true; |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Use to alter a table |
|
| 415 | - * |
|
| 416 | - * @return bool true if success, false if an error occured |
|
| 417 | - * |
|
| 418 | - */ |
|
| 419 | - public function alterTable() |
|
| 420 | - { |
|
| 421 | - global $xoopsDB; |
|
| 422 | - $ret = true; |
|
| 423 | - |
|
| 424 | - foreach ($this->getAlteredFields() as $alteredField) { |
|
| 425 | - if (!$alteredField['newname']) { |
|
| 426 | - $alteredField['newname'] = $alteredField['name']; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
| 430 | - $ret = $ret && $xoopsDB->query($query); |
|
| 431 | - if ($alteredField['showerror']) { |
|
| 432 | - if (!$ret) { |
|
| 433 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 434 | - } else { |
|
| 435 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - return $ret; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Use to add new fileds in the table |
|
| 445 | - * |
|
| 446 | - * @return bool true if success, false if an error occured |
|
| 447 | - * |
|
| 448 | - */ |
|
| 449 | - public function addNewFields() |
|
| 450 | - { |
|
| 451 | - global $xoopsDB; |
|
| 452 | - $ret = true; |
|
| 453 | - foreach ($this->getNewFields() as $newField) { |
|
| 454 | - $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
| 455 | - //echo $query; |
|
| 456 | - $ret = $ret && $xoopsDB->query($query); |
|
| 457 | - if (!$ret) { |
|
| 458 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 459 | - } else { |
|
| 460 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return $ret; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Use to update fields values |
|
| 469 | - * |
|
| 470 | - * @return bool true if success, false if an error occured |
|
| 471 | - * |
|
| 472 | - */ |
|
| 473 | - public function updateFieldsValues() |
|
| 474 | - { |
|
| 475 | - global $xoopsDB; |
|
| 476 | - $ret = true; |
|
| 477 | - foreach ($this->getUpdatedFields() as $updatedField) { |
|
| 478 | - $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
| 479 | - $ret = $ret && $xoopsDB->query($query); |
|
| 480 | - if (!$ret) { |
|
| 481 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 482 | - } else { |
|
| 483 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $ret; |
|
| 488 | - } |
|
| 489 | - /** |
|
| 490 | - * Use to update fields values |
|
| 491 | - * |
|
| 492 | - * @return bool true if success, false if an error occured |
|
| 493 | - * |
|
| 494 | - */ //felix |
|
| 495 | - public function updateWhereValues() |
|
| 496 | - { |
|
| 497 | - global $xoopsDB; |
|
| 498 | - $ret = true; |
|
| 499 | - foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
| 500 | - $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
| 501 | - //echo $query."<br>"; |
|
| 502 | - $ret = $ret && $xoopsDB->query($query); |
|
| 503 | - if (!$ret) { |
|
| 504 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 505 | - } else { |
|
| 506 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - return $ret; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Use to drop fields |
|
| 515 | - * |
|
| 516 | - * @return bool true if success, false if an error occured |
|
| 517 | - * |
|
| 518 | - */ |
|
| 519 | - public function dropFields() |
|
| 520 | - { |
|
| 521 | - global $xoopsDB; |
|
| 522 | - $ret = true; |
|
| 523 | - foreach ($this->getDroppedFields() as $droppedField) { |
|
| 524 | - $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
| 525 | - $ret = $ret && $xoopsDB->query($query); |
|
| 526 | - if (!$ret) { |
|
| 527 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 528 | - } else { |
|
| 529 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - return $ret; |
|
| 534 | - } |
|
| 38 | + /** |
|
| 39 | + * @var string $_name name of the table |
|
| 40 | + */ |
|
| 41 | + public $_name; |
|
| 42 | + /** |
|
| 43 | + * @var string $_structure structure of the table |
|
| 44 | + */ |
|
| 45 | + public $_structure; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var array $_data containing valued of each records to be added |
|
| 49 | + */ |
|
| 50 | + public $_data; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var array $_alteredFields containing fields to be altered |
|
| 54 | + */ |
|
| 55 | + public $_alteredFields; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var array $_newFields containing new fields to be added |
|
| 59 | + */ |
|
| 60 | + public $_newFields; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var array $_droppedFields containing fields to be dropped |
|
| 64 | + */ |
|
| 65 | + public $_droppedFields; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var array $_flagForDrop flag table to drop it |
|
| 69 | + */ |
|
| 70 | + public $_flagForDrop = false; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var array $_updatedFields containing fields which values will be updated |
|
| 74 | + */ |
|
| 75 | + public $_updatedFields; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var array $_updatedFields containing fields which values will be updated |
|
| 79 | + */ //felix |
|
| 80 | + public $_updatedWhere; |
|
| 81 | + |
|
| 82 | + public $_existingFieldsArray = false; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Constructor |
|
| 86 | + * |
|
| 87 | + * @param string $name name of the table |
|
| 88 | + * |
|
| 89 | + */ |
|
| 90 | + public function __construct($name) |
|
| 91 | + { |
|
| 92 | + $this->_name = $name; |
|
| 93 | + $this->_data = array(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Return the table name, prefixed with site table prefix |
|
| 98 | + * |
|
| 99 | + * @return string table name |
|
| 100 | + * |
|
| 101 | + */ |
|
| 102 | + public function name() |
|
| 103 | + { |
|
| 104 | + global $xoopsDB; |
|
| 105 | + |
|
| 106 | + return $xoopsDB->prefix($this->_name); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Checks if the table already exists in the database |
|
| 111 | + * |
|
| 112 | + * @return bool TRUE if it exists, FALSE if not |
|
| 113 | + * |
|
| 114 | + */ |
|
| 115 | + public function exists() |
|
| 116 | + { |
|
| 117 | + return smart_TableExists($this->_name); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return mixed |
|
| 122 | + */ |
|
| 123 | + public function getExistingFieldsArray() |
|
| 124 | + { |
|
| 125 | + global $xoopsDB; |
|
| 126 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 127 | + while ($existing_field = $xoopsDB->fetchArray($result)) { |
|
| 128 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 129 | + if ($existing_field['Null'] !== 'YES') { |
|
| 130 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 131 | + } |
|
| 132 | + if ($existing_field['Extra']) { |
|
| 133 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 134 | + } |
|
| 135 | + if (!($existing_field['Default'] === null) |
|
| 136 | + && ($existing_field['Default'] |
|
| 137 | + || $existing_field['Default'] === '' |
|
| 138 | + || $existing_field['Default'] == 0)) { |
|
| 139 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $fields; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param $field |
|
| 148 | + * @return bool |
|
| 149 | + */ |
|
| 150 | + public function fieldExists($field) |
|
| 151 | + { |
|
| 152 | + $existingFields = $this->getExistingFieldsArray(); |
|
| 153 | + |
|
| 154 | + return isset($existingFields[$field]); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Set the table structure |
|
| 159 | + * |
|
| 160 | + * Example: |
|
| 161 | + * |
|
| 162 | + * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
| 163 | + * `date` int(11) NOT NULL default '0', |
|
| 164 | + * `status` int(1) NOT NULL default '-1', |
|
| 165 | + * `itemid` int(11) NOT NULL default '0', |
|
| 166 | + * `uid` int(11) NOT NULL default '0', |
|
| 167 | + * `price` float NOT NULL default '0', |
|
| 168 | + * `currency` varchar(100) NOT NULL default '', |
|
| 169 | + * PRIMARY KEY (`transactionid`)"); |
|
| 170 | + * |
|
| 171 | + * @param string $structure table structure |
|
| 172 | + * |
|
| 173 | + */ |
|
| 174 | + public function setStructure($structure) |
|
| 175 | + { |
|
| 176 | + $this->_structure = $structure; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Return the table structure |
|
| 181 | + * |
|
| 182 | + * @return string table structure |
|
| 183 | + * |
|
| 184 | + */ |
|
| 185 | + public function getStructure() |
|
| 186 | + { |
|
| 187 | + return sprintf($this->_structure, $this->name()); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Add values of a record to be added |
|
| 192 | + * |
|
| 193 | + * @param string $data values of a record |
|
| 194 | + * |
|
| 195 | + */ |
|
| 196 | + public function setData($data) |
|
| 197 | + { |
|
| 198 | + $this->_data[] = $data; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Get the data array |
|
| 203 | + * |
|
| 204 | + * @return array containing the records values to be added |
|
| 205 | + * |
|
| 206 | + */ |
|
| 207 | + public function getData() |
|
| 208 | + { |
|
| 209 | + return $this->_data; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Use to insert data in a table |
|
| 214 | + * |
|
| 215 | + * @return bool true if success, false if an error occured |
|
| 216 | + * |
|
| 217 | + */ |
|
| 218 | + public function addData() |
|
| 219 | + { |
|
| 220 | + global $xoopsDB; |
|
| 221 | + foreach ($this->getData() as $data) { |
|
| 222 | + $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
| 223 | + $ret = $xoopsDB->query($query); |
|
| 224 | + if (!$ret) { |
|
| 225 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 226 | + } else { |
|
| 227 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + return $ret; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Add a field to be added |
|
| 236 | + * |
|
| 237 | + * @param string $name name of the field |
|
| 238 | + * @param string $properties properties of the field |
|
| 239 | + * @param bool $newname |
|
| 240 | + * @param bool $showerror |
|
| 241 | + */ |
|
| 242 | + public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
| 243 | + { |
|
| 244 | + $field['name'] = $name; |
|
| 245 | + $field['properties'] = $properties; |
|
| 246 | + $field['showerror'] = $showerror; |
|
| 247 | + $field['newname'] = $newname; |
|
| 248 | + $this->_alteredFields[] = $field; |
|
| 249 | + } |
|
| 250 | + /** |
|
| 251 | + * Invert values 0 to 1 and 1 to 0 |
|
| 252 | + * |
|
| 253 | + * @param string $name name of the field |
|
| 254 | + * @param $newValue |
|
| 255 | + * @param $oldValue |
|
| 256 | + * @internal param string $old old propertie |
|
| 257 | + * @internal param string $new new propertie |
|
| 258 | + */ //felix |
|
| 259 | + public function addUpdatedWhere($name, $newValue, $oldValue) |
|
| 260 | + { |
|
| 261 | + $field['name'] = $name; |
|
| 262 | + $field['value'] = $newValue; |
|
| 263 | + $field['where'] = $oldValue; |
|
| 264 | + $this->_updatedWhere[] = $field; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Add new field of a record to be added |
|
| 269 | + * |
|
| 270 | + * @param string $name name of the field |
|
| 271 | + * @param string $properties properties of the field |
|
| 272 | + * |
|
| 273 | + */ |
|
| 274 | + public function addNewField($name, $properties) |
|
| 275 | + { |
|
| 276 | + $field['name'] = $name; |
|
| 277 | + $field['properties'] = $properties; |
|
| 278 | + $this->_newFields[] = $field; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Get fields that need to be altered |
|
| 283 | + * |
|
| 284 | + * @return array fields that need to be altered |
|
| 285 | + * |
|
| 286 | + */ |
|
| 287 | + public function getAlteredFields() |
|
| 288 | + { |
|
| 289 | + return $this->_alteredFields; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Add field for which the value will be updated |
|
| 294 | + * |
|
| 295 | + * @param string $name name of the field |
|
| 296 | + * @param string $value value to be set |
|
| 297 | + * |
|
| 298 | + */ |
|
| 299 | + public function addUpdatedField($name, $value) |
|
| 300 | + { |
|
| 301 | + $field['name'] = $name; |
|
| 302 | + $field['value'] = $value; |
|
| 303 | + $this->_updatedFields[] = $field; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Get new fields to be added |
|
| 308 | + * |
|
| 309 | + * @return array fields to be added |
|
| 310 | + * |
|
| 311 | + */ |
|
| 312 | + public function getNewFields() |
|
| 313 | + { |
|
| 314 | + return $this->_newFields; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Get fields which values need to be updated |
|
| 319 | + * |
|
| 320 | + * @return array fields which values need to be updated |
|
| 321 | + * |
|
| 322 | + */ |
|
| 323 | + public function getUpdatedFields() |
|
| 324 | + { |
|
| 325 | + return $this->_updatedFields; |
|
| 326 | + } |
|
| 327 | + /** |
|
| 328 | + * Get fields which values need to be updated |
|
| 329 | + * |
|
| 330 | + * @return array fields which values need to be updated |
|
| 331 | + * |
|
| 332 | + */ //felix |
|
| 333 | + public function getUpdatedWhere() |
|
| 334 | + { |
|
| 335 | + return $this->_updatedWhere; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Add values of a record to be added |
|
| 340 | + * |
|
| 341 | + * @param string $name name of the field |
|
| 342 | + * |
|
| 343 | + */ |
|
| 344 | + public function addDroppedField($name) |
|
| 345 | + { |
|
| 346 | + $this->_droppedFields[] = $name; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Get fields that need to be dropped |
|
| 351 | + * |
|
| 352 | + * @return array fields that need to be dropped |
|
| 353 | + * |
|
| 354 | + */ |
|
| 355 | + public function getDroppedFields() |
|
| 356 | + { |
|
| 357 | + return $this->_droppedFields; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Set the flag to drop the table |
|
| 362 | + * |
|
| 363 | + */ |
|
| 364 | + public function setFlagForDrop() |
|
| 365 | + { |
|
| 366 | + $this->_flagForDrop = true; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Use to create a table |
|
| 371 | + * |
|
| 372 | + * @return bool true if success, false if an error occured |
|
| 373 | + * |
|
| 374 | + */ |
|
| 375 | + public function createTable() |
|
| 376 | + { |
|
| 377 | + global $xoopsDB; |
|
| 378 | + $query = $this->getStructure(); |
|
| 379 | + $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 380 | + //xoops_debug($query); |
|
| 381 | + $ret = $xoopsDB->query($query); |
|
| 382 | + if (!$ret) { |
|
| 383 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 384 | + } else { |
|
| 385 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + return $ret; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Use to drop a table |
|
| 393 | + * |
|
| 394 | + * @return bool true if success, false if an error occured |
|
| 395 | + * |
|
| 396 | + */ |
|
| 397 | + public function dropTable() |
|
| 398 | + { |
|
| 399 | + global $xoopsDB; |
|
| 400 | + $query = sprintf('DROP TABLE %s', $this->name()); |
|
| 401 | + $ret = $xoopsDB->query($query); |
|
| 402 | + if (!$ret) { |
|
| 403 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 404 | + |
|
| 405 | + return false; |
|
| 406 | + } else { |
|
| 407 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 408 | + |
|
| 409 | + return true; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Use to alter a table |
|
| 415 | + * |
|
| 416 | + * @return bool true if success, false if an error occured |
|
| 417 | + * |
|
| 418 | + */ |
|
| 419 | + public function alterTable() |
|
| 420 | + { |
|
| 421 | + global $xoopsDB; |
|
| 422 | + $ret = true; |
|
| 423 | + |
|
| 424 | + foreach ($this->getAlteredFields() as $alteredField) { |
|
| 425 | + if (!$alteredField['newname']) { |
|
| 426 | + $alteredField['newname'] = $alteredField['name']; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
| 430 | + $ret = $ret && $xoopsDB->query($query); |
|
| 431 | + if ($alteredField['showerror']) { |
|
| 432 | + if (!$ret) { |
|
| 433 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 434 | + } else { |
|
| 435 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + return $ret; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Use to add new fileds in the table |
|
| 445 | + * |
|
| 446 | + * @return bool true if success, false if an error occured |
|
| 447 | + * |
|
| 448 | + */ |
|
| 449 | + public function addNewFields() |
|
| 450 | + { |
|
| 451 | + global $xoopsDB; |
|
| 452 | + $ret = true; |
|
| 453 | + foreach ($this->getNewFields() as $newField) { |
|
| 454 | + $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
| 455 | + //echo $query; |
|
| 456 | + $ret = $ret && $xoopsDB->query($query); |
|
| 457 | + if (!$ret) { |
|
| 458 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 459 | + } else { |
|
| 460 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return $ret; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Use to update fields values |
|
| 469 | + * |
|
| 470 | + * @return bool true if success, false if an error occured |
|
| 471 | + * |
|
| 472 | + */ |
|
| 473 | + public function updateFieldsValues() |
|
| 474 | + { |
|
| 475 | + global $xoopsDB; |
|
| 476 | + $ret = true; |
|
| 477 | + foreach ($this->getUpdatedFields() as $updatedField) { |
|
| 478 | + $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
| 479 | + $ret = $ret && $xoopsDB->query($query); |
|
| 480 | + if (!$ret) { |
|
| 481 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 482 | + } else { |
|
| 483 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $ret; |
|
| 488 | + } |
|
| 489 | + /** |
|
| 490 | + * Use to update fields values |
|
| 491 | + * |
|
| 492 | + * @return bool true if success, false if an error occured |
|
| 493 | + * |
|
| 494 | + */ //felix |
|
| 495 | + public function updateWhereValues() |
|
| 496 | + { |
|
| 497 | + global $xoopsDB; |
|
| 498 | + $ret = true; |
|
| 499 | + foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
| 500 | + $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
| 501 | + //echo $query."<br>"; |
|
| 502 | + $ret = $ret && $xoopsDB->query($query); |
|
| 503 | + if (!$ret) { |
|
| 504 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 505 | + } else { |
|
| 506 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + return $ret; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Use to drop fields |
|
| 515 | + * |
|
| 516 | + * @return bool true if success, false if an error occured |
|
| 517 | + * |
|
| 518 | + */ |
|
| 519 | + public function dropFields() |
|
| 520 | + { |
|
| 521 | + global $xoopsDB; |
|
| 522 | + $ret = true; |
|
| 523 | + foreach ($this->getDroppedFields() as $droppedField) { |
|
| 524 | + $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
| 525 | + $ret = $ret && $xoopsDB->query($query); |
|
| 526 | + if (!$ret) { |
|
| 527 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 528 | + } else { |
|
| 529 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + return $ret; |
|
| 534 | + } |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /** |
@@ -545,328 +545,328 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | class SmartobjectDbupdater |
| 547 | 547 | { |
| 548 | - public $_dbTypesArray; |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * SmartobjectDbupdater constructor. |
|
| 552 | - */ |
|
| 553 | - public function __construct() |
|
| 554 | - { |
|
| 555 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
| 556 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
| 557 | - $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
| 558 | - $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
| 559 | - $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
| 560 | - $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
| 561 | - $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
| 562 | - $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
| 563 | - $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
| 564 | - $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
| 565 | - $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
| 566 | - $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
| 567 | - $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
| 568 | - $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
| 569 | - $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
| 570 | - $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
| 571 | - $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
| 572 | - $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Use to execute a general query |
|
| 577 | - * |
|
| 578 | - * @param string $query query that will be executed |
|
| 579 | - * @param string $goodmsg message displayed on success |
|
| 580 | - * @param string $badmsg message displayed on error |
|
| 581 | - * |
|
| 582 | - * @return bool true if success, false if an error occured |
|
| 583 | - * |
|
| 584 | - */ |
|
| 585 | - public function runQuery($query, $goodmsg, $badmsg) |
|
| 586 | - { |
|
| 587 | - global $xoopsDB; |
|
| 588 | - $ret = $xoopsDB->query($query); |
|
| 589 | - if (!$ret) { |
|
| 590 | - echo " $badmsg<br>"; |
|
| 591 | - |
|
| 592 | - return false; |
|
| 593 | - } else { |
|
| 594 | - echo " $goodmsg<br>"; |
|
| 595 | - |
|
| 596 | - return true; |
|
| 597 | - } |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Use to rename a table |
|
| 602 | - * |
|
| 603 | - * @param string $from name of the table to rename |
|
| 604 | - * @param string $to new name of the renamed table |
|
| 605 | - * |
|
| 606 | - * @return bool true if success, false if an error occured |
|
| 607 | - */ |
|
| 608 | - public function renameTable($from, $to) |
|
| 609 | - { |
|
| 610 | - global $xoopsDB; |
|
| 611 | - $from = $xoopsDB->prefix($from); |
|
| 612 | - $to = $xoopsDB->prefix($to); |
|
| 613 | - $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
| 614 | - $ret = $xoopsDB->query($query); |
|
| 615 | - if (!$ret) { |
|
| 616 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
| 617 | - |
|
| 618 | - return false; |
|
| 619 | - } else { |
|
| 620 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
| 621 | - |
|
| 622 | - return true; |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Use to update a table |
|
| 628 | - * |
|
| 629 | - * @param object $table {@link SmartDbTable} that will be updated |
|
| 630 | - * |
|
| 631 | - * @see SmartDbTable |
|
| 632 | - * |
|
| 633 | - * @return bool true if success, false if an error occured |
|
| 634 | - */ |
|
| 635 | - public function updateTable($table) |
|
| 636 | - { |
|
| 637 | - global $xoopsDB; |
|
| 638 | - $ret = true; |
|
| 639 | - // If table has a structure, create the table |
|
| 640 | - if ($table->getStructure()) { |
|
| 641 | - $ret = $table->createTable() && $ret; |
|
| 642 | - } |
|
| 643 | - // If table is flag for drop, drop it |
|
| 644 | - if ($table->_flagForDrop) { |
|
| 645 | - $ret = $table->dropTable() && $ret; |
|
| 646 | - } |
|
| 647 | - // If table has data, insert it |
|
| 648 | - if ($table->getData()) { |
|
| 649 | - $ret = $table->addData() && $ret; |
|
| 650 | - } |
|
| 651 | - // If table has new fields to be added, add them |
|
| 652 | - if ($table->getNewFields()) { |
|
| 653 | - $ret = $table->addNewFields() && $ret; |
|
| 654 | - } |
|
| 655 | - // If table has altered field, alter the table |
|
| 656 | - if ($table->getAlteredFields()) { |
|
| 657 | - $ret = $table->alterTable() && $ret; |
|
| 658 | - } |
|
| 659 | - // If table has updated field values, update the table |
|
| 660 | - if ($table->getUpdatedFields()) { |
|
| 661 | - $ret = $table->updateFieldsValues($table) && $ret; |
|
| 662 | - } |
|
| 663 | - // If table has dropped field, alter the table |
|
| 664 | - if ($table->getDroppedFields()) { |
|
| 665 | - $ret = $table->dropFields($table) && $ret; |
|
| 666 | - } |
|
| 667 | - //felix |
|
| 668 | - // If table has updated field values, update the table |
|
| 669 | - if ($table->getUpdatedWhere()) { |
|
| 670 | - $ret = $table->UpdateWhereValues($table) && $ret; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return $ret; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * @param $module |
|
| 678 | - * @param $item |
|
| 679 | - */ |
|
| 680 | - public function automaticUpgrade($module, $item) |
|
| 681 | - { |
|
| 682 | - if (is_array($item)) { |
|
| 683 | - foreach ($item as $v) { |
|
| 684 | - $this->upgradeObjectItem($module, $v); |
|
| 685 | - } |
|
| 686 | - } else { |
|
| 687 | - $this->upgradeObjectItem($module, $item); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * @param $var |
|
| 693 | - * @return string |
|
| 694 | - */ |
|
| 695 | - public function getFieldTypeFromVar($var) |
|
| 696 | - { |
|
| 697 | - $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
| 698 | - |
|
| 699 | - return $ret; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * @param $var |
|
| 704 | - * @param bool $key |
|
| 705 | - * @return string |
|
| 706 | - */ |
|
| 707 | - public function getFieldDefaultFromVar($var, $key = false) |
|
| 708 | - { |
|
| 709 | - if ($var['value']) { |
|
| 710 | - return $var['value']; |
|
| 711 | - } else { |
|
| 712 | - if (in_array($var['data_type'], array( |
|
| 713 | - XOBJ_DTYPE_INT, |
|
| 714 | - XOBJ_DTYPE_STIME, |
|
| 715 | - XOBJ_DTYPE_MTIME, |
|
| 716 | - XOBJ_DTYPE_LTIME, |
|
| 717 | - XOBJ_DTYPE_TIME_ONLY, |
|
| 718 | - XOBJ_DTYPE_URLLINK, |
|
| 719 | - XOBJ_DTYPE_FILE |
|
| 720 | - ))) { |
|
| 721 | - return '0'; |
|
| 722 | - } else { |
|
| 723 | - return ''; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * @param $module |
|
| 730 | - * @param $item |
|
| 731 | - * @return bool |
|
| 732 | - */ |
|
| 733 | - public function upgradeObjectItem($module, $item) |
|
| 734 | - { |
|
| 735 | - $moduleHandler = xoops_getModuleHandler($item, $module); |
|
| 736 | - if (!$moduleHandler) { |
|
| 737 | - return false; |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - $table = new SmartDbTable($module . '_' . $item); |
|
| 741 | - $object = $moduleHandler->create(); |
|
| 742 | - $objectVars = $object->getVars(); |
|
| 743 | - |
|
| 744 | - if (!$table->exists()) { |
|
| 745 | - // table was never created, let's do it |
|
| 746 | - $structure = ''; |
|
| 747 | - foreach ($objectVars as $key => $var) { |
|
| 748 | - if ($var['persistent']) { |
|
| 749 | - $type = $this->getFieldTypeFromVar($var); |
|
| 750 | - if ($key == $moduleHandler->keyName) { |
|
| 751 | - $extra = 'auto_increment'; |
|
| 752 | - } else { |
|
| 753 | - $default = $this->getFieldDefaultFromVar($var); |
|
| 754 | - $extra = "default '$default' |
|
| 548 | + public $_dbTypesArray; |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * SmartobjectDbupdater constructor. |
|
| 552 | + */ |
|
| 553 | + public function __construct() |
|
| 554 | + { |
|
| 555 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
| 556 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
| 557 | + $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
| 558 | + $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
| 559 | + $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
| 560 | + $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
| 561 | + $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
| 562 | + $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
| 563 | + $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
| 564 | + $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
| 565 | + $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
| 566 | + $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
| 567 | + $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
| 568 | + $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
| 569 | + $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
| 570 | + $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
| 571 | + $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
| 572 | + $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Use to execute a general query |
|
| 577 | + * |
|
| 578 | + * @param string $query query that will be executed |
|
| 579 | + * @param string $goodmsg message displayed on success |
|
| 580 | + * @param string $badmsg message displayed on error |
|
| 581 | + * |
|
| 582 | + * @return bool true if success, false if an error occured |
|
| 583 | + * |
|
| 584 | + */ |
|
| 585 | + public function runQuery($query, $goodmsg, $badmsg) |
|
| 586 | + { |
|
| 587 | + global $xoopsDB; |
|
| 588 | + $ret = $xoopsDB->query($query); |
|
| 589 | + if (!$ret) { |
|
| 590 | + echo " $badmsg<br>"; |
|
| 591 | + |
|
| 592 | + return false; |
|
| 593 | + } else { |
|
| 594 | + echo " $goodmsg<br>"; |
|
| 595 | + |
|
| 596 | + return true; |
|
| 597 | + } |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Use to rename a table |
|
| 602 | + * |
|
| 603 | + * @param string $from name of the table to rename |
|
| 604 | + * @param string $to new name of the renamed table |
|
| 605 | + * |
|
| 606 | + * @return bool true if success, false if an error occured |
|
| 607 | + */ |
|
| 608 | + public function renameTable($from, $to) |
|
| 609 | + { |
|
| 610 | + global $xoopsDB; |
|
| 611 | + $from = $xoopsDB->prefix($from); |
|
| 612 | + $to = $xoopsDB->prefix($to); |
|
| 613 | + $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
| 614 | + $ret = $xoopsDB->query($query); |
|
| 615 | + if (!$ret) { |
|
| 616 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
| 617 | + |
|
| 618 | + return false; |
|
| 619 | + } else { |
|
| 620 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
| 621 | + |
|
| 622 | + return true; |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Use to update a table |
|
| 628 | + * |
|
| 629 | + * @param object $table {@link SmartDbTable} that will be updated |
|
| 630 | + * |
|
| 631 | + * @see SmartDbTable |
|
| 632 | + * |
|
| 633 | + * @return bool true if success, false if an error occured |
|
| 634 | + */ |
|
| 635 | + public function updateTable($table) |
|
| 636 | + { |
|
| 637 | + global $xoopsDB; |
|
| 638 | + $ret = true; |
|
| 639 | + // If table has a structure, create the table |
|
| 640 | + if ($table->getStructure()) { |
|
| 641 | + $ret = $table->createTable() && $ret; |
|
| 642 | + } |
|
| 643 | + // If table is flag for drop, drop it |
|
| 644 | + if ($table->_flagForDrop) { |
|
| 645 | + $ret = $table->dropTable() && $ret; |
|
| 646 | + } |
|
| 647 | + // If table has data, insert it |
|
| 648 | + if ($table->getData()) { |
|
| 649 | + $ret = $table->addData() && $ret; |
|
| 650 | + } |
|
| 651 | + // If table has new fields to be added, add them |
|
| 652 | + if ($table->getNewFields()) { |
|
| 653 | + $ret = $table->addNewFields() && $ret; |
|
| 654 | + } |
|
| 655 | + // If table has altered field, alter the table |
|
| 656 | + if ($table->getAlteredFields()) { |
|
| 657 | + $ret = $table->alterTable() && $ret; |
|
| 658 | + } |
|
| 659 | + // If table has updated field values, update the table |
|
| 660 | + if ($table->getUpdatedFields()) { |
|
| 661 | + $ret = $table->updateFieldsValues($table) && $ret; |
|
| 662 | + } |
|
| 663 | + // If table has dropped field, alter the table |
|
| 664 | + if ($table->getDroppedFields()) { |
|
| 665 | + $ret = $table->dropFields($table) && $ret; |
|
| 666 | + } |
|
| 667 | + //felix |
|
| 668 | + // If table has updated field values, update the table |
|
| 669 | + if ($table->getUpdatedWhere()) { |
|
| 670 | + $ret = $table->UpdateWhereValues($table) && $ret; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return $ret; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * @param $module |
|
| 678 | + * @param $item |
|
| 679 | + */ |
|
| 680 | + public function automaticUpgrade($module, $item) |
|
| 681 | + { |
|
| 682 | + if (is_array($item)) { |
|
| 683 | + foreach ($item as $v) { |
|
| 684 | + $this->upgradeObjectItem($module, $v); |
|
| 685 | + } |
|
| 686 | + } else { |
|
| 687 | + $this->upgradeObjectItem($module, $item); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * @param $var |
|
| 693 | + * @return string |
|
| 694 | + */ |
|
| 695 | + public function getFieldTypeFromVar($var) |
|
| 696 | + { |
|
| 697 | + $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
| 698 | + |
|
| 699 | + return $ret; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * @param $var |
|
| 704 | + * @param bool $key |
|
| 705 | + * @return string |
|
| 706 | + */ |
|
| 707 | + public function getFieldDefaultFromVar($var, $key = false) |
|
| 708 | + { |
|
| 709 | + if ($var['value']) { |
|
| 710 | + return $var['value']; |
|
| 711 | + } else { |
|
| 712 | + if (in_array($var['data_type'], array( |
|
| 713 | + XOBJ_DTYPE_INT, |
|
| 714 | + XOBJ_DTYPE_STIME, |
|
| 715 | + XOBJ_DTYPE_MTIME, |
|
| 716 | + XOBJ_DTYPE_LTIME, |
|
| 717 | + XOBJ_DTYPE_TIME_ONLY, |
|
| 718 | + XOBJ_DTYPE_URLLINK, |
|
| 719 | + XOBJ_DTYPE_FILE |
|
| 720 | + ))) { |
|
| 721 | + return '0'; |
|
| 722 | + } else { |
|
| 723 | + return ''; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * @param $module |
|
| 730 | + * @param $item |
|
| 731 | + * @return bool |
|
| 732 | + */ |
|
| 733 | + public function upgradeObjectItem($module, $item) |
|
| 734 | + { |
|
| 735 | + $moduleHandler = xoops_getModuleHandler($item, $module); |
|
| 736 | + if (!$moduleHandler) { |
|
| 737 | + return false; |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + $table = new SmartDbTable($module . '_' . $item); |
|
| 741 | + $object = $moduleHandler->create(); |
|
| 742 | + $objectVars = $object->getVars(); |
|
| 743 | + |
|
| 744 | + if (!$table->exists()) { |
|
| 745 | + // table was never created, let's do it |
|
| 746 | + $structure = ''; |
|
| 747 | + foreach ($objectVars as $key => $var) { |
|
| 748 | + if ($var['persistent']) { |
|
| 749 | + $type = $this->getFieldTypeFromVar($var); |
|
| 750 | + if ($key == $moduleHandler->keyName) { |
|
| 751 | + $extra = 'auto_increment'; |
|
| 752 | + } else { |
|
| 753 | + $default = $this->getFieldDefaultFromVar($var); |
|
| 754 | + $extra = "default '$default' |
|
| 755 | 755 | "; |
| 756 | - } |
|
| 757 | - $structure .= "`$key` $type not null $extra, |
|
| 756 | + } |
|
| 757 | + $structure .= "`$key` $type not null $extra, |
|
| 758 | 758 | "; |
| 759 | - } |
|
| 760 | - } |
|
| 761 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
| 762 | 762 | '; |
| 763 | - $table->setStructure($structure); |
|
| 764 | - if (!$this->updateTable($table)) { |
|
| 765 | - /** |
|
| 766 | - * @todo trap the errors |
|
| 767 | - */ |
|
| 768 | - } |
|
| 769 | - } else { |
|
| 770 | - $existingFieldsArray = $table->getExistingFieldsArray(); |
|
| 771 | - foreach ($objectVars as $key => $var) { |
|
| 772 | - if ($var['persistent']) { |
|
| 773 | - if (!isset($existingFieldsArray[$key])) { |
|
| 774 | - // the fiels does not exist, let's create it |
|
| 775 | - $type = $this->getFieldTypeFromVar($var); |
|
| 776 | - $default = $this->getFieldDefaultFromVar($var); |
|
| 777 | - $table->addNewField($key, "$type not null default '$default'"); |
|
| 778 | - } else { |
|
| 779 | - // if field already exists, let's check if the definition is correct |
|
| 780 | - $definition = strtolower($existingFieldsArray[$key]); |
|
| 781 | - $type = $this->getFieldTypeFromVar($var); |
|
| 782 | - if ($key == $moduleHandler->keyName) { |
|
| 783 | - $extra = 'auto_increment'; |
|
| 784 | - } else { |
|
| 785 | - $default = $this->getFieldDefaultFromVar($var, $key); |
|
| 786 | - $extra = "default '$default'"; |
|
| 787 | - } |
|
| 788 | - $actual_definition = "$type not null $extra"; |
|
| 789 | - if ($definition != $actual_definition) { |
|
| 790 | - $table->addAlteredField($key, $actual_definition); |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - // check to see if there are some unused fields left in the table |
|
| 797 | - foreach ($existingFieldsArray as $key => $v) { |
|
| 798 | - if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
| 799 | - $table->addDroppedField($key); |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - if (!$this->updateTable($table)) { |
|
| 804 | - /** |
|
| 805 | - * @todo trap the errors |
|
| 806 | - */ |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * @param $module |
|
| 813 | - * @return bool |
|
| 814 | - */ |
|
| 815 | - public function moduleUpgrade(XoopsModule $module) |
|
| 816 | - { |
|
| 817 | - $dirname = $module->getVar('dirname'); |
|
| 818 | - |
|
| 819 | - ob_start(); |
|
| 820 | - |
|
| 821 | - $table = new SmartDbTable($dirname . '_meta'); |
|
| 822 | - if (!$table->exists()) { |
|
| 823 | - $table->setStructure(" |
|
| 763 | + $table->setStructure($structure); |
|
| 764 | + if (!$this->updateTable($table)) { |
|
| 765 | + /** |
|
| 766 | + * @todo trap the errors |
|
| 767 | + */ |
|
| 768 | + } |
|
| 769 | + } else { |
|
| 770 | + $existingFieldsArray = $table->getExistingFieldsArray(); |
|
| 771 | + foreach ($objectVars as $key => $var) { |
|
| 772 | + if ($var['persistent']) { |
|
| 773 | + if (!isset($existingFieldsArray[$key])) { |
|
| 774 | + // the fiels does not exist, let's create it |
|
| 775 | + $type = $this->getFieldTypeFromVar($var); |
|
| 776 | + $default = $this->getFieldDefaultFromVar($var); |
|
| 777 | + $table->addNewField($key, "$type not null default '$default'"); |
|
| 778 | + } else { |
|
| 779 | + // if field already exists, let's check if the definition is correct |
|
| 780 | + $definition = strtolower($existingFieldsArray[$key]); |
|
| 781 | + $type = $this->getFieldTypeFromVar($var); |
|
| 782 | + if ($key == $moduleHandler->keyName) { |
|
| 783 | + $extra = 'auto_increment'; |
|
| 784 | + } else { |
|
| 785 | + $default = $this->getFieldDefaultFromVar($var, $key); |
|
| 786 | + $extra = "default '$default'"; |
|
| 787 | + } |
|
| 788 | + $actual_definition = "$type not null $extra"; |
|
| 789 | + if ($definition != $actual_definition) { |
|
| 790 | + $table->addAlteredField($key, $actual_definition); |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + // check to see if there are some unused fields left in the table |
|
| 797 | + foreach ($existingFieldsArray as $key => $v) { |
|
| 798 | + if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
| 799 | + $table->addDroppedField($key); |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + if (!$this->updateTable($table)) { |
|
| 804 | + /** |
|
| 805 | + * @todo trap the errors |
|
| 806 | + */ |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * @param $module |
|
| 813 | + * @return bool |
|
| 814 | + */ |
|
| 815 | + public function moduleUpgrade(XoopsModule $module) |
|
| 816 | + { |
|
| 817 | + $dirname = $module->getVar('dirname'); |
|
| 818 | + |
|
| 819 | + ob_start(); |
|
| 820 | + |
|
| 821 | + $table = new SmartDbTable($dirname . '_meta'); |
|
| 822 | + if (!$table->exists()) { |
|
| 823 | + $table->setStructure(" |
|
| 824 | 824 | `metakey` varchar(50) NOT NULL default '', |
| 825 | 825 | `metavalue` varchar(255) NOT NULL default '', |
| 826 | 826 | PRIMARY KEY (`metakey`)"); |
| 827 | - $table->setData("'version',0"); |
|
| 828 | - if (!$this->updateTable($table)) { |
|
| 829 | - /** |
|
| 830 | - * @todo trap the errors |
|
| 831 | - */ |
|
| 832 | - } |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - $dbVersion = smart_GetMeta('version', $dirname); |
|
| 836 | - if (!$dbVersion) { |
|
| 837 | - $dbVersion = 0; |
|
| 838 | - } |
|
| 839 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
| 840 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
| 841 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
| 842 | - |
|
| 843 | - if ($newDbVersion > $dbVersion) { |
|
| 844 | - for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
| 845 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
| 846 | - if (function_exists($upgrade_function)) { |
|
| 847 | - $upgrade_function(); |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 853 | - |
|
| 854 | - // if there is a function to execute for this DB version, let's do it |
|
| 855 | - //$function_ |
|
| 856 | - |
|
| 857 | - $module_info = smart_getModuleInfo($dirname); |
|
| 858 | - $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
| 859 | - |
|
| 860 | - echo '</code>'; |
|
| 861 | - |
|
| 862 | - $feedback = ob_get_clean(); |
|
| 863 | - if (method_exists($module, 'setMessage')) { |
|
| 864 | - $module->setMessage($feedback); |
|
| 865 | - } else { |
|
| 866 | - echo $feedback; |
|
| 867 | - } |
|
| 868 | - smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
| 869 | - |
|
| 870 | - return true; |
|
| 871 | - } |
|
| 827 | + $table->setData("'version',0"); |
|
| 828 | + if (!$this->updateTable($table)) { |
|
| 829 | + /** |
|
| 830 | + * @todo trap the errors |
|
| 831 | + */ |
|
| 832 | + } |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + $dbVersion = smart_GetMeta('version', $dirname); |
|
| 836 | + if (!$dbVersion) { |
|
| 837 | + $dbVersion = 0; |
|
| 838 | + } |
|
| 839 | + $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
| 840 | + echo 'Database version: ' . $dbVersion . '<br>'; |
|
| 841 | + echo 'New database version: ' . $newDbVersion . '<br>'; |
|
| 842 | + |
|
| 843 | + if ($newDbVersion > $dbVersion) { |
|
| 844 | + for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
| 845 | + $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
| 846 | + if (function_exists($upgrade_function)) { |
|
| 847 | + $upgrade_function(); |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 853 | + |
|
| 854 | + // if there is a function to execute for this DB version, let's do it |
|
| 855 | + //$function_ |
|
| 856 | + |
|
| 857 | + $module_info = smart_getModuleInfo($dirname); |
|
| 858 | + $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
| 859 | + |
|
| 860 | + echo '</code>'; |
|
| 861 | + |
|
| 862 | + $feedback = ob_get_clean(); |
|
| 863 | + if (method_exists($module, 'setMessage')) { |
|
| 864 | + $module->setMessage($feedback); |
|
| 865 | + } else { |
|
| 866 | + echo $feedback; |
|
| 867 | + } |
|
| 868 | + smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
| 869 | + |
|
| 870 | + return true; |
|
| 871 | + } |
|
| 872 | 872 | } |
@@ -25,980 +25,980 @@ |
||
| 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 XoopsDatabase $db {@link XoopsDatabase} |
|
| 134 | - * @param string $itemname Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
| 135 | - * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
| 136 | - * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
| 137 | - * @param string $summaryName |
|
| 138 | - * @param string $modulename |
|
| 139 | - * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 140 | - * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 141 | - * @internal param string $moduleName name of the module |
|
| 142 | - */ |
|
| 143 | - public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
| 144 | - { |
|
| 145 | - parent::__construct($db); |
|
| 146 | - |
|
| 147 | - $this->_itemname = $itemname; |
|
| 148 | - $this->_moduleName = $modulename; |
|
| 149 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 150 | - $this->keyName = $keyname; |
|
| 151 | - $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 152 | - $this->identifierName = $idenfierName; |
|
| 153 | - $this->summaryName = $summaryName; |
|
| 154 | - $this->_page = $itemname . '.php'; |
|
| 155 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 156 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 157 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 158 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param $event |
|
| 163 | - * @param $method |
|
| 164 | - */ |
|
| 165 | - public function addEventHook($event, $method) |
|
| 166 | - { |
|
| 167 | - $this->_eventHooks[$event] = $method; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Add a permission that this handler will manage for its objects |
|
| 172 | - * |
|
| 173 | - * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
| 174 | - * |
|
| 175 | - * @param string $perm_name name of the permission |
|
| 176 | - * @param string $caption caption of the control that will be displayed in the form |
|
| 177 | - * @param bool|string $description description of the control that will be displayed in the form |
|
| 178 | - */ |
|
| 179 | - public function addPermission($perm_name, $caption, $description = false) |
|
| 180 | - { |
|
| 181 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
|
| 182 | - |
|
| 183 | - $this->permissionsArray[] = array( |
|
| 184 | - 'perm_name' => $perm_name, |
|
| 185 | - 'caption' => $caption, |
|
| 186 | - 'description' => $description |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @param $criteria |
|
| 192 | - * @param $perm_name |
|
| 193 | - * @return bool |
|
| 194 | - */ |
|
| 195 | - public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
|
| 196 | - { |
|
| 197 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
| 198 | - $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 199 | - if (count($grantedItems) > 0) { |
|
| 200 | - $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 201 | - |
|
| 202 | - return true; |
|
| 203 | - } else { |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param bool $_uploadPath |
|
| 210 | - * @param bool $_allowedMimeTypes |
|
| 211 | - * @param bool $_maxFileSize |
|
| 212 | - * @param bool $_maxWidth |
|
| 213 | - * @param bool $_maxHeight |
|
| 214 | - */ |
|
| 215 | - public function setUploaderConfig( |
|
| 216 | - $_uploadPath = false, |
|
| 217 | - $_allowedMimeTypes = false, |
|
| 218 | - $_maxFileSize = false, |
|
| 219 | - $_maxWidth = false, |
|
| 220 | - $_maxHeight = false |
|
| 221 | - ) { |
|
| 222 | - $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
| 223 | - $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
| 224 | - $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
| 225 | - $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
| 226 | - $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * create a new {@link SmartObject} |
|
| 231 | - * |
|
| 232 | - * @param bool $isNew Flag the new objects as "new"? |
|
| 233 | - * |
|
| 234 | - * @return SmartObject {@link SmartObject} |
|
| 235 | - */ |
|
| 236 | - public function create($isNew = true) |
|
| 237 | - { |
|
| 238 | - $obj = new $this->className($this); |
|
| 239 | - $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
| 240 | - if (!$obj->handler) { |
|
| 241 | - $obj->Handler = $this; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - if ($isNew === true) { |
|
| 245 | - $obj->setNew(); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - return $obj; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @return string |
|
| 253 | - */ |
|
| 254 | - public function getImageUrl() |
|
| 255 | - { |
|
| 256 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function getImagePath() |
|
| 263 | - { |
|
| 264 | - $dir = $this->_uploadPath . $this->_itemname; |
|
| 265 | - if (!file_exists($dir)) { |
|
| 266 | - smart_admin_mkdir($dir); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - return $dir . '/'; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * retrieve a {@link SmartObject} |
|
| 274 | - * |
|
| 275 | - * @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 |
|
| 276 | - * @param bool $as_object whether to return an object or an array |
|
| 277 | - * @param bool $debug |
|
| 278 | - * @param bool $criteria |
|
| 279 | - * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
| 280 | - * FALSE if failed |
|
| 281 | - */ |
|
| 282 | - public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
| 283 | - { |
|
| 284 | - if (!$criteria) { |
|
| 285 | - $criteria = new CriteriaCompo(); |
|
| 286 | - } |
|
| 287 | - if (is_array($this->keyName)) { |
|
| 288 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 289 | - /** |
|
| 290 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 291 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
| 292 | - */ |
|
| 293 | - //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
| 294 | - $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
| 295 | - } |
|
| 296 | - } else { |
|
| 297 | - //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
| 298 | - /** |
|
| 299 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 300 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
| 301 | - */ |
|
| 302 | - $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
| 303 | - } |
|
| 304 | - $criteria->setLimit(1); |
|
| 305 | - if ($debug) { |
|
| 306 | - $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
| 307 | - } else { |
|
| 308 | - $obj_array = $this->getObjects($criteria, false, $as_object); |
|
| 309 | - //patch: weird bug of indexing by id even if id_as_key = false; |
|
| 310 | - if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
| 311 | - $obj_array[0] = $obj_array[$id]; |
|
| 312 | - unset($obj_array[$id]); |
|
| 313 | - $obj_array[0]->unsetNew(); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - if (count($obj_array) != 1) { |
|
| 318 | - $obj = $this->create(); |
|
| 319 | - |
|
| 320 | - return $obj; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - return $obj_array[0]; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * retrieve a {@link SmartObject} |
|
| 328 | - * |
|
| 329 | - * @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 |
|
| 330 | - * @param bool $as_object whether to return an object or an array |
|
| 331 | - * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
| 332 | - */ |
|
| 333 | - public function &getD($id, $as_object = true) |
|
| 334 | - { |
|
| 335 | - return $this->get($id, $as_object, true); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * retrieve objects from the database |
|
| 340 | - * |
|
| 341 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 342 | - * @param bool $id_as_key use the ID as key for the array? |
|
| 343 | - * @param bool $as_object return an array of objects? |
|
| 344 | - * |
|
| 345 | - * @param bool $sql |
|
| 346 | - * @param bool $debug |
|
| 347 | - * @return array |
|
| 348 | - */ |
|
| 349 | - public function getObjects( |
|
| 350 | - CriteriaElement $criteria = null, |
|
| 351 | - $id_as_key = false, |
|
| 352 | - $as_object = true, |
|
| 353 | - $sql = false, |
|
| 354 | - $debug = false |
|
| 355 | - ) { |
|
| 356 | - $ret = array(); |
|
| 357 | - $limit = $start = 0; |
|
| 358 | - |
|
| 359 | - if ($this->generalSQL) { |
|
| 360 | - $sql = $this->generalSQL; |
|
| 361 | - } elseif (!$sql) { |
|
| 362 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 366 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 367 | - if ($criteria->getSort() !== '') { |
|
| 368 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 369 | - } |
|
| 370 | - $limit = $criteria->getLimit(); |
|
| 371 | - $start = $criteria->getStart(); |
|
| 372 | - } |
|
| 373 | - if ($debug) { |
|
| 374 | - xoops_debug($sql); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - $result = $this->db->query($sql, $limit, $start); |
|
| 378 | - if (!$result) { |
|
| 379 | - return $ret; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - return $this->convertResultSet($result, $id_as_key, $as_object); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @param $sql |
|
| 387 | - * @param $criteria |
|
| 388 | - * @param bool $force |
|
| 389 | - * @param bool $debug |
|
| 390 | - * @return array |
|
| 391 | - */ |
|
| 392 | - public function query($sql, $criteria, $force = false, $debug = false) |
|
| 393 | - { |
|
| 394 | - $ret = array(); |
|
| 395 | - |
|
| 396 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 397 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 398 | - if ($criteria->groupby) { |
|
| 399 | - $sql .= $criteria->getGroupby(); |
|
| 400 | - } |
|
| 401 | - if ($criteria->getSort() !== '') { |
|
| 402 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - if ($debug) { |
|
| 406 | - xoops_debug($sql); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - if ($force) { |
|
| 410 | - $result = $this->db->queryF($sql); |
|
| 411 | - } else { |
|
| 412 | - $result = $this->db->query($sql); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - if (!$result) { |
|
| 416 | - return $ret; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 420 | - $ret[] = $myrow; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $ret; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * retrieve objects with debug mode - so will show the query |
|
| 428 | - * |
|
| 429 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 430 | - * @param bool $id_as_key use the ID as key for the array? |
|
| 431 | - * @param bool $as_object return an array of objects? |
|
| 432 | - * |
|
| 433 | - * @param bool $sql |
|
| 434 | - * @return array |
|
| 435 | - */ |
|
| 436 | - public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
| 437 | - { |
|
| 438 | - return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @param $arrayObjects |
|
| 443 | - * @return array|bool |
|
| 444 | - */ |
|
| 445 | - public function getObjectsAsArray($arrayObjects) |
|
| 446 | - { |
|
| 447 | - $ret = array(); |
|
| 448 | - foreach ($arrayObjects as $key => $object) { |
|
| 449 | - $ret[$key] = $object->toArray(); |
|
| 450 | - } |
|
| 451 | - if (count($ret > 0)) { |
|
| 452 | - return $ret; |
|
| 453 | - } else { |
|
| 454 | - return false; |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Convert a database resultset to a returnable array |
|
| 460 | - * |
|
| 461 | - * @param object $result database resultset |
|
| 462 | - * @param bool $id_as_key - should NOT be used with joint keys |
|
| 463 | - * @param bool $as_object |
|
| 464 | - * |
|
| 465 | - * @return array |
|
| 466 | - */ |
|
| 467 | - public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
| 468 | - { |
|
| 469 | - $ret = array(); |
|
| 470 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 471 | - $obj = $this->create(false); |
|
| 472 | - $obj->assignVars($myrow); |
|
| 473 | - if (!$id_as_key) { |
|
| 474 | - if ($as_object) { |
|
| 475 | - $ret[] =& $obj; |
|
| 476 | - } else { |
|
| 477 | - $ret[] = $obj->toArray(); |
|
| 478 | - } |
|
| 479 | - } else { |
|
| 480 | - if ($as_object) { |
|
| 481 | - $value =& $obj; |
|
| 482 | - } else { |
|
| 483 | - $value = $obj->toArray(); |
|
| 484 | - } |
|
| 485 | - if ($id_as_key === 'parentid') { |
|
| 486 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 487 | - } else { |
|
| 488 | - $ret[$obj->getVar($this->keyName)] = $value; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - unset($obj); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $ret; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * @param null $criteria |
|
| 499 | - * @param int $limit |
|
| 500 | - * @param int $start |
|
| 501 | - * @return array |
|
| 502 | - */ |
|
| 503 | - public function getListD($criteria = null, $limit = 0, $start = 0) |
|
| 504 | - { |
|
| 505 | - return $this->getList($criteria, $limit, $start, true); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
| 510 | - * |
|
| 511 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 512 | - * @param int $limit Max number of objects to fetch |
|
| 513 | - * @param int $start Which record to start at |
|
| 514 | - * |
|
| 515 | - * @param bool $debug |
|
| 516 | - * @return array |
|
| 517 | - */ |
|
| 518 | - public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
| 519 | - { |
|
| 520 | - $ret = array(); |
|
| 521 | - if ($criteria === null) { |
|
| 522 | - $criteria = new CriteriaCompo(); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - if ($criteria->getSort() === '') { |
|
| 526 | - $criteria->setSort($this->getIdentifierName()); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 530 | - if (!empty($this->identifierName)) { |
|
| 531 | - $sql .= ', ' . $this->getIdentifierName(); |
|
| 532 | - } |
|
| 533 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 534 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 535 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 536 | - if ($criteria->getSort() !== '') { |
|
| 537 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 538 | - } |
|
| 539 | - $limit = $criteria->getLimit(); |
|
| 540 | - $start = $criteria->getStart(); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - if ($debug) { |
|
| 544 | - xoops_debug($sql); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - $result = $this->db->query($sql, $limit, $start); |
|
| 548 | - if (!$result) { |
|
| 549 | - return $ret; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - $myts = MyTextSanitizer::getInstance(); |
|
| 553 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 554 | - //identifiers should be textboxes, so sanitize them like that |
|
| 555 | - $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - return $ret; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * count objects matching a condition |
|
| 563 | - * |
|
| 564 | - * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
| 565 | - * @return int count of objects |
|
| 566 | - */ |
|
| 567 | - public function getCount(CriteriaElement $criteria = null) |
|
| 568 | - { |
|
| 569 | - $field = ''; |
|
| 570 | - $groupby = false; |
|
| 571 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 572 | - if ($criteria->groupby !== '') { |
|
| 573 | - $groupby = true; |
|
| 574 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - /** |
|
| 578 | - * if we have a generalSQL, lets used this one. |
|
| 579 | - * This needs to be improved... |
|
| 580 | - */ |
|
| 581 | - if ($this->generalSQL) { |
|
| 582 | - $sql = $this->generalSQL; |
|
| 583 | - $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
| 584 | - } else { |
|
| 585 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 586 | - } |
|
| 587 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 588 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 589 | - if ($criteria->groupby !== '') { |
|
| 590 | - $sql .= $criteria->getGroupby(); |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - $result = $this->db->query($sql); |
|
| 595 | - if (!$result) { |
|
| 596 | - return 0; |
|
| 597 | - } |
|
| 598 | - if ($groupby === false) { |
|
| 599 | - list($count) = $this->db->fetchRow($result); |
|
| 600 | - |
|
| 601 | - return $count; |
|
| 602 | - } else { |
|
| 603 | - $ret = array(); |
|
| 604 | - while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
| 605 | - $ret[$id] = $count; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - return $ret; |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * delete an object from the database |
|
| 614 | - * |
|
| 615 | - * @param XoopsObject $obj reference to the object to delete |
|
| 616 | - * @param bool $force |
|
| 617 | - * @return bool FALSE if failed. |
|
| 618 | - */ |
|
| 619 | - public function delete(XoopsObject $obj, $force = false) |
|
| 620 | - { |
|
| 621 | - $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
| 622 | - if (!$eventResult) { |
|
| 623 | - $obj->setErrors('An error occured during the BeforeDelete event'); |
|
| 624 | - |
|
| 625 | - return false; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - if (is_array($this->keyName)) { |
|
| 629 | - $clause = array(); |
|
| 630 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 631 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 632 | - } |
|
| 633 | - $whereclause = implode(' AND ', $clause); |
|
| 634 | - } else { |
|
| 635 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 636 | - } |
|
| 637 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 638 | - if (false !== $force) { |
|
| 639 | - $result = $this->db->queryF($sql); |
|
| 640 | - } else { |
|
| 641 | - $result = $this->db->query($sql); |
|
| 642 | - } |
|
| 643 | - if (!$result) { |
|
| 644 | - return false; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - $eventResult = $this->executeEvent('afterDelete', $obj); |
|
| 648 | - if (!$eventResult) { |
|
| 649 | - $obj->setErrors('An error occured during the AfterDelete event'); |
|
| 650 | - |
|
| 651 | - return false; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return true; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * @param $event |
|
| 659 | - */ |
|
| 660 | - public function disableEvent($event) |
|
| 661 | - { |
|
| 662 | - if (is_array($event)) { |
|
| 663 | - foreach ($event as $v) { |
|
| 664 | - $this->_disabledEvents[] = $v; |
|
| 665 | - } |
|
| 666 | - } else { |
|
| 667 | - $this->_disabledEvents[] = $event; |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * @return array |
|
| 673 | - */ |
|
| 674 | - public function getPermissions() |
|
| 675 | - { |
|
| 676 | - return $this->permissionsArray; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * insert a new object in the database |
|
| 681 | - * |
|
| 682 | - * @param XoopsObject $obj reference to the object |
|
| 683 | - * @param bool $force whether to force the query execution despite security settings |
|
| 684 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
| 685 | - * @param bool $debug |
|
| 686 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 687 | - */ |
|
| 688 | - public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
| 689 | - { |
|
| 690 | - if ($checkObject !== false) { |
|
| 691 | - if (!is_object($obj)) { |
|
| 692 | - return false; |
|
| 693 | - } |
|
| 694 | - /** |
|
| 695 | - * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
| 696 | - */ |
|
| 697 | - if (!is_a($obj, $this->className)) { |
|
| 698 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 699 | - |
|
| 700 | - return false; |
|
| 701 | - } |
|
| 702 | - if (!$obj->isDirty()) { |
|
| 703 | - $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 |
|
| 704 | - |
|
| 705 | - return true; |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - if ($obj->seoEnabled) { |
|
| 710 | - // Auto create meta tags if empty |
|
| 711 | - $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
| 712 | - |
|
| 713 | - if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
| 714 | - if (!$obj->meta_keywords()) { |
|
| 715 | - $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - if (!$obj->meta_description()) { |
|
| 719 | - $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - // Auto create short_url if empty |
|
| 724 | - if (!$obj->short_url()) { |
|
| 725 | - $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - $eventResult = $this->executeEvent('beforeSave', $obj); |
|
| 730 | - if (!$eventResult) { |
|
| 731 | - $obj->setErrors('An error occured during the BeforeSave event'); |
|
| 732 | - |
|
| 733 | - return false; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - if ($obj->isNew()) { |
|
| 737 | - $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
| 738 | - if (!$eventResult) { |
|
| 739 | - $obj->setErrors('An error occured during the BeforeInsert event'); |
|
| 740 | - |
|
| 741 | - return false; |
|
| 742 | - } |
|
| 743 | - } else { |
|
| 744 | - $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
| 745 | - if (!$eventResult) { |
|
| 746 | - $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
| 747 | - |
|
| 748 | - return false; |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - if (!$obj->cleanVars()) { |
|
| 752 | - $obj->setErrors('Variables were not cleaned properly.'); |
|
| 753 | - |
|
| 754 | - return false; |
|
| 755 | - } |
|
| 756 | - $fieldsToStoreInDB = array(); |
|
| 757 | - foreach ($obj->cleanVars as $k => $v) { |
|
| 758 | - if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
| 759 | - $cleanvars[$k] = (int)$v; |
|
| 760 | - } elseif (is_array($v)) { |
|
| 761 | - $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
| 762 | - } else { |
|
| 763 | - $cleanvars[$k] = $this->db->quoteString($v); |
|
| 764 | - } |
|
| 765 | - if ($obj->vars[$k]['persistent']) { |
|
| 766 | - $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - if ($obj->isNew()) { |
|
| 770 | - if (!is_array($this->keyName)) { |
|
| 771 | - if ($cleanvars[$this->keyName] < 1) { |
|
| 772 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 777 | - } else { |
|
| 778 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 779 | - foreach ($fieldsToStoreInDB as $key => $value) { |
|
| 780 | - if ((!is_array($this->keyName) && $key == $this->keyName) |
|
| 781 | - || (is_array($this->keyName) |
|
| 782 | - && in_array($key, $this->keyName))) { |
|
| 783 | - continue; |
|
| 784 | - } |
|
| 785 | - if (isset($notfirst)) { |
|
| 786 | - $sql .= ','; |
|
| 787 | - } |
|
| 788 | - $sql .= ' ' . $key . ' = ' . $value; |
|
| 789 | - $notfirst = true; |
|
| 790 | - } |
|
| 791 | - if (is_array($this->keyName)) { |
|
| 792 | - $whereclause = ''; |
|
| 793 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 794 | - if ($i > 0) { |
|
| 795 | - $whereclause .= ' AND '; |
|
| 796 | - } |
|
| 797 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 798 | - } |
|
| 799 | - } else { |
|
| 800 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 801 | - } |
|
| 802 | - $sql .= ' WHERE ' . $whereclause; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - if ($debug) { |
|
| 806 | - xoops_debug($sql); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if (false != $force) { |
|
| 810 | - $result = $this->db->queryF($sql); |
|
| 811 | - } else { |
|
| 812 | - $result = $this->db->query($sql); |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - if (!$result) { |
|
| 816 | - $obj->setErrors($this->db->error()); |
|
| 817 | - |
|
| 818 | - return false; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - if ($obj->isNew() && !is_array($this->keyName)) { |
|
| 822 | - $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
| 823 | - } |
|
| 824 | - $eventResult = $this->executeEvent('afterSave', $obj); |
|
| 825 | - if (!$eventResult) { |
|
| 826 | - $obj->setErrors('An error occured during the AfterSave event'); |
|
| 827 | - |
|
| 828 | - return false; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - if ($obj->isNew()) { |
|
| 832 | - $obj->unsetNew(); |
|
| 833 | - $eventResult = $this->executeEvent('afterInsert', $obj); |
|
| 834 | - if (!$eventResult) { |
|
| 835 | - $obj->setErrors('An error occured during the AfterInsert event'); |
|
| 836 | - |
|
| 837 | - return false; |
|
| 838 | - } |
|
| 839 | - } else { |
|
| 840 | - $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
| 841 | - if (!$eventResult) { |
|
| 842 | - $obj->setErrors('An error occured during the AfterUpdate event'); |
|
| 843 | - |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - return true; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * @param $obj |
|
| 853 | - * @param bool $force |
|
| 854 | - * @param bool $checkObject |
|
| 855 | - * @param bool $debug |
|
| 856 | - * @return bool |
|
| 857 | - */ |
|
| 858 | - public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
| 859 | - { |
|
| 860 | - return $this->insert($obj, $force, $checkObject, true); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Change a value for objects with a certain criteria |
|
| 865 | - * |
|
| 866 | - * @param string $fieldname Name of the field |
|
| 867 | - * @param string $fieldvalue Value to write |
|
| 868 | - * @param CriteriaElement $criteria {@link CriteriaElement} |
|
| 869 | - * |
|
| 870 | - * @param bool $force |
|
| 871 | - * @return bool |
|
| 872 | - */ |
|
| 873 | - public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
| 874 | - { |
|
| 875 | - $set_clause = $fieldname . ' = '; |
|
| 876 | - if (is_numeric($fieldvalue)) { |
|
| 877 | - $set_clause .= $fieldvalue; |
|
| 878 | - } elseif (is_array($fieldvalue)) { |
|
| 879 | - $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
| 880 | - } else { |
|
| 881 | - $set_clause .= $this->db->quoteString($fieldvalue); |
|
| 882 | - } |
|
| 883 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 884 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 885 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 886 | - } |
|
| 887 | - if (false != $force) { |
|
| 888 | - $result = $this->db->queryF($sql); |
|
| 889 | - } else { |
|
| 890 | - $result = $this->db->query($sql); |
|
| 891 | - } |
|
| 892 | - if (!$result) { |
|
| 893 | - return false; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - return true; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * delete all objects meeting the conditions |
|
| 901 | - * |
|
| 902 | - * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
| 903 | - * @return bool |
|
| 904 | - */ |
|
| 905 | - |
|
| 906 | - public function deleteAll(CriteriaElement $criteria = null) |
|
| 907 | - { |
|
| 908 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 909 | - $sql = 'DELETE FROM ' . $this->table; |
|
| 910 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 911 | - if (!$this->db->query($sql)) { |
|
| 912 | - return false; |
|
| 913 | - } |
|
| 914 | - $rows = $this->db->getAffectedRows(); |
|
| 915 | - |
|
| 916 | - return $rows > 0 ? $rows : true; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - return false; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - /** |
|
| 923 | - * @return mixed |
|
| 924 | - */ |
|
| 925 | - public function getModuleInfo() |
|
| 926 | - { |
|
| 927 | - return smart_getModuleInfo($this->_moduleName); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * @return bool |
|
| 932 | - */ |
|
| 933 | - public function getModuleConfig() |
|
| 934 | - { |
|
| 935 | - return smart_getModuleConfig($this->_moduleName); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * @return string |
|
| 940 | - */ |
|
| 941 | - public function getModuleItemString() |
|
| 942 | - { |
|
| 943 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 944 | - |
|
| 945 | - return $ret; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - /** |
|
| 949 | - * @param $object |
|
| 950 | - */ |
|
| 951 | - public function updateCounter($object) |
|
| 952 | - { |
|
| 953 | - if (isset($object->vars['counter'])) { |
|
| 954 | - $new_counter = $object->getVar('counter') + 1; |
|
| 955 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 956 | - $this->query($sql, null, true); |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - /** |
|
| 961 | - * Execute the function associated with an event |
|
| 962 | - * This method will check if the function is available |
|
| 963 | - * |
|
| 964 | - * @param string $event name of the event |
|
| 965 | - * @param $executeEventObj |
|
| 966 | - * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
| 967 | - * @internal param object $obj $object on which is performed the event |
|
| 968 | - */ |
|
| 969 | - public function executeEvent($event, &$executeEventObj) |
|
| 970 | - { |
|
| 971 | - if (!in_array($event, $this->_disabledEvents)) { |
|
| 972 | - if (method_exists($this, $event)) { |
|
| 973 | - $ret = $this->$event($executeEventObj); |
|
| 974 | - } else { |
|
| 975 | - // check to see if there is a hook for this event |
|
| 976 | - if (isset($this->_eventHooks[$event])) { |
|
| 977 | - $method = $this->_eventHooks[$event]; |
|
| 978 | - // check to see if the method specified by this hook exists |
|
| 979 | - if (method_exists($this, $method)) { |
|
| 980 | - $ret = $this->$method($executeEventObj); |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - $ret = true; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - return $ret; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - return true; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - /** |
|
| 993 | - * @param bool $withprefix |
|
| 994 | - * @return string |
|
| 995 | - */ |
|
| 996 | - public function getIdentifierName($withprefix = true) |
|
| 997 | - { |
|
| 998 | - if ($withprefix) { |
|
| 999 | - return $this->_itemname . '.' . $this->identifierName; |
|
| 1000 | - } else { |
|
| 1001 | - return $this->identifierName; |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 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 XoopsDatabase $db {@link XoopsDatabase} |
|
| 134 | + * @param string $itemname Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
| 135 | + * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
| 136 | + * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
| 137 | + * @param string $summaryName |
|
| 138 | + * @param string $modulename |
|
| 139 | + * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 140 | + * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 141 | + * @internal param string $moduleName name of the module |
|
| 142 | + */ |
|
| 143 | + public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
| 144 | + { |
|
| 145 | + parent::__construct($db); |
|
| 146 | + |
|
| 147 | + $this->_itemname = $itemname; |
|
| 148 | + $this->_moduleName = $modulename; |
|
| 149 | + $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 150 | + $this->keyName = $keyname; |
|
| 151 | + $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 152 | + $this->identifierName = $idenfierName; |
|
| 153 | + $this->summaryName = $summaryName; |
|
| 154 | + $this->_page = $itemname . '.php'; |
|
| 155 | + $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 156 | + $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 157 | + $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 158 | + $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param $event |
|
| 163 | + * @param $method |
|
| 164 | + */ |
|
| 165 | + public function addEventHook($event, $method) |
|
| 166 | + { |
|
| 167 | + $this->_eventHooks[$event] = $method; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Add a permission that this handler will manage for its objects |
|
| 172 | + * |
|
| 173 | + * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
| 174 | + * |
|
| 175 | + * @param string $perm_name name of the permission |
|
| 176 | + * @param string $caption caption of the control that will be displayed in the form |
|
| 177 | + * @param bool|string $description description of the control that will be displayed in the form |
|
| 178 | + */ |
|
| 179 | + public function addPermission($perm_name, $caption, $description = false) |
|
| 180 | + { |
|
| 181 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
|
| 182 | + |
|
| 183 | + $this->permissionsArray[] = array( |
|
| 184 | + 'perm_name' => $perm_name, |
|
| 185 | + 'caption' => $caption, |
|
| 186 | + 'description' => $description |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @param $criteria |
|
| 192 | + * @param $perm_name |
|
| 193 | + * @return bool |
|
| 194 | + */ |
|
| 195 | + public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
|
| 196 | + { |
|
| 197 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
| 198 | + $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 199 | + if (count($grantedItems) > 0) { |
|
| 200 | + $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 201 | + |
|
| 202 | + return true; |
|
| 203 | + } else { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param bool $_uploadPath |
|
| 210 | + * @param bool $_allowedMimeTypes |
|
| 211 | + * @param bool $_maxFileSize |
|
| 212 | + * @param bool $_maxWidth |
|
| 213 | + * @param bool $_maxHeight |
|
| 214 | + */ |
|
| 215 | + public function setUploaderConfig( |
|
| 216 | + $_uploadPath = false, |
|
| 217 | + $_allowedMimeTypes = false, |
|
| 218 | + $_maxFileSize = false, |
|
| 219 | + $_maxWidth = false, |
|
| 220 | + $_maxHeight = false |
|
| 221 | + ) { |
|
| 222 | + $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
| 223 | + $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
| 224 | + $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
| 225 | + $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
| 226 | + $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * create a new {@link SmartObject} |
|
| 231 | + * |
|
| 232 | + * @param bool $isNew Flag the new objects as "new"? |
|
| 233 | + * |
|
| 234 | + * @return SmartObject {@link SmartObject} |
|
| 235 | + */ |
|
| 236 | + public function create($isNew = true) |
|
| 237 | + { |
|
| 238 | + $obj = new $this->className($this); |
|
| 239 | + $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
| 240 | + if (!$obj->handler) { |
|
| 241 | + $obj->Handler = $this; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + if ($isNew === true) { |
|
| 245 | + $obj->setNew(); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + return $obj; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @return string |
|
| 253 | + */ |
|
| 254 | + public function getImageUrl() |
|
| 255 | + { |
|
| 256 | + return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function getImagePath() |
|
| 263 | + { |
|
| 264 | + $dir = $this->_uploadPath . $this->_itemname; |
|
| 265 | + if (!file_exists($dir)) { |
|
| 266 | + smart_admin_mkdir($dir); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + return $dir . '/'; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * retrieve a {@link SmartObject} |
|
| 274 | + * |
|
| 275 | + * @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 |
|
| 276 | + * @param bool $as_object whether to return an object or an array |
|
| 277 | + * @param bool $debug |
|
| 278 | + * @param bool $criteria |
|
| 279 | + * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
| 280 | + * FALSE if failed |
|
| 281 | + */ |
|
| 282 | + public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
| 283 | + { |
|
| 284 | + if (!$criteria) { |
|
| 285 | + $criteria = new CriteriaCompo(); |
|
| 286 | + } |
|
| 287 | + if (is_array($this->keyName)) { |
|
| 288 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 289 | + /** |
|
| 290 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 291 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
| 292 | + */ |
|
| 293 | + //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
| 294 | + $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
| 295 | + } |
|
| 296 | + } else { |
|
| 297 | + //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
| 298 | + /** |
|
| 299 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 300 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
| 301 | + */ |
|
| 302 | + $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
| 303 | + } |
|
| 304 | + $criteria->setLimit(1); |
|
| 305 | + if ($debug) { |
|
| 306 | + $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
| 307 | + } else { |
|
| 308 | + $obj_array = $this->getObjects($criteria, false, $as_object); |
|
| 309 | + //patch: weird bug of indexing by id even if id_as_key = false; |
|
| 310 | + if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
| 311 | + $obj_array[0] = $obj_array[$id]; |
|
| 312 | + unset($obj_array[$id]); |
|
| 313 | + $obj_array[0]->unsetNew(); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + if (count($obj_array) != 1) { |
|
| 318 | + $obj = $this->create(); |
|
| 319 | + |
|
| 320 | + return $obj; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + return $obj_array[0]; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * retrieve a {@link SmartObject} |
|
| 328 | + * |
|
| 329 | + * @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 |
|
| 330 | + * @param bool $as_object whether to return an object or an array |
|
| 331 | + * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
| 332 | + */ |
|
| 333 | + public function &getD($id, $as_object = true) |
|
| 334 | + { |
|
| 335 | + return $this->get($id, $as_object, true); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * retrieve objects from the database |
|
| 340 | + * |
|
| 341 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 342 | + * @param bool $id_as_key use the ID as key for the array? |
|
| 343 | + * @param bool $as_object return an array of objects? |
|
| 344 | + * |
|
| 345 | + * @param bool $sql |
|
| 346 | + * @param bool $debug |
|
| 347 | + * @return array |
|
| 348 | + */ |
|
| 349 | + public function getObjects( |
|
| 350 | + CriteriaElement $criteria = null, |
|
| 351 | + $id_as_key = false, |
|
| 352 | + $as_object = true, |
|
| 353 | + $sql = false, |
|
| 354 | + $debug = false |
|
| 355 | + ) { |
|
| 356 | + $ret = array(); |
|
| 357 | + $limit = $start = 0; |
|
| 358 | + |
|
| 359 | + if ($this->generalSQL) { |
|
| 360 | + $sql = $this->generalSQL; |
|
| 361 | + } elseif (!$sql) { |
|
| 362 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 366 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 367 | + if ($criteria->getSort() !== '') { |
|
| 368 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 369 | + } |
|
| 370 | + $limit = $criteria->getLimit(); |
|
| 371 | + $start = $criteria->getStart(); |
|
| 372 | + } |
|
| 373 | + if ($debug) { |
|
| 374 | + xoops_debug($sql); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + $result = $this->db->query($sql, $limit, $start); |
|
| 378 | + if (!$result) { |
|
| 379 | + return $ret; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + return $this->convertResultSet($result, $id_as_key, $as_object); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @param $sql |
|
| 387 | + * @param $criteria |
|
| 388 | + * @param bool $force |
|
| 389 | + * @param bool $debug |
|
| 390 | + * @return array |
|
| 391 | + */ |
|
| 392 | + public function query($sql, $criteria, $force = false, $debug = false) |
|
| 393 | + { |
|
| 394 | + $ret = array(); |
|
| 395 | + |
|
| 396 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 397 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 398 | + if ($criteria->groupby) { |
|
| 399 | + $sql .= $criteria->getGroupby(); |
|
| 400 | + } |
|
| 401 | + if ($criteria->getSort() !== '') { |
|
| 402 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + if ($debug) { |
|
| 406 | + xoops_debug($sql); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + if ($force) { |
|
| 410 | + $result = $this->db->queryF($sql); |
|
| 411 | + } else { |
|
| 412 | + $result = $this->db->query($sql); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + if (!$result) { |
|
| 416 | + return $ret; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 420 | + $ret[] = $myrow; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $ret; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * retrieve objects with debug mode - so will show the query |
|
| 428 | + * |
|
| 429 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 430 | + * @param bool $id_as_key use the ID as key for the array? |
|
| 431 | + * @param bool $as_object return an array of objects? |
|
| 432 | + * |
|
| 433 | + * @param bool $sql |
|
| 434 | + * @return array |
|
| 435 | + */ |
|
| 436 | + public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
| 437 | + { |
|
| 438 | + return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @param $arrayObjects |
|
| 443 | + * @return array|bool |
|
| 444 | + */ |
|
| 445 | + public function getObjectsAsArray($arrayObjects) |
|
| 446 | + { |
|
| 447 | + $ret = array(); |
|
| 448 | + foreach ($arrayObjects as $key => $object) { |
|
| 449 | + $ret[$key] = $object->toArray(); |
|
| 450 | + } |
|
| 451 | + if (count($ret > 0)) { |
|
| 452 | + return $ret; |
|
| 453 | + } else { |
|
| 454 | + return false; |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Convert a database resultset to a returnable array |
|
| 460 | + * |
|
| 461 | + * @param object $result database resultset |
|
| 462 | + * @param bool $id_as_key - should NOT be used with joint keys |
|
| 463 | + * @param bool $as_object |
|
| 464 | + * |
|
| 465 | + * @return array |
|
| 466 | + */ |
|
| 467 | + public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
| 468 | + { |
|
| 469 | + $ret = array(); |
|
| 470 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 471 | + $obj = $this->create(false); |
|
| 472 | + $obj->assignVars($myrow); |
|
| 473 | + if (!$id_as_key) { |
|
| 474 | + if ($as_object) { |
|
| 475 | + $ret[] =& $obj; |
|
| 476 | + } else { |
|
| 477 | + $ret[] = $obj->toArray(); |
|
| 478 | + } |
|
| 479 | + } else { |
|
| 480 | + if ($as_object) { |
|
| 481 | + $value =& $obj; |
|
| 482 | + } else { |
|
| 483 | + $value = $obj->toArray(); |
|
| 484 | + } |
|
| 485 | + if ($id_as_key === 'parentid') { |
|
| 486 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 487 | + } else { |
|
| 488 | + $ret[$obj->getVar($this->keyName)] = $value; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + unset($obj); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $ret; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * @param null $criteria |
|
| 499 | + * @param int $limit |
|
| 500 | + * @param int $start |
|
| 501 | + * @return array |
|
| 502 | + */ |
|
| 503 | + public function getListD($criteria = null, $limit = 0, $start = 0) |
|
| 504 | + { |
|
| 505 | + return $this->getList($criteria, $limit, $start, true); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
| 510 | + * |
|
| 511 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 512 | + * @param int $limit Max number of objects to fetch |
|
| 513 | + * @param int $start Which record to start at |
|
| 514 | + * |
|
| 515 | + * @param bool $debug |
|
| 516 | + * @return array |
|
| 517 | + */ |
|
| 518 | + public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
| 519 | + { |
|
| 520 | + $ret = array(); |
|
| 521 | + if ($criteria === null) { |
|
| 522 | + $criteria = new CriteriaCompo(); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + if ($criteria->getSort() === '') { |
|
| 526 | + $criteria->setSort($this->getIdentifierName()); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 530 | + if (!empty($this->identifierName)) { |
|
| 531 | + $sql .= ', ' . $this->getIdentifierName(); |
|
| 532 | + } |
|
| 533 | + $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 534 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 535 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 536 | + if ($criteria->getSort() !== '') { |
|
| 537 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 538 | + } |
|
| 539 | + $limit = $criteria->getLimit(); |
|
| 540 | + $start = $criteria->getStart(); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + if ($debug) { |
|
| 544 | + xoops_debug($sql); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + $result = $this->db->query($sql, $limit, $start); |
|
| 548 | + if (!$result) { |
|
| 549 | + return $ret; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + $myts = MyTextSanitizer::getInstance(); |
|
| 553 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 554 | + //identifiers should be textboxes, so sanitize them like that |
|
| 555 | + $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + return $ret; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * count objects matching a condition |
|
| 563 | + * |
|
| 564 | + * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
| 565 | + * @return int count of objects |
|
| 566 | + */ |
|
| 567 | + public function getCount(CriteriaElement $criteria = null) |
|
| 568 | + { |
|
| 569 | + $field = ''; |
|
| 570 | + $groupby = false; |
|
| 571 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 572 | + if ($criteria->groupby !== '') { |
|
| 573 | + $groupby = true; |
|
| 574 | + $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + /** |
|
| 578 | + * if we have a generalSQL, lets used this one. |
|
| 579 | + * This needs to be improved... |
|
| 580 | + */ |
|
| 581 | + if ($this->generalSQL) { |
|
| 582 | + $sql = $this->generalSQL; |
|
| 583 | + $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
| 584 | + } else { |
|
| 585 | + $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 586 | + } |
|
| 587 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 588 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 589 | + if ($criteria->groupby !== '') { |
|
| 590 | + $sql .= $criteria->getGroupby(); |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + $result = $this->db->query($sql); |
|
| 595 | + if (!$result) { |
|
| 596 | + return 0; |
|
| 597 | + } |
|
| 598 | + if ($groupby === false) { |
|
| 599 | + list($count) = $this->db->fetchRow($result); |
|
| 600 | + |
|
| 601 | + return $count; |
|
| 602 | + } else { |
|
| 603 | + $ret = array(); |
|
| 604 | + while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
| 605 | + $ret[$id] = $count; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + return $ret; |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * delete an object from the database |
|
| 614 | + * |
|
| 615 | + * @param XoopsObject $obj reference to the object to delete |
|
| 616 | + * @param bool $force |
|
| 617 | + * @return bool FALSE if failed. |
|
| 618 | + */ |
|
| 619 | + public function delete(XoopsObject $obj, $force = false) |
|
| 620 | + { |
|
| 621 | + $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
| 622 | + if (!$eventResult) { |
|
| 623 | + $obj->setErrors('An error occured during the BeforeDelete event'); |
|
| 624 | + |
|
| 625 | + return false; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + if (is_array($this->keyName)) { |
|
| 629 | + $clause = array(); |
|
| 630 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 631 | + $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 632 | + } |
|
| 633 | + $whereclause = implode(' AND ', $clause); |
|
| 634 | + } else { |
|
| 635 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 636 | + } |
|
| 637 | + $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 638 | + if (false !== $force) { |
|
| 639 | + $result = $this->db->queryF($sql); |
|
| 640 | + } else { |
|
| 641 | + $result = $this->db->query($sql); |
|
| 642 | + } |
|
| 643 | + if (!$result) { |
|
| 644 | + return false; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + $eventResult = $this->executeEvent('afterDelete', $obj); |
|
| 648 | + if (!$eventResult) { |
|
| 649 | + $obj->setErrors('An error occured during the AfterDelete event'); |
|
| 650 | + |
|
| 651 | + return false; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return true; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * @param $event |
|
| 659 | + */ |
|
| 660 | + public function disableEvent($event) |
|
| 661 | + { |
|
| 662 | + if (is_array($event)) { |
|
| 663 | + foreach ($event as $v) { |
|
| 664 | + $this->_disabledEvents[] = $v; |
|
| 665 | + } |
|
| 666 | + } else { |
|
| 667 | + $this->_disabledEvents[] = $event; |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * @return array |
|
| 673 | + */ |
|
| 674 | + public function getPermissions() |
|
| 675 | + { |
|
| 676 | + return $this->permissionsArray; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * insert a new object in the database |
|
| 681 | + * |
|
| 682 | + * @param XoopsObject $obj reference to the object |
|
| 683 | + * @param bool $force whether to force the query execution despite security settings |
|
| 684 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
| 685 | + * @param bool $debug |
|
| 686 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 687 | + */ |
|
| 688 | + public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
| 689 | + { |
|
| 690 | + if ($checkObject !== false) { |
|
| 691 | + if (!is_object($obj)) { |
|
| 692 | + return false; |
|
| 693 | + } |
|
| 694 | + /** |
|
| 695 | + * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
| 696 | + */ |
|
| 697 | + if (!is_a($obj, $this->className)) { |
|
| 698 | + $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 699 | + |
|
| 700 | + return false; |
|
| 701 | + } |
|
| 702 | + if (!$obj->isDirty()) { |
|
| 703 | + $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 |
|
| 704 | + |
|
| 705 | + return true; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + if ($obj->seoEnabled) { |
|
| 710 | + // Auto create meta tags if empty |
|
| 711 | + $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
| 712 | + |
|
| 713 | + if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
| 714 | + if (!$obj->meta_keywords()) { |
|
| 715 | + $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + if (!$obj->meta_description()) { |
|
| 719 | + $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + // Auto create short_url if empty |
|
| 724 | + if (!$obj->short_url()) { |
|
| 725 | + $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + $eventResult = $this->executeEvent('beforeSave', $obj); |
|
| 730 | + if (!$eventResult) { |
|
| 731 | + $obj->setErrors('An error occured during the BeforeSave event'); |
|
| 732 | + |
|
| 733 | + return false; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + if ($obj->isNew()) { |
|
| 737 | + $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
| 738 | + if (!$eventResult) { |
|
| 739 | + $obj->setErrors('An error occured during the BeforeInsert event'); |
|
| 740 | + |
|
| 741 | + return false; |
|
| 742 | + } |
|
| 743 | + } else { |
|
| 744 | + $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
| 745 | + if (!$eventResult) { |
|
| 746 | + $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
| 747 | + |
|
| 748 | + return false; |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + if (!$obj->cleanVars()) { |
|
| 752 | + $obj->setErrors('Variables were not cleaned properly.'); |
|
| 753 | + |
|
| 754 | + return false; |
|
| 755 | + } |
|
| 756 | + $fieldsToStoreInDB = array(); |
|
| 757 | + foreach ($obj->cleanVars as $k => $v) { |
|
| 758 | + if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
| 759 | + $cleanvars[$k] = (int)$v; |
|
| 760 | + } elseif (is_array($v)) { |
|
| 761 | + $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
| 762 | + } else { |
|
| 763 | + $cleanvars[$k] = $this->db->quoteString($v); |
|
| 764 | + } |
|
| 765 | + if ($obj->vars[$k]['persistent']) { |
|
| 766 | + $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + if ($obj->isNew()) { |
|
| 770 | + if (!is_array($this->keyName)) { |
|
| 771 | + if ($cleanvars[$this->keyName] < 1) { |
|
| 772 | + $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 777 | + } else { |
|
| 778 | + $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 779 | + foreach ($fieldsToStoreInDB as $key => $value) { |
|
| 780 | + if ((!is_array($this->keyName) && $key == $this->keyName) |
|
| 781 | + || (is_array($this->keyName) |
|
| 782 | + && in_array($key, $this->keyName))) { |
|
| 783 | + continue; |
|
| 784 | + } |
|
| 785 | + if (isset($notfirst)) { |
|
| 786 | + $sql .= ','; |
|
| 787 | + } |
|
| 788 | + $sql .= ' ' . $key . ' = ' . $value; |
|
| 789 | + $notfirst = true; |
|
| 790 | + } |
|
| 791 | + if (is_array($this->keyName)) { |
|
| 792 | + $whereclause = ''; |
|
| 793 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 794 | + if ($i > 0) { |
|
| 795 | + $whereclause .= ' AND '; |
|
| 796 | + } |
|
| 797 | + $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 798 | + } |
|
| 799 | + } else { |
|
| 800 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 801 | + } |
|
| 802 | + $sql .= ' WHERE ' . $whereclause; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + if ($debug) { |
|
| 806 | + xoops_debug($sql); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if (false != $force) { |
|
| 810 | + $result = $this->db->queryF($sql); |
|
| 811 | + } else { |
|
| 812 | + $result = $this->db->query($sql); |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + if (!$result) { |
|
| 816 | + $obj->setErrors($this->db->error()); |
|
| 817 | + |
|
| 818 | + return false; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + if ($obj->isNew() && !is_array($this->keyName)) { |
|
| 822 | + $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
| 823 | + } |
|
| 824 | + $eventResult = $this->executeEvent('afterSave', $obj); |
|
| 825 | + if (!$eventResult) { |
|
| 826 | + $obj->setErrors('An error occured during the AfterSave event'); |
|
| 827 | + |
|
| 828 | + return false; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + if ($obj->isNew()) { |
|
| 832 | + $obj->unsetNew(); |
|
| 833 | + $eventResult = $this->executeEvent('afterInsert', $obj); |
|
| 834 | + if (!$eventResult) { |
|
| 835 | + $obj->setErrors('An error occured during the AfterInsert event'); |
|
| 836 | + |
|
| 837 | + return false; |
|
| 838 | + } |
|
| 839 | + } else { |
|
| 840 | + $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
| 841 | + if (!$eventResult) { |
|
| 842 | + $obj->setErrors('An error occured during the AfterUpdate event'); |
|
| 843 | + |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + return true; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * @param $obj |
|
| 853 | + * @param bool $force |
|
| 854 | + * @param bool $checkObject |
|
| 855 | + * @param bool $debug |
|
| 856 | + * @return bool |
|
| 857 | + */ |
|
| 858 | + public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
| 859 | + { |
|
| 860 | + return $this->insert($obj, $force, $checkObject, true); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Change a value for objects with a certain criteria |
|
| 865 | + * |
|
| 866 | + * @param string $fieldname Name of the field |
|
| 867 | + * @param string $fieldvalue Value to write |
|
| 868 | + * @param CriteriaElement $criteria {@link CriteriaElement} |
|
| 869 | + * |
|
| 870 | + * @param bool $force |
|
| 871 | + * @return bool |
|
| 872 | + */ |
|
| 873 | + public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
| 874 | + { |
|
| 875 | + $set_clause = $fieldname . ' = '; |
|
| 876 | + if (is_numeric($fieldvalue)) { |
|
| 877 | + $set_clause .= $fieldvalue; |
|
| 878 | + } elseif (is_array($fieldvalue)) { |
|
| 879 | + $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
| 880 | + } else { |
|
| 881 | + $set_clause .= $this->db->quoteString($fieldvalue); |
|
| 882 | + } |
|
| 883 | + $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 884 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 885 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 886 | + } |
|
| 887 | + if (false != $force) { |
|
| 888 | + $result = $this->db->queryF($sql); |
|
| 889 | + } else { |
|
| 890 | + $result = $this->db->query($sql); |
|
| 891 | + } |
|
| 892 | + if (!$result) { |
|
| 893 | + return false; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + return true; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * delete all objects meeting the conditions |
|
| 901 | + * |
|
| 902 | + * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
| 903 | + * @return bool |
|
| 904 | + */ |
|
| 905 | + |
|
| 906 | + public function deleteAll(CriteriaElement $criteria = null) |
|
| 907 | + { |
|
| 908 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 909 | + $sql = 'DELETE FROM ' . $this->table; |
|
| 910 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 911 | + if (!$this->db->query($sql)) { |
|
| 912 | + return false; |
|
| 913 | + } |
|
| 914 | + $rows = $this->db->getAffectedRows(); |
|
| 915 | + |
|
| 916 | + return $rows > 0 ? $rows : true; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + return false; |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + /** |
|
| 923 | + * @return mixed |
|
| 924 | + */ |
|
| 925 | + public function getModuleInfo() |
|
| 926 | + { |
|
| 927 | + return smart_getModuleInfo($this->_moduleName); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * @return bool |
|
| 932 | + */ |
|
| 933 | + public function getModuleConfig() |
|
| 934 | + { |
|
| 935 | + return smart_getModuleConfig($this->_moduleName); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * @return string |
|
| 940 | + */ |
|
| 941 | + public function getModuleItemString() |
|
| 942 | + { |
|
| 943 | + $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 944 | + |
|
| 945 | + return $ret; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + /** |
|
| 949 | + * @param $object |
|
| 950 | + */ |
|
| 951 | + public function updateCounter($object) |
|
| 952 | + { |
|
| 953 | + if (isset($object->vars['counter'])) { |
|
| 954 | + $new_counter = $object->getVar('counter') + 1; |
|
| 955 | + $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 956 | + $this->query($sql, null, true); |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + /** |
|
| 961 | + * Execute the function associated with an event |
|
| 962 | + * This method will check if the function is available |
|
| 963 | + * |
|
| 964 | + * @param string $event name of the event |
|
| 965 | + * @param $executeEventObj |
|
| 966 | + * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
| 967 | + * @internal param object $obj $object on which is performed the event |
|
| 968 | + */ |
|
| 969 | + public function executeEvent($event, &$executeEventObj) |
|
| 970 | + { |
|
| 971 | + if (!in_array($event, $this->_disabledEvents)) { |
|
| 972 | + if (method_exists($this, $event)) { |
|
| 973 | + $ret = $this->$event($executeEventObj); |
|
| 974 | + } else { |
|
| 975 | + // check to see if there is a hook for this event |
|
| 976 | + if (isset($this->_eventHooks[$event])) { |
|
| 977 | + $method = $this->_eventHooks[$event]; |
|
| 978 | + // check to see if the method specified by this hook exists |
|
| 979 | + if (method_exists($this, $method)) { |
|
| 980 | + $ret = $this->$method($executeEventObj); |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + $ret = true; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + return $ret; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + return true; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + /** |
|
| 993 | + * @param bool $withprefix |
|
| 994 | + * @return string |
|
| 995 | + */ |
|
| 996 | + public function getIdentifierName($withprefix = true) |
|
| 997 | + { |
|
| 998 | + if ($withprefix) { |
|
| 999 | + return $this->_itemname . '.' . $this->identifierName; |
|
| 1000 | + } else { |
|
| 1001 | + return $this->identifierName; |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | 1004 | } |
@@ -19,165 +19,165 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class SmartobjectAbout |
| 21 | 21 | { |
| 22 | - public $_lang_aboutTitle; |
|
| 23 | - public $_lang_author_info; |
|
| 24 | - public $_lang_developer_lead; |
|
| 25 | - public $_lang_developer_contributor; |
|
| 26 | - public $_lang_developer_website; |
|
| 27 | - public $_lang_developer_email; |
|
| 28 | - public $_lang_developer_credits; |
|
| 29 | - public $_lang_module_info; |
|
| 30 | - public $_lang_module_status; |
|
| 31 | - public $_lang_module_release_date; |
|
| 32 | - public $_lang_module_demo; |
|
| 33 | - public $_lang_module_support; |
|
| 34 | - public $_lang_module_bug; |
|
| 35 | - public $_lang_module_submit_bug; |
|
| 36 | - public $_lang_module_feature; |
|
| 37 | - public $_lang_module_submit_feature; |
|
| 38 | - public $_lang_module_disclaimer; |
|
| 39 | - public $_lang_author_word; |
|
| 40 | - public $_lang_version_history; |
|
| 41 | - public $_lang_by; |
|
| 42 | - public $_tpl; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * SmartobjectAbout constructor. |
|
| 46 | - * @param string $aboutTitle |
|
| 47 | - */ |
|
| 48 | - public function __construct($aboutTitle = 'About') |
|
| 49 | - { |
|
| 50 | - global $xoopsModule, $xoopsConfig; |
|
| 51 | - |
|
| 52 | - $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
|
| 53 | - if (file_exists($fileName)) { |
|
| 54 | - require_once $fileName; |
|
| 55 | - } else { |
|
| 56 | - require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
| 57 | - } |
|
| 58 | - $this->_aboutTitle = $aboutTitle; |
|
| 59 | - |
|
| 60 | - $this->_lang_developer_contributor = _CO_SOBJECT_DEVELOPER_CONTRIBUTOR; |
|
| 61 | - $this->_lang_developer_website = _CO_SOBJECT_DEVELOPER_WEBSITE; |
|
| 62 | - $this->_lang_developer_email = _CO_SOBJECT_DEVELOPER_EMAIL; |
|
| 63 | - $this->_lang_developer_credits = _CO_SOBJECT_DEVELOPER_CREDITS; |
|
| 64 | - $this->_lang_module_info = _CO_SOBJECT_MODULE_INFO; |
|
| 65 | - $this->_lang_module_status = _CO_SOBJECT_MODULE_STATUS; |
|
| 66 | - $this->_lang_module_release_date = _CO_SOBJECT_MODULE_RELEASE_DATE; |
|
| 67 | - $this->_lang_module_demo = _CO_SOBJECT_MODULE_DEMO; |
|
| 68 | - $this->_lang_module_support = _CO_SOBJECT_MODULE_SUPPORT; |
|
| 69 | - $this->_lang_module_bug = _CO_SOBJECT_MODULE_BUG; |
|
| 70 | - $this->_lang_module_submit_bug = _CO_SOBJECT_MODULE_SUBMIT_BUG; |
|
| 71 | - $this->_lang_module_feature = _CO_SOBJECT_MODULE_FEATURE; |
|
| 72 | - $this->_lang_module_submit_feature = _CO_SOBJECT_MODULE_SUBMIT_FEATURE; |
|
| 73 | - $this->_lang_module_disclaimer = _CO_SOBJECT_MODULE_DISCLAIMER; |
|
| 74 | - $this->_lang_author_word = _CO_SOBJECT_AUTHOR_WORD; |
|
| 75 | - $this->_lang_version_history = _CO_SOBJECT_VERSION_HISTORY; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param $value |
|
| 80 | - * @return mixed |
|
| 81 | - */ |
|
| 82 | - public function sanitize($value) |
|
| 83 | - { |
|
| 84 | - $myts = MyTextSanitizer::getInstance(); |
|
| 85 | - |
|
| 86 | - return $myts->displayTarea($value, 1); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function render() |
|
| 90 | - { |
|
| 91 | - /** |
|
| 92 | - * @todo move the output to a template |
|
| 93 | - * @todo make the output XHTML compliant |
|
| 94 | - */ |
|
| 95 | - |
|
| 96 | - $myts = MyTextSanitizer::getInstance(); |
|
| 97 | - |
|
| 98 | - global $xoopsModule; |
|
| 99 | - |
|
| 100 | - smart_xoops_cp_header(); |
|
| 101 | - |
|
| 102 | - /** @var XoopsModuleHandler $moduleHandler */ |
|
| 103 | - $moduleHandler = xoops_getHandler('module'); |
|
| 104 | - $versioninfo = $moduleHandler->get($xoopsModule->getVar('mid')); |
|
| 105 | - |
|
| 106 | - //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
|
| 107 | - |
|
| 108 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 109 | - |
|
| 110 | - // --- |
|
| 111 | - // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
| 112 | - // $this->_tpl = new XoopsTpl(); |
|
| 113 | - $this->_tpl = new XoopsTpl(); |
|
| 114 | - // --- |
|
| 115 | - |
|
| 116 | - $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
| 117 | - $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
|
| 118 | - $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
|
| 119 | - $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
|
| 120 | - $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version')); |
|
| 121 | - |
|
| 122 | - // Left headings... |
|
| 123 | - if ($versioninfo->getInfo('author_realname') !== '') { |
|
| 124 | - $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
| 125 | - } else { |
|
| 126 | - $author_name = $versioninfo->getInfo('author'); |
|
| 127 | - } |
|
| 128 | - $this->_tpl->assign('module_author_name', $author_name); |
|
| 129 | - |
|
| 130 | - $this->_tpl->assign('module_license', $versioninfo->getInfo('license')); |
|
| 131 | - |
|
| 132 | - $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits')); |
|
| 133 | - |
|
| 134 | - // Developers Information |
|
| 135 | - $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead')); |
|
| 136 | - $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor')); |
|
| 137 | - $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url')); |
|
| 138 | - $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name')); |
|
| 139 | - $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email')); |
|
| 140 | - |
|
| 141 | - $people = $versioninfo->getInfo('people'); |
|
| 142 | - if ($people) { |
|
| 143 | - $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map(array($this, 'sanitize'), $people['developers']) : false); |
|
| 144 | - $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map(array($this, 'sanitize'), $people['testers']) : false); |
|
| 145 | - $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map(array($this, 'sanitize'), $people['translators']) : false); |
|
| 146 | - $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map(array($this, 'sanitize'), $people['documenters']) : false); |
|
| 147 | - $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map(array($this, 'sanitize'), $people['other']) : false); |
|
| 148 | - } |
|
| 149 | - //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email')); |
|
| 150 | - |
|
| 151 | - // Module Development information |
|
| 152 | - $this->_tpl->assign('module_date', $versioninfo->getInfo('date')); |
|
| 153 | - $this->_tpl->assign('module_status', $versioninfo->getInfo('status')); |
|
| 154 | - $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url')); |
|
| 155 | - $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name')); |
|
| 156 | - $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url')); |
|
| 157 | - $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name')); |
|
| 158 | - $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug')); |
|
| 159 | - $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature')); |
|
| 160 | - |
|
| 161 | - // Warning |
|
| 162 | - $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning'))); |
|
| 163 | - |
|
| 164 | - // Author's note |
|
| 165 | - $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
|
| 166 | - |
|
| 167 | - // For changelog thanks to 3Dev |
|
| 168 | - global $xoopsModule; |
|
| 169 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
| 170 | - if (is_file($filename)) { |
|
| 171 | - $filesize = filesize($filename); |
|
| 172 | - $handle = fopen($filename, 'r'); |
|
| 173 | - $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
| 174 | - fclose($handle); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $this->_tpl->display('db:smartobject_about.tpl'); |
|
| 178 | - |
|
| 179 | - smart_modFooter(); |
|
| 180 | - |
|
| 181 | - xoops_cp_footer(); |
|
| 182 | - } |
|
| 22 | + public $_lang_aboutTitle; |
|
| 23 | + public $_lang_author_info; |
|
| 24 | + public $_lang_developer_lead; |
|
| 25 | + public $_lang_developer_contributor; |
|
| 26 | + public $_lang_developer_website; |
|
| 27 | + public $_lang_developer_email; |
|
| 28 | + public $_lang_developer_credits; |
|
| 29 | + public $_lang_module_info; |
|
| 30 | + public $_lang_module_status; |
|
| 31 | + public $_lang_module_release_date; |
|
| 32 | + public $_lang_module_demo; |
|
| 33 | + public $_lang_module_support; |
|
| 34 | + public $_lang_module_bug; |
|
| 35 | + public $_lang_module_submit_bug; |
|
| 36 | + public $_lang_module_feature; |
|
| 37 | + public $_lang_module_submit_feature; |
|
| 38 | + public $_lang_module_disclaimer; |
|
| 39 | + public $_lang_author_word; |
|
| 40 | + public $_lang_version_history; |
|
| 41 | + public $_lang_by; |
|
| 42 | + public $_tpl; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * SmartobjectAbout constructor. |
|
| 46 | + * @param string $aboutTitle |
|
| 47 | + */ |
|
| 48 | + public function __construct($aboutTitle = 'About') |
|
| 49 | + { |
|
| 50 | + global $xoopsModule, $xoopsConfig; |
|
| 51 | + |
|
| 52 | + $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
|
| 53 | + if (file_exists($fileName)) { |
|
| 54 | + require_once $fileName; |
|
| 55 | + } else { |
|
| 56 | + require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
| 57 | + } |
|
| 58 | + $this->_aboutTitle = $aboutTitle; |
|
| 59 | + |
|
| 60 | + $this->_lang_developer_contributor = _CO_SOBJECT_DEVELOPER_CONTRIBUTOR; |
|
| 61 | + $this->_lang_developer_website = _CO_SOBJECT_DEVELOPER_WEBSITE; |
|
| 62 | + $this->_lang_developer_email = _CO_SOBJECT_DEVELOPER_EMAIL; |
|
| 63 | + $this->_lang_developer_credits = _CO_SOBJECT_DEVELOPER_CREDITS; |
|
| 64 | + $this->_lang_module_info = _CO_SOBJECT_MODULE_INFO; |
|
| 65 | + $this->_lang_module_status = _CO_SOBJECT_MODULE_STATUS; |
|
| 66 | + $this->_lang_module_release_date = _CO_SOBJECT_MODULE_RELEASE_DATE; |
|
| 67 | + $this->_lang_module_demo = _CO_SOBJECT_MODULE_DEMO; |
|
| 68 | + $this->_lang_module_support = _CO_SOBJECT_MODULE_SUPPORT; |
|
| 69 | + $this->_lang_module_bug = _CO_SOBJECT_MODULE_BUG; |
|
| 70 | + $this->_lang_module_submit_bug = _CO_SOBJECT_MODULE_SUBMIT_BUG; |
|
| 71 | + $this->_lang_module_feature = _CO_SOBJECT_MODULE_FEATURE; |
|
| 72 | + $this->_lang_module_submit_feature = _CO_SOBJECT_MODULE_SUBMIT_FEATURE; |
|
| 73 | + $this->_lang_module_disclaimer = _CO_SOBJECT_MODULE_DISCLAIMER; |
|
| 74 | + $this->_lang_author_word = _CO_SOBJECT_AUTHOR_WORD; |
|
| 75 | + $this->_lang_version_history = _CO_SOBJECT_VERSION_HISTORY; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param $value |
|
| 80 | + * @return mixed |
|
| 81 | + */ |
|
| 82 | + public function sanitize($value) |
|
| 83 | + { |
|
| 84 | + $myts = MyTextSanitizer::getInstance(); |
|
| 85 | + |
|
| 86 | + return $myts->displayTarea($value, 1); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function render() |
|
| 90 | + { |
|
| 91 | + /** |
|
| 92 | + * @todo move the output to a template |
|
| 93 | + * @todo make the output XHTML compliant |
|
| 94 | + */ |
|
| 95 | + |
|
| 96 | + $myts = MyTextSanitizer::getInstance(); |
|
| 97 | + |
|
| 98 | + global $xoopsModule; |
|
| 99 | + |
|
| 100 | + smart_xoops_cp_header(); |
|
| 101 | + |
|
| 102 | + /** @var XoopsModuleHandler $moduleHandler */ |
|
| 103 | + $moduleHandler = xoops_getHandler('module'); |
|
| 104 | + $versioninfo = $moduleHandler->get($xoopsModule->getVar('mid')); |
|
| 105 | + |
|
| 106 | + //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
|
| 107 | + |
|
| 108 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 109 | + |
|
| 110 | + // --- |
|
| 111 | + // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
| 112 | + // $this->_tpl = new XoopsTpl(); |
|
| 113 | + $this->_tpl = new XoopsTpl(); |
|
| 114 | + // --- |
|
| 115 | + |
|
| 116 | + $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
| 117 | + $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
|
| 118 | + $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
|
| 119 | + $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
|
| 120 | + $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version')); |
|
| 121 | + |
|
| 122 | + // Left headings... |
|
| 123 | + if ($versioninfo->getInfo('author_realname') !== '') { |
|
| 124 | + $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
| 125 | + } else { |
|
| 126 | + $author_name = $versioninfo->getInfo('author'); |
|
| 127 | + } |
|
| 128 | + $this->_tpl->assign('module_author_name', $author_name); |
|
| 129 | + |
|
| 130 | + $this->_tpl->assign('module_license', $versioninfo->getInfo('license')); |
|
| 131 | + |
|
| 132 | + $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits')); |
|
| 133 | + |
|
| 134 | + // Developers Information |
|
| 135 | + $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead')); |
|
| 136 | + $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor')); |
|
| 137 | + $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url')); |
|
| 138 | + $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name')); |
|
| 139 | + $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email')); |
|
| 140 | + |
|
| 141 | + $people = $versioninfo->getInfo('people'); |
|
| 142 | + if ($people) { |
|
| 143 | + $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map(array($this, 'sanitize'), $people['developers']) : false); |
|
| 144 | + $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map(array($this, 'sanitize'), $people['testers']) : false); |
|
| 145 | + $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map(array($this, 'sanitize'), $people['translators']) : false); |
|
| 146 | + $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map(array($this, 'sanitize'), $people['documenters']) : false); |
|
| 147 | + $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map(array($this, 'sanitize'), $people['other']) : false); |
|
| 148 | + } |
|
| 149 | + //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email')); |
|
| 150 | + |
|
| 151 | + // Module Development information |
|
| 152 | + $this->_tpl->assign('module_date', $versioninfo->getInfo('date')); |
|
| 153 | + $this->_tpl->assign('module_status', $versioninfo->getInfo('status')); |
|
| 154 | + $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url')); |
|
| 155 | + $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name')); |
|
| 156 | + $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url')); |
|
| 157 | + $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name')); |
|
| 158 | + $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug')); |
|
| 159 | + $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature')); |
|
| 160 | + |
|
| 161 | + // Warning |
|
| 162 | + $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning'))); |
|
| 163 | + |
|
| 164 | + // Author's note |
|
| 165 | + $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
|
| 166 | + |
|
| 167 | + // For changelog thanks to 3Dev |
|
| 168 | + global $xoopsModule; |
|
| 169 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
| 170 | + if (is_file($filename)) { |
|
| 171 | + $filesize = filesize($filename); |
|
| 172 | + $handle = fopen($filename, 'r'); |
|
| 173 | + $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
| 174 | + fclose($handle); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $this->_tpl->display('db:smartobject_about.tpl'); |
|
| 178 | + |
|
| 179 | + smart_modFooter(); |
|
| 180 | + |
|
| 181 | + xoops_cp_footer(); |
|
| 182 | + } |
|
| 183 | 183 | } |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class SmartobjectTag extends SmartMlObject |
| 37 | 37 | { |
| 38 | - /** |
|
| 39 | - * SmartobjectTag constructor. |
|
| 40 | - */ |
|
| 41 | - public function __construct() |
|
| 42 | - { |
|
| 43 | - $this->initVar('tagid', XOBJ_DTYPE_INT, '', true); |
|
| 44 | - $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true); |
|
| 45 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC); |
|
| 46 | - $this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC); |
|
| 38 | + /** |
|
| 39 | + * SmartobjectTag constructor. |
|
| 40 | + */ |
|
| 41 | + public function __construct() |
|
| 42 | + { |
|
| 43 | + $this->initVar('tagid', XOBJ_DTYPE_INT, '', true); |
|
| 44 | + $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true); |
|
| 45 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC); |
|
| 46 | + $this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC); |
|
| 47 | 47 | |
| 48 | - // call parent constructor to get Multilanguage field initiated |
|
| 49 | - $this->SmartMlObject(); |
|
| 50 | - } |
|
| 48 | + // call parent constructor to get Multilanguage field initiated |
|
| 49 | + $this->SmartMlObject(); |
|
| 50 | + } |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -55,27 +55,27 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | class SmartobjectTagHandler extends SmartPersistableMlObjectHandler |
| 57 | 57 | { |
| 58 | - /** |
|
| 59 | - * SmartobjectTagHandler constructor. |
|
| 60 | - * @param XoopsDatabase $db |
|
| 61 | - */ |
|
| 62 | - public function __construct(XoopsDatabase $db) |
|
| 63 | - { |
|
| 64 | - parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject'); |
|
| 65 | - } |
|
| 58 | + /** |
|
| 59 | + * SmartobjectTagHandler constructor. |
|
| 60 | + * @param XoopsDatabase $db |
|
| 61 | + */ |
|
| 62 | + public function __construct(XoopsDatabase $db) |
|
| 63 | + { |
|
| 64 | + parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject'); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return mixed |
|
| 69 | - */ |
|
| 70 | - public function getLanguages() |
|
| 71 | - { |
|
| 72 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 73 | - $aLanguages = XoopsLists::getLangList(); |
|
| 74 | - $ret['default'] = _CO_SOBJECT_ALL; |
|
| 75 | - foreach ($aLanguages as $lang) { |
|
| 76 | - $ret[$lang] = $lang; |
|
| 77 | - } |
|
| 67 | + /** |
|
| 68 | + * @return mixed |
|
| 69 | + */ |
|
| 70 | + public function getLanguages() |
|
| 71 | + { |
|
| 72 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 73 | + $aLanguages = XoopsLists::getLangList(); |
|
| 74 | + $ret['default'] = _CO_SOBJECT_ALL; |
|
| 75 | + foreach ($aLanguages as $lang) { |
|
| 76 | + $ret[$lang] = $lang; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return $ret; |
|
| 80 | - } |
|
| 79 | + return $ret; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -5,68 +5,68 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | class SmartPlugin |
| 7 | 7 | { |
| 8 | - public $_infoArray; |
|
| 9 | - |
|
| 10 | - /** |
|
| 11 | - * SmartPlugin constructor. |
|
| 12 | - * @param $array |
|
| 13 | - */ |
|
| 14 | - public function __construct($array) |
|
| 15 | - { |
|
| 16 | - $this->_infoArray = $array; |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @param $item |
|
| 21 | - * @return bool |
|
| 22 | - */ |
|
| 23 | - public function getItemInfo($item) |
|
| 24 | - { |
|
| 25 | - if (isset($this->_infoArray['items'][$item])) { |
|
| 26 | - return $this->_infoArray['items'][$item]; |
|
| 27 | - } else { |
|
| 28 | - return false; |
|
| 29 | - } |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @return mixed |
|
| 34 | - */ |
|
| 35 | - public function getItemList() |
|
| 36 | - { |
|
| 37 | - $itemsArray = $this->_infoArray['items']; |
|
| 38 | - foreach ($itemsArray as $k => $v) { |
|
| 39 | - $ret[$k] = $v['caption']; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - return $ret; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return bool|int|string |
|
| 47 | - */ |
|
| 48 | - public function getItem() |
|
| 49 | - { |
|
| 50 | - $ret = false; |
|
| 51 | - foreach ($this->_infoArray['items'] as $k => $v) { |
|
| 52 | - $search_str = str_replace('%u', '', $v['url']); |
|
| 53 | - if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) { |
|
| 54 | - $ret = $k; |
|
| 55 | - break; |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return $ret; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param $item |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function getItemIdForItem($item) |
|
| 67 | - { |
|
| 68 | - return $_REQUEST[$this->_infoArray['items'][$item]['request']]; |
|
| 69 | - } |
|
| 8 | + public $_infoArray; |
|
| 9 | + |
|
| 10 | + /** |
|
| 11 | + * SmartPlugin constructor. |
|
| 12 | + * @param $array |
|
| 13 | + */ |
|
| 14 | + public function __construct($array) |
|
| 15 | + { |
|
| 16 | + $this->_infoArray = $array; |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @param $item |
|
| 21 | + * @return bool |
|
| 22 | + */ |
|
| 23 | + public function getItemInfo($item) |
|
| 24 | + { |
|
| 25 | + if (isset($this->_infoArray['items'][$item])) { |
|
| 26 | + return $this->_infoArray['items'][$item]; |
|
| 27 | + } else { |
|
| 28 | + return false; |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @return mixed |
|
| 34 | + */ |
|
| 35 | + public function getItemList() |
|
| 36 | + { |
|
| 37 | + $itemsArray = $this->_infoArray['items']; |
|
| 38 | + foreach ($itemsArray as $k => $v) { |
|
| 39 | + $ret[$k] = $v['caption']; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + return $ret; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return bool|int|string |
|
| 47 | + */ |
|
| 48 | + public function getItem() |
|
| 49 | + { |
|
| 50 | + $ret = false; |
|
| 51 | + foreach ($this->_infoArray['items'] as $k => $v) { |
|
| 52 | + $search_str = str_replace('%u', '', $v['url']); |
|
| 53 | + if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) { |
|
| 54 | + $ret = $k; |
|
| 55 | + break; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return $ret; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param $item |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function getItemIdForItem($item) |
|
| 67 | + { |
|
| 68 | + return $_REQUEST[$this->_infoArray['items'][$item]['request']]; |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,57 +74,57 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | class SmartPluginHandler |
| 76 | 76 | { |
| 77 | - public $pluginPatterns = false; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param $dirname |
|
| 81 | - * @return bool|SmartPlugin |
|
| 82 | - */ |
|
| 83 | - public function getPlugin($dirname) |
|
| 84 | - { |
|
| 85 | - $pluginName = SMARTOBJECT_ROOT_PATH . 'plugins/' . $dirname . '.php'; |
|
| 86 | - if (file_exists($pluginName)) { |
|
| 87 | - require_once $pluginName; |
|
| 88 | - $function = 'smartobject_plugin_' . $dirname; |
|
| 89 | - if (function_exists($function)) { |
|
| 90 | - $array = $function(); |
|
| 91 | - $ret = new SmartPlugin($array); |
|
| 92 | - |
|
| 93 | - return $ret; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - public function getPluginsArray() |
|
| 104 | - { |
|
| 105 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 106 | - |
|
| 107 | - $moduleHandler = xoops_getHandler('module'); |
|
| 108 | - $criteria = new CriteriaCompo(); |
|
| 109 | - $criteria->add(new Criteria('isactive', 1)); |
|
| 110 | - $tempModulesObj = $moduleHandler->getObjects($criteria); |
|
| 111 | - $modulesObj = array(); |
|
| 112 | - foreach ($tempModulesObj as $moduleObj) { |
|
| 113 | - $modulesObj[$moduleObj->getVar('dirname')] = $moduleObj; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH . 'plugins/'); |
|
| 117 | - $ret = array(); |
|
| 118 | - foreach ($aFiles as $file) { |
|
| 119 | - if (substr($file, strlen($file) - 4, 4) === '.php') { |
|
| 120 | - $pluginName = str_replace('.php', '', $file); |
|
| 121 | - $module_xoops_version_file = XOOPS_ROOT_PATH . "/modules/$pluginName/xoops_version.php"; |
|
| 122 | - if (file_exists($module_xoops_version_file) && isset($modulesObj[$pluginName])) { |
|
| 123 | - $ret[$pluginName] = $modulesObj[$pluginName]->getVar('name'); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return $ret; |
|
| 129 | - } |
|
| 77 | + public $pluginPatterns = false; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param $dirname |
|
| 81 | + * @return bool|SmartPlugin |
|
| 82 | + */ |
|
| 83 | + public function getPlugin($dirname) |
|
| 84 | + { |
|
| 85 | + $pluginName = SMARTOBJECT_ROOT_PATH . 'plugins/' . $dirname . '.php'; |
|
| 86 | + if (file_exists($pluginName)) { |
|
| 87 | + require_once $pluginName; |
|
| 88 | + $function = 'smartobject_plugin_' . $dirname; |
|
| 89 | + if (function_exists($function)) { |
|
| 90 | + $array = $function(); |
|
| 91 | + $ret = new SmartPlugin($array); |
|
| 92 | + |
|
| 93 | + return $ret; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + public function getPluginsArray() |
|
| 104 | + { |
|
| 105 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 106 | + |
|
| 107 | + $moduleHandler = xoops_getHandler('module'); |
|
| 108 | + $criteria = new CriteriaCompo(); |
|
| 109 | + $criteria->add(new Criteria('isactive', 1)); |
|
| 110 | + $tempModulesObj = $moduleHandler->getObjects($criteria); |
|
| 111 | + $modulesObj = array(); |
|
| 112 | + foreach ($tempModulesObj as $moduleObj) { |
|
| 113 | + $modulesObj[$moduleObj->getVar('dirname')] = $moduleObj; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH . 'plugins/'); |
|
| 117 | + $ret = array(); |
|
| 118 | + foreach ($aFiles as $file) { |
|
| 119 | + if (substr($file, strlen($file) - 4, 4) === '.php') { |
|
| 120 | + $pluginName = str_replace('.php', '', $file); |
|
| 121 | + $module_xoops_version_file = XOOPS_ROOT_PATH . "/modules/$pluginName/xoops_version.php"; |
|
| 122 | + if (file_exists($module_xoops_version_file) && isset($modulesObj[$pluginName])) { |
|
| 123 | + $ret[$pluginName] = $modulesObj[$pluginName]->getVar('name'); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return $ret; |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -10,66 +10,66 @@ |
||
| 10 | 10 | |
| 11 | 11 | class SmartAddTo |
| 12 | 12 | { |
| 13 | - public $_layout; |
|
| 14 | - public $_method; |
|
| 13 | + public $_layout; |
|
| 14 | + public $_method; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Constructor of SmartAddTo |
|
| 18 | - * |
|
| 19 | - * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons |
|
| 20 | - * @param int $method 0=directpage, 1=popup |
|
| 21 | - */ |
|
| 22 | - public function __construct($layout = 0, $method = 1) |
|
| 23 | - { |
|
| 24 | - $layout = (int)$layout; |
|
| 25 | - if ($layout < 0 || $layout > 3) { |
|
| 26 | - $layout = 0; |
|
| 27 | - } |
|
| 28 | - $this->_layout = $layout; |
|
| 16 | + /** |
|
| 17 | + * Constructor of SmartAddTo |
|
| 18 | + * |
|
| 19 | + * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons |
|
| 20 | + * @param int $method 0=directpage, 1=popup |
|
| 21 | + */ |
|
| 22 | + public function __construct($layout = 0, $method = 1) |
|
| 23 | + { |
|
| 24 | + $layout = (int)$layout; |
|
| 25 | + if ($layout < 0 || $layout > 3) { |
|
| 26 | + $layout = 0; |
|
| 27 | + } |
|
| 28 | + $this->_layout = $layout; |
|
| 29 | 29 | |
| 30 | - $method = (int)$method; |
|
| 31 | - if ($method < 0 || $method > 1) { |
|
| 32 | - $method = 1; |
|
| 33 | - } |
|
| 34 | - $this->_method = $method; |
|
| 35 | - } |
|
| 30 | + $method = (int)$method; |
|
| 31 | + if ($method < 0 || $method > 1) { |
|
| 32 | + $method = 1; |
|
| 33 | + } |
|
| 34 | + $this->_method = $method; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param bool $fetchOnly |
|
| 39 | - * @return mixed|string|void |
|
| 40 | - */ |
|
| 41 | - public function render($fetchOnly = false) |
|
| 42 | - { |
|
| 43 | - global $xoTheme, $xoopsTpl; |
|
| 37 | + /** |
|
| 38 | + * @param bool $fetchOnly |
|
| 39 | + * @return mixed|string|void |
|
| 40 | + */ |
|
| 41 | + public function render($fetchOnly = false) |
|
| 42 | + { |
|
| 43 | + global $xoTheme, $xoopsTpl; |
|
| 44 | 44 | |
| 45 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
| 45 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
| 46 | 46 | |
| 47 | - $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
|
| 48 | - $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
|
| 47 | + $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
|
| 48 | + $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
|
| 49 | 49 | |
| 50 | - $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
| 50 | + $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
| 51 | 51 | |
| 52 | - if ($fetchOnly) { |
|
| 53 | - return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
|
| 54 | - } else { |
|
| 55 | - $xoopsTpl->display('db:smartobject_addto.tpl'); |
|
| 56 | - } |
|
| 57 | - } |
|
| 52 | + if ($fetchOnly) { |
|
| 53 | + return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
|
| 54 | + } else { |
|
| 55 | + $xoopsTpl->display('db:smartobject_addto.tpl'); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - public function renderForBlock() |
|
| 63 | - { |
|
| 64 | - global $xoTheme; |
|
| 59 | + /** |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + public function renderForBlock() |
|
| 63 | + { |
|
| 64 | + global $xoTheme; |
|
| 65 | 65 | |
| 66 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
| 66 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
| 67 | 67 | |
| 68 | - $block = array(); |
|
| 69 | - $block['smartobject_addto_method'] = $this->_method; |
|
| 70 | - $block['smartobject_addto_layout'] = $this->_layout; |
|
| 71 | - $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
| 68 | + $block = array(); |
|
| 69 | + $block['smartobject_addto_method'] = $this->_method; |
|
| 70 | + $block['smartobject_addto_layout'] = $this->_layout; |
|
| 71 | + $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
| 72 | 72 | |
| 73 | - return $block; |
|
| 74 | - } |
|
| 73 | + return $block; |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -5,149 +5,149 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class SmartObjectUtility extends XoopsObject |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
| 10 | - * |
|
| 11 | - * @param string $folder The full path of the directory to check |
|
| 12 | - * |
|
| 13 | - * @return void |
|
| 14 | - */ |
|
| 15 | - public static function createFolder($folder) |
|
| 16 | - { |
|
| 17 | - // try { |
|
| 18 | - // if (!mkdir($folder) && !is_dir($folder)) { |
|
| 19 | - // throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
| 20 | - // } else { |
|
| 21 | - // file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
| 22 | - // } |
|
| 23 | - // } |
|
| 24 | - // catch (Exception $e) { |
|
| 25 | - // echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
| 26 | - // } |
|
| 27 | - try { |
|
| 28 | - if (!file_exists($folder)) { |
|
| 29 | - if (!mkdir($folder) && !is_dir($folder)) { |
|
| 30 | - throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
| 31 | - } else { |
|
| 32 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - } catch (Exception $e) { |
|
| 36 | - echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
| 37 | - } |
|
| 38 | - } |
|
| 8 | + /** |
|
| 9 | + * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
| 10 | + * |
|
| 11 | + * @param string $folder The full path of the directory to check |
|
| 12 | + * |
|
| 13 | + * @return void |
|
| 14 | + */ |
|
| 15 | + public static function createFolder($folder) |
|
| 16 | + { |
|
| 17 | + // try { |
|
| 18 | + // if (!mkdir($folder) && !is_dir($folder)) { |
|
| 19 | + // throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
| 20 | + // } else { |
|
| 21 | + // file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
| 22 | + // } |
|
| 23 | + // } |
|
| 24 | + // catch (Exception $e) { |
|
| 25 | + // echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
| 26 | + // } |
|
| 27 | + try { |
|
| 28 | + if (!file_exists($folder)) { |
|
| 29 | + if (!mkdir($folder) && !is_dir($folder)) { |
|
| 30 | + throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
| 31 | + } else { |
|
| 32 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + } catch (Exception $e) { |
|
| 36 | + echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param $file |
|
| 42 | - * @param $folder |
|
| 43 | - * @return bool |
|
| 44 | - */ |
|
| 45 | - public static function copyFile($file, $folder) |
|
| 46 | - { |
|
| 47 | - return copy($file, $folder); |
|
| 48 | - // try { |
|
| 49 | - // if (!is_dir($folder)) { |
|
| 50 | - // throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
|
| 51 | - // } else { |
|
| 52 | - // return copy($file, $folder); |
|
| 53 | - // } |
|
| 54 | - // } catch (Exception $e) { |
|
| 55 | - // echo 'Caught exception: ', $e->getMessage(), "\n", "<br>"; |
|
| 56 | - // } |
|
| 57 | - // return false; |
|
| 58 | - } |
|
| 40 | + /** |
|
| 41 | + * @param $file |
|
| 42 | + * @param $folder |
|
| 43 | + * @return bool |
|
| 44 | + */ |
|
| 45 | + public static function copyFile($file, $folder) |
|
| 46 | + { |
|
| 47 | + return copy($file, $folder); |
|
| 48 | + // try { |
|
| 49 | + // if (!is_dir($folder)) { |
|
| 50 | + // throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
|
| 51 | + // } else { |
|
| 52 | + // return copy($file, $folder); |
|
| 53 | + // } |
|
| 54 | + // } catch (Exception $e) { |
|
| 55 | + // echo 'Caught exception: ', $e->getMessage(), "\n", "<br>"; |
|
| 56 | + // } |
|
| 57 | + // return false; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param $src |
|
| 62 | - * @param $dst |
|
| 63 | - */ |
|
| 64 | - public static function recurseCopy($src, $dst) |
|
| 65 | - { |
|
| 66 | - $dir = opendir($src); |
|
| 67 | - // @mkdir($dst); |
|
| 68 | - while (false !== ($file = readdir($dir))) { |
|
| 69 | - if (($file !== '.') && ($file !== '..')) { |
|
| 70 | - if (is_dir($src . '/' . $file)) { |
|
| 71 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
| 72 | - } else { |
|
| 73 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - closedir($dir); |
|
| 78 | - } |
|
| 60 | + /** |
|
| 61 | + * @param $src |
|
| 62 | + * @param $dst |
|
| 63 | + */ |
|
| 64 | + public static function recurseCopy($src, $dst) |
|
| 65 | + { |
|
| 66 | + $dir = opendir($src); |
|
| 67 | + // @mkdir($dst); |
|
| 68 | + while (false !== ($file = readdir($dir))) { |
|
| 69 | + if (($file !== '.') && ($file !== '..')) { |
|
| 70 | + if (is_dir($src . '/' . $file)) { |
|
| 71 | + self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
| 72 | + } else { |
|
| 73 | + copy($src . '/' . $file, $dst . '/' . $file); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + closedir($dir); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * |
|
| 82 | - * Verifies XOOPS version meets minimum requirements for this module |
|
| 83 | - * @static |
|
| 84 | - * @param XoopsModule $module |
|
| 85 | - * |
|
| 86 | - * @param null|string $requiredVer |
|
| 87 | - * @return bool true if meets requirements, false if not |
|
| 88 | - */ |
|
| 89 | - public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null) |
|
| 90 | - { |
|
| 91 | - $moduleDirName = basename(dirname(__DIR__)); |
|
| 92 | - if (null === $module) { |
|
| 93 | - $module = XoopsModule::getByDirname($moduleDirName); |
|
| 94 | - } |
|
| 95 | - xoops_loadLanguage('admin', $moduleDirName); |
|
| 96 | - //check for minimum XOOPS version |
|
| 97 | - $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
| 98 | - $currArray = explode('.', $currentVer); |
|
| 99 | - if (null === $requiredVer) { |
|
| 100 | - $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
| 101 | - } |
|
| 102 | - $reqArray = explode('.', $requiredVer); |
|
| 103 | - $success = true; |
|
| 104 | - foreach ($reqArray as $k => $v) { |
|
| 105 | - if (isset($currArray[$k])) { |
|
| 106 | - if ($currArray[$k] > $v) { |
|
| 107 | - break; |
|
| 108 | - } elseif ($currArray[$k] == $v) { |
|
| 109 | - continue; |
|
| 110 | - } else { |
|
| 111 | - $success = false; |
|
| 112 | - break; |
|
| 113 | - } |
|
| 114 | - } else { |
|
| 115 | - if ((int)$v > 0) { // handles versions like x.x.x.0_RC2 |
|
| 116 | - $success = false; |
|
| 117 | - break; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 80 | + /** |
|
| 81 | + * |
|
| 82 | + * Verifies XOOPS version meets minimum requirements for this module |
|
| 83 | + * @static |
|
| 84 | + * @param XoopsModule $module |
|
| 85 | + * |
|
| 86 | + * @param null|string $requiredVer |
|
| 87 | + * @return bool true if meets requirements, false if not |
|
| 88 | + */ |
|
| 89 | + public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null) |
|
| 90 | + { |
|
| 91 | + $moduleDirName = basename(dirname(__DIR__)); |
|
| 92 | + if (null === $module) { |
|
| 93 | + $module = XoopsModule::getByDirname($moduleDirName); |
|
| 94 | + } |
|
| 95 | + xoops_loadLanguage('admin', $moduleDirName); |
|
| 96 | + //check for minimum XOOPS version |
|
| 97 | + $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
| 98 | + $currArray = explode('.', $currentVer); |
|
| 99 | + if (null === $requiredVer) { |
|
| 100 | + $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
| 101 | + } |
|
| 102 | + $reqArray = explode('.', $requiredVer); |
|
| 103 | + $success = true; |
|
| 104 | + foreach ($reqArray as $k => $v) { |
|
| 105 | + if (isset($currArray[$k])) { |
|
| 106 | + if ($currArray[$k] > $v) { |
|
| 107 | + break; |
|
| 108 | + } elseif ($currArray[$k] == $v) { |
|
| 109 | + continue; |
|
| 110 | + } else { |
|
| 111 | + $success = false; |
|
| 112 | + break; |
|
| 113 | + } |
|
| 114 | + } else { |
|
| 115 | + if ((int)$v > 0) { // handles versions like x.x.x.0_RC2 |
|
| 116 | + $success = false; |
|
| 117 | + break; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - if (!$success) { |
|
| 123 | - $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
| 124 | - } |
|
| 122 | + if (!$success) { |
|
| 123 | + $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $success; |
|
| 127 | - } |
|
| 126 | + return $success; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * |
|
| 131 | - * Verifies PHP version meets minimum requirements for this module |
|
| 132 | - * @static |
|
| 133 | - * @param XoopsModule $module |
|
| 134 | - * |
|
| 135 | - * @return bool true if meets requirements, false if not |
|
| 136 | - */ |
|
| 137 | - public static function checkVerPhp(XoopsModule $module) |
|
| 138 | - { |
|
| 139 | - xoops_loadLanguage('admin', $module->dirname()); |
|
| 140 | - // check for minimum PHP version |
|
| 141 | - $success = true; |
|
| 142 | - $verNum = PHP_VERSION; |
|
| 143 | - $reqVer = $module->getInfo('min_php'); |
|
| 144 | - if (false !== $reqVer && '' !== $reqVer) { |
|
| 145 | - if (version_compare($verNum, $reqVer, '<')) { |
|
| 146 | - $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
| 147 | - $success = false; |
|
| 148 | - } |
|
| 149 | - } |
|
| 129 | + /** |
|
| 130 | + * |
|
| 131 | + * Verifies PHP version meets minimum requirements for this module |
|
| 132 | + * @static |
|
| 133 | + * @param XoopsModule $module |
|
| 134 | + * |
|
| 135 | + * @return bool true if meets requirements, false if not |
|
| 136 | + */ |
|
| 137 | + public static function checkVerPhp(XoopsModule $module) |
|
| 138 | + { |
|
| 139 | + xoops_loadLanguage('admin', $module->dirname()); |
|
| 140 | + // check for minimum PHP version |
|
| 141 | + $success = true; |
|
| 142 | + $verNum = PHP_VERSION; |
|
| 143 | + $reqVer = $module->getInfo('min_php'); |
|
| 144 | + if (false !== $reqVer && '' !== $reqVer) { |
|
| 145 | + if (version_compare($verNum, $reqVer, '<')) { |
|
| 146 | + $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
| 147 | + $success = false; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - return $success; |
|
| 152 | - } |
|
| 151 | + return $success; |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -12,18 +12,18 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | class SmartobjectPermissionHandler extends XoopsObjectHandler |
| 14 | 14 | { |
| 15 | - public $handler; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * SmartobjectPermissionHandler constructor. |
|
| 19 | - * @param XoopsDatabase $handler |
|
| 20 | - */ |
|
| 21 | - public function __construct($handler) |
|
| 22 | - { |
|
| 23 | - $this->handler = $handler; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - /* |
|
| 15 | + public $handler; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * SmartobjectPermissionHandler constructor. |
|
| 19 | + * @param XoopsDatabase $handler |
|
| 20 | + */ |
|
| 21 | + public function __construct($handler) |
|
| 22 | + { |
|
| 23 | + $this->handler = $handler; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + /* |
|
| 27 | 27 | * Returns permissions for a certain type |
| 28 | 28 | * |
| 29 | 29 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -31,74 +31,74 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - /** |
|
| 35 | - * @param $gperm_name |
|
| 36 | - * @param null $id |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - public function getGrantedGroups($gperm_name, $id = null) |
|
| 40 | - { |
|
| 41 | - static $groups; |
|
| 42 | - |
|
| 43 | - if (!isset($groups[$gperm_name]) || ($id !== null && !isset($groups[$gperm_name][$id]))) { |
|
| 44 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 45 | - //Get group permissions handler |
|
| 46 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 47 | - |
|
| 48 | - //Get groups allowed for an item id |
|
| 49 | - $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 50 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - //Return the permission array |
|
| 54 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array(); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param $item_ids_array |
|
| 59 | - * @param bool $gperm_name |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 63 | - { |
|
| 64 | - static $groups; |
|
| 65 | - |
|
| 66 | - if ($gperm_name) { |
|
| 67 | - if (isset($groups[$gperm_name])) { |
|
| 68 | - return $groups[$gperm_name]; |
|
| 69 | - } |
|
| 70 | - } else { |
|
| 71 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 72 | - return $groups; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 76 | - |
|
| 77 | - $criteria = new CriteriaCompo(); |
|
| 78 | - $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 79 | - |
|
| 80 | - if ($gperm_name) { |
|
| 81 | - $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - //Get group permissions handler |
|
| 85 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 86 | - |
|
| 87 | - $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 88 | - |
|
| 89 | - foreach ($permissionsObj as $permissionObj) { |
|
| 90 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - //Return the permission array |
|
| 94 | - if ($gperm_name) { |
|
| 95 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array(); |
|
| 96 | - } else { |
|
| 97 | - return isset($groups) ? $groups : array(); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /* |
|
| 34 | + /** |
|
| 35 | + * @param $gperm_name |
|
| 36 | + * @param null $id |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + public function getGrantedGroups($gperm_name, $id = null) |
|
| 40 | + { |
|
| 41 | + static $groups; |
|
| 42 | + |
|
| 43 | + if (!isset($groups[$gperm_name]) || ($id !== null && !isset($groups[$gperm_name][$id]))) { |
|
| 44 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 45 | + //Get group permissions handler |
|
| 46 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 47 | + |
|
| 48 | + //Get groups allowed for an item id |
|
| 49 | + $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 50 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + //Return the permission array |
|
| 54 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array(); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param $item_ids_array |
|
| 59 | + * @param bool $gperm_name |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 63 | + { |
|
| 64 | + static $groups; |
|
| 65 | + |
|
| 66 | + if ($gperm_name) { |
|
| 67 | + if (isset($groups[$gperm_name])) { |
|
| 68 | + return $groups[$gperm_name]; |
|
| 69 | + } |
|
| 70 | + } else { |
|
| 71 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 72 | + return $groups; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 76 | + |
|
| 77 | + $criteria = new CriteriaCompo(); |
|
| 78 | + $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 79 | + |
|
| 80 | + if ($gperm_name) { |
|
| 81 | + $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + //Get group permissions handler |
|
| 85 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 86 | + |
|
| 87 | + $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 88 | + |
|
| 89 | + foreach ($permissionsObj as $permissionObj) { |
|
| 90 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + //Return the permission array |
|
| 94 | + if ($gperm_name) { |
|
| 95 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array(); |
|
| 96 | + } else { |
|
| 97 | + return isset($groups) ? $groups : array(); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /* |
|
| 102 | 102 | * Returns permissions for a certain type |
| 103 | 103 | * |
| 104 | 104 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -106,123 +106,123 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @return array |
| 108 | 108 | */ |
| 109 | - /** |
|
| 110 | - * @param $gperm_name |
|
| 111 | - * @param null $id |
|
| 112 | - * @return array |
|
| 113 | - */ |
|
| 114 | - public function getGrantedItems($gperm_name, $id = null) |
|
| 115 | - { |
|
| 116 | - global $xoopsUser; |
|
| 117 | - static $permissions; |
|
| 118 | - |
|
| 119 | - if (!isset($permissions[$gperm_name]) || ($id !== null && !isset($permissions[$gperm_name][$id]))) { |
|
| 120 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 121 | - |
|
| 122 | - if (is_object($smartModule)) { |
|
| 123 | - |
|
| 124 | - //Get group permissions handler |
|
| 125 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 126 | - |
|
| 127 | - //Get user's groups |
|
| 128 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 129 | - |
|
| 130 | - //Get all allowed item ids in this module and for this user's groups |
|
| 131 | - $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 132 | - $permissions[$gperm_name] = $userpermissions; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - //Return the permission array |
|
| 137 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param $id |
|
| 142 | - */ |
|
| 143 | - public function storeAllPermissionsForId($id) |
|
| 144 | - { |
|
| 145 | - foreach ($this->handler->getPermissions() as $permission) { |
|
| 146 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Saves permissions for the selected item |
|
| 152 | - * |
|
| 153 | - * saveItem_Permissions() |
|
| 154 | - * |
|
| 155 | - * @param array $groups : group with granted permission |
|
| 156 | - * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
| 157 | - * @param string $perm_name : name of the permission |
|
| 158 | - * @return bool : TRUE if the no errors occured |
|
| 159 | - */ |
|
| 160 | - |
|
| 161 | - public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 162 | - { |
|
| 163 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 164 | - |
|
| 165 | - $result = true; |
|
| 166 | - $module_id = $smartModule->getVar('mid'); |
|
| 167 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 168 | - |
|
| 169 | - // First, if the permissions are already there, delete them |
|
| 170 | - $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 171 | - //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 172 | - //exit; |
|
| 173 | - // Save the new permissions |
|
| 174 | - |
|
| 175 | - if (count($groups) > 0) { |
|
| 176 | - foreach ($groups as $group_id) { |
|
| 177 | - $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return $result; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Delete all permission for a specific item |
|
| 186 | - * |
|
| 187 | - * deletePermissions() |
|
| 188 | - * |
|
| 189 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
| 190 | - * @param $gperm_name |
|
| 191 | - * @return bool: TRUE if the no errors occured |
|
| 192 | - */ |
|
| 193 | - public function deletePermissions($itemid, $gperm_name) |
|
| 194 | - { |
|
| 195 | - global $xoopsModule; |
|
| 196 | - |
|
| 197 | - $smartModule =& smartsection_getModuleInfo(); |
|
| 198 | - |
|
| 199 | - $result = true; |
|
| 200 | - $module_id = $smartModule->getVar('mid'); |
|
| 201 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 202 | - |
|
| 203 | - $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 204 | - |
|
| 205 | - return $result; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Checks if the user has access to a specific permission on a given object |
|
| 210 | - * |
|
| 211 | - * @param string $gperm_name name of the permission to test |
|
| 212 | - * @param int $gperm_itemid id of the object to check |
|
| 213 | - * @return boolean: TRUE if user has access, FALSE if not |
|
| 214 | - **/ |
|
| 215 | - public function accessGranted($gperm_name, $gperm_itemid) |
|
| 216 | - { |
|
| 217 | - global $xoopsUser; |
|
| 218 | - |
|
| 219 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 220 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 221 | - $gperm_modid = $smartModule->getVar('mid'); |
|
| 222 | - |
|
| 223 | - //Get group permissions handler |
|
| 224 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 225 | - |
|
| 226 | - return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 227 | - } |
|
| 109 | + /** |
|
| 110 | + * @param $gperm_name |
|
| 111 | + * @param null $id |
|
| 112 | + * @return array |
|
| 113 | + */ |
|
| 114 | + public function getGrantedItems($gperm_name, $id = null) |
|
| 115 | + { |
|
| 116 | + global $xoopsUser; |
|
| 117 | + static $permissions; |
|
| 118 | + |
|
| 119 | + if (!isset($permissions[$gperm_name]) || ($id !== null && !isset($permissions[$gperm_name][$id]))) { |
|
| 120 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 121 | + |
|
| 122 | + if (is_object($smartModule)) { |
|
| 123 | + |
|
| 124 | + //Get group permissions handler |
|
| 125 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 126 | + |
|
| 127 | + //Get user's groups |
|
| 128 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 129 | + |
|
| 130 | + //Get all allowed item ids in this module and for this user's groups |
|
| 131 | + $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 132 | + $permissions[$gperm_name] = $userpermissions; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + //Return the permission array |
|
| 137 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param $id |
|
| 142 | + */ |
|
| 143 | + public function storeAllPermissionsForId($id) |
|
| 144 | + { |
|
| 145 | + foreach ($this->handler->getPermissions() as $permission) { |
|
| 146 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Saves permissions for the selected item |
|
| 152 | + * |
|
| 153 | + * saveItem_Permissions() |
|
| 154 | + * |
|
| 155 | + * @param array $groups : group with granted permission |
|
| 156 | + * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
| 157 | + * @param string $perm_name : name of the permission |
|
| 158 | + * @return bool : TRUE if the no errors occured |
|
| 159 | + */ |
|
| 160 | + |
|
| 161 | + public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 162 | + { |
|
| 163 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 164 | + |
|
| 165 | + $result = true; |
|
| 166 | + $module_id = $smartModule->getVar('mid'); |
|
| 167 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 168 | + |
|
| 169 | + // First, if the permissions are already there, delete them |
|
| 170 | + $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 171 | + //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 172 | + //exit; |
|
| 173 | + // Save the new permissions |
|
| 174 | + |
|
| 175 | + if (count($groups) > 0) { |
|
| 176 | + foreach ($groups as $group_id) { |
|
| 177 | + $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return $result; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Delete all permission for a specific item |
|
| 186 | + * |
|
| 187 | + * deletePermissions() |
|
| 188 | + * |
|
| 189 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
| 190 | + * @param $gperm_name |
|
| 191 | + * @return bool: TRUE if the no errors occured |
|
| 192 | + */ |
|
| 193 | + public function deletePermissions($itemid, $gperm_name) |
|
| 194 | + { |
|
| 195 | + global $xoopsModule; |
|
| 196 | + |
|
| 197 | + $smartModule =& smartsection_getModuleInfo(); |
|
| 198 | + |
|
| 199 | + $result = true; |
|
| 200 | + $module_id = $smartModule->getVar('mid'); |
|
| 201 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 202 | + |
|
| 203 | + $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 204 | + |
|
| 205 | + return $result; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Checks if the user has access to a specific permission on a given object |
|
| 210 | + * |
|
| 211 | + * @param string $gperm_name name of the permission to test |
|
| 212 | + * @param int $gperm_itemid id of the object to check |
|
| 213 | + * @return boolean: TRUE if user has access, FALSE if not |
|
| 214 | + **/ |
|
| 215 | + public function accessGranted($gperm_name, $gperm_itemid) |
|
| 216 | + { |
|
| 217 | + global $xoopsUser; |
|
| 218 | + |
|
| 219 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 220 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 221 | + $gperm_modid = $smartModule->getVar('mid'); |
|
| 222 | + |
|
| 223 | + //Get group permissions handler |
|
| 224 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 225 | + |
|
| 226 | + return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 227 | + } |
|
| 228 | 228 | } |
@@ -15,65 +15,65 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class SmartPrinterFriendly |
| 17 | 17 | { |
| 18 | - public $_title; |
|
| 19 | - public $_dsc; |
|
| 20 | - public $_content; |
|
| 21 | - public $_tpl; |
|
| 22 | - public $_pageTitle = false; |
|
| 23 | - public $_width = 680; |
|
| 18 | + public $_title; |
|
| 19 | + public $_dsc; |
|
| 20 | + public $_content; |
|
| 21 | + public $_tpl; |
|
| 22 | + public $_pageTitle = false; |
|
| 23 | + public $_width = 680; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * SmartPrinterFriendly constructor. |
|
| 27 | - * @param $content |
|
| 28 | - * @param bool $title |
|
| 29 | - * @param bool $dsc |
|
| 30 | - */ |
|
| 31 | - public function __construct($content, $title = false, $dsc = false) |
|
| 32 | - { |
|
| 33 | - $this->_title = $title; |
|
| 34 | - $this->_dsc = $dsc; |
|
| 35 | - $this->_content = $content; |
|
| 36 | - } |
|
| 25 | + /** |
|
| 26 | + * SmartPrinterFriendly constructor. |
|
| 27 | + * @param $content |
|
| 28 | + * @param bool $title |
|
| 29 | + * @param bool $dsc |
|
| 30 | + */ |
|
| 31 | + public function __construct($content, $title = false, $dsc = false) |
|
| 32 | + { |
|
| 33 | + $this->_title = $title; |
|
| 34 | + $this->_dsc = $dsc; |
|
| 35 | + $this->_content = $content; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function render() |
|
| 39 | - { |
|
| 40 | - /** |
|
| 41 | - * @todo move the output to a template |
|
| 42 | - * @todo make the output XHTML compliant |
|
| 43 | - */ |
|
| 38 | + public function render() |
|
| 39 | + { |
|
| 40 | + /** |
|
| 41 | + * @todo move the output to a template |
|
| 42 | + * @todo make the output XHTML compliant |
|
| 43 | + */ |
|
| 44 | 44 | |
| 45 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 45 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 46 | 46 | |
| 47 | - $this->_tpl = new XoopsTpl(); |
|
| 47 | + $this->_tpl = new XoopsTpl(); |
|
| 48 | 48 | |
| 49 | - $this->_tpl->assign('smartobject_print_pageTitle', $this->_pageTitle ?: $this->_title); |
|
| 50 | - $this->_tpl->assign('smartobject_print_title', $this->_title); |
|
| 51 | - $this->_tpl->assign('smartobject_print_dsc', $this->_dsc); |
|
| 52 | - $this->_tpl->assign('smartobject_print_content', $this->_content); |
|
| 53 | - $this->_tpl->assign('smartobject_print_width', $this->_width); |
|
| 49 | + $this->_tpl->assign('smartobject_print_pageTitle', $this->_pageTitle ?: $this->_title); |
|
| 50 | + $this->_tpl->assign('smartobject_print_title', $this->_title); |
|
| 51 | + $this->_tpl->assign('smartobject_print_dsc', $this->_dsc); |
|
| 52 | + $this->_tpl->assign('smartobject_print_content', $this->_content); |
|
| 53 | + $this->_tpl->assign('smartobject_print_width', $this->_width); |
|
| 54 | 54 | |
| 55 | - $current_urls = smart_getCurrentUrls(); |
|
| 56 | - $current_url = $current_urls['full']; |
|
| 55 | + $current_urls = smart_getCurrentUrls(); |
|
| 56 | + $current_url = $current_urls['full']; |
|
| 57 | 57 | |
| 58 | - $this->_tpl->assign('smartobject_print_currenturl', $current_url); |
|
| 59 | - $this->_tpl->assign('smartobject_print_url', $this->url); |
|
| 58 | + $this->_tpl->assign('smartobject_print_currenturl', $current_url); |
|
| 59 | + $this->_tpl->assign('smartobject_print_url', $this->url); |
|
| 60 | 60 | |
| 61 | - $this->_tpl->display('db:smartobject_print.tpl'); |
|
| 62 | - } |
|
| 61 | + $this->_tpl->display('db:smartobject_print.tpl'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param $text |
|
| 66 | - */ |
|
| 67 | - public function setPageTitle($text) |
|
| 68 | - { |
|
| 69 | - $this->_pageTitle = $text; |
|
| 70 | - } |
|
| 64 | + /** |
|
| 65 | + * @param $text |
|
| 66 | + */ |
|
| 67 | + public function setPageTitle($text) |
|
| 68 | + { |
|
| 69 | + $this->_pageTitle = $text; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @param $width |
|
| 74 | - */ |
|
| 75 | - public function setWidth($width) |
|
| 76 | - { |
|
| 77 | - $this->_width = $width; |
|
| 78 | - } |
|
| 72 | + /** |
|
| 73 | + * @param $width |
|
| 74 | + */ |
|
| 75 | + public function setWidth($width) |
|
| 76 | + { |
|
| 77 | + $this->_width = $width; |
|
| 78 | + } |
|
| 79 | 79 | } |