@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class SmartobjectTag extends SmartMlObject |
| 37 | 37 | { |
| 38 | - /** |
|
| 39 | - * SmartobjectTag constructor. |
|
| 40 | - */ |
|
| 41 | - public function __construct() |
|
| 42 | - { |
|
| 43 | - $this->initVar('tagid', XOBJ_DTYPE_INT, '', true); |
|
| 44 | - $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true); |
|
| 45 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC); |
|
| 46 | - $this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC); |
|
| 38 | + /** |
|
| 39 | + * SmartobjectTag constructor. |
|
| 40 | + */ |
|
| 41 | + public function __construct() |
|
| 42 | + { |
|
| 43 | + $this->initVar('tagid', XOBJ_DTYPE_INT, '', true); |
|
| 44 | + $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true); |
|
| 45 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC); |
|
| 46 | + $this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC); |
|
| 47 | 47 | |
| 48 | - // call parent constructor to get Multilanguage field initiated |
|
| 49 | - $this->SmartMlObject(); |
|
| 50 | - } |
|
| 48 | + // call parent constructor to get Multilanguage field initiated |
|
| 49 | + $this->SmartMlObject(); |
|
| 50 | + } |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -55,27 +55,27 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | class SmartobjectTagHandler extends SmartPersistableMlObjectHandler |
| 57 | 57 | { |
| 58 | - /** |
|
| 59 | - * SmartobjectTagHandler constructor. |
|
| 60 | - * @param XoopsDatabase $db |
|
| 61 | - */ |
|
| 62 | - public function __construct(XoopsDatabase $db) |
|
| 63 | - { |
|
| 64 | - parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject'); |
|
| 65 | - } |
|
| 58 | + /** |
|
| 59 | + * SmartobjectTagHandler constructor. |
|
| 60 | + * @param XoopsDatabase $db |
|
| 61 | + */ |
|
| 62 | + public function __construct(XoopsDatabase $db) |
|
| 63 | + { |
|
| 64 | + parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject'); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return mixed |
|
| 69 | - */ |
|
| 70 | - public function getLanguages() |
|
| 71 | - { |
|
| 72 | - include_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 73 | - $aLanguages = XoopsLists::getLangList(); |
|
| 74 | - $ret['default'] = _CO_SOBJECT_ALL; |
|
| 75 | - foreach ($aLanguages as $lang) { |
|
| 76 | - $ret[$lang] = $lang; |
|
| 77 | - } |
|
| 67 | + /** |
|
| 68 | + * @return mixed |
|
| 69 | + */ |
|
| 70 | + public function getLanguages() |
|
| 71 | + { |
|
| 72 | + include_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 73 | + $aLanguages = XoopsLists::getLangList(); |
|
| 74 | + $ret['default'] = _CO_SOBJECT_ALL; |
|
| 75 | + foreach ($aLanguages as $lang) { |
|
| 76 | + $ret[$lang] = $lang; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return $ret; |
|
| 80 | - } |
|
| 79 | + return $ret; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -18,320 +18,320 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class SmartMetaGen |
| 20 | 20 | { |
| 21 | - public $_myts; |
|
| 22 | - |
|
| 23 | - public $_title; |
|
| 24 | - public $_original_title; |
|
| 25 | - public $_keywords; |
|
| 26 | - public $_meta_description; |
|
| 27 | - public $_categoryPath; |
|
| 28 | - public $_description; |
|
| 29 | - public $_minChar = 4; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * SmartMetaGen constructor. |
|
| 33 | - * @param $title |
|
| 34 | - * @param bool $keywords |
|
| 35 | - * @param bool $description |
|
| 36 | - * @param bool $categoryPath |
|
| 37 | - */ |
|
| 38 | - public function __construct($title, $keywords = false, $description = false, $categoryPath = false) |
|
| 39 | - { |
|
| 40 | - $this->_myts = MyTextSanitizer::getInstance(); |
|
| 41 | - $this->setCategoryPath($categoryPath); |
|
| 42 | - $this->setTitle($title); |
|
| 43 | - $this->setDescription($description); |
|
| 44 | - |
|
| 45 | - if (!$keywords) { |
|
| 46 | - $keywords = $this->createMetaKeywords(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /* $myts = MyTextSanitizer::getInstance(); |
|
| 21 | + public $_myts; |
|
| 22 | + |
|
| 23 | + public $_title; |
|
| 24 | + public $_original_title; |
|
| 25 | + public $_keywords; |
|
| 26 | + public $_meta_description; |
|
| 27 | + public $_categoryPath; |
|
| 28 | + public $_description; |
|
| 29 | + public $_minChar = 4; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * SmartMetaGen constructor. |
|
| 33 | + * @param $title |
|
| 34 | + * @param bool $keywords |
|
| 35 | + * @param bool $description |
|
| 36 | + * @param bool $categoryPath |
|
| 37 | + */ |
|
| 38 | + public function __construct($title, $keywords = false, $description = false, $categoryPath = false) |
|
| 39 | + { |
|
| 40 | + $this->_myts = MyTextSanitizer::getInstance(); |
|
| 41 | + $this->setCategoryPath($categoryPath); |
|
| 42 | + $this->setTitle($title); |
|
| 43 | + $this->setDescription($description); |
|
| 44 | + |
|
| 45 | + if (!$keywords) { |
|
| 46 | + $keywords = $this->createMetaKeywords(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /* $myts = MyTextSanitizer::getInstance(); |
|
| 50 | 50 | if (method_exists($myts, 'formatForML')) { |
| 51 | 51 | $keywords = $myts->formatForML($keywords); |
| 52 | 52 | $description = $myts->formatForML($description); |
| 53 | 53 | } |
| 54 | 54 | */ |
| 55 | - $this->setKeywords($keywords); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Return true if the string is length > 0 |
|
| 60 | - * |
|
| 61 | - * @credit psylove |
|
| 62 | - * |
|
| 63 | - * @var string $string Chaine de caract�re |
|
| 64 | - * @return boolean |
|
| 65 | - */ |
|
| 66 | - public function emptyString($var) |
|
| 67 | - { |
|
| 68 | - return (strlen($var) > 0); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Create a title for the short_url field of an article |
|
| 73 | - * |
|
| 74 | - * @credit psylove |
|
| 75 | - * |
|
| 76 | - * @var string $title title of the article |
|
| 77 | - * @param bool|string $withExt |
|
| 78 | - * @return string sort_url for the article |
|
| 79 | - */ |
|
| 80 | - public function generateSeoTitle($title = '', $withExt = true) |
|
| 81 | - { |
|
| 82 | - // Transformation de la chaine en minuscule |
|
| 83 | - // Codage de la chaine afin d'�viter les erreurs 500 en cas de caract�res impr�vus |
|
| 84 | - $title = rawurlencode(strtolower($title)); |
|
| 85 | - |
|
| 86 | - // Transformation des ponctuations |
|
| 87 | - $pattern = array( |
|
| 88 | - '/%09/', // Tab |
|
| 89 | - '/%20/', // Space |
|
| 90 | - '/%21/', // ! |
|
| 91 | - '/%22/', // " |
|
| 92 | - '/%23/', // # |
|
| 93 | - '/%25/', // % |
|
| 94 | - '/%26/', // & |
|
| 95 | - '/%27/', // ' |
|
| 96 | - '/%28/', // ( |
|
| 97 | - '/%29/', // ) |
|
| 98 | - '/%2C/', // , |
|
| 99 | - '/%2F/', // / |
|
| 100 | - '/%3A/', // : |
|
| 101 | - '/%3B/', // ; |
|
| 102 | - '/%3C/', // < |
|
| 103 | - '/%3D/', // = |
|
| 104 | - '/%3E/', // > |
|
| 105 | - '/%3F/', // ? |
|
| 106 | - '/%40/', // @ |
|
| 107 | - '/%5B/', // [ |
|
| 108 | - '/%5C/', // \ |
|
| 109 | - '/%5D/', // ] |
|
| 110 | - '/%5E/', // ^ |
|
| 111 | - '/%7B/', // { |
|
| 112 | - '/%7C/', // | |
|
| 113 | - '/%7D/', // } |
|
| 114 | - '/%7E/', // ~ |
|
| 115 | - "/\./" // . |
|
| 116 | - ); |
|
| 117 | - $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
| 118 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 119 | - |
|
| 120 | - // Transformation des caract�res accentu�s |
|
| 121 | - $pattern = array( |
|
| 122 | - '/%B0/', // ° |
|
| 123 | - '/%E8/', // è |
|
| 124 | - '/%E9/', // é |
|
| 125 | - '/%EA/', // ê |
|
| 126 | - '/%EB/', // ë |
|
| 127 | - '/%E7/', // ç |
|
| 128 | - '/%E0/', // à |
|
| 129 | - '/%E2/', // â |
|
| 130 | - '/%E4/', // ä |
|
| 131 | - '/%EE/', // î |
|
| 132 | - '/%EF/', // ï |
|
| 133 | - '/%F9/', // ù |
|
| 134 | - '/%FC/', // ü |
|
| 135 | - '/%FB/', // û |
|
| 136 | - '/%F4/', // ô |
|
| 137 | - '/%F6/', // ö |
|
| 138 | - ); |
|
| 139 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
| 140 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 141 | - |
|
| 142 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 143 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
| 144 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 145 | - |
|
| 146 | - if (count($title) > 0) { |
|
| 147 | - if ($withExt) { |
|
| 148 | - $title .= '.html'; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $title; |
|
| 152 | - } else { |
|
| 153 | - return ''; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param $document |
|
| 159 | - * @return mixed |
|
| 160 | - */ |
|
| 161 | - public function html2text($document) |
|
| 162 | - { |
|
| 163 | - return smart_html2text($document); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param $title |
|
| 168 | - */ |
|
| 169 | - public function setTitle($title) |
|
| 170 | - { |
|
| 171 | - global $xoopsModule, $xoopsModuleConfig; |
|
| 172 | - $this->_title = $this->html2text($title); |
|
| 173 | - $this->_title = $this->purifyText($this->_title); |
|
| 174 | - $this->_original_title = $this->_title; |
|
| 175 | - |
|
| 176 | - $moduleName = $xoopsModule->getVar('name'); |
|
| 177 | - |
|
| 178 | - $titleTag = array(); |
|
| 179 | - |
|
| 180 | - $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true; |
|
| 181 | - |
|
| 182 | - if ($moduleName && $show_mod_name_breadcrumb) { |
|
| 183 | - $titleTag['module'] = $moduleName; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if (isset($this->_title) && ($this->_title !== '') && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
| 187 | - $titleTag['title'] = $this->_title; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if (isset($this->_categoryPath) && ($this->_categoryPath !== '')) { |
|
| 191 | - $titleTag['category'] = $this->_categoryPath; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
| 195 | - |
|
| 196 | - if (isset($titleTag['category']) && $titleTag['category'] !== '') { |
|
| 197 | - if ($ret !== '') { |
|
| 198 | - $ret .= ' - '; |
|
| 199 | - } |
|
| 200 | - $ret .= $titleTag['category']; |
|
| 201 | - } |
|
| 202 | - if (isset($titleTag['module']) && $titleTag['module'] !== '') { |
|
| 203 | - if ($ret !== '') { |
|
| 204 | - $ret .= ' - '; |
|
| 205 | - } |
|
| 206 | - $ret .= $titleTag['module']; |
|
| 207 | - } |
|
| 208 | - $this->_title = $ret; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @param $keywords |
|
| 213 | - */ |
|
| 214 | - public function setKeywords($keywords) |
|
| 215 | - { |
|
| 216 | - $this->_keywords = $keywords; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param $categoryPath |
|
| 221 | - */ |
|
| 222 | - public function setCategoryPath($categoryPath) |
|
| 223 | - { |
|
| 224 | - $categoryPath = $this->html2text($categoryPath); |
|
| 225 | - $this->_categoryPath = $categoryPath; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @param $description |
|
| 230 | - */ |
|
| 231 | - public function setDescription($description) |
|
| 232 | - { |
|
| 233 | - if (!$description) { |
|
| 234 | - global $xoopsModuleConfig; |
|
| 235 | - if (isset($xoopsModuleConfig['module_meta_description'])) { |
|
| 236 | - $description = $xoopsModuleConfig['module_meta_description']; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $description = $this->html2text($description); |
|
| 241 | - $description = $this->purifyText($description); |
|
| 242 | - |
|
| 243 | - $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
| 244 | - $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
| 245 | - $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
| 246 | - $description = stripslashes($description); |
|
| 247 | - |
|
| 248 | - $this->_description = $description; |
|
| 249 | - $this->_meta_description = $this->createMetaDescription(); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - public function createTitleTag() |
|
| 253 | - { |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @param $text |
|
| 258 | - * @param bool $keyword |
|
| 259 | - * @return mixed|string |
|
| 260 | - */ |
|
| 261 | - public function purifyText($text, $keyword = false) |
|
| 262 | - { |
|
| 263 | - return smart_purifyText($text, $keyword); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param int $maxWords |
|
| 268 | - * @return string |
|
| 269 | - */ |
|
| 270 | - public function createMetaDescription($maxWords = 100) |
|
| 271 | - { |
|
| 272 | - $words = array(); |
|
| 273 | - $words = explode(' ', $this->_description); |
|
| 274 | - |
|
| 275 | - // Only keep $maxWords words |
|
| 276 | - $newWords = array(); |
|
| 277 | - $i = 0; |
|
| 278 | - |
|
| 279 | - while ($i < $maxWords - 1 && $i < count($words)) { |
|
| 280 | - $newWords[] = $words[$i]; |
|
| 281 | - ++$i; |
|
| 282 | - } |
|
| 283 | - $ret = implode(' ', $newWords); |
|
| 284 | - |
|
| 285 | - return $ret; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @param $text |
|
| 290 | - * @param $minChar |
|
| 291 | - * @return array |
|
| 292 | - */ |
|
| 293 | - public function findMetaKeywords($text, $minChar) |
|
| 294 | - { |
|
| 295 | - $keywords = array(); |
|
| 296 | - |
|
| 297 | - $text = $this->purifyText($text); |
|
| 298 | - $text = $this->html2text($text); |
|
| 299 | - |
|
| 300 | - $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
| 301 | - $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
| 302 | - $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
| 303 | - $text = stripslashes($text); |
|
| 304 | - $text = |
|
| 305 | - |
|
| 306 | - $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 307 | - |
|
| 308 | - foreach ($originalKeywords as $originalKeyword) { |
|
| 309 | - $secondRoundKeywords = explode("'", $originalKeyword); |
|
| 310 | - foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
| 311 | - if (strlen($secondRoundKeyword) >= $minChar) { |
|
| 312 | - if (!in_array($secondRoundKeyword, $keywords)) { |
|
| 313 | - $keywords[] = trim($secondRoundKeyword); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return $keywords; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - public function createMetaKeywords() |
|
| 326 | - { |
|
| 327 | - global $xoopsModuleConfig; |
|
| 328 | - $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
| 329 | - if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) && $xoopsModuleConfig['moduleMetaKeywords'] !== '') { |
|
| 330 | - $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
|
| 331 | - $keywords = array_merge($keywords, $moduleKeywords); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /* Commenting this out as it may cause problem on XOOPS ML websites |
|
| 55 | + $this->setKeywords($keywords); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Return true if the string is length > 0 |
|
| 60 | + * |
|
| 61 | + * @credit psylove |
|
| 62 | + * |
|
| 63 | + * @var string $string Chaine de caract�re |
|
| 64 | + * @return boolean |
|
| 65 | + */ |
|
| 66 | + public function emptyString($var) |
|
| 67 | + { |
|
| 68 | + return (strlen($var) > 0); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Create a title for the short_url field of an article |
|
| 73 | + * |
|
| 74 | + * @credit psylove |
|
| 75 | + * |
|
| 76 | + * @var string $title title of the article |
|
| 77 | + * @param bool|string $withExt |
|
| 78 | + * @return string sort_url for the article |
|
| 79 | + */ |
|
| 80 | + public function generateSeoTitle($title = '', $withExt = true) |
|
| 81 | + { |
|
| 82 | + // Transformation de la chaine en minuscule |
|
| 83 | + // Codage de la chaine afin d'�viter les erreurs 500 en cas de caract�res impr�vus |
|
| 84 | + $title = rawurlencode(strtolower($title)); |
|
| 85 | + |
|
| 86 | + // Transformation des ponctuations |
|
| 87 | + $pattern = array( |
|
| 88 | + '/%09/', // Tab |
|
| 89 | + '/%20/', // Space |
|
| 90 | + '/%21/', // ! |
|
| 91 | + '/%22/', // " |
|
| 92 | + '/%23/', // # |
|
| 93 | + '/%25/', // % |
|
| 94 | + '/%26/', // & |
|
| 95 | + '/%27/', // ' |
|
| 96 | + '/%28/', // ( |
|
| 97 | + '/%29/', // ) |
|
| 98 | + '/%2C/', // , |
|
| 99 | + '/%2F/', // / |
|
| 100 | + '/%3A/', // : |
|
| 101 | + '/%3B/', // ; |
|
| 102 | + '/%3C/', // < |
|
| 103 | + '/%3D/', // = |
|
| 104 | + '/%3E/', // > |
|
| 105 | + '/%3F/', // ? |
|
| 106 | + '/%40/', // @ |
|
| 107 | + '/%5B/', // [ |
|
| 108 | + '/%5C/', // \ |
|
| 109 | + '/%5D/', // ] |
|
| 110 | + '/%5E/', // ^ |
|
| 111 | + '/%7B/', // { |
|
| 112 | + '/%7C/', // | |
|
| 113 | + '/%7D/', // } |
|
| 114 | + '/%7E/', // ~ |
|
| 115 | + "/\./" // . |
|
| 116 | + ); |
|
| 117 | + $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
| 118 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 119 | + |
|
| 120 | + // Transformation des caract�res accentu�s |
|
| 121 | + $pattern = array( |
|
| 122 | + '/%B0/', // ° |
|
| 123 | + '/%E8/', // è |
|
| 124 | + '/%E9/', // é |
|
| 125 | + '/%EA/', // ê |
|
| 126 | + '/%EB/', // ë |
|
| 127 | + '/%E7/', // ç |
|
| 128 | + '/%E0/', // à |
|
| 129 | + '/%E2/', // â |
|
| 130 | + '/%E4/', // ä |
|
| 131 | + '/%EE/', // î |
|
| 132 | + '/%EF/', // ï |
|
| 133 | + '/%F9/', // ù |
|
| 134 | + '/%FC/', // ü |
|
| 135 | + '/%FB/', // û |
|
| 136 | + '/%F4/', // ô |
|
| 137 | + '/%F6/', // ö |
|
| 138 | + ); |
|
| 139 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
| 140 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 141 | + |
|
| 142 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 143 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
| 144 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 145 | + |
|
| 146 | + if (count($title) > 0) { |
|
| 147 | + if ($withExt) { |
|
| 148 | + $title .= '.html'; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $title; |
|
| 152 | + } else { |
|
| 153 | + return ''; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param $document |
|
| 159 | + * @return mixed |
|
| 160 | + */ |
|
| 161 | + public function html2text($document) |
|
| 162 | + { |
|
| 163 | + return smart_html2text($document); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param $title |
|
| 168 | + */ |
|
| 169 | + public function setTitle($title) |
|
| 170 | + { |
|
| 171 | + global $xoopsModule, $xoopsModuleConfig; |
|
| 172 | + $this->_title = $this->html2text($title); |
|
| 173 | + $this->_title = $this->purifyText($this->_title); |
|
| 174 | + $this->_original_title = $this->_title; |
|
| 175 | + |
|
| 176 | + $moduleName = $xoopsModule->getVar('name'); |
|
| 177 | + |
|
| 178 | + $titleTag = array(); |
|
| 179 | + |
|
| 180 | + $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true; |
|
| 181 | + |
|
| 182 | + if ($moduleName && $show_mod_name_breadcrumb) { |
|
| 183 | + $titleTag['module'] = $moduleName; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if (isset($this->_title) && ($this->_title !== '') && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
| 187 | + $titleTag['title'] = $this->_title; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if (isset($this->_categoryPath) && ($this->_categoryPath !== '')) { |
|
| 191 | + $titleTag['category'] = $this->_categoryPath; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
| 195 | + |
|
| 196 | + if (isset($titleTag['category']) && $titleTag['category'] !== '') { |
|
| 197 | + if ($ret !== '') { |
|
| 198 | + $ret .= ' - '; |
|
| 199 | + } |
|
| 200 | + $ret .= $titleTag['category']; |
|
| 201 | + } |
|
| 202 | + if (isset($titleTag['module']) && $titleTag['module'] !== '') { |
|
| 203 | + if ($ret !== '') { |
|
| 204 | + $ret .= ' - '; |
|
| 205 | + } |
|
| 206 | + $ret .= $titleTag['module']; |
|
| 207 | + } |
|
| 208 | + $this->_title = $ret; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @param $keywords |
|
| 213 | + */ |
|
| 214 | + public function setKeywords($keywords) |
|
| 215 | + { |
|
| 216 | + $this->_keywords = $keywords; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param $categoryPath |
|
| 221 | + */ |
|
| 222 | + public function setCategoryPath($categoryPath) |
|
| 223 | + { |
|
| 224 | + $categoryPath = $this->html2text($categoryPath); |
|
| 225 | + $this->_categoryPath = $categoryPath; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @param $description |
|
| 230 | + */ |
|
| 231 | + public function setDescription($description) |
|
| 232 | + { |
|
| 233 | + if (!$description) { |
|
| 234 | + global $xoopsModuleConfig; |
|
| 235 | + if (isset($xoopsModuleConfig['module_meta_description'])) { |
|
| 236 | + $description = $xoopsModuleConfig['module_meta_description']; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $description = $this->html2text($description); |
|
| 241 | + $description = $this->purifyText($description); |
|
| 242 | + |
|
| 243 | + $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
| 244 | + $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
| 245 | + $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
| 246 | + $description = stripslashes($description); |
|
| 247 | + |
|
| 248 | + $this->_description = $description; |
|
| 249 | + $this->_meta_description = $this->createMetaDescription(); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + public function createTitleTag() |
|
| 253 | + { |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @param $text |
|
| 258 | + * @param bool $keyword |
|
| 259 | + * @return mixed|string |
|
| 260 | + */ |
|
| 261 | + public function purifyText($text, $keyword = false) |
|
| 262 | + { |
|
| 263 | + return smart_purifyText($text, $keyword); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param int $maxWords |
|
| 268 | + * @return string |
|
| 269 | + */ |
|
| 270 | + public function createMetaDescription($maxWords = 100) |
|
| 271 | + { |
|
| 272 | + $words = array(); |
|
| 273 | + $words = explode(' ', $this->_description); |
|
| 274 | + |
|
| 275 | + // Only keep $maxWords words |
|
| 276 | + $newWords = array(); |
|
| 277 | + $i = 0; |
|
| 278 | + |
|
| 279 | + while ($i < $maxWords - 1 && $i < count($words)) { |
|
| 280 | + $newWords[] = $words[$i]; |
|
| 281 | + ++$i; |
|
| 282 | + } |
|
| 283 | + $ret = implode(' ', $newWords); |
|
| 284 | + |
|
| 285 | + return $ret; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @param $text |
|
| 290 | + * @param $minChar |
|
| 291 | + * @return array |
|
| 292 | + */ |
|
| 293 | + public function findMetaKeywords($text, $minChar) |
|
| 294 | + { |
|
| 295 | + $keywords = array(); |
|
| 296 | + |
|
| 297 | + $text = $this->purifyText($text); |
|
| 298 | + $text = $this->html2text($text); |
|
| 299 | + |
|
| 300 | + $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
| 301 | + $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
| 302 | + $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
| 303 | + $text = stripslashes($text); |
|
| 304 | + $text = |
|
| 305 | + |
|
| 306 | + $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 307 | + |
|
| 308 | + foreach ($originalKeywords as $originalKeyword) { |
|
| 309 | + $secondRoundKeywords = explode("'", $originalKeyword); |
|
| 310 | + foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
| 311 | + if (strlen($secondRoundKeyword) >= $minChar) { |
|
| 312 | + if (!in_array($secondRoundKeyword, $keywords)) { |
|
| 313 | + $keywords[] = trim($secondRoundKeyword); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return $keywords; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + public function createMetaKeywords() |
|
| 326 | + { |
|
| 327 | + global $xoopsModuleConfig; |
|
| 328 | + $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
| 329 | + if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) && $xoopsModuleConfig['moduleMetaKeywords'] !== '') { |
|
| 330 | + $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
|
| 331 | + $keywords = array_merge($keywords, $moduleKeywords); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /* Commenting this out as it may cause problem on XOOPS ML websites |
|
| 335 | 335 | $return_keywords = array(); |
| 336 | 336 | |
| 337 | 337 | // Cleaning for duplicate keywords |
@@ -341,43 +341,43 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | }*/ |
| 343 | 343 | |
| 344 | - // Only take the first 90 keywords |
|
| 345 | - $newKeywords = array(); |
|
| 346 | - $i = 0; |
|
| 347 | - while ($i < 90 - 1 && isset($keywords[$i])) { |
|
| 348 | - $newKeywords[] = $keywords[$i]; |
|
| 349 | - ++$i; |
|
| 350 | - } |
|
| 351 | - $ret = implode(', ', $newKeywords); |
|
| 352 | - |
|
| 353 | - return $ret; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - public function autoBuildMeta_keywords() |
|
| 357 | - { |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - public function buildAutoMetaTags() |
|
| 361 | - { |
|
| 362 | - global $xoopsModule, $xoopsModuleConfig; |
|
| 363 | - |
|
| 364 | - $this->_keywords = $this->createMetaKeywords(); |
|
| 365 | - $this->_meta_description = $this->createMetaDescription(); |
|
| 366 | - $this->_title = $this->createTitleTag(); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - public function createMetaTags() |
|
| 370 | - { |
|
| 371 | - global $xoopsTpl, $xoTheme; |
|
| 372 | - |
|
| 373 | - if (is_object($xoTheme)) { |
|
| 374 | - $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
| 375 | - $xoTheme->addMeta('meta', 'description', $this->_description); |
|
| 376 | - $xoTheme->addMeta('meta', 'title', $this->_title); |
|
| 377 | - } else { |
|
| 378 | - $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
| 379 | - $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
| 380 | - } |
|
| 381 | - $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
| 382 | - } |
|
| 344 | + // Only take the first 90 keywords |
|
| 345 | + $newKeywords = array(); |
|
| 346 | + $i = 0; |
|
| 347 | + while ($i < 90 - 1 && isset($keywords[$i])) { |
|
| 348 | + $newKeywords[] = $keywords[$i]; |
|
| 349 | + ++$i; |
|
| 350 | + } |
|
| 351 | + $ret = implode(', ', $newKeywords); |
|
| 352 | + |
|
| 353 | + return $ret; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + public function autoBuildMeta_keywords() |
|
| 357 | + { |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + public function buildAutoMetaTags() |
|
| 361 | + { |
|
| 362 | + global $xoopsModule, $xoopsModuleConfig; |
|
| 363 | + |
|
| 364 | + $this->_keywords = $this->createMetaKeywords(); |
|
| 365 | + $this->_meta_description = $this->createMetaDescription(); |
|
| 366 | + $this->_title = $this->createTitleTag(); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + public function createMetaTags() |
|
| 370 | + { |
|
| 371 | + global $xoopsTpl, $xoTheme; |
|
| 372 | + |
|
| 373 | + if (is_object($xoTheme)) { |
|
| 374 | + $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
| 375 | + $xoTheme->addMeta('meta', 'description', $this->_description); |
|
| 376 | + $xoTheme->addMeta('meta', 'title', $this->_title); |
|
| 377 | + } else { |
|
| 378 | + $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
| 379 | + $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
| 380 | + } |
|
| 381 | + $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
| 382 | + } |
|
| 383 | 383 | } |
@@ -13,169 +13,169 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class SmartObjectsRegistry |
| 15 | 15 | { |
| 16 | - public $_registryArray; |
|
| 16 | + public $_registryArray; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Access the only instance of this class |
|
| 20 | - * |
|
| 21 | - * @return XoopsObject |
|
| 22 | - * |
|
| 23 | - * @static |
|
| 24 | - * @staticvar object |
|
| 25 | - */ |
|
| 26 | - public static function getInstance() |
|
| 27 | - { |
|
| 28 | - static $instance; |
|
| 29 | - if (null === $instance) { |
|
| 30 | - $instance = new static(); |
|
| 31 | - } |
|
| 18 | + /** |
|
| 19 | + * Access the only instance of this class |
|
| 20 | + * |
|
| 21 | + * @return XoopsObject |
|
| 22 | + * |
|
| 23 | + * @static |
|
| 24 | + * @staticvar object |
|
| 25 | + */ |
|
| 26 | + public static function getInstance() |
|
| 27 | + { |
|
| 28 | + static $instance; |
|
| 29 | + if (null === $instance) { |
|
| 30 | + $instance = new static(); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return $instance; |
|
| 34 | - } |
|
| 33 | + return $instance; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Adding objects to the registry |
|
| 38 | - * |
|
| 39 | - * @param SmartPersistableObjectHandler $handler of the objects to add |
|
| 40 | - * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 41 | - * @return FALSE if an error occured |
|
| 42 | - */ |
|
| 43 | - public function addObjectsFromHandler(&$handler, $criteria = false) |
|
| 44 | - { |
|
| 45 | - if (method_exists($handler, 'getObjects')) { |
|
| 46 | - $objects = $handler->getObjects($criteria, true); |
|
| 47 | - $this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects; |
|
| 36 | + /** |
|
| 37 | + * Adding objects to the registry |
|
| 38 | + * |
|
| 39 | + * @param SmartPersistableObjectHandler $handler of the objects to add |
|
| 40 | + * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 41 | + * @return FALSE if an error occured |
|
| 42 | + */ |
|
| 43 | + public function addObjectsFromHandler(&$handler, $criteria = false) |
|
| 44 | + { |
|
| 45 | + if (method_exists($handler, 'getObjects')) { |
|
| 46 | + $objects = $handler->getObjects($criteria, true); |
|
| 47 | + $this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects; |
|
| 48 | 48 | |
| 49 | - return $objects; |
|
| 50 | - } else { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - } |
|
| 49 | + return $objects; |
|
| 50 | + } else { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Adding objects to the registry from an item name |
|
| 57 | - * This method will fetch the handler of the item / module and call the addObjectsFromHandler |
|
| 58 | - * |
|
| 59 | - * @param string $item name of the item |
|
| 60 | - * @param bool|string $modulename name of the module |
|
| 61 | - * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 62 | - * @return FALSE if an error occured |
|
| 63 | - */ |
|
| 64 | - public function addObjectsFromItemName($item, $modulename = false, $criteria = false) |
|
| 65 | - { |
|
| 66 | - if (!$modulename) { |
|
| 67 | - global $xoopsModule; |
|
| 68 | - if (!is_object($xoopsModule)) { |
|
| 69 | - return false; |
|
| 70 | - } else { |
|
| 71 | - $modulename = $xoopsModule->dirname(); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - $objectHandler = xoops_getModuleHandler($item, $modulename); |
|
| 55 | + /** |
|
| 56 | + * Adding objects to the registry from an item name |
|
| 57 | + * This method will fetch the handler of the item / module and call the addObjectsFromHandler |
|
| 58 | + * |
|
| 59 | + * @param string $item name of the item |
|
| 60 | + * @param bool|string $modulename name of the module |
|
| 61 | + * @param bool|CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key) |
|
| 62 | + * @return FALSE if an error occured |
|
| 63 | + */ |
|
| 64 | + public function addObjectsFromItemName($item, $modulename = false, $criteria = false) |
|
| 65 | + { |
|
| 66 | + if (!$modulename) { |
|
| 67 | + global $xoopsModule; |
|
| 68 | + if (!is_object($xoopsModule)) { |
|
| 69 | + return false; |
|
| 70 | + } else { |
|
| 71 | + $modulename = $xoopsModule->dirname(); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + $objectHandler = xoops_getModuleHandler($item, $modulename); |
|
| 75 | 75 | |
| 76 | - if (method_exists($objectHandler, 'getObjects')) { |
|
| 77 | - $objects = $objectHandler->getObjects($criteria, true); |
|
| 78 | - $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects; |
|
| 76 | + if (method_exists($objectHandler, 'getObjects')) { |
|
| 77 | + $objects = $objectHandler->getObjects($criteria, true); |
|
| 78 | + $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects; |
|
| 79 | 79 | |
| 80 | - return $objects; |
|
| 81 | - } else { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 84 | - } |
|
| 80 | + return $objects; |
|
| 81 | + } else { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Fetching objects from the registry |
|
| 88 | - * |
|
| 89 | - * @param string $itemname |
|
| 90 | - * @param string $modulename |
|
| 91 | - * |
|
| 92 | - * @return the requested objects or FALSE if they don't exists in the registry |
|
| 93 | - */ |
|
| 94 | - public function getObjects($itemname, $modulename) |
|
| 95 | - { |
|
| 96 | - if (!$modulename) { |
|
| 97 | - global $xoopsModule; |
|
| 98 | - if (!is_object($xoopsModule)) { |
|
| 99 | - return false; |
|
| 100 | - } else { |
|
| 101 | - $modulename = $xoopsModule->dirname(); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - if (isset($this->_registryArray['objects'][$modulename][$itemname])) { |
|
| 105 | - return $this->_registryArray['objects'][$modulename][$itemname]; |
|
| 106 | - } else { |
|
| 107 | - // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 108 | - $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 109 | - if (method_exists($moduleHandler, 'getObjects')) { |
|
| 110 | - $objects = $moduleHandler->getObjects(); |
|
| 111 | - } |
|
| 112 | - $this->_registryArray['objects'][$modulename][$itemname] = $objects; |
|
| 86 | + /** |
|
| 87 | + * Fetching objects from the registry |
|
| 88 | + * |
|
| 89 | + * @param string $itemname |
|
| 90 | + * @param string $modulename |
|
| 91 | + * |
|
| 92 | + * @return the requested objects or FALSE if they don't exists in the registry |
|
| 93 | + */ |
|
| 94 | + public function getObjects($itemname, $modulename) |
|
| 95 | + { |
|
| 96 | + if (!$modulename) { |
|
| 97 | + global $xoopsModule; |
|
| 98 | + if (!is_object($xoopsModule)) { |
|
| 99 | + return false; |
|
| 100 | + } else { |
|
| 101 | + $modulename = $xoopsModule->dirname(); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + if (isset($this->_registryArray['objects'][$modulename][$itemname])) { |
|
| 105 | + return $this->_registryArray['objects'][$modulename][$itemname]; |
|
| 106 | + } else { |
|
| 107 | + // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 108 | + $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 109 | + if (method_exists($moduleHandler, 'getObjects')) { |
|
| 110 | + $objects = $moduleHandler->getObjects(); |
|
| 111 | + } |
|
| 112 | + $this->_registryArray['objects'][$modulename][$itemname] = $objects; |
|
| 113 | 113 | |
| 114 | - return $objects; |
|
| 115 | - } |
|
| 116 | - } |
|
| 114 | + return $objects; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Fetching objects from the registry, as a list: objectid => identifier |
|
| 120 | - * |
|
| 121 | - * @param string $itemname |
|
| 122 | - * @param string $modulename |
|
| 123 | - * |
|
| 124 | - * @return the requested objects or FALSE if they don't exists in the registry |
|
| 125 | - */ |
|
| 126 | - public function getList($itemname, $modulename) |
|
| 127 | - { |
|
| 128 | - if (!$modulename) { |
|
| 129 | - global $xoopsModule; |
|
| 130 | - if (!is_object($xoopsModule)) { |
|
| 131 | - return false; |
|
| 132 | - } else { |
|
| 133 | - $modulename = $xoopsModule->dirname(); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - if (isset($this->_registryArray['list'][$modulename][$itemname])) { |
|
| 137 | - return $this->_registryArray['list'][$modulename][$itemname]; |
|
| 138 | - } else { |
|
| 139 | - // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 140 | - $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 141 | - if (method_exists($moduleHandler, 'getList')) { |
|
| 142 | - $objects = $moduleHandler->getList(); |
|
| 143 | - } |
|
| 144 | - $this->_registryArray['list'][$modulename][$itemname] = $objects; |
|
| 118 | + /** |
|
| 119 | + * Fetching objects from the registry, as a list: objectid => identifier |
|
| 120 | + * |
|
| 121 | + * @param string $itemname |
|
| 122 | + * @param string $modulename |
|
| 123 | + * |
|
| 124 | + * @return the requested objects or FALSE if they don't exists in the registry |
|
| 125 | + */ |
|
| 126 | + public function getList($itemname, $modulename) |
|
| 127 | + { |
|
| 128 | + if (!$modulename) { |
|
| 129 | + global $xoopsModule; |
|
| 130 | + if (!is_object($xoopsModule)) { |
|
| 131 | + return false; |
|
| 132 | + } else { |
|
| 133 | + $modulename = $xoopsModule->dirname(); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + if (isset($this->_registryArray['list'][$modulename][$itemname])) { |
|
| 137 | + return $this->_registryArray['list'][$modulename][$itemname]; |
|
| 138 | + } else { |
|
| 139 | + // if they were not in registry, let's fetch them and add them to the reigistry |
|
| 140 | + $moduleHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 141 | + if (method_exists($moduleHandler, 'getList')) { |
|
| 142 | + $objects = $moduleHandler->getList(); |
|
| 143 | + } |
|
| 144 | + $this->_registryArray['list'][$modulename][$itemname] = $objects; |
|
| 145 | 145 | |
| 146 | - return $objects; |
|
| 147 | - } |
|
| 148 | - } |
|
| 146 | + return $objects; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Retreive a single object |
|
| 152 | - * |
|
| 153 | - * @param string $itemname |
|
| 154 | - * @param string $key |
|
| 155 | - * |
|
| 156 | - * @param bool $modulename |
|
| 157 | - * @return the requestd object or FALSE if they don't exists in the registry |
|
| 158 | - */ |
|
| 159 | - public function getSingleObject($itemname, $key, $modulename = false) |
|
| 160 | - { |
|
| 161 | - if (!$modulename) { |
|
| 162 | - global $xoopsModule; |
|
| 163 | - if (!is_object($xoopsModule)) { |
|
| 164 | - return false; |
|
| 165 | - } else { |
|
| 166 | - $modulename = $xoopsModule->dirname(); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) { |
|
| 170 | - return $this->_registryArray['objects'][$modulename][$itemname][$key]; |
|
| 171 | - } else { |
|
| 172 | - $objectHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 173 | - $object = $objectHandler->get($key); |
|
| 174 | - if (!$object->isNew()) { |
|
| 175 | - return $object; |
|
| 176 | - } else { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 150 | + /** |
|
| 151 | + * Retreive a single object |
|
| 152 | + * |
|
| 153 | + * @param string $itemname |
|
| 154 | + * @param string $key |
|
| 155 | + * |
|
| 156 | + * @param bool $modulename |
|
| 157 | + * @return the requestd object or FALSE if they don't exists in the registry |
|
| 158 | + */ |
|
| 159 | + public function getSingleObject($itemname, $key, $modulename = false) |
|
| 160 | + { |
|
| 161 | + if (!$modulename) { |
|
| 162 | + global $xoopsModule; |
|
| 163 | + if (!is_object($xoopsModule)) { |
|
| 164 | + return false; |
|
| 165 | + } else { |
|
| 166 | + $modulename = $xoopsModule->dirname(); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) { |
|
| 170 | + return $this->_registryArray['objects'][$modulename][$itemname][$key]; |
|
| 171 | + } else { |
|
| 172 | + $objectHandler = xoops_getModuleHandler($itemname, $modulename); |
|
| 173 | + $object = $objectHandler->get($key); |
|
| 174 | + if (!$object->isNew()) { |
|
| 175 | + return $object; |
|
| 176 | + } else { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -11,18 +11,18 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class SmartobjectPermissionHandler extends XoopsObjectHandler |
| 13 | 13 | { |
| 14 | - public $handler; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * SmartobjectPermissionHandler constructor. |
|
| 18 | - * @param XoopsDatabase $handler |
|
| 19 | - */ |
|
| 20 | - public function __construct($handler) |
|
| 21 | - { |
|
| 22 | - $this->handler = $handler; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /* |
|
| 14 | + public $handler; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * SmartobjectPermissionHandler constructor. |
|
| 18 | + * @param XoopsDatabase $handler |
|
| 19 | + */ |
|
| 20 | + public function __construct($handler) |
|
| 21 | + { |
|
| 22 | + $this->handler = $handler; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /* |
|
| 26 | 26 | * Returns permissions for a certain type |
| 27 | 27 | * |
| 28 | 28 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -30,73 +30,73 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return array |
| 32 | 32 | */ |
| 33 | - /** |
|
| 34 | - * @param $gperm_name |
|
| 35 | - * @param null $id |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 38 | - public function getGrantedGroups($gperm_name, $id = null) |
|
| 39 | - { |
|
| 40 | - static $groups; |
|
| 41 | - |
|
| 42 | - if (!isset($groups[$gperm_name]) || ($id !== null && !isset($groups[$gperm_name][$id]))) { |
|
| 43 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 44 | - //Get group permissions handler |
|
| 45 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 46 | - |
|
| 47 | - //Get groups allowed for an item id |
|
| 48 | - $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 49 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
| 50 | - } |
|
| 51 | - //Return the permission array |
|
| 52 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param $item_ids_array |
|
| 57 | - * @param bool $gperm_name |
|
| 58 | - * @return array |
|
| 59 | - */ |
|
| 60 | - public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 61 | - { |
|
| 62 | - static $groups; |
|
| 63 | - |
|
| 64 | - if ($gperm_name) { |
|
| 65 | - if (isset($groups[$gperm_name])) { |
|
| 66 | - return $groups[$gperm_name]; |
|
| 67 | - } |
|
| 68 | - } else { |
|
| 69 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 70 | - return $groups; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 74 | - |
|
| 75 | - $criteria = new CriteriaCompo(); |
|
| 76 | - $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 77 | - |
|
| 78 | - if ($gperm_name) { |
|
| 79 | - $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - //Get group permissions handler |
|
| 83 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 84 | - |
|
| 85 | - $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 86 | - |
|
| 87 | - foreach ($permissionsObj as $permissionObj) { |
|
| 88 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - //Return the permission array |
|
| 92 | - if ($gperm_name) { |
|
| 93 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array(); |
|
| 94 | - } else { |
|
| 95 | - return isset($groups) ? $groups : array(); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /* |
|
| 33 | + /** |
|
| 34 | + * @param $gperm_name |
|
| 35 | + * @param null $id |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | + public function getGrantedGroups($gperm_name, $id = null) |
|
| 39 | + { |
|
| 40 | + static $groups; |
|
| 41 | + |
|
| 42 | + if (!isset($groups[$gperm_name]) || ($id !== null && !isset($groups[$gperm_name][$id]))) { |
|
| 43 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 44 | + //Get group permissions handler |
|
| 45 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 46 | + |
|
| 47 | + //Get groups allowed for an item id |
|
| 48 | + $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 49 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
| 50 | + } |
|
| 51 | + //Return the permission array |
|
| 52 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param $item_ids_array |
|
| 57 | + * @param bool $gperm_name |
|
| 58 | + * @return array |
|
| 59 | + */ |
|
| 60 | + public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 61 | + { |
|
| 62 | + static $groups; |
|
| 63 | + |
|
| 64 | + if ($gperm_name) { |
|
| 65 | + if (isset($groups[$gperm_name])) { |
|
| 66 | + return $groups[$gperm_name]; |
|
| 67 | + } |
|
| 68 | + } else { |
|
| 69 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 70 | + return $groups; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 74 | + |
|
| 75 | + $criteria = new CriteriaCompo(); |
|
| 76 | + $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 77 | + |
|
| 78 | + if ($gperm_name) { |
|
| 79 | + $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + //Get group permissions handler |
|
| 83 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 84 | + |
|
| 85 | + $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 86 | + |
|
| 87 | + foreach ($permissionsObj as $permissionObj) { |
|
| 88 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + //Return the permission array |
|
| 92 | + if ($gperm_name) { |
|
| 93 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array(); |
|
| 94 | + } else { |
|
| 95 | + return isset($groups) ? $groups : array(); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /* |
|
| 100 | 100 | * Returns permissions for a certain type |
| 101 | 101 | * |
| 102 | 102 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -104,123 +104,123 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return array |
| 106 | 106 | */ |
| 107 | - /** |
|
| 108 | - * @param $gperm_name |
|
| 109 | - * @param null $id |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function getGrantedItems($gperm_name, $id = null) |
|
| 113 | - { |
|
| 114 | - global $xoopsUser; |
|
| 115 | - static $permissions; |
|
| 116 | - |
|
| 117 | - if (!isset($permissions[$gperm_name]) || ($id !== null && !isset($permissions[$gperm_name][$id]))) { |
|
| 118 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 119 | - |
|
| 120 | - if (is_object($smartModule)) { |
|
| 121 | - |
|
| 122 | - //Get group permissions handler |
|
| 123 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 124 | - |
|
| 125 | - //Get user's groups |
|
| 126 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 127 | - |
|
| 128 | - //Get all allowed item ids in this module and for this user's groups |
|
| 129 | - $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 130 | - $permissions[$gperm_name] = $userpermissions; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - //Return the permission array |
|
| 134 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array(); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param $id |
|
| 139 | - */ |
|
| 140 | - public function storeAllPermissionsForId($id) |
|
| 141 | - { |
|
| 142 | - foreach ($this->handler->getPermissions() as $permission) { |
|
| 143 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Saves permissions for the selected category |
|
| 149 | - * |
|
| 150 | - * saveCategory_Permissions() |
|
| 151 | - * |
|
| 152 | - * @param array $groups : group with granted permission |
|
| 153 | - * @param $itemid |
|
| 154 | - * @param string $perm_name : name of the permission |
|
| 155 | - * @return bool : TRUE if the no errors occured |
|
| 156 | - * @internal param int $categoryID: categoryID on which we are setting permissions for Categories and Forums |
|
| 157 | - */ |
|
| 158 | - |
|
| 159 | - public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 160 | - { |
|
| 161 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 162 | - |
|
| 163 | - $result = true; |
|
| 164 | - $module_id = $smartModule->getVar('mid'); |
|
| 165 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 166 | - |
|
| 167 | - // First, if the permissions are already there, delete them |
|
| 168 | - $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 169 | - //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 170 | - //exit; |
|
| 171 | - // Save the new permissions |
|
| 172 | - |
|
| 173 | - if (count($groups) > 0) { |
|
| 174 | - foreach ($groups as $group_id) { |
|
| 175 | - $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $result; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Delete all permission for a specific item |
|
| 184 | - * |
|
| 185 | - * deletePermissions() |
|
| 186 | - * |
|
| 187 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
| 188 | - * @param $gperm_name |
|
| 189 | - * @return bool: TRUE if the no errors occured |
|
| 190 | - */ |
|
| 191 | - public function deletePermissions($itemid, $gperm_name) |
|
| 192 | - { |
|
| 193 | - global $xoopsModule; |
|
| 194 | - |
|
| 195 | - $smartModule =& smartsection_getModuleInfo(); |
|
| 196 | - |
|
| 197 | - $result = true; |
|
| 198 | - $module_id = $smartModule->getVar('mid'); |
|
| 199 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 200 | - |
|
| 201 | - $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 202 | - |
|
| 203 | - return $result; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Checks if the user has access to a specific permission on a given object |
|
| 208 | - * |
|
| 209 | - * @param string $gperm_name name of the permission to test |
|
| 210 | - * @param int $gperm_itemid id of the object to check |
|
| 211 | - * @return boolean: TRUE if user has access, FALSE if not |
|
| 212 | - **/ |
|
| 213 | - public function accessGranted($gperm_name, $gperm_itemid) |
|
| 214 | - { |
|
| 215 | - global $xoopsUser; |
|
| 216 | - |
|
| 217 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 218 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 219 | - $gperm_modid = $smartModule->getVar('mid'); |
|
| 220 | - |
|
| 221 | - //Get group permissions handler |
|
| 222 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 223 | - |
|
| 224 | - return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 225 | - } |
|
| 107 | + /** |
|
| 108 | + * @param $gperm_name |
|
| 109 | + * @param null $id |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function getGrantedItems($gperm_name, $id = null) |
|
| 113 | + { |
|
| 114 | + global $xoopsUser; |
|
| 115 | + static $permissions; |
|
| 116 | + |
|
| 117 | + if (!isset($permissions[$gperm_name]) || ($id !== null && !isset($permissions[$gperm_name][$id]))) { |
|
| 118 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 119 | + |
|
| 120 | + if (is_object($smartModule)) { |
|
| 121 | + |
|
| 122 | + //Get group permissions handler |
|
| 123 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 124 | + |
|
| 125 | + //Get user's groups |
|
| 126 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 127 | + |
|
| 128 | + //Get all allowed item ids in this module and for this user's groups |
|
| 129 | + $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 130 | + $permissions[$gperm_name] = $userpermissions; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + //Return the permission array |
|
| 134 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array(); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param $id |
|
| 139 | + */ |
|
| 140 | + public function storeAllPermissionsForId($id) |
|
| 141 | + { |
|
| 142 | + foreach ($this->handler->getPermissions() as $permission) { |
|
| 143 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Saves permissions for the selected category |
|
| 149 | + * |
|
| 150 | + * saveCategory_Permissions() |
|
| 151 | + * |
|
| 152 | + * @param array $groups : group with granted permission |
|
| 153 | + * @param $itemid |
|
| 154 | + * @param string $perm_name : name of the permission |
|
| 155 | + * @return bool : TRUE if the no errors occured |
|
| 156 | + * @internal param int $categoryID: categoryID on which we are setting permissions for Categories and Forums |
|
| 157 | + */ |
|
| 158 | + |
|
| 159 | + public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 160 | + { |
|
| 161 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 162 | + |
|
| 163 | + $result = true; |
|
| 164 | + $module_id = $smartModule->getVar('mid'); |
|
| 165 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 166 | + |
|
| 167 | + // First, if the permissions are already there, delete them |
|
| 168 | + $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 169 | + //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 170 | + //exit; |
|
| 171 | + // Save the new permissions |
|
| 172 | + |
|
| 173 | + if (count($groups) > 0) { |
|
| 174 | + foreach ($groups as $group_id) { |
|
| 175 | + $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $result; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Delete all permission for a specific item |
|
| 184 | + * |
|
| 185 | + * deletePermissions() |
|
| 186 | + * |
|
| 187 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
| 188 | + * @param $gperm_name |
|
| 189 | + * @return bool: TRUE if the no errors occured |
|
| 190 | + */ |
|
| 191 | + public function deletePermissions($itemid, $gperm_name) |
|
| 192 | + { |
|
| 193 | + global $xoopsModule; |
|
| 194 | + |
|
| 195 | + $smartModule =& smartsection_getModuleInfo(); |
|
| 196 | + |
|
| 197 | + $result = true; |
|
| 198 | + $module_id = $smartModule->getVar('mid'); |
|
| 199 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 200 | + |
|
| 201 | + $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 202 | + |
|
| 203 | + return $result; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Checks if the user has access to a specific permission on a given object |
|
| 208 | + * |
|
| 209 | + * @param string $gperm_name name of the permission to test |
|
| 210 | + * @param int $gperm_itemid id of the object to check |
|
| 211 | + * @return boolean: TRUE if user has access, FALSE if not |
|
| 212 | + **/ |
|
| 213 | + public function accessGranted($gperm_name, $gperm_itemid) |
|
| 214 | + { |
|
| 215 | + global $xoopsUser; |
|
| 216 | + |
|
| 217 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
| 218 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 219 | + $gperm_modid = $smartModule->getVar('mid'); |
|
| 220 | + |
|
| 221 | + //Get group permissions handler |
|
| 222 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 223 | + |
|
| 224 | + return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -36,87 +36,87 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | class SmartobjectAdsense extends SmartObject |
| 38 | 38 | { |
| 39 | - /** |
|
| 40 | - * SmartobjectAdsense constructor. |
|
| 41 | - */ |
|
| 42 | - public function __construct() |
|
| 43 | - { |
|
| 44 | - $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
| 45 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
| 46 | - $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
| 47 | - $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
| 48 | - $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
| 49 | - $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 50 | - $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 51 | - $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
| 52 | - $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
| 53 | - $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
| 54 | - $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
| 55 | - |
|
| 56 | - $this->setControl('format', array( |
|
| 57 | - 'handler' => 'adsense', |
|
| 58 | - 'method' => 'getFormats' |
|
| 59 | - )); |
|
| 60 | - |
|
| 61 | - $this->setControl('border_color', array( |
|
| 62 | - 'name' => 'text', |
|
| 63 | - 'size' => 6, |
|
| 64 | - 'maxlength' => 6 |
|
| 65 | - )); |
|
| 66 | - |
|
| 67 | - $this->setControl('background_color', array( |
|
| 68 | - 'name' => 'text', |
|
| 69 | - 'size' => 6, |
|
| 70 | - 'maxlength' => 6 |
|
| 71 | - )); |
|
| 72 | - |
|
| 73 | - $this->setControl('link_color', array( |
|
| 74 | - 'name' => 'text', |
|
| 75 | - 'size' => 6, |
|
| 76 | - 'maxlength' => 6 |
|
| 77 | - )); |
|
| 78 | - |
|
| 79 | - $this->setControl('url_color', array( |
|
| 80 | - 'name' => 'text', |
|
| 81 | - 'size' => 6, |
|
| 82 | - 'maxlength' => 6 |
|
| 83 | - )); |
|
| 84 | - |
|
| 85 | - $this->setControl('text_color', array( |
|
| 86 | - 'name' => 'text', |
|
| 87 | - 'size' => 6, |
|
| 88 | - 'maxlength' => 6 |
|
| 89 | - )); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $key |
|
| 94 | - * @param string $format |
|
| 95 | - * @return mixed |
|
| 96 | - */ |
|
| 97 | - public function getVar($key, $format = 's') |
|
| 98 | - { |
|
| 99 | - if ($format === 's' && in_array($key, array())) { |
|
| 100 | - // return call_user_func(array($this, $key)); |
|
| 101 | - return $this->{$key}(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return parent::getVar($key, $format); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function render() |
|
| 111 | - { |
|
| 112 | - global $smartobjectAdsenseHandler; |
|
| 113 | - if ($this->getVar('style', 'n') !== '') { |
|
| 114 | - $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 115 | - } else { |
|
| 116 | - $ret = '<div>'; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $ret .= '<script type="text/javascript"><!-- |
|
| 39 | + /** |
|
| 40 | + * SmartobjectAdsense constructor. |
|
| 41 | + */ |
|
| 42 | + public function __construct() |
|
| 43 | + { |
|
| 44 | + $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
| 45 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
| 46 | + $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
| 47 | + $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
| 48 | + $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
| 49 | + $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 50 | + $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 51 | + $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
| 52 | + $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
| 53 | + $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
| 54 | + $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
| 55 | + |
|
| 56 | + $this->setControl('format', array( |
|
| 57 | + 'handler' => 'adsense', |
|
| 58 | + 'method' => 'getFormats' |
|
| 59 | + )); |
|
| 60 | + |
|
| 61 | + $this->setControl('border_color', array( |
|
| 62 | + 'name' => 'text', |
|
| 63 | + 'size' => 6, |
|
| 64 | + 'maxlength' => 6 |
|
| 65 | + )); |
|
| 66 | + |
|
| 67 | + $this->setControl('background_color', array( |
|
| 68 | + 'name' => 'text', |
|
| 69 | + 'size' => 6, |
|
| 70 | + 'maxlength' => 6 |
|
| 71 | + )); |
|
| 72 | + |
|
| 73 | + $this->setControl('link_color', array( |
|
| 74 | + 'name' => 'text', |
|
| 75 | + 'size' => 6, |
|
| 76 | + 'maxlength' => 6 |
|
| 77 | + )); |
|
| 78 | + |
|
| 79 | + $this->setControl('url_color', array( |
|
| 80 | + 'name' => 'text', |
|
| 81 | + 'size' => 6, |
|
| 82 | + 'maxlength' => 6 |
|
| 83 | + )); |
|
| 84 | + |
|
| 85 | + $this->setControl('text_color', array( |
|
| 86 | + 'name' => 'text', |
|
| 87 | + 'size' => 6, |
|
| 88 | + 'maxlength' => 6 |
|
| 89 | + )); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $key |
|
| 94 | + * @param string $format |
|
| 95 | + * @return mixed |
|
| 96 | + */ |
|
| 97 | + public function getVar($key, $format = 's') |
|
| 98 | + { |
|
| 99 | + if ($format === 's' && in_array($key, array())) { |
|
| 100 | + // return call_user_func(array($this, $key)); |
|
| 101 | + return $this->{$key}(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return parent::getVar($key, $format); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function render() |
|
| 111 | + { |
|
| 112 | + global $smartobjectAdsenseHandler; |
|
| 113 | + if ($this->getVar('style', 'n') !== '') { |
|
| 114 | + $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 115 | + } else { |
|
| 116 | + $ret = '<div>'; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $ret .= '<script type="text/javascript"><!-- |
|
| 120 | 120 | google_ad_client = "' . $this->getVar('client_id', 'n') . '"; |
| 121 | 121 | google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . '; |
| 122 | 122 | google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . '; |
@@ -134,120 +134,120 @@ discard block |
||
| 134 | 134 | </script> |
| 135 | 135 | </div>'; |
| 136 | 136 | |
| 137 | - return $ret; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function getXoopsCode() |
|
| 144 | - { |
|
| 145 | - $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 146 | - |
|
| 147 | - return $ret; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param $var |
|
| 152 | - * @return bool |
|
| 153 | - */ |
|
| 154 | - public function emptyString($var) |
|
| 155 | - { |
|
| 156 | - return (strlen($var) > 0); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return mixed|string |
|
| 161 | - */ |
|
| 162 | - public function generateTag() |
|
| 163 | - { |
|
| 164 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 165 | - $title = xoops_substr($title, 0, 10, ''); |
|
| 166 | - // Transformation des ponctuations |
|
| 167 | - $pattern = array( |
|
| 168 | - '/%09/', // Tab |
|
| 169 | - '/%20/', // Space |
|
| 170 | - '/%21/', // ! |
|
| 171 | - '/%22/', // " |
|
| 172 | - '/%23/', // # |
|
| 173 | - '/%25/', // % |
|
| 174 | - '/%26/', // & |
|
| 175 | - '/%27/', // ' |
|
| 176 | - '/%28/', // ( |
|
| 177 | - '/%29/', // ) |
|
| 178 | - '/%2C/', // , |
|
| 179 | - '/%2F/', // / |
|
| 180 | - '/%3A/', // : |
|
| 181 | - '/%3B/', // ; |
|
| 182 | - '/%3C/', // < |
|
| 183 | - '/%3D/', // = |
|
| 184 | - '/%3E/', // > |
|
| 185 | - '/%3F/', // ? |
|
| 186 | - '/%40/', // @ |
|
| 187 | - '/%5B/', // [ |
|
| 188 | - '/%5C/', // \ |
|
| 189 | - '/%5D/', // ] |
|
| 190 | - '/%5E/', // ^ |
|
| 191 | - '/%7B/', // { |
|
| 192 | - '/%7C/', // | |
|
| 193 | - '/%7D/', // } |
|
| 194 | - '/%7E/', // ~ |
|
| 195 | - "/\./" // . |
|
| 196 | - ); |
|
| 197 | - $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
| 198 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 199 | - |
|
| 200 | - // Transformation des caract�res accentu�s |
|
| 201 | - $pattern = array( |
|
| 202 | - '/%B0/', // ° |
|
| 203 | - '/%E8/', // è |
|
| 204 | - '/%E9/', // é |
|
| 205 | - '/%EA/', // ê |
|
| 206 | - '/%EB/', // ë |
|
| 207 | - '/%E7/', // ç |
|
| 208 | - '/%E0/', // à |
|
| 209 | - '/%E2/', // â |
|
| 210 | - '/%E4/', // ä |
|
| 211 | - '/%EE/', // î |
|
| 212 | - '/%EF/', // ï |
|
| 213 | - '/%F9/', // ù |
|
| 214 | - '/%FC/', // ü |
|
| 215 | - '/%FB/', // û |
|
| 216 | - '/%F4/', // ô |
|
| 217 | - '/%F6/', // ö |
|
| 218 | - ); |
|
| 219 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
| 220 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 221 | - |
|
| 222 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 223 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
| 224 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 225 | - |
|
| 226 | - $title .= time(); |
|
| 227 | - $title = md5($title); |
|
| 228 | - |
|
| 229 | - return $title; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @return string |
|
| 234 | - */ |
|
| 235 | - public function getCloneLink() |
|
| 236 | - { |
|
| 237 | - $ret = '<a href="' . |
|
| 238 | - SMARTOBJECT_URL . |
|
| 239 | - 'admin/adsense.php?op=clone&adsenseid=' . |
|
| 240 | - $this->getVar('adsenseid') . |
|
| 241 | - '"><img src="' . |
|
| 242 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
| 243 | - 'editcopy.png" alt="' . |
|
| 244 | - _CO_SOBJECT_ADSENSE_CLONE . |
|
| 245 | - '" title="' . |
|
| 246 | - _CO_SOBJECT_ADSENSE_CLONE . |
|
| 247 | - '" /></a>'; |
|
| 248 | - |
|
| 249 | - return $ret; |
|
| 250 | - } |
|
| 137 | + return $ret; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function getXoopsCode() |
|
| 144 | + { |
|
| 145 | + $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 146 | + |
|
| 147 | + return $ret; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param $var |
|
| 152 | + * @return bool |
|
| 153 | + */ |
|
| 154 | + public function emptyString($var) |
|
| 155 | + { |
|
| 156 | + return (strlen($var) > 0); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return mixed|string |
|
| 161 | + */ |
|
| 162 | + public function generateTag() |
|
| 163 | + { |
|
| 164 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 165 | + $title = xoops_substr($title, 0, 10, ''); |
|
| 166 | + // Transformation des ponctuations |
|
| 167 | + $pattern = array( |
|
| 168 | + '/%09/', // Tab |
|
| 169 | + '/%20/', // Space |
|
| 170 | + '/%21/', // ! |
|
| 171 | + '/%22/', // " |
|
| 172 | + '/%23/', // # |
|
| 173 | + '/%25/', // % |
|
| 174 | + '/%26/', // & |
|
| 175 | + '/%27/', // ' |
|
| 176 | + '/%28/', // ( |
|
| 177 | + '/%29/', // ) |
|
| 178 | + '/%2C/', // , |
|
| 179 | + '/%2F/', // / |
|
| 180 | + '/%3A/', // : |
|
| 181 | + '/%3B/', // ; |
|
| 182 | + '/%3C/', // < |
|
| 183 | + '/%3D/', // = |
|
| 184 | + '/%3E/', // > |
|
| 185 | + '/%3F/', // ? |
|
| 186 | + '/%40/', // @ |
|
| 187 | + '/%5B/', // [ |
|
| 188 | + '/%5C/', // \ |
|
| 189 | + '/%5D/', // ] |
|
| 190 | + '/%5E/', // ^ |
|
| 191 | + '/%7B/', // { |
|
| 192 | + '/%7C/', // | |
|
| 193 | + '/%7D/', // } |
|
| 194 | + '/%7E/', // ~ |
|
| 195 | + "/\./" // . |
|
| 196 | + ); |
|
| 197 | + $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
| 198 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 199 | + |
|
| 200 | + // Transformation des caract�res accentu�s |
|
| 201 | + $pattern = array( |
|
| 202 | + '/%B0/', // ° |
|
| 203 | + '/%E8/', // è |
|
| 204 | + '/%E9/', // é |
|
| 205 | + '/%EA/', // ê |
|
| 206 | + '/%EB/', // ë |
|
| 207 | + '/%E7/', // ç |
|
| 208 | + '/%E0/', // à |
|
| 209 | + '/%E2/', // â |
|
| 210 | + '/%E4/', // ä |
|
| 211 | + '/%EE/', // î |
|
| 212 | + '/%EF/', // ï |
|
| 213 | + '/%F9/', // ù |
|
| 214 | + '/%FC/', // ü |
|
| 215 | + '/%FB/', // û |
|
| 216 | + '/%F4/', // ô |
|
| 217 | + '/%F6/', // ö |
|
| 218 | + ); |
|
| 219 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
| 220 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 221 | + |
|
| 222 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 223 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
| 224 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 225 | + |
|
| 226 | + $title .= time(); |
|
| 227 | + $title = md5($title); |
|
| 228 | + |
|
| 229 | + return $title; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @return string |
|
| 234 | + */ |
|
| 235 | + public function getCloneLink() |
|
| 236 | + { |
|
| 237 | + $ret = '<a href="' . |
|
| 238 | + SMARTOBJECT_URL . |
|
| 239 | + 'admin/adsense.php?op=clone&adsenseid=' . |
|
| 240 | + $this->getVar('adsenseid') . |
|
| 241 | + '"><img src="' . |
|
| 242 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
| 243 | + 'editcopy.png" alt="' . |
|
| 244 | + _CO_SOBJECT_ADSENSE_CLONE . |
|
| 245 | + '" title="' . |
|
| 246 | + _CO_SOBJECT_ADSENSE_CLONE . |
|
| 247 | + '" /></a>'; |
|
| 248 | + |
|
| 249 | + return $ret; |
|
| 250 | + } |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -255,116 +255,116 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | class SmartobjectAdsenseHandler extends SmartPersistableObjectHandler |
| 257 | 257 | { |
| 258 | - public $adFormats; |
|
| 259 | - public $adFormatsList; |
|
| 260 | - public $objects = false; |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * SmartobjectAdsenseHandler constructor. |
|
| 264 | - * @param XoopsDatabase $db |
|
| 265 | - */ |
|
| 266 | - public function __construct(XoopsDatabase $db) |
|
| 267 | - { |
|
| 268 | - parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
| 269 | - $this->adFormats = array(); |
|
| 270 | - $this->adFormatsList = array(); |
|
| 271 | - |
|
| 272 | - $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 273 | - $this->adFormats['728x90_as']['width'] = 728; |
|
| 274 | - $this->adFormats['728x90_as']['height'] = 90; |
|
| 275 | - $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 276 | - |
|
| 277 | - $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 278 | - $this->adFormats['468x60_as']['width'] = 468; |
|
| 279 | - $this->adFormats['468x60_as']['height'] = 60; |
|
| 280 | - $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 281 | - |
|
| 282 | - $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 283 | - $this->adFormats['234x60_as']['width'] = 234; |
|
| 284 | - $this->adFormats['234x60_as']['height'] = 60; |
|
| 285 | - $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 286 | - |
|
| 287 | - $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 288 | - $this->adFormats['120x600_as']['width'] = 120; |
|
| 289 | - $this->adFormats['120x600_as']['height'] = 600; |
|
| 290 | - $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 291 | - |
|
| 292 | - $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 293 | - $this->adFormats['160x600_as']['width'] = 160; |
|
| 294 | - $this->adFormats['160x600_as']['height'] = 600; |
|
| 295 | - $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 296 | - |
|
| 297 | - $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 298 | - $this->adFormats['120x240_as']['width'] = 120; |
|
| 299 | - $this->adFormats['120x240_as']['height'] = 240; |
|
| 300 | - $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 301 | - |
|
| 302 | - $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 303 | - $this->adFormats['336x280_as']['width'] = 136; |
|
| 304 | - $this->adFormats['336x280_as']['height'] = 280; |
|
| 305 | - $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 306 | - |
|
| 307 | - $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 308 | - $this->adFormats['300x250_as']['width'] = 300; |
|
| 309 | - $this->adFormats['300x250_as']['height'] = 250; |
|
| 310 | - $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 311 | - |
|
| 312 | - $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 313 | - $this->adFormats['250x250_as']['width'] = 250; |
|
| 314 | - $this->adFormats['250x250_as']['height'] = 250; |
|
| 315 | - $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 316 | - |
|
| 317 | - $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 318 | - $this->adFormats['200x200_as']['width'] = 200; |
|
| 319 | - $this->adFormats['200x200_as']['height'] = 200; |
|
| 320 | - $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 321 | - |
|
| 322 | - $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 323 | - $this->adFormats['180x150_as']['width'] = 180; |
|
| 324 | - $this->adFormats['180x150_as']['height'] = 150; |
|
| 325 | - $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 326 | - |
|
| 327 | - $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 328 | - $this->adFormats['125x125_as']['width'] = 125; |
|
| 329 | - $this->adFormats['125x125_as']['height'] = 125; |
|
| 330 | - $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @return array |
|
| 335 | - */ |
|
| 336 | - public function getFormats() |
|
| 337 | - { |
|
| 338 | - return $this->adFormatsList; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @param $obj |
|
| 343 | - * @return bool |
|
| 344 | - */ |
|
| 345 | - public function beforeSave($obj) |
|
| 346 | - { |
|
| 347 | - if ($obj->getVar('tag') === '') { |
|
| 348 | - $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return true; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * @return array|bool |
|
| 356 | - */ |
|
| 357 | - public function getAdsensesByTag() |
|
| 358 | - { |
|
| 359 | - if (!$this->objects) { |
|
| 360 | - $adsensesObj = $this->getObjects(null, true); |
|
| 361 | - $ret = array(); |
|
| 362 | - foreach ($adsensesObj as $adsenseObj) { |
|
| 363 | - $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 364 | - } |
|
| 365 | - $this->objects = $ret; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $this->objects; |
|
| 369 | - } |
|
| 258 | + public $adFormats; |
|
| 259 | + public $adFormatsList; |
|
| 260 | + public $objects = false; |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * SmartobjectAdsenseHandler constructor. |
|
| 264 | + * @param XoopsDatabase $db |
|
| 265 | + */ |
|
| 266 | + public function __construct(XoopsDatabase $db) |
|
| 267 | + { |
|
| 268 | + parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
| 269 | + $this->adFormats = array(); |
|
| 270 | + $this->adFormatsList = array(); |
|
| 271 | + |
|
| 272 | + $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 273 | + $this->adFormats['728x90_as']['width'] = 728; |
|
| 274 | + $this->adFormats['728x90_as']['height'] = 90; |
|
| 275 | + $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 276 | + |
|
| 277 | + $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 278 | + $this->adFormats['468x60_as']['width'] = 468; |
|
| 279 | + $this->adFormats['468x60_as']['height'] = 60; |
|
| 280 | + $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 281 | + |
|
| 282 | + $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 283 | + $this->adFormats['234x60_as']['width'] = 234; |
|
| 284 | + $this->adFormats['234x60_as']['height'] = 60; |
|
| 285 | + $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 286 | + |
|
| 287 | + $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 288 | + $this->adFormats['120x600_as']['width'] = 120; |
|
| 289 | + $this->adFormats['120x600_as']['height'] = 600; |
|
| 290 | + $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 291 | + |
|
| 292 | + $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 293 | + $this->adFormats['160x600_as']['width'] = 160; |
|
| 294 | + $this->adFormats['160x600_as']['height'] = 600; |
|
| 295 | + $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 296 | + |
|
| 297 | + $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 298 | + $this->adFormats['120x240_as']['width'] = 120; |
|
| 299 | + $this->adFormats['120x240_as']['height'] = 240; |
|
| 300 | + $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 301 | + |
|
| 302 | + $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 303 | + $this->adFormats['336x280_as']['width'] = 136; |
|
| 304 | + $this->adFormats['336x280_as']['height'] = 280; |
|
| 305 | + $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 306 | + |
|
| 307 | + $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 308 | + $this->adFormats['300x250_as']['width'] = 300; |
|
| 309 | + $this->adFormats['300x250_as']['height'] = 250; |
|
| 310 | + $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 311 | + |
|
| 312 | + $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 313 | + $this->adFormats['250x250_as']['width'] = 250; |
|
| 314 | + $this->adFormats['250x250_as']['height'] = 250; |
|
| 315 | + $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 316 | + |
|
| 317 | + $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 318 | + $this->adFormats['200x200_as']['width'] = 200; |
|
| 319 | + $this->adFormats['200x200_as']['height'] = 200; |
|
| 320 | + $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 321 | + |
|
| 322 | + $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 323 | + $this->adFormats['180x150_as']['width'] = 180; |
|
| 324 | + $this->adFormats['180x150_as']['height'] = 150; |
|
| 325 | + $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 326 | + |
|
| 327 | + $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 328 | + $this->adFormats['125x125_as']['width'] = 125; |
|
| 329 | + $this->adFormats['125x125_as']['height'] = 125; |
|
| 330 | + $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @return array |
|
| 335 | + */ |
|
| 336 | + public function getFormats() |
|
| 337 | + { |
|
| 338 | + return $this->adFormatsList; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @param $obj |
|
| 343 | + * @return bool |
|
| 344 | + */ |
|
| 345 | + public function beforeSave($obj) |
|
| 346 | + { |
|
| 347 | + if ($obj->getVar('tag') === '') { |
|
| 348 | + $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return true; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * @return array|bool |
|
| 356 | + */ |
|
| 357 | + public function getAdsensesByTag() |
|
| 358 | + { |
|
| 359 | + if (!$this->objects) { |
|
| 360 | + $adsensesObj = $this->getObjects(null, true); |
|
| 361 | + $ret = array(); |
|
| 362 | + foreach ($adsensesObj as $adsenseObj) { |
|
| 363 | + $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 364 | + } |
|
| 365 | + $this->objects = $ret; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $this->objects; |
|
| 369 | + } |
|
| 370 | 370 | } |
@@ -30,790 +30,790 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartObjectForm extends XoopsThemeForm |
| 32 | 32 | { |
| 33 | - public $targetObject = null; |
|
| 34 | - public $form_fields = null; |
|
| 35 | - public $_cancel_js_action = false; |
|
| 36 | - public $_custom_button = false; |
|
| 37 | - public $_captcha = false; |
|
| 38 | - public $_form_name = false; |
|
| 39 | - public $_form_caption = false; |
|
| 40 | - public $_submit_button_caption = false; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * SmartobjectForm constructor. |
|
| 44 | - * @param string $target |
|
| 45 | - * @param string $form_name |
|
| 46 | - * @param string $form_caption |
|
| 47 | - * @param string $form_action |
|
| 48 | - * @param null $form_fields |
|
| 49 | - * @param bool $submit_button_caption |
|
| 50 | - * @param bool $cancel_js_action |
|
| 51 | - * @param bool $captcha |
|
| 52 | - */ |
|
| 53 | - public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false) |
|
| 54 | - { |
|
| 55 | - $this->targetObject =& $target; |
|
| 56 | - $this->form_fields = $form_fields; |
|
| 57 | - $this->_cancel_js_action = $cancel_js_action; |
|
| 58 | - $this->_captcha = $captcha; |
|
| 59 | - $this->_form_name = $form_name; |
|
| 60 | - $this->_form_caption = $form_caption; |
|
| 61 | - $this->_submit_button_caption = $submit_button_caption; |
|
| 62 | - |
|
| 63 | - if (!isset($form_action)) { |
|
| 64 | - $form_action = xoops_getenv('PHP_SELF'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - parent::__construct($form_caption, $form_name, $form_action); |
|
| 68 | - $this->setExtra('enctype="multipart/form-data"'); |
|
| 69 | - |
|
| 70 | - $this->createElements(); |
|
| 71 | - |
|
| 72 | - if ($captcha) { |
|
| 73 | - $this->addCaptcha(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $this->createPermissionControls(); |
|
| 77 | - |
|
| 78 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function addCaptcha() |
|
| 82 | - { |
|
| 83 | - include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'); |
|
| 84 | - $this->addElement(new XoopsFormCaptcha(), true); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param $name |
|
| 89 | - * @param $caption |
|
| 90 | - * @param bool $onclick |
|
| 91 | - */ |
|
| 92 | - public function addCustomButton($name, $caption, $onclick = false) |
|
| 93 | - { |
|
| 94 | - $custom_button_array = array( |
|
| 95 | - 'name' => $name, |
|
| 96 | - 'caption' => $caption, |
|
| 97 | - 'onclick' => $onclick |
|
| 98 | - ); |
|
| 99 | - $this->_custom_button[] = $custom_button_array; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Add an element to the form |
|
| 104 | - * |
|
| 105 | - * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 106 | - * @param bool $key |
|
| 107 | - * @param bool $var |
|
| 108 | - * @param bool|string $required is this a "required" element? |
|
| 109 | - */ |
|
| 110 | - public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 111 | - { |
|
| 112 | - if ($key) { |
|
| 113 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
| 114 | - $formElement->setExtra('disabled="disabled"'); |
|
| 115 | - $formElement->setName($key . '-readonly'); |
|
| 116 | - // Since this element is disable, we still want to pass it's value in the form |
|
| 117 | - $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 118 | - $this->addElement($hidden); |
|
| 119 | - } |
|
| 120 | - $formElement->setDescription($var['form_dsc']); |
|
| 121 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 122 | - $hidden = new XoopsFormHidden('changedField', false); |
|
| 123 | - $this->addElement($hidden); |
|
| 124 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 125 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 126 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 127 | - } else { |
|
| 128 | - if (isset($var['form_extra'])) { |
|
| 129 | - $formElement->setExtra($var['form_extra']); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - $controls = $this->targetObject->controls; |
|
| 133 | - if (isset($controls[$key]['js'])) { |
|
| 134 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 135 | - } |
|
| 136 | - parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
| 137 | - } else { |
|
| 138 | - parent::addElement($formElement, $required === 'notset' ? false : true); |
|
| 139 | - } |
|
| 140 | - unset($formElement); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - public function createElements() |
|
| 144 | - { |
|
| 145 | - $controls = $this->targetObject->controls; |
|
| 146 | - $vars = $this->targetObject->vars; |
|
| 147 | - foreach ($vars as $key => $var) { |
|
| 148 | - |
|
| 149 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 150 | - // need to be displayed, then we only create an hidden field |
|
| 151 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 152 | - $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
| 153 | - $this->addElement($elementToAdd, $key, $var, false); |
|
| 154 | - unset($elementToAdd); |
|
| 155 | - // If not, the we need to create the proper form control for this fields |
|
| 156 | - } else { |
|
| 157 | - // If this field has a specific control, we will use it |
|
| 158 | - |
|
| 159 | - if ($key === 'parentid') { |
|
| 160 | - /** |
|
| 161 | - * Why this ? |
|
| 162 | - */ |
|
| 163 | - } |
|
| 164 | - if (isset($controls[$key])) { |
|
| 165 | - /* If the control has name, it's because it's an object already present in the script |
|
| 33 | + public $targetObject = null; |
|
| 34 | + public $form_fields = null; |
|
| 35 | + public $_cancel_js_action = false; |
|
| 36 | + public $_custom_button = false; |
|
| 37 | + public $_captcha = false; |
|
| 38 | + public $_form_name = false; |
|
| 39 | + public $_form_caption = false; |
|
| 40 | + public $_submit_button_caption = false; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * SmartobjectForm constructor. |
|
| 44 | + * @param string $target |
|
| 45 | + * @param string $form_name |
|
| 46 | + * @param string $form_caption |
|
| 47 | + * @param string $form_action |
|
| 48 | + * @param null $form_fields |
|
| 49 | + * @param bool $submit_button_caption |
|
| 50 | + * @param bool $cancel_js_action |
|
| 51 | + * @param bool $captcha |
|
| 52 | + */ |
|
| 53 | + public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false) |
|
| 54 | + { |
|
| 55 | + $this->targetObject =& $target; |
|
| 56 | + $this->form_fields = $form_fields; |
|
| 57 | + $this->_cancel_js_action = $cancel_js_action; |
|
| 58 | + $this->_captcha = $captcha; |
|
| 59 | + $this->_form_name = $form_name; |
|
| 60 | + $this->_form_caption = $form_caption; |
|
| 61 | + $this->_submit_button_caption = $submit_button_caption; |
|
| 62 | + |
|
| 63 | + if (!isset($form_action)) { |
|
| 64 | + $form_action = xoops_getenv('PHP_SELF'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + parent::__construct($form_caption, $form_name, $form_action); |
|
| 68 | + $this->setExtra('enctype="multipart/form-data"'); |
|
| 69 | + |
|
| 70 | + $this->createElements(); |
|
| 71 | + |
|
| 72 | + if ($captcha) { |
|
| 73 | + $this->addCaptcha(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $this->createPermissionControls(); |
|
| 77 | + |
|
| 78 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function addCaptcha() |
|
| 82 | + { |
|
| 83 | + include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'); |
|
| 84 | + $this->addElement(new XoopsFormCaptcha(), true); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param $name |
|
| 89 | + * @param $caption |
|
| 90 | + * @param bool $onclick |
|
| 91 | + */ |
|
| 92 | + public function addCustomButton($name, $caption, $onclick = false) |
|
| 93 | + { |
|
| 94 | + $custom_button_array = array( |
|
| 95 | + 'name' => $name, |
|
| 96 | + 'caption' => $caption, |
|
| 97 | + 'onclick' => $onclick |
|
| 98 | + ); |
|
| 99 | + $this->_custom_button[] = $custom_button_array; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Add an element to the form |
|
| 104 | + * |
|
| 105 | + * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 106 | + * @param bool $key |
|
| 107 | + * @param bool $var |
|
| 108 | + * @param bool|string $required is this a "required" element? |
|
| 109 | + */ |
|
| 110 | + public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 111 | + { |
|
| 112 | + if ($key) { |
|
| 113 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
| 114 | + $formElement->setExtra('disabled="disabled"'); |
|
| 115 | + $formElement->setName($key . '-readonly'); |
|
| 116 | + // Since this element is disable, we still want to pass it's value in the form |
|
| 117 | + $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 118 | + $this->addElement($hidden); |
|
| 119 | + } |
|
| 120 | + $formElement->setDescription($var['form_dsc']); |
|
| 121 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 122 | + $hidden = new XoopsFormHidden('changedField', false); |
|
| 123 | + $this->addElement($hidden); |
|
| 124 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 125 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 126 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 127 | + } else { |
|
| 128 | + if (isset($var['form_extra'])) { |
|
| 129 | + $formElement->setExtra($var['form_extra']); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + $controls = $this->targetObject->controls; |
|
| 133 | + if (isset($controls[$key]['js'])) { |
|
| 134 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 135 | + } |
|
| 136 | + parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
| 137 | + } else { |
|
| 138 | + parent::addElement($formElement, $required === 'notset' ? false : true); |
|
| 139 | + } |
|
| 140 | + unset($formElement); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + public function createElements() |
|
| 144 | + { |
|
| 145 | + $controls = $this->targetObject->controls; |
|
| 146 | + $vars = $this->targetObject->vars; |
|
| 147 | + foreach ($vars as $key => $var) { |
|
| 148 | + |
|
| 149 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 150 | + // need to be displayed, then we only create an hidden field |
|
| 151 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 152 | + $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
| 153 | + $this->addElement($elementToAdd, $key, $var, false); |
|
| 154 | + unset($elementToAdd); |
|
| 155 | + // If not, the we need to create the proper form control for this fields |
|
| 156 | + } else { |
|
| 157 | + // If this field has a specific control, we will use it |
|
| 158 | + |
|
| 159 | + if ($key === 'parentid') { |
|
| 160 | + /** |
|
| 161 | + * Why this ? |
|
| 162 | + */ |
|
| 163 | + } |
|
| 164 | + if (isset($controls[$key])) { |
|
| 165 | + /* If the control has name, it's because it's an object already present in the script |
|
| 166 | 166 | * for example, "user" |
| 167 | 167 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
| 168 | 168 | */ |
| 169 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 170 | - $controls[$key]['name'] = 'select'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 174 | - |
|
| 175 | - // Adding on the form, the control for this field |
|
| 176 | - $this->addElement($form_select, $key, $var); |
|
| 177 | - unset($form_select); |
|
| 178 | - |
|
| 179 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 180 | - } else { |
|
| 181 | - switch ($var['data_type']) { |
|
| 182 | - |
|
| 183 | - case XOBJ_DTYPE_TXTBOX: |
|
| 184 | - |
|
| 185 | - $form_text = $this->getControl('text', $key); |
|
| 186 | - $this->addElement($form_text, $key, $var); |
|
| 187 | - unset($form_text); |
|
| 188 | - break; |
|
| 189 | - |
|
| 190 | - case XOBJ_DTYPE_INT: |
|
| 191 | - $this->targetObject->setControl($key, array( |
|
| 192 | - 'name' => 'text', |
|
| 193 | - 'size' => '5' |
|
| 194 | - )); |
|
| 195 | - $form_text = $this->getControl('text', $key); |
|
| 196 | - $this->addElement($form_text, $key, $var); |
|
| 197 | - unset($form_text); |
|
| 198 | - break; |
|
| 199 | - |
|
| 200 | - case XOBJ_DTYPE_FLOAT: |
|
| 201 | - $this->targetObject->setControl($key, array( |
|
| 202 | - 'name' => 'text', |
|
| 203 | - 'size' => '5' |
|
| 204 | - )); |
|
| 205 | - $form_text = $this->getControl('text', $key); |
|
| 206 | - $this->addElement($form_text, $key, $var); |
|
| 207 | - unset($form_text); |
|
| 208 | - break; |
|
| 209 | - |
|
| 210 | - case XOBJ_DTYPE_LTIME: |
|
| 211 | - $form_date_time = $this->getControl('date_time', $key); |
|
| 212 | - $this->addElement($form_date_time, $key, $var); |
|
| 213 | - unset($form_date_time); |
|
| 214 | - break; |
|
| 215 | - |
|
| 216 | - case XOBJ_DTYPE_STIME: |
|
| 217 | - $form_date_time = $this->getControl('date', $key); |
|
| 218 | - $this->addElement($form_date_time, $key, $var); |
|
| 219 | - unset($form_date_time); |
|
| 220 | - break; |
|
| 221 | - |
|
| 222 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 223 | - $form_time = $this->getControl('time', $key); |
|
| 224 | - $this->addElement($form_time, $key, $var); |
|
| 225 | - unset($form_time); |
|
| 226 | - break; |
|
| 227 | - |
|
| 228 | - case XOBJ_DTYPE_CURRENCY: |
|
| 229 | - $this->targetObject->setControl($key, array( |
|
| 230 | - 'name' => 'text', |
|
| 231 | - 'size' => '15' |
|
| 232 | - )); |
|
| 233 | - $form_currency = $this->getControl('text', $key); |
|
| 234 | - $this->addElement($form_currency, $key, $var); |
|
| 235 | - unset($form_currency); |
|
| 236 | - break; |
|
| 237 | - |
|
| 238 | - case XOBJ_DTYPE_URLLINK: |
|
| 239 | - $form_urllink = $this->getControl('urllink', $key); |
|
| 240 | - $this->addElement($form_urllink, $key, $var); |
|
| 241 | - unset($form_urllink); |
|
| 242 | - break; |
|
| 243 | - |
|
| 244 | - case XOBJ_DTYPE_FILE: |
|
| 245 | - $form_file = $this->getControl('richfile', $key); |
|
| 246 | - $this->addElement($form_file, $key, $var); |
|
| 247 | - unset($form_file); |
|
| 248 | - break; |
|
| 249 | - |
|
| 250 | - case XOBJ_DTYPE_TXTAREA: |
|
| 251 | - |
|
| 252 | - $form_text_area = $this->getTextArea($key, $var); |
|
| 253 | - $this->addElement($form_text_area, $key, $var); |
|
| 254 | - unset($form_text_area); |
|
| 255 | - break; |
|
| 256 | - |
|
| 257 | - case XOBJ_DTYPE_ARRAY: |
|
| 258 | - // TODO: To come... |
|
| 259 | - break; |
|
| 260 | - case XOBJ_DTYPE_SOURCE: |
|
| 261 | - // TODO: To come... |
|
| 262 | - break; |
|
| 263 | - case XOBJ_DTYPE_FORM_SECTION: |
|
| 264 | - $section_control = new SmartFormSection($key, $var['value']); |
|
| 265 | - $this->addElement($section_control, $key, $var); |
|
| 266 | - unset($section_control); |
|
| 267 | - break; |
|
| 268 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 269 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 270 | - $this->addElement($section_control, $key, $var); |
|
| 271 | - unset($section_control); |
|
| 272 | - break; |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - // Add an hidden field to store the URL of the page before this form |
|
| 278 | - $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - public function createPermissionControls() |
|
| 282 | - { |
|
| 283 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 284 | - |
|
| 285 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
| 286 | - |
|
| 287 | - if ($permissions) { |
|
| 288 | - $memberHandler = xoops_getHandler('member'); |
|
| 289 | - $group_list = $memberHandler->getGroupList(); |
|
| 290 | - asort($group_list); |
|
| 291 | - foreach ($permissions as $permission) { |
|
| 292 | - if ($this->targetObject->isNew()) { |
|
| 293 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 294 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 295 | - } |
|
| 296 | - } else { |
|
| 297 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 298 | - } |
|
| 299 | - $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 300 | - $groups_select->setDescription($permission['description']); |
|
| 301 | - $groups_select->addOptionArray($group_list); |
|
| 302 | - $this->addElement($groups_select); |
|
| 303 | - unset($groups_select); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * @param $form_name |
|
| 310 | - * @param $form_caption |
|
| 311 | - * @param bool $submit_button_caption |
|
| 312 | - */ |
|
| 313 | - public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 314 | - { |
|
| 315 | - $button_tray = new XoopsFormElementTray('', ''); |
|
| 316 | - $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
| 317 | - if (!$submit_button_caption) { |
|
| 318 | - if ($this->targetObject->isNew()) { |
|
| 319 | - $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 320 | - } else { |
|
| 321 | - $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 322 | - } |
|
| 323 | - } else { |
|
| 324 | - $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 325 | - } |
|
| 326 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 327 | - $button_tray->addElement($butt_create); |
|
| 328 | - |
|
| 329 | - //creating custom buttons |
|
| 330 | - if ($this->_custom_button) { |
|
| 331 | - foreach ($this->_custom_button as $custom_button) { |
|
| 332 | - $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 333 | - if ($custom_button['onclick']) { |
|
| 334 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 335 | - } |
|
| 336 | - $button_tray->addElement($butt_custom); |
|
| 337 | - unset($butt_custom); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // creating the "cancel" button |
|
| 342 | - $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 343 | - if ($this->_cancel_js_action) { |
|
| 344 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 345 | - } else { |
|
| 346 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 347 | - } |
|
| 348 | - $button_tray->addElement($butt_cancel); |
|
| 349 | - |
|
| 350 | - $this->addElement($button_tray); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @param $controlName |
|
| 355 | - * @param $key |
|
| 356 | - * @return XoopsFormLabel |
|
| 357 | - */ |
|
| 358 | - public function getControl($controlName, $key) |
|
| 359 | - { |
|
| 360 | - switch ($controlName) { |
|
| 361 | - case 'check': |
|
| 362 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'); |
|
| 363 | - $control = $this->targetObject->getControl($key); |
|
| 364 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 365 | - $controlObj->addOptionArray($control['options']); |
|
| 366 | - |
|
| 367 | - return $controlObj; |
|
| 368 | - break; |
|
| 369 | - |
|
| 370 | - case 'color': |
|
| 371 | - $control = $this->targetObject->getControl($key); |
|
| 372 | - $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 373 | - |
|
| 374 | - return $controlObj; |
|
| 375 | - break; |
|
| 376 | - |
|
| 377 | - case 'radio': |
|
| 378 | - $control = $this->targetObject->getControl($key); |
|
| 379 | - |
|
| 380 | - $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 381 | - $controlObj->addOptionArray($control['options']); |
|
| 382 | - |
|
| 383 | - return $controlObj; |
|
| 384 | - break; |
|
| 385 | - |
|
| 386 | - case 'label': |
|
| 387 | - return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 388 | - break; |
|
| 389 | - |
|
| 390 | - case 'textarea': |
|
| 391 | - return $this->getTextArea($key); |
|
| 392 | - |
|
| 393 | - case 'theme': |
|
| 394 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 395 | - |
|
| 396 | - case 'theme_multi': |
|
| 397 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 398 | - break; |
|
| 399 | - |
|
| 400 | - case 'timezone': |
|
| 401 | - return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 402 | - break; |
|
| 403 | - |
|
| 404 | - case 'group': |
|
| 405 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 406 | - break; |
|
| 407 | - |
|
| 408 | - case 'group_multi': |
|
| 409 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 410 | - break; |
|
| 411 | - |
|
| 412 | - /*case 'user': |
|
| 169 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 170 | + $controls[$key]['name'] = 'select'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 174 | + |
|
| 175 | + // Adding on the form, the control for this field |
|
| 176 | + $this->addElement($form_select, $key, $var); |
|
| 177 | + unset($form_select); |
|
| 178 | + |
|
| 179 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 180 | + } else { |
|
| 181 | + switch ($var['data_type']) { |
|
| 182 | + |
|
| 183 | + case XOBJ_DTYPE_TXTBOX: |
|
| 184 | + |
|
| 185 | + $form_text = $this->getControl('text', $key); |
|
| 186 | + $this->addElement($form_text, $key, $var); |
|
| 187 | + unset($form_text); |
|
| 188 | + break; |
|
| 189 | + |
|
| 190 | + case XOBJ_DTYPE_INT: |
|
| 191 | + $this->targetObject->setControl($key, array( |
|
| 192 | + 'name' => 'text', |
|
| 193 | + 'size' => '5' |
|
| 194 | + )); |
|
| 195 | + $form_text = $this->getControl('text', $key); |
|
| 196 | + $this->addElement($form_text, $key, $var); |
|
| 197 | + unset($form_text); |
|
| 198 | + break; |
|
| 199 | + |
|
| 200 | + case XOBJ_DTYPE_FLOAT: |
|
| 201 | + $this->targetObject->setControl($key, array( |
|
| 202 | + 'name' => 'text', |
|
| 203 | + 'size' => '5' |
|
| 204 | + )); |
|
| 205 | + $form_text = $this->getControl('text', $key); |
|
| 206 | + $this->addElement($form_text, $key, $var); |
|
| 207 | + unset($form_text); |
|
| 208 | + break; |
|
| 209 | + |
|
| 210 | + case XOBJ_DTYPE_LTIME: |
|
| 211 | + $form_date_time = $this->getControl('date_time', $key); |
|
| 212 | + $this->addElement($form_date_time, $key, $var); |
|
| 213 | + unset($form_date_time); |
|
| 214 | + break; |
|
| 215 | + |
|
| 216 | + case XOBJ_DTYPE_STIME: |
|
| 217 | + $form_date_time = $this->getControl('date', $key); |
|
| 218 | + $this->addElement($form_date_time, $key, $var); |
|
| 219 | + unset($form_date_time); |
|
| 220 | + break; |
|
| 221 | + |
|
| 222 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 223 | + $form_time = $this->getControl('time', $key); |
|
| 224 | + $this->addElement($form_time, $key, $var); |
|
| 225 | + unset($form_time); |
|
| 226 | + break; |
|
| 227 | + |
|
| 228 | + case XOBJ_DTYPE_CURRENCY: |
|
| 229 | + $this->targetObject->setControl($key, array( |
|
| 230 | + 'name' => 'text', |
|
| 231 | + 'size' => '15' |
|
| 232 | + )); |
|
| 233 | + $form_currency = $this->getControl('text', $key); |
|
| 234 | + $this->addElement($form_currency, $key, $var); |
|
| 235 | + unset($form_currency); |
|
| 236 | + break; |
|
| 237 | + |
|
| 238 | + case XOBJ_DTYPE_URLLINK: |
|
| 239 | + $form_urllink = $this->getControl('urllink', $key); |
|
| 240 | + $this->addElement($form_urllink, $key, $var); |
|
| 241 | + unset($form_urllink); |
|
| 242 | + break; |
|
| 243 | + |
|
| 244 | + case XOBJ_DTYPE_FILE: |
|
| 245 | + $form_file = $this->getControl('richfile', $key); |
|
| 246 | + $this->addElement($form_file, $key, $var); |
|
| 247 | + unset($form_file); |
|
| 248 | + break; |
|
| 249 | + |
|
| 250 | + case XOBJ_DTYPE_TXTAREA: |
|
| 251 | + |
|
| 252 | + $form_text_area = $this->getTextArea($key, $var); |
|
| 253 | + $this->addElement($form_text_area, $key, $var); |
|
| 254 | + unset($form_text_area); |
|
| 255 | + break; |
|
| 256 | + |
|
| 257 | + case XOBJ_DTYPE_ARRAY: |
|
| 258 | + // TODO: To come... |
|
| 259 | + break; |
|
| 260 | + case XOBJ_DTYPE_SOURCE: |
|
| 261 | + // TODO: To come... |
|
| 262 | + break; |
|
| 263 | + case XOBJ_DTYPE_FORM_SECTION: |
|
| 264 | + $section_control = new SmartFormSection($key, $var['value']); |
|
| 265 | + $this->addElement($section_control, $key, $var); |
|
| 266 | + unset($section_control); |
|
| 267 | + break; |
|
| 268 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 269 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 270 | + $this->addElement($section_control, $key, $var); |
|
| 271 | + unset($section_control); |
|
| 272 | + break; |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + // Add an hidden field to store the URL of the page before this form |
|
| 278 | + $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + public function createPermissionControls() |
|
| 282 | + { |
|
| 283 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 284 | + |
|
| 285 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
| 286 | + |
|
| 287 | + if ($permissions) { |
|
| 288 | + $memberHandler = xoops_getHandler('member'); |
|
| 289 | + $group_list = $memberHandler->getGroupList(); |
|
| 290 | + asort($group_list); |
|
| 291 | + foreach ($permissions as $permission) { |
|
| 292 | + if ($this->targetObject->isNew()) { |
|
| 293 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 294 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 295 | + } |
|
| 296 | + } else { |
|
| 297 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 298 | + } |
|
| 299 | + $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 300 | + $groups_select->setDescription($permission['description']); |
|
| 301 | + $groups_select->addOptionArray($group_list); |
|
| 302 | + $this->addElement($groups_select); |
|
| 303 | + unset($groups_select); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * @param $form_name |
|
| 310 | + * @param $form_caption |
|
| 311 | + * @param bool $submit_button_caption |
|
| 312 | + */ |
|
| 313 | + public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 314 | + { |
|
| 315 | + $button_tray = new XoopsFormElementTray('', ''); |
|
| 316 | + $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
| 317 | + if (!$submit_button_caption) { |
|
| 318 | + if ($this->targetObject->isNew()) { |
|
| 319 | + $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 320 | + } else { |
|
| 321 | + $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 322 | + } |
|
| 323 | + } else { |
|
| 324 | + $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 325 | + } |
|
| 326 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 327 | + $button_tray->addElement($butt_create); |
|
| 328 | + |
|
| 329 | + //creating custom buttons |
|
| 330 | + if ($this->_custom_button) { |
|
| 331 | + foreach ($this->_custom_button as $custom_button) { |
|
| 332 | + $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 333 | + if ($custom_button['onclick']) { |
|
| 334 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 335 | + } |
|
| 336 | + $button_tray->addElement($butt_custom); |
|
| 337 | + unset($butt_custom); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // creating the "cancel" button |
|
| 342 | + $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 343 | + if ($this->_cancel_js_action) { |
|
| 344 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 345 | + } else { |
|
| 346 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 347 | + } |
|
| 348 | + $button_tray->addElement($butt_cancel); |
|
| 349 | + |
|
| 350 | + $this->addElement($button_tray); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @param $controlName |
|
| 355 | + * @param $key |
|
| 356 | + * @return XoopsFormLabel |
|
| 357 | + */ |
|
| 358 | + public function getControl($controlName, $key) |
|
| 359 | + { |
|
| 360 | + switch ($controlName) { |
|
| 361 | + case 'check': |
|
| 362 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'); |
|
| 363 | + $control = $this->targetObject->getControl($key); |
|
| 364 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 365 | + $controlObj->addOptionArray($control['options']); |
|
| 366 | + |
|
| 367 | + return $controlObj; |
|
| 368 | + break; |
|
| 369 | + |
|
| 370 | + case 'color': |
|
| 371 | + $control = $this->targetObject->getControl($key); |
|
| 372 | + $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 373 | + |
|
| 374 | + return $controlObj; |
|
| 375 | + break; |
|
| 376 | + |
|
| 377 | + case 'radio': |
|
| 378 | + $control = $this->targetObject->getControl($key); |
|
| 379 | + |
|
| 380 | + $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 381 | + $controlObj->addOptionArray($control['options']); |
|
| 382 | + |
|
| 383 | + return $controlObj; |
|
| 384 | + break; |
|
| 385 | + |
|
| 386 | + case 'label': |
|
| 387 | + return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 388 | + break; |
|
| 389 | + |
|
| 390 | + case 'textarea': |
|
| 391 | + return $this->getTextArea($key); |
|
| 392 | + |
|
| 393 | + case 'theme': |
|
| 394 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 395 | + |
|
| 396 | + case 'theme_multi': |
|
| 397 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 398 | + break; |
|
| 399 | + |
|
| 400 | + case 'timezone': |
|
| 401 | + return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 402 | + break; |
|
| 403 | + |
|
| 404 | + case 'group': |
|
| 405 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 406 | + break; |
|
| 407 | + |
|
| 408 | + case 'group_multi': |
|
| 409 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 410 | + break; |
|
| 411 | + |
|
| 412 | + /*case 'user': |
|
| 413 | 413 | return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
| 414 | 414 | break;*/ |
| 415 | 415 | |
| 416 | - case 'user_multi': |
|
| 417 | - return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 418 | - break; |
|
| 419 | - |
|
| 420 | - case 'password': |
|
| 421 | - return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 422 | - break; |
|
| 423 | - |
|
| 424 | - case 'country': |
|
| 425 | - return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 426 | - break; |
|
| 427 | - |
|
| 428 | - case 'urllink': |
|
| 429 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'); |
|
| 430 | - |
|
| 431 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 432 | - break; |
|
| 433 | - |
|
| 434 | - case 'richfile': |
|
| 435 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'); |
|
| 436 | - |
|
| 437 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 438 | - break; |
|
| 439 | - case 'section': |
|
| 440 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'); |
|
| 441 | - |
|
| 442 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 443 | - break; |
|
| 444 | - |
|
| 445 | - default: |
|
| 446 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 447 | - if (!class_exists($classname)) { |
|
| 448 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 449 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'); |
|
| 450 | - } else { |
|
| 451 | - // perhaps this is a control created by the module |
|
| 452 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
| 453 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 454 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 455 | - $classFileName = strtolower($classname) . '.php'; |
|
| 456 | - |
|
| 457 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 458 | - include_once($moduleFormElementsPath . $classFileName); |
|
| 459 | - } else { |
|
| 460 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 461 | - |
|
| 462 | - return new XoopsFormLabel(); //Empty object |
|
| 463 | - } |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - return new $classname($this->targetObject, $key); |
|
| 468 | - break; |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * @param $key |
|
| 474 | - * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
| 475 | - */ |
|
| 476 | - public function getTextArea($key) |
|
| 477 | - { |
|
| 478 | - $var = $this->targetObject->vars[$key]; |
|
| 479 | - |
|
| 480 | - // if no control has been created, let's create a default one |
|
| 481 | - if (!isset($this->targetObject->controls[$key])) { |
|
| 482 | - $control = array( |
|
| 483 | - 'name' => 'textarea', |
|
| 484 | - 'itemHandler' => false, |
|
| 485 | - 'method' => false, |
|
| 486 | - 'module' => false, |
|
| 487 | - 'form_editor' => 'default' |
|
| 488 | - ); |
|
| 489 | - } else { |
|
| 490 | - $control = $this->targetObject->controls[$key]; |
|
| 491 | - } |
|
| 492 | - $xoops22 = smart_isXoops22(); |
|
| 493 | - |
|
| 494 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 495 | - /** |
|
| 496 | - * If the editor is 'default', retreive the default editor of this module |
|
| 497 | - */ |
|
| 498 | - if ($form_editor === 'default') { |
|
| 499 | - global $xoopsModuleConfig; |
|
| 500 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $caption = $var['form_caption']; |
|
| 504 | - $name = $key; |
|
| 505 | - |
|
| 506 | - $value = $this->targetObject->getVar($key); |
|
| 507 | - |
|
| 508 | - $value = $this->targetObject->getValueFor($key, true); |
|
| 509 | - |
|
| 510 | - $editor_configs = array(); |
|
| 511 | - $editor_configs['name'] = $name; |
|
| 512 | - $editor_configs['value'] = $value; |
|
| 513 | - if ($form_editor !== 'textarea') { |
|
| 514 | - $editor_configs['rows'] = 35; |
|
| 515 | - $editor_configs['cols'] = 60; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - if (isset($control['rows'])) { |
|
| 519 | - $editor_configs['rows'] = $control['rows']; |
|
| 520 | - } |
|
| 521 | - if (isset($control['cols'])) { |
|
| 522 | - $editor_configs['cols'] = $control['cols']; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $editor_configs['width'] = '100%'; |
|
| 526 | - $editor_configs['height'] = '400px'; |
|
| 527 | - |
|
| 528 | - $dhtml = true; |
|
| 529 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 530 | - |
|
| 531 | - if (file_exists($xoopseditorclass)) { |
|
| 532 | - include_once($xoopseditorclass); |
|
| 533 | - $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 534 | - } else { |
|
| 535 | - switch ($form_editor) { |
|
| 536 | - |
|
| 537 | - case 'tiny': |
|
| 538 | - if (!$xoops22) { |
|
| 539 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 540 | - include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'); |
|
| 541 | - $editor = new XoopsFormTinyTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
| 542 | - } else { |
|
| 543 | - if ($dhtml) { |
|
| 544 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 545 | - } else { |
|
| 546 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - } else { |
|
| 550 | - $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 551 | - } |
|
| 552 | - break; |
|
| 553 | - |
|
| 554 | - case 'dhtmltextarea': |
|
| 555 | - case 'dhtmltext': |
|
| 556 | - $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 557 | - if ($var['form_dsc']) { |
|
| 558 | - $editor->setDescription($var['form_dsc']); |
|
| 559 | - } |
|
| 560 | - break; |
|
| 561 | - |
|
| 562 | - case 'fckeditor': |
|
| 563 | - if (!$xoops22) { |
|
| 564 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
| 565 | - include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'); |
|
| 566 | - $editor = new XoopsFormFckeditor(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
| 567 | - } else { |
|
| 568 | - if ($dhtml) { |
|
| 569 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 570 | - } else { |
|
| 571 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - } else { |
|
| 575 | - $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
|
| 576 | - } |
|
| 577 | - break; |
|
| 578 | - |
|
| 579 | - case 'inbetween': |
|
| 580 | - if (!$xoops22) { |
|
| 581 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
| 582 | - include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'); |
|
| 583 | - $editor = new XoopsFormInbetweenTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
| 584 | - } else { |
|
| 585 | - if ($dhtml) { |
|
| 586 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 587 | - } else { |
|
| 588 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs); |
|
| 593 | - } |
|
| 594 | - break; |
|
| 595 | - |
|
| 596 | - case 'koivi': |
|
| 597 | - if (!$xoops22) { |
|
| 598 | - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
| 599 | - include_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'); |
|
| 600 | - $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
| 601 | - } else { |
|
| 602 | - if ($dhtml) { |
|
| 603 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 604 | - } else { |
|
| 605 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - } else { |
|
| 609 | - $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
|
| 610 | - } |
|
| 611 | - break; |
|
| 612 | - |
|
| 613 | - case 'spaw': |
|
| 614 | - if (!$xoops22) { |
|
| 615 | - if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
| 616 | - include_once(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'); |
|
| 617 | - $editor = new XoopsFormSpaw($caption, $name, $value); |
|
| 618 | - } |
|
| 619 | - } else { |
|
| 620 | - $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
|
| 621 | - } |
|
| 622 | - break; |
|
| 623 | - |
|
| 624 | - case 'htmlarea': |
|
| 625 | - if (!$xoops22) { |
|
| 626 | - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
| 627 | - include_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'); |
|
| 628 | - $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
| 629 | - } |
|
| 630 | - } else { |
|
| 631 | - $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
|
| 632 | - } |
|
| 633 | - break; |
|
| 634 | - |
|
| 635 | - default: |
|
| 636 | - case 'textarea': |
|
| 637 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 638 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 639 | - |
|
| 640 | - $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 641 | - if ($var['form_dsc']) { |
|
| 642 | - $editor->setDescription($var['form_dsc']); |
|
| 643 | - } |
|
| 644 | - break; |
|
| 645 | - |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - return $editor; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * @param $key |
|
| 654 | - * @param $var |
|
| 655 | - * @param bool $multiple |
|
| 656 | - * @return XoopsFormSelect |
|
| 657 | - */ |
|
| 658 | - public function getThemeSelect($key, $var, $multiple = false) |
|
| 659 | - { |
|
| 660 | - $size = $multiple ? 5 : 1; |
|
| 661 | - $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 662 | - |
|
| 663 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 664 | - $dirlist = array(); |
|
| 665 | - while (false !== ($file = readdir($handle))) { |
|
| 666 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) !== 'cvs') { |
|
| 667 | - $dirlist[$file] = $file; |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - closedir($handle); |
|
| 671 | - if (!empty($dirlist)) { |
|
| 672 | - asort($dirlist); |
|
| 673 | - $theme_select->addOptionArray($dirlist); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - return $theme_select; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * @param $keyname |
|
| 681 | - * @return bool |
|
| 682 | - */ |
|
| 683 | - public function &getElementById($keyname) |
|
| 684 | - { |
|
| 685 | - foreach ($this->_elements as $eleObj) { |
|
| 686 | - if ($eleObj->getName() == $keyname) { |
|
| 687 | - $ret =& $eleObj; |
|
| 688 | - break; |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - return isset($ret) ? $ret : false; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * create HTML to output the form as a theme-enabled table with validation. |
|
| 697 | - * |
|
| 698 | - * @return string |
|
| 699 | - */ |
|
| 700 | - public function render() |
|
| 701 | - { |
|
| 702 | - $required = $this->getRequired(); |
|
| 703 | - $ret = " |
|
| 416 | + case 'user_multi': |
|
| 417 | + return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 418 | + break; |
|
| 419 | + |
|
| 420 | + case 'password': |
|
| 421 | + return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 422 | + break; |
|
| 423 | + |
|
| 424 | + case 'country': |
|
| 425 | + return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 426 | + break; |
|
| 427 | + |
|
| 428 | + case 'urllink': |
|
| 429 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'); |
|
| 430 | + |
|
| 431 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 432 | + break; |
|
| 433 | + |
|
| 434 | + case 'richfile': |
|
| 435 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'); |
|
| 436 | + |
|
| 437 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 438 | + break; |
|
| 439 | + case 'section': |
|
| 440 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'); |
|
| 441 | + |
|
| 442 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 443 | + break; |
|
| 444 | + |
|
| 445 | + default: |
|
| 446 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 447 | + if (!class_exists($classname)) { |
|
| 448 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 449 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'); |
|
| 450 | + } else { |
|
| 451 | + // perhaps this is a control created by the module |
|
| 452 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
| 453 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 454 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 455 | + $classFileName = strtolower($classname) . '.php'; |
|
| 456 | + |
|
| 457 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 458 | + include_once($moduleFormElementsPath . $classFileName); |
|
| 459 | + } else { |
|
| 460 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 461 | + |
|
| 462 | + return new XoopsFormLabel(); //Empty object |
|
| 463 | + } |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + return new $classname($this->targetObject, $key); |
|
| 468 | + break; |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * @param $key |
|
| 474 | + * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
| 475 | + */ |
|
| 476 | + public function getTextArea($key) |
|
| 477 | + { |
|
| 478 | + $var = $this->targetObject->vars[$key]; |
|
| 479 | + |
|
| 480 | + // if no control has been created, let's create a default one |
|
| 481 | + if (!isset($this->targetObject->controls[$key])) { |
|
| 482 | + $control = array( |
|
| 483 | + 'name' => 'textarea', |
|
| 484 | + 'itemHandler' => false, |
|
| 485 | + 'method' => false, |
|
| 486 | + 'module' => false, |
|
| 487 | + 'form_editor' => 'default' |
|
| 488 | + ); |
|
| 489 | + } else { |
|
| 490 | + $control = $this->targetObject->controls[$key]; |
|
| 491 | + } |
|
| 492 | + $xoops22 = smart_isXoops22(); |
|
| 493 | + |
|
| 494 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 495 | + /** |
|
| 496 | + * If the editor is 'default', retreive the default editor of this module |
|
| 497 | + */ |
|
| 498 | + if ($form_editor === 'default') { |
|
| 499 | + global $xoopsModuleConfig; |
|
| 500 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $caption = $var['form_caption']; |
|
| 504 | + $name = $key; |
|
| 505 | + |
|
| 506 | + $value = $this->targetObject->getVar($key); |
|
| 507 | + |
|
| 508 | + $value = $this->targetObject->getValueFor($key, true); |
|
| 509 | + |
|
| 510 | + $editor_configs = array(); |
|
| 511 | + $editor_configs['name'] = $name; |
|
| 512 | + $editor_configs['value'] = $value; |
|
| 513 | + if ($form_editor !== 'textarea') { |
|
| 514 | + $editor_configs['rows'] = 35; |
|
| 515 | + $editor_configs['cols'] = 60; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + if (isset($control['rows'])) { |
|
| 519 | + $editor_configs['rows'] = $control['rows']; |
|
| 520 | + } |
|
| 521 | + if (isset($control['cols'])) { |
|
| 522 | + $editor_configs['cols'] = $control['cols']; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $editor_configs['width'] = '100%'; |
|
| 526 | + $editor_configs['height'] = '400px'; |
|
| 527 | + |
|
| 528 | + $dhtml = true; |
|
| 529 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 530 | + |
|
| 531 | + if (file_exists($xoopseditorclass)) { |
|
| 532 | + include_once($xoopseditorclass); |
|
| 533 | + $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 534 | + } else { |
|
| 535 | + switch ($form_editor) { |
|
| 536 | + |
|
| 537 | + case 'tiny': |
|
| 538 | + if (!$xoops22) { |
|
| 539 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 540 | + include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'); |
|
| 541 | + $editor = new XoopsFormTinyTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
| 542 | + } else { |
|
| 543 | + if ($dhtml) { |
|
| 544 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 545 | + } else { |
|
| 546 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + } else { |
|
| 550 | + $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 551 | + } |
|
| 552 | + break; |
|
| 553 | + |
|
| 554 | + case 'dhtmltextarea': |
|
| 555 | + case 'dhtmltext': |
|
| 556 | + $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 557 | + if ($var['form_dsc']) { |
|
| 558 | + $editor->setDescription($var['form_dsc']); |
|
| 559 | + } |
|
| 560 | + break; |
|
| 561 | + |
|
| 562 | + case 'fckeditor': |
|
| 563 | + if (!$xoops22) { |
|
| 564 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
| 565 | + include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'); |
|
| 566 | + $editor = new XoopsFormFckeditor(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
| 567 | + } else { |
|
| 568 | + if ($dhtml) { |
|
| 569 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 570 | + } else { |
|
| 571 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + } else { |
|
| 575 | + $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
|
| 576 | + } |
|
| 577 | + break; |
|
| 578 | + |
|
| 579 | + case 'inbetween': |
|
| 580 | + if (!$xoops22) { |
|
| 581 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
| 582 | + include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'); |
|
| 583 | + $editor = new XoopsFormInbetweenTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
| 584 | + } else { |
|
| 585 | + if ($dhtml) { |
|
| 586 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 587 | + } else { |
|
| 588 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs); |
|
| 593 | + } |
|
| 594 | + break; |
|
| 595 | + |
|
| 596 | + case 'koivi': |
|
| 597 | + if (!$xoops22) { |
|
| 598 | + if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
| 599 | + include_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'); |
|
| 600 | + $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
| 601 | + } else { |
|
| 602 | + if ($dhtml) { |
|
| 603 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 604 | + } else { |
|
| 605 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + } else { |
|
| 609 | + $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
|
| 610 | + } |
|
| 611 | + break; |
|
| 612 | + |
|
| 613 | + case 'spaw': |
|
| 614 | + if (!$xoops22) { |
|
| 615 | + if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
| 616 | + include_once(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'); |
|
| 617 | + $editor = new XoopsFormSpaw($caption, $name, $value); |
|
| 618 | + } |
|
| 619 | + } else { |
|
| 620 | + $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
|
| 621 | + } |
|
| 622 | + break; |
|
| 623 | + |
|
| 624 | + case 'htmlarea': |
|
| 625 | + if (!$xoops22) { |
|
| 626 | + if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
| 627 | + include_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'); |
|
| 628 | + $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
| 629 | + } |
|
| 630 | + } else { |
|
| 631 | + $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
|
| 632 | + } |
|
| 633 | + break; |
|
| 634 | + |
|
| 635 | + default: |
|
| 636 | + case 'textarea': |
|
| 637 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 638 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 639 | + |
|
| 640 | + $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 641 | + if ($var['form_dsc']) { |
|
| 642 | + $editor->setDescription($var['form_dsc']); |
|
| 643 | + } |
|
| 644 | + break; |
|
| 645 | + |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + return $editor; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * @param $key |
|
| 654 | + * @param $var |
|
| 655 | + * @param bool $multiple |
|
| 656 | + * @return XoopsFormSelect |
|
| 657 | + */ |
|
| 658 | + public function getThemeSelect($key, $var, $multiple = false) |
|
| 659 | + { |
|
| 660 | + $size = $multiple ? 5 : 1; |
|
| 661 | + $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 662 | + |
|
| 663 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 664 | + $dirlist = array(); |
|
| 665 | + while (false !== ($file = readdir($handle))) { |
|
| 666 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) !== 'cvs') { |
|
| 667 | + $dirlist[$file] = $file; |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + closedir($handle); |
|
| 671 | + if (!empty($dirlist)) { |
|
| 672 | + asort($dirlist); |
|
| 673 | + $theme_select->addOptionArray($dirlist); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + return $theme_select; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * @param $keyname |
|
| 681 | + * @return bool |
|
| 682 | + */ |
|
| 683 | + public function &getElementById($keyname) |
|
| 684 | + { |
|
| 685 | + foreach ($this->_elements as $eleObj) { |
|
| 686 | + if ($eleObj->getName() == $keyname) { |
|
| 687 | + $ret =& $eleObj; |
|
| 688 | + break; |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + return isset($ret) ? $ret : false; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * create HTML to output the form as a theme-enabled table with validation. |
|
| 697 | + * |
|
| 698 | + * @return string |
|
| 699 | + */ |
|
| 700 | + public function render() |
|
| 701 | + { |
|
| 702 | + $required = $this->getRequired(); |
|
| 703 | + $ret = " |
|
| 704 | 704 | <form name='" . |
| 705 | - $this->getName() . |
|
| 706 | - "' id='" . |
|
| 707 | - $this->getName() . |
|
| 708 | - "' action='" . |
|
| 709 | - $this->getAction() . |
|
| 710 | - "' method='" . |
|
| 711 | - $this->getMethod() . |
|
| 712 | - "' onsubmit='return xoopsFormValidate_" . |
|
| 713 | - $this->getName() . |
|
| 714 | - "(this);'" . |
|
| 715 | - $this->getExtra() . |
|
| 716 | - "> |
|
| 705 | + $this->getName() . |
|
| 706 | + "' id='" . |
|
| 707 | + $this->getName() . |
|
| 708 | + "' action='" . |
|
| 709 | + $this->getAction() . |
|
| 710 | + "' method='" . |
|
| 711 | + $this->getMethod() . |
|
| 712 | + "' onsubmit='return xoopsFormValidate_" . |
|
| 713 | + $this->getName() . |
|
| 714 | + "(this);'" . |
|
| 715 | + $this->getExtra() . |
|
| 716 | + "> |
|
| 717 | 717 | <table width='100%' class='outer' cellspacing='1'> |
| 718 | 718 | <tr><th colspan='2'>" . |
| 719 | - $this->getTitle() . |
|
| 720 | - '</th></tr> |
|
| 719 | + $this->getTitle() . |
|
| 720 | + '</th></tr> |
|
| 721 | 721 | '; |
| 722 | - $hidden = ''; |
|
| 723 | - $class = 'even'; |
|
| 724 | - foreach ($this->getElements() as $ele) { |
|
| 725 | - if (!is_object($ele)) { |
|
| 726 | - $ret .= $ele; |
|
| 727 | - } elseif (!$ele->isHidden()) { |
|
| 728 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 729 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 730 | - if ($ele->getDescription() !== '') { |
|
| 731 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 732 | - } |
|
| 733 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 734 | - } else { |
|
| 735 | - $hidden .= $ele->render(); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 739 | - $ret .= $this->renderValidationJS(true); |
|
| 740 | - |
|
| 741 | - return $ret; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * assign to smarty form template instead of displaying directly |
|
| 746 | - * |
|
| 747 | - * @param XoopsTpl &$tpl reference to a {@link Smarty} object |
|
| 748 | - * @param bool $smartyName |
|
| 749 | - * @see Smarty |
|
| 750 | - */ |
|
| 751 | - public function assign(XoopsTpl $tpl, $smartyName = false) |
|
| 752 | - { |
|
| 753 | - $i = 0; |
|
| 754 | - $elements = array(); |
|
| 755 | - foreach ($this->getElements() as $ele) { |
|
| 756 | - $n = ($ele->getName() !== '') ? $ele->getName() : $i; |
|
| 757 | - $elements[$n]['name'] = $ele->getName(); |
|
| 758 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
| 759 | - $elements[$n]['body'] = $ele->render(); |
|
| 760 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 761 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 762 | - $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
| 763 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 764 | - if ($ele->getDescription() !== '') { |
|
| 765 | - $elements[$n]['description'] = $ele->getDescription(); |
|
| 766 | - } |
|
| 767 | - ++$i; |
|
| 768 | - } |
|
| 769 | - $js = $this->renderValidationJS(); |
|
| 770 | - if (!$smartyName) { |
|
| 771 | - $smartyName = $this->getName(); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - $tpl->assign($smartyName, array( |
|
| 775 | - 'title' => $this->getTitle(), |
|
| 776 | - 'name' => $this->getName(), |
|
| 777 | - 'action' => $this->getAction(), |
|
| 778 | - 'method' => $this->getMethod(), |
|
| 779 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 780 | - 'javascript' => $js, |
|
| 781 | - 'elements' => $elements |
|
| 782 | - )); |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - /** |
|
| 786 | - * @param bool $withtags |
|
| 787 | - * @return string |
|
| 788 | - */ |
|
| 789 | - public function renderValidationJS($withtags = true) |
|
| 790 | - { |
|
| 791 | - $js = ''; |
|
| 792 | - if ($withtags) { |
|
| 793 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 794 | - } |
|
| 795 | - $myts = MyTextSanitizer::getInstance(); |
|
| 796 | - $formname = $this->getName(); |
|
| 797 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 798 | - // First, output code to check required elements |
|
| 799 | - $elements = $this->getRequired(); |
|
| 800 | - foreach ($elements as $elt) { |
|
| 801 | - $eltname = $elt->getName(); |
|
| 802 | - $eltcaption = trim($elt->getCaption()); |
|
| 803 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 804 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 805 | - if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
| 806 | - $js .= 'var myOption = -1;'; |
|
| 807 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 722 | + $hidden = ''; |
|
| 723 | + $class = 'even'; |
|
| 724 | + foreach ($this->getElements() as $ele) { |
|
| 725 | + if (!is_object($ele)) { |
|
| 726 | + $ret .= $ele; |
|
| 727 | + } elseif (!$ele->isHidden()) { |
|
| 728 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 729 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 730 | + if ($ele->getDescription() !== '') { |
|
| 731 | + $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 732 | + } |
|
| 733 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 734 | + } else { |
|
| 735 | + $hidden .= $ele->render(); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 739 | + $ret .= $this->renderValidationJS(true); |
|
| 740 | + |
|
| 741 | + return $ret; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * assign to smarty form template instead of displaying directly |
|
| 746 | + * |
|
| 747 | + * @param XoopsTpl &$tpl reference to a {@link Smarty} object |
|
| 748 | + * @param bool $smartyName |
|
| 749 | + * @see Smarty |
|
| 750 | + */ |
|
| 751 | + public function assign(XoopsTpl $tpl, $smartyName = false) |
|
| 752 | + { |
|
| 753 | + $i = 0; |
|
| 754 | + $elements = array(); |
|
| 755 | + foreach ($this->getElements() as $ele) { |
|
| 756 | + $n = ($ele->getName() !== '') ? $ele->getName() : $i; |
|
| 757 | + $elements[$n]['name'] = $ele->getName(); |
|
| 758 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
| 759 | + $elements[$n]['body'] = $ele->render(); |
|
| 760 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 761 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 762 | + $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
| 763 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 764 | + if ($ele->getDescription() !== '') { |
|
| 765 | + $elements[$n]['description'] = $ele->getDescription(); |
|
| 766 | + } |
|
| 767 | + ++$i; |
|
| 768 | + } |
|
| 769 | + $js = $this->renderValidationJS(); |
|
| 770 | + if (!$smartyName) { |
|
| 771 | + $smartyName = $this->getName(); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + $tpl->assign($smartyName, array( |
|
| 775 | + 'title' => $this->getTitle(), |
|
| 776 | + 'name' => $this->getName(), |
|
| 777 | + 'action' => $this->getAction(), |
|
| 778 | + 'method' => $this->getMethod(), |
|
| 779 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 780 | + 'javascript' => $js, |
|
| 781 | + 'elements' => $elements |
|
| 782 | + )); |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + /** |
|
| 786 | + * @param bool $withtags |
|
| 787 | + * @return string |
|
| 788 | + */ |
|
| 789 | + public function renderValidationJS($withtags = true) |
|
| 790 | + { |
|
| 791 | + $js = ''; |
|
| 792 | + if ($withtags) { |
|
| 793 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 794 | + } |
|
| 795 | + $myts = MyTextSanitizer::getInstance(); |
|
| 796 | + $formname = $this->getName(); |
|
| 797 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 798 | + // First, output code to check required elements |
|
| 799 | + $elements = $this->getRequired(); |
|
| 800 | + foreach ($elements as $elt) { |
|
| 801 | + $eltname = $elt->getName(); |
|
| 802 | + $eltcaption = trim($elt->getCaption()); |
|
| 803 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 804 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 805 | + if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
| 806 | + $js .= 'var myOption = -1;'; |
|
| 807 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 808 | 808 | if (myform.{$eltname}[i].checked) { |
| 809 | 809 | myOption = i; i = -1; |
| 810 | 810 | } |
| 811 | 811 | } |
| 812 | 812 | if (myOption == -1) { |
| 813 | 813 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
| 814 | - } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
| 815 | - $js .= 'var hasSelections = false;'; |
|
| 816 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 814 | + } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
| 815 | + $js .= 'var hasSelections = false;'; |
|
| 816 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 817 | 817 | if (myform['{$eltname}[]'].options[i].selected) { |
| 818 | 818 | hasSelections = true; |
| 819 | 819 | } |
@@ -821,11 +821,11 @@ discard block |
||
| 821 | 821 | } |
| 822 | 822 | if (hasSelections == false) { |
| 823 | 823 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
| 824 | - } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
| 825 | - $js .= 'var hasSelections = false;'; |
|
| 826 | - //sometimes, there is an implicit '[]', sometimes not |
|
| 827 | - if (strpos($eltname, '[') === false) { |
|
| 828 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 824 | + } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
| 825 | + $js .= 'var hasSelections = false;'; |
|
| 826 | + //sometimes, there is an implicit '[]', sometimes not |
|
| 827 | + if (strpos($eltname, '[') === false) { |
|
| 828 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 829 | 829 | if (myform['{$eltname}[]'][i].checked) { |
| 830 | 830 | hasSelections = true; |
| 831 | 831 | } |
@@ -833,8 +833,8 @@ discard block |
||
| 833 | 833 | } |
| 834 | 834 | if (hasSelections == false) { |
| 835 | 835 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
| 836 | - } else { |
|
| 837 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 836 | + } else { |
|
| 837 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 838 | 838 | if (myform['{$eltname}'][i].checked) { |
| 839 | 839 | hasSelections = true; |
| 840 | 840 | } |
@@ -842,25 +842,25 @@ discard block |
||
| 842 | 842 | } |
| 843 | 843 | if (hasSelections == false) { |
| 844 | 844 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 845 | - } |
|
| 846 | - } else { |
|
| 847 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - // Now, handle custom validation code |
|
| 851 | - $elements =& $this->getElements(true); |
|
| 852 | - foreach ($elements as $elt) { |
|
| 853 | - if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
| 854 | - if ($eltjs = $elt->renderValidationJS()) { |
|
| 855 | - $js .= $eltjs . "\n"; |
|
| 856 | - } |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - $js .= "return true;\n}\n"; |
|
| 860 | - if ($withtags) { |
|
| 861 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - return $js; |
|
| 865 | - } |
|
| 845 | + } |
|
| 846 | + } else { |
|
| 847 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + // Now, handle custom validation code |
|
| 851 | + $elements =& $this->getElements(true); |
|
| 852 | + foreach ($elements as $elt) { |
|
| 853 | + if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
| 854 | + if ($eltjs = $elt->renderValidationJS()) { |
|
| 855 | + $js .= $eltjs . "\n"; |
|
| 856 | + } |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + $js .= "return true;\n}\n"; |
|
| 860 | + if ($withtags) { |
|
| 861 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + return $js; |
|
| 865 | + } |
|
| 866 | 866 | } |
@@ -12,23 +12,23 @@ |
||
| 12 | 12 | |
| 13 | 13 | class SmartFormUser_sigElement extends XoopsFormElementTray |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * SmartFormUser_sigElement constructor. |
|
| 17 | - * @param string $object |
|
| 18 | - * @param string $key |
|
| 19 | - */ |
|
| 20 | - public function __construct($object, $key) |
|
| 21 | - { |
|
| 22 | - $var = $object->vars[$key]; |
|
| 23 | - $control = $object->controls[$key]; |
|
| 15 | + /** |
|
| 16 | + * SmartFormUser_sigElement constructor. |
|
| 17 | + * @param string $object |
|
| 18 | + * @param string $key |
|
| 19 | + */ |
|
| 20 | + public function __construct($object, $key) |
|
| 21 | + { |
|
| 22 | + $var = $object->vars[$key]; |
|
| 23 | + $control = $object->controls[$key]; |
|
| 24 | 24 | |
| 25 | - parent::__construct($var['form_caption'], '<br><br>', $key . '_signature_tray'); |
|
| 25 | + parent::__construct($var['form_caption'], '<br><br>', $key . '_signature_tray'); |
|
| 26 | 26 | |
| 27 | - $signature_textarea = new XoopsFormDhtmlTextArea('', $key, $object->getVar($key, 'e')); |
|
| 28 | - $this->addElement($signature_textarea); |
|
| 27 | + $signature_textarea = new XoopsFormDhtmlTextArea('', $key, $object->getVar($key, 'e')); |
|
| 28 | + $this->addElement($signature_textarea); |
|
| 29 | 29 | |
| 30 | - $attach_checkbox = new XoopsFormCheckBox('', 'attachsig', $object->getVar('attachsig', 'e')); |
|
| 31 | - $attach_checkbox->addOption(1, _US_SHOWSIG); |
|
| 32 | - $this->addElement($attach_checkbox); |
|
| 33 | - } |
|
| 30 | + $attach_checkbox = new XoopsFormCheckBox('', 'attachsig', $object->getVar('attachsig', 'e')); |
|
| 31 | + $attach_checkbox->addOption(1, _US_SHOWSIG); |
|
| 32 | + $this->addElement($attach_checkbox); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -11,31 +11,31 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class SmartFormUrlLinkElement extends XoopsFormElementTray |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * SmartFormUrlLinkElement constructor. |
|
| 16 | - * @param string $form_caption |
|
| 17 | - * @param string $key |
|
| 18 | - * @param string $object |
|
| 19 | - */ |
|
| 20 | - public function __construct($form_caption, $key, $object) |
|
| 21 | - { |
|
| 22 | - parent::__construct($form_caption, ' '); |
|
| 14 | + /** |
|
| 15 | + * SmartFormUrlLinkElement constructor. |
|
| 16 | + * @param string $form_caption |
|
| 17 | + * @param string $key |
|
| 18 | + * @param string $object |
|
| 19 | + */ |
|
| 20 | + public function __construct($form_caption, $key, $object) |
|
| 21 | + { |
|
| 22 | + parent::__construct($form_caption, ' '); |
|
| 23 | 23 | |
| 24 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_URL)); |
|
| 25 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
| 24 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_URL)); |
|
| 25 | + $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
| 26 | 26 | |
| 27 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
| 28 | - $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
| 27 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
| 28 | + $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
| 29 | 29 | |
| 30 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
| 31 | - $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
| 30 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
| 31 | + $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
| 32 | 32 | |
| 33 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_TARGET)); |
|
| 34 | - $targ_val = $object->getVar('target'); |
|
| 35 | - $targetRadio = new XoopsFormRadio('', 'target_' . $key, $targ_val !== '' ? $targ_val : '_blank'); |
|
| 36 | - $control = $object->getControl('target'); |
|
| 37 | - $targetRadio->addOptionArray($control['options']); |
|
| 33 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_TARGET)); |
|
| 34 | + $targ_val = $object->getVar('target'); |
|
| 35 | + $targetRadio = new XoopsFormRadio('', 'target_' . $key, $targ_val !== '' ? $targ_val : '_blank'); |
|
| 36 | + $control = $object->getControl('target'); |
|
| 37 | + $targetRadio->addOptionArray($control['options']); |
|
| 38 | 38 | |
| 39 | - $this->addElement($targetRadio); |
|
| 40 | - } |
|
| 39 | + $this->addElement($targetRadio); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -11,44 +11,44 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class SmartFormRichFileElement extends XoopsFormElementTray |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * SmartFormRichFileElement constructor. |
|
| 16 | - * @param string $form_caption |
|
| 17 | - * @param string $key |
|
| 18 | - * @param string $object |
|
| 19 | - */ |
|
| 20 | - public function __construct($form_caption, $key, $object) |
|
| 21 | - { |
|
| 22 | - parent::__construct($form_caption, ' '); |
|
| 23 | - if ($object->getVar('url') !== '') { |
|
| 24 | - $caption = $object->getVar('caption') !== '' ? $object->getVar('caption') : $object->getVar('url'); |
|
| 25 | - $this->addElement(new XoopsFormLabel('', _CO_SOBJECT_CURRENT_FILE . |
|
| 26 | - "<a href='" . |
|
| 27 | - str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar('url')) . |
|
| 28 | - "' target='_blank' >" . |
|
| 29 | - $caption . |
|
| 30 | - '</a><br><br>')); |
|
| 31 | - //$this->addElement( new XoopsFormLabel( '', "<br><a href = '".SMARTOBJECT_URL."admin/file.php?op=del&fileid=".$object->id()."'>"._CO_SOBJECT_DELETE_FILE."</a>")); |
|
| 32 | - } |
|
| 14 | + /** |
|
| 15 | + * SmartFormRichFileElement constructor. |
|
| 16 | + * @param string $form_caption |
|
| 17 | + * @param string $key |
|
| 18 | + * @param string $object |
|
| 19 | + */ |
|
| 20 | + public function __construct($form_caption, $key, $object) |
|
| 21 | + { |
|
| 22 | + parent::__construct($form_caption, ' '); |
|
| 23 | + if ($object->getVar('url') !== '') { |
|
| 24 | + $caption = $object->getVar('caption') !== '' ? $object->getVar('caption') : $object->getVar('url'); |
|
| 25 | + $this->addElement(new XoopsFormLabel('', _CO_SOBJECT_CURRENT_FILE . |
|
| 26 | + "<a href='" . |
|
| 27 | + str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar('url')) . |
|
| 28 | + "' target='_blank' >" . |
|
| 29 | + $caption . |
|
| 30 | + '</a><br><br>')); |
|
| 31 | + //$this->addElement( new XoopsFormLabel( '', "<br><a href = '".SMARTOBJECT_URL."admin/file.php?op=del&fileid=".$object->id()."'>"._CO_SOBJECT_DELETE_FILE."</a>")); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - include_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
| 35 | - if ($object->isNew()) { |
|
| 36 | - $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
| 37 | - $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
| 38 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
| 39 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
| 40 | - } |
|
| 41 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
| 42 | - $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
| 43 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
| 44 | - $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
| 34 | + include_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
| 35 | + if ($object->isNew()) { |
|
| 36 | + $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
| 37 | + $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
| 38 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
| 39 | + $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
| 40 | + } |
|
| 41 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
| 42 | + $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
| 43 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
| 44 | + $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
| 45 | 45 | |
| 46 | - if (!$object->isNew()) { |
|
| 47 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CHANGE_FILE)); |
|
| 48 | - $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
| 49 | - $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
| 50 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
| 51 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
| 52 | - } |
|
| 53 | - } |
|
| 46 | + if (!$object->isNew()) { |
|
| 47 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CHANGE_FILE)); |
|
| 48 | + $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
| 49 | + $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
| 50 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
| 51 | + $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | } |