@@ -46,227 +46,227 @@ |
||
46 | 46 | */ |
47 | 47 | class SmartobjectMemberHandler extends XoopsMemberHandler |
48 | 48 | { |
49 | - /** |
|
50 | - * constructor |
|
51 | - * @param XoopsDatabase $db |
|
52 | - */ |
|
53 | - public function __construct(XoopsDatabase $db) |
|
54 | - { |
|
55 | - parent::__construct($db); |
|
56 | - $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
57 | - } |
|
49 | + /** |
|
50 | + * constructor |
|
51 | + * @param XoopsDatabase $db |
|
52 | + */ |
|
53 | + public function __construct(XoopsDatabase $db) |
|
54 | + { |
|
55 | + parent::__construct($db); |
|
56 | + $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param $userObj |
|
61 | - * @param bool $groups |
|
62 | - * @param bool $notifyUser |
|
63 | - * @param bool $password |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
67 | - { |
|
68 | - $email = $userObj->getVar('email'); |
|
69 | - if (!$userObj->getVar('email') || $email === '') { |
|
70 | - $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
59 | + /** |
|
60 | + * @param $userObj |
|
61 | + * @param bool $groups |
|
62 | + * @param bool $notifyUser |
|
63 | + * @param bool $password |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
67 | + { |
|
68 | + $email = $userObj->getVar('email'); |
|
69 | + if (!$userObj->getVar('email') || $email === '') { |
|
70 | + $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
71 | 71 | |
72 | - return false; |
|
73 | - } |
|
72 | + return false; |
|
73 | + } |
|
74 | 74 | |
75 | - $password = $userObj->getVar('pass'); |
|
76 | - // randomly generating the password if not already set |
|
77 | - if ('' === $password) { |
|
78 | - $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
79 | - } |
|
80 | - $userObj->setVar('pass', md5($password)); |
|
75 | + $password = $userObj->getVar('pass'); |
|
76 | + // randomly generating the password if not already set |
|
77 | + if ('' === $password) { |
|
78 | + $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
79 | + } |
|
80 | + $userObj->setVar('pass', md5($password)); |
|
81 | 81 | |
82 | - // if no username is set, let's generate one |
|
83 | - $unamecount = 20; |
|
84 | - $uname = $userObj->getVar('uname'); |
|
85 | - if (!$uname || $uname === '') { |
|
86 | - $usernames = $this->genUserNames($email, $unamecount); |
|
87 | - $newuser = false; |
|
88 | - $i = 0; |
|
89 | - while ($newuser === false) { |
|
90 | - $crit = new Criteria('uname', $usernames[$i]); |
|
91 | - $count = $this->getUserCount($crit); |
|
92 | - if ($count == 0) { |
|
93 | - $newuser = true; |
|
94 | - } else { |
|
95 | - //Move to next username |
|
96 | - ++$i; |
|
97 | - if ($i == $unamecount) { |
|
98 | - //Get next batch of usernames to try, reset counter |
|
99 | - $usernames = $this->genUserNames($email, $unamecount); |
|
100 | - $i = 0; |
|
101 | - } |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
82 | + // if no username is set, let's generate one |
|
83 | + $unamecount = 20; |
|
84 | + $uname = $userObj->getVar('uname'); |
|
85 | + if (!$uname || $uname === '') { |
|
86 | + $usernames = $this->genUserNames($email, $unamecount); |
|
87 | + $newuser = false; |
|
88 | + $i = 0; |
|
89 | + while ($newuser === false) { |
|
90 | + $crit = new Criteria('uname', $usernames[$i]); |
|
91 | + $count = $this->getUserCount($crit); |
|
92 | + if ($count == 0) { |
|
93 | + $newuser = true; |
|
94 | + } else { |
|
95 | + //Move to next username |
|
96 | + ++$i; |
|
97 | + if ($i == $unamecount) { |
|
98 | + //Get next batch of usernames to try, reset counter |
|
99 | + $usernames = $this->genUserNames($email, $unamecount); |
|
100 | + $i = 0; |
|
101 | + } |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - global $xoopsConfig; |
|
106 | + global $xoopsConfig; |
|
107 | 107 | |
108 | - $configHandler = xoops_getHandler('config'); |
|
109 | - $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
110 | - switch ($xoopsConfigUser['activation_type']) { |
|
111 | - case 0: |
|
112 | - $level = 0; |
|
113 | - $mailtemplate = 'smartmail_activate_user.tpl'; |
|
114 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
115 | - break; |
|
116 | - case 1: |
|
117 | - $level = 1; |
|
118 | - $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
119 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
120 | - break; |
|
121 | - case 2: |
|
122 | - default: |
|
123 | - $level = 0; |
|
124 | - $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
125 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
126 | - } |
|
108 | + $configHandler = xoops_getHandler('config'); |
|
109 | + $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
110 | + switch ($xoopsConfigUser['activation_type']) { |
|
111 | + case 0: |
|
112 | + $level = 0; |
|
113 | + $mailtemplate = 'smartmail_activate_user.tpl'; |
|
114 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
115 | + break; |
|
116 | + case 1: |
|
117 | + $level = 1; |
|
118 | + $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
119 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
120 | + break; |
|
121 | + case 2: |
|
122 | + default: |
|
123 | + $level = 0; |
|
124 | + $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
125 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
126 | + } |
|
127 | 127 | |
128 | - $userObj->setVar('uname', $usernames[$i]); |
|
129 | - $userObj->setVar('user_avatar', 'blank.gif'); |
|
130 | - $userObj->setVar('user_regdate', time()); |
|
131 | - $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
132 | - $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
133 | - $userObj->setVar('actkey', $actkey); |
|
134 | - $userObj->setVar('email', $email); |
|
135 | - $userObj->setVar('notify_method', 2); |
|
136 | - $userObj->setVar('level', $userObj); |
|
128 | + $userObj->setVar('uname', $usernames[$i]); |
|
129 | + $userObj->setVar('user_avatar', 'blank.gif'); |
|
130 | + $userObj->setVar('user_regdate', time()); |
|
131 | + $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
132 | + $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
133 | + $userObj->setVar('actkey', $actkey); |
|
134 | + $userObj->setVar('email', $email); |
|
135 | + $userObj->setVar('notify_method', 2); |
|
136 | + $userObj->setVar('level', $userObj); |
|
137 | 137 | |
138 | - if ($this->insertUser($userObj)) { |
|
138 | + if ($this->insertUser($userObj)) { |
|
139 | 139 | |
140 | - // if $groups=false, Add the user to Registered Users group |
|
141 | - if (!$groups) { |
|
142 | - $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
143 | - } else { |
|
144 | - foreach ($groups as $groupid) { |
|
145 | - $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
146 | - } |
|
147 | - } |
|
148 | - } else { |
|
149 | - return false; |
|
150 | - } |
|
140 | + // if $groups=false, Add the user to Registered Users group |
|
141 | + if (!$groups) { |
|
142 | + $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
143 | + } else { |
|
144 | + foreach ($groups as $groupid) { |
|
145 | + $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
146 | + } |
|
147 | + } |
|
148 | + } else { |
|
149 | + return false; |
|
150 | + } |
|
151 | 151 | |
152 | - if ($notifyUser) { |
|
153 | - // send some notifications |
|
154 | - $xoopsMailer =& getMailer(); |
|
155 | - $xoopsMailer->useMail(); |
|
156 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
157 | - $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
158 | - $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
159 | - $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
160 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
161 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
162 | - $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
163 | - $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
164 | - $xoopsMailer->setToUsers($userObj); |
|
165 | - $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
166 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
167 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
152 | + if ($notifyUser) { |
|
153 | + // send some notifications |
|
154 | + $xoopsMailer =& getMailer(); |
|
155 | + $xoopsMailer->useMail(); |
|
156 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
157 | + $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
158 | + $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
159 | + $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
160 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
161 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
162 | + $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
163 | + $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
164 | + $xoopsMailer->setToUsers($userObj); |
|
165 | + $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
166 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
167 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
168 | 168 | |
169 | - if (!$xoopsMailer->send(true)) { |
|
170 | - /** |
|
171 | - * @todo trap error if email was not sent |
|
172 | - */ |
|
173 | - $xoopsMailer->getErrors(true); |
|
174 | - } |
|
175 | - } |
|
169 | + if (!$xoopsMailer->send(true)) { |
|
170 | + /** |
|
171 | + * @todo trap error if email was not sent |
|
172 | + */ |
|
173 | + $xoopsMailer->getErrors(true); |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | - return true; |
|
178 | - } |
|
177 | + return true; |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Generates an array of usernames |
|
182 | - * |
|
183 | - * @param string $email email of user |
|
184 | - * @param int $count number of names to generate |
|
185 | - * @return array $names |
|
186 | - * @internal param string $name name of user |
|
187 | - * @author xHelp Team |
|
188 | - * |
|
189 | - * @access public |
|
190 | - */ |
|
191 | - public function genUserNames($email, $count = 20) |
|
192 | - { |
|
193 | - $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
180 | + /** |
|
181 | + * Generates an array of usernames |
|
182 | + * |
|
183 | + * @param string $email email of user |
|
184 | + * @param int $count number of names to generate |
|
185 | + * @return array $names |
|
186 | + * @internal param string $name name of user |
|
187 | + * @author xHelp Team |
|
188 | + * |
|
189 | + * @access public |
|
190 | + */ |
|
191 | + public function genUserNames($email, $count = 20) |
|
192 | + { |
|
193 | + $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
194 | 194 | |
195 | - $names = array(); |
|
196 | - $userid = explode('@', $email); |
|
195 | + $names = array(); |
|
196 | + $userid = explode('@', $email); |
|
197 | 197 | |
198 | - $basename = ''; |
|
199 | - $hasbasename = false; |
|
200 | - $emailname = $userid[0]; |
|
198 | + $basename = ''; |
|
199 | + $hasbasename = false; |
|
200 | + $emailname = $userid[0]; |
|
201 | 201 | |
202 | - $names[] = $emailname; |
|
202 | + $names[] = $emailname; |
|
203 | 203 | |
204 | - if (strlen($name) > 0) { |
|
205 | - $name = explode(' ', trim($name)); |
|
206 | - if (count($name) > 1) { |
|
207 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
208 | - } else { |
|
209 | - $basename = strtolower($name[0]); |
|
210 | - } |
|
211 | - $basename = xoops_substr($basename, 0, 60, ''); |
|
212 | - //Prevent Duplication of Email Username and Name |
|
213 | - if (!in_array($basename, $names)) { |
|
214 | - $names[] = $basename; |
|
215 | - $hasbasename = true; |
|
216 | - } |
|
217 | - } |
|
204 | + if (strlen($name) > 0) { |
|
205 | + $name = explode(' ', trim($name)); |
|
206 | + if (count($name) > 1) { |
|
207 | + $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
208 | + } else { |
|
209 | + $basename = strtolower($name[0]); |
|
210 | + } |
|
211 | + $basename = xoops_substr($basename, 0, 60, ''); |
|
212 | + //Prevent Duplication of Email Username and Name |
|
213 | + if (!in_array($basename, $names)) { |
|
214 | + $names[] = $basename; |
|
215 | + $hasbasename = true; |
|
216 | + } |
|
217 | + } |
|
218 | 218 | |
219 | - $i = count($names); |
|
220 | - $onbasename = 1; |
|
221 | - while ($i < $count) { |
|
222 | - $num = $this->genRandNumber(); |
|
223 | - if ($onbasename < 0 && $hasbasename) { |
|
224 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
225 | - } else { |
|
226 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
227 | - } |
|
228 | - $i = count($names); |
|
229 | - $onbasename = ~$onbasename; |
|
230 | - $num = ''; |
|
231 | - } |
|
219 | + $i = count($names); |
|
220 | + $onbasename = 1; |
|
221 | + while ($i < $count) { |
|
222 | + $num = $this->genRandNumber(); |
|
223 | + if ($onbasename < 0 && $hasbasename) { |
|
224 | + $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
225 | + } else { |
|
226 | + $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
227 | + } |
|
228 | + $i = count($names); |
|
229 | + $onbasename = ~$onbasename; |
|
230 | + $num = ''; |
|
231 | + } |
|
232 | 232 | |
233 | - return $names; |
|
234 | - } |
|
233 | + return $names; |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Creates a random number with a specified number of $digits |
|
238 | - * |
|
239 | - * @param int $digits number of digits |
|
240 | - * @return return int random number |
|
241 | - * @author xHelp Team |
|
242 | - * |
|
243 | - * @access public |
|
244 | - */ |
|
245 | - public function genRandNumber($digits = 2) |
|
246 | - { |
|
247 | - $this->initRand(); |
|
248 | - $tmp = array(); |
|
236 | + /** |
|
237 | + * Creates a random number with a specified number of $digits |
|
238 | + * |
|
239 | + * @param int $digits number of digits |
|
240 | + * @return return int random number |
|
241 | + * @author xHelp Team |
|
242 | + * |
|
243 | + * @access public |
|
244 | + */ |
|
245 | + public function genRandNumber($digits = 2) |
|
246 | + { |
|
247 | + $this->initRand(); |
|
248 | + $tmp = array(); |
|
249 | 249 | |
250 | - for ($i = 0; $i < $digits; ++$i) { |
|
251 | - $tmp[$i] = (mt_rand() % 9); |
|
252 | - } |
|
250 | + for ($i = 0; $i < $digits; ++$i) { |
|
251 | + $tmp[$i] = (mt_rand() % 9); |
|
252 | + } |
|
253 | 253 | |
254 | - return implode('', $tmp); |
|
255 | - } |
|
254 | + return implode('', $tmp); |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Gives the random number generator a seed to start from |
|
259 | - * |
|
260 | - * @return void |
|
261 | - * |
|
262 | - * @access public |
|
263 | - */ |
|
264 | - public function initRand() |
|
265 | - { |
|
266 | - static $randCalled = false; |
|
267 | - if (!$randCalled) { |
|
268 | - mt_srand((double)microtime() * 1000000); |
|
269 | - $randCalled = true; |
|
270 | - } |
|
271 | - } |
|
257 | + /** |
|
258 | + * Gives the random number generator a seed to start from |
|
259 | + * |
|
260 | + * @return void |
|
261 | + * |
|
262 | + * @access public |
|
263 | + */ |
|
264 | + public function initRand() |
|
265 | + { |
|
266 | + static $randCalled = false; |
|
267 | + if (!$randCalled) { |
|
268 | + mt_srand((double)microtime() * 1000000); |
|
269 | + $randCalled = true; |
|
270 | + } |
|
271 | + } |
|
272 | 272 | } |
@@ -24,82 +24,82 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class SmartMlObject extends SmartObject |
26 | 26 | { |
27 | - /** |
|
28 | - * SmartMlObject constructor. |
|
29 | - */ |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true); |
|
33 | - $this->setControl('language', 'language'); |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * If object is not new, change the control of the not-multilanguage fields |
|
38 | - * |
|
39 | - * We need to intercept this function from SmartObject because if the object is not new... |
|
40 | - */ |
|
41 | - // function getForm() { |
|
42 | - |
|
43 | - //} |
|
44 | - |
|
45 | - /** |
|
46 | - * Strip Multilanguage Fields |
|
47 | - * |
|
48 | - * Get rid of all the multilanguage fields to have an object with only global fields. |
|
49 | - * This will be usefull when creating the ML object for the first time. Then we will be able |
|
50 | - * to create translations. |
|
51 | - */ |
|
52 | - public function stripMultilanguageFields() |
|
53 | - { |
|
54 | - $objectVars =& $this->getVars(); |
|
55 | - $newObjectVars = array(); |
|
56 | - foreach ($objectVars as $key => $var) { |
|
57 | - if (!$var['multilingual']) { |
|
58 | - $newObjectVars[$key] = $var; |
|
59 | - } |
|
60 | - } |
|
61 | - $this->vars = $newObjectVars; |
|
62 | - } |
|
63 | - |
|
64 | - public function stripNonMultilanguageFields() |
|
65 | - { |
|
66 | - $objectVars =& $this->getVars(); |
|
67 | - $newObjectVars = array(); |
|
68 | - foreach ($objectVars as $key => $var) { |
|
69 | - if ($var['multilingual'] || $key == $this->handler->keyName) { |
|
70 | - $newObjectVars[$key] = $var; |
|
71 | - } |
|
72 | - } |
|
73 | - $this->vars = $newObjectVars; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Make non multilanguage fields read only |
|
78 | - * |
|
79 | - * This is used when we are creating/editing a translation. |
|
80 | - * We only want to edit the multilanguag fields, not the global one. |
|
81 | - */ |
|
82 | - public function makeNonMLFieldReadOnly() |
|
83 | - { |
|
84 | - foreach ($this->getVars() as $key => $var) { |
|
85 | - //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) { |
|
86 | - if (!$var['multilingual'] && $key != $this->handler->keyName) { |
|
87 | - $this->setControl($key, 'label'); |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param bool $onlyUrl |
|
94 | - * @param bool $withimage |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
|
98 | - { |
|
99 | - $controller = new SmartObjectController($this->handler); |
|
100 | - |
|
101 | - return $controller->getEditLanguageLink($this, $onlyUrl, $withimage); |
|
102 | - } |
|
27 | + /** |
|
28 | + * SmartMlObject constructor. |
|
29 | + */ |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true); |
|
33 | + $this->setControl('language', 'language'); |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * If object is not new, change the control of the not-multilanguage fields |
|
38 | + * |
|
39 | + * We need to intercept this function from SmartObject because if the object is not new... |
|
40 | + */ |
|
41 | + // function getForm() { |
|
42 | + |
|
43 | + //} |
|
44 | + |
|
45 | + /** |
|
46 | + * Strip Multilanguage Fields |
|
47 | + * |
|
48 | + * Get rid of all the multilanguage fields to have an object with only global fields. |
|
49 | + * This will be usefull when creating the ML object for the first time. Then we will be able |
|
50 | + * to create translations. |
|
51 | + */ |
|
52 | + public function stripMultilanguageFields() |
|
53 | + { |
|
54 | + $objectVars =& $this->getVars(); |
|
55 | + $newObjectVars = array(); |
|
56 | + foreach ($objectVars as $key => $var) { |
|
57 | + if (!$var['multilingual']) { |
|
58 | + $newObjectVars[$key] = $var; |
|
59 | + } |
|
60 | + } |
|
61 | + $this->vars = $newObjectVars; |
|
62 | + } |
|
63 | + |
|
64 | + public function stripNonMultilanguageFields() |
|
65 | + { |
|
66 | + $objectVars =& $this->getVars(); |
|
67 | + $newObjectVars = array(); |
|
68 | + foreach ($objectVars as $key => $var) { |
|
69 | + if ($var['multilingual'] || $key == $this->handler->keyName) { |
|
70 | + $newObjectVars[$key] = $var; |
|
71 | + } |
|
72 | + } |
|
73 | + $this->vars = $newObjectVars; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Make non multilanguage fields read only |
|
78 | + * |
|
79 | + * This is used when we are creating/editing a translation. |
|
80 | + * We only want to edit the multilanguag fields, not the global one. |
|
81 | + */ |
|
82 | + public function makeNonMLFieldReadOnly() |
|
83 | + { |
|
84 | + foreach ($this->getVars() as $key => $var) { |
|
85 | + //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) { |
|
86 | + if (!$var['multilingual'] && $key != $this->handler->keyName) { |
|
87 | + $this->setControl($key, 'label'); |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param bool $onlyUrl |
|
94 | + * @param bool $withimage |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
|
98 | + { |
|
99 | + $controller = new SmartObjectController($this->handler); |
|
100 | + |
|
101 | + return $controller->getEditLanguageLink($this, $onlyUrl, $withimage); |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,70 +107,70 @@ discard block |
||
107 | 107 | */ |
108 | 108 | class SmartPersistableMlObjectHandler extends SmartPersistableObjectHandler |
109 | 109 | { |
110 | - /** |
|
111 | - * @param null $criteria |
|
112 | - * @param bool $id_as_key |
|
113 | - * @param bool $as_object |
|
114 | - * @param bool $debug |
|
115 | - * @param bool $language |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $debug = false, $language = false) |
|
119 | - { |
|
120 | - // Create the first part of the SQL query to join the "_text" table |
|
121 | - $sql = 'SELECT * FROM ' . |
|
122 | - $this->table . |
|
123 | - ' AS ' . |
|
124 | - $this->_itemname . |
|
125 | - ' INNER JOIN ' . |
|
126 | - $this->table . |
|
127 | - '_text AS ' . |
|
128 | - $this->_itemname . |
|
129 | - '_text ON ' . |
|
130 | - $this->_itemname . |
|
131 | - '.' . |
|
132 | - $this->keyName . |
|
133 | - '=' . |
|
134 | - $this->_itemname . |
|
135 | - '_text.' . |
|
136 | - $this->keyName; |
|
137 | - |
|
138 | - if ($language) { |
|
139 | - // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
140 | - |
|
141 | - // if no criteria was previously created, let's create it |
|
142 | - if (!$criteria) { |
|
143 | - $criteria = new CriteriaCompo(); |
|
144 | - } |
|
145 | - $criteria->add(new Criteria('language', $language)); |
|
146 | - |
|
147 | - return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
148 | - } |
|
149 | - |
|
150 | - return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param mixed $id |
|
155 | - * @param bool $language |
|
156 | - * @param bool $as_object |
|
157 | - * @param bool $debug |
|
158 | - * @return mixed |
|
159 | - */ |
|
160 | - public function &get($id, $language = false, $as_object = true, $debug = false) |
|
161 | - { |
|
162 | - if (!$language) { |
|
163 | - return parent::get($id, $as_object, $debug); |
|
164 | - } else { |
|
165 | - $criteria = new CriteriaCompo(); |
|
166 | - $criteria->add(new Criteria('language', $language)); |
|
167 | - |
|
168 | - return parent::get($id, $as_object, $debug, $criteria); |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - public function changeTableNameForML() |
|
173 | - { |
|
174 | - $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
175 | - } |
|
110 | + /** |
|
111 | + * @param null $criteria |
|
112 | + * @param bool $id_as_key |
|
113 | + * @param bool $as_object |
|
114 | + * @param bool $debug |
|
115 | + * @param bool $language |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $debug = false, $language = false) |
|
119 | + { |
|
120 | + // Create the first part of the SQL query to join the "_text" table |
|
121 | + $sql = 'SELECT * FROM ' . |
|
122 | + $this->table . |
|
123 | + ' AS ' . |
|
124 | + $this->_itemname . |
|
125 | + ' INNER JOIN ' . |
|
126 | + $this->table . |
|
127 | + '_text AS ' . |
|
128 | + $this->_itemname . |
|
129 | + '_text ON ' . |
|
130 | + $this->_itemname . |
|
131 | + '.' . |
|
132 | + $this->keyName . |
|
133 | + '=' . |
|
134 | + $this->_itemname . |
|
135 | + '_text.' . |
|
136 | + $this->keyName; |
|
137 | + |
|
138 | + if ($language) { |
|
139 | + // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
140 | + |
|
141 | + // if no criteria was previously created, let's create it |
|
142 | + if (!$criteria) { |
|
143 | + $criteria = new CriteriaCompo(); |
|
144 | + } |
|
145 | + $criteria->add(new Criteria('language', $language)); |
|
146 | + |
|
147 | + return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
148 | + } |
|
149 | + |
|
150 | + return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param mixed $id |
|
155 | + * @param bool $language |
|
156 | + * @param bool $as_object |
|
157 | + * @param bool $debug |
|
158 | + * @return mixed |
|
159 | + */ |
|
160 | + public function &get($id, $language = false, $as_object = true, $debug = false) |
|
161 | + { |
|
162 | + if (!$language) { |
|
163 | + return parent::get($id, $as_object, $debug); |
|
164 | + } else { |
|
165 | + $criteria = new CriteriaCompo(); |
|
166 | + $criteria->add(new Criteria('language', $language)); |
|
167 | + |
|
168 | + return parent::get($id, $as_object, $debug, $criteria); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + public function changeTableNameForML() |
|
173 | + { |
|
174 | + $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
175 | + } |
|
176 | 176 | } |
@@ -8,14 +8,14 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class SmartobjectFile extends SmartobjectBasedUrl |
10 | 10 | { |
11 | - /** |
|
12 | - * SmartobjectFile constructor. |
|
13 | - */ |
|
14 | - public function __construct() |
|
15 | - { |
|
16 | - parent::__construct(); |
|
17 | - $this->quickInitVar('fileid', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
18 | - } |
|
11 | + /** |
|
12 | + * SmartobjectFile constructor. |
|
13 | + */ |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + parent::__construct(); |
|
17 | + $this->quickInitVar('fileid', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
18 | + } |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class SmartobjectFileHandler extends SmartPersistableObjectHandler |
25 | 25 | { |
26 | - /** |
|
27 | - * SmartobjectFileHandler constructor. |
|
28 | - * @param XoopsDatabase $db |
|
29 | - */ |
|
30 | - public function __construct(XoopsDatabase $db) |
|
31 | - { |
|
32 | - parent::__construct($db, 'file', 'fileid', 'caption', 'desc', 'smartobject'); |
|
33 | - } |
|
26 | + /** |
|
27 | + * SmartobjectFileHandler constructor. |
|
28 | + * @param XoopsDatabase $db |
|
29 | + */ |
|
30 | + public function __construct(XoopsDatabase $db) |
|
31 | + { |
|
32 | + parent::__construct($db, 'file', 'fileid', 'caption', 'desc', 'smartobject'); |
|
33 | + } |
|
34 | 34 | } |
@@ -37,115 +37,115 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class SmartobjectCurrency extends SmartObject |
39 | 39 | { |
40 | - public $_modulePlugin = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * SmartobjectCurrency constructor. |
|
44 | - */ |
|
45 | - public function __construct() |
|
46 | - { |
|
47 | - $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
|
48 | - $this->quickInitVar('iso4217', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_ISO4217, _CO_SOBJECT_CURRENCY_ISO4217_DSC); |
|
49 | - $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_NAME); |
|
50 | - $this->quickInitVar('symbol', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_SYMBOL); |
|
51 | - $this->quickInitVar('rate', XOBJ_DTYPE_FLOAT, true, _CO_SOBJECT_CURRENCY_RATE, '', '1.0'); |
|
52 | - $this->quickInitVar('default_currency', XOBJ_DTYPE_INT, false, _CO_SOBJECT_CURRENCY_DEFAULT, '', false); |
|
53 | - |
|
54 | - $this->setControl('symbol', array( |
|
55 | - 'name' => 'text', |
|
56 | - 'size' => '15', |
|
57 | - 'maxlength' => '15' |
|
58 | - )); |
|
59 | - |
|
60 | - $this->setControl('iso4217', array( |
|
61 | - 'name' => 'text', |
|
62 | - 'size' => '5', |
|
63 | - 'maxlength' => '5' |
|
64 | - )); |
|
65 | - |
|
66 | - $this->setControl('rate', array( |
|
67 | - 'name' => 'text', |
|
68 | - 'size' => '5', |
|
69 | - 'maxlength' => '5' |
|
70 | - )); |
|
71 | - |
|
72 | - $this->setControl('rate', array( |
|
73 | - 'name' => 'text', |
|
74 | - 'size' => '5', |
|
75 | - 'maxlength' => '5' |
|
76 | - )); |
|
77 | - |
|
78 | - $this->hideFieldFromForm('default_currency'); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $key |
|
83 | - * @param string $format |
|
84 | - * @return mixed |
|
85 | - */ |
|
86 | - public function getVar($key, $format = 's') |
|
87 | - { |
|
88 | - if ($format === 's' && in_array($key, array('rate', 'default_currency'))) { |
|
89 | - // return call_user_func(array($this, $key)); |
|
90 | - return $this->{$key}(); |
|
91 | - } |
|
92 | - |
|
93 | - return parent::getVar($key, $format); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return mixed |
|
98 | - */ |
|
99 | - public function getCurrencyLink() |
|
100 | - { |
|
101 | - $ret = $this->getVar('name', 'e'); |
|
102 | - |
|
103 | - return $ret; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @return mixed |
|
108 | - */ |
|
109 | - public function getCode() |
|
110 | - { |
|
111 | - $ret = $this->getVar('iso4217', 'e'); |
|
112 | - |
|
113 | - return $ret; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @return float|int|mixed|string |
|
118 | - */ |
|
119 | - public function rate() |
|
120 | - { |
|
121 | - return smart_currency($this->getVar('rate', 'e')); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function defaultCurrency() |
|
128 | - { |
|
129 | - if ($this->getVar('default_currency', 'e') === true) { |
|
130 | - return _YES; |
|
131 | - } else { |
|
132 | - return _NO; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function getDefaultCurrencyControl() |
|
140 | - { |
|
141 | - $radio_box = '<input name="default_currency" value="' . $this->getVar('currencyid') . '" type="radio"'; |
|
142 | - if ($this->getVar('default_currency', 'e')) { |
|
143 | - $radio_box .= 'checked="checked"'; |
|
144 | - } |
|
145 | - $radio_box .= '>'; |
|
146 | - |
|
147 | - return $radio_box; |
|
148 | - } |
|
40 | + public $_modulePlugin = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * SmartobjectCurrency constructor. |
|
44 | + */ |
|
45 | + public function __construct() |
|
46 | + { |
|
47 | + $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
|
48 | + $this->quickInitVar('iso4217', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_ISO4217, _CO_SOBJECT_CURRENCY_ISO4217_DSC); |
|
49 | + $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_NAME); |
|
50 | + $this->quickInitVar('symbol', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_SYMBOL); |
|
51 | + $this->quickInitVar('rate', XOBJ_DTYPE_FLOAT, true, _CO_SOBJECT_CURRENCY_RATE, '', '1.0'); |
|
52 | + $this->quickInitVar('default_currency', XOBJ_DTYPE_INT, false, _CO_SOBJECT_CURRENCY_DEFAULT, '', false); |
|
53 | + |
|
54 | + $this->setControl('symbol', array( |
|
55 | + 'name' => 'text', |
|
56 | + 'size' => '15', |
|
57 | + 'maxlength' => '15' |
|
58 | + )); |
|
59 | + |
|
60 | + $this->setControl('iso4217', array( |
|
61 | + 'name' => 'text', |
|
62 | + 'size' => '5', |
|
63 | + 'maxlength' => '5' |
|
64 | + )); |
|
65 | + |
|
66 | + $this->setControl('rate', array( |
|
67 | + 'name' => 'text', |
|
68 | + 'size' => '5', |
|
69 | + 'maxlength' => '5' |
|
70 | + )); |
|
71 | + |
|
72 | + $this->setControl('rate', array( |
|
73 | + 'name' => 'text', |
|
74 | + 'size' => '5', |
|
75 | + 'maxlength' => '5' |
|
76 | + )); |
|
77 | + |
|
78 | + $this->hideFieldFromForm('default_currency'); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $key |
|
83 | + * @param string $format |
|
84 | + * @return mixed |
|
85 | + */ |
|
86 | + public function getVar($key, $format = 's') |
|
87 | + { |
|
88 | + if ($format === 's' && in_array($key, array('rate', 'default_currency'))) { |
|
89 | + // return call_user_func(array($this, $key)); |
|
90 | + return $this->{$key}(); |
|
91 | + } |
|
92 | + |
|
93 | + return parent::getVar($key, $format); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return mixed |
|
98 | + */ |
|
99 | + public function getCurrencyLink() |
|
100 | + { |
|
101 | + $ret = $this->getVar('name', 'e'); |
|
102 | + |
|
103 | + return $ret; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @return mixed |
|
108 | + */ |
|
109 | + public function getCode() |
|
110 | + { |
|
111 | + $ret = $this->getVar('iso4217', 'e'); |
|
112 | + |
|
113 | + return $ret; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @return float|int|mixed|string |
|
118 | + */ |
|
119 | + public function rate() |
|
120 | + { |
|
121 | + return smart_currency($this->getVar('rate', 'e')); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function defaultCurrency() |
|
128 | + { |
|
129 | + if ($this->getVar('default_currency', 'e') === true) { |
|
130 | + return _YES; |
|
131 | + } else { |
|
132 | + return _NO; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function getDefaultCurrencyControl() |
|
140 | + { |
|
141 | + $radio_box = '<input name="default_currency" value="' . $this->getVar('currencyid') . '" type="radio"'; |
|
142 | + if ($this->getVar('default_currency', 'e')) { |
|
143 | + $radio_box .= 'checked="checked"'; |
|
144 | + } |
|
145 | + $radio_box .= '>'; |
|
146 | + |
|
147 | + return $radio_box; |
|
148 | + } |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -153,22 +153,22 @@ discard block |
||
153 | 153 | */ |
154 | 154 | class SmartObjectCurrencyHandler extends SmartPersistableObjectHandler |
155 | 155 | { |
156 | - /** |
|
157 | - * SmartObjectCurrencyHandler constructor. |
|
158 | - * @param XoopsDatabase $db |
|
159 | - */ |
|
160 | - public function __construct(XoopsDatabase $db) |
|
161 | - { |
|
162 | - parent::__construct($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - public function getCurrencies() |
|
169 | - { |
|
170 | - $currenciesObj = $this->getObjects(null, true); |
|
171 | - |
|
172 | - return $currenciesObj; |
|
173 | - } |
|
156 | + /** |
|
157 | + * SmartObjectCurrencyHandler constructor. |
|
158 | + * @param XoopsDatabase $db |
|
159 | + */ |
|
160 | + public function __construct(XoopsDatabase $db) |
|
161 | + { |
|
162 | + parent::__construct($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + public function getCurrencies() |
|
169 | + { |
|
170 | + $currenciesObj = $this->getObjects(null, true); |
|
171 | + |
|
172 | + return $currenciesObj; |
|
173 | + } |
|
174 | 174 | } |
@@ -25,970 +25,970 @@ |
||
25 | 25 | */ |
26 | 26 | class SmartPersistableObjectHandler extends XoopsObjectHandler |
27 | 27 | { |
28 | - public $_itemname; |
|
29 | - |
|
30 | - /** |
|
31 | - * Name of the table use to store this {@link SmartObject} |
|
32 | - * |
|
33 | - * Note that the name of the table needs to be free of the database prefix. |
|
34 | - * For example "smartsection_categories" |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - public $table; |
|
38 | - |
|
39 | - /** |
|
40 | - * Name of the table key that uniquely identify each {@link SmartObject} |
|
41 | - * |
|
42 | - * For example: "categoryid" |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $keyName; |
|
46 | - |
|
47 | - /** |
|
48 | - * Name of the class derived from {@link SmartObject} and which this handler is handling |
|
49 | - * |
|
50 | - * Note that this string needs to be lowercase |
|
51 | - * |
|
52 | - * For example: "smartsectioncategory" |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $className; |
|
56 | - |
|
57 | - /** |
|
58 | - * Name of the field which properly identify the {@link SmartObject} |
|
59 | - * |
|
60 | - * For example: "name" (this will be the category's name) |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $identifierName; |
|
64 | - |
|
65 | - /** |
|
66 | - * Name of the field which will be use as a summary for the object |
|
67 | - * |
|
68 | - * For example: "summary" |
|
69 | - * @var string |
|
70 | - */ |
|
71 | - public $summaryName; |
|
72 | - |
|
73 | - /** |
|
74 | - * Page name use to basically manage and display the {@link SmartObject} |
|
75 | - * |
|
76 | - * This page needs to be the same in user side and admin side |
|
77 | - * |
|
78 | - * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php |
|
79 | - * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page |
|
80 | - * @var string |
|
81 | - */ |
|
82 | - public $_page; |
|
83 | - |
|
84 | - /** |
|
85 | - * Full path of the module using this {@link SmartObject} |
|
86 | - * |
|
87 | - * <code>XOOPS_URL . "/modules/smartsection/"</code> |
|
88 | - * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name |
|
89 | - * @var string |
|
90 | - */ |
|
91 | - public $_modulePath; |
|
92 | - |
|
93 | - public $_moduleUrl; |
|
94 | - |
|
95 | - public $_moduleName; |
|
96 | - |
|
97 | - public $_uploadUrl; |
|
98 | - |
|
99 | - public $_uploadPath; |
|
100 | - |
|
101 | - public $_allowedMimeTypes = 0; |
|
102 | - |
|
103 | - public $_maxFileSize = 1000000; |
|
104 | - |
|
105 | - public $_maxWidth = 500; |
|
106 | - |
|
107 | - public $_maxHeight = 500; |
|
108 | - |
|
109 | - public $highlightFields = array(); |
|
110 | - |
|
111 | - /** |
|
112 | - * Array containing the events name and functions |
|
113 | - * |
|
114 | - * @var array |
|
115 | - */ |
|
116 | - public $eventArray = array(); |
|
117 | - |
|
118 | - /** |
|
119 | - * Array containing the permissions that this handler will manage on the objects |
|
120 | - * |
|
121 | - * @var array |
|
122 | - */ |
|
123 | - public $permissionsArray = false; |
|
124 | - |
|
125 | - public $generalSQL = false; |
|
126 | - |
|
127 | - public $_eventHooks = array(); |
|
128 | - public $_disabledEvents = array(); |
|
129 | - |
|
130 | - /** |
|
131 | - * Constructor - called from child classes |
|
132 | - * |
|
133 | - * @param XoopsDatabase $db {@link XoopsDatabase} |
|
134 | - * object |
|
135 | - * @param $itemname |
|
136 | - * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
137 | - * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
138 | - * @param $summaryName |
|
139 | - * @param $modulename |
|
140 | - * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
141 | - * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
142 | - * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
143 | - * @internal param string $moduleName name of the module |
|
144 | - */ |
|
145 | - public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
146 | - { |
|
147 | - parent::__construct($db); |
|
148 | - |
|
149 | - $this->_itemname = $itemname; |
|
150 | - $this->_moduleName = $modulename; |
|
151 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
152 | - $this->keyName = $keyname; |
|
153 | - $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
154 | - $this->identifierName = $idenfierName; |
|
155 | - $this->summaryName = $summaryName; |
|
156 | - $this->_page = $itemname . '.php'; |
|
157 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
158 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
159 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
160 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param $event |
|
165 | - * @param $method |
|
166 | - */ |
|
167 | - public function addEventHook($event, $method) |
|
168 | - { |
|
169 | - $this->_eventHooks[$event] = $method; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Add a permission that this handler will manage for its objects |
|
174 | - * |
|
175 | - * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
176 | - * |
|
177 | - * @param string $perm_name name of the permission |
|
178 | - * @param string $caption caption of the control that will be displayed in the form |
|
179 | - * @param bool|string $description description of the control that will be displayed in the form |
|
180 | - */ |
|
181 | - public function addPermission($perm_name, $caption, $description = false) |
|
182 | - { |
|
183 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'); |
|
184 | - |
|
185 | - $this->permissionsArray[] = array( |
|
186 | - 'perm_name' => $perm_name, |
|
187 | - 'caption' => $caption, |
|
188 | - 'description' => $description |
|
189 | - ); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @param $criteria |
|
194 | - * @param $perm_name |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
|
198 | - { |
|
199 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
200 | - $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
201 | - if (count($grantedItems) > 0) { |
|
202 | - $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
203 | - |
|
204 | - return true; |
|
205 | - } else { |
|
206 | - return false; |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param bool $_uploadPath |
|
212 | - * @param bool $_allowedMimeTypes |
|
213 | - * @param bool $_maxFileSize |
|
214 | - * @param bool $_maxWidth |
|
215 | - * @param bool $_maxHeight |
|
216 | - */ |
|
217 | - public function setUploaderConfig($_uploadPath = false, $_allowedMimeTypes = false, $_maxFileSize = false, $_maxWidth = false, $_maxHeight = false) |
|
218 | - { |
|
219 | - $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
220 | - $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
221 | - $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
222 | - $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
223 | - $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * create a new {@link SmartObject} |
|
228 | - * |
|
229 | - * @param bool $isNew Flag the new objects as "new"? |
|
230 | - * |
|
231 | - * @return SmartObject {@link SmartObject} |
|
232 | - */ |
|
233 | - public function create($isNew = true) |
|
234 | - { |
|
235 | - $obj = new $this->className($this); |
|
236 | - $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
237 | - if (!$obj->handler) { |
|
238 | - $obj->handler =& $this; |
|
239 | - } |
|
240 | - |
|
241 | - if ($isNew === true) { |
|
242 | - $obj->setNew(); |
|
243 | - } |
|
244 | - |
|
245 | - return $obj; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function getImageUrl() |
|
252 | - { |
|
253 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @return string |
|
258 | - */ |
|
259 | - public function getImagePath() |
|
260 | - { |
|
261 | - $dir = $this->_uploadPath . $this->_itemname; |
|
262 | - if (!file_exists($dir)) { |
|
263 | - smart_admin_mkdir($dir); |
|
264 | - } |
|
265 | - |
|
266 | - return $dir . '/'; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * retrieve a {@link SmartObject} |
|
271 | - * |
|
272 | - * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
273 | - * @param bool $as_object whether to return an object or an array |
|
274 | - * @param bool $debug |
|
275 | - * @param bool $criteria |
|
276 | - * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
277 | - * FALSE if failed |
|
278 | - */ |
|
279 | - public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
280 | - { |
|
281 | - if (!$criteria) { |
|
282 | - $criteria = new CriteriaCompo(); |
|
283 | - } |
|
284 | - if (is_array($this->keyName)) { |
|
285 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
286 | - /** |
|
287 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
288 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
289 | - */ |
|
290 | - //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
291 | - $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
292 | - } |
|
293 | - } else { |
|
294 | - //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
295 | - /** |
|
296 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
297 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
298 | - */ |
|
299 | - $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
300 | - } |
|
301 | - $criteria->setLimit(1); |
|
302 | - if ($debug) { |
|
303 | - $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
304 | - } else { |
|
305 | - $obj_array = $this->getObjects($criteria, false, $as_object); |
|
306 | - //patch: weird bug of indexing by id even if id_as_key = false; |
|
307 | - if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
308 | - $obj_array[0] = $obj_array[$id]; |
|
309 | - unset($obj_array[$id]); |
|
310 | - $obj_array[0]->unsetNew(); |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - if (count($obj_array) != 1) { |
|
315 | - $obj = $this->create(); |
|
316 | - |
|
317 | - return $obj; |
|
318 | - } |
|
319 | - |
|
320 | - return $obj_array[0]; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * retrieve a {@link SmartObject} |
|
325 | - * |
|
326 | - * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
327 | - * @param bool $as_object whether to return an object or an array |
|
328 | - * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
329 | - */ |
|
330 | - public function &getD($id, $as_object = true) |
|
331 | - { |
|
332 | - return $this->get($id, $as_object, true); |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * retrieve objects from the database |
|
337 | - * |
|
338 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
339 | - * @param bool $id_as_key use the ID as key for the array? |
|
340 | - * @param bool $as_object return an array of objects? |
|
341 | - * |
|
342 | - * @param bool $sql |
|
343 | - * @param bool $debug |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - public function getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false) |
|
347 | - { |
|
348 | - $ret = array(); |
|
349 | - $limit = $start = 0; |
|
350 | - |
|
351 | - if ($this->generalSQL) { |
|
352 | - $sql = $this->generalSQL; |
|
353 | - } elseif (!$sql) { |
|
354 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
355 | - } |
|
356 | - |
|
357 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
358 | - $sql .= ' ' . $criteria->renderWhere(); |
|
359 | - if ($criteria->getSort() !== '') { |
|
360 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
361 | - } |
|
362 | - $limit = $criteria->getLimit(); |
|
363 | - $start = $criteria->getStart(); |
|
364 | - } |
|
365 | - if ($debug) { |
|
366 | - xoops_debug($sql); |
|
367 | - } |
|
368 | - |
|
369 | - $result = $this->db->query($sql, $limit, $start); |
|
370 | - if (!$result) { |
|
371 | - return $ret; |
|
372 | - } |
|
373 | - |
|
374 | - return $this->convertResultSet($result, $id_as_key, $as_object); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * @param $sql |
|
379 | - * @param $criteria |
|
380 | - * @param bool $force |
|
381 | - * @param bool $debug |
|
382 | - * @return array |
|
383 | - */ |
|
384 | - public function query($sql, $criteria, $force = false, $debug = false) |
|
385 | - { |
|
386 | - $ret = array(); |
|
387 | - |
|
388 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
389 | - $sql .= ' ' . $criteria->renderWhere(); |
|
390 | - if ($criteria->groupby) { |
|
391 | - $sql .= $criteria->getGroupby(); |
|
392 | - } |
|
393 | - if ($criteria->getSort() !== '') { |
|
394 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
395 | - } |
|
396 | - } |
|
397 | - if ($debug) { |
|
398 | - xoops_debug($sql); |
|
399 | - } |
|
400 | - |
|
401 | - if ($force) { |
|
402 | - $result = $this->db->queryF($sql); |
|
403 | - } else { |
|
404 | - $result = $this->db->query($sql); |
|
405 | - } |
|
406 | - |
|
407 | - if (!$result) { |
|
408 | - return $ret; |
|
409 | - } |
|
410 | - |
|
411 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
412 | - $ret[] = $myrow; |
|
413 | - } |
|
414 | - |
|
415 | - return $ret; |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * retrieve objects with debug mode - so will show the query |
|
420 | - * |
|
421 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
422 | - * @param bool $id_as_key use the ID as key for the array? |
|
423 | - * @param bool $as_object return an array of objects? |
|
424 | - * |
|
425 | - * @param bool $sql |
|
426 | - * @return array |
|
427 | - */ |
|
428 | - public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
429 | - { |
|
430 | - return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * @param $arrayObjects |
|
435 | - * @return array|bool |
|
436 | - */ |
|
437 | - public function getObjectsAsArray($arrayObjects) |
|
438 | - { |
|
439 | - $ret = array(); |
|
440 | - foreach ($arrayObjects as $key => $object) { |
|
441 | - $ret[$key] = $object->toArray(); |
|
442 | - } |
|
443 | - if (count($ret > 0)) { |
|
444 | - return $ret; |
|
445 | - } else { |
|
446 | - return false; |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Convert a database resultset to a returnable array |
|
452 | - * |
|
453 | - * @param object $result database resultset |
|
454 | - * @param bool $id_as_key - should NOT be used with joint keys |
|
455 | - * @param bool $as_object |
|
456 | - * |
|
457 | - * @return array |
|
458 | - */ |
|
459 | - public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
460 | - { |
|
461 | - $ret = array(); |
|
462 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
463 | - $obj = $this->create(false); |
|
464 | - $obj->assignVars($myrow); |
|
465 | - if (!$id_as_key) { |
|
466 | - if ($as_object) { |
|
467 | - $ret[] =& $obj; |
|
468 | - } else { |
|
469 | - $ret[] = $obj->toArray(); |
|
470 | - } |
|
471 | - } else { |
|
472 | - if ($as_object) { |
|
473 | - $value =& $obj; |
|
474 | - } else { |
|
475 | - $value = $obj->toArray(); |
|
476 | - } |
|
477 | - if ($id_as_key === 'parentid') { |
|
478 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
479 | - } else { |
|
480 | - $ret[$obj->getVar($this->keyName)] = $value; |
|
481 | - } |
|
482 | - } |
|
483 | - unset($obj); |
|
484 | - } |
|
485 | - |
|
486 | - return $ret; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * @param null $criteria |
|
491 | - * @param int $limit |
|
492 | - * @param int $start |
|
493 | - * @return array |
|
494 | - */ |
|
495 | - public function getListD($criteria = null, $limit = 0, $start = 0) |
|
496 | - { |
|
497 | - return $this->getList($criteria, $limit, $start, true); |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
502 | - * |
|
503 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
504 | - * @param int $limit Max number of objects to fetch |
|
505 | - * @param int $start Which record to start at |
|
506 | - * |
|
507 | - * @param bool $debug |
|
508 | - * @return array |
|
509 | - */ |
|
510 | - public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
511 | - { |
|
512 | - $ret = array(); |
|
513 | - if ($criteria === null) { |
|
514 | - $criteria = new CriteriaCompo(); |
|
515 | - } |
|
516 | - |
|
517 | - if ($criteria->getSort() === '') { |
|
518 | - $criteria->setSort($this->getIdentifierName()); |
|
519 | - } |
|
520 | - |
|
521 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
522 | - if (!empty($this->identifierName)) { |
|
523 | - $sql .= ', ' . $this->getIdentifierName(); |
|
524 | - } |
|
525 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
526 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
527 | - $sql .= ' ' . $criteria->renderWhere(); |
|
528 | - if ($criteria->getSort() !== '') { |
|
529 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
530 | - } |
|
531 | - $limit = $criteria->getLimit(); |
|
532 | - $start = $criteria->getStart(); |
|
533 | - } |
|
534 | - |
|
535 | - if ($debug) { |
|
536 | - xoops_debug($sql); |
|
537 | - } |
|
538 | - |
|
539 | - $result = $this->db->query($sql, $limit, $start); |
|
540 | - if (!$result) { |
|
541 | - return $ret; |
|
542 | - } |
|
543 | - |
|
544 | - $myts = MyTextSanitizer::getInstance(); |
|
545 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
546 | - //identifiers should be textboxes, so sanitize them like that |
|
547 | - $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
548 | - } |
|
549 | - |
|
550 | - return $ret; |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * count objects matching a condition |
|
555 | - * |
|
556 | - * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
557 | - * @return int count of objects |
|
558 | - */ |
|
559 | - public function getCount(CriteriaElement $criteria = null) |
|
560 | - { |
|
561 | - $field = ''; |
|
562 | - $groupby = false; |
|
563 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
564 | - if ($criteria->groupby !== '') { |
|
565 | - $groupby = true; |
|
566 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
567 | - } |
|
568 | - } |
|
569 | - /** |
|
570 | - * if we have a generalSQL, lets used this one. |
|
571 | - * This needs to be improved... |
|
572 | - */ |
|
573 | - if ($this->generalSQL) { |
|
574 | - $sql = $this->generalSQL; |
|
575 | - $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
576 | - } else { |
|
577 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
578 | - } |
|
579 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
580 | - $sql .= ' ' . $criteria->renderWhere(); |
|
581 | - if ($criteria->groupby !== '') { |
|
582 | - $sql .= $criteria->getGroupby(); |
|
583 | - } |
|
584 | - } |
|
585 | - |
|
586 | - $result = $this->db->query($sql); |
|
587 | - if (!$result) { |
|
588 | - return 0; |
|
589 | - } |
|
590 | - if ($groupby === false) { |
|
591 | - list($count) = $this->db->fetchRow($result); |
|
592 | - |
|
593 | - return $count; |
|
594 | - } else { |
|
595 | - $ret = array(); |
|
596 | - while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
597 | - $ret[$id] = $count; |
|
598 | - } |
|
599 | - |
|
600 | - return $ret; |
|
601 | - } |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * delete an object from the database |
|
606 | - * |
|
607 | - * @param XoopsObject $obj reference to the object to delete |
|
608 | - * @param bool $force |
|
609 | - * @return bool FALSE if failed. |
|
610 | - */ |
|
611 | - public function delete(XoopsObject $obj, $force = false) |
|
612 | - { |
|
613 | - $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
614 | - if (!$eventResult) { |
|
615 | - $obj->setErrors('An error occured during the BeforeDelete event'); |
|
616 | - |
|
617 | - return false; |
|
618 | - } |
|
619 | - |
|
620 | - if (is_array($this->keyName)) { |
|
621 | - $clause = array(); |
|
622 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
623 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
624 | - } |
|
625 | - $whereclause = implode(' AND ', $clause); |
|
626 | - } else { |
|
627 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
628 | - } |
|
629 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
630 | - if (false !== $force) { |
|
631 | - $result = $this->db->queryF($sql); |
|
632 | - } else { |
|
633 | - $result = $this->db->query($sql); |
|
634 | - } |
|
635 | - if (!$result) { |
|
636 | - return false; |
|
637 | - } |
|
638 | - |
|
639 | - $eventResult = $this->executeEvent('afterDelete', $obj); |
|
640 | - if (!$eventResult) { |
|
641 | - $obj->setErrors('An error occured during the AfterDelete event'); |
|
642 | - |
|
643 | - return false; |
|
644 | - } |
|
645 | - |
|
646 | - return true; |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * @param $event |
|
651 | - */ |
|
652 | - public function disableEvent($event) |
|
653 | - { |
|
654 | - if (is_array($event)) { |
|
655 | - foreach ($event as $v) { |
|
656 | - $this->_disabledEvents[] = $v; |
|
657 | - } |
|
658 | - } else { |
|
659 | - $this->_disabledEvents[] = $event; |
|
660 | - } |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * @return array |
|
665 | - */ |
|
666 | - public function getPermissions() |
|
667 | - { |
|
668 | - return $this->permissionsArray; |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * insert a new object in the database |
|
673 | - * |
|
674 | - * @param XoopsObject $obj reference to the object |
|
675 | - * @param bool $force whether to force the query execution despite security settings |
|
676 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
677 | - * @param bool $debug |
|
678 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
679 | - */ |
|
680 | - public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
681 | - { |
|
682 | - if ($checkObject !== false) { |
|
683 | - if (!is_object($obj)) { |
|
684 | - return false; |
|
685 | - } |
|
686 | - /** |
|
687 | - * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
688 | - */ |
|
689 | - if (!is_a($obj, $this->className)) { |
|
690 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
691 | - |
|
692 | - return false; |
|
693 | - } |
|
694 | - if (!$obj->isDirty()) { |
|
695 | - $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith |
|
696 | - |
|
697 | - return true; |
|
698 | - } |
|
699 | - } |
|
700 | - |
|
701 | - if ($obj->seoEnabled) { |
|
702 | - // Auto create meta tags if empty |
|
703 | - $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
704 | - |
|
705 | - if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
706 | - if (!$obj->meta_keywords()) { |
|
707 | - $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
708 | - } |
|
709 | - |
|
710 | - if (!$obj->meta_description()) { |
|
711 | - $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
712 | - } |
|
713 | - } |
|
714 | - |
|
715 | - // Auto create short_url if empty |
|
716 | - if (!$obj->short_url()) { |
|
717 | - $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
718 | - } |
|
719 | - } |
|
720 | - |
|
721 | - $eventResult = $this->executeEvent('beforeSave', $obj); |
|
722 | - if (!$eventResult) { |
|
723 | - $obj->setErrors('An error occured during the BeforeSave event'); |
|
724 | - |
|
725 | - return false; |
|
726 | - } |
|
727 | - |
|
728 | - if ($obj->isNew()) { |
|
729 | - $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
730 | - if (!$eventResult) { |
|
731 | - $obj->setErrors('An error occured during the BeforeInsert event'); |
|
732 | - |
|
733 | - return false; |
|
734 | - } |
|
735 | - } else { |
|
736 | - $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
737 | - if (!$eventResult) { |
|
738 | - $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
739 | - |
|
740 | - return false; |
|
741 | - } |
|
742 | - } |
|
743 | - if (!$obj->cleanVars()) { |
|
744 | - $obj->setErrors('Variables were not cleaned properly.'); |
|
745 | - |
|
746 | - return false; |
|
747 | - } |
|
748 | - $fieldsToStoreInDB = array(); |
|
749 | - foreach ($obj->cleanVars as $k => $v) { |
|
750 | - if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
751 | - $cleanvars[$k] = (int)$v; |
|
752 | - } elseif (is_array($v)) { |
|
753 | - $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
754 | - } else { |
|
755 | - $cleanvars[$k] = $this->db->quoteString($v); |
|
756 | - } |
|
757 | - if ($obj->vars[$k]['persistent']) { |
|
758 | - $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
759 | - } |
|
760 | - } |
|
761 | - if ($obj->isNew()) { |
|
762 | - if (!is_array($this->keyName)) { |
|
763 | - if ($cleanvars[$this->keyName] < 1) { |
|
764 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
765 | - } |
|
766 | - } |
|
767 | - |
|
768 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
769 | - } else { |
|
770 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
771 | - foreach ($fieldsToStoreInDB as $key => $value) { |
|
772 | - if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
|
773 | - continue; |
|
774 | - } |
|
775 | - if (isset($notfirst)) { |
|
776 | - $sql .= ','; |
|
777 | - } |
|
778 | - $sql .= ' ' . $key . ' = ' . $value; |
|
779 | - $notfirst = true; |
|
780 | - } |
|
781 | - if (is_array($this->keyName)) { |
|
782 | - $whereclause = ''; |
|
783 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
784 | - if ($i > 0) { |
|
785 | - $whereclause .= ' AND '; |
|
786 | - } |
|
787 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
788 | - } |
|
789 | - } else { |
|
790 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
791 | - } |
|
792 | - $sql .= ' WHERE ' . $whereclause; |
|
793 | - } |
|
794 | - |
|
795 | - if ($debug) { |
|
796 | - xoops_debug($sql); |
|
797 | - } |
|
798 | - |
|
799 | - if (false != $force) { |
|
800 | - $result = $this->db->queryF($sql); |
|
801 | - } else { |
|
802 | - $result = $this->db->query($sql); |
|
803 | - } |
|
804 | - |
|
805 | - if (!$result) { |
|
806 | - $obj->setErrors($this->db->error()); |
|
807 | - |
|
808 | - return false; |
|
809 | - } |
|
810 | - |
|
811 | - if ($obj->isNew() && !is_array($this->keyName)) { |
|
812 | - $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
813 | - } |
|
814 | - $eventResult = $this->executeEvent('afterSave', $obj); |
|
815 | - if (!$eventResult) { |
|
816 | - $obj->setErrors('An error occured during the AfterSave event'); |
|
817 | - |
|
818 | - return false; |
|
819 | - } |
|
820 | - |
|
821 | - if ($obj->isNew()) { |
|
822 | - $obj->unsetNew(); |
|
823 | - $eventResult = $this->executeEvent('afterInsert', $obj); |
|
824 | - if (!$eventResult) { |
|
825 | - $obj->setErrors('An error occured during the AfterInsert event'); |
|
826 | - |
|
827 | - return false; |
|
828 | - } |
|
829 | - } else { |
|
830 | - $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
831 | - if (!$eventResult) { |
|
832 | - $obj->setErrors('An error occured during the AfterUpdate event'); |
|
833 | - |
|
834 | - return false; |
|
835 | - } |
|
836 | - } |
|
837 | - |
|
838 | - return true; |
|
839 | - } |
|
840 | - |
|
841 | - /** |
|
842 | - * @param $obj |
|
843 | - * @param bool $force |
|
844 | - * @param bool $checkObject |
|
845 | - * @param bool $debug |
|
846 | - * @return bool |
|
847 | - */ |
|
848 | - public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
849 | - { |
|
850 | - return $this->insert($obj, $force, $checkObject, true); |
|
851 | - } |
|
852 | - |
|
853 | - /** |
|
854 | - * Change a value for objects with a certain criteria |
|
855 | - * |
|
856 | - * @param string $fieldname Name of the field |
|
857 | - * @param string $fieldvalue Value to write |
|
858 | - * @param CriteriaElement $criteria {@link CriteriaElement} |
|
859 | - * |
|
860 | - * @param bool $force |
|
861 | - * @return bool |
|
862 | - */ |
|
863 | - public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
864 | - { |
|
865 | - $set_clause = $fieldname . ' = '; |
|
866 | - if (is_numeric($fieldvalue)) { |
|
867 | - $set_clause .= $fieldvalue; |
|
868 | - } elseif (is_array($fieldvalue)) { |
|
869 | - $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
870 | - } else { |
|
871 | - $set_clause .= $this->db->quoteString($fieldvalue); |
|
872 | - } |
|
873 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
874 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
875 | - $sql .= ' ' . $criteria->renderWhere(); |
|
876 | - } |
|
877 | - if (false != $force) { |
|
878 | - $result = $this->db->queryF($sql); |
|
879 | - } else { |
|
880 | - $result = $this->db->query($sql); |
|
881 | - } |
|
882 | - if (!$result) { |
|
883 | - return false; |
|
884 | - } |
|
885 | - |
|
886 | - return true; |
|
887 | - } |
|
888 | - |
|
889 | - /** |
|
890 | - * delete all objects meeting the conditions |
|
891 | - * |
|
892 | - * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
893 | - * @return bool |
|
894 | - */ |
|
895 | - |
|
896 | - public function deleteAll(CriteriaElement $criteria = null) |
|
897 | - { |
|
898 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
899 | - $sql = 'DELETE FROM ' . $this->table; |
|
900 | - $sql .= ' ' . $criteria->renderWhere(); |
|
901 | - if (!$this->db->query($sql)) { |
|
902 | - return false; |
|
903 | - } |
|
904 | - $rows = $this->db->getAffectedRows(); |
|
905 | - |
|
906 | - return $rows > 0 ? $rows : true; |
|
907 | - } |
|
908 | - |
|
909 | - return false; |
|
910 | - } |
|
911 | - |
|
912 | - /** |
|
913 | - * @return mixed |
|
914 | - */ |
|
915 | - public function getModuleInfo() |
|
916 | - { |
|
917 | - return smart_getModuleInfo($this->_moduleName); |
|
918 | - } |
|
919 | - |
|
920 | - /** |
|
921 | - * @return bool |
|
922 | - */ |
|
923 | - public function getModuleConfig() |
|
924 | - { |
|
925 | - return smart_getModuleConfig($this->_moduleName); |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * @return string |
|
930 | - */ |
|
931 | - public function getModuleItemString() |
|
932 | - { |
|
933 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
934 | - |
|
935 | - return $ret; |
|
936 | - } |
|
937 | - |
|
938 | - /** |
|
939 | - * @param $object |
|
940 | - */ |
|
941 | - public function updateCounter($object) |
|
942 | - { |
|
943 | - if (isset($object->vars['counter'])) { |
|
944 | - $new_counter = $object->getVar('counter') + 1; |
|
945 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
946 | - $this->query($sql, null, true); |
|
947 | - } |
|
948 | - } |
|
949 | - |
|
950 | - /** |
|
951 | - * Execute the function associated with an event |
|
952 | - * This method will check if the function is available |
|
953 | - * |
|
954 | - * @param string $event name of the event |
|
955 | - * @param $executeEventObj |
|
956 | - * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
957 | - * @internal param object $obj $object on which is performed the event |
|
958 | - */ |
|
959 | - public function executeEvent($event, &$executeEventObj) |
|
960 | - { |
|
961 | - if (!in_array($event, $this->_disabledEvents)) { |
|
962 | - if (method_exists($this, $event)) { |
|
963 | - $ret = $this->$event($executeEventObj); |
|
964 | - } else { |
|
965 | - // check to see if there is a hook for this event |
|
966 | - if (isset($this->_eventHooks[$event])) { |
|
967 | - $method = $this->_eventHooks[$event]; |
|
968 | - // check to see if the method specified by this hook exists |
|
969 | - if (method_exists($this, $method)) { |
|
970 | - $ret = $this->$method($executeEventObj); |
|
971 | - } |
|
972 | - } |
|
973 | - $ret = true; |
|
974 | - } |
|
975 | - |
|
976 | - return $ret; |
|
977 | - } |
|
978 | - |
|
979 | - return true; |
|
980 | - } |
|
981 | - |
|
982 | - /** |
|
983 | - * @param bool $withprefix |
|
984 | - * @return string |
|
985 | - */ |
|
986 | - public function getIdentifierName($withprefix = true) |
|
987 | - { |
|
988 | - if ($withprefix) { |
|
989 | - return $this->_itemname . '.' . $this->identifierName; |
|
990 | - } else { |
|
991 | - return $this->identifierName; |
|
992 | - } |
|
993 | - } |
|
28 | + public $_itemname; |
|
29 | + |
|
30 | + /** |
|
31 | + * Name of the table use to store this {@link SmartObject} |
|
32 | + * |
|
33 | + * Note that the name of the table needs to be free of the database prefix. |
|
34 | + * For example "smartsection_categories" |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + public $table; |
|
38 | + |
|
39 | + /** |
|
40 | + * Name of the table key that uniquely identify each {@link SmartObject} |
|
41 | + * |
|
42 | + * For example: "categoryid" |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $keyName; |
|
46 | + |
|
47 | + /** |
|
48 | + * Name of the class derived from {@link SmartObject} and which this handler is handling |
|
49 | + * |
|
50 | + * Note that this string needs to be lowercase |
|
51 | + * |
|
52 | + * For example: "smartsectioncategory" |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $className; |
|
56 | + |
|
57 | + /** |
|
58 | + * Name of the field which properly identify the {@link SmartObject} |
|
59 | + * |
|
60 | + * For example: "name" (this will be the category's name) |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $identifierName; |
|
64 | + |
|
65 | + /** |
|
66 | + * Name of the field which will be use as a summary for the object |
|
67 | + * |
|
68 | + * For example: "summary" |
|
69 | + * @var string |
|
70 | + */ |
|
71 | + public $summaryName; |
|
72 | + |
|
73 | + /** |
|
74 | + * Page name use to basically manage and display the {@link SmartObject} |
|
75 | + * |
|
76 | + * This page needs to be the same in user side and admin side |
|
77 | + * |
|
78 | + * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php |
|
79 | + * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page |
|
80 | + * @var string |
|
81 | + */ |
|
82 | + public $_page; |
|
83 | + |
|
84 | + /** |
|
85 | + * Full path of the module using this {@link SmartObject} |
|
86 | + * |
|
87 | + * <code>XOOPS_URL . "/modules/smartsection/"</code> |
|
88 | + * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name |
|
89 | + * @var string |
|
90 | + */ |
|
91 | + public $_modulePath; |
|
92 | + |
|
93 | + public $_moduleUrl; |
|
94 | + |
|
95 | + public $_moduleName; |
|
96 | + |
|
97 | + public $_uploadUrl; |
|
98 | + |
|
99 | + public $_uploadPath; |
|
100 | + |
|
101 | + public $_allowedMimeTypes = 0; |
|
102 | + |
|
103 | + public $_maxFileSize = 1000000; |
|
104 | + |
|
105 | + public $_maxWidth = 500; |
|
106 | + |
|
107 | + public $_maxHeight = 500; |
|
108 | + |
|
109 | + public $highlightFields = array(); |
|
110 | + |
|
111 | + /** |
|
112 | + * Array containing the events name and functions |
|
113 | + * |
|
114 | + * @var array |
|
115 | + */ |
|
116 | + public $eventArray = array(); |
|
117 | + |
|
118 | + /** |
|
119 | + * Array containing the permissions that this handler will manage on the objects |
|
120 | + * |
|
121 | + * @var array |
|
122 | + */ |
|
123 | + public $permissionsArray = false; |
|
124 | + |
|
125 | + public $generalSQL = false; |
|
126 | + |
|
127 | + public $_eventHooks = array(); |
|
128 | + public $_disabledEvents = array(); |
|
129 | + |
|
130 | + /** |
|
131 | + * Constructor - called from child classes |
|
132 | + * |
|
133 | + * @param XoopsDatabase $db {@link XoopsDatabase} |
|
134 | + * object |
|
135 | + * @param $itemname |
|
136 | + * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
137 | + * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
138 | + * @param $summaryName |
|
139 | + * @param $modulename |
|
140 | + * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
141 | + * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
142 | + * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
143 | + * @internal param string $moduleName name of the module |
|
144 | + */ |
|
145 | + public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
146 | + { |
|
147 | + parent::__construct($db); |
|
148 | + |
|
149 | + $this->_itemname = $itemname; |
|
150 | + $this->_moduleName = $modulename; |
|
151 | + $this->table = $db->prefix($modulename . '_' . $itemname); |
|
152 | + $this->keyName = $keyname; |
|
153 | + $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
154 | + $this->identifierName = $idenfierName; |
|
155 | + $this->summaryName = $summaryName; |
|
156 | + $this->_page = $itemname . '.php'; |
|
157 | + $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
158 | + $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
159 | + $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
160 | + $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param $event |
|
165 | + * @param $method |
|
166 | + */ |
|
167 | + public function addEventHook($event, $method) |
|
168 | + { |
|
169 | + $this->_eventHooks[$event] = $method; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Add a permission that this handler will manage for its objects |
|
174 | + * |
|
175 | + * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
176 | + * |
|
177 | + * @param string $perm_name name of the permission |
|
178 | + * @param string $caption caption of the control that will be displayed in the form |
|
179 | + * @param bool|string $description description of the control that will be displayed in the form |
|
180 | + */ |
|
181 | + public function addPermission($perm_name, $caption, $description = false) |
|
182 | + { |
|
183 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'); |
|
184 | + |
|
185 | + $this->permissionsArray[] = array( |
|
186 | + 'perm_name' => $perm_name, |
|
187 | + 'caption' => $caption, |
|
188 | + 'description' => $description |
|
189 | + ); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @param $criteria |
|
194 | + * @param $perm_name |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
|
198 | + { |
|
199 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
200 | + $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
201 | + if (count($grantedItems) > 0) { |
|
202 | + $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
203 | + |
|
204 | + return true; |
|
205 | + } else { |
|
206 | + return false; |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param bool $_uploadPath |
|
212 | + * @param bool $_allowedMimeTypes |
|
213 | + * @param bool $_maxFileSize |
|
214 | + * @param bool $_maxWidth |
|
215 | + * @param bool $_maxHeight |
|
216 | + */ |
|
217 | + public function setUploaderConfig($_uploadPath = false, $_allowedMimeTypes = false, $_maxFileSize = false, $_maxWidth = false, $_maxHeight = false) |
|
218 | + { |
|
219 | + $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
220 | + $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
221 | + $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
222 | + $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
223 | + $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * create a new {@link SmartObject} |
|
228 | + * |
|
229 | + * @param bool $isNew Flag the new objects as "new"? |
|
230 | + * |
|
231 | + * @return SmartObject {@link SmartObject} |
|
232 | + */ |
|
233 | + public function create($isNew = true) |
|
234 | + { |
|
235 | + $obj = new $this->className($this); |
|
236 | + $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
237 | + if (!$obj->handler) { |
|
238 | + $obj->handler =& $this; |
|
239 | + } |
|
240 | + |
|
241 | + if ($isNew === true) { |
|
242 | + $obj->setNew(); |
|
243 | + } |
|
244 | + |
|
245 | + return $obj; |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function getImageUrl() |
|
252 | + { |
|
253 | + return $this->_uploadUrl . $this->_itemname . '/'; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @return string |
|
258 | + */ |
|
259 | + public function getImagePath() |
|
260 | + { |
|
261 | + $dir = $this->_uploadPath . $this->_itemname; |
|
262 | + if (!file_exists($dir)) { |
|
263 | + smart_admin_mkdir($dir); |
|
264 | + } |
|
265 | + |
|
266 | + return $dir . '/'; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * retrieve a {@link SmartObject} |
|
271 | + * |
|
272 | + * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
273 | + * @param bool $as_object whether to return an object or an array |
|
274 | + * @param bool $debug |
|
275 | + * @param bool $criteria |
|
276 | + * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
277 | + * FALSE if failed |
|
278 | + */ |
|
279 | + public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
280 | + { |
|
281 | + if (!$criteria) { |
|
282 | + $criteria = new CriteriaCompo(); |
|
283 | + } |
|
284 | + if (is_array($this->keyName)) { |
|
285 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
286 | + /** |
|
287 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
288 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
289 | + */ |
|
290 | + //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
291 | + $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
292 | + } |
|
293 | + } else { |
|
294 | + //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
295 | + /** |
|
296 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
297 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
298 | + */ |
|
299 | + $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
300 | + } |
|
301 | + $criteria->setLimit(1); |
|
302 | + if ($debug) { |
|
303 | + $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
304 | + } else { |
|
305 | + $obj_array = $this->getObjects($criteria, false, $as_object); |
|
306 | + //patch: weird bug of indexing by id even if id_as_key = false; |
|
307 | + if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
308 | + $obj_array[0] = $obj_array[$id]; |
|
309 | + unset($obj_array[$id]); |
|
310 | + $obj_array[0]->unsetNew(); |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + if (count($obj_array) != 1) { |
|
315 | + $obj = $this->create(); |
|
316 | + |
|
317 | + return $obj; |
|
318 | + } |
|
319 | + |
|
320 | + return $obj_array[0]; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * retrieve a {@link SmartObject} |
|
325 | + * |
|
326 | + * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
327 | + * @param bool $as_object whether to return an object or an array |
|
328 | + * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
329 | + */ |
|
330 | + public function &getD($id, $as_object = true) |
|
331 | + { |
|
332 | + return $this->get($id, $as_object, true); |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * retrieve objects from the database |
|
337 | + * |
|
338 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
339 | + * @param bool $id_as_key use the ID as key for the array? |
|
340 | + * @param bool $as_object return an array of objects? |
|
341 | + * |
|
342 | + * @param bool $sql |
|
343 | + * @param bool $debug |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + public function getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false) |
|
347 | + { |
|
348 | + $ret = array(); |
|
349 | + $limit = $start = 0; |
|
350 | + |
|
351 | + if ($this->generalSQL) { |
|
352 | + $sql = $this->generalSQL; |
|
353 | + } elseif (!$sql) { |
|
354 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
355 | + } |
|
356 | + |
|
357 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
358 | + $sql .= ' ' . $criteria->renderWhere(); |
|
359 | + if ($criteria->getSort() !== '') { |
|
360 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
361 | + } |
|
362 | + $limit = $criteria->getLimit(); |
|
363 | + $start = $criteria->getStart(); |
|
364 | + } |
|
365 | + if ($debug) { |
|
366 | + xoops_debug($sql); |
|
367 | + } |
|
368 | + |
|
369 | + $result = $this->db->query($sql, $limit, $start); |
|
370 | + if (!$result) { |
|
371 | + return $ret; |
|
372 | + } |
|
373 | + |
|
374 | + return $this->convertResultSet($result, $id_as_key, $as_object); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * @param $sql |
|
379 | + * @param $criteria |
|
380 | + * @param bool $force |
|
381 | + * @param bool $debug |
|
382 | + * @return array |
|
383 | + */ |
|
384 | + public function query($sql, $criteria, $force = false, $debug = false) |
|
385 | + { |
|
386 | + $ret = array(); |
|
387 | + |
|
388 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
389 | + $sql .= ' ' . $criteria->renderWhere(); |
|
390 | + if ($criteria->groupby) { |
|
391 | + $sql .= $criteria->getGroupby(); |
|
392 | + } |
|
393 | + if ($criteria->getSort() !== '') { |
|
394 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
395 | + } |
|
396 | + } |
|
397 | + if ($debug) { |
|
398 | + xoops_debug($sql); |
|
399 | + } |
|
400 | + |
|
401 | + if ($force) { |
|
402 | + $result = $this->db->queryF($sql); |
|
403 | + } else { |
|
404 | + $result = $this->db->query($sql); |
|
405 | + } |
|
406 | + |
|
407 | + if (!$result) { |
|
408 | + return $ret; |
|
409 | + } |
|
410 | + |
|
411 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
412 | + $ret[] = $myrow; |
|
413 | + } |
|
414 | + |
|
415 | + return $ret; |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * retrieve objects with debug mode - so will show the query |
|
420 | + * |
|
421 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
422 | + * @param bool $id_as_key use the ID as key for the array? |
|
423 | + * @param bool $as_object return an array of objects? |
|
424 | + * |
|
425 | + * @param bool $sql |
|
426 | + * @return array |
|
427 | + */ |
|
428 | + public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
429 | + { |
|
430 | + return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * @param $arrayObjects |
|
435 | + * @return array|bool |
|
436 | + */ |
|
437 | + public function getObjectsAsArray($arrayObjects) |
|
438 | + { |
|
439 | + $ret = array(); |
|
440 | + foreach ($arrayObjects as $key => $object) { |
|
441 | + $ret[$key] = $object->toArray(); |
|
442 | + } |
|
443 | + if (count($ret > 0)) { |
|
444 | + return $ret; |
|
445 | + } else { |
|
446 | + return false; |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Convert a database resultset to a returnable array |
|
452 | + * |
|
453 | + * @param object $result database resultset |
|
454 | + * @param bool $id_as_key - should NOT be used with joint keys |
|
455 | + * @param bool $as_object |
|
456 | + * |
|
457 | + * @return array |
|
458 | + */ |
|
459 | + public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
460 | + { |
|
461 | + $ret = array(); |
|
462 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
463 | + $obj = $this->create(false); |
|
464 | + $obj->assignVars($myrow); |
|
465 | + if (!$id_as_key) { |
|
466 | + if ($as_object) { |
|
467 | + $ret[] =& $obj; |
|
468 | + } else { |
|
469 | + $ret[] = $obj->toArray(); |
|
470 | + } |
|
471 | + } else { |
|
472 | + if ($as_object) { |
|
473 | + $value =& $obj; |
|
474 | + } else { |
|
475 | + $value = $obj->toArray(); |
|
476 | + } |
|
477 | + if ($id_as_key === 'parentid') { |
|
478 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
479 | + } else { |
|
480 | + $ret[$obj->getVar($this->keyName)] = $value; |
|
481 | + } |
|
482 | + } |
|
483 | + unset($obj); |
|
484 | + } |
|
485 | + |
|
486 | + return $ret; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * @param null $criteria |
|
491 | + * @param int $limit |
|
492 | + * @param int $start |
|
493 | + * @return array |
|
494 | + */ |
|
495 | + public function getListD($criteria = null, $limit = 0, $start = 0) |
|
496 | + { |
|
497 | + return $this->getList($criteria, $limit, $start, true); |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
502 | + * |
|
503 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
504 | + * @param int $limit Max number of objects to fetch |
|
505 | + * @param int $start Which record to start at |
|
506 | + * |
|
507 | + * @param bool $debug |
|
508 | + * @return array |
|
509 | + */ |
|
510 | + public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
511 | + { |
|
512 | + $ret = array(); |
|
513 | + if ($criteria === null) { |
|
514 | + $criteria = new CriteriaCompo(); |
|
515 | + } |
|
516 | + |
|
517 | + if ($criteria->getSort() === '') { |
|
518 | + $criteria->setSort($this->getIdentifierName()); |
|
519 | + } |
|
520 | + |
|
521 | + $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
522 | + if (!empty($this->identifierName)) { |
|
523 | + $sql .= ', ' . $this->getIdentifierName(); |
|
524 | + } |
|
525 | + $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
526 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
527 | + $sql .= ' ' . $criteria->renderWhere(); |
|
528 | + if ($criteria->getSort() !== '') { |
|
529 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
530 | + } |
|
531 | + $limit = $criteria->getLimit(); |
|
532 | + $start = $criteria->getStart(); |
|
533 | + } |
|
534 | + |
|
535 | + if ($debug) { |
|
536 | + xoops_debug($sql); |
|
537 | + } |
|
538 | + |
|
539 | + $result = $this->db->query($sql, $limit, $start); |
|
540 | + if (!$result) { |
|
541 | + return $ret; |
|
542 | + } |
|
543 | + |
|
544 | + $myts = MyTextSanitizer::getInstance(); |
|
545 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
546 | + //identifiers should be textboxes, so sanitize them like that |
|
547 | + $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
548 | + } |
|
549 | + |
|
550 | + return $ret; |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * count objects matching a condition |
|
555 | + * |
|
556 | + * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
557 | + * @return int count of objects |
|
558 | + */ |
|
559 | + public function getCount(CriteriaElement $criteria = null) |
|
560 | + { |
|
561 | + $field = ''; |
|
562 | + $groupby = false; |
|
563 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
564 | + if ($criteria->groupby !== '') { |
|
565 | + $groupby = true; |
|
566 | + $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
567 | + } |
|
568 | + } |
|
569 | + /** |
|
570 | + * if we have a generalSQL, lets used this one. |
|
571 | + * This needs to be improved... |
|
572 | + */ |
|
573 | + if ($this->generalSQL) { |
|
574 | + $sql = $this->generalSQL; |
|
575 | + $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
576 | + } else { |
|
577 | + $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
578 | + } |
|
579 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
580 | + $sql .= ' ' . $criteria->renderWhere(); |
|
581 | + if ($criteria->groupby !== '') { |
|
582 | + $sql .= $criteria->getGroupby(); |
|
583 | + } |
|
584 | + } |
|
585 | + |
|
586 | + $result = $this->db->query($sql); |
|
587 | + if (!$result) { |
|
588 | + return 0; |
|
589 | + } |
|
590 | + if ($groupby === false) { |
|
591 | + list($count) = $this->db->fetchRow($result); |
|
592 | + |
|
593 | + return $count; |
|
594 | + } else { |
|
595 | + $ret = array(); |
|
596 | + while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
597 | + $ret[$id] = $count; |
|
598 | + } |
|
599 | + |
|
600 | + return $ret; |
|
601 | + } |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * delete an object from the database |
|
606 | + * |
|
607 | + * @param XoopsObject $obj reference to the object to delete |
|
608 | + * @param bool $force |
|
609 | + * @return bool FALSE if failed. |
|
610 | + */ |
|
611 | + public function delete(XoopsObject $obj, $force = false) |
|
612 | + { |
|
613 | + $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
614 | + if (!$eventResult) { |
|
615 | + $obj->setErrors('An error occured during the BeforeDelete event'); |
|
616 | + |
|
617 | + return false; |
|
618 | + } |
|
619 | + |
|
620 | + if (is_array($this->keyName)) { |
|
621 | + $clause = array(); |
|
622 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
623 | + $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
624 | + } |
|
625 | + $whereclause = implode(' AND ', $clause); |
|
626 | + } else { |
|
627 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
628 | + } |
|
629 | + $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
630 | + if (false !== $force) { |
|
631 | + $result = $this->db->queryF($sql); |
|
632 | + } else { |
|
633 | + $result = $this->db->query($sql); |
|
634 | + } |
|
635 | + if (!$result) { |
|
636 | + return false; |
|
637 | + } |
|
638 | + |
|
639 | + $eventResult = $this->executeEvent('afterDelete', $obj); |
|
640 | + if (!$eventResult) { |
|
641 | + $obj->setErrors('An error occured during the AfterDelete event'); |
|
642 | + |
|
643 | + return false; |
|
644 | + } |
|
645 | + |
|
646 | + return true; |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * @param $event |
|
651 | + */ |
|
652 | + public function disableEvent($event) |
|
653 | + { |
|
654 | + if (is_array($event)) { |
|
655 | + foreach ($event as $v) { |
|
656 | + $this->_disabledEvents[] = $v; |
|
657 | + } |
|
658 | + } else { |
|
659 | + $this->_disabledEvents[] = $event; |
|
660 | + } |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * @return array |
|
665 | + */ |
|
666 | + public function getPermissions() |
|
667 | + { |
|
668 | + return $this->permissionsArray; |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * insert a new object in the database |
|
673 | + * |
|
674 | + * @param XoopsObject $obj reference to the object |
|
675 | + * @param bool $force whether to force the query execution despite security settings |
|
676 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
677 | + * @param bool $debug |
|
678 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
679 | + */ |
|
680 | + public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
681 | + { |
|
682 | + if ($checkObject !== false) { |
|
683 | + if (!is_object($obj)) { |
|
684 | + return false; |
|
685 | + } |
|
686 | + /** |
|
687 | + * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
688 | + */ |
|
689 | + if (!is_a($obj, $this->className)) { |
|
690 | + $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
691 | + |
|
692 | + return false; |
|
693 | + } |
|
694 | + if (!$obj->isDirty()) { |
|
695 | + $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith |
|
696 | + |
|
697 | + return true; |
|
698 | + } |
|
699 | + } |
|
700 | + |
|
701 | + if ($obj->seoEnabled) { |
|
702 | + // Auto create meta tags if empty |
|
703 | + $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
704 | + |
|
705 | + if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
706 | + if (!$obj->meta_keywords()) { |
|
707 | + $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
708 | + } |
|
709 | + |
|
710 | + if (!$obj->meta_description()) { |
|
711 | + $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
712 | + } |
|
713 | + } |
|
714 | + |
|
715 | + // Auto create short_url if empty |
|
716 | + if (!$obj->short_url()) { |
|
717 | + $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
718 | + } |
|
719 | + } |
|
720 | + |
|
721 | + $eventResult = $this->executeEvent('beforeSave', $obj); |
|
722 | + if (!$eventResult) { |
|
723 | + $obj->setErrors('An error occured during the BeforeSave event'); |
|
724 | + |
|
725 | + return false; |
|
726 | + } |
|
727 | + |
|
728 | + if ($obj->isNew()) { |
|
729 | + $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
730 | + if (!$eventResult) { |
|
731 | + $obj->setErrors('An error occured during the BeforeInsert event'); |
|
732 | + |
|
733 | + return false; |
|
734 | + } |
|
735 | + } else { |
|
736 | + $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
737 | + if (!$eventResult) { |
|
738 | + $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
739 | + |
|
740 | + return false; |
|
741 | + } |
|
742 | + } |
|
743 | + if (!$obj->cleanVars()) { |
|
744 | + $obj->setErrors('Variables were not cleaned properly.'); |
|
745 | + |
|
746 | + return false; |
|
747 | + } |
|
748 | + $fieldsToStoreInDB = array(); |
|
749 | + foreach ($obj->cleanVars as $k => $v) { |
|
750 | + if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
751 | + $cleanvars[$k] = (int)$v; |
|
752 | + } elseif (is_array($v)) { |
|
753 | + $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
754 | + } else { |
|
755 | + $cleanvars[$k] = $this->db->quoteString($v); |
|
756 | + } |
|
757 | + if ($obj->vars[$k]['persistent']) { |
|
758 | + $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
759 | + } |
|
760 | + } |
|
761 | + if ($obj->isNew()) { |
|
762 | + if (!is_array($this->keyName)) { |
|
763 | + if ($cleanvars[$this->keyName] < 1) { |
|
764 | + $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
765 | + } |
|
766 | + } |
|
767 | + |
|
768 | + $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
769 | + } else { |
|
770 | + $sql = 'UPDATE ' . $this->table . ' SET'; |
|
771 | + foreach ($fieldsToStoreInDB as $key => $value) { |
|
772 | + if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
|
773 | + continue; |
|
774 | + } |
|
775 | + if (isset($notfirst)) { |
|
776 | + $sql .= ','; |
|
777 | + } |
|
778 | + $sql .= ' ' . $key . ' = ' . $value; |
|
779 | + $notfirst = true; |
|
780 | + } |
|
781 | + if (is_array($this->keyName)) { |
|
782 | + $whereclause = ''; |
|
783 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
784 | + if ($i > 0) { |
|
785 | + $whereclause .= ' AND '; |
|
786 | + } |
|
787 | + $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
788 | + } |
|
789 | + } else { |
|
790 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
791 | + } |
|
792 | + $sql .= ' WHERE ' . $whereclause; |
|
793 | + } |
|
794 | + |
|
795 | + if ($debug) { |
|
796 | + xoops_debug($sql); |
|
797 | + } |
|
798 | + |
|
799 | + if (false != $force) { |
|
800 | + $result = $this->db->queryF($sql); |
|
801 | + } else { |
|
802 | + $result = $this->db->query($sql); |
|
803 | + } |
|
804 | + |
|
805 | + if (!$result) { |
|
806 | + $obj->setErrors($this->db->error()); |
|
807 | + |
|
808 | + return false; |
|
809 | + } |
|
810 | + |
|
811 | + if ($obj->isNew() && !is_array($this->keyName)) { |
|
812 | + $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
813 | + } |
|
814 | + $eventResult = $this->executeEvent('afterSave', $obj); |
|
815 | + if (!$eventResult) { |
|
816 | + $obj->setErrors('An error occured during the AfterSave event'); |
|
817 | + |
|
818 | + return false; |
|
819 | + } |
|
820 | + |
|
821 | + if ($obj->isNew()) { |
|
822 | + $obj->unsetNew(); |
|
823 | + $eventResult = $this->executeEvent('afterInsert', $obj); |
|
824 | + if (!$eventResult) { |
|
825 | + $obj->setErrors('An error occured during the AfterInsert event'); |
|
826 | + |
|
827 | + return false; |
|
828 | + } |
|
829 | + } else { |
|
830 | + $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
831 | + if (!$eventResult) { |
|
832 | + $obj->setErrors('An error occured during the AfterUpdate event'); |
|
833 | + |
|
834 | + return false; |
|
835 | + } |
|
836 | + } |
|
837 | + |
|
838 | + return true; |
|
839 | + } |
|
840 | + |
|
841 | + /** |
|
842 | + * @param $obj |
|
843 | + * @param bool $force |
|
844 | + * @param bool $checkObject |
|
845 | + * @param bool $debug |
|
846 | + * @return bool |
|
847 | + */ |
|
848 | + public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
849 | + { |
|
850 | + return $this->insert($obj, $force, $checkObject, true); |
|
851 | + } |
|
852 | + |
|
853 | + /** |
|
854 | + * Change a value for objects with a certain criteria |
|
855 | + * |
|
856 | + * @param string $fieldname Name of the field |
|
857 | + * @param string $fieldvalue Value to write |
|
858 | + * @param CriteriaElement $criteria {@link CriteriaElement} |
|
859 | + * |
|
860 | + * @param bool $force |
|
861 | + * @return bool |
|
862 | + */ |
|
863 | + public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
864 | + { |
|
865 | + $set_clause = $fieldname . ' = '; |
|
866 | + if (is_numeric($fieldvalue)) { |
|
867 | + $set_clause .= $fieldvalue; |
|
868 | + } elseif (is_array($fieldvalue)) { |
|
869 | + $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
870 | + } else { |
|
871 | + $set_clause .= $this->db->quoteString($fieldvalue); |
|
872 | + } |
|
873 | + $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
874 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
875 | + $sql .= ' ' . $criteria->renderWhere(); |
|
876 | + } |
|
877 | + if (false != $force) { |
|
878 | + $result = $this->db->queryF($sql); |
|
879 | + } else { |
|
880 | + $result = $this->db->query($sql); |
|
881 | + } |
|
882 | + if (!$result) { |
|
883 | + return false; |
|
884 | + } |
|
885 | + |
|
886 | + return true; |
|
887 | + } |
|
888 | + |
|
889 | + /** |
|
890 | + * delete all objects meeting the conditions |
|
891 | + * |
|
892 | + * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
893 | + * @return bool |
|
894 | + */ |
|
895 | + |
|
896 | + public function deleteAll(CriteriaElement $criteria = null) |
|
897 | + { |
|
898 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
899 | + $sql = 'DELETE FROM ' . $this->table; |
|
900 | + $sql .= ' ' . $criteria->renderWhere(); |
|
901 | + if (!$this->db->query($sql)) { |
|
902 | + return false; |
|
903 | + } |
|
904 | + $rows = $this->db->getAffectedRows(); |
|
905 | + |
|
906 | + return $rows > 0 ? $rows : true; |
|
907 | + } |
|
908 | + |
|
909 | + return false; |
|
910 | + } |
|
911 | + |
|
912 | + /** |
|
913 | + * @return mixed |
|
914 | + */ |
|
915 | + public function getModuleInfo() |
|
916 | + { |
|
917 | + return smart_getModuleInfo($this->_moduleName); |
|
918 | + } |
|
919 | + |
|
920 | + /** |
|
921 | + * @return bool |
|
922 | + */ |
|
923 | + public function getModuleConfig() |
|
924 | + { |
|
925 | + return smart_getModuleConfig($this->_moduleName); |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * @return string |
|
930 | + */ |
|
931 | + public function getModuleItemString() |
|
932 | + { |
|
933 | + $ret = $this->_moduleName . '_' . $this->_itemname; |
|
934 | + |
|
935 | + return $ret; |
|
936 | + } |
|
937 | + |
|
938 | + /** |
|
939 | + * @param $object |
|
940 | + */ |
|
941 | + public function updateCounter($object) |
|
942 | + { |
|
943 | + if (isset($object->vars['counter'])) { |
|
944 | + $new_counter = $object->getVar('counter') + 1; |
|
945 | + $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
946 | + $this->query($sql, null, true); |
|
947 | + } |
|
948 | + } |
|
949 | + |
|
950 | + /** |
|
951 | + * Execute the function associated with an event |
|
952 | + * This method will check if the function is available |
|
953 | + * |
|
954 | + * @param string $event name of the event |
|
955 | + * @param $executeEventObj |
|
956 | + * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
957 | + * @internal param object $obj $object on which is performed the event |
|
958 | + */ |
|
959 | + public function executeEvent($event, &$executeEventObj) |
|
960 | + { |
|
961 | + if (!in_array($event, $this->_disabledEvents)) { |
|
962 | + if (method_exists($this, $event)) { |
|
963 | + $ret = $this->$event($executeEventObj); |
|
964 | + } else { |
|
965 | + // check to see if there is a hook for this event |
|
966 | + if (isset($this->_eventHooks[$event])) { |
|
967 | + $method = $this->_eventHooks[$event]; |
|
968 | + // check to see if the method specified by this hook exists |
|
969 | + if (method_exists($this, $method)) { |
|
970 | + $ret = $this->$method($executeEventObj); |
|
971 | + } |
|
972 | + } |
|
973 | + $ret = true; |
|
974 | + } |
|
975 | + |
|
976 | + return $ret; |
|
977 | + } |
|
978 | + |
|
979 | + return true; |
|
980 | + } |
|
981 | + |
|
982 | + /** |
|
983 | + * @param bool $withprefix |
|
984 | + * @return string |
|
985 | + */ |
|
986 | + public function getIdentifierName($withprefix = true) |
|
987 | + { |
|
988 | + if ($withprefix) { |
|
989 | + return $this->_itemname . '.' . $this->identifierName; |
|
990 | + } else { |
|
991 | + return $this->identifierName; |
|
992 | + } |
|
993 | + } |
|
994 | 994 | } |
@@ -22,153 +22,153 @@ |
||
22 | 22 | */ |
23 | 23 | class SmartObjectTreeTable extends SmartObjectTable |
24 | 24 | { |
25 | - /** |
|
26 | - * SmartObjectTreeTable constructor. |
|
27 | - * @param SmartPersistableObjectHandler $objectHandler |
|
28 | - * @param bool $criteria |
|
29 | - * @param array $actions |
|
30 | - * @param bool $userSide |
|
31 | - */ |
|
32 | - public function __construct(SmartPersistableObjectHandler $objectHandler, $criteria = false, $actions = array('edit', 'delete'), $userSide = false) |
|
33 | - { |
|
34 | - $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
35 | - $this->_isTree = true; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Get children objects given a specific parentid |
|
40 | - * |
|
41 | - * @var int $parentid id of the parent which children we want to retreive |
|
42 | - * @return array of SmartObject |
|
43 | - */ |
|
44 | - public function getChildrenOf($parentid = 0) |
|
45 | - { |
|
46 | - return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @param $object |
|
51 | - * @param int $level |
|
52 | - */ |
|
53 | - public function createTableRow($object, $level = 0) |
|
54 | - { |
|
55 | - $aObject = array(); |
|
56 | - |
|
57 | - $i = 0; |
|
58 | - |
|
59 | - $aColumns = array(); |
|
60 | - $doWeHaveActions = false; |
|
61 | - |
|
62 | - foreach ($this->_columns as $column) { |
|
63 | - $aColumn = array(); |
|
64 | - |
|
65 | - if ($i == 0) { |
|
66 | - $class = 'head'; |
|
67 | - } elseif ($i % 2 == 0) { |
|
68 | - $class = 'even'; |
|
69 | - } else { |
|
70 | - $class = 'odd'; |
|
71 | - } |
|
72 | - |
|
73 | - if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
74 | - $method = $column->_customMethodForValue; |
|
75 | - $value = $object->$method(); |
|
76 | - } else { |
|
77 | - /** |
|
78 | - * If the column is the identifier, then put a link on it |
|
79 | - */ |
|
80 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
81 | - $value = $object->getItemLink(); |
|
82 | - } else { |
|
83 | - $value = $object->getVar($column->getKeyName()); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - $space = ''; |
|
88 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
89 | - for ($i = 0; $i < $level; ++$i) { |
|
90 | - $space .= '--'; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - if ($space !== '') { |
|
95 | - $space .= ' '; |
|
96 | - } |
|
97 | - |
|
98 | - $aColumn['value'] = $space . $value; |
|
99 | - $aColumn['class'] = $class; |
|
100 | - $aColumn['width'] = $column->getWidth(); |
|
101 | - $aColumn['align'] = $column->getAlign(); |
|
102 | - $aColumn['key'] = $column->getKeyName(); |
|
103 | - |
|
104 | - $aColumns[] = $aColumn; |
|
105 | - ++$i; |
|
106 | - } |
|
107 | - |
|
108 | - $aObject['columns'] = $aColumns; |
|
109 | - |
|
110 | - $class = $class === 'even' ? 'odd' : 'even'; |
|
111 | - $aObject['class'] = $class; |
|
112 | - |
|
113 | - $actions = array(); |
|
114 | - |
|
115 | - // Adding the custom actions if any |
|
116 | - foreach ($this->_custom_actions as $action) { |
|
117 | - if (method_exists($object, $action)) { |
|
118 | - $actions[] = $object->$action(); |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
123 | - $controller = new SmartObjectController($this->_objectHandler); |
|
124 | - |
|
125 | - if (in_array('edit', $this->_actions)) { |
|
126 | - $actions[] = $controller->getEditItemLink($object, false, true); |
|
127 | - } |
|
128 | - if (in_array('delete', $this->_actions)) { |
|
129 | - $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
130 | - } |
|
131 | - $aObject['actions'] = $actions; |
|
132 | - |
|
133 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
134 | - $aObject['id'] = $object->id(); |
|
135 | - $this->_aObjects[] = $aObject; |
|
136 | - |
|
137 | - $childrenObjects = $this->getChildrenOf($object->id()); |
|
138 | - |
|
139 | - $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
|
140 | - |
|
141 | - if ($childrenObjects) { |
|
142 | - ++$level; |
|
143 | - foreach ($childrenObjects as $subObject) { |
|
144 | - $this->createTableRow($subObject, $level); |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - public function createTableRows() |
|
150 | - { |
|
151 | - $this->_aObjects = array(); |
|
152 | - |
|
153 | - if (count($this->_objects) > 0) { |
|
154 | - foreach ($this->getChildrenOf() as $object) { |
|
155 | - $this->createTableRow($object); |
|
156 | - } |
|
157 | - |
|
158 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
159 | - } else { |
|
160 | - $colspan = count($this->_columns) + 1; |
|
161 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return mixed |
|
167 | - */ |
|
168 | - public function fetchObjects() |
|
169 | - { |
|
170 | - $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
171 | - |
|
172 | - return $ret; |
|
173 | - } |
|
25 | + /** |
|
26 | + * SmartObjectTreeTable constructor. |
|
27 | + * @param SmartPersistableObjectHandler $objectHandler |
|
28 | + * @param bool $criteria |
|
29 | + * @param array $actions |
|
30 | + * @param bool $userSide |
|
31 | + */ |
|
32 | + public function __construct(SmartPersistableObjectHandler $objectHandler, $criteria = false, $actions = array('edit', 'delete'), $userSide = false) |
|
33 | + { |
|
34 | + $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
35 | + $this->_isTree = true; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Get children objects given a specific parentid |
|
40 | + * |
|
41 | + * @var int $parentid id of the parent which children we want to retreive |
|
42 | + * @return array of SmartObject |
|
43 | + */ |
|
44 | + public function getChildrenOf($parentid = 0) |
|
45 | + { |
|
46 | + return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @param $object |
|
51 | + * @param int $level |
|
52 | + */ |
|
53 | + public function createTableRow($object, $level = 0) |
|
54 | + { |
|
55 | + $aObject = array(); |
|
56 | + |
|
57 | + $i = 0; |
|
58 | + |
|
59 | + $aColumns = array(); |
|
60 | + $doWeHaveActions = false; |
|
61 | + |
|
62 | + foreach ($this->_columns as $column) { |
|
63 | + $aColumn = array(); |
|
64 | + |
|
65 | + if ($i == 0) { |
|
66 | + $class = 'head'; |
|
67 | + } elseif ($i % 2 == 0) { |
|
68 | + $class = 'even'; |
|
69 | + } else { |
|
70 | + $class = 'odd'; |
|
71 | + } |
|
72 | + |
|
73 | + if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
74 | + $method = $column->_customMethodForValue; |
|
75 | + $value = $object->$method(); |
|
76 | + } else { |
|
77 | + /** |
|
78 | + * If the column is the identifier, then put a link on it |
|
79 | + */ |
|
80 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
81 | + $value = $object->getItemLink(); |
|
82 | + } else { |
|
83 | + $value = $object->getVar($column->getKeyName()); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + $space = ''; |
|
88 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
89 | + for ($i = 0; $i < $level; ++$i) { |
|
90 | + $space .= '--'; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + if ($space !== '') { |
|
95 | + $space .= ' '; |
|
96 | + } |
|
97 | + |
|
98 | + $aColumn['value'] = $space . $value; |
|
99 | + $aColumn['class'] = $class; |
|
100 | + $aColumn['width'] = $column->getWidth(); |
|
101 | + $aColumn['align'] = $column->getAlign(); |
|
102 | + $aColumn['key'] = $column->getKeyName(); |
|
103 | + |
|
104 | + $aColumns[] = $aColumn; |
|
105 | + ++$i; |
|
106 | + } |
|
107 | + |
|
108 | + $aObject['columns'] = $aColumns; |
|
109 | + |
|
110 | + $class = $class === 'even' ? 'odd' : 'even'; |
|
111 | + $aObject['class'] = $class; |
|
112 | + |
|
113 | + $actions = array(); |
|
114 | + |
|
115 | + // Adding the custom actions if any |
|
116 | + foreach ($this->_custom_actions as $action) { |
|
117 | + if (method_exists($object, $action)) { |
|
118 | + $actions[] = $object->$action(); |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
123 | + $controller = new SmartObjectController($this->_objectHandler); |
|
124 | + |
|
125 | + if (in_array('edit', $this->_actions)) { |
|
126 | + $actions[] = $controller->getEditItemLink($object, false, true); |
|
127 | + } |
|
128 | + if (in_array('delete', $this->_actions)) { |
|
129 | + $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
130 | + } |
|
131 | + $aObject['actions'] = $actions; |
|
132 | + |
|
133 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
134 | + $aObject['id'] = $object->id(); |
|
135 | + $this->_aObjects[] = $aObject; |
|
136 | + |
|
137 | + $childrenObjects = $this->getChildrenOf($object->id()); |
|
138 | + |
|
139 | + $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
|
140 | + |
|
141 | + if ($childrenObjects) { |
|
142 | + ++$level; |
|
143 | + foreach ($childrenObjects as $subObject) { |
|
144 | + $this->createTableRow($subObject, $level); |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + public function createTableRows() |
|
150 | + { |
|
151 | + $this->_aObjects = array(); |
|
152 | + |
|
153 | + if (count($this->_objects) > 0) { |
|
154 | + foreach ($this->getChildrenOf() as $object) { |
|
155 | + $this->createTableRow($object); |
|
156 | + } |
|
157 | + |
|
158 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
159 | + } else { |
|
160 | + $colspan = count($this->_columns) + 1; |
|
161 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return mixed |
|
167 | + */ |
|
168 | + public function fetchObjects() |
|
169 | + { |
|
170 | + $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
171 | + |
|
172 | + return $ret; |
|
173 | + } |
|
174 | 174 | } |
@@ -35,164 +35,164 @@ 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, array('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="' . |
|
132 | - SMARTOBJECT_URL . |
|
133 | - 'admin/link.php?op=view&linkid=' . |
|
134 | - $this->getVar('linkid') . |
|
135 | - '"><img src="' . |
|
136 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
137 | - 'mail_find.png" alt="' . |
|
138 | - _AM_SOBJECT_SENT_LINK_VIEW . |
|
139 | - '" title="' . |
|
140 | - _AM_SOBJECT_SENT_LINK_VIEW . |
|
141 | - '" /></a>'; |
|
142 | - |
|
143 | - return $ret; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function getFromInfo() |
|
150 | - { |
|
151 | - // check if from_uid represent a user |
|
152 | - |
|
153 | - if ($this->getVar('from_uid')) { |
|
154 | - $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
155 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
156 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
157 | - } |
|
158 | - } else { |
|
159 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
160 | - } |
|
161 | - |
|
162 | - return $user; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - public function toArray() |
|
169 | - { |
|
170 | - $ret = parent::toArray(); |
|
171 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
172 | - $ret['toInfo'] = $this->getToInfo(); |
|
173 | - $ret['fullLink'] = $this->link(true); |
|
174 | - |
|
175 | - return $ret; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function getToInfo() |
|
182 | - { |
|
183 | - // check if from_uid represent a user |
|
184 | - |
|
185 | - if ($this->getVar('to_uid')) { |
|
186 | - $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
187 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
188 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
189 | - } |
|
190 | - } else { |
|
191 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
192 | - } |
|
193 | - |
|
194 | - return $user; |
|
195 | - } |
|
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, array('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="' . |
|
132 | + SMARTOBJECT_URL . |
|
133 | + 'admin/link.php?op=view&linkid=' . |
|
134 | + $this->getVar('linkid') . |
|
135 | + '"><img src="' . |
|
136 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
137 | + 'mail_find.png" alt="' . |
|
138 | + _AM_SOBJECT_SENT_LINK_VIEW . |
|
139 | + '" title="' . |
|
140 | + _AM_SOBJECT_SENT_LINK_VIEW . |
|
141 | + '" /></a>'; |
|
142 | + |
|
143 | + return $ret; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function getFromInfo() |
|
150 | + { |
|
151 | + // check if from_uid represent a user |
|
152 | + |
|
153 | + if ($this->getVar('from_uid')) { |
|
154 | + $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
155 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
156 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
157 | + } |
|
158 | + } else { |
|
159 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
160 | + } |
|
161 | + |
|
162 | + return $user; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + public function toArray() |
|
169 | + { |
|
170 | + $ret = parent::toArray(); |
|
171 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
172 | + $ret['toInfo'] = $this->getToInfo(); |
|
173 | + $ret['fullLink'] = $this->link(true); |
|
174 | + |
|
175 | + return $ret; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function getToInfo() |
|
182 | + { |
|
183 | + // check if from_uid represent a user |
|
184 | + |
|
185 | + if ($this->getVar('to_uid')) { |
|
186 | + $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
187 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
188 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
189 | + } |
|
190 | + } else { |
|
191 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
192 | + } |
|
193 | + |
|
194 | + return $user; |
|
195 | + } |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | */ |
201 | 201 | class SmartobjectLinkHandler extends SmartPersistableObjectHandler |
202 | 202 | { |
203 | - /** |
|
204 | - * SmartobjectLinkHandler constructor. |
|
205 | - * @param XoopsDatabase $db |
|
206 | - */ |
|
207 | - public function __construct(XoopsDatabase $db) |
|
208 | - { |
|
209 | - parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
210 | - } |
|
203 | + /** |
|
204 | + * SmartobjectLinkHandler constructor. |
|
205 | + * @param XoopsDatabase $db |
|
206 | + */ |
|
207 | + public function __construct(XoopsDatabase $db) |
|
208 | + { |
|
209 | + parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
210 | + } |
|
211 | 211 | } |
@@ -36,208 +36,208 @@ 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', array( |
|
58 | - 'name' => 'textarea', |
|
59 | - 'form_editor' => 'textarea', |
|
60 | - 'form_rows' => 25 |
|
61 | - )); |
|
62 | - $this->setControl('language', array( |
|
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, array())) { |
|
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="' . |
|
136 | - SMARTOBJECT_URL . |
|
137 | - 'admin/customtag.php?op=clone&customtagid=' . |
|
138 | - $this->id() . |
|
139 | - '"><img src="' . |
|
140 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
141 | - 'editcopy.png" style="vertical-align: middle;" alt="' . |
|
142 | - _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
143 | - '" title="' . |
|
144 | - _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
145 | - '" /></a>'; |
|
146 | - |
|
147 | - return $ret; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param $var |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - public function emptyString($var) |
|
155 | - { |
|
156 | - return (strlen($var) > 0); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return mixed|string |
|
161 | - */ |
|
162 | - public function generateTag() |
|
163 | - { |
|
164 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
165 | - $title = xoops_substr($title, 0, 10, ''); |
|
166 | - // Transformation des ponctuations |
|
167 | - $pattern = array( |
|
168 | - '/%09/', // Tab |
|
169 | - '/%20/', // Space |
|
170 | - '/%21/', // ! |
|
171 | - '/%22/', // " |
|
172 | - '/%23/', // # |
|
173 | - '/%25/', // % |
|
174 | - '/%26/', // & |
|
175 | - '/%27/', // ' |
|
176 | - '/%28/', // ( |
|
177 | - '/%29/', // ) |
|
178 | - '/%2C/', // , |
|
179 | - '/%2F/', // / |
|
180 | - '/%3A/', // : |
|
181 | - '/%3B/', // ; |
|
182 | - '/%3C/', // < |
|
183 | - '/%3D/', // = |
|
184 | - '/%3E/', // > |
|
185 | - '/%3F/', // ? |
|
186 | - '/%40/', // @ |
|
187 | - '/%5B/', // [ |
|
188 | - '/%5C/', // \ |
|
189 | - '/%5D/', // ] |
|
190 | - '/%5E/', // ^ |
|
191 | - '/%7B/', // { |
|
192 | - '/%7C/', // | |
|
193 | - '/%7D/', // } |
|
194 | - '/%7E/', // ~ |
|
195 | - "/\./" // . |
|
196 | - ); |
|
197 | - $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
198 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
199 | - |
|
200 | - // Transformation des caract�res accentu�s |
|
201 | - $pattern = array( |
|
202 | - '/%B0/', // ° |
|
203 | - '/%E8/', // è |
|
204 | - '/%E9/', // é |
|
205 | - '/%EA/', // ê |
|
206 | - '/%EB/', // ë |
|
207 | - '/%E7/', // ç |
|
208 | - '/%E0/', // à |
|
209 | - '/%E2/', // â |
|
210 | - '/%E4/', // ä |
|
211 | - '/%EE/', // î |
|
212 | - '/%EF/', // ï |
|
213 | - '/%F9/', // ù |
|
214 | - '/%FC/', // ü |
|
215 | - '/%FB/', // û |
|
216 | - '/%F4/', // ô |
|
217 | - '/%F6/', // ö |
|
218 | - ); |
|
219 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
220 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
221 | - |
|
222 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
223 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
224 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
225 | - |
|
226 | - $title .= time(); |
|
227 | - $title = md5($title); |
|
228 | - |
|
229 | - return $title; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @return mixed |
|
234 | - */ |
|
235 | - public function getCustomtagName() |
|
236 | - { |
|
237 | - $ret = $this->getVar('name'); |
|
238 | - |
|
239 | - return $ret; |
|
240 | - } |
|
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', array( |
|
58 | + 'name' => 'textarea', |
|
59 | + 'form_editor' => 'textarea', |
|
60 | + 'form_rows' => 25 |
|
61 | + )); |
|
62 | + $this->setControl('language', array( |
|
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, array())) { |
|
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="' . |
|
136 | + SMARTOBJECT_URL . |
|
137 | + 'admin/customtag.php?op=clone&customtagid=' . |
|
138 | + $this->id() . |
|
139 | + '"><img src="' . |
|
140 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
141 | + 'editcopy.png" style="vertical-align: middle;" alt="' . |
|
142 | + _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
143 | + '" title="' . |
|
144 | + _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
145 | + '" /></a>'; |
|
146 | + |
|
147 | + return $ret; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param $var |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + public function emptyString($var) |
|
155 | + { |
|
156 | + return (strlen($var) > 0); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return mixed|string |
|
161 | + */ |
|
162 | + public function generateTag() |
|
163 | + { |
|
164 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
165 | + $title = xoops_substr($title, 0, 10, ''); |
|
166 | + // Transformation des ponctuations |
|
167 | + $pattern = array( |
|
168 | + '/%09/', // Tab |
|
169 | + '/%20/', // Space |
|
170 | + '/%21/', // ! |
|
171 | + '/%22/', // " |
|
172 | + '/%23/', // # |
|
173 | + '/%25/', // % |
|
174 | + '/%26/', // & |
|
175 | + '/%27/', // ' |
|
176 | + '/%28/', // ( |
|
177 | + '/%29/', // ) |
|
178 | + '/%2C/', // , |
|
179 | + '/%2F/', // / |
|
180 | + '/%3A/', // : |
|
181 | + '/%3B/', // ; |
|
182 | + '/%3C/', // < |
|
183 | + '/%3D/', // = |
|
184 | + '/%3E/', // > |
|
185 | + '/%3F/', // ? |
|
186 | + '/%40/', // @ |
|
187 | + '/%5B/', // [ |
|
188 | + '/%5C/', // \ |
|
189 | + '/%5D/', // ] |
|
190 | + '/%5E/', // ^ |
|
191 | + '/%7B/', // { |
|
192 | + '/%7C/', // | |
|
193 | + '/%7D/', // } |
|
194 | + '/%7E/', // ~ |
|
195 | + "/\./" // . |
|
196 | + ); |
|
197 | + $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
198 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
199 | + |
|
200 | + // Transformation des caract�res accentu�s |
|
201 | + $pattern = array( |
|
202 | + '/%B0/', // ° |
|
203 | + '/%E8/', // è |
|
204 | + '/%E9/', // é |
|
205 | + '/%EA/', // ê |
|
206 | + '/%EB/', // ë |
|
207 | + '/%E7/', // ç |
|
208 | + '/%E0/', // à |
|
209 | + '/%E2/', // â |
|
210 | + '/%E4/', // ä |
|
211 | + '/%EE/', // î |
|
212 | + '/%EF/', // ï |
|
213 | + '/%F9/', // ù |
|
214 | + '/%FC/', // ü |
|
215 | + '/%FB/', // û |
|
216 | + '/%F4/', // ô |
|
217 | + '/%F6/', // ö |
|
218 | + ); |
|
219 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
220 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
221 | + |
|
222 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
223 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
224 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
225 | + |
|
226 | + $title .= time(); |
|
227 | + $title = md5($title); |
|
228 | + |
|
229 | + return $title; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @return mixed |
|
234 | + */ |
|
235 | + public function getCustomtagName() |
|
236 | + { |
|
237 | + $ret = $this->getVar('name'); |
|
238 | + |
|
239 | + return $ret; |
|
240 | + } |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -245,48 +245,48 @@ discard block |
||
245 | 245 | */ |
246 | 246 | class SmartobjectCustomtagHandler extends SmartPersistableObjectHandler |
247 | 247 | { |
248 | - public $objects = false; |
|
249 | - |
|
250 | - /** |
|
251 | - * SmartobjectCustomtagHandler constructor. |
|
252 | - * @param XoopsDatabase $db |
|
253 | - */ |
|
254 | - public function __construct(XoopsDatabase $db) |
|
255 | - { |
|
256 | - parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
257 | - $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @return array|bool |
|
262 | - */ |
|
263 | - public function getCustomtagsByName() |
|
264 | - { |
|
265 | - if (!$this->objects) { |
|
266 | - global $xoopsConfig; |
|
267 | - |
|
268 | - $ret = array(); |
|
269 | - |
|
270 | - $criteria = new CriteriaCompo(); |
|
271 | - |
|
272 | - $criteria_language = new CriteriaCompo(); |
|
273 | - $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
274 | - $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
275 | - $criteria->add($criteria_language); |
|
276 | - |
|
277 | - $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
278 | - $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
279 | - |
|
280 | - if ($granted_ids && count($granted_ids) > 0) { |
|
281 | - $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
282 | - $customtagsObj = $this->getObjects($criteria, true); |
|
283 | - foreach ($customtagsObj as $customtagObj) { |
|
284 | - $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
285 | - } |
|
286 | - } |
|
287 | - $this->objects = $ret; |
|
288 | - } |
|
289 | - |
|
290 | - return $this->objects; |
|
291 | - } |
|
248 | + public $objects = false; |
|
249 | + |
|
250 | + /** |
|
251 | + * SmartobjectCustomtagHandler constructor. |
|
252 | + * @param XoopsDatabase $db |
|
253 | + */ |
|
254 | + public function __construct(XoopsDatabase $db) |
|
255 | + { |
|
256 | + parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
257 | + $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @return array|bool |
|
262 | + */ |
|
263 | + public function getCustomtagsByName() |
|
264 | + { |
|
265 | + if (!$this->objects) { |
|
266 | + global $xoopsConfig; |
|
267 | + |
|
268 | + $ret = array(); |
|
269 | + |
|
270 | + $criteria = new CriteriaCompo(); |
|
271 | + |
|
272 | + $criteria_language = new CriteriaCompo(); |
|
273 | + $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
274 | + $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
275 | + $criteria->add($criteria_language); |
|
276 | + |
|
277 | + $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
278 | + $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
279 | + |
|
280 | + if ($granted_ids && count($granted_ids) > 0) { |
|
281 | + $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
282 | + $customtagsObj = $this->getObjects($criteria, true); |
|
283 | + foreach ($customtagsObj as $customtagObj) { |
|
284 | + $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
285 | + } |
|
286 | + } |
|
287 | + $this->objects = $ret; |
|
288 | + } |
|
289 | + |
|
290 | + return $this->objects; |
|
291 | + } |
|
292 | 292 | } |
@@ -19,164 +19,164 @@ |
||
19 | 19 | */ |
20 | 20 | class SmartobjectAbout |
21 | 21 | { |
22 | - public $_lang_aboutTitle; |
|
23 | - public $_lang_author_info; |
|
24 | - public $_lang_developer_lead; |
|
25 | - public $_lang_developer_contributor; |
|
26 | - public $_lang_developer_website; |
|
27 | - public $_lang_developer_email; |
|
28 | - public $_lang_developer_credits; |
|
29 | - public $_lang_module_info; |
|
30 | - public $_lang_module_status; |
|
31 | - public $_lang_module_release_date; |
|
32 | - public $_lang_module_demo; |
|
33 | - public $_lang_module_support; |
|
34 | - public $_lang_module_bug; |
|
35 | - public $_lang_module_submit_bug; |
|
36 | - public $_lang_module_feature; |
|
37 | - public $_lang_module_submit_feature; |
|
38 | - public $_lang_module_disclaimer; |
|
39 | - public $_lang_author_word; |
|
40 | - public $_lang_version_history; |
|
41 | - public $_lang_by; |
|
42 | - public $_tpl; |
|
43 | - |
|
44 | - /** |
|
45 | - * SmartobjectAbout constructor. |
|
46 | - * @param string $aboutTitle |
|
47 | - */ |
|
48 | - public function __construct($aboutTitle = 'About') |
|
49 | - { |
|
50 | - global $xoopsModule, $xoopsConfig; |
|
51 | - |
|
52 | - $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
|
53 | - if (file_exists($fileName)) { |
|
54 | - include_once $fileName; |
|
55 | - } else { |
|
56 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
57 | - } |
|
58 | - $this->_aboutTitle = $aboutTitle; |
|
59 | - |
|
60 | - $this->_lang_developer_contributor = _CO_SOBJECT_DEVELOPER_CONTRIBUTOR; |
|
61 | - $this->_lang_developer_website = _CO_SOBJECT_DEVELOPER_WEBSITE; |
|
62 | - $this->_lang_developer_email = _CO_SOBJECT_DEVELOPER_EMAIL; |
|
63 | - $this->_lang_developer_credits = _CO_SOBJECT_DEVELOPER_CREDITS; |
|
64 | - $this->_lang_module_info = _CO_SOBJECT_MODULE_INFO; |
|
65 | - $this->_lang_module_status = _CO_SOBJECT_MODULE_STATUS; |
|
66 | - $this->_lang_module_release_date = _CO_SOBJECT_MODULE_RELEASE_DATE; |
|
67 | - $this->_lang_module_demo = _CO_SOBJECT_MODULE_DEMO; |
|
68 | - $this->_lang_module_support = _CO_SOBJECT_MODULE_SUPPORT; |
|
69 | - $this->_lang_module_bug = _CO_SOBJECT_MODULE_BUG; |
|
70 | - $this->_lang_module_submit_bug = _CO_SOBJECT_MODULE_SUBMIT_BUG; |
|
71 | - $this->_lang_module_feature = _CO_SOBJECT_MODULE_FEATURE; |
|
72 | - $this->_lang_module_submit_feature = _CO_SOBJECT_MODULE_SUBMIT_FEATURE; |
|
73 | - $this->_lang_module_disclaimer = _CO_SOBJECT_MODULE_DISCLAIMER; |
|
74 | - $this->_lang_author_word = _CO_SOBJECT_AUTHOR_WORD; |
|
75 | - $this->_lang_version_history = _CO_SOBJECT_VERSION_HISTORY; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param $value |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - public function sanitize($value) |
|
83 | - { |
|
84 | - $myts = MyTextSanitizer::getInstance(); |
|
85 | - |
|
86 | - return $myts->displayTarea($value, 1); |
|
87 | - } |
|
88 | - |
|
89 | - public function render() |
|
90 | - { |
|
91 | - /** |
|
92 | - * @todo move the output to a template |
|
93 | - * @todo make the output XHTML compliant |
|
94 | - */ |
|
95 | - |
|
96 | - $myts = MyTextSanitizer::getInstance(); |
|
97 | - |
|
98 | - global $xoopsModule; |
|
99 | - |
|
100 | - smart_xoops_cp_header(); |
|
101 | - |
|
102 | - $moduleHandler = xoops_getHandler('module'); |
|
103 | - $versioninfo = $moduleHandler->get($xoopsModule->getVar('mid')); |
|
104 | - |
|
105 | - //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
|
106 | - |
|
107 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
108 | - |
|
109 | - // --- |
|
110 | - // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
111 | - // $this->_tpl =& new XoopsTpl(); |
|
112 | - $this->_tpl = new XoopsTpl(); |
|
113 | - // --- |
|
114 | - |
|
115 | - $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
116 | - $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
|
117 | - $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
|
118 | - $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
|
119 | - $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version')); |
|
120 | - |
|
121 | - // Left headings... |
|
122 | - if ($versioninfo->getInfo('author_realname') !== '') { |
|
123 | - $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
124 | - } else { |
|
125 | - $author_name = $versioninfo->getInfo('author'); |
|
126 | - } |
|
127 | - $this->_tpl->assign('module_author_name', $author_name); |
|
128 | - |
|
129 | - $this->_tpl->assign('module_license', $versioninfo->getInfo('license')); |
|
130 | - |
|
131 | - $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits')); |
|
132 | - |
|
133 | - // Developers Information |
|
134 | - $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead')); |
|
135 | - $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor')); |
|
136 | - $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url')); |
|
137 | - $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name')); |
|
138 | - $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email')); |
|
139 | - |
|
140 | - $people = $versioninfo->getInfo('people'); |
|
141 | - if ($people) { |
|
142 | - $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map(array($this, 'sanitize'), $people['developers']) : false); |
|
143 | - $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map(array($this, 'sanitize'), $people['testers']) : false); |
|
144 | - $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map(array($this, 'sanitize'), $people['translators']) : false); |
|
145 | - $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map(array($this, 'sanitize'), $people['documenters']) : false); |
|
146 | - $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map(array($this, 'sanitize'), $people['other']) : false); |
|
147 | - } |
|
148 | - //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email')); |
|
149 | - |
|
150 | - // Module Development information |
|
151 | - $this->_tpl->assign('module_date', $versioninfo->getInfo('date')); |
|
152 | - $this->_tpl->assign('module_status', $versioninfo->getInfo('status')); |
|
153 | - $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url')); |
|
154 | - $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name')); |
|
155 | - $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url')); |
|
156 | - $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name')); |
|
157 | - $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug')); |
|
158 | - $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature')); |
|
159 | - |
|
160 | - // Warning |
|
161 | - $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning'))); |
|
162 | - |
|
163 | - // Author's note |
|
164 | - $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
|
165 | - |
|
166 | - // For changelog thanks to 3Dev |
|
167 | - global $xoopsModule; |
|
168 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
169 | - if (is_file($filename)) { |
|
170 | - $filesize = filesize($filename); |
|
171 | - $handle = fopen($filename, 'r'); |
|
172 | - $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
173 | - fclose($handle); |
|
174 | - } |
|
175 | - |
|
176 | - $this->_tpl->display('db:smartobject_about.tpl'); |
|
177 | - |
|
178 | - smart_modFooter(); |
|
179 | - |
|
180 | - xoops_cp_footer(); |
|
181 | - } |
|
22 | + public $_lang_aboutTitle; |
|
23 | + public $_lang_author_info; |
|
24 | + public $_lang_developer_lead; |
|
25 | + public $_lang_developer_contributor; |
|
26 | + public $_lang_developer_website; |
|
27 | + public $_lang_developer_email; |
|
28 | + public $_lang_developer_credits; |
|
29 | + public $_lang_module_info; |
|
30 | + public $_lang_module_status; |
|
31 | + public $_lang_module_release_date; |
|
32 | + public $_lang_module_demo; |
|
33 | + public $_lang_module_support; |
|
34 | + public $_lang_module_bug; |
|
35 | + public $_lang_module_submit_bug; |
|
36 | + public $_lang_module_feature; |
|
37 | + public $_lang_module_submit_feature; |
|
38 | + public $_lang_module_disclaimer; |
|
39 | + public $_lang_author_word; |
|
40 | + public $_lang_version_history; |
|
41 | + public $_lang_by; |
|
42 | + public $_tpl; |
|
43 | + |
|
44 | + /** |
|
45 | + * SmartobjectAbout constructor. |
|
46 | + * @param string $aboutTitle |
|
47 | + */ |
|
48 | + public function __construct($aboutTitle = 'About') |
|
49 | + { |
|
50 | + global $xoopsModule, $xoopsConfig; |
|
51 | + |
|
52 | + $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
|
53 | + if (file_exists($fileName)) { |
|
54 | + include_once $fileName; |
|
55 | + } else { |
|
56 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
57 | + } |
|
58 | + $this->_aboutTitle = $aboutTitle; |
|
59 | + |
|
60 | + $this->_lang_developer_contributor = _CO_SOBJECT_DEVELOPER_CONTRIBUTOR; |
|
61 | + $this->_lang_developer_website = _CO_SOBJECT_DEVELOPER_WEBSITE; |
|
62 | + $this->_lang_developer_email = _CO_SOBJECT_DEVELOPER_EMAIL; |
|
63 | + $this->_lang_developer_credits = _CO_SOBJECT_DEVELOPER_CREDITS; |
|
64 | + $this->_lang_module_info = _CO_SOBJECT_MODULE_INFO; |
|
65 | + $this->_lang_module_status = _CO_SOBJECT_MODULE_STATUS; |
|
66 | + $this->_lang_module_release_date = _CO_SOBJECT_MODULE_RELEASE_DATE; |
|
67 | + $this->_lang_module_demo = _CO_SOBJECT_MODULE_DEMO; |
|
68 | + $this->_lang_module_support = _CO_SOBJECT_MODULE_SUPPORT; |
|
69 | + $this->_lang_module_bug = _CO_SOBJECT_MODULE_BUG; |
|
70 | + $this->_lang_module_submit_bug = _CO_SOBJECT_MODULE_SUBMIT_BUG; |
|
71 | + $this->_lang_module_feature = _CO_SOBJECT_MODULE_FEATURE; |
|
72 | + $this->_lang_module_submit_feature = _CO_SOBJECT_MODULE_SUBMIT_FEATURE; |
|
73 | + $this->_lang_module_disclaimer = _CO_SOBJECT_MODULE_DISCLAIMER; |
|
74 | + $this->_lang_author_word = _CO_SOBJECT_AUTHOR_WORD; |
|
75 | + $this->_lang_version_history = _CO_SOBJECT_VERSION_HISTORY; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param $value |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + public function sanitize($value) |
|
83 | + { |
|
84 | + $myts = MyTextSanitizer::getInstance(); |
|
85 | + |
|
86 | + return $myts->displayTarea($value, 1); |
|
87 | + } |
|
88 | + |
|
89 | + public function render() |
|
90 | + { |
|
91 | + /** |
|
92 | + * @todo move the output to a template |
|
93 | + * @todo make the output XHTML compliant |
|
94 | + */ |
|
95 | + |
|
96 | + $myts = MyTextSanitizer::getInstance(); |
|
97 | + |
|
98 | + global $xoopsModule; |
|
99 | + |
|
100 | + smart_xoops_cp_header(); |
|
101 | + |
|
102 | + $moduleHandler = xoops_getHandler('module'); |
|
103 | + $versioninfo = $moduleHandler->get($xoopsModule->getVar('mid')); |
|
104 | + |
|
105 | + //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
|
106 | + |
|
107 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
108 | + |
|
109 | + // --- |
|
110 | + // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
111 | + // $this->_tpl =& new XoopsTpl(); |
|
112 | + $this->_tpl = new XoopsTpl(); |
|
113 | + // --- |
|
114 | + |
|
115 | + $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
116 | + $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
|
117 | + $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
|
118 | + $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
|
119 | + $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version')); |
|
120 | + |
|
121 | + // Left headings... |
|
122 | + if ($versioninfo->getInfo('author_realname') !== '') { |
|
123 | + $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
124 | + } else { |
|
125 | + $author_name = $versioninfo->getInfo('author'); |
|
126 | + } |
|
127 | + $this->_tpl->assign('module_author_name', $author_name); |
|
128 | + |
|
129 | + $this->_tpl->assign('module_license', $versioninfo->getInfo('license')); |
|
130 | + |
|
131 | + $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits')); |
|
132 | + |
|
133 | + // Developers Information |
|
134 | + $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead')); |
|
135 | + $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor')); |
|
136 | + $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url')); |
|
137 | + $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name')); |
|
138 | + $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email')); |
|
139 | + |
|
140 | + $people = $versioninfo->getInfo('people'); |
|
141 | + if ($people) { |
|
142 | + $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map(array($this, 'sanitize'), $people['developers']) : false); |
|
143 | + $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map(array($this, 'sanitize'), $people['testers']) : false); |
|
144 | + $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map(array($this, 'sanitize'), $people['translators']) : false); |
|
145 | + $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map(array($this, 'sanitize'), $people['documenters']) : false); |
|
146 | + $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map(array($this, 'sanitize'), $people['other']) : false); |
|
147 | + } |
|
148 | + //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email')); |
|
149 | + |
|
150 | + // Module Development information |
|
151 | + $this->_tpl->assign('module_date', $versioninfo->getInfo('date')); |
|
152 | + $this->_tpl->assign('module_status', $versioninfo->getInfo('status')); |
|
153 | + $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url')); |
|
154 | + $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name')); |
|
155 | + $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url')); |
|
156 | + $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name')); |
|
157 | + $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug')); |
|
158 | + $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature')); |
|
159 | + |
|
160 | + // Warning |
|
161 | + $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning'))); |
|
162 | + |
|
163 | + // Author's note |
|
164 | + $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
|
165 | + |
|
166 | + // For changelog thanks to 3Dev |
|
167 | + global $xoopsModule; |
|
168 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
169 | + if (is_file($filename)) { |
|
170 | + $filesize = filesize($filename); |
|
171 | + $handle = fopen($filename, 'r'); |
|
172 | + $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
173 | + fclose($handle); |
|
174 | + } |
|
175 | + |
|
176 | + $this->_tpl->display('db:smartobject_about.tpl'); |
|
177 | + |
|
178 | + smart_modFooter(); |
|
179 | + |
|
180 | + xoops_cp_footer(); |
|
181 | + } |
|
182 | 182 | } |