@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
| 179 | - * @param $key |
|
| 179 | + * @param string $key |
|
| 180 | 180 | * @param $data_type |
| 181 | 181 | * @param bool $itemName |
| 182 | 182 | * @param string $form_caption |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
| 213 | 213 | * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
| 214 | 214 | * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
| 215 | - * @param mixed $value default value of this variable |
|
| 215 | + * @param string|false $value default value of this variable |
|
| 216 | 216 | */ |
| 217 | 217 | public function quickInitVar( |
| 218 | 218 | $key, |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | - * @param $varname |
|
| 230 | + * @param string $varname |
|
| 231 | 231 | * @param bool $displayOnForm |
| 232 | 232 | * @param string $default |
| 233 | 233 | */ |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | /** |
| 490 | 490 | * add an error |
| 491 | 491 | * |
| 492 | - * @param $err_str |
|
| 492 | + * @param string $err_str |
|
| 493 | 493 | * @param bool $prefix |
| 494 | 494 | * @internal param string $value error to add |
| 495 | 495 | * @access public |
@@ -751,8 +751,8 @@ discard block |
||
| 751 | 751 | |
| 752 | 752 | /** |
| 753 | 753 | * @param $key |
| 754 | - * @param $info |
|
| 755 | - * @param $value |
|
| 754 | + * @param string $info |
|
| 755 | + * @param boolean $value |
|
| 756 | 756 | */ |
| 757 | 757 | public function setVarInfo($key, $info, $value) |
| 758 | 758 | { |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | /** |
| 763 | - * @param $key |
|
| 763 | + * @param string $key |
|
| 764 | 764 | * @param bool $editor |
| 765 | 765 | * @return string |
| 766 | 766 | */ |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | * @access public |
| 940 | 940 | * @param string $key key of the object's variable to be returned |
| 941 | 941 | * @param string $format format to use for the output |
| 942 | - * @return mixed formatted value of the variable |
|
| 942 | + * @return string formatted value of the variable |
|
| 943 | 943 | */ |
| 944 | 944 | public function getVar($key, $format = 's') |
| 945 | 945 | { |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | /** |
| 1252 | - * @param $key |
|
| 1252 | + * @param string $key |
|
| 1253 | 1253 | */ |
| 1254 | 1254 | public function hideFieldFromForm($key) |
| 1255 | 1255 | { |
@@ -18,31 +18,31 @@ discard block |
||
| 18 | 18 | require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
| 19 | 19 | |
| 20 | 20 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
| 21 | - define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
| 21 | + define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
| 22 | 22 | } |
| 23 | 23 | if (!defined('XOBJ_DTYPE_CURRENCY')) { |
| 24 | - define('XOBJ_DTYPE_CURRENCY', 200); |
|
| 24 | + define('XOBJ_DTYPE_CURRENCY', 200); |
|
| 25 | 25 | } |
| 26 | 26 | if (!defined('XOBJ_DTYPE_FLOAT')) { |
| 27 | - define('XOBJ_DTYPE_FLOAT', 201); |
|
| 27 | + define('XOBJ_DTYPE_FLOAT', 201); |
|
| 28 | 28 | } |
| 29 | 29 | if (!defined('XOBJ_DTYPE_TIME_ONLY')) { |
| 30 | - define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
| 30 | + define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
| 31 | 31 | } |
| 32 | 32 | if (!defined('XOBJ_DTYPE_URLLINK')) { |
| 33 | - define('XOBJ_DTYPE_URLLINK', 203); |
|
| 33 | + define('XOBJ_DTYPE_URLLINK', 203); |
|
| 34 | 34 | } |
| 35 | 35 | if (!defined('XOBJ_DTYPE_FILE')) { |
| 36 | - define('XOBJ_DTYPE_FILE', 204); |
|
| 36 | + define('XOBJ_DTYPE_FILE', 204); |
|
| 37 | 37 | } |
| 38 | 38 | if (!defined('XOBJ_DTYPE_IMAGE')) { |
| 39 | - define('XOBJ_DTYPE_IMAGE', 205); |
|
| 39 | + define('XOBJ_DTYPE_IMAGE', 205); |
|
| 40 | 40 | } |
| 41 | 41 | if (!defined('XOBJ_DTYPE_FORM_SECTION')) { |
| 42 | - define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
| 42 | + define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
| 43 | 43 | } |
| 44 | 44 | if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) { |
| 45 | - define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
| 45 | + define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -56,1399 +56,1399 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | class BaseSmartObject extends \XoopsObject |
| 58 | 58 | { |
| 59 | - public $_image_path; |
|
| 60 | - public $_image_url; |
|
| 61 | - |
|
| 62 | - public $seoEnabled = false; |
|
| 63 | - public $titleField; |
|
| 64 | - public $summaryField = false; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Reference to the handler managing this object |
|
| 68 | - * |
|
| 69 | - * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
| 70 | - */ |
|
| 71 | - public $handler; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * References to control objects, managing the form fields of this object |
|
| 75 | - */ |
|
| 76 | - public $controls = []; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * SmartObject constructor. |
|
| 80 | - * @param $handler |
|
| 81 | - */ |
|
| 82 | - public function __construct($handler) |
|
| 83 | - { |
|
| 84 | - $this->handler = $handler; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Checks if the user has a specific access on this object |
|
| 89 | - * |
|
| 90 | - * @param $perm_name |
|
| 91 | - * @return bool: TRUE if user has access, false if not |
|
| 92 | - * @internal param string $gperm_name name of the permission to test |
|
| 93 | - */ |
|
| 94 | - public function accessGranted($perm_name) |
|
| 95 | - { |
|
| 96 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
| 97 | - |
|
| 98 | - return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param $section_name |
|
| 103 | - * @param bool $value |
|
| 104 | - * @param bool $hide |
|
| 105 | - */ |
|
| 106 | - public function addFormSection($section_name, $value = false, $hide = false) |
|
| 107 | - { |
|
| 108 | - $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
| 109 | - $this->vars[$section_name]['hide'] = $hide; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @param $section_name |
|
| 114 | - */ |
|
| 115 | - public function closeSection($section_name) |
|
| 116 | - { |
|
| 117 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * |
|
| 122 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
| 123 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
| 124 | - * @param mixed $value default value of this variable |
|
| 125 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
| 126 | - * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
| 127 | - * @param string $options does this data have any select options? |
|
| 128 | - * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
| 129 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
| 130 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
| 131 | - * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
| 132 | - * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
| 133 | - * @param bool $displayOnForm |
|
| 134 | - */ |
|
| 135 | - public function initVar( |
|
| 136 | - $key, |
|
| 137 | - $data_type, |
|
| 138 | - $value = null, |
|
| 139 | - $required = false, |
|
| 140 | - $maxlength = null, |
|
| 141 | - $options = '', |
|
| 142 | - $multilingual = false, |
|
| 143 | - $form_caption = '', |
|
| 144 | - $form_dsc = '', |
|
| 145 | - $sortby = false, |
|
| 146 | - $persistent = true, |
|
| 147 | - $displayOnForm = true |
|
| 148 | - ) { |
|
| 149 | - //url_ is reserved for files. |
|
| 150 | - if (0 === strpos($key, 'url_')) { |
|
| 151 | - trigger_error("Cannot use variable starting with 'url_'."); |
|
| 152 | - } |
|
| 153 | - parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
| 154 | - if ($this->handler && (!$form_caption || '' === $form_caption)) { |
|
| 155 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
| 156 | - if (defined($dyn_form_caption)) { |
|
| 157 | - $form_caption = constant($dyn_form_caption); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - if ($this->handler && (!$form_dsc || '' === $form_dsc)) { |
|
| 161 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
| 162 | - if (defined($dyn_form_dsc)) { |
|
| 163 | - $form_dsc = constant($dyn_form_dsc); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $this->vars[$key] = array_merge($this->vars[$key], [ |
|
| 168 | - 'multilingual' => $multilingual, |
|
| 169 | - 'form_caption' => $form_caption, |
|
| 170 | - 'form_dsc' => $form_dsc, |
|
| 171 | - 'sortby' => $sortby, |
|
| 172 | - 'persistent' => $persistent, |
|
| 173 | - 'displayOnForm' => $displayOnForm, |
|
| 174 | - 'displayOnSingleView' => true, |
|
| 175 | - 'readonly' => false |
|
| 176 | - ]); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @param $key |
|
| 181 | - * @param $data_type |
|
| 182 | - * @param bool $itemName |
|
| 183 | - * @param string $form_caption |
|
| 184 | - * @param bool $sortby |
|
| 185 | - * @param string $value |
|
| 186 | - * @param bool $displayOnForm |
|
| 187 | - * @param bool $required |
|
| 188 | - */ |
|
| 189 | - public function initNonPersistableVar( |
|
| 190 | - $key, |
|
| 191 | - $data_type, |
|
| 192 | - $itemName = false, |
|
| 193 | - $form_caption = '', |
|
| 194 | - $sortby = false, |
|
| 195 | - $value = '', |
|
| 196 | - $displayOnForm = false, |
|
| 197 | - $required = false |
|
| 198 | - ) { |
|
| 199 | - $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
| 200 | - $this->vars[$key]['itemName'] = $itemName; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Quickly initiate a var |
|
| 205 | - * |
|
| 206 | - * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
| 207 | - * |
|
| 208 | - * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
| 209 | - * - all other vars are NULL or '' depending of the parameter |
|
| 210 | - * |
|
| 211 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
| 212 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
| 213 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
| 214 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
| 215 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
| 216 | - * @param mixed $value default value of this variable |
|
| 217 | - */ |
|
| 218 | - public function quickInitVar( |
|
| 219 | - $key, |
|
| 220 | - $data_type, |
|
| 221 | - $required = false, |
|
| 222 | - $form_caption = '', |
|
| 223 | - $form_dsc = '', |
|
| 224 | - $value = null |
|
| 225 | - ) { |
|
| 226 | - $maxlength = 'XOBJ_DTYPE_TXTBOX' === $data_type ? 255 : null; |
|
| 227 | - $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @param $varname |
|
| 232 | - * @param bool $displayOnForm |
|
| 233 | - * @param string $default |
|
| 234 | - */ |
|
| 235 | - public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
| 236 | - { |
|
| 237 | - switch ($varname) { |
|
| 238 | - case 'dohtml': |
|
| 239 | - $value = 'notdefined' !== $default ? $default : true; |
|
| 240 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 241 | - $this->setControl($varname, 'yesno'); |
|
| 242 | - break; |
|
| 243 | - |
|
| 244 | - case 'dobr': |
|
| 245 | - $value = ('notdefined' === $default) ? true : $default; |
|
| 246 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 247 | - $this->setControl($varname, 'yesno'); |
|
| 248 | - break; |
|
| 249 | - |
|
| 250 | - case 'doimage': |
|
| 251 | - $value = 'notdefined' !== $default ? $default : true; |
|
| 252 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 253 | - $this->setControl($varname, 'yesno'); |
|
| 254 | - break; |
|
| 255 | - |
|
| 256 | - case 'dosmiley': |
|
| 257 | - $value = 'notdefined' !== $default ? $default : true; |
|
| 258 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 259 | - $this->setControl($varname, 'yesno'); |
|
| 260 | - break; |
|
| 261 | - |
|
| 262 | - case 'doxcode': |
|
| 263 | - $value = 'notdefined' !== $default ? $default : true; |
|
| 264 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 265 | - $this->setControl($varname, 'yesno'); |
|
| 266 | - break; |
|
| 267 | - |
|
| 268 | - case 'meta_keywords': |
|
| 269 | - $value = 'notdefined' !== $default ? $default : ''; |
|
| 270 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
| 271 | - $this->setControl('meta_keywords', [ |
|
| 272 | - 'name' => 'textarea', |
|
| 273 | - 'form_editor' => 'textarea' |
|
| 274 | - ]); |
|
| 275 | - break; |
|
| 276 | - |
|
| 277 | - case 'meta_description': |
|
| 278 | - $value = 'notdefined' !== $default ? $default : ''; |
|
| 279 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
| 280 | - $this->setControl('meta_description', [ |
|
| 281 | - 'name' => 'textarea', |
|
| 282 | - 'form_editor' => 'textarea' |
|
| 283 | - ]); |
|
| 284 | - break; |
|
| 285 | - |
|
| 286 | - case 'short_url': |
|
| 287 | - $value = 'notdefined' !== $default ? $default : ''; |
|
| 288 | - $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
| 289 | - break; |
|
| 290 | - |
|
| 291 | - case 'hierarchy_path': |
|
| 292 | - $value = 'notdefined' !== $default ? $default : ''; |
|
| 293 | - $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
| 294 | - break; |
|
| 295 | - |
|
| 296 | - case 'counter': |
|
| 297 | - $value = 'notdefined' !== $default ? $default : 0; |
|
| 298 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 299 | - break; |
|
| 300 | - |
|
| 301 | - case 'weight': |
|
| 302 | - $value = 'notdefined' !== $default ? $default : 0; |
|
| 303 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
| 304 | - break; |
|
| 305 | - case 'custom_css': |
|
| 306 | - $value = 'notdefined' !== $default ? $default : ''; |
|
| 307 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
| 308 | - $this->setControl('custom_css', [ |
|
| 309 | - 'name' => 'textarea', |
|
| 310 | - 'form_editor' => 'textarea' |
|
| 311 | - ]); |
|
| 312 | - break; |
|
| 313 | - } |
|
| 314 | - $this->hideFieldFromSingleView($varname); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Set control information for an instance variable |
|
| 319 | - * |
|
| 320 | - * The $options parameter can be a string or an array. Using a string |
|
| 321 | - * is the quickest way: |
|
| 322 | - * |
|
| 323 | - * $this->setControl('date', 'date_time'); |
|
| 324 | - * |
|
| 325 | - * This will create a date and time selectbox for the 'date' var on the |
|
| 326 | - * form to edit or create this item. |
|
| 327 | - * |
|
| 328 | - * Here are the currently supported controls: |
|
| 329 | - * |
|
| 330 | - * - color |
|
| 331 | - * - country |
|
| 332 | - * - date_time |
|
| 333 | - * - date |
|
| 334 | ||
| 335 | - * - group |
|
| 336 | - * - group_multi |
|
| 337 | - * - image |
|
| 338 | - * - imageupload |
|
| 339 | - * - label |
|
| 340 | - * - language |
|
| 341 | - * - parentcategory |
|
| 342 | - * - password |
|
| 343 | - * - select_multi |
|
| 344 | - * - select |
|
| 345 | - * - text |
|
| 346 | - * - textarea |
|
| 347 | - * - theme |
|
| 348 | - * - theme_multi |
|
| 349 | - * - timezone |
|
| 350 | - * - user |
|
| 351 | - * - user_multi |
|
| 352 | - * - yesno |
|
| 353 | - * |
|
| 354 | - * Now, using an array as $options, you can customize what information to |
|
| 355 | - * use in the control. For example, if one needs to display a select box for |
|
| 356 | - * the user to choose the status of an item. We only need to tell SmartObject |
|
| 357 | - * what method to execute within what handler to retreive the options of the |
|
| 358 | - * selectbox. |
|
| 359 | - * |
|
| 360 | - * $this->setControl('status', array('name' => false, |
|
| 361 | - * 'itemHandler' => 'item', |
|
| 362 | - * 'method' => 'getStatus', |
|
| 363 | - * 'module' => 'smartshop')); |
|
| 364 | - * |
|
| 365 | - * In this example, the array elements are the following: |
|
| 366 | - * - name: false, as we don't need to set a special control here. |
|
| 367 | - * we will use the default control related to the object type (defined in initVar) |
|
| 368 | - * - itemHandler: name of the object for which we will use the handler |
|
| 369 | - * - method: name of the method of this handler that we will execute |
|
| 370 | - * - module: name of the module from wich the handler is |
|
| 371 | - * |
|
| 372 | - * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
| 373 | - * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
| 374 | - * |
|
| 375 | - * Another example of the use of $options as an array is for TextArea: |
|
| 376 | - * |
|
| 377 | - * $this->setControl('body', array('name' => 'textarea', |
|
| 378 | - * 'form_editor' => 'default')); |
|
| 379 | - * |
|
| 380 | - * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
| 381 | - * the 'default' editor, providing it is defined in the module |
|
| 382 | - * preferences: $xoopsModuleConfig['default_editor'] |
|
| 383 | - * |
|
| 384 | - * Of course, you can force the use of a specific editor: |
|
| 385 | - * |
|
| 386 | - * $this->setControl('body', array('name' => 'textarea', |
|
| 387 | - * 'form_editor' => 'koivi')); |
|
| 388 | - * |
|
| 389 | - * Here is a list of supported editor: |
|
| 390 | - * - tiny: TinyEditor |
|
| 391 | - * - dhtmltextarea: XOOPS DHTML Area |
|
| 392 | - * - fckeditor: FCKEditor |
|
| 393 | - * - inbetween: InBetween |
|
| 394 | - * - koivi: Koivi |
|
| 395 | - * - spaw: Spaw WYSIWYG Editor |
|
| 396 | - * - htmlarea: HTMLArea |
|
| 397 | - * - textarea: basic textarea with no options |
|
| 398 | - * |
|
| 399 | - * @param string $var name of the variable for which we want to set a control |
|
| 400 | - * @param array $options |
|
| 401 | - */ |
|
| 402 | - public function setControl($var, $options = []) |
|
| 403 | - { |
|
| 404 | - if (isset($this->controls[$var])) { |
|
| 405 | - unset($this->controls[$var]); |
|
| 406 | - } |
|
| 407 | - if (is_string($options)) { |
|
| 408 | - $options = ['name' => $options]; |
|
| 409 | - } |
|
| 410 | - $this->controls[$var] = $options; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Get control information for an instance variable |
|
| 415 | - * |
|
| 416 | - * @param string $var |
|
| 417 | - * @return bool|mixed |
|
| 418 | - */ |
|
| 419 | - public function getControl($var) |
|
| 420 | - { |
|
| 421 | - return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Create the form for this object |
|
| 426 | - * |
|
| 427 | - * @param $form_caption |
|
| 428 | - * @param $form_name |
|
| 429 | - * @param bool $form_action |
|
| 430 | - * @param string $submit_button_caption |
|
| 431 | - * @param bool $cancel_js_action |
|
| 432 | - * @param bool $captcha |
|
| 433 | - * @return \XoopsModules\Smartobject\Form\SmartobjectForm <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
| 434 | - * object for this object |
|
| 435 | - * @see SmartObjectForm::SmartObjectForm() |
|
| 436 | - */ |
|
| 437 | - public function getForm( |
|
| 438 | - $form_caption, |
|
| 439 | - $form_name, |
|
| 440 | - $form_action = false, |
|
| 441 | - $submit_button_caption = _CO_SOBJECT_SUBMIT, |
|
| 442 | - $cancel_js_action = false, |
|
| 443 | - $captcha = false |
|
| 444 | - ) { |
|
| 59 | + public $_image_path; |
|
| 60 | + public $_image_url; |
|
| 61 | + |
|
| 62 | + public $seoEnabled = false; |
|
| 63 | + public $titleField; |
|
| 64 | + public $summaryField = false; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Reference to the handler managing this object |
|
| 68 | + * |
|
| 69 | + * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
| 70 | + */ |
|
| 71 | + public $handler; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * References to control objects, managing the form fields of this object |
|
| 75 | + */ |
|
| 76 | + public $controls = []; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * SmartObject constructor. |
|
| 80 | + * @param $handler |
|
| 81 | + */ |
|
| 82 | + public function __construct($handler) |
|
| 83 | + { |
|
| 84 | + $this->handler = $handler; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Checks if the user has a specific access on this object |
|
| 89 | + * |
|
| 90 | + * @param $perm_name |
|
| 91 | + * @return bool: TRUE if user has access, false if not |
|
| 92 | + * @internal param string $gperm_name name of the permission to test |
|
| 93 | + */ |
|
| 94 | + public function accessGranted($perm_name) |
|
| 95 | + { |
|
| 96 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
| 97 | + |
|
| 98 | + return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param $section_name |
|
| 103 | + * @param bool $value |
|
| 104 | + * @param bool $hide |
|
| 105 | + */ |
|
| 106 | + public function addFormSection($section_name, $value = false, $hide = false) |
|
| 107 | + { |
|
| 108 | + $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
| 109 | + $this->vars[$section_name]['hide'] = $hide; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @param $section_name |
|
| 114 | + */ |
|
| 115 | + public function closeSection($section_name) |
|
| 116 | + { |
|
| 117 | + $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * |
|
| 122 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
| 123 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
| 124 | + * @param mixed $value default value of this variable |
|
| 125 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
| 126 | + * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
| 127 | + * @param string $options does this data have any select options? |
|
| 128 | + * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
| 129 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
| 130 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
| 131 | + * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
| 132 | + * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
| 133 | + * @param bool $displayOnForm |
|
| 134 | + */ |
|
| 135 | + public function initVar( |
|
| 136 | + $key, |
|
| 137 | + $data_type, |
|
| 138 | + $value = null, |
|
| 139 | + $required = false, |
|
| 140 | + $maxlength = null, |
|
| 141 | + $options = '', |
|
| 142 | + $multilingual = false, |
|
| 143 | + $form_caption = '', |
|
| 144 | + $form_dsc = '', |
|
| 145 | + $sortby = false, |
|
| 146 | + $persistent = true, |
|
| 147 | + $displayOnForm = true |
|
| 148 | + ) { |
|
| 149 | + //url_ is reserved for files. |
|
| 150 | + if (0 === strpos($key, 'url_')) { |
|
| 151 | + trigger_error("Cannot use variable starting with 'url_'."); |
|
| 152 | + } |
|
| 153 | + parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
| 154 | + if ($this->handler && (!$form_caption || '' === $form_caption)) { |
|
| 155 | + $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
| 156 | + if (defined($dyn_form_caption)) { |
|
| 157 | + $form_caption = constant($dyn_form_caption); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + if ($this->handler && (!$form_dsc || '' === $form_dsc)) { |
|
| 161 | + $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
| 162 | + if (defined($dyn_form_dsc)) { |
|
| 163 | + $form_dsc = constant($dyn_form_dsc); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $this->vars[$key] = array_merge($this->vars[$key], [ |
|
| 168 | + 'multilingual' => $multilingual, |
|
| 169 | + 'form_caption' => $form_caption, |
|
| 170 | + 'form_dsc' => $form_dsc, |
|
| 171 | + 'sortby' => $sortby, |
|
| 172 | + 'persistent' => $persistent, |
|
| 173 | + 'displayOnForm' => $displayOnForm, |
|
| 174 | + 'displayOnSingleView' => true, |
|
| 175 | + 'readonly' => false |
|
| 176 | + ]); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @param $key |
|
| 181 | + * @param $data_type |
|
| 182 | + * @param bool $itemName |
|
| 183 | + * @param string $form_caption |
|
| 184 | + * @param bool $sortby |
|
| 185 | + * @param string $value |
|
| 186 | + * @param bool $displayOnForm |
|
| 187 | + * @param bool $required |
|
| 188 | + */ |
|
| 189 | + public function initNonPersistableVar( |
|
| 190 | + $key, |
|
| 191 | + $data_type, |
|
| 192 | + $itemName = false, |
|
| 193 | + $form_caption = '', |
|
| 194 | + $sortby = false, |
|
| 195 | + $value = '', |
|
| 196 | + $displayOnForm = false, |
|
| 197 | + $required = false |
|
| 198 | + ) { |
|
| 199 | + $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
| 200 | + $this->vars[$key]['itemName'] = $itemName; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Quickly initiate a var |
|
| 205 | + * |
|
| 206 | + * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
| 207 | + * |
|
| 208 | + * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
| 209 | + * - all other vars are NULL or '' depending of the parameter |
|
| 210 | + * |
|
| 211 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
| 212 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
| 213 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
| 214 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
| 215 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
| 216 | + * @param mixed $value default value of this variable |
|
| 217 | + */ |
|
| 218 | + public function quickInitVar( |
|
| 219 | + $key, |
|
| 220 | + $data_type, |
|
| 221 | + $required = false, |
|
| 222 | + $form_caption = '', |
|
| 223 | + $form_dsc = '', |
|
| 224 | + $value = null |
|
| 225 | + ) { |
|
| 226 | + $maxlength = 'XOBJ_DTYPE_TXTBOX' === $data_type ? 255 : null; |
|
| 227 | + $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @param $varname |
|
| 232 | + * @param bool $displayOnForm |
|
| 233 | + * @param string $default |
|
| 234 | + */ |
|
| 235 | + public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
| 236 | + { |
|
| 237 | + switch ($varname) { |
|
| 238 | + case 'dohtml': |
|
| 239 | + $value = 'notdefined' !== $default ? $default : true; |
|
| 240 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 241 | + $this->setControl($varname, 'yesno'); |
|
| 242 | + break; |
|
| 243 | + |
|
| 244 | + case 'dobr': |
|
| 245 | + $value = ('notdefined' === $default) ? true : $default; |
|
| 246 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 247 | + $this->setControl($varname, 'yesno'); |
|
| 248 | + break; |
|
| 249 | + |
|
| 250 | + case 'doimage': |
|
| 251 | + $value = 'notdefined' !== $default ? $default : true; |
|
| 252 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 253 | + $this->setControl($varname, 'yesno'); |
|
| 254 | + break; |
|
| 255 | + |
|
| 256 | + case 'dosmiley': |
|
| 257 | + $value = 'notdefined' !== $default ? $default : true; |
|
| 258 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 259 | + $this->setControl($varname, 'yesno'); |
|
| 260 | + break; |
|
| 261 | + |
|
| 262 | + case 'doxcode': |
|
| 263 | + $value = 'notdefined' !== $default ? $default : true; |
|
| 264 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 265 | + $this->setControl($varname, 'yesno'); |
|
| 266 | + break; |
|
| 267 | + |
|
| 268 | + case 'meta_keywords': |
|
| 269 | + $value = 'notdefined' !== $default ? $default : ''; |
|
| 270 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
| 271 | + $this->setControl('meta_keywords', [ |
|
| 272 | + 'name' => 'textarea', |
|
| 273 | + 'form_editor' => 'textarea' |
|
| 274 | + ]); |
|
| 275 | + break; |
|
| 276 | + |
|
| 277 | + case 'meta_description': |
|
| 278 | + $value = 'notdefined' !== $default ? $default : ''; |
|
| 279 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
| 280 | + $this->setControl('meta_description', [ |
|
| 281 | + 'name' => 'textarea', |
|
| 282 | + 'form_editor' => 'textarea' |
|
| 283 | + ]); |
|
| 284 | + break; |
|
| 285 | + |
|
| 286 | + case 'short_url': |
|
| 287 | + $value = 'notdefined' !== $default ? $default : ''; |
|
| 288 | + $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
| 289 | + break; |
|
| 290 | + |
|
| 291 | + case 'hierarchy_path': |
|
| 292 | + $value = 'notdefined' !== $default ? $default : ''; |
|
| 293 | + $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
| 294 | + break; |
|
| 295 | + |
|
| 296 | + case 'counter': |
|
| 297 | + $value = 'notdefined' !== $default ? $default : 0; |
|
| 298 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 299 | + break; |
|
| 300 | + |
|
| 301 | + case 'weight': |
|
| 302 | + $value = 'notdefined' !== $default ? $default : 0; |
|
| 303 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
| 304 | + break; |
|
| 305 | + case 'custom_css': |
|
| 306 | + $value = 'notdefined' !== $default ? $default : ''; |
|
| 307 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
| 308 | + $this->setControl('custom_css', [ |
|
| 309 | + 'name' => 'textarea', |
|
| 310 | + 'form_editor' => 'textarea' |
|
| 311 | + ]); |
|
| 312 | + break; |
|
| 313 | + } |
|
| 314 | + $this->hideFieldFromSingleView($varname); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Set control information for an instance variable |
|
| 319 | + * |
|
| 320 | + * The $options parameter can be a string or an array. Using a string |
|
| 321 | + * is the quickest way: |
|
| 322 | + * |
|
| 323 | + * $this->setControl('date', 'date_time'); |
|
| 324 | + * |
|
| 325 | + * This will create a date and time selectbox for the 'date' var on the |
|
| 326 | + * form to edit or create this item. |
|
| 327 | + * |
|
| 328 | + * Here are the currently supported controls: |
|
| 329 | + * |
|
| 330 | + * - color |
|
| 331 | + * - country |
|
| 332 | + * - date_time |
|
| 333 | + * - date |
|
| 334 | ||
| 335 | + * - group |
|
| 336 | + * - group_multi |
|
| 337 | + * - image |
|
| 338 | + * - imageupload |
|
| 339 | + * - label |
|
| 340 | + * - language |
|
| 341 | + * - parentcategory |
|
| 342 | + * - password |
|
| 343 | + * - select_multi |
|
| 344 | + * - select |
|
| 345 | + * - text |
|
| 346 | + * - textarea |
|
| 347 | + * - theme |
|
| 348 | + * - theme_multi |
|
| 349 | + * - timezone |
|
| 350 | + * - user |
|
| 351 | + * - user_multi |
|
| 352 | + * - yesno |
|
| 353 | + * |
|
| 354 | + * Now, using an array as $options, you can customize what information to |
|
| 355 | + * use in the control. For example, if one needs to display a select box for |
|
| 356 | + * the user to choose the status of an item. We only need to tell SmartObject |
|
| 357 | + * what method to execute within what handler to retreive the options of the |
|
| 358 | + * selectbox. |
|
| 359 | + * |
|
| 360 | + * $this->setControl('status', array('name' => false, |
|
| 361 | + * 'itemHandler' => 'item', |
|
| 362 | + * 'method' => 'getStatus', |
|
| 363 | + * 'module' => 'smartshop')); |
|
| 364 | + * |
|
| 365 | + * In this example, the array elements are the following: |
|
| 366 | + * - name: false, as we don't need to set a special control here. |
|
| 367 | + * we will use the default control related to the object type (defined in initVar) |
|
| 368 | + * - itemHandler: name of the object for which we will use the handler |
|
| 369 | + * - method: name of the method of this handler that we will execute |
|
| 370 | + * - module: name of the module from wich the handler is |
|
| 371 | + * |
|
| 372 | + * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
| 373 | + * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
| 374 | + * |
|
| 375 | + * Another example of the use of $options as an array is for TextArea: |
|
| 376 | + * |
|
| 377 | + * $this->setControl('body', array('name' => 'textarea', |
|
| 378 | + * 'form_editor' => 'default')); |
|
| 379 | + * |
|
| 380 | + * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
| 381 | + * the 'default' editor, providing it is defined in the module |
|
| 382 | + * preferences: $xoopsModuleConfig['default_editor'] |
|
| 383 | + * |
|
| 384 | + * Of course, you can force the use of a specific editor: |
|
| 385 | + * |
|
| 386 | + * $this->setControl('body', array('name' => 'textarea', |
|
| 387 | + * 'form_editor' => 'koivi')); |
|
| 388 | + * |
|
| 389 | + * Here is a list of supported editor: |
|
| 390 | + * - tiny: TinyEditor |
|
| 391 | + * - dhtmltextarea: XOOPS DHTML Area |
|
| 392 | + * - fckeditor: FCKEditor |
|
| 393 | + * - inbetween: InBetween |
|
| 394 | + * - koivi: Koivi |
|
| 395 | + * - spaw: Spaw WYSIWYG Editor |
|
| 396 | + * - htmlarea: HTMLArea |
|
| 397 | + * - textarea: basic textarea with no options |
|
| 398 | + * |
|
| 399 | + * @param string $var name of the variable for which we want to set a control |
|
| 400 | + * @param array $options |
|
| 401 | + */ |
|
| 402 | + public function setControl($var, $options = []) |
|
| 403 | + { |
|
| 404 | + if (isset($this->controls[$var])) { |
|
| 405 | + unset($this->controls[$var]); |
|
| 406 | + } |
|
| 407 | + if (is_string($options)) { |
|
| 408 | + $options = ['name' => $options]; |
|
| 409 | + } |
|
| 410 | + $this->controls[$var] = $options; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Get control information for an instance variable |
|
| 415 | + * |
|
| 416 | + * @param string $var |
|
| 417 | + * @return bool|mixed |
|
| 418 | + */ |
|
| 419 | + public function getControl($var) |
|
| 420 | + { |
|
| 421 | + return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Create the form for this object |
|
| 426 | + * |
|
| 427 | + * @param $form_caption |
|
| 428 | + * @param $form_name |
|
| 429 | + * @param bool $form_action |
|
| 430 | + * @param string $submit_button_caption |
|
| 431 | + * @param bool $cancel_js_action |
|
| 432 | + * @param bool $captcha |
|
| 433 | + * @return \XoopsModules\Smartobject\Form\SmartobjectForm <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
| 434 | + * object for this object |
|
| 435 | + * @see SmartObjectForm::SmartObjectForm() |
|
| 436 | + */ |
|
| 437 | + public function getForm( |
|
| 438 | + $form_caption, |
|
| 439 | + $form_name, |
|
| 440 | + $form_action = false, |
|
| 441 | + $submit_button_caption = _CO_SOBJECT_SUBMIT, |
|
| 442 | + $cancel_js_action = false, |
|
| 443 | + $captcha = false |
|
| 444 | + ) { |
|
| 445 | 445 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
| 446 | - $form = new Smartobject\Form\SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
| 447 | - |
|
| 448 | - return $form; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @return array |
|
| 453 | - */ |
|
| 454 | - public function toArray() |
|
| 455 | - { |
|
| 456 | - $ret = []; |
|
| 457 | - $vars =& $this->getVars(); |
|
| 458 | - foreach ($vars as $key => $var) { |
|
| 459 | - $value = $this->getVar($key); |
|
| 460 | - $ret[$key] = $value; |
|
| 461 | - } |
|
| 462 | - if ('' !== $this->handler->identifierName) { |
|
| 463 | - $controller = new SmartObjectController($this->handler); |
|
| 464 | - /** |
|
| 465 | - * Addition of some automatic value |
|
| 466 | - */ |
|
| 467 | - $ret['itemLink'] = $controller->getItemLink($this); |
|
| 468 | - $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
| 469 | - $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
| 470 | - $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
| 471 | - $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // Hightlighting searched words |
|
| 475 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
|
| 476 | - $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
| 477 | - |
|
| 478 | - if ($highlight && isset($_GET['keywords'])) { |
|
| 479 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 480 | - $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
| 481 | - $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
| 482 | - foreach ($this->handler->highlightFields as $field) { |
|
| 483 | - $ret[$field] = $h->highlight($ret[$field]); |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $ret; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * add an error |
|
| 492 | - * |
|
| 493 | - * @param $err_str |
|
| 494 | - * @param bool $prefix |
|
| 495 | - * @internal param string $value error to add |
|
| 496 | - * @access public |
|
| 497 | - */ |
|
| 498 | - public function setErrors($err_str, $prefix = false) |
|
| 499 | - { |
|
| 500 | - if (is_array($err_str)) { |
|
| 501 | - foreach ($err_str as $str) { |
|
| 502 | - $this->setErrors($str, $prefix); |
|
| 503 | - } |
|
| 504 | - } else { |
|
| 505 | - if ($prefix) { |
|
| 506 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
| 507 | - } |
|
| 508 | - parent::setErrors($err_str); |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * @param $field |
|
| 514 | - * @param bool $required |
|
| 515 | - */ |
|
| 516 | - public function setFieldAsRequired($field, $required = true) |
|
| 517 | - { |
|
| 518 | - if (is_array($field)) { |
|
| 519 | - foreach ($field as $v) { |
|
| 520 | - $this->doSetFieldAsRequired($v, $required); |
|
| 521 | - } |
|
| 522 | - } else { |
|
| 523 | - $this->doSetFieldAsRequired($field, $required); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * @param $field |
|
| 529 | - */ |
|
| 530 | - public function setFieldForSorting($field) |
|
| 531 | - { |
|
| 532 | - if (is_array($field)) { |
|
| 533 | - foreach ($field as $v) { |
|
| 534 | - $this->doSetFieldForSorting($v); |
|
| 535 | - } |
|
| 536 | - } else { |
|
| 537 | - $this->doSetFieldForSorting($field); |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * @return bool |
|
| 543 | - */ |
|
| 544 | - public function hasError() |
|
| 545 | - { |
|
| 546 | - return count($this->_errors) > 0; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * @param $url |
|
| 551 | - * @param $path |
|
| 552 | - */ |
|
| 553 | - public function setImageDir($url, $path) |
|
| 554 | - { |
|
| 555 | - $this->_image_url = $url; |
|
| 556 | - $this->_image_path = $path; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Retreive the group that have been granted access to a specific permission for this object |
|
| 561 | - * |
|
| 562 | - * @param $group_perm |
|
| 563 | - * @return string $group_perm name of the permission |
|
| 564 | - */ |
|
| 565 | - public function getGroupPerm($group_perm) |
|
| 566 | - { |
|
| 567 | - if (!$this->handler->getPermissions()) { |
|
| 568 | - $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
| 569 | - |
|
| 570 | - return false; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
| 574 | - $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
| 575 | - |
|
| 576 | - if (0 == count($ret)) { |
|
| 577 | - return false; |
|
| 578 | - } else { |
|
| 579 | - return $ret; |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * @param bool $path |
|
| 585 | - * @return mixed |
|
| 586 | - */ |
|
| 587 | - public function getImageDir($path = false) |
|
| 588 | - { |
|
| 589 | - if ($path) { |
|
| 590 | - return $this->_image_path; |
|
| 591 | - } else { |
|
| 592 | - return $this->_image_url; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @param bool $path |
|
| 598 | - * @return mixed |
|
| 599 | - */ |
|
| 600 | - public function getUploadDir($path = false) |
|
| 601 | - { |
|
| 602 | - if ($path) { |
|
| 603 | - return $this->_image_path; |
|
| 604 | - } else { |
|
| 605 | - return $this->_image_url; |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * @param string $key |
|
| 611 | - * @param string $info |
|
| 612 | - * @return array |
|
| 613 | - */ |
|
| 614 | - public function getVarInfo($key = '', $info = '') |
|
| 615 | - { |
|
| 616 | - if (isset($this->vars[$key][$info])) { |
|
| 617 | - return $this->vars[$key][$info]; |
|
| 618 | - } elseif ('' === $info && isset($this->vars[$key])) { |
|
| 619 | - return $this->vars[$key]; |
|
| 620 | - } else { |
|
| 621 | - return $this->vars; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * Get the id of the object |
|
| 627 | - * |
|
| 628 | - * @return int id of this object |
|
| 629 | - */ |
|
| 630 | - public function id() |
|
| 631 | - { |
|
| 632 | - return $this->getVar($this->handler->keyName, 'e'); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Return the value of the title field of this object |
|
| 637 | - * |
|
| 638 | - * @param string $format |
|
| 639 | - * @return string |
|
| 640 | - */ |
|
| 641 | - public function title($format = 's') |
|
| 642 | - { |
|
| 643 | - return $this->getVar($this->handler->identifierName, $format); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * Return the value of the title field of this object |
|
| 648 | - * |
|
| 649 | - * @return string |
|
| 650 | - */ |
|
| 651 | - public function summary() |
|
| 652 | - { |
|
| 653 | - if ($this->handler->summaryName) { |
|
| 654 | - return $this->getVar($this->handler->summaryName); |
|
| 655 | - } else { |
|
| 656 | - return false; |
|
| 657 | - } |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Retreive the object admin side link, displayijng a SingleView page |
|
| 662 | - * |
|
| 663 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 664 | - * @return string user side link to the object |
|
| 665 | - */ |
|
| 666 | - public function getAdminViewItemLink($onlyUrl = false) |
|
| 667 | - { |
|
| 668 | - $controller = new SmartObjectController($this->handler); |
|
| 669 | - |
|
| 670 | - return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Retreive the object user side link |
|
| 675 | - * |
|
| 676 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 677 | - * @return string user side link to the object |
|
| 678 | - */ |
|
| 679 | - public function getItemLink($onlyUrl = false) |
|
| 680 | - { |
|
| 681 | - $controller = new SmartObjectController($this->handler); |
|
| 682 | - |
|
| 683 | - return $controller->getItemLink($this, $onlyUrl); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * @param bool $onlyUrl |
|
| 688 | - * @param bool $withimage |
|
| 689 | - * @param bool $userSide |
|
| 690 | - * @return string |
|
| 691 | - */ |
|
| 692 | - public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
| 693 | - { |
|
| 694 | - $controller = new SmartObjectController($this->handler); |
|
| 695 | - |
|
| 696 | - return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * @param bool $onlyUrl |
|
| 701 | - * @param bool $withimage |
|
| 702 | - * @param bool $userSide |
|
| 703 | - * @return string |
|
| 704 | - */ |
|
| 705 | - public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
| 706 | - { |
|
| 707 | - $controller = new SmartObjectController($this->handler); |
|
| 708 | - |
|
| 709 | - return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * @return string |
|
| 714 | - */ |
|
| 715 | - public function getPrintAndMailLink() |
|
| 716 | - { |
|
| 717 | - $controller = new SmartObjectController($this->handler); |
|
| 718 | - |
|
| 719 | - return $controller->getPrintAndMailLink($this); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * @param $sortsel |
|
| 724 | - * @return array|bool |
|
| 725 | - */ |
|
| 726 | - public function getFieldsForSorting($sortsel) |
|
| 727 | - { |
|
| 728 | - $ret = []; |
|
| 729 | - |
|
| 730 | - foreach ($this->vars as $key => $field_info) { |
|
| 731 | - if ($field_info['sortby']) { |
|
| 732 | - $ret[$key]['caption'] = $field_info['form_caption']; |
|
| 733 | - $ret[$key]['selected'] = $key == $sortsel ? 'selected' : ''; |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - if (count($ret) > 0) { |
|
| 738 | - return $ret; |
|
| 739 | - } else { |
|
| 740 | - return false; |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * @param $key |
|
| 746 | - * @param $newType |
|
| 747 | - */ |
|
| 748 | - public function setType($key, $newType) |
|
| 749 | - { |
|
| 750 | - $this->vars[$key]['data_type'] = $newType; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * @param $key |
|
| 755 | - * @param $info |
|
| 756 | - * @param $value |
|
| 757 | - */ |
|
| 758 | - public function setVarInfo($key, $info, $value) |
|
| 759 | - { |
|
| 760 | - $this->vars[$key][$info] = $value; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - /** |
|
| 764 | - * @param $key |
|
| 765 | - * @param bool $editor |
|
| 766 | - * @return string |
|
| 767 | - */ |
|
| 768 | - public function getValueFor($key, $editor = true) |
|
| 769 | - { |
|
| 770 | - global $xoopsModuleConfig; |
|
| 771 | - |
|
| 772 | - $ret = $this->getVar($key, 'n'); |
|
| 773 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 774 | - |
|
| 775 | - $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
| 776 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 777 | - |
|
| 778 | - $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
| 779 | - $smiley = true; |
|
| 780 | - $xcode = true; |
|
| 781 | - $image = true; |
|
| 782 | - $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
| 783 | - $formatML = true; |
|
| 784 | - |
|
| 785 | - if ('default' === $form_editor) { |
|
| 786 | - global $xoopsModuleConfig; |
|
| 787 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - if ($editor) { |
|
| 791 | - if (defined('XOOPS_EDITOR_IS_HTML') |
|
| 792 | - && !in_array($form_editor, ['formtextarea', 'textarea', 'dhtmltextarea'])) { |
|
| 793 | - $br = false; |
|
| 794 | - $formatML = !$editor; |
|
| 795 | - } else { |
|
| 796 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - if (method_exists($myts, 'formatForML')) { |
|
| 801 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
| 802 | - } else { |
|
| 803 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * clean values of all variables of the object for storage. |
|
| 809 | - * also add slashes whereever needed |
|
| 810 | - * |
|
| 811 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
| 812 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
| 813 | - * as a string separated by | |
|
| 814 | - * |
|
| 815 | - * @return bool true if successful |
|
| 816 | - * @access public |
|
| 817 | - */ |
|
| 818 | - public function cleanVars() |
|
| 819 | - { |
|
| 820 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 821 | - $existing_errors = $this->getErrors(); |
|
| 822 | - $this->_errors = []; |
|
| 823 | - foreach ($this->vars as $k => $v) { |
|
| 824 | - $cleanv = $v['value']; |
|
| 825 | - if (!$v['changed']) { |
|
| 826 | - } else { |
|
| 827 | - $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
| 828 | - switch ($v['data_type']) { |
|
| 829 | - case XOBJ_DTYPE_TXTBOX: |
|
| 830 | - if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
| 831 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 832 | - continue 2; |
|
| 833 | - } |
|
| 834 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
| 835 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
| 836 | - continue 2; |
|
| 837 | - } |
|
| 838 | - if (!$v['not_gpc']) { |
|
| 839 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
| 840 | - } else { |
|
| 841 | - $cleanv = $ts->censorString($cleanv); |
|
| 842 | - } |
|
| 843 | - break; |
|
| 844 | - case XOBJ_DTYPE_TXTAREA: |
|
| 845 | - if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
| 846 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 847 | - continue 2; |
|
| 848 | - } |
|
| 849 | - if (!$v['not_gpc']) { |
|
| 850 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
| 851 | - } else { |
|
| 852 | - $cleanv = $ts->censorString($cleanv); |
|
| 853 | - } |
|
| 854 | - break; |
|
| 855 | - case XOBJ_DTYPE_SOURCE: |
|
| 856 | - if (!$v['not_gpc']) { |
|
| 857 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
| 858 | - } else { |
|
| 859 | - $cleanv = $cleanv; |
|
| 860 | - } |
|
| 861 | - break; |
|
| 862 | - case XOBJ_DTYPE_INT: |
|
| 863 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 864 | - $cleanv = (int)$cleanv; |
|
| 865 | - break; |
|
| 866 | - |
|
| 867 | - case XOBJ_DTYPE_CURRENCY: |
|
| 868 | - $cleanv = smart_currency($cleanv); |
|
| 869 | - break; |
|
| 870 | - |
|
| 871 | - case XOBJ_DTYPE_FLOAT: |
|
| 872 | - $cleanv = smart_float($cleanv); |
|
| 873 | - break; |
|
| 874 | - |
|
| 875 | - case XOBJ_DTYPE_EMAIL: |
|
| 876 | - if ($v['required'] && '' === $cleanv) { |
|
| 877 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 878 | - continue 2; |
|
| 879 | - } |
|
| 880 | - if ('' !== $cleanv |
|
| 881 | - && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
| 882 | - $this->setErrors('Invalid Email'); |
|
| 883 | - continue 2; |
|
| 884 | - } |
|
| 885 | - if (!$v['not_gpc']) { |
|
| 886 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
| 887 | - } |
|
| 888 | - break; |
|
| 889 | - case XOBJ_DTYPE_URL: |
|
| 890 | - if ($v['required'] && '' === $cleanv) { |
|
| 891 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 892 | - continue 2; |
|
| 893 | - } |
|
| 894 | - if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
| 895 | - $cleanv = 'http://' . $cleanv; |
|
| 896 | - } |
|
| 897 | - if (!$v['not_gpc']) { |
|
| 898 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
| 899 | - } |
|
| 900 | - break; |
|
| 901 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
| 902 | - $cleanv = implode('|', $cleanv); |
|
| 903 | - break; |
|
| 904 | - case XOBJ_DTYPE_ARRAY: |
|
| 905 | - $cleanv = serialize($cleanv); |
|
| 906 | - break; |
|
| 907 | - case XOBJ_DTYPE_STIME: |
|
| 908 | - case XOBJ_DTYPE_MTIME: |
|
| 909 | - case XOBJ_DTYPE_LTIME: |
|
| 910 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
| 911 | - if (!($cleanv > 0)) { |
|
| 912 | - $cleanv = strtotime($cleanv); |
|
| 913 | - } |
|
| 914 | - break; |
|
| 915 | - default: |
|
| 916 | - break; |
|
| 917 | - } |
|
| 918 | - } |
|
| 919 | - $this->cleanVars[$k] =& $cleanv; |
|
| 920 | - unset($cleanv); |
|
| 921 | - } |
|
| 922 | - if (count($this->_errors) > 0) { |
|
| 923 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
| 924 | - |
|
| 925 | - return false; |
|
| 926 | - } |
|
| 927 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
| 928 | - $this->unsetDirty(); |
|
| 929 | - |
|
| 930 | - return true; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - /** |
|
| 934 | - * returns a specific variable for the object in a proper format |
|
| 935 | - * |
|
| 936 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
| 937 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
| 938 | - * as a string separated by | |
|
| 939 | - * |
|
| 940 | - * @access public |
|
| 941 | - * @param string $key key of the object's variable to be returned |
|
| 942 | - * @param string $format format to use for the output |
|
| 943 | - * @return mixed formatted value of the variable |
|
| 944 | - */ |
|
| 945 | - public function getVar($key, $format = 's') |
|
| 946 | - { |
|
| 947 | - global $myts; |
|
| 948 | - |
|
| 949 | - $ret = $this->vars[$key]['value']; |
|
| 950 | - |
|
| 951 | - switch ($this->vars[$key]['data_type']) { |
|
| 952 | - |
|
| 953 | - case XOBJ_DTYPE_TXTBOX: |
|
| 954 | - switch (strtolower($format)) { |
|
| 955 | - case 's': |
|
| 956 | - case 'show': |
|
| 957 | - // ML Hack by marcan |
|
| 958 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 959 | - $ret = $ts->htmlSpecialChars($ret); |
|
| 960 | - |
|
| 961 | - if (method_exists($myts, 'formatForML')) { |
|
| 962 | - return $ts->formatForML($ret); |
|
| 963 | - } else { |
|
| 964 | - return $ret; |
|
| 965 | - } |
|
| 966 | - break 1; |
|
| 967 | - // End of ML Hack by marcan |
|
| 968 | - |
|
| 969 | - case 'clean': |
|
| 970 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 971 | - |
|
| 972 | - $ret = smart_html2text($ret); |
|
| 973 | - $ret = smart_purifyText($ret); |
|
| 974 | - |
|
| 975 | - if (method_exists($myts, 'formatForML')) { |
|
| 976 | - return $ts->formatForML($ret); |
|
| 977 | - } else { |
|
| 978 | - return $ret; |
|
| 979 | - } |
|
| 980 | - break 1; |
|
| 981 | - // End of ML Hack by marcan |
|
| 982 | - |
|
| 983 | - case 'e': |
|
| 984 | - case 'edit': |
|
| 985 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 986 | - |
|
| 987 | - return $ts->htmlSpecialChars($ret); |
|
| 988 | - break 1; |
|
| 989 | - case 'p': |
|
| 990 | - case 'preview': |
|
| 991 | - case 'f': |
|
| 992 | - case 'formpreview': |
|
| 993 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 994 | - |
|
| 995 | - return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
| 996 | - break 1; |
|
| 997 | - case 'n': |
|
| 998 | - case 'none': |
|
| 999 | - default: |
|
| 1000 | - break 1; |
|
| 1001 | - } |
|
| 1002 | - break; |
|
| 1003 | - case XOBJ_DTYPE_LTIME: |
|
| 1004 | - switch (strtolower($format)) { |
|
| 1005 | - case 's': |
|
| 1006 | - case 'show': |
|
| 1007 | - case 'p': |
|
| 1008 | - case 'preview': |
|
| 1009 | - case 'f': |
|
| 1010 | - case 'formpreview': |
|
| 1011 | - $ret = formatTimestamp($ret, _DATESTRING); |
|
| 1012 | - |
|
| 1013 | - return $ret; |
|
| 1014 | - break 1; |
|
| 1015 | - case 'n': |
|
| 1016 | - case 'none': |
|
| 1017 | - case 'e': |
|
| 1018 | - case 'edit': |
|
| 1019 | - break 1; |
|
| 1020 | - default: |
|
| 1021 | - break 1; |
|
| 1022 | - } |
|
| 1023 | - break; |
|
| 1024 | - case XOBJ_DTYPE_STIME: |
|
| 1025 | - switch (strtolower($format)) { |
|
| 1026 | - case 's': |
|
| 1027 | - case 'show': |
|
| 1028 | - case 'p': |
|
| 1029 | - case 'preview': |
|
| 1030 | - case 'f': |
|
| 1031 | - case 'formpreview': |
|
| 1032 | - $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
| 1033 | - |
|
| 1034 | - return $ret; |
|
| 1035 | - break 1; |
|
| 1036 | - case 'n': |
|
| 1037 | - case 'none': |
|
| 1038 | - case 'e': |
|
| 1039 | - case 'edit': |
|
| 1040 | - break 1; |
|
| 1041 | - default: |
|
| 1042 | - break 1; |
|
| 1043 | - } |
|
| 1044 | - break; |
|
| 1045 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 1046 | - switch (strtolower($format)) { |
|
| 1047 | - case 's': |
|
| 1048 | - case 'show': |
|
| 1049 | - case 'p': |
|
| 1050 | - case 'preview': |
|
| 1051 | - case 'f': |
|
| 1052 | - case 'formpreview': |
|
| 1053 | - $ret = formatTimestamp($ret, 'G:i'); |
|
| 1054 | - |
|
| 1055 | - return $ret; |
|
| 1056 | - break 1; |
|
| 1057 | - case 'n': |
|
| 1058 | - case 'none': |
|
| 1059 | - case 'e': |
|
| 1060 | - case 'edit': |
|
| 1061 | - break 1; |
|
| 1062 | - default: |
|
| 1063 | - break 1; |
|
| 1064 | - } |
|
| 1065 | - break; |
|
| 1066 | - |
|
| 1067 | - case XOBJ_DTYPE_CURRENCY: |
|
| 1068 | - $decimal_section_original = strstr($ret, '.'); |
|
| 1069 | - $decimal_section = $decimal_section_original; |
|
| 1070 | - if ($decimal_section) { |
|
| 1071 | - if (1 == strlen($decimal_section)) { |
|
| 1072 | - $decimal_section = '.00'; |
|
| 1073 | - } elseif (2 == strlen($decimal_section)) { |
|
| 1074 | - $decimal_section .= '0'; |
|
| 1075 | - } |
|
| 1076 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
| 1077 | - } else { |
|
| 1078 | - $ret .= '.00'; |
|
| 1079 | - } |
|
| 1080 | - break; |
|
| 1081 | - |
|
| 1082 | - case XOBJ_DTYPE_TXTAREA: |
|
| 1083 | - switch (strtolower($format)) { |
|
| 1084 | - case 's': |
|
| 1085 | - case 'show': |
|
| 1086 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 1087 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
| 1088 | - |
|
| 1089 | - $xcode = (!isset($this->vars['doxcode']['value']) |
|
| 1090 | - || 1 == $this->vars['doxcode']['value']) ? 1 : 0; |
|
| 1091 | - |
|
| 1092 | - $smiley = (!isset($this->vars['dosmiley']['value']) |
|
| 1093 | - || 1 == $this->vars['dosmiley']['value']) ? 1 : 0; |
|
| 1094 | - $image = (!isset($this->vars['doimage']['value']) |
|
| 1095 | - || 1 == $this->vars['doimage']['value']) ? 1 : 0; |
|
| 1096 | - $br = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0; |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * Hack by marcan <INBOX> for SCSPRO |
|
| 1100 | - * Setting mastop as the main editor |
|
| 1101 | - */ |
|
| 1102 | - if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
| 1103 | - $br = false; |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - /** |
|
| 1107 | - * Hack by marcan <INBOX> for SCSPRO |
|
| 1108 | - * Setting mastop as the main editor |
|
| 1109 | - */ |
|
| 1110 | - |
|
| 1111 | - return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 1112 | - break 1; |
|
| 1113 | - case 'e': |
|
| 1114 | - case 'edit': |
|
| 1115 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
| 1116 | - break 1; |
|
| 1117 | - case 'p': |
|
| 1118 | - case 'preview': |
|
| 1119 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 1120 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
| 1121 | - $xcode = (!isset($this->vars['doxcode']['value']) |
|
| 1122 | - || 1 == $this->vars['doxcode']['value']) ? 1 : 0; |
|
| 1123 | - $smiley = (!isset($this->vars['dosmiley']['value']) |
|
| 1124 | - || 1 == $this->vars['dosmiley']['value']) ? 1 : 0; |
|
| 1125 | - $image = (!isset($this->vars['doimage']['value']) |
|
| 1126 | - || 1 == $this->vars['doimage']['value']) ? 1 : 0; |
|
| 1127 | - $br = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0; |
|
| 1128 | - |
|
| 1129 | - return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 1130 | - break 1; |
|
| 1131 | - case 'f': |
|
| 1132 | - case 'formpreview': |
|
| 1133 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 1134 | - |
|
| 1135 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
| 1136 | - break 1; |
|
| 1137 | - case 'n': |
|
| 1138 | - case 'none': |
|
| 1139 | - default: |
|
| 1140 | - break 1; |
|
| 1141 | - } |
|
| 1142 | - break; |
|
| 1143 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
| 1144 | - $ret =& explode('|', $ret); |
|
| 1145 | - break; |
|
| 1146 | - case XOBJ_DTYPE_ARRAY: |
|
| 1147 | - $ret =& unserialize($ret); |
|
| 1148 | - break; |
|
| 1149 | - case XOBJ_DTYPE_SOURCE: |
|
| 1150 | - switch (strtolower($format)) { |
|
| 1151 | - case 's': |
|
| 1152 | - case 'show': |
|
| 1153 | - break 1; |
|
| 1154 | - case 'e': |
|
| 1155 | - case 'edit': |
|
| 1156 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
| 1157 | - break 1; |
|
| 1158 | - case 'p': |
|
| 1159 | - case 'preview': |
|
| 1160 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 1161 | - |
|
| 1162 | - return $ts->stripSlashesGPC($ret); |
|
| 1163 | - break 1; |
|
| 1164 | - case 'f': |
|
| 1165 | - case 'formpreview': |
|
| 1166 | - $ts = \MyTextSanitizer::getInstance(); |
|
| 1167 | - |
|
| 1168 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
| 1169 | - break 1; |
|
| 1170 | - case 'n': |
|
| 1171 | - case 'none': |
|
| 1172 | - default: |
|
| 1173 | - break 1; |
|
| 1174 | - } |
|
| 1175 | - break; |
|
| 1176 | - default: |
|
| 1177 | - if ('' !== $this->vars[$key]['options'] && '' != $ret) { |
|
| 1178 | - switch (strtolower($format)) { |
|
| 1179 | - case 's': |
|
| 1180 | - case 'show': |
|
| 1181 | - $selected = explode('|', $ret); |
|
| 1182 | - $options = explode('|', $this->vars[$key]['options']); |
|
| 1183 | - $i = 1; |
|
| 1184 | - $ret = []; |
|
| 1185 | - foreach ($options as $op) { |
|
| 1186 | - if (in_array($i, $selected)) { |
|
| 1187 | - $ret[] = $op; |
|
| 1188 | - } |
|
| 1189 | - ++$i; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - return implode(', ', $ret); |
|
| 1193 | - case 'e': |
|
| 1194 | - case 'edit': |
|
| 1195 | - $ret = explode('|', $ret); |
|
| 1196 | - break 1; |
|
| 1197 | - default: |
|
| 1198 | - break 1; |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - break; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - return $ret; |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - /** |
|
| 1208 | - * @param $key |
|
| 1209 | - */ |
|
| 1210 | - public function doMakeFieldreadOnly($key) |
|
| 1211 | - { |
|
| 1212 | - if (isset($this->vars[$key])) { |
|
| 1213 | - $this->vars[$key]['readonly'] = true; |
|
| 1214 | - $this->vars[$key]['displayOnForm'] = true; |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * @param $key |
|
| 1220 | - */ |
|
| 1221 | - public function makeFieldReadOnly($key) |
|
| 1222 | - { |
|
| 1223 | - if (is_array($key)) { |
|
| 1224 | - foreach ($key as $v) { |
|
| 1225 | - $this->doMakeFieldreadOnly($v); |
|
| 1226 | - } |
|
| 1227 | - } else { |
|
| 1228 | - $this->doMakeFieldreadOnly($key); |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * @param $key |
|
| 1234 | - */ |
|
| 1235 | - public function doHideFieldFromForm($key) |
|
| 1236 | - { |
|
| 1237 | - if (isset($this->vars[$key])) { |
|
| 1238 | - $this->vars[$key]['displayOnForm'] = false; |
|
| 1239 | - } |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - /** |
|
| 1243 | - * @param $key |
|
| 1244 | - */ |
|
| 1245 | - public function doHideFieldFromSingleView($key) |
|
| 1246 | - { |
|
| 1247 | - if (isset($this->vars[$key])) { |
|
| 1248 | - $this->vars[$key]['displayOnSingleView'] = false; |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - /** |
|
| 1253 | - * @param $key |
|
| 1254 | - */ |
|
| 1255 | - public function hideFieldFromForm($key) |
|
| 1256 | - { |
|
| 1257 | - if (is_array($key)) { |
|
| 1258 | - foreach ($key as $v) { |
|
| 1259 | - $this->doHideFieldFromForm($v); |
|
| 1260 | - } |
|
| 1261 | - } else { |
|
| 1262 | - $this->doHideFieldFromForm($key); |
|
| 1263 | - } |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - /** |
|
| 1267 | - * @param $key |
|
| 1268 | - */ |
|
| 1269 | - public function hideFieldFromSingleView($key) |
|
| 1270 | - { |
|
| 1271 | - if (is_array($key)) { |
|
| 1272 | - foreach ($key as $v) { |
|
| 1273 | - $this->doHideFieldFromSingleView($v); |
|
| 1274 | - } |
|
| 1275 | - } else { |
|
| 1276 | - $this->doHideFieldFromSingleView($key); |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * @param $key |
|
| 1282 | - */ |
|
| 1283 | - public function doShowFieldOnForm($key) |
|
| 1284 | - { |
|
| 1285 | - if (isset($this->vars[$key])) { |
|
| 1286 | - $this->vars[$key]['displayOnForm'] = true; |
|
| 1287 | - } |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - /** |
|
| 1291 | - * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
| 1292 | - * |
|
| 1293 | - * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
| 1294 | - * @param bool $userSide for futur use, to do something different on the user side |
|
| 1295 | - * @param array $actions |
|
| 1296 | - * @param bool $headerAsRow |
|
| 1297 | - * @return string content of the template if $fetchOnly or nothing if !$fetchOnly |
|
| 1298 | - */ |
|
| 1299 | - public function displaySingleObject( |
|
| 1300 | - $fetchOnly = false, |
|
| 1301 | - $userSide = false, |
|
| 1302 | - $actions = [], |
|
| 1303 | - $headerAsRow = true |
|
| 1304 | - ) { |
|
| 1305 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
| 1306 | - $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
| 1307 | - // add all fields mark as displayOnSingleView except the keyid |
|
| 1308 | - foreach ($this->vars as $key => $var) { |
|
| 1309 | - if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
| 1310 | - $is_header = ($key == $this->handler->identifierName); |
|
| 1311 | - $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - if ($fetchOnly) { |
|
| 1316 | - $ret = $singleview->render($fetchOnly); |
|
| 1317 | - |
|
| 1318 | - return $ret; |
|
| 1319 | - } else { |
|
| 1320 | - $singleview->render($fetchOnly); |
|
| 1321 | - } |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - /** |
|
| 1325 | - * @param $key |
|
| 1326 | - */ |
|
| 1327 | - public function doDisplayFieldOnSingleView($key) |
|
| 1328 | - { |
|
| 1329 | - if (isset($this->vars[$key])) { |
|
| 1330 | - $this->vars[$key]['displayOnSingleView'] = true; |
|
| 1331 | - } |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * @param $field |
|
| 1336 | - * @param bool $required |
|
| 1337 | - */ |
|
| 1338 | - public function doSetFieldAsRequired($field, $required = true) |
|
| 1339 | - { |
|
| 1340 | - $this->setVarInfo($field, 'required', $required); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - /** |
|
| 1344 | - * @param $field |
|
| 1345 | - */ |
|
| 1346 | - public function doSetFieldForSorting($field) |
|
| 1347 | - { |
|
| 1348 | - $this->setVarInfo($field, 'sortby', true); |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * @param $key |
|
| 1353 | - */ |
|
| 1354 | - public function showFieldOnForm($key) |
|
| 1355 | - { |
|
| 1356 | - if (is_array($key)) { |
|
| 1357 | - foreach ($key as $v) { |
|
| 1358 | - $this->doShowFieldOnForm($v); |
|
| 1359 | - } |
|
| 1360 | - } else { |
|
| 1361 | - $this->doShowFieldOnForm($key); |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - /** |
|
| 1366 | - * @param $key |
|
| 1367 | - */ |
|
| 1368 | - public function displayFieldOnSingleView($key) |
|
| 1369 | - { |
|
| 1370 | - if (is_array($key)) { |
|
| 1371 | - foreach ($key as $v) { |
|
| 1372 | - $this->doDisplayFieldOnSingleView($v); |
|
| 1373 | - } |
|
| 1374 | - } else { |
|
| 1375 | - $this->doDisplayFieldOnSingleView($key); |
|
| 1376 | - } |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - /** |
|
| 1380 | - * @param $key |
|
| 1381 | - */ |
|
| 1382 | - public function doSetAdvancedFormFields($key) |
|
| 1383 | - { |
|
| 1384 | - if (isset($this->vars[$key])) { |
|
| 1385 | - $this->vars[$key]['advancedform'] = true; |
|
| 1386 | - } |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - /** |
|
| 1390 | - * @param $key |
|
| 1391 | - */ |
|
| 1392 | - public function setAdvancedFormFields($key) |
|
| 1393 | - { |
|
| 1394 | - if (is_array($key)) { |
|
| 1395 | - foreach ($key as $v) { |
|
| 1396 | - $this->doSetAdvancedFormFields($v); |
|
| 1397 | - } |
|
| 1398 | - } else { |
|
| 1399 | - $this->doSetAdvancedFormFields($key); |
|
| 1400 | - } |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - /** |
|
| 1404 | - * @param $key |
|
| 1405 | - * @return mixed |
|
| 1406 | - */ |
|
| 1407 | - public function getUrlLinkObj($key) |
|
| 1408 | - { |
|
| 1409 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
| 1410 | - $urllinkid = null !== $this->getVar($key) ? $this->getVar($key) : 0; |
|
| 1411 | - if (0 != $urllinkid) { |
|
| 1412 | - return $smartobjectLinkurlHandler->get($urllinkid); |
|
| 1413 | - } else { |
|
| 1414 | - return $smartobjectLinkurlHandler->create(); |
|
| 1415 | - } |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - /** |
|
| 1419 | - * @param $urlLinkObj |
|
| 1420 | - * @return mixed |
|
| 1421 | - */ |
|
| 1422 | - public function &storeUrlLinkObj($urlLinkObj) |
|
| 1423 | - { |
|
| 1424 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
| 1425 | - |
|
| 1426 | - return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * @param $key |
|
| 1431 | - * @return mixed |
|
| 1432 | - */ |
|
| 1433 | - public function getFileObj($key) |
|
| 1434 | - { |
|
| 1435 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
| 1436 | - $fileid = null !== $this->getVar($key) ? $this->getVar($key) : 0; |
|
| 1437 | - if (0 != $fileid) { |
|
| 1438 | - return $smartobjectFileHandler->get($fileid); |
|
| 1439 | - } else { |
|
| 1440 | - return $smartobjectFileHandler->create(); |
|
| 1441 | - } |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - /** |
|
| 1445 | - * @param $fileObj |
|
| 1446 | - * @return mixed |
|
| 1447 | - */ |
|
| 1448 | - public function &storeFileObj($fileObj) |
|
| 1449 | - { |
|
| 1450 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
| 1451 | - |
|
| 1452 | - return $smartobjectFileHandler->insert($fileObj); |
|
| 1453 | - } |
|
| 446 | + $form = new Smartobject\Form\SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
| 447 | + |
|
| 448 | + return $form; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @return array |
|
| 453 | + */ |
|
| 454 | + public function toArray() |
|
| 455 | + { |
|
| 456 | + $ret = []; |
|
| 457 | + $vars =& $this->getVars(); |
|
| 458 | + foreach ($vars as $key => $var) { |
|
| 459 | + $value = $this->getVar($key); |
|
| 460 | + $ret[$key] = $value; |
|
| 461 | + } |
|
| 462 | + if ('' !== $this->handler->identifierName) { |
|
| 463 | + $controller = new SmartObjectController($this->handler); |
|
| 464 | + /** |
|
| 465 | + * Addition of some automatic value |
|
| 466 | + */ |
|
| 467 | + $ret['itemLink'] = $controller->getItemLink($this); |
|
| 468 | + $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
| 469 | + $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
| 470 | + $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
| 471 | + $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // Hightlighting searched words |
|
| 475 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
|
| 476 | + $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
| 477 | + |
|
| 478 | + if ($highlight && isset($_GET['keywords'])) { |
|
| 479 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 480 | + $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
| 481 | + $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
| 482 | + foreach ($this->handler->highlightFields as $field) { |
|
| 483 | + $ret[$field] = $h->highlight($ret[$field]); |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $ret; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * add an error |
|
| 492 | + * |
|
| 493 | + * @param $err_str |
|
| 494 | + * @param bool $prefix |
|
| 495 | + * @internal param string $value error to add |
|
| 496 | + * @access public |
|
| 497 | + */ |
|
| 498 | + public function setErrors($err_str, $prefix = false) |
|
| 499 | + { |
|
| 500 | + if (is_array($err_str)) { |
|
| 501 | + foreach ($err_str as $str) { |
|
| 502 | + $this->setErrors($str, $prefix); |
|
| 503 | + } |
|
| 504 | + } else { |
|
| 505 | + if ($prefix) { |
|
| 506 | + $err_str = '[' . $prefix . '] ' . $err_str; |
|
| 507 | + } |
|
| 508 | + parent::setErrors($err_str); |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * @param $field |
|
| 514 | + * @param bool $required |
|
| 515 | + */ |
|
| 516 | + public function setFieldAsRequired($field, $required = true) |
|
| 517 | + { |
|
| 518 | + if (is_array($field)) { |
|
| 519 | + foreach ($field as $v) { |
|
| 520 | + $this->doSetFieldAsRequired($v, $required); |
|
| 521 | + } |
|
| 522 | + } else { |
|
| 523 | + $this->doSetFieldAsRequired($field, $required); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * @param $field |
|
| 529 | + */ |
|
| 530 | + public function setFieldForSorting($field) |
|
| 531 | + { |
|
| 532 | + if (is_array($field)) { |
|
| 533 | + foreach ($field as $v) { |
|
| 534 | + $this->doSetFieldForSorting($v); |
|
| 535 | + } |
|
| 536 | + } else { |
|
| 537 | + $this->doSetFieldForSorting($field); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * @return bool |
|
| 543 | + */ |
|
| 544 | + public function hasError() |
|
| 545 | + { |
|
| 546 | + return count($this->_errors) > 0; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * @param $url |
|
| 551 | + * @param $path |
|
| 552 | + */ |
|
| 553 | + public function setImageDir($url, $path) |
|
| 554 | + { |
|
| 555 | + $this->_image_url = $url; |
|
| 556 | + $this->_image_path = $path; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Retreive the group that have been granted access to a specific permission for this object |
|
| 561 | + * |
|
| 562 | + * @param $group_perm |
|
| 563 | + * @return string $group_perm name of the permission |
|
| 564 | + */ |
|
| 565 | + public function getGroupPerm($group_perm) |
|
| 566 | + { |
|
| 567 | + if (!$this->handler->getPermissions()) { |
|
| 568 | + $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
| 569 | + |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
| 574 | + $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
| 575 | + |
|
| 576 | + if (0 == count($ret)) { |
|
| 577 | + return false; |
|
| 578 | + } else { |
|
| 579 | + return $ret; |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * @param bool $path |
|
| 585 | + * @return mixed |
|
| 586 | + */ |
|
| 587 | + public function getImageDir($path = false) |
|
| 588 | + { |
|
| 589 | + if ($path) { |
|
| 590 | + return $this->_image_path; |
|
| 591 | + } else { |
|
| 592 | + return $this->_image_url; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @param bool $path |
|
| 598 | + * @return mixed |
|
| 599 | + */ |
|
| 600 | + public function getUploadDir($path = false) |
|
| 601 | + { |
|
| 602 | + if ($path) { |
|
| 603 | + return $this->_image_path; |
|
| 604 | + } else { |
|
| 605 | + return $this->_image_url; |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * @param string $key |
|
| 611 | + * @param string $info |
|
| 612 | + * @return array |
|
| 613 | + */ |
|
| 614 | + public function getVarInfo($key = '', $info = '') |
|
| 615 | + { |
|
| 616 | + if (isset($this->vars[$key][$info])) { |
|
| 617 | + return $this->vars[$key][$info]; |
|
| 618 | + } elseif ('' === $info && isset($this->vars[$key])) { |
|
| 619 | + return $this->vars[$key]; |
|
| 620 | + } else { |
|
| 621 | + return $this->vars; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * Get the id of the object |
|
| 627 | + * |
|
| 628 | + * @return int id of this object |
|
| 629 | + */ |
|
| 630 | + public function id() |
|
| 631 | + { |
|
| 632 | + return $this->getVar($this->handler->keyName, 'e'); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Return the value of the title field of this object |
|
| 637 | + * |
|
| 638 | + * @param string $format |
|
| 639 | + * @return string |
|
| 640 | + */ |
|
| 641 | + public function title($format = 's') |
|
| 642 | + { |
|
| 643 | + return $this->getVar($this->handler->identifierName, $format); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * Return the value of the title field of this object |
|
| 648 | + * |
|
| 649 | + * @return string |
|
| 650 | + */ |
|
| 651 | + public function summary() |
|
| 652 | + { |
|
| 653 | + if ($this->handler->summaryName) { |
|
| 654 | + return $this->getVar($this->handler->summaryName); |
|
| 655 | + } else { |
|
| 656 | + return false; |
|
| 657 | + } |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Retreive the object admin side link, displayijng a SingleView page |
|
| 662 | + * |
|
| 663 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 664 | + * @return string user side link to the object |
|
| 665 | + */ |
|
| 666 | + public function getAdminViewItemLink($onlyUrl = false) |
|
| 667 | + { |
|
| 668 | + $controller = new SmartObjectController($this->handler); |
|
| 669 | + |
|
| 670 | + return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Retreive the object user side link |
|
| 675 | + * |
|
| 676 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 677 | + * @return string user side link to the object |
|
| 678 | + */ |
|
| 679 | + public function getItemLink($onlyUrl = false) |
|
| 680 | + { |
|
| 681 | + $controller = new SmartObjectController($this->handler); |
|
| 682 | + |
|
| 683 | + return $controller->getItemLink($this, $onlyUrl); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * @param bool $onlyUrl |
|
| 688 | + * @param bool $withimage |
|
| 689 | + * @param bool $userSide |
|
| 690 | + * @return string |
|
| 691 | + */ |
|
| 692 | + public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
| 693 | + { |
|
| 694 | + $controller = new SmartObjectController($this->handler); |
|
| 695 | + |
|
| 696 | + return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * @param bool $onlyUrl |
|
| 701 | + * @param bool $withimage |
|
| 702 | + * @param bool $userSide |
|
| 703 | + * @return string |
|
| 704 | + */ |
|
| 705 | + public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
| 706 | + { |
|
| 707 | + $controller = new SmartObjectController($this->handler); |
|
| 708 | + |
|
| 709 | + return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * @return string |
|
| 714 | + */ |
|
| 715 | + public function getPrintAndMailLink() |
|
| 716 | + { |
|
| 717 | + $controller = new SmartObjectController($this->handler); |
|
| 718 | + |
|
| 719 | + return $controller->getPrintAndMailLink($this); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * @param $sortsel |
|
| 724 | + * @return array|bool |
|
| 725 | + */ |
|
| 726 | + public function getFieldsForSorting($sortsel) |
|
| 727 | + { |
|
| 728 | + $ret = []; |
|
| 729 | + |
|
| 730 | + foreach ($this->vars as $key => $field_info) { |
|
| 731 | + if ($field_info['sortby']) { |
|
| 732 | + $ret[$key]['caption'] = $field_info['form_caption']; |
|
| 733 | + $ret[$key]['selected'] = $key == $sortsel ? 'selected' : ''; |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + if (count($ret) > 0) { |
|
| 738 | + return $ret; |
|
| 739 | + } else { |
|
| 740 | + return false; |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * @param $key |
|
| 746 | + * @param $newType |
|
| 747 | + */ |
|
| 748 | + public function setType($key, $newType) |
|
| 749 | + { |
|
| 750 | + $this->vars[$key]['data_type'] = $newType; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * @param $key |
|
| 755 | + * @param $info |
|
| 756 | + * @param $value |
|
| 757 | + */ |
|
| 758 | + public function setVarInfo($key, $info, $value) |
|
| 759 | + { |
|
| 760 | + $this->vars[$key][$info] = $value; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + /** |
|
| 764 | + * @param $key |
|
| 765 | + * @param bool $editor |
|
| 766 | + * @return string |
|
| 767 | + */ |
|
| 768 | + public function getValueFor($key, $editor = true) |
|
| 769 | + { |
|
| 770 | + global $xoopsModuleConfig; |
|
| 771 | + |
|
| 772 | + $ret = $this->getVar($key, 'n'); |
|
| 773 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 774 | + |
|
| 775 | + $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
| 776 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 777 | + |
|
| 778 | + $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
| 779 | + $smiley = true; |
|
| 780 | + $xcode = true; |
|
| 781 | + $image = true; |
|
| 782 | + $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
| 783 | + $formatML = true; |
|
| 784 | + |
|
| 785 | + if ('default' === $form_editor) { |
|
| 786 | + global $xoopsModuleConfig; |
|
| 787 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + if ($editor) { |
|
| 791 | + if (defined('XOOPS_EDITOR_IS_HTML') |
|
| 792 | + && !in_array($form_editor, ['formtextarea', 'textarea', 'dhtmltextarea'])) { |
|
| 793 | + $br = false; |
|
| 794 | + $formatML = !$editor; |
|
| 795 | + } else { |
|
| 796 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + if (method_exists($myts, 'formatForML')) { |
|
| 801 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
| 802 | + } else { |
|
| 803 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * clean values of all variables of the object for storage. |
|
| 809 | + * also add slashes whereever needed |
|
| 810 | + * |
|
| 811 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
| 812 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
| 813 | + * as a string separated by | |
|
| 814 | + * |
|
| 815 | + * @return bool true if successful |
|
| 816 | + * @access public |
|
| 817 | + */ |
|
| 818 | + public function cleanVars() |
|
| 819 | + { |
|
| 820 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 821 | + $existing_errors = $this->getErrors(); |
|
| 822 | + $this->_errors = []; |
|
| 823 | + foreach ($this->vars as $k => $v) { |
|
| 824 | + $cleanv = $v['value']; |
|
| 825 | + if (!$v['changed']) { |
|
| 826 | + } else { |
|
| 827 | + $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
| 828 | + switch ($v['data_type']) { |
|
| 829 | + case XOBJ_DTYPE_TXTBOX: |
|
| 830 | + if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
| 831 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 832 | + continue 2; |
|
| 833 | + } |
|
| 834 | + if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
| 835 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
| 836 | + continue 2; |
|
| 837 | + } |
|
| 838 | + if (!$v['not_gpc']) { |
|
| 839 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
| 840 | + } else { |
|
| 841 | + $cleanv = $ts->censorString($cleanv); |
|
| 842 | + } |
|
| 843 | + break; |
|
| 844 | + case XOBJ_DTYPE_TXTAREA: |
|
| 845 | + if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
| 846 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 847 | + continue 2; |
|
| 848 | + } |
|
| 849 | + if (!$v['not_gpc']) { |
|
| 850 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
| 851 | + } else { |
|
| 852 | + $cleanv = $ts->censorString($cleanv); |
|
| 853 | + } |
|
| 854 | + break; |
|
| 855 | + case XOBJ_DTYPE_SOURCE: |
|
| 856 | + if (!$v['not_gpc']) { |
|
| 857 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
| 858 | + } else { |
|
| 859 | + $cleanv = $cleanv; |
|
| 860 | + } |
|
| 861 | + break; |
|
| 862 | + case XOBJ_DTYPE_INT: |
|
| 863 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 864 | + $cleanv = (int)$cleanv; |
|
| 865 | + break; |
|
| 866 | + |
|
| 867 | + case XOBJ_DTYPE_CURRENCY: |
|
| 868 | + $cleanv = smart_currency($cleanv); |
|
| 869 | + break; |
|
| 870 | + |
|
| 871 | + case XOBJ_DTYPE_FLOAT: |
|
| 872 | + $cleanv = smart_float($cleanv); |
|
| 873 | + break; |
|
| 874 | + |
|
| 875 | + case XOBJ_DTYPE_EMAIL: |
|
| 876 | + if ($v['required'] && '' === $cleanv) { |
|
| 877 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 878 | + continue 2; |
|
| 879 | + } |
|
| 880 | + if ('' !== $cleanv |
|
| 881 | + && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
| 882 | + $this->setErrors('Invalid Email'); |
|
| 883 | + continue 2; |
|
| 884 | + } |
|
| 885 | + if (!$v['not_gpc']) { |
|
| 886 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
| 887 | + } |
|
| 888 | + break; |
|
| 889 | + case XOBJ_DTYPE_URL: |
|
| 890 | + if ($v['required'] && '' === $cleanv) { |
|
| 891 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 892 | + continue 2; |
|
| 893 | + } |
|
| 894 | + if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
| 895 | + $cleanv = 'http://' . $cleanv; |
|
| 896 | + } |
|
| 897 | + if (!$v['not_gpc']) { |
|
| 898 | + $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
| 899 | + } |
|
| 900 | + break; |
|
| 901 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
| 902 | + $cleanv = implode('|', $cleanv); |
|
| 903 | + break; |
|
| 904 | + case XOBJ_DTYPE_ARRAY: |
|
| 905 | + $cleanv = serialize($cleanv); |
|
| 906 | + break; |
|
| 907 | + case XOBJ_DTYPE_STIME: |
|
| 908 | + case XOBJ_DTYPE_MTIME: |
|
| 909 | + case XOBJ_DTYPE_LTIME: |
|
| 910 | + $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
| 911 | + if (!($cleanv > 0)) { |
|
| 912 | + $cleanv = strtotime($cleanv); |
|
| 913 | + } |
|
| 914 | + break; |
|
| 915 | + default: |
|
| 916 | + break; |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | + $this->cleanVars[$k] =& $cleanv; |
|
| 920 | + unset($cleanv); |
|
| 921 | + } |
|
| 922 | + if (count($this->_errors) > 0) { |
|
| 923 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
| 924 | + |
|
| 925 | + return false; |
|
| 926 | + } |
|
| 927 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
| 928 | + $this->unsetDirty(); |
|
| 929 | + |
|
| 930 | + return true; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + /** |
|
| 934 | + * returns a specific variable for the object in a proper format |
|
| 935 | + * |
|
| 936 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
| 937 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
| 938 | + * as a string separated by | |
|
| 939 | + * |
|
| 940 | + * @access public |
|
| 941 | + * @param string $key key of the object's variable to be returned |
|
| 942 | + * @param string $format format to use for the output |
|
| 943 | + * @return mixed formatted value of the variable |
|
| 944 | + */ |
|
| 945 | + public function getVar($key, $format = 's') |
|
| 946 | + { |
|
| 947 | + global $myts; |
|
| 948 | + |
|
| 949 | + $ret = $this->vars[$key]['value']; |
|
| 950 | + |
|
| 951 | + switch ($this->vars[$key]['data_type']) { |
|
| 952 | + |
|
| 953 | + case XOBJ_DTYPE_TXTBOX: |
|
| 954 | + switch (strtolower($format)) { |
|
| 955 | + case 's': |
|
| 956 | + case 'show': |
|
| 957 | + // ML Hack by marcan |
|
| 958 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 959 | + $ret = $ts->htmlSpecialChars($ret); |
|
| 960 | + |
|
| 961 | + if (method_exists($myts, 'formatForML')) { |
|
| 962 | + return $ts->formatForML($ret); |
|
| 963 | + } else { |
|
| 964 | + return $ret; |
|
| 965 | + } |
|
| 966 | + break 1; |
|
| 967 | + // End of ML Hack by marcan |
|
| 968 | + |
|
| 969 | + case 'clean': |
|
| 970 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 971 | + |
|
| 972 | + $ret = smart_html2text($ret); |
|
| 973 | + $ret = smart_purifyText($ret); |
|
| 974 | + |
|
| 975 | + if (method_exists($myts, 'formatForML')) { |
|
| 976 | + return $ts->formatForML($ret); |
|
| 977 | + } else { |
|
| 978 | + return $ret; |
|
| 979 | + } |
|
| 980 | + break 1; |
|
| 981 | + // End of ML Hack by marcan |
|
| 982 | + |
|
| 983 | + case 'e': |
|
| 984 | + case 'edit': |
|
| 985 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 986 | + |
|
| 987 | + return $ts->htmlSpecialChars($ret); |
|
| 988 | + break 1; |
|
| 989 | + case 'p': |
|
| 990 | + case 'preview': |
|
| 991 | + case 'f': |
|
| 992 | + case 'formpreview': |
|
| 993 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 994 | + |
|
| 995 | + return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
| 996 | + break 1; |
|
| 997 | + case 'n': |
|
| 998 | + case 'none': |
|
| 999 | + default: |
|
| 1000 | + break 1; |
|
| 1001 | + } |
|
| 1002 | + break; |
|
| 1003 | + case XOBJ_DTYPE_LTIME: |
|
| 1004 | + switch (strtolower($format)) { |
|
| 1005 | + case 's': |
|
| 1006 | + case 'show': |
|
| 1007 | + case 'p': |
|
| 1008 | + case 'preview': |
|
| 1009 | + case 'f': |
|
| 1010 | + case 'formpreview': |
|
| 1011 | + $ret = formatTimestamp($ret, _DATESTRING); |
|
| 1012 | + |
|
| 1013 | + return $ret; |
|
| 1014 | + break 1; |
|
| 1015 | + case 'n': |
|
| 1016 | + case 'none': |
|
| 1017 | + case 'e': |
|
| 1018 | + case 'edit': |
|
| 1019 | + break 1; |
|
| 1020 | + default: |
|
| 1021 | + break 1; |
|
| 1022 | + } |
|
| 1023 | + break; |
|
| 1024 | + case XOBJ_DTYPE_STIME: |
|
| 1025 | + switch (strtolower($format)) { |
|
| 1026 | + case 's': |
|
| 1027 | + case 'show': |
|
| 1028 | + case 'p': |
|
| 1029 | + case 'preview': |
|
| 1030 | + case 'f': |
|
| 1031 | + case 'formpreview': |
|
| 1032 | + $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
| 1033 | + |
|
| 1034 | + return $ret; |
|
| 1035 | + break 1; |
|
| 1036 | + case 'n': |
|
| 1037 | + case 'none': |
|
| 1038 | + case 'e': |
|
| 1039 | + case 'edit': |
|
| 1040 | + break 1; |
|
| 1041 | + default: |
|
| 1042 | + break 1; |
|
| 1043 | + } |
|
| 1044 | + break; |
|
| 1045 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 1046 | + switch (strtolower($format)) { |
|
| 1047 | + case 's': |
|
| 1048 | + case 'show': |
|
| 1049 | + case 'p': |
|
| 1050 | + case 'preview': |
|
| 1051 | + case 'f': |
|
| 1052 | + case 'formpreview': |
|
| 1053 | + $ret = formatTimestamp($ret, 'G:i'); |
|
| 1054 | + |
|
| 1055 | + return $ret; |
|
| 1056 | + break 1; |
|
| 1057 | + case 'n': |
|
| 1058 | + case 'none': |
|
| 1059 | + case 'e': |
|
| 1060 | + case 'edit': |
|
| 1061 | + break 1; |
|
| 1062 | + default: |
|
| 1063 | + break 1; |
|
| 1064 | + } |
|
| 1065 | + break; |
|
| 1066 | + |
|
| 1067 | + case XOBJ_DTYPE_CURRENCY: |
|
| 1068 | + $decimal_section_original = strstr($ret, '.'); |
|
| 1069 | + $decimal_section = $decimal_section_original; |
|
| 1070 | + if ($decimal_section) { |
|
| 1071 | + if (1 == strlen($decimal_section)) { |
|
| 1072 | + $decimal_section = '.00'; |
|
| 1073 | + } elseif (2 == strlen($decimal_section)) { |
|
| 1074 | + $decimal_section .= '0'; |
|
| 1075 | + } |
|
| 1076 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
| 1077 | + } else { |
|
| 1078 | + $ret .= '.00'; |
|
| 1079 | + } |
|
| 1080 | + break; |
|
| 1081 | + |
|
| 1082 | + case XOBJ_DTYPE_TXTAREA: |
|
| 1083 | + switch (strtolower($format)) { |
|
| 1084 | + case 's': |
|
| 1085 | + case 'show': |
|
| 1086 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 1087 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
| 1088 | + |
|
| 1089 | + $xcode = (!isset($this->vars['doxcode']['value']) |
|
| 1090 | + || 1 == $this->vars['doxcode']['value']) ? 1 : 0; |
|
| 1091 | + |
|
| 1092 | + $smiley = (!isset($this->vars['dosmiley']['value']) |
|
| 1093 | + || 1 == $this->vars['dosmiley']['value']) ? 1 : 0; |
|
| 1094 | + $image = (!isset($this->vars['doimage']['value']) |
|
| 1095 | + || 1 == $this->vars['doimage']['value']) ? 1 : 0; |
|
| 1096 | + $br = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0; |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * Hack by marcan <INBOX> for SCSPRO |
|
| 1100 | + * Setting mastop as the main editor |
|
| 1101 | + */ |
|
| 1102 | + if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
| 1103 | + $br = false; |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + /** |
|
| 1107 | + * Hack by marcan <INBOX> for SCSPRO |
|
| 1108 | + * Setting mastop as the main editor |
|
| 1109 | + */ |
|
| 1110 | + |
|
| 1111 | + return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 1112 | + break 1; |
|
| 1113 | + case 'e': |
|
| 1114 | + case 'edit': |
|
| 1115 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
| 1116 | + break 1; |
|
| 1117 | + case 'p': |
|
| 1118 | + case 'preview': |
|
| 1119 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 1120 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
| 1121 | + $xcode = (!isset($this->vars['doxcode']['value']) |
|
| 1122 | + || 1 == $this->vars['doxcode']['value']) ? 1 : 0; |
|
| 1123 | + $smiley = (!isset($this->vars['dosmiley']['value']) |
|
| 1124 | + || 1 == $this->vars['dosmiley']['value']) ? 1 : 0; |
|
| 1125 | + $image = (!isset($this->vars['doimage']['value']) |
|
| 1126 | + || 1 == $this->vars['doimage']['value']) ? 1 : 0; |
|
| 1127 | + $br = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0; |
|
| 1128 | + |
|
| 1129 | + return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 1130 | + break 1; |
|
| 1131 | + case 'f': |
|
| 1132 | + case 'formpreview': |
|
| 1133 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 1134 | + |
|
| 1135 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
| 1136 | + break 1; |
|
| 1137 | + case 'n': |
|
| 1138 | + case 'none': |
|
| 1139 | + default: |
|
| 1140 | + break 1; |
|
| 1141 | + } |
|
| 1142 | + break; |
|
| 1143 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
| 1144 | + $ret =& explode('|', $ret); |
|
| 1145 | + break; |
|
| 1146 | + case XOBJ_DTYPE_ARRAY: |
|
| 1147 | + $ret =& unserialize($ret); |
|
| 1148 | + break; |
|
| 1149 | + case XOBJ_DTYPE_SOURCE: |
|
| 1150 | + switch (strtolower($format)) { |
|
| 1151 | + case 's': |
|
| 1152 | + case 'show': |
|
| 1153 | + break 1; |
|
| 1154 | + case 'e': |
|
| 1155 | + case 'edit': |
|
| 1156 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
| 1157 | + break 1; |
|
| 1158 | + case 'p': |
|
| 1159 | + case 'preview': |
|
| 1160 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 1161 | + |
|
| 1162 | + return $ts->stripSlashesGPC($ret); |
|
| 1163 | + break 1; |
|
| 1164 | + case 'f': |
|
| 1165 | + case 'formpreview': |
|
| 1166 | + $ts = \MyTextSanitizer::getInstance(); |
|
| 1167 | + |
|
| 1168 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
| 1169 | + break 1; |
|
| 1170 | + case 'n': |
|
| 1171 | + case 'none': |
|
| 1172 | + default: |
|
| 1173 | + break 1; |
|
| 1174 | + } |
|
| 1175 | + break; |
|
| 1176 | + default: |
|
| 1177 | + if ('' !== $this->vars[$key]['options'] && '' != $ret) { |
|
| 1178 | + switch (strtolower($format)) { |
|
| 1179 | + case 's': |
|
| 1180 | + case 'show': |
|
| 1181 | + $selected = explode('|', $ret); |
|
| 1182 | + $options = explode('|', $this->vars[$key]['options']); |
|
| 1183 | + $i = 1; |
|
| 1184 | + $ret = []; |
|
| 1185 | + foreach ($options as $op) { |
|
| 1186 | + if (in_array($i, $selected)) { |
|
| 1187 | + $ret[] = $op; |
|
| 1188 | + } |
|
| 1189 | + ++$i; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + return implode(', ', $ret); |
|
| 1193 | + case 'e': |
|
| 1194 | + case 'edit': |
|
| 1195 | + $ret = explode('|', $ret); |
|
| 1196 | + break 1; |
|
| 1197 | + default: |
|
| 1198 | + break 1; |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + break; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + return $ret; |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + /** |
|
| 1208 | + * @param $key |
|
| 1209 | + */ |
|
| 1210 | + public function doMakeFieldreadOnly($key) |
|
| 1211 | + { |
|
| 1212 | + if (isset($this->vars[$key])) { |
|
| 1213 | + $this->vars[$key]['readonly'] = true; |
|
| 1214 | + $this->vars[$key]['displayOnForm'] = true; |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * @param $key |
|
| 1220 | + */ |
|
| 1221 | + public function makeFieldReadOnly($key) |
|
| 1222 | + { |
|
| 1223 | + if (is_array($key)) { |
|
| 1224 | + foreach ($key as $v) { |
|
| 1225 | + $this->doMakeFieldreadOnly($v); |
|
| 1226 | + } |
|
| 1227 | + } else { |
|
| 1228 | + $this->doMakeFieldreadOnly($key); |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + /** |
|
| 1233 | + * @param $key |
|
| 1234 | + */ |
|
| 1235 | + public function doHideFieldFromForm($key) |
|
| 1236 | + { |
|
| 1237 | + if (isset($this->vars[$key])) { |
|
| 1238 | + $this->vars[$key]['displayOnForm'] = false; |
|
| 1239 | + } |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + /** |
|
| 1243 | + * @param $key |
|
| 1244 | + */ |
|
| 1245 | + public function doHideFieldFromSingleView($key) |
|
| 1246 | + { |
|
| 1247 | + if (isset($this->vars[$key])) { |
|
| 1248 | + $this->vars[$key]['displayOnSingleView'] = false; |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + /** |
|
| 1253 | + * @param $key |
|
| 1254 | + */ |
|
| 1255 | + public function hideFieldFromForm($key) |
|
| 1256 | + { |
|
| 1257 | + if (is_array($key)) { |
|
| 1258 | + foreach ($key as $v) { |
|
| 1259 | + $this->doHideFieldFromForm($v); |
|
| 1260 | + } |
|
| 1261 | + } else { |
|
| 1262 | + $this->doHideFieldFromForm($key); |
|
| 1263 | + } |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + /** |
|
| 1267 | + * @param $key |
|
| 1268 | + */ |
|
| 1269 | + public function hideFieldFromSingleView($key) |
|
| 1270 | + { |
|
| 1271 | + if (is_array($key)) { |
|
| 1272 | + foreach ($key as $v) { |
|
| 1273 | + $this->doHideFieldFromSingleView($v); |
|
| 1274 | + } |
|
| 1275 | + } else { |
|
| 1276 | + $this->doHideFieldFromSingleView($key); |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * @param $key |
|
| 1282 | + */ |
|
| 1283 | + public function doShowFieldOnForm($key) |
|
| 1284 | + { |
|
| 1285 | + if (isset($this->vars[$key])) { |
|
| 1286 | + $this->vars[$key]['displayOnForm'] = true; |
|
| 1287 | + } |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + /** |
|
| 1291 | + * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
| 1292 | + * |
|
| 1293 | + * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
| 1294 | + * @param bool $userSide for futur use, to do something different on the user side |
|
| 1295 | + * @param array $actions |
|
| 1296 | + * @param bool $headerAsRow |
|
| 1297 | + * @return string content of the template if $fetchOnly or nothing if !$fetchOnly |
|
| 1298 | + */ |
|
| 1299 | + public function displaySingleObject( |
|
| 1300 | + $fetchOnly = false, |
|
| 1301 | + $userSide = false, |
|
| 1302 | + $actions = [], |
|
| 1303 | + $headerAsRow = true |
|
| 1304 | + ) { |
|
| 1305 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
| 1306 | + $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
| 1307 | + // add all fields mark as displayOnSingleView except the keyid |
|
| 1308 | + foreach ($this->vars as $key => $var) { |
|
| 1309 | + if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
| 1310 | + $is_header = ($key == $this->handler->identifierName); |
|
| 1311 | + $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + if ($fetchOnly) { |
|
| 1316 | + $ret = $singleview->render($fetchOnly); |
|
| 1317 | + |
|
| 1318 | + return $ret; |
|
| 1319 | + } else { |
|
| 1320 | + $singleview->render($fetchOnly); |
|
| 1321 | + } |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + /** |
|
| 1325 | + * @param $key |
|
| 1326 | + */ |
|
| 1327 | + public function doDisplayFieldOnSingleView($key) |
|
| 1328 | + { |
|
| 1329 | + if (isset($this->vars[$key])) { |
|
| 1330 | + $this->vars[$key]['displayOnSingleView'] = true; |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * @param $field |
|
| 1336 | + * @param bool $required |
|
| 1337 | + */ |
|
| 1338 | + public function doSetFieldAsRequired($field, $required = true) |
|
| 1339 | + { |
|
| 1340 | + $this->setVarInfo($field, 'required', $required); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + /** |
|
| 1344 | + * @param $field |
|
| 1345 | + */ |
|
| 1346 | + public function doSetFieldForSorting($field) |
|
| 1347 | + { |
|
| 1348 | + $this->setVarInfo($field, 'sortby', true); |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * @param $key |
|
| 1353 | + */ |
|
| 1354 | + public function showFieldOnForm($key) |
|
| 1355 | + { |
|
| 1356 | + if (is_array($key)) { |
|
| 1357 | + foreach ($key as $v) { |
|
| 1358 | + $this->doShowFieldOnForm($v); |
|
| 1359 | + } |
|
| 1360 | + } else { |
|
| 1361 | + $this->doShowFieldOnForm($key); |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + /** |
|
| 1366 | + * @param $key |
|
| 1367 | + */ |
|
| 1368 | + public function displayFieldOnSingleView($key) |
|
| 1369 | + { |
|
| 1370 | + if (is_array($key)) { |
|
| 1371 | + foreach ($key as $v) { |
|
| 1372 | + $this->doDisplayFieldOnSingleView($v); |
|
| 1373 | + } |
|
| 1374 | + } else { |
|
| 1375 | + $this->doDisplayFieldOnSingleView($key); |
|
| 1376 | + } |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + /** |
|
| 1380 | + * @param $key |
|
| 1381 | + */ |
|
| 1382 | + public function doSetAdvancedFormFields($key) |
|
| 1383 | + { |
|
| 1384 | + if (isset($this->vars[$key])) { |
|
| 1385 | + $this->vars[$key]['advancedform'] = true; |
|
| 1386 | + } |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + /** |
|
| 1390 | + * @param $key |
|
| 1391 | + */ |
|
| 1392 | + public function setAdvancedFormFields($key) |
|
| 1393 | + { |
|
| 1394 | + if (is_array($key)) { |
|
| 1395 | + foreach ($key as $v) { |
|
| 1396 | + $this->doSetAdvancedFormFields($v); |
|
| 1397 | + } |
|
| 1398 | + } else { |
|
| 1399 | + $this->doSetAdvancedFormFields($key); |
|
| 1400 | + } |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + /** |
|
| 1404 | + * @param $key |
|
| 1405 | + * @return mixed |
|
| 1406 | + */ |
|
| 1407 | + public function getUrlLinkObj($key) |
|
| 1408 | + { |
|
| 1409 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
| 1410 | + $urllinkid = null !== $this->getVar($key) ? $this->getVar($key) : 0; |
|
| 1411 | + if (0 != $urllinkid) { |
|
| 1412 | + return $smartobjectLinkurlHandler->get($urllinkid); |
|
| 1413 | + } else { |
|
| 1414 | + return $smartobjectLinkurlHandler->create(); |
|
| 1415 | + } |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + /** |
|
| 1419 | + * @param $urlLinkObj |
|
| 1420 | + * @return mixed |
|
| 1421 | + */ |
|
| 1422 | + public function &storeUrlLinkObj($urlLinkObj) |
|
| 1423 | + { |
|
| 1424 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
| 1425 | + |
|
| 1426 | + return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * @param $key |
|
| 1431 | + * @return mixed |
|
| 1432 | + */ |
|
| 1433 | + public function getFileObj($key) |
|
| 1434 | + { |
|
| 1435 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
| 1436 | + $fileid = null !== $this->getVar($key) ? $this->getVar($key) : 0; |
|
| 1437 | + if (0 != $fileid) { |
|
| 1438 | + return $smartobjectFileHandler->get($fileid); |
|
| 1439 | + } else { |
|
| 1440 | + return $smartobjectFileHandler->create(); |
|
| 1441 | + } |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + /** |
|
| 1445 | + * @param $fileObj |
|
| 1446 | + * @return mixed |
|
| 1447 | + */ |
|
| 1448 | + public function &storeFileObj($fileObj) |
|
| 1449 | + { |
|
| 1450 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
| 1451 | + |
|
| 1452 | + return $smartobjectFileHandler->insert($fileObj); |
|
| 1453 | + } |
|
| 1454 | 1454 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
| 17 | 17 | |
| 18 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 18 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
| 19 | 19 | |
| 20 | 20 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
| 21 | 21 | define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function closeSection($section_name) |
| 116 | 116 | { |
| 117 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
| 117 | + $this->initVar('close_section_'.$section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -152,13 +152,13 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
| 154 | 154 | if ($this->handler && (!$form_caption || '' === $form_caption)) { |
| 155 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
| 155 | + $dyn_form_caption = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key); |
|
| 156 | 156 | if (defined($dyn_form_caption)) { |
| 157 | 157 | $form_caption = constant($dyn_form_caption); |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | if ($this->handler && (!$form_dsc || '' === $form_dsc)) { |
| 161 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
| 161 | + $dyn_form_dsc = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key.'_DSC'); |
|
| 162 | 162 | if (defined($dyn_form_dsc)) { |
| 163 | 163 | $form_dsc = constant($dyn_form_dsc); |
| 164 | 164 | } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | public function toArray() |
| 455 | 455 | { |
| 456 | 456 | $ret = []; |
| 457 | - $vars =& $this->getVars(); |
|
| 457 | + $vars = & $this->getVars(); |
|
| 458 | 458 | foreach ($vars as $key => $var) { |
| 459 | 459 | $value = $this->getVar($key); |
| 460 | 460 | $ret[$key] = $value; |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | // Hightlighting searched words |
| 475 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
|
| 475 | + require_once SMARTOBJECT_ROOT_PATH.'class/smarthighlighter.php'; |
|
| 476 | 476 | $highlight = smart_getConfig('module_search_highlighter', false, true); |
| 477 | 477 | |
| 478 | 478 | if ($highlight && isset($_GET['keywords'])) { |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | } |
| 504 | 504 | } else { |
| 505 | 505 | if ($prefix) { |
| 506 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
| 506 | + $err_str = '['.$prefix.'] '.$err_str; |
|
| 507 | 507 | } |
| 508 | 508 | parent::setErrors($err_str); |
| 509 | 509 | } |
@@ -831,8 +831,8 @@ discard block |
||
| 831 | 831 | $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
| 832 | 832 | continue 2; |
| 833 | 833 | } |
| 834 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
| 835 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
| 834 | + if (isset($v['maxlength']) && strlen($cleanv) > (int) $v['maxlength']) { |
|
| 835 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int) $v['maxlength'])); |
|
| 836 | 836 | continue 2; |
| 837 | 837 | } |
| 838 | 838 | if (!$v['not_gpc']) { |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | break; |
| 862 | 862 | case XOBJ_DTYPE_INT: |
| 863 | 863 | case XOBJ_DTYPE_TIME_ONLY: |
| 864 | - $cleanv = (int)$cleanv; |
|
| 864 | + $cleanv = (int) $cleanv; |
|
| 865 | 865 | break; |
| 866 | 866 | |
| 867 | 867 | case XOBJ_DTYPE_CURRENCY: |
@@ -892,10 +892,10 @@ discard block |
||
| 892 | 892 | continue 2; |
| 893 | 893 | } |
| 894 | 894 | if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
| 895 | - $cleanv = 'http://' . $cleanv; |
|
| 895 | + $cleanv = 'http://'.$cleanv; |
|
| 896 | 896 | } |
| 897 | 897 | if (!$v['not_gpc']) { |
| 898 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
| 898 | + $cleanv = & $ts->stripSlashesGPC($cleanv); |
|
| 899 | 899 | } |
| 900 | 900 | break; |
| 901 | 901 | case XOBJ_DTYPE_SIMPLE_ARRAY: |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | case XOBJ_DTYPE_STIME: |
| 908 | 908 | case XOBJ_DTYPE_MTIME: |
| 909 | 909 | case XOBJ_DTYPE_LTIME: |
| 910 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
| 910 | + $cleanv = !is_string($cleanv) ? (int) $cleanv : strtotime($cleanv); |
|
| 911 | 911 | if (!($cleanv > 0)) { |
| 912 | 912 | $cleanv = strtotime($cleanv); |
| 913 | 913 | } |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | break; |
| 917 | 917 | } |
| 918 | 918 | } |
| 919 | - $this->cleanVars[$k] =& $cleanv; |
|
| 919 | + $this->cleanVars[$k] = & $cleanv; |
|
| 920 | 920 | unset($cleanv); |
| 921 | 921 | } |
| 922 | 922 | if (count($this->_errors) > 0) { |
@@ -1141,10 +1141,10 @@ discard block |
||
| 1141 | 1141 | } |
| 1142 | 1142 | break; |
| 1143 | 1143 | case XOBJ_DTYPE_SIMPLE_ARRAY: |
| 1144 | - $ret =& explode('|', $ret); |
|
| 1144 | + $ret = & explode('|', $ret); |
|
| 1145 | 1145 | break; |
| 1146 | 1146 | case XOBJ_DTYPE_ARRAY: |
| 1147 | - $ret =& unserialize($ret); |
|
| 1147 | + $ret = & unserialize($ret); |
|
| 1148 | 1148 | break; |
| 1149 | 1149 | case XOBJ_DTYPE_SOURCE: |
| 1150 | 1150 | switch (strtolower($format)) { |
@@ -1302,7 +1302,7 @@ discard block |
||
| 1302 | 1302 | $actions = [], |
| 1303 | 1303 | $headerAsRow = true |
| 1304 | 1304 | ) { |
| 1305 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
| 1305 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectsingleview.php'; |
|
| 1306 | 1306 | $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
| 1307 | 1307 | // add all fields mark as displayOnSingleView except the keyid |
| 1308 | 1308 | foreach ($this->vars as $key => $var) { |
@@ -19,8 +19,8 @@ |
||
| 19 | 19 | class SmartFormUploadElement extends \XoopsFormFile |
| 20 | 20 | { |
| 21 | 21 | /** |
| 22 | - * @param $object |
|
| 23 | - * @param $key |
|
| 22 | + * @param string $object |
|
| 23 | + * @param string $key |
|
| 24 | 24 | */ |
| 25 | 25 | public function SmartFormFileElement($object, $key) |
| 26 | 26 | { |
@@ -18,25 +18,25 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class SmartFormUploadElement extends \XoopsFormFile |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @param $object |
|
| 23 | - * @param $key |
|
| 24 | - */ |
|
| 25 | - public function SmartFormFileElement($object, $key) |
|
| 26 | - { |
|
| 27 | - parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
| 28 | - $this->setExtra(' size=50'); |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * @param $object |
|
| 23 | + * @param $key |
|
| 24 | + */ |
|
| 25 | + public function SmartFormFileElement($object, $key) |
|
| 26 | + { |
|
| 27 | + parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
| 28 | + $this->setExtra(' size=50'); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * prepare HTML for output |
|
| 33 | - * |
|
| 34 | - * @return string HTML |
|
| 35 | - */ |
|
| 36 | - public function render() |
|
| 37 | - { |
|
| 38 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 31 | + /** |
|
| 32 | + * prepare HTML for output |
|
| 33 | + * |
|
| 34 | + * @return string HTML |
|
| 35 | + */ |
|
| 36 | + public function render() |
|
| 37 | + { |
|
| 38 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 39 | 39 | <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
| 40 | 40 | <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>"; |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -28,8 +28,8 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | public function render() |
| 30 | 30 | { |
| 31 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 32 | - <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
|
| 33 | - <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>"; |
|
| 31 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."'> |
|
| 32 | + <input type='file' name='" . $this->getName()."' id='".$this->getName()."'".$this->getExtra()."> |
|
| 33 | + <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName()."'>"; |
|
| 34 | 34 | } |
| 35 | 35 | } |
@@ -306,8 +306,8 @@ |
||
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
| 309 | - * @param $form_name |
|
| 310 | - * @param $form_caption |
|
| 309 | + * @param string $form_name |
|
| 310 | + * @param string $form_caption |
|
| 311 | 311 | * @param bool $submit_button_caption |
| 312 | 312 | */ |
| 313 | 313 | public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
@@ -40,548 +40,548 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | class SmartObjectForm extends \XoopsThemeForm |
| 42 | 42 | { |
| 43 | - public $targetObject = null; |
|
| 44 | - public $form_fields = null; |
|
| 45 | - public $_cancel_js_action = false; |
|
| 46 | - public $_custom_button = false; |
|
| 47 | - public $_captcha = false; |
|
| 48 | - public $_form_name = false; |
|
| 49 | - public $_form_caption = false; |
|
| 50 | - public $_submit_button_caption = false; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * SmartobjectForm constructor. |
|
| 54 | - * @param string $target |
|
| 55 | - * @param string $form_name |
|
| 56 | - * @param string $form_caption |
|
| 57 | - * @param string $form_action |
|
| 58 | - * @param null $form_fields |
|
| 59 | - * @param bool $submit_button_caption |
|
| 60 | - * @param bool $cancel_js_action |
|
| 61 | - * @param bool $captcha |
|
| 62 | - */ |
|
| 63 | - public function __construct( |
|
| 64 | - &$target, |
|
| 65 | - $form_name, |
|
| 66 | - $form_caption, |
|
| 67 | - $form_action, |
|
| 68 | - $form_fields = null, |
|
| 69 | - $submit_button_caption = false, |
|
| 70 | - $cancel_js_action = false, |
|
| 71 | - $captcha = false |
|
| 72 | - ) { |
|
| 73 | - $this->targetObject =& $target; |
|
| 74 | - $this->form_fields = $form_fields; |
|
| 75 | - $this->_cancel_js_action = $cancel_js_action; |
|
| 76 | - $this->_captcha = $captcha; |
|
| 77 | - $this->_form_name = $form_name; |
|
| 78 | - $this->_form_caption = $form_caption; |
|
| 79 | - $this->_submit_button_caption = $submit_button_caption; |
|
| 80 | - |
|
| 81 | - if (!isset($form_action)) { |
|
| 82 | - $form_action = xoops_getenv('PHP_SELF'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 86 | - $this->setExtra('enctype="multipart/form-data"'); |
|
| 87 | - |
|
| 88 | - $this->createElements(); |
|
| 89 | - |
|
| 90 | - if ($captcha) { |
|
| 91 | - $this->addCaptcha(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $this->createPermissionControls(); |
|
| 95 | - |
|
| 96 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function addCaptcha() |
|
| 100 | - { |
|
| 101 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 102 | - $this->addElement(new \XoopsFormCaptcha(), true); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @param $name |
|
| 107 | - * @param $caption |
|
| 108 | - * @param bool $onclick |
|
| 109 | - */ |
|
| 110 | - public function addCustomButton($name, $caption, $onclick = false) |
|
| 111 | - { |
|
| 112 | - $custom_button_array = [ |
|
| 113 | - 'name' => $name, |
|
| 114 | - 'caption' => $caption, |
|
| 115 | - 'onclick' => $onclick |
|
| 116 | - ]; |
|
| 117 | - $this->_custom_button[] = $custom_button_array; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Add an element to the form |
|
| 122 | - * |
|
| 123 | - * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 124 | - * @param bool $key |
|
| 125 | - * @param bool $var |
|
| 126 | - * @param bool|string $required is this a "required" element? |
|
| 127 | - */ |
|
| 128 | - public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 129 | - { |
|
| 130 | - if ($key) { |
|
| 131 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
| 132 | - $formElement->setExtra('disabled="disabled"'); |
|
| 133 | - $formElement->setName($key . '-readonly'); |
|
| 134 | - // Since this element is disable, we still want to pass it's value in the form |
|
| 135 | - $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 136 | - $this->addElement($hidden); |
|
| 137 | - } |
|
| 138 | - $formElement->setDescription($var['form_dsc']); |
|
| 139 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 140 | - $hidden = new \XoopsFormHidden('changedField', false); |
|
| 141 | - $this->addElement($hidden); |
|
| 142 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 143 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 144 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 145 | - } else { |
|
| 146 | - if (isset($var['form_extra'])) { |
|
| 147 | - $formElement->setExtra($var['form_extra']); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $controls = $this->targetObject->controls; |
|
| 151 | - if (isset($controls[$key]['js'])) { |
|
| 152 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 153 | - } |
|
| 154 | - parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required); |
|
| 155 | - } else { |
|
| 156 | - parent::addElement($formElement, 'notset' === $required ? false : true); |
|
| 157 | - } |
|
| 158 | - unset($formElement); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - public function createElements() |
|
| 162 | - { |
|
| 163 | - $controls = $this->targetObject->controls; |
|
| 164 | - $vars = $this->targetObject->vars; |
|
| 165 | - foreach ($vars as $key => $var) { |
|
| 166 | - |
|
| 167 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 168 | - // need to be displayed, then we only create an hidden field |
|
| 169 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 170 | - $elementToAdd = new \XoopsFormHidden($key, $var['value']); |
|
| 171 | - $this->addElement($elementToAdd, $key, $var, false); |
|
| 172 | - unset($elementToAdd); |
|
| 173 | - // If not, the we need to create the proper form control for this fields |
|
| 174 | - } else { |
|
| 175 | - // If this field has a specific control, we will use it |
|
| 176 | - |
|
| 177 | - if ('parentid' === $key) { |
|
| 178 | - /** |
|
| 179 | - * Why this ? |
|
| 180 | - */ |
|
| 181 | - } |
|
| 182 | - if (isset($controls[$key])) { |
|
| 183 | - /* If the control has name, it's because it's an object already present in the script |
|
| 43 | + public $targetObject = null; |
|
| 44 | + public $form_fields = null; |
|
| 45 | + public $_cancel_js_action = false; |
|
| 46 | + public $_custom_button = false; |
|
| 47 | + public $_captcha = false; |
|
| 48 | + public $_form_name = false; |
|
| 49 | + public $_form_caption = false; |
|
| 50 | + public $_submit_button_caption = false; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * SmartobjectForm constructor. |
|
| 54 | + * @param string $target |
|
| 55 | + * @param string $form_name |
|
| 56 | + * @param string $form_caption |
|
| 57 | + * @param string $form_action |
|
| 58 | + * @param null $form_fields |
|
| 59 | + * @param bool $submit_button_caption |
|
| 60 | + * @param bool $cancel_js_action |
|
| 61 | + * @param bool $captcha |
|
| 62 | + */ |
|
| 63 | + public function __construct( |
|
| 64 | + &$target, |
|
| 65 | + $form_name, |
|
| 66 | + $form_caption, |
|
| 67 | + $form_action, |
|
| 68 | + $form_fields = null, |
|
| 69 | + $submit_button_caption = false, |
|
| 70 | + $cancel_js_action = false, |
|
| 71 | + $captcha = false |
|
| 72 | + ) { |
|
| 73 | + $this->targetObject =& $target; |
|
| 74 | + $this->form_fields = $form_fields; |
|
| 75 | + $this->_cancel_js_action = $cancel_js_action; |
|
| 76 | + $this->_captcha = $captcha; |
|
| 77 | + $this->_form_name = $form_name; |
|
| 78 | + $this->_form_caption = $form_caption; |
|
| 79 | + $this->_submit_button_caption = $submit_button_caption; |
|
| 80 | + |
|
| 81 | + if (!isset($form_action)) { |
|
| 82 | + $form_action = xoops_getenv('PHP_SELF'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 86 | + $this->setExtra('enctype="multipart/form-data"'); |
|
| 87 | + |
|
| 88 | + $this->createElements(); |
|
| 89 | + |
|
| 90 | + if ($captcha) { |
|
| 91 | + $this->addCaptcha(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $this->createPermissionControls(); |
|
| 95 | + |
|
| 96 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function addCaptcha() |
|
| 100 | + { |
|
| 101 | + require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 102 | + $this->addElement(new \XoopsFormCaptcha(), true); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param $name |
|
| 107 | + * @param $caption |
|
| 108 | + * @param bool $onclick |
|
| 109 | + */ |
|
| 110 | + public function addCustomButton($name, $caption, $onclick = false) |
|
| 111 | + { |
|
| 112 | + $custom_button_array = [ |
|
| 113 | + 'name' => $name, |
|
| 114 | + 'caption' => $caption, |
|
| 115 | + 'onclick' => $onclick |
|
| 116 | + ]; |
|
| 117 | + $this->_custom_button[] = $custom_button_array; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Add an element to the form |
|
| 122 | + * |
|
| 123 | + * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 124 | + * @param bool $key |
|
| 125 | + * @param bool $var |
|
| 126 | + * @param bool|string $required is this a "required" element? |
|
| 127 | + */ |
|
| 128 | + public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 129 | + { |
|
| 130 | + if ($key) { |
|
| 131 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
| 132 | + $formElement->setExtra('disabled="disabled"'); |
|
| 133 | + $formElement->setName($key . '-readonly'); |
|
| 134 | + // Since this element is disable, we still want to pass it's value in the form |
|
| 135 | + $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 136 | + $this->addElement($hidden); |
|
| 137 | + } |
|
| 138 | + $formElement->setDescription($var['form_dsc']); |
|
| 139 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 140 | + $hidden = new \XoopsFormHidden('changedField', false); |
|
| 141 | + $this->addElement($hidden); |
|
| 142 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 143 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 144 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 145 | + } else { |
|
| 146 | + if (isset($var['form_extra'])) { |
|
| 147 | + $formElement->setExtra($var['form_extra']); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $controls = $this->targetObject->controls; |
|
| 151 | + if (isset($controls[$key]['js'])) { |
|
| 152 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 153 | + } |
|
| 154 | + parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required); |
|
| 155 | + } else { |
|
| 156 | + parent::addElement($formElement, 'notset' === $required ? false : true); |
|
| 157 | + } |
|
| 158 | + unset($formElement); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + public function createElements() |
|
| 162 | + { |
|
| 163 | + $controls = $this->targetObject->controls; |
|
| 164 | + $vars = $this->targetObject->vars; |
|
| 165 | + foreach ($vars as $key => $var) { |
|
| 166 | + |
|
| 167 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 168 | + // need to be displayed, then we only create an hidden field |
|
| 169 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 170 | + $elementToAdd = new \XoopsFormHidden($key, $var['value']); |
|
| 171 | + $this->addElement($elementToAdd, $key, $var, false); |
|
| 172 | + unset($elementToAdd); |
|
| 173 | + // If not, the we need to create the proper form control for this fields |
|
| 174 | + } else { |
|
| 175 | + // If this field has a specific control, we will use it |
|
| 176 | + |
|
| 177 | + if ('parentid' === $key) { |
|
| 178 | + /** |
|
| 179 | + * Why this ? |
|
| 180 | + */ |
|
| 181 | + } |
|
| 182 | + if (isset($controls[$key])) { |
|
| 183 | + /* If the control has name, it's because it's an object already present in the script |
|
| 184 | 184 | * for example, "user" |
| 185 | 185 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
| 186 | 186 | */ |
| 187 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 188 | - $controls[$key]['name'] = 'select'; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 192 | - |
|
| 193 | - // Adding on the form, the control for this field |
|
| 194 | - $this->addElement($form_select, $key, $var); |
|
| 195 | - unset($form_select); |
|
| 196 | - |
|
| 197 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 198 | - } else { |
|
| 199 | - switch ($var['data_type']) { |
|
| 200 | - |
|
| 201 | - case XOBJ_DTYPE_TXTBOX: |
|
| 202 | - |
|
| 203 | - $form_text = $this->getControl('text', $key); |
|
| 204 | - $this->addElement($form_text, $key, $var); |
|
| 205 | - unset($form_text); |
|
| 206 | - break; |
|
| 207 | - |
|
| 208 | - case XOBJ_DTYPE_INT: |
|
| 209 | - $this->targetObject->setControl($key, [ |
|
| 210 | - 'name' => 'text', |
|
| 211 | - 'size' => '5' |
|
| 212 | - ]); |
|
| 213 | - $form_text = $this->getControl('text', $key); |
|
| 214 | - $this->addElement($form_text, $key, $var); |
|
| 215 | - unset($form_text); |
|
| 216 | - break; |
|
| 217 | - |
|
| 218 | - case XOBJ_DTYPE_FLOAT: |
|
| 219 | - $this->targetObject->setControl($key, [ |
|
| 220 | - 'name' => 'text', |
|
| 221 | - 'size' => '5' |
|
| 222 | - ]); |
|
| 223 | - $form_text = $this->getControl('text', $key); |
|
| 224 | - $this->addElement($form_text, $key, $var); |
|
| 225 | - unset($form_text); |
|
| 226 | - break; |
|
| 227 | - |
|
| 228 | - case XOBJ_DTYPE_LTIME: |
|
| 229 | - $form_date_time = $this->getControl('date_time', $key); |
|
| 230 | - $this->addElement($form_date_time, $key, $var); |
|
| 231 | - unset($form_date_time); |
|
| 232 | - break; |
|
| 233 | - |
|
| 234 | - case XOBJ_DTYPE_STIME: |
|
| 235 | - $form_date_time = $this->getControl('date', $key); |
|
| 236 | - $this->addElement($form_date_time, $key, $var); |
|
| 237 | - unset($form_date_time); |
|
| 238 | - break; |
|
| 239 | - |
|
| 240 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 241 | - $form_time = $this->getControl('time', $key); |
|
| 242 | - $this->addElement($form_time, $key, $var); |
|
| 243 | - unset($form_time); |
|
| 244 | - break; |
|
| 245 | - |
|
| 246 | - case XOBJ_DTYPE_CURRENCY: |
|
| 247 | - $this->targetObject->setControl($key, [ |
|
| 248 | - 'name' => 'text', |
|
| 249 | - 'size' => '15' |
|
| 250 | - ]); |
|
| 251 | - $form_currency = $this->getControl('text', $key); |
|
| 252 | - $this->addElement($form_currency, $key, $var); |
|
| 253 | - unset($form_currency); |
|
| 254 | - break; |
|
| 255 | - |
|
| 256 | - case XOBJ_DTYPE_URLLINK: |
|
| 257 | - $form_urllink = $this->getControl('urllink', $key); |
|
| 258 | - $this->addElement($form_urllink, $key, $var); |
|
| 259 | - unset($form_urllink); |
|
| 260 | - break; |
|
| 261 | - |
|
| 262 | - case XOBJ_DTYPE_FILE: |
|
| 263 | - $form_file = $this->getControl('richfile', $key); |
|
| 264 | - $this->addElement($form_file, $key, $var); |
|
| 265 | - unset($form_file); |
|
| 266 | - break; |
|
| 267 | - |
|
| 268 | - case XOBJ_DTYPE_TXTAREA: |
|
| 269 | - |
|
| 270 | - $form_text_area = $this->getTextArea($key, $var); |
|
| 271 | - $this->addElement($form_text_area, $key, $var); |
|
| 272 | - unset($form_text_area); |
|
| 273 | - break; |
|
| 274 | - |
|
| 275 | - case XOBJ_DTYPE_ARRAY: |
|
| 276 | - // TODO: To come... |
|
| 277 | - break; |
|
| 278 | - case XOBJ_DTYPE_SOURCE: |
|
| 279 | - // TODO: To come... |
|
| 280 | - break; |
|
| 281 | - case XOBJ_DTYPE_FORM_SECTION: |
|
| 282 | - $section_control = new SmartFormSection($key, $var['value']); |
|
| 283 | - $this->addElement($section_control, $key, $var); |
|
| 284 | - unset($section_control); |
|
| 285 | - break; |
|
| 286 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 287 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 288 | - $this->addElement($section_control, $key, $var); |
|
| 289 | - unset($section_control); |
|
| 290 | - break; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - // Add an hidden field to store the URL of the page before this form |
|
| 296 | - $this->addElement(new \XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - public function createPermissionControls() |
|
| 300 | - { |
|
| 301 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 302 | - |
|
| 303 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
| 304 | - |
|
| 305 | - if ($permissions) { |
|
| 306 | - $memberHandler = xoops_getHandler('member'); |
|
| 307 | - $group_list = $memberHandler->getGroupList(); |
|
| 308 | - asort($group_list); |
|
| 309 | - foreach ($permissions as $permission) { |
|
| 310 | - if ($this->targetObject->isNew()) { |
|
| 311 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 312 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 316 | - } |
|
| 317 | - $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 318 | - $groups_select->setDescription($permission['description']); |
|
| 319 | - $groups_select->addOptionArray($group_list); |
|
| 320 | - $this->addElement($groups_select); |
|
| 321 | - unset($groups_select); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @param $form_name |
|
| 328 | - * @param $form_caption |
|
| 329 | - * @param bool $submit_button_caption |
|
| 330 | - */ |
|
| 331 | - public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 332 | - { |
|
| 333 | - $button_tray = new \XoopsFormElementTray('', ''); |
|
| 334 | - $button_tray->addElement(new \XoopsFormHidden('op', $form_name)); |
|
| 335 | - if (!$submit_button_caption) { |
|
| 336 | - if ($this->targetObject->isNew()) { |
|
| 337 | - $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 338 | - } else { |
|
| 339 | - $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 340 | - } |
|
| 341 | - } else { |
|
| 342 | - $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 343 | - } |
|
| 344 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 345 | - $button_tray->addElement($butt_create); |
|
| 346 | - |
|
| 347 | - //creating custom buttons |
|
| 348 | - if ($this->_custom_button) { |
|
| 349 | - foreach ($this->_custom_button as $custom_button) { |
|
| 350 | - $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 351 | - if ($custom_button['onclick']) { |
|
| 352 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 353 | - } |
|
| 354 | - $button_tray->addElement($butt_custom); |
|
| 355 | - unset($butt_custom); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - // creating the "cancel" button |
|
| 360 | - $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 361 | - if ($this->_cancel_js_action) { |
|
| 362 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 363 | - } else { |
|
| 364 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 365 | - } |
|
| 366 | - $button_tray->addElement($butt_cancel); |
|
| 367 | - |
|
| 368 | - $this->addElement($button_tray); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @param $controlName |
|
| 373 | - * @param $key |
|
| 374 | - * @return \XoopsFormLabel |
|
| 375 | - */ |
|
| 376 | - public function getControl($controlName, $key) |
|
| 377 | - { |
|
| 378 | - switch ($controlName) { |
|
| 379 | - case 'check': |
|
| 187 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 188 | + $controls[$key]['name'] = 'select'; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 192 | + |
|
| 193 | + // Adding on the form, the control for this field |
|
| 194 | + $this->addElement($form_select, $key, $var); |
|
| 195 | + unset($form_select); |
|
| 196 | + |
|
| 197 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 198 | + } else { |
|
| 199 | + switch ($var['data_type']) { |
|
| 200 | + |
|
| 201 | + case XOBJ_DTYPE_TXTBOX: |
|
| 202 | + |
|
| 203 | + $form_text = $this->getControl('text', $key); |
|
| 204 | + $this->addElement($form_text, $key, $var); |
|
| 205 | + unset($form_text); |
|
| 206 | + break; |
|
| 207 | + |
|
| 208 | + case XOBJ_DTYPE_INT: |
|
| 209 | + $this->targetObject->setControl($key, [ |
|
| 210 | + 'name' => 'text', |
|
| 211 | + 'size' => '5' |
|
| 212 | + ]); |
|
| 213 | + $form_text = $this->getControl('text', $key); |
|
| 214 | + $this->addElement($form_text, $key, $var); |
|
| 215 | + unset($form_text); |
|
| 216 | + break; |
|
| 217 | + |
|
| 218 | + case XOBJ_DTYPE_FLOAT: |
|
| 219 | + $this->targetObject->setControl($key, [ |
|
| 220 | + 'name' => 'text', |
|
| 221 | + 'size' => '5' |
|
| 222 | + ]); |
|
| 223 | + $form_text = $this->getControl('text', $key); |
|
| 224 | + $this->addElement($form_text, $key, $var); |
|
| 225 | + unset($form_text); |
|
| 226 | + break; |
|
| 227 | + |
|
| 228 | + case XOBJ_DTYPE_LTIME: |
|
| 229 | + $form_date_time = $this->getControl('date_time', $key); |
|
| 230 | + $this->addElement($form_date_time, $key, $var); |
|
| 231 | + unset($form_date_time); |
|
| 232 | + break; |
|
| 233 | + |
|
| 234 | + case XOBJ_DTYPE_STIME: |
|
| 235 | + $form_date_time = $this->getControl('date', $key); |
|
| 236 | + $this->addElement($form_date_time, $key, $var); |
|
| 237 | + unset($form_date_time); |
|
| 238 | + break; |
|
| 239 | + |
|
| 240 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 241 | + $form_time = $this->getControl('time', $key); |
|
| 242 | + $this->addElement($form_time, $key, $var); |
|
| 243 | + unset($form_time); |
|
| 244 | + break; |
|
| 245 | + |
|
| 246 | + case XOBJ_DTYPE_CURRENCY: |
|
| 247 | + $this->targetObject->setControl($key, [ |
|
| 248 | + 'name' => 'text', |
|
| 249 | + 'size' => '15' |
|
| 250 | + ]); |
|
| 251 | + $form_currency = $this->getControl('text', $key); |
|
| 252 | + $this->addElement($form_currency, $key, $var); |
|
| 253 | + unset($form_currency); |
|
| 254 | + break; |
|
| 255 | + |
|
| 256 | + case XOBJ_DTYPE_URLLINK: |
|
| 257 | + $form_urllink = $this->getControl('urllink', $key); |
|
| 258 | + $this->addElement($form_urllink, $key, $var); |
|
| 259 | + unset($form_urllink); |
|
| 260 | + break; |
|
| 261 | + |
|
| 262 | + case XOBJ_DTYPE_FILE: |
|
| 263 | + $form_file = $this->getControl('richfile', $key); |
|
| 264 | + $this->addElement($form_file, $key, $var); |
|
| 265 | + unset($form_file); |
|
| 266 | + break; |
|
| 267 | + |
|
| 268 | + case XOBJ_DTYPE_TXTAREA: |
|
| 269 | + |
|
| 270 | + $form_text_area = $this->getTextArea($key, $var); |
|
| 271 | + $this->addElement($form_text_area, $key, $var); |
|
| 272 | + unset($form_text_area); |
|
| 273 | + break; |
|
| 274 | + |
|
| 275 | + case XOBJ_DTYPE_ARRAY: |
|
| 276 | + // TODO: To come... |
|
| 277 | + break; |
|
| 278 | + case XOBJ_DTYPE_SOURCE: |
|
| 279 | + // TODO: To come... |
|
| 280 | + break; |
|
| 281 | + case XOBJ_DTYPE_FORM_SECTION: |
|
| 282 | + $section_control = new SmartFormSection($key, $var['value']); |
|
| 283 | + $this->addElement($section_control, $key, $var); |
|
| 284 | + unset($section_control); |
|
| 285 | + break; |
|
| 286 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 287 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 288 | + $this->addElement($section_control, $key, $var); |
|
| 289 | + unset($section_control); |
|
| 290 | + break; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + // Add an hidden field to store the URL of the page before this form |
|
| 296 | + $this->addElement(new \XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + public function createPermissionControls() |
|
| 300 | + { |
|
| 301 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 302 | + |
|
| 303 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
| 304 | + |
|
| 305 | + if ($permissions) { |
|
| 306 | + $memberHandler = xoops_getHandler('member'); |
|
| 307 | + $group_list = $memberHandler->getGroupList(); |
|
| 308 | + asort($group_list); |
|
| 309 | + foreach ($permissions as $permission) { |
|
| 310 | + if ($this->targetObject->isNew()) { |
|
| 311 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 312 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 316 | + } |
|
| 317 | + $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 318 | + $groups_select->setDescription($permission['description']); |
|
| 319 | + $groups_select->addOptionArray($group_list); |
|
| 320 | + $this->addElement($groups_select); |
|
| 321 | + unset($groups_select); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @param $form_name |
|
| 328 | + * @param $form_caption |
|
| 329 | + * @param bool $submit_button_caption |
|
| 330 | + */ |
|
| 331 | + public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 332 | + { |
|
| 333 | + $button_tray = new \XoopsFormElementTray('', ''); |
|
| 334 | + $button_tray->addElement(new \XoopsFormHidden('op', $form_name)); |
|
| 335 | + if (!$submit_button_caption) { |
|
| 336 | + if ($this->targetObject->isNew()) { |
|
| 337 | + $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 338 | + } else { |
|
| 339 | + $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 340 | + } |
|
| 341 | + } else { |
|
| 342 | + $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 343 | + } |
|
| 344 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 345 | + $button_tray->addElement($butt_create); |
|
| 346 | + |
|
| 347 | + //creating custom buttons |
|
| 348 | + if ($this->_custom_button) { |
|
| 349 | + foreach ($this->_custom_button as $custom_button) { |
|
| 350 | + $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 351 | + if ($custom_button['onclick']) { |
|
| 352 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 353 | + } |
|
| 354 | + $button_tray->addElement($butt_custom); |
|
| 355 | + unset($butt_custom); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + // creating the "cancel" button |
|
| 360 | + $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 361 | + if ($this->_cancel_js_action) { |
|
| 362 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 363 | + } else { |
|
| 364 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 365 | + } |
|
| 366 | + $button_tray->addElement($butt_cancel); |
|
| 367 | + |
|
| 368 | + $this->addElement($button_tray); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @param $controlName |
|
| 373 | + * @param $key |
|
| 374 | + * @return \XoopsFormLabel |
|
| 375 | + */ |
|
| 376 | + public function getControl($controlName, $key) |
|
| 377 | + { |
|
| 378 | + switch ($controlName) { |
|
| 379 | + case 'check': |
|
| 380 | 380 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
| 381 | - $control = $this->targetObject->getControl($key); |
|
| 382 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 383 | - $controlObj->addOptionArray($control['options']); |
|
| 381 | + $control = $this->targetObject->getControl($key); |
|
| 382 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 383 | + $controlObj->addOptionArray($control['options']); |
|
| 384 | 384 | |
| 385 | - return $controlObj; |
|
| 386 | - break; |
|
| 385 | + return $controlObj; |
|
| 386 | + break; |
|
| 387 | 387 | |
| 388 | - case 'color': |
|
| 389 | - $control = $this->targetObject->getControl($key); |
|
| 390 | - $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 388 | + case 'color': |
|
| 389 | + $control = $this->targetObject->getControl($key); |
|
| 390 | + $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 391 | 391 | |
| 392 | - return $controlObj; |
|
| 393 | - break; |
|
| 392 | + return $controlObj; |
|
| 393 | + break; |
|
| 394 | 394 | |
| 395 | - case 'radio': |
|
| 396 | - $control = $this->targetObject->getControl($key); |
|
| 395 | + case 'radio': |
|
| 396 | + $control = $this->targetObject->getControl($key); |
|
| 397 | 397 | |
| 398 | - $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 399 | - $controlObj->addOptionArray($control['options']); |
|
| 398 | + $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 399 | + $controlObj->addOptionArray($control['options']); |
|
| 400 | 400 | |
| 401 | - return $controlObj; |
|
| 402 | - break; |
|
| 401 | + return $controlObj; |
|
| 402 | + break; |
|
| 403 | 403 | |
| 404 | - case 'label': |
|
| 405 | - return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 406 | - break; |
|
| 404 | + case 'label': |
|
| 405 | + return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 406 | + break; |
|
| 407 | 407 | |
| 408 | - case 'textarea': |
|
| 409 | - return $this->getTextArea($key); |
|
| 408 | + case 'textarea': |
|
| 409 | + return $this->getTextArea($key); |
|
| 410 | 410 | |
| 411 | - case 'theme': |
|
| 412 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 411 | + case 'theme': |
|
| 412 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 413 | 413 | |
| 414 | - case 'theme_multi': |
|
| 415 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 416 | - break; |
|
| 414 | + case 'theme_multi': |
|
| 415 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 416 | + break; |
|
| 417 | 417 | |
| 418 | - case 'timezone': |
|
| 419 | - return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 420 | - break; |
|
| 418 | + case 'timezone': |
|
| 419 | + return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 420 | + break; |
|
| 421 | 421 | |
| 422 | - case 'group': |
|
| 423 | - return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 424 | - break; |
|
| 422 | + case 'group': |
|
| 423 | + return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 424 | + break; |
|
| 425 | 425 | |
| 426 | - case 'group_multi': |
|
| 427 | - return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 428 | - break; |
|
| 426 | + case 'group_multi': |
|
| 427 | + return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 428 | + break; |
|
| 429 | 429 | |
| 430 | - /*case 'user': |
|
| 430 | + /*case 'user': |
|
| 431 | 431 | return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
| 432 | 432 | break;*/ |
| 433 | 433 | |
| 434 | - case 'user_multi': |
|
| 435 | - return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 436 | - break; |
|
| 434 | + case 'user_multi': |
|
| 435 | + return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 436 | + break; |
|
| 437 | 437 | |
| 438 | - case 'password': |
|
| 439 | - return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 440 | - break; |
|
| 438 | + case 'password': |
|
| 439 | + return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 440 | + break; |
|
| 441 | 441 | |
| 442 | - case 'country': |
|
| 443 | - return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 444 | - break; |
|
| 442 | + case 'country': |
|
| 443 | + return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 444 | + break; |
|
| 445 | 445 | |
| 446 | - case 'urllink': |
|
| 446 | + case 'urllink': |
|
| 447 | 447 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
| 448 | 448 | |
| 449 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 450 | - break; |
|
| 449 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 450 | + break; |
|
| 451 | 451 | |
| 452 | - case 'richfile': |
|
| 452 | + case 'richfile': |
|
| 453 | 453 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
| 454 | 454 | |
| 455 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 456 | - break; |
|
| 457 | - case 'section': |
|
| 455 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 456 | + break; |
|
| 457 | + case 'section': |
|
| 458 | 458 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
| 459 | 459 | |
| 460 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 461 | - break; |
|
| 460 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 461 | + break; |
|
| 462 | 462 | |
| 463 | - default: |
|
| 464 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 465 | - if (!class_exists($classname)) { |
|
| 466 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 463 | + default: |
|
| 464 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 465 | + if (!class_exists($classname)) { |
|
| 466 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 467 | 467 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
| 468 | - } else { |
|
| 469 | - // perhaps this is a control created by the module |
|
| 470 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
| 471 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 472 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 473 | - $classFileName = strtolower($classname) . '.php'; |
|
| 474 | - |
|
| 475 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 468 | + } else { |
|
| 469 | + // perhaps this is a control created by the module |
|
| 470 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
| 471 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 472 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 473 | + $classFileName = strtolower($classname) . '.php'; |
|
| 474 | + |
|
| 475 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 476 | 476 | // require_once $moduleFormElementsPath . $classFileName; |
| 477 | - } else { |
|
| 478 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 479 | - |
|
| 480 | - return new \XoopsFormLabel(); //Empty object |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - return new $classname($this->targetObject, $key); |
|
| 486 | - break; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * @param $key |
|
| 492 | - * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4 |
|
| 493 | - */ |
|
| 494 | - public function getTextArea($key) |
|
| 495 | - { |
|
| 496 | - $var = $this->targetObject->vars[$key]; |
|
| 497 | - |
|
| 498 | - // if no control has been created, let's create a default one |
|
| 499 | - if (!isset($this->targetObject->controls[$key])) { |
|
| 500 | - $control = [ |
|
| 501 | - 'name' => 'textarea', |
|
| 502 | - 'itemHandler' => false, |
|
| 503 | - 'method' => false, |
|
| 504 | - 'module' => false, |
|
| 505 | - 'form_editor' => 'default' |
|
| 506 | - ]; |
|
| 507 | - } else { |
|
| 508 | - $control = $this->targetObject->controls[$key]; |
|
| 509 | - } |
|
| 510 | - $xoops22 = smart_isXoops22(); |
|
| 511 | - |
|
| 512 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 513 | - /** |
|
| 514 | - * If the editor is 'default', retreive the default editor of this module |
|
| 515 | - */ |
|
| 516 | - if ('default' === $form_editor) { |
|
| 517 | - global $xoopsModuleConfig; |
|
| 518 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $caption = $var['form_caption']; |
|
| 522 | - $name = $key; |
|
| 523 | - |
|
| 524 | - $value = $this->targetObject->getVar($key); |
|
| 525 | - |
|
| 526 | - $value = $this->targetObject->getValueFor($key, true); |
|
| 527 | - |
|
| 528 | - $editor_configs = []; |
|
| 529 | - $editor_configs['name'] = $name; |
|
| 530 | - $editor_configs['value'] = $value; |
|
| 531 | - if ('textarea' !== $form_editor) { |
|
| 532 | - $editor_configs['rows'] = 35; |
|
| 533 | - $editor_configs['cols'] = 60; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - if (isset($control['rows'])) { |
|
| 537 | - $editor_configs['rows'] = $control['rows']; |
|
| 538 | - } |
|
| 539 | - if (isset($control['cols'])) { |
|
| 540 | - $editor_configs['cols'] = $control['cols']; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - $editor_configs['width'] = '100%'; |
|
| 544 | - $editor_configs['height'] = '400px'; |
|
| 545 | - |
|
| 546 | - $dhtml = true; |
|
| 547 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 548 | - |
|
| 549 | - if (file_exists($xoopseditorclass)) { |
|
| 550 | - require_once $xoopseditorclass; |
|
| 551 | - $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 552 | - } else { |
|
| 553 | - switch ($form_editor) { |
|
| 554 | - |
|
| 555 | - case 'tiny': |
|
| 556 | - if (!$xoops22) { |
|
| 557 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 559 | - $editor = new \XoopsFormTinymce([ |
|
| 560 | - 'caption' => $caption, |
|
| 561 | - 'name' => $name, |
|
| 562 | - 'value' => $value, |
|
| 563 | - 'width' => '100%', |
|
| 564 | - 'height' => '300px' |
|
| 565 | - ], true); |
|
| 566 | - } else { |
|
| 567 | - if ($dhtml) { |
|
| 568 | - $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 569 | - } else { |
|
| 570 | - $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - } else { |
|
| 574 | - $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 575 | - } |
|
| 576 | - break; |
|
| 577 | - |
|
| 578 | - case 'dhtmltextarea': |
|
| 579 | - case 'dhtmltext': |
|
| 580 | - $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 581 | - if ($var['form_dsc']) { |
|
| 582 | - $editor->setDescription($var['form_dsc']); |
|
| 583 | - } |
|
| 584 | - break; |
|
| 477 | + } else { |
|
| 478 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 479 | + |
|
| 480 | + return new \XoopsFormLabel(); //Empty object |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + return new $classname($this->targetObject, $key); |
|
| 486 | + break; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @param $key |
|
| 492 | + * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4 |
|
| 493 | + */ |
|
| 494 | + public function getTextArea($key) |
|
| 495 | + { |
|
| 496 | + $var = $this->targetObject->vars[$key]; |
|
| 497 | + |
|
| 498 | + // if no control has been created, let's create a default one |
|
| 499 | + if (!isset($this->targetObject->controls[$key])) { |
|
| 500 | + $control = [ |
|
| 501 | + 'name' => 'textarea', |
|
| 502 | + 'itemHandler' => false, |
|
| 503 | + 'method' => false, |
|
| 504 | + 'module' => false, |
|
| 505 | + 'form_editor' => 'default' |
|
| 506 | + ]; |
|
| 507 | + } else { |
|
| 508 | + $control = $this->targetObject->controls[$key]; |
|
| 509 | + } |
|
| 510 | + $xoops22 = smart_isXoops22(); |
|
| 511 | + |
|
| 512 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 513 | + /** |
|
| 514 | + * If the editor is 'default', retreive the default editor of this module |
|
| 515 | + */ |
|
| 516 | + if ('default' === $form_editor) { |
|
| 517 | + global $xoopsModuleConfig; |
|
| 518 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $caption = $var['form_caption']; |
|
| 522 | + $name = $key; |
|
| 523 | + |
|
| 524 | + $value = $this->targetObject->getVar($key); |
|
| 525 | + |
|
| 526 | + $value = $this->targetObject->getValueFor($key, true); |
|
| 527 | + |
|
| 528 | + $editor_configs = []; |
|
| 529 | + $editor_configs['name'] = $name; |
|
| 530 | + $editor_configs['value'] = $value; |
|
| 531 | + if ('textarea' !== $form_editor) { |
|
| 532 | + $editor_configs['rows'] = 35; |
|
| 533 | + $editor_configs['cols'] = 60; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + if (isset($control['rows'])) { |
|
| 537 | + $editor_configs['rows'] = $control['rows']; |
|
| 538 | + } |
|
| 539 | + if (isset($control['cols'])) { |
|
| 540 | + $editor_configs['cols'] = $control['cols']; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + $editor_configs['width'] = '100%'; |
|
| 544 | + $editor_configs['height'] = '400px'; |
|
| 545 | + |
|
| 546 | + $dhtml = true; |
|
| 547 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 548 | + |
|
| 549 | + if (file_exists($xoopseditorclass)) { |
|
| 550 | + require_once $xoopseditorclass; |
|
| 551 | + $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 552 | + } else { |
|
| 553 | + switch ($form_editor) { |
|
| 554 | + |
|
| 555 | + case 'tiny': |
|
| 556 | + if (!$xoops22) { |
|
| 557 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 559 | + $editor = new \XoopsFormTinymce([ |
|
| 560 | + 'caption' => $caption, |
|
| 561 | + 'name' => $name, |
|
| 562 | + 'value' => $value, |
|
| 563 | + 'width' => '100%', |
|
| 564 | + 'height' => '300px' |
|
| 565 | + ], true); |
|
| 566 | + } else { |
|
| 567 | + if ($dhtml) { |
|
| 568 | + $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 569 | + } else { |
|
| 570 | + $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + } else { |
|
| 574 | + $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 575 | + } |
|
| 576 | + break; |
|
| 577 | + |
|
| 578 | + case 'dhtmltextarea': |
|
| 579 | + case 'dhtmltext': |
|
| 580 | + $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 581 | + if ($var['form_dsc']) { |
|
| 582 | + $editor->setDescription($var['form_dsc']); |
|
| 583 | + } |
|
| 584 | + break; |
|
| 585 | 585 | |
| 586 | 586 | // case 'inbetween': |
| 587 | 587 | // if (!$xoops22) { |
@@ -634,177 +634,177 @@ discard block |
||
| 634 | 634 | // } |
| 635 | 635 | // break; |
| 636 | 636 | |
| 637 | - default: |
|
| 638 | - case 'textarea': |
|
| 639 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 640 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 641 | - |
|
| 642 | - $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 643 | - if ($var['form_dsc']) { |
|
| 644 | - $editor->setDescription($var['form_dsc']); |
|
| 645 | - } |
|
| 646 | - break; |
|
| 647 | - |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - return $editor; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * @param $key |
|
| 656 | - * @param $var |
|
| 657 | - * @param bool $multiple |
|
| 658 | - * @return \XoopsFormSelect |
|
| 659 | - */ |
|
| 660 | - public function getThemeSelect($key, $var, $multiple = false) |
|
| 661 | - { |
|
| 662 | - $size = $multiple ? 5 : 1; |
|
| 663 | - $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 664 | - |
|
| 665 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 666 | - $dirlist = []; |
|
| 667 | - while (false !== ($file = readdir($handle))) { |
|
| 668 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 669 | - && 'cvs' !== strtolower($file)) { |
|
| 670 | - $dirlist[$file] = $file; |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - closedir($handle); |
|
| 674 | - if (!empty($dirlist)) { |
|
| 675 | - asort($dirlist); |
|
| 676 | - $theme_select->addOptionArray($dirlist); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - return $theme_select; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * @param $keyname |
|
| 684 | - * @return bool |
|
| 685 | - */ |
|
| 686 | - public function &getElementById($keyname) |
|
| 687 | - { |
|
| 688 | - foreach ($this->_elements as $eleObj) { |
|
| 689 | - if ($eleObj->getName() == $keyname) { |
|
| 690 | - $ret =& $eleObj; |
|
| 691 | - break; |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - return isset($ret) ? $ret : false; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * create HTML to output the form as a theme-enabled table with validation. |
|
| 700 | - * |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - public function render() |
|
| 704 | - { |
|
| 705 | - $required = $this->getRequired(); |
|
| 706 | - $ret = " |
|
| 637 | + default: |
|
| 638 | + case 'textarea': |
|
| 639 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 640 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 641 | + |
|
| 642 | + $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 643 | + if ($var['form_dsc']) { |
|
| 644 | + $editor->setDescription($var['form_dsc']); |
|
| 645 | + } |
|
| 646 | + break; |
|
| 647 | + |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + return $editor; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * @param $key |
|
| 656 | + * @param $var |
|
| 657 | + * @param bool $multiple |
|
| 658 | + * @return \XoopsFormSelect |
|
| 659 | + */ |
|
| 660 | + public function getThemeSelect($key, $var, $multiple = false) |
|
| 661 | + { |
|
| 662 | + $size = $multiple ? 5 : 1; |
|
| 663 | + $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 664 | + |
|
| 665 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 666 | + $dirlist = []; |
|
| 667 | + while (false !== ($file = readdir($handle))) { |
|
| 668 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 669 | + && 'cvs' !== strtolower($file)) { |
|
| 670 | + $dirlist[$file] = $file; |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + closedir($handle); |
|
| 674 | + if (!empty($dirlist)) { |
|
| 675 | + asort($dirlist); |
|
| 676 | + $theme_select->addOptionArray($dirlist); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + return $theme_select; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * @param $keyname |
|
| 684 | + * @return bool |
|
| 685 | + */ |
|
| 686 | + public function &getElementById($keyname) |
|
| 687 | + { |
|
| 688 | + foreach ($this->_elements as $eleObj) { |
|
| 689 | + if ($eleObj->getName() == $keyname) { |
|
| 690 | + $ret =& $eleObj; |
|
| 691 | + break; |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + return isset($ret) ? $ret : false; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * create HTML to output the form as a theme-enabled table with validation. |
|
| 700 | + * |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + public function render() |
|
| 704 | + { |
|
| 705 | + $required = $this->getRequired(); |
|
| 706 | + $ret = " |
|
| 707 | 707 | <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
| 708 | 708 | <table width='100%' class='outer' cellspacing='1'> |
| 709 | 709 | <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
| 710 | 710 | '; |
| 711 | - $hidden = ''; |
|
| 712 | - $class = 'even'; |
|
| 713 | - foreach ($this->getElements() as $ele) { |
|
| 714 | - if (!is_object($ele)) { |
|
| 715 | - $ret .= $ele; |
|
| 716 | - } elseif (!$ele->isHidden()) { |
|
| 717 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 718 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 719 | - if ('' !== $ele->getDescription()) { |
|
| 720 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 721 | - } |
|
| 722 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 723 | - } else { |
|
| 724 | - $hidden .= $ele->render(); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 728 | - $ret .= $this->renderValidationJS(true); |
|
| 729 | - |
|
| 730 | - return $ret; |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * assign to smarty form template instead of displaying directly |
|
| 735 | - * |
|
| 736 | - * @param \XoopsTpl $tpl |
|
| 737 | - * |
|
| 738 | - * object |
|
| 739 | - * @param bool $smartyName |
|
| 740 | - * @see Smarty |
|
| 741 | - */ |
|
| 742 | - public function assign(\XoopsTpl $tpl, $smartyName = false) |
|
| 743 | - { |
|
| 744 | - $i = 0; |
|
| 745 | - $elements = []; |
|
| 746 | - foreach ($this->getElements() as $ele) { |
|
| 747 | - $n = ('' !== $ele->getName()) ? $ele->getName() : $i; |
|
| 748 | - $elements[$n]['name'] = $ele->getName(); |
|
| 749 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
| 750 | - $elements[$n]['body'] = $ele->render(); |
|
| 751 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 752 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 753 | - $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
|
| 754 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 755 | - if ('' !== $ele->getDescription()) { |
|
| 756 | - $elements[$n]['description'] = $ele->getDescription(); |
|
| 757 | - } |
|
| 758 | - ++$i; |
|
| 759 | - } |
|
| 760 | - $js = $this->renderValidationJS(); |
|
| 761 | - if (!$smartyName) { |
|
| 762 | - $smartyName = $this->getName(); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - $tpl->assign($smartyName, [ |
|
| 766 | - 'title' => $this->getTitle(), |
|
| 767 | - 'name' => $this->getName(), |
|
| 768 | - 'action' => $this->getAction(), |
|
| 769 | - 'method' => $this->getMethod(), |
|
| 770 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 771 | - 'javascript' => $js, |
|
| 772 | - 'elements' => $elements |
|
| 773 | - ]); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * @param bool $withtags |
|
| 778 | - * @return string |
|
| 779 | - */ |
|
| 780 | - public function renderValidationJS($withtags = true) |
|
| 781 | - { |
|
| 782 | - $js = ''; |
|
| 783 | - if ($withtags) { |
|
| 784 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 785 | - } |
|
| 786 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 787 | - $formname = $this->getName(); |
|
| 788 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 789 | - // First, output code to check required elements |
|
| 790 | - $elements = $this->getRequired(); |
|
| 791 | - foreach ($elements as $elt) { |
|
| 792 | - $eltname = $elt->getName(); |
|
| 793 | - $eltcaption = trim($elt->getCaption()); |
|
| 794 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 795 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 796 | - if ('xoopsformradio' === strtolower(get_class($elt))) { |
|
| 797 | - $js .= 'var myOption = -1;'; |
|
| 798 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 711 | + $hidden = ''; |
|
| 712 | + $class = 'even'; |
|
| 713 | + foreach ($this->getElements() as $ele) { |
|
| 714 | + if (!is_object($ele)) { |
|
| 715 | + $ret .= $ele; |
|
| 716 | + } elseif (!$ele->isHidden()) { |
|
| 717 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 718 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 719 | + if ('' !== $ele->getDescription()) { |
|
| 720 | + $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 721 | + } |
|
| 722 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 723 | + } else { |
|
| 724 | + $hidden .= $ele->render(); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 728 | + $ret .= $this->renderValidationJS(true); |
|
| 729 | + |
|
| 730 | + return $ret; |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * assign to smarty form template instead of displaying directly |
|
| 735 | + * |
|
| 736 | + * @param \XoopsTpl $tpl |
|
| 737 | + * |
|
| 738 | + * object |
|
| 739 | + * @param bool $smartyName |
|
| 740 | + * @see Smarty |
|
| 741 | + */ |
|
| 742 | + public function assign(\XoopsTpl $tpl, $smartyName = false) |
|
| 743 | + { |
|
| 744 | + $i = 0; |
|
| 745 | + $elements = []; |
|
| 746 | + foreach ($this->getElements() as $ele) { |
|
| 747 | + $n = ('' !== $ele->getName()) ? $ele->getName() : $i; |
|
| 748 | + $elements[$n]['name'] = $ele->getName(); |
|
| 749 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
| 750 | + $elements[$n]['body'] = $ele->render(); |
|
| 751 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 752 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 753 | + $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
|
| 754 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 755 | + if ('' !== $ele->getDescription()) { |
|
| 756 | + $elements[$n]['description'] = $ele->getDescription(); |
|
| 757 | + } |
|
| 758 | + ++$i; |
|
| 759 | + } |
|
| 760 | + $js = $this->renderValidationJS(); |
|
| 761 | + if (!$smartyName) { |
|
| 762 | + $smartyName = $this->getName(); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + $tpl->assign($smartyName, [ |
|
| 766 | + 'title' => $this->getTitle(), |
|
| 767 | + 'name' => $this->getName(), |
|
| 768 | + 'action' => $this->getAction(), |
|
| 769 | + 'method' => $this->getMethod(), |
|
| 770 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 771 | + 'javascript' => $js, |
|
| 772 | + 'elements' => $elements |
|
| 773 | + ]); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * @param bool $withtags |
|
| 778 | + * @return string |
|
| 779 | + */ |
|
| 780 | + public function renderValidationJS($withtags = true) |
|
| 781 | + { |
|
| 782 | + $js = ''; |
|
| 783 | + if ($withtags) { |
|
| 784 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 785 | + } |
|
| 786 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 787 | + $formname = $this->getName(); |
|
| 788 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 789 | + // First, output code to check required elements |
|
| 790 | + $elements = $this->getRequired(); |
|
| 791 | + foreach ($elements as $elt) { |
|
| 792 | + $eltname = $elt->getName(); |
|
| 793 | + $eltcaption = trim($elt->getCaption()); |
|
| 794 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 795 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 796 | + if ('xoopsformradio' === strtolower(get_class($elt))) { |
|
| 797 | + $js .= 'var myOption = -1;'; |
|
| 798 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 799 | 799 | if (myform.{$eltname}[i].checked) { |
| 800 | 800 | myOption = i; i = -1; |
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | if (myOption == -1) { |
| 804 | 804 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
| 805 | - } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
| 806 | - $js .= 'var hasSelections = false;'; |
|
| 807 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 805 | + } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
| 806 | + $js .= 'var hasSelections = false;'; |
|
| 807 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 808 | 808 | if (myform['{$eltname}[]'].options[i].selected) { |
| 809 | 809 | hasSelections = true; |
| 810 | 810 | } |
@@ -812,12 +812,12 @@ discard block |
||
| 812 | 812 | } |
| 813 | 813 | if (hasSelections === false) { |
| 814 | 814 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
| 815 | - } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
| 816 | - || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
| 817 | - $js .= 'var hasSelections = false;'; |
|
| 818 | - //sometimes, there is an implicit '[]', sometimes not |
|
| 819 | - if (false === strpos($eltname, '[')) { |
|
| 820 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 815 | + } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
| 816 | + || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
| 817 | + $js .= 'var hasSelections = false;'; |
|
| 818 | + //sometimes, there is an implicit '[]', sometimes not |
|
| 819 | + if (false === strpos($eltname, '[')) { |
|
| 820 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 821 | 821 | if (myform['{$eltname}[]'][i].checked) { |
| 822 | 822 | hasSelections = true; |
| 823 | 823 | } |
@@ -825,8 +825,8 @@ discard block |
||
| 825 | 825 | } |
| 826 | 826 | if (hasSelections === false) { |
| 827 | 827 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
| 828 | - } else { |
|
| 829 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 828 | + } else { |
|
| 829 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 830 | 830 | if (myform['{$eltname}'][i].checked) { |
| 831 | 831 | hasSelections = true; |
| 832 | 832 | } |
@@ -834,25 +834,25 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | if (hasSelections === false) { |
| 836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 837 | - } |
|
| 838 | - } else { |
|
| 839 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - // Now, handle custom validation code |
|
| 843 | - $elements =& $this->getElements(true); |
|
| 844 | - foreach ($elements as $elt) { |
|
| 845 | - if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
| 846 | - if ($eltjs = $elt->renderValidationJS()) { |
|
| 847 | - $js .= $eltjs . "\n"; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - $js .= "return true;\n}\n"; |
|
| 852 | - if ($withtags) { |
|
| 853 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return $js; |
|
| 857 | - } |
|
| 837 | + } |
|
| 838 | + } else { |
|
| 839 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + // Now, handle custom validation code |
|
| 843 | + $elements =& $this->getElements(true); |
|
| 844 | + foreach ($elements as $elt) { |
|
| 845 | + if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
| 846 | + if ($eltjs = $elt->renderValidationJS()) { |
|
| 847 | + $js .= $eltjs . "\n"; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + $js .= "return true;\n}\n"; |
|
| 852 | + if ($withtags) { |
|
| 853 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return $js; |
|
| 857 | + } |
|
| 858 | 858 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | use XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
| 26 | 26 | use XoopsModules\Smartobject\Form\Elements\SmartFormUrlLinkElement; |
| 27 | 27 | |
| 28 | -require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 28 | +require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
| 29 | 29 | //require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
| 30 | 30 | //require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsectionclose.php'; |
| 31 | 31 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $cancel_js_action = false, |
| 71 | 71 | $captcha = false |
| 72 | 72 | ) { |
| 73 | - $this->targetObject =& $target; |
|
| 73 | + $this->targetObject = & $target; |
|
| 74 | 74 | $this->form_fields = $form_fields; |
| 75 | 75 | $this->_cancel_js_action = $cancel_js_action; |
| 76 | 76 | $this->_captcha = $captcha; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | public function addCaptcha() |
| 100 | 100 | { |
| 101 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 101 | + require_once SMARTOBJECT_ROOT_PATH.'include/captcha/formcaptcha.php'; |
|
| 102 | 102 | $this->addElement(new \XoopsFormCaptcha(), true); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function addCustomButton($name, $caption, $onclick = false) |
| 111 | 111 | { |
| 112 | - $custom_button_array = [ |
|
| 112 | + $custom_button_array = [ |
|
| 113 | 113 | 'name' => $name, |
| 114 | 114 | 'caption' => $caption, |
| 115 | 115 | 'onclick' => $onclick |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | if ($key) { |
| 131 | 131 | if ($this->targetObject->vars[$key]['readonly']) { |
| 132 | 132 | $formElement->setExtra('disabled="disabled"'); |
| 133 | - $formElement->setName($key . '-readonly'); |
|
| 133 | + $formElement->setName($key.'-readonly'); |
|
| 134 | 134 | // Since this element is disable, we still want to pass it's value in the form |
| 135 | 135 | $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
| 136 | 136 | $this->addElement($hidden); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $this->addElement($hidden); |
| 142 | 142 | $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
| 143 | 143 | $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
| 144 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 144 | + $formElement->setExtra('onchange="'.$onchangedString.'"'.' '.$otherExtra); |
|
| 145 | 145 | } else { |
| 146 | 146 | if (isset($var['form_extra'])) { |
| 147 | 147 | $formElement->setExtra($var['form_extra']); |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | asort($group_list); |
| 309 | 309 | foreach ($permissions as $permission) { |
| 310 | 310 | if ($this->targetObject->isNew()) { |
| 311 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 312 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 311 | + if (isset($smartModuleConfig['def_perm_'.$permission['perm_name']])) { |
|
| 312 | + $groups_value = $smartModuleConfig['def_perm_'.$permission['perm_name']]; |
|
| 313 | 313 | } |
| 314 | 314 | } else { |
| 315 | 315 | $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | } else { |
| 342 | 342 | $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
| 343 | 343 | } |
| 344 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 344 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\''.$form_name.'\'"'); |
|
| 345 | 345 | $button_tray->addElement($butt_create); |
| 346 | 346 | |
| 347 | 347 | //creating custom buttons |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | foreach ($this->_custom_button as $custom_button) { |
| 350 | 350 | $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
| 351 | 351 | if ($custom_button['onclick']) { |
| 352 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 352 | + $butt_custom->setExtra('onclick="'.$custom_button['onclick'].'"'); |
|
| 353 | 353 | } |
| 354 | 354 | $button_tray->addElement($butt_custom); |
| 355 | 355 | unset($butt_custom); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | // creating the "cancel" button |
| 360 | 360 | $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
| 361 | 361 | if ($this->_cancel_js_action) { |
| 362 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 362 | + $butt_cancel->setExtra('onclick="'.$this->_cancel_js_action.'"'); |
|
| 363 | 363 | } else { |
| 364 | 364 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
| 365 | 365 | } |
@@ -461,21 +461,21 @@ discard block |
||
| 461 | 461 | break; |
| 462 | 462 | |
| 463 | 463 | default: |
| 464 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 464 | + $classname = 'SmartForm'.ucfirst($controlName).'Element'; |
|
| 465 | 465 | if (!class_exists($classname)) { |
| 466 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 466 | + if (file_exists(SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php')) { |
|
| 467 | 467 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
| 468 | 468 | } else { |
| 469 | 469 | // perhaps this is a control created by the module |
| 470 | 470 | $moduleName = $this->targetObject->handler->_moduleName; |
| 471 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 472 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 473 | - $classFileName = strtolower($classname) . '.php'; |
|
| 471 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath.'class/form/elements/'; |
|
| 472 | + $classname = ucfirst($moduleName).ucfirst($controlName).'Element'; |
|
| 473 | + $classFileName = strtolower($classname).'.php'; |
|
| 474 | 474 | |
| 475 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 475 | + if (file_exists($moduleFormElementsPath.$classFileName)) { |
|
| 476 | 476 | // require_once $moduleFormElementsPath . $classFileName; |
| 477 | 477 | } else { |
| 478 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 478 | + trigger_error($classname.' Not found', E_USER_WARNING); |
|
| 479 | 479 | |
| 480 | 480 | return new \XoopsFormLabel(); //Empty object |
| 481 | 481 | } |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | $editor_configs['height'] = '400px'; |
| 545 | 545 | |
| 546 | 546 | $dhtml = true; |
| 547 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 547 | + $xoopseditorclass = XOOPS_ROOT_PATH.'/class/xoopsform/formeditor.php'; |
|
| 548 | 548 | |
| 549 | 549 | if (file_exists($xoopseditorclass)) { |
| 550 | 550 | require_once $xoopseditorclass; |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | case 'tiny': |
| 556 | 556 | if (!$xoops22) { |
| 557 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 557 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 559 | 559 | $editor = new \XoopsFormTinymce([ |
| 560 | 560 | 'caption' => $caption, |
| 561 | 561 | 'name' => $name, |
@@ -662,10 +662,10 @@ discard block |
||
| 662 | 662 | $size = $multiple ? 5 : 1; |
| 663 | 663 | $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
| 664 | 664 | |
| 665 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 665 | + $handle = opendir(XOOPS_THEME_PATH.'/'); |
|
| 666 | 666 | $dirlist = []; |
| 667 | 667 | while (false !== ($file = readdir($handle))) { |
| 668 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 668 | + if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 669 | 669 | && 'cvs' !== strtolower($file)) { |
| 670 | 670 | $dirlist[$file] = $file; |
| 671 | 671 | } |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | { |
| 688 | 688 | foreach ($this->_elements as $eleObj) { |
| 689 | 689 | if ($eleObj->getName() == $keyname) { |
| 690 | - $ret =& $eleObj; |
|
| 690 | + $ret = & $eleObj; |
|
| 691 | 691 | break; |
| 692 | 692 | } |
| 693 | 693 | } |
@@ -704,9 +704,9 @@ discard block |
||
| 704 | 704 | { |
| 705 | 705 | $required = $this->getRequired(); |
| 706 | 706 | $ret = " |
| 707 | - <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
|
| 707 | + <form name='" . $this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra()."> |
|
| 708 | 708 | <table width='100%' class='outer' cellspacing='1'> |
| 709 | - <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
|
| 709 | + <tr><th colspan='2'>" . $this->getTitle().'</th></tr> |
|
| 710 | 710 | '; |
| 711 | 711 | $hidden = ''; |
| 712 | 712 | $class = 'even'; |
@@ -715,11 +715,11 @@ discard block |
||
| 715 | 715 | $ret .= $ele; |
| 716 | 716 | } elseif (!$ele->isHidden()) { |
| 717 | 717 | //$class = ( $class == 'even' ) ? 'odd': 'even'; |
| 718 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 718 | + $ret .= "<tr id='".$ele->getName()."' valign='top' align='left'><td class='head'>".$ele->getCaption(); |
|
| 719 | 719 | if ('' !== $ele->getDescription()) { |
| 720 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 720 | + $ret .= '<br><br><span style="font-weight: normal;">'.$ele->getDescription().'</span>'; |
|
| 721 | 721 | } |
| 722 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 722 | + $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n"; |
|
| 723 | 723 | } else { |
| 724 | 724 | $hidden .= $ele->render(); |
| 725 | 725 | } |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | 'name' => $this->getName(), |
| 768 | 768 | 'action' => $this->getAction(), |
| 769 | 769 | 'method' => $this->getMethod(), |
| 770 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 770 | + 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), |
|
| 771 | 771 | 'javascript' => $js, |
| 772 | 772 | 'elements' => $elements |
| 773 | 773 | ]); |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | } |
| 786 | 786 | $myts = \MyTextSanitizer::getInstance(); |
| 787 | 787 | $formname = $this->getName(); |
| 788 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 788 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 789 | 789 | // First, output code to check required elements |
| 790 | 790 | $elements = $this->getRequired(); |
| 791 | 791 | foreach ($elements as $elt) { |
@@ -836,15 +836,15 @@ discard block |
||
| 836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 837 | 837 | } |
| 838 | 838 | } else { |
| 839 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 839 | + $js .= "if ( myform.{$eltname}.value == \"\" ) "."{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 840 | 840 | } |
| 841 | 841 | } |
| 842 | 842 | // Now, handle custom validation code |
| 843 | - $elements =& $this->getElements(true); |
|
| 843 | + $elements = & $this->getElements(true); |
|
| 844 | 844 | foreach ($elements as $elt) { |
| 845 | 845 | if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
| 846 | 846 | if ($eltjs = $elt->renderValidationJS()) { |
| 847 | - $js .= $eltjs . "\n"; |
|
| 847 | + $js .= $eltjs."\n"; |
|
| 848 | 848 | } |
| 849 | 849 | } |
| 850 | 850 | } |
@@ -164,7 +164,7 @@ |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | - * @param $field |
|
| 167 | + * @param string $field |
|
| 168 | 168 | * @return bool |
| 169 | 169 | */ |
| 170 | 170 | public function fieldExists($field) |
@@ -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 SmartDbTable |
| 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 smart_TableExists($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 smart_TableExists($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 | } |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
| 40 | 40 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
| 41 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 41 | + require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
| 42 | 42 | } |
| 43 | 43 | /** |
| 44 | 44 | * Include the language constants for the SmartObjectDBUpdater |
| 45 | 45 | */ |
| 46 | 46 | global $xoopsConfig; |
| 47 | -$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
|
| 47 | +$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php'; |
|
| 48 | 48 | if (!file_exists($common_file)) { |
| 49 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 49 | + $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php'; |
|
| 50 | 50 | } |
| 51 | 51 | include $common_file; |
| 52 | 52 | |
@@ -143,20 +143,20 @@ discard block |
||
| 143 | 143 | public function getExistingFieldsArray() |
| 144 | 144 | { |
| 145 | 145 | global $xoopsDB; |
| 146 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 146 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$this->name()); |
|
| 147 | 147 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
| 148 | 148 | $fields[$existing_field['Field']] = $existing_field['Type']; |
| 149 | 149 | if ('YES' !== $existing_field['Null']) { |
| 150 | 150 | $fields[$existing_field['Field']] .= ' NOT NULL'; |
| 151 | 151 | } |
| 152 | 152 | if ($existing_field['Extra']) { |
| 153 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 153 | + $fields[$existing_field['Field']] .= ' '.$existing_field['Extra']; |
|
| 154 | 154 | } |
| 155 | 155 | if (!(null === $existing_field['Default']) |
| 156 | 156 | && ($existing_field['Default'] |
| 157 | 157 | || '' === $existing_field['Default'] |
| 158 | 158 | || 0 == $existing_field['Default'])) { |
| 159 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 159 | + $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'"; |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
@@ -242,9 +242,9 @@ discard block |
||
| 242 | 242 | $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
| 243 | 243 | $ret = $xoopsDB->query($query); |
| 244 | 244 | if (!$ret) { |
| 245 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 245 | + echo ' '.sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()).'<br>'; |
|
| 246 | 246 | } else { |
| 247 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 247 | + echo ' '.sprintf(_SDU_MSG_ADD_DATA, $this->name()).'<br>'; |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | |
@@ -396,13 +396,13 @@ discard block |
||
| 396 | 396 | { |
| 397 | 397 | global $xoopsDB; |
| 398 | 398 | $query = $this->getStructure(); |
| 399 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 399 | + $query = 'CREATE TABLE `'.$this->name().'` ('.$query.") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 400 | 400 | //xoops_debug($query); |
| 401 | 401 | $ret = $xoopsDB->query($query); |
| 402 | 402 | if (!$ret) { |
| 403 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 403 | + echo ' '.sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 404 | 404 | } else { |
| 405 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 405 | + echo ' '.sprintf(_SDU_MSG_CREATE_TABLE, $this->name()).'<br>'; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | return $ret; |
@@ -420,11 +420,11 @@ discard block |
||
| 420 | 420 | $query = sprintf('DROP TABLE %s', $this->name()); |
| 421 | 421 | $ret = $xoopsDB->query($query); |
| 422 | 422 | if (!$ret) { |
| 423 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 423 | + echo ' '.sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 424 | 424 | |
| 425 | 425 | return false; |
| 426 | 426 | } else { |
| 427 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 427 | + echo ' '.sprintf(_SDU_MSG_DROP_TABLE, $this->name()).'<br>'; |
|
| 428 | 428 | |
| 429 | 429 | return true; |
| 430 | 430 | } |
@@ -450,9 +450,9 @@ discard block |
||
| 450 | 450 | $ret = $ret && $xoopsDB->query($query); |
| 451 | 451 | if ($alteredField['showerror']) { |
| 452 | 452 | if (!$ret) { |
| 453 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 453 | + echo ' '.sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 454 | 454 | } else { |
| 455 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 455 | + echo ' '.sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()).'<br>'; |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | } |
@@ -475,9 +475,9 @@ discard block |
||
| 475 | 475 | //echo $query; |
| 476 | 476 | $ret = $ret && $xoopsDB->query($query); |
| 477 | 477 | if (!$ret) { |
| 478 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 478 | + echo ' '.sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()).'<br>'; |
|
| 479 | 479 | } else { |
| 480 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 480 | + echo ' '.sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()).'<br>'; |
|
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | |
@@ -498,9 +498,9 @@ discard block |
||
| 498 | 498 | $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
| 499 | 499 | $ret = $ret && $xoopsDB->query($query); |
| 500 | 500 | if (!$ret) { |
| 501 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 501 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 502 | 502 | } else { |
| 503 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 503 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>'; |
|
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | |
@@ -521,9 +521,9 @@ discard block |
||
| 521 | 521 | //echo $query."<br>"; |
| 522 | 522 | $ret = $ret && $xoopsDB->query($query); |
| 523 | 523 | if (!$ret) { |
| 524 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 524 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 525 | 525 | } else { |
| 526 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 526 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>'; |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | |
@@ -544,9 +544,9 @@ discard block |
||
| 544 | 544 | $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
| 545 | 545 | $ret = $ret && $xoopsDB->query($query); |
| 546 | 546 | if (!$ret) { |
| 547 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 547 | + echo ' '.sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 548 | 548 | } else { |
| 549 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 549 | + echo ' '.sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()).'<br>'; |
|
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | /** |
| 198 | 198 | * @param $val |
| 199 | 199 | * @param $separator |
| 200 | - * @param $trimFunction |
|
| 200 | + * @param false|string $trimFunction |
|
| 201 | 201 | * @return mixed|string |
| 202 | 202 | */ |
| 203 | 203 | public function valToCsvHelper($val, $separator, $trimFunction) |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
| 251 | - * @param $content |
|
| 251 | + * @param string $content |
|
| 252 | 252 | */ |
| 253 | 253 | public function saveExportFile($content) |
| 254 | 254 | { |
@@ -41,186 +41,186 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class SmartExportRenderer |
| 43 | 43 | { |
| 44 | - public $data; |
|
| 45 | - public $format; |
|
| 46 | - public $filename; |
|
| 47 | - public $filepath; |
|
| 48 | - public $options; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Constructor |
|
| 52 | - * |
|
| 53 | - * @param array $data contains the data to be exported |
|
| 54 | - * @param bool|string $filename name of the file in which the exported data will be saved |
|
| 55 | - * @param bool|string $filepath path where the file will be saved |
|
| 56 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 57 | - * @param array $options options of the format to be exported in |
|
| 58 | - */ |
|
| 59 | - public function __construct( |
|
| 60 | - $data, |
|
| 61 | - $filename = false, |
|
| 62 | - $filepath = false, |
|
| 63 | - $format = 'csv', |
|
| 64 | - $options = ['separator' => ';'] |
|
| 65 | - ) { |
|
| 66 | - $this->data = $data; |
|
| 67 | - $this->format = $format; |
|
| 68 | - $this->filename = $filename; |
|
| 69 | - $this->filepath = $filepath; |
|
| 70 | - $this->options = $options; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param $dataArray |
|
| 75 | - * @param $separator |
|
| 76 | - * @param string $trim |
|
| 77 | - * @param bool $removeEmptyLines |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
| 81 | - { |
|
| 82 | - if (!is_array($dataArray) || empty($dataArray)) { |
|
| 83 | - return ''; |
|
| 84 | - } |
|
| 85 | - switch ($trim) { |
|
| 86 | - case 'none': |
|
| 87 | - $trimFunction = false; |
|
| 88 | - break; |
|
| 89 | - case 'left': |
|
| 90 | - $trimFunction = 'ltrim'; |
|
| 91 | - break; |
|
| 92 | - case 'right': |
|
| 93 | - $trimFunction = 'rtrim'; |
|
| 94 | - break; |
|
| 95 | - default: //'both': |
|
| 96 | - $trimFunction = 'trim'; |
|
| 97 | - break; |
|
| 98 | - } |
|
| 99 | - $ret = []; |
|
| 100 | - foreach ($dataArray as $key => $field) { |
|
| 101 | - $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return implode($separator, $ret); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param $val |
|
| 109 | - * @param $separator |
|
| 110 | - * @param $trimFunction |
|
| 111 | - * @return mixed|string |
|
| 112 | - */ |
|
| 113 | - public function valToCsvHelper($val, $separator, $trimFunction) |
|
| 114 | - { |
|
| 115 | - if ($trimFunction) { |
|
| 116 | - $val = $trimFunction($val); |
|
| 117 | - } |
|
| 118 | - //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
| 119 | - $needQuote = false; |
|
| 120 | - do { |
|
| 121 | - if (false !== strpos($val, '"')) { |
|
| 122 | - $val = str_replace('"', '""', $val); |
|
| 123 | - $needQuote = true; |
|
| 124 | - break; |
|
| 125 | - } |
|
| 126 | - if (false !== strpos($val, $separator)) { |
|
| 127 | - $needQuote = true; |
|
| 128 | - break; |
|
| 129 | - } |
|
| 130 | - if ((false !== strpos($val, "\n")) || (false !== strpos($val, "\r"))) { // \r is for mac |
|
| 131 | - $needQuote = true; |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } while (false); |
|
| 135 | - if ($needQuote) { |
|
| 136 | - $val = '"' . $val . '"'; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $val; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - public function execute() |
|
| 143 | - { |
|
| 144 | - $exportFileData = ''; |
|
| 145 | - |
|
| 146 | - switch ($this->format) { |
|
| 147 | - case 'csv': |
|
| 148 | - $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
| 149 | - $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
| 150 | - $exportFileData .= $firstRow . "\r\n"; |
|
| 151 | - |
|
| 152 | - foreach ($this->data['rows'] as $cols) { |
|
| 153 | - $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
| 154 | - } |
|
| 155 | - break; |
|
| 156 | - } |
|
| 157 | - $this->saveExportFile($exportFileData); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param $content |
|
| 162 | - */ |
|
| 163 | - public function saveExportFile($content) |
|
| 164 | - { |
|
| 165 | - switch ($this->format) { |
|
| 166 | - case 'csv': |
|
| 167 | - $this->saveCsv($content); |
|
| 168 | - break; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @param $content |
|
| 174 | - */ |
|
| 175 | - public function saveCsv($content) |
|
| 176 | - { |
|
| 177 | - if (!$this->filepath) { |
|
| 178 | - $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
| 179 | - } |
|
| 180 | - if (!$this->filename) { |
|
| 181 | - $this->filename .= time(); |
|
| 182 | - $this->filename .= '.csv'; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $fullFileName = $this->filepath . $this->filename; |
|
| 186 | - |
|
| 187 | - if (!$handle = fopen($fullFileName, 'a+')) { |
|
| 188 | - trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
| 189 | - } elseif (false === fwrite($handle, $content)) { |
|
| 190 | - trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
| 191 | - } else { |
|
| 192 | - $mimeType = 'text/csv'; |
|
| 193 | - $file = strrev($this->filename); |
|
| 194 | - $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
| 195 | - if ('' === $temp_name) { |
|
| 196 | - $file_name = $this->filename; |
|
| 197 | - } else { |
|
| 198 | - $file_name = $temp_name; |
|
| 199 | - } |
|
| 200 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
| 201 | - |
|
| 202 | - if (ini_get('zlib.output_compression')) { |
|
| 203 | - ini_set('zlib.output_compression', 'Off'); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - header('Pragma: public'); |
|
| 207 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 208 | - header('Cache-Control: private', false); |
|
| 209 | - header('Content-Transfer-Encoding: binary'); |
|
| 210 | - if (isset($mimeType)) { |
|
| 211 | - header('Content-Type: ' . $mimeType); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - header('Content-Disposition: attachment; filename=' . $file_name); |
|
| 215 | - |
|
| 216 | - if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
| 217 | - $fp = fopen($fullFileName, 'r'); |
|
| 218 | - } else { |
|
| 219 | - $fp = fopen($fullFileName, 'rb'); |
|
| 220 | - } |
|
| 221 | - fpassthru($fp); |
|
| 222 | - exit(); |
|
| 223 | - } |
|
| 224 | - fclose($handle); |
|
| 225 | - } |
|
| 44 | + public $data; |
|
| 45 | + public $format; |
|
| 46 | + public $filename; |
|
| 47 | + public $filepath; |
|
| 48 | + public $options; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Constructor |
|
| 52 | + * |
|
| 53 | + * @param array $data contains the data to be exported |
|
| 54 | + * @param bool|string $filename name of the file in which the exported data will be saved |
|
| 55 | + * @param bool|string $filepath path where the file will be saved |
|
| 56 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 57 | + * @param array $options options of the format to be exported in |
|
| 58 | + */ |
|
| 59 | + public function __construct( |
|
| 60 | + $data, |
|
| 61 | + $filename = false, |
|
| 62 | + $filepath = false, |
|
| 63 | + $format = 'csv', |
|
| 64 | + $options = ['separator' => ';'] |
|
| 65 | + ) { |
|
| 66 | + $this->data = $data; |
|
| 67 | + $this->format = $format; |
|
| 68 | + $this->filename = $filename; |
|
| 69 | + $this->filepath = $filepath; |
|
| 70 | + $this->options = $options; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param $dataArray |
|
| 75 | + * @param $separator |
|
| 76 | + * @param string $trim |
|
| 77 | + * @param bool $removeEmptyLines |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
| 81 | + { |
|
| 82 | + if (!is_array($dataArray) || empty($dataArray)) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 85 | + switch ($trim) { |
|
| 86 | + case 'none': |
|
| 87 | + $trimFunction = false; |
|
| 88 | + break; |
|
| 89 | + case 'left': |
|
| 90 | + $trimFunction = 'ltrim'; |
|
| 91 | + break; |
|
| 92 | + case 'right': |
|
| 93 | + $trimFunction = 'rtrim'; |
|
| 94 | + break; |
|
| 95 | + default: //'both': |
|
| 96 | + $trimFunction = 'trim'; |
|
| 97 | + break; |
|
| 98 | + } |
|
| 99 | + $ret = []; |
|
| 100 | + foreach ($dataArray as $key => $field) { |
|
| 101 | + $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return implode($separator, $ret); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param $val |
|
| 109 | + * @param $separator |
|
| 110 | + * @param $trimFunction |
|
| 111 | + * @return mixed|string |
|
| 112 | + */ |
|
| 113 | + public function valToCsvHelper($val, $separator, $trimFunction) |
|
| 114 | + { |
|
| 115 | + if ($trimFunction) { |
|
| 116 | + $val = $trimFunction($val); |
|
| 117 | + } |
|
| 118 | + //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
| 119 | + $needQuote = false; |
|
| 120 | + do { |
|
| 121 | + if (false !== strpos($val, '"')) { |
|
| 122 | + $val = str_replace('"', '""', $val); |
|
| 123 | + $needQuote = true; |
|
| 124 | + break; |
|
| 125 | + } |
|
| 126 | + if (false !== strpos($val, $separator)) { |
|
| 127 | + $needQuote = true; |
|
| 128 | + break; |
|
| 129 | + } |
|
| 130 | + if ((false !== strpos($val, "\n")) || (false !== strpos($val, "\r"))) { // \r is for mac |
|
| 131 | + $needQuote = true; |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } while (false); |
|
| 135 | + if ($needQuote) { |
|
| 136 | + $val = '"' . $val . '"'; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $val; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + public function execute() |
|
| 143 | + { |
|
| 144 | + $exportFileData = ''; |
|
| 145 | + |
|
| 146 | + switch ($this->format) { |
|
| 147 | + case 'csv': |
|
| 148 | + $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
| 149 | + $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
| 150 | + $exportFileData .= $firstRow . "\r\n"; |
|
| 151 | + |
|
| 152 | + foreach ($this->data['rows'] as $cols) { |
|
| 153 | + $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
| 154 | + } |
|
| 155 | + break; |
|
| 156 | + } |
|
| 157 | + $this->saveExportFile($exportFileData); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param $content |
|
| 162 | + */ |
|
| 163 | + public function saveExportFile($content) |
|
| 164 | + { |
|
| 165 | + switch ($this->format) { |
|
| 166 | + case 'csv': |
|
| 167 | + $this->saveCsv($content); |
|
| 168 | + break; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @param $content |
|
| 174 | + */ |
|
| 175 | + public function saveCsv($content) |
|
| 176 | + { |
|
| 177 | + if (!$this->filepath) { |
|
| 178 | + $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
| 179 | + } |
|
| 180 | + if (!$this->filename) { |
|
| 181 | + $this->filename .= time(); |
|
| 182 | + $this->filename .= '.csv'; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $fullFileName = $this->filepath . $this->filename; |
|
| 186 | + |
|
| 187 | + if (!$handle = fopen($fullFileName, 'a+')) { |
|
| 188 | + trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
| 189 | + } elseif (false === fwrite($handle, $content)) { |
|
| 190 | + trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
| 191 | + } else { |
|
| 192 | + $mimeType = 'text/csv'; |
|
| 193 | + $file = strrev($this->filename); |
|
| 194 | + $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
| 195 | + if ('' === $temp_name) { |
|
| 196 | + $file_name = $this->filename; |
|
| 197 | + } else { |
|
| 198 | + $file_name = $temp_name; |
|
| 199 | + } |
|
| 200 | + $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
| 201 | + |
|
| 202 | + if (ini_get('zlib.output_compression')) { |
|
| 203 | + ini_set('zlib.output_compression', 'Off'); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + header('Pragma: public'); |
|
| 207 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 208 | + header('Cache-Control: private', false); |
|
| 209 | + header('Content-Transfer-Encoding: binary'); |
|
| 210 | + if (isset($mimeType)) { |
|
| 211 | + header('Content-Type: ' . $mimeType); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + header('Content-Disposition: attachment; filename=' . $file_name); |
|
| 215 | + |
|
| 216 | + if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
| 217 | + $fp = fopen($fullFileName, 'r'); |
|
| 218 | + } else { |
|
| 219 | + $fp = fopen($fullFileName, 'rb'); |
|
| 220 | + } |
|
| 221 | + fpassthru($fp); |
|
| 222 | + exit(); |
|
| 223 | + } |
|
| 224 | + fclose($handle); |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | } while (false); |
| 238 | 238 | if ($needQuote) { |
| 239 | - $val = '"' . $val . '"'; |
|
| 239 | + $val = '"'.$val.'"'; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | return $val; |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | case 'csv': |
| 251 | 251 | $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
| 252 | 252 | $firstRow = implode($separator, $this->data['columnsHeaders']); |
| 253 | - $exportFileData .= $firstRow . "\r\n"; |
|
| 253 | + $exportFileData .= $firstRow."\r\n"; |
|
| 254 | 254 | |
| 255 | 255 | foreach ($this->data['rows'] as $cols) { |
| 256 | - $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
| 256 | + $exportFileData .= $this->arrayToCsvString($cols, $separator)."\r\n"; |
|
| 257 | 257 | } |
| 258 | 258 | break; |
| 259 | 259 | } |
@@ -278,19 +278,19 @@ discard block |
||
| 278 | 278 | public function saveCsv($content) |
| 279 | 279 | { |
| 280 | 280 | if (!$this->filepath) { |
| 281 | - $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
| 281 | + $this->filepath = XOOPS_UPLOAD_PATH.'/'; |
|
| 282 | 282 | } |
| 283 | 283 | if (!$this->filename) { |
| 284 | 284 | $this->filename .= time(); |
| 285 | 285 | $this->filename .= '.csv'; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $fullFileName = $this->filepath . $this->filename; |
|
| 288 | + $fullFileName = $this->filepath.$this->filename; |
|
| 289 | 289 | |
| 290 | 290 | if (!$handle = fopen($fullFileName, 'a+')) { |
| 291 | - trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
| 291 | + trigger_error('Unable to open '.$fullFileName, E_USER_WARNING); |
|
| 292 | 292 | } elseif (false === fwrite($handle, $content)) { |
| 293 | - trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
| 293 | + trigger_error('Unable to write in '.$fullFileName, E_USER_WARNING); |
|
| 294 | 294 | } else { |
| 295 | 295 | $mimeType = 'text/csv'; |
| 296 | 296 | $file = strrev($this->filename); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | } else { |
| 301 | 301 | $file_name = $temp_name; |
| 302 | 302 | } |
| 303 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
| 303 | + $fullFileName = $this->filepath.stripslashes(trim($this->filename)); |
|
| 304 | 304 | |
| 305 | 305 | if (ini_get('zlib.output_compression')) { |
| 306 | 306 | ini_set('zlib.output_compression', 'Off'); |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | header('Cache-Control: private', false); |
| 312 | 312 | header('Content-Transfer-Encoding: binary'); |
| 313 | 313 | if (isset($mimeType)) { |
| 314 | - header('Content-Type: ' . $mimeType); |
|
| 314 | + header('Content-Type: '.$mimeType); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - header('Content-Disposition: attachment; filename=' . $file_name); |
|
| 317 | + header('Content-Disposition: attachment; filename='.$file_name); |
|
| 318 | 318 | |
| 319 | 319 | if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
| 320 | 320 | $fp = fopen($fullFileName, 'r'); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | - * @param $keywords |
|
| 168 | + * @param string|boolean $keywords |
|
| 169 | 169 | */ |
| 170 | 170 | public function setKeywords($keywords) |
| 171 | 171 | { |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | - * @param $categoryPath |
|
| 176 | + * @param boolean $categoryPath |
|
| 177 | 177 | */ |
| 178 | 178 | public function setCategoryPath($categoryPath) |
| 179 | 179 | { |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * @param $description |
|
| 185 | + * @param boolean $description |
|
| 186 | 186 | */ |
| 187 | 187 | public function setDescription($description) |
| 188 | 188 | { |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * @param $text |
|
| 246 | - * @param $minChar |
|
| 245 | + * @param string $text |
|
| 246 | + * @param integer $minChar |
|
| 247 | 247 | * @return array |
| 248 | 248 | */ |
| 249 | 249 | public function findMetaKeywords($text, $minChar) |
@@ -20,350 +20,350 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class SmartMetaGen |
| 22 | 22 | { |
| 23 | - public $_myts; |
|
| 24 | - |
|
| 25 | - public $_title; |
|
| 26 | - public $_original_title; |
|
| 27 | - public $_keywords; |
|
| 28 | - public $_meta_description; |
|
| 29 | - public $_categoryPath; |
|
| 30 | - public $_description; |
|
| 31 | - public $_minChar = 4; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * SmartMetaGen constructor. |
|
| 35 | - * @param $title |
|
| 36 | - * @param bool $keywords |
|
| 37 | - * @param bool $description |
|
| 38 | - * @param bool $categoryPath |
|
| 39 | - */ |
|
| 40 | - public function __construct($title, $keywords = false, $description = false, $categoryPath = false) |
|
| 41 | - { |
|
| 42 | - $this->_myts = \MyTextSanitizer::getInstance(); |
|
| 43 | - $this->setCategoryPath($categoryPath); |
|
| 44 | - $this->setTitle($title); |
|
| 45 | - $this->setDescription($description); |
|
| 46 | - |
|
| 47 | - if (!$keywords) { |
|
| 48 | - $keywords = $this->createMetaKeywords(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /* $myts = \MyTextSanitizer::getInstance(); |
|
| 23 | + public $_myts; |
|
| 24 | + |
|
| 25 | + public $_title; |
|
| 26 | + public $_original_title; |
|
| 27 | + public $_keywords; |
|
| 28 | + public $_meta_description; |
|
| 29 | + public $_categoryPath; |
|
| 30 | + public $_description; |
|
| 31 | + public $_minChar = 4; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * SmartMetaGen constructor. |
|
| 35 | + * @param $title |
|
| 36 | + * @param bool $keywords |
|
| 37 | + * @param bool $description |
|
| 38 | + * @param bool $categoryPath |
|
| 39 | + */ |
|
| 40 | + public function __construct($title, $keywords = false, $description = false, $categoryPath = false) |
|
| 41 | + { |
|
| 42 | + $this->_myts = \MyTextSanitizer::getInstance(); |
|
| 43 | + $this->setCategoryPath($categoryPath); |
|
| 44 | + $this->setTitle($title); |
|
| 45 | + $this->setDescription($description); |
|
| 46 | + |
|
| 47 | + if (!$keywords) { |
|
| 48 | + $keywords = $this->createMetaKeywords(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /* $myts = \MyTextSanitizer::getInstance(); |
|
| 52 | 52 | if (method_exists($myts, 'formatForML')) { |
| 53 | 53 | $keywords = $myts->formatForML($keywords); |
| 54 | 54 | $description = $myts->formatForML($description); |
| 55 | 55 | } |
| 56 | 56 | */ |
| 57 | - $this->setKeywords($keywords); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Return true if the string is length > 0 |
|
| 62 | - * |
|
| 63 | - * @credit psylove |
|
| 64 | - * |
|
| 65 | - * @var string $string Chaine de caract�re |
|
| 66 | - * @return boolean |
|
| 67 | - */ |
|
| 68 | - public function emptyString($var) |
|
| 69 | - { |
|
| 70 | - return (strlen($var) > 0); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Create a title for the short_url field of an article |
|
| 75 | - * |
|
| 76 | - * @credit psylove |
|
| 77 | - * |
|
| 78 | - * @var string $title title of the article |
|
| 79 | - * @param bool|string $withExt |
|
| 80 | - * @return string sort_url for the article |
|
| 81 | - */ |
|
| 82 | - public function generateSeoTitle($title = '', $withExt = true) |
|
| 83 | - { |
|
| 84 | - // Transformation de la chaine en minuscule |
|
| 85 | - // Codage de la chaine afin d'éviter les erreurs 500 en cas de caractères imprévus |
|
| 86 | - $title = rawurlencode(strtolower($title)); |
|
| 87 | - |
|
| 88 | - // Transformation des ponctuations |
|
| 89 | - $pattern = [ |
|
| 90 | - '/%09/', // Tab |
|
| 91 | - '/%20/', // Space |
|
| 92 | - '/%21/', // ! |
|
| 93 | - '/%22/', // " |
|
| 94 | - '/%23/', // # |
|
| 95 | - '/%25/', // % |
|
| 96 | - '/%26/', // & |
|
| 97 | - '/%27/', // ' |
|
| 98 | - '/%28/', // ( |
|
| 99 | - '/%29/', // ) |
|
| 100 | - '/%2C/', // , |
|
| 101 | - '/%2F/', // / |
|
| 102 | - '/%3A/', // : |
|
| 103 | - '/%3B/', // ; |
|
| 104 | - '/%3C/', // < |
|
| 105 | - '/%3D/', // = |
|
| 106 | - '/%3E/', // > |
|
| 107 | - '/%3F/', // ? |
|
| 108 | - '/%40/', // @ |
|
| 109 | - '/%5B/', // [ |
|
| 110 | - '/%5C/', // \ |
|
| 111 | - '/%5D/', // ] |
|
| 112 | - '/%5E/', // ^ |
|
| 113 | - '/%7B/', // { |
|
| 114 | - '/%7C/', // | |
|
| 115 | - '/%7D/', // } |
|
| 116 | - '/%7E/', // ~ |
|
| 117 | - "/\./" // . |
|
| 118 | - ]; |
|
| 119 | - $rep_pat = [ |
|
| 120 | - '-', |
|
| 121 | - '-', |
|
| 122 | - '-', |
|
| 123 | - '-', |
|
| 124 | - '-', |
|
| 125 | - '-100', |
|
| 126 | - '-', |
|
| 127 | - '-', |
|
| 128 | - '-', |
|
| 129 | - '-', |
|
| 130 | - '-', |
|
| 131 | - '-', |
|
| 132 | - '-', |
|
| 133 | - '-', |
|
| 134 | - '-', |
|
| 135 | - '-', |
|
| 136 | - '-', |
|
| 137 | - '-', |
|
| 138 | - '-at-', |
|
| 139 | - '-', |
|
| 140 | - '-', |
|
| 141 | - '-', |
|
| 142 | - '-', |
|
| 143 | - '-', |
|
| 144 | - '-', |
|
| 145 | - '-', |
|
| 146 | - '-', |
|
| 147 | - '-' |
|
| 148 | - ]; |
|
| 149 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 150 | - |
|
| 151 | - // Transformation des caractères accentués |
|
| 152 | - $pattern = [ |
|
| 153 | - '/%B0/', // ° |
|
| 154 | - '/%E8/', // è |
|
| 155 | - '/%E9/', // é |
|
| 156 | - '/%EA/', // ê |
|
| 157 | - '/%EB/', // ë |
|
| 158 | - '/%E7/', // ç |
|
| 159 | - '/%E0/', // à |
|
| 160 | - '/%E2/', // â |
|
| 161 | - '/%E4/', // ä |
|
| 162 | - '/%EE/', // î |
|
| 163 | - '/%EF/', // ï |
|
| 164 | - '/%F9/', // ù |
|
| 165 | - '/%FC/', // ü |
|
| 166 | - '/%FB/', // û |
|
| 167 | - '/%F4/', // ô |
|
| 168 | - '/%F6/', // ö |
|
| 169 | - ]; |
|
| 170 | - $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 171 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 172 | - |
|
| 173 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 174 | - $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 175 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 176 | - |
|
| 177 | - if (count($title) > 0) { |
|
| 178 | - if ($withExt) { |
|
| 179 | - $title .= '.html'; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return $title; |
|
| 183 | - } else { |
|
| 184 | - return ''; |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param $document |
|
| 190 | - * @return mixed |
|
| 191 | - */ |
|
| 192 | - public function html2text($document) |
|
| 193 | - { |
|
| 194 | - return smart_html2text($document); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param $title |
|
| 199 | - */ |
|
| 200 | - public function setTitle($title) |
|
| 201 | - { |
|
| 202 | - global $xoopsModule, $xoopsModuleConfig; |
|
| 203 | - $this->_title = $this->html2text($title); |
|
| 204 | - $this->_title = $this->purifyText($this->_title); |
|
| 205 | - $this->_original_title = $this->_title; |
|
| 206 | - |
|
| 207 | - $moduleName = $xoopsModule->getVar('name'); |
|
| 208 | - |
|
| 209 | - $titleTag = []; |
|
| 210 | - |
|
| 211 | - $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true; |
|
| 212 | - |
|
| 213 | - if ($moduleName && $show_mod_name_breadcrumb) { |
|
| 214 | - $titleTag['module'] = $moduleName; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - if (isset($this->_title) && ('' !== $this->_title) && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
| 218 | - $titleTag['title'] = $this->_title; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - if (isset($this->_categoryPath) && ('' !== $this->_categoryPath)) { |
|
| 222 | - $titleTag['category'] = $this->_categoryPath; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
| 226 | - |
|
| 227 | - if (isset($titleTag['category']) && '' !== $titleTag['category']) { |
|
| 228 | - if ('' !== $ret) { |
|
| 229 | - $ret .= ' - '; |
|
| 230 | - } |
|
| 231 | - $ret .= $titleTag['category']; |
|
| 232 | - } |
|
| 233 | - if (isset($titleTag['module']) && '' !== $titleTag['module']) { |
|
| 234 | - if ('' !== $ret) { |
|
| 235 | - $ret .= ' - '; |
|
| 236 | - } |
|
| 237 | - $ret .= $titleTag['module']; |
|
| 238 | - } |
|
| 239 | - $this->_title = $ret; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param $keywords |
|
| 244 | - */ |
|
| 245 | - public function setKeywords($keywords) |
|
| 246 | - { |
|
| 247 | - $this->_keywords = $keywords; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param $categoryPath |
|
| 252 | - */ |
|
| 253 | - public function setCategoryPath($categoryPath) |
|
| 254 | - { |
|
| 255 | - $categoryPath = $this->html2text($categoryPath); |
|
| 256 | - $this->_categoryPath = $categoryPath; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @param $description |
|
| 261 | - */ |
|
| 262 | - public function setDescription($description) |
|
| 263 | - { |
|
| 264 | - if (!$description) { |
|
| 265 | - global $xoopsModuleConfig; |
|
| 266 | - if (isset($xoopsModuleConfig['module_meta_description'])) { |
|
| 267 | - $description = $xoopsModuleConfig['module_meta_description']; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - $description = $this->html2text($description); |
|
| 272 | - $description = $this->purifyText($description); |
|
| 273 | - |
|
| 274 | - $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
| 275 | - $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
| 276 | - $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
| 277 | - $description = stripslashes($description); |
|
| 278 | - |
|
| 279 | - $this->_description = $description; |
|
| 280 | - $this->_meta_description = $this->createMetaDescription(); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - public function createTitleTag() |
|
| 284 | - { |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @param $text |
|
| 289 | - * @param bool $keyword |
|
| 290 | - * @return mixed|string |
|
| 291 | - */ |
|
| 292 | - public function purifyText($text, $keyword = false) |
|
| 293 | - { |
|
| 294 | - return smart_purifyText($text, $keyword); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @param int $maxWords |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 301 | - public function createMetaDescription($maxWords = 100) |
|
| 302 | - { |
|
| 303 | - $words = []; |
|
| 304 | - $words = explode(' ', $this->_description); |
|
| 305 | - |
|
| 306 | - // Only keep $maxWords words |
|
| 307 | - $newWords = []; |
|
| 308 | - $i = 0; |
|
| 309 | - |
|
| 310 | - while ($i < $maxWords - 1 && $i < count($words)) { |
|
| 311 | - $newWords[] = $words[$i]; |
|
| 312 | - ++$i; |
|
| 313 | - } |
|
| 314 | - $ret = implode(' ', $newWords); |
|
| 315 | - |
|
| 316 | - return $ret; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @param $text |
|
| 321 | - * @param $minChar |
|
| 322 | - * @return array |
|
| 323 | - */ |
|
| 324 | - public function findMetaKeywords($text, $minChar) |
|
| 325 | - { |
|
| 326 | - $keywords = []; |
|
| 327 | - |
|
| 328 | - $text = $this->purifyText($text); |
|
| 329 | - $text = $this->html2text($text); |
|
| 330 | - |
|
| 331 | - $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
| 332 | - $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
| 333 | - $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
| 334 | - $text = stripslashes($text); |
|
| 335 | - $text = |
|
| 336 | - |
|
| 337 | - $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 338 | - |
|
| 339 | - foreach ($originalKeywords as $originalKeyword) { |
|
| 340 | - $secondRoundKeywords = explode("'", $originalKeyword); |
|
| 341 | - foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
| 342 | - if (strlen($secondRoundKeyword) >= $minChar) { |
|
| 343 | - if (!in_array($secondRoundKeyword, $keywords)) { |
|
| 344 | - $keywords[] = trim($secondRoundKeyword); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return $keywords; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @return string |
|
| 355 | - */ |
|
| 356 | - public function createMetaKeywords() |
|
| 357 | - { |
|
| 358 | - global $xoopsModuleConfig; |
|
| 359 | - $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
| 360 | - if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) |
|
| 361 | - && '' !== $xoopsModuleConfig['moduleMetaKeywords']) { |
|
| 362 | - $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
|
| 363 | - $keywords = array_merge($keywords, $moduleKeywords); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /* Commenting this out as it may cause problem on XOOPS ML websites |
|
| 57 | + $this->setKeywords($keywords); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Return true if the string is length > 0 |
|
| 62 | + * |
|
| 63 | + * @credit psylove |
|
| 64 | + * |
|
| 65 | + * @var string $string Chaine de caract�re |
|
| 66 | + * @return boolean |
|
| 67 | + */ |
|
| 68 | + public function emptyString($var) |
|
| 69 | + { |
|
| 70 | + return (strlen($var) > 0); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Create a title for the short_url field of an article |
|
| 75 | + * |
|
| 76 | + * @credit psylove |
|
| 77 | + * |
|
| 78 | + * @var string $title title of the article |
|
| 79 | + * @param bool|string $withExt |
|
| 80 | + * @return string sort_url for the article |
|
| 81 | + */ |
|
| 82 | + public function generateSeoTitle($title = '', $withExt = true) |
|
| 83 | + { |
|
| 84 | + // Transformation de la chaine en minuscule |
|
| 85 | + // Codage de la chaine afin d'éviter les erreurs 500 en cas de caractères imprévus |
|
| 86 | + $title = rawurlencode(strtolower($title)); |
|
| 87 | + |
|
| 88 | + // Transformation des ponctuations |
|
| 89 | + $pattern = [ |
|
| 90 | + '/%09/', // Tab |
|
| 91 | + '/%20/', // Space |
|
| 92 | + '/%21/', // ! |
|
| 93 | + '/%22/', // " |
|
| 94 | + '/%23/', // # |
|
| 95 | + '/%25/', // % |
|
| 96 | + '/%26/', // & |
|
| 97 | + '/%27/', // ' |
|
| 98 | + '/%28/', // ( |
|
| 99 | + '/%29/', // ) |
|
| 100 | + '/%2C/', // , |
|
| 101 | + '/%2F/', // / |
|
| 102 | + '/%3A/', // : |
|
| 103 | + '/%3B/', // ; |
|
| 104 | + '/%3C/', // < |
|
| 105 | + '/%3D/', // = |
|
| 106 | + '/%3E/', // > |
|
| 107 | + '/%3F/', // ? |
|
| 108 | + '/%40/', // @ |
|
| 109 | + '/%5B/', // [ |
|
| 110 | + '/%5C/', // \ |
|
| 111 | + '/%5D/', // ] |
|
| 112 | + '/%5E/', // ^ |
|
| 113 | + '/%7B/', // { |
|
| 114 | + '/%7C/', // | |
|
| 115 | + '/%7D/', // } |
|
| 116 | + '/%7E/', // ~ |
|
| 117 | + "/\./" // . |
|
| 118 | + ]; |
|
| 119 | + $rep_pat = [ |
|
| 120 | + '-', |
|
| 121 | + '-', |
|
| 122 | + '-', |
|
| 123 | + '-', |
|
| 124 | + '-', |
|
| 125 | + '-100', |
|
| 126 | + '-', |
|
| 127 | + '-', |
|
| 128 | + '-', |
|
| 129 | + '-', |
|
| 130 | + '-', |
|
| 131 | + '-', |
|
| 132 | + '-', |
|
| 133 | + '-', |
|
| 134 | + '-', |
|
| 135 | + '-', |
|
| 136 | + '-', |
|
| 137 | + '-', |
|
| 138 | + '-at-', |
|
| 139 | + '-', |
|
| 140 | + '-', |
|
| 141 | + '-', |
|
| 142 | + '-', |
|
| 143 | + '-', |
|
| 144 | + '-', |
|
| 145 | + '-', |
|
| 146 | + '-', |
|
| 147 | + '-' |
|
| 148 | + ]; |
|
| 149 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 150 | + |
|
| 151 | + // Transformation des caractères accentués |
|
| 152 | + $pattern = [ |
|
| 153 | + '/%B0/', // ° |
|
| 154 | + '/%E8/', // è |
|
| 155 | + '/%E9/', // é |
|
| 156 | + '/%EA/', // ê |
|
| 157 | + '/%EB/', // ë |
|
| 158 | + '/%E7/', // ç |
|
| 159 | + '/%E0/', // à |
|
| 160 | + '/%E2/', // â |
|
| 161 | + '/%E4/', // ä |
|
| 162 | + '/%EE/', // î |
|
| 163 | + '/%EF/', // ï |
|
| 164 | + '/%F9/', // ù |
|
| 165 | + '/%FC/', // ü |
|
| 166 | + '/%FB/', // û |
|
| 167 | + '/%F4/', // ô |
|
| 168 | + '/%F6/', // ö |
|
| 169 | + ]; |
|
| 170 | + $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 171 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 172 | + |
|
| 173 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 174 | + $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 175 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 176 | + |
|
| 177 | + if (count($title) > 0) { |
|
| 178 | + if ($withExt) { |
|
| 179 | + $title .= '.html'; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return $title; |
|
| 183 | + } else { |
|
| 184 | + return ''; |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param $document |
|
| 190 | + * @return mixed |
|
| 191 | + */ |
|
| 192 | + public function html2text($document) |
|
| 193 | + { |
|
| 194 | + return smart_html2text($document); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param $title |
|
| 199 | + */ |
|
| 200 | + public function setTitle($title) |
|
| 201 | + { |
|
| 202 | + global $xoopsModule, $xoopsModuleConfig; |
|
| 203 | + $this->_title = $this->html2text($title); |
|
| 204 | + $this->_title = $this->purifyText($this->_title); |
|
| 205 | + $this->_original_title = $this->_title; |
|
| 206 | + |
|
| 207 | + $moduleName = $xoopsModule->getVar('name'); |
|
| 208 | + |
|
| 209 | + $titleTag = []; |
|
| 210 | + |
|
| 211 | + $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true; |
|
| 212 | + |
|
| 213 | + if ($moduleName && $show_mod_name_breadcrumb) { |
|
| 214 | + $titleTag['module'] = $moduleName; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + if (isset($this->_title) && ('' !== $this->_title) && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
| 218 | + $titleTag['title'] = $this->_title; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + if (isset($this->_categoryPath) && ('' !== $this->_categoryPath)) { |
|
| 222 | + $titleTag['category'] = $this->_categoryPath; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
| 226 | + |
|
| 227 | + if (isset($titleTag['category']) && '' !== $titleTag['category']) { |
|
| 228 | + if ('' !== $ret) { |
|
| 229 | + $ret .= ' - '; |
|
| 230 | + } |
|
| 231 | + $ret .= $titleTag['category']; |
|
| 232 | + } |
|
| 233 | + if (isset($titleTag['module']) && '' !== $titleTag['module']) { |
|
| 234 | + if ('' !== $ret) { |
|
| 235 | + $ret .= ' - '; |
|
| 236 | + } |
|
| 237 | + $ret .= $titleTag['module']; |
|
| 238 | + } |
|
| 239 | + $this->_title = $ret; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param $keywords |
|
| 244 | + */ |
|
| 245 | + public function setKeywords($keywords) |
|
| 246 | + { |
|
| 247 | + $this->_keywords = $keywords; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param $categoryPath |
|
| 252 | + */ |
|
| 253 | + public function setCategoryPath($categoryPath) |
|
| 254 | + { |
|
| 255 | + $categoryPath = $this->html2text($categoryPath); |
|
| 256 | + $this->_categoryPath = $categoryPath; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @param $description |
|
| 261 | + */ |
|
| 262 | + public function setDescription($description) |
|
| 263 | + { |
|
| 264 | + if (!$description) { |
|
| 265 | + global $xoopsModuleConfig; |
|
| 266 | + if (isset($xoopsModuleConfig['module_meta_description'])) { |
|
| 267 | + $description = $xoopsModuleConfig['module_meta_description']; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + $description = $this->html2text($description); |
|
| 272 | + $description = $this->purifyText($description); |
|
| 273 | + |
|
| 274 | + $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
| 275 | + $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
| 276 | + $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
| 277 | + $description = stripslashes($description); |
|
| 278 | + |
|
| 279 | + $this->_description = $description; |
|
| 280 | + $this->_meta_description = $this->createMetaDescription(); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + public function createTitleTag() |
|
| 284 | + { |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @param $text |
|
| 289 | + * @param bool $keyword |
|
| 290 | + * @return mixed|string |
|
| 291 | + */ |
|
| 292 | + public function purifyText($text, $keyword = false) |
|
| 293 | + { |
|
| 294 | + return smart_purifyText($text, $keyword); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @param int $maxWords |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | + public function createMetaDescription($maxWords = 100) |
|
| 302 | + { |
|
| 303 | + $words = []; |
|
| 304 | + $words = explode(' ', $this->_description); |
|
| 305 | + |
|
| 306 | + // Only keep $maxWords words |
|
| 307 | + $newWords = []; |
|
| 308 | + $i = 0; |
|
| 309 | + |
|
| 310 | + while ($i < $maxWords - 1 && $i < count($words)) { |
|
| 311 | + $newWords[] = $words[$i]; |
|
| 312 | + ++$i; |
|
| 313 | + } |
|
| 314 | + $ret = implode(' ', $newWords); |
|
| 315 | + |
|
| 316 | + return $ret; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * @param $text |
|
| 321 | + * @param $minChar |
|
| 322 | + * @return array |
|
| 323 | + */ |
|
| 324 | + public function findMetaKeywords($text, $minChar) |
|
| 325 | + { |
|
| 326 | + $keywords = []; |
|
| 327 | + |
|
| 328 | + $text = $this->purifyText($text); |
|
| 329 | + $text = $this->html2text($text); |
|
| 330 | + |
|
| 331 | + $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
| 332 | + $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
| 333 | + $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
| 334 | + $text = stripslashes($text); |
|
| 335 | + $text = |
|
| 336 | + |
|
| 337 | + $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 338 | + |
|
| 339 | + foreach ($originalKeywords as $originalKeyword) { |
|
| 340 | + $secondRoundKeywords = explode("'", $originalKeyword); |
|
| 341 | + foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
| 342 | + if (strlen($secondRoundKeyword) >= $minChar) { |
|
| 343 | + if (!in_array($secondRoundKeyword, $keywords)) { |
|
| 344 | + $keywords[] = trim($secondRoundKeyword); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return $keywords; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @return string |
|
| 355 | + */ |
|
| 356 | + public function createMetaKeywords() |
|
| 357 | + { |
|
| 358 | + global $xoopsModuleConfig; |
|
| 359 | + $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
| 360 | + if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) |
|
| 361 | + && '' !== $xoopsModuleConfig['moduleMetaKeywords']) { |
|
| 362 | + $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
|
| 363 | + $keywords = array_merge($keywords, $moduleKeywords); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /* Commenting this out as it may cause problem on XOOPS ML websites |
|
| 367 | 367 | $return_keywords = array(); |
| 368 | 368 | |
| 369 | 369 | // Cleaning for duplicate keywords |
@@ -373,43 +373,43 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | }*/ |
| 375 | 375 | |
| 376 | - // Only take the first 90 keywords |
|
| 377 | - $newKeywords = []; |
|
| 378 | - $i = 0; |
|
| 379 | - while ($i < 90 - 1 && isset($keywords[$i])) { |
|
| 380 | - $newKeywords[] = $keywords[$i]; |
|
| 381 | - ++$i; |
|
| 382 | - } |
|
| 383 | - $ret = implode(', ', $newKeywords); |
|
| 384 | - |
|
| 385 | - return $ret; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - public function autoBuildMeta_keywords() |
|
| 389 | - { |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - public function buildAutoMetaTags() |
|
| 393 | - { |
|
| 394 | - global $xoopsModule, $xoopsModuleConfig; |
|
| 395 | - |
|
| 396 | - $this->_keywords = $this->createMetaKeywords(); |
|
| 397 | - $this->_meta_description = $this->createMetaDescription(); |
|
| 398 | - $this->_title = $this->createTitleTag(); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - public function createMetaTags() |
|
| 402 | - { |
|
| 403 | - global $xoopsTpl, $xoTheme; |
|
| 404 | - |
|
| 405 | - if (is_object($xoTheme)) { |
|
| 406 | - $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
| 407 | - $xoTheme->addMeta('meta', 'description', $this->_description); |
|
| 408 | - $xoTheme->addMeta('meta', 'title', $this->_title); |
|
| 409 | - } else { |
|
| 410 | - $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
| 411 | - $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
| 412 | - } |
|
| 413 | - $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
| 414 | - } |
|
| 376 | + // Only take the first 90 keywords |
|
| 377 | + $newKeywords = []; |
|
| 378 | + $i = 0; |
|
| 379 | + while ($i < 90 - 1 && isset($keywords[$i])) { |
|
| 380 | + $newKeywords[] = $keywords[$i]; |
|
| 381 | + ++$i; |
|
| 382 | + } |
|
| 383 | + $ret = implode(', ', $newKeywords); |
|
| 384 | + |
|
| 385 | + return $ret; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + public function autoBuildMeta_keywords() |
|
| 389 | + { |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + public function buildAutoMetaTags() |
|
| 393 | + { |
|
| 394 | + global $xoopsModule, $xoopsModuleConfig; |
|
| 395 | + |
|
| 396 | + $this->_keywords = $this->createMetaKeywords(); |
|
| 397 | + $this->_meta_description = $this->createMetaDescription(); |
|
| 398 | + $this->_title = $this->createTitleTag(); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + public function createMetaTags() |
|
| 402 | + { |
|
| 403 | + global $xoopsTpl, $xoTheme; |
|
| 404 | + |
|
| 405 | + if (is_object($xoTheme)) { |
|
| 406 | + $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
| 407 | + $xoTheme->addMeta('meta', 'description', $this->_description); |
|
| 408 | + $xoTheme->addMeta('meta', 'title', $this->_title); |
|
| 409 | + } else { |
|
| 410 | + $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
| 411 | + $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
| 412 | + } |
|
| 413 | + $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
| 414 | + } |
|
| 415 | 415 | } |
@@ -354,7 +354,7 @@ |
||
| 354 | 354 | public function createMetaKeywords() |
| 355 | 355 | { |
| 356 | 356 | global $xoopsModuleConfig; |
| 357 | - $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
| 357 | + $keywords = $this->findMetaKeywords($this->_original_title.' '.$this->_description, $this->_minChar); |
|
| 358 | 358 | if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) |
| 359 | 359 | && '' !== $xoopsModuleConfig['moduleMetaKeywords']) { |
| 360 | 360 | $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * SmartObjectColumn constructor. |
| 36 | - * @param $keyname |
|
| 36 | + * @param string $keyname |
|
| 37 | 37 | * @param string $align |
| 38 | 38 | * @param bool $width |
| 39 | 39 | * @param bool $customMethodForValue |
@@ -23,82 +23,82 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class SmartObjectColumn |
| 25 | 25 | { |
| 26 | - public $_keyname; |
|
| 27 | - public $_align; |
|
| 28 | - public $_width; |
|
| 29 | - public $_customMethodForValue; |
|
| 30 | - public $_extraParams; |
|
| 31 | - public $_sortable; |
|
| 32 | - public $_customCaption; |
|
| 26 | + public $_keyname; |
|
| 27 | + public $_align; |
|
| 28 | + public $_width; |
|
| 29 | + public $_customMethodForValue; |
|
| 30 | + public $_extraParams; |
|
| 31 | + public $_sortable; |
|
| 32 | + public $_customCaption; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * SmartObjectColumn constructor. |
|
| 36 | - * @param $keyname |
|
| 37 | - * @param string $align |
|
| 38 | - * @param bool $width |
|
| 39 | - * @param bool $customMethodForValue |
|
| 40 | - * @param bool $param |
|
| 41 | - * @param bool $customCaption |
|
| 42 | - * @param bool $sortable |
|
| 43 | - */ |
|
| 44 | - public function __construct( |
|
| 45 | - $keyname, |
|
| 46 | - $align = 'left', |
|
| 47 | - $width = false, |
|
| 48 | - $customMethodForValue = false, |
|
| 49 | - $param = false, |
|
| 50 | - $customCaption = false, |
|
| 51 | - $sortable = true |
|
| 52 | - ) { |
|
| 53 | - $this->_keyname = $keyname; |
|
| 54 | - $this->_align = $align; |
|
| 55 | - $this->_width = $width; |
|
| 56 | - $this->_customMethodForValue = $customMethodForValue; |
|
| 57 | - $this->_sortable = $sortable; |
|
| 58 | - $this->_param = $param; |
|
| 59 | - $this->_customCaption = $customCaption; |
|
| 60 | - } |
|
| 34 | + /** |
|
| 35 | + * SmartObjectColumn constructor. |
|
| 36 | + * @param $keyname |
|
| 37 | + * @param string $align |
|
| 38 | + * @param bool $width |
|
| 39 | + * @param bool $customMethodForValue |
|
| 40 | + * @param bool $param |
|
| 41 | + * @param bool $customCaption |
|
| 42 | + * @param bool $sortable |
|
| 43 | + */ |
|
| 44 | + public function __construct( |
|
| 45 | + $keyname, |
|
| 46 | + $align = 'left', |
|
| 47 | + $width = false, |
|
| 48 | + $customMethodForValue = false, |
|
| 49 | + $param = false, |
|
| 50 | + $customCaption = false, |
|
| 51 | + $sortable = true |
|
| 52 | + ) { |
|
| 53 | + $this->_keyname = $keyname; |
|
| 54 | + $this->_align = $align; |
|
| 55 | + $this->_width = $width; |
|
| 56 | + $this->_customMethodForValue = $customMethodForValue; |
|
| 57 | + $this->_sortable = $sortable; |
|
| 58 | + $this->_param = $param; |
|
| 59 | + $this->_customCaption = $customCaption; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function getKeyName() |
|
| 63 | - { |
|
| 64 | - return $this->_keyname; |
|
| 65 | - } |
|
| 62 | + public function getKeyName() |
|
| 63 | + { |
|
| 64 | + return $this->_keyname; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return string |
|
| 69 | - */ |
|
| 70 | - public function getAlign() |
|
| 71 | - { |
|
| 72 | - return $this->_align; |
|
| 73 | - } |
|
| 67 | + /** |
|
| 68 | + * @return string |
|
| 69 | + */ |
|
| 70 | + public function getAlign() |
|
| 71 | + { |
|
| 72 | + return $this->_align; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - public function isSortable() |
|
| 79 | - { |
|
| 80 | - return $this->_sortable; |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + public function isSortable() |
|
| 79 | + { |
|
| 80 | + return $this->_sortable; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @return bool|string |
|
| 85 | - */ |
|
| 86 | - public function getWidth() |
|
| 87 | - { |
|
| 88 | - if ($this->_width) { |
|
| 89 | - $ret = $this->_width; |
|
| 90 | - } else { |
|
| 91 | - $ret = ''; |
|
| 92 | - } |
|
| 83 | + /** |
|
| 84 | + * @return bool|string |
|
| 85 | + */ |
|
| 86 | + public function getWidth() |
|
| 87 | + { |
|
| 88 | + if ($this->_width) { |
|
| 89 | + $ret = $this->_width; |
|
| 90 | + } else { |
|
| 91 | + $ret = ''; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $ret; |
|
| 95 | - } |
|
| 94 | + return $ret; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 100 | - public function getCustomCaption() |
|
| 101 | - { |
|
| 102 | - return $this->_customCaption; |
|
| 103 | - } |
|
| 97 | + /** |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | + public function getCustomCaption() |
|
| 101 | + { |
|
| 102 | + return $this->_customCaption; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * @param $smartObj |
| 129 | - * @param $objectid |
|
| 130 | - * @param $created_success_msg |
|
| 131 | - * @param $modified_success_msg |
|
| 129 | + * @param integer $objectid |
|
| 130 | + * @param string $created_success_msg |
|
| 131 | + * @param string $modified_success_msg |
|
| 132 | 132 | * @param bool $redirect_page |
| 133 | 133 | * @param bool $debug |
| 134 | 134 | * @return mixed |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
| 443 | - * @param $smartObj |
|
| 443 | + * @param SmartMlObject $smartObj |
|
| 444 | 444 | * @param bool $onlyUrl |
| 445 | 445 | * @param bool $withimage |
| 446 | 446 | * @return string |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
| 501 | - * @param $smartObj |
|
| 501 | + * @param BaseSmartObject $smartObj |
|
| 502 | 502 | * @return string |
| 503 | 503 | */ |
| 504 | 504 | public function getPrintAndMailLink($smartObj) |
@@ -33,511 +33,511 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class SmartObjectController |
| 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 SmartUploader($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 SmartobjectPermissionHandler($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 ?: smart_get_page_before_form(); |
|
| 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 = smart_getModuleModeSEO($this->handler->_moduleName); |
|
| 419 | - $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName); |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
| 423 | - */ |
|
| 424 | - //$seoIncludeId = smart_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 = smart_getModuleInfo($smartObj->handler->_moduleName); |
|
| 513 | - $link = smart_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 SmartUploader($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 SmartobjectPermissionHandler($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 ?: smart_get_page_before_form(); |
|
| 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 = smart_getModuleModeSEO($this->handler->_moduleName); |
|
| 419 | + $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName); |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
| 423 | + */ |
|
| 424 | + //$seoIncludeId = smart_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 = smart_getModuleInfo($smartObj->handler->_moduleName); |
|
| 513 | + $link = smart_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 | } |
@@ -52,15 +52,15 @@ discard block |
||
| 52 | 52 | foreach (array_keys($smartObj->vars) as $key) { |
| 53 | 53 | switch ($smartObj->vars[$key]['data_type']) { |
| 54 | 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]); |
|
| 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 | 58 | if (file_exists($oldFile)) { |
| 59 | 59 | unlink($oldFile); |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | - if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
| 63 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
| 62 | + if (isset($_POST['delete_'.$key]) && '1' == $_POST['delete_'.$key]) { |
|
| 63 | + $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e'); |
|
| 64 | 64 | $smartObj->setVar($key, ''); |
| 65 | 65 | if (file_exists($oldFile)) { |
| 66 | 66 | unlink($oldFile); |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | case XOBJ_DTYPE_URLLINK: |
| 72 | 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]); |
|
| 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 | 77 | if ('' !== $linkObj->getVar('url')) { |
| 78 | 78 | $smartObj->storeUrlLinkObj($linkObj); |
| 79 | 79 | } |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | break; |
| 83 | 83 | |
| 84 | 84 | case XOBJ_DTYPE_FILE: |
| 85 | - if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
| 85 | + if (!isset($_FILES['upload_'.$key]['name']) || '' === $_FILES['upload_'.$key]['name']) { |
|
| 86 | 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]); |
|
| 87 | + $fileObj->setVar('caption', $_POST['caption_'.$key]); |
|
| 88 | + $fileObj->setVar('description', $_POST['desc_'.$key]); |
|
| 89 | + $fileObj->setVar('url', $_POST['url_'.$key]); |
|
| 90 | 90 | if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
| 91 | 91 | && '' === $fileObj->getVar('url'))) { |
| 92 | 92 | $res = $smartObj->storeFileObj($fileObj); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $value = strtotime($_POST[$key]); |
| 111 | 111 | //if strtotime returns false, the value is already a time stamp |
| 112 | 112 | if (!$value) { |
| 113 | - $value = (int)$_POST[$key]; |
|
| 113 | + $value = (int) $_POST[$key]; |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | $smartObj->setVar($key, $value); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | if (isset($file_array['name']) && '' !== $file_array['name'] |
| 160 | 160 | && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
| 161 | 161 | if ($uploaderObj->fetchMedia($name)) { |
| 162 | - $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
| 162 | + $uploaderObj->setTargetFileName(time().'_'.$uploaderObj->getMediaName()); |
|
| 163 | 163 | if ($uploaderObj->upload()) { |
| 164 | 164 | // Find the related field in the SmartObject |
| 165 | 165 | $related_field = str_replace('upload_', '', $name); |
@@ -168,14 +168,14 @@ discard block |
||
| 168 | 168 | if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
| 169 | 169 | $object_fileurl = $smartObj->getUploadDir(); |
| 170 | 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]); |
|
| 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 | 174 | $smartObj->storeFileObj($fileObj); |
| 175 | 175 | //todo: catch errors |
| 176 | 176 | $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
| 177 | 177 | } else { |
| 178 | - $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
| 178 | + $old_file = $smartObj->getUploadDir(true).$smartObj->getVar($related_field); |
|
| 179 | 179 | unlink($old_file); |
| 180 | 180 | $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
| 181 | 181 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | return $smartObj; |
| 207 | 207 | } else { |
| 208 | 208 | if (!$storeResult) { |
| 209 | - redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
| 209 | + redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR.$smartObj->getHtmlErrors()); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $redirect_page = $redirect_page ?: smart_get_page_before_form(); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $debug = false, |
| 236 | 236 | $x_param = false |
| 237 | 237 | ) { |
| 238 | - $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
| 238 | + $objectid = isset($_POST[$this->handler->keyName]) ? (int) $_POST[$this->handler->keyName] : 0; |
|
| 239 | 239 | if ($debug) { |
| 240 | 240 | if ($x_param) { |
| 241 | 241 | $smartObj = $this->handler->getD($objectid, true, $x_param); |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | { |
| 312 | 312 | global $smart_previous_page; |
| 313 | 313 | |
| 314 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
| 314 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0; |
|
| 315 | 315 | $smartObj = $this->handler->get($objectid); |
| 316 | 316 | |
| 317 | 317 | if ($smartObj->isNew()) { |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
| 322 | 322 | if ($confirm) { |
| 323 | 323 | if (!$this->handler->delete($smartObj)) { |
| 324 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
| 324 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors()); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | { |
| 355 | 355 | global $smart_previous_page, $xoopsTpl; |
| 356 | 356 | |
| 357 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
| 357 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0; |
|
| 358 | 358 | $smartObj = $this->handler->get($objectid); |
| 359 | 359 | |
| 360 | 360 | if ($smartObj->isNew()) { |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
| 365 | 365 | if ($confirm) { |
| 366 | 366 | if (!$this->handler->delete($smartObj)) { |
| 367 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
| 367 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors()); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
@@ -396,14 +396,14 @@ discard block |
||
| 396 | 396 | */ |
| 397 | 397 | public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
| 398 | 398 | { |
| 399 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 399 | + $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=view&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
| 400 | 400 | if ($onlyUrl) { |
| 401 | 401 | return $ret; |
| 402 | 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>"; |
|
| 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 | 404 | } |
| 405 | 405 | |
| 406 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 406 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -425,15 +425,15 @@ discard block |
||
| 425 | 425 | $seoIncludeId = true; |
| 426 | 426 | |
| 427 | 427 | if ('rewrite' === $seoMode) { |
| 428 | - $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
| 428 | + $ret = XOOPS_URL.'/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html'; |
|
| 429 | 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'; |
|
| 430 | + $ret = SMARTOBJECT_URL.'seo.php/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html'; |
|
| 431 | 431 | } else { |
| 432 | - $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
| 432 | + $ret = $this->handler->_moduleUrl.$this->handler->_page.'?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | if (!$onlyUrl) { |
| 436 | - $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 436 | + $ret = "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | return $ret; |
@@ -447,14 +447,14 @@ discard block |
||
| 447 | 447 | */ |
| 448 | 448 | public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
| 449 | 449 | { |
| 450 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
| 450 | + $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName).'&language='.$smartObj->getVar('language'); |
|
| 451 | 451 | if ($onlyUrl) { |
| 452 | 452 | return $ret; |
| 453 | 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>"; |
|
| 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 | 455 | } |
| 456 | 456 | |
| 457 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 457 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -467,14 +467,14 @@ discard block |
||
| 467 | 467 | public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
| 468 | 468 | { |
| 469 | 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); |
|
| 470 | + $ret = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
| 471 | 471 | if ($onlyUrl) { |
| 472 | 472 | return $ret; |
| 473 | 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>"; |
|
| 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 | 475 | } |
| 476 | 476 | |
| 477 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 477 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -487,14 +487,14 @@ discard block |
||
| 487 | 487 | public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
| 488 | 488 | { |
| 489 | 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); |
|
| 490 | + $ret = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=del&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
| 491 | 491 | if ($onlyUrl) { |
| 492 | 492 | return $ret; |
| 493 | 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>"; |
|
| 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 | 495 | } |
| 496 | 496 | |
| 497 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
| 497 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -505,9 +505,9 @@ discard block |
||
| 505 | 505 | { |
| 506 | 506 | global $xoopsConfig; |
| 507 | 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>'; |
|
| 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 | 511 | |
| 512 | 512 | $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName); |
| 513 | 513 | $link = smart_getCurrentPage(); |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | . _CO_SOBJECT_EMAIL |
| 527 | 527 | . '" style="vertical-align: middle;"></a>'; |
| 528 | 528 | |
| 529 | - $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
| 529 | + $ret = '<span id="smartobject_print_button">'.$printlink.' </span>'.'<span id="smartobject_mail_button">'.$friendlink.'</span>'; |
|
| 530 | 530 | |
| 531 | 531 | return $ret; |
| 532 | 532 | } |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | */ |
| 537 | 537 | public function getModuleItemString() |
| 538 | 538 | { |
| 539 | - $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
| 539 | + $ret = $this->handler->_moduleName.'_'.$this->handler->_itemname; |
|
| 540 | 540 | |
| 541 | 541 | return $ret; |
| 542 | 542 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | /** |
| 144 | 144 | * Use to update a table |
| 145 | 145 | * |
| 146 | - * @param object $table {@link SmartDbTable} that will be updated |
|
| 146 | + * @param SmartDbTable $table {@link SmartDbTable} that will be updated |
|
| 147 | 147 | * |
| 148 | 148 | * @see SmartDbTable |
| 149 | 149 | * |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | /** |
| 246 | 246 | * @param $module |
| 247 | 247 | * @param $item |
| 248 | - * @return bool |
|
| 248 | + * @return false|null |
|
| 249 | 249 | */ |
| 250 | 250 | public function upgradeObjectItem($module, $item) |
| 251 | 251 | { |
@@ -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 | |
@@ -62,328 +61,328 @@ discard block |
||
| 62 | 61 | */ |
| 63 | 62 | class SmartobjectDbupdater |
| 64 | 63 | { |
| 65 | - public $_dbTypesArray; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * SmartobjectDbupdater constructor. |
|
| 69 | - */ |
|
| 70 | - public function __construct() |
|
| 71 | - { |
|
| 72 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
| 73 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
| 74 | - $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
| 75 | - $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
| 76 | - $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
| 77 | - $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
| 78 | - $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
| 79 | - $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
| 80 | - $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
| 81 | - $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
| 82 | - $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
| 83 | - $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
| 84 | - $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
| 85 | - $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
| 86 | - $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
| 87 | - $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
| 88 | - $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
| 89 | - $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Use to execute a general query |
|
| 94 | - * |
|
| 95 | - * @param string $query query that will be executed |
|
| 96 | - * @param string $goodmsg message displayed on success |
|
| 97 | - * @param string $badmsg message displayed on error |
|
| 98 | - * |
|
| 99 | - * @return bool true if success, false if an error occured |
|
| 100 | - * |
|
| 101 | - */ |
|
| 102 | - public function runQuery($query, $goodmsg, $badmsg) |
|
| 103 | - { |
|
| 104 | - global $xoopsDB; |
|
| 105 | - $ret = $xoopsDB->query($query); |
|
| 106 | - if (!$ret) { |
|
| 107 | - echo " $badmsg<br>"; |
|
| 108 | - |
|
| 109 | - return false; |
|
| 110 | - } else { |
|
| 111 | - echo " $goodmsg<br>"; |
|
| 112 | - |
|
| 113 | - return true; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Use to rename a table |
|
| 119 | - * |
|
| 120 | - * @param string $from name of the table to rename |
|
| 121 | - * @param string $to new name of the renamed table |
|
| 122 | - * |
|
| 123 | - * @return bool true if success, false if an error occured |
|
| 124 | - */ |
|
| 125 | - public function renameTable($from, $to) |
|
| 126 | - { |
|
| 127 | - global $xoopsDB; |
|
| 128 | - $from = $xoopsDB->prefix($from); |
|
| 129 | - $to = $xoopsDB->prefix($to); |
|
| 130 | - $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
| 131 | - $ret = $xoopsDB->query($query); |
|
| 132 | - if (!$ret) { |
|
| 133 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
| 134 | - |
|
| 135 | - return false; |
|
| 136 | - } else { |
|
| 137 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
| 138 | - |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Use to update a table |
|
| 145 | - * |
|
| 146 | - * @param object $table {@link SmartDbTable} that will be updated |
|
| 147 | - * |
|
| 148 | - * @see SmartDbTable |
|
| 149 | - * |
|
| 150 | - * @return bool true if success, false if an error occured |
|
| 151 | - */ |
|
| 152 | - public function updateTable($table) |
|
| 153 | - { |
|
| 154 | - global $xoopsDB; |
|
| 155 | - $ret = true; |
|
| 156 | - // If table has a structure, create the table |
|
| 157 | - if ($table->getStructure()) { |
|
| 158 | - $ret = $table->createTable() && $ret; |
|
| 159 | - } |
|
| 160 | - // If table is flag for drop, drop it |
|
| 161 | - if ($table->_flagForDrop) { |
|
| 162 | - $ret = $table->dropTable() && $ret; |
|
| 163 | - } |
|
| 164 | - // If table has data, insert it |
|
| 165 | - if ($table->getData()) { |
|
| 166 | - $ret = $table->addData() && $ret; |
|
| 167 | - } |
|
| 168 | - // If table has new fields to be added, add them |
|
| 169 | - if ($table->getNewFields()) { |
|
| 170 | - $ret = $table->addNewFields() && $ret; |
|
| 171 | - } |
|
| 172 | - // If table has altered field, alter the table |
|
| 173 | - if ($table->getAlteredFields()) { |
|
| 174 | - $ret = $table->alterTable() && $ret; |
|
| 175 | - } |
|
| 176 | - // If table has updated field values, update the table |
|
| 177 | - if ($table->getUpdatedFields()) { |
|
| 178 | - $ret = $table->updateFieldsValues($table) && $ret; |
|
| 179 | - } |
|
| 180 | - // If table has dropped field, alter the table |
|
| 181 | - if ($table->getDroppedFields()) { |
|
| 182 | - $ret = $table->dropFields($table) && $ret; |
|
| 183 | - } |
|
| 184 | - //felix |
|
| 185 | - // If table has updated field values, update the table |
|
| 186 | - if ($table->getUpdatedWhere()) { |
|
| 187 | - $ret = $table->UpdateWhereValues($table) && $ret; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return $ret; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @param $module |
|
| 195 | - * @param $item |
|
| 196 | - */ |
|
| 197 | - public function automaticUpgrade($module, $item) |
|
| 198 | - { |
|
| 199 | - if (is_array($item)) { |
|
| 200 | - foreach ($item as $v) { |
|
| 201 | - $this->upgradeObjectItem($module, $v); |
|
| 202 | - } |
|
| 203 | - } else { |
|
| 204 | - $this->upgradeObjectItem($module, $item); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param $var |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - public function getFieldTypeFromVar($var) |
|
| 213 | - { |
|
| 214 | - $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
| 215 | - |
|
| 216 | - return $ret; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param $var |
|
| 221 | - * @param bool $key |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - public function getFieldDefaultFromVar($var, $key = false) |
|
| 225 | - { |
|
| 226 | - if ($var['value']) { |
|
| 227 | - return $var['value']; |
|
| 228 | - } else { |
|
| 229 | - if (in_array($var['data_type'], [ |
|
| 230 | - XOBJ_DTYPE_INT, |
|
| 231 | - XOBJ_DTYPE_STIME, |
|
| 232 | - XOBJ_DTYPE_MTIME, |
|
| 233 | - XOBJ_DTYPE_LTIME, |
|
| 234 | - XOBJ_DTYPE_TIME_ONLY, |
|
| 235 | - XOBJ_DTYPE_URLLINK, |
|
| 236 | - XOBJ_DTYPE_FILE |
|
| 237 | - ])) { |
|
| 238 | - return '0'; |
|
| 239 | - } else { |
|
| 240 | - return ''; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param $module |
|
| 247 | - * @param $item |
|
| 248 | - * @return bool |
|
| 249 | - */ |
|
| 250 | - public function upgradeObjectItem($module, $item) |
|
| 251 | - { |
|
| 252 | - $moduleHandler = xoops_getModuleHandler($item, $module); |
|
| 253 | - if (!$moduleHandler) { |
|
| 254 | - return false; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $table = new SmartDbTable($module . '_' . $item); |
|
| 258 | - $object = $moduleHandler->create(); |
|
| 259 | - $objectVars = $object->getVars(); |
|
| 260 | - |
|
| 261 | - if (!$table->exists()) { |
|
| 262 | - // table was never created, let's do it |
|
| 263 | - $structure = ''; |
|
| 264 | - foreach ($objectVars as $key => $var) { |
|
| 265 | - if ($var['persistent']) { |
|
| 266 | - $type = $this->getFieldTypeFromVar($var); |
|
| 267 | - if ($key == $moduleHandler->keyName) { |
|
| 268 | - $extra = 'auto_increment'; |
|
| 269 | - } else { |
|
| 270 | - $default = $this->getFieldDefaultFromVar($var); |
|
| 271 | - $extra = "default '$default' |
|
| 64 | + public $_dbTypesArray; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * SmartobjectDbupdater constructor. |
|
| 68 | + */ |
|
| 69 | + public function __construct() |
|
| 70 | + { |
|
| 71 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
| 72 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
| 73 | + $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
| 74 | + $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
| 75 | + $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
| 76 | + $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
| 77 | + $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
| 78 | + $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
| 79 | + $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
| 80 | + $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
| 81 | + $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
| 82 | + $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
| 83 | + $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
| 84 | + $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
| 85 | + $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
| 86 | + $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
| 87 | + $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
| 88 | + $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Use to execute a general query |
|
| 93 | + * |
|
| 94 | + * @param string $query query that will be executed |
|
| 95 | + * @param string $goodmsg message displayed on success |
|
| 96 | + * @param string $badmsg message displayed on error |
|
| 97 | + * |
|
| 98 | + * @return bool true if success, false if an error occured |
|
| 99 | + * |
|
| 100 | + */ |
|
| 101 | + public function runQuery($query, $goodmsg, $badmsg) |
|
| 102 | + { |
|
| 103 | + global $xoopsDB; |
|
| 104 | + $ret = $xoopsDB->query($query); |
|
| 105 | + if (!$ret) { |
|
| 106 | + echo " $badmsg<br>"; |
|
| 107 | + |
|
| 108 | + return false; |
|
| 109 | + } else { |
|
| 110 | + echo " $goodmsg<br>"; |
|
| 111 | + |
|
| 112 | + return true; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Use to rename a table |
|
| 118 | + * |
|
| 119 | + * @param string $from name of the table to rename |
|
| 120 | + * @param string $to new name of the renamed table |
|
| 121 | + * |
|
| 122 | + * @return bool true if success, false if an error occured |
|
| 123 | + */ |
|
| 124 | + public function renameTable($from, $to) |
|
| 125 | + { |
|
| 126 | + global $xoopsDB; |
|
| 127 | + $from = $xoopsDB->prefix($from); |
|
| 128 | + $to = $xoopsDB->prefix($to); |
|
| 129 | + $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
| 130 | + $ret = $xoopsDB->query($query); |
|
| 131 | + if (!$ret) { |
|
| 132 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
| 133 | + |
|
| 134 | + return false; |
|
| 135 | + } else { |
|
| 136 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
| 137 | + |
|
| 138 | + return true; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Use to update a table |
|
| 144 | + * |
|
| 145 | + * @param object $table {@link SmartDbTable} that will be updated |
|
| 146 | + * |
|
| 147 | + * @see SmartDbTable |
|
| 148 | + * |
|
| 149 | + * @return bool true if success, false if an error occured |
|
| 150 | + */ |
|
| 151 | + public function updateTable($table) |
|
| 152 | + { |
|
| 153 | + global $xoopsDB; |
|
| 154 | + $ret = true; |
|
| 155 | + // If table has a structure, create the table |
|
| 156 | + if ($table->getStructure()) { |
|
| 157 | + $ret = $table->createTable() && $ret; |
|
| 158 | + } |
|
| 159 | + // If table is flag for drop, drop it |
|
| 160 | + if ($table->_flagForDrop) { |
|
| 161 | + $ret = $table->dropTable() && $ret; |
|
| 162 | + } |
|
| 163 | + // If table has data, insert it |
|
| 164 | + if ($table->getData()) { |
|
| 165 | + $ret = $table->addData() && $ret; |
|
| 166 | + } |
|
| 167 | + // If table has new fields to be added, add them |
|
| 168 | + if ($table->getNewFields()) { |
|
| 169 | + $ret = $table->addNewFields() && $ret; |
|
| 170 | + } |
|
| 171 | + // If table has altered field, alter the table |
|
| 172 | + if ($table->getAlteredFields()) { |
|
| 173 | + $ret = $table->alterTable() && $ret; |
|
| 174 | + } |
|
| 175 | + // If table has updated field values, update the table |
|
| 176 | + if ($table->getUpdatedFields()) { |
|
| 177 | + $ret = $table->updateFieldsValues($table) && $ret; |
|
| 178 | + } |
|
| 179 | + // If table has dropped field, alter the table |
|
| 180 | + if ($table->getDroppedFields()) { |
|
| 181 | + $ret = $table->dropFields($table) && $ret; |
|
| 182 | + } |
|
| 183 | + //felix |
|
| 184 | + // If table has updated field values, update the table |
|
| 185 | + if ($table->getUpdatedWhere()) { |
|
| 186 | + $ret = $table->UpdateWhereValues($table) && $ret; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return $ret; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @param $module |
|
| 194 | + * @param $item |
|
| 195 | + */ |
|
| 196 | + public function automaticUpgrade($module, $item) |
|
| 197 | + { |
|
| 198 | + if (is_array($item)) { |
|
| 199 | + foreach ($item as $v) { |
|
| 200 | + $this->upgradeObjectItem($module, $v); |
|
| 201 | + } |
|
| 202 | + } else { |
|
| 203 | + $this->upgradeObjectItem($module, $item); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @param $var |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + public function getFieldTypeFromVar($var) |
|
| 212 | + { |
|
| 213 | + $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
| 214 | + |
|
| 215 | + return $ret; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @param $var |
|
| 220 | + * @param bool $key |
|
| 221 | + * @return string |
|
| 222 | + */ |
|
| 223 | + public function getFieldDefaultFromVar($var, $key = false) |
|
| 224 | + { |
|
| 225 | + if ($var['value']) { |
|
| 226 | + return $var['value']; |
|
| 227 | + } else { |
|
| 228 | + if (in_array($var['data_type'], [ |
|
| 229 | + XOBJ_DTYPE_INT, |
|
| 230 | + XOBJ_DTYPE_STIME, |
|
| 231 | + XOBJ_DTYPE_MTIME, |
|
| 232 | + XOBJ_DTYPE_LTIME, |
|
| 233 | + XOBJ_DTYPE_TIME_ONLY, |
|
| 234 | + XOBJ_DTYPE_URLLINK, |
|
| 235 | + XOBJ_DTYPE_FILE |
|
| 236 | + ])) { |
|
| 237 | + return '0'; |
|
| 238 | + } else { |
|
| 239 | + return ''; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @param $module |
|
| 246 | + * @param $item |
|
| 247 | + * @return bool |
|
| 248 | + */ |
|
| 249 | + public function upgradeObjectItem($module, $item) |
|
| 250 | + { |
|
| 251 | + $moduleHandler = xoops_getModuleHandler($item, $module); |
|
| 252 | + if (!$moduleHandler) { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $table = new SmartDbTable($module . '_' . $item); |
|
| 257 | + $object = $moduleHandler->create(); |
|
| 258 | + $objectVars = $object->getVars(); |
|
| 259 | + |
|
| 260 | + if (!$table->exists()) { |
|
| 261 | + // table was never created, let's do it |
|
| 262 | + $structure = ''; |
|
| 263 | + foreach ($objectVars as $key => $var) { |
|
| 264 | + if ($var['persistent']) { |
|
| 265 | + $type = $this->getFieldTypeFromVar($var); |
|
| 266 | + if ($key == $moduleHandler->keyName) { |
|
| 267 | + $extra = 'auto_increment'; |
|
| 268 | + } else { |
|
| 269 | + $default = $this->getFieldDefaultFromVar($var); |
|
| 270 | + $extra = "default '$default' |
|
| 272 | 271 | "; |
| 273 | - } |
|
| 274 | - $structure .= "`$key` $type not null $extra, |
|
| 272 | + } |
|
| 273 | + $structure .= "`$key` $type not null $extra, |
|
| 275 | 274 | "; |
| 276 | - } |
|
| 277 | - } |
|
| 278 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
| 279 | 278 | '; |
| 280 | - $table->setStructure($structure); |
|
| 281 | - if (!$this->updateTable($table)) { |
|
| 282 | - /** |
|
| 283 | - * @todo trap the errors |
|
| 284 | - */ |
|
| 285 | - } |
|
| 286 | - } else { |
|
| 287 | - $existingFieldsArray = $table->getExistingFieldsArray(); |
|
| 288 | - foreach ($objectVars as $key => $var) { |
|
| 289 | - if ($var['persistent']) { |
|
| 290 | - if (!isset($existingFieldsArray[$key])) { |
|
| 291 | - // the fiels does not exist, let's create it |
|
| 292 | - $type = $this->getFieldTypeFromVar($var); |
|
| 293 | - $default = $this->getFieldDefaultFromVar($var); |
|
| 294 | - $table->addNewField($key, "$type not null default '$default'"); |
|
| 295 | - } else { |
|
| 296 | - // if field already exists, let's check if the definition is correct |
|
| 297 | - $definition = strtolower($existingFieldsArray[$key]); |
|
| 298 | - $type = $this->getFieldTypeFromVar($var); |
|
| 299 | - if ($key == $moduleHandler->keyName) { |
|
| 300 | - $extra = 'auto_increment'; |
|
| 301 | - } else { |
|
| 302 | - $default = $this->getFieldDefaultFromVar($var, $key); |
|
| 303 | - $extra = "default '$default'"; |
|
| 304 | - } |
|
| 305 | - $actual_definition = "$type not null $extra"; |
|
| 306 | - if ($definition != $actual_definition) { |
|
| 307 | - $table->addAlteredField($key, $actual_definition); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - // check to see if there are some unused fields left in the table |
|
| 314 | - foreach ($existingFieldsArray as $key => $v) { |
|
| 315 | - if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
| 316 | - $table->addDroppedField($key); |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - if (!$this->updateTable($table)) { |
|
| 321 | - /** |
|
| 322 | - * @todo trap the errors |
|
| 323 | - */ |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @param $module |
|
| 330 | - * @return bool |
|
| 331 | - */ |
|
| 332 | - public function moduleUpgrade(\XoopsModule $module) |
|
| 333 | - { |
|
| 334 | - $dirname = $module->getVar('dirname'); |
|
| 335 | - |
|
| 336 | - ob_start(); |
|
| 337 | - |
|
| 338 | - $table = new SmartDbTable($dirname . '_meta'); |
|
| 339 | - if (!$table->exists()) { |
|
| 340 | - $table->setStructure(" |
|
| 279 | + $table->setStructure($structure); |
|
| 280 | + if (!$this->updateTable($table)) { |
|
| 281 | + /** |
|
| 282 | + * @todo trap the errors |
|
| 283 | + */ |
|
| 284 | + } |
|
| 285 | + } else { |
|
| 286 | + $existingFieldsArray = $table->getExistingFieldsArray(); |
|
| 287 | + foreach ($objectVars as $key => $var) { |
|
| 288 | + if ($var['persistent']) { |
|
| 289 | + if (!isset($existingFieldsArray[$key])) { |
|
| 290 | + // the fiels does not exist, let's create it |
|
| 291 | + $type = $this->getFieldTypeFromVar($var); |
|
| 292 | + $default = $this->getFieldDefaultFromVar($var); |
|
| 293 | + $table->addNewField($key, "$type not null default '$default'"); |
|
| 294 | + } else { |
|
| 295 | + // if field already exists, let's check if the definition is correct |
|
| 296 | + $definition = strtolower($existingFieldsArray[$key]); |
|
| 297 | + $type = $this->getFieldTypeFromVar($var); |
|
| 298 | + if ($key == $moduleHandler->keyName) { |
|
| 299 | + $extra = 'auto_increment'; |
|
| 300 | + } else { |
|
| 301 | + $default = $this->getFieldDefaultFromVar($var, $key); |
|
| 302 | + $extra = "default '$default'"; |
|
| 303 | + } |
|
| 304 | + $actual_definition = "$type not null $extra"; |
|
| 305 | + if ($definition != $actual_definition) { |
|
| 306 | + $table->addAlteredField($key, $actual_definition); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + // check to see if there are some unused fields left in the table |
|
| 313 | + foreach ($existingFieldsArray as $key => $v) { |
|
| 314 | + if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
| 315 | + $table->addDroppedField($key); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + if (!$this->updateTable($table)) { |
|
| 320 | + /** |
|
| 321 | + * @todo trap the errors |
|
| 322 | + */ |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * @param $module |
|
| 329 | + * @return bool |
|
| 330 | + */ |
|
| 331 | + public function moduleUpgrade(\XoopsModule $module) |
|
| 332 | + { |
|
| 333 | + $dirname = $module->getVar('dirname'); |
|
| 334 | + |
|
| 335 | + ob_start(); |
|
| 336 | + |
|
| 337 | + $table = new SmartDbTable($dirname . '_meta'); |
|
| 338 | + if (!$table->exists()) { |
|
| 339 | + $table->setStructure(" |
|
| 341 | 340 | `metakey` varchar(50) NOT NULL default '', |
| 342 | 341 | `metavalue` varchar(255) NOT NULL default '', |
| 343 | 342 | PRIMARY KEY (`metakey`)"); |
| 344 | - $table->setData("'version',0"); |
|
| 345 | - if (!$this->updateTable($table)) { |
|
| 346 | - /** |
|
| 347 | - * @todo trap the errors |
|
| 348 | - */ |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - $dbVersion = smart_GetMeta('version', $dirname); |
|
| 353 | - if (!$dbVersion) { |
|
| 354 | - $dbVersion = 0; |
|
| 355 | - } |
|
| 356 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
| 357 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
| 358 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
| 359 | - |
|
| 360 | - if ($newDbVersion > $dbVersion) { |
|
| 361 | - for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
| 362 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
| 363 | - if (function_exists($upgrade_function)) { |
|
| 364 | - $upgrade_function(); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 370 | - |
|
| 371 | - // if there is a function to execute for this DB version, let's do it |
|
| 372 | - //$function_ |
|
| 373 | - |
|
| 374 | - $module_info = smart_getModuleInfo($dirname); |
|
| 375 | - $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
| 376 | - |
|
| 377 | - echo '</code>'; |
|
| 378 | - |
|
| 379 | - $feedback = ob_get_clean(); |
|
| 380 | - if (method_exists($module, 'setMessage')) { |
|
| 381 | - $module->setMessage($feedback); |
|
| 382 | - } else { |
|
| 383 | - echo $feedback; |
|
| 384 | - } |
|
| 385 | - smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
| 386 | - |
|
| 387 | - return true; |
|
| 388 | - } |
|
| 343 | + $table->setData("'version',0"); |
|
| 344 | + if (!$this->updateTable($table)) { |
|
| 345 | + /** |
|
| 346 | + * @todo trap the errors |
|
| 347 | + */ |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + $dbVersion = smart_GetMeta('version', $dirname); |
|
| 352 | + if (!$dbVersion) { |
|
| 353 | + $dbVersion = 0; |
|
| 354 | + } |
|
| 355 | + $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
| 356 | + echo 'Database version: ' . $dbVersion . '<br>'; |
|
| 357 | + echo 'New database version: ' . $newDbVersion . '<br>'; |
|
| 358 | + |
|
| 359 | + if ($newDbVersion > $dbVersion) { |
|
| 360 | + for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
| 361 | + $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
| 362 | + if (function_exists($upgrade_function)) { |
|
| 363 | + $upgrade_function(); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 369 | + |
|
| 370 | + // if there is a function to execute for this DB version, let's do it |
|
| 371 | + //$function_ |
|
| 372 | + |
|
| 373 | + $module_info = smart_getModuleInfo($dirname); |
|
| 374 | + $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
| 375 | + |
|
| 376 | + echo '</code>'; |
|
| 377 | + |
|
| 378 | + $feedback = ob_get_clean(); |
|
| 379 | + if (method_exists($module, 'setMessage')) { |
|
| 380 | + $module->setMessage($feedback); |
|
| 381 | + } else { |
|
| 382 | + echo $feedback; |
|
| 383 | + } |
|
| 384 | + smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
| 385 | + |
|
| 386 | + return true; |
|
| 387 | + } |
|
| 389 | 388 | } |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
| 40 | 40 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
| 41 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 41 | + require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
| 42 | 42 | } |
| 43 | 43 | /** |
| 44 | 44 | * Include the language constants for the SmartObjectDBUpdater |
| 45 | 45 | */ |
| 46 | 46 | global $xoopsConfig; |
| 47 | -$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
|
| 47 | +$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php'; |
|
| 48 | 48 | if (!file_exists($common_file)) { |
| 49 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 49 | + $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php'; |
|
| 50 | 50 | } |
| 51 | 51 | include $common_file; |
| 52 | 52 | |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
| 131 | 131 | $ret = $xoopsDB->query($query); |
| 132 | 132 | if (!$ret) { |
| 133 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
| 133 | + echo ' '.sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from).'<br>'; |
|
| 134 | 134 | |
| 135 | 135 | return false; |
| 136 | 136 | } else { |
| 137 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
| 137 | + echo ' '.sprintf(_SDU_MSG_RENAME_TABLE, $from, $to).'<br>'; |
|
| 138 | 138 | |
| 139 | 139 | return true; |
| 140 | 140 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | return false; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - $table = new SmartDbTable($module . '_' . $item); |
|
| 257 | + $table = new SmartDbTable($module.'_'.$item); |
|
| 258 | 258 | $object = $moduleHandler->create(); |
| 259 | 259 | $objectVars = $object->getVars(); |
| 260 | 260 | |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | "; |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
| 278 | + $structure .= 'PRIMARY KEY (`'.$moduleHandler->keyName.'`) |
|
| 279 | 279 | '; |
| 280 | 280 | $table->setStructure($structure); |
| 281 | 281 | if (!$this->updateTable($table)) { |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | |
| 336 | 336 | ob_start(); |
| 337 | 337 | |
| 338 | - $table = new SmartDbTable($dirname . '_meta'); |
|
| 338 | + $table = new SmartDbTable($dirname.'_meta'); |
|
| 339 | 339 | if (!$table->exists()) { |
| 340 | 340 | $table->setStructure(" |
| 341 | 341 | `metakey` varchar(50) NOT NULL default '', |
@@ -353,20 +353,20 @@ discard block |
||
| 353 | 353 | if (!$dbVersion) { |
| 354 | 354 | $dbVersion = 0; |
| 355 | 355 | } |
| 356 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
| 357 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
| 358 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
| 356 | + $newDbVersion = constant(strtoupper($dirname.'_db_version')) ?: 0; |
|
| 357 | + echo 'Database version: '.$dbVersion.'<br>'; |
|
| 358 | + echo 'New database version: '.$newDbVersion.'<br>'; |
|
| 359 | 359 | |
| 360 | 360 | if ($newDbVersion > $dbVersion) { |
| 361 | 361 | for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
| 362 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
| 362 | + $upgrade_function = $dirname.'_db_upgrade_'.$i; |
|
| 363 | 363 | if (function_exists($upgrade_function)) { |
| 364 | 364 | $upgrade_function(); |
| 365 | 365 | } |
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 369 | + echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>'; |
|
| 370 | 370 | |
| 371 | 371 | // if there is a function to execute for this DB version, let's do it |
| 372 | 372 | //$function_ |