@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | /** |
| 93 | 93 | * @param string $key |
| 94 | 94 | * @param string $format |
| 95 | - * @return mixed |
|
| 95 | + * @return string |
|
| 96 | 96 | */ |
| 97 | 97 | public function getVar($key, $format = 's') |
| 98 | 98 | { |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | - * @return mixed|string |
|
| 160 | + * @return string |
|
| 161 | 161 | */ |
| 162 | 162 | public function generateTag() |
| 163 | 163 | { |
@@ -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', [ |
|
| 57 | - 'handler' => 'adsense', |
|
| 58 | - 'method' => 'getFormats' |
|
| 59 | - ]); |
|
| 60 | - |
|
| 61 | - $this->setControl('border_color', [ |
|
| 62 | - 'name' => 'text', |
|
| 63 | - 'size' => 6, |
|
| 64 | - 'maxlength' => 6 |
|
| 65 | - ]); |
|
| 66 | - |
|
| 67 | - $this->setControl('background_color', [ |
|
| 68 | - 'name' => 'text', |
|
| 69 | - 'size' => 6, |
|
| 70 | - 'maxlength' => 6 |
|
| 71 | - ]); |
|
| 72 | - |
|
| 73 | - $this->setControl('link_color', [ |
|
| 74 | - 'name' => 'text', |
|
| 75 | - 'size' => 6, |
|
| 76 | - 'maxlength' => 6 |
|
| 77 | - ]); |
|
| 78 | - |
|
| 79 | - $this->setControl('url_color', [ |
|
| 80 | - 'name' => 'text', |
|
| 81 | - 'size' => 6, |
|
| 82 | - 'maxlength' => 6 |
|
| 83 | - ]); |
|
| 84 | - |
|
| 85 | - $this->setControl('text_color', [ |
|
| 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, [])) { |
|
| 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', [ |
|
| 57 | + 'handler' => 'adsense', |
|
| 58 | + 'method' => 'getFormats' |
|
| 59 | + ]); |
|
| 60 | + |
|
| 61 | + $this->setControl('border_color', [ |
|
| 62 | + 'name' => 'text', |
|
| 63 | + 'size' => 6, |
|
| 64 | + 'maxlength' => 6 |
|
| 65 | + ]); |
|
| 66 | + |
|
| 67 | + $this->setControl('background_color', [ |
|
| 68 | + 'name' => 'text', |
|
| 69 | + 'size' => 6, |
|
| 70 | + 'maxlength' => 6 |
|
| 71 | + ]); |
|
| 72 | + |
|
| 73 | + $this->setControl('link_color', [ |
|
| 74 | + 'name' => 'text', |
|
| 75 | + 'size' => 6, |
|
| 76 | + 'maxlength' => 6 |
|
| 77 | + ]); |
|
| 78 | + |
|
| 79 | + $this->setControl('url_color', [ |
|
| 80 | + 'name' => 'text', |
|
| 81 | + 'size' => 6, |
|
| 82 | + 'maxlength' => 6 |
|
| 83 | + ]); |
|
| 84 | + |
|
| 85 | + $this->setControl('text_color', [ |
|
| 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, [])) { |
|
| 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,139 +134,139 @@ 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 = [ |
|
| 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 = [ |
|
| 198 | - '-', |
|
| 199 | - '-', |
|
| 200 | - '-', |
|
| 201 | - '-', |
|
| 202 | - '-', |
|
| 203 | - '-100', |
|
| 204 | - '-', |
|
| 205 | - '-', |
|
| 206 | - '-', |
|
| 207 | - '-', |
|
| 208 | - '-', |
|
| 209 | - '-', |
|
| 210 | - '-', |
|
| 211 | - '-', |
|
| 212 | - '-', |
|
| 213 | - '-', |
|
| 214 | - '-', |
|
| 215 | - '-', |
|
| 216 | - '-at-', |
|
| 217 | - '-', |
|
| 218 | - '-', |
|
| 219 | - '-', |
|
| 220 | - '-', |
|
| 221 | - '-', |
|
| 222 | - '-', |
|
| 223 | - '-', |
|
| 224 | - '-', |
|
| 225 | - '-' |
|
| 226 | - ]; |
|
| 227 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 228 | - |
|
| 229 | - // Transformation des caractères accentués |
|
| 230 | - $pattern = [ |
|
| 231 | - '/%B0/', // ° |
|
| 232 | - '/%E8/', // è |
|
| 233 | - '/%E9/', // é |
|
| 234 | - '/%EA/', // ê |
|
| 235 | - '/%EB/', // ë |
|
| 236 | - '/%E7/', // ç |
|
| 237 | - '/%E0/', // à |
|
| 238 | - '/%E2/', // â |
|
| 239 | - '/%E4/', // ä |
|
| 240 | - '/%EE/', // î |
|
| 241 | - '/%EF/', // ï |
|
| 242 | - '/%F9/', // ù |
|
| 243 | - '/%FC/', // ü |
|
| 244 | - '/%FB/', // û |
|
| 245 | - '/%F4/', // ô |
|
| 246 | - '/%F6/', // ö |
|
| 247 | - ]; |
|
| 248 | - $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 249 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 250 | - |
|
| 251 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 252 | - $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 253 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 254 | - |
|
| 255 | - $title .= time(); |
|
| 256 | - $title = md5($title); |
|
| 257 | - |
|
| 258 | - return $title; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - public function getCloneLink() |
|
| 265 | - { |
|
| 266 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 267 | - |
|
| 268 | - return $ret; |
|
| 269 | - } |
|
| 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 = [ |
|
| 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 = [ |
|
| 198 | + '-', |
|
| 199 | + '-', |
|
| 200 | + '-', |
|
| 201 | + '-', |
|
| 202 | + '-', |
|
| 203 | + '-100', |
|
| 204 | + '-', |
|
| 205 | + '-', |
|
| 206 | + '-', |
|
| 207 | + '-', |
|
| 208 | + '-', |
|
| 209 | + '-', |
|
| 210 | + '-', |
|
| 211 | + '-', |
|
| 212 | + '-', |
|
| 213 | + '-', |
|
| 214 | + '-', |
|
| 215 | + '-', |
|
| 216 | + '-at-', |
|
| 217 | + '-', |
|
| 218 | + '-', |
|
| 219 | + '-', |
|
| 220 | + '-', |
|
| 221 | + '-', |
|
| 222 | + '-', |
|
| 223 | + '-', |
|
| 224 | + '-', |
|
| 225 | + '-' |
|
| 226 | + ]; |
|
| 227 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 228 | + |
|
| 229 | + // Transformation des caractères accentués |
|
| 230 | + $pattern = [ |
|
| 231 | + '/%B0/', // ° |
|
| 232 | + '/%E8/', // è |
|
| 233 | + '/%E9/', // é |
|
| 234 | + '/%EA/', // ê |
|
| 235 | + '/%EB/', // ë |
|
| 236 | + '/%E7/', // ç |
|
| 237 | + '/%E0/', // à |
|
| 238 | + '/%E2/', // â |
|
| 239 | + '/%E4/', // ä |
|
| 240 | + '/%EE/', // î |
|
| 241 | + '/%EF/', // ï |
|
| 242 | + '/%F9/', // ù |
|
| 243 | + '/%FC/', // ü |
|
| 244 | + '/%FB/', // û |
|
| 245 | + '/%F4/', // ô |
|
| 246 | + '/%F6/', // ö |
|
| 247 | + ]; |
|
| 248 | + $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 249 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 250 | + |
|
| 251 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 252 | + $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 253 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 254 | + |
|
| 255 | + $title .= time(); |
|
| 256 | + $title = md5($title); |
|
| 257 | + |
|
| 258 | + return $title; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + public function getCloneLink() |
|
| 265 | + { |
|
| 266 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 267 | + |
|
| 268 | + return $ret; |
|
| 269 | + } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -274,116 +274,116 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | class SmartobjectAdsenseHandler extends SmartPersistableObjectHandler |
| 276 | 276 | { |
| 277 | - public $adFormats; |
|
| 278 | - public $adFormatsList; |
|
| 279 | - public $objects = false; |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * SmartobjectAdsenseHandler constructor. |
|
| 283 | - * @param XoopsDatabase $db |
|
| 284 | - */ |
|
| 285 | - public function __construct(XoopsDatabase $db) |
|
| 286 | - { |
|
| 287 | - parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
| 288 | - $this->adFormats = []; |
|
| 289 | - $this->adFormatsList = []; |
|
| 290 | - |
|
| 291 | - $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 292 | - $this->adFormats['728x90_as']['width'] = 728; |
|
| 293 | - $this->adFormats['728x90_as']['height'] = 90; |
|
| 294 | - $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 295 | - |
|
| 296 | - $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 297 | - $this->adFormats['468x60_as']['width'] = 468; |
|
| 298 | - $this->adFormats['468x60_as']['height'] = 60; |
|
| 299 | - $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 300 | - |
|
| 301 | - $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 302 | - $this->adFormats['234x60_as']['width'] = 234; |
|
| 303 | - $this->adFormats['234x60_as']['height'] = 60; |
|
| 304 | - $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 305 | - |
|
| 306 | - $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 307 | - $this->adFormats['120x600_as']['width'] = 120; |
|
| 308 | - $this->adFormats['120x600_as']['height'] = 600; |
|
| 309 | - $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 310 | - |
|
| 311 | - $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 312 | - $this->adFormats['160x600_as']['width'] = 160; |
|
| 313 | - $this->adFormats['160x600_as']['height'] = 600; |
|
| 314 | - $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 315 | - |
|
| 316 | - $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 317 | - $this->adFormats['120x240_as']['width'] = 120; |
|
| 318 | - $this->adFormats['120x240_as']['height'] = 240; |
|
| 319 | - $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 320 | - |
|
| 321 | - $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 322 | - $this->adFormats['336x280_as']['width'] = 136; |
|
| 323 | - $this->adFormats['336x280_as']['height'] = 280; |
|
| 324 | - $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 325 | - |
|
| 326 | - $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 327 | - $this->adFormats['300x250_as']['width'] = 300; |
|
| 328 | - $this->adFormats['300x250_as']['height'] = 250; |
|
| 329 | - $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 330 | - |
|
| 331 | - $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 332 | - $this->adFormats['250x250_as']['width'] = 250; |
|
| 333 | - $this->adFormats['250x250_as']['height'] = 250; |
|
| 334 | - $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 335 | - |
|
| 336 | - $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 337 | - $this->adFormats['200x200_as']['width'] = 200; |
|
| 338 | - $this->adFormats['200x200_as']['height'] = 200; |
|
| 339 | - $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 340 | - |
|
| 341 | - $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 342 | - $this->adFormats['180x150_as']['width'] = 180; |
|
| 343 | - $this->adFormats['180x150_as']['height'] = 150; |
|
| 344 | - $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 345 | - |
|
| 346 | - $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 347 | - $this->adFormats['125x125_as']['width'] = 125; |
|
| 348 | - $this->adFormats['125x125_as']['height'] = 125; |
|
| 349 | - $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @return array |
|
| 354 | - */ |
|
| 355 | - public function getFormats() |
|
| 356 | - { |
|
| 357 | - return $this->adFormatsList; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @param $obj |
|
| 362 | - * @return bool |
|
| 363 | - */ |
|
| 364 | - public function beforeSave($obj) |
|
| 365 | - { |
|
| 366 | - if ($obj->getVar('tag') === '') { |
|
| 367 | - $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - return true; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * @return array|bool |
|
| 375 | - */ |
|
| 376 | - public function getAdsensesByTag() |
|
| 377 | - { |
|
| 378 | - if (!$this->objects) { |
|
| 379 | - $adsensesObj = $this->getObjects(null, true); |
|
| 380 | - $ret = []; |
|
| 381 | - foreach ($adsensesObj as $adsenseObj) { |
|
| 382 | - $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 383 | - } |
|
| 384 | - $this->objects = $ret; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - return $this->objects; |
|
| 388 | - } |
|
| 277 | + public $adFormats; |
|
| 278 | + public $adFormatsList; |
|
| 279 | + public $objects = false; |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * SmartobjectAdsenseHandler constructor. |
|
| 283 | + * @param XoopsDatabase $db |
|
| 284 | + */ |
|
| 285 | + public function __construct(XoopsDatabase $db) |
|
| 286 | + { |
|
| 287 | + parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
| 288 | + $this->adFormats = []; |
|
| 289 | + $this->adFormatsList = []; |
|
| 290 | + |
|
| 291 | + $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 292 | + $this->adFormats['728x90_as']['width'] = 728; |
|
| 293 | + $this->adFormats['728x90_as']['height'] = 90; |
|
| 294 | + $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 295 | + |
|
| 296 | + $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 297 | + $this->adFormats['468x60_as']['width'] = 468; |
|
| 298 | + $this->adFormats['468x60_as']['height'] = 60; |
|
| 299 | + $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 300 | + |
|
| 301 | + $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 302 | + $this->adFormats['234x60_as']['width'] = 234; |
|
| 303 | + $this->adFormats['234x60_as']['height'] = 60; |
|
| 304 | + $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 305 | + |
|
| 306 | + $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 307 | + $this->adFormats['120x600_as']['width'] = 120; |
|
| 308 | + $this->adFormats['120x600_as']['height'] = 600; |
|
| 309 | + $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 310 | + |
|
| 311 | + $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 312 | + $this->adFormats['160x600_as']['width'] = 160; |
|
| 313 | + $this->adFormats['160x600_as']['height'] = 600; |
|
| 314 | + $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 315 | + |
|
| 316 | + $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 317 | + $this->adFormats['120x240_as']['width'] = 120; |
|
| 318 | + $this->adFormats['120x240_as']['height'] = 240; |
|
| 319 | + $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 320 | + |
|
| 321 | + $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 322 | + $this->adFormats['336x280_as']['width'] = 136; |
|
| 323 | + $this->adFormats['336x280_as']['height'] = 280; |
|
| 324 | + $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 325 | + |
|
| 326 | + $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 327 | + $this->adFormats['300x250_as']['width'] = 300; |
|
| 328 | + $this->adFormats['300x250_as']['height'] = 250; |
|
| 329 | + $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 330 | + |
|
| 331 | + $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 332 | + $this->adFormats['250x250_as']['width'] = 250; |
|
| 333 | + $this->adFormats['250x250_as']['height'] = 250; |
|
| 334 | + $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 335 | + |
|
| 336 | + $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 337 | + $this->adFormats['200x200_as']['width'] = 200; |
|
| 338 | + $this->adFormats['200x200_as']['height'] = 200; |
|
| 339 | + $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 340 | + |
|
| 341 | + $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 342 | + $this->adFormats['180x150_as']['width'] = 180; |
|
| 343 | + $this->adFormats['180x150_as']['height'] = 150; |
|
| 344 | + $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 345 | + |
|
| 346 | + $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 347 | + $this->adFormats['125x125_as']['width'] = 125; |
|
| 348 | + $this->adFormats['125x125_as']['height'] = 125; |
|
| 349 | + $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @return array |
|
| 354 | + */ |
|
| 355 | + public function getFormats() |
|
| 356 | + { |
|
| 357 | + return $this->adFormatsList; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @param $obj |
|
| 362 | + * @return bool |
|
| 363 | + */ |
|
| 364 | + public function beforeSave($obj) |
|
| 365 | + { |
|
| 366 | + if ($obj->getVar('tag') === '') { |
|
| 367 | + $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + return true; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * @return array|bool |
|
| 375 | + */ |
|
| 376 | + public function getAdsensesByTag() |
|
| 377 | + { |
|
| 378 | + if (!$this->objects) { |
|
| 379 | + $adsensesObj = $this->getObjects(null, true); |
|
| 380 | + $ret = []; |
|
| 381 | + foreach ($adsensesObj as $adsenseObj) { |
|
| 382 | + $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 383 | + } |
|
| 384 | + $this->objects = $ret; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + return $this->objects; |
|
| 388 | + } |
|
| 389 | 389 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
| 31 | 31 | |
| 32 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
| 32 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Class SmartobjectAdsense |
@@ -111,23 +111,23 @@ discard block |
||
| 111 | 111 | { |
| 112 | 112 | global $smartobjectAdsenseHandler; |
| 113 | 113 | if ($this->getVar('style', 'n') !== '') { |
| 114 | - $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 114 | + $ret = '<div style="'.$this->getVar('style', 'n').'">'; |
|
| 115 | 115 | } else { |
| 116 | 116 | $ret = '<div>'; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $ret .= '<script type="text/javascript"><!-- |
| 120 | -google_ad_client = "' . $this->getVar('client_id', 'n') . '"; |
|
| 121 | -google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . '; |
|
| 122 | -google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . '; |
|
| 123 | -google_ad_format = "' . $this->getVar('format', 'n') . '"; |
|
| 120 | +google_ad_client = "' . $this->getVar('client_id', 'n').'"; |
|
| 121 | +google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'].'; |
|
| 122 | +google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'].'; |
|
| 123 | +google_ad_format = "' . $this->getVar('format', 'n').'"; |
|
| 124 | 124 | google_ad_type = "text"; |
| 125 | 125 | google_ad_channel =""; |
| 126 | -google_color_border = "' . $this->getVar('border_color', 'n') . '"; |
|
| 127 | -google_color_bg = "' . $this->getVar('background_color', 'n') . '"; |
|
| 128 | -google_color_link = "' . $this->getVar('link_color', 'n') . '"; |
|
| 129 | -google_color_url = "' . $this->getVar('url_color', 'n') . '"; |
|
| 130 | -google_color_text = "' . $this->getVar('text_color', 'n') . '"; |
|
| 126 | +google_color_border = "' . $this->getVar('border_color', 'n').'"; |
|
| 127 | +google_color_bg = "' . $this->getVar('background_color', 'n').'"; |
|
| 128 | +google_color_link = "' . $this->getVar('link_color', 'n').'"; |
|
| 129 | +google_color_url = "' . $this->getVar('url_color', 'n').'"; |
|
| 130 | +google_color_text = "' . $this->getVar('text_color', 'n').'"; |
|
| 131 | 131 | //--></script> |
| 132 | 132 | <script type="text/javascript" |
| 133 | 133 | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function getXoopsCode() |
| 144 | 144 | { |
| 145 | - $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 145 | + $ret = '[adsense]'.$this->getVar('tag', 'n').'[/adsense]'; |
|
| 146 | 146 | |
| 147 | 147 | return $ret; |
| 148 | 148 | } |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | public function getCloneLink() |
| 265 | 265 | { |
| 266 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 266 | + $ret = '<a href="'.SMARTOBJECT_URL.'admin/adsense.php?op=clone&adsenseid='.$this->getVar('adsenseid').'"><img src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'editcopy.png" alt="'._CO_SOBJECT_ADSENSE_CLONE.'" title="'._CO_SOBJECT_ADSENSE_CLONE.'"></a>'; |
|
| 267 | 267 | |
| 268 | 268 | return $ret; |
| 269 | 269 | } |
@@ -147,7 +147,7 @@ |
||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | - * @return mixed|string |
|
| 150 | + * @return string |
|
| 151 | 151 | */ |
| 152 | 152 | public function generateTag() |
| 153 | 153 | { |
@@ -36,227 +36,227 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | class SmartobjectCustomtag extends SmartObject |
| 38 | 38 | { |
| 39 | - public $content = false; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * SmartobjectCustomtag constructor. |
|
| 43 | - */ |
|
| 44 | - public function __construct() |
|
| 45 | - { |
|
| 46 | - $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
|
| 47 | - $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
|
| 48 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
|
| 49 | - $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
|
| 50 | - $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
|
| 51 | - |
|
| 52 | - $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
|
| 53 | - $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
|
| 54 | - $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
|
| 55 | - $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
|
| 56 | - |
|
| 57 | - $this->setControl('content', [ |
|
| 58 | - 'name' => 'textarea', |
|
| 59 | - 'form_editor' => 'textarea', |
|
| 60 | - 'form_rows' => 25 |
|
| 61 | - ]); |
|
| 62 | - $this->setControl('language', [ |
|
| 63 | - 'name' => 'language', |
|
| 64 | - 'all' => true |
|
| 65 | - ]); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param string $key |
|
| 70 | - * @param string $format |
|
| 71 | - * @return mixed |
|
| 72 | - */ |
|
| 73 | - public function getVar($key, $format = 's') |
|
| 74 | - { |
|
| 75 | - if ($format === 's' && in_array($key, [])) { |
|
| 76 | - // return call_user_func(array($this, $key)); |
|
| 77 | - return $this->{$key}(); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return parent::getVar($key, $format); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @return bool|mixed |
|
| 85 | - */ |
|
| 86 | - public function render() |
|
| 87 | - { |
|
| 88 | - if (!$this->content) { |
|
| 89 | - $ret = $this->getVar('content'); |
|
| 90 | - $this->content = $ret; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $this->content; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return bool|mixed|string |
|
| 98 | - */ |
|
| 99 | - public function renderWithPhp() |
|
| 100 | - { |
|
| 101 | - if (!$this->content) { |
|
| 102 | - $ret = $this->getVar('content'); |
|
| 103 | - $this->content = $ret; |
|
| 104 | - } else { |
|
| 105 | - $ret = $this->content; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // check for PHP if we are not on admin side |
|
| 109 | - if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
|
| 110 | - $ret = str_replace('[php]', '', $ret); |
|
| 111 | - // we have PHP code, let's evaluate |
|
| 112 | - eval($ret); |
|
| 113 | - |
|
| 114 | - return ''; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return $this->content; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function getXoopsCode() |
|
| 124 | - { |
|
| 125 | - $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
| 126 | - |
|
| 127 | - return $ret; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function getCloneLink() |
|
| 134 | - { |
|
| 135 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/customtag.php?op=clone&customtagid=' . $this->id() . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" style="vertical-align: middle;" alt="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" title="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '"></a>'; |
|
| 136 | - |
|
| 137 | - return $ret; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param $var |
|
| 142 | - * @return bool |
|
| 143 | - */ |
|
| 144 | - public function emptyString($var) |
|
| 145 | - { |
|
| 146 | - return (strlen($var) > 0); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return mixed|string |
|
| 151 | - */ |
|
| 152 | - public function generateTag() |
|
| 153 | - { |
|
| 154 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 155 | - $title = xoops_substr($title, 0, 10, ''); |
|
| 156 | - // Transformation des ponctuations |
|
| 157 | - $pattern = [ |
|
| 158 | - '/%09/', // Tab |
|
| 159 | - '/%20/', // Space |
|
| 160 | - '/%21/', // ! |
|
| 161 | - '/%22/', // " |
|
| 162 | - '/%23/', // # |
|
| 163 | - '/%25/', // % |
|
| 164 | - '/%26/', // & |
|
| 165 | - '/%27/', // ' |
|
| 166 | - '/%28/', // ( |
|
| 167 | - '/%29/', // ) |
|
| 168 | - '/%2C/', // , |
|
| 169 | - '/%2F/', // / |
|
| 170 | - '/%3A/', // : |
|
| 171 | - '/%3B/', // ; |
|
| 172 | - '/%3C/', // < |
|
| 173 | - '/%3D/', // = |
|
| 174 | - '/%3E/', // > |
|
| 175 | - '/%3F/', // ? |
|
| 176 | - '/%40/', // @ |
|
| 177 | - '/%5B/', // [ |
|
| 178 | - '/%5C/', // \ |
|
| 179 | - '/%5D/', // ] |
|
| 180 | - '/%5E/', // ^ |
|
| 181 | - '/%7B/', // { |
|
| 182 | - '/%7C/', // | |
|
| 183 | - '/%7D/', // } |
|
| 184 | - '/%7E/', // ~ |
|
| 185 | - "/\./" // . |
|
| 186 | - ]; |
|
| 187 | - $rep_pat = [ |
|
| 188 | - '-', |
|
| 189 | - '-', |
|
| 190 | - '-', |
|
| 191 | - '-', |
|
| 192 | - '-', |
|
| 193 | - '-100', |
|
| 194 | - '-', |
|
| 195 | - '-', |
|
| 196 | - '-', |
|
| 197 | - '-', |
|
| 198 | - '-', |
|
| 199 | - '-', |
|
| 200 | - '-', |
|
| 201 | - '-', |
|
| 202 | - '-', |
|
| 203 | - '-', |
|
| 204 | - '-', |
|
| 205 | - '-', |
|
| 206 | - '-at-', |
|
| 207 | - '-', |
|
| 208 | - '-', |
|
| 209 | - '-', |
|
| 210 | - '-', |
|
| 211 | - '-', |
|
| 212 | - '-', |
|
| 213 | - '-', |
|
| 214 | - '-', |
|
| 215 | - '-' |
|
| 216 | - ]; |
|
| 217 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 218 | - |
|
| 219 | - // Transformation des caractères accentués |
|
| 220 | - $pattern = [ |
|
| 221 | - '/%B0/', // ° |
|
| 222 | - '/%E8/', // è |
|
| 223 | - '/%E9/', // é |
|
| 224 | - '/%EA/', // ê |
|
| 225 | - '/%EB/', // ë |
|
| 226 | - '/%E7/', // ç |
|
| 227 | - '/%E0/', // à |
|
| 228 | - '/%E2/', // â |
|
| 229 | - '/%E4/', // ä |
|
| 230 | - '/%EE/', // î |
|
| 231 | - '/%EF/', // ï |
|
| 232 | - '/%F9/', // ù |
|
| 233 | - '/%FC/', // ü |
|
| 234 | - '/%FB/', // û |
|
| 235 | - '/%F4/', // ô |
|
| 236 | - '/%F6/', // ö |
|
| 237 | - ]; |
|
| 238 | - $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 239 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 240 | - |
|
| 241 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 242 | - $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 243 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 244 | - |
|
| 245 | - $title .= time(); |
|
| 246 | - $title = md5($title); |
|
| 247 | - |
|
| 248 | - return $title; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @return mixed |
|
| 253 | - */ |
|
| 254 | - public function getCustomtagName() |
|
| 255 | - { |
|
| 256 | - $ret = $this->getVar('name'); |
|
| 257 | - |
|
| 258 | - return $ret; |
|
| 259 | - } |
|
| 39 | + public $content = false; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * SmartobjectCustomtag constructor. |
|
| 43 | + */ |
|
| 44 | + public function __construct() |
|
| 45 | + { |
|
| 46 | + $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
|
| 47 | + $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
|
| 48 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
|
| 49 | + $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
|
| 50 | + $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
|
| 51 | + |
|
| 52 | + $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
|
| 53 | + $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
|
| 54 | + $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
|
| 55 | + $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
|
| 56 | + |
|
| 57 | + $this->setControl('content', [ |
|
| 58 | + 'name' => 'textarea', |
|
| 59 | + 'form_editor' => 'textarea', |
|
| 60 | + 'form_rows' => 25 |
|
| 61 | + ]); |
|
| 62 | + $this->setControl('language', [ |
|
| 63 | + 'name' => 'language', |
|
| 64 | + 'all' => true |
|
| 65 | + ]); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param string $key |
|
| 70 | + * @param string $format |
|
| 71 | + * @return mixed |
|
| 72 | + */ |
|
| 73 | + public function getVar($key, $format = 's') |
|
| 74 | + { |
|
| 75 | + if ($format === 's' && in_array($key, [])) { |
|
| 76 | + // return call_user_func(array($this, $key)); |
|
| 77 | + return $this->{$key}(); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return parent::getVar($key, $format); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @return bool|mixed |
|
| 85 | + */ |
|
| 86 | + public function render() |
|
| 87 | + { |
|
| 88 | + if (!$this->content) { |
|
| 89 | + $ret = $this->getVar('content'); |
|
| 90 | + $this->content = $ret; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $this->content; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return bool|mixed|string |
|
| 98 | + */ |
|
| 99 | + public function renderWithPhp() |
|
| 100 | + { |
|
| 101 | + if (!$this->content) { |
|
| 102 | + $ret = $this->getVar('content'); |
|
| 103 | + $this->content = $ret; |
|
| 104 | + } else { |
|
| 105 | + $ret = $this->content; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // check for PHP if we are not on admin side |
|
| 109 | + if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
|
| 110 | + $ret = str_replace('[php]', '', $ret); |
|
| 111 | + // we have PHP code, let's evaluate |
|
| 112 | + eval($ret); |
|
| 113 | + |
|
| 114 | + return ''; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return $this->content; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function getXoopsCode() |
|
| 124 | + { |
|
| 125 | + $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
| 126 | + |
|
| 127 | + return $ret; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function getCloneLink() |
|
| 134 | + { |
|
| 135 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/customtag.php?op=clone&customtagid=' . $this->id() . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" style="vertical-align: middle;" alt="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" title="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '"></a>'; |
|
| 136 | + |
|
| 137 | + return $ret; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param $var |
|
| 142 | + * @return bool |
|
| 143 | + */ |
|
| 144 | + public function emptyString($var) |
|
| 145 | + { |
|
| 146 | + return (strlen($var) > 0); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return mixed|string |
|
| 151 | + */ |
|
| 152 | + public function generateTag() |
|
| 153 | + { |
|
| 154 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 155 | + $title = xoops_substr($title, 0, 10, ''); |
|
| 156 | + // Transformation des ponctuations |
|
| 157 | + $pattern = [ |
|
| 158 | + '/%09/', // Tab |
|
| 159 | + '/%20/', // Space |
|
| 160 | + '/%21/', // ! |
|
| 161 | + '/%22/', // " |
|
| 162 | + '/%23/', // # |
|
| 163 | + '/%25/', // % |
|
| 164 | + '/%26/', // & |
|
| 165 | + '/%27/', // ' |
|
| 166 | + '/%28/', // ( |
|
| 167 | + '/%29/', // ) |
|
| 168 | + '/%2C/', // , |
|
| 169 | + '/%2F/', // / |
|
| 170 | + '/%3A/', // : |
|
| 171 | + '/%3B/', // ; |
|
| 172 | + '/%3C/', // < |
|
| 173 | + '/%3D/', // = |
|
| 174 | + '/%3E/', // > |
|
| 175 | + '/%3F/', // ? |
|
| 176 | + '/%40/', // @ |
|
| 177 | + '/%5B/', // [ |
|
| 178 | + '/%5C/', // \ |
|
| 179 | + '/%5D/', // ] |
|
| 180 | + '/%5E/', // ^ |
|
| 181 | + '/%7B/', // { |
|
| 182 | + '/%7C/', // | |
|
| 183 | + '/%7D/', // } |
|
| 184 | + '/%7E/', // ~ |
|
| 185 | + "/\./" // . |
|
| 186 | + ]; |
|
| 187 | + $rep_pat = [ |
|
| 188 | + '-', |
|
| 189 | + '-', |
|
| 190 | + '-', |
|
| 191 | + '-', |
|
| 192 | + '-', |
|
| 193 | + '-100', |
|
| 194 | + '-', |
|
| 195 | + '-', |
|
| 196 | + '-', |
|
| 197 | + '-', |
|
| 198 | + '-', |
|
| 199 | + '-', |
|
| 200 | + '-', |
|
| 201 | + '-', |
|
| 202 | + '-', |
|
| 203 | + '-', |
|
| 204 | + '-', |
|
| 205 | + '-', |
|
| 206 | + '-at-', |
|
| 207 | + '-', |
|
| 208 | + '-', |
|
| 209 | + '-', |
|
| 210 | + '-', |
|
| 211 | + '-', |
|
| 212 | + '-', |
|
| 213 | + '-', |
|
| 214 | + '-', |
|
| 215 | + '-' |
|
| 216 | + ]; |
|
| 217 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 218 | + |
|
| 219 | + // Transformation des caractères accentués |
|
| 220 | + $pattern = [ |
|
| 221 | + '/%B0/', // ° |
|
| 222 | + '/%E8/', // è |
|
| 223 | + '/%E9/', // é |
|
| 224 | + '/%EA/', // ê |
|
| 225 | + '/%EB/', // ë |
|
| 226 | + '/%E7/', // ç |
|
| 227 | + '/%E0/', // à |
|
| 228 | + '/%E2/', // â |
|
| 229 | + '/%E4/', // ä |
|
| 230 | + '/%EE/', // î |
|
| 231 | + '/%EF/', // ï |
|
| 232 | + '/%F9/', // ù |
|
| 233 | + '/%FC/', // ü |
|
| 234 | + '/%FB/', // û |
|
| 235 | + '/%F4/', // ô |
|
| 236 | + '/%F6/', // ö |
|
| 237 | + ]; |
|
| 238 | + $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 239 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 240 | + |
|
| 241 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 242 | + $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 243 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 244 | + |
|
| 245 | + $title .= time(); |
|
| 246 | + $title = md5($title); |
|
| 247 | + |
|
| 248 | + return $title; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @return mixed |
|
| 253 | + */ |
|
| 254 | + public function getCustomtagName() |
|
| 255 | + { |
|
| 256 | + $ret = $this->getVar('name'); |
|
| 257 | + |
|
| 258 | + return $ret; |
|
| 259 | + } |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -264,48 +264,48 @@ discard block |
||
| 264 | 264 | */ |
| 265 | 265 | class SmartobjectCustomtagHandler extends SmartPersistableObjectHandler |
| 266 | 266 | { |
| 267 | - public $objects = false; |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * SmartobjectCustomtagHandler constructor. |
|
| 271 | - * @param XoopsDatabase $db |
|
| 272 | - */ |
|
| 273 | - public function __construct(XoopsDatabase $db) |
|
| 274 | - { |
|
| 275 | - parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
| 276 | - $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @return array|bool |
|
| 281 | - */ |
|
| 282 | - public function getCustomtagsByName() |
|
| 283 | - { |
|
| 284 | - if (!$this->objects) { |
|
| 285 | - global $xoopsConfig; |
|
| 286 | - |
|
| 287 | - $ret = []; |
|
| 288 | - |
|
| 289 | - $criteria = new CriteriaCompo(); |
|
| 290 | - |
|
| 291 | - $criteria_language = new CriteriaCompo(); |
|
| 292 | - $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
| 293 | - $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
| 294 | - $criteria->add($criteria_language); |
|
| 295 | - |
|
| 296 | - $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
| 297 | - $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
| 298 | - |
|
| 299 | - if ($granted_ids && count($granted_ids) > 0) { |
|
| 300 | - $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
| 301 | - $customtagsObj = $this->getObjects($criteria, true); |
|
| 302 | - foreach ($customtagsObj as $customtagObj) { |
|
| 303 | - $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - $this->objects = $ret; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - return $this->objects; |
|
| 310 | - } |
|
| 267 | + public $objects = false; |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * SmartobjectCustomtagHandler constructor. |
|
| 271 | + * @param XoopsDatabase $db |
|
| 272 | + */ |
|
| 273 | + public function __construct(XoopsDatabase $db) |
|
| 274 | + { |
|
| 275 | + parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
| 276 | + $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @return array|bool |
|
| 281 | + */ |
|
| 282 | + public function getCustomtagsByName() |
|
| 283 | + { |
|
| 284 | + if (!$this->objects) { |
|
| 285 | + global $xoopsConfig; |
|
| 286 | + |
|
| 287 | + $ret = []; |
|
| 288 | + |
|
| 289 | + $criteria = new CriteriaCompo(); |
|
| 290 | + |
|
| 291 | + $criteria_language = new CriteriaCompo(); |
|
| 292 | + $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
| 293 | + $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
| 294 | + $criteria->add($criteria_language); |
|
| 295 | + |
|
| 296 | + $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
| 297 | + $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
| 298 | + |
|
| 299 | + if ($granted_ids && count($granted_ids) > 0) { |
|
| 300 | + $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
| 301 | + $customtagsObj = $this->getObjects($criteria, true); |
|
| 302 | + foreach ($customtagsObj as $customtagObj) { |
|
| 303 | + $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + $this->objects = $ret; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + return $this->objects; |
|
| 310 | + } |
|
| 311 | 311 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
| 31 | 31 | |
| 32 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
| 32 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Class SmartobjectCustomtag |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function getXoopsCode() |
| 124 | 124 | { |
| 125 | - $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
| 125 | + $ret = '[customtag]'.$this->getVar('tag', 'n').'[/customtag]'; |
|
| 126 | 126 | |
| 127 | 127 | return $ret; |
| 128 | 128 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | public function getCloneLink() |
| 134 | 134 | { |
| 135 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/customtag.php?op=clone&customtagid=' . $this->id() . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" style="vertical-align: middle;" alt="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" title="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '"></a>'; |
|
| 135 | + $ret = '<a href="'.SMARTOBJECT_URL.'admin/customtag.php?op=clone&customtagid='.$this->id().'"><img src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'editcopy.png" style="vertical-align: middle;" alt="'._CO_SOBJECT_CUSTOMTAG_CLONE.'" title="'._CO_SOBJECT_CUSTOMTAG_CLONE.'"></a>'; |
|
| 136 | 136 | |
| 137 | 137 | return $ret; |
| 138 | 138 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
| 298 | 298 | |
| 299 | 299 | if ($granted_ids && count($granted_ids) > 0) { |
| 300 | - $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
| 300 | + $criteria->add(new Criteria('customtagid', '('.implode(', ', $granted_ids).')', 'IN')); |
|
| 301 | 301 | $customtagsObj = $this->getObjects($criteria, true); |
| 302 | 302 | foreach ($customtagsObj as $customtagObj) { |
| 303 | 303 | $ret[$customtagObj->getVar('name')] = $customtagObj; |
@@ -12,8 +12,8 @@ |
||
| 12 | 12 | class SmartFormUploadElement extends XoopsFormFile |
| 13 | 13 | { |
| 14 | 14 | /** |
| 15 | - * @param $object |
|
| 16 | - * @param $key |
|
| 15 | + * @param string $object |
|
| 16 | + * @param string $key |
|
| 17 | 17 | */ |
| 18 | 18 | public function SmartFormFileElement($object, $key) |
| 19 | 19 | { |
@@ -11,25 +11,25 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class SmartFormUploadElement extends XoopsFormFile |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @param $object |
|
| 16 | - * @param $key |
|
| 17 | - */ |
|
| 18 | - public function SmartFormFileElement($object, $key) |
|
| 19 | - { |
|
| 20 | - parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
| 21 | - $this->setExtra(' size=50'); |
|
| 22 | - } |
|
| 14 | + /** |
|
| 15 | + * @param $object |
|
| 16 | + * @param $key |
|
| 17 | + */ |
|
| 18 | + public function SmartFormFileElement($object, $key) |
|
| 19 | + { |
|
| 20 | + parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
| 21 | + $this->setExtra(' size=50'); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * prepare HTML for output |
|
| 26 | - * |
|
| 27 | - * @return string HTML |
|
| 28 | - */ |
|
| 29 | - public function render() |
|
| 30 | - { |
|
| 31 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 24 | + /** |
|
| 25 | + * prepare HTML for output |
|
| 26 | + * |
|
| 27 | + * @return string HTML |
|
| 28 | + */ |
|
| 29 | + public function render() |
|
| 30 | + { |
|
| 31 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 32 | 32 | <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
| 33 | 33 | <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>"; |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -28,8 +28,8 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | public function render() |
| 30 | 30 | { |
| 31 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 32 | - <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
|
| 33 | - <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>"; |
|
| 31 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."'> |
|
| 32 | + <input type='file' name='" . $this->getName()."' id='".$this->getName()."'".$this->getExtra()."> |
|
| 33 | + <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName()."'>"; |
|
| 34 | 34 | } |
| 35 | 35 | } |
@@ -306,8 +306,8 @@ |
||
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
| 309 | - * @param $form_name |
|
| 310 | - * @param $form_caption |
|
| 309 | + * @param string $form_name |
|
| 310 | + * @param string $form_caption |
|
| 311 | 311 | * @param bool $submit_button_caption |
| 312 | 312 | */ |
| 313 | 313 | public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
@@ -30,803 +30,803 @@ 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( |
|
| 54 | - &$target, |
|
| 55 | - $form_name, |
|
| 56 | - $form_caption, |
|
| 57 | - $form_action, |
|
| 58 | - $form_fields = null, |
|
| 59 | - $submit_button_caption = false, |
|
| 60 | - $cancel_js_action = false, |
|
| 61 | - $captcha = false |
|
| 62 | - ) { |
|
| 63 | - $this->targetObject =& $target; |
|
| 64 | - $this->form_fields = $form_fields; |
|
| 65 | - $this->_cancel_js_action = $cancel_js_action; |
|
| 66 | - $this->_captcha = $captcha; |
|
| 67 | - $this->_form_name = $form_name; |
|
| 68 | - $this->_form_caption = $form_caption; |
|
| 69 | - $this->_submit_button_caption = $submit_button_caption; |
|
| 70 | - |
|
| 71 | - if (!isset($form_action)) { |
|
| 72 | - $form_action = xoops_getenv('PHP_SELF'); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 76 | - $this->setExtra('enctype="multipart/form-data"'); |
|
| 77 | - |
|
| 78 | - $this->createElements(); |
|
| 79 | - |
|
| 80 | - if ($captcha) { |
|
| 81 | - $this->addCaptcha(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $this->createPermissionControls(); |
|
| 85 | - |
|
| 86 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function addCaptcha() |
|
| 90 | - { |
|
| 91 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 92 | - $this->addElement(new XoopsFormCaptcha(), true); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @param $name |
|
| 97 | - * @param $caption |
|
| 98 | - * @param bool $onclick |
|
| 99 | - */ |
|
| 100 | - public function addCustomButton($name, $caption, $onclick = false) |
|
| 101 | - { |
|
| 102 | - $custom_button_array = [ |
|
| 103 | - 'name' => $name, |
|
| 104 | - 'caption' => $caption, |
|
| 105 | - 'onclick' => $onclick |
|
| 106 | - ]; |
|
| 107 | - $this->_custom_button[] = $custom_button_array; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Add an element to the form |
|
| 112 | - * |
|
| 113 | - * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 114 | - * @param bool $key |
|
| 115 | - * @param bool $var |
|
| 116 | - * @param bool|string $required is this a "required" element? |
|
| 117 | - */ |
|
| 118 | - public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 119 | - { |
|
| 120 | - if ($key) { |
|
| 121 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
| 122 | - $formElement->setExtra('disabled="disabled"'); |
|
| 123 | - $formElement->setName($key . '-readonly'); |
|
| 124 | - // Since this element is disable, we still want to pass it's value in the form |
|
| 125 | - $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 126 | - $this->addElement($hidden); |
|
| 127 | - } |
|
| 128 | - $formElement->setDescription($var['form_dsc']); |
|
| 129 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 130 | - $hidden = new XoopsFormHidden('changedField', false); |
|
| 131 | - $this->addElement($hidden); |
|
| 132 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 133 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 134 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 135 | - } else { |
|
| 136 | - if (isset($var['form_extra'])) { |
|
| 137 | - $formElement->setExtra($var['form_extra']); |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - $controls = $this->targetObject->controls; |
|
| 141 | - if (isset($controls[$key]['js'])) { |
|
| 142 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 143 | - } |
|
| 144 | - parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
| 145 | - } else { |
|
| 146 | - parent::addElement($formElement, $required === 'notset' ? false : true); |
|
| 147 | - } |
|
| 148 | - unset($formElement); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function createElements() |
|
| 152 | - { |
|
| 153 | - $controls = $this->targetObject->controls; |
|
| 154 | - $vars = $this->targetObject->vars; |
|
| 155 | - foreach ($vars as $key => $var) { |
|
| 156 | - |
|
| 157 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 158 | - // need to be displayed, then we only create an hidden field |
|
| 159 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 160 | - $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
| 161 | - $this->addElement($elementToAdd, $key, $var, false); |
|
| 162 | - unset($elementToAdd); |
|
| 163 | - // If not, the we need to create the proper form control for this fields |
|
| 164 | - } else { |
|
| 165 | - // If this field has a specific control, we will use it |
|
| 166 | - |
|
| 167 | - if ($key === 'parentid') { |
|
| 168 | - /** |
|
| 169 | - * Why this ? |
|
| 170 | - */ |
|
| 171 | - } |
|
| 172 | - if (isset($controls[$key])) { |
|
| 173 | - /* 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( |
|
| 54 | + &$target, |
|
| 55 | + $form_name, |
|
| 56 | + $form_caption, |
|
| 57 | + $form_action, |
|
| 58 | + $form_fields = null, |
|
| 59 | + $submit_button_caption = false, |
|
| 60 | + $cancel_js_action = false, |
|
| 61 | + $captcha = false |
|
| 62 | + ) { |
|
| 63 | + $this->targetObject =& $target; |
|
| 64 | + $this->form_fields = $form_fields; |
|
| 65 | + $this->_cancel_js_action = $cancel_js_action; |
|
| 66 | + $this->_captcha = $captcha; |
|
| 67 | + $this->_form_name = $form_name; |
|
| 68 | + $this->_form_caption = $form_caption; |
|
| 69 | + $this->_submit_button_caption = $submit_button_caption; |
|
| 70 | + |
|
| 71 | + if (!isset($form_action)) { |
|
| 72 | + $form_action = xoops_getenv('PHP_SELF'); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 76 | + $this->setExtra('enctype="multipart/form-data"'); |
|
| 77 | + |
|
| 78 | + $this->createElements(); |
|
| 79 | + |
|
| 80 | + if ($captcha) { |
|
| 81 | + $this->addCaptcha(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $this->createPermissionControls(); |
|
| 85 | + |
|
| 86 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function addCaptcha() |
|
| 90 | + { |
|
| 91 | + require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 92 | + $this->addElement(new XoopsFormCaptcha(), true); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @param $name |
|
| 97 | + * @param $caption |
|
| 98 | + * @param bool $onclick |
|
| 99 | + */ |
|
| 100 | + public function addCustomButton($name, $caption, $onclick = false) |
|
| 101 | + { |
|
| 102 | + $custom_button_array = [ |
|
| 103 | + 'name' => $name, |
|
| 104 | + 'caption' => $caption, |
|
| 105 | + 'onclick' => $onclick |
|
| 106 | + ]; |
|
| 107 | + $this->_custom_button[] = $custom_button_array; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Add an element to the form |
|
| 112 | + * |
|
| 113 | + * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 114 | + * @param bool $key |
|
| 115 | + * @param bool $var |
|
| 116 | + * @param bool|string $required is this a "required" element? |
|
| 117 | + */ |
|
| 118 | + public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 119 | + { |
|
| 120 | + if ($key) { |
|
| 121 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
| 122 | + $formElement->setExtra('disabled="disabled"'); |
|
| 123 | + $formElement->setName($key . '-readonly'); |
|
| 124 | + // Since this element is disable, we still want to pass it's value in the form |
|
| 125 | + $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 126 | + $this->addElement($hidden); |
|
| 127 | + } |
|
| 128 | + $formElement->setDescription($var['form_dsc']); |
|
| 129 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 130 | + $hidden = new XoopsFormHidden('changedField', false); |
|
| 131 | + $this->addElement($hidden); |
|
| 132 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 133 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 134 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 135 | + } else { |
|
| 136 | + if (isset($var['form_extra'])) { |
|
| 137 | + $formElement->setExtra($var['form_extra']); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + $controls = $this->targetObject->controls; |
|
| 141 | + if (isset($controls[$key]['js'])) { |
|
| 142 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 143 | + } |
|
| 144 | + parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
| 145 | + } else { |
|
| 146 | + parent::addElement($formElement, $required === 'notset' ? false : true); |
|
| 147 | + } |
|
| 148 | + unset($formElement); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function createElements() |
|
| 152 | + { |
|
| 153 | + $controls = $this->targetObject->controls; |
|
| 154 | + $vars = $this->targetObject->vars; |
|
| 155 | + foreach ($vars as $key => $var) { |
|
| 156 | + |
|
| 157 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 158 | + // need to be displayed, then we only create an hidden field |
|
| 159 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 160 | + $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
| 161 | + $this->addElement($elementToAdd, $key, $var, false); |
|
| 162 | + unset($elementToAdd); |
|
| 163 | + // If not, the we need to create the proper form control for this fields |
|
| 164 | + } else { |
|
| 165 | + // If this field has a specific control, we will use it |
|
| 166 | + |
|
| 167 | + if ($key === 'parentid') { |
|
| 168 | + /** |
|
| 169 | + * Why this ? |
|
| 170 | + */ |
|
| 171 | + } |
|
| 172 | + if (isset($controls[$key])) { |
|
| 173 | + /* If the control has name, it's because it's an object already present in the script |
|
| 174 | 174 | * for example, "user" |
| 175 | 175 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
| 176 | 176 | */ |
| 177 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 178 | - $controls[$key]['name'] = 'select'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 182 | - |
|
| 183 | - // Adding on the form, the control for this field |
|
| 184 | - $this->addElement($form_select, $key, $var); |
|
| 185 | - unset($form_select); |
|
| 186 | - |
|
| 187 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 188 | - } else { |
|
| 189 | - switch ($var['data_type']) { |
|
| 190 | - |
|
| 191 | - case XOBJ_DTYPE_TXTBOX: |
|
| 192 | - |
|
| 193 | - $form_text = $this->getControl('text', $key); |
|
| 194 | - $this->addElement($form_text, $key, $var); |
|
| 195 | - unset($form_text); |
|
| 196 | - break; |
|
| 197 | - |
|
| 198 | - case XOBJ_DTYPE_INT: |
|
| 199 | - $this->targetObject->setControl($key, [ |
|
| 200 | - 'name' => 'text', |
|
| 201 | - 'size' => '5' |
|
| 202 | - ]); |
|
| 203 | - $form_text = $this->getControl('text', $key); |
|
| 204 | - $this->addElement($form_text, $key, $var); |
|
| 205 | - unset($form_text); |
|
| 206 | - break; |
|
| 207 | - |
|
| 208 | - case XOBJ_DTYPE_FLOAT: |
|
| 209 | - $this->targetObject->setControl($key, [ |
|
| 210 | - 'name' => 'text', |
|
| 211 | - 'size' => '5' |
|
| 212 | - ]); |
|
| 213 | - $form_text = $this->getControl('text', $key); |
|
| 214 | - $this->addElement($form_text, $key, $var); |
|
| 215 | - unset($form_text); |
|
| 216 | - break; |
|
| 217 | - |
|
| 218 | - case XOBJ_DTYPE_LTIME: |
|
| 219 | - $form_date_time = $this->getControl('date_time', $key); |
|
| 220 | - $this->addElement($form_date_time, $key, $var); |
|
| 221 | - unset($form_date_time); |
|
| 222 | - break; |
|
| 223 | - |
|
| 224 | - case XOBJ_DTYPE_STIME: |
|
| 225 | - $form_date_time = $this->getControl('date', $key); |
|
| 226 | - $this->addElement($form_date_time, $key, $var); |
|
| 227 | - unset($form_date_time); |
|
| 228 | - break; |
|
| 229 | - |
|
| 230 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 231 | - $form_time = $this->getControl('time', $key); |
|
| 232 | - $this->addElement($form_time, $key, $var); |
|
| 233 | - unset($form_time); |
|
| 234 | - break; |
|
| 235 | - |
|
| 236 | - case XOBJ_DTYPE_CURRENCY: |
|
| 237 | - $this->targetObject->setControl($key, [ |
|
| 238 | - 'name' => 'text', |
|
| 239 | - 'size' => '15' |
|
| 240 | - ]); |
|
| 241 | - $form_currency = $this->getControl('text', $key); |
|
| 242 | - $this->addElement($form_currency, $key, $var); |
|
| 243 | - unset($form_currency); |
|
| 244 | - break; |
|
| 245 | - |
|
| 246 | - case XOBJ_DTYPE_URLLINK: |
|
| 247 | - $form_urllink = $this->getControl('urllink', $key); |
|
| 248 | - $this->addElement($form_urllink, $key, $var); |
|
| 249 | - unset($form_urllink); |
|
| 250 | - break; |
|
| 251 | - |
|
| 252 | - case XOBJ_DTYPE_FILE: |
|
| 253 | - $form_file = $this->getControl('richfile', $key); |
|
| 254 | - $this->addElement($form_file, $key, $var); |
|
| 255 | - unset($form_file); |
|
| 256 | - break; |
|
| 257 | - |
|
| 258 | - case XOBJ_DTYPE_TXTAREA: |
|
| 259 | - |
|
| 260 | - $form_text_area = $this->getTextArea($key, $var); |
|
| 261 | - $this->addElement($form_text_area, $key, $var); |
|
| 262 | - unset($form_text_area); |
|
| 263 | - break; |
|
| 264 | - |
|
| 265 | - case XOBJ_DTYPE_ARRAY: |
|
| 266 | - // TODO: To come... |
|
| 267 | - break; |
|
| 268 | - case XOBJ_DTYPE_SOURCE: |
|
| 269 | - // TODO: To come... |
|
| 270 | - break; |
|
| 271 | - case XOBJ_DTYPE_FORM_SECTION: |
|
| 272 | - $section_control = new SmartFormSection($key, $var['value']); |
|
| 273 | - $this->addElement($section_control, $key, $var); |
|
| 274 | - unset($section_control); |
|
| 275 | - break; |
|
| 276 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 277 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 278 | - $this->addElement($section_control, $key, $var); |
|
| 279 | - unset($section_control); |
|
| 280 | - break; |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - // Add an hidden field to store the URL of the page before this form |
|
| 286 | - $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - public function createPermissionControls() |
|
| 290 | - { |
|
| 291 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 292 | - |
|
| 293 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
| 294 | - |
|
| 295 | - if ($permissions) { |
|
| 296 | - $memberHandler = xoops_getHandler('member'); |
|
| 297 | - $group_list = $memberHandler->getGroupList(); |
|
| 298 | - asort($group_list); |
|
| 299 | - foreach ($permissions as $permission) { |
|
| 300 | - if ($this->targetObject->isNew()) { |
|
| 301 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 302 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 303 | - } |
|
| 304 | - } else { |
|
| 305 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 306 | - } |
|
| 307 | - $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 308 | - $groups_select->setDescription($permission['description']); |
|
| 309 | - $groups_select->addOptionArray($group_list); |
|
| 310 | - $this->addElement($groups_select); |
|
| 311 | - unset($groups_select); |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @param $form_name |
|
| 318 | - * @param $form_caption |
|
| 319 | - * @param bool $submit_button_caption |
|
| 320 | - */ |
|
| 321 | - public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 322 | - { |
|
| 323 | - $button_tray = new XoopsFormElementTray('', ''); |
|
| 324 | - $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
| 325 | - if (!$submit_button_caption) { |
|
| 326 | - if ($this->targetObject->isNew()) { |
|
| 327 | - $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 328 | - } else { |
|
| 329 | - $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 330 | - } |
|
| 331 | - } else { |
|
| 332 | - $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 333 | - } |
|
| 334 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 335 | - $button_tray->addElement($butt_create); |
|
| 336 | - |
|
| 337 | - //creating custom buttons |
|
| 338 | - if ($this->_custom_button) { |
|
| 339 | - foreach ($this->_custom_button as $custom_button) { |
|
| 340 | - $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 341 | - if ($custom_button['onclick']) { |
|
| 342 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 343 | - } |
|
| 344 | - $button_tray->addElement($butt_custom); |
|
| 345 | - unset($butt_custom); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - // creating the "cancel" button |
|
| 350 | - $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 351 | - if ($this->_cancel_js_action) { |
|
| 352 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 353 | - } else { |
|
| 354 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 355 | - } |
|
| 356 | - $button_tray->addElement($butt_cancel); |
|
| 357 | - |
|
| 358 | - $this->addElement($button_tray); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * @param $controlName |
|
| 363 | - * @param $key |
|
| 364 | - * @return XoopsFormLabel |
|
| 365 | - */ |
|
| 366 | - public function getControl($controlName, $key) |
|
| 367 | - { |
|
| 368 | - switch ($controlName) { |
|
| 369 | - case 'check': |
|
| 370 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
| 371 | - $control = $this->targetObject->getControl($key); |
|
| 372 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 373 | - $controlObj->addOptionArray($control['options']); |
|
| 374 | - |
|
| 375 | - return $controlObj; |
|
| 376 | - break; |
|
| 377 | - |
|
| 378 | - case 'color': |
|
| 379 | - $control = $this->targetObject->getControl($key); |
|
| 380 | - $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 381 | - |
|
| 382 | - return $controlObj; |
|
| 383 | - break; |
|
| 384 | - |
|
| 385 | - case 'radio': |
|
| 386 | - $control = $this->targetObject->getControl($key); |
|
| 387 | - |
|
| 388 | - $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 389 | - $controlObj->addOptionArray($control['options']); |
|
| 390 | - |
|
| 391 | - return $controlObj; |
|
| 392 | - break; |
|
| 393 | - |
|
| 394 | - case 'label': |
|
| 395 | - return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 396 | - break; |
|
| 397 | - |
|
| 398 | - case 'textarea': |
|
| 399 | - return $this->getTextArea($key); |
|
| 400 | - |
|
| 401 | - case 'theme': |
|
| 402 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 403 | - |
|
| 404 | - case 'theme_multi': |
|
| 405 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 406 | - break; |
|
| 407 | - |
|
| 408 | - case 'timezone': |
|
| 409 | - return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 410 | - break; |
|
| 411 | - |
|
| 412 | - case 'group': |
|
| 413 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 414 | - break; |
|
| 415 | - |
|
| 416 | - case 'group_multi': |
|
| 417 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 418 | - break; |
|
| 419 | - |
|
| 420 | - /*case 'user': |
|
| 177 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 178 | + $controls[$key]['name'] = 'select'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 182 | + |
|
| 183 | + // Adding on the form, the control for this field |
|
| 184 | + $this->addElement($form_select, $key, $var); |
|
| 185 | + unset($form_select); |
|
| 186 | + |
|
| 187 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 188 | + } else { |
|
| 189 | + switch ($var['data_type']) { |
|
| 190 | + |
|
| 191 | + case XOBJ_DTYPE_TXTBOX: |
|
| 192 | + |
|
| 193 | + $form_text = $this->getControl('text', $key); |
|
| 194 | + $this->addElement($form_text, $key, $var); |
|
| 195 | + unset($form_text); |
|
| 196 | + break; |
|
| 197 | + |
|
| 198 | + case XOBJ_DTYPE_INT: |
|
| 199 | + $this->targetObject->setControl($key, [ |
|
| 200 | + 'name' => 'text', |
|
| 201 | + 'size' => '5' |
|
| 202 | + ]); |
|
| 203 | + $form_text = $this->getControl('text', $key); |
|
| 204 | + $this->addElement($form_text, $key, $var); |
|
| 205 | + unset($form_text); |
|
| 206 | + break; |
|
| 207 | + |
|
| 208 | + case XOBJ_DTYPE_FLOAT: |
|
| 209 | + $this->targetObject->setControl($key, [ |
|
| 210 | + 'name' => 'text', |
|
| 211 | + 'size' => '5' |
|
| 212 | + ]); |
|
| 213 | + $form_text = $this->getControl('text', $key); |
|
| 214 | + $this->addElement($form_text, $key, $var); |
|
| 215 | + unset($form_text); |
|
| 216 | + break; |
|
| 217 | + |
|
| 218 | + case XOBJ_DTYPE_LTIME: |
|
| 219 | + $form_date_time = $this->getControl('date_time', $key); |
|
| 220 | + $this->addElement($form_date_time, $key, $var); |
|
| 221 | + unset($form_date_time); |
|
| 222 | + break; |
|
| 223 | + |
|
| 224 | + case XOBJ_DTYPE_STIME: |
|
| 225 | + $form_date_time = $this->getControl('date', $key); |
|
| 226 | + $this->addElement($form_date_time, $key, $var); |
|
| 227 | + unset($form_date_time); |
|
| 228 | + break; |
|
| 229 | + |
|
| 230 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 231 | + $form_time = $this->getControl('time', $key); |
|
| 232 | + $this->addElement($form_time, $key, $var); |
|
| 233 | + unset($form_time); |
|
| 234 | + break; |
|
| 235 | + |
|
| 236 | + case XOBJ_DTYPE_CURRENCY: |
|
| 237 | + $this->targetObject->setControl($key, [ |
|
| 238 | + 'name' => 'text', |
|
| 239 | + 'size' => '15' |
|
| 240 | + ]); |
|
| 241 | + $form_currency = $this->getControl('text', $key); |
|
| 242 | + $this->addElement($form_currency, $key, $var); |
|
| 243 | + unset($form_currency); |
|
| 244 | + break; |
|
| 245 | + |
|
| 246 | + case XOBJ_DTYPE_URLLINK: |
|
| 247 | + $form_urllink = $this->getControl('urllink', $key); |
|
| 248 | + $this->addElement($form_urllink, $key, $var); |
|
| 249 | + unset($form_urllink); |
|
| 250 | + break; |
|
| 251 | + |
|
| 252 | + case XOBJ_DTYPE_FILE: |
|
| 253 | + $form_file = $this->getControl('richfile', $key); |
|
| 254 | + $this->addElement($form_file, $key, $var); |
|
| 255 | + unset($form_file); |
|
| 256 | + break; |
|
| 257 | + |
|
| 258 | + case XOBJ_DTYPE_TXTAREA: |
|
| 259 | + |
|
| 260 | + $form_text_area = $this->getTextArea($key, $var); |
|
| 261 | + $this->addElement($form_text_area, $key, $var); |
|
| 262 | + unset($form_text_area); |
|
| 263 | + break; |
|
| 264 | + |
|
| 265 | + case XOBJ_DTYPE_ARRAY: |
|
| 266 | + // TODO: To come... |
|
| 267 | + break; |
|
| 268 | + case XOBJ_DTYPE_SOURCE: |
|
| 269 | + // TODO: To come... |
|
| 270 | + break; |
|
| 271 | + case XOBJ_DTYPE_FORM_SECTION: |
|
| 272 | + $section_control = new SmartFormSection($key, $var['value']); |
|
| 273 | + $this->addElement($section_control, $key, $var); |
|
| 274 | + unset($section_control); |
|
| 275 | + break; |
|
| 276 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 277 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 278 | + $this->addElement($section_control, $key, $var); |
|
| 279 | + unset($section_control); |
|
| 280 | + break; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + // Add an hidden field to store the URL of the page before this form |
|
| 286 | + $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + public function createPermissionControls() |
|
| 290 | + { |
|
| 291 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 292 | + |
|
| 293 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
| 294 | + |
|
| 295 | + if ($permissions) { |
|
| 296 | + $memberHandler = xoops_getHandler('member'); |
|
| 297 | + $group_list = $memberHandler->getGroupList(); |
|
| 298 | + asort($group_list); |
|
| 299 | + foreach ($permissions as $permission) { |
|
| 300 | + if ($this->targetObject->isNew()) { |
|
| 301 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 302 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 303 | + } |
|
| 304 | + } else { |
|
| 305 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 306 | + } |
|
| 307 | + $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 308 | + $groups_select->setDescription($permission['description']); |
|
| 309 | + $groups_select->addOptionArray($group_list); |
|
| 310 | + $this->addElement($groups_select); |
|
| 311 | + unset($groups_select); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @param $form_name |
|
| 318 | + * @param $form_caption |
|
| 319 | + * @param bool $submit_button_caption |
|
| 320 | + */ |
|
| 321 | + public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 322 | + { |
|
| 323 | + $button_tray = new XoopsFormElementTray('', ''); |
|
| 324 | + $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
| 325 | + if (!$submit_button_caption) { |
|
| 326 | + if ($this->targetObject->isNew()) { |
|
| 327 | + $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 328 | + } else { |
|
| 329 | + $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 330 | + } |
|
| 331 | + } else { |
|
| 332 | + $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 333 | + } |
|
| 334 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 335 | + $button_tray->addElement($butt_create); |
|
| 336 | + |
|
| 337 | + //creating custom buttons |
|
| 338 | + if ($this->_custom_button) { |
|
| 339 | + foreach ($this->_custom_button as $custom_button) { |
|
| 340 | + $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 341 | + if ($custom_button['onclick']) { |
|
| 342 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 343 | + } |
|
| 344 | + $button_tray->addElement($butt_custom); |
|
| 345 | + unset($butt_custom); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + // creating the "cancel" button |
|
| 350 | + $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 351 | + if ($this->_cancel_js_action) { |
|
| 352 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 353 | + } else { |
|
| 354 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 355 | + } |
|
| 356 | + $button_tray->addElement($butt_cancel); |
|
| 357 | + |
|
| 358 | + $this->addElement($button_tray); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * @param $controlName |
|
| 363 | + * @param $key |
|
| 364 | + * @return XoopsFormLabel |
|
| 365 | + */ |
|
| 366 | + public function getControl($controlName, $key) |
|
| 367 | + { |
|
| 368 | + switch ($controlName) { |
|
| 369 | + case 'check': |
|
| 370 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
| 371 | + $control = $this->targetObject->getControl($key); |
|
| 372 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 373 | + $controlObj->addOptionArray($control['options']); |
|
| 374 | + |
|
| 375 | + return $controlObj; |
|
| 376 | + break; |
|
| 377 | + |
|
| 378 | + case 'color': |
|
| 379 | + $control = $this->targetObject->getControl($key); |
|
| 380 | + $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 381 | + |
|
| 382 | + return $controlObj; |
|
| 383 | + break; |
|
| 384 | + |
|
| 385 | + case 'radio': |
|
| 386 | + $control = $this->targetObject->getControl($key); |
|
| 387 | + |
|
| 388 | + $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 389 | + $controlObj->addOptionArray($control['options']); |
|
| 390 | + |
|
| 391 | + return $controlObj; |
|
| 392 | + break; |
|
| 393 | + |
|
| 394 | + case 'label': |
|
| 395 | + return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 396 | + break; |
|
| 397 | + |
|
| 398 | + case 'textarea': |
|
| 399 | + return $this->getTextArea($key); |
|
| 400 | + |
|
| 401 | + case 'theme': |
|
| 402 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 403 | + |
|
| 404 | + case 'theme_multi': |
|
| 405 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 406 | + break; |
|
| 407 | + |
|
| 408 | + case 'timezone': |
|
| 409 | + return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 410 | + break; |
|
| 411 | + |
|
| 412 | + case 'group': |
|
| 413 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 414 | + break; |
|
| 415 | + |
|
| 416 | + case 'group_multi': |
|
| 417 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 418 | + break; |
|
| 419 | + |
|
| 420 | + /*case 'user': |
|
| 421 | 421 | return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
| 422 | 422 | break;*/ |
| 423 | 423 | |
| 424 | - case 'user_multi': |
|
| 425 | - return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 426 | - break; |
|
| 427 | - |
|
| 428 | - case 'password': |
|
| 429 | - return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 430 | - break; |
|
| 431 | - |
|
| 432 | - case 'country': |
|
| 433 | - return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 434 | - break; |
|
| 435 | - |
|
| 436 | - case 'urllink': |
|
| 437 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
|
| 438 | - |
|
| 439 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 440 | - break; |
|
| 441 | - |
|
| 442 | - case 'richfile': |
|
| 443 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
|
| 444 | - |
|
| 445 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 446 | - break; |
|
| 447 | - case 'section': |
|
| 448 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
| 449 | - |
|
| 450 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 451 | - break; |
|
| 452 | - |
|
| 453 | - default: |
|
| 454 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 455 | - if (!class_exists($classname)) { |
|
| 456 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 457 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
|
| 458 | - } else { |
|
| 459 | - // perhaps this is a control created by the module |
|
| 460 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
| 461 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 462 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 463 | - $classFileName = strtolower($classname) . '.php'; |
|
| 464 | - |
|
| 465 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 466 | - require_once $moduleFormElementsPath . $classFileName; |
|
| 467 | - } else { |
|
| 468 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 469 | - |
|
| 470 | - return new XoopsFormLabel(); //Empty object |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - return new $classname($this->targetObject, $key); |
|
| 476 | - break; |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * @param $key |
|
| 482 | - * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
| 483 | - */ |
|
| 484 | - public function getTextArea($key) |
|
| 485 | - { |
|
| 486 | - $var = $this->targetObject->vars[$key]; |
|
| 487 | - |
|
| 488 | - // if no control has been created, let's create a default one |
|
| 489 | - if (!isset($this->targetObject->controls[$key])) { |
|
| 490 | - $control = [ |
|
| 491 | - 'name' => 'textarea', |
|
| 492 | - 'itemHandler' => false, |
|
| 493 | - 'method' => false, |
|
| 494 | - 'module' => false, |
|
| 495 | - 'form_editor' => 'default' |
|
| 496 | - ]; |
|
| 497 | - } else { |
|
| 498 | - $control = $this->targetObject->controls[$key]; |
|
| 499 | - } |
|
| 500 | - $xoops22 = smart_isXoops22(); |
|
| 501 | - |
|
| 502 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 503 | - /** |
|
| 504 | - * If the editor is 'default', retreive the default editor of this module |
|
| 505 | - */ |
|
| 506 | - if ($form_editor === 'default') { |
|
| 507 | - global $xoopsModuleConfig; |
|
| 508 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - $caption = $var['form_caption']; |
|
| 512 | - $name = $key; |
|
| 513 | - |
|
| 514 | - $value = $this->targetObject->getVar($key); |
|
| 515 | - |
|
| 516 | - $value = $this->targetObject->getValueFor($key, true); |
|
| 517 | - |
|
| 518 | - $editor_configs = []; |
|
| 519 | - $editor_configs['name'] = $name; |
|
| 520 | - $editor_configs['value'] = $value; |
|
| 521 | - if ($form_editor !== 'textarea') { |
|
| 522 | - $editor_configs['rows'] = 35; |
|
| 523 | - $editor_configs['cols'] = 60; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - if (isset($control['rows'])) { |
|
| 527 | - $editor_configs['rows'] = $control['rows']; |
|
| 528 | - } |
|
| 529 | - if (isset($control['cols'])) { |
|
| 530 | - $editor_configs['cols'] = $control['cols']; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $editor_configs['width'] = '100%'; |
|
| 534 | - $editor_configs['height'] = '400px'; |
|
| 535 | - |
|
| 536 | - $dhtml = true; |
|
| 537 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 538 | - |
|
| 539 | - if (file_exists($xoopseditorclass)) { |
|
| 540 | - require_once $xoopseditorclass; |
|
| 541 | - $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 542 | - } else { |
|
| 543 | - switch ($form_editor) { |
|
| 544 | - |
|
| 545 | - case 'tiny': |
|
| 546 | - if (!$xoops22) { |
|
| 547 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 548 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 549 | - $editor = new XoopsFormTinyTextArea([ |
|
| 550 | - 'caption' => $caption, |
|
| 551 | - 'name' => $name, |
|
| 552 | - 'value' => $value, |
|
| 553 | - 'width' => '100%', |
|
| 554 | - 'height' => '300px' |
|
| 555 | - ], true); |
|
| 556 | - } else { |
|
| 557 | - if ($dhtml) { |
|
| 558 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 559 | - } else { |
|
| 560 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } else { |
|
| 564 | - $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 565 | - } |
|
| 566 | - break; |
|
| 567 | - |
|
| 568 | - case 'dhtmltextarea': |
|
| 569 | - case 'dhtmltext': |
|
| 570 | - $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 571 | - if ($var['form_dsc']) { |
|
| 572 | - $editor->setDescription($var['form_dsc']); |
|
| 573 | - } |
|
| 574 | - break; |
|
| 575 | - |
|
| 576 | - case 'fckeditor': |
|
| 577 | - if (!$xoops22) { |
|
| 578 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
| 579 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'; |
|
| 580 | - $editor = new XoopsFormFckeditor([ |
|
| 581 | - 'caption' => $caption, |
|
| 582 | - 'name' => $name, |
|
| 583 | - 'value' => $value, |
|
| 584 | - 'width' => '100%', |
|
| 585 | - 'height' => '300px' |
|
| 586 | - ], true); |
|
| 587 | - } else { |
|
| 588 | - if ($dhtml) { |
|
| 589 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 590 | - } else { |
|
| 591 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - } else { |
|
| 595 | - $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
|
| 596 | - } |
|
| 597 | - break; |
|
| 598 | - |
|
| 599 | - case 'inbetween': |
|
| 600 | - if (!$xoops22) { |
|
| 601 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
| 602 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'; |
|
| 603 | - $editor = new XoopsFormInbetweenTextArea([ |
|
| 604 | - 'caption' => $caption, |
|
| 605 | - 'name' => $name, |
|
| 606 | - 'value' => $value, |
|
| 607 | - 'width' => '100%', |
|
| 608 | - 'height' => '300px' |
|
| 609 | - ], true); |
|
| 610 | - } else { |
|
| 611 | - if ($dhtml) { |
|
| 612 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 613 | - } else { |
|
| 614 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - } else { |
|
| 618 | - $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs); |
|
| 619 | - } |
|
| 620 | - break; |
|
| 621 | - |
|
| 622 | - case 'koivi': |
|
| 623 | - if (!$xoops22) { |
|
| 624 | - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
| 625 | - require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; |
|
| 626 | - $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
| 627 | - } else { |
|
| 628 | - if ($dhtml) { |
|
| 629 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 630 | - } else { |
|
| 631 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - } else { |
|
| 635 | - $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
|
| 636 | - } |
|
| 637 | - break; |
|
| 638 | - |
|
| 639 | - case 'spaw': |
|
| 640 | - if (!$xoops22) { |
|
| 641 | - if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
| 642 | - require_once XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'; |
|
| 643 | - $editor = new XoopsFormSpaw($caption, $name, $value); |
|
| 644 | - } |
|
| 645 | - } else { |
|
| 646 | - $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
|
| 647 | - } |
|
| 648 | - break; |
|
| 649 | - |
|
| 650 | - case 'htmlarea': |
|
| 651 | - if (!$xoops22) { |
|
| 652 | - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
| 653 | - require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
|
| 654 | - $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
| 655 | - } |
|
| 656 | - } else { |
|
| 657 | - $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
|
| 658 | - } |
|
| 659 | - break; |
|
| 660 | - |
|
| 661 | - default: |
|
| 662 | - case 'textarea': |
|
| 663 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 664 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 665 | - |
|
| 666 | - $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 667 | - if ($var['form_dsc']) { |
|
| 668 | - $editor->setDescription($var['form_dsc']); |
|
| 669 | - } |
|
| 670 | - break; |
|
| 671 | - |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - return $editor; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * @param $key |
|
| 680 | - * @param $var |
|
| 681 | - * @param bool $multiple |
|
| 682 | - * @return XoopsFormSelect |
|
| 683 | - */ |
|
| 684 | - public function getThemeSelect($key, $var, $multiple = false) |
|
| 685 | - { |
|
| 686 | - $size = $multiple ? 5 : 1; |
|
| 687 | - $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 688 | - |
|
| 689 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 690 | - $dirlist = []; |
|
| 691 | - while (false !== ($file = readdir($handle))) { |
|
| 692 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) |
|
| 693 | - && strtolower($file) !== 'cvs') { |
|
| 694 | - $dirlist[$file] = $file; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - closedir($handle); |
|
| 698 | - if (!empty($dirlist)) { |
|
| 699 | - asort($dirlist); |
|
| 700 | - $theme_select->addOptionArray($dirlist); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - return $theme_select; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * @param $keyname |
|
| 708 | - * @return bool |
|
| 709 | - */ |
|
| 710 | - public function &getElementById($keyname) |
|
| 711 | - { |
|
| 712 | - foreach ($this->_elements as $eleObj) { |
|
| 713 | - if ($eleObj->getName() == $keyname) { |
|
| 714 | - $ret =& $eleObj; |
|
| 715 | - break; |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - return isset($ret) ? $ret : false; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * create HTML to output the form as a theme-enabled table with validation. |
|
| 724 | - * |
|
| 725 | - * @return string |
|
| 726 | - */ |
|
| 727 | - public function render() |
|
| 728 | - { |
|
| 729 | - $required = $this->getRequired(); |
|
| 730 | - $ret = " |
|
| 424 | + case 'user_multi': |
|
| 425 | + return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 426 | + break; |
|
| 427 | + |
|
| 428 | + case 'password': |
|
| 429 | + return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 430 | + break; |
|
| 431 | + |
|
| 432 | + case 'country': |
|
| 433 | + return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 434 | + break; |
|
| 435 | + |
|
| 436 | + case 'urllink': |
|
| 437 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
|
| 438 | + |
|
| 439 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 440 | + break; |
|
| 441 | + |
|
| 442 | + case 'richfile': |
|
| 443 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
|
| 444 | + |
|
| 445 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 446 | + break; |
|
| 447 | + case 'section': |
|
| 448 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
| 449 | + |
|
| 450 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 451 | + break; |
|
| 452 | + |
|
| 453 | + default: |
|
| 454 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 455 | + if (!class_exists($classname)) { |
|
| 456 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 457 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
|
| 458 | + } else { |
|
| 459 | + // perhaps this is a control created by the module |
|
| 460 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
| 461 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 462 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 463 | + $classFileName = strtolower($classname) . '.php'; |
|
| 464 | + |
|
| 465 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 466 | + require_once $moduleFormElementsPath . $classFileName; |
|
| 467 | + } else { |
|
| 468 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 469 | + |
|
| 470 | + return new XoopsFormLabel(); //Empty object |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + return new $classname($this->targetObject, $key); |
|
| 476 | + break; |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * @param $key |
|
| 482 | + * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
| 483 | + */ |
|
| 484 | + public function getTextArea($key) |
|
| 485 | + { |
|
| 486 | + $var = $this->targetObject->vars[$key]; |
|
| 487 | + |
|
| 488 | + // if no control has been created, let's create a default one |
|
| 489 | + if (!isset($this->targetObject->controls[$key])) { |
|
| 490 | + $control = [ |
|
| 491 | + 'name' => 'textarea', |
|
| 492 | + 'itemHandler' => false, |
|
| 493 | + 'method' => false, |
|
| 494 | + 'module' => false, |
|
| 495 | + 'form_editor' => 'default' |
|
| 496 | + ]; |
|
| 497 | + } else { |
|
| 498 | + $control = $this->targetObject->controls[$key]; |
|
| 499 | + } |
|
| 500 | + $xoops22 = smart_isXoops22(); |
|
| 501 | + |
|
| 502 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 503 | + /** |
|
| 504 | + * If the editor is 'default', retreive the default editor of this module |
|
| 505 | + */ |
|
| 506 | + if ($form_editor === 'default') { |
|
| 507 | + global $xoopsModuleConfig; |
|
| 508 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + $caption = $var['form_caption']; |
|
| 512 | + $name = $key; |
|
| 513 | + |
|
| 514 | + $value = $this->targetObject->getVar($key); |
|
| 515 | + |
|
| 516 | + $value = $this->targetObject->getValueFor($key, true); |
|
| 517 | + |
|
| 518 | + $editor_configs = []; |
|
| 519 | + $editor_configs['name'] = $name; |
|
| 520 | + $editor_configs['value'] = $value; |
|
| 521 | + if ($form_editor !== 'textarea') { |
|
| 522 | + $editor_configs['rows'] = 35; |
|
| 523 | + $editor_configs['cols'] = 60; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + if (isset($control['rows'])) { |
|
| 527 | + $editor_configs['rows'] = $control['rows']; |
|
| 528 | + } |
|
| 529 | + if (isset($control['cols'])) { |
|
| 530 | + $editor_configs['cols'] = $control['cols']; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $editor_configs['width'] = '100%'; |
|
| 534 | + $editor_configs['height'] = '400px'; |
|
| 535 | + |
|
| 536 | + $dhtml = true; |
|
| 537 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 538 | + |
|
| 539 | + if (file_exists($xoopseditorclass)) { |
|
| 540 | + require_once $xoopseditorclass; |
|
| 541 | + $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 542 | + } else { |
|
| 543 | + switch ($form_editor) { |
|
| 544 | + |
|
| 545 | + case 'tiny': |
|
| 546 | + if (!$xoops22) { |
|
| 547 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 548 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 549 | + $editor = new XoopsFormTinyTextArea([ |
|
| 550 | + 'caption' => $caption, |
|
| 551 | + 'name' => $name, |
|
| 552 | + 'value' => $value, |
|
| 553 | + 'width' => '100%', |
|
| 554 | + 'height' => '300px' |
|
| 555 | + ], true); |
|
| 556 | + } else { |
|
| 557 | + if ($dhtml) { |
|
| 558 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 559 | + } else { |
|
| 560 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } else { |
|
| 564 | + $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 565 | + } |
|
| 566 | + break; |
|
| 567 | + |
|
| 568 | + case 'dhtmltextarea': |
|
| 569 | + case 'dhtmltext': |
|
| 570 | + $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 571 | + if ($var['form_dsc']) { |
|
| 572 | + $editor->setDescription($var['form_dsc']); |
|
| 573 | + } |
|
| 574 | + break; |
|
| 575 | + |
|
| 576 | + case 'fckeditor': |
|
| 577 | + if (!$xoops22) { |
|
| 578 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
| 579 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'; |
|
| 580 | + $editor = new XoopsFormFckeditor([ |
|
| 581 | + 'caption' => $caption, |
|
| 582 | + 'name' => $name, |
|
| 583 | + 'value' => $value, |
|
| 584 | + 'width' => '100%', |
|
| 585 | + 'height' => '300px' |
|
| 586 | + ], true); |
|
| 587 | + } else { |
|
| 588 | + if ($dhtml) { |
|
| 589 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 590 | + } else { |
|
| 591 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + } else { |
|
| 595 | + $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
|
| 596 | + } |
|
| 597 | + break; |
|
| 598 | + |
|
| 599 | + case 'inbetween': |
|
| 600 | + if (!$xoops22) { |
|
| 601 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
| 602 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'; |
|
| 603 | + $editor = new XoopsFormInbetweenTextArea([ |
|
| 604 | + 'caption' => $caption, |
|
| 605 | + 'name' => $name, |
|
| 606 | + 'value' => $value, |
|
| 607 | + 'width' => '100%', |
|
| 608 | + 'height' => '300px' |
|
| 609 | + ], true); |
|
| 610 | + } else { |
|
| 611 | + if ($dhtml) { |
|
| 612 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 613 | + } else { |
|
| 614 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + } else { |
|
| 618 | + $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs); |
|
| 619 | + } |
|
| 620 | + break; |
|
| 621 | + |
|
| 622 | + case 'koivi': |
|
| 623 | + if (!$xoops22) { |
|
| 624 | + if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
| 625 | + require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; |
|
| 626 | + $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
| 627 | + } else { |
|
| 628 | + if ($dhtml) { |
|
| 629 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 630 | + } else { |
|
| 631 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + } else { |
|
| 635 | + $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
|
| 636 | + } |
|
| 637 | + break; |
|
| 638 | + |
|
| 639 | + case 'spaw': |
|
| 640 | + if (!$xoops22) { |
|
| 641 | + if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
| 642 | + require_once XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'; |
|
| 643 | + $editor = new XoopsFormSpaw($caption, $name, $value); |
|
| 644 | + } |
|
| 645 | + } else { |
|
| 646 | + $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
|
| 647 | + } |
|
| 648 | + break; |
|
| 649 | + |
|
| 650 | + case 'htmlarea': |
|
| 651 | + if (!$xoops22) { |
|
| 652 | + if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
| 653 | + require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
|
| 654 | + $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
| 655 | + } |
|
| 656 | + } else { |
|
| 657 | + $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
|
| 658 | + } |
|
| 659 | + break; |
|
| 660 | + |
|
| 661 | + default: |
|
| 662 | + case 'textarea': |
|
| 663 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 664 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 665 | + |
|
| 666 | + $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 667 | + if ($var['form_dsc']) { |
|
| 668 | + $editor->setDescription($var['form_dsc']); |
|
| 669 | + } |
|
| 670 | + break; |
|
| 671 | + |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + return $editor; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * @param $key |
|
| 680 | + * @param $var |
|
| 681 | + * @param bool $multiple |
|
| 682 | + * @return XoopsFormSelect |
|
| 683 | + */ |
|
| 684 | + public function getThemeSelect($key, $var, $multiple = false) |
|
| 685 | + { |
|
| 686 | + $size = $multiple ? 5 : 1; |
|
| 687 | + $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 688 | + |
|
| 689 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 690 | + $dirlist = []; |
|
| 691 | + while (false !== ($file = readdir($handle))) { |
|
| 692 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) |
|
| 693 | + && strtolower($file) !== 'cvs') { |
|
| 694 | + $dirlist[$file] = $file; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + closedir($handle); |
|
| 698 | + if (!empty($dirlist)) { |
|
| 699 | + asort($dirlist); |
|
| 700 | + $theme_select->addOptionArray($dirlist); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + return $theme_select; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * @param $keyname |
|
| 708 | + * @return bool |
|
| 709 | + */ |
|
| 710 | + public function &getElementById($keyname) |
|
| 711 | + { |
|
| 712 | + foreach ($this->_elements as $eleObj) { |
|
| 713 | + if ($eleObj->getName() == $keyname) { |
|
| 714 | + $ret =& $eleObj; |
|
| 715 | + break; |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + return isset($ret) ? $ret : false; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * create HTML to output the form as a theme-enabled table with validation. |
|
| 724 | + * |
|
| 725 | + * @return string |
|
| 726 | + */ |
|
| 727 | + public function render() |
|
| 728 | + { |
|
| 729 | + $required = $this->getRequired(); |
|
| 730 | + $ret = " |
|
| 731 | 731 | <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
| 732 | 732 | <table width='100%' class='outer' cellspacing='1'> |
| 733 | 733 | <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
| 734 | 734 | '; |
| 735 | - $hidden = ''; |
|
| 736 | - $class = 'even'; |
|
| 737 | - foreach ($this->getElements() as $ele) { |
|
| 738 | - if (!is_object($ele)) { |
|
| 739 | - $ret .= $ele; |
|
| 740 | - } elseif (!$ele->isHidden()) { |
|
| 741 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 742 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 743 | - if ($ele->getDescription() !== '') { |
|
| 744 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 745 | - } |
|
| 746 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 747 | - } else { |
|
| 748 | - $hidden .= $ele->render(); |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 752 | - $ret .= $this->renderValidationJS(true); |
|
| 753 | - |
|
| 754 | - return $ret; |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * assign to smarty form template instead of displaying directly |
|
| 759 | - * |
|
| 760 | - * @param XoopsTpl &$tpl reference to a {@link Smarty} object |
|
| 761 | - * @param bool $smartyName |
|
| 762 | - * @see Smarty |
|
| 763 | - */ |
|
| 764 | - public function assign(XoopsTpl $tpl, $smartyName = false) |
|
| 765 | - { |
|
| 766 | - $i = 0; |
|
| 767 | - $elements = []; |
|
| 768 | - foreach ($this->getElements() as $ele) { |
|
| 769 | - $n = ($ele->getName() !== '') ? $ele->getName() : $i; |
|
| 770 | - $elements[$n]['name'] = $ele->getName(); |
|
| 771 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
| 772 | - $elements[$n]['body'] = $ele->render(); |
|
| 773 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 774 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 775 | - $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
| 776 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 777 | - if ($ele->getDescription() !== '') { |
|
| 778 | - $elements[$n]['description'] = $ele->getDescription(); |
|
| 779 | - } |
|
| 780 | - ++$i; |
|
| 781 | - } |
|
| 782 | - $js = $this->renderValidationJS(); |
|
| 783 | - if (!$smartyName) { |
|
| 784 | - $smartyName = $this->getName(); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - $tpl->assign($smartyName, [ |
|
| 788 | - 'title' => $this->getTitle(), |
|
| 789 | - 'name' => $this->getName(), |
|
| 790 | - 'action' => $this->getAction(), |
|
| 791 | - 'method' => $this->getMethod(), |
|
| 792 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 793 | - 'javascript' => $js, |
|
| 794 | - 'elements' => $elements |
|
| 795 | - ]); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * @param bool $withtags |
|
| 800 | - * @return string |
|
| 801 | - */ |
|
| 802 | - public function renderValidationJS($withtags = true) |
|
| 803 | - { |
|
| 804 | - $js = ''; |
|
| 805 | - if ($withtags) { |
|
| 806 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 807 | - } |
|
| 808 | - $myts = MyTextSanitizer::getInstance(); |
|
| 809 | - $formname = $this->getName(); |
|
| 810 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 811 | - // First, output code to check required elements |
|
| 812 | - $elements = $this->getRequired(); |
|
| 813 | - foreach ($elements as $elt) { |
|
| 814 | - $eltname = $elt->getName(); |
|
| 815 | - $eltcaption = trim($elt->getCaption()); |
|
| 816 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 817 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 818 | - if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
| 819 | - $js .= 'var myOption = -1;'; |
|
| 820 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 735 | + $hidden = ''; |
|
| 736 | + $class = 'even'; |
|
| 737 | + foreach ($this->getElements() as $ele) { |
|
| 738 | + if (!is_object($ele)) { |
|
| 739 | + $ret .= $ele; |
|
| 740 | + } elseif (!$ele->isHidden()) { |
|
| 741 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 742 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 743 | + if ($ele->getDescription() !== '') { |
|
| 744 | + $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 745 | + } |
|
| 746 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 747 | + } else { |
|
| 748 | + $hidden .= $ele->render(); |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 752 | + $ret .= $this->renderValidationJS(true); |
|
| 753 | + |
|
| 754 | + return $ret; |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * assign to smarty form template instead of displaying directly |
|
| 759 | + * |
|
| 760 | + * @param XoopsTpl &$tpl reference to a {@link Smarty} object |
|
| 761 | + * @param bool $smartyName |
|
| 762 | + * @see Smarty |
|
| 763 | + */ |
|
| 764 | + public function assign(XoopsTpl $tpl, $smartyName = false) |
|
| 765 | + { |
|
| 766 | + $i = 0; |
|
| 767 | + $elements = []; |
|
| 768 | + foreach ($this->getElements() as $ele) { |
|
| 769 | + $n = ($ele->getName() !== '') ? $ele->getName() : $i; |
|
| 770 | + $elements[$n]['name'] = $ele->getName(); |
|
| 771 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
| 772 | + $elements[$n]['body'] = $ele->render(); |
|
| 773 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 774 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 775 | + $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
| 776 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 777 | + if ($ele->getDescription() !== '') { |
|
| 778 | + $elements[$n]['description'] = $ele->getDescription(); |
|
| 779 | + } |
|
| 780 | + ++$i; |
|
| 781 | + } |
|
| 782 | + $js = $this->renderValidationJS(); |
|
| 783 | + if (!$smartyName) { |
|
| 784 | + $smartyName = $this->getName(); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + $tpl->assign($smartyName, [ |
|
| 788 | + 'title' => $this->getTitle(), |
|
| 789 | + 'name' => $this->getName(), |
|
| 790 | + 'action' => $this->getAction(), |
|
| 791 | + 'method' => $this->getMethod(), |
|
| 792 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 793 | + 'javascript' => $js, |
|
| 794 | + 'elements' => $elements |
|
| 795 | + ]); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * @param bool $withtags |
|
| 800 | + * @return string |
|
| 801 | + */ |
|
| 802 | + public function renderValidationJS($withtags = true) |
|
| 803 | + { |
|
| 804 | + $js = ''; |
|
| 805 | + if ($withtags) { |
|
| 806 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 807 | + } |
|
| 808 | + $myts = MyTextSanitizer::getInstance(); |
|
| 809 | + $formname = $this->getName(); |
|
| 810 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 811 | + // First, output code to check required elements |
|
| 812 | + $elements = $this->getRequired(); |
|
| 813 | + foreach ($elements as $elt) { |
|
| 814 | + $eltname = $elt->getName(); |
|
| 815 | + $eltcaption = trim($elt->getCaption()); |
|
| 816 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 817 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 818 | + if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
| 819 | + $js .= 'var myOption = -1;'; |
|
| 820 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 821 | 821 | if (myform.{$eltname}[i].checked) { |
| 822 | 822 | myOption = i; i = -1; |
| 823 | 823 | } |
| 824 | 824 | } |
| 825 | 825 | if (myOption == -1) { |
| 826 | 826 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
| 827 | - } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
| 828 | - $js .= 'var hasSelections = false;'; |
|
| 829 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 827 | + } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
| 828 | + $js .= 'var hasSelections = false;'; |
|
| 829 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 830 | 830 | if (myform['{$eltname}[]'].options[i].selected) { |
| 831 | 831 | hasSelections = true; |
| 832 | 832 | } |
@@ -834,12 +834,12 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | if (hasSelections === false) { |
| 836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
| 837 | - } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' |
|
| 838 | - || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
| 839 | - $js .= 'var hasSelections = false;'; |
|
| 840 | - //sometimes, there is an implicit '[]', sometimes not |
|
| 841 | - if (strpos($eltname, '[') === false) { |
|
| 842 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 837 | + } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' |
|
| 838 | + || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
| 839 | + $js .= 'var hasSelections = false;'; |
|
| 840 | + //sometimes, there is an implicit '[]', sometimes not |
|
| 841 | + if (strpos($eltname, '[') === false) { |
|
| 842 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 843 | 843 | if (myform['{$eltname}[]'][i].checked) { |
| 844 | 844 | hasSelections = true; |
| 845 | 845 | } |
@@ -847,8 +847,8 @@ discard block |
||
| 847 | 847 | } |
| 848 | 848 | if (hasSelections === false) { |
| 849 | 849 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
| 850 | - } else { |
|
| 851 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 850 | + } else { |
|
| 851 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 852 | 852 | if (myform['{$eltname}'][i].checked) { |
| 853 | 853 | hasSelections = true; |
| 854 | 854 | } |
@@ -856,25 +856,25 @@ discard block |
||
| 856 | 856 | } |
| 857 | 857 | if (hasSelections === false) { |
| 858 | 858 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 859 | - } |
|
| 860 | - } else { |
|
| 861 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - // Now, handle custom validation code |
|
| 865 | - $elements =& $this->getElements(true); |
|
| 866 | - foreach ($elements as $elt) { |
|
| 867 | - if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
| 868 | - if ($eltjs = $elt->renderValidationJS()) { |
|
| 869 | - $js .= $eltjs . "\n"; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - $js .= "return true;\n}\n"; |
|
| 874 | - if ($withtags) { |
|
| 875 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - return $js; |
|
| 879 | - } |
|
| 859 | + } |
|
| 860 | + } else { |
|
| 861 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + // Now, handle custom validation code |
|
| 865 | + $elements =& $this->getElements(true); |
|
| 866 | + foreach ($elements as $elt) { |
|
| 867 | + if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
| 868 | + if ($eltjs = $elt->renderValidationJS()) { |
|
| 869 | + $js .= $eltjs . "\n"; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + $js .= "return true;\n}\n"; |
|
| 874 | + if ($withtags) { |
|
| 875 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + return $js; |
|
| 879 | + } |
|
| 880 | 880 | } |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * Including the XoopsFormLoader classes |
| 17 | 17 | */ |
| 18 | -require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 19 | -require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
| 20 | -require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsectionclose.php'; |
|
| 18 | +require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
| 19 | +require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsection.php'; |
|
| 20 | +require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsectionclose.php'; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * SmartForm base class |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | $cancel_js_action = false, |
| 61 | 61 | $captcha = false |
| 62 | 62 | ) { |
| 63 | - $this->targetObject =& $target; |
|
| 63 | + $this->targetObject = & $target; |
|
| 64 | 64 | $this->form_fields = $form_fields; |
| 65 | 65 | $this->_cancel_js_action = $cancel_js_action; |
| 66 | 66 | $this->_captcha = $captcha; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | public function addCaptcha() |
| 90 | 90 | { |
| 91 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 91 | + require_once SMARTOBJECT_ROOT_PATH.'include/captcha/formcaptcha.php'; |
|
| 92 | 92 | $this->addElement(new XoopsFormCaptcha(), true); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function addCustomButton($name, $caption, $onclick = false) |
| 101 | 101 | { |
| 102 | - $custom_button_array = [ |
|
| 102 | + $custom_button_array = [ |
|
| 103 | 103 | 'name' => $name, |
| 104 | 104 | 'caption' => $caption, |
| 105 | 105 | 'onclick' => $onclick |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | if ($key) { |
| 121 | 121 | if ($this->targetObject->vars[$key]['readonly']) { |
| 122 | 122 | $formElement->setExtra('disabled="disabled"'); |
| 123 | - $formElement->setName($key . '-readonly'); |
|
| 123 | + $formElement->setName($key.'-readonly'); |
|
| 124 | 124 | // Since this element is disable, we still want to pass it's value in the form |
| 125 | 125 | $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
| 126 | 126 | $this->addElement($hidden); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $this->addElement($hidden); |
| 132 | 132 | $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
| 133 | 133 | $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
| 134 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 134 | + $formElement->setExtra('onchange="'.$onchangedString.'"'.' '.$otherExtra); |
|
| 135 | 135 | } else { |
| 136 | 136 | if (isset($var['form_extra'])) { |
| 137 | 137 | $formElement->setExtra($var['form_extra']); |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | asort($group_list); |
| 299 | 299 | foreach ($permissions as $permission) { |
| 300 | 300 | if ($this->targetObject->isNew()) { |
| 301 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 302 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 301 | + if (isset($smartModuleConfig['def_perm_'.$permission['perm_name']])) { |
|
| 302 | + $groups_value = $smartModuleConfig['def_perm_'.$permission['perm_name']]; |
|
| 303 | 303 | } |
| 304 | 304 | } else { |
| 305 | 305 | $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | } else { |
| 332 | 332 | $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
| 333 | 333 | } |
| 334 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 334 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\''.$form_name.'\'"'); |
|
| 335 | 335 | $button_tray->addElement($butt_create); |
| 336 | 336 | |
| 337 | 337 | //creating custom buttons |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | foreach ($this->_custom_button as $custom_button) { |
| 340 | 340 | $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
| 341 | 341 | if ($custom_button['onclick']) { |
| 342 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 342 | + $butt_custom->setExtra('onclick="'.$custom_button['onclick'].'"'); |
|
| 343 | 343 | } |
| 344 | 344 | $button_tray->addElement($butt_custom); |
| 345 | 345 | unset($butt_custom); |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | // creating the "cancel" button |
| 350 | 350 | $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
| 351 | 351 | if ($this->_cancel_js_action) { |
| 352 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 352 | + $butt_cancel->setExtra('onclick="'.$this->_cancel_js_action.'"'); |
|
| 353 | 353 | } else { |
| 354 | 354 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
| 355 | 355 | } |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | { |
| 368 | 368 | switch ($controlName) { |
| 369 | 369 | case 'check': |
| 370 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
| 370 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformcheckelement.php'; |
|
| 371 | 371 | $control = $this->targetObject->getControl($key); |
| 372 | 372 | $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
| 373 | 373 | $controlObj->addOptionArray($control['options']); |
@@ -434,38 +434,38 @@ discard block |
||
| 434 | 434 | break; |
| 435 | 435 | |
| 436 | 436 | case 'urllink': |
| 437 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
|
| 437 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformurllinkelement.php'; |
|
| 438 | 438 | |
| 439 | 439 | return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
| 440 | 440 | break; |
| 441 | 441 | |
| 442 | 442 | case 'richfile': |
| 443 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
|
| 443 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformrichfileelement.php'; |
|
| 444 | 444 | |
| 445 | 445 | return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
| 446 | 446 | break; |
| 447 | 447 | case 'section': |
| 448 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
| 448 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsection.php'; |
|
| 449 | 449 | |
| 450 | 450 | return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
| 451 | 451 | break; |
| 452 | 452 | |
| 453 | 453 | default: |
| 454 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 454 | + $classname = 'SmartForm'.ucfirst($controlName).'Element'; |
|
| 455 | 455 | if (!class_exists($classname)) { |
| 456 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 457 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
|
| 456 | + if (file_exists(SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php')) { |
|
| 457 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php'; |
|
| 458 | 458 | } else { |
| 459 | 459 | // perhaps this is a control created by the module |
| 460 | 460 | $moduleName = $this->targetObject->handler->_moduleName; |
| 461 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 462 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 463 | - $classFileName = strtolower($classname) . '.php'; |
|
| 461 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath.'class/form/elements/'; |
|
| 462 | + $classname = ucfirst($moduleName).ucfirst($controlName).'Element'; |
|
| 463 | + $classFileName = strtolower($classname).'.php'; |
|
| 464 | 464 | |
| 465 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 466 | - require_once $moduleFormElementsPath . $classFileName; |
|
| 465 | + if (file_exists($moduleFormElementsPath.$classFileName)) { |
|
| 466 | + require_once $moduleFormElementsPath.$classFileName; |
|
| 467 | 467 | } else { |
| 468 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 468 | + trigger_error($classname.' Not found', E_USER_WARNING); |
|
| 469 | 469 | |
| 470 | 470 | return new XoopsFormLabel(); //Empty object |
| 471 | 471 | } |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | $editor_configs['height'] = '400px'; |
| 535 | 535 | |
| 536 | 536 | $dhtml = true; |
| 537 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 537 | + $xoopseditorclass = XOOPS_ROOT_PATH.'/class/xoopsform/formeditor.php'; |
|
| 538 | 538 | |
| 539 | 539 | if (file_exists($xoopseditorclass)) { |
| 540 | 540 | require_once $xoopseditorclass; |
@@ -544,8 +544,8 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | case 'tiny': |
| 546 | 546 | if (!$xoops22) { |
| 547 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 548 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 547 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 548 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 549 | 549 | $editor = new XoopsFormTinyTextArea([ |
| 550 | 550 | 'caption' => $caption, |
| 551 | 551 | 'name' => $name, |
@@ -575,8 +575,8 @@ discard block |
||
| 575 | 575 | |
| 576 | 576 | case 'fckeditor': |
| 577 | 577 | if (!$xoops22) { |
| 578 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
| 579 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'; |
|
| 578 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
| 579 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/fckeditor/formfckeditor.php'; |
|
| 580 | 580 | $editor = new XoopsFormFckeditor([ |
| 581 | 581 | 'caption' => $caption, |
| 582 | 582 | 'name' => $name, |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | |
| 599 | 599 | case 'inbetween': |
| 600 | 600 | if (!$xoops22) { |
| 601 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
| 602 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'; |
|
| 601 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
| 602 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/inbetween/forminbetweentextarea.php'; |
|
| 603 | 603 | $editor = new XoopsFormInbetweenTextArea([ |
| 604 | 604 | 'caption' => $caption, |
| 605 | 605 | 'name' => $name, |
@@ -621,8 +621,8 @@ discard block |
||
| 621 | 621 | |
| 622 | 622 | case 'koivi': |
| 623 | 623 | if (!$xoops22) { |
| 624 | - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
| 625 | - require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; |
|
| 624 | + if (is_readable(XOOPS_ROOT_PATH.'/class/wysiwyg/formwysiwygtextarea.php')) { |
|
| 625 | + require_once XOOPS_ROOT_PATH.'/class/wysiwyg/formwysiwygtextarea.php'; |
|
| 626 | 626 | $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
| 627 | 627 | } else { |
| 628 | 628 | if ($dhtml) { |
@@ -638,8 +638,8 @@ discard block |
||
| 638 | 638 | |
| 639 | 639 | case 'spaw': |
| 640 | 640 | if (!$xoops22) { |
| 641 | - if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
| 642 | - require_once XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'; |
|
| 641 | + if (is_readable(XOOPS_ROOT_PATH.'/class/spaw/formspaw.php')) { |
|
| 642 | + require_once XOOPS_ROOT_PATH.'/class/spaw/formspaw.php'; |
|
| 643 | 643 | $editor = new XoopsFormSpaw($caption, $name, $value); |
| 644 | 644 | } |
| 645 | 645 | } else { |
@@ -649,8 +649,8 @@ discard block |
||
| 649 | 649 | |
| 650 | 650 | case 'htmlarea': |
| 651 | 651 | if (!$xoops22) { |
| 652 | - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
| 653 | - require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
|
| 652 | + if (is_readable(XOOPS_ROOT_PATH.'/class/htmlarea/formhtmlarea.php')) { |
|
| 653 | + require_once XOOPS_ROOT_PATH.'/class/htmlarea/formhtmlarea.php'; |
|
| 654 | 654 | $editor = new XoopsFormHtmlarea($caption, $name, $value); |
| 655 | 655 | } |
| 656 | 656 | } else { |
@@ -686,10 +686,10 @@ discard block |
||
| 686 | 686 | $size = $multiple ? 5 : 1; |
| 687 | 687 | $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
| 688 | 688 | |
| 689 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 689 | + $handle = opendir(XOOPS_THEME_PATH.'/'); |
|
| 690 | 690 | $dirlist = []; |
| 691 | 691 | while (false !== ($file = readdir($handle))) { |
| 692 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) |
|
| 692 | + if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match("/^[.]{1,2}$/", $file) |
|
| 693 | 693 | && strtolower($file) !== 'cvs') { |
| 694 | 694 | $dirlist[$file] = $file; |
| 695 | 695 | } |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | { |
| 712 | 712 | foreach ($this->_elements as $eleObj) { |
| 713 | 713 | if ($eleObj->getName() == $keyname) { |
| 714 | - $ret =& $eleObj; |
|
| 714 | + $ret = & $eleObj; |
|
| 715 | 715 | break; |
| 716 | 716 | } |
| 717 | 717 | } |
@@ -728,9 +728,9 @@ discard block |
||
| 728 | 728 | { |
| 729 | 729 | $required = $this->getRequired(); |
| 730 | 730 | $ret = " |
| 731 | - <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
|
| 731 | + <form name='" . $this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra()."> |
|
| 732 | 732 | <table width='100%' class='outer' cellspacing='1'> |
| 733 | - <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
|
| 733 | + <tr><th colspan='2'>" . $this->getTitle().'</th></tr> |
|
| 734 | 734 | '; |
| 735 | 735 | $hidden = ''; |
| 736 | 736 | $class = 'even'; |
@@ -739,11 +739,11 @@ discard block |
||
| 739 | 739 | $ret .= $ele; |
| 740 | 740 | } elseif (!$ele->isHidden()) { |
| 741 | 741 | //$class = ( $class == 'even' ) ? 'odd': 'even'; |
| 742 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 742 | + $ret .= "<tr id='".$ele->getName()."' valign='top' align='left'><td class='head'>".$ele->getCaption(); |
|
| 743 | 743 | if ($ele->getDescription() !== '') { |
| 744 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 744 | + $ret .= '<br><br><span style="font-weight: normal;">'.$ele->getDescription().'</span>'; |
|
| 745 | 745 | } |
| 746 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 746 | + $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n"; |
|
| 747 | 747 | } else { |
| 748 | 748 | $hidden .= $ele->render(); |
| 749 | 749 | } |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | 'name' => $this->getName(), |
| 790 | 790 | 'action' => $this->getAction(), |
| 791 | 791 | 'method' => $this->getMethod(), |
| 792 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 792 | + 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), |
|
| 793 | 793 | 'javascript' => $js, |
| 794 | 794 | 'elements' => $elements |
| 795 | 795 | ]); |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | } |
| 808 | 808 | $myts = MyTextSanitizer::getInstance(); |
| 809 | 809 | $formname = $this->getName(); |
| 810 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 810 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 811 | 811 | // First, output code to check required elements |
| 812 | 812 | $elements = $this->getRequired(); |
| 813 | 813 | foreach ($elements as $elt) { |
@@ -858,15 +858,15 @@ discard block |
||
| 858 | 858 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 859 | 859 | } |
| 860 | 860 | } else { |
| 861 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 861 | + $js .= "if ( myform.{$eltname}.value == \"\" ) "."{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 862 | 862 | } |
| 863 | 863 | } |
| 864 | 864 | // Now, handle custom validation code |
| 865 | - $elements =& $this->getElements(true); |
|
| 865 | + $elements = & $this->getElements(true); |
|
| 866 | 866 | foreach ($elements as $elt) { |
| 867 | 867 | if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
| 868 | 868 | if ($eltjs = $elt->renderValidationJS()) { |
| 869 | - $js .= $eltjs . "\n"; |
|
| 869 | + $js .= $eltjs."\n"; |
|
| 870 | 870 | } |
| 871 | 871 | } |
| 872 | 872 | } |
@@ -237,7 +237,7 @@ |
||
| 237 | 237 | * Creates a random number with a specified number of $digits |
| 238 | 238 | * |
| 239 | 239 | * @param int $digits number of digits |
| 240 | - * @return return int random number |
|
| 240 | + * @return string int random number |
|
| 241 | 241 | * @author xHelp Team |
| 242 | 242 | * |
| 243 | 243 | * @access public |
@@ -34,227 +34,227 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class SmartobjectMemberHandler extends XoopsMemberHandler |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * constructor |
|
| 39 | - * @param XoopsDatabase $db |
|
| 40 | - */ |
|
| 41 | - public function __construct(XoopsDatabase $db) |
|
| 42 | - { |
|
| 43 | - parent::__construct($db); |
|
| 44 | - $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * constructor |
|
| 39 | + * @param XoopsDatabase $db |
|
| 40 | + */ |
|
| 41 | + public function __construct(XoopsDatabase $db) |
|
| 42 | + { |
|
| 43 | + parent::__construct($db); |
|
| 44 | + $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param $userObj |
|
| 49 | - * @param bool $groups |
|
| 50 | - * @param bool $notifyUser |
|
| 51 | - * @param bool $password |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
| 55 | - { |
|
| 56 | - $email = $userObj->getVar('email'); |
|
| 57 | - if (!$userObj->getVar('email') || $email === '') { |
|
| 58 | - $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
| 47 | + /** |
|
| 48 | + * @param $userObj |
|
| 49 | + * @param bool $groups |
|
| 50 | + * @param bool $notifyUser |
|
| 51 | + * @param bool $password |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
| 55 | + { |
|
| 56 | + $email = $userObj->getVar('email'); |
|
| 57 | + if (!$userObj->getVar('email') || $email === '') { |
|
| 58 | + $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
| 59 | 59 | |
| 60 | - return false; |
|
| 61 | - } |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $password = $userObj->getVar('pass'); |
|
| 64 | - // randomly generating the password if not already set |
|
| 65 | - if ('' === $password) { |
|
| 66 | - $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
| 67 | - } |
|
| 68 | - $userObj->setVar('pass', md5($password)); |
|
| 63 | + $password = $userObj->getVar('pass'); |
|
| 64 | + // randomly generating the password if not already set |
|
| 65 | + if ('' === $password) { |
|
| 66 | + $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
| 67 | + } |
|
| 68 | + $userObj->setVar('pass', md5($password)); |
|
| 69 | 69 | |
| 70 | - // if no username is set, let's generate one |
|
| 71 | - $unamecount = 20; |
|
| 72 | - $uname = $userObj->getVar('uname'); |
|
| 73 | - if (!$uname || $uname === '') { |
|
| 74 | - $usernames = $this->genUserNames($email, $unamecount); |
|
| 75 | - $newuser = false; |
|
| 76 | - $i = 0; |
|
| 77 | - while ($newuser === false) { |
|
| 78 | - $crit = new Criteria('uname', $usernames[$i]); |
|
| 79 | - $count = $this->getUserCount($crit); |
|
| 80 | - if ($count == 0) { |
|
| 81 | - $newuser = true; |
|
| 82 | - } else { |
|
| 83 | - //Move to next username |
|
| 84 | - ++$i; |
|
| 85 | - if ($i == $unamecount) { |
|
| 86 | - //Get next batch of usernames to try, reset counter |
|
| 87 | - $usernames = $this->genUserNames($email, $unamecount); |
|
| 88 | - $i = 0; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 70 | + // if no username is set, let's generate one |
|
| 71 | + $unamecount = 20; |
|
| 72 | + $uname = $userObj->getVar('uname'); |
|
| 73 | + if (!$uname || $uname === '') { |
|
| 74 | + $usernames = $this->genUserNames($email, $unamecount); |
|
| 75 | + $newuser = false; |
|
| 76 | + $i = 0; |
|
| 77 | + while ($newuser === false) { |
|
| 78 | + $crit = new Criteria('uname', $usernames[$i]); |
|
| 79 | + $count = $this->getUserCount($crit); |
|
| 80 | + if ($count == 0) { |
|
| 81 | + $newuser = true; |
|
| 82 | + } else { |
|
| 83 | + //Move to next username |
|
| 84 | + ++$i; |
|
| 85 | + if ($i == $unamecount) { |
|
| 86 | + //Get next batch of usernames to try, reset counter |
|
| 87 | + $usernames = $this->genUserNames($email, $unamecount); |
|
| 88 | + $i = 0; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - global $xoopsConfig; |
|
| 94 | + global $xoopsConfig; |
|
| 95 | 95 | |
| 96 | - $configHandler = xoops_getHandler('config'); |
|
| 97 | - $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
| 98 | - switch ($xoopsConfigUser['activation_type']) { |
|
| 99 | - case 0: |
|
| 100 | - $level = 0; |
|
| 101 | - $mailtemplate = 'smartmail_activate_user.tpl'; |
|
| 102 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
| 103 | - break; |
|
| 104 | - case 1: |
|
| 105 | - $level = 1; |
|
| 106 | - $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
| 107 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
| 108 | - break; |
|
| 109 | - case 2: |
|
| 110 | - default: |
|
| 111 | - $level = 0; |
|
| 112 | - $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
| 113 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
| 114 | - } |
|
| 96 | + $configHandler = xoops_getHandler('config'); |
|
| 97 | + $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
| 98 | + switch ($xoopsConfigUser['activation_type']) { |
|
| 99 | + case 0: |
|
| 100 | + $level = 0; |
|
| 101 | + $mailtemplate = 'smartmail_activate_user.tpl'; |
|
| 102 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
| 103 | + break; |
|
| 104 | + case 1: |
|
| 105 | + $level = 1; |
|
| 106 | + $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
| 107 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
| 108 | + break; |
|
| 109 | + case 2: |
|
| 110 | + default: |
|
| 111 | + $level = 0; |
|
| 112 | + $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
| 113 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - $userObj->setVar('uname', $usernames[$i]); |
|
| 117 | - $userObj->setVar('user_avatar', 'blank.gif'); |
|
| 118 | - $userObj->setVar('user_regdate', time()); |
|
| 119 | - $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
| 120 | - $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
| 121 | - $userObj->setVar('actkey', $actkey); |
|
| 122 | - $userObj->setVar('email', $email); |
|
| 123 | - $userObj->setVar('notify_method', 2); |
|
| 124 | - $userObj->setVar('level', $userObj); |
|
| 116 | + $userObj->setVar('uname', $usernames[$i]); |
|
| 117 | + $userObj->setVar('user_avatar', 'blank.gif'); |
|
| 118 | + $userObj->setVar('user_regdate', time()); |
|
| 119 | + $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
| 120 | + $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
| 121 | + $userObj->setVar('actkey', $actkey); |
|
| 122 | + $userObj->setVar('email', $email); |
|
| 123 | + $userObj->setVar('notify_method', 2); |
|
| 124 | + $userObj->setVar('level', $userObj); |
|
| 125 | 125 | |
| 126 | - if ($this->insertUser($userObj)) { |
|
| 126 | + if ($this->insertUser($userObj)) { |
|
| 127 | 127 | |
| 128 | - // if $groups=false, Add the user to Registered Users group |
|
| 129 | - if (!$groups) { |
|
| 130 | - $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
| 131 | - } else { |
|
| 132 | - foreach ($groups as $groupid) { |
|
| 133 | - $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } else { |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 128 | + // if $groups=false, Add the user to Registered Users group |
|
| 129 | + if (!$groups) { |
|
| 130 | + $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
| 131 | + } else { |
|
| 132 | + foreach ($groups as $groupid) { |
|
| 133 | + $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } else { |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - if ($notifyUser) { |
|
| 141 | - // send some notifications |
|
| 142 | - $xoopsMailer = xoops_getMailer(); |
|
| 143 | - $xoopsMailer->useMail(); |
|
| 144 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 145 | - $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
| 146 | - $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
| 147 | - $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
| 148 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
| 149 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 150 | - $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
| 151 | - $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
| 152 | - $xoopsMailer->setToUsers($userObj); |
|
| 153 | - $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
| 154 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
| 155 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
| 140 | + if ($notifyUser) { |
|
| 141 | + // send some notifications |
|
| 142 | + $xoopsMailer = xoops_getMailer(); |
|
| 143 | + $xoopsMailer->useMail(); |
|
| 144 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 145 | + $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
| 146 | + $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
| 147 | + $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
| 148 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
| 149 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 150 | + $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
| 151 | + $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
| 152 | + $xoopsMailer->setToUsers($userObj); |
|
| 153 | + $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
| 154 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
| 155 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
| 156 | 156 | |
| 157 | - if (!$xoopsMailer->send(true)) { |
|
| 158 | - /** |
|
| 159 | - * @todo trap error if email was not sent |
|
| 160 | - */ |
|
| 161 | - $xoopsMailer->getErrors(true); |
|
| 162 | - } |
|
| 163 | - } |
|
| 157 | + if (!$xoopsMailer->send(true)) { |
|
| 158 | + /** |
|
| 159 | + * @todo trap error if email was not sent |
|
| 160 | + */ |
|
| 161 | + $xoopsMailer->getErrors(true); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - return true; |
|
| 166 | - } |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Generates an array of usernames |
|
| 170 | - * |
|
| 171 | - * @param string $email email of user |
|
| 172 | - * @param int $count number of names to generate |
|
| 173 | - * @return array $names |
|
| 174 | - * @internal param string $name name of user |
|
| 175 | - * @author xHelp Team |
|
| 176 | - * |
|
| 177 | - * @access public |
|
| 178 | - */ |
|
| 179 | - public function genUserNames($email, $count = 20) |
|
| 180 | - { |
|
| 181 | - $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
| 168 | + /** |
|
| 169 | + * Generates an array of usernames |
|
| 170 | + * |
|
| 171 | + * @param string $email email of user |
|
| 172 | + * @param int $count number of names to generate |
|
| 173 | + * @return array $names |
|
| 174 | + * @internal param string $name name of user |
|
| 175 | + * @author xHelp Team |
|
| 176 | + * |
|
| 177 | + * @access public |
|
| 178 | + */ |
|
| 179 | + public function genUserNames($email, $count = 20) |
|
| 180 | + { |
|
| 181 | + $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
| 182 | 182 | |
| 183 | - $names = []; |
|
| 184 | - $userid = explode('@', $email); |
|
| 183 | + $names = []; |
|
| 184 | + $userid = explode('@', $email); |
|
| 185 | 185 | |
| 186 | - $basename = ''; |
|
| 187 | - $hasbasename = false; |
|
| 188 | - $emailname = $userid[0]; |
|
| 186 | + $basename = ''; |
|
| 187 | + $hasbasename = false; |
|
| 188 | + $emailname = $userid[0]; |
|
| 189 | 189 | |
| 190 | - $names[] = $emailname; |
|
| 190 | + $names[] = $emailname; |
|
| 191 | 191 | |
| 192 | - if (strlen($name) > 0) { |
|
| 193 | - $name = explode(' ', trim($name)); |
|
| 194 | - if (count($name) > 1) { |
|
| 195 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 196 | - } else { |
|
| 197 | - $basename = strtolower($name[0]); |
|
| 198 | - } |
|
| 199 | - $basename = xoops_substr($basename, 0, 60, ''); |
|
| 200 | - //Prevent Duplication of Email Username and Name |
|
| 201 | - if (!in_array($basename, $names)) { |
|
| 202 | - $names[] = $basename; |
|
| 203 | - $hasbasename = true; |
|
| 204 | - } |
|
| 205 | - } |
|
| 192 | + if (strlen($name) > 0) { |
|
| 193 | + $name = explode(' ', trim($name)); |
|
| 194 | + if (count($name) > 1) { |
|
| 195 | + $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 196 | + } else { |
|
| 197 | + $basename = strtolower($name[0]); |
|
| 198 | + } |
|
| 199 | + $basename = xoops_substr($basename, 0, 60, ''); |
|
| 200 | + //Prevent Duplication of Email Username and Name |
|
| 201 | + if (!in_array($basename, $names)) { |
|
| 202 | + $names[] = $basename; |
|
| 203 | + $hasbasename = true; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $i = count($names); |
|
| 208 | - $onbasename = 1; |
|
| 209 | - while ($i < $count) { |
|
| 210 | - $num = $this->genRandNumber(); |
|
| 211 | - if ($onbasename < 0 && $hasbasename) { |
|
| 212 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 213 | - } else { |
|
| 214 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 215 | - } |
|
| 216 | - $i = count($names); |
|
| 217 | - $onbasename = ~$onbasename; |
|
| 218 | - $num = ''; |
|
| 219 | - } |
|
| 207 | + $i = count($names); |
|
| 208 | + $onbasename = 1; |
|
| 209 | + while ($i < $count) { |
|
| 210 | + $num = $this->genRandNumber(); |
|
| 211 | + if ($onbasename < 0 && $hasbasename) { |
|
| 212 | + $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 213 | + } else { |
|
| 214 | + $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 215 | + } |
|
| 216 | + $i = count($names); |
|
| 217 | + $onbasename = ~$onbasename; |
|
| 218 | + $num = ''; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - return $names; |
|
| 222 | - } |
|
| 221 | + return $names; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Creates a random number with a specified number of $digits |
|
| 226 | - * |
|
| 227 | - * @param int $digits number of digits |
|
| 228 | - * @return return int random number |
|
| 229 | - * @author xHelp Team |
|
| 230 | - * |
|
| 231 | - * @access public |
|
| 232 | - */ |
|
| 233 | - public function genRandNumber($digits = 2) |
|
| 234 | - { |
|
| 235 | - $this->initRand(); |
|
| 236 | - $tmp = []; |
|
| 224 | + /** |
|
| 225 | + * Creates a random number with a specified number of $digits |
|
| 226 | + * |
|
| 227 | + * @param int $digits number of digits |
|
| 228 | + * @return return int random number |
|
| 229 | + * @author xHelp Team |
|
| 230 | + * |
|
| 231 | + * @access public |
|
| 232 | + */ |
|
| 233 | + public function genRandNumber($digits = 2) |
|
| 234 | + { |
|
| 235 | + $this->initRand(); |
|
| 236 | + $tmp = []; |
|
| 237 | 237 | |
| 238 | - for ($i = 0; $i < $digits; ++$i) { |
|
| 239 | - $tmp[$i] = (mt_rand() % 9); |
|
| 240 | - } |
|
| 238 | + for ($i = 0; $i < $digits; ++$i) { |
|
| 239 | + $tmp[$i] = (mt_rand() % 9); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return implode('', $tmp); |
|
| 243 | - } |
|
| 242 | + return implode('', $tmp); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Gives the random number generator a seed to start from |
|
| 247 | - * |
|
| 248 | - * @return void |
|
| 249 | - * |
|
| 250 | - * @access public |
|
| 251 | - */ |
|
| 252 | - public function initRand() |
|
| 253 | - { |
|
| 254 | - static $randCalled = false; |
|
| 255 | - if (!$randCalled) { |
|
| 256 | - mt_srand((double)microtime() * 1000000); |
|
| 257 | - $randCalled = true; |
|
| 258 | - } |
|
| 259 | - } |
|
| 245 | + /** |
|
| 246 | + * Gives the random number generator a seed to start from |
|
| 247 | + * |
|
| 248 | + * @return void |
|
| 249 | + * |
|
| 250 | + * @access public |
|
| 251 | + */ |
|
| 252 | + public function initRand() |
|
| 253 | + { |
|
| 254 | + static $randCalled = false; |
|
| 255 | + if (!$randCalled) { |
|
| 256 | + mt_srand((double)microtime() * 1000000); |
|
| 257 | + $randCalled = true; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | } |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
| 21 | -require_once XOOPS_ROOT_PATH . '/kernel/user.php'; |
|
| 22 | -require_once XOOPS_ROOT_PATH . '/kernel/group.php'; |
|
| 23 | -require_once XOOPS_ROOT_PATH . '/kernel/member.php'; |
|
| 21 | +require_once XOOPS_ROOT_PATH.'/kernel/user.php'; |
|
| 22 | +require_once XOOPS_ROOT_PATH.'/kernel/group.php'; |
|
| 23 | +require_once XOOPS_ROOT_PATH.'/kernel/member.php'; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * XOOPS member handler class. |
@@ -141,12 +141,12 @@ discard block |
||
| 141 | 141 | // send some notifications |
| 142 | 142 | $xoopsMailer = xoops_getMailer(); |
| 143 | 143 | $xoopsMailer->useMail(); |
| 144 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 144 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/mail_template'); |
|
| 145 | 145 | $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
| 146 | 146 | $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
| 147 | 147 | $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
| 148 | 148 | $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
| 149 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 149 | + $xoopsMailer->assign('SITEURL', XOOPS_URL.'/'); |
|
| 150 | 150 | $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
| 151 | 151 | $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
| 152 | 152 | $xoopsMailer->setToUsers($userObj); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | if (strlen($name) > 0) { |
| 193 | 193 | $name = explode(' ', trim($name)); |
| 194 | 194 | if (count($name) > 1) { |
| 195 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 195 | + $basename = strtolower(substr($name[0], 0, 1).$name[count($name) - 1]); |
|
| 196 | 196 | } else { |
| 197 | 197 | $basename = strtolower($name[0]); |
| 198 | 198 | } |
@@ -209,9 +209,9 @@ discard block |
||
| 209 | 209 | while ($i < $count) { |
| 210 | 210 | $num = $this->genRandNumber(); |
| 211 | 211 | if ($onbasename < 0 && $hasbasename) { |
| 212 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 212 | + $names[] = xoops_substr($basename, 0, 58, '').$num; |
|
| 213 | 213 | } else { |
| 214 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 214 | + $names[] = xoops_substr($emailname, 0, 58, '').$num; |
|
| 215 | 215 | } |
| 216 | 216 | $i = count($names); |
| 217 | 217 | $onbasename = ~$onbasename; |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | static $randCalled = false; |
| 255 | 255 | if (!$randCalled) { |
| 256 | - mt_srand((double)microtime() * 1000000); |
|
| 256 | + mt_srand((double) microtime() * 1000000); |
|
| 257 | 257 | $randCalled = true; |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | - * @param $field |
|
| 144 | + * @param string $field |
|
| 145 | 145 | * @return bool |
| 146 | 146 | */ |
| 147 | 147 | public function fieldExists($field) |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | /** |
| 624 | 624 | * Use to update a table |
| 625 | 625 | * |
| 626 | - * @param object $table {@link SmartDbTable} that will be updated |
|
| 626 | + * @param SmartDbTable $table {@link SmartDbTable} that will be updated |
|
| 627 | 627 | * |
| 628 | 628 | * @see SmartDbTable |
| 629 | 629 | * |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | /** |
| 726 | 726 | * @param $module |
| 727 | 727 | * @param $item |
| 728 | - * @return bool |
|
| 728 | + * @return false|null |
|
| 729 | 729 | */ |
| 730 | 730 | public function upgradeObjectItem($module, $item) |
| 731 | 731 | { |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
| 20 | 20 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
| 21 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 21 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 22 | 22 | } |
| 23 | 23 | /** |
| 24 | 24 | * Include the language constants for the SmartObjectDBUpdater |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | global $xoopsConfig; |
| 27 | 27 | $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
| 28 | 28 | if (!file_exists($common_file)) { |
| 29 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 29 | + $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 30 | 30 | } |
| 31 | 31 | include $common_file; |
| 32 | 32 | |
@@ -35,503 +35,503 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class SmartDbTable |
| 37 | 37 | { |
| 38 | - /** |
|
| 39 | - * @var string $_name name of the table |
|
| 40 | - */ |
|
| 41 | - public $_name; |
|
| 42 | - /** |
|
| 43 | - * @var string $_structure structure of the table |
|
| 44 | - */ |
|
| 45 | - public $_structure; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var array $_data containing valued of each records to be added |
|
| 49 | - */ |
|
| 50 | - public $_data; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var array $_alteredFields containing fields to be altered |
|
| 54 | - */ |
|
| 55 | - public $_alteredFields; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var array $_newFields containing new fields to be added |
|
| 59 | - */ |
|
| 60 | - public $_newFields; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var array $_droppedFields containing fields to be dropped |
|
| 64 | - */ |
|
| 65 | - public $_droppedFields; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var array $_flagForDrop flag table to drop it |
|
| 69 | - */ |
|
| 70 | - public $_flagForDrop = false; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var array $_updatedFields containing fields which values will be updated |
|
| 74 | - */ |
|
| 75 | - public $_updatedFields; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var array $_updatedFields containing fields which values will be updated |
|
| 79 | - */ //felix |
|
| 80 | - public $_updatedWhere; |
|
| 81 | - |
|
| 82 | - public $_existingFieldsArray = false; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Constructor |
|
| 86 | - * |
|
| 87 | - * @param string $name name of the table |
|
| 88 | - * |
|
| 89 | - */ |
|
| 90 | - public function __construct($name) |
|
| 91 | - { |
|
| 92 | - $this->_name = $name; |
|
| 93 | - $this->_data = []; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Return the table name, prefixed with site table prefix |
|
| 98 | - * |
|
| 99 | - * @return string table name |
|
| 100 | - * |
|
| 101 | - */ |
|
| 102 | - public function name() |
|
| 103 | - { |
|
| 104 | - global $xoopsDB; |
|
| 105 | - |
|
| 106 | - return $xoopsDB->prefix($this->_name); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Checks if the table already exists in the database |
|
| 111 | - * |
|
| 112 | - * @return bool TRUE if it exists, FALSE if not |
|
| 113 | - * |
|
| 114 | - */ |
|
| 115 | - public function exists() |
|
| 116 | - { |
|
| 117 | - return smart_TableExists($this->_name); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return mixed |
|
| 122 | - */ |
|
| 123 | - public function getExistingFieldsArray() |
|
| 124 | - { |
|
| 125 | - global $xoopsDB; |
|
| 126 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 127 | - while ($existing_field = $xoopsDB->fetchArray($result)) { |
|
| 128 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 129 | - if ($existing_field['Null'] !== 'YES') { |
|
| 130 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 131 | - } |
|
| 132 | - if ($existing_field['Extra']) { |
|
| 133 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 134 | - } |
|
| 135 | - if (!($existing_field['Default'] === null) |
|
| 136 | - && ($existing_field['Default'] |
|
| 137 | - || $existing_field['Default'] === '' |
|
| 138 | - || $existing_field['Default'] == 0)) { |
|
| 139 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $fields; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param $field |
|
| 148 | - * @return bool |
|
| 149 | - */ |
|
| 150 | - public function fieldExists($field) |
|
| 151 | - { |
|
| 152 | - $existingFields = $this->getExistingFieldsArray(); |
|
| 153 | - |
|
| 154 | - return isset($existingFields[$field]); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Set the table structure |
|
| 159 | - * |
|
| 160 | - * Example: |
|
| 161 | - * |
|
| 162 | - * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
| 163 | - * `date` int(11) NOT NULL default '0', |
|
| 164 | - * `status` int(1) NOT NULL default '-1', |
|
| 165 | - * `itemid` int(11) NOT NULL default '0', |
|
| 166 | - * `uid` int(11) NOT NULL default '0', |
|
| 167 | - * `price` float NOT NULL default '0', |
|
| 168 | - * `currency` varchar(100) NOT NULL default '', |
|
| 169 | - * PRIMARY KEY (`transactionid`)"); |
|
| 170 | - * |
|
| 171 | - * @param string $structure table structure |
|
| 172 | - * |
|
| 173 | - */ |
|
| 174 | - public function setStructure($structure) |
|
| 175 | - { |
|
| 176 | - $this->_structure = $structure; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Return the table structure |
|
| 181 | - * |
|
| 182 | - * @return string table structure |
|
| 183 | - * |
|
| 184 | - */ |
|
| 185 | - public function getStructure() |
|
| 186 | - { |
|
| 187 | - return sprintf($this->_structure, $this->name()); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Add values of a record to be added |
|
| 192 | - * |
|
| 193 | - * @param string $data values of a record |
|
| 194 | - * |
|
| 195 | - */ |
|
| 196 | - public function setData($data) |
|
| 197 | - { |
|
| 198 | - $this->_data[] = $data; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Get the data array |
|
| 203 | - * |
|
| 204 | - * @return array containing the records values to be added |
|
| 205 | - * |
|
| 206 | - */ |
|
| 207 | - public function getData() |
|
| 208 | - { |
|
| 209 | - return $this->_data; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Use to insert data in a table |
|
| 214 | - * |
|
| 215 | - * @return bool true if success, false if an error occured |
|
| 216 | - * |
|
| 217 | - */ |
|
| 218 | - public function addData() |
|
| 219 | - { |
|
| 220 | - global $xoopsDB; |
|
| 221 | - foreach ($this->getData() as $data) { |
|
| 222 | - $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
| 223 | - $ret = $xoopsDB->query($query); |
|
| 224 | - if (!$ret) { |
|
| 225 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 226 | - } else { |
|
| 227 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - return $ret; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Add a field to be added |
|
| 236 | - * |
|
| 237 | - * @param string $name name of the field |
|
| 238 | - * @param string $properties properties of the field |
|
| 239 | - * @param bool $newname |
|
| 240 | - * @param bool $showerror |
|
| 241 | - */ |
|
| 242 | - public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
| 243 | - { |
|
| 244 | - $field['name'] = $name; |
|
| 245 | - $field['properties'] = $properties; |
|
| 246 | - $field['showerror'] = $showerror; |
|
| 247 | - $field['newname'] = $newname; |
|
| 248 | - $this->_alteredFields[] = $field; |
|
| 249 | - } |
|
| 250 | - /** |
|
| 251 | - * Invert values 0 to 1 and 1 to 0 |
|
| 252 | - * |
|
| 253 | - * @param string $name name of the field |
|
| 254 | - * @param $newValue |
|
| 255 | - * @param $oldValue |
|
| 256 | - * @internal param string $old old propertie |
|
| 257 | - * @internal param string $new new propertie |
|
| 258 | - */ //felix |
|
| 259 | - public function addUpdatedWhere($name, $newValue, $oldValue) |
|
| 260 | - { |
|
| 261 | - $field['name'] = $name; |
|
| 262 | - $field['value'] = $newValue; |
|
| 263 | - $field['where'] = $oldValue; |
|
| 264 | - $this->_updatedWhere[] = $field; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Add new field of a record to be added |
|
| 269 | - * |
|
| 270 | - * @param string $name name of the field |
|
| 271 | - * @param string $properties properties of the field |
|
| 272 | - * |
|
| 273 | - */ |
|
| 274 | - public function addNewField($name, $properties) |
|
| 275 | - { |
|
| 276 | - $field['name'] = $name; |
|
| 277 | - $field['properties'] = $properties; |
|
| 278 | - $this->_newFields[] = $field; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Get fields that need to be altered |
|
| 283 | - * |
|
| 284 | - * @return array fields that need to be altered |
|
| 285 | - * |
|
| 286 | - */ |
|
| 287 | - public function getAlteredFields() |
|
| 288 | - { |
|
| 289 | - return $this->_alteredFields; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Add field for which the value will be updated |
|
| 294 | - * |
|
| 295 | - * @param string $name name of the field |
|
| 296 | - * @param string $value value to be set |
|
| 297 | - * |
|
| 298 | - */ |
|
| 299 | - public function addUpdatedField($name, $value) |
|
| 300 | - { |
|
| 301 | - $field['name'] = $name; |
|
| 302 | - $field['value'] = $value; |
|
| 303 | - $this->_updatedFields[] = $field; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Get new fields to be added |
|
| 308 | - * |
|
| 309 | - * @return array fields to be added |
|
| 310 | - * |
|
| 311 | - */ |
|
| 312 | - public function getNewFields() |
|
| 313 | - { |
|
| 314 | - return $this->_newFields; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Get fields which values need to be updated |
|
| 319 | - * |
|
| 320 | - * @return array fields which values need to be updated |
|
| 321 | - * |
|
| 322 | - */ |
|
| 323 | - public function getUpdatedFields() |
|
| 324 | - { |
|
| 325 | - return $this->_updatedFields; |
|
| 326 | - } |
|
| 327 | - /** |
|
| 328 | - * Get fields which values need to be updated |
|
| 329 | - * |
|
| 330 | - * @return array fields which values need to be updated |
|
| 331 | - * |
|
| 332 | - */ //felix |
|
| 333 | - public function getUpdatedWhere() |
|
| 334 | - { |
|
| 335 | - return $this->_updatedWhere; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Add values of a record to be added |
|
| 340 | - * |
|
| 341 | - * @param string $name name of the field |
|
| 342 | - * |
|
| 343 | - */ |
|
| 344 | - public function addDroppedField($name) |
|
| 345 | - { |
|
| 346 | - $this->_droppedFields[] = $name; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Get fields that need to be dropped |
|
| 351 | - * |
|
| 352 | - * @return array fields that need to be dropped |
|
| 353 | - * |
|
| 354 | - */ |
|
| 355 | - public function getDroppedFields() |
|
| 356 | - { |
|
| 357 | - return $this->_droppedFields; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Set the flag to drop the table |
|
| 362 | - * |
|
| 363 | - */ |
|
| 364 | - public function setFlagForDrop() |
|
| 365 | - { |
|
| 366 | - $this->_flagForDrop = true; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Use to create a table |
|
| 371 | - * |
|
| 372 | - * @return bool true if success, false if an error occured |
|
| 373 | - * |
|
| 374 | - */ |
|
| 375 | - public function createTable() |
|
| 376 | - { |
|
| 377 | - global $xoopsDB; |
|
| 378 | - $query = $this->getStructure(); |
|
| 379 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 380 | - //xoops_debug($query); |
|
| 381 | - $ret = $xoopsDB->query($query); |
|
| 382 | - if (!$ret) { |
|
| 383 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 384 | - } else { |
|
| 385 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - return $ret; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Use to drop a table |
|
| 393 | - * |
|
| 394 | - * @return bool true if success, false if an error occured |
|
| 395 | - * |
|
| 396 | - */ |
|
| 397 | - public function dropTable() |
|
| 398 | - { |
|
| 399 | - global $xoopsDB; |
|
| 400 | - $query = sprintf('DROP TABLE %s', $this->name()); |
|
| 401 | - $ret = $xoopsDB->query($query); |
|
| 402 | - if (!$ret) { |
|
| 403 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 404 | - |
|
| 405 | - return false; |
|
| 406 | - } else { |
|
| 407 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 408 | - |
|
| 409 | - return true; |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Use to alter a table |
|
| 415 | - * |
|
| 416 | - * @return bool true if success, false if an error occured |
|
| 417 | - * |
|
| 418 | - */ |
|
| 419 | - public function alterTable() |
|
| 420 | - { |
|
| 421 | - global $xoopsDB; |
|
| 422 | - $ret = true; |
|
| 423 | - |
|
| 424 | - foreach ($this->getAlteredFields() as $alteredField) { |
|
| 425 | - if (!$alteredField['newname']) { |
|
| 426 | - $alteredField['newname'] = $alteredField['name']; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
| 430 | - $ret = $ret && $xoopsDB->query($query); |
|
| 431 | - if ($alteredField['showerror']) { |
|
| 432 | - if (!$ret) { |
|
| 433 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 434 | - } else { |
|
| 435 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - return $ret; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Use to add new fileds in the table |
|
| 445 | - * |
|
| 446 | - * @return bool true if success, false if an error occured |
|
| 447 | - * |
|
| 448 | - */ |
|
| 449 | - public function addNewFields() |
|
| 450 | - { |
|
| 451 | - global $xoopsDB; |
|
| 452 | - $ret = true; |
|
| 453 | - foreach ($this->getNewFields() as $newField) { |
|
| 454 | - $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
| 455 | - //echo $query; |
|
| 456 | - $ret = $ret && $xoopsDB->query($query); |
|
| 457 | - if (!$ret) { |
|
| 458 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 459 | - } else { |
|
| 460 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return $ret; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Use to update fields values |
|
| 469 | - * |
|
| 470 | - * @return bool true if success, false if an error occured |
|
| 471 | - * |
|
| 472 | - */ |
|
| 473 | - public function updateFieldsValues() |
|
| 474 | - { |
|
| 475 | - global $xoopsDB; |
|
| 476 | - $ret = true; |
|
| 477 | - foreach ($this->getUpdatedFields() as $updatedField) { |
|
| 478 | - $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
| 479 | - $ret = $ret && $xoopsDB->query($query); |
|
| 480 | - if (!$ret) { |
|
| 481 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 482 | - } else { |
|
| 483 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $ret; |
|
| 488 | - } |
|
| 489 | - /** |
|
| 490 | - * Use to update fields values |
|
| 491 | - * |
|
| 492 | - * @return bool true if success, false if an error occured |
|
| 493 | - * |
|
| 494 | - */ //felix |
|
| 495 | - public function updateWhereValues() |
|
| 496 | - { |
|
| 497 | - global $xoopsDB; |
|
| 498 | - $ret = true; |
|
| 499 | - foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
| 500 | - $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
| 501 | - //echo $query."<br>"; |
|
| 502 | - $ret = $ret && $xoopsDB->query($query); |
|
| 503 | - if (!$ret) { |
|
| 504 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 505 | - } else { |
|
| 506 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - return $ret; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Use to drop fields |
|
| 515 | - * |
|
| 516 | - * @return bool true if success, false if an error occured |
|
| 517 | - * |
|
| 518 | - */ |
|
| 519 | - public function dropFields() |
|
| 520 | - { |
|
| 521 | - global $xoopsDB; |
|
| 522 | - $ret = true; |
|
| 523 | - foreach ($this->getDroppedFields() as $droppedField) { |
|
| 524 | - $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
| 525 | - $ret = $ret && $xoopsDB->query($query); |
|
| 526 | - if (!$ret) { |
|
| 527 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 528 | - } else { |
|
| 529 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - return $ret; |
|
| 534 | - } |
|
| 38 | + /** |
|
| 39 | + * @var string $_name name of the table |
|
| 40 | + */ |
|
| 41 | + public $_name; |
|
| 42 | + /** |
|
| 43 | + * @var string $_structure structure of the table |
|
| 44 | + */ |
|
| 45 | + public $_structure; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var array $_data containing valued of each records to be added |
|
| 49 | + */ |
|
| 50 | + public $_data; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var array $_alteredFields containing fields to be altered |
|
| 54 | + */ |
|
| 55 | + public $_alteredFields; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var array $_newFields containing new fields to be added |
|
| 59 | + */ |
|
| 60 | + public $_newFields; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var array $_droppedFields containing fields to be dropped |
|
| 64 | + */ |
|
| 65 | + public $_droppedFields; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var array $_flagForDrop flag table to drop it |
|
| 69 | + */ |
|
| 70 | + public $_flagForDrop = false; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var array $_updatedFields containing fields which values will be updated |
|
| 74 | + */ |
|
| 75 | + public $_updatedFields; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var array $_updatedFields containing fields which values will be updated |
|
| 79 | + */ //felix |
|
| 80 | + public $_updatedWhere; |
|
| 81 | + |
|
| 82 | + public $_existingFieldsArray = false; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Constructor |
|
| 86 | + * |
|
| 87 | + * @param string $name name of the table |
|
| 88 | + * |
|
| 89 | + */ |
|
| 90 | + public function __construct($name) |
|
| 91 | + { |
|
| 92 | + $this->_name = $name; |
|
| 93 | + $this->_data = []; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Return the table name, prefixed with site table prefix |
|
| 98 | + * |
|
| 99 | + * @return string table name |
|
| 100 | + * |
|
| 101 | + */ |
|
| 102 | + public function name() |
|
| 103 | + { |
|
| 104 | + global $xoopsDB; |
|
| 105 | + |
|
| 106 | + return $xoopsDB->prefix($this->_name); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Checks if the table already exists in the database |
|
| 111 | + * |
|
| 112 | + * @return bool TRUE if it exists, FALSE if not |
|
| 113 | + * |
|
| 114 | + */ |
|
| 115 | + public function exists() |
|
| 116 | + { |
|
| 117 | + return smart_TableExists($this->_name); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return mixed |
|
| 122 | + */ |
|
| 123 | + public function getExistingFieldsArray() |
|
| 124 | + { |
|
| 125 | + global $xoopsDB; |
|
| 126 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 127 | + while ($existing_field = $xoopsDB->fetchArray($result)) { |
|
| 128 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 129 | + if ($existing_field['Null'] !== 'YES') { |
|
| 130 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 131 | + } |
|
| 132 | + if ($existing_field['Extra']) { |
|
| 133 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 134 | + } |
|
| 135 | + if (!($existing_field['Default'] === null) |
|
| 136 | + && ($existing_field['Default'] |
|
| 137 | + || $existing_field['Default'] === '' |
|
| 138 | + || $existing_field['Default'] == 0)) { |
|
| 139 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $fields; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param $field |
|
| 148 | + * @return bool |
|
| 149 | + */ |
|
| 150 | + public function fieldExists($field) |
|
| 151 | + { |
|
| 152 | + $existingFields = $this->getExistingFieldsArray(); |
|
| 153 | + |
|
| 154 | + return isset($existingFields[$field]); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Set the table structure |
|
| 159 | + * |
|
| 160 | + * Example: |
|
| 161 | + * |
|
| 162 | + * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
| 163 | + * `date` int(11) NOT NULL default '0', |
|
| 164 | + * `status` int(1) NOT NULL default '-1', |
|
| 165 | + * `itemid` int(11) NOT NULL default '0', |
|
| 166 | + * `uid` int(11) NOT NULL default '0', |
|
| 167 | + * `price` float NOT NULL default '0', |
|
| 168 | + * `currency` varchar(100) NOT NULL default '', |
|
| 169 | + * PRIMARY KEY (`transactionid`)"); |
|
| 170 | + * |
|
| 171 | + * @param string $structure table structure |
|
| 172 | + * |
|
| 173 | + */ |
|
| 174 | + public function setStructure($structure) |
|
| 175 | + { |
|
| 176 | + $this->_structure = $structure; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Return the table structure |
|
| 181 | + * |
|
| 182 | + * @return string table structure |
|
| 183 | + * |
|
| 184 | + */ |
|
| 185 | + public function getStructure() |
|
| 186 | + { |
|
| 187 | + return sprintf($this->_structure, $this->name()); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Add values of a record to be added |
|
| 192 | + * |
|
| 193 | + * @param string $data values of a record |
|
| 194 | + * |
|
| 195 | + */ |
|
| 196 | + public function setData($data) |
|
| 197 | + { |
|
| 198 | + $this->_data[] = $data; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Get the data array |
|
| 203 | + * |
|
| 204 | + * @return array containing the records values to be added |
|
| 205 | + * |
|
| 206 | + */ |
|
| 207 | + public function getData() |
|
| 208 | + { |
|
| 209 | + return $this->_data; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Use to insert data in a table |
|
| 214 | + * |
|
| 215 | + * @return bool true if success, false if an error occured |
|
| 216 | + * |
|
| 217 | + */ |
|
| 218 | + public function addData() |
|
| 219 | + { |
|
| 220 | + global $xoopsDB; |
|
| 221 | + foreach ($this->getData() as $data) { |
|
| 222 | + $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
| 223 | + $ret = $xoopsDB->query($query); |
|
| 224 | + if (!$ret) { |
|
| 225 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 226 | + } else { |
|
| 227 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + return $ret; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Add a field to be added |
|
| 236 | + * |
|
| 237 | + * @param string $name name of the field |
|
| 238 | + * @param string $properties properties of the field |
|
| 239 | + * @param bool $newname |
|
| 240 | + * @param bool $showerror |
|
| 241 | + */ |
|
| 242 | + public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
| 243 | + { |
|
| 244 | + $field['name'] = $name; |
|
| 245 | + $field['properties'] = $properties; |
|
| 246 | + $field['showerror'] = $showerror; |
|
| 247 | + $field['newname'] = $newname; |
|
| 248 | + $this->_alteredFields[] = $field; |
|
| 249 | + } |
|
| 250 | + /** |
|
| 251 | + * Invert values 0 to 1 and 1 to 0 |
|
| 252 | + * |
|
| 253 | + * @param string $name name of the field |
|
| 254 | + * @param $newValue |
|
| 255 | + * @param $oldValue |
|
| 256 | + * @internal param string $old old propertie |
|
| 257 | + * @internal param string $new new propertie |
|
| 258 | + */ //felix |
|
| 259 | + public function addUpdatedWhere($name, $newValue, $oldValue) |
|
| 260 | + { |
|
| 261 | + $field['name'] = $name; |
|
| 262 | + $field['value'] = $newValue; |
|
| 263 | + $field['where'] = $oldValue; |
|
| 264 | + $this->_updatedWhere[] = $field; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Add new field of a record to be added |
|
| 269 | + * |
|
| 270 | + * @param string $name name of the field |
|
| 271 | + * @param string $properties properties of the field |
|
| 272 | + * |
|
| 273 | + */ |
|
| 274 | + public function addNewField($name, $properties) |
|
| 275 | + { |
|
| 276 | + $field['name'] = $name; |
|
| 277 | + $field['properties'] = $properties; |
|
| 278 | + $this->_newFields[] = $field; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Get fields that need to be altered |
|
| 283 | + * |
|
| 284 | + * @return array fields that need to be altered |
|
| 285 | + * |
|
| 286 | + */ |
|
| 287 | + public function getAlteredFields() |
|
| 288 | + { |
|
| 289 | + return $this->_alteredFields; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Add field for which the value will be updated |
|
| 294 | + * |
|
| 295 | + * @param string $name name of the field |
|
| 296 | + * @param string $value value to be set |
|
| 297 | + * |
|
| 298 | + */ |
|
| 299 | + public function addUpdatedField($name, $value) |
|
| 300 | + { |
|
| 301 | + $field['name'] = $name; |
|
| 302 | + $field['value'] = $value; |
|
| 303 | + $this->_updatedFields[] = $field; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Get new fields to be added |
|
| 308 | + * |
|
| 309 | + * @return array fields to be added |
|
| 310 | + * |
|
| 311 | + */ |
|
| 312 | + public function getNewFields() |
|
| 313 | + { |
|
| 314 | + return $this->_newFields; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Get fields which values need to be updated |
|
| 319 | + * |
|
| 320 | + * @return array fields which values need to be updated |
|
| 321 | + * |
|
| 322 | + */ |
|
| 323 | + public function getUpdatedFields() |
|
| 324 | + { |
|
| 325 | + return $this->_updatedFields; |
|
| 326 | + } |
|
| 327 | + /** |
|
| 328 | + * Get fields which values need to be updated |
|
| 329 | + * |
|
| 330 | + * @return array fields which values need to be updated |
|
| 331 | + * |
|
| 332 | + */ //felix |
|
| 333 | + public function getUpdatedWhere() |
|
| 334 | + { |
|
| 335 | + return $this->_updatedWhere; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Add values of a record to be added |
|
| 340 | + * |
|
| 341 | + * @param string $name name of the field |
|
| 342 | + * |
|
| 343 | + */ |
|
| 344 | + public function addDroppedField($name) |
|
| 345 | + { |
|
| 346 | + $this->_droppedFields[] = $name; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Get fields that need to be dropped |
|
| 351 | + * |
|
| 352 | + * @return array fields that need to be dropped |
|
| 353 | + * |
|
| 354 | + */ |
|
| 355 | + public function getDroppedFields() |
|
| 356 | + { |
|
| 357 | + return $this->_droppedFields; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Set the flag to drop the table |
|
| 362 | + * |
|
| 363 | + */ |
|
| 364 | + public function setFlagForDrop() |
|
| 365 | + { |
|
| 366 | + $this->_flagForDrop = true; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Use to create a table |
|
| 371 | + * |
|
| 372 | + * @return bool true if success, false if an error occured |
|
| 373 | + * |
|
| 374 | + */ |
|
| 375 | + public function createTable() |
|
| 376 | + { |
|
| 377 | + global $xoopsDB; |
|
| 378 | + $query = $this->getStructure(); |
|
| 379 | + $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 380 | + //xoops_debug($query); |
|
| 381 | + $ret = $xoopsDB->query($query); |
|
| 382 | + if (!$ret) { |
|
| 383 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 384 | + } else { |
|
| 385 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + return $ret; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Use to drop a table |
|
| 393 | + * |
|
| 394 | + * @return bool true if success, false if an error occured |
|
| 395 | + * |
|
| 396 | + */ |
|
| 397 | + public function dropTable() |
|
| 398 | + { |
|
| 399 | + global $xoopsDB; |
|
| 400 | + $query = sprintf('DROP TABLE %s', $this->name()); |
|
| 401 | + $ret = $xoopsDB->query($query); |
|
| 402 | + if (!$ret) { |
|
| 403 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 404 | + |
|
| 405 | + return false; |
|
| 406 | + } else { |
|
| 407 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 408 | + |
|
| 409 | + return true; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Use to alter a table |
|
| 415 | + * |
|
| 416 | + * @return bool true if success, false if an error occured |
|
| 417 | + * |
|
| 418 | + */ |
|
| 419 | + public function alterTable() |
|
| 420 | + { |
|
| 421 | + global $xoopsDB; |
|
| 422 | + $ret = true; |
|
| 423 | + |
|
| 424 | + foreach ($this->getAlteredFields() as $alteredField) { |
|
| 425 | + if (!$alteredField['newname']) { |
|
| 426 | + $alteredField['newname'] = $alteredField['name']; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
| 430 | + $ret = $ret && $xoopsDB->query($query); |
|
| 431 | + if ($alteredField['showerror']) { |
|
| 432 | + if (!$ret) { |
|
| 433 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 434 | + } else { |
|
| 435 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + return $ret; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Use to add new fileds in the table |
|
| 445 | + * |
|
| 446 | + * @return bool true if success, false if an error occured |
|
| 447 | + * |
|
| 448 | + */ |
|
| 449 | + public function addNewFields() |
|
| 450 | + { |
|
| 451 | + global $xoopsDB; |
|
| 452 | + $ret = true; |
|
| 453 | + foreach ($this->getNewFields() as $newField) { |
|
| 454 | + $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
| 455 | + //echo $query; |
|
| 456 | + $ret = $ret && $xoopsDB->query($query); |
|
| 457 | + if (!$ret) { |
|
| 458 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 459 | + } else { |
|
| 460 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return $ret; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Use to update fields values |
|
| 469 | + * |
|
| 470 | + * @return bool true if success, false if an error occured |
|
| 471 | + * |
|
| 472 | + */ |
|
| 473 | + public function updateFieldsValues() |
|
| 474 | + { |
|
| 475 | + global $xoopsDB; |
|
| 476 | + $ret = true; |
|
| 477 | + foreach ($this->getUpdatedFields() as $updatedField) { |
|
| 478 | + $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
| 479 | + $ret = $ret && $xoopsDB->query($query); |
|
| 480 | + if (!$ret) { |
|
| 481 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 482 | + } else { |
|
| 483 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $ret; |
|
| 488 | + } |
|
| 489 | + /** |
|
| 490 | + * Use to update fields values |
|
| 491 | + * |
|
| 492 | + * @return bool true if success, false if an error occured |
|
| 493 | + * |
|
| 494 | + */ //felix |
|
| 495 | + public function updateWhereValues() |
|
| 496 | + { |
|
| 497 | + global $xoopsDB; |
|
| 498 | + $ret = true; |
|
| 499 | + foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
| 500 | + $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
| 501 | + //echo $query."<br>"; |
|
| 502 | + $ret = $ret && $xoopsDB->query($query); |
|
| 503 | + if (!$ret) { |
|
| 504 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 505 | + } else { |
|
| 506 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + return $ret; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Use to drop fields |
|
| 515 | + * |
|
| 516 | + * @return bool true if success, false if an error occured |
|
| 517 | + * |
|
| 518 | + */ |
|
| 519 | + public function dropFields() |
|
| 520 | + { |
|
| 521 | + global $xoopsDB; |
|
| 522 | + $ret = true; |
|
| 523 | + foreach ($this->getDroppedFields() as $droppedField) { |
|
| 524 | + $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
| 525 | + $ret = $ret && $xoopsDB->query($query); |
|
| 526 | + if (!$ret) { |
|
| 527 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 528 | + } else { |
|
| 529 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + return $ret; |
|
| 534 | + } |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /** |
@@ -545,328 +545,328 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | class SmartobjectDbupdater |
| 547 | 547 | { |
| 548 | - public $_dbTypesArray; |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * SmartobjectDbupdater constructor. |
|
| 552 | - */ |
|
| 553 | - public function __construct() |
|
| 554 | - { |
|
| 555 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
| 556 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
| 557 | - $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
| 558 | - $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
| 559 | - $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
| 560 | - $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
| 561 | - $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
| 562 | - $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
| 563 | - $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
| 564 | - $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
| 565 | - $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
| 566 | - $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
| 567 | - $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
| 568 | - $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
| 569 | - $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
| 570 | - $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
| 571 | - $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
| 572 | - $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Use to execute a general query |
|
| 577 | - * |
|
| 578 | - * @param string $query query that will be executed |
|
| 579 | - * @param string $goodmsg message displayed on success |
|
| 580 | - * @param string $badmsg message displayed on error |
|
| 581 | - * |
|
| 582 | - * @return bool true if success, false if an error occured |
|
| 583 | - * |
|
| 584 | - */ |
|
| 585 | - public function runQuery($query, $goodmsg, $badmsg) |
|
| 586 | - { |
|
| 587 | - global $xoopsDB; |
|
| 588 | - $ret = $xoopsDB->query($query); |
|
| 589 | - if (!$ret) { |
|
| 590 | - echo " $badmsg<br>"; |
|
| 591 | - |
|
| 592 | - return false; |
|
| 593 | - } else { |
|
| 594 | - echo " $goodmsg<br>"; |
|
| 595 | - |
|
| 596 | - return true; |
|
| 597 | - } |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Use to rename a table |
|
| 602 | - * |
|
| 603 | - * @param string $from name of the table to rename |
|
| 604 | - * @param string $to new name of the renamed table |
|
| 605 | - * |
|
| 606 | - * @return bool true if success, false if an error occured |
|
| 607 | - */ |
|
| 608 | - public function renameTable($from, $to) |
|
| 609 | - { |
|
| 610 | - global $xoopsDB; |
|
| 611 | - $from = $xoopsDB->prefix($from); |
|
| 612 | - $to = $xoopsDB->prefix($to); |
|
| 613 | - $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
| 614 | - $ret = $xoopsDB->query($query); |
|
| 615 | - if (!$ret) { |
|
| 616 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
| 617 | - |
|
| 618 | - return false; |
|
| 619 | - } else { |
|
| 620 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
| 621 | - |
|
| 622 | - return true; |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Use to update a table |
|
| 628 | - * |
|
| 629 | - * @param object $table {@link SmartDbTable} that will be updated |
|
| 630 | - * |
|
| 631 | - * @see SmartDbTable |
|
| 632 | - * |
|
| 633 | - * @return bool true if success, false if an error occured |
|
| 634 | - */ |
|
| 635 | - public function updateTable($table) |
|
| 636 | - { |
|
| 637 | - global $xoopsDB; |
|
| 638 | - $ret = true; |
|
| 639 | - // If table has a structure, create the table |
|
| 640 | - if ($table->getStructure()) { |
|
| 641 | - $ret = $table->createTable() && $ret; |
|
| 642 | - } |
|
| 643 | - // If table is flag for drop, drop it |
|
| 644 | - if ($table->_flagForDrop) { |
|
| 645 | - $ret = $table->dropTable() && $ret; |
|
| 646 | - } |
|
| 647 | - // If table has data, insert it |
|
| 648 | - if ($table->getData()) { |
|
| 649 | - $ret = $table->addData() && $ret; |
|
| 650 | - } |
|
| 651 | - // If table has new fields to be added, add them |
|
| 652 | - if ($table->getNewFields()) { |
|
| 653 | - $ret = $table->addNewFields() && $ret; |
|
| 654 | - } |
|
| 655 | - // If table has altered field, alter the table |
|
| 656 | - if ($table->getAlteredFields()) { |
|
| 657 | - $ret = $table->alterTable() && $ret; |
|
| 658 | - } |
|
| 659 | - // If table has updated field values, update the table |
|
| 660 | - if ($table->getUpdatedFields()) { |
|
| 661 | - $ret = $table->updateFieldsValues($table) && $ret; |
|
| 662 | - } |
|
| 663 | - // If table has dropped field, alter the table |
|
| 664 | - if ($table->getDroppedFields()) { |
|
| 665 | - $ret = $table->dropFields($table) && $ret; |
|
| 666 | - } |
|
| 667 | - //felix |
|
| 668 | - // If table has updated field values, update the table |
|
| 669 | - if ($table->getUpdatedWhere()) { |
|
| 670 | - $ret = $table->UpdateWhereValues($table) && $ret; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return $ret; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * @param $module |
|
| 678 | - * @param $item |
|
| 679 | - */ |
|
| 680 | - public function automaticUpgrade($module, $item) |
|
| 681 | - { |
|
| 682 | - if (is_array($item)) { |
|
| 683 | - foreach ($item as $v) { |
|
| 684 | - $this->upgradeObjectItem($module, $v); |
|
| 685 | - } |
|
| 686 | - } else { |
|
| 687 | - $this->upgradeObjectItem($module, $item); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * @param $var |
|
| 693 | - * @return string |
|
| 694 | - */ |
|
| 695 | - public function getFieldTypeFromVar($var) |
|
| 696 | - { |
|
| 697 | - $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
| 698 | - |
|
| 699 | - return $ret; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * @param $var |
|
| 704 | - * @param bool $key |
|
| 705 | - * @return string |
|
| 706 | - */ |
|
| 707 | - public function getFieldDefaultFromVar($var, $key = false) |
|
| 708 | - { |
|
| 709 | - if ($var['value']) { |
|
| 710 | - return $var['value']; |
|
| 711 | - } else { |
|
| 712 | - if (in_array($var['data_type'], [ |
|
| 713 | - XOBJ_DTYPE_INT, |
|
| 714 | - XOBJ_DTYPE_STIME, |
|
| 715 | - XOBJ_DTYPE_MTIME, |
|
| 716 | - XOBJ_DTYPE_LTIME, |
|
| 717 | - XOBJ_DTYPE_TIME_ONLY, |
|
| 718 | - XOBJ_DTYPE_URLLINK, |
|
| 719 | - XOBJ_DTYPE_FILE |
|
| 720 | - ])) { |
|
| 721 | - return '0'; |
|
| 722 | - } else { |
|
| 723 | - return ''; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * @param $module |
|
| 730 | - * @param $item |
|
| 731 | - * @return bool |
|
| 732 | - */ |
|
| 733 | - public function upgradeObjectItem($module, $item) |
|
| 734 | - { |
|
| 735 | - $moduleHandler = xoops_getModuleHandler($item, $module); |
|
| 736 | - if (!$moduleHandler) { |
|
| 737 | - return false; |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - $table = new SmartDbTable($module . '_' . $item); |
|
| 741 | - $object = $moduleHandler->create(); |
|
| 742 | - $objectVars = $object->getVars(); |
|
| 743 | - |
|
| 744 | - if (!$table->exists()) { |
|
| 745 | - // table was never created, let's do it |
|
| 746 | - $structure = ''; |
|
| 747 | - foreach ($objectVars as $key => $var) { |
|
| 748 | - if ($var['persistent']) { |
|
| 749 | - $type = $this->getFieldTypeFromVar($var); |
|
| 750 | - if ($key == $moduleHandler->keyName) { |
|
| 751 | - $extra = 'auto_increment'; |
|
| 752 | - } else { |
|
| 753 | - $default = $this->getFieldDefaultFromVar($var); |
|
| 754 | - $extra = "default '$default' |
|
| 548 | + public $_dbTypesArray; |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * SmartobjectDbupdater constructor. |
|
| 552 | + */ |
|
| 553 | + public function __construct() |
|
| 554 | + { |
|
| 555 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
| 556 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
| 557 | + $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
| 558 | + $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
| 559 | + $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
| 560 | + $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
| 561 | + $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
| 562 | + $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
| 563 | + $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
| 564 | + $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
| 565 | + $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
| 566 | + $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
| 567 | + $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
| 568 | + $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
| 569 | + $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
| 570 | + $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
| 571 | + $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
| 572 | + $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Use to execute a general query |
|
| 577 | + * |
|
| 578 | + * @param string $query query that will be executed |
|
| 579 | + * @param string $goodmsg message displayed on success |
|
| 580 | + * @param string $badmsg message displayed on error |
|
| 581 | + * |
|
| 582 | + * @return bool true if success, false if an error occured |
|
| 583 | + * |
|
| 584 | + */ |
|
| 585 | + public function runQuery($query, $goodmsg, $badmsg) |
|
| 586 | + { |
|
| 587 | + global $xoopsDB; |
|
| 588 | + $ret = $xoopsDB->query($query); |
|
| 589 | + if (!$ret) { |
|
| 590 | + echo " $badmsg<br>"; |
|
| 591 | + |
|
| 592 | + return false; |
|
| 593 | + } else { |
|
| 594 | + echo " $goodmsg<br>"; |
|
| 595 | + |
|
| 596 | + return true; |
|
| 597 | + } |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Use to rename a table |
|
| 602 | + * |
|
| 603 | + * @param string $from name of the table to rename |
|
| 604 | + * @param string $to new name of the renamed table |
|
| 605 | + * |
|
| 606 | + * @return bool true if success, false if an error occured |
|
| 607 | + */ |
|
| 608 | + public function renameTable($from, $to) |
|
| 609 | + { |
|
| 610 | + global $xoopsDB; |
|
| 611 | + $from = $xoopsDB->prefix($from); |
|
| 612 | + $to = $xoopsDB->prefix($to); |
|
| 613 | + $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
| 614 | + $ret = $xoopsDB->query($query); |
|
| 615 | + if (!$ret) { |
|
| 616 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
| 617 | + |
|
| 618 | + return false; |
|
| 619 | + } else { |
|
| 620 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
| 621 | + |
|
| 622 | + return true; |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Use to update a table |
|
| 628 | + * |
|
| 629 | + * @param object $table {@link SmartDbTable} that will be updated |
|
| 630 | + * |
|
| 631 | + * @see SmartDbTable |
|
| 632 | + * |
|
| 633 | + * @return bool true if success, false if an error occured |
|
| 634 | + */ |
|
| 635 | + public function updateTable($table) |
|
| 636 | + { |
|
| 637 | + global $xoopsDB; |
|
| 638 | + $ret = true; |
|
| 639 | + // If table has a structure, create the table |
|
| 640 | + if ($table->getStructure()) { |
|
| 641 | + $ret = $table->createTable() && $ret; |
|
| 642 | + } |
|
| 643 | + // If table is flag for drop, drop it |
|
| 644 | + if ($table->_flagForDrop) { |
|
| 645 | + $ret = $table->dropTable() && $ret; |
|
| 646 | + } |
|
| 647 | + // If table has data, insert it |
|
| 648 | + if ($table->getData()) { |
|
| 649 | + $ret = $table->addData() && $ret; |
|
| 650 | + } |
|
| 651 | + // If table has new fields to be added, add them |
|
| 652 | + if ($table->getNewFields()) { |
|
| 653 | + $ret = $table->addNewFields() && $ret; |
|
| 654 | + } |
|
| 655 | + // If table has altered field, alter the table |
|
| 656 | + if ($table->getAlteredFields()) { |
|
| 657 | + $ret = $table->alterTable() && $ret; |
|
| 658 | + } |
|
| 659 | + // If table has updated field values, update the table |
|
| 660 | + if ($table->getUpdatedFields()) { |
|
| 661 | + $ret = $table->updateFieldsValues($table) && $ret; |
|
| 662 | + } |
|
| 663 | + // If table has dropped field, alter the table |
|
| 664 | + if ($table->getDroppedFields()) { |
|
| 665 | + $ret = $table->dropFields($table) && $ret; |
|
| 666 | + } |
|
| 667 | + //felix |
|
| 668 | + // If table has updated field values, update the table |
|
| 669 | + if ($table->getUpdatedWhere()) { |
|
| 670 | + $ret = $table->UpdateWhereValues($table) && $ret; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return $ret; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * @param $module |
|
| 678 | + * @param $item |
|
| 679 | + */ |
|
| 680 | + public function automaticUpgrade($module, $item) |
|
| 681 | + { |
|
| 682 | + if (is_array($item)) { |
|
| 683 | + foreach ($item as $v) { |
|
| 684 | + $this->upgradeObjectItem($module, $v); |
|
| 685 | + } |
|
| 686 | + } else { |
|
| 687 | + $this->upgradeObjectItem($module, $item); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * @param $var |
|
| 693 | + * @return string |
|
| 694 | + */ |
|
| 695 | + public function getFieldTypeFromVar($var) |
|
| 696 | + { |
|
| 697 | + $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
| 698 | + |
|
| 699 | + return $ret; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * @param $var |
|
| 704 | + * @param bool $key |
|
| 705 | + * @return string |
|
| 706 | + */ |
|
| 707 | + public function getFieldDefaultFromVar($var, $key = false) |
|
| 708 | + { |
|
| 709 | + if ($var['value']) { |
|
| 710 | + return $var['value']; |
|
| 711 | + } else { |
|
| 712 | + if (in_array($var['data_type'], [ |
|
| 713 | + XOBJ_DTYPE_INT, |
|
| 714 | + XOBJ_DTYPE_STIME, |
|
| 715 | + XOBJ_DTYPE_MTIME, |
|
| 716 | + XOBJ_DTYPE_LTIME, |
|
| 717 | + XOBJ_DTYPE_TIME_ONLY, |
|
| 718 | + XOBJ_DTYPE_URLLINK, |
|
| 719 | + XOBJ_DTYPE_FILE |
|
| 720 | + ])) { |
|
| 721 | + return '0'; |
|
| 722 | + } else { |
|
| 723 | + return ''; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * @param $module |
|
| 730 | + * @param $item |
|
| 731 | + * @return bool |
|
| 732 | + */ |
|
| 733 | + public function upgradeObjectItem($module, $item) |
|
| 734 | + { |
|
| 735 | + $moduleHandler = xoops_getModuleHandler($item, $module); |
|
| 736 | + if (!$moduleHandler) { |
|
| 737 | + return false; |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + $table = new SmartDbTable($module . '_' . $item); |
|
| 741 | + $object = $moduleHandler->create(); |
|
| 742 | + $objectVars = $object->getVars(); |
|
| 743 | + |
|
| 744 | + if (!$table->exists()) { |
|
| 745 | + // table was never created, let's do it |
|
| 746 | + $structure = ''; |
|
| 747 | + foreach ($objectVars as $key => $var) { |
|
| 748 | + if ($var['persistent']) { |
|
| 749 | + $type = $this->getFieldTypeFromVar($var); |
|
| 750 | + if ($key == $moduleHandler->keyName) { |
|
| 751 | + $extra = 'auto_increment'; |
|
| 752 | + } else { |
|
| 753 | + $default = $this->getFieldDefaultFromVar($var); |
|
| 754 | + $extra = "default '$default' |
|
| 755 | 755 | "; |
| 756 | - } |
|
| 757 | - $structure .= "`$key` $type not null $extra, |
|
| 756 | + } |
|
| 757 | + $structure .= "`$key` $type not null $extra, |
|
| 758 | 758 | "; |
| 759 | - } |
|
| 760 | - } |
|
| 761 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
| 762 | 762 | '; |
| 763 | - $table->setStructure($structure); |
|
| 764 | - if (!$this->updateTable($table)) { |
|
| 765 | - /** |
|
| 766 | - * @todo trap the errors |
|
| 767 | - */ |
|
| 768 | - } |
|
| 769 | - } else { |
|
| 770 | - $existingFieldsArray = $table->getExistingFieldsArray(); |
|
| 771 | - foreach ($objectVars as $key => $var) { |
|
| 772 | - if ($var['persistent']) { |
|
| 773 | - if (!isset($existingFieldsArray[$key])) { |
|
| 774 | - // the fiels does not exist, let's create it |
|
| 775 | - $type = $this->getFieldTypeFromVar($var); |
|
| 776 | - $default = $this->getFieldDefaultFromVar($var); |
|
| 777 | - $table->addNewField($key, "$type not null default '$default'"); |
|
| 778 | - } else { |
|
| 779 | - // if field already exists, let's check if the definition is correct |
|
| 780 | - $definition = strtolower($existingFieldsArray[$key]); |
|
| 781 | - $type = $this->getFieldTypeFromVar($var); |
|
| 782 | - if ($key == $moduleHandler->keyName) { |
|
| 783 | - $extra = 'auto_increment'; |
|
| 784 | - } else { |
|
| 785 | - $default = $this->getFieldDefaultFromVar($var, $key); |
|
| 786 | - $extra = "default '$default'"; |
|
| 787 | - } |
|
| 788 | - $actual_definition = "$type not null $extra"; |
|
| 789 | - if ($definition != $actual_definition) { |
|
| 790 | - $table->addAlteredField($key, $actual_definition); |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - // check to see if there are some unused fields left in the table |
|
| 797 | - foreach ($existingFieldsArray as $key => $v) { |
|
| 798 | - if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
| 799 | - $table->addDroppedField($key); |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - if (!$this->updateTable($table)) { |
|
| 804 | - /** |
|
| 805 | - * @todo trap the errors |
|
| 806 | - */ |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * @param $module |
|
| 813 | - * @return bool |
|
| 814 | - */ |
|
| 815 | - public function moduleUpgrade(XoopsModule $module) |
|
| 816 | - { |
|
| 817 | - $dirname = $module->getVar('dirname'); |
|
| 818 | - |
|
| 819 | - ob_start(); |
|
| 820 | - |
|
| 821 | - $table = new SmartDbTable($dirname . '_meta'); |
|
| 822 | - if (!$table->exists()) { |
|
| 823 | - $table->setStructure(" |
|
| 763 | + $table->setStructure($structure); |
|
| 764 | + if (!$this->updateTable($table)) { |
|
| 765 | + /** |
|
| 766 | + * @todo trap the errors |
|
| 767 | + */ |
|
| 768 | + } |
|
| 769 | + } else { |
|
| 770 | + $existingFieldsArray = $table->getExistingFieldsArray(); |
|
| 771 | + foreach ($objectVars as $key => $var) { |
|
| 772 | + if ($var['persistent']) { |
|
| 773 | + if (!isset($existingFieldsArray[$key])) { |
|
| 774 | + // the fiels does not exist, let's create it |
|
| 775 | + $type = $this->getFieldTypeFromVar($var); |
|
| 776 | + $default = $this->getFieldDefaultFromVar($var); |
|
| 777 | + $table->addNewField($key, "$type not null default '$default'"); |
|
| 778 | + } else { |
|
| 779 | + // if field already exists, let's check if the definition is correct |
|
| 780 | + $definition = strtolower($existingFieldsArray[$key]); |
|
| 781 | + $type = $this->getFieldTypeFromVar($var); |
|
| 782 | + if ($key == $moduleHandler->keyName) { |
|
| 783 | + $extra = 'auto_increment'; |
|
| 784 | + } else { |
|
| 785 | + $default = $this->getFieldDefaultFromVar($var, $key); |
|
| 786 | + $extra = "default '$default'"; |
|
| 787 | + } |
|
| 788 | + $actual_definition = "$type not null $extra"; |
|
| 789 | + if ($definition != $actual_definition) { |
|
| 790 | + $table->addAlteredField($key, $actual_definition); |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + // check to see if there are some unused fields left in the table |
|
| 797 | + foreach ($existingFieldsArray as $key => $v) { |
|
| 798 | + if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
| 799 | + $table->addDroppedField($key); |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + if (!$this->updateTable($table)) { |
|
| 804 | + /** |
|
| 805 | + * @todo trap the errors |
|
| 806 | + */ |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * @param $module |
|
| 813 | + * @return bool |
|
| 814 | + */ |
|
| 815 | + public function moduleUpgrade(XoopsModule $module) |
|
| 816 | + { |
|
| 817 | + $dirname = $module->getVar('dirname'); |
|
| 818 | + |
|
| 819 | + ob_start(); |
|
| 820 | + |
|
| 821 | + $table = new SmartDbTable($dirname . '_meta'); |
|
| 822 | + if (!$table->exists()) { |
|
| 823 | + $table->setStructure(" |
|
| 824 | 824 | `metakey` varchar(50) NOT NULL default '', |
| 825 | 825 | `metavalue` varchar(255) NOT NULL default '', |
| 826 | 826 | PRIMARY KEY (`metakey`)"); |
| 827 | - $table->setData("'version',0"); |
|
| 828 | - if (!$this->updateTable($table)) { |
|
| 829 | - /** |
|
| 830 | - * @todo trap the errors |
|
| 831 | - */ |
|
| 832 | - } |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - $dbVersion = smart_GetMeta('version', $dirname); |
|
| 836 | - if (!$dbVersion) { |
|
| 837 | - $dbVersion = 0; |
|
| 838 | - } |
|
| 839 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
| 840 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
| 841 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
| 842 | - |
|
| 843 | - if ($newDbVersion > $dbVersion) { |
|
| 844 | - for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
| 845 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
| 846 | - if (function_exists($upgrade_function)) { |
|
| 847 | - $upgrade_function(); |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 853 | - |
|
| 854 | - // if there is a function to execute for this DB version, let's do it |
|
| 855 | - //$function_ |
|
| 856 | - |
|
| 857 | - $module_info = smart_getModuleInfo($dirname); |
|
| 858 | - $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
| 859 | - |
|
| 860 | - echo '</code>'; |
|
| 861 | - |
|
| 862 | - $feedback = ob_get_clean(); |
|
| 863 | - if (method_exists($module, 'setMessage')) { |
|
| 864 | - $module->setMessage($feedback); |
|
| 865 | - } else { |
|
| 866 | - echo $feedback; |
|
| 867 | - } |
|
| 868 | - smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
| 869 | - |
|
| 870 | - return true; |
|
| 871 | - } |
|
| 827 | + $table->setData("'version',0"); |
|
| 828 | + if (!$this->updateTable($table)) { |
|
| 829 | + /** |
|
| 830 | + * @todo trap the errors |
|
| 831 | + */ |
|
| 832 | + } |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + $dbVersion = smart_GetMeta('version', $dirname); |
|
| 836 | + if (!$dbVersion) { |
|
| 837 | + $dbVersion = 0; |
|
| 838 | + } |
|
| 839 | + $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
| 840 | + echo 'Database version: ' . $dbVersion . '<br>'; |
|
| 841 | + echo 'New database version: ' . $newDbVersion . '<br>'; |
|
| 842 | + |
|
| 843 | + if ($newDbVersion > $dbVersion) { |
|
| 844 | + for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
| 845 | + $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
| 846 | + if (function_exists($upgrade_function)) { |
|
| 847 | + $upgrade_function(); |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 853 | + |
|
| 854 | + // if there is a function to execute for this DB version, let's do it |
|
| 855 | + //$function_ |
|
| 856 | + |
|
| 857 | + $module_info = smart_getModuleInfo($dirname); |
|
| 858 | + $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
| 859 | + |
|
| 860 | + echo '</code>'; |
|
| 861 | + |
|
| 862 | + $feedback = ob_get_clean(); |
|
| 863 | + if (method_exists($module, 'setMessage')) { |
|
| 864 | + $module->setMessage($feedback); |
|
| 865 | + } else { |
|
| 866 | + echo $feedback; |
|
| 867 | + } |
|
| 868 | + smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
| 869 | + |
|
| 870 | + return true; |
|
| 871 | + } |
|
| 872 | 872 | } |
@@ -18,15 +18,15 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
| 20 | 20 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
| 21 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 21 | + require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
| 22 | 22 | } |
| 23 | 23 | /** |
| 24 | 24 | * Include the language constants for the SmartObjectDBUpdater |
| 25 | 25 | */ |
| 26 | 26 | global $xoopsConfig; |
| 27 | -$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
|
| 27 | +$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php'; |
|
| 28 | 28 | if (!file_exists($common_file)) { |
| 29 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 29 | + $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php'; |
|
| 30 | 30 | } |
| 31 | 31 | include $common_file; |
| 32 | 32 | |
@@ -123,20 +123,20 @@ discard block |
||
| 123 | 123 | public function getExistingFieldsArray() |
| 124 | 124 | { |
| 125 | 125 | global $xoopsDB; |
| 126 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 126 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$this->name()); |
|
| 127 | 127 | while ($existing_field = $xoopsDB->fetchArray($result)) { |
| 128 | 128 | $fields[$existing_field['Field']] = $existing_field['Type']; |
| 129 | 129 | if ($existing_field['Null'] !== 'YES') { |
| 130 | 130 | $fields[$existing_field['Field']] .= ' NOT NULL'; |
| 131 | 131 | } |
| 132 | 132 | if ($existing_field['Extra']) { |
| 133 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 133 | + $fields[$existing_field['Field']] .= ' '.$existing_field['Extra']; |
|
| 134 | 134 | } |
| 135 | 135 | if (!($existing_field['Default'] === null) |
| 136 | 136 | && ($existing_field['Default'] |
| 137 | 137 | || $existing_field['Default'] === '' |
| 138 | 138 | || $existing_field['Default'] == 0)) { |
| 139 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 139 | + $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'"; |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
@@ -222,9 +222,9 @@ discard block |
||
| 222 | 222 | $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
| 223 | 223 | $ret = $xoopsDB->query($query); |
| 224 | 224 | if (!$ret) { |
| 225 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 225 | + echo ' '.sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()).'<br>'; |
|
| 226 | 226 | } else { |
| 227 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 227 | + echo ' '.sprintf(_SDU_MSG_ADD_DATA, $this->name()).'<br>'; |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
@@ -376,13 +376,13 @@ discard block |
||
| 376 | 376 | { |
| 377 | 377 | global $xoopsDB; |
| 378 | 378 | $query = $this->getStructure(); |
| 379 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 379 | + $query = 'CREATE TABLE `'.$this->name().'` ('.$query.") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 380 | 380 | //xoops_debug($query); |
| 381 | 381 | $ret = $xoopsDB->query($query); |
| 382 | 382 | if (!$ret) { |
| 383 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 383 | + echo ' '.sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 384 | 384 | } else { |
| 385 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 385 | + echo ' '.sprintf(_SDU_MSG_CREATE_TABLE, $this->name()).'<br>'; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | return $ret; |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | $query = sprintf('DROP TABLE %s', $this->name()); |
| 401 | 401 | $ret = $xoopsDB->query($query); |
| 402 | 402 | if (!$ret) { |
| 403 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 403 | + echo ' '.sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 404 | 404 | |
| 405 | 405 | return false; |
| 406 | 406 | } else { |
| 407 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 407 | + echo ' '.sprintf(_SDU_MSG_DROP_TABLE, $this->name()).'<br>'; |
|
| 408 | 408 | |
| 409 | 409 | return true; |
| 410 | 410 | } |
@@ -430,9 +430,9 @@ discard block |
||
| 430 | 430 | $ret = $ret && $xoopsDB->query($query); |
| 431 | 431 | if ($alteredField['showerror']) { |
| 432 | 432 | if (!$ret) { |
| 433 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 433 | + echo ' '.sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 434 | 434 | } else { |
| 435 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 435 | + echo ' '.sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()).'<br>'; |
|
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | } |
@@ -455,9 +455,9 @@ discard block |
||
| 455 | 455 | //echo $query; |
| 456 | 456 | $ret = $ret && $xoopsDB->query($query); |
| 457 | 457 | if (!$ret) { |
| 458 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 458 | + echo ' '.sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()).'<br>'; |
|
| 459 | 459 | } else { |
| 460 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 460 | + echo ' '.sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()).'<br>'; |
|
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | |
@@ -478,9 +478,9 @@ discard block |
||
| 478 | 478 | $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
| 479 | 479 | $ret = $ret && $xoopsDB->query($query); |
| 480 | 480 | if (!$ret) { |
| 481 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 481 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 482 | 482 | } else { |
| 483 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 483 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>'; |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
@@ -501,9 +501,9 @@ discard block |
||
| 501 | 501 | //echo $query."<br>"; |
| 502 | 502 | $ret = $ret && $xoopsDB->query($query); |
| 503 | 503 | if (!$ret) { |
| 504 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 504 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 505 | 505 | } else { |
| 506 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 506 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>'; |
|
| 507 | 507 | } |
| 508 | 508 | } |
| 509 | 509 | |
@@ -524,9 +524,9 @@ discard block |
||
| 524 | 524 | $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
| 525 | 525 | $ret = $ret && $xoopsDB->query($query); |
| 526 | 526 | if (!$ret) { |
| 527 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 527 | + echo ' '.sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
| 528 | 528 | } else { |
| 529 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 529 | + echo ' '.sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()).'<br>'; |
|
| 530 | 530 | } |
| 531 | 531 | } |
| 532 | 532 | |
@@ -613,11 +613,11 @@ discard block |
||
| 613 | 613 | $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
| 614 | 614 | $ret = $xoopsDB->query($query); |
| 615 | 615 | if (!$ret) { |
| 616 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
| 616 | + echo ' '.sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from).'<br>'; |
|
| 617 | 617 | |
| 618 | 618 | return false; |
| 619 | 619 | } else { |
| 620 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
| 620 | + echo ' '.sprintf(_SDU_MSG_RENAME_TABLE, $from, $to).'<br>'; |
|
| 621 | 621 | |
| 622 | 622 | return true; |
| 623 | 623 | } |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | return false; |
| 738 | 738 | } |
| 739 | 739 | |
| 740 | - $table = new SmartDbTable($module . '_' . $item); |
|
| 740 | + $table = new SmartDbTable($module.'_'.$item); |
|
| 741 | 741 | $object = $moduleHandler->create(); |
| 742 | 742 | $objectVars = $object->getVars(); |
| 743 | 743 | |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | "; |
| 759 | 759 | } |
| 760 | 760 | } |
| 761 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
| 761 | + $structure .= 'PRIMARY KEY (`'.$moduleHandler->keyName.'`) |
|
| 762 | 762 | '; |
| 763 | 763 | $table->setStructure($structure); |
| 764 | 764 | if (!$this->updateTable($table)) { |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | |
| 819 | 819 | ob_start(); |
| 820 | 820 | |
| 821 | - $table = new SmartDbTable($dirname . '_meta'); |
|
| 821 | + $table = new SmartDbTable($dirname.'_meta'); |
|
| 822 | 822 | if (!$table->exists()) { |
| 823 | 823 | $table->setStructure(" |
| 824 | 824 | `metakey` varchar(50) NOT NULL default '', |
@@ -836,20 +836,20 @@ discard block |
||
| 836 | 836 | if (!$dbVersion) { |
| 837 | 837 | $dbVersion = 0; |
| 838 | 838 | } |
| 839 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
| 840 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
| 841 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
| 839 | + $newDbVersion = constant(strtoupper($dirname.'_db_version')) ?: 0; |
|
| 840 | + echo 'Database version: '.$dbVersion.'<br>'; |
|
| 841 | + echo 'New database version: '.$newDbVersion.'<br>'; |
|
| 842 | 842 | |
| 843 | 843 | if ($newDbVersion > $dbVersion) { |
| 844 | 844 | for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
| 845 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
| 845 | + $upgrade_function = $dirname.'_db_upgrade_'.$i; |
|
| 846 | 846 | if (function_exists($upgrade_function)) { |
| 847 | 847 | $upgrade_function(); |
| 848 | 848 | } |
| 849 | 849 | } |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 852 | + echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>'; |
|
| 853 | 853 | |
| 854 | 854 | // if there is a function to execute for this DB version, let's do it |
| 855 | 855 | //$function_ |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | /** |
| 198 | 198 | * @param $val |
| 199 | 199 | * @param $separator |
| 200 | - * @param $trimFunction |
|
| 200 | + * @param false|string $trimFunction |
|
| 201 | 201 | * @return mixed|string |
| 202 | 202 | */ |
| 203 | 203 | public function valToCsvHelper($val, $separator, $trimFunction) |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
| 251 | - * @param $content |
|
| 251 | + * @param string $content |
|
| 252 | 252 | */ |
| 253 | 253 | public function saveExportFile($content) |
| 254 | 254 | { |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | } while (false); |
| 238 | 238 | if ($needQuote) { |
| 239 | - $val = '"' . $val . '"'; |
|
| 239 | + $val = '"'.$val.'"'; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | return $val; |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | case 'csv': |
| 251 | 251 | $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
| 252 | 252 | $firstRow = implode($separator, $this->data['columnsHeaders']); |
| 253 | - $exportFileData .= $firstRow . "\r\n"; |
|
| 253 | + $exportFileData .= $firstRow."\r\n"; |
|
| 254 | 254 | |
| 255 | 255 | foreach ($this->data['rows'] as $cols) { |
| 256 | - $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
| 256 | + $exportFileData .= $this->arrayToCsvString($cols, $separator)."\r\n"; |
|
| 257 | 257 | } |
| 258 | 258 | break; |
| 259 | 259 | } |
@@ -278,19 +278,19 @@ discard block |
||
| 278 | 278 | public function saveCsv($content) |
| 279 | 279 | { |
| 280 | 280 | if (!$this->filepath) { |
| 281 | - $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
| 281 | + $this->filepath = XOOPS_UPLOAD_PATH.'/'; |
|
| 282 | 282 | } |
| 283 | 283 | if (!$this->filename) { |
| 284 | 284 | $this->filename .= time(); |
| 285 | 285 | $this->filename .= '.csv'; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $fullFileName = $this->filepath . $this->filename; |
|
| 288 | + $fullFileName = $this->filepath.$this->filename; |
|
| 289 | 289 | |
| 290 | 290 | if (!$handle = fopen($fullFileName, 'a+')) { |
| 291 | - trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
| 291 | + trigger_error('Unable to open '.$fullFileName, E_USER_WARNING); |
|
| 292 | 292 | } elseif (fwrite($handle, $content) === false) { |
| 293 | - trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
| 293 | + trigger_error('Unable to write in '.$fullFileName, E_USER_WARNING); |
|
| 294 | 294 | } else { |
| 295 | 295 | $mimeType = 'text/csv'; |
| 296 | 296 | $file = strrev($this->filename); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | } else { |
| 301 | 301 | $file_name = $temp_name; |
| 302 | 302 | } |
| 303 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
| 303 | + $fullFileName = $this->filepath.stripslashes(trim($this->filename)); |
|
| 304 | 304 | |
| 305 | 305 | if (ini_get('zlib.output_compression')) { |
| 306 | 306 | ini_set('zlib.output_compression', 'Off'); |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | header('Cache-Control: private', false); |
| 312 | 312 | header('Content-Transfer-Encoding: binary'); |
| 313 | 313 | if (isset($mimeType)) { |
| 314 | - header('Content-Type: ' . $mimeType); |
|
| 314 | + header('Content-Type: '.$mimeType); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - header('Content-Disposition: attachment; filename=' . $file_name); |
|
| 317 | + header('Content-Disposition: attachment; filename='.$file_name); |
|
| 318 | 318 | |
| 319 | 319 | if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
| 320 | 320 | $fp = fopen($fullFileName, 'r'); |
@@ -19,118 +19,118 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class SmartObjectExport |
| 21 | 21 | { |
| 22 | - public $handler; |
|
| 23 | - public $criteria; |
|
| 24 | - public $fields; |
|
| 25 | - public $format; |
|
| 26 | - public $filename; |
|
| 27 | - public $filepath; |
|
| 28 | - public $options; |
|
| 29 | - public $outputMethods = false; |
|
| 30 | - public $notDisplayFields; |
|
| 22 | + public $handler; |
|
| 23 | + public $criteria; |
|
| 24 | + public $fields; |
|
| 25 | + public $format; |
|
| 26 | + public $filename; |
|
| 27 | + public $filepath; |
|
| 28 | + public $options; |
|
| 29 | + public $outputMethods = false; |
|
| 30 | + public $notDisplayFields; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Constructor |
|
| 34 | - * |
|
| 35 | - * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export |
|
| 36 | - * @param CriteriaElement $criteria containing the criteria of the query fetching the objects to be exported |
|
| 37 | - * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
| 38 | - * @param bool|string $filename name of the file to be created |
|
| 39 | - * @param bool|string $filepath path where the file will be saved |
|
| 40 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 41 | - * @param array|bool $options options of the format to be exported in |
|
| 42 | - */ |
|
| 43 | - public function __construct( |
|
| 44 | - SmartPersistableObjectHandler $objectHandler, |
|
| 45 | - CriteriaElement $criteria = null, |
|
| 46 | - $fields = false, |
|
| 47 | - $filename = false, |
|
| 48 | - $filepath = false, |
|
| 49 | - $format = 'csv', |
|
| 50 | - $options = false |
|
| 51 | - ) { |
|
| 52 | - $this->handler = $objectHandler; |
|
| 53 | - $this->criteria = $criteria; |
|
| 54 | - $this->fields = $fields; |
|
| 55 | - $this->filename = $filename; |
|
| 56 | - $this->format = $format; |
|
| 57 | - $this->options = $options; |
|
| 58 | - $this->notDisplayFields = false; |
|
| 59 | - } |
|
| 32 | + /** |
|
| 33 | + * Constructor |
|
| 34 | + * |
|
| 35 | + * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export |
|
| 36 | + * @param CriteriaElement $criteria containing the criteria of the query fetching the objects to be exported |
|
| 37 | + * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
| 38 | + * @param bool|string $filename name of the file to be created |
|
| 39 | + * @param bool|string $filepath path where the file will be saved |
|
| 40 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 41 | + * @param array|bool $options options of the format to be exported in |
|
| 42 | + */ |
|
| 43 | + public function __construct( |
|
| 44 | + SmartPersistableObjectHandler $objectHandler, |
|
| 45 | + CriteriaElement $criteria = null, |
|
| 46 | + $fields = false, |
|
| 47 | + $filename = false, |
|
| 48 | + $filepath = false, |
|
| 49 | + $format = 'csv', |
|
| 50 | + $options = false |
|
| 51 | + ) { |
|
| 52 | + $this->handler = $objectHandler; |
|
| 53 | + $this->criteria = $criteria; |
|
| 54 | + $this->fields = $fields; |
|
| 55 | + $this->filename = $filename; |
|
| 56 | + $this->format = $format; |
|
| 57 | + $this->options = $options; |
|
| 58 | + $this->notDisplayFields = false; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Renders the export |
|
| 63 | - * @param $filename |
|
| 64 | - */ |
|
| 65 | - public function render($filename) |
|
| 66 | - { |
|
| 67 | - $this->filename = $filename; |
|
| 61 | + /** |
|
| 62 | + * Renders the export |
|
| 63 | + * @param $filename |
|
| 64 | + */ |
|
| 65 | + public function render($filename) |
|
| 66 | + { |
|
| 67 | + $this->filename = $filename; |
|
| 68 | 68 | |
| 69 | - $objects = $this->handler->getObjects($this->criteria); |
|
| 70 | - $rows = []; |
|
| 71 | - $columnsHeaders = []; |
|
| 72 | - $firstObject = true; |
|
| 73 | - foreach ($objects as $object) { |
|
| 74 | - $row = []; |
|
| 75 | - foreach ($object->vars as $key => $var) { |
|
| 76 | - if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
| 77 | - if ($this->outputMethods && isset($this->outputMethods[$key]) |
|
| 78 | - && method_exists($object, $this->outputMethods[$key])) { |
|
| 79 | - $method = $this->outputMethods[$key]; |
|
| 80 | - $row[$key] = $object->$method(); |
|
| 81 | - } else { |
|
| 82 | - $row[$key] = $object->getVar($key); |
|
| 83 | - } |
|
| 84 | - if ($firstObject) { |
|
| 85 | - // then set the columnsHeaders array as well |
|
| 86 | - $columnsHeaders[$key] = $var['form_caption']; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - $firstObject = false; |
|
| 91 | - $rows[] = $row; |
|
| 92 | - unset($row); |
|
| 93 | - } |
|
| 94 | - $data = []; |
|
| 95 | - $data['rows'] = $rows; |
|
| 96 | - $data['columnsHeaders'] = $columnsHeaders; |
|
| 97 | - $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
| 98 | - $smartExportRenderer->execute(); |
|
| 99 | - } |
|
| 69 | + $objects = $this->handler->getObjects($this->criteria); |
|
| 70 | + $rows = []; |
|
| 71 | + $columnsHeaders = []; |
|
| 72 | + $firstObject = true; |
|
| 73 | + foreach ($objects as $object) { |
|
| 74 | + $row = []; |
|
| 75 | + foreach ($object->vars as $key => $var) { |
|
| 76 | + if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
| 77 | + if ($this->outputMethods && isset($this->outputMethods[$key]) |
|
| 78 | + && method_exists($object, $this->outputMethods[$key])) { |
|
| 79 | + $method = $this->outputMethods[$key]; |
|
| 80 | + $row[$key] = $object->$method(); |
|
| 81 | + } else { |
|
| 82 | + $row[$key] = $object->getVar($key); |
|
| 83 | + } |
|
| 84 | + if ($firstObject) { |
|
| 85 | + // then set the columnsHeaders array as well |
|
| 86 | + $columnsHeaders[$key] = $var['form_caption']; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + $firstObject = false; |
|
| 91 | + $rows[] = $row; |
|
| 92 | + unset($row); |
|
| 93 | + } |
|
| 94 | + $data = []; |
|
| 95 | + $data['rows'] = $rows; |
|
| 96 | + $data['columnsHeaders'] = $columnsHeaders; |
|
| 97 | + $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
| 98 | + $smartExportRenderer->execute(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Set an array contaning the alternate methods to use instead of the default getVar() |
|
| 103 | - * |
|
| 104 | - * $outputMethods array example: 'uid' => 'getUserName'... |
|
| 105 | - * @param $outputMethods |
|
| 106 | - */ |
|
| 107 | - public function setOuptutMethods($outputMethods) |
|
| 108 | - { |
|
| 109 | - $this->outputMethods = $outputMethods; |
|
| 110 | - } |
|
| 101 | + /** |
|
| 102 | + * Set an array contaning the alternate methods to use instead of the default getVar() |
|
| 103 | + * |
|
| 104 | + * $outputMethods array example: 'uid' => 'getUserName'... |
|
| 105 | + * @param $outputMethods |
|
| 106 | + */ |
|
| 107 | + public function setOuptutMethods($outputMethods) |
|
| 108 | + { |
|
| 109 | + $this->outputMethods = $outputMethods; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /* |
|
| 112 | + /* |
|
| 113 | 113 | * Set an array of fields that we don't want in export |
| 114 | 114 | */ |
| 115 | - /** |
|
| 116 | - * @param $fields |
|
| 117 | - */ |
|
| 118 | - public function setNotDisplayFields($fields) |
|
| 119 | - { |
|
| 120 | - if (!$this->notDisplayFields) { |
|
| 121 | - if (is_array($fields)) { |
|
| 122 | - $this->notDisplayFields = $fields; |
|
| 123 | - } else { |
|
| 124 | - $this->notDisplayFields = [$fields]; |
|
| 125 | - } |
|
| 126 | - } else { |
|
| 127 | - if (is_array($fields)) { |
|
| 128 | - $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
| 129 | - } else { |
|
| 130 | - $this->notDisplayFields[] = $fields; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 115 | + /** |
|
| 116 | + * @param $fields |
|
| 117 | + */ |
|
| 118 | + public function setNotDisplayFields($fields) |
|
| 119 | + { |
|
| 120 | + if (!$this->notDisplayFields) { |
|
| 121 | + if (is_array($fields)) { |
|
| 122 | + $this->notDisplayFields = $fields; |
|
| 123 | + } else { |
|
| 124 | + $this->notDisplayFields = [$fields]; |
|
| 125 | + } |
|
| 126 | + } else { |
|
| 127 | + if (is_array($fields)) { |
|
| 128 | + $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
| 129 | + } else { |
|
| 130 | + $this->notDisplayFields[] = $fields; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -144,186 +144,186 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | class SmartExportRenderer |
| 146 | 146 | { |
| 147 | - public $data; |
|
| 148 | - public $format; |
|
| 149 | - public $filename; |
|
| 150 | - public $filepath; |
|
| 151 | - public $options; |
|
| 147 | + public $data; |
|
| 148 | + public $format; |
|
| 149 | + public $filename; |
|
| 150 | + public $filepath; |
|
| 151 | + public $options; |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Constructor |
|
| 155 | - * |
|
| 156 | - * @param array $data contains the data to be exported |
|
| 157 | - * @param bool|string $filename name of the file in which the exported data will be saved |
|
| 158 | - * @param bool|string $filepath path where the file will be saved |
|
| 159 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 160 | - * @param array $options options of the format to be exported in |
|
| 161 | - */ |
|
| 162 | - public function __construct( |
|
| 163 | - $data, |
|
| 164 | - $filename = false, |
|
| 165 | - $filepath = false, |
|
| 166 | - $format = 'csv', |
|
| 167 | - $options = ['separator' => ';'] |
|
| 168 | - ) { |
|
| 169 | - $this->data = $data; |
|
| 170 | - $this->format = $format; |
|
| 171 | - $this->filename = $filename; |
|
| 172 | - $this->filepath = $filepath; |
|
| 173 | - $this->options = $options; |
|
| 174 | - } |
|
| 153 | + /** |
|
| 154 | + * Constructor |
|
| 155 | + * |
|
| 156 | + * @param array $data contains the data to be exported |
|
| 157 | + * @param bool|string $filename name of the file in which the exported data will be saved |
|
| 158 | + * @param bool|string $filepath path where the file will be saved |
|
| 159 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 160 | + * @param array $options options of the format to be exported in |
|
| 161 | + */ |
|
| 162 | + public function __construct( |
|
| 163 | + $data, |
|
| 164 | + $filename = false, |
|
| 165 | + $filepath = false, |
|
| 166 | + $format = 'csv', |
|
| 167 | + $options = ['separator' => ';'] |
|
| 168 | + ) { |
|
| 169 | + $this->data = $data; |
|
| 170 | + $this->format = $format; |
|
| 171 | + $this->filename = $filename; |
|
| 172 | + $this->filepath = $filepath; |
|
| 173 | + $this->options = $options; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * @param $dataArray |
|
| 178 | - * @param $separator |
|
| 179 | - * @param string $trim |
|
| 180 | - * @param bool $removeEmptyLines |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
| 184 | - { |
|
| 185 | - if (!is_array($dataArray) || empty($dataArray)) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - switch ($trim) { |
|
| 189 | - case 'none': |
|
| 190 | - $trimFunction = false; |
|
| 191 | - break; |
|
| 192 | - case 'left': |
|
| 193 | - $trimFunction = 'ltrim'; |
|
| 194 | - break; |
|
| 195 | - case 'right': |
|
| 196 | - $trimFunction = 'rtrim'; |
|
| 197 | - break; |
|
| 198 | - default: //'both': |
|
| 199 | - $trimFunction = 'trim'; |
|
| 200 | - break; |
|
| 201 | - } |
|
| 202 | - $ret = []; |
|
| 203 | - foreach ($dataArray as $key => $field) { |
|
| 204 | - $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
| 205 | - } |
|
| 176 | + /** |
|
| 177 | + * @param $dataArray |
|
| 178 | + * @param $separator |
|
| 179 | + * @param string $trim |
|
| 180 | + * @param bool $removeEmptyLines |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
| 184 | + { |
|
| 185 | + if (!is_array($dataArray) || empty($dataArray)) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + switch ($trim) { |
|
| 189 | + case 'none': |
|
| 190 | + $trimFunction = false; |
|
| 191 | + break; |
|
| 192 | + case 'left': |
|
| 193 | + $trimFunction = 'ltrim'; |
|
| 194 | + break; |
|
| 195 | + case 'right': |
|
| 196 | + $trimFunction = 'rtrim'; |
|
| 197 | + break; |
|
| 198 | + default: //'both': |
|
| 199 | + $trimFunction = 'trim'; |
|
| 200 | + break; |
|
| 201 | + } |
|
| 202 | + $ret = []; |
|
| 203 | + foreach ($dataArray as $key => $field) { |
|
| 204 | + $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return implode($separator, $ret); |
|
| 208 | - } |
|
| 207 | + return implode($separator, $ret); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * @param $val |
|
| 212 | - * @param $separator |
|
| 213 | - * @param $trimFunction |
|
| 214 | - * @return mixed|string |
|
| 215 | - */ |
|
| 216 | - public function valToCsvHelper($val, $separator, $trimFunction) |
|
| 217 | - { |
|
| 218 | - if ($trimFunction) { |
|
| 219 | - $val = $trimFunction($val); |
|
| 220 | - } |
|
| 221 | - //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
| 222 | - $needQuote = false; |
|
| 223 | - do { |
|
| 224 | - if (strpos($val, '"') !== false) { |
|
| 225 | - $val = str_replace('"', '""', $val); |
|
| 226 | - $needQuote = true; |
|
| 227 | - break; |
|
| 228 | - } |
|
| 229 | - if (strpos($val, $separator) !== false) { |
|
| 230 | - $needQuote = true; |
|
| 231 | - break; |
|
| 232 | - } |
|
| 233 | - if ((strpos($val, "\n") !== false) || (strpos($val, "\r") !== false)) { // \r is for mac |
|
| 234 | - $needQuote = true; |
|
| 235 | - break; |
|
| 236 | - } |
|
| 237 | - } while (false); |
|
| 238 | - if ($needQuote) { |
|
| 239 | - $val = '"' . $val . '"'; |
|
| 240 | - } |
|
| 210 | + /** |
|
| 211 | + * @param $val |
|
| 212 | + * @param $separator |
|
| 213 | + * @param $trimFunction |
|
| 214 | + * @return mixed|string |
|
| 215 | + */ |
|
| 216 | + public function valToCsvHelper($val, $separator, $trimFunction) |
|
| 217 | + { |
|
| 218 | + if ($trimFunction) { |
|
| 219 | + $val = $trimFunction($val); |
|
| 220 | + } |
|
| 221 | + //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
| 222 | + $needQuote = false; |
|
| 223 | + do { |
|
| 224 | + if (strpos($val, '"') !== false) { |
|
| 225 | + $val = str_replace('"', '""', $val); |
|
| 226 | + $needQuote = true; |
|
| 227 | + break; |
|
| 228 | + } |
|
| 229 | + if (strpos($val, $separator) !== false) { |
|
| 230 | + $needQuote = true; |
|
| 231 | + break; |
|
| 232 | + } |
|
| 233 | + if ((strpos($val, "\n") !== false) || (strpos($val, "\r") !== false)) { // \r is for mac |
|
| 234 | + $needQuote = true; |
|
| 235 | + break; |
|
| 236 | + } |
|
| 237 | + } while (false); |
|
| 238 | + if ($needQuote) { |
|
| 239 | + $val = '"' . $val . '"'; |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $val; |
|
| 243 | - } |
|
| 242 | + return $val; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - public function execute() |
|
| 246 | - { |
|
| 247 | - $exportFileData = ''; |
|
| 245 | + public function execute() |
|
| 246 | + { |
|
| 247 | + $exportFileData = ''; |
|
| 248 | 248 | |
| 249 | - switch ($this->format) { |
|
| 250 | - case 'csv': |
|
| 251 | - $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
| 252 | - $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
| 253 | - $exportFileData .= $firstRow . "\r\n"; |
|
| 249 | + switch ($this->format) { |
|
| 250 | + case 'csv': |
|
| 251 | + $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
| 252 | + $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
| 253 | + $exportFileData .= $firstRow . "\r\n"; |
|
| 254 | 254 | |
| 255 | - foreach ($this->data['rows'] as $cols) { |
|
| 256 | - $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
| 257 | - } |
|
| 258 | - break; |
|
| 259 | - } |
|
| 260 | - $this->saveExportFile($exportFileData); |
|
| 261 | - } |
|
| 255 | + foreach ($this->data['rows'] as $cols) { |
|
| 256 | + $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
| 257 | + } |
|
| 258 | + break; |
|
| 259 | + } |
|
| 260 | + $this->saveExportFile($exportFileData); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * @param $content |
|
| 265 | - */ |
|
| 266 | - public function saveExportFile($content) |
|
| 267 | - { |
|
| 268 | - switch ($this->format) { |
|
| 269 | - case 'csv': |
|
| 270 | - $this->saveCsv($content); |
|
| 271 | - break; |
|
| 272 | - } |
|
| 273 | - } |
|
| 263 | + /** |
|
| 264 | + * @param $content |
|
| 265 | + */ |
|
| 266 | + public function saveExportFile($content) |
|
| 267 | + { |
|
| 268 | + switch ($this->format) { |
|
| 269 | + case 'csv': |
|
| 270 | + $this->saveCsv($content); |
|
| 271 | + break; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * @param $content |
|
| 277 | - */ |
|
| 278 | - public function saveCsv($content) |
|
| 279 | - { |
|
| 280 | - if (!$this->filepath) { |
|
| 281 | - $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
| 282 | - } |
|
| 283 | - if (!$this->filename) { |
|
| 284 | - $this->filename .= time(); |
|
| 285 | - $this->filename .= '.csv'; |
|
| 286 | - } |
|
| 275 | + /** |
|
| 276 | + * @param $content |
|
| 277 | + */ |
|
| 278 | + public function saveCsv($content) |
|
| 279 | + { |
|
| 280 | + if (!$this->filepath) { |
|
| 281 | + $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
| 282 | + } |
|
| 283 | + if (!$this->filename) { |
|
| 284 | + $this->filename .= time(); |
|
| 285 | + $this->filename .= '.csv'; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - $fullFileName = $this->filepath . $this->filename; |
|
| 288 | + $fullFileName = $this->filepath . $this->filename; |
|
| 289 | 289 | |
| 290 | - if (!$handle = fopen($fullFileName, 'a+')) { |
|
| 291 | - trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
| 292 | - } elseif (fwrite($handle, $content) === false) { |
|
| 293 | - trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
| 294 | - } else { |
|
| 295 | - $mimeType = 'text/csv'; |
|
| 296 | - $file = strrev($this->filename); |
|
| 297 | - $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
| 298 | - if ($temp_name === '') { |
|
| 299 | - $file_name = $this->filename; |
|
| 300 | - } else { |
|
| 301 | - $file_name = $temp_name; |
|
| 302 | - } |
|
| 303 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
| 290 | + if (!$handle = fopen($fullFileName, 'a+')) { |
|
| 291 | + trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
| 292 | + } elseif (fwrite($handle, $content) === false) { |
|
| 293 | + trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
| 294 | + } else { |
|
| 295 | + $mimeType = 'text/csv'; |
|
| 296 | + $file = strrev($this->filename); |
|
| 297 | + $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
| 298 | + if ($temp_name === '') { |
|
| 299 | + $file_name = $this->filename; |
|
| 300 | + } else { |
|
| 301 | + $file_name = $temp_name; |
|
| 302 | + } |
|
| 303 | + $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
| 304 | 304 | |
| 305 | - if (ini_get('zlib.output_compression')) { |
|
| 306 | - ini_set('zlib.output_compression', 'Off'); |
|
| 307 | - } |
|
| 305 | + if (ini_get('zlib.output_compression')) { |
|
| 306 | + ini_set('zlib.output_compression', 'Off'); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - header('Pragma: public'); |
|
| 310 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 311 | - header('Cache-Control: private', false); |
|
| 312 | - header('Content-Transfer-Encoding: binary'); |
|
| 313 | - if (isset($mimeType)) { |
|
| 314 | - header('Content-Type: ' . $mimeType); |
|
| 315 | - } |
|
| 309 | + header('Pragma: public'); |
|
| 310 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 311 | + header('Cache-Control: private', false); |
|
| 312 | + header('Content-Transfer-Encoding: binary'); |
|
| 313 | + if (isset($mimeType)) { |
|
| 314 | + header('Content-Type: ' . $mimeType); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - header('Content-Disposition: attachment; filename=' . $file_name); |
|
| 317 | + header('Content-Disposition: attachment; filename=' . $file_name); |
|
| 318 | 318 | |
| 319 | - if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
| 320 | - $fp = fopen($fullFileName, 'r'); |
|
| 321 | - } else { |
|
| 322 | - $fp = fopen($fullFileName, 'rb'); |
|
| 323 | - } |
|
| 324 | - fpassthru($fp); |
|
| 325 | - exit(); |
|
| 326 | - } |
|
| 327 | - fclose($handle); |
|
| 328 | - } |
|
| 319 | + if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
| 320 | + $fp = fopen($fullFileName, 'r'); |
|
| 321 | + } else { |
|
| 322 | + $fp = fopen($fullFileName, 'rb'); |
|
| 323 | + } |
|
| 324 | + fpassthru($fp); |
|
| 325 | + exit(); |
|
| 326 | + } |
|
| 327 | + fclose($handle); |
|
| 328 | + } |
|
| 329 | 329 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | - * @param $keywords |
|
| 168 | + * @param string|boolean $keywords |
|
| 169 | 169 | */ |
| 170 | 170 | public function setKeywords($keywords) |
| 171 | 171 | { |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | - * @param $categoryPath |
|
| 176 | + * @param boolean $categoryPath |
|
| 177 | 177 | */ |
| 178 | 178 | public function setCategoryPath($categoryPath) |
| 179 | 179 | { |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * @param $description |
|
| 185 | + * @param boolean $description |
|
| 186 | 186 | */ |
| 187 | 187 | public function setDescription($description) |
| 188 | 188 | { |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * @param $text |
|
| 246 | - * @param $minChar |
|
| 245 | + * @param string $text |
|
| 246 | + * @param integer $minChar |
|
| 247 | 247 | * @return array |
| 248 | 248 | */ |
| 249 | 249 | public function findMetaKeywords($text, $minChar) |
@@ -354,7 +354,7 @@ |
||
| 354 | 354 | public function createMetaKeywords() |
| 355 | 355 | { |
| 356 | 356 | global $xoopsModuleConfig; |
| 357 | - $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
| 357 | + $keywords = $this->findMetaKeywords($this->_original_title.' '.$this->_description, $this->_minChar); |
|
| 358 | 358 | if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) |
| 359 | 359 | && $xoopsModuleConfig['moduleMetaKeywords'] !== '') { |
| 360 | 360 | $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
@@ -18,350 +18,350 @@ 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 = [ |
|
| 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 = [ |
|
| 118 | - '-', |
|
| 119 | - '-', |
|
| 120 | - '-', |
|
| 121 | - '-', |
|
| 122 | - '-', |
|
| 123 | - '-100', |
|
| 124 | - '-', |
|
| 125 | - '-', |
|
| 126 | - '-', |
|
| 127 | - '-', |
|
| 128 | - '-', |
|
| 129 | - '-', |
|
| 130 | - '-', |
|
| 131 | - '-', |
|
| 132 | - '-', |
|
| 133 | - '-', |
|
| 134 | - '-', |
|
| 135 | - '-', |
|
| 136 | - '-at-', |
|
| 137 | - '-', |
|
| 138 | - '-', |
|
| 139 | - '-', |
|
| 140 | - '-', |
|
| 141 | - '-', |
|
| 142 | - '-', |
|
| 143 | - '-', |
|
| 144 | - '-', |
|
| 145 | - '-' |
|
| 146 | - ]; |
|
| 147 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 148 | - |
|
| 149 | - // Transformation des caractères accentués |
|
| 150 | - $pattern = [ |
|
| 151 | - '/%B0/', // ° |
|
| 152 | - '/%E8/', // è |
|
| 153 | - '/%E9/', // é |
|
| 154 | - '/%EA/', // ê |
|
| 155 | - '/%EB/', // ë |
|
| 156 | - '/%E7/', // ç |
|
| 157 | - '/%E0/', // à |
|
| 158 | - '/%E2/', // â |
|
| 159 | - '/%E4/', // ä |
|
| 160 | - '/%EE/', // î |
|
| 161 | - '/%EF/', // ï |
|
| 162 | - '/%F9/', // ù |
|
| 163 | - '/%FC/', // ü |
|
| 164 | - '/%FB/', // û |
|
| 165 | - '/%F4/', // ô |
|
| 166 | - '/%F6/', // ö |
|
| 167 | - ]; |
|
| 168 | - $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 169 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 170 | - |
|
| 171 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 172 | - $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 173 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 174 | - |
|
| 175 | - if (count($title) > 0) { |
|
| 176 | - if ($withExt) { |
|
| 177 | - $title .= '.html'; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $title; |
|
| 181 | - } else { |
|
| 182 | - return ''; |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param $document |
|
| 188 | - * @return mixed |
|
| 189 | - */ |
|
| 190 | - public function html2text($document) |
|
| 191 | - { |
|
| 192 | - return smart_html2text($document); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param $title |
|
| 197 | - */ |
|
| 198 | - public function setTitle($title) |
|
| 199 | - { |
|
| 200 | - global $xoopsModule, $xoopsModuleConfig; |
|
| 201 | - $this->_title = $this->html2text($title); |
|
| 202 | - $this->_title = $this->purifyText($this->_title); |
|
| 203 | - $this->_original_title = $this->_title; |
|
| 204 | - |
|
| 205 | - $moduleName = $xoopsModule->getVar('name'); |
|
| 206 | - |
|
| 207 | - $titleTag = []; |
|
| 208 | - |
|
| 209 | - $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true; |
|
| 210 | - |
|
| 211 | - if ($moduleName && $show_mod_name_breadcrumb) { |
|
| 212 | - $titleTag['module'] = $moduleName; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - if (isset($this->_title) && ($this->_title !== '') && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
| 216 | - $titleTag['title'] = $this->_title; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if (isset($this->_categoryPath) && ($this->_categoryPath !== '')) { |
|
| 220 | - $titleTag['category'] = $this->_categoryPath; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
| 224 | - |
|
| 225 | - if (isset($titleTag['category']) && $titleTag['category'] !== '') { |
|
| 226 | - if ($ret !== '') { |
|
| 227 | - $ret .= ' - '; |
|
| 228 | - } |
|
| 229 | - $ret .= $titleTag['category']; |
|
| 230 | - } |
|
| 231 | - if (isset($titleTag['module']) && $titleTag['module'] !== '') { |
|
| 232 | - if ($ret !== '') { |
|
| 233 | - $ret .= ' - '; |
|
| 234 | - } |
|
| 235 | - $ret .= $titleTag['module']; |
|
| 236 | - } |
|
| 237 | - $this->_title = $ret; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param $keywords |
|
| 242 | - */ |
|
| 243 | - public function setKeywords($keywords) |
|
| 244 | - { |
|
| 245 | - $this->_keywords = $keywords; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @param $categoryPath |
|
| 250 | - */ |
|
| 251 | - public function setCategoryPath($categoryPath) |
|
| 252 | - { |
|
| 253 | - $categoryPath = $this->html2text($categoryPath); |
|
| 254 | - $this->_categoryPath = $categoryPath; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @param $description |
|
| 259 | - */ |
|
| 260 | - public function setDescription($description) |
|
| 261 | - { |
|
| 262 | - if (!$description) { |
|
| 263 | - global $xoopsModuleConfig; |
|
| 264 | - if (isset($xoopsModuleConfig['module_meta_description'])) { |
|
| 265 | - $description = $xoopsModuleConfig['module_meta_description']; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $description = $this->html2text($description); |
|
| 270 | - $description = $this->purifyText($description); |
|
| 271 | - |
|
| 272 | - $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
| 273 | - $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
| 274 | - $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
| 275 | - $description = stripslashes($description); |
|
| 276 | - |
|
| 277 | - $this->_description = $description; |
|
| 278 | - $this->_meta_description = $this->createMetaDescription(); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - public function createTitleTag() |
|
| 282 | - { |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @param $text |
|
| 287 | - * @param bool $keyword |
|
| 288 | - * @return mixed|string |
|
| 289 | - */ |
|
| 290 | - public function purifyText($text, $keyword = false) |
|
| 291 | - { |
|
| 292 | - return smart_purifyText($text, $keyword); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @param int $maxWords |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - public function createMetaDescription($maxWords = 100) |
|
| 300 | - { |
|
| 301 | - $words = []; |
|
| 302 | - $words = explode(' ', $this->_description); |
|
| 303 | - |
|
| 304 | - // Only keep $maxWords words |
|
| 305 | - $newWords = []; |
|
| 306 | - $i = 0; |
|
| 307 | - |
|
| 308 | - while ($i < $maxWords - 1 && $i < count($words)) { |
|
| 309 | - $newWords[] = $words[$i]; |
|
| 310 | - ++$i; |
|
| 311 | - } |
|
| 312 | - $ret = implode(' ', $newWords); |
|
| 313 | - |
|
| 314 | - return $ret; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param $text |
|
| 319 | - * @param $minChar |
|
| 320 | - * @return array |
|
| 321 | - */ |
|
| 322 | - public function findMetaKeywords($text, $minChar) |
|
| 323 | - { |
|
| 324 | - $keywords = []; |
|
| 325 | - |
|
| 326 | - $text = $this->purifyText($text); |
|
| 327 | - $text = $this->html2text($text); |
|
| 328 | - |
|
| 329 | - $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
| 330 | - $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
| 331 | - $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
| 332 | - $text = stripslashes($text); |
|
| 333 | - $text = |
|
| 334 | - |
|
| 335 | - $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 336 | - |
|
| 337 | - foreach ($originalKeywords as $originalKeyword) { |
|
| 338 | - $secondRoundKeywords = explode("'", $originalKeyword); |
|
| 339 | - foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
| 340 | - if (strlen($secondRoundKeyword) >= $minChar) { |
|
| 341 | - if (!in_array($secondRoundKeyword, $keywords)) { |
|
| 342 | - $keywords[] = trim($secondRoundKeyword); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - return $keywords; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @return string |
|
| 353 | - */ |
|
| 354 | - public function createMetaKeywords() |
|
| 355 | - { |
|
| 356 | - global $xoopsModuleConfig; |
|
| 357 | - $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
| 358 | - if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) |
|
| 359 | - && $xoopsModuleConfig['moduleMetaKeywords'] !== '') { |
|
| 360 | - $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
|
| 361 | - $keywords = array_merge($keywords, $moduleKeywords); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /* 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 = [ |
|
| 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 = [ |
|
| 118 | + '-', |
|
| 119 | + '-', |
|
| 120 | + '-', |
|
| 121 | + '-', |
|
| 122 | + '-', |
|
| 123 | + '-100', |
|
| 124 | + '-', |
|
| 125 | + '-', |
|
| 126 | + '-', |
|
| 127 | + '-', |
|
| 128 | + '-', |
|
| 129 | + '-', |
|
| 130 | + '-', |
|
| 131 | + '-', |
|
| 132 | + '-', |
|
| 133 | + '-', |
|
| 134 | + '-', |
|
| 135 | + '-', |
|
| 136 | + '-at-', |
|
| 137 | + '-', |
|
| 138 | + '-', |
|
| 139 | + '-', |
|
| 140 | + '-', |
|
| 141 | + '-', |
|
| 142 | + '-', |
|
| 143 | + '-', |
|
| 144 | + '-', |
|
| 145 | + '-' |
|
| 146 | + ]; |
|
| 147 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 148 | + |
|
| 149 | + // Transformation des caractères accentués |
|
| 150 | + $pattern = [ |
|
| 151 | + '/%B0/', // ° |
|
| 152 | + '/%E8/', // è |
|
| 153 | + '/%E9/', // é |
|
| 154 | + '/%EA/', // ê |
|
| 155 | + '/%EB/', // ë |
|
| 156 | + '/%E7/', // ç |
|
| 157 | + '/%E0/', // à |
|
| 158 | + '/%E2/', // â |
|
| 159 | + '/%E4/', // ä |
|
| 160 | + '/%EE/', // î |
|
| 161 | + '/%EF/', // ï |
|
| 162 | + '/%F9/', // ù |
|
| 163 | + '/%FC/', // ü |
|
| 164 | + '/%FB/', // û |
|
| 165 | + '/%F4/', // ô |
|
| 166 | + '/%F6/', // ö |
|
| 167 | + ]; |
|
| 168 | + $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
| 169 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 170 | + |
|
| 171 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 172 | + $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
| 173 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 174 | + |
|
| 175 | + if (count($title) > 0) { |
|
| 176 | + if ($withExt) { |
|
| 177 | + $title .= '.html'; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $title; |
|
| 181 | + } else { |
|
| 182 | + return ''; |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param $document |
|
| 188 | + * @return mixed |
|
| 189 | + */ |
|
| 190 | + public function html2text($document) |
|
| 191 | + { |
|
| 192 | + return smart_html2text($document); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param $title |
|
| 197 | + */ |
|
| 198 | + public function setTitle($title) |
|
| 199 | + { |
|
| 200 | + global $xoopsModule, $xoopsModuleConfig; |
|
| 201 | + $this->_title = $this->html2text($title); |
|
| 202 | + $this->_title = $this->purifyText($this->_title); |
|
| 203 | + $this->_original_title = $this->_title; |
|
| 204 | + |
|
| 205 | + $moduleName = $xoopsModule->getVar('name'); |
|
| 206 | + |
|
| 207 | + $titleTag = []; |
|
| 208 | + |
|
| 209 | + $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true; |
|
| 210 | + |
|
| 211 | + if ($moduleName && $show_mod_name_breadcrumb) { |
|
| 212 | + $titleTag['module'] = $moduleName; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + if (isset($this->_title) && ($this->_title !== '') && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
| 216 | + $titleTag['title'] = $this->_title; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if (isset($this->_categoryPath) && ($this->_categoryPath !== '')) { |
|
| 220 | + $titleTag['category'] = $this->_categoryPath; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
| 224 | + |
|
| 225 | + if (isset($titleTag['category']) && $titleTag['category'] !== '') { |
|
| 226 | + if ($ret !== '') { |
|
| 227 | + $ret .= ' - '; |
|
| 228 | + } |
|
| 229 | + $ret .= $titleTag['category']; |
|
| 230 | + } |
|
| 231 | + if (isset($titleTag['module']) && $titleTag['module'] !== '') { |
|
| 232 | + if ($ret !== '') { |
|
| 233 | + $ret .= ' - '; |
|
| 234 | + } |
|
| 235 | + $ret .= $titleTag['module']; |
|
| 236 | + } |
|
| 237 | + $this->_title = $ret; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param $keywords |
|
| 242 | + */ |
|
| 243 | + public function setKeywords($keywords) |
|
| 244 | + { |
|
| 245 | + $this->_keywords = $keywords; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @param $categoryPath |
|
| 250 | + */ |
|
| 251 | + public function setCategoryPath($categoryPath) |
|
| 252 | + { |
|
| 253 | + $categoryPath = $this->html2text($categoryPath); |
|
| 254 | + $this->_categoryPath = $categoryPath; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param $description |
|
| 259 | + */ |
|
| 260 | + public function setDescription($description) |
|
| 261 | + { |
|
| 262 | + if (!$description) { |
|
| 263 | + global $xoopsModuleConfig; |
|
| 264 | + if (isset($xoopsModuleConfig['module_meta_description'])) { |
|
| 265 | + $description = $xoopsModuleConfig['module_meta_description']; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $description = $this->html2text($description); |
|
| 270 | + $description = $this->purifyText($description); |
|
| 271 | + |
|
| 272 | + $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
| 273 | + $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
| 274 | + $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
| 275 | + $description = stripslashes($description); |
|
| 276 | + |
|
| 277 | + $this->_description = $description; |
|
| 278 | + $this->_meta_description = $this->createMetaDescription(); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + public function createTitleTag() |
|
| 282 | + { |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @param $text |
|
| 287 | + * @param bool $keyword |
|
| 288 | + * @return mixed|string |
|
| 289 | + */ |
|
| 290 | + public function purifyText($text, $keyword = false) |
|
| 291 | + { |
|
| 292 | + return smart_purifyText($text, $keyword); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @param int $maxWords |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + public function createMetaDescription($maxWords = 100) |
|
| 300 | + { |
|
| 301 | + $words = []; |
|
| 302 | + $words = explode(' ', $this->_description); |
|
| 303 | + |
|
| 304 | + // Only keep $maxWords words |
|
| 305 | + $newWords = []; |
|
| 306 | + $i = 0; |
|
| 307 | + |
|
| 308 | + while ($i < $maxWords - 1 && $i < count($words)) { |
|
| 309 | + $newWords[] = $words[$i]; |
|
| 310 | + ++$i; |
|
| 311 | + } |
|
| 312 | + $ret = implode(' ', $newWords); |
|
| 313 | + |
|
| 314 | + return $ret; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param $text |
|
| 319 | + * @param $minChar |
|
| 320 | + * @return array |
|
| 321 | + */ |
|
| 322 | + public function findMetaKeywords($text, $minChar) |
|
| 323 | + { |
|
| 324 | + $keywords = []; |
|
| 325 | + |
|
| 326 | + $text = $this->purifyText($text); |
|
| 327 | + $text = $this->html2text($text); |
|
| 328 | + |
|
| 329 | + $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
| 330 | + $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
| 331 | + $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
| 332 | + $text = stripslashes($text); |
|
| 333 | + $text = |
|
| 334 | + |
|
| 335 | + $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 336 | + |
|
| 337 | + foreach ($originalKeywords as $originalKeyword) { |
|
| 338 | + $secondRoundKeywords = explode("'", $originalKeyword); |
|
| 339 | + foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
| 340 | + if (strlen($secondRoundKeyword) >= $minChar) { |
|
| 341 | + if (!in_array($secondRoundKeyword, $keywords)) { |
|
| 342 | + $keywords[] = trim($secondRoundKeyword); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + return $keywords; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @return string |
|
| 353 | + */ |
|
| 354 | + public function createMetaKeywords() |
|
| 355 | + { |
|
| 356 | + global $xoopsModuleConfig; |
|
| 357 | + $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
| 358 | + if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) |
|
| 359 | + && $xoopsModuleConfig['moduleMetaKeywords'] !== '') { |
|
| 360 | + $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
|
| 361 | + $keywords = array_merge($keywords, $moduleKeywords); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /* Commenting this out as it may cause problem on XOOPS ML websites |
|
| 365 | 365 | $return_keywords = array(); |
| 366 | 366 | |
| 367 | 367 | // Cleaning for duplicate keywords |
@@ -371,43 +371,43 @@ discard block |
||
| 371 | 371 | } |
| 372 | 372 | }*/ |
| 373 | 373 | |
| 374 | - // Only take the first 90 keywords |
|
| 375 | - $newKeywords = []; |
|
| 376 | - $i = 0; |
|
| 377 | - while ($i < 90 - 1 && isset($keywords[$i])) { |
|
| 378 | - $newKeywords[] = $keywords[$i]; |
|
| 379 | - ++$i; |
|
| 380 | - } |
|
| 381 | - $ret = implode(', ', $newKeywords); |
|
| 382 | - |
|
| 383 | - return $ret; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - public function autoBuildMeta_keywords() |
|
| 387 | - { |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - public function buildAutoMetaTags() |
|
| 391 | - { |
|
| 392 | - global $xoopsModule, $xoopsModuleConfig; |
|
| 393 | - |
|
| 394 | - $this->_keywords = $this->createMetaKeywords(); |
|
| 395 | - $this->_meta_description = $this->createMetaDescription(); |
|
| 396 | - $this->_title = $this->createTitleTag(); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - public function createMetaTags() |
|
| 400 | - { |
|
| 401 | - global $xoopsTpl, $xoTheme; |
|
| 402 | - |
|
| 403 | - if (is_object($xoTheme)) { |
|
| 404 | - $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
| 405 | - $xoTheme->addMeta('meta', 'description', $this->_description); |
|
| 406 | - $xoTheme->addMeta('meta', 'title', $this->_title); |
|
| 407 | - } else { |
|
| 408 | - $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
| 409 | - $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
| 410 | - } |
|
| 411 | - $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
| 412 | - } |
|
| 374 | + // Only take the first 90 keywords |
|
| 375 | + $newKeywords = []; |
|
| 376 | + $i = 0; |
|
| 377 | + while ($i < 90 - 1 && isset($keywords[$i])) { |
|
| 378 | + $newKeywords[] = $keywords[$i]; |
|
| 379 | + ++$i; |
|
| 380 | + } |
|
| 381 | + $ret = implode(', ', $newKeywords); |
|
| 382 | + |
|
| 383 | + return $ret; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + public function autoBuildMeta_keywords() |
|
| 387 | + { |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + public function buildAutoMetaTags() |
|
| 391 | + { |
|
| 392 | + global $xoopsModule, $xoopsModuleConfig; |
|
| 393 | + |
|
| 394 | + $this->_keywords = $this->createMetaKeywords(); |
|
| 395 | + $this->_meta_description = $this->createMetaDescription(); |
|
| 396 | + $this->_title = $this->createTitleTag(); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + public function createMetaTags() |
|
| 400 | + { |
|
| 401 | + global $xoopsTpl, $xoTheme; |
|
| 402 | + |
|
| 403 | + if (is_object($xoTheme)) { |
|
| 404 | + $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
| 405 | + $xoTheme->addMeta('meta', 'description', $this->_description); |
|
| 406 | + $xoTheme->addMeta('meta', 'title', $this->_title); |
|
| 407 | + } else { |
|
| 408 | + $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
| 409 | + $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
| 410 | + } |
|
| 411 | + $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
| 412 | + } |
|
| 413 | 413 | } |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | * @access public |
| 62 | 62 | * @param string $key key of the object's variable to be returned |
| 63 | 63 | * @param string $format format to use for the output |
| 64 | - * @return mixed formatted value of the variable |
|
| 64 | + * @return integer formatted value of the variable |
|
| 65 | 65 | */ |
| 66 | 66 | public function getVar($key, $format = 's') |
| 67 | 67 | { |
@@ -35,154 +35,154 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class SmartobjectLink extends SmartObject |
| 37 | 37 | { |
| 38 | - /** |
|
| 39 | - * SmartobjectLink constructor. |
|
| 40 | - */ |
|
| 41 | - public function __construct() |
|
| 42 | - { |
|
| 43 | - $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
| 44 | - $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
| 45 | - $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
| 46 | - $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
| 47 | - $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
| 48 | - $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
| 49 | - $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
| 50 | - $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
| 51 | - $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
| 52 | - $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
| 53 | - $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
| 54 | - $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
| 55 | - $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * returns a specific variable for the object in a proper format |
|
| 60 | - * |
|
| 61 | - * @access public |
|
| 62 | - * @param string $key key of the object's variable to be returned |
|
| 63 | - * @param string $format format to use for the output |
|
| 64 | - * @return mixed formatted value of the variable |
|
| 65 | - */ |
|
| 66 | - public function getVar($key, $format = 's') |
|
| 67 | - { |
|
| 68 | - if ($format === 's' && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
| 69 | - // return call_user_func(array($this, $key)); |
|
| 70 | - return $this->{$key}(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return parent::getVar($key, $format); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public function from_uid() |
|
| 80 | - { |
|
| 81 | - $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
| 82 | - |
|
| 83 | - return $ret; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param bool $withContact |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function to_uid($withContact = false) |
|
| 91 | - { |
|
| 92 | - $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
| 93 | - |
|
| 94 | - return $ret; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function date() |
|
| 101 | - { |
|
| 102 | - $ret = formatTimestamp($this->getVar('date', 'e')); |
|
| 103 | - |
|
| 104 | - return $ret; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param bool $full |
|
| 109 | - * @return mixed|string |
|
| 110 | - */ |
|
| 111 | - public function link($full = false) |
|
| 112 | - { |
|
| 113 | - $ret = $this->getVar('link', 'e'); |
|
| 114 | - if ($full) { |
|
| 115 | - $myts = MyTextSanitizer::getInstance(); |
|
| 116 | - $ret = $myts->displayTarea($ret); |
|
| 117 | - |
|
| 118 | - return $ret; |
|
| 119 | - } else { |
|
| 120 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 121 | - |
|
| 122 | - return $ret; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function getViewItemLink() |
|
| 130 | - { |
|
| 131 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
| 132 | - |
|
| 133 | - return $ret; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - public function getFromInfo() |
|
| 140 | - { |
|
| 141 | - // check if from_uid represent a user |
|
| 142 | - |
|
| 143 | - if ($this->getVar('from_uid')) { |
|
| 144 | - $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
| 145 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 146 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $user; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @return array |
|
| 157 | - */ |
|
| 158 | - public function toArray() |
|
| 159 | - { |
|
| 160 | - $ret = parent::toArray(); |
|
| 161 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
| 162 | - $ret['toInfo'] = $this->getToInfo(); |
|
| 163 | - $ret['fullLink'] = $this->link(true); |
|
| 164 | - |
|
| 165 | - return $ret; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 171 | - public function getToInfo() |
|
| 172 | - { |
|
| 173 | - // check if from_uid represent a user |
|
| 174 | - |
|
| 175 | - if ($this->getVar('to_uid')) { |
|
| 176 | - $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
| 177 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 178 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 179 | - } |
|
| 180 | - } else { |
|
| 181 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $user; |
|
| 185 | - } |
|
| 38 | + /** |
|
| 39 | + * SmartobjectLink constructor. |
|
| 40 | + */ |
|
| 41 | + public function __construct() |
|
| 42 | + { |
|
| 43 | + $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
| 44 | + $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
| 45 | + $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
| 46 | + $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
| 47 | + $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
| 48 | + $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
| 49 | + $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
| 50 | + $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
| 51 | + $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
| 52 | + $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
| 53 | + $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
| 54 | + $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
| 55 | + $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * returns a specific variable for the object in a proper format |
|
| 60 | + * |
|
| 61 | + * @access public |
|
| 62 | + * @param string $key key of the object's variable to be returned |
|
| 63 | + * @param string $format format to use for the output |
|
| 64 | + * @return mixed formatted value of the variable |
|
| 65 | + */ |
|
| 66 | + public function getVar($key, $format = 's') |
|
| 67 | + { |
|
| 68 | + if ($format === 's' && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
| 69 | + // return call_user_func(array($this, $key)); |
|
| 70 | + return $this->{$key}(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return parent::getVar($key, $format); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public function from_uid() |
|
| 80 | + { |
|
| 81 | + $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
| 82 | + |
|
| 83 | + return $ret; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param bool $withContact |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function to_uid($withContact = false) |
|
| 91 | + { |
|
| 92 | + $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
| 93 | + |
|
| 94 | + return $ret; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function date() |
|
| 101 | + { |
|
| 102 | + $ret = formatTimestamp($this->getVar('date', 'e')); |
|
| 103 | + |
|
| 104 | + return $ret; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param bool $full |
|
| 109 | + * @return mixed|string |
|
| 110 | + */ |
|
| 111 | + public function link($full = false) |
|
| 112 | + { |
|
| 113 | + $ret = $this->getVar('link', 'e'); |
|
| 114 | + if ($full) { |
|
| 115 | + $myts = MyTextSanitizer::getInstance(); |
|
| 116 | + $ret = $myts->displayTarea($ret); |
|
| 117 | + |
|
| 118 | + return $ret; |
|
| 119 | + } else { |
|
| 120 | + $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 121 | + |
|
| 122 | + return $ret; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function getViewItemLink() |
|
| 130 | + { |
|
| 131 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
| 132 | + |
|
| 133 | + return $ret; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + public function getFromInfo() |
|
| 140 | + { |
|
| 141 | + // check if from_uid represent a user |
|
| 142 | + |
|
| 143 | + if ($this->getVar('from_uid')) { |
|
| 144 | + $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
| 145 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 146 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $user; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @return array |
|
| 157 | + */ |
|
| 158 | + public function toArray() |
|
| 159 | + { |
|
| 160 | + $ret = parent::toArray(); |
|
| 161 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
| 162 | + $ret['toInfo'] = $this->getToInfo(); |
|
| 163 | + $ret['fullLink'] = $this->link(true); |
|
| 164 | + |
|
| 165 | + return $ret; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | + public function getToInfo() |
|
| 172 | + { |
|
| 173 | + // check if from_uid represent a user |
|
| 174 | + |
|
| 175 | + if ($this->getVar('to_uid')) { |
|
| 176 | + $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
| 177 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 178 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 179 | + } |
|
| 180 | + } else { |
|
| 181 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $user; |
|
| 185 | + } |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | class SmartobjectLinkHandler extends SmartPersistableObjectHandler |
| 192 | 192 | { |
| 193 | - /** |
|
| 194 | - * SmartobjectLinkHandler constructor. |
|
| 195 | - * @param XoopsDatabase $db |
|
| 196 | - */ |
|
| 197 | - public function __construct(XoopsDatabase $db) |
|
| 198 | - { |
|
| 199 | - parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
| 200 | - } |
|
| 193 | + /** |
|
| 194 | + * SmartobjectLinkHandler constructor. |
|
| 195 | + * @param XoopsDatabase $db |
|
| 196 | + */ |
|
| 197 | + public function __construct(XoopsDatabase $db) |
|
| 198 | + { |
|
| 199 | + parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
| 200 | + } |
|
| 201 | 201 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | // -------------------------------------------------------------------------// |
| 29 | 29 | |
| 30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
| 31 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
| 31 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Class SmartobjectLink |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | return $ret; |
| 119 | 119 | } else { |
| 120 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 120 | + $ret = '<a href="'.$ret.'" alt="'.$this->getVar('link', 'e').'" title="'.$this->getVar('link', 'e').'">'._AM_SOBJECT_SENT_LINKS_GOTO.'</a>'; |
|
| 121 | 121 | |
| 122 | 122 | return $ret; |
| 123 | 123 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function getViewItemLink() |
| 130 | 130 | { |
| 131 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
| 131 | + $ret = '<a href="'.SMARTOBJECT_URL.'admin/link.php?op=view&linkid='.$this->getVar('linkid').'"><img src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'mail_find.png" alt="'._AM_SOBJECT_SENT_LINK_VIEW.'" title="'._AM_SOBJECT_SENT_LINK_VIEW.'"></a>'; |
|
| 132 | 132 | |
| 133 | 133 | return $ret; |
| 134 | 134 | } |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | if ($this->getVar('from_uid')) { |
| 144 | 144 | $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
| 145 | 145 | if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
| 146 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 146 | + $user = '<a href="mailto:'.$this->getVar('from_email').'">'.$this->getVar('from_email').'</a>'; |
|
| 147 | 147 | } |
| 148 | 148 | } else { |
| 149 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 149 | + $user = '<a href="mailto:'.$this->getVar('from_email').'">'.$this->getVar('from_email').'</a>'; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return $user; |
@@ -175,10 +175,10 @@ discard block |
||
| 175 | 175 | if ($this->getVar('to_uid')) { |
| 176 | 176 | $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
| 177 | 177 | if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
| 178 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 178 | + $user = '<a href="mailto:'.$this->getVar('to_email').'">'.$this->getVar('to_email').'</a>'; |
|
| 179 | 179 | } |
| 180 | 180 | } else { |
| 181 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 181 | + $user = '<a href="mailto:'.$this->getVar('to_email').'">'.$this->getVar('to_email').'</a>'; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | return $user; |