@@ -30,10 +30,10 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class Jax extends \Projax |
| 32 | 32 | { |
| 33 | - public function initiateFromUserside() |
|
| 34 | - { |
|
| 35 | - global $xoTheme; |
|
| 36 | - $xoTheme->addScript(SMARTOBJECT_URL . 'include/projax/js/prototype.js'); |
|
| 37 | - $xoTheme->addScript(SMARTOBJECT_URL . 'include/projax/js/scriptaculous.js'); |
|
| 38 | - } |
|
| 33 | + public function initiateFromUserside() |
|
| 34 | + { |
|
| 35 | + global $xoTheme; |
|
| 36 | + $xoTheme->addScript(SMARTOBJECT_URL . 'include/projax/js/prototype.js'); |
|
| 37 | + $xoTheme->addScript(SMARTOBJECT_URL . 'include/projax/js/scriptaculous.js'); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -32,12 +32,12 @@ |
||
| 32 | 32 | { |
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * LinkHandler constructor. |
|
| 37 | - * @param \XoopsDatabase $db |
|
| 38 | - */ |
|
| 39 | - public function __construct(\XoopsDatabase $db) |
|
| 40 | - { |
|
| 41 | - parent::__construct($db, Link::class, 'linkid', 'subject', 'body', 'smartobject'); |
|
| 42 | - } |
|
| 35 | + /** |
|
| 36 | + * LinkHandler constructor. |
|
| 37 | + * @param \XoopsDatabase $db |
|
| 38 | + */ |
|
| 39 | + public function __construct(\XoopsDatabase $db) |
|
| 40 | + { |
|
| 41 | + parent::__construct($db, Link::class, 'linkid', 'subject', 'body', 'smartobject'); |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -28,44 +28,44 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class SeoObject extends Smartobject\BaseSmartObject |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * SmartSeoObject constructor. |
|
| 33 | - */ |
|
| 34 | - public function __construct() |
|
| 35 | - { |
|
| 36 | - $this->initCommonVar('meta_keywords'); |
|
| 37 | - $this->initCommonVar('meta_description'); |
|
| 38 | - $this->initCommonVar('short_url'); |
|
| 39 | - $this->seoEnabled = true; |
|
| 40 | - } |
|
| 31 | + /** |
|
| 32 | + * SmartSeoObject constructor. |
|
| 33 | + */ |
|
| 34 | + public function __construct() |
|
| 35 | + { |
|
| 36 | + $this->initCommonVar('meta_keywords'); |
|
| 37 | + $this->initCommonVar('meta_description'); |
|
| 38 | + $this->initCommonVar('short_url'); |
|
| 39 | + $this->seoEnabled = true; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Return the value of the short_url field of this object |
|
| 44 | - * |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function short_url() |
|
| 48 | - { |
|
| 49 | - return $this->getVar('short_url'); |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * Return the value of the short_url field of this object |
|
| 44 | + * |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function short_url() |
|
| 48 | + { |
|
| 49 | + return $this->getVar('short_url'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Return the value of the meta_keywords field of this object |
|
| 54 | - * |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function meta_keywords() |
|
| 58 | - { |
|
| 59 | - return $this->getVar('meta_keywords'); |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * Return the value of the meta_keywords field of this object |
|
| 54 | + * |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function meta_keywords() |
|
| 58 | + { |
|
| 59 | + return $this->getVar('meta_keywords'); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Return the value of the meta_description field of this object |
|
| 64 | - * |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function meta_description() |
|
| 68 | - { |
|
| 69 | - return $this->getVar('meta_description'); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * Return the value of the meta_description field of this object |
|
| 64 | + * |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function meta_description() |
|
| 68 | + { |
|
| 69 | + return $this->getVar('meta_description'); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -29,20 +29,20 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class UrlLink extends Smartobject\BaseSmartObjectBasedUrl |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectUrlLink constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - parent::__construct(); |
|
| 38 | - $this->quickInitVar('urllinkid', XOBJ_DTYPE_TXTBOX, true); |
|
| 39 | - $this->quickInitVar('target', XOBJ_DTYPE_TXTBOX, true); |
|
| 32 | + /** |
|
| 33 | + * SmartobjectUrlLink constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + parent::__construct(); |
|
| 38 | + $this->quickInitVar('urllinkid', XOBJ_DTYPE_TXTBOX, true); |
|
| 39 | + $this->quickInitVar('target', XOBJ_DTYPE_TXTBOX, true); |
|
| 40 | 40 | |
| 41 | - $this->setControl('target', [ |
|
| 42 | - 'options' => [ |
|
| 43 | - '_self' => _CO_SOBJECT_URLLINK_SELF, |
|
| 44 | - '_blank' => _CO_SOBJECT_URLLINK_BLANK |
|
| 45 | - ] |
|
| 46 | - ]); |
|
| 47 | - } |
|
| 41 | + $this->setControl('target', [ |
|
| 42 | + 'options' => [ |
|
| 43 | + '_self' => _CO_SOBJECT_URLLINK_SELF, |
|
| 44 | + '_blank' => _CO_SOBJECT_URLLINK_BLANK |
|
| 45 | + ] |
|
| 46 | + ]); |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -25,7 +25,6 @@ discard block |
||
| 25 | 25 | * Contains the classes for updating database tables |
| 26 | 26 | * |
| 27 | 27 | * @license GNU |
| 28 | - |
|
| 29 | 28 | */ |
| 30 | 29 | /** |
| 31 | 30 | * SmartDbTable class |
@@ -38,7 +37,7 @@ discard block |
||
| 38 | 37 | */ |
| 39 | 38 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
| 40 | 39 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
| 41 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 40 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 42 | 41 | } |
| 43 | 42 | /** |
| 44 | 43 | * Include the language constants for the SmartObjectDBUpdater |
@@ -46,7 +45,7 @@ discard block |
||
| 46 | 45 | global $xoopsConfig; |
| 47 | 46 | $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
| 48 | 47 | if (!file_exists($common_file)) { |
| 49 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 48 | + $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 50 | 49 | } |
| 51 | 50 | include $common_file; |
| 52 | 51 | |
@@ -55,501 +54,501 @@ discard block |
||
| 55 | 54 | */ |
| 56 | 55 | class DbTable |
| 57 | 56 | { |
| 58 | - /** |
|
| 59 | - * @var string $_name name of the table |
|
| 60 | - */ |
|
| 61 | - public $_name; |
|
| 62 | - /** |
|
| 63 | - * @var string $_structure structure of the table |
|
| 64 | - */ |
|
| 65 | - public $_structure; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var array $_data containing valued of each records to be added |
|
| 69 | - */ |
|
| 70 | - public $_data; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var array $_alteredFields containing fields to be altered |
|
| 74 | - */ |
|
| 75 | - public $_alteredFields; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var array $_newFields containing new fields to be added |
|
| 79 | - */ |
|
| 80 | - public $_newFields; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @var array $_droppedFields containing fields to be dropped |
|
| 84 | - */ |
|
| 85 | - public $_droppedFields; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @var array $_flagForDrop flag table to drop it |
|
| 89 | - */ |
|
| 90 | - public $_flagForDrop = false; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var array $_updatedFields containing fields which values will be updated |
|
| 94 | - */ |
|
| 95 | - public $_updatedFields; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @var array $_updatedFields containing fields which values will be updated |
|
| 99 | - */ //felix |
|
| 100 | - public $_updatedWhere; |
|
| 101 | - |
|
| 102 | - public $_existingFieldsArray = false; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Constructor |
|
| 106 | - * |
|
| 107 | - * @param string $name name of the table |
|
| 108 | - * |
|
| 109 | - */ |
|
| 110 | - public function __construct($name) |
|
| 111 | - { |
|
| 112 | - $this->_name = $name; |
|
| 113 | - $this->_data = []; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Return the table name, prefixed with site table prefix |
|
| 118 | - * |
|
| 119 | - * @return string table name |
|
| 120 | - * |
|
| 121 | - */ |
|
| 122 | - public function name() |
|
| 123 | - { |
|
| 124 | - global $xoopsDB; |
|
| 125 | - |
|
| 126 | - return $xoopsDB->prefix($this->_name); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Checks if the table already exists in the database |
|
| 131 | - * |
|
| 132 | - * @return bool TRUE if it exists, FALSE if not |
|
| 133 | - * |
|
| 134 | - */ |
|
| 135 | - public function exists() |
|
| 136 | - { |
|
| 137 | - return Smartobject\Utility::isTable($this->_name); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return mixed |
|
| 142 | - */ |
|
| 143 | - public function getExistingFieldsArray() |
|
| 144 | - { |
|
| 145 | - global $xoopsDB; |
|
| 146 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 147 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
| 148 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 149 | - if ('YES' !== $existing_field['Null']) { |
|
| 150 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 151 | - } |
|
| 152 | - if ($existing_field['Extra']) { |
|
| 153 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 154 | - } |
|
| 155 | - if (!(null === $existing_field['Default']) |
|
| 156 | - && ($existing_field['Default'] |
|
| 157 | - || '' === $existing_field['Default'] |
|
| 158 | - || 0 == $existing_field['Default'])) { |
|
| 159 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return $fields; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param $field |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - public function fieldExists($field) |
|
| 171 | - { |
|
| 172 | - $existingFields = $this->getExistingFieldsArray(); |
|
| 173 | - |
|
| 174 | - return isset($existingFields[$field]); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Set the table structure |
|
| 179 | - * |
|
| 180 | - * Example: |
|
| 181 | - * |
|
| 182 | - * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
| 183 | - * `date` int(11) NOT NULL default '0', |
|
| 184 | - * `status` int(1) NOT NULL default '-1', |
|
| 185 | - * `itemid` int(11) NOT NULL default '0', |
|
| 186 | - * `uid` int(11) NOT NULL default '0', |
|
| 187 | - * `price` float NOT NULL default '0', |
|
| 188 | - * `currency` varchar(100) NOT NULL default '', |
|
| 189 | - * PRIMARY KEY (`transactionid`)"); |
|
| 190 | - * |
|
| 191 | - * @param string $structure table structure |
|
| 192 | - * |
|
| 193 | - */ |
|
| 194 | - public function setStructure($structure) |
|
| 195 | - { |
|
| 196 | - $this->_structure = $structure; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Return the table structure |
|
| 201 | - * |
|
| 202 | - * @return string table structure |
|
| 203 | - * |
|
| 204 | - */ |
|
| 205 | - public function getStructure() |
|
| 206 | - { |
|
| 207 | - return sprintf($this->_structure, $this->name()); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Add values of a record to be added |
|
| 212 | - * |
|
| 213 | - * @param string $data values of a record |
|
| 214 | - * |
|
| 215 | - */ |
|
| 216 | - public function setData($data) |
|
| 217 | - { |
|
| 218 | - $this->_data[] = $data; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Get the data array |
|
| 223 | - * |
|
| 224 | - * @return array containing the records values to be added |
|
| 225 | - * |
|
| 226 | - */ |
|
| 227 | - public function getData() |
|
| 228 | - { |
|
| 229 | - return $this->_data; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Use to insert data in a table |
|
| 234 | - * |
|
| 235 | - * @return bool true if success, false if an error occured |
|
| 236 | - * |
|
| 237 | - */ |
|
| 238 | - public function addData() |
|
| 239 | - { |
|
| 240 | - global $xoopsDB; |
|
| 241 | - foreach ($this->getData() as $data) { |
|
| 242 | - $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
| 243 | - $ret = $xoopsDB->query($query); |
|
| 244 | - if (!$ret) { |
|
| 245 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 246 | - } else { |
|
| 247 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - return $ret; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Add a field to be added |
|
| 256 | - * |
|
| 257 | - * @param string $name name of the field |
|
| 258 | - * @param string $properties properties of the field |
|
| 259 | - * @param bool $newname |
|
| 260 | - * @param bool $showerror |
|
| 261 | - */ |
|
| 262 | - public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
| 263 | - { |
|
| 264 | - $field['name'] = $name; |
|
| 265 | - $field['properties'] = $properties; |
|
| 266 | - $field['showerror'] = $showerror; |
|
| 267 | - $field['newname'] = $newname; |
|
| 268 | - $this->_alteredFields[] = $field; |
|
| 269 | - } |
|
| 270 | - /** |
|
| 271 | - * Invert values 0 to 1 and 1 to 0 |
|
| 272 | - * |
|
| 273 | - * @param string $name name of the field |
|
| 274 | - * @param $newValue |
|
| 275 | - * @param $oldValue |
|
| 276 | - * @internal param string $old old propertie |
|
| 277 | - * @internal param string $new new propertie |
|
| 278 | - */ //felix |
|
| 279 | - public function addUpdatedWhere($name, $newValue, $oldValue) |
|
| 280 | - { |
|
| 281 | - $field['name'] = $name; |
|
| 282 | - $field['value'] = $newValue; |
|
| 283 | - $field['where'] = $oldValue; |
|
| 284 | - $this->_updatedWhere[] = $field; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Add new field of a record to be added |
|
| 289 | - * |
|
| 290 | - * @param string $name name of the field |
|
| 291 | - * @param string $properties properties of the field |
|
| 292 | - * |
|
| 293 | - */ |
|
| 294 | - public function addNewField($name, $properties) |
|
| 295 | - { |
|
| 296 | - $field['name'] = $name; |
|
| 297 | - $field['properties'] = $properties; |
|
| 298 | - $this->_newFields[] = $field; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Get fields that need to be altered |
|
| 303 | - * |
|
| 304 | - * @return array fields that need to be altered |
|
| 305 | - * |
|
| 306 | - */ |
|
| 307 | - public function getAlteredFields() |
|
| 308 | - { |
|
| 309 | - return $this->_alteredFields; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Add field for which the value will be updated |
|
| 314 | - * |
|
| 315 | - * @param string $name name of the field |
|
| 316 | - * @param string $value value to be set |
|
| 317 | - * |
|
| 318 | - */ |
|
| 319 | - public function addUpdatedField($name, $value) |
|
| 320 | - { |
|
| 321 | - $field['name'] = $name; |
|
| 322 | - $field['value'] = $value; |
|
| 323 | - $this->_updatedFields[] = $field; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Get new fields to be added |
|
| 328 | - * |
|
| 329 | - * @return array fields to be added |
|
| 330 | - * |
|
| 331 | - */ |
|
| 332 | - public function getNewFields() |
|
| 333 | - { |
|
| 334 | - return $this->_newFields; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Get fields which values need to be updated |
|
| 339 | - * |
|
| 340 | - * @return array fields which values need to be updated |
|
| 341 | - * |
|
| 342 | - */ |
|
| 343 | - public function getUpdatedFields() |
|
| 344 | - { |
|
| 345 | - return $this->_updatedFields; |
|
| 346 | - } |
|
| 347 | - /** |
|
| 348 | - * Get fields which values need to be updated |
|
| 349 | - * |
|
| 350 | - * @return array fields which values need to be updated |
|
| 351 | - * |
|
| 352 | - */ //felix |
|
| 353 | - public function getUpdatedWhere() |
|
| 354 | - { |
|
| 355 | - return $this->_updatedWhere; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Add values of a record to be added |
|
| 360 | - * |
|
| 361 | - * @param string $name name of the field |
|
| 362 | - * |
|
| 363 | - */ |
|
| 364 | - public function addDroppedField($name) |
|
| 365 | - { |
|
| 366 | - $this->_droppedFields[] = $name; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Get fields that need to be dropped |
|
| 371 | - * |
|
| 372 | - * @return array fields that need to be dropped |
|
| 373 | - * |
|
| 374 | - */ |
|
| 375 | - public function getDroppedFields() |
|
| 376 | - { |
|
| 377 | - return $this->_droppedFields; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Set the flag to drop the table |
|
| 382 | - * |
|
| 383 | - */ |
|
| 384 | - public function setFlagForDrop() |
|
| 385 | - { |
|
| 386 | - $this->_flagForDrop = true; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Use to create a table |
|
| 391 | - * |
|
| 392 | - * @return bool true if success, false if an error occured |
|
| 393 | - * |
|
| 394 | - */ |
|
| 395 | - public function createTable() |
|
| 396 | - { |
|
| 397 | - global $xoopsDB; |
|
| 398 | - $query = $this->getStructure(); |
|
| 399 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 400 | - //xoops_debug($query); |
|
| 401 | - $ret = $xoopsDB->query($query); |
|
| 402 | - if (!$ret) { |
|
| 403 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 404 | - } else { |
|
| 405 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - return $ret; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Use to drop a table |
|
| 413 | - * |
|
| 414 | - * @return bool true if success, false if an error occured |
|
| 415 | - * |
|
| 416 | - */ |
|
| 417 | - public function dropTable() |
|
| 418 | - { |
|
| 419 | - global $xoopsDB; |
|
| 420 | - $query = sprintf('DROP TABLE %s', $this->name()); |
|
| 421 | - $ret = $xoopsDB->query($query); |
|
| 422 | - if (!$ret) { |
|
| 423 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 424 | - |
|
| 425 | - return false; |
|
| 426 | - } else { |
|
| 427 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 428 | - |
|
| 429 | - return true; |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Use to alter a table |
|
| 435 | - * |
|
| 436 | - * @return bool true if success, false if an error occured |
|
| 437 | - * |
|
| 438 | - */ |
|
| 439 | - public function alterTable() |
|
| 440 | - { |
|
| 441 | - global $xoopsDB; |
|
| 442 | - $ret = true; |
|
| 443 | - |
|
| 444 | - foreach ($this->getAlteredFields() as $alteredField) { |
|
| 445 | - if (!$alteredField['newname']) { |
|
| 446 | - $alteredField['newname'] = $alteredField['name']; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
| 450 | - $ret = $ret && $xoopsDB->query($query); |
|
| 451 | - if ($alteredField['showerror']) { |
|
| 452 | - if (!$ret) { |
|
| 453 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 454 | - } else { |
|
| 455 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - return $ret; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Use to add new fileds in the table |
|
| 465 | - * |
|
| 466 | - * @return bool true if success, false if an error occured |
|
| 467 | - * |
|
| 468 | - */ |
|
| 469 | - public function addNewFields() |
|
| 470 | - { |
|
| 471 | - global $xoopsDB; |
|
| 472 | - $ret = true; |
|
| 473 | - foreach ($this->getNewFields() as $newField) { |
|
| 474 | - $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
| 475 | - //echo $query; |
|
| 476 | - $ret = $ret && $xoopsDB->query($query); |
|
| 477 | - if (!$ret) { |
|
| 478 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 479 | - } else { |
|
| 480 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return $ret; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Use to update fields values |
|
| 489 | - * |
|
| 490 | - * @return bool true if success, false if an error occured |
|
| 491 | - * |
|
| 492 | - */ |
|
| 493 | - public function updateFieldsValues() |
|
| 494 | - { |
|
| 495 | - global $xoopsDB; |
|
| 496 | - $ret = true; |
|
| 497 | - foreach ($this->getUpdatedFields() as $updatedField) { |
|
| 498 | - $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
| 499 | - $ret = $ret && $xoopsDB->query($query); |
|
| 500 | - if (!$ret) { |
|
| 501 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 502 | - } else { |
|
| 503 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - return $ret; |
|
| 508 | - } |
|
| 509 | - /** |
|
| 510 | - * Use to update fields values |
|
| 511 | - * |
|
| 512 | - * @return bool true if success, false if an error occured |
|
| 513 | - * |
|
| 514 | - */ //felix |
|
| 515 | - public function updateWhereValues() |
|
| 516 | - { |
|
| 517 | - global $xoopsDB; |
|
| 518 | - $ret = true; |
|
| 519 | - foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
| 520 | - $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
| 521 | - //echo $query."<br>"; |
|
| 522 | - $ret = $ret && $xoopsDB->query($query); |
|
| 523 | - if (!$ret) { |
|
| 524 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 525 | - } else { |
|
| 526 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - return $ret; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Use to drop fields |
|
| 535 | - * |
|
| 536 | - * @return bool true if success, false if an error occured |
|
| 537 | - * |
|
| 538 | - */ |
|
| 539 | - public function dropFields() |
|
| 540 | - { |
|
| 541 | - global $xoopsDB; |
|
| 542 | - $ret = true; |
|
| 543 | - foreach ($this->getDroppedFields() as $droppedField) { |
|
| 544 | - $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
| 545 | - $ret = $ret && $xoopsDB->query($query); |
|
| 546 | - if (!$ret) { |
|
| 547 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 548 | - } else { |
|
| 549 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - return $ret; |
|
| 554 | - } |
|
| 57 | + /** |
|
| 58 | + * @var string $_name name of the table |
|
| 59 | + */ |
|
| 60 | + public $_name; |
|
| 61 | + /** |
|
| 62 | + * @var string $_structure structure of the table |
|
| 63 | + */ |
|
| 64 | + public $_structure; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var array $_data containing valued of each records to be added |
|
| 68 | + */ |
|
| 69 | + public $_data; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var array $_alteredFields containing fields to be altered |
|
| 73 | + */ |
|
| 74 | + public $_alteredFields; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var array $_newFields containing new fields to be added |
|
| 78 | + */ |
|
| 79 | + public $_newFields; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var array $_droppedFields containing fields to be dropped |
|
| 83 | + */ |
|
| 84 | + public $_droppedFields; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @var array $_flagForDrop flag table to drop it |
|
| 88 | + */ |
|
| 89 | + public $_flagForDrop = false; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var array $_updatedFields containing fields which values will be updated |
|
| 93 | + */ |
|
| 94 | + public $_updatedFields; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var array $_updatedFields containing fields which values will be updated |
|
| 98 | + */ //felix |
|
| 99 | + public $_updatedWhere; |
|
| 100 | + |
|
| 101 | + public $_existingFieldsArray = false; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Constructor |
|
| 105 | + * |
|
| 106 | + * @param string $name name of the table |
|
| 107 | + * |
|
| 108 | + */ |
|
| 109 | + public function __construct($name) |
|
| 110 | + { |
|
| 111 | + $this->_name = $name; |
|
| 112 | + $this->_data = []; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Return the table name, prefixed with site table prefix |
|
| 117 | + * |
|
| 118 | + * @return string table name |
|
| 119 | + * |
|
| 120 | + */ |
|
| 121 | + public function name() |
|
| 122 | + { |
|
| 123 | + global $xoopsDB; |
|
| 124 | + |
|
| 125 | + return $xoopsDB->prefix($this->_name); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Checks if the table already exists in the database |
|
| 130 | + * |
|
| 131 | + * @return bool TRUE if it exists, FALSE if not |
|
| 132 | + * |
|
| 133 | + */ |
|
| 134 | + public function exists() |
|
| 135 | + { |
|
| 136 | + return Smartobject\Utility::isTable($this->_name); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return mixed |
|
| 141 | + */ |
|
| 142 | + public function getExistingFieldsArray() |
|
| 143 | + { |
|
| 144 | + global $xoopsDB; |
|
| 145 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 146 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
| 147 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 148 | + if ('YES' !== $existing_field['Null']) { |
|
| 149 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 150 | + } |
|
| 151 | + if ($existing_field['Extra']) { |
|
| 152 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 153 | + } |
|
| 154 | + if (!(null === $existing_field['Default']) |
|
| 155 | + && ($existing_field['Default'] |
|
| 156 | + || '' === $existing_field['Default'] |
|
| 157 | + || 0 == $existing_field['Default'])) { |
|
| 158 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return $fields; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param $field |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + public function fieldExists($field) |
|
| 170 | + { |
|
| 171 | + $existingFields = $this->getExistingFieldsArray(); |
|
| 172 | + |
|
| 173 | + return isset($existingFields[$field]); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Set the table structure |
|
| 178 | + * |
|
| 179 | + * Example: |
|
| 180 | + * |
|
| 181 | + * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
| 182 | + * `date` int(11) NOT NULL default '0', |
|
| 183 | + * `status` int(1) NOT NULL default '-1', |
|
| 184 | + * `itemid` int(11) NOT NULL default '0', |
|
| 185 | + * `uid` int(11) NOT NULL default '0', |
|
| 186 | + * `price` float NOT NULL default '0', |
|
| 187 | + * `currency` varchar(100) NOT NULL default '', |
|
| 188 | + * PRIMARY KEY (`transactionid`)"); |
|
| 189 | + * |
|
| 190 | + * @param string $structure table structure |
|
| 191 | + * |
|
| 192 | + */ |
|
| 193 | + public function setStructure($structure) |
|
| 194 | + { |
|
| 195 | + $this->_structure = $structure; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Return the table structure |
|
| 200 | + * |
|
| 201 | + * @return string table structure |
|
| 202 | + * |
|
| 203 | + */ |
|
| 204 | + public function getStructure() |
|
| 205 | + { |
|
| 206 | + return sprintf($this->_structure, $this->name()); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Add values of a record to be added |
|
| 211 | + * |
|
| 212 | + * @param string $data values of a record |
|
| 213 | + * |
|
| 214 | + */ |
|
| 215 | + public function setData($data) |
|
| 216 | + { |
|
| 217 | + $this->_data[] = $data; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Get the data array |
|
| 222 | + * |
|
| 223 | + * @return array containing the records values to be added |
|
| 224 | + * |
|
| 225 | + */ |
|
| 226 | + public function getData() |
|
| 227 | + { |
|
| 228 | + return $this->_data; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Use to insert data in a table |
|
| 233 | + * |
|
| 234 | + * @return bool true if success, false if an error occured |
|
| 235 | + * |
|
| 236 | + */ |
|
| 237 | + public function addData() |
|
| 238 | + { |
|
| 239 | + global $xoopsDB; |
|
| 240 | + foreach ($this->getData() as $data) { |
|
| 241 | + $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
| 242 | + $ret = $xoopsDB->query($query); |
|
| 243 | + if (!$ret) { |
|
| 244 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 245 | + } else { |
|
| 246 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $ret; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Add a field to be added |
|
| 255 | + * |
|
| 256 | + * @param string $name name of the field |
|
| 257 | + * @param string $properties properties of the field |
|
| 258 | + * @param bool $newname |
|
| 259 | + * @param bool $showerror |
|
| 260 | + */ |
|
| 261 | + public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
| 262 | + { |
|
| 263 | + $field['name'] = $name; |
|
| 264 | + $field['properties'] = $properties; |
|
| 265 | + $field['showerror'] = $showerror; |
|
| 266 | + $field['newname'] = $newname; |
|
| 267 | + $this->_alteredFields[] = $field; |
|
| 268 | + } |
|
| 269 | + /** |
|
| 270 | + * Invert values 0 to 1 and 1 to 0 |
|
| 271 | + * |
|
| 272 | + * @param string $name name of the field |
|
| 273 | + * @param $newValue |
|
| 274 | + * @param $oldValue |
|
| 275 | + * @internal param string $old old propertie |
|
| 276 | + * @internal param string $new new propertie |
|
| 277 | + */ //felix |
|
| 278 | + public function addUpdatedWhere($name, $newValue, $oldValue) |
|
| 279 | + { |
|
| 280 | + $field['name'] = $name; |
|
| 281 | + $field['value'] = $newValue; |
|
| 282 | + $field['where'] = $oldValue; |
|
| 283 | + $this->_updatedWhere[] = $field; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Add new field of a record to be added |
|
| 288 | + * |
|
| 289 | + * @param string $name name of the field |
|
| 290 | + * @param string $properties properties of the field |
|
| 291 | + * |
|
| 292 | + */ |
|
| 293 | + public function addNewField($name, $properties) |
|
| 294 | + { |
|
| 295 | + $field['name'] = $name; |
|
| 296 | + $field['properties'] = $properties; |
|
| 297 | + $this->_newFields[] = $field; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Get fields that need to be altered |
|
| 302 | + * |
|
| 303 | + * @return array fields that need to be altered |
|
| 304 | + * |
|
| 305 | + */ |
|
| 306 | + public function getAlteredFields() |
|
| 307 | + { |
|
| 308 | + return $this->_alteredFields; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Add field for which the value will be updated |
|
| 313 | + * |
|
| 314 | + * @param string $name name of the field |
|
| 315 | + * @param string $value value to be set |
|
| 316 | + * |
|
| 317 | + */ |
|
| 318 | + public function addUpdatedField($name, $value) |
|
| 319 | + { |
|
| 320 | + $field['name'] = $name; |
|
| 321 | + $field['value'] = $value; |
|
| 322 | + $this->_updatedFields[] = $field; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Get new fields to be added |
|
| 327 | + * |
|
| 328 | + * @return array fields to be added |
|
| 329 | + * |
|
| 330 | + */ |
|
| 331 | + public function getNewFields() |
|
| 332 | + { |
|
| 333 | + return $this->_newFields; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Get fields which values need to be updated |
|
| 338 | + * |
|
| 339 | + * @return array fields which values need to be updated |
|
| 340 | + * |
|
| 341 | + */ |
|
| 342 | + public function getUpdatedFields() |
|
| 343 | + { |
|
| 344 | + return $this->_updatedFields; |
|
| 345 | + } |
|
| 346 | + /** |
|
| 347 | + * Get fields which values need to be updated |
|
| 348 | + * |
|
| 349 | + * @return array fields which values need to be updated |
|
| 350 | + * |
|
| 351 | + */ //felix |
|
| 352 | + public function getUpdatedWhere() |
|
| 353 | + { |
|
| 354 | + return $this->_updatedWhere; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Add values of a record to be added |
|
| 359 | + * |
|
| 360 | + * @param string $name name of the field |
|
| 361 | + * |
|
| 362 | + */ |
|
| 363 | + public function addDroppedField($name) |
|
| 364 | + { |
|
| 365 | + $this->_droppedFields[] = $name; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Get fields that need to be dropped |
|
| 370 | + * |
|
| 371 | + * @return array fields that need to be dropped |
|
| 372 | + * |
|
| 373 | + */ |
|
| 374 | + public function getDroppedFields() |
|
| 375 | + { |
|
| 376 | + return $this->_droppedFields; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Set the flag to drop the table |
|
| 381 | + * |
|
| 382 | + */ |
|
| 383 | + public function setFlagForDrop() |
|
| 384 | + { |
|
| 385 | + $this->_flagForDrop = true; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Use to create a table |
|
| 390 | + * |
|
| 391 | + * @return bool true if success, false if an error occured |
|
| 392 | + * |
|
| 393 | + */ |
|
| 394 | + public function createTable() |
|
| 395 | + { |
|
| 396 | + global $xoopsDB; |
|
| 397 | + $query = $this->getStructure(); |
|
| 398 | + $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 399 | + //xoops_debug($query); |
|
| 400 | + $ret = $xoopsDB->query($query); |
|
| 401 | + if (!$ret) { |
|
| 402 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 403 | + } else { |
|
| 404 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + return $ret; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Use to drop a table |
|
| 412 | + * |
|
| 413 | + * @return bool true if success, false if an error occured |
|
| 414 | + * |
|
| 415 | + */ |
|
| 416 | + public function dropTable() |
|
| 417 | + { |
|
| 418 | + global $xoopsDB; |
|
| 419 | + $query = sprintf('DROP TABLE %s', $this->name()); |
|
| 420 | + $ret = $xoopsDB->query($query); |
|
| 421 | + if (!$ret) { |
|
| 422 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 423 | + |
|
| 424 | + return false; |
|
| 425 | + } else { |
|
| 426 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 427 | + |
|
| 428 | + return true; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Use to alter a table |
|
| 434 | + * |
|
| 435 | + * @return bool true if success, false if an error occured |
|
| 436 | + * |
|
| 437 | + */ |
|
| 438 | + public function alterTable() |
|
| 439 | + { |
|
| 440 | + global $xoopsDB; |
|
| 441 | + $ret = true; |
|
| 442 | + |
|
| 443 | + foreach ($this->getAlteredFields() as $alteredField) { |
|
| 444 | + if (!$alteredField['newname']) { |
|
| 445 | + $alteredField['newname'] = $alteredField['name']; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
| 449 | + $ret = $ret && $xoopsDB->query($query); |
|
| 450 | + if ($alteredField['showerror']) { |
|
| 451 | + if (!$ret) { |
|
| 452 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 453 | + } else { |
|
| 454 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return $ret; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Use to add new fileds in the table |
|
| 464 | + * |
|
| 465 | + * @return bool true if success, false if an error occured |
|
| 466 | + * |
|
| 467 | + */ |
|
| 468 | + public function addNewFields() |
|
| 469 | + { |
|
| 470 | + global $xoopsDB; |
|
| 471 | + $ret = true; |
|
| 472 | + foreach ($this->getNewFields() as $newField) { |
|
| 473 | + $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
| 474 | + //echo $query; |
|
| 475 | + $ret = $ret && $xoopsDB->query($query); |
|
| 476 | + if (!$ret) { |
|
| 477 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 478 | + } else { |
|
| 479 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + return $ret; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Use to update fields values |
|
| 488 | + * |
|
| 489 | + * @return bool true if success, false if an error occured |
|
| 490 | + * |
|
| 491 | + */ |
|
| 492 | + public function updateFieldsValues() |
|
| 493 | + { |
|
| 494 | + global $xoopsDB; |
|
| 495 | + $ret = true; |
|
| 496 | + foreach ($this->getUpdatedFields() as $updatedField) { |
|
| 497 | + $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
| 498 | + $ret = $ret && $xoopsDB->query($query); |
|
| 499 | + if (!$ret) { |
|
| 500 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 501 | + } else { |
|
| 502 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + return $ret; |
|
| 507 | + } |
|
| 508 | + /** |
|
| 509 | + * Use to update fields values |
|
| 510 | + * |
|
| 511 | + * @return bool true if success, false if an error occured |
|
| 512 | + * |
|
| 513 | + */ //felix |
|
| 514 | + public function updateWhereValues() |
|
| 515 | + { |
|
| 516 | + global $xoopsDB; |
|
| 517 | + $ret = true; |
|
| 518 | + foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
| 519 | + $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
| 520 | + //echo $query."<br>"; |
|
| 521 | + $ret = $ret && $xoopsDB->query($query); |
|
| 522 | + if (!$ret) { |
|
| 523 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 524 | + } else { |
|
| 525 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return $ret; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Use to drop fields |
|
| 534 | + * |
|
| 535 | + * @return bool true if success, false if an error occured |
|
| 536 | + * |
|
| 537 | + */ |
|
| 538 | + public function dropFields() |
|
| 539 | + { |
|
| 540 | + global $xoopsDB; |
|
| 541 | + $ret = true; |
|
| 542 | + foreach ($this->getDroppedFields() as $droppedField) { |
|
| 543 | + $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
| 544 | + $ret = $ret && $xoopsDB->query($query); |
|
| 545 | + if (!$ret) { |
|
| 546 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 547 | + } else { |
|
| 548 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $ret; |
|
| 553 | + } |
|
| 555 | 554 | } |
@@ -23,94 +23,94 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class SingleView |
| 25 | 25 | { |
| 26 | - public $_object; |
|
| 27 | - public $_userSide; |
|
| 28 | - public $_tpl; |
|
| 29 | - public $_rows; |
|
| 30 | - public $_actions; |
|
| 31 | - public $_headerAsRow = true; |
|
| 26 | + public $_object; |
|
| 27 | + public $_userSide; |
|
| 28 | + public $_tpl; |
|
| 29 | + public $_rows; |
|
| 30 | + public $_actions; |
|
| 31 | + public $_headerAsRow = true; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor |
|
| 35 | - * @param $object |
|
| 36 | - * @param bool $userSide |
|
| 37 | - * @param array $actions |
|
| 38 | - * @param bool $headerAsRow |
|
| 39 | - */ |
|
| 40 | - public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
| 41 | - { |
|
| 42 | - $this->_object = $object; |
|
| 43 | - $this->_userSide = $userSide; |
|
| 44 | - $this->_actions = $actions; |
|
| 45 | - $this->_headerAsRow = $headerAsRow; |
|
| 46 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor |
|
| 35 | + * @param $object |
|
| 36 | + * @param bool $userSide |
|
| 37 | + * @param array $actions |
|
| 38 | + * @param bool $headerAsRow |
|
| 39 | + */ |
|
| 40 | + public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
| 41 | + { |
|
| 42 | + $this->_object = $object; |
|
| 43 | + $this->_userSide = $userSide; |
|
| 44 | + $this->_actions = $actions; |
|
| 45 | + $this->_headerAsRow = $headerAsRow; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param $rowObj |
|
| 50 | - */ |
|
| 51 | - public function addRow($rowObj) |
|
| 52 | - { |
|
| 53 | - $this->_rows[] = $rowObj; |
|
| 54 | - } |
|
| 48 | + /** |
|
| 49 | + * @param $rowObj |
|
| 50 | + */ |
|
| 51 | + public function addRow($rowObj) |
|
| 52 | + { |
|
| 53 | + $this->_rows[] = $rowObj; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param bool $fetchOnly |
|
| 58 | - * @param bool $debug |
|
| 59 | - * @return mixed|string|void |
|
| 60 | - */ |
|
| 61 | - public function render($fetchOnly = false, $debug = false) |
|
| 62 | - { |
|
| 63 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 56 | + /** |
|
| 57 | + * @param bool $fetchOnly |
|
| 58 | + * @param bool $debug |
|
| 59 | + * @return mixed|string|void |
|
| 60 | + */ |
|
| 61 | + public function render($fetchOnly = false, $debug = false) |
|
| 62 | + { |
|
| 63 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 64 | 64 | |
| 65 | - $this->_tpl = new \XoopsTpl(); |
|
| 66 | - $vars = $this->_object->vars; |
|
| 67 | - $smartobjectObjectArray = []; |
|
| 65 | + $this->_tpl = new \XoopsTpl(); |
|
| 66 | + $vars = $this->_object->vars; |
|
| 67 | + $smartobjectObjectArray = []; |
|
| 68 | 68 | |
| 69 | - foreach ($this->_rows as $row) { |
|
| 70 | - $key = $row->getKeyName(); |
|
| 71 | - if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
| 72 | - $method = $row->_customMethodForValue; |
|
| 73 | - $value = $this->_object->$method(); |
|
| 74 | - } else { |
|
| 75 | - $value = $this->_object->getVar($row->getKeyName()); |
|
| 76 | - } |
|
| 77 | - if ($row->isHeader()) { |
|
| 78 | - $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
| 79 | - $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
| 80 | - } else { |
|
| 81 | - $smartobjectObjectArray[$key]['value'] = $value; |
|
| 82 | - $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
| 83 | - $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - $action_row = ''; |
|
| 87 | - if (in_array('edit', $this->_actions)) { |
|
| 88 | - $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
| 89 | - } |
|
| 90 | - if (in_array('delete', $this->_actions)) { |
|
| 91 | - $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
| 92 | - } |
|
| 93 | - if ($action_row) { |
|
| 94 | - $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
| 95 | - $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
| 96 | - } |
|
| 69 | + foreach ($this->_rows as $row) { |
|
| 70 | + $key = $row->getKeyName(); |
|
| 71 | + if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
| 72 | + $method = $row->_customMethodForValue; |
|
| 73 | + $value = $this->_object->$method(); |
|
| 74 | + } else { |
|
| 75 | + $value = $this->_object->getVar($row->getKeyName()); |
|
| 76 | + } |
|
| 77 | + if ($row->isHeader()) { |
|
| 78 | + $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
| 79 | + $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
| 80 | + } else { |
|
| 81 | + $smartobjectObjectArray[$key]['value'] = $value; |
|
| 82 | + $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
| 83 | + $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + $action_row = ''; |
|
| 87 | + if (in_array('edit', $this->_actions)) { |
|
| 88 | + $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
| 89 | + } |
|
| 90 | + if (in_array('delete', $this->_actions)) { |
|
| 91 | + $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
| 92 | + } |
|
| 93 | + if ($action_row) { |
|
| 94 | + $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
| 95 | + $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
| 99 | - $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
| 98 | + $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
| 99 | + $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
| 100 | 100 | |
| 101 | - if ($fetchOnly) { |
|
| 102 | - return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
| 103 | - } else { |
|
| 104 | - $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
| 105 | - } |
|
| 106 | - } |
|
| 101 | + if ($fetchOnly) { |
|
| 102 | + return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
| 103 | + } else { |
|
| 104 | + $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @param bool $debug |
|
| 110 | - * @return mixed|string|void |
|
| 111 | - */ |
|
| 112 | - public function fetch($debug = false) |
|
| 113 | - { |
|
| 114 | - return $this->render(true, $debug); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * @param bool $debug |
|
| 110 | + * @return mixed|string|void |
|
| 111 | + */ |
|
| 112 | + public function fetch($debug = false) |
|
| 113 | + { |
|
| 114 | + return $this->render(true, $debug); |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -29,87 +29,87 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | class Adsense extends Smartobject\BaseSmartObject |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectAdsense constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
| 38 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
| 39 | - $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
| 40 | - $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
| 41 | - $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
| 42 | - $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 43 | - $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 44 | - $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
| 45 | - $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
| 46 | - $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
| 47 | - $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
| 32 | + /** |
|
| 33 | + * SmartobjectAdsense constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
| 38 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
| 39 | + $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
| 40 | + $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
| 41 | + $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
| 42 | + $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 43 | + $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 44 | + $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
| 45 | + $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
| 46 | + $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
| 47 | + $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
| 48 | 48 | |
| 49 | - $this->setControl('format', [ |
|
| 50 | - 'handler' => 'adsense', |
|
| 51 | - 'method' => 'getFormats' |
|
| 52 | - ]); |
|
| 49 | + $this->setControl('format', [ |
|
| 50 | + 'handler' => 'adsense', |
|
| 51 | + 'method' => 'getFormats' |
|
| 52 | + ]); |
|
| 53 | 53 | |
| 54 | - $this->setControl('border_color', [ |
|
| 55 | - 'name' => 'text', |
|
| 56 | - 'size' => 6, |
|
| 57 | - 'maxlength' => 6 |
|
| 58 | - ]); |
|
| 54 | + $this->setControl('border_color', [ |
|
| 55 | + 'name' => 'text', |
|
| 56 | + 'size' => 6, |
|
| 57 | + 'maxlength' => 6 |
|
| 58 | + ]); |
|
| 59 | 59 | |
| 60 | - $this->setControl('background_color', [ |
|
| 61 | - 'name' => 'text', |
|
| 62 | - 'size' => 6, |
|
| 63 | - 'maxlength' => 6 |
|
| 64 | - ]); |
|
| 60 | + $this->setControl('background_color', [ |
|
| 61 | + 'name' => 'text', |
|
| 62 | + 'size' => 6, |
|
| 63 | + 'maxlength' => 6 |
|
| 64 | + ]); |
|
| 65 | 65 | |
| 66 | - $this->setControl('link_color', [ |
|
| 67 | - 'name' => 'text', |
|
| 68 | - 'size' => 6, |
|
| 69 | - 'maxlength' => 6 |
|
| 70 | - ]); |
|
| 66 | + $this->setControl('link_color', [ |
|
| 67 | + 'name' => 'text', |
|
| 68 | + 'size' => 6, |
|
| 69 | + 'maxlength' => 6 |
|
| 70 | + ]); |
|
| 71 | 71 | |
| 72 | - $this->setControl('url_color', [ |
|
| 73 | - 'name' => 'text', |
|
| 74 | - 'size' => 6, |
|
| 75 | - 'maxlength' => 6 |
|
| 76 | - ]); |
|
| 72 | + $this->setControl('url_color', [ |
|
| 73 | + 'name' => 'text', |
|
| 74 | + 'size' => 6, |
|
| 75 | + 'maxlength' => 6 |
|
| 76 | + ]); |
|
| 77 | 77 | |
| 78 | - $this->setControl('text_color', [ |
|
| 79 | - 'name' => 'text', |
|
| 80 | - 'size' => 6, |
|
| 81 | - 'maxlength' => 6 |
|
| 82 | - ]); |
|
| 83 | - } |
|
| 78 | + $this->setControl('text_color', [ |
|
| 79 | + 'name' => 'text', |
|
| 80 | + 'size' => 6, |
|
| 81 | + 'maxlength' => 6 |
|
| 82 | + ]); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param string $key |
|
| 87 | - * @param string $format |
|
| 88 | - * @return mixed |
|
| 89 | - */ |
|
| 90 | - public function getVar($key, $format = 's') |
|
| 91 | - { |
|
| 92 | - if ('s' === $format && in_array($key, [])) { |
|
| 93 | - // return call_user_func(array($this, $key)); |
|
| 94 | - return $this->{$key}(); |
|
| 95 | - } |
|
| 85 | + /** |
|
| 86 | + * @param string $key |
|
| 87 | + * @param string $format |
|
| 88 | + * @return mixed |
|
| 89 | + */ |
|
| 90 | + public function getVar($key, $format = 's') |
|
| 91 | + { |
|
| 92 | + if ('s' === $format && in_array($key, [])) { |
|
| 93 | + // return call_user_func(array($this, $key)); |
|
| 94 | + return $this->{$key}(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return parent::getVar($key, $format); |
|
| 98 | - } |
|
| 97 | + return parent::getVar($key, $format); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function render() |
|
| 104 | - { |
|
| 105 | - global $smartobjectAdsenseHandler; |
|
| 106 | - if ('' !== $this->getVar('style', 'n')) { |
|
| 107 | - $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 108 | - } else { |
|
| 109 | - $ret = '<div>'; |
|
| 110 | - } |
|
| 100 | + /** |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function render() |
|
| 104 | + { |
|
| 105 | + global $smartobjectAdsenseHandler; |
|
| 106 | + if ('' !== $this->getVar('style', 'n')) { |
|
| 107 | + $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 108 | + } else { |
|
| 109 | + $ret = '<div>'; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - $ret .= '<script type="text/javascript"><!-- |
|
| 112 | + $ret .= '<script type="text/javascript"><!-- |
|
| 113 | 113 | google_ad_client = "' . $this->getVar('client_id', 'n') . '"; |
| 114 | 114 | google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . '; |
| 115 | 115 | google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . '; |
@@ -127,137 +127,137 @@ discard block |
||
| 127 | 127 | </script> |
| 128 | 128 | </div>'; |
| 129 | 129 | |
| 130 | - return $ret; |
|
| 131 | - } |
|
| 130 | + return $ret; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function getXoopsCode() |
|
| 137 | - { |
|
| 138 | - $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 133 | + /** |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function getXoopsCode() |
|
| 137 | + { |
|
| 138 | + $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 139 | 139 | |
| 140 | - return $ret; |
|
| 141 | - } |
|
| 140 | + return $ret; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * @param $var |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - public function emptyString($var) |
|
| 148 | - { |
|
| 149 | - return (strlen($var) > 0); |
|
| 150 | - } |
|
| 143 | + /** |
|
| 144 | + * @param $var |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + public function emptyString($var) |
|
| 148 | + { |
|
| 149 | + return (strlen($var) > 0); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * @return mixed|string |
|
| 154 | - */ |
|
| 155 | - public function generateTag() |
|
| 156 | - { |
|
| 157 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 158 | - $title = xoops_substr($title, 0, 10, ''); |
|
| 159 | - // Transformation des ponctuations |
|
| 160 | - $pattern = [ |
|
| 161 | - '/%09/', // Tab |
|
| 162 | - '/%20/', // Space |
|
| 163 | - '/%21/', // ! |
|
| 164 | - '/%22/', // " |
|
| 165 | - '/%23/', // # |
|
| 166 | - '/%25/', // % |
|
| 167 | - '/%26/', // & |
|
| 168 | - '/%27/', // ' |
|
| 169 | - '/%28/', // ( |
|
| 170 | - '/%29/', // ) |
|
| 171 | - '/%2C/', // , |
|
| 172 | - '/%2F/', // / |
|
| 173 | - '/%3A/', // : |
|
| 174 | - '/%3B/', // ; |
|
| 175 | - '/%3C/', // < |
|
| 176 | - '/%3D/', // = |
|
| 177 | - '/%3E/', // > |
|
| 178 | - '/%3F/', // ? |
|
| 179 | - '/%40/', // @ |
|
| 180 | - '/%5B/', // [ |
|
| 181 | - '/%5C/', // \ |
|
| 182 | - '/%5D/', // ] |
|
| 183 | - '/%5E/', // ^ |
|
| 184 | - '/%7B/', // { |
|
| 185 | - '/%7C/', // | |
|
| 186 | - '/%7D/', // } |
|
| 187 | - '/%7E/', // ~ |
|
| 188 | - "/\./" // . |
|
| 189 | - ]; |
|
| 190 | - $rep_pat = [ |
|
| 191 | - '-', |
|
| 192 | - '-', |
|
| 193 | - '-', |
|
| 194 | - '-', |
|
| 195 | - '-', |
|
| 196 | - '-100', |
|
| 197 | - '-', |
|
| 198 | - '-', |
|
| 199 | - '-', |
|
| 200 | - '-', |
|
| 201 | - '-', |
|
| 202 | - '-', |
|
| 203 | - '-', |
|
| 204 | - '-', |
|
| 205 | - '-', |
|
| 206 | - '-', |
|
| 207 | - '-', |
|
| 208 | - '-', |
|
| 209 | - '-at-', |
|
| 210 | - '-', |
|
| 211 | - '-', |
|
| 212 | - '-', |
|
| 213 | - '-', |
|
| 214 | - '-', |
|
| 215 | - '-', |
|
| 216 | - '-', |
|
| 217 | - '-', |
|
| 218 | - '-' |
|
| 219 | - ]; |
|
| 220 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 152 | + /** |
|
| 153 | + * @return mixed|string |
|
| 154 | + */ |
|
| 155 | + public function generateTag() |
|
| 156 | + { |
|
| 157 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 158 | + $title = xoops_substr($title, 0, 10, ''); |
|
| 159 | + // Transformation des ponctuations |
|
| 160 | + $pattern = [ |
|
| 161 | + '/%09/', // Tab |
|
| 162 | + '/%20/', // Space |
|
| 163 | + '/%21/', // ! |
|
| 164 | + '/%22/', // " |
|
| 165 | + '/%23/', // # |
|
| 166 | + '/%25/', // % |
|
| 167 | + '/%26/', // & |
|
| 168 | + '/%27/', // ' |
|
| 169 | + '/%28/', // ( |
|
| 170 | + '/%29/', // ) |
|
| 171 | + '/%2C/', // , |
|
| 172 | + '/%2F/', // / |
|
| 173 | + '/%3A/', // : |
|
| 174 | + '/%3B/', // ; |
|
| 175 | + '/%3C/', // < |
|
| 176 | + '/%3D/', // = |
|
| 177 | + '/%3E/', // > |
|
| 178 | + '/%3F/', // ? |
|
| 179 | + '/%40/', // @ |
|
| 180 | + '/%5B/', // [ |
|
| 181 | + '/%5C/', // \ |
|
| 182 | + '/%5D/', // ] |
|
| 183 | + '/%5E/', // ^ |
|
| 184 | + '/%7B/', // { |
|
| 185 | + '/%7C/', // | |
|
| 186 | + '/%7D/', // } |
|
| 187 | + '/%7E/', // ~ |
|
| 188 | + "/\./" // . |
|
| 189 | + ]; |
|
| 190 | + $rep_pat = [ |
|
| 191 | + '-', |
|
| 192 | + '-', |
|
| 193 | + '-', |
|
| 194 | + '-', |
|
| 195 | + '-', |
|
| 196 | + '-100', |
|
| 197 | + '-', |
|
| 198 | + '-', |
|
| 199 | + '-', |
|
| 200 | + '-', |
|
| 201 | + '-', |
|
| 202 | + '-', |
|
| 203 | + '-', |
|
| 204 | + '-', |
|
| 205 | + '-', |
|
| 206 | + '-', |
|
| 207 | + '-', |
|
| 208 | + '-', |
|
| 209 | + '-at-', |
|
| 210 | + '-', |
|
| 211 | + '-', |
|
| 212 | + '-', |
|
| 213 | + '-', |
|
| 214 | + '-', |
|
| 215 | + '-', |
|
| 216 | + '-', |
|
| 217 | + '-', |
|
| 218 | + '-' |
|
| 219 | + ]; |
|
| 220 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 221 | 221 | |
| 222 | - // Transformation des caractères accentués |
|
| 223 | - $pattern = [ |
|
| 224 | - '/%B0/', // ° |
|
| 225 | - '/%E8/', // è |
|
| 226 | - '/%E9/', // é |
|
| 227 | - '/%EA/', // ê |
|
| 228 | - '/%EB/', // ë |
|
| 229 | - '/%E7/', // ç |
|
| 230 | - '/%E0/', // à |
|
| 231 | - '/%E2/', // â |
|
| 232 | - '/%E4/', // ä |
|
| 233 | - '/%EE/', // î |
|
| 234 | - '/%EF/', // ï |
|
| 235 | - '/%F9/', // ù |
|
| 236 | - '/%FC/', // ü |
|
| 237 | - '/%FB/', // û |
|
| 238 | - '/%F4/', // ô |
|
| 239 | - '/%F6/', // ö |
|
| 240 | - ]; |
|
| 241 | - $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 242 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 222 | + // Transformation des caractères accentués |
|
| 223 | + $pattern = [ |
|
| 224 | + '/%B0/', // ° |
|
| 225 | + '/%E8/', // è |
|
| 226 | + '/%E9/', // é |
|
| 227 | + '/%EA/', // ê |
|
| 228 | + '/%EB/', // ë |
|
| 229 | + '/%E7/', // ç |
|
| 230 | + '/%E0/', // à |
|
| 231 | + '/%E2/', // â |
|
| 232 | + '/%E4/', // ä |
|
| 233 | + '/%EE/', // î |
|
| 234 | + '/%EF/', // ï |
|
| 235 | + '/%F9/', // ù |
|
| 236 | + '/%FC/', // ü |
|
| 237 | + '/%FB/', // û |
|
| 238 | + '/%F4/', // ô |
|
| 239 | + '/%F6/', // ö |
|
| 240 | + ]; |
|
| 241 | + $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 242 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 243 | 243 | |
| 244 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 245 | - $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 246 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 244 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 245 | + $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 246 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 247 | 247 | |
| 248 | - $title .= time(); |
|
| 249 | - $title = md5($title); |
|
| 248 | + $title .= time(); |
|
| 249 | + $title = md5($title); |
|
| 250 | 250 | |
| 251 | - return $title; |
|
| 252 | - } |
|
| 251 | + return $title; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function getCloneLink() |
|
| 258 | - { |
|
| 259 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 254 | + /** |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function getCloneLink() |
|
| 258 | + { |
|
| 259 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 260 | 260 | |
| 261 | - return $ret; |
|
| 262 | - } |
|
| 261 | + return $ret; |
|
| 262 | + } |
|
| 263 | 263 | } |
@@ -19,18 +19,18 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class PermissionHandler extends \XoopsObjectHandler |
| 21 | 21 | { |
| 22 | - public $handler; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * SmartobjectPermissionHandler constructor. |
|
| 26 | - * @param \XoopsDatabase $handler |
|
| 27 | - */ |
|
| 28 | - public function __construct($handler) |
|
| 29 | - { |
|
| 30 | - $this->handler = $handler; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /* |
|
| 22 | + public $handler; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * SmartobjectPermissionHandler constructor. |
|
| 26 | + * @param \XoopsDatabase $handler |
|
| 27 | + */ |
|
| 28 | + public function __construct($handler) |
|
| 29 | + { |
|
| 30 | + $this->handler = $handler; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /* |
|
| 34 | 34 | * Returns permissions for a certain type |
| 35 | 35 | * |
| 36 | 36 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -38,74 +38,74 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | - /** |
|
| 42 | - * @param $gperm_name |
|
| 43 | - * @param null $id |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function getGrantedGroups($gperm_name, $id = null) |
|
| 47 | - { |
|
| 48 | - static $groups; |
|
| 49 | - |
|
| 50 | - if (!isset($groups[$gperm_name]) || (null !== $id && !isset($groups[$gperm_name][$id]))) { |
|
| 51 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 52 | - //Get group permissions handler |
|
| 53 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 54 | - |
|
| 55 | - //Get groups allowed for an item id |
|
| 56 | - $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 57 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - //Return the permission array |
|
| 61 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param $item_ids_array |
|
| 66 | - * @param bool $gperm_name |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 70 | - { |
|
| 71 | - static $groups; |
|
| 72 | - |
|
| 73 | - if ($gperm_name) { |
|
| 74 | - if (isset($groups[$gperm_name])) { |
|
| 75 | - return $groups[$gperm_name]; |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 79 | - return $groups; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 83 | - |
|
| 84 | - $criteria = new \CriteriaCompo(); |
|
| 85 | - $criteria->add(new \Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 86 | - |
|
| 87 | - if ($gperm_name) { |
|
| 88 | - $criteria->add(new \Criteria('gperm_name', $gperm_name)); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - //Get group permissions handler |
|
| 92 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 93 | - |
|
| 94 | - $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 95 | - |
|
| 96 | - foreach ($permissionsObj as $permissionObj) { |
|
| 97 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - //Return the permission array |
|
| 101 | - if ($gperm_name) { |
|
| 102 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
| 103 | - } else { |
|
| 104 | - return isset($groups) ? $groups : []; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /* |
|
| 41 | + /** |
|
| 42 | + * @param $gperm_name |
|
| 43 | + * @param null $id |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function getGrantedGroups($gperm_name, $id = null) |
|
| 47 | + { |
|
| 48 | + static $groups; |
|
| 49 | + |
|
| 50 | + if (!isset($groups[$gperm_name]) || (null !== $id && !isset($groups[$gperm_name][$id]))) { |
|
| 51 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 52 | + //Get group permissions handler |
|
| 53 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 54 | + |
|
| 55 | + //Get groups allowed for an item id |
|
| 56 | + $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 57 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + //Return the permission array |
|
| 61 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param $item_ids_array |
|
| 66 | + * @param bool $gperm_name |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 70 | + { |
|
| 71 | + static $groups; |
|
| 72 | + |
|
| 73 | + if ($gperm_name) { |
|
| 74 | + if (isset($groups[$gperm_name])) { |
|
| 75 | + return $groups[$gperm_name]; |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 79 | + return $groups; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 83 | + |
|
| 84 | + $criteria = new \CriteriaCompo(); |
|
| 85 | + $criteria->add(new \Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 86 | + |
|
| 87 | + if ($gperm_name) { |
|
| 88 | + $criteria->add(new \Criteria('gperm_name', $gperm_name)); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + //Get group permissions handler |
|
| 92 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 93 | + |
|
| 94 | + $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 95 | + |
|
| 96 | + foreach ($permissionsObj as $permissionObj) { |
|
| 97 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + //Return the permission array |
|
| 101 | + if ($gperm_name) { |
|
| 102 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
| 103 | + } else { |
|
| 104 | + return isset($groups) ? $groups : []; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /* |
|
| 109 | 109 | * Returns permissions for a certain type |
| 110 | 110 | * |
| 111 | 111 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -113,123 +113,123 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return array |
| 115 | 115 | */ |
| 116 | - /** |
|
| 117 | - * @param $gperm_name |
|
| 118 | - * @param null $id |
|
| 119 | - * @return array |
|
| 120 | - */ |
|
| 121 | - public function getGrantedItems($gperm_name, $id = null) |
|
| 122 | - { |
|
| 123 | - global $xoopsUser; |
|
| 124 | - static $permissions; |
|
| 125 | - |
|
| 126 | - if (!isset($permissions[$gperm_name]) || (null !== $id && !isset($permissions[$gperm_name][$id]))) { |
|
| 127 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 128 | - |
|
| 129 | - if (is_object($smartModule)) { |
|
| 130 | - |
|
| 131 | - //Get group permissions handler |
|
| 132 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 133 | - |
|
| 134 | - //Get user's groups |
|
| 135 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 136 | - |
|
| 137 | - //Get all allowed item ids in this module and for this user's groups |
|
| 138 | - $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 139 | - $permissions[$gperm_name] = $userpermissions; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - //Return the permission array |
|
| 144 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param $id |
|
| 149 | - */ |
|
| 150 | - public function storeAllPermissionsForId($id) |
|
| 151 | - { |
|
| 152 | - foreach ($this->handler->getPermissions() as $permission) { |
|
| 153 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Saves permissions for the selected item |
|
| 159 | - * |
|
| 160 | - * saveItem_Permissions() |
|
| 161 | - * |
|
| 162 | - * @param array $groups : group with granted permission |
|
| 163 | - * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
| 164 | - * @param string $perm_name : name of the permission |
|
| 165 | - * @return bool : TRUE if the no errors occured |
|
| 166 | - */ |
|
| 167 | - |
|
| 168 | - public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 169 | - { |
|
| 170 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 171 | - |
|
| 172 | - $result = true; |
|
| 173 | - $module_id = $smartModule->getVar('mid'); |
|
| 174 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 175 | - |
|
| 176 | - // First, if the permissions are already there, delete them |
|
| 177 | - $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 178 | - //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 179 | - //exit; |
|
| 180 | - // Save the new permissions |
|
| 181 | - |
|
| 182 | - if (count($groups) > 0) { |
|
| 183 | - foreach ($groups as $group_id) { |
|
| 184 | - $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $result; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Delete all permission for a specific item |
|
| 193 | - * |
|
| 194 | - * deletePermissions() |
|
| 195 | - * |
|
| 196 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
| 197 | - * @param $gperm_name |
|
| 198 | - * @return bool: TRUE if the no errors occured |
|
| 199 | - */ |
|
| 200 | - public function deletePermissions($itemid, $gperm_name) |
|
| 201 | - { |
|
| 202 | - global $xoopsModule; |
|
| 203 | - |
|
| 204 | - $smartModule = smartsection_getModuleInfo(); |
|
| 205 | - |
|
| 206 | - $result = true; |
|
| 207 | - $module_id = $smartModule->getVar('mid'); |
|
| 208 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 209 | - |
|
| 210 | - $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 211 | - |
|
| 212 | - return $result; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Checks if the user has access to a specific permission on a given object |
|
| 217 | - * |
|
| 218 | - * @param string $gperm_name name of the permission to test |
|
| 219 | - * @param int $gperm_itemid id of the object to check |
|
| 220 | - * @return boolean: TRUE if user has access, FALSE if not |
|
| 221 | - **/ |
|
| 222 | - public function accessGranted($gperm_name, $gperm_itemid) |
|
| 223 | - { |
|
| 224 | - global $xoopsUser; |
|
| 225 | - |
|
| 226 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 227 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 228 | - $gperm_modid = $smartModule->getVar('mid'); |
|
| 229 | - |
|
| 230 | - //Get group permissions handler |
|
| 231 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 232 | - |
|
| 233 | - return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 234 | - } |
|
| 116 | + /** |
|
| 117 | + * @param $gperm_name |
|
| 118 | + * @param null $id |
|
| 119 | + * @return array |
|
| 120 | + */ |
|
| 121 | + public function getGrantedItems($gperm_name, $id = null) |
|
| 122 | + { |
|
| 123 | + global $xoopsUser; |
|
| 124 | + static $permissions; |
|
| 125 | + |
|
| 126 | + if (!isset($permissions[$gperm_name]) || (null !== $id && !isset($permissions[$gperm_name][$id]))) { |
|
| 127 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 128 | + |
|
| 129 | + if (is_object($smartModule)) { |
|
| 130 | + |
|
| 131 | + //Get group permissions handler |
|
| 132 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 133 | + |
|
| 134 | + //Get user's groups |
|
| 135 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 136 | + |
|
| 137 | + //Get all allowed item ids in this module and for this user's groups |
|
| 138 | + $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 139 | + $permissions[$gperm_name] = $userpermissions; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + //Return the permission array |
|
| 144 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param $id |
|
| 149 | + */ |
|
| 150 | + public function storeAllPermissionsForId($id) |
|
| 151 | + { |
|
| 152 | + foreach ($this->handler->getPermissions() as $permission) { |
|
| 153 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Saves permissions for the selected item |
|
| 159 | + * |
|
| 160 | + * saveItem_Permissions() |
|
| 161 | + * |
|
| 162 | + * @param array $groups : group with granted permission |
|
| 163 | + * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
| 164 | + * @param string $perm_name : name of the permission |
|
| 165 | + * @return bool : TRUE if the no errors occured |
|
| 166 | + */ |
|
| 167 | + |
|
| 168 | + public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 169 | + { |
|
| 170 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 171 | + |
|
| 172 | + $result = true; |
|
| 173 | + $module_id = $smartModule->getVar('mid'); |
|
| 174 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 175 | + |
|
| 176 | + // First, if the permissions are already there, delete them |
|
| 177 | + $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 178 | + //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 179 | + //exit; |
|
| 180 | + // Save the new permissions |
|
| 181 | + |
|
| 182 | + if (count($groups) > 0) { |
|
| 183 | + foreach ($groups as $group_id) { |
|
| 184 | + $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $result; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Delete all permission for a specific item |
|
| 193 | + * |
|
| 194 | + * deletePermissions() |
|
| 195 | + * |
|
| 196 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
| 197 | + * @param $gperm_name |
|
| 198 | + * @return bool: TRUE if the no errors occured |
|
| 199 | + */ |
|
| 200 | + public function deletePermissions($itemid, $gperm_name) |
|
| 201 | + { |
|
| 202 | + global $xoopsModule; |
|
| 203 | + |
|
| 204 | + $smartModule = smartsection_getModuleInfo(); |
|
| 205 | + |
|
| 206 | + $result = true; |
|
| 207 | + $module_id = $smartModule->getVar('mid'); |
|
| 208 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 209 | + |
|
| 210 | + $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 211 | + |
|
| 212 | + return $result; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Checks if the user has access to a specific permission on a given object |
|
| 217 | + * |
|
| 218 | + * @param string $gperm_name name of the permission to test |
|
| 219 | + * @param int $gperm_itemid id of the object to check |
|
| 220 | + * @return boolean: TRUE if user has access, FALSE if not |
|
| 221 | + **/ |
|
| 222 | + public function accessGranted($gperm_name, $gperm_itemid) |
|
| 223 | + { |
|
| 224 | + global $xoopsUser; |
|
| 225 | + |
|
| 226 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 227 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 228 | + $gperm_modid = $smartModule->getVar('mid'); |
|
| 229 | + |
|
| 230 | + //Get group permissions handler |
|
| 231 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 232 | + |
|
| 233 | + return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -33,511 +33,511 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class ObjectController |
| 35 | 35 | { |
| 36 | - public $handler; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * SmartObjectController constructor. |
|
| 40 | - * @param $handler |
|
| 41 | - */ |
|
| 42 | - public function __construct($handler) |
|
| 43 | - { |
|
| 44 | - $this->handler = $handler; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param $smartObj |
|
| 49 | - */ |
|
| 50 | - public function postDataToObject(&$smartObj) |
|
| 51 | - { |
|
| 52 | - foreach (array_keys($smartObj->vars) as $key) { |
|
| 53 | - switch ($smartObj->vars[$key]['data_type']) { |
|
| 54 | - case XOBJ_DTYPE_IMAGE: |
|
| 55 | - if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) { |
|
| 56 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
| 57 | - $smartObj->setVar($key, $_POST['url_' . $key]); |
|
| 58 | - if (file_exists($oldFile)) { |
|
| 59 | - unlink($oldFile); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
| 63 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
| 64 | - $smartObj->setVar($key, ''); |
|
| 65 | - if (file_exists($oldFile)) { |
|
| 66 | - unlink($oldFile); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - break; |
|
| 70 | - |
|
| 71 | - case XOBJ_DTYPE_URLLINK: |
|
| 72 | - $linkObj = $smartObj->getUrlLinkObj($key); |
|
| 73 | - $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
| 74 | - $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
| 75 | - $linkObj->setVar('target', $_POST['target_' . $key]); |
|
| 76 | - $linkObj->setVar('url', $_POST['url_' . $key]); |
|
| 77 | - if ('' !== $linkObj->getVar('url')) { |
|
| 78 | - $smartObj->storeUrlLinkObj($linkObj); |
|
| 79 | - } |
|
| 80 | - //todo: catch errors |
|
| 81 | - $smartObj->setVar($key, $linkObj->getVar('urllinkid')); |
|
| 82 | - break; |
|
| 83 | - |
|
| 84 | - case XOBJ_DTYPE_FILE: |
|
| 85 | - if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
| 86 | - $fileObj = $smartObj->getFileObj($key); |
|
| 87 | - $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
| 88 | - $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
| 89 | - $fileObj->setVar('url', $_POST['url_' . $key]); |
|
| 90 | - if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
|
| 91 | - && '' === $fileObj->getVar('url'))) { |
|
| 92 | - $res = $smartObj->storeFileObj($fileObj); |
|
| 93 | - if ($res) { |
|
| 94 | - $smartObj->setVar($key, $fileObj->getVar('fileid')); |
|
| 95 | - } else { |
|
| 96 | - //error setted, but no error message (to be improved) |
|
| 97 | - $smartObj->setErrors($fileObj->getErrors()); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - break; |
|
| 102 | - |
|
| 103 | - case XOBJ_DTYPE_STIME: |
|
| 104 | - case XOBJ_DTYPE_MTIME: |
|
| 105 | - case XOBJ_DTYPE_LTIME: |
|
| 106 | - // check if this field's value is available in the POST array |
|
| 107 | - if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) { |
|
| 108 | - $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time']; |
|
| 109 | - } else { |
|
| 110 | - $value = strtotime($_POST[$key]); |
|
| 111 | - //if strtotime returns false, the value is already a time stamp |
|
| 112 | - if (!$value) { |
|
| 113 | - $value = (int)$_POST[$key]; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - $smartObj->setVar($key, $value); |
|
| 117 | - |
|
| 118 | - break; |
|
| 119 | - |
|
| 120 | - default: |
|
| 121 | - $smartObj->setVar($key, $_POST[$key]); |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param $smartObj |
|
| 129 | - * @param $objectid |
|
| 130 | - * @param $created_success_msg |
|
| 131 | - * @param $modified_success_msg |
|
| 132 | - * @param bool $redirect_page |
|
| 133 | - * @param bool $debug |
|
| 134 | - * @return mixed |
|
| 135 | - */ |
|
| 136 | - public function doStoreFromDefaultForm( |
|
| 137 | - &$smartObj, |
|
| 138 | - $objectid, |
|
| 139 | - $created_success_msg, |
|
| 140 | - $modified_success_msg, |
|
| 141 | - $redirect_page = false, |
|
| 142 | - $debug = false |
|
| 143 | - ) { |
|
| 144 | - global $smart_previous_page; |
|
| 145 | - |
|
| 146 | - $this->postDataToObject($smartObj); |
|
| 147 | - |
|
| 148 | - if ($smartObj->isNew()) { |
|
| 149 | - $redirect_msg = $created_success_msg; |
|
| 150 | - } else { |
|
| 151 | - $redirect_msg = $modified_success_msg; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // Check if there were uploaded files |
|
| 155 | - if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { |
|
| 36 | + public $handler; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * SmartObjectController constructor. |
|
| 40 | + * @param $handler |
|
| 41 | + */ |
|
| 42 | + public function __construct($handler) |
|
| 43 | + { |
|
| 44 | + $this->handler = $handler; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param $smartObj |
|
| 49 | + */ |
|
| 50 | + public function postDataToObject(&$smartObj) |
|
| 51 | + { |
|
| 52 | + foreach (array_keys($smartObj->vars) as $key) { |
|
| 53 | + switch ($smartObj->vars[$key]['data_type']) { |
|
| 54 | + case XOBJ_DTYPE_IMAGE: |
|
| 55 | + if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) { |
|
| 56 | + $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
| 57 | + $smartObj->setVar($key, $_POST['url_' . $key]); |
|
| 58 | + if (file_exists($oldFile)) { |
|
| 59 | + unlink($oldFile); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
| 63 | + $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
| 64 | + $smartObj->setVar($key, ''); |
|
| 65 | + if (file_exists($oldFile)) { |
|
| 66 | + unlink($oldFile); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + break; |
|
| 70 | + |
|
| 71 | + case XOBJ_DTYPE_URLLINK: |
|
| 72 | + $linkObj = $smartObj->getUrlLinkObj($key); |
|
| 73 | + $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
| 74 | + $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
| 75 | + $linkObj->setVar('target', $_POST['target_' . $key]); |
|
| 76 | + $linkObj->setVar('url', $_POST['url_' . $key]); |
|
| 77 | + if ('' !== $linkObj->getVar('url')) { |
|
| 78 | + $smartObj->storeUrlLinkObj($linkObj); |
|
| 79 | + } |
|
| 80 | + //todo: catch errors |
|
| 81 | + $smartObj->setVar($key, $linkObj->getVar('urllinkid')); |
|
| 82 | + break; |
|
| 83 | + |
|
| 84 | + case XOBJ_DTYPE_FILE: |
|
| 85 | + if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
| 86 | + $fileObj = $smartObj->getFileObj($key); |
|
| 87 | + $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
| 88 | + $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
| 89 | + $fileObj->setVar('url', $_POST['url_' . $key]); |
|
| 90 | + if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
|
| 91 | + && '' === $fileObj->getVar('url'))) { |
|
| 92 | + $res = $smartObj->storeFileObj($fileObj); |
|
| 93 | + if ($res) { |
|
| 94 | + $smartObj->setVar($key, $fileObj->getVar('fileid')); |
|
| 95 | + } else { |
|
| 96 | + //error setted, but no error message (to be improved) |
|
| 97 | + $smartObj->setErrors($fileObj->getErrors()); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + break; |
|
| 102 | + |
|
| 103 | + case XOBJ_DTYPE_STIME: |
|
| 104 | + case XOBJ_DTYPE_MTIME: |
|
| 105 | + case XOBJ_DTYPE_LTIME: |
|
| 106 | + // check if this field's value is available in the POST array |
|
| 107 | + if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) { |
|
| 108 | + $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time']; |
|
| 109 | + } else { |
|
| 110 | + $value = strtotime($_POST[$key]); |
|
| 111 | + //if strtotime returns false, the value is already a time stamp |
|
| 112 | + if (!$value) { |
|
| 113 | + $value = (int)$_POST[$key]; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + $smartObj->setVar($key, $value); |
|
| 117 | + |
|
| 118 | + break; |
|
| 119 | + |
|
| 120 | + default: |
|
| 121 | + $smartObj->setVar($key, $_POST[$key]); |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param $smartObj |
|
| 129 | + * @param $objectid |
|
| 130 | + * @param $created_success_msg |
|
| 131 | + * @param $modified_success_msg |
|
| 132 | + * @param bool $redirect_page |
|
| 133 | + * @param bool $debug |
|
| 134 | + * @return mixed |
|
| 135 | + */ |
|
| 136 | + public function doStoreFromDefaultForm( |
|
| 137 | + &$smartObj, |
|
| 138 | + $objectid, |
|
| 139 | + $created_success_msg, |
|
| 140 | + $modified_success_msg, |
|
| 141 | + $redirect_page = false, |
|
| 142 | + $debug = false |
|
| 143 | + ) { |
|
| 144 | + global $smart_previous_page; |
|
| 145 | + |
|
| 146 | + $this->postDataToObject($smartObj); |
|
| 147 | + |
|
| 148 | + if ($smartObj->isNew()) { |
|
| 149 | + $redirect_msg = $created_success_msg; |
|
| 150 | + } else { |
|
| 151 | + $redirect_msg = $modified_success_msg; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // Check if there were uploaded files |
|
| 155 | + if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { |
|
| 156 | 156 | // require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php'; |
| 157 | - $uploaderObj = new Uploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); |
|
| 158 | - foreach ($_FILES as $name => $file_array) { |
|
| 159 | - if (isset($file_array['name']) && '' !== $file_array['name'] |
|
| 160 | - && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
|
| 161 | - if ($uploaderObj->fetchMedia($name)) { |
|
| 162 | - $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
| 163 | - if ($uploaderObj->upload()) { |
|
| 164 | - // Find the related field in the SmartObject |
|
| 165 | - $related_field = str_replace('upload_', '', $name); |
|
| 166 | - $uploadedArray[] = $related_field; |
|
| 167 | - //si c'est un fichier Rich |
|
| 168 | - if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
|
| 169 | - $object_fileurl = $smartObj->getUploadDir(); |
|
| 170 | - $fileObj = $smartObj->getFileObj($related_field); |
|
| 171 | - $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
| 172 | - $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
| 173 | - $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
| 174 | - $smartObj->storeFileObj($fileObj); |
|
| 175 | - //todo: catch errors |
|
| 176 | - $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
|
| 177 | - } else { |
|
| 178 | - $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
| 179 | - unlink($old_file); |
|
| 180 | - $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
|
| 181 | - } |
|
| 182 | - } else { |
|
| 183 | - $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
| 184 | - } |
|
| 185 | - } else { |
|
| 186 | - $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - if ($debug) { |
|
| 193 | - $storeResult = $this->handler->insertD($smartObj); |
|
| 194 | - } else { |
|
| 195 | - $storeResult = $this->handler->insert($smartObj); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if ($storeResult) { |
|
| 199 | - if ($this->handler->getPermissions()) { |
|
| 200 | - $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
| 201 | - $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id()); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - if (null === $redirect_page) { |
|
| 206 | - return $smartObj; |
|
| 207 | - } else { |
|
| 208 | - if (!$storeResult) { |
|
| 209 | - redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm(); |
|
| 213 | - |
|
| 214 | - redirect_header($redirect_page, 2, $redirect_msg); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Store the object in the database autmatically from a form sending POST data |
|
| 220 | - * |
|
| 221 | - * @param string $created_success_msg message to display if new object was created |
|
| 222 | - * @param string $modified_success_msg message to display if object was successfully edited |
|
| 223 | - * @param bool|string $redirect_page redirect page, if not set, then we backup once |
|
| 224 | - * @param bool $debug |
|
| 225 | - * @param bool $x_param |
|
| 226 | - * @return bool |
|
| 227 | - * @internal param string $created_redir_page redirect page after creating the object |
|
| 228 | - * @internal param string $modified_redir_page redirect page after editing the object |
|
| 229 | - * @internal param bool $exit if set to TRUE then the script ends |
|
| 230 | - */ |
|
| 231 | - public function storeFromDefaultForm( |
|
| 232 | - $created_success_msg, |
|
| 233 | - $modified_success_msg, |
|
| 234 | - $redirect_page = false, |
|
| 235 | - $debug = false, |
|
| 236 | - $x_param = false |
|
| 237 | - ) { |
|
| 238 | - $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
| 239 | - if ($debug) { |
|
| 240 | - if ($x_param) { |
|
| 241 | - $smartObj = $this->handler->getD($objectid, true, $x_param); |
|
| 242 | - } else { |
|
| 243 | - $smartObj = $this->handler->getD($objectid); |
|
| 244 | - } |
|
| 245 | - } else { |
|
| 246 | - if ($x_param) { |
|
| 247 | - $smartObj = $this->handler->get($objectid, true, false, false, $x_param); |
|
| 248 | - } else { |
|
| 249 | - $smartObj = $this->handler->get($objectid); |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - // if handler is the Multilanguage handler, we will need to treat this for multilanguage |
|
| 254 | - if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) { |
|
| 255 | - if ($smartObj->isNew()) { |
|
| 256 | - // This is a new object. We need to store the meta data and then the language data |
|
| 257 | - // First, we will get rid of the multilanguage data to only store the meta data |
|
| 258 | - $smartObj->stripMultilanguageFields(); |
|
| 259 | - $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
| 260 | - /** |
|
| 261 | - * @todo we need to trap potential errors here |
|
| 262 | - */ |
|
| 263 | - |
|
| 264 | - // ok, the meta daa is stored. Let's recreate the object and then |
|
| 265 | - // get rid of anything not multilanguage |
|
| 266 | - unset($smartObj); |
|
| 267 | - $smartObj = $this->handler->get($objectid); |
|
| 268 | - $smartObj->stripNonMultilanguageFields(); |
|
| 269 | - |
|
| 270 | - $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName)); |
|
| 271 | - $this->handler->changeTableNameForML(); |
|
| 272 | - $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
| 273 | - |
|
| 274 | - return $ret; |
|
| 275 | - } |
|
| 276 | - } else { |
|
| 277 | - return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @return bool |
|
| 283 | - */ |
|
| 284 | - public function storeSmartObjectD() |
|
| 285 | - { |
|
| 286 | - return $this->storeSmartObject(true); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @param bool $debug |
|
| 291 | - * @param bool $xparam |
|
| 292 | - * @return bool |
|
| 293 | - */ |
|
| 294 | - public function storeSmartObject($debug = false, $xparam = false) |
|
| 295 | - { |
|
| 296 | - $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam); |
|
| 297 | - |
|
| 298 | - return $ret; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Handles deletion of an object which keyid is passed as a GET param |
|
| 303 | - * |
|
| 304 | - * @param bool $confirm_msg |
|
| 305 | - * @param string $op |
|
| 306 | - * @param bool $userSide |
|
| 307 | - * @return void |
|
| 308 | - * @internal param string $redir_page redirect page after deleting the object |
|
| 309 | - */ |
|
| 310 | - public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false) |
|
| 311 | - { |
|
| 312 | - global $smart_previous_page; |
|
| 313 | - |
|
| 314 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
| 315 | - $smartObj = $this->handler->get($objectid); |
|
| 316 | - |
|
| 317 | - if ($smartObj->isNew()) { |
|
| 318 | - redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
| 322 | - if ($confirm) { |
|
| 323 | - if (!$this->handler->delete($smartObj)) { |
|
| 324 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
| 328 | - } else { |
|
| 329 | - // no confirm: show deletion condition |
|
| 330 | - |
|
| 331 | - xoops_cp_header(); |
|
| 332 | - |
|
| 333 | - if (!$confirm_msg) { |
|
| 334 | - $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - xoops_confirm([ |
|
| 338 | - 'op' => $op, |
|
| 339 | - $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
| 340 | - 'confirm' => 1, |
|
| 341 | - 'redirect_page' => $smart_previous_page |
|
| 342 | - ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
| 343 | - |
|
| 344 | - xoops_cp_footer(); |
|
| 345 | - } |
|
| 346 | - exit(); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * @param bool $confirm_msg |
|
| 351 | - * @param string $op |
|
| 352 | - */ |
|
| 353 | - public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del') |
|
| 354 | - { |
|
| 355 | - global $smart_previous_page, $xoopsTpl; |
|
| 356 | - |
|
| 357 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
| 358 | - $smartObj = $this->handler->get($objectid); |
|
| 359 | - |
|
| 360 | - if ($smartObj->isNew()) { |
|
| 361 | - redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
| 365 | - if ($confirm) { |
|
| 366 | - if (!$this->handler->delete($smartObj)) { |
|
| 367 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
| 371 | - } else { |
|
| 372 | - // no confirm: show deletion condition |
|
| 373 | - if (!$confirm_msg) { |
|
| 374 | - $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - ob_start(); |
|
| 378 | - xoops_confirm([ |
|
| 379 | - 'op' => $op, |
|
| 380 | - $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
| 381 | - 'confirm' => 1, |
|
| 382 | - 'redirect_page' => $smart_previous_page |
|
| 383 | - ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
| 384 | - $smartobjectDeleteConfirm = ob_get_clean(); |
|
| 385 | - $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm); |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Retreive the object admin side link for a {@link SmartObjectSingleView} page |
|
| 391 | - * |
|
| 392 | - * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
| 393 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 394 | - * @param bool $withimage |
|
| 395 | - * @return string admin side link to the object |
|
| 396 | - */ |
|
| 397 | - public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
|
| 398 | - { |
|
| 399 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 400 | - if ($onlyUrl) { |
|
| 401 | - return $ret; |
|
| 402 | - } elseif ($withimage) { |
|
| 403 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "' title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>"; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Retreive the object user side link |
|
| 411 | - * |
|
| 412 | - * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
| 413 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 414 | - * @return string user side link to the object |
|
| 415 | - */ |
|
| 416 | - public function getItemLink(SmartObject $smartObj, $onlyUrl = false) |
|
| 417 | - { |
|
| 418 | - $seoMode = Smartobject\Utility::getModuleModeSEO($this->handler->_moduleName); |
|
| 419 | - $seoModuleName = Smartobject\Utility::getModuleNameForSEO($this->handler->_moduleName); |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
| 423 | - */ |
|
| 424 | - //$seoIncludeId = Smartobject\Utility::getModuleIncludeIdSEO($this->handler->_moduleName); |
|
| 425 | - $seoIncludeId = true; |
|
| 426 | - |
|
| 427 | - if ('rewrite' === $seoMode) { |
|
| 428 | - $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
| 429 | - } elseif ('pathinfo' === $seoMode) { |
|
| 430 | - $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
| 431 | - } else { |
|
| 432 | - $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - if (!$onlyUrl) { |
|
| 436 | - $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - return $ret; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @param $smartObj |
|
| 444 | - * @param bool $onlyUrl |
|
| 445 | - * @param bool $withimage |
|
| 446 | - * @return string |
|
| 447 | - */ |
|
| 448 | - public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
|
| 449 | - { |
|
| 450 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
| 451 | - if ($onlyUrl) { |
|
| 452 | - return $ret; |
|
| 453 | - } elseif ($withimage) { |
|
| 454 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "' title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>"; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @param $smartObj |
|
| 462 | - * @param bool $onlyUrl |
|
| 463 | - * @param bool $withimage |
|
| 464 | - * @param bool $userSide |
|
| 465 | - * @return string |
|
| 466 | - */ |
|
| 467 | - public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
| 468 | - { |
|
| 469 | - $admin_side = $userSide ? '' : 'admin/'; |
|
| 470 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 471 | - if ($onlyUrl) { |
|
| 472 | - return $ret; |
|
| 473 | - } elseif ($withimage) { |
|
| 474 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "' title='" . _CO_SOBJECT_MODIFY . "'></a>"; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * @param $smartObj |
|
| 482 | - * @param bool $onlyUrl |
|
| 483 | - * @param bool $withimage |
|
| 484 | - * @param bool $userSide |
|
| 485 | - * @return string |
|
| 486 | - */ |
|
| 487 | - public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
| 488 | - { |
|
| 489 | - $admin_side = $userSide ? '' : 'admin/'; |
|
| 490 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 491 | - if ($onlyUrl) { |
|
| 492 | - return $ret; |
|
| 493 | - } elseif ($withimage) { |
|
| 494 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "' title='" . _CO_SOBJECT_DELETE . "'></a>"; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * @param $smartObj |
|
| 502 | - * @return string |
|
| 503 | - */ |
|
| 504 | - public function getPrintAndMailLink($smartObj) |
|
| 505 | - { |
|
| 506 | - global $xoopsConfig; |
|
| 507 | - |
|
| 508 | - $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 509 | - $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
| 510 | - $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
| 511 | - |
|
| 512 | - $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName); |
|
| 513 | - $link = Smartobject\Utility::getCurrentPage(); |
|
| 514 | - $mid = $smartModule->getVar('mid'); |
|
| 515 | - $friendlink = "<a href=\"javascript:openWithSelfMain('" |
|
| 516 | - . SMARTOBJECT_URL |
|
| 517 | - . 'sendlink.php?link=' |
|
| 518 | - . $link |
|
| 519 | - . '&mid=' |
|
| 520 | - . $mid |
|
| 521 | - . "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" |
|
| 522 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 523 | - . 'mail_send.png" alt="' |
|
| 524 | - . _CO_SOBJECT_EMAIL |
|
| 525 | - . '" title="' |
|
| 526 | - . _CO_SOBJECT_EMAIL |
|
| 527 | - . '" style="vertical-align: middle;"></a>'; |
|
| 528 | - |
|
| 529 | - $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
| 530 | - |
|
| 531 | - return $ret; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * @return string |
|
| 536 | - */ |
|
| 537 | - public function getModuleItemString() |
|
| 538 | - { |
|
| 539 | - $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
| 540 | - |
|
| 541 | - return $ret; |
|
| 542 | - } |
|
| 157 | + $uploaderObj = new Uploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); |
|
| 158 | + foreach ($_FILES as $name => $file_array) { |
|
| 159 | + if (isset($file_array['name']) && '' !== $file_array['name'] |
|
| 160 | + && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
|
| 161 | + if ($uploaderObj->fetchMedia($name)) { |
|
| 162 | + $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
| 163 | + if ($uploaderObj->upload()) { |
|
| 164 | + // Find the related field in the SmartObject |
|
| 165 | + $related_field = str_replace('upload_', '', $name); |
|
| 166 | + $uploadedArray[] = $related_field; |
|
| 167 | + //si c'est un fichier Rich |
|
| 168 | + if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
|
| 169 | + $object_fileurl = $smartObj->getUploadDir(); |
|
| 170 | + $fileObj = $smartObj->getFileObj($related_field); |
|
| 171 | + $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
| 172 | + $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
| 173 | + $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
| 174 | + $smartObj->storeFileObj($fileObj); |
|
| 175 | + //todo: catch errors |
|
| 176 | + $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
|
| 177 | + } else { |
|
| 178 | + $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
| 179 | + unlink($old_file); |
|
| 180 | + $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
|
| 181 | + } |
|
| 182 | + } else { |
|
| 183 | + $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
| 184 | + } |
|
| 185 | + } else { |
|
| 186 | + $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + if ($debug) { |
|
| 193 | + $storeResult = $this->handler->insertD($smartObj); |
|
| 194 | + } else { |
|
| 195 | + $storeResult = $this->handler->insert($smartObj); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if ($storeResult) { |
|
| 199 | + if ($this->handler->getPermissions()) { |
|
| 200 | + $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
| 201 | + $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id()); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + if (null === $redirect_page) { |
|
| 206 | + return $smartObj; |
|
| 207 | + } else { |
|
| 208 | + if (!$storeResult) { |
|
| 209 | + redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm(); |
|
| 213 | + |
|
| 214 | + redirect_header($redirect_page, 2, $redirect_msg); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Store the object in the database autmatically from a form sending POST data |
|
| 220 | + * |
|
| 221 | + * @param string $created_success_msg message to display if new object was created |
|
| 222 | + * @param string $modified_success_msg message to display if object was successfully edited |
|
| 223 | + * @param bool|string $redirect_page redirect page, if not set, then we backup once |
|
| 224 | + * @param bool $debug |
|
| 225 | + * @param bool $x_param |
|
| 226 | + * @return bool |
|
| 227 | + * @internal param string $created_redir_page redirect page after creating the object |
|
| 228 | + * @internal param string $modified_redir_page redirect page after editing the object |
|
| 229 | + * @internal param bool $exit if set to TRUE then the script ends |
|
| 230 | + */ |
|
| 231 | + public function storeFromDefaultForm( |
|
| 232 | + $created_success_msg, |
|
| 233 | + $modified_success_msg, |
|
| 234 | + $redirect_page = false, |
|
| 235 | + $debug = false, |
|
| 236 | + $x_param = false |
|
| 237 | + ) { |
|
| 238 | + $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
| 239 | + if ($debug) { |
|
| 240 | + if ($x_param) { |
|
| 241 | + $smartObj = $this->handler->getD($objectid, true, $x_param); |
|
| 242 | + } else { |
|
| 243 | + $smartObj = $this->handler->getD($objectid); |
|
| 244 | + } |
|
| 245 | + } else { |
|
| 246 | + if ($x_param) { |
|
| 247 | + $smartObj = $this->handler->get($objectid, true, false, false, $x_param); |
|
| 248 | + } else { |
|
| 249 | + $smartObj = $this->handler->get($objectid); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + // if handler is the Multilanguage handler, we will need to treat this for multilanguage |
|
| 254 | + if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) { |
|
| 255 | + if ($smartObj->isNew()) { |
|
| 256 | + // This is a new object. We need to store the meta data and then the language data |
|
| 257 | + // First, we will get rid of the multilanguage data to only store the meta data |
|
| 258 | + $smartObj->stripMultilanguageFields(); |
|
| 259 | + $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
| 260 | + /** |
|
| 261 | + * @todo we need to trap potential errors here |
|
| 262 | + */ |
|
| 263 | + |
|
| 264 | + // ok, the meta daa is stored. Let's recreate the object and then |
|
| 265 | + // get rid of anything not multilanguage |
|
| 266 | + unset($smartObj); |
|
| 267 | + $smartObj = $this->handler->get($objectid); |
|
| 268 | + $smartObj->stripNonMultilanguageFields(); |
|
| 269 | + |
|
| 270 | + $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName)); |
|
| 271 | + $this->handler->changeTableNameForML(); |
|
| 272 | + $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
| 273 | + |
|
| 274 | + return $ret; |
|
| 275 | + } |
|
| 276 | + } else { |
|
| 277 | + return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @return bool |
|
| 283 | + */ |
|
| 284 | + public function storeSmartObjectD() |
|
| 285 | + { |
|
| 286 | + return $this->storeSmartObject(true); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @param bool $debug |
|
| 291 | + * @param bool $xparam |
|
| 292 | + * @return bool |
|
| 293 | + */ |
|
| 294 | + public function storeSmartObject($debug = false, $xparam = false) |
|
| 295 | + { |
|
| 296 | + $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam); |
|
| 297 | + |
|
| 298 | + return $ret; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Handles deletion of an object which keyid is passed as a GET param |
|
| 303 | + * |
|
| 304 | + * @param bool $confirm_msg |
|
| 305 | + * @param string $op |
|
| 306 | + * @param bool $userSide |
|
| 307 | + * @return void |
|
| 308 | + * @internal param string $redir_page redirect page after deleting the object |
|
| 309 | + */ |
|
| 310 | + public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false) |
|
| 311 | + { |
|
| 312 | + global $smart_previous_page; |
|
| 313 | + |
|
| 314 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
| 315 | + $smartObj = $this->handler->get($objectid); |
|
| 316 | + |
|
| 317 | + if ($smartObj->isNew()) { |
|
| 318 | + redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
| 322 | + if ($confirm) { |
|
| 323 | + if (!$this->handler->delete($smartObj)) { |
|
| 324 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
| 328 | + } else { |
|
| 329 | + // no confirm: show deletion condition |
|
| 330 | + |
|
| 331 | + xoops_cp_header(); |
|
| 332 | + |
|
| 333 | + if (!$confirm_msg) { |
|
| 334 | + $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + xoops_confirm([ |
|
| 338 | + 'op' => $op, |
|
| 339 | + $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
| 340 | + 'confirm' => 1, |
|
| 341 | + 'redirect_page' => $smart_previous_page |
|
| 342 | + ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
| 343 | + |
|
| 344 | + xoops_cp_footer(); |
|
| 345 | + } |
|
| 346 | + exit(); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * @param bool $confirm_msg |
|
| 351 | + * @param string $op |
|
| 352 | + */ |
|
| 353 | + public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del') |
|
| 354 | + { |
|
| 355 | + global $smart_previous_page, $xoopsTpl; |
|
| 356 | + |
|
| 357 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
| 358 | + $smartObj = $this->handler->get($objectid); |
|
| 359 | + |
|
| 360 | + if ($smartObj->isNew()) { |
|
| 361 | + redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
| 365 | + if ($confirm) { |
|
| 366 | + if (!$this->handler->delete($smartObj)) { |
|
| 367 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
| 371 | + } else { |
|
| 372 | + // no confirm: show deletion condition |
|
| 373 | + if (!$confirm_msg) { |
|
| 374 | + $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + ob_start(); |
|
| 378 | + xoops_confirm([ |
|
| 379 | + 'op' => $op, |
|
| 380 | + $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
| 381 | + 'confirm' => 1, |
|
| 382 | + 'redirect_page' => $smart_previous_page |
|
| 383 | + ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
| 384 | + $smartobjectDeleteConfirm = ob_get_clean(); |
|
| 385 | + $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm); |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Retreive the object admin side link for a {@link SmartObjectSingleView} page |
|
| 391 | + * |
|
| 392 | + * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
| 393 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 394 | + * @param bool $withimage |
|
| 395 | + * @return string admin side link to the object |
|
| 396 | + */ |
|
| 397 | + public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
|
| 398 | + { |
|
| 399 | + $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 400 | + if ($onlyUrl) { |
|
| 401 | + return $ret; |
|
| 402 | + } elseif ($withimage) { |
|
| 403 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "' title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>"; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Retreive the object user side link |
|
| 411 | + * |
|
| 412 | + * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
| 413 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 414 | + * @return string user side link to the object |
|
| 415 | + */ |
|
| 416 | + public function getItemLink(SmartObject $smartObj, $onlyUrl = false) |
|
| 417 | + { |
|
| 418 | + $seoMode = Smartobject\Utility::getModuleModeSEO($this->handler->_moduleName); |
|
| 419 | + $seoModuleName = Smartobject\Utility::getModuleNameForSEO($this->handler->_moduleName); |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
| 423 | + */ |
|
| 424 | + //$seoIncludeId = Smartobject\Utility::getModuleIncludeIdSEO($this->handler->_moduleName); |
|
| 425 | + $seoIncludeId = true; |
|
| 426 | + |
|
| 427 | + if ('rewrite' === $seoMode) { |
|
| 428 | + $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
| 429 | + } elseif ('pathinfo' === $seoMode) { |
|
| 430 | + $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
| 431 | + } else { |
|
| 432 | + $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + if (!$onlyUrl) { |
|
| 436 | + $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + return $ret; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @param $smartObj |
|
| 444 | + * @param bool $onlyUrl |
|
| 445 | + * @param bool $withimage |
|
| 446 | + * @return string |
|
| 447 | + */ |
|
| 448 | + public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
|
| 449 | + { |
|
| 450 | + $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
| 451 | + if ($onlyUrl) { |
|
| 452 | + return $ret; |
|
| 453 | + } elseif ($withimage) { |
|
| 454 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "' title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>"; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @param $smartObj |
|
| 462 | + * @param bool $onlyUrl |
|
| 463 | + * @param bool $withimage |
|
| 464 | + * @param bool $userSide |
|
| 465 | + * @return string |
|
| 466 | + */ |
|
| 467 | + public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
| 468 | + { |
|
| 469 | + $admin_side = $userSide ? '' : 'admin/'; |
|
| 470 | + $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 471 | + if ($onlyUrl) { |
|
| 472 | + return $ret; |
|
| 473 | + } elseif ($withimage) { |
|
| 474 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "' title='" . _CO_SOBJECT_MODIFY . "'></a>"; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * @param $smartObj |
|
| 482 | + * @param bool $onlyUrl |
|
| 483 | + * @param bool $withimage |
|
| 484 | + * @param bool $userSide |
|
| 485 | + * @return string |
|
| 486 | + */ |
|
| 487 | + public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
| 488 | + { |
|
| 489 | + $admin_side = $userSide ? '' : 'admin/'; |
|
| 490 | + $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 491 | + if ($onlyUrl) { |
|
| 492 | + return $ret; |
|
| 493 | + } elseif ($withimage) { |
|
| 494 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "' title='" . _CO_SOBJECT_DELETE . "'></a>"; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * @param $smartObj |
|
| 502 | + * @return string |
|
| 503 | + */ |
|
| 504 | + public function getPrintAndMailLink($smartObj) |
|
| 505 | + { |
|
| 506 | + global $xoopsConfig; |
|
| 507 | + |
|
| 508 | + $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 509 | + $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
| 510 | + $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
| 511 | + |
|
| 512 | + $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName); |
|
| 513 | + $link = Smartobject\Utility::getCurrentPage(); |
|
| 514 | + $mid = $smartModule->getVar('mid'); |
|
| 515 | + $friendlink = "<a href=\"javascript:openWithSelfMain('" |
|
| 516 | + . SMARTOBJECT_URL |
|
| 517 | + . 'sendlink.php?link=' |
|
| 518 | + . $link |
|
| 519 | + . '&mid=' |
|
| 520 | + . $mid |
|
| 521 | + . "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" |
|
| 522 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 523 | + . 'mail_send.png" alt="' |
|
| 524 | + . _CO_SOBJECT_EMAIL |
|
| 525 | + . '" title="' |
|
| 526 | + . _CO_SOBJECT_EMAIL |
|
| 527 | + . '" style="vertical-align: middle;"></a>'; |
|
| 528 | + |
|
| 529 | + $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
| 530 | + |
|
| 531 | + return $ret; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * @return string |
|
| 536 | + */ |
|
| 537 | + public function getModuleItemString() |
|
| 538 | + { |
|
| 539 | + $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
| 540 | + |
|
| 541 | + return $ret; |
|
| 542 | + } |
|
| 543 | 543 | } |