@@ -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 | } |
@@ -29,27 +29,27 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class SmartobjectTagHandler extends Smartobject\SmartPersistableMlObjectHandler |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectTagHandler constructor. |
|
| 34 | - * @param \XoopsDatabase $db |
|
| 35 | - */ |
|
| 36 | - public function __construct(\XoopsDatabase $db) |
|
| 37 | - { |
|
| 38 | - parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject'); |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * SmartobjectTagHandler constructor. |
|
| 34 | + * @param \XoopsDatabase $db |
|
| 35 | + */ |
|
| 36 | + public function __construct(\XoopsDatabase $db) |
|
| 37 | + { |
|
| 38 | + parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject'); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return mixed |
|
| 43 | - */ |
|
| 44 | - public function getLanguages() |
|
| 45 | - { |
|
| 46 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 47 | - $aLanguages = XoopsLists::getLangList(); |
|
| 48 | - $ret['default'] = _CO_SOBJECT_ALL; |
|
| 49 | - foreach ($aLanguages as $lang) { |
|
| 50 | - $ret[$lang] = $lang; |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * @return mixed |
|
| 43 | + */ |
|
| 44 | + public function getLanguages() |
|
| 45 | + { |
|
| 46 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 47 | + $aLanguages = XoopsLists::getLangList(); |
|
| 48 | + $ret['default'] = _CO_SOBJECT_ALL; |
|
| 49 | + foreach ($aLanguages as $lang) { |
|
| 50 | + $ret[$lang] = $lang; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return $ret; |
|
| 54 | - } |
|
| 53 | + return $ret; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | public function getLanguages() |
| 45 | 45 | { |
| 46 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 46 | + require_once XOOPS_ROOT_PATH.'/class/xoopslists.php'; |
|
| 47 | 47 | $aLanguages = XoopsLists::getLangList(); |
| 48 | 48 | $ret['default'] = _CO_SOBJECT_ALL; |
| 49 | 49 | foreach ($aLanguages as $lang) { |
@@ -34,169 +34,169 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class SmartObjectsRegistry |
| 36 | 36 | { |
| 37 | - public $_registryArray; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Access the only instance of this class |
|
| 41 | - * |
|
| 42 | - * @return \XoopsModules\Smartobject\SmartObjectsRegistry |
|
| 43 | - * |
|
| 44 | - * @static |
|
| 45 | - * @staticvar object |
|
| 46 | - */ |
|
| 47 | - public static function getInstance() |
|
| 48 | - { |
|
| 49 | - static $instance; |
|
| 50 | - if (null === $instance) { |
|
| 51 | - $instance = new static(); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return $instance; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Adding objects to the registry |
|
| 59 | - * |
|
| 60 | - * @param SmartPersistableObjectHandler $handler of the objects to add |
|
| 61 | - * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 62 | - * @return FALSE if an error occured |
|
| 63 | - */ |
|
| 64 | - public function addObjectsFromHandler(&$handler, $criteria = false) |
|
| 65 | - { |
|
| 66 | - if (method_exists($handler, 'getObjects')) { |
|
| 67 | - $objects = $handler->getObjects($criteria, true); |
|
| 68 | - $this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects; |
|
| 69 | - |
|
| 70 | - return $objects; |
|
| 71 | - } else { |
|
| 72 | - return false; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Adding objects to the registry from an item name |
|
| 78 | - * This method will fetch the handler of the item / module and call the addObjectsFromHandler |
|
| 79 | - * |
|
| 80 | - * @param string $item name of the item |
|
| 81 | - * @param bool|string $modulename name of the module |
|
| 82 | - * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 83 | - * @return FALSE if an error occured |
|
| 84 | - */ |
|
| 85 | - public function addObjectsFromItemName($item, $modulename = false, $criteria = false) |
|
| 86 | - { |
|
| 87 | - if (!$modulename) { |
|
| 88 | - global $xoopsModule; |
|
| 89 | - if (!is_object($xoopsModule)) { |
|
| 90 | - return false; |
|
| 91 | - } else { |
|
| 92 | - $modulename = $xoopsModule->dirname(); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - $objectHandler = xoops_getModuleHandler($item, $modulename); |
|
| 96 | - |
|
| 97 | - if (method_exists($objectHandler, 'getObjects')) { |
|
| 98 | - $objects = $objectHandler->getObjects($criteria, true); |
|
| 99 | - $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects; |
|
| 100 | - |
|
| 101 | - return $objects; |
|
| 102 | - } else { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Fetching objects from the registry |
|
| 109 | - * |
|
| 110 | - * @param string $itemname |
|
| 111 | - * @param string $modulename |
|
| 112 | - * |
|
| 113 | - * @return false|array the requested objects or FALSE if they don't exists in the registry |
|
| 114 | - */ |
|
| 115 | - public function getObjects($itemname, $modulename) |
|
| 116 | - { |
|
| 117 | - if (!$modulename) { |
|
| 118 | - global $xoopsModule; |
|
| 119 | - if (!is_object($xoopsModule)) { |
|
| 120 | - return false; |
|
| 121 | - } else { |
|
| 122 | - $modulename = $xoopsModule->dirname(); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - if (isset($this->_registryArray['objects'][$modulename][$itemname])) { |
|
| 126 | - return $this->_registryArray['objects'][$modulename][$itemname]; |
|
| 127 | - } else { |
|
| 128 | - // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 129 | - $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 130 | - if (method_exists($moduleHandler, 'getObjects')) { |
|
| 131 | - $objects = $moduleHandler->getObjects(); |
|
| 132 | - } |
|
| 133 | - $this->_registryArray['objects'][$modulename][$itemname] = $objects; |
|
| 134 | - |
|
| 135 | - return $objects; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Fetching objects from the registry, as a list: objectid => identifier |
|
| 141 | - * |
|
| 142 | - * @param string $itemname |
|
| 143 | - * @param string $modulename |
|
| 144 | - * |
|
| 145 | - * @return false|array the requested objects or FALSE if they don't exists in the registry |
|
| 146 | - */ |
|
| 147 | - public function getList($itemname, $modulename) |
|
| 148 | - { |
|
| 149 | - if (!$modulename) { |
|
| 150 | - global $xoopsModule; |
|
| 151 | - if (!is_object($xoopsModule)) { |
|
| 152 | - return false; |
|
| 153 | - } else { |
|
| 154 | - $modulename = $xoopsModule->dirname(); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - if (isset($this->_registryArray['list'][$modulename][$itemname])) { |
|
| 158 | - return $this->_registryArray['list'][$modulename][$itemname]; |
|
| 159 | - } else { |
|
| 160 | - // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 161 | - $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 162 | - if (method_exists($moduleHandler, 'getList')) { |
|
| 163 | - $objects = $moduleHandler->getList(); |
|
| 164 | - } |
|
| 165 | - $this->_registryArray['list'][$modulename][$itemname] = $objects; |
|
| 166 | - |
|
| 167 | - return $objects; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Retreive a single object |
|
| 173 | - * |
|
| 174 | - * @param string $itemname |
|
| 175 | - * @param string $key |
|
| 176 | - * |
|
| 177 | - * @param bool $modulename |
|
| 178 | - * @return false|\XoopsObject the requestd object or FALSE if they don't exists in the registry |
|
| 179 | - */ |
|
| 180 | - public function getSingleObject($itemname, $key, $modulename = false) |
|
| 181 | - { |
|
| 182 | - if (!$modulename) { |
|
| 183 | - global $xoopsModule; |
|
| 184 | - if (!is_object($xoopsModule)) { |
|
| 185 | - return false; |
|
| 186 | - } else { |
|
| 187 | - $modulename = $xoopsModule->dirname(); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) { |
|
| 191 | - return $this->_registryArray['objects'][$modulename][$itemname][$key]; |
|
| 192 | - } else { |
|
| 193 | - $objectHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 194 | - $object = $objectHandler->get($key); |
|
| 195 | - if (!$object->isNew()) { |
|
| 196 | - return $object; |
|
| 197 | - } else { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 37 | + public $_registryArray; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Access the only instance of this class |
|
| 41 | + * |
|
| 42 | + * @return \XoopsModules\Smartobject\SmartObjectsRegistry |
|
| 43 | + * |
|
| 44 | + * @static |
|
| 45 | + * @staticvar object |
|
| 46 | + */ |
|
| 47 | + public static function getInstance() |
|
| 48 | + { |
|
| 49 | + static $instance; |
|
| 50 | + if (null === $instance) { |
|
| 51 | + $instance = new static(); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return $instance; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Adding objects to the registry |
|
| 59 | + * |
|
| 60 | + * @param SmartPersistableObjectHandler $handler of the objects to add |
|
| 61 | + * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 62 | + * @return FALSE if an error occured |
|
| 63 | + */ |
|
| 64 | + public function addObjectsFromHandler(&$handler, $criteria = false) |
|
| 65 | + { |
|
| 66 | + if (method_exists($handler, 'getObjects')) { |
|
| 67 | + $objects = $handler->getObjects($criteria, true); |
|
| 68 | + $this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects; |
|
| 69 | + |
|
| 70 | + return $objects; |
|
| 71 | + } else { |
|
| 72 | + return false; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Adding objects to the registry from an item name |
|
| 78 | + * This method will fetch the handler of the item / module and call the addObjectsFromHandler |
|
| 79 | + * |
|
| 80 | + * @param string $item name of the item |
|
| 81 | + * @param bool|string $modulename name of the module |
|
| 82 | + * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 83 | + * @return FALSE if an error occured |
|
| 84 | + */ |
|
| 85 | + public function addObjectsFromItemName($item, $modulename = false, $criteria = false) |
|
| 86 | + { |
|
| 87 | + if (!$modulename) { |
|
| 88 | + global $xoopsModule; |
|
| 89 | + if (!is_object($xoopsModule)) { |
|
| 90 | + return false; |
|
| 91 | + } else { |
|
| 92 | + $modulename = $xoopsModule->dirname(); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + $objectHandler = xoops_getModuleHandler($item, $modulename); |
|
| 96 | + |
|
| 97 | + if (method_exists($objectHandler, 'getObjects')) { |
|
| 98 | + $objects = $objectHandler->getObjects($criteria, true); |
|
| 99 | + $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects; |
|
| 100 | + |
|
| 101 | + return $objects; |
|
| 102 | + } else { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Fetching objects from the registry |
|
| 109 | + * |
|
| 110 | + * @param string $itemname |
|
| 111 | + * @param string $modulename |
|
| 112 | + * |
|
| 113 | + * @return false|array the requested objects or FALSE if they don't exists in the registry |
|
| 114 | + */ |
|
| 115 | + public function getObjects($itemname, $modulename) |
|
| 116 | + { |
|
| 117 | + if (!$modulename) { |
|
| 118 | + global $xoopsModule; |
|
| 119 | + if (!is_object($xoopsModule)) { |
|
| 120 | + return false; |
|
| 121 | + } else { |
|
| 122 | + $modulename = $xoopsModule->dirname(); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + if (isset($this->_registryArray['objects'][$modulename][$itemname])) { |
|
| 126 | + return $this->_registryArray['objects'][$modulename][$itemname]; |
|
| 127 | + } else { |
|
| 128 | + // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 129 | + $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 130 | + if (method_exists($moduleHandler, 'getObjects')) { |
|
| 131 | + $objects = $moduleHandler->getObjects(); |
|
| 132 | + } |
|
| 133 | + $this->_registryArray['objects'][$modulename][$itemname] = $objects; |
|
| 134 | + |
|
| 135 | + return $objects; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Fetching objects from the registry, as a list: objectid => identifier |
|
| 141 | + * |
|
| 142 | + * @param string $itemname |
|
| 143 | + * @param string $modulename |
|
| 144 | + * |
|
| 145 | + * @return false|array the requested objects or FALSE if they don't exists in the registry |
|
| 146 | + */ |
|
| 147 | + public function getList($itemname, $modulename) |
|
| 148 | + { |
|
| 149 | + if (!$modulename) { |
|
| 150 | + global $xoopsModule; |
|
| 151 | + if (!is_object($xoopsModule)) { |
|
| 152 | + return false; |
|
| 153 | + } else { |
|
| 154 | + $modulename = $xoopsModule->dirname(); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + if (isset($this->_registryArray['list'][$modulename][$itemname])) { |
|
| 158 | + return $this->_registryArray['list'][$modulename][$itemname]; |
|
| 159 | + } else { |
|
| 160 | + // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 161 | + $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 162 | + if (method_exists($moduleHandler, 'getList')) { |
|
| 163 | + $objects = $moduleHandler->getList(); |
|
| 164 | + } |
|
| 165 | + $this->_registryArray['list'][$modulename][$itemname] = $objects; |
|
| 166 | + |
|
| 167 | + return $objects; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Retreive a single object |
|
| 173 | + * |
|
| 174 | + * @param string $itemname |
|
| 175 | + * @param string $key |
|
| 176 | + * |
|
| 177 | + * @param bool $modulename |
|
| 178 | + * @return false|\XoopsObject the requestd object or FALSE if they don't exists in the registry |
|
| 179 | + */ |
|
| 180 | + public function getSingleObject($itemname, $key, $modulename = false) |
|
| 181 | + { |
|
| 182 | + if (!$modulename) { |
|
| 183 | + global $xoopsModule; |
|
| 184 | + if (!is_object($xoopsModule)) { |
|
| 185 | + return false; |
|
| 186 | + } else { |
|
| 187 | + $modulename = $xoopsModule->dirname(); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) { |
|
| 191 | + return $this->_registryArray['objects'][$modulename][$itemname][$key]; |
|
| 192 | + } else { |
|
| 193 | + $objectHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 194 | + $object = $objectHandler->get($key); |
|
| 195 | + if (!$object->isNew()) { |
|
| 196 | + return $object; |
|
| 197 | + } else { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -30,12 +30,12 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartobjectUrlLinkHandler extends Smartobject\SmartPersistableObjectHandler |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * SmartobjectUrlLinkHandler constructor. |
|
| 35 | - * @param \XoopsDatabase $db |
|
| 36 | - */ |
|
| 37 | - public function __construct(\XoopsDatabase $db) |
|
| 38 | - { |
|
| 39 | - parent::__construct($db, 'urllink', 'urllinkid', 'caption', 'desc', 'smartobject'); |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * SmartobjectUrlLinkHandler constructor. |
|
| 35 | + * @param \XoopsDatabase $db |
|
| 36 | + */ |
|
| 37 | + public function __construct(\XoopsDatabase $db) |
|
| 38 | + { |
|
| 39 | + parent::__construct($db, 'urllink', 'urllinkid', 'caption', 'desc', 'smartobject'); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -28,44 +28,44 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class SmartSeoObject extends Smartobject\BaseSmartObject |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * SmartSeoObject constructor. |
|
| 33 | - */ |
|
| 34 | - public function __construct() |
|
| 35 | - { |
|
| 36 | - $this->initCommonVar('meta_keywords'); |
|
| 37 | - $this->initCommonVar('meta_description'); |
|
| 38 | - $this->initCommonVar('short_url'); |
|
| 39 | - $this->seoEnabled = true; |
|
| 40 | - } |
|
| 31 | + /** |
|
| 32 | + * SmartSeoObject constructor. |
|
| 33 | + */ |
|
| 34 | + public function __construct() |
|
| 35 | + { |
|
| 36 | + $this->initCommonVar('meta_keywords'); |
|
| 37 | + $this->initCommonVar('meta_description'); |
|
| 38 | + $this->initCommonVar('short_url'); |
|
| 39 | + $this->seoEnabled = true; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Return the value of the short_url field of this object |
|
| 44 | - * |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function short_url() |
|
| 48 | - { |
|
| 49 | - return $this->getVar('short_url'); |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * Return the value of the short_url field of this object |
|
| 44 | + * |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function short_url() |
|
| 48 | + { |
|
| 49 | + return $this->getVar('short_url'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Return the value of the meta_keywords field of this object |
|
| 54 | - * |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function meta_keywords() |
|
| 58 | - { |
|
| 59 | - return $this->getVar('meta_keywords'); |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * Return the value of the meta_keywords field of this object |
|
| 54 | + * |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function meta_keywords() |
|
| 58 | + { |
|
| 59 | + return $this->getVar('meta_keywords'); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Return the value of the meta_description field of this object |
|
| 64 | - * |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function meta_description() |
|
| 68 | - { |
|
| 69 | - return $this->getVar('meta_description'); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * Return the value of the meta_description field of this object |
|
| 64 | + * |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function meta_description() |
|
| 68 | + { |
|
| 69 | + return $this->getVar('meta_description'); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -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) { |
@@ -29,87 +29,87 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | class SmartobjectAdsense extends Smartobject\BaseSmartObject |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectAdsense constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
| 38 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
| 39 | - $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
| 40 | - $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
| 41 | - $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
| 42 | - $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 43 | - $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 44 | - $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
| 45 | - $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
| 46 | - $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
| 47 | - $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
| 32 | + /** |
|
| 33 | + * SmartobjectAdsense constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
| 38 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
| 39 | + $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
| 40 | + $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
| 41 | + $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
| 42 | + $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 43 | + $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 44 | + $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
| 45 | + $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
| 46 | + $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
| 47 | + $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
| 48 | 48 | |
| 49 | - $this->setControl('format', [ |
|
| 50 | - 'handler' => 'adsense', |
|
| 51 | - 'method' => 'getFormats' |
|
| 52 | - ]); |
|
| 49 | + $this->setControl('format', [ |
|
| 50 | + 'handler' => 'adsense', |
|
| 51 | + 'method' => 'getFormats' |
|
| 52 | + ]); |
|
| 53 | 53 | |
| 54 | - $this->setControl('border_color', [ |
|
| 55 | - 'name' => 'text', |
|
| 56 | - 'size' => 6, |
|
| 57 | - 'maxlength' => 6 |
|
| 58 | - ]); |
|
| 54 | + $this->setControl('border_color', [ |
|
| 55 | + 'name' => 'text', |
|
| 56 | + 'size' => 6, |
|
| 57 | + 'maxlength' => 6 |
|
| 58 | + ]); |
|
| 59 | 59 | |
| 60 | - $this->setControl('background_color', [ |
|
| 61 | - 'name' => 'text', |
|
| 62 | - 'size' => 6, |
|
| 63 | - 'maxlength' => 6 |
|
| 64 | - ]); |
|
| 60 | + $this->setControl('background_color', [ |
|
| 61 | + 'name' => 'text', |
|
| 62 | + 'size' => 6, |
|
| 63 | + 'maxlength' => 6 |
|
| 64 | + ]); |
|
| 65 | 65 | |
| 66 | - $this->setControl('link_color', [ |
|
| 67 | - 'name' => 'text', |
|
| 68 | - 'size' => 6, |
|
| 69 | - 'maxlength' => 6 |
|
| 70 | - ]); |
|
| 66 | + $this->setControl('link_color', [ |
|
| 67 | + 'name' => 'text', |
|
| 68 | + 'size' => 6, |
|
| 69 | + 'maxlength' => 6 |
|
| 70 | + ]); |
|
| 71 | 71 | |
| 72 | - $this->setControl('url_color', [ |
|
| 73 | - 'name' => 'text', |
|
| 74 | - 'size' => 6, |
|
| 75 | - 'maxlength' => 6 |
|
| 76 | - ]); |
|
| 72 | + $this->setControl('url_color', [ |
|
| 73 | + 'name' => 'text', |
|
| 74 | + 'size' => 6, |
|
| 75 | + 'maxlength' => 6 |
|
| 76 | + ]); |
|
| 77 | 77 | |
| 78 | - $this->setControl('text_color', [ |
|
| 79 | - 'name' => 'text', |
|
| 80 | - 'size' => 6, |
|
| 81 | - 'maxlength' => 6 |
|
| 82 | - ]); |
|
| 83 | - } |
|
| 78 | + $this->setControl('text_color', [ |
|
| 79 | + 'name' => 'text', |
|
| 80 | + 'size' => 6, |
|
| 81 | + 'maxlength' => 6 |
|
| 82 | + ]); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param string $key |
|
| 87 | - * @param string $format |
|
| 88 | - * @return mixed |
|
| 89 | - */ |
|
| 90 | - public function getVar($key, $format = 's') |
|
| 91 | - { |
|
| 92 | - if ('s' === $format && in_array($key, [])) { |
|
| 93 | - // return call_user_func(array($this, $key)); |
|
| 94 | - return $this->{$key}(); |
|
| 95 | - } |
|
| 85 | + /** |
|
| 86 | + * @param string $key |
|
| 87 | + * @param string $format |
|
| 88 | + * @return mixed |
|
| 89 | + */ |
|
| 90 | + public function getVar($key, $format = 's') |
|
| 91 | + { |
|
| 92 | + if ('s' === $format && in_array($key, [])) { |
|
| 93 | + // return call_user_func(array($this, $key)); |
|
| 94 | + return $this->{$key}(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return parent::getVar($key, $format); |
|
| 98 | - } |
|
| 97 | + return parent::getVar($key, $format); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function render() |
|
| 104 | - { |
|
| 105 | - global $smartobjectAdsenseHandler; |
|
| 106 | - if ('' !== $this->getVar('style', 'n')) { |
|
| 107 | - $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 108 | - } else { |
|
| 109 | - $ret = '<div>'; |
|
| 110 | - } |
|
| 100 | + /** |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function render() |
|
| 104 | + { |
|
| 105 | + global $smartobjectAdsenseHandler; |
|
| 106 | + if ('' !== $this->getVar('style', 'n')) { |
|
| 107 | + $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 108 | + } else { |
|
| 109 | + $ret = '<div>'; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - $ret .= '<script type="text/javascript"><!-- |
|
| 112 | + $ret .= '<script type="text/javascript"><!-- |
|
| 113 | 113 | google_ad_client = "' . $this->getVar('client_id', 'n') . '"; |
| 114 | 114 | google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . '; |
| 115 | 115 | google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . '; |
@@ -127,137 +127,137 @@ discard block |
||
| 127 | 127 | </script> |
| 128 | 128 | </div>'; |
| 129 | 129 | |
| 130 | - return $ret; |
|
| 131 | - } |
|
| 130 | + return $ret; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function getXoopsCode() |
|
| 137 | - { |
|
| 138 | - $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 133 | + /** |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function getXoopsCode() |
|
| 137 | + { |
|
| 138 | + $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 139 | 139 | |
| 140 | - return $ret; |
|
| 141 | - } |
|
| 140 | + return $ret; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * @param $var |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - public function emptyString($var) |
|
| 148 | - { |
|
| 149 | - return (strlen($var) > 0); |
|
| 150 | - } |
|
| 143 | + /** |
|
| 144 | + * @param $var |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + public function emptyString($var) |
|
| 148 | + { |
|
| 149 | + return (strlen($var) > 0); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * @return mixed|string |
|
| 154 | - */ |
|
| 155 | - public function generateTag() |
|
| 156 | - { |
|
| 157 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 158 | - $title = xoops_substr($title, 0, 10, ''); |
|
| 159 | - // Transformation des ponctuations |
|
| 160 | - $pattern = [ |
|
| 161 | - '/%09/', // Tab |
|
| 162 | - '/%20/', // Space |
|
| 163 | - '/%21/', // ! |
|
| 164 | - '/%22/', // " |
|
| 165 | - '/%23/', // # |
|
| 166 | - '/%25/', // % |
|
| 167 | - '/%26/', // & |
|
| 168 | - '/%27/', // ' |
|
| 169 | - '/%28/', // ( |
|
| 170 | - '/%29/', // ) |
|
| 171 | - '/%2C/', // , |
|
| 172 | - '/%2F/', // / |
|
| 173 | - '/%3A/', // : |
|
| 174 | - '/%3B/', // ; |
|
| 175 | - '/%3C/', // < |
|
| 176 | - '/%3D/', // = |
|
| 177 | - '/%3E/', // > |
|
| 178 | - '/%3F/', // ? |
|
| 179 | - '/%40/', // @ |
|
| 180 | - '/%5B/', // [ |
|
| 181 | - '/%5C/', // \ |
|
| 182 | - '/%5D/', // ] |
|
| 183 | - '/%5E/', // ^ |
|
| 184 | - '/%7B/', // { |
|
| 185 | - '/%7C/', // | |
|
| 186 | - '/%7D/', // } |
|
| 187 | - '/%7E/', // ~ |
|
| 188 | - "/\./" // . |
|
| 189 | - ]; |
|
| 190 | - $rep_pat = [ |
|
| 191 | - '-', |
|
| 192 | - '-', |
|
| 193 | - '-', |
|
| 194 | - '-', |
|
| 195 | - '-', |
|
| 196 | - '-100', |
|
| 197 | - '-', |
|
| 198 | - '-', |
|
| 199 | - '-', |
|
| 200 | - '-', |
|
| 201 | - '-', |
|
| 202 | - '-', |
|
| 203 | - '-', |
|
| 204 | - '-', |
|
| 205 | - '-', |
|
| 206 | - '-', |
|
| 207 | - '-', |
|
| 208 | - '-', |
|
| 209 | - '-at-', |
|
| 210 | - '-', |
|
| 211 | - '-', |
|
| 212 | - '-', |
|
| 213 | - '-', |
|
| 214 | - '-', |
|
| 215 | - '-', |
|
| 216 | - '-', |
|
| 217 | - '-', |
|
| 218 | - '-' |
|
| 219 | - ]; |
|
| 220 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 152 | + /** |
|
| 153 | + * @return mixed|string |
|
| 154 | + */ |
|
| 155 | + public function generateTag() |
|
| 156 | + { |
|
| 157 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 158 | + $title = xoops_substr($title, 0, 10, ''); |
|
| 159 | + // Transformation des ponctuations |
|
| 160 | + $pattern = [ |
|
| 161 | + '/%09/', // Tab |
|
| 162 | + '/%20/', // Space |
|
| 163 | + '/%21/', // ! |
|
| 164 | + '/%22/', // " |
|
| 165 | + '/%23/', // # |
|
| 166 | + '/%25/', // % |
|
| 167 | + '/%26/', // & |
|
| 168 | + '/%27/', // ' |
|
| 169 | + '/%28/', // ( |
|
| 170 | + '/%29/', // ) |
|
| 171 | + '/%2C/', // , |
|
| 172 | + '/%2F/', // / |
|
| 173 | + '/%3A/', // : |
|
| 174 | + '/%3B/', // ; |
|
| 175 | + '/%3C/', // < |
|
| 176 | + '/%3D/', // = |
|
| 177 | + '/%3E/', // > |
|
| 178 | + '/%3F/', // ? |
|
| 179 | + '/%40/', // @ |
|
| 180 | + '/%5B/', // [ |
|
| 181 | + '/%5C/', // \ |
|
| 182 | + '/%5D/', // ] |
|
| 183 | + '/%5E/', // ^ |
|
| 184 | + '/%7B/', // { |
|
| 185 | + '/%7C/', // | |
|
| 186 | + '/%7D/', // } |
|
| 187 | + '/%7E/', // ~ |
|
| 188 | + "/\./" // . |
|
| 189 | + ]; |
|
| 190 | + $rep_pat = [ |
|
| 191 | + '-', |
|
| 192 | + '-', |
|
| 193 | + '-', |
|
| 194 | + '-', |
|
| 195 | + '-', |
|
| 196 | + '-100', |
|
| 197 | + '-', |
|
| 198 | + '-', |
|
| 199 | + '-', |
|
| 200 | + '-', |
|
| 201 | + '-', |
|
| 202 | + '-', |
|
| 203 | + '-', |
|
| 204 | + '-', |
|
| 205 | + '-', |
|
| 206 | + '-', |
|
| 207 | + '-', |
|
| 208 | + '-', |
|
| 209 | + '-at-', |
|
| 210 | + '-', |
|
| 211 | + '-', |
|
| 212 | + '-', |
|
| 213 | + '-', |
|
| 214 | + '-', |
|
| 215 | + '-', |
|
| 216 | + '-', |
|
| 217 | + '-', |
|
| 218 | + '-' |
|
| 219 | + ]; |
|
| 220 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 221 | 221 | |
| 222 | - // Transformation des caractères accentués |
|
| 223 | - $pattern = [ |
|
| 224 | - '/%B0/', // ° |
|
| 225 | - '/%E8/', // è |
|
| 226 | - '/%E9/', // é |
|
| 227 | - '/%EA/', // ê |
|
| 228 | - '/%EB/', // ë |
|
| 229 | - '/%E7/', // ç |
|
| 230 | - '/%E0/', // à |
|
| 231 | - '/%E2/', // â |
|
| 232 | - '/%E4/', // ä |
|
| 233 | - '/%EE/', // î |
|
| 234 | - '/%EF/', // ï |
|
| 235 | - '/%F9/', // ù |
|
| 236 | - '/%FC/', // ü |
|
| 237 | - '/%FB/', // û |
|
| 238 | - '/%F4/', // ô |
|
| 239 | - '/%F6/', // ö |
|
| 240 | - ]; |
|
| 241 | - $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 242 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 222 | + // Transformation des caractères accentués |
|
| 223 | + $pattern = [ |
|
| 224 | + '/%B0/', // ° |
|
| 225 | + '/%E8/', // è |
|
| 226 | + '/%E9/', // é |
|
| 227 | + '/%EA/', // ê |
|
| 228 | + '/%EB/', // ë |
|
| 229 | + '/%E7/', // ç |
|
| 230 | + '/%E0/', // à |
|
| 231 | + '/%E2/', // â |
|
| 232 | + '/%E4/', // ä |
|
| 233 | + '/%EE/', // î |
|
| 234 | + '/%EF/', // ï |
|
| 235 | + '/%F9/', // ù |
|
| 236 | + '/%FC/', // ü |
|
| 237 | + '/%FB/', // û |
|
| 238 | + '/%F4/', // ô |
|
| 239 | + '/%F6/', // ö |
|
| 240 | + ]; |
|
| 241 | + $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 242 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 243 | 243 | |
| 244 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 245 | - $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 246 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 244 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 245 | + $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 246 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 247 | 247 | |
| 248 | - $title .= time(); |
|
| 249 | - $title = md5($title); |
|
| 248 | + $title .= time(); |
|
| 249 | + $title = md5($title); |
|
| 250 | 250 | |
| 251 | - return $title; |
|
| 252 | - } |
|
| 251 | + return $title; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function getCloneLink() |
|
| 258 | - { |
|
| 259 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 254 | + /** |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function getCloneLink() |
|
| 258 | + { |
|
| 259 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 260 | 260 | |
| 261 | - return $ret; |
|
| 262 | - } |
|
| 261 | + return $ret; |
|
| 262 | + } |
|
| 263 | 263 | } |
@@ -104,23 +104,23 @@ discard block |
||
| 104 | 104 | { |
| 105 | 105 | global $smartobjectAdsenseHandler; |
| 106 | 106 | if ('' !== $this->getVar('style', 'n')) { |
| 107 | - $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 107 | + $ret = '<div style="'.$this->getVar('style', 'n').'">'; |
|
| 108 | 108 | } else { |
| 109 | 109 | $ret = '<div>'; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $ret .= '<script type="text/javascript"><!-- |
| 113 | -google_ad_client = "' . $this->getVar('client_id', 'n') . '"; |
|
| 114 | -google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . '; |
|
| 115 | -google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . '; |
|
| 116 | -google_ad_format = "' . $this->getVar('format', 'n') . '"; |
|
| 113 | +google_ad_client = "' . $this->getVar('client_id', 'n').'"; |
|
| 114 | +google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'].'; |
|
| 115 | +google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'].'; |
|
| 116 | +google_ad_format = "' . $this->getVar('format', 'n').'"; |
|
| 117 | 117 | google_ad_type = "text"; |
| 118 | 118 | google_ad_channel =""; |
| 119 | -google_color_border = "' . $this->getVar('border_color', 'n') . '"; |
|
| 120 | -google_color_bg = "' . $this->getVar('background_color', 'n') . '"; |
|
| 121 | -google_color_link = "' . $this->getVar('link_color', 'n') . '"; |
|
| 122 | -google_color_url = "' . $this->getVar('url_color', 'n') . '"; |
|
| 123 | -google_color_text = "' . $this->getVar('text_color', 'n') . '"; |
|
| 119 | +google_color_border = "' . $this->getVar('border_color', 'n').'"; |
|
| 120 | +google_color_bg = "' . $this->getVar('background_color', 'n').'"; |
|
| 121 | +google_color_link = "' . $this->getVar('link_color', 'n').'"; |
|
| 122 | +google_color_url = "' . $this->getVar('url_color', 'n').'"; |
|
| 123 | +google_color_text = "' . $this->getVar('text_color', 'n').'"; |
|
| 124 | 124 | //--></script> |
| 125 | 125 | <script type="text/javascript" |
| 126 | 126 | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function getXoopsCode() |
| 137 | 137 | { |
| 138 | - $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 138 | + $ret = '[adsense]'.$this->getVar('tag', 'n').'[/adsense]'; |
|
| 139 | 139 | |
| 140 | 140 | return $ret; |
| 141 | 141 | } |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function getCloneLink() |
| 258 | 258 | { |
| 259 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 259 | + $ret = '<a href="'.SMARTOBJECT_URL.'admin/adsense.php?op=clone&adsenseid='.$this->getVar('adsenseid').'"><img src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'editcopy.png" alt="'._CO_SOBJECT_ADSENSE_CLONE.'" title="'._CO_SOBJECT_ADSENSE_CLONE.'"></a>'; |
|
| 260 | 260 | |
| 261 | 261 | return $ret; |
| 262 | 262 | } |
@@ -30,12 +30,12 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartobjectLinkHandler extends Smartobject\SmartPersistableObjectHandler |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * SmartobjectLinkHandler constructor. |
|
| 35 | - * @param \XoopsDatabase $db |
|
| 36 | - */ |
|
| 37 | - public function __construct(\XoopsDatabase $db) |
|
| 38 | - { |
|
| 39 | - parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * SmartobjectLinkHandler constructor. |
|
| 35 | + * @param \XoopsDatabase $db |
|
| 36 | + */ |
|
| 37 | + public function __construct(\XoopsDatabase $db) |
|
| 38 | + { |
|
| 39 | + parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -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 | } |