@@ -237,7 +237,7 @@ |
||
| 237 | 237 | * Creates a random number with a specified number of $digits |
| 238 | 238 | * |
| 239 | 239 | * @param int $digits number of digits |
| 240 | - * @return return int random number |
|
| 240 | + * @return string int random number |
|
| 241 | 241 | * @author xHelp Team |
| 242 | 242 | * |
| 243 | 243 | * @access public |
@@ -34,227 +34,227 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class SmartobjectMemberHandler extends XoopsMemberHandler |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * constructor |
|
| 39 | - * @param XoopsDatabase $db |
|
| 40 | - */ |
|
| 41 | - public function __construct(XoopsDatabase $db) |
|
| 42 | - { |
|
| 43 | - parent::__construct($db); |
|
| 44 | - $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * constructor |
|
| 39 | + * @param XoopsDatabase $db |
|
| 40 | + */ |
|
| 41 | + public function __construct(XoopsDatabase $db) |
|
| 42 | + { |
|
| 43 | + parent::__construct($db); |
|
| 44 | + $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param $userObj |
|
| 49 | - * @param bool $groups |
|
| 50 | - * @param bool $notifyUser |
|
| 51 | - * @param bool $password |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
| 55 | - { |
|
| 56 | - $email = $userObj->getVar('email'); |
|
| 57 | - if (!$userObj->getVar('email') || $email === '') { |
|
| 58 | - $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
| 47 | + /** |
|
| 48 | + * @param $userObj |
|
| 49 | + * @param bool $groups |
|
| 50 | + * @param bool $notifyUser |
|
| 51 | + * @param bool $password |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
| 55 | + { |
|
| 56 | + $email = $userObj->getVar('email'); |
|
| 57 | + if (!$userObj->getVar('email') || $email === '') { |
|
| 58 | + $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
| 59 | 59 | |
| 60 | - return false; |
|
| 61 | - } |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $password = $userObj->getVar('pass'); |
|
| 64 | - // randomly generating the password if not already set |
|
| 65 | - if ('' === $password) { |
|
| 66 | - $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
| 67 | - } |
|
| 68 | - $userObj->setVar('pass', md5($password)); |
|
| 63 | + $password = $userObj->getVar('pass'); |
|
| 64 | + // randomly generating the password if not already set |
|
| 65 | + if ('' === $password) { |
|
| 66 | + $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
| 67 | + } |
|
| 68 | + $userObj->setVar('pass', md5($password)); |
|
| 69 | 69 | |
| 70 | - // if no username is set, let's generate one |
|
| 71 | - $unamecount = 20; |
|
| 72 | - $uname = $userObj->getVar('uname'); |
|
| 73 | - if (!$uname || $uname === '') { |
|
| 74 | - $usernames = $this->genUserNames($email, $unamecount); |
|
| 75 | - $newuser = false; |
|
| 76 | - $i = 0; |
|
| 77 | - while ($newuser === false) { |
|
| 78 | - $crit = new Criteria('uname', $usernames[$i]); |
|
| 79 | - $count = $this->getUserCount($crit); |
|
| 80 | - if ($count == 0) { |
|
| 81 | - $newuser = true; |
|
| 82 | - } else { |
|
| 83 | - //Move to next username |
|
| 84 | - ++$i; |
|
| 85 | - if ($i == $unamecount) { |
|
| 86 | - //Get next batch of usernames to try, reset counter |
|
| 87 | - $usernames = $this->genUserNames($email, $unamecount); |
|
| 88 | - $i = 0; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 70 | + // if no username is set, let's generate one |
|
| 71 | + $unamecount = 20; |
|
| 72 | + $uname = $userObj->getVar('uname'); |
|
| 73 | + if (!$uname || $uname === '') { |
|
| 74 | + $usernames = $this->genUserNames($email, $unamecount); |
|
| 75 | + $newuser = false; |
|
| 76 | + $i = 0; |
|
| 77 | + while ($newuser === false) { |
|
| 78 | + $crit = new Criteria('uname', $usernames[$i]); |
|
| 79 | + $count = $this->getUserCount($crit); |
|
| 80 | + if ($count == 0) { |
|
| 81 | + $newuser = true; |
|
| 82 | + } else { |
|
| 83 | + //Move to next username |
|
| 84 | + ++$i; |
|
| 85 | + if ($i == $unamecount) { |
|
| 86 | + //Get next batch of usernames to try, reset counter |
|
| 87 | + $usernames = $this->genUserNames($email, $unamecount); |
|
| 88 | + $i = 0; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - global $xoopsConfig; |
|
| 94 | + global $xoopsConfig; |
|
| 95 | 95 | |
| 96 | - $configHandler = xoops_getHandler('config'); |
|
| 97 | - $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
| 98 | - switch ($xoopsConfigUser['activation_type']) { |
|
| 99 | - case 0: |
|
| 100 | - $level = 0; |
|
| 101 | - $mailtemplate = 'smartmail_activate_user.tpl'; |
|
| 102 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
| 103 | - break; |
|
| 104 | - case 1: |
|
| 105 | - $level = 1; |
|
| 106 | - $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
| 107 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
| 108 | - break; |
|
| 109 | - case 2: |
|
| 110 | - default: |
|
| 111 | - $level = 0; |
|
| 112 | - $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
| 113 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
| 114 | - } |
|
| 96 | + $configHandler = xoops_getHandler('config'); |
|
| 97 | + $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
| 98 | + switch ($xoopsConfigUser['activation_type']) { |
|
| 99 | + case 0: |
|
| 100 | + $level = 0; |
|
| 101 | + $mailtemplate = 'smartmail_activate_user.tpl'; |
|
| 102 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
| 103 | + break; |
|
| 104 | + case 1: |
|
| 105 | + $level = 1; |
|
| 106 | + $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
| 107 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
| 108 | + break; |
|
| 109 | + case 2: |
|
| 110 | + default: |
|
| 111 | + $level = 0; |
|
| 112 | + $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
| 113 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - $userObj->setVar('uname', $usernames[$i]); |
|
| 117 | - $userObj->setVar('user_avatar', 'blank.gif'); |
|
| 118 | - $userObj->setVar('user_regdate', time()); |
|
| 119 | - $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
| 120 | - $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
| 121 | - $userObj->setVar('actkey', $actkey); |
|
| 122 | - $userObj->setVar('email', $email); |
|
| 123 | - $userObj->setVar('notify_method', 2); |
|
| 124 | - $userObj->setVar('level', $userObj); |
|
| 116 | + $userObj->setVar('uname', $usernames[$i]); |
|
| 117 | + $userObj->setVar('user_avatar', 'blank.gif'); |
|
| 118 | + $userObj->setVar('user_regdate', time()); |
|
| 119 | + $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
| 120 | + $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
| 121 | + $userObj->setVar('actkey', $actkey); |
|
| 122 | + $userObj->setVar('email', $email); |
|
| 123 | + $userObj->setVar('notify_method', 2); |
|
| 124 | + $userObj->setVar('level', $userObj); |
|
| 125 | 125 | |
| 126 | - if ($this->insertUser($userObj)) { |
|
| 126 | + if ($this->insertUser($userObj)) { |
|
| 127 | 127 | |
| 128 | - // if $groups=false, Add the user to Registered Users group |
|
| 129 | - if (!$groups) { |
|
| 130 | - $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
| 131 | - } else { |
|
| 132 | - foreach ($groups as $groupid) { |
|
| 133 | - $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } else { |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 128 | + // if $groups=false, Add the user to Registered Users group |
|
| 129 | + if (!$groups) { |
|
| 130 | + $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
| 131 | + } else { |
|
| 132 | + foreach ($groups as $groupid) { |
|
| 133 | + $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } else { |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - if ($notifyUser) { |
|
| 141 | - // send some notifications |
|
| 142 | - $xoopsMailer = xoops_getMailer(); |
|
| 143 | - $xoopsMailer->useMail(); |
|
| 144 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 145 | - $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
| 146 | - $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
| 147 | - $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
| 148 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
| 149 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 150 | - $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
| 151 | - $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
| 152 | - $xoopsMailer->setToUsers($userObj); |
|
| 153 | - $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
| 154 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
| 155 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
| 140 | + if ($notifyUser) { |
|
| 141 | + // send some notifications |
|
| 142 | + $xoopsMailer = xoops_getMailer(); |
|
| 143 | + $xoopsMailer->useMail(); |
|
| 144 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 145 | + $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
| 146 | + $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
| 147 | + $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
| 148 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
| 149 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 150 | + $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
| 151 | + $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
| 152 | + $xoopsMailer->setToUsers($userObj); |
|
| 153 | + $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
| 154 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
| 155 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
| 156 | 156 | |
| 157 | - if (!$xoopsMailer->send(true)) { |
|
| 158 | - /** |
|
| 159 | - * @todo trap error if email was not sent |
|
| 160 | - */ |
|
| 161 | - $xoopsMailer->getErrors(true); |
|
| 162 | - } |
|
| 163 | - } |
|
| 157 | + if (!$xoopsMailer->send(true)) { |
|
| 158 | + /** |
|
| 159 | + * @todo trap error if email was not sent |
|
| 160 | + */ |
|
| 161 | + $xoopsMailer->getErrors(true); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - return true; |
|
| 166 | - } |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Generates an array of usernames |
|
| 170 | - * |
|
| 171 | - * @param string $email email of user |
|
| 172 | - * @param int $count number of names to generate |
|
| 173 | - * @return array $names |
|
| 174 | - * @internal param string $name name of user |
|
| 175 | - * @author xHelp Team |
|
| 176 | - * |
|
| 177 | - * @access public |
|
| 178 | - */ |
|
| 179 | - public function genUserNames($email, $count = 20) |
|
| 180 | - { |
|
| 181 | - $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
| 168 | + /** |
|
| 169 | + * Generates an array of usernames |
|
| 170 | + * |
|
| 171 | + * @param string $email email of user |
|
| 172 | + * @param int $count number of names to generate |
|
| 173 | + * @return array $names |
|
| 174 | + * @internal param string $name name of user |
|
| 175 | + * @author xHelp Team |
|
| 176 | + * |
|
| 177 | + * @access public |
|
| 178 | + */ |
|
| 179 | + public function genUserNames($email, $count = 20) |
|
| 180 | + { |
|
| 181 | + $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
| 182 | 182 | |
| 183 | - $names = array(); |
|
| 184 | - $userid = explode('@', $email); |
|
| 183 | + $names = array(); |
|
| 184 | + $userid = explode('@', $email); |
|
| 185 | 185 | |
| 186 | - $basename = ''; |
|
| 187 | - $hasbasename = false; |
|
| 188 | - $emailname = $userid[0]; |
|
| 186 | + $basename = ''; |
|
| 187 | + $hasbasename = false; |
|
| 188 | + $emailname = $userid[0]; |
|
| 189 | 189 | |
| 190 | - $names[] = $emailname; |
|
| 190 | + $names[] = $emailname; |
|
| 191 | 191 | |
| 192 | - if (strlen($name) > 0) { |
|
| 193 | - $name = explode(' ', trim($name)); |
|
| 194 | - if (count($name) > 1) { |
|
| 195 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 196 | - } else { |
|
| 197 | - $basename = strtolower($name[0]); |
|
| 198 | - } |
|
| 199 | - $basename = xoops_substr($basename, 0, 60, ''); |
|
| 200 | - //Prevent Duplication of Email Username and Name |
|
| 201 | - if (!in_array($basename, $names)) { |
|
| 202 | - $names[] = $basename; |
|
| 203 | - $hasbasename = true; |
|
| 204 | - } |
|
| 205 | - } |
|
| 192 | + if (strlen($name) > 0) { |
|
| 193 | + $name = explode(' ', trim($name)); |
|
| 194 | + if (count($name) > 1) { |
|
| 195 | + $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 196 | + } else { |
|
| 197 | + $basename = strtolower($name[0]); |
|
| 198 | + } |
|
| 199 | + $basename = xoops_substr($basename, 0, 60, ''); |
|
| 200 | + //Prevent Duplication of Email Username and Name |
|
| 201 | + if (!in_array($basename, $names)) { |
|
| 202 | + $names[] = $basename; |
|
| 203 | + $hasbasename = true; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $i = count($names); |
|
| 208 | - $onbasename = 1; |
|
| 209 | - while ($i < $count) { |
|
| 210 | - $num = $this->genRandNumber(); |
|
| 211 | - if ($onbasename < 0 && $hasbasename) { |
|
| 212 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 213 | - } else { |
|
| 214 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 215 | - } |
|
| 216 | - $i = count($names); |
|
| 217 | - $onbasename = ~$onbasename; |
|
| 218 | - $num = ''; |
|
| 219 | - } |
|
| 207 | + $i = count($names); |
|
| 208 | + $onbasename = 1; |
|
| 209 | + while ($i < $count) { |
|
| 210 | + $num = $this->genRandNumber(); |
|
| 211 | + if ($onbasename < 0 && $hasbasename) { |
|
| 212 | + $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 213 | + } else { |
|
| 214 | + $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 215 | + } |
|
| 216 | + $i = count($names); |
|
| 217 | + $onbasename = ~$onbasename; |
|
| 218 | + $num = ''; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - return $names; |
|
| 222 | - } |
|
| 221 | + return $names; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Creates a random number with a specified number of $digits |
|
| 226 | - * |
|
| 227 | - * @param int $digits number of digits |
|
| 228 | - * @return return int random number |
|
| 229 | - * @author xHelp Team |
|
| 230 | - * |
|
| 231 | - * @access public |
|
| 232 | - */ |
|
| 233 | - public function genRandNumber($digits = 2) |
|
| 234 | - { |
|
| 235 | - $this->initRand(); |
|
| 236 | - $tmp = array(); |
|
| 224 | + /** |
|
| 225 | + * Creates a random number with a specified number of $digits |
|
| 226 | + * |
|
| 227 | + * @param int $digits number of digits |
|
| 228 | + * @return return int random number |
|
| 229 | + * @author xHelp Team |
|
| 230 | + * |
|
| 231 | + * @access public |
|
| 232 | + */ |
|
| 233 | + public function genRandNumber($digits = 2) |
|
| 234 | + { |
|
| 235 | + $this->initRand(); |
|
| 236 | + $tmp = array(); |
|
| 237 | 237 | |
| 238 | - for ($i = 0; $i < $digits; ++$i) { |
|
| 239 | - $tmp[$i] = (mt_rand() % 9); |
|
| 240 | - } |
|
| 238 | + for ($i = 0; $i < $digits; ++$i) { |
|
| 239 | + $tmp[$i] = (mt_rand() % 9); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return implode('', $tmp); |
|
| 243 | - } |
|
| 242 | + return implode('', $tmp); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Gives the random number generator a seed to start from |
|
| 247 | - * |
|
| 248 | - * @return void |
|
| 249 | - * |
|
| 250 | - * @access public |
|
| 251 | - */ |
|
| 252 | - public function initRand() |
|
| 253 | - { |
|
| 254 | - static $randCalled = false; |
|
| 255 | - if (!$randCalled) { |
|
| 256 | - mt_srand((double)microtime() * 1000000); |
|
| 257 | - $randCalled = true; |
|
| 258 | - } |
|
| 259 | - } |
|
| 245 | + /** |
|
| 246 | + * Gives the random number generator a seed to start from |
|
| 247 | + * |
|
| 248 | + * @return void |
|
| 249 | + * |
|
| 250 | + * @access public |
|
| 251 | + */ |
|
| 252 | + public function initRand() |
|
| 253 | + { |
|
| 254 | + static $randCalled = false; |
|
| 255 | + if (!$randCalled) { |
|
| 256 | + mt_srand((double)microtime() * 1000000); |
|
| 257 | + $randCalled = true; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | } |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
| 21 | -require_once XOOPS_ROOT_PATH . '/kernel/user.php'; |
|
| 22 | -require_once XOOPS_ROOT_PATH . '/kernel/group.php'; |
|
| 23 | -require_once XOOPS_ROOT_PATH . '/kernel/member.php'; |
|
| 21 | +require_once XOOPS_ROOT_PATH.'/kernel/user.php'; |
|
| 22 | +require_once XOOPS_ROOT_PATH.'/kernel/group.php'; |
|
| 23 | +require_once XOOPS_ROOT_PATH.'/kernel/member.php'; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * XOOPS member handler class. |
@@ -141,12 +141,12 @@ discard block |
||
| 141 | 141 | // send some notifications |
| 142 | 142 | $xoopsMailer = xoops_getMailer(); |
| 143 | 143 | $xoopsMailer->useMail(); |
| 144 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 144 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/mail_template'); |
|
| 145 | 145 | $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
| 146 | 146 | $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
| 147 | 147 | $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
| 148 | 148 | $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
| 149 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 149 | + $xoopsMailer->assign('SITEURL', XOOPS_URL.'/'); |
|
| 150 | 150 | $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
| 151 | 151 | $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
| 152 | 152 | $xoopsMailer->setToUsers($userObj); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | if (strlen($name) > 0) { |
| 193 | 193 | $name = explode(' ', trim($name)); |
| 194 | 194 | if (count($name) > 1) { |
| 195 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 195 | + $basename = strtolower(substr($name[0], 0, 1).$name[count($name) - 1]); |
|
| 196 | 196 | } else { |
| 197 | 197 | $basename = strtolower($name[0]); |
| 198 | 198 | } |
@@ -209,9 +209,9 @@ discard block |
||
| 209 | 209 | while ($i < $count) { |
| 210 | 210 | $num = $this->genRandNumber(); |
| 211 | 211 | if ($onbasename < 0 && $hasbasename) { |
| 212 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 212 | + $names[] = xoops_substr($basename, 0, 58, '').$num; |
|
| 213 | 213 | } else { |
| 214 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 214 | + $names[] = xoops_substr($emailname, 0, 58, '').$num; |
|
| 215 | 215 | } |
| 216 | 216 | $i = count($names); |
| 217 | 217 | $onbasename = ~$onbasename; |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | static $randCalled = false; |
| 255 | 255 | if (!$randCalled) { |
| 256 | - mt_srand((double)microtime() * 1000000); |
|
| 256 | + mt_srand((double) microtime() * 1000000); |
|
| 257 | 257 | $randCalled = true; |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
| 179 | - * @param $key |
|
| 179 | + * @param string $key |
|
| 180 | 180 | * @param $data_type |
| 181 | 181 | * @param bool $itemName |
| 182 | 182 | * @param string $form_caption |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
| 213 | 213 | * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
| 214 | 214 | * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
| 215 | - * @param mixed $value default value of this variable |
|
| 215 | + * @param string|false $value default value of this variable |
|
| 216 | 216 | */ |
| 217 | 217 | public function quickInitVar( |
| 218 | 218 | $key, |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | - * @param $varname |
|
| 230 | + * @param string $varname |
|
| 231 | 231 | * @param bool $displayOnForm |
| 232 | 232 | * @param string $default |
| 233 | 233 | */ |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | /** |
| 490 | 490 | * add an error |
| 491 | 491 | * |
| 492 | - * @param $err_str |
|
| 492 | + * @param string $err_str |
|
| 493 | 493 | * @param bool $prefix |
| 494 | 494 | * @internal param string $value error to add |
| 495 | 495 | * @access public |
@@ -751,8 +751,8 @@ discard block |
||
| 751 | 751 | |
| 752 | 752 | /** |
| 753 | 753 | * @param $key |
| 754 | - * @param $info |
|
| 755 | - * @param $value |
|
| 754 | + * @param string $info |
|
| 755 | + * @param boolean $value |
|
| 756 | 756 | */ |
| 757 | 757 | public function setVarInfo($key, $info, $value) |
| 758 | 758 | { |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | /** |
| 763 | - * @param $key |
|
| 763 | + * @param string $key |
|
| 764 | 764 | * @param bool $editor |
| 765 | 765 | * @return string |
| 766 | 766 | */ |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | * @access public |
| 940 | 940 | * @param string $key key of the object's variable to be returned |
| 941 | 941 | * @param string $format format to use for the output |
| 942 | - * @return mixed formatted value of the variable |
|
| 942 | + * @return string formatted value of the variable |
|
| 943 | 943 | */ |
| 944 | 944 | public function getVar($key, $format = 's') |
| 945 | 945 | { |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | /** |
| 1252 | - * @param $key |
|
| 1252 | + * @param string $key |
|
| 1253 | 1253 | */ |
| 1254 | 1254 | public function hideFieldFromForm($key) |
| 1255 | 1255 | { |
@@ -17,31 +17,31 @@ discard block |
||
| 17 | 17 | require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
| 18 | 18 | |
| 19 | 19 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
| 20 | - define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
| 20 | + define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
| 21 | 21 | } |
| 22 | 22 | if (!defined('XOBJ_DTYPE_CURRENCY')) { |
| 23 | - define('XOBJ_DTYPE_CURRENCY', 200); |
|
| 23 | + define('XOBJ_DTYPE_CURRENCY', 200); |
|
| 24 | 24 | } |
| 25 | 25 | if (!defined('XOBJ_DTYPE_FLOAT')) { |
| 26 | - define('XOBJ_DTYPE_FLOAT', 201); |
|
| 26 | + define('XOBJ_DTYPE_FLOAT', 201); |
|
| 27 | 27 | } |
| 28 | 28 | if (!defined('XOBJ_DTYPE_TIME_ONLY')) { |
| 29 | - define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
| 29 | + define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('XOBJ_DTYPE_URLLINK')) { |
| 32 | - define('XOBJ_DTYPE_URLLINK', 203); |
|
| 32 | + define('XOBJ_DTYPE_URLLINK', 203); |
|
| 33 | 33 | } |
| 34 | 34 | if (!defined('XOBJ_DTYPE_FILE')) { |
| 35 | - define('XOBJ_DTYPE_FILE', 204); |
|
| 35 | + define('XOBJ_DTYPE_FILE', 204); |
|
| 36 | 36 | } |
| 37 | 37 | if (!defined('XOBJ_DTYPE_IMAGE')) { |
| 38 | - define('XOBJ_DTYPE_IMAGE', 205); |
|
| 38 | + define('XOBJ_DTYPE_IMAGE', 205); |
|
| 39 | 39 | } |
| 40 | 40 | if (!defined('XOBJ_DTYPE_FORM_SECTION')) { |
| 41 | - define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
| 41 | + define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
| 42 | 42 | } |
| 43 | 43 | if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) { |
| 44 | - define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
| 44 | + define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -55,1399 +55,1399 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | class SmartObject extends XoopsObject |
| 57 | 57 | { |
| 58 | - public $_image_path; |
|
| 59 | - public $_image_url; |
|
| 60 | - |
|
| 61 | - public $seoEnabled = false; |
|
| 62 | - public $titleField; |
|
| 63 | - public $summaryField = false; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Reference to the handler managing this object |
|
| 67 | - * |
|
| 68 | - * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
| 69 | - */ |
|
| 70 | - public $handler; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * References to control objects, managing the form fields of this object |
|
| 74 | - */ |
|
| 75 | - public $controls = array(); |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * SmartObject constructor. |
|
| 79 | - * @param $handler |
|
| 80 | - */ |
|
| 81 | - public function __construct($handler) |
|
| 82 | - { |
|
| 83 | - $this->handler = $handler; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Checks if the user has a specific access on this object |
|
| 88 | - * |
|
| 89 | - * @param $perm_name |
|
| 90 | - * @return bool: TRUE if user has access, false if not |
|
| 91 | - * @internal param string $gperm_name name of the permission to test |
|
| 92 | - */ |
|
| 93 | - public function accessGranted($perm_name) |
|
| 94 | - { |
|
| 95 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
| 96 | - |
|
| 97 | - return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param $section_name |
|
| 102 | - * @param bool $value |
|
| 103 | - * @param bool $hide |
|
| 104 | - */ |
|
| 105 | - public function addFormSection($section_name, $value = false, $hide = false) |
|
| 106 | - { |
|
| 107 | - $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
| 108 | - $this->vars[$section_name]['hide'] = $hide; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param $section_name |
|
| 113 | - */ |
|
| 114 | - public function closeSection($section_name) |
|
| 115 | - { |
|
| 116 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * |
|
| 121 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
| 122 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
| 123 | - * @param mixed $value default value of this variable |
|
| 124 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
| 125 | - * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
| 126 | - * @param string $options does this data have any select options? |
|
| 127 | - * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
| 128 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
| 129 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
| 130 | - * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
| 131 | - * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
| 132 | - * @param bool $displayOnForm |
|
| 133 | - */ |
|
| 134 | - public function initVar( |
|
| 135 | - $key, |
|
| 136 | - $data_type, |
|
| 137 | - $value = null, |
|
| 138 | - $required = false, |
|
| 139 | - $maxlength = null, |
|
| 140 | - $options = '', |
|
| 141 | - $multilingual = false, |
|
| 142 | - $form_caption = '', |
|
| 143 | - $form_dsc = '', |
|
| 144 | - $sortby = false, |
|
| 145 | - $persistent = true, |
|
| 146 | - $displayOnForm = true |
|
| 147 | - ) { |
|
| 148 | - //url_ is reserved for files. |
|
| 149 | - if (0 === strpos($key, 'url_')) { |
|
| 150 | - trigger_error("Cannot use variable starting with 'url_'."); |
|
| 151 | - } |
|
| 152 | - parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
| 153 | - if ($this->handler && (!$form_caption || $form_caption === '')) { |
|
| 154 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
| 155 | - if (defined($dyn_form_caption)) { |
|
| 156 | - $form_caption = constant($dyn_form_caption); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - if ($this->handler && (!$form_dsc || $form_dsc === '')) { |
|
| 160 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
| 161 | - if (defined($dyn_form_dsc)) { |
|
| 162 | - $form_dsc = constant($dyn_form_dsc); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $this->vars[$key] = array_merge($this->vars[$key], array( |
|
| 167 | - 'multilingual' => $multilingual, |
|
| 168 | - 'form_caption' => $form_caption, |
|
| 169 | - 'form_dsc' => $form_dsc, |
|
| 170 | - 'sortby' => $sortby, |
|
| 171 | - 'persistent' => $persistent, |
|
| 172 | - 'displayOnForm' => $displayOnForm, |
|
| 173 | - 'displayOnSingleView' => true, |
|
| 174 | - 'readonly' => false |
|
| 175 | - )); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @param $key |
|
| 180 | - * @param $data_type |
|
| 181 | - * @param bool $itemName |
|
| 182 | - * @param string $form_caption |
|
| 183 | - * @param bool $sortby |
|
| 184 | - * @param string $value |
|
| 185 | - * @param bool $displayOnForm |
|
| 186 | - * @param bool $required |
|
| 187 | - */ |
|
| 188 | - public function initNonPersistableVar( |
|
| 189 | - $key, |
|
| 190 | - $data_type, |
|
| 191 | - $itemName = false, |
|
| 192 | - $form_caption = '', |
|
| 193 | - $sortby = false, |
|
| 194 | - $value = '', |
|
| 195 | - $displayOnForm = false, |
|
| 196 | - $required = false |
|
| 197 | - ) { |
|
| 198 | - $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
| 199 | - $this->vars[$key]['itemName'] = $itemName; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Quickly initiate a var |
|
| 204 | - * |
|
| 205 | - * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
| 206 | - * |
|
| 207 | - * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
| 208 | - * - all other vars are NULL or '' depending of the parameter |
|
| 209 | - * |
|
| 210 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
| 211 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
| 212 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
| 213 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
| 214 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
| 215 | - * @param mixed $value default value of this variable |
|
| 216 | - */ |
|
| 217 | - public function quickInitVar( |
|
| 218 | - $key, |
|
| 219 | - $data_type, |
|
| 220 | - $required = false, |
|
| 221 | - $form_caption = '', |
|
| 222 | - $form_dsc = '', |
|
| 223 | - $value = null |
|
| 224 | - ) { |
|
| 225 | - $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null; |
|
| 226 | - $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @param $varname |
|
| 231 | - * @param bool $displayOnForm |
|
| 232 | - * @param string $default |
|
| 233 | - */ |
|
| 234 | - public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
| 235 | - { |
|
| 236 | - switch ($varname) { |
|
| 237 | - case 'dohtml': |
|
| 238 | - $value = $default !== 'notdefined' ? $default : true; |
|
| 239 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 240 | - $this->setControl($varname, 'yesno'); |
|
| 241 | - break; |
|
| 242 | - |
|
| 243 | - case 'dobr': |
|
| 244 | - $value = ($default === 'notdefined') ? true : $default; |
|
| 245 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 246 | - $this->setControl($varname, 'yesno'); |
|
| 247 | - break; |
|
| 248 | - |
|
| 249 | - case 'doimage': |
|
| 250 | - $value = $default !== 'notdefined' ? $default : true; |
|
| 251 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 252 | - $this->setControl($varname, 'yesno'); |
|
| 253 | - break; |
|
| 254 | - |
|
| 255 | - case 'dosmiley': |
|
| 256 | - $value = $default !== 'notdefined' ? $default : true; |
|
| 257 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 258 | - $this->setControl($varname, 'yesno'); |
|
| 259 | - break; |
|
| 260 | - |
|
| 261 | - case 'doxcode': |
|
| 262 | - $value = $default !== 'notdefined' ? $default : true; |
|
| 263 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 264 | - $this->setControl($varname, 'yesno'); |
|
| 265 | - break; |
|
| 266 | - |
|
| 267 | - case 'meta_keywords': |
|
| 268 | - $value = $default !== 'notdefined' ? $default : ''; |
|
| 269 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
| 270 | - $this->setControl('meta_keywords', array( |
|
| 271 | - 'name' => 'textarea', |
|
| 272 | - 'form_editor' => 'textarea' |
|
| 273 | - )); |
|
| 274 | - break; |
|
| 275 | - |
|
| 276 | - case 'meta_description': |
|
| 277 | - $value = $default !== 'notdefined' ? $default : ''; |
|
| 278 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
| 279 | - $this->setControl('meta_description', array( |
|
| 280 | - 'name' => 'textarea', |
|
| 281 | - 'form_editor' => 'textarea' |
|
| 282 | - )); |
|
| 283 | - break; |
|
| 284 | - |
|
| 285 | - case 'short_url': |
|
| 286 | - $value = $default !== 'notdefined' ? $default : ''; |
|
| 287 | - $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
| 288 | - break; |
|
| 289 | - |
|
| 290 | - case 'hierarchy_path': |
|
| 291 | - $value = $default !== 'notdefined' ? $default : ''; |
|
| 292 | - $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
| 293 | - break; |
|
| 294 | - |
|
| 295 | - case 'counter': |
|
| 296 | - $value = $default !== 'notdefined' ? $default : 0; |
|
| 297 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 298 | - break; |
|
| 299 | - |
|
| 300 | - case 'weight': |
|
| 301 | - $value = $default !== 'notdefined' ? $default : 0; |
|
| 302 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
| 303 | - break; |
|
| 304 | - case 'custom_css': |
|
| 305 | - $value = $default !== 'notdefined' ? $default : ''; |
|
| 306 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
| 307 | - $this->setControl('custom_css', array( |
|
| 308 | - 'name' => 'textarea', |
|
| 309 | - 'form_editor' => 'textarea' |
|
| 310 | - )); |
|
| 311 | - break; |
|
| 312 | - } |
|
| 313 | - $this->hideFieldFromSingleView($varname); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Set control information for an instance variable |
|
| 318 | - * |
|
| 319 | - * The $options parameter can be a string or an array. Using a string |
|
| 320 | - * is the quickest way: |
|
| 321 | - * |
|
| 322 | - * $this->setControl('date', 'date_time'); |
|
| 323 | - * |
|
| 324 | - * This will create a date and time selectbox for the 'date' var on the |
|
| 325 | - * form to edit or create this item. |
|
| 326 | - * |
|
| 327 | - * Here are the currently supported controls: |
|
| 328 | - * |
|
| 329 | - * - color |
|
| 330 | - * - country |
|
| 331 | - * - date_time |
|
| 332 | - * - date |
|
| 333 | ||
| 334 | - * - group |
|
| 335 | - * - group_multi |
|
| 336 | - * - image |
|
| 337 | - * - imageupload |
|
| 338 | - * - label |
|
| 339 | - * - language |
|
| 340 | - * - parentcategory |
|
| 341 | - * - password |
|
| 342 | - * - select_multi |
|
| 343 | - * - select |
|
| 344 | - * - text |
|
| 345 | - * - textarea |
|
| 346 | - * - theme |
|
| 347 | - * - theme_multi |
|
| 348 | - * - timezone |
|
| 349 | - * - user |
|
| 350 | - * - user_multi |
|
| 351 | - * - yesno |
|
| 352 | - * |
|
| 353 | - * Now, using an array as $options, you can customize what information to |
|
| 354 | - * use in the control. For example, if one needs to display a select box for |
|
| 355 | - * the user to choose the status of an item. We only need to tell SmartObject |
|
| 356 | - * what method to execute within what handler to retreive the options of the |
|
| 357 | - * selectbox. |
|
| 358 | - * |
|
| 359 | - * $this->setControl('status', array('name' => false, |
|
| 360 | - * 'itemHandler' => 'item', |
|
| 361 | - * 'method' => 'getStatus', |
|
| 362 | - * 'module' => 'smartshop')); |
|
| 363 | - * |
|
| 364 | - * In this example, the array elements are the following: |
|
| 365 | - * - name: false, as we don't need to set a special control here. |
|
| 366 | - * we will use the default control related to the object type (defined in initVar) |
|
| 367 | - * - itemHandler: name of the object for which we will use the handler |
|
| 368 | - * - method: name of the method of this handler that we will execute |
|
| 369 | - * - module: name of the module from wich the handler is |
|
| 370 | - * |
|
| 371 | - * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
| 372 | - * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
| 373 | - * |
|
| 374 | - * Another example of the use of $options as an array is for TextArea: |
|
| 375 | - * |
|
| 376 | - * $this->setControl('body', array('name' => 'textarea', |
|
| 377 | - * 'form_editor' => 'default')); |
|
| 378 | - * |
|
| 379 | - * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
| 380 | - * the 'default' editor, providing it is defined in the module |
|
| 381 | - * preferences: $xoopsModuleConfig['default_editor'] |
|
| 382 | - * |
|
| 383 | - * Of course, you can force the use of a specific editor: |
|
| 384 | - * |
|
| 385 | - * $this->setControl('body', array('name' => 'textarea', |
|
| 386 | - * 'form_editor' => 'koivi')); |
|
| 387 | - * |
|
| 388 | - * Here is a list of supported editor: |
|
| 389 | - * - tiny: TinyEditor |
|
| 390 | - * - dhtmltextarea: XOOPS DHTML Area |
|
| 391 | - * - fckeditor: FCKEditor |
|
| 392 | - * - inbetween: InBetween |
|
| 393 | - * - koivi: Koivi |
|
| 394 | - * - spaw: Spaw WYSIWYG Editor |
|
| 395 | - * - htmlarea: HTMLArea |
|
| 396 | - * - textarea: basic textarea with no options |
|
| 397 | - * |
|
| 398 | - * @param string $var name of the variable for which we want to set a control |
|
| 399 | - * @param array $options |
|
| 400 | - */ |
|
| 401 | - public function setControl($var, $options = array()) |
|
| 402 | - { |
|
| 403 | - if (isset($this->controls[$var])) { |
|
| 404 | - unset($this->controls[$var]); |
|
| 405 | - } |
|
| 406 | - if (is_string($options)) { |
|
| 407 | - $options = array('name' => $options); |
|
| 408 | - } |
|
| 409 | - $this->controls[$var] = $options; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Get control information for an instance variable |
|
| 414 | - * |
|
| 415 | - * @param string $var |
|
| 416 | - * @return bool|mixed |
|
| 417 | - */ |
|
| 418 | - public function getControl($var) |
|
| 419 | - { |
|
| 420 | - return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Create the form for this object |
|
| 425 | - * |
|
| 426 | - * @param $form_caption |
|
| 427 | - * @param $form_name |
|
| 428 | - * @param bool $form_action |
|
| 429 | - * @param string $submit_button_caption |
|
| 430 | - * @param bool $cancel_js_action |
|
| 431 | - * @param bool $captcha |
|
| 432 | - * @return a <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
| 433 | - * object for this object |
|
| 434 | - * @see SmartObjectForm::SmartObjectForm() |
|
| 435 | - */ |
|
| 436 | - public function getForm( |
|
| 437 | - $form_caption, |
|
| 438 | - $form_name, |
|
| 439 | - $form_action = false, |
|
| 440 | - $submit_button_caption = _CO_SOBJECT_SUBMIT, |
|
| 441 | - $cancel_js_action = false, |
|
| 442 | - $captcha = false |
|
| 443 | - ) { |
|
| 444 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
| 445 | - $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
| 446 | - |
|
| 447 | - return $form; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * @return array |
|
| 452 | - */ |
|
| 453 | - public function toArray() |
|
| 454 | - { |
|
| 455 | - $ret = array(); |
|
| 456 | - $vars =& $this->getVars(); |
|
| 457 | - foreach ($vars as $key => $var) { |
|
| 458 | - $value = $this->getVar($key); |
|
| 459 | - $ret[$key] = $value; |
|
| 460 | - } |
|
| 461 | - if ($this->handler->identifierName !== '') { |
|
| 462 | - $controller = new SmartObjectController($this->handler); |
|
| 463 | - /** |
|
| 464 | - * Addition of some automatic value |
|
| 465 | - */ |
|
| 466 | - $ret['itemLink'] = $controller->getItemLink($this); |
|
| 467 | - $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
| 468 | - $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
| 469 | - $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
| 470 | - $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // Hightlighting searched words |
|
| 474 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
|
| 475 | - $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
| 476 | - |
|
| 477 | - if ($highlight && isset($_GET['keywords'])) { |
|
| 478 | - $myts = MyTextSanitizer::getInstance(); |
|
| 479 | - $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
| 480 | - $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
| 481 | - foreach ($this->handler->highlightFields as $field) { |
|
| 482 | - $ret[$field] = $h->highlight($ret[$field]); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $ret; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * add an error |
|
| 491 | - * |
|
| 492 | - * @param $err_str |
|
| 493 | - * @param bool $prefix |
|
| 494 | - * @internal param string $value error to add |
|
| 495 | - * @access public |
|
| 496 | - */ |
|
| 497 | - public function setErrors($err_str, $prefix = false) |
|
| 498 | - { |
|
| 499 | - if (is_array($err_str)) { |
|
| 500 | - foreach ($err_str as $str) { |
|
| 501 | - $this->setErrors($str, $prefix); |
|
| 502 | - } |
|
| 503 | - } else { |
|
| 504 | - if ($prefix) { |
|
| 505 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
| 506 | - } |
|
| 507 | - parent::setErrors($err_str); |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * @param $field |
|
| 513 | - * @param bool $required |
|
| 514 | - */ |
|
| 515 | - public function setFieldAsRequired($field, $required = true) |
|
| 516 | - { |
|
| 517 | - if (is_array($field)) { |
|
| 518 | - foreach ($field as $v) { |
|
| 519 | - $this->doSetFieldAsRequired($v, $required); |
|
| 520 | - } |
|
| 521 | - } else { |
|
| 522 | - $this->doSetFieldAsRequired($field, $required); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * @param $field |
|
| 528 | - */ |
|
| 529 | - public function setFieldForSorting($field) |
|
| 530 | - { |
|
| 531 | - if (is_array($field)) { |
|
| 532 | - foreach ($field as $v) { |
|
| 533 | - $this->doSetFieldForSorting($v); |
|
| 534 | - } |
|
| 535 | - } else { |
|
| 536 | - $this->doSetFieldForSorting($field); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * @return bool |
|
| 542 | - */ |
|
| 543 | - public function hasError() |
|
| 544 | - { |
|
| 545 | - return count($this->_errors) > 0; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * @param $url |
|
| 550 | - * @param $path |
|
| 551 | - */ |
|
| 552 | - public function setImageDir($url, $path) |
|
| 553 | - { |
|
| 554 | - $this->_image_url = $url; |
|
| 555 | - $this->_image_path = $path; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Retreive the group that have been granted access to a specific permission for this object |
|
| 560 | - * |
|
| 561 | - * @param $group_perm |
|
| 562 | - * @return string $group_perm name of the permission |
|
| 563 | - */ |
|
| 564 | - public function getGroupPerm($group_perm) |
|
| 565 | - { |
|
| 566 | - if (!$this->handler->getPermissions()) { |
|
| 567 | - $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
| 568 | - |
|
| 569 | - return false; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
| 573 | - $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
| 574 | - |
|
| 575 | - if (count($ret) == 0) { |
|
| 576 | - return false; |
|
| 577 | - } else { |
|
| 578 | - return $ret; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * @param bool $path |
|
| 584 | - * @return mixed |
|
| 585 | - */ |
|
| 586 | - public function getImageDir($path = false) |
|
| 587 | - { |
|
| 588 | - if ($path) { |
|
| 589 | - return $this->_image_path; |
|
| 590 | - } else { |
|
| 591 | - return $this->_image_url; |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * @param bool $path |
|
| 597 | - * @return mixed |
|
| 598 | - */ |
|
| 599 | - public function getUploadDir($path = false) |
|
| 600 | - { |
|
| 601 | - if ($path) { |
|
| 602 | - return $this->_image_path; |
|
| 603 | - } else { |
|
| 604 | - return $this->_image_url; |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * @param string $key |
|
| 610 | - * @param string $info |
|
| 611 | - * @return array |
|
| 612 | - */ |
|
| 613 | - public function getVarInfo($key = '', $info = '') |
|
| 614 | - { |
|
| 615 | - if (isset($this->vars[$key][$info])) { |
|
| 616 | - return $this->vars[$key][$info]; |
|
| 617 | - } elseif ($info === '' && isset($this->vars[$key])) { |
|
| 618 | - return $this->vars[$key]; |
|
| 619 | - } else { |
|
| 620 | - return $this->vars; |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Get the id of the object |
|
| 626 | - * |
|
| 627 | - * @return int id of this object |
|
| 628 | - */ |
|
| 629 | - public function id() |
|
| 630 | - { |
|
| 631 | - return $this->getVar($this->handler->keyName, 'e'); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * Return the value of the title field of this object |
|
| 636 | - * |
|
| 637 | - * @param string $format |
|
| 638 | - * @return string |
|
| 639 | - */ |
|
| 640 | - public function title($format = 's') |
|
| 641 | - { |
|
| 642 | - return $this->getVar($this->handler->identifierName, $format); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Return the value of the title field of this object |
|
| 647 | - * |
|
| 648 | - * @return string |
|
| 649 | - */ |
|
| 650 | - public function summary() |
|
| 651 | - { |
|
| 652 | - if ($this->handler->summaryName) { |
|
| 653 | - return $this->getVar($this->handler->summaryName); |
|
| 654 | - } else { |
|
| 655 | - return false; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Retreive the object admin side link, displayijng a SingleView page |
|
| 661 | - * |
|
| 662 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 663 | - * @return string user side link to the object |
|
| 664 | - */ |
|
| 665 | - public function getAdminViewItemLink($onlyUrl = false) |
|
| 666 | - { |
|
| 667 | - $controller = new SmartObjectController($this->handler); |
|
| 668 | - |
|
| 669 | - return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Retreive the object user side link |
|
| 674 | - * |
|
| 675 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 676 | - * @return string user side link to the object |
|
| 677 | - */ |
|
| 678 | - public function getItemLink($onlyUrl = false) |
|
| 679 | - { |
|
| 680 | - $controller = new SmartObjectController($this->handler); |
|
| 681 | - |
|
| 682 | - return $controller->getItemLink($this, $onlyUrl); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * @param bool $onlyUrl |
|
| 687 | - * @param bool $withimage |
|
| 688 | - * @param bool $userSide |
|
| 689 | - * @return string |
|
| 690 | - */ |
|
| 691 | - public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
| 692 | - { |
|
| 693 | - $controller = new SmartObjectController($this->handler); |
|
| 694 | - |
|
| 695 | - return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * @param bool $onlyUrl |
|
| 700 | - * @param bool $withimage |
|
| 701 | - * @param bool $userSide |
|
| 702 | - * @return string |
|
| 703 | - */ |
|
| 704 | - public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
| 705 | - { |
|
| 706 | - $controller = new SmartObjectController($this->handler); |
|
| 707 | - |
|
| 708 | - return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * @return string |
|
| 713 | - */ |
|
| 714 | - public function getPrintAndMailLink() |
|
| 715 | - { |
|
| 716 | - $controller = new SmartObjectController($this->handler); |
|
| 717 | - |
|
| 718 | - return $controller->getPrintAndMailLink($this); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * @param $sortsel |
|
| 723 | - * @return array|bool |
|
| 724 | - */ |
|
| 725 | - public function getFieldsForSorting($sortsel) |
|
| 726 | - { |
|
| 727 | - $ret = array(); |
|
| 728 | - |
|
| 729 | - foreach ($this->vars as $key => $field_info) { |
|
| 730 | - if ($field_info['sortby']) { |
|
| 731 | - $ret[$key]['caption'] = $field_info['form_caption']; |
|
| 732 | - $ret[$key]['selected'] = $key == $sortsel ? 'selected' : ''; |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - if (count($ret) > 0) { |
|
| 737 | - return $ret; |
|
| 738 | - } else { |
|
| 739 | - return false; |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - /** |
|
| 744 | - * @param $key |
|
| 745 | - * @param $newType |
|
| 746 | - */ |
|
| 747 | - public function setType($key, $newType) |
|
| 748 | - { |
|
| 749 | - $this->vars[$key]['data_type'] = $newType; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - /** |
|
| 753 | - * @param $key |
|
| 754 | - * @param $info |
|
| 755 | - * @param $value |
|
| 756 | - */ |
|
| 757 | - public function setVarInfo($key, $info, $value) |
|
| 758 | - { |
|
| 759 | - $this->vars[$key][$info] = $value; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * @param $key |
|
| 764 | - * @param bool $editor |
|
| 765 | - * @return string |
|
| 766 | - */ |
|
| 767 | - public function getValueFor($key, $editor = true) |
|
| 768 | - { |
|
| 769 | - global $xoopsModuleConfig; |
|
| 770 | - |
|
| 771 | - $ret = $this->getVar($key, 'n'); |
|
| 772 | - $myts = MyTextSanitizer::getInstance(); |
|
| 773 | - |
|
| 774 | - $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
| 775 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 776 | - |
|
| 777 | - $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
| 778 | - $smiley = true; |
|
| 779 | - $xcode = true; |
|
| 780 | - $image = true; |
|
| 781 | - $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
| 782 | - $formatML = true; |
|
| 783 | - |
|
| 784 | - if ($form_editor === 'default') { |
|
| 785 | - global $xoopsModuleConfig; |
|
| 786 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - if ($editor) { |
|
| 790 | - if (defined('XOOPS_EDITOR_IS_HTML') |
|
| 791 | - && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) { |
|
| 792 | - $br = false; |
|
| 793 | - $formatML = !$editor; |
|
| 794 | - } else { |
|
| 795 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - if (method_exists($myts, 'formatForML')) { |
|
| 800 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
| 801 | - } else { |
|
| 802 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * clean values of all variables of the object for storage. |
|
| 808 | - * also add slashes whereever needed |
|
| 809 | - * |
|
| 810 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
| 811 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
| 812 | - * as a string separated by | |
|
| 813 | - * |
|
| 814 | - * @return bool true if successful |
|
| 815 | - * @access public |
|
| 816 | - */ |
|
| 817 | - public function cleanVars() |
|
| 818 | - { |
|
| 819 | - $ts = MyTextSanitizer::getInstance(); |
|
| 820 | - $existing_errors = $this->getErrors(); |
|
| 821 | - $this->_errors = array(); |
|
| 822 | - foreach ($this->vars as $k => $v) { |
|
| 823 | - $cleanv = $v['value']; |
|
| 824 | - if (!$v['changed']) { |
|
| 825 | - } else { |
|
| 826 | - $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
| 827 | - switch ($v['data_type']) { |
|
| 828 | - case XOBJ_DTYPE_TXTBOX: |
|
| 829 | - if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
| 830 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 831 | - continue 2; |
|
| 832 | - } |
|
| 833 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
| 834 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
| 835 | - continue 2; |
|
| 836 | - } |
|
| 837 | - if (!$v['not_gpc']) { |
|
| 838 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
| 839 | - } else { |
|
| 840 | - $cleanv = $ts->censorString($cleanv); |
|
| 841 | - } |
|
| 842 | - break; |
|
| 843 | - case XOBJ_DTYPE_TXTAREA: |
|
| 844 | - if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
| 845 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 846 | - continue 2; |
|
| 847 | - } |
|
| 848 | - if (!$v['not_gpc']) { |
|
| 849 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
| 850 | - } else { |
|
| 851 | - $cleanv = $ts->censorString($cleanv); |
|
| 852 | - } |
|
| 853 | - break; |
|
| 854 | - case XOBJ_DTYPE_SOURCE: |
|
| 855 | - if (!$v['not_gpc']) { |
|
| 856 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
| 857 | - } else { |
|
| 858 | - $cleanv = $cleanv; |
|
| 859 | - } |
|
| 860 | - break; |
|
| 861 | - case XOBJ_DTYPE_INT: |
|
| 862 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 863 | - $cleanv = (int)$cleanv; |
|
| 864 | - break; |
|
| 865 | - |
|
| 866 | - case XOBJ_DTYPE_CURRENCY: |
|
| 867 | - $cleanv = smart_currency($cleanv); |
|
| 868 | - break; |
|
| 869 | - |
|
| 870 | - case XOBJ_DTYPE_FLOAT: |
|
| 871 | - $cleanv = smart_float($cleanv); |
|
| 872 | - break; |
|
| 873 | - |
|
| 874 | - case XOBJ_DTYPE_EMAIL: |
|
| 875 | - if ($v['required'] && $cleanv === '') { |
|
| 876 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 877 | - continue 2; |
|
| 878 | - } |
|
| 879 | - if ($cleanv !== '' |
|
| 880 | - && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
| 881 | - $this->setErrors('Invalid Email'); |
|
| 882 | - continue 2; |
|
| 883 | - } |
|
| 884 | - if (!$v['not_gpc']) { |
|
| 885 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
| 886 | - } |
|
| 887 | - break; |
|
| 888 | - case XOBJ_DTYPE_URL: |
|
| 889 | - if ($v['required'] && $cleanv === '') { |
|
| 890 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 891 | - continue 2; |
|
| 892 | - } |
|
| 893 | - if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
| 894 | - $cleanv = 'http://' . $cleanv; |
|
| 895 | - } |
|
| 896 | - if (!$v['not_gpc']) { |
|
| 897 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
| 898 | - } |
|
| 899 | - break; |
|
| 900 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
| 901 | - $cleanv = implode('|', $cleanv); |
|
| 902 | - break; |
|
| 903 | - case XOBJ_DTYPE_ARRAY: |
|
| 904 | - $cleanv = serialize($cleanv); |
|
| 905 | - break; |
|
| 906 | - case XOBJ_DTYPE_STIME: |
|
| 907 | - case XOBJ_DTYPE_MTIME: |
|
| 908 | - case XOBJ_DTYPE_LTIME: |
|
| 909 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
| 910 | - if (!($cleanv > 0)) { |
|
| 911 | - $cleanv = strtotime($cleanv); |
|
| 912 | - } |
|
| 913 | - break; |
|
| 914 | - default: |
|
| 915 | - break; |
|
| 916 | - } |
|
| 917 | - } |
|
| 918 | - $this->cleanVars[$k] =& $cleanv; |
|
| 919 | - unset($cleanv); |
|
| 920 | - } |
|
| 921 | - if (count($this->_errors) > 0) { |
|
| 922 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
| 923 | - |
|
| 924 | - return false; |
|
| 925 | - } |
|
| 926 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
| 927 | - $this->unsetDirty(); |
|
| 928 | - |
|
| 929 | - return true; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - /** |
|
| 933 | - * returns a specific variable for the object in a proper format |
|
| 934 | - * |
|
| 935 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
| 936 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
| 937 | - * as a string separated by | |
|
| 938 | - * |
|
| 939 | - * @access public |
|
| 940 | - * @param string $key key of the object's variable to be returned |
|
| 941 | - * @param string $format format to use for the output |
|
| 942 | - * @return mixed formatted value of the variable |
|
| 943 | - */ |
|
| 944 | - public function getVar($key, $format = 's') |
|
| 945 | - { |
|
| 946 | - global $myts; |
|
| 947 | - |
|
| 948 | - $ret = $this->vars[$key]['value']; |
|
| 949 | - |
|
| 950 | - switch ($this->vars[$key]['data_type']) { |
|
| 951 | - |
|
| 952 | - case XOBJ_DTYPE_TXTBOX: |
|
| 953 | - switch (strtolower($format)) { |
|
| 954 | - case 's': |
|
| 955 | - case 'show': |
|
| 956 | - // ML Hack by marcan |
|
| 957 | - $ts = MyTextSanitizer::getInstance(); |
|
| 958 | - $ret = $ts->htmlSpecialChars($ret); |
|
| 959 | - |
|
| 960 | - if (method_exists($myts, 'formatForML')) { |
|
| 961 | - return $ts->formatForML($ret); |
|
| 962 | - } else { |
|
| 963 | - return $ret; |
|
| 964 | - } |
|
| 965 | - break 1; |
|
| 966 | - // End of ML Hack by marcan |
|
| 967 | - |
|
| 968 | - case 'clean': |
|
| 969 | - $ts = MyTextSanitizer::getInstance(); |
|
| 970 | - |
|
| 971 | - $ret = smart_html2text($ret); |
|
| 972 | - $ret = smart_purifyText($ret); |
|
| 973 | - |
|
| 974 | - if (method_exists($myts, 'formatForML')) { |
|
| 975 | - return $ts->formatForML($ret); |
|
| 976 | - } else { |
|
| 977 | - return $ret; |
|
| 978 | - } |
|
| 979 | - break 1; |
|
| 980 | - // End of ML Hack by marcan |
|
| 981 | - |
|
| 982 | - case 'e': |
|
| 983 | - case 'edit': |
|
| 984 | - $ts = MyTextSanitizer::getInstance(); |
|
| 985 | - |
|
| 986 | - return $ts->htmlSpecialChars($ret); |
|
| 987 | - break 1; |
|
| 988 | - case 'p': |
|
| 989 | - case 'preview': |
|
| 990 | - case 'f': |
|
| 991 | - case 'formpreview': |
|
| 992 | - $ts = MyTextSanitizer::getInstance(); |
|
| 993 | - |
|
| 994 | - return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
| 995 | - break 1; |
|
| 996 | - case 'n': |
|
| 997 | - case 'none': |
|
| 998 | - default: |
|
| 999 | - break 1; |
|
| 1000 | - } |
|
| 1001 | - break; |
|
| 1002 | - case XOBJ_DTYPE_LTIME: |
|
| 1003 | - switch (strtolower($format)) { |
|
| 1004 | - case 's': |
|
| 1005 | - case 'show': |
|
| 1006 | - case 'p': |
|
| 1007 | - case 'preview': |
|
| 1008 | - case 'f': |
|
| 1009 | - case 'formpreview': |
|
| 1010 | - $ret = formatTimestamp($ret, _DATESTRING); |
|
| 1011 | - |
|
| 1012 | - return $ret; |
|
| 1013 | - break 1; |
|
| 1014 | - case 'n': |
|
| 1015 | - case 'none': |
|
| 1016 | - case 'e': |
|
| 1017 | - case 'edit': |
|
| 1018 | - break 1; |
|
| 1019 | - default: |
|
| 1020 | - break 1; |
|
| 1021 | - } |
|
| 1022 | - break; |
|
| 1023 | - case XOBJ_DTYPE_STIME: |
|
| 1024 | - switch (strtolower($format)) { |
|
| 1025 | - case 's': |
|
| 1026 | - case 'show': |
|
| 1027 | - case 'p': |
|
| 1028 | - case 'preview': |
|
| 1029 | - case 'f': |
|
| 1030 | - case 'formpreview': |
|
| 1031 | - $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
| 1032 | - |
|
| 1033 | - return $ret; |
|
| 1034 | - break 1; |
|
| 1035 | - case 'n': |
|
| 1036 | - case 'none': |
|
| 1037 | - case 'e': |
|
| 1038 | - case 'edit': |
|
| 1039 | - break 1; |
|
| 1040 | - default: |
|
| 1041 | - break 1; |
|
| 1042 | - } |
|
| 1043 | - break; |
|
| 1044 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 1045 | - switch (strtolower($format)) { |
|
| 1046 | - case 's': |
|
| 1047 | - case 'show': |
|
| 1048 | - case 'p': |
|
| 1049 | - case 'preview': |
|
| 1050 | - case 'f': |
|
| 1051 | - case 'formpreview': |
|
| 1052 | - $ret = formatTimestamp($ret, 'G:i'); |
|
| 1053 | - |
|
| 1054 | - return $ret; |
|
| 1055 | - break 1; |
|
| 1056 | - case 'n': |
|
| 1057 | - case 'none': |
|
| 1058 | - case 'e': |
|
| 1059 | - case 'edit': |
|
| 1060 | - break 1; |
|
| 1061 | - default: |
|
| 1062 | - break 1; |
|
| 1063 | - } |
|
| 1064 | - break; |
|
| 1065 | - |
|
| 1066 | - case XOBJ_DTYPE_CURRENCY: |
|
| 1067 | - $decimal_section_original = strstr($ret, '.'); |
|
| 1068 | - $decimal_section = $decimal_section_original; |
|
| 1069 | - if ($decimal_section) { |
|
| 1070 | - if (strlen($decimal_section) == 1) { |
|
| 1071 | - $decimal_section = '.00'; |
|
| 1072 | - } elseif (strlen($decimal_section) == 2) { |
|
| 1073 | - $decimal_section .= '0'; |
|
| 1074 | - } |
|
| 1075 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
| 1076 | - } else { |
|
| 1077 | - $ret .= '.00'; |
|
| 1078 | - } |
|
| 1079 | - break; |
|
| 1080 | - |
|
| 1081 | - case XOBJ_DTYPE_TXTAREA: |
|
| 1082 | - switch (strtolower($format)) { |
|
| 1083 | - case 's': |
|
| 1084 | - case 'show': |
|
| 1085 | - $ts = MyTextSanitizer::getInstance(); |
|
| 1086 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
| 1087 | - |
|
| 1088 | - $xcode = (!isset($this->vars['doxcode']['value']) |
|
| 1089 | - || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
| 1090 | - |
|
| 1091 | - $smiley = (!isset($this->vars['dosmiley']['value']) |
|
| 1092 | - || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
| 1093 | - $image = (!isset($this->vars['doimage']['value']) |
|
| 1094 | - || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
| 1095 | - $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
| 1096 | - |
|
| 1097 | - /** |
|
| 1098 | - * Hack by marcan <INBOX> for SCSPRO |
|
| 1099 | - * Setting mastop as the main editor |
|
| 1100 | - */ |
|
| 1101 | - if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
| 1102 | - $br = false; |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * Hack by marcan <INBOX> for SCSPRO |
|
| 1107 | - * Setting mastop as the main editor |
|
| 1108 | - */ |
|
| 1109 | - |
|
| 1110 | - return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 1111 | - break 1; |
|
| 1112 | - case 'e': |
|
| 1113 | - case 'edit': |
|
| 1114 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
| 1115 | - break 1; |
|
| 1116 | - case 'p': |
|
| 1117 | - case 'preview': |
|
| 1118 | - $ts = MyTextSanitizer::getInstance(); |
|
| 1119 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
| 1120 | - $xcode = (!isset($this->vars['doxcode']['value']) |
|
| 1121 | - || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
| 1122 | - $smiley = (!isset($this->vars['dosmiley']['value']) |
|
| 1123 | - || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
| 1124 | - $image = (!isset($this->vars['doimage']['value']) |
|
| 1125 | - || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
| 1126 | - $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
| 1127 | - |
|
| 1128 | - return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 1129 | - break 1; |
|
| 1130 | - case 'f': |
|
| 1131 | - case 'formpreview': |
|
| 1132 | - $ts = MyTextSanitizer::getInstance(); |
|
| 1133 | - |
|
| 1134 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
| 1135 | - break 1; |
|
| 1136 | - case 'n': |
|
| 1137 | - case 'none': |
|
| 1138 | - default: |
|
| 1139 | - break 1; |
|
| 1140 | - } |
|
| 1141 | - break; |
|
| 1142 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
| 1143 | - $ret =& explode('|', $ret); |
|
| 1144 | - break; |
|
| 1145 | - case XOBJ_DTYPE_ARRAY: |
|
| 1146 | - $ret =& unserialize($ret); |
|
| 1147 | - break; |
|
| 1148 | - case XOBJ_DTYPE_SOURCE: |
|
| 1149 | - switch (strtolower($format)) { |
|
| 1150 | - case 's': |
|
| 1151 | - case 'show': |
|
| 1152 | - break 1; |
|
| 1153 | - case 'e': |
|
| 1154 | - case 'edit': |
|
| 1155 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
| 1156 | - break 1; |
|
| 1157 | - case 'p': |
|
| 1158 | - case 'preview': |
|
| 1159 | - $ts = MyTextSanitizer::getInstance(); |
|
| 1160 | - |
|
| 1161 | - return $ts->stripSlashesGPC($ret); |
|
| 1162 | - break 1; |
|
| 1163 | - case 'f': |
|
| 1164 | - case 'formpreview': |
|
| 1165 | - $ts = MyTextSanitizer::getInstance(); |
|
| 1166 | - |
|
| 1167 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
| 1168 | - break 1; |
|
| 1169 | - case 'n': |
|
| 1170 | - case 'none': |
|
| 1171 | - default: |
|
| 1172 | - break 1; |
|
| 1173 | - } |
|
| 1174 | - break; |
|
| 1175 | - default: |
|
| 1176 | - if ($this->vars[$key]['options'] !== '' && $ret != '') { |
|
| 1177 | - switch (strtolower($format)) { |
|
| 1178 | - case 's': |
|
| 1179 | - case 'show': |
|
| 1180 | - $selected = explode('|', $ret); |
|
| 1181 | - $options = explode('|', $this->vars[$key]['options']); |
|
| 1182 | - $i = 1; |
|
| 1183 | - $ret = array(); |
|
| 1184 | - foreach ($options as $op) { |
|
| 1185 | - if (in_array($i, $selected)) { |
|
| 1186 | - $ret[] = $op; |
|
| 1187 | - } |
|
| 1188 | - ++$i; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - return implode(', ', $ret); |
|
| 1192 | - case 'e': |
|
| 1193 | - case 'edit': |
|
| 1194 | - $ret = explode('|', $ret); |
|
| 1195 | - break 1; |
|
| 1196 | - default: |
|
| 1197 | - break 1; |
|
| 1198 | - } |
|
| 1199 | - } |
|
| 1200 | - break; |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - return $ret; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * @param $key |
|
| 1208 | - */ |
|
| 1209 | - public function doMakeFieldreadOnly($key) |
|
| 1210 | - { |
|
| 1211 | - if (isset($this->vars[$key])) { |
|
| 1212 | - $this->vars[$key]['readonly'] = true; |
|
| 1213 | - $this->vars[$key]['displayOnForm'] = true; |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - /** |
|
| 1218 | - * @param $key |
|
| 1219 | - */ |
|
| 1220 | - public function makeFieldReadOnly($key) |
|
| 1221 | - { |
|
| 1222 | - if (is_array($key)) { |
|
| 1223 | - foreach ($key as $v) { |
|
| 1224 | - $this->doMakeFieldreadOnly($v); |
|
| 1225 | - } |
|
| 1226 | - } else { |
|
| 1227 | - $this->doMakeFieldreadOnly($key); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - /** |
|
| 1232 | - * @param $key |
|
| 1233 | - */ |
|
| 1234 | - public function doHideFieldFromForm($key) |
|
| 1235 | - { |
|
| 1236 | - if (isset($this->vars[$key])) { |
|
| 1237 | - $this->vars[$key]['displayOnForm'] = false; |
|
| 1238 | - } |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - /** |
|
| 1242 | - * @param $key |
|
| 1243 | - */ |
|
| 1244 | - public function doHideFieldFromSingleView($key) |
|
| 1245 | - { |
|
| 1246 | - if (isset($this->vars[$key])) { |
|
| 1247 | - $this->vars[$key]['displayOnSingleView'] = false; |
|
| 1248 | - } |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - /** |
|
| 1252 | - * @param $key |
|
| 1253 | - */ |
|
| 1254 | - public function hideFieldFromForm($key) |
|
| 1255 | - { |
|
| 1256 | - if (is_array($key)) { |
|
| 1257 | - foreach ($key as $v) { |
|
| 1258 | - $this->doHideFieldFromForm($v); |
|
| 1259 | - } |
|
| 1260 | - } else { |
|
| 1261 | - $this->doHideFieldFromForm($key); |
|
| 1262 | - } |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - /** |
|
| 1266 | - * @param $key |
|
| 1267 | - */ |
|
| 1268 | - public function hideFieldFromSingleView($key) |
|
| 1269 | - { |
|
| 1270 | - if (is_array($key)) { |
|
| 1271 | - foreach ($key as $v) { |
|
| 1272 | - $this->doHideFieldFromSingleView($v); |
|
| 1273 | - } |
|
| 1274 | - } else { |
|
| 1275 | - $this->doHideFieldFromSingleView($key); |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * @param $key |
|
| 1281 | - */ |
|
| 1282 | - public function doShowFieldOnForm($key) |
|
| 1283 | - { |
|
| 1284 | - if (isset($this->vars[$key])) { |
|
| 1285 | - $this->vars[$key]['displayOnForm'] = true; |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
| 1291 | - * |
|
| 1292 | - * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
| 1293 | - * @param bool $userSide for futur use, to do something different on the user side |
|
| 1294 | - * @param array $actions |
|
| 1295 | - * @param bool $headerAsRow |
|
| 1296 | - * @return content of the template if $fetchOnly or nothing if !$fetchOnly |
|
| 1297 | - */ |
|
| 1298 | - public function displaySingleObject( |
|
| 1299 | - $fetchOnly = false, |
|
| 1300 | - $userSide = false, |
|
| 1301 | - $actions = array(), |
|
| 1302 | - $headerAsRow = true |
|
| 1303 | - ) { |
|
| 1304 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
| 1305 | - $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
| 1306 | - // add all fields mark as displayOnSingleView except the keyid |
|
| 1307 | - foreach ($this->vars as $key => $var) { |
|
| 1308 | - if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
| 1309 | - $is_header = ($key == $this->handler->identifierName); |
|
| 1310 | - $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
| 1311 | - } |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - if ($fetchOnly) { |
|
| 1315 | - $ret = $singleview->render($fetchOnly); |
|
| 1316 | - |
|
| 1317 | - return $ret; |
|
| 1318 | - } else { |
|
| 1319 | - $singleview->render($fetchOnly); |
|
| 1320 | - } |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - /** |
|
| 1324 | - * @param $key |
|
| 1325 | - */ |
|
| 1326 | - public function doDisplayFieldOnSingleView($key) |
|
| 1327 | - { |
|
| 1328 | - if (isset($this->vars[$key])) { |
|
| 1329 | - $this->vars[$key]['displayOnSingleView'] = true; |
|
| 1330 | - } |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - /** |
|
| 1334 | - * @param $field |
|
| 1335 | - * @param bool $required |
|
| 1336 | - */ |
|
| 1337 | - public function doSetFieldAsRequired($field, $required = true) |
|
| 1338 | - { |
|
| 1339 | - $this->setVarInfo($field, 'required', $required); |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - /** |
|
| 1343 | - * @param $field |
|
| 1344 | - */ |
|
| 1345 | - public function doSetFieldForSorting($field) |
|
| 1346 | - { |
|
| 1347 | - $this->setVarInfo($field, 'sortby', true); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * @param $key |
|
| 1352 | - */ |
|
| 1353 | - public function showFieldOnForm($key) |
|
| 1354 | - { |
|
| 1355 | - if (is_array($key)) { |
|
| 1356 | - foreach ($key as $v) { |
|
| 1357 | - $this->doShowFieldOnForm($v); |
|
| 1358 | - } |
|
| 1359 | - } else { |
|
| 1360 | - $this->doShowFieldOnForm($key); |
|
| 1361 | - } |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - /** |
|
| 1365 | - * @param $key |
|
| 1366 | - */ |
|
| 1367 | - public function displayFieldOnSingleView($key) |
|
| 1368 | - { |
|
| 1369 | - if (is_array($key)) { |
|
| 1370 | - foreach ($key as $v) { |
|
| 1371 | - $this->doDisplayFieldOnSingleView($v); |
|
| 1372 | - } |
|
| 1373 | - } else { |
|
| 1374 | - $this->doDisplayFieldOnSingleView($key); |
|
| 1375 | - } |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * @param $key |
|
| 1380 | - */ |
|
| 1381 | - public function doSetAdvancedFormFields($key) |
|
| 1382 | - { |
|
| 1383 | - if (isset($this->vars[$key])) { |
|
| 1384 | - $this->vars[$key]['advancedform'] = true; |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * @param $key |
|
| 1390 | - */ |
|
| 1391 | - public function setAdvancedFormFields($key) |
|
| 1392 | - { |
|
| 1393 | - if (is_array($key)) { |
|
| 1394 | - foreach ($key as $v) { |
|
| 1395 | - $this->doSetAdvancedFormFields($v); |
|
| 1396 | - } |
|
| 1397 | - } else { |
|
| 1398 | - $this->doSetAdvancedFormFields($key); |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - |
|
| 1402 | - /** |
|
| 1403 | - * @param $key |
|
| 1404 | - * @return mixed |
|
| 1405 | - */ |
|
| 1406 | - public function getUrlLinkObj($key) |
|
| 1407 | - { |
|
| 1408 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
| 1409 | - $urllinkid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
| 1410 | - if ($urllinkid != 0) { |
|
| 1411 | - return $smartobjectLinkurlHandler->get($urllinkid); |
|
| 1412 | - } else { |
|
| 1413 | - return $smartobjectLinkurlHandler->create(); |
|
| 1414 | - } |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * @param $urlLinkObj |
|
| 1419 | - * @return mixed |
|
| 1420 | - */ |
|
| 1421 | - public function &storeUrlLinkObj($urlLinkObj) |
|
| 1422 | - { |
|
| 1423 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
| 1424 | - |
|
| 1425 | - return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - /** |
|
| 1429 | - * @param $key |
|
| 1430 | - * @return mixed |
|
| 1431 | - */ |
|
| 1432 | - public function getFileObj($key) |
|
| 1433 | - { |
|
| 1434 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
| 1435 | - $fileid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
| 1436 | - if ($fileid != 0) { |
|
| 1437 | - return $smartobjectFileHandler->get($fileid); |
|
| 1438 | - } else { |
|
| 1439 | - return $smartobjectFileHandler->create(); |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - /** |
|
| 1444 | - * @param $fileObj |
|
| 1445 | - * @return mixed |
|
| 1446 | - */ |
|
| 1447 | - public function &storeFileObj($fileObj) |
|
| 1448 | - { |
|
| 1449 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
| 1450 | - |
|
| 1451 | - return $smartobjectFileHandler->insert($fileObj); |
|
| 1452 | - } |
|
| 58 | + public $_image_path; |
|
| 59 | + public $_image_url; |
|
| 60 | + |
|
| 61 | + public $seoEnabled = false; |
|
| 62 | + public $titleField; |
|
| 63 | + public $summaryField = false; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Reference to the handler managing this object |
|
| 67 | + * |
|
| 68 | + * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
| 69 | + */ |
|
| 70 | + public $handler; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * References to control objects, managing the form fields of this object |
|
| 74 | + */ |
|
| 75 | + public $controls = array(); |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * SmartObject constructor. |
|
| 79 | + * @param $handler |
|
| 80 | + */ |
|
| 81 | + public function __construct($handler) |
|
| 82 | + { |
|
| 83 | + $this->handler = $handler; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Checks if the user has a specific access on this object |
|
| 88 | + * |
|
| 89 | + * @param $perm_name |
|
| 90 | + * @return bool: TRUE if user has access, false if not |
|
| 91 | + * @internal param string $gperm_name name of the permission to test |
|
| 92 | + */ |
|
| 93 | + public function accessGranted($perm_name) |
|
| 94 | + { |
|
| 95 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
| 96 | + |
|
| 97 | + return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param $section_name |
|
| 102 | + * @param bool $value |
|
| 103 | + * @param bool $hide |
|
| 104 | + */ |
|
| 105 | + public function addFormSection($section_name, $value = false, $hide = false) |
|
| 106 | + { |
|
| 107 | + $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
| 108 | + $this->vars[$section_name]['hide'] = $hide; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param $section_name |
|
| 113 | + */ |
|
| 114 | + public function closeSection($section_name) |
|
| 115 | + { |
|
| 116 | + $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * |
|
| 121 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
| 122 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
| 123 | + * @param mixed $value default value of this variable |
|
| 124 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
| 125 | + * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
| 126 | + * @param string $options does this data have any select options? |
|
| 127 | + * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
| 128 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
| 129 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
| 130 | + * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
| 131 | + * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
| 132 | + * @param bool $displayOnForm |
|
| 133 | + */ |
|
| 134 | + public function initVar( |
|
| 135 | + $key, |
|
| 136 | + $data_type, |
|
| 137 | + $value = null, |
|
| 138 | + $required = false, |
|
| 139 | + $maxlength = null, |
|
| 140 | + $options = '', |
|
| 141 | + $multilingual = false, |
|
| 142 | + $form_caption = '', |
|
| 143 | + $form_dsc = '', |
|
| 144 | + $sortby = false, |
|
| 145 | + $persistent = true, |
|
| 146 | + $displayOnForm = true |
|
| 147 | + ) { |
|
| 148 | + //url_ is reserved for files. |
|
| 149 | + if (0 === strpos($key, 'url_')) { |
|
| 150 | + trigger_error("Cannot use variable starting with 'url_'."); |
|
| 151 | + } |
|
| 152 | + parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
| 153 | + if ($this->handler && (!$form_caption || $form_caption === '')) { |
|
| 154 | + $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
| 155 | + if (defined($dyn_form_caption)) { |
|
| 156 | + $form_caption = constant($dyn_form_caption); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + if ($this->handler && (!$form_dsc || $form_dsc === '')) { |
|
| 160 | + $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
| 161 | + if (defined($dyn_form_dsc)) { |
|
| 162 | + $form_dsc = constant($dyn_form_dsc); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $this->vars[$key] = array_merge($this->vars[$key], array( |
|
| 167 | + 'multilingual' => $multilingual, |
|
| 168 | + 'form_caption' => $form_caption, |
|
| 169 | + 'form_dsc' => $form_dsc, |
|
| 170 | + 'sortby' => $sortby, |
|
| 171 | + 'persistent' => $persistent, |
|
| 172 | + 'displayOnForm' => $displayOnForm, |
|
| 173 | + 'displayOnSingleView' => true, |
|
| 174 | + 'readonly' => false |
|
| 175 | + )); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @param $key |
|
| 180 | + * @param $data_type |
|
| 181 | + * @param bool $itemName |
|
| 182 | + * @param string $form_caption |
|
| 183 | + * @param bool $sortby |
|
| 184 | + * @param string $value |
|
| 185 | + * @param bool $displayOnForm |
|
| 186 | + * @param bool $required |
|
| 187 | + */ |
|
| 188 | + public function initNonPersistableVar( |
|
| 189 | + $key, |
|
| 190 | + $data_type, |
|
| 191 | + $itemName = false, |
|
| 192 | + $form_caption = '', |
|
| 193 | + $sortby = false, |
|
| 194 | + $value = '', |
|
| 195 | + $displayOnForm = false, |
|
| 196 | + $required = false |
|
| 197 | + ) { |
|
| 198 | + $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
| 199 | + $this->vars[$key]['itemName'] = $itemName; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Quickly initiate a var |
|
| 204 | + * |
|
| 205 | + * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
| 206 | + * |
|
| 207 | + * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
| 208 | + * - all other vars are NULL or '' depending of the parameter |
|
| 209 | + * |
|
| 210 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
| 211 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
| 212 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
| 213 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
| 214 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
| 215 | + * @param mixed $value default value of this variable |
|
| 216 | + */ |
|
| 217 | + public function quickInitVar( |
|
| 218 | + $key, |
|
| 219 | + $data_type, |
|
| 220 | + $required = false, |
|
| 221 | + $form_caption = '', |
|
| 222 | + $form_dsc = '', |
|
| 223 | + $value = null |
|
| 224 | + ) { |
|
| 225 | + $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null; |
|
| 226 | + $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @param $varname |
|
| 231 | + * @param bool $displayOnForm |
|
| 232 | + * @param string $default |
|
| 233 | + */ |
|
| 234 | + public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
| 235 | + { |
|
| 236 | + switch ($varname) { |
|
| 237 | + case 'dohtml': |
|
| 238 | + $value = $default !== 'notdefined' ? $default : true; |
|
| 239 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 240 | + $this->setControl($varname, 'yesno'); |
|
| 241 | + break; |
|
| 242 | + |
|
| 243 | + case 'dobr': |
|
| 244 | + $value = ($default === 'notdefined') ? true : $default; |
|
| 245 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 246 | + $this->setControl($varname, 'yesno'); |
|
| 247 | + break; |
|
| 248 | + |
|
| 249 | + case 'doimage': |
|
| 250 | + $value = $default !== 'notdefined' ? $default : true; |
|
| 251 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 252 | + $this->setControl($varname, 'yesno'); |
|
| 253 | + break; |
|
| 254 | + |
|
| 255 | + case 'dosmiley': |
|
| 256 | + $value = $default !== 'notdefined' ? $default : true; |
|
| 257 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 258 | + $this->setControl($varname, 'yesno'); |
|
| 259 | + break; |
|
| 260 | + |
|
| 261 | + case 'doxcode': |
|
| 262 | + $value = $default !== 'notdefined' ? $default : true; |
|
| 263 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 264 | + $this->setControl($varname, 'yesno'); |
|
| 265 | + break; |
|
| 266 | + |
|
| 267 | + case 'meta_keywords': |
|
| 268 | + $value = $default !== 'notdefined' ? $default : ''; |
|
| 269 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
| 270 | + $this->setControl('meta_keywords', array( |
|
| 271 | + 'name' => 'textarea', |
|
| 272 | + 'form_editor' => 'textarea' |
|
| 273 | + )); |
|
| 274 | + break; |
|
| 275 | + |
|
| 276 | + case 'meta_description': |
|
| 277 | + $value = $default !== 'notdefined' ? $default : ''; |
|
| 278 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
| 279 | + $this->setControl('meta_description', array( |
|
| 280 | + 'name' => 'textarea', |
|
| 281 | + 'form_editor' => 'textarea' |
|
| 282 | + )); |
|
| 283 | + break; |
|
| 284 | + |
|
| 285 | + case 'short_url': |
|
| 286 | + $value = $default !== 'notdefined' ? $default : ''; |
|
| 287 | + $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
| 288 | + break; |
|
| 289 | + |
|
| 290 | + case 'hierarchy_path': |
|
| 291 | + $value = $default !== 'notdefined' ? $default : ''; |
|
| 292 | + $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
| 293 | + break; |
|
| 294 | + |
|
| 295 | + case 'counter': |
|
| 296 | + $value = $default !== 'notdefined' ? $default : 0; |
|
| 297 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
| 298 | + break; |
|
| 299 | + |
|
| 300 | + case 'weight': |
|
| 301 | + $value = $default !== 'notdefined' ? $default : 0; |
|
| 302 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
| 303 | + break; |
|
| 304 | + case 'custom_css': |
|
| 305 | + $value = $default !== 'notdefined' ? $default : ''; |
|
| 306 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
| 307 | + $this->setControl('custom_css', array( |
|
| 308 | + 'name' => 'textarea', |
|
| 309 | + 'form_editor' => 'textarea' |
|
| 310 | + )); |
|
| 311 | + break; |
|
| 312 | + } |
|
| 313 | + $this->hideFieldFromSingleView($varname); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Set control information for an instance variable |
|
| 318 | + * |
|
| 319 | + * The $options parameter can be a string or an array. Using a string |
|
| 320 | + * is the quickest way: |
|
| 321 | + * |
|
| 322 | + * $this->setControl('date', 'date_time'); |
|
| 323 | + * |
|
| 324 | + * This will create a date and time selectbox for the 'date' var on the |
|
| 325 | + * form to edit or create this item. |
|
| 326 | + * |
|
| 327 | + * Here are the currently supported controls: |
|
| 328 | + * |
|
| 329 | + * - color |
|
| 330 | + * - country |
|
| 331 | + * - date_time |
|
| 332 | + * - date |
|
| 333 | ||
| 334 | + * - group |
|
| 335 | + * - group_multi |
|
| 336 | + * - image |
|
| 337 | + * - imageupload |
|
| 338 | + * - label |
|
| 339 | + * - language |
|
| 340 | + * - parentcategory |
|
| 341 | + * - password |
|
| 342 | + * - select_multi |
|
| 343 | + * - select |
|
| 344 | + * - text |
|
| 345 | + * - textarea |
|
| 346 | + * - theme |
|
| 347 | + * - theme_multi |
|
| 348 | + * - timezone |
|
| 349 | + * - user |
|
| 350 | + * - user_multi |
|
| 351 | + * - yesno |
|
| 352 | + * |
|
| 353 | + * Now, using an array as $options, you can customize what information to |
|
| 354 | + * use in the control. For example, if one needs to display a select box for |
|
| 355 | + * the user to choose the status of an item. We only need to tell SmartObject |
|
| 356 | + * what method to execute within what handler to retreive the options of the |
|
| 357 | + * selectbox. |
|
| 358 | + * |
|
| 359 | + * $this->setControl('status', array('name' => false, |
|
| 360 | + * 'itemHandler' => 'item', |
|
| 361 | + * 'method' => 'getStatus', |
|
| 362 | + * 'module' => 'smartshop')); |
|
| 363 | + * |
|
| 364 | + * In this example, the array elements are the following: |
|
| 365 | + * - name: false, as we don't need to set a special control here. |
|
| 366 | + * we will use the default control related to the object type (defined in initVar) |
|
| 367 | + * - itemHandler: name of the object for which we will use the handler |
|
| 368 | + * - method: name of the method of this handler that we will execute |
|
| 369 | + * - module: name of the module from wich the handler is |
|
| 370 | + * |
|
| 371 | + * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
| 372 | + * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
| 373 | + * |
|
| 374 | + * Another example of the use of $options as an array is for TextArea: |
|
| 375 | + * |
|
| 376 | + * $this->setControl('body', array('name' => 'textarea', |
|
| 377 | + * 'form_editor' => 'default')); |
|
| 378 | + * |
|
| 379 | + * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
| 380 | + * the 'default' editor, providing it is defined in the module |
|
| 381 | + * preferences: $xoopsModuleConfig['default_editor'] |
|
| 382 | + * |
|
| 383 | + * Of course, you can force the use of a specific editor: |
|
| 384 | + * |
|
| 385 | + * $this->setControl('body', array('name' => 'textarea', |
|
| 386 | + * 'form_editor' => 'koivi')); |
|
| 387 | + * |
|
| 388 | + * Here is a list of supported editor: |
|
| 389 | + * - tiny: TinyEditor |
|
| 390 | + * - dhtmltextarea: XOOPS DHTML Area |
|
| 391 | + * - fckeditor: FCKEditor |
|
| 392 | + * - inbetween: InBetween |
|
| 393 | + * - koivi: Koivi |
|
| 394 | + * - spaw: Spaw WYSIWYG Editor |
|
| 395 | + * - htmlarea: HTMLArea |
|
| 396 | + * - textarea: basic textarea with no options |
|
| 397 | + * |
|
| 398 | + * @param string $var name of the variable for which we want to set a control |
|
| 399 | + * @param array $options |
|
| 400 | + */ |
|
| 401 | + public function setControl($var, $options = array()) |
|
| 402 | + { |
|
| 403 | + if (isset($this->controls[$var])) { |
|
| 404 | + unset($this->controls[$var]); |
|
| 405 | + } |
|
| 406 | + if (is_string($options)) { |
|
| 407 | + $options = array('name' => $options); |
|
| 408 | + } |
|
| 409 | + $this->controls[$var] = $options; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Get control information for an instance variable |
|
| 414 | + * |
|
| 415 | + * @param string $var |
|
| 416 | + * @return bool|mixed |
|
| 417 | + */ |
|
| 418 | + public function getControl($var) |
|
| 419 | + { |
|
| 420 | + return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Create the form for this object |
|
| 425 | + * |
|
| 426 | + * @param $form_caption |
|
| 427 | + * @param $form_name |
|
| 428 | + * @param bool $form_action |
|
| 429 | + * @param string $submit_button_caption |
|
| 430 | + * @param bool $cancel_js_action |
|
| 431 | + * @param bool $captcha |
|
| 432 | + * @return a <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
| 433 | + * object for this object |
|
| 434 | + * @see SmartObjectForm::SmartObjectForm() |
|
| 435 | + */ |
|
| 436 | + public function getForm( |
|
| 437 | + $form_caption, |
|
| 438 | + $form_name, |
|
| 439 | + $form_action = false, |
|
| 440 | + $submit_button_caption = _CO_SOBJECT_SUBMIT, |
|
| 441 | + $cancel_js_action = false, |
|
| 442 | + $captcha = false |
|
| 443 | + ) { |
|
| 444 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
| 445 | + $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
| 446 | + |
|
| 447 | + return $form; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * @return array |
|
| 452 | + */ |
|
| 453 | + public function toArray() |
|
| 454 | + { |
|
| 455 | + $ret = array(); |
|
| 456 | + $vars =& $this->getVars(); |
|
| 457 | + foreach ($vars as $key => $var) { |
|
| 458 | + $value = $this->getVar($key); |
|
| 459 | + $ret[$key] = $value; |
|
| 460 | + } |
|
| 461 | + if ($this->handler->identifierName !== '') { |
|
| 462 | + $controller = new SmartObjectController($this->handler); |
|
| 463 | + /** |
|
| 464 | + * Addition of some automatic value |
|
| 465 | + */ |
|
| 466 | + $ret['itemLink'] = $controller->getItemLink($this); |
|
| 467 | + $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
| 468 | + $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
| 469 | + $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
| 470 | + $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // Hightlighting searched words |
|
| 474 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
|
| 475 | + $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
| 476 | + |
|
| 477 | + if ($highlight && isset($_GET['keywords'])) { |
|
| 478 | + $myts = MyTextSanitizer::getInstance(); |
|
| 479 | + $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
| 480 | + $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
| 481 | + foreach ($this->handler->highlightFields as $field) { |
|
| 482 | + $ret[$field] = $h->highlight($ret[$field]); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $ret; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * add an error |
|
| 491 | + * |
|
| 492 | + * @param $err_str |
|
| 493 | + * @param bool $prefix |
|
| 494 | + * @internal param string $value error to add |
|
| 495 | + * @access public |
|
| 496 | + */ |
|
| 497 | + public function setErrors($err_str, $prefix = false) |
|
| 498 | + { |
|
| 499 | + if (is_array($err_str)) { |
|
| 500 | + foreach ($err_str as $str) { |
|
| 501 | + $this->setErrors($str, $prefix); |
|
| 502 | + } |
|
| 503 | + } else { |
|
| 504 | + if ($prefix) { |
|
| 505 | + $err_str = '[' . $prefix . '] ' . $err_str; |
|
| 506 | + } |
|
| 507 | + parent::setErrors($err_str); |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * @param $field |
|
| 513 | + * @param bool $required |
|
| 514 | + */ |
|
| 515 | + public function setFieldAsRequired($field, $required = true) |
|
| 516 | + { |
|
| 517 | + if (is_array($field)) { |
|
| 518 | + foreach ($field as $v) { |
|
| 519 | + $this->doSetFieldAsRequired($v, $required); |
|
| 520 | + } |
|
| 521 | + } else { |
|
| 522 | + $this->doSetFieldAsRequired($field, $required); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * @param $field |
|
| 528 | + */ |
|
| 529 | + public function setFieldForSorting($field) |
|
| 530 | + { |
|
| 531 | + if (is_array($field)) { |
|
| 532 | + foreach ($field as $v) { |
|
| 533 | + $this->doSetFieldForSorting($v); |
|
| 534 | + } |
|
| 535 | + } else { |
|
| 536 | + $this->doSetFieldForSorting($field); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * @return bool |
|
| 542 | + */ |
|
| 543 | + public function hasError() |
|
| 544 | + { |
|
| 545 | + return count($this->_errors) > 0; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * @param $url |
|
| 550 | + * @param $path |
|
| 551 | + */ |
|
| 552 | + public function setImageDir($url, $path) |
|
| 553 | + { |
|
| 554 | + $this->_image_url = $url; |
|
| 555 | + $this->_image_path = $path; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Retreive the group that have been granted access to a specific permission for this object |
|
| 560 | + * |
|
| 561 | + * @param $group_perm |
|
| 562 | + * @return string $group_perm name of the permission |
|
| 563 | + */ |
|
| 564 | + public function getGroupPerm($group_perm) |
|
| 565 | + { |
|
| 566 | + if (!$this->handler->getPermissions()) { |
|
| 567 | + $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
| 568 | + |
|
| 569 | + return false; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
| 573 | + $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
| 574 | + |
|
| 575 | + if (count($ret) == 0) { |
|
| 576 | + return false; |
|
| 577 | + } else { |
|
| 578 | + return $ret; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * @param bool $path |
|
| 584 | + * @return mixed |
|
| 585 | + */ |
|
| 586 | + public function getImageDir($path = false) |
|
| 587 | + { |
|
| 588 | + if ($path) { |
|
| 589 | + return $this->_image_path; |
|
| 590 | + } else { |
|
| 591 | + return $this->_image_url; |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * @param bool $path |
|
| 597 | + * @return mixed |
|
| 598 | + */ |
|
| 599 | + public function getUploadDir($path = false) |
|
| 600 | + { |
|
| 601 | + if ($path) { |
|
| 602 | + return $this->_image_path; |
|
| 603 | + } else { |
|
| 604 | + return $this->_image_url; |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * @param string $key |
|
| 610 | + * @param string $info |
|
| 611 | + * @return array |
|
| 612 | + */ |
|
| 613 | + public function getVarInfo($key = '', $info = '') |
|
| 614 | + { |
|
| 615 | + if (isset($this->vars[$key][$info])) { |
|
| 616 | + return $this->vars[$key][$info]; |
|
| 617 | + } elseif ($info === '' && isset($this->vars[$key])) { |
|
| 618 | + return $this->vars[$key]; |
|
| 619 | + } else { |
|
| 620 | + return $this->vars; |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * Get the id of the object |
|
| 626 | + * |
|
| 627 | + * @return int id of this object |
|
| 628 | + */ |
|
| 629 | + public function id() |
|
| 630 | + { |
|
| 631 | + return $this->getVar($this->handler->keyName, 'e'); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * Return the value of the title field of this object |
|
| 636 | + * |
|
| 637 | + * @param string $format |
|
| 638 | + * @return string |
|
| 639 | + */ |
|
| 640 | + public function title($format = 's') |
|
| 641 | + { |
|
| 642 | + return $this->getVar($this->handler->identifierName, $format); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Return the value of the title field of this object |
|
| 647 | + * |
|
| 648 | + * @return string |
|
| 649 | + */ |
|
| 650 | + public function summary() |
|
| 651 | + { |
|
| 652 | + if ($this->handler->summaryName) { |
|
| 653 | + return $this->getVar($this->handler->summaryName); |
|
| 654 | + } else { |
|
| 655 | + return false; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Retreive the object admin side link, displayijng a SingleView page |
|
| 661 | + * |
|
| 662 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 663 | + * @return string user side link to the object |
|
| 664 | + */ |
|
| 665 | + public function getAdminViewItemLink($onlyUrl = false) |
|
| 666 | + { |
|
| 667 | + $controller = new SmartObjectController($this->handler); |
|
| 668 | + |
|
| 669 | + return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Retreive the object user side link |
|
| 674 | + * |
|
| 675 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
| 676 | + * @return string user side link to the object |
|
| 677 | + */ |
|
| 678 | + public function getItemLink($onlyUrl = false) |
|
| 679 | + { |
|
| 680 | + $controller = new SmartObjectController($this->handler); |
|
| 681 | + |
|
| 682 | + return $controller->getItemLink($this, $onlyUrl); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * @param bool $onlyUrl |
|
| 687 | + * @param bool $withimage |
|
| 688 | + * @param bool $userSide |
|
| 689 | + * @return string |
|
| 690 | + */ |
|
| 691 | + public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
| 692 | + { |
|
| 693 | + $controller = new SmartObjectController($this->handler); |
|
| 694 | + |
|
| 695 | + return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * @param bool $onlyUrl |
|
| 700 | + * @param bool $withimage |
|
| 701 | + * @param bool $userSide |
|
| 702 | + * @return string |
|
| 703 | + */ |
|
| 704 | + public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
| 705 | + { |
|
| 706 | + $controller = new SmartObjectController($this->handler); |
|
| 707 | + |
|
| 708 | + return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * @return string |
|
| 713 | + */ |
|
| 714 | + public function getPrintAndMailLink() |
|
| 715 | + { |
|
| 716 | + $controller = new SmartObjectController($this->handler); |
|
| 717 | + |
|
| 718 | + return $controller->getPrintAndMailLink($this); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * @param $sortsel |
|
| 723 | + * @return array|bool |
|
| 724 | + */ |
|
| 725 | + public function getFieldsForSorting($sortsel) |
|
| 726 | + { |
|
| 727 | + $ret = array(); |
|
| 728 | + |
|
| 729 | + foreach ($this->vars as $key => $field_info) { |
|
| 730 | + if ($field_info['sortby']) { |
|
| 731 | + $ret[$key]['caption'] = $field_info['form_caption']; |
|
| 732 | + $ret[$key]['selected'] = $key == $sortsel ? 'selected' : ''; |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + if (count($ret) > 0) { |
|
| 737 | + return $ret; |
|
| 738 | + } else { |
|
| 739 | + return false; |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + /** |
|
| 744 | + * @param $key |
|
| 745 | + * @param $newType |
|
| 746 | + */ |
|
| 747 | + public function setType($key, $newType) |
|
| 748 | + { |
|
| 749 | + $this->vars[$key]['data_type'] = $newType; |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + /** |
|
| 753 | + * @param $key |
|
| 754 | + * @param $info |
|
| 755 | + * @param $value |
|
| 756 | + */ |
|
| 757 | + public function setVarInfo($key, $info, $value) |
|
| 758 | + { |
|
| 759 | + $this->vars[$key][$info] = $value; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * @param $key |
|
| 764 | + * @param bool $editor |
|
| 765 | + * @return string |
|
| 766 | + */ |
|
| 767 | + public function getValueFor($key, $editor = true) |
|
| 768 | + { |
|
| 769 | + global $xoopsModuleConfig; |
|
| 770 | + |
|
| 771 | + $ret = $this->getVar($key, 'n'); |
|
| 772 | + $myts = MyTextSanitizer::getInstance(); |
|
| 773 | + |
|
| 774 | + $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
| 775 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 776 | + |
|
| 777 | + $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
| 778 | + $smiley = true; |
|
| 779 | + $xcode = true; |
|
| 780 | + $image = true; |
|
| 781 | + $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
| 782 | + $formatML = true; |
|
| 783 | + |
|
| 784 | + if ($form_editor === 'default') { |
|
| 785 | + global $xoopsModuleConfig; |
|
| 786 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + if ($editor) { |
|
| 790 | + if (defined('XOOPS_EDITOR_IS_HTML') |
|
| 791 | + && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) { |
|
| 792 | + $br = false; |
|
| 793 | + $formatML = !$editor; |
|
| 794 | + } else { |
|
| 795 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + if (method_exists($myts, 'formatForML')) { |
|
| 800 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
| 801 | + } else { |
|
| 802 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * clean values of all variables of the object for storage. |
|
| 808 | + * also add slashes whereever needed |
|
| 809 | + * |
|
| 810 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
| 811 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
| 812 | + * as a string separated by | |
|
| 813 | + * |
|
| 814 | + * @return bool true if successful |
|
| 815 | + * @access public |
|
| 816 | + */ |
|
| 817 | + public function cleanVars() |
|
| 818 | + { |
|
| 819 | + $ts = MyTextSanitizer::getInstance(); |
|
| 820 | + $existing_errors = $this->getErrors(); |
|
| 821 | + $this->_errors = array(); |
|
| 822 | + foreach ($this->vars as $k => $v) { |
|
| 823 | + $cleanv = $v['value']; |
|
| 824 | + if (!$v['changed']) { |
|
| 825 | + } else { |
|
| 826 | + $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
| 827 | + switch ($v['data_type']) { |
|
| 828 | + case XOBJ_DTYPE_TXTBOX: |
|
| 829 | + if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
| 830 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 831 | + continue 2; |
|
| 832 | + } |
|
| 833 | + if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
| 834 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
| 835 | + continue 2; |
|
| 836 | + } |
|
| 837 | + if (!$v['not_gpc']) { |
|
| 838 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
| 839 | + } else { |
|
| 840 | + $cleanv = $ts->censorString($cleanv); |
|
| 841 | + } |
|
| 842 | + break; |
|
| 843 | + case XOBJ_DTYPE_TXTAREA: |
|
| 844 | + if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
| 845 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 846 | + continue 2; |
|
| 847 | + } |
|
| 848 | + if (!$v['not_gpc']) { |
|
| 849 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
| 850 | + } else { |
|
| 851 | + $cleanv = $ts->censorString($cleanv); |
|
| 852 | + } |
|
| 853 | + break; |
|
| 854 | + case XOBJ_DTYPE_SOURCE: |
|
| 855 | + if (!$v['not_gpc']) { |
|
| 856 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
| 857 | + } else { |
|
| 858 | + $cleanv = $cleanv; |
|
| 859 | + } |
|
| 860 | + break; |
|
| 861 | + case XOBJ_DTYPE_INT: |
|
| 862 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 863 | + $cleanv = (int)$cleanv; |
|
| 864 | + break; |
|
| 865 | + |
|
| 866 | + case XOBJ_DTYPE_CURRENCY: |
|
| 867 | + $cleanv = smart_currency($cleanv); |
|
| 868 | + break; |
|
| 869 | + |
|
| 870 | + case XOBJ_DTYPE_FLOAT: |
|
| 871 | + $cleanv = smart_float($cleanv); |
|
| 872 | + break; |
|
| 873 | + |
|
| 874 | + case XOBJ_DTYPE_EMAIL: |
|
| 875 | + if ($v['required'] && $cleanv === '') { |
|
| 876 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 877 | + continue 2; |
|
| 878 | + } |
|
| 879 | + if ($cleanv !== '' |
|
| 880 | + && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
| 881 | + $this->setErrors('Invalid Email'); |
|
| 882 | + continue 2; |
|
| 883 | + } |
|
| 884 | + if (!$v['not_gpc']) { |
|
| 885 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
| 886 | + } |
|
| 887 | + break; |
|
| 888 | + case XOBJ_DTYPE_URL: |
|
| 889 | + if ($v['required'] && $cleanv === '') { |
|
| 890 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
| 891 | + continue 2; |
|
| 892 | + } |
|
| 893 | + if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
| 894 | + $cleanv = 'http://' . $cleanv; |
|
| 895 | + } |
|
| 896 | + if (!$v['not_gpc']) { |
|
| 897 | + $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
| 898 | + } |
|
| 899 | + break; |
|
| 900 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
| 901 | + $cleanv = implode('|', $cleanv); |
|
| 902 | + break; |
|
| 903 | + case XOBJ_DTYPE_ARRAY: |
|
| 904 | + $cleanv = serialize($cleanv); |
|
| 905 | + break; |
|
| 906 | + case XOBJ_DTYPE_STIME: |
|
| 907 | + case XOBJ_DTYPE_MTIME: |
|
| 908 | + case XOBJ_DTYPE_LTIME: |
|
| 909 | + $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
| 910 | + if (!($cleanv > 0)) { |
|
| 911 | + $cleanv = strtotime($cleanv); |
|
| 912 | + } |
|
| 913 | + break; |
|
| 914 | + default: |
|
| 915 | + break; |
|
| 916 | + } |
|
| 917 | + } |
|
| 918 | + $this->cleanVars[$k] =& $cleanv; |
|
| 919 | + unset($cleanv); |
|
| 920 | + } |
|
| 921 | + if (count($this->_errors) > 0) { |
|
| 922 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
| 923 | + |
|
| 924 | + return false; |
|
| 925 | + } |
|
| 926 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
| 927 | + $this->unsetDirty(); |
|
| 928 | + |
|
| 929 | + return true; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + /** |
|
| 933 | + * returns a specific variable for the object in a proper format |
|
| 934 | + * |
|
| 935 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
| 936 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
| 937 | + * as a string separated by | |
|
| 938 | + * |
|
| 939 | + * @access public |
|
| 940 | + * @param string $key key of the object's variable to be returned |
|
| 941 | + * @param string $format format to use for the output |
|
| 942 | + * @return mixed formatted value of the variable |
|
| 943 | + */ |
|
| 944 | + public function getVar($key, $format = 's') |
|
| 945 | + { |
|
| 946 | + global $myts; |
|
| 947 | + |
|
| 948 | + $ret = $this->vars[$key]['value']; |
|
| 949 | + |
|
| 950 | + switch ($this->vars[$key]['data_type']) { |
|
| 951 | + |
|
| 952 | + case XOBJ_DTYPE_TXTBOX: |
|
| 953 | + switch (strtolower($format)) { |
|
| 954 | + case 's': |
|
| 955 | + case 'show': |
|
| 956 | + // ML Hack by marcan |
|
| 957 | + $ts = MyTextSanitizer::getInstance(); |
|
| 958 | + $ret = $ts->htmlSpecialChars($ret); |
|
| 959 | + |
|
| 960 | + if (method_exists($myts, 'formatForML')) { |
|
| 961 | + return $ts->formatForML($ret); |
|
| 962 | + } else { |
|
| 963 | + return $ret; |
|
| 964 | + } |
|
| 965 | + break 1; |
|
| 966 | + // End of ML Hack by marcan |
|
| 967 | + |
|
| 968 | + case 'clean': |
|
| 969 | + $ts = MyTextSanitizer::getInstance(); |
|
| 970 | + |
|
| 971 | + $ret = smart_html2text($ret); |
|
| 972 | + $ret = smart_purifyText($ret); |
|
| 973 | + |
|
| 974 | + if (method_exists($myts, 'formatForML')) { |
|
| 975 | + return $ts->formatForML($ret); |
|
| 976 | + } else { |
|
| 977 | + return $ret; |
|
| 978 | + } |
|
| 979 | + break 1; |
|
| 980 | + // End of ML Hack by marcan |
|
| 981 | + |
|
| 982 | + case 'e': |
|
| 983 | + case 'edit': |
|
| 984 | + $ts = MyTextSanitizer::getInstance(); |
|
| 985 | + |
|
| 986 | + return $ts->htmlSpecialChars($ret); |
|
| 987 | + break 1; |
|
| 988 | + case 'p': |
|
| 989 | + case 'preview': |
|
| 990 | + case 'f': |
|
| 991 | + case 'formpreview': |
|
| 992 | + $ts = MyTextSanitizer::getInstance(); |
|
| 993 | + |
|
| 994 | + return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
| 995 | + break 1; |
|
| 996 | + case 'n': |
|
| 997 | + case 'none': |
|
| 998 | + default: |
|
| 999 | + break 1; |
|
| 1000 | + } |
|
| 1001 | + break; |
|
| 1002 | + case XOBJ_DTYPE_LTIME: |
|
| 1003 | + switch (strtolower($format)) { |
|
| 1004 | + case 's': |
|
| 1005 | + case 'show': |
|
| 1006 | + case 'p': |
|
| 1007 | + case 'preview': |
|
| 1008 | + case 'f': |
|
| 1009 | + case 'formpreview': |
|
| 1010 | + $ret = formatTimestamp($ret, _DATESTRING); |
|
| 1011 | + |
|
| 1012 | + return $ret; |
|
| 1013 | + break 1; |
|
| 1014 | + case 'n': |
|
| 1015 | + case 'none': |
|
| 1016 | + case 'e': |
|
| 1017 | + case 'edit': |
|
| 1018 | + break 1; |
|
| 1019 | + default: |
|
| 1020 | + break 1; |
|
| 1021 | + } |
|
| 1022 | + break; |
|
| 1023 | + case XOBJ_DTYPE_STIME: |
|
| 1024 | + switch (strtolower($format)) { |
|
| 1025 | + case 's': |
|
| 1026 | + case 'show': |
|
| 1027 | + case 'p': |
|
| 1028 | + case 'preview': |
|
| 1029 | + case 'f': |
|
| 1030 | + case 'formpreview': |
|
| 1031 | + $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
| 1032 | + |
|
| 1033 | + return $ret; |
|
| 1034 | + break 1; |
|
| 1035 | + case 'n': |
|
| 1036 | + case 'none': |
|
| 1037 | + case 'e': |
|
| 1038 | + case 'edit': |
|
| 1039 | + break 1; |
|
| 1040 | + default: |
|
| 1041 | + break 1; |
|
| 1042 | + } |
|
| 1043 | + break; |
|
| 1044 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 1045 | + switch (strtolower($format)) { |
|
| 1046 | + case 's': |
|
| 1047 | + case 'show': |
|
| 1048 | + case 'p': |
|
| 1049 | + case 'preview': |
|
| 1050 | + case 'f': |
|
| 1051 | + case 'formpreview': |
|
| 1052 | + $ret = formatTimestamp($ret, 'G:i'); |
|
| 1053 | + |
|
| 1054 | + return $ret; |
|
| 1055 | + break 1; |
|
| 1056 | + case 'n': |
|
| 1057 | + case 'none': |
|
| 1058 | + case 'e': |
|
| 1059 | + case 'edit': |
|
| 1060 | + break 1; |
|
| 1061 | + default: |
|
| 1062 | + break 1; |
|
| 1063 | + } |
|
| 1064 | + break; |
|
| 1065 | + |
|
| 1066 | + case XOBJ_DTYPE_CURRENCY: |
|
| 1067 | + $decimal_section_original = strstr($ret, '.'); |
|
| 1068 | + $decimal_section = $decimal_section_original; |
|
| 1069 | + if ($decimal_section) { |
|
| 1070 | + if (strlen($decimal_section) == 1) { |
|
| 1071 | + $decimal_section = '.00'; |
|
| 1072 | + } elseif (strlen($decimal_section) == 2) { |
|
| 1073 | + $decimal_section .= '0'; |
|
| 1074 | + } |
|
| 1075 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
| 1076 | + } else { |
|
| 1077 | + $ret .= '.00'; |
|
| 1078 | + } |
|
| 1079 | + break; |
|
| 1080 | + |
|
| 1081 | + case XOBJ_DTYPE_TXTAREA: |
|
| 1082 | + switch (strtolower($format)) { |
|
| 1083 | + case 's': |
|
| 1084 | + case 'show': |
|
| 1085 | + $ts = MyTextSanitizer::getInstance(); |
|
| 1086 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
| 1087 | + |
|
| 1088 | + $xcode = (!isset($this->vars['doxcode']['value']) |
|
| 1089 | + || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
| 1090 | + |
|
| 1091 | + $smiley = (!isset($this->vars['dosmiley']['value']) |
|
| 1092 | + || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
| 1093 | + $image = (!isset($this->vars['doimage']['value']) |
|
| 1094 | + || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
| 1095 | + $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
| 1096 | + |
|
| 1097 | + /** |
|
| 1098 | + * Hack by marcan <INBOX> for SCSPRO |
|
| 1099 | + * Setting mastop as the main editor |
|
| 1100 | + */ |
|
| 1101 | + if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
| 1102 | + $br = false; |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * Hack by marcan <INBOX> for SCSPRO |
|
| 1107 | + * Setting mastop as the main editor |
|
| 1108 | + */ |
|
| 1109 | + |
|
| 1110 | + return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 1111 | + break 1; |
|
| 1112 | + case 'e': |
|
| 1113 | + case 'edit': |
|
| 1114 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
| 1115 | + break 1; |
|
| 1116 | + case 'p': |
|
| 1117 | + case 'preview': |
|
| 1118 | + $ts = MyTextSanitizer::getInstance(); |
|
| 1119 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
| 1120 | + $xcode = (!isset($this->vars['doxcode']['value']) |
|
| 1121 | + || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
| 1122 | + $smiley = (!isset($this->vars['dosmiley']['value']) |
|
| 1123 | + || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
| 1124 | + $image = (!isset($this->vars['doimage']['value']) |
|
| 1125 | + || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
| 1126 | + $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
| 1127 | + |
|
| 1128 | + return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
| 1129 | + break 1; |
|
| 1130 | + case 'f': |
|
| 1131 | + case 'formpreview': |
|
| 1132 | + $ts = MyTextSanitizer::getInstance(); |
|
| 1133 | + |
|
| 1134 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
| 1135 | + break 1; |
|
| 1136 | + case 'n': |
|
| 1137 | + case 'none': |
|
| 1138 | + default: |
|
| 1139 | + break 1; |
|
| 1140 | + } |
|
| 1141 | + break; |
|
| 1142 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
| 1143 | + $ret =& explode('|', $ret); |
|
| 1144 | + break; |
|
| 1145 | + case XOBJ_DTYPE_ARRAY: |
|
| 1146 | + $ret =& unserialize($ret); |
|
| 1147 | + break; |
|
| 1148 | + case XOBJ_DTYPE_SOURCE: |
|
| 1149 | + switch (strtolower($format)) { |
|
| 1150 | + case 's': |
|
| 1151 | + case 'show': |
|
| 1152 | + break 1; |
|
| 1153 | + case 'e': |
|
| 1154 | + case 'edit': |
|
| 1155 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
| 1156 | + break 1; |
|
| 1157 | + case 'p': |
|
| 1158 | + case 'preview': |
|
| 1159 | + $ts = MyTextSanitizer::getInstance(); |
|
| 1160 | + |
|
| 1161 | + return $ts->stripSlashesGPC($ret); |
|
| 1162 | + break 1; |
|
| 1163 | + case 'f': |
|
| 1164 | + case 'formpreview': |
|
| 1165 | + $ts = MyTextSanitizer::getInstance(); |
|
| 1166 | + |
|
| 1167 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
| 1168 | + break 1; |
|
| 1169 | + case 'n': |
|
| 1170 | + case 'none': |
|
| 1171 | + default: |
|
| 1172 | + break 1; |
|
| 1173 | + } |
|
| 1174 | + break; |
|
| 1175 | + default: |
|
| 1176 | + if ($this->vars[$key]['options'] !== '' && $ret != '') { |
|
| 1177 | + switch (strtolower($format)) { |
|
| 1178 | + case 's': |
|
| 1179 | + case 'show': |
|
| 1180 | + $selected = explode('|', $ret); |
|
| 1181 | + $options = explode('|', $this->vars[$key]['options']); |
|
| 1182 | + $i = 1; |
|
| 1183 | + $ret = array(); |
|
| 1184 | + foreach ($options as $op) { |
|
| 1185 | + if (in_array($i, $selected)) { |
|
| 1186 | + $ret[] = $op; |
|
| 1187 | + } |
|
| 1188 | + ++$i; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + return implode(', ', $ret); |
|
| 1192 | + case 'e': |
|
| 1193 | + case 'edit': |
|
| 1194 | + $ret = explode('|', $ret); |
|
| 1195 | + break 1; |
|
| 1196 | + default: |
|
| 1197 | + break 1; |
|
| 1198 | + } |
|
| 1199 | + } |
|
| 1200 | + break; |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + return $ret; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * @param $key |
|
| 1208 | + */ |
|
| 1209 | + public function doMakeFieldreadOnly($key) |
|
| 1210 | + { |
|
| 1211 | + if (isset($this->vars[$key])) { |
|
| 1212 | + $this->vars[$key]['readonly'] = true; |
|
| 1213 | + $this->vars[$key]['displayOnForm'] = true; |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + /** |
|
| 1218 | + * @param $key |
|
| 1219 | + */ |
|
| 1220 | + public function makeFieldReadOnly($key) |
|
| 1221 | + { |
|
| 1222 | + if (is_array($key)) { |
|
| 1223 | + foreach ($key as $v) { |
|
| 1224 | + $this->doMakeFieldreadOnly($v); |
|
| 1225 | + } |
|
| 1226 | + } else { |
|
| 1227 | + $this->doMakeFieldreadOnly($key); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + /** |
|
| 1232 | + * @param $key |
|
| 1233 | + */ |
|
| 1234 | + public function doHideFieldFromForm($key) |
|
| 1235 | + { |
|
| 1236 | + if (isset($this->vars[$key])) { |
|
| 1237 | + $this->vars[$key]['displayOnForm'] = false; |
|
| 1238 | + } |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + /** |
|
| 1242 | + * @param $key |
|
| 1243 | + */ |
|
| 1244 | + public function doHideFieldFromSingleView($key) |
|
| 1245 | + { |
|
| 1246 | + if (isset($this->vars[$key])) { |
|
| 1247 | + $this->vars[$key]['displayOnSingleView'] = false; |
|
| 1248 | + } |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + /** |
|
| 1252 | + * @param $key |
|
| 1253 | + */ |
|
| 1254 | + public function hideFieldFromForm($key) |
|
| 1255 | + { |
|
| 1256 | + if (is_array($key)) { |
|
| 1257 | + foreach ($key as $v) { |
|
| 1258 | + $this->doHideFieldFromForm($v); |
|
| 1259 | + } |
|
| 1260 | + } else { |
|
| 1261 | + $this->doHideFieldFromForm($key); |
|
| 1262 | + } |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + /** |
|
| 1266 | + * @param $key |
|
| 1267 | + */ |
|
| 1268 | + public function hideFieldFromSingleView($key) |
|
| 1269 | + { |
|
| 1270 | + if (is_array($key)) { |
|
| 1271 | + foreach ($key as $v) { |
|
| 1272 | + $this->doHideFieldFromSingleView($v); |
|
| 1273 | + } |
|
| 1274 | + } else { |
|
| 1275 | + $this->doHideFieldFromSingleView($key); |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * @param $key |
|
| 1281 | + */ |
|
| 1282 | + public function doShowFieldOnForm($key) |
|
| 1283 | + { |
|
| 1284 | + if (isset($this->vars[$key])) { |
|
| 1285 | + $this->vars[$key]['displayOnForm'] = true; |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + /** |
|
| 1290 | + * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
| 1291 | + * |
|
| 1292 | + * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
| 1293 | + * @param bool $userSide for futur use, to do something different on the user side |
|
| 1294 | + * @param array $actions |
|
| 1295 | + * @param bool $headerAsRow |
|
| 1296 | + * @return content of the template if $fetchOnly or nothing if !$fetchOnly |
|
| 1297 | + */ |
|
| 1298 | + public function displaySingleObject( |
|
| 1299 | + $fetchOnly = false, |
|
| 1300 | + $userSide = false, |
|
| 1301 | + $actions = array(), |
|
| 1302 | + $headerAsRow = true |
|
| 1303 | + ) { |
|
| 1304 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
| 1305 | + $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
| 1306 | + // add all fields mark as displayOnSingleView except the keyid |
|
| 1307 | + foreach ($this->vars as $key => $var) { |
|
| 1308 | + if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
| 1309 | + $is_header = ($key == $this->handler->identifierName); |
|
| 1310 | + $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
| 1311 | + } |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + if ($fetchOnly) { |
|
| 1315 | + $ret = $singleview->render($fetchOnly); |
|
| 1316 | + |
|
| 1317 | + return $ret; |
|
| 1318 | + } else { |
|
| 1319 | + $singleview->render($fetchOnly); |
|
| 1320 | + } |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + /** |
|
| 1324 | + * @param $key |
|
| 1325 | + */ |
|
| 1326 | + public function doDisplayFieldOnSingleView($key) |
|
| 1327 | + { |
|
| 1328 | + if (isset($this->vars[$key])) { |
|
| 1329 | + $this->vars[$key]['displayOnSingleView'] = true; |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + /** |
|
| 1334 | + * @param $field |
|
| 1335 | + * @param bool $required |
|
| 1336 | + */ |
|
| 1337 | + public function doSetFieldAsRequired($field, $required = true) |
|
| 1338 | + { |
|
| 1339 | + $this->setVarInfo($field, 'required', $required); |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + /** |
|
| 1343 | + * @param $field |
|
| 1344 | + */ |
|
| 1345 | + public function doSetFieldForSorting($field) |
|
| 1346 | + { |
|
| 1347 | + $this->setVarInfo($field, 'sortby', true); |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + /** |
|
| 1351 | + * @param $key |
|
| 1352 | + */ |
|
| 1353 | + public function showFieldOnForm($key) |
|
| 1354 | + { |
|
| 1355 | + if (is_array($key)) { |
|
| 1356 | + foreach ($key as $v) { |
|
| 1357 | + $this->doShowFieldOnForm($v); |
|
| 1358 | + } |
|
| 1359 | + } else { |
|
| 1360 | + $this->doShowFieldOnForm($key); |
|
| 1361 | + } |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + /** |
|
| 1365 | + * @param $key |
|
| 1366 | + */ |
|
| 1367 | + public function displayFieldOnSingleView($key) |
|
| 1368 | + { |
|
| 1369 | + if (is_array($key)) { |
|
| 1370 | + foreach ($key as $v) { |
|
| 1371 | + $this->doDisplayFieldOnSingleView($v); |
|
| 1372 | + } |
|
| 1373 | + } else { |
|
| 1374 | + $this->doDisplayFieldOnSingleView($key); |
|
| 1375 | + } |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * @param $key |
|
| 1380 | + */ |
|
| 1381 | + public function doSetAdvancedFormFields($key) |
|
| 1382 | + { |
|
| 1383 | + if (isset($this->vars[$key])) { |
|
| 1384 | + $this->vars[$key]['advancedform'] = true; |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * @param $key |
|
| 1390 | + */ |
|
| 1391 | + public function setAdvancedFormFields($key) |
|
| 1392 | + { |
|
| 1393 | + if (is_array($key)) { |
|
| 1394 | + foreach ($key as $v) { |
|
| 1395 | + $this->doSetAdvancedFormFields($v); |
|
| 1396 | + } |
|
| 1397 | + } else { |
|
| 1398 | + $this->doSetAdvancedFormFields($key); |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | + |
|
| 1402 | + /** |
|
| 1403 | + * @param $key |
|
| 1404 | + * @return mixed |
|
| 1405 | + */ |
|
| 1406 | + public function getUrlLinkObj($key) |
|
| 1407 | + { |
|
| 1408 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
| 1409 | + $urllinkid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
| 1410 | + if ($urllinkid != 0) { |
|
| 1411 | + return $smartobjectLinkurlHandler->get($urllinkid); |
|
| 1412 | + } else { |
|
| 1413 | + return $smartobjectLinkurlHandler->create(); |
|
| 1414 | + } |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * @param $urlLinkObj |
|
| 1419 | + * @return mixed |
|
| 1420 | + */ |
|
| 1421 | + public function &storeUrlLinkObj($urlLinkObj) |
|
| 1422 | + { |
|
| 1423 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
| 1424 | + |
|
| 1425 | + return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + /** |
|
| 1429 | + * @param $key |
|
| 1430 | + * @return mixed |
|
| 1431 | + */ |
|
| 1432 | + public function getFileObj($key) |
|
| 1433 | + { |
|
| 1434 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
| 1435 | + $fileid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
| 1436 | + if ($fileid != 0) { |
|
| 1437 | + return $smartobjectFileHandler->get($fileid); |
|
| 1438 | + } else { |
|
| 1439 | + return $smartobjectFileHandler->create(); |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + /** |
|
| 1444 | + * @param $fileObj |
|
| 1445 | + * @return mixed |
|
| 1446 | + */ |
|
| 1447 | + public function &storeFileObj($fileObj) |
|
| 1448 | + { |
|
| 1449 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
| 1450 | + |
|
| 1451 | + return $smartobjectFileHandler->insert($fileObj); |
|
| 1452 | + } |
|
| 1453 | 1453 | } |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
| 14 | 14 | |
| 15 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 15 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
| 16 | 16 | |
| 17 | -require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 17 | +require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
| 18 | 18 | |
| 19 | 19 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
| 20 | 20 | define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function closeSection($section_name) |
| 115 | 115 | { |
| 116 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
| 116 | + $this->initVar('close_section_'.$section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
| 153 | 153 | if ($this->handler && (!$form_caption || $form_caption === '')) { |
| 154 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
| 154 | + $dyn_form_caption = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key); |
|
| 155 | 155 | if (defined($dyn_form_caption)) { |
| 156 | 156 | $form_caption = constant($dyn_form_caption); |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | if ($this->handler && (!$form_dsc || $form_dsc === '')) { |
| 160 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
| 160 | + $dyn_form_dsc = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key.'_DSC'); |
|
| 161 | 161 | if (defined($dyn_form_dsc)) { |
| 162 | 162 | $form_dsc = constant($dyn_form_dsc); |
| 163 | 163 | } |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | $cancel_js_action = false, |
| 442 | 442 | $captcha = false |
| 443 | 443 | ) { |
| 444 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
| 444 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/smartobjectform.php'; |
|
| 445 | 445 | $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
| 446 | 446 | |
| 447 | 447 | return $form; |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | public function toArray() |
| 454 | 454 | { |
| 455 | 455 | $ret = array(); |
| 456 | - $vars =& $this->getVars(); |
|
| 456 | + $vars = & $this->getVars(); |
|
| 457 | 457 | foreach ($vars as $key => $var) { |
| 458 | 458 | $value = $this->getVar($key); |
| 459 | 459 | $ret[$key] = $value; |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // Hightlighting searched words |
| 474 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
|
| 474 | + require_once SMARTOBJECT_ROOT_PATH.'class/smarthighlighter.php'; |
|
| 475 | 475 | $highlight = smart_getConfig('module_search_highlighter', false, true); |
| 476 | 476 | |
| 477 | 477 | if ($highlight && isset($_GET['keywords'])) { |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | } |
| 503 | 503 | } else { |
| 504 | 504 | if ($prefix) { |
| 505 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
| 505 | + $err_str = '['.$prefix.'] '.$err_str; |
|
| 506 | 506 | } |
| 507 | 507 | parent::setErrors($err_str); |
| 508 | 508 | } |
@@ -830,8 +830,8 @@ discard block |
||
| 830 | 830 | $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
| 831 | 831 | continue 2; |
| 832 | 832 | } |
| 833 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
| 834 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
| 833 | + if (isset($v['maxlength']) && strlen($cleanv) > (int) $v['maxlength']) { |
|
| 834 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int) $v['maxlength'])); |
|
| 835 | 835 | continue 2; |
| 836 | 836 | } |
| 837 | 837 | if (!$v['not_gpc']) { |
@@ -860,7 +860,7 @@ discard block |
||
| 860 | 860 | break; |
| 861 | 861 | case XOBJ_DTYPE_INT: |
| 862 | 862 | case XOBJ_DTYPE_TIME_ONLY: |
| 863 | - $cleanv = (int)$cleanv; |
|
| 863 | + $cleanv = (int) $cleanv; |
|
| 864 | 864 | break; |
| 865 | 865 | |
| 866 | 866 | case XOBJ_DTYPE_CURRENCY: |
@@ -891,10 +891,10 @@ discard block |
||
| 891 | 891 | continue 2; |
| 892 | 892 | } |
| 893 | 893 | if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
| 894 | - $cleanv = 'http://' . $cleanv; |
|
| 894 | + $cleanv = 'http://'.$cleanv; |
|
| 895 | 895 | } |
| 896 | 896 | if (!$v['not_gpc']) { |
| 897 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
| 897 | + $cleanv = & $ts->stripSlashesGPC($cleanv); |
|
| 898 | 898 | } |
| 899 | 899 | break; |
| 900 | 900 | case XOBJ_DTYPE_SIMPLE_ARRAY: |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | case XOBJ_DTYPE_STIME: |
| 907 | 907 | case XOBJ_DTYPE_MTIME: |
| 908 | 908 | case XOBJ_DTYPE_LTIME: |
| 909 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
| 909 | + $cleanv = !is_string($cleanv) ? (int) $cleanv : strtotime($cleanv); |
|
| 910 | 910 | if (!($cleanv > 0)) { |
| 911 | 911 | $cleanv = strtotime($cleanv); |
| 912 | 912 | } |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | break; |
| 916 | 916 | } |
| 917 | 917 | } |
| 918 | - $this->cleanVars[$k] =& $cleanv; |
|
| 918 | + $this->cleanVars[$k] = & $cleanv; |
|
| 919 | 919 | unset($cleanv); |
| 920 | 920 | } |
| 921 | 921 | if (count($this->_errors) > 0) { |
@@ -1140,10 +1140,10 @@ discard block |
||
| 1140 | 1140 | } |
| 1141 | 1141 | break; |
| 1142 | 1142 | case XOBJ_DTYPE_SIMPLE_ARRAY: |
| 1143 | - $ret =& explode('|', $ret); |
|
| 1143 | + $ret = & explode('|', $ret); |
|
| 1144 | 1144 | break; |
| 1145 | 1145 | case XOBJ_DTYPE_ARRAY: |
| 1146 | - $ret =& unserialize($ret); |
|
| 1146 | + $ret = & unserialize($ret); |
|
| 1147 | 1147 | break; |
| 1148 | 1148 | case XOBJ_DTYPE_SOURCE: |
| 1149 | 1149 | switch (strtolower($format)) { |
@@ -1301,7 +1301,7 @@ discard block |
||
| 1301 | 1301 | $actions = array(), |
| 1302 | 1302 | $headerAsRow = true |
| 1303 | 1303 | ) { |
| 1304 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
| 1304 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectsingleview.php'; |
|
| 1305 | 1305 | $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
| 1306 | 1306 | // add all fields mark as displayOnSingleView except the keyid |
| 1307 | 1307 | foreach ($this->vars as $key => $var) { |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * @param $criteria |
| 192 | - * @param $perm_name |
|
| 192 | + * @param boolean $perm_name |
|
| 193 | 193 | * @return bool |
| 194 | 194 | */ |
| 195 | 195 | public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
| 386 | - * @param $sql |
|
| 386 | + * @param string $sql |
|
| 387 | 387 | * @param $criteria |
| 388 | 388 | * @param bool $force |
| 389 | 389 | * @param bool $debug |
@@ -25,980 +25,980 @@ |
||
| 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 | - * @param string $itemname Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
| 135 | - * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
| 136 | - * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
| 137 | - * @param string $summaryName |
|
| 138 | - * @param string $modulename |
|
| 139 | - * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 140 | - * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 141 | - * @internal param string $moduleName name of the module |
|
| 142 | - */ |
|
| 143 | - public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
| 144 | - { |
|
| 145 | - parent::__construct($db); |
|
| 146 | - |
|
| 147 | - $this->_itemname = $itemname; |
|
| 148 | - $this->_moduleName = $modulename; |
|
| 149 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 150 | - $this->keyName = $keyname; |
|
| 151 | - $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 152 | - $this->identifierName = $idenfierName; |
|
| 153 | - $this->summaryName = $summaryName; |
|
| 154 | - $this->_page = $itemname . '.php'; |
|
| 155 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 156 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 157 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 158 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param $event |
|
| 163 | - * @param $method |
|
| 164 | - */ |
|
| 165 | - public function addEventHook($event, $method) |
|
| 166 | - { |
|
| 167 | - $this->_eventHooks[$event] = $method; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Add a permission that this handler will manage for its objects |
|
| 172 | - * |
|
| 173 | - * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
| 174 | - * |
|
| 175 | - * @param string $perm_name name of the permission |
|
| 176 | - * @param string $caption caption of the control that will be displayed in the form |
|
| 177 | - * @param bool|string $description description of the control that will be displayed in the form |
|
| 178 | - */ |
|
| 179 | - public function addPermission($perm_name, $caption, $description = false) |
|
| 180 | - { |
|
| 181 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
|
| 182 | - |
|
| 183 | - $this->permissionsArray[] = array( |
|
| 184 | - 'perm_name' => $perm_name, |
|
| 185 | - 'caption' => $caption, |
|
| 186 | - 'description' => $description |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @param $criteria |
|
| 192 | - * @param $perm_name |
|
| 193 | - * @return bool |
|
| 194 | - */ |
|
| 195 | - public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
|
| 196 | - { |
|
| 197 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
| 198 | - $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 199 | - if (count($grantedItems) > 0) { |
|
| 200 | - $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 201 | - |
|
| 202 | - return true; |
|
| 203 | - } else { |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param bool $_uploadPath |
|
| 210 | - * @param bool $_allowedMimeTypes |
|
| 211 | - * @param bool $_maxFileSize |
|
| 212 | - * @param bool $_maxWidth |
|
| 213 | - * @param bool $_maxHeight |
|
| 214 | - */ |
|
| 215 | - public function setUploaderConfig( |
|
| 216 | - $_uploadPath = false, |
|
| 217 | - $_allowedMimeTypes = false, |
|
| 218 | - $_maxFileSize = false, |
|
| 219 | - $_maxWidth = false, |
|
| 220 | - $_maxHeight = false |
|
| 221 | - ) { |
|
| 222 | - $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
| 223 | - $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
| 224 | - $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
| 225 | - $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
| 226 | - $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * create a new {@link SmartObject} |
|
| 231 | - * |
|
| 232 | - * @param bool $isNew Flag the new objects as "new"? |
|
| 233 | - * |
|
| 234 | - * @return SmartObject {@link SmartObject} |
|
| 235 | - */ |
|
| 236 | - public function create($isNew = true) |
|
| 237 | - { |
|
| 238 | - $obj = new $this->className($this); |
|
| 239 | - $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
| 240 | - if (!$obj->handler) { |
|
| 241 | - $obj->Handler = $this; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - if ($isNew === true) { |
|
| 245 | - $obj->setNew(); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - return $obj; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @return string |
|
| 253 | - */ |
|
| 254 | - public function getImageUrl() |
|
| 255 | - { |
|
| 256 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function getImagePath() |
|
| 263 | - { |
|
| 264 | - $dir = $this->_uploadPath . $this->_itemname; |
|
| 265 | - if (!file_exists($dir)) { |
|
| 266 | - smart_admin_mkdir($dir); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - return $dir . '/'; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * retrieve a {@link SmartObject} |
|
| 274 | - * |
|
| 275 | - * @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 |
|
| 276 | - * @param bool $as_object whether to return an object or an array |
|
| 277 | - * @param bool $debug |
|
| 278 | - * @param bool $criteria |
|
| 279 | - * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
| 280 | - * FALSE if failed |
|
| 281 | - */ |
|
| 282 | - public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
| 283 | - { |
|
| 284 | - if (!$criteria) { |
|
| 285 | - $criteria = new CriteriaCompo(); |
|
| 286 | - } |
|
| 287 | - if (is_array($this->keyName)) { |
|
| 288 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 289 | - /** |
|
| 290 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 291 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
| 292 | - */ |
|
| 293 | - //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
| 294 | - $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
| 295 | - } |
|
| 296 | - } else { |
|
| 297 | - //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
| 298 | - /** |
|
| 299 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 300 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
| 301 | - */ |
|
| 302 | - $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
| 303 | - } |
|
| 304 | - $criteria->setLimit(1); |
|
| 305 | - if ($debug) { |
|
| 306 | - $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
| 307 | - } else { |
|
| 308 | - $obj_array = $this->getObjects($criteria, false, $as_object); |
|
| 309 | - //patch: weird bug of indexing by id even if id_as_key = false; |
|
| 310 | - if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
| 311 | - $obj_array[0] = $obj_array[$id]; |
|
| 312 | - unset($obj_array[$id]); |
|
| 313 | - $obj_array[0]->unsetNew(); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - if (count($obj_array) != 1) { |
|
| 318 | - $obj = $this->create(); |
|
| 319 | - |
|
| 320 | - return $obj; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - return $obj_array[0]; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * retrieve a {@link SmartObject} |
|
| 328 | - * |
|
| 329 | - * @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 |
|
| 330 | - * @param bool $as_object whether to return an object or an array |
|
| 331 | - * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
| 332 | - */ |
|
| 333 | - public function &getD($id, $as_object = true) |
|
| 334 | - { |
|
| 335 | - return $this->get($id, $as_object, true); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * retrieve objects from the database |
|
| 340 | - * |
|
| 341 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 342 | - * @param bool $id_as_key use the ID as key for the array? |
|
| 343 | - * @param bool $as_object return an array of objects? |
|
| 344 | - * |
|
| 345 | - * @param bool $sql |
|
| 346 | - * @param bool $debug |
|
| 347 | - * @return array |
|
| 348 | - */ |
|
| 349 | - public function getObjects( |
|
| 350 | - CriteriaElement $criteria = null, |
|
| 351 | - $id_as_key = false, |
|
| 352 | - $as_object = true, |
|
| 353 | - $sql = false, |
|
| 354 | - $debug = false |
|
| 355 | - ) { |
|
| 356 | - $ret = array(); |
|
| 357 | - $limit = $start = 0; |
|
| 358 | - |
|
| 359 | - if ($this->generalSQL) { |
|
| 360 | - $sql = $this->generalSQL; |
|
| 361 | - } elseif (!$sql) { |
|
| 362 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 366 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 367 | - if ($criteria->getSort() !== '') { |
|
| 368 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 369 | - } |
|
| 370 | - $limit = $criteria->getLimit(); |
|
| 371 | - $start = $criteria->getStart(); |
|
| 372 | - } |
|
| 373 | - if ($debug) { |
|
| 374 | - xoops_debug($sql); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - $result = $this->db->query($sql, $limit, $start); |
|
| 378 | - if (!$result) { |
|
| 379 | - return $ret; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - return $this->convertResultSet($result, $id_as_key, $as_object); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @param $sql |
|
| 387 | - * @param $criteria |
|
| 388 | - * @param bool $force |
|
| 389 | - * @param bool $debug |
|
| 390 | - * @return array |
|
| 391 | - */ |
|
| 392 | - public function query($sql, $criteria, $force = false, $debug = false) |
|
| 393 | - { |
|
| 394 | - $ret = array(); |
|
| 395 | - |
|
| 396 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 397 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 398 | - if ($criteria->groupby) { |
|
| 399 | - $sql .= $criteria->getGroupby(); |
|
| 400 | - } |
|
| 401 | - if ($criteria->getSort() !== '') { |
|
| 402 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - if ($debug) { |
|
| 406 | - xoops_debug($sql); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - if ($force) { |
|
| 410 | - $result = $this->db->queryF($sql); |
|
| 411 | - } else { |
|
| 412 | - $result = $this->db->query($sql); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - if (!$result) { |
|
| 416 | - return $ret; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 420 | - $ret[] = $myrow; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $ret; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * retrieve objects with debug mode - so will show the query |
|
| 428 | - * |
|
| 429 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 430 | - * @param bool $id_as_key use the ID as key for the array? |
|
| 431 | - * @param bool $as_object return an array of objects? |
|
| 432 | - * |
|
| 433 | - * @param bool $sql |
|
| 434 | - * @return array |
|
| 435 | - */ |
|
| 436 | - public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
| 437 | - { |
|
| 438 | - return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @param $arrayObjects |
|
| 443 | - * @return array|bool |
|
| 444 | - */ |
|
| 445 | - public function getObjectsAsArray($arrayObjects) |
|
| 446 | - { |
|
| 447 | - $ret = array(); |
|
| 448 | - foreach ($arrayObjects as $key => $object) { |
|
| 449 | - $ret[$key] = $object->toArray(); |
|
| 450 | - } |
|
| 451 | - if (count($ret > 0)) { |
|
| 452 | - return $ret; |
|
| 453 | - } else { |
|
| 454 | - return false; |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Convert a database resultset to a returnable array |
|
| 460 | - * |
|
| 461 | - * @param object $result database resultset |
|
| 462 | - * @param bool $id_as_key - should NOT be used with joint keys |
|
| 463 | - * @param bool $as_object |
|
| 464 | - * |
|
| 465 | - * @return array |
|
| 466 | - */ |
|
| 467 | - public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
| 468 | - { |
|
| 469 | - $ret = array(); |
|
| 470 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 471 | - $obj = $this->create(false); |
|
| 472 | - $obj->assignVars($myrow); |
|
| 473 | - if (!$id_as_key) { |
|
| 474 | - if ($as_object) { |
|
| 475 | - $ret[] =& $obj; |
|
| 476 | - } else { |
|
| 477 | - $ret[] = $obj->toArray(); |
|
| 478 | - } |
|
| 479 | - } else { |
|
| 480 | - if ($as_object) { |
|
| 481 | - $value =& $obj; |
|
| 482 | - } else { |
|
| 483 | - $value = $obj->toArray(); |
|
| 484 | - } |
|
| 485 | - if ($id_as_key === 'parentid') { |
|
| 486 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 487 | - } else { |
|
| 488 | - $ret[$obj->getVar($this->keyName)] = $value; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - unset($obj); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $ret; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * @param null $criteria |
|
| 499 | - * @param int $limit |
|
| 500 | - * @param int $start |
|
| 501 | - * @return array |
|
| 502 | - */ |
|
| 503 | - public function getListD($criteria = null, $limit = 0, $start = 0) |
|
| 504 | - { |
|
| 505 | - return $this->getList($criteria, $limit, $start, true); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
| 510 | - * |
|
| 511 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 512 | - * @param int $limit Max number of objects to fetch |
|
| 513 | - * @param int $start Which record to start at |
|
| 514 | - * |
|
| 515 | - * @param bool $debug |
|
| 516 | - * @return array |
|
| 517 | - */ |
|
| 518 | - public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
| 519 | - { |
|
| 520 | - $ret = array(); |
|
| 521 | - if ($criteria === null) { |
|
| 522 | - $criteria = new CriteriaCompo(); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - if ($criteria->getSort() === '') { |
|
| 526 | - $criteria->setSort($this->getIdentifierName()); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 530 | - if (!empty($this->identifierName)) { |
|
| 531 | - $sql .= ', ' . $this->getIdentifierName(); |
|
| 532 | - } |
|
| 533 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 534 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 535 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 536 | - if ($criteria->getSort() !== '') { |
|
| 537 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 538 | - } |
|
| 539 | - $limit = $criteria->getLimit(); |
|
| 540 | - $start = $criteria->getStart(); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - if ($debug) { |
|
| 544 | - xoops_debug($sql); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - $result = $this->db->query($sql, $limit, $start); |
|
| 548 | - if (!$result) { |
|
| 549 | - return $ret; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - $myts = MyTextSanitizer::getInstance(); |
|
| 553 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 554 | - //identifiers should be textboxes, so sanitize them like that |
|
| 555 | - $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - return $ret; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * count objects matching a condition |
|
| 563 | - * |
|
| 564 | - * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
| 565 | - * @return int count of objects |
|
| 566 | - */ |
|
| 567 | - public function getCount(CriteriaElement $criteria = null) |
|
| 568 | - { |
|
| 569 | - $field = ''; |
|
| 570 | - $groupby = false; |
|
| 571 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 572 | - if ($criteria->groupby !== '') { |
|
| 573 | - $groupby = true; |
|
| 574 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - /** |
|
| 578 | - * if we have a generalSQL, lets used this one. |
|
| 579 | - * This needs to be improved... |
|
| 580 | - */ |
|
| 581 | - if ($this->generalSQL) { |
|
| 582 | - $sql = $this->generalSQL; |
|
| 583 | - $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
| 584 | - } else { |
|
| 585 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 586 | - } |
|
| 587 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 588 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 589 | - if ($criteria->groupby !== '') { |
|
| 590 | - $sql .= $criteria->getGroupby(); |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - $result = $this->db->query($sql); |
|
| 595 | - if (!$result) { |
|
| 596 | - return 0; |
|
| 597 | - } |
|
| 598 | - if ($groupby === false) { |
|
| 599 | - list($count) = $this->db->fetchRow($result); |
|
| 600 | - |
|
| 601 | - return $count; |
|
| 602 | - } else { |
|
| 603 | - $ret = array(); |
|
| 604 | - while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
| 605 | - $ret[$id] = $count; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - return $ret; |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * delete an object from the database |
|
| 614 | - * |
|
| 615 | - * @param XoopsObject $obj reference to the object to delete |
|
| 616 | - * @param bool $force |
|
| 617 | - * @return bool FALSE if failed. |
|
| 618 | - */ |
|
| 619 | - public function delete(XoopsObject $obj, $force = false) |
|
| 620 | - { |
|
| 621 | - $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
| 622 | - if (!$eventResult) { |
|
| 623 | - $obj->setErrors('An error occured during the BeforeDelete event'); |
|
| 624 | - |
|
| 625 | - return false; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - if (is_array($this->keyName)) { |
|
| 629 | - $clause = array(); |
|
| 630 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 631 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 632 | - } |
|
| 633 | - $whereclause = implode(' AND ', $clause); |
|
| 634 | - } else { |
|
| 635 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 636 | - } |
|
| 637 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 638 | - if (false !== $force) { |
|
| 639 | - $result = $this->db->queryF($sql); |
|
| 640 | - } else { |
|
| 641 | - $result = $this->db->query($sql); |
|
| 642 | - } |
|
| 643 | - if (!$result) { |
|
| 644 | - return false; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - $eventResult = $this->executeEvent('afterDelete', $obj); |
|
| 648 | - if (!$eventResult) { |
|
| 649 | - $obj->setErrors('An error occured during the AfterDelete event'); |
|
| 650 | - |
|
| 651 | - return false; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return true; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * @param $event |
|
| 659 | - */ |
|
| 660 | - public function disableEvent($event) |
|
| 661 | - { |
|
| 662 | - if (is_array($event)) { |
|
| 663 | - foreach ($event as $v) { |
|
| 664 | - $this->_disabledEvents[] = $v; |
|
| 665 | - } |
|
| 666 | - } else { |
|
| 667 | - $this->_disabledEvents[] = $event; |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * @return array |
|
| 673 | - */ |
|
| 674 | - public function getPermissions() |
|
| 675 | - { |
|
| 676 | - return $this->permissionsArray; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * insert a new object in the database |
|
| 681 | - * |
|
| 682 | - * @param XoopsObject $obj reference to the object |
|
| 683 | - * @param bool $force whether to force the query execution despite security settings |
|
| 684 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
| 685 | - * @param bool $debug |
|
| 686 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 687 | - */ |
|
| 688 | - public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
| 689 | - { |
|
| 690 | - if ($checkObject !== false) { |
|
| 691 | - if (!is_object($obj)) { |
|
| 692 | - return false; |
|
| 693 | - } |
|
| 694 | - /** |
|
| 695 | - * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
| 696 | - */ |
|
| 697 | - if (!is_a($obj, $this->className)) { |
|
| 698 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 699 | - |
|
| 700 | - return false; |
|
| 701 | - } |
|
| 702 | - if (!$obj->isDirty()) { |
|
| 703 | - $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 |
|
| 704 | - |
|
| 705 | - return true; |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - if ($obj->seoEnabled) { |
|
| 710 | - // Auto create meta tags if empty |
|
| 711 | - $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
| 712 | - |
|
| 713 | - if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
| 714 | - if (!$obj->meta_keywords()) { |
|
| 715 | - $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - if (!$obj->meta_description()) { |
|
| 719 | - $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - // Auto create short_url if empty |
|
| 724 | - if (!$obj->short_url()) { |
|
| 725 | - $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - $eventResult = $this->executeEvent('beforeSave', $obj); |
|
| 730 | - if (!$eventResult) { |
|
| 731 | - $obj->setErrors('An error occured during the BeforeSave event'); |
|
| 732 | - |
|
| 733 | - return false; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - if ($obj->isNew()) { |
|
| 737 | - $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
| 738 | - if (!$eventResult) { |
|
| 739 | - $obj->setErrors('An error occured during the BeforeInsert event'); |
|
| 740 | - |
|
| 741 | - return false; |
|
| 742 | - } |
|
| 743 | - } else { |
|
| 744 | - $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
| 745 | - if (!$eventResult) { |
|
| 746 | - $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
| 747 | - |
|
| 748 | - return false; |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - if (!$obj->cleanVars()) { |
|
| 752 | - $obj->setErrors('Variables were not cleaned properly.'); |
|
| 753 | - |
|
| 754 | - return false; |
|
| 755 | - } |
|
| 756 | - $fieldsToStoreInDB = array(); |
|
| 757 | - foreach ($obj->cleanVars as $k => $v) { |
|
| 758 | - if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
| 759 | - $cleanvars[$k] = (int)$v; |
|
| 760 | - } elseif (is_array($v)) { |
|
| 761 | - $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
| 762 | - } else { |
|
| 763 | - $cleanvars[$k] = $this->db->quoteString($v); |
|
| 764 | - } |
|
| 765 | - if ($obj->vars[$k]['persistent']) { |
|
| 766 | - $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - if ($obj->isNew()) { |
|
| 770 | - if (!is_array($this->keyName)) { |
|
| 771 | - if ($cleanvars[$this->keyName] < 1) { |
|
| 772 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 777 | - } else { |
|
| 778 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 779 | - foreach ($fieldsToStoreInDB as $key => $value) { |
|
| 780 | - if ((!is_array($this->keyName) && $key == $this->keyName) |
|
| 781 | - || (is_array($this->keyName) |
|
| 782 | - && in_array($key, $this->keyName))) { |
|
| 783 | - continue; |
|
| 784 | - } |
|
| 785 | - if (isset($notfirst)) { |
|
| 786 | - $sql .= ','; |
|
| 787 | - } |
|
| 788 | - $sql .= ' ' . $key . ' = ' . $value; |
|
| 789 | - $notfirst = true; |
|
| 790 | - } |
|
| 791 | - if (is_array($this->keyName)) { |
|
| 792 | - $whereclause = ''; |
|
| 793 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 794 | - if ($i > 0) { |
|
| 795 | - $whereclause .= ' AND '; |
|
| 796 | - } |
|
| 797 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 798 | - } |
|
| 799 | - } else { |
|
| 800 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 801 | - } |
|
| 802 | - $sql .= ' WHERE ' . $whereclause; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - if ($debug) { |
|
| 806 | - xoops_debug($sql); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if (false != $force) { |
|
| 810 | - $result = $this->db->queryF($sql); |
|
| 811 | - } else { |
|
| 812 | - $result = $this->db->query($sql); |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - if (!$result) { |
|
| 816 | - $obj->setErrors($this->db->error()); |
|
| 817 | - |
|
| 818 | - return false; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - if ($obj->isNew() && !is_array($this->keyName)) { |
|
| 822 | - $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
| 823 | - } |
|
| 824 | - $eventResult = $this->executeEvent('afterSave', $obj); |
|
| 825 | - if (!$eventResult) { |
|
| 826 | - $obj->setErrors('An error occured during the AfterSave event'); |
|
| 827 | - |
|
| 828 | - return false; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - if ($obj->isNew()) { |
|
| 832 | - $obj->unsetNew(); |
|
| 833 | - $eventResult = $this->executeEvent('afterInsert', $obj); |
|
| 834 | - if (!$eventResult) { |
|
| 835 | - $obj->setErrors('An error occured during the AfterInsert event'); |
|
| 836 | - |
|
| 837 | - return false; |
|
| 838 | - } |
|
| 839 | - } else { |
|
| 840 | - $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
| 841 | - if (!$eventResult) { |
|
| 842 | - $obj->setErrors('An error occured during the AfterUpdate event'); |
|
| 843 | - |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - return true; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * @param $obj |
|
| 853 | - * @param bool $force |
|
| 854 | - * @param bool $checkObject |
|
| 855 | - * @param bool $debug |
|
| 856 | - * @return bool |
|
| 857 | - */ |
|
| 858 | - public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
| 859 | - { |
|
| 860 | - return $this->insert($obj, $force, $checkObject, true); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Change a value for objects with a certain criteria |
|
| 865 | - * |
|
| 866 | - * @param string $fieldname Name of the field |
|
| 867 | - * @param string $fieldvalue Value to write |
|
| 868 | - * @param CriteriaElement $criteria {@link CriteriaElement} |
|
| 869 | - * |
|
| 870 | - * @param bool $force |
|
| 871 | - * @return bool |
|
| 872 | - */ |
|
| 873 | - public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
| 874 | - { |
|
| 875 | - $set_clause = $fieldname . ' = '; |
|
| 876 | - if (is_numeric($fieldvalue)) { |
|
| 877 | - $set_clause .= $fieldvalue; |
|
| 878 | - } elseif (is_array($fieldvalue)) { |
|
| 879 | - $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
| 880 | - } else { |
|
| 881 | - $set_clause .= $this->db->quoteString($fieldvalue); |
|
| 882 | - } |
|
| 883 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 884 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 885 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 886 | - } |
|
| 887 | - if (false != $force) { |
|
| 888 | - $result = $this->db->queryF($sql); |
|
| 889 | - } else { |
|
| 890 | - $result = $this->db->query($sql); |
|
| 891 | - } |
|
| 892 | - if (!$result) { |
|
| 893 | - return false; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - return true; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * delete all objects meeting the conditions |
|
| 901 | - * |
|
| 902 | - * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
| 903 | - * @return bool |
|
| 904 | - */ |
|
| 905 | - |
|
| 906 | - public function deleteAll(CriteriaElement $criteria = null) |
|
| 907 | - { |
|
| 908 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 909 | - $sql = 'DELETE FROM ' . $this->table; |
|
| 910 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 911 | - if (!$this->db->query($sql)) { |
|
| 912 | - return false; |
|
| 913 | - } |
|
| 914 | - $rows = $this->db->getAffectedRows(); |
|
| 915 | - |
|
| 916 | - return $rows > 0 ? $rows : true; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - return false; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - /** |
|
| 923 | - * @return mixed |
|
| 924 | - */ |
|
| 925 | - public function getModuleInfo() |
|
| 926 | - { |
|
| 927 | - return smart_getModuleInfo($this->_moduleName); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * @return bool |
|
| 932 | - */ |
|
| 933 | - public function getModuleConfig() |
|
| 934 | - { |
|
| 935 | - return smart_getModuleConfig($this->_moduleName); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * @return string |
|
| 940 | - */ |
|
| 941 | - public function getModuleItemString() |
|
| 942 | - { |
|
| 943 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 944 | - |
|
| 945 | - return $ret; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - /** |
|
| 949 | - * @param $object |
|
| 950 | - */ |
|
| 951 | - public function updateCounter($object) |
|
| 952 | - { |
|
| 953 | - if (isset($object->vars['counter'])) { |
|
| 954 | - $new_counter = $object->getVar('counter') + 1; |
|
| 955 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 956 | - $this->query($sql, null, true); |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - /** |
|
| 961 | - * Execute the function associated with an event |
|
| 962 | - * This method will check if the function is available |
|
| 963 | - * |
|
| 964 | - * @param string $event name of the event |
|
| 965 | - * @param $executeEventObj |
|
| 966 | - * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
| 967 | - * @internal param object $obj $object on which is performed the event |
|
| 968 | - */ |
|
| 969 | - public function executeEvent($event, &$executeEventObj) |
|
| 970 | - { |
|
| 971 | - if (!in_array($event, $this->_disabledEvents)) { |
|
| 972 | - if (method_exists($this, $event)) { |
|
| 973 | - $ret = $this->$event($executeEventObj); |
|
| 974 | - } else { |
|
| 975 | - // check to see if there is a hook for this event |
|
| 976 | - if (isset($this->_eventHooks[$event])) { |
|
| 977 | - $method = $this->_eventHooks[$event]; |
|
| 978 | - // check to see if the method specified by this hook exists |
|
| 979 | - if (method_exists($this, $method)) { |
|
| 980 | - $ret = $this->$method($executeEventObj); |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - $ret = true; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - return $ret; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - return true; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - /** |
|
| 993 | - * @param bool $withprefix |
|
| 994 | - * @return string |
|
| 995 | - */ |
|
| 996 | - public function getIdentifierName($withprefix = true) |
|
| 997 | - { |
|
| 998 | - if ($withprefix) { |
|
| 999 | - return $this->_itemname . '.' . $this->identifierName; |
|
| 1000 | - } else { |
|
| 1001 | - return $this->identifierName; |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 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 | + * @param string $itemname Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
| 135 | + * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
| 136 | + * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
| 137 | + * @param string $summaryName |
|
| 138 | + * @param string $modulename |
|
| 139 | + * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 140 | + * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 141 | + * @internal param string $moduleName name of the module |
|
| 142 | + */ |
|
| 143 | + public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
| 144 | + { |
|
| 145 | + parent::__construct($db); |
|
| 146 | + |
|
| 147 | + $this->_itemname = $itemname; |
|
| 148 | + $this->_moduleName = $modulename; |
|
| 149 | + $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 150 | + $this->keyName = $keyname; |
|
| 151 | + $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 152 | + $this->identifierName = $idenfierName; |
|
| 153 | + $this->summaryName = $summaryName; |
|
| 154 | + $this->_page = $itemname . '.php'; |
|
| 155 | + $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 156 | + $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 157 | + $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 158 | + $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param $event |
|
| 163 | + * @param $method |
|
| 164 | + */ |
|
| 165 | + public function addEventHook($event, $method) |
|
| 166 | + { |
|
| 167 | + $this->_eventHooks[$event] = $method; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Add a permission that this handler will manage for its objects |
|
| 172 | + * |
|
| 173 | + * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
| 174 | + * |
|
| 175 | + * @param string $perm_name name of the permission |
|
| 176 | + * @param string $caption caption of the control that will be displayed in the form |
|
| 177 | + * @param bool|string $description description of the control that will be displayed in the form |
|
| 178 | + */ |
|
| 179 | + public function addPermission($perm_name, $caption, $description = false) |
|
| 180 | + { |
|
| 181 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
|
| 182 | + |
|
| 183 | + $this->permissionsArray[] = array( |
|
| 184 | + 'perm_name' => $perm_name, |
|
| 185 | + 'caption' => $caption, |
|
| 186 | + 'description' => $description |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @param $criteria |
|
| 192 | + * @param $perm_name |
|
| 193 | + * @return bool |
|
| 194 | + */ |
|
| 195 | + public function setGrantedObjectsCriteria(&$criteria, $perm_name) |
|
| 196 | + { |
|
| 197 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
| 198 | + $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 199 | + if (count($grantedItems) > 0) { |
|
| 200 | + $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 201 | + |
|
| 202 | + return true; |
|
| 203 | + } else { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param bool $_uploadPath |
|
| 210 | + * @param bool $_allowedMimeTypes |
|
| 211 | + * @param bool $_maxFileSize |
|
| 212 | + * @param bool $_maxWidth |
|
| 213 | + * @param bool $_maxHeight |
|
| 214 | + */ |
|
| 215 | + public function setUploaderConfig( |
|
| 216 | + $_uploadPath = false, |
|
| 217 | + $_allowedMimeTypes = false, |
|
| 218 | + $_maxFileSize = false, |
|
| 219 | + $_maxWidth = false, |
|
| 220 | + $_maxHeight = false |
|
| 221 | + ) { |
|
| 222 | + $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
| 223 | + $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
| 224 | + $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
| 225 | + $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
| 226 | + $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * create a new {@link SmartObject} |
|
| 231 | + * |
|
| 232 | + * @param bool $isNew Flag the new objects as "new"? |
|
| 233 | + * |
|
| 234 | + * @return SmartObject {@link SmartObject} |
|
| 235 | + */ |
|
| 236 | + public function create($isNew = true) |
|
| 237 | + { |
|
| 238 | + $obj = new $this->className($this); |
|
| 239 | + $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
| 240 | + if (!$obj->handler) { |
|
| 241 | + $obj->Handler = $this; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + if ($isNew === true) { |
|
| 245 | + $obj->setNew(); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + return $obj; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @return string |
|
| 253 | + */ |
|
| 254 | + public function getImageUrl() |
|
| 255 | + { |
|
| 256 | + return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function getImagePath() |
|
| 263 | + { |
|
| 264 | + $dir = $this->_uploadPath . $this->_itemname; |
|
| 265 | + if (!file_exists($dir)) { |
|
| 266 | + smart_admin_mkdir($dir); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + return $dir . '/'; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * retrieve a {@link SmartObject} |
|
| 274 | + * |
|
| 275 | + * @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 |
|
| 276 | + * @param bool $as_object whether to return an object or an array |
|
| 277 | + * @param bool $debug |
|
| 278 | + * @param bool $criteria |
|
| 279 | + * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
| 280 | + * FALSE if failed |
|
| 281 | + */ |
|
| 282 | + public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
| 283 | + { |
|
| 284 | + if (!$criteria) { |
|
| 285 | + $criteria = new CriteriaCompo(); |
|
| 286 | + } |
|
| 287 | + if (is_array($this->keyName)) { |
|
| 288 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 289 | + /** |
|
| 290 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 291 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
| 292 | + */ |
|
| 293 | + //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
| 294 | + $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
| 295 | + } |
|
| 296 | + } else { |
|
| 297 | + //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
| 298 | + /** |
|
| 299 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 300 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
| 301 | + */ |
|
| 302 | + $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
| 303 | + } |
|
| 304 | + $criteria->setLimit(1); |
|
| 305 | + if ($debug) { |
|
| 306 | + $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
| 307 | + } else { |
|
| 308 | + $obj_array = $this->getObjects($criteria, false, $as_object); |
|
| 309 | + //patch: weird bug of indexing by id even if id_as_key = false; |
|
| 310 | + if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
| 311 | + $obj_array[0] = $obj_array[$id]; |
|
| 312 | + unset($obj_array[$id]); |
|
| 313 | + $obj_array[0]->unsetNew(); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + if (count($obj_array) != 1) { |
|
| 318 | + $obj = $this->create(); |
|
| 319 | + |
|
| 320 | + return $obj; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + return $obj_array[0]; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * retrieve a {@link SmartObject} |
|
| 328 | + * |
|
| 329 | + * @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 |
|
| 330 | + * @param bool $as_object whether to return an object or an array |
|
| 331 | + * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
| 332 | + */ |
|
| 333 | + public function &getD($id, $as_object = true) |
|
| 334 | + { |
|
| 335 | + return $this->get($id, $as_object, true); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * retrieve objects from the database |
|
| 340 | + * |
|
| 341 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 342 | + * @param bool $id_as_key use the ID as key for the array? |
|
| 343 | + * @param bool $as_object return an array of objects? |
|
| 344 | + * |
|
| 345 | + * @param bool $sql |
|
| 346 | + * @param bool $debug |
|
| 347 | + * @return array |
|
| 348 | + */ |
|
| 349 | + public function getObjects( |
|
| 350 | + CriteriaElement $criteria = null, |
|
| 351 | + $id_as_key = false, |
|
| 352 | + $as_object = true, |
|
| 353 | + $sql = false, |
|
| 354 | + $debug = false |
|
| 355 | + ) { |
|
| 356 | + $ret = array(); |
|
| 357 | + $limit = $start = 0; |
|
| 358 | + |
|
| 359 | + if ($this->generalSQL) { |
|
| 360 | + $sql = $this->generalSQL; |
|
| 361 | + } elseif (!$sql) { |
|
| 362 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 366 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 367 | + if ($criteria->getSort() !== '') { |
|
| 368 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 369 | + } |
|
| 370 | + $limit = $criteria->getLimit(); |
|
| 371 | + $start = $criteria->getStart(); |
|
| 372 | + } |
|
| 373 | + if ($debug) { |
|
| 374 | + xoops_debug($sql); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + $result = $this->db->query($sql, $limit, $start); |
|
| 378 | + if (!$result) { |
|
| 379 | + return $ret; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + return $this->convertResultSet($result, $id_as_key, $as_object); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @param $sql |
|
| 387 | + * @param $criteria |
|
| 388 | + * @param bool $force |
|
| 389 | + * @param bool $debug |
|
| 390 | + * @return array |
|
| 391 | + */ |
|
| 392 | + public function query($sql, $criteria, $force = false, $debug = false) |
|
| 393 | + { |
|
| 394 | + $ret = array(); |
|
| 395 | + |
|
| 396 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 397 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 398 | + if ($criteria->groupby) { |
|
| 399 | + $sql .= $criteria->getGroupby(); |
|
| 400 | + } |
|
| 401 | + if ($criteria->getSort() !== '') { |
|
| 402 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + if ($debug) { |
|
| 406 | + xoops_debug($sql); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + if ($force) { |
|
| 410 | + $result = $this->db->queryF($sql); |
|
| 411 | + } else { |
|
| 412 | + $result = $this->db->query($sql); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + if (!$result) { |
|
| 416 | + return $ret; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 420 | + $ret[] = $myrow; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $ret; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * retrieve objects with debug mode - so will show the query |
|
| 428 | + * |
|
| 429 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 430 | + * @param bool $id_as_key use the ID as key for the array? |
|
| 431 | + * @param bool $as_object return an array of objects? |
|
| 432 | + * |
|
| 433 | + * @param bool $sql |
|
| 434 | + * @return array |
|
| 435 | + */ |
|
| 436 | + public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
| 437 | + { |
|
| 438 | + return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @param $arrayObjects |
|
| 443 | + * @return array|bool |
|
| 444 | + */ |
|
| 445 | + public function getObjectsAsArray($arrayObjects) |
|
| 446 | + { |
|
| 447 | + $ret = array(); |
|
| 448 | + foreach ($arrayObjects as $key => $object) { |
|
| 449 | + $ret[$key] = $object->toArray(); |
|
| 450 | + } |
|
| 451 | + if (count($ret > 0)) { |
|
| 452 | + return $ret; |
|
| 453 | + } else { |
|
| 454 | + return false; |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Convert a database resultset to a returnable array |
|
| 460 | + * |
|
| 461 | + * @param object $result database resultset |
|
| 462 | + * @param bool $id_as_key - should NOT be used with joint keys |
|
| 463 | + * @param bool $as_object |
|
| 464 | + * |
|
| 465 | + * @return array |
|
| 466 | + */ |
|
| 467 | + public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
| 468 | + { |
|
| 469 | + $ret = array(); |
|
| 470 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 471 | + $obj = $this->create(false); |
|
| 472 | + $obj->assignVars($myrow); |
|
| 473 | + if (!$id_as_key) { |
|
| 474 | + if ($as_object) { |
|
| 475 | + $ret[] =& $obj; |
|
| 476 | + } else { |
|
| 477 | + $ret[] = $obj->toArray(); |
|
| 478 | + } |
|
| 479 | + } else { |
|
| 480 | + if ($as_object) { |
|
| 481 | + $value =& $obj; |
|
| 482 | + } else { |
|
| 483 | + $value = $obj->toArray(); |
|
| 484 | + } |
|
| 485 | + if ($id_as_key === 'parentid') { |
|
| 486 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 487 | + } else { |
|
| 488 | + $ret[$obj->getVar($this->keyName)] = $value; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + unset($obj); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $ret; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * @param null $criteria |
|
| 499 | + * @param int $limit |
|
| 500 | + * @param int $start |
|
| 501 | + * @return array |
|
| 502 | + */ |
|
| 503 | + public function getListD($criteria = null, $limit = 0, $start = 0) |
|
| 504 | + { |
|
| 505 | + return $this->getList($criteria, $limit, $start, true); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
| 510 | + * |
|
| 511 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 512 | + * @param int $limit Max number of objects to fetch |
|
| 513 | + * @param int $start Which record to start at |
|
| 514 | + * |
|
| 515 | + * @param bool $debug |
|
| 516 | + * @return array |
|
| 517 | + */ |
|
| 518 | + public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
| 519 | + { |
|
| 520 | + $ret = array(); |
|
| 521 | + if ($criteria === null) { |
|
| 522 | + $criteria = new CriteriaCompo(); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + if ($criteria->getSort() === '') { |
|
| 526 | + $criteria->setSort($this->getIdentifierName()); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 530 | + if (!empty($this->identifierName)) { |
|
| 531 | + $sql .= ', ' . $this->getIdentifierName(); |
|
| 532 | + } |
|
| 533 | + $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 534 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 535 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 536 | + if ($criteria->getSort() !== '') { |
|
| 537 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 538 | + } |
|
| 539 | + $limit = $criteria->getLimit(); |
|
| 540 | + $start = $criteria->getStart(); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + if ($debug) { |
|
| 544 | + xoops_debug($sql); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + $result = $this->db->query($sql, $limit, $start); |
|
| 548 | + if (!$result) { |
|
| 549 | + return $ret; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + $myts = MyTextSanitizer::getInstance(); |
|
| 553 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 554 | + //identifiers should be textboxes, so sanitize them like that |
|
| 555 | + $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + return $ret; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * count objects matching a condition |
|
| 563 | + * |
|
| 564 | + * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
| 565 | + * @return int count of objects |
|
| 566 | + */ |
|
| 567 | + public function getCount(CriteriaElement $criteria = null) |
|
| 568 | + { |
|
| 569 | + $field = ''; |
|
| 570 | + $groupby = false; |
|
| 571 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 572 | + if ($criteria->groupby !== '') { |
|
| 573 | + $groupby = true; |
|
| 574 | + $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + /** |
|
| 578 | + * if we have a generalSQL, lets used this one. |
|
| 579 | + * This needs to be improved... |
|
| 580 | + */ |
|
| 581 | + if ($this->generalSQL) { |
|
| 582 | + $sql = $this->generalSQL; |
|
| 583 | + $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
| 584 | + } else { |
|
| 585 | + $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 586 | + } |
|
| 587 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 588 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 589 | + if ($criteria->groupby !== '') { |
|
| 590 | + $sql .= $criteria->getGroupby(); |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + $result = $this->db->query($sql); |
|
| 595 | + if (!$result) { |
|
| 596 | + return 0; |
|
| 597 | + } |
|
| 598 | + if ($groupby === false) { |
|
| 599 | + list($count) = $this->db->fetchRow($result); |
|
| 600 | + |
|
| 601 | + return $count; |
|
| 602 | + } else { |
|
| 603 | + $ret = array(); |
|
| 604 | + while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
| 605 | + $ret[$id] = $count; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + return $ret; |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * delete an object from the database |
|
| 614 | + * |
|
| 615 | + * @param XoopsObject $obj reference to the object to delete |
|
| 616 | + * @param bool $force |
|
| 617 | + * @return bool FALSE if failed. |
|
| 618 | + */ |
|
| 619 | + public function delete(XoopsObject $obj, $force = false) |
|
| 620 | + { |
|
| 621 | + $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
| 622 | + if (!$eventResult) { |
|
| 623 | + $obj->setErrors('An error occured during the BeforeDelete event'); |
|
| 624 | + |
|
| 625 | + return false; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + if (is_array($this->keyName)) { |
|
| 629 | + $clause = array(); |
|
| 630 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 631 | + $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 632 | + } |
|
| 633 | + $whereclause = implode(' AND ', $clause); |
|
| 634 | + } else { |
|
| 635 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 636 | + } |
|
| 637 | + $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 638 | + if (false !== $force) { |
|
| 639 | + $result = $this->db->queryF($sql); |
|
| 640 | + } else { |
|
| 641 | + $result = $this->db->query($sql); |
|
| 642 | + } |
|
| 643 | + if (!$result) { |
|
| 644 | + return false; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + $eventResult = $this->executeEvent('afterDelete', $obj); |
|
| 648 | + if (!$eventResult) { |
|
| 649 | + $obj->setErrors('An error occured during the AfterDelete event'); |
|
| 650 | + |
|
| 651 | + return false; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return true; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * @param $event |
|
| 659 | + */ |
|
| 660 | + public function disableEvent($event) |
|
| 661 | + { |
|
| 662 | + if (is_array($event)) { |
|
| 663 | + foreach ($event as $v) { |
|
| 664 | + $this->_disabledEvents[] = $v; |
|
| 665 | + } |
|
| 666 | + } else { |
|
| 667 | + $this->_disabledEvents[] = $event; |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * @return array |
|
| 673 | + */ |
|
| 674 | + public function getPermissions() |
|
| 675 | + { |
|
| 676 | + return $this->permissionsArray; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * insert a new object in the database |
|
| 681 | + * |
|
| 682 | + * @param XoopsObject $obj reference to the object |
|
| 683 | + * @param bool $force whether to force the query execution despite security settings |
|
| 684 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
| 685 | + * @param bool $debug |
|
| 686 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 687 | + */ |
|
| 688 | + public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
| 689 | + { |
|
| 690 | + if ($checkObject !== false) { |
|
| 691 | + if (!is_object($obj)) { |
|
| 692 | + return false; |
|
| 693 | + } |
|
| 694 | + /** |
|
| 695 | + * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
| 696 | + */ |
|
| 697 | + if (!is_a($obj, $this->className)) { |
|
| 698 | + $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 699 | + |
|
| 700 | + return false; |
|
| 701 | + } |
|
| 702 | + if (!$obj->isDirty()) { |
|
| 703 | + $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 |
|
| 704 | + |
|
| 705 | + return true; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + if ($obj->seoEnabled) { |
|
| 710 | + // Auto create meta tags if empty |
|
| 711 | + $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
| 712 | + |
|
| 713 | + if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
| 714 | + if (!$obj->meta_keywords()) { |
|
| 715 | + $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + if (!$obj->meta_description()) { |
|
| 719 | + $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + // Auto create short_url if empty |
|
| 724 | + if (!$obj->short_url()) { |
|
| 725 | + $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + $eventResult = $this->executeEvent('beforeSave', $obj); |
|
| 730 | + if (!$eventResult) { |
|
| 731 | + $obj->setErrors('An error occured during the BeforeSave event'); |
|
| 732 | + |
|
| 733 | + return false; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + if ($obj->isNew()) { |
|
| 737 | + $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
| 738 | + if (!$eventResult) { |
|
| 739 | + $obj->setErrors('An error occured during the BeforeInsert event'); |
|
| 740 | + |
|
| 741 | + return false; |
|
| 742 | + } |
|
| 743 | + } else { |
|
| 744 | + $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
| 745 | + if (!$eventResult) { |
|
| 746 | + $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
| 747 | + |
|
| 748 | + return false; |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + if (!$obj->cleanVars()) { |
|
| 752 | + $obj->setErrors('Variables were not cleaned properly.'); |
|
| 753 | + |
|
| 754 | + return false; |
|
| 755 | + } |
|
| 756 | + $fieldsToStoreInDB = array(); |
|
| 757 | + foreach ($obj->cleanVars as $k => $v) { |
|
| 758 | + if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
| 759 | + $cleanvars[$k] = (int)$v; |
|
| 760 | + } elseif (is_array($v)) { |
|
| 761 | + $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
| 762 | + } else { |
|
| 763 | + $cleanvars[$k] = $this->db->quoteString($v); |
|
| 764 | + } |
|
| 765 | + if ($obj->vars[$k]['persistent']) { |
|
| 766 | + $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + if ($obj->isNew()) { |
|
| 770 | + if (!is_array($this->keyName)) { |
|
| 771 | + if ($cleanvars[$this->keyName] < 1) { |
|
| 772 | + $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 777 | + } else { |
|
| 778 | + $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 779 | + foreach ($fieldsToStoreInDB as $key => $value) { |
|
| 780 | + if ((!is_array($this->keyName) && $key == $this->keyName) |
|
| 781 | + || (is_array($this->keyName) |
|
| 782 | + && in_array($key, $this->keyName))) { |
|
| 783 | + continue; |
|
| 784 | + } |
|
| 785 | + if (isset($notfirst)) { |
|
| 786 | + $sql .= ','; |
|
| 787 | + } |
|
| 788 | + $sql .= ' ' . $key . ' = ' . $value; |
|
| 789 | + $notfirst = true; |
|
| 790 | + } |
|
| 791 | + if (is_array($this->keyName)) { |
|
| 792 | + $whereclause = ''; |
|
| 793 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 794 | + if ($i > 0) { |
|
| 795 | + $whereclause .= ' AND '; |
|
| 796 | + } |
|
| 797 | + $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 798 | + } |
|
| 799 | + } else { |
|
| 800 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 801 | + } |
|
| 802 | + $sql .= ' WHERE ' . $whereclause; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + if ($debug) { |
|
| 806 | + xoops_debug($sql); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if (false != $force) { |
|
| 810 | + $result = $this->db->queryF($sql); |
|
| 811 | + } else { |
|
| 812 | + $result = $this->db->query($sql); |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + if (!$result) { |
|
| 816 | + $obj->setErrors($this->db->error()); |
|
| 817 | + |
|
| 818 | + return false; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + if ($obj->isNew() && !is_array($this->keyName)) { |
|
| 822 | + $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
| 823 | + } |
|
| 824 | + $eventResult = $this->executeEvent('afterSave', $obj); |
|
| 825 | + if (!$eventResult) { |
|
| 826 | + $obj->setErrors('An error occured during the AfterSave event'); |
|
| 827 | + |
|
| 828 | + return false; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + if ($obj->isNew()) { |
|
| 832 | + $obj->unsetNew(); |
|
| 833 | + $eventResult = $this->executeEvent('afterInsert', $obj); |
|
| 834 | + if (!$eventResult) { |
|
| 835 | + $obj->setErrors('An error occured during the AfterInsert event'); |
|
| 836 | + |
|
| 837 | + return false; |
|
| 838 | + } |
|
| 839 | + } else { |
|
| 840 | + $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
| 841 | + if (!$eventResult) { |
|
| 842 | + $obj->setErrors('An error occured during the AfterUpdate event'); |
|
| 843 | + |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + return true; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * @param $obj |
|
| 853 | + * @param bool $force |
|
| 854 | + * @param bool $checkObject |
|
| 855 | + * @param bool $debug |
|
| 856 | + * @return bool |
|
| 857 | + */ |
|
| 858 | + public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
| 859 | + { |
|
| 860 | + return $this->insert($obj, $force, $checkObject, true); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Change a value for objects with a certain criteria |
|
| 865 | + * |
|
| 866 | + * @param string $fieldname Name of the field |
|
| 867 | + * @param string $fieldvalue Value to write |
|
| 868 | + * @param CriteriaElement $criteria {@link CriteriaElement} |
|
| 869 | + * |
|
| 870 | + * @param bool $force |
|
| 871 | + * @return bool |
|
| 872 | + */ |
|
| 873 | + public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
| 874 | + { |
|
| 875 | + $set_clause = $fieldname . ' = '; |
|
| 876 | + if (is_numeric($fieldvalue)) { |
|
| 877 | + $set_clause .= $fieldvalue; |
|
| 878 | + } elseif (is_array($fieldvalue)) { |
|
| 879 | + $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
| 880 | + } else { |
|
| 881 | + $set_clause .= $this->db->quoteString($fieldvalue); |
|
| 882 | + } |
|
| 883 | + $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 884 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 885 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 886 | + } |
|
| 887 | + if (false != $force) { |
|
| 888 | + $result = $this->db->queryF($sql); |
|
| 889 | + } else { |
|
| 890 | + $result = $this->db->query($sql); |
|
| 891 | + } |
|
| 892 | + if (!$result) { |
|
| 893 | + return false; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + return true; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * delete all objects meeting the conditions |
|
| 901 | + * |
|
| 902 | + * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
| 903 | + * @return bool |
|
| 904 | + */ |
|
| 905 | + |
|
| 906 | + public function deleteAll(CriteriaElement $criteria = null) |
|
| 907 | + { |
|
| 908 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
| 909 | + $sql = 'DELETE FROM ' . $this->table; |
|
| 910 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 911 | + if (!$this->db->query($sql)) { |
|
| 912 | + return false; |
|
| 913 | + } |
|
| 914 | + $rows = $this->db->getAffectedRows(); |
|
| 915 | + |
|
| 916 | + return $rows > 0 ? $rows : true; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + return false; |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + /** |
|
| 923 | + * @return mixed |
|
| 924 | + */ |
|
| 925 | + public function getModuleInfo() |
|
| 926 | + { |
|
| 927 | + return smart_getModuleInfo($this->_moduleName); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * @return bool |
|
| 932 | + */ |
|
| 933 | + public function getModuleConfig() |
|
| 934 | + { |
|
| 935 | + return smart_getModuleConfig($this->_moduleName); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * @return string |
|
| 940 | + */ |
|
| 941 | + public function getModuleItemString() |
|
| 942 | + { |
|
| 943 | + $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 944 | + |
|
| 945 | + return $ret; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + /** |
|
| 949 | + * @param $object |
|
| 950 | + */ |
|
| 951 | + public function updateCounter($object) |
|
| 952 | + { |
|
| 953 | + if (isset($object->vars['counter'])) { |
|
| 954 | + $new_counter = $object->getVar('counter') + 1; |
|
| 955 | + $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 956 | + $this->query($sql, null, true); |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + /** |
|
| 961 | + * Execute the function associated with an event |
|
| 962 | + * This method will check if the function is available |
|
| 963 | + * |
|
| 964 | + * @param string $event name of the event |
|
| 965 | + * @param $executeEventObj |
|
| 966 | + * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
| 967 | + * @internal param object $obj $object on which is performed the event |
|
| 968 | + */ |
|
| 969 | + public function executeEvent($event, &$executeEventObj) |
|
| 970 | + { |
|
| 971 | + if (!in_array($event, $this->_disabledEvents)) { |
|
| 972 | + if (method_exists($this, $event)) { |
|
| 973 | + $ret = $this->$event($executeEventObj); |
|
| 974 | + } else { |
|
| 975 | + // check to see if there is a hook for this event |
|
| 976 | + if (isset($this->_eventHooks[$event])) { |
|
| 977 | + $method = $this->_eventHooks[$event]; |
|
| 978 | + // check to see if the method specified by this hook exists |
|
| 979 | + if (method_exists($this, $method)) { |
|
| 980 | + $ret = $this->$method($executeEventObj); |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + $ret = true; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + return $ret; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + return true; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + /** |
|
| 993 | + * @param bool $withprefix |
|
| 994 | + * @return string |
|
| 995 | + */ |
|
| 996 | + public function getIdentifierName($withprefix = true) |
|
| 997 | + { |
|
| 998 | + if ($withprefix) { |
|
| 999 | + return $this->_itemname . '.' . $this->identifierName; |
|
| 1000 | + } else { |
|
| 1001 | + return $this->identifierName; |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | 1004 | } |
@@ -146,16 +146,16 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | $this->_itemname = $itemname; |
| 148 | 148 | $this->_moduleName = $modulename; |
| 149 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 149 | + $this->table = $db->prefix($modulename.'_'.$itemname); |
|
| 150 | 150 | $this->keyName = $keyname; |
| 151 | - $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 151 | + $this->className = ucfirst($modulename).ucfirst($itemname); |
|
| 152 | 152 | $this->identifierName = $idenfierName; |
| 153 | 153 | $this->summaryName = $summaryName; |
| 154 | - $this->_page = $itemname . '.php'; |
|
| 155 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 156 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 157 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 158 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 154 | + $this->_page = $itemname.'.php'; |
|
| 155 | + $this->_modulePath = XOOPS_ROOT_PATH.'/modules/'.$this->_moduleName.'/'; |
|
| 156 | + $this->_moduleUrl = XOOPS_URL.'/modules/'.$this->_moduleName.'/'; |
|
| 157 | + $this->_uploadPath = XOOPS_UPLOAD_PATH.'/'.$this->_moduleName.'/'; |
|
| 158 | + $this->_uploadUrl = XOOPS_UPLOAD_URL.'/'.$this->_moduleName.'/'; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function addPermission($perm_name, $caption, $description = false) |
| 180 | 180 | { |
| 181 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
|
| 181 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectpermission.php'; |
|
| 182 | 182 | |
| 183 | 183 | $this->permissionsArray[] = array( |
| 184 | 184 | 'perm_name' => $perm_name, |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
| 198 | 198 | $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
| 199 | 199 | if (count($grantedItems) > 0) { |
| 200 | - $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 200 | + $criteria->add(new Criteria($this->keyName, '('.implode(', ', $grantedItems).')', 'IN')); |
|
| 201 | 201 | |
| 202 | 202 | return true; |
| 203 | 203 | } else { |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | public function getImageUrl() |
| 255 | 255 | { |
| 256 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 256 | + return $this->_uploadUrl.$this->_itemname.'/'; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -261,12 +261,12 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function getImagePath() |
| 263 | 263 | { |
| 264 | - $dir = $this->_uploadPath . $this->_itemname; |
|
| 264 | + $dir = $this->_uploadPath.$this->_itemname; |
|
| 265 | 265 | if (!file_exists($dir)) { |
| 266 | 266 | smart_admin_mkdir($dir); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - return $dir . '/'; |
|
| 269 | + return $dir.'/'; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -359,13 +359,13 @@ discard block |
||
| 359 | 359 | if ($this->generalSQL) { |
| 360 | 360 | $sql = $this->generalSQL; |
| 361 | 361 | } elseif (!$sql) { |
| 362 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 362 | + $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
| 366 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 366 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 367 | 367 | if ($criteria->getSort() !== '') { |
| 368 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 368 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
| 369 | 369 | } |
| 370 | 370 | $limit = $criteria->getLimit(); |
| 371 | 371 | $start = $criteria->getStart(); |
@@ -394,12 +394,12 @@ discard block |
||
| 394 | 394 | $ret = array(); |
| 395 | 395 | |
| 396 | 396 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
| 397 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 397 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 398 | 398 | if ($criteria->groupby) { |
| 399 | 399 | $sql .= $criteria->getGroupby(); |
| 400 | 400 | } |
| 401 | 401 | if ($criteria->getSort() !== '') { |
| 402 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 402 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | 405 | if ($debug) { |
@@ -472,18 +472,18 @@ discard block |
||
| 472 | 472 | $obj->assignVars($myrow); |
| 473 | 473 | if (!$id_as_key) { |
| 474 | 474 | if ($as_object) { |
| 475 | - $ret[] =& $obj; |
|
| 475 | + $ret[] = & $obj; |
|
| 476 | 476 | } else { |
| 477 | 477 | $ret[] = $obj->toArray(); |
| 478 | 478 | } |
| 479 | 479 | } else { |
| 480 | 480 | if ($as_object) { |
| 481 | - $value =& $obj; |
|
| 481 | + $value = & $obj; |
|
| 482 | 482 | } else { |
| 483 | 483 | $value = $obj->toArray(); |
| 484 | 484 | } |
| 485 | 485 | if ($id_as_key === 'parentid') { |
| 486 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 486 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value; |
|
| 487 | 487 | } else { |
| 488 | 488 | $ret[$obj->getVar($this->keyName)] = $value; |
| 489 | 489 | } |
@@ -526,15 +526,15 @@ discard block |
||
| 526 | 526 | $criteria->setSort($this->getIdentifierName()); |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 529 | + $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 530 | 530 | if (!empty($this->identifierName)) { |
| 531 | - $sql .= ', ' . $this->getIdentifierName(); |
|
| 531 | + $sql .= ', '.$this->getIdentifierName(); |
|
| 532 | 532 | } |
| 533 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 533 | + $sql .= ' FROM '.$this->table.' AS '.$this->_itemname; |
|
| 534 | 534 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
| 535 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 535 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 536 | 536 | if ($criteria->getSort() !== '') { |
| 537 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 537 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
| 538 | 538 | } |
| 539 | 539 | $limit = $criteria->getLimit(); |
| 540 | 540 | $start = $criteria->getStart(); |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
| 572 | 572 | if ($criteria->groupby !== '') { |
| 573 | 573 | $groupby = true; |
| 574 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 574 | + $field = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | /** |
@@ -582,10 +582,10 @@ discard block |
||
| 582 | 582 | $sql = $this->generalSQL; |
| 583 | 583 | $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
| 584 | 584 | } else { |
| 585 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 585 | + $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table.' AS '.$this->_itemname; |
|
| 586 | 586 | } |
| 587 | 587 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
| 588 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 588 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 589 | 589 | if ($criteria->groupby !== '') { |
| 590 | 590 | $sql .= $criteria->getGroupby(); |
| 591 | 591 | } |
@@ -628,13 +628,13 @@ discard block |
||
| 628 | 628 | if (is_array($this->keyName)) { |
| 629 | 629 | $clause = array(); |
| 630 | 630 | for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
| 631 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 631 | + $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]); |
|
| 632 | 632 | } |
| 633 | 633 | $whereclause = implode(' AND ', $clause); |
| 634 | 634 | } else { |
| 635 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 635 | + $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName); |
|
| 636 | 636 | } |
| 637 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 637 | + $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause; |
|
| 638 | 638 | if (false !== $force) { |
| 639 | 639 | $result = $this->db->queryF($sql); |
| 640 | 640 | } else { |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
| 696 | 696 | */ |
| 697 | 697 | if (!is_a($obj, $this->className)) { |
| 698 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 698 | + $obj->setError(get_class($obj).' Differs from '.$this->className); |
|
| 699 | 699 | |
| 700 | 700 | return false; |
| 701 | 701 | } |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | $fieldsToStoreInDB = array(); |
| 757 | 757 | foreach ($obj->cleanVars as $k => $v) { |
| 758 | 758 | if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
| 759 | - $cleanvars[$k] = (int)$v; |
|
| 759 | + $cleanvars[$k] = (int) $v; |
|
| 760 | 760 | } elseif (is_array($v)) { |
| 761 | 761 | $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
| 762 | 762 | } else { |
@@ -769,13 +769,13 @@ discard block |
||
| 769 | 769 | if ($obj->isNew()) { |
| 770 | 770 | if (!is_array($this->keyName)) { |
| 771 | 771 | if ($cleanvars[$this->keyName] < 1) { |
| 772 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 772 | + $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq'); |
|
| 773 | 773 | } |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 776 | + $sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($fieldsToStoreInDB)).') VALUES ('.implode(',', array_values($fieldsToStoreInDB)).')'; |
|
| 777 | 777 | } else { |
| 778 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 778 | + $sql = 'UPDATE '.$this->table.' SET'; |
|
| 779 | 779 | foreach ($fieldsToStoreInDB as $key => $value) { |
| 780 | 780 | if ((!is_array($this->keyName) && $key == $this->keyName) |
| 781 | 781 | || (is_array($this->keyName) |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | if (isset($notfirst)) { |
| 786 | 786 | $sql .= ','; |
| 787 | 787 | } |
| 788 | - $sql .= ' ' . $key . ' = ' . $value; |
|
| 788 | + $sql .= ' '.$key.' = '.$value; |
|
| 789 | 789 | $notfirst = true; |
| 790 | 790 | } |
| 791 | 791 | if (is_array($this->keyName)) { |
@@ -794,12 +794,12 @@ discard block |
||
| 794 | 794 | if ($i > 0) { |
| 795 | 795 | $whereclause .= ' AND '; |
| 796 | 796 | } |
| 797 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 797 | + $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]); |
|
| 798 | 798 | } |
| 799 | 799 | } else { |
| 800 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 800 | + $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName); |
|
| 801 | 801 | } |
| 802 | - $sql .= ' WHERE ' . $whereclause; |
|
| 802 | + $sql .= ' WHERE '.$whereclause; |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | if ($debug) { |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | */ |
| 873 | 873 | public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
| 874 | 874 | { |
| 875 | - $set_clause = $fieldname . ' = '; |
|
| 875 | + $set_clause = $fieldname.' = '; |
|
| 876 | 876 | if (is_numeric($fieldvalue)) { |
| 877 | 877 | $set_clause .= $fieldvalue; |
| 878 | 878 | } elseif (is_array($fieldvalue)) { |
@@ -880,9 +880,9 @@ discard block |
||
| 880 | 880 | } else { |
| 881 | 881 | $set_clause .= $this->db->quoteString($fieldvalue); |
| 882 | 882 | } |
| 883 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 883 | + $sql = 'UPDATE '.$this->table.' SET '.$set_clause; |
|
| 884 | 884 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
| 885 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 885 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 886 | 886 | } |
| 887 | 887 | if (false != $force) { |
| 888 | 888 | $result = $this->db->queryF($sql); |
@@ -906,8 +906,8 @@ discard block |
||
| 906 | 906 | public function deleteAll(CriteriaElement $criteria = null) |
| 907 | 907 | { |
| 908 | 908 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
| 909 | - $sql = 'DELETE FROM ' . $this->table; |
|
| 910 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 909 | + $sql = 'DELETE FROM '.$this->table; |
|
| 910 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 911 | 911 | if (!$this->db->query($sql)) { |
| 912 | 912 | return false; |
| 913 | 913 | } |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | */ |
| 941 | 941 | public function getModuleItemString() |
| 942 | 942 | { |
| 943 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 943 | + $ret = $this->_moduleName.'_'.$this->_itemname; |
|
| 944 | 944 | |
| 945 | 945 | return $ret; |
| 946 | 946 | } |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | { |
| 953 | 953 | if (isset($object->vars['counter'])) { |
| 954 | 954 | $new_counter = $object->getVar('counter') + 1; |
| 955 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 955 | + $sql = 'UPDATE '.$this->table.' SET counter='.$new_counter.' WHERE '.$this->keyName.'='.$object->id(); |
|
| 956 | 956 | $this->query($sql, null, true); |
| 957 | 957 | } |
| 958 | 958 | } |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | public function getIdentifierName($withprefix = true) |
| 997 | 997 | { |
| 998 | 998 | if ($withprefix) { |
| 999 | - return $this->_itemname . '.' . $this->identifierName; |
|
| 999 | + return $this->_itemname.'.'.$this->identifierName; |
|
| 1000 | 1000 | } else { |
| 1001 | 1001 | return $this->identifierName; |
| 1002 | 1002 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * SmartObjectColumn constructor. |
| 34 | - * @param $keyname |
|
| 34 | + * @param string $keyname |
|
| 35 | 35 | * @param string $align |
| 36 | 36 | * @param bool $width |
| 37 | 37 | * @param bool $customMethodForValue |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * @param $columnObj |
|
| 196 | + * @param SmartObjectColumn $columnObj |
|
| 197 | 197 | */ |
| 198 | 198 | public function addColumn($columnObj) |
| 199 | 199 | { |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | - * @param $name |
|
| 205 | - * @param $location |
|
| 204 | + * @param string $name |
|
| 205 | + * @param string $location |
|
| 206 | 206 | * @param $value |
| 207 | 207 | */ |
| 208 | 208 | public function addIntroButton($name, $location, $value) |
@@ -21,84 +21,84 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class SmartObjectColumn |
| 23 | 23 | { |
| 24 | - public $_keyname; |
|
| 25 | - public $_align; |
|
| 26 | - public $_width; |
|
| 27 | - public $_customMethodForValue; |
|
| 28 | - public $_extraParams; |
|
| 29 | - public $_sortable; |
|
| 30 | - public $_customCaption; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * SmartObjectColumn constructor. |
|
| 34 | - * @param $keyname |
|
| 35 | - * @param string $align |
|
| 36 | - * @param bool $width |
|
| 37 | - * @param bool $customMethodForValue |
|
| 38 | - * @param bool $param |
|
| 39 | - * @param bool $customCaption |
|
| 40 | - * @param bool $sortable |
|
| 41 | - */ |
|
| 42 | - public function __construct( |
|
| 43 | - $keyname, |
|
| 44 | - $align = 'left', |
|
| 45 | - $width = false, |
|
| 46 | - $customMethodForValue = false, |
|
| 47 | - $param = false, |
|
| 48 | - $customCaption = false, |
|
| 49 | - $sortable = true |
|
| 50 | - ) { |
|
| 51 | - $this->_keyname = $keyname; |
|
| 52 | - $this->_align = $align; |
|
| 53 | - $this->_width = $width; |
|
| 54 | - $this->_customMethodForValue = $customMethodForValue; |
|
| 55 | - $this->_sortable = $sortable; |
|
| 56 | - $this->_param = $param; |
|
| 57 | - $this->_customCaption = $customCaption; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function getKeyName() |
|
| 61 | - { |
|
| 62 | - return $this->_keyname; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function getAlign() |
|
| 69 | - { |
|
| 70 | - return $this->_align; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @return bool |
|
| 75 | - */ |
|
| 76 | - public function isSortable() |
|
| 77 | - { |
|
| 78 | - return $this->_sortable; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return bool|string |
|
| 83 | - */ |
|
| 84 | - public function getWidth() |
|
| 85 | - { |
|
| 86 | - if ($this->_width) { |
|
| 87 | - $ret = $this->_width; |
|
| 88 | - } else { |
|
| 89 | - $ret = ''; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $ret; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return bool |
|
| 97 | - */ |
|
| 98 | - public function getCustomCaption() |
|
| 99 | - { |
|
| 100 | - return $this->_customCaption; |
|
| 101 | - } |
|
| 24 | + public $_keyname; |
|
| 25 | + public $_align; |
|
| 26 | + public $_width; |
|
| 27 | + public $_customMethodForValue; |
|
| 28 | + public $_extraParams; |
|
| 29 | + public $_sortable; |
|
| 30 | + public $_customCaption; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * SmartObjectColumn constructor. |
|
| 34 | + * @param $keyname |
|
| 35 | + * @param string $align |
|
| 36 | + * @param bool $width |
|
| 37 | + * @param bool $customMethodForValue |
|
| 38 | + * @param bool $param |
|
| 39 | + * @param bool $customCaption |
|
| 40 | + * @param bool $sortable |
|
| 41 | + */ |
|
| 42 | + public function __construct( |
|
| 43 | + $keyname, |
|
| 44 | + $align = 'left', |
|
| 45 | + $width = false, |
|
| 46 | + $customMethodForValue = false, |
|
| 47 | + $param = false, |
|
| 48 | + $customCaption = false, |
|
| 49 | + $sortable = true |
|
| 50 | + ) { |
|
| 51 | + $this->_keyname = $keyname; |
|
| 52 | + $this->_align = $align; |
|
| 53 | + $this->_width = $width; |
|
| 54 | + $this->_customMethodForValue = $customMethodForValue; |
|
| 55 | + $this->_sortable = $sortable; |
|
| 56 | + $this->_param = $param; |
|
| 57 | + $this->_customCaption = $customCaption; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function getKeyName() |
|
| 61 | + { |
|
| 62 | + return $this->_keyname; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function getAlign() |
|
| 69 | + { |
|
| 70 | + return $this->_align; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @return bool |
|
| 75 | + */ |
|
| 76 | + public function isSortable() |
|
| 77 | + { |
|
| 78 | + return $this->_sortable; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return bool|string |
|
| 83 | + */ |
|
| 84 | + public function getWidth() |
|
| 85 | + { |
|
| 86 | + if ($this->_width) { |
|
| 87 | + $ret = $this->_width; |
|
| 88 | + } else { |
|
| 89 | + $ret = ''; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $ret; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return bool |
|
| 97 | + */ |
|
| 98 | + public function getCustomCaption() |
|
| 99 | + { |
|
| 100 | + return $this->_customCaption; |
|
| 101 | + } |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -112,805 +112,805 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | class SmartObjectTable |
| 114 | 114 | { |
| 115 | - public $_id; |
|
| 116 | - public $_objectHandler; |
|
| 117 | - public $_columns; |
|
| 118 | - public $_criteria; |
|
| 119 | - public $_actions; |
|
| 120 | - public $_objects = false; |
|
| 121 | - public $_aObjects; |
|
| 122 | - public $_custom_actions; |
|
| 123 | - public $_sortsel; |
|
| 124 | - public $_ordersel; |
|
| 125 | - public $_limitsel; |
|
| 126 | - public $_filtersel; |
|
| 127 | - public $_filterseloptions; |
|
| 128 | - public $_filtersel2; |
|
| 129 | - public $_filtersel2options; |
|
| 130 | - public $_filtersel2optionsDefault; |
|
| 131 | - |
|
| 132 | - public $_tempObject; |
|
| 133 | - public $_tpl; |
|
| 134 | - public $_introButtons; |
|
| 135 | - public $_quickSearch = false; |
|
| 136 | - public $_actionButtons = false; |
|
| 137 | - public $_head_css_class = 'bg3'; |
|
| 138 | - public $_hasActions = false; |
|
| 139 | - public $_userSide = false; |
|
| 140 | - public $_printerFriendlyPage = false; |
|
| 141 | - public $_tableHeader = false; |
|
| 142 | - public $_tableFooter = false; |
|
| 143 | - public $_showActionsColumnTitle = true; |
|
| 144 | - public $_isTree = false; |
|
| 145 | - public $_showFilterAndLimit = true; |
|
| 146 | - public $_enableColumnsSorting = true; |
|
| 147 | - public $_customTemplate = false; |
|
| 148 | - public $_withSelectedActions = array(); |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Constructor |
|
| 152 | - * |
|
| 153 | - * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
| 154 | - * @param CriteriaElement $criteria |
|
| 155 | - * @param array $actions array representing the actions to offer |
|
| 156 | - * |
|
| 157 | - * @param bool $userSide |
|
| 158 | - */ |
|
| 159 | - public function __construct( |
|
| 160 | - SmartPersistableObjectHandler $objectHandler, |
|
| 161 | - CriteriaElement $criteria = null, |
|
| 162 | - $actions = array('edit', 'delete'), |
|
| 163 | - $userSide = false |
|
| 164 | - ) { |
|
| 165 | - $this->_id = $objectHandler->className; |
|
| 166 | - $this->_objectHandler = $objectHandler; |
|
| 167 | - |
|
| 168 | - if (!$criteria) { |
|
| 169 | - $criteria = new CriteriaCompo(); |
|
| 170 | - } |
|
| 171 | - $this->_criteria = $criteria; |
|
| 172 | - $this->_actions = $actions; |
|
| 173 | - $this->_custom_actions = array(); |
|
| 174 | - $this->_userSide = $userSide; |
|
| 175 | - if ($userSide) { |
|
| 176 | - $this->_head_css_class = 'head'; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @param $op |
|
| 182 | - * @param bool $caption |
|
| 183 | - * @param bool $text |
|
| 184 | - */ |
|
| 185 | - public function addActionButton($op, $caption = false, $text = false) |
|
| 186 | - { |
|
| 187 | - $action = array( |
|
| 188 | - 'op' => $op, |
|
| 189 | - 'caption' => $caption, |
|
| 190 | - 'text' => $text |
|
| 191 | - ); |
|
| 192 | - $this->_actionButtons[] = $action; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param $columnObj |
|
| 197 | - */ |
|
| 198 | - public function addColumn($columnObj) |
|
| 199 | - { |
|
| 200 | - $this->_columns[] = $columnObj; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param $name |
|
| 205 | - * @param $location |
|
| 206 | - * @param $value |
|
| 207 | - */ |
|
| 208 | - public function addIntroButton($name, $location, $value) |
|
| 209 | - { |
|
| 210 | - $introButton = array(); |
|
| 211 | - $introButton['name'] = $name; |
|
| 212 | - $introButton['location'] = $location; |
|
| 213 | - $introButton['value'] = $value; |
|
| 214 | - $this->_introButtons[] = $introButton; |
|
| 215 | - unset($introButton); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - public function addPrinterFriendlyLink() |
|
| 219 | - { |
|
| 220 | - $current_urls = smart_getCurrentUrls(); |
|
| 221 | - $current_url = $current_urls['full']; |
|
| 222 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param $fields |
|
| 227 | - * @param string $caption |
|
| 228 | - */ |
|
| 229 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 230 | - { |
|
| 231 | - $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @param $content |
|
| 236 | - */ |
|
| 237 | - public function addHeader($content) |
|
| 238 | - { |
|
| 239 | - $this->_tableHeader = $content; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param $content |
|
| 244 | - */ |
|
| 245 | - public function addFooter($content) |
|
| 246 | - { |
|
| 247 | - $this->_tableFooter = $content; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param $caption |
|
| 252 | - */ |
|
| 253 | - public function addDefaultIntroButton($caption) |
|
| 254 | - { |
|
| 255 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * @param $method |
|
| 260 | - */ |
|
| 261 | - public function addCustomAction($method) |
|
| 262 | - { |
|
| 263 | - $this->_custom_actions[] = $method; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param $default_sort |
|
| 268 | - */ |
|
| 269 | - public function setDefaultSort($default_sort) |
|
| 270 | - { |
|
| 271 | - $this->_sortsel = $default_sort; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @return string |
|
| 276 | - */ |
|
| 277 | - public function getDefaultSort() |
|
| 278 | - { |
|
| 279 | - if ($this->_sortsel) { |
|
| 280 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 281 | - } else { |
|
| 282 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param $default_order |
|
| 288 | - */ |
|
| 289 | - public function setDefaultOrder($default_order) |
|
| 290 | - { |
|
| 291 | - $this->_ordersel = $default_order; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @return string |
|
| 296 | - */ |
|
| 297 | - public function getDefaultOrder() |
|
| 298 | - { |
|
| 299 | - if ($this->_ordersel) { |
|
| 300 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 301 | - } else { |
|
| 302 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @param array $actions |
|
| 308 | - */ |
|
| 309 | - public function addWithSelectedActions($actions = array()) |
|
| 310 | - { |
|
| 311 | - $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 312 | - $this->_withSelectedActions = $actions; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Adding a filter in the table |
|
| 317 | - * |
|
| 318 | - * @param string $key key to the field that will be used for sorting |
|
| 319 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 320 | - * @param bool $default |
|
| 321 | - */ |
|
| 322 | - public function addFilter($key, $method, $default = false) |
|
| 323 | - { |
|
| 324 | - $this->_filterseloptions[$key] = $method; |
|
| 325 | - $this->_filtersel2optionsDefault = $default; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @param $default_filter |
|
| 330 | - */ |
|
| 331 | - public function setDefaultFilter($default_filter) |
|
| 332 | - { |
|
| 333 | - $this->_filtersel = $default_filter; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - public function isForUserSide() |
|
| 337 | - { |
|
| 338 | - $this->_userSide = true; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @param $template |
|
| 343 | - */ |
|
| 344 | - public function setCustomTemplate($template) |
|
| 345 | - { |
|
| 346 | - $this->_customTemplate = $template; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - public function setSortOrder() |
|
| 350 | - { |
|
| 351 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 352 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 353 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 354 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 355 | - |
|
| 356 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
| 357 | - && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 358 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 359 | - } else { |
|
| 360 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 364 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 365 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 366 | - $ordersArray = $this->getOrdersArray(); |
|
| 367 | - $this->_criteria->setOrder($this->_ordersel); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * @param $id |
|
| 372 | - */ |
|
| 373 | - public function setTableId($id) |
|
| 374 | - { |
|
| 375 | - $this->_id = $id; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @param $objects |
|
| 380 | - */ |
|
| 381 | - public function setObjects($objects) |
|
| 382 | - { |
|
| 383 | - $this->_objects = $objects; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - public function createTableRows() |
|
| 387 | - { |
|
| 388 | - $this->_aObjects = array(); |
|
| 389 | - |
|
| 390 | - $doWeHaveActions = false; |
|
| 391 | - |
|
| 392 | - $objectclass = 'odd'; |
|
| 393 | - if (count($this->_objects) > 0) { |
|
| 394 | - foreach ($this->_objects as $object) { |
|
| 395 | - $aObject = array(); |
|
| 396 | - |
|
| 397 | - $i = 0; |
|
| 398 | - |
|
| 399 | - $aColumns = array(); |
|
| 400 | - |
|
| 401 | - foreach ($this->_columns as $column) { |
|
| 402 | - $aColumn = array(); |
|
| 403 | - |
|
| 404 | - if ($i == 0) { |
|
| 405 | - $class = 'head'; |
|
| 406 | - } elseif ($i % 2 == 0) { |
|
| 407 | - $class = 'even'; |
|
| 408 | - } else { |
|
| 409 | - $class = 'odd'; |
|
| 410 | - } |
|
| 411 | - if (method_exists($object, 'initiateCustomFields')) { |
|
| 412 | - //$object->initiateCustomFields(); |
|
| 413 | - } |
|
| 414 | - if ($column->_keyname === 'checked') { |
|
| 415 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 416 | - } elseif ($column->_customMethodForValue |
|
| 417 | - && method_exists($object, $column->_customMethodForValue)) { |
|
| 418 | - $method = $column->_customMethodForValue; |
|
| 419 | - if ($column->_param) { |
|
| 420 | - $value = $object->$method($column->_param); |
|
| 421 | - } else { |
|
| 422 | - $value = $object->$method(); |
|
| 423 | - } |
|
| 424 | - } else { |
|
| 425 | - /** |
|
| 426 | - * If the column is the identifier, then put a link on it |
|
| 427 | - */ |
|
| 428 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 429 | - $value = $object->getItemLink(); |
|
| 430 | - } else { |
|
| 431 | - $value = $object->getVar($column->getKeyName()); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - $aColumn['value'] = $value; |
|
| 436 | - $aColumn['class'] = $class; |
|
| 437 | - $aColumn['width'] = $column->getWidth(); |
|
| 438 | - $aColumn['align'] = $column->getAlign(); |
|
| 439 | - |
|
| 440 | - $aColumns[] = $aColumn; |
|
| 441 | - ++$i; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - $aObject['columns'] = $aColumns; |
|
| 445 | - $aObject['id'] = $object->id(); |
|
| 446 | - |
|
| 447 | - $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
| 448 | - |
|
| 449 | - $aObject['class'] = $objectclass; |
|
| 450 | - |
|
| 451 | - $actions = array(); |
|
| 452 | - |
|
| 453 | - // Adding the custom actions if any |
|
| 454 | - foreach ($this->_custom_actions as $action) { |
|
| 455 | - if (method_exists($object, $action)) { |
|
| 456 | - $actions[] = $object->$action(); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 461 | - $controller = new SmartObjectController($this->_objectHandler); |
|
| 462 | - |
|
| 463 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 464 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 465 | - } |
|
| 466 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 467 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 468 | - } |
|
| 469 | - $aObject['actions'] = $actions; |
|
| 470 | - |
|
| 471 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 472 | - |
|
| 473 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 474 | - |
|
| 475 | - $this->_aObjects[] = $aObject; |
|
| 476 | - } |
|
| 477 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 478 | - } else { |
|
| 479 | - $colspan = count($this->_columns) + 1; |
|
| 480 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 481 | - } |
|
| 482 | - $this->_hasActions = $doWeHaveActions; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * @param bool $debug |
|
| 487 | - * @return mixed |
|
| 488 | - */ |
|
| 489 | - public function fetchObjects($debug = false) |
|
| 490 | - { |
|
| 491 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * @return string |
|
| 496 | - */ |
|
| 497 | - public function getDefaultFilter() |
|
| 498 | - { |
|
| 499 | - if ($this->_filtersel) { |
|
| 500 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 501 | - } else { |
|
| 502 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 503 | - } |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * @return array|bool |
|
| 508 | - */ |
|
| 509 | - public function getFiltersArray() |
|
| 510 | - { |
|
| 511 | - $ret = array(); |
|
| 512 | - $field = array(); |
|
| 513 | - $field['caption'] = _CO_OBJ_NONE; |
|
| 514 | - $field['selected'] = ''; |
|
| 515 | - $ret['default'] = $field; |
|
| 516 | - unset($field); |
|
| 517 | - |
|
| 518 | - if ($this->_filterseloptions) { |
|
| 519 | - foreach ($this->_filterseloptions as $key => $value) { |
|
| 520 | - $field = array(); |
|
| 521 | - if (is_array($value)) { |
|
| 522 | - $field['caption'] = $key; |
|
| 523 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 524 | - } else { |
|
| 525 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 526 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 527 | - } |
|
| 528 | - $ret[$key] = $field; |
|
| 529 | - unset($field); |
|
| 530 | - } |
|
| 531 | - } else { |
|
| 532 | - $ret = false; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - return $ret; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @param $default_filter2 |
|
| 540 | - */ |
|
| 541 | - public function setDefaultFilter2($default_filter2) |
|
| 542 | - { |
|
| 543 | - $this->_filtersel2 = $default_filter2; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * @return string |
|
| 548 | - */ |
|
| 549 | - public function getDefaultFilter2() |
|
| 550 | - { |
|
| 551 | - if ($this->_filtersel2) { |
|
| 552 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 553 | - } else { |
|
| 554 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * @return array |
|
| 560 | - */ |
|
| 561 | - public function getFilters2Array() |
|
| 562 | - { |
|
| 563 | - $ret = array(); |
|
| 564 | - |
|
| 565 | - foreach ($this->_filtersel2options as $key => $value) { |
|
| 566 | - $field = array(); |
|
| 567 | - $field['caption'] = $value; |
|
| 568 | - $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
| 569 | - $ret[$key] = $field; |
|
| 570 | - unset($field); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return $ret; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * @param $limitsArray |
|
| 578 | - * @param $params_of_the_options_sel |
|
| 579 | - */ |
|
| 580 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 581 | - { |
|
| 582 | - // Rendering the form to select options on the table |
|
| 583 | - $current_urls = smart_getCurrentUrls(); |
|
| 584 | - $current_url = $current_urls['full']; |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * What was $params_of_the_options_sel doing again ? |
|
| 588 | - */ |
|
| 589 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 590 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 591 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * @return array |
|
| 596 | - */ |
|
| 597 | - public function getLimitsArray() |
|
| 598 | - { |
|
| 599 | - $ret = array(); |
|
| 600 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 601 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
| 602 | - |
|
| 603 | - $ret['5']['caption'] = '5'; |
|
| 604 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
| 605 | - |
|
| 606 | - $ret['10']['caption'] = '10'; |
|
| 607 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
| 608 | - |
|
| 609 | - $ret['15']['caption'] = '15'; |
|
| 610 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
| 611 | - |
|
| 612 | - $ret['20']['caption'] = '20'; |
|
| 613 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
| 614 | - |
|
| 615 | - $ret['25']['caption'] = '25'; |
|
| 616 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
| 617 | - |
|
| 618 | - $ret['30']['caption'] = '30'; |
|
| 619 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
| 620 | - |
|
| 621 | - $ret['35']['caption'] = '35'; |
|
| 622 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
| 623 | - |
|
| 624 | - $ret['40']['caption'] = '40'; |
|
| 625 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
| 626 | - |
|
| 627 | - return $ret; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * @return bool |
|
| 632 | - */ |
|
| 633 | - public function getObjects() |
|
| 634 | - { |
|
| 635 | - return $this->_objects; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - public function hideActionColumnTitle() |
|
| 639 | - { |
|
| 640 | - $this->_showActionsColumnTitle = false; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - public function hideFilterAndLimit() |
|
| 644 | - { |
|
| 645 | - $this->_showFilterAndLimit = false; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * @return array |
|
| 650 | - */ |
|
| 651 | - public function getOrdersArray() |
|
| 652 | - { |
|
| 653 | - $ret = array(); |
|
| 654 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 655 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
| 656 | - |
|
| 657 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 658 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
| 659 | - |
|
| 660 | - return $ret; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * @return mixed|string|void |
|
| 665 | - */ |
|
| 666 | - public function renderD() |
|
| 667 | - { |
|
| 668 | - return $this->render(false, true); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - public function renderForPrint() |
|
| 672 | - { |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * @param bool $fetchOnly |
|
| 677 | - * @param bool $debug |
|
| 678 | - * @return mixed|string|void |
|
| 679 | - */ |
|
| 680 | - public function render($fetchOnly = false, $debug = false) |
|
| 681 | - { |
|
| 682 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 683 | - |
|
| 684 | - $this->_tpl = new XoopsTpl(); |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 688 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 689 | - * and we will free it after |
|
| 690 | - */ |
|
| 691 | - $this->_tempObject = $this->_objectHandler->create(); |
|
| 692 | - |
|
| 693 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 694 | - |
|
| 695 | - $this->setSortOrder(); |
|
| 696 | - |
|
| 697 | - if (!$this->_isTree) { |
|
| 698 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 699 | - } else { |
|
| 700 | - $this->_limitsel = 'all'; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 704 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 705 | - $limitsArray = $this->getLimitsArray(); |
|
| 706 | - $this->_criteria->setLimit($this->_limitsel); |
|
| 707 | - |
|
| 708 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 709 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 710 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 711 | - $filtersArray = $this->getFiltersArray(); |
|
| 712 | - |
|
| 713 | - if ($filtersArray) { |
|
| 714 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 718 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 719 | - // check if method associate with this filter exists in the handler |
|
| 720 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 721 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 722 | - $this->_criteria->add($filter['criteria']); |
|
| 723 | - } else { |
|
| 724 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 725 | - |
|
| 726 | - // then we will create the selfilter2 options by calling this method |
|
| 727 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 728 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 729 | - |
|
| 730 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 731 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 732 | - |
|
| 733 | - $filters2Array = $this->getFilters2Array(); |
|
| 734 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 735 | - |
|
| 736 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 737 | - if ($this->_filtersel2 !== 'default') { |
|
| 738 | - $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - // Check if we have a quicksearch |
|
| 744 | - |
|
| 745 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
| 746 | - $quicksearch_criteria = new CriteriaCompo(); |
|
| 747 | - if (is_array($this->_quickSearch['fields'])) { |
|
| 748 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
| 749 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 750 | - } |
|
| 751 | - } else { |
|
| 752 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 753 | - } |
|
| 754 | - $this->_criteria->add($quicksearch_criteria); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - $this->_objects = $this->fetchObjects($debug); |
|
| 758 | - |
|
| 759 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 760 | - if ($this->_criteria->getLimit() > 0) { |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * Geeting rid of the old params |
|
| 764 | - * $new_get_array is an array containing the new GET parameters |
|
| 765 | - */ |
|
| 766 | - $new_get_array = array(); |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 770 | - * but without the pagenave parameters. This array will be used in the |
|
| 771 | - * OptionsSelection |
|
| 772 | - */ |
|
| 773 | - $params_of_the_options_sel = array(); |
|
| 774 | - |
|
| 775 | - $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
| 776 | - foreach ($_GET as $k => $v) { |
|
| 777 | - if (!in_array($k, $not_needed_params)) { |
|
| 778 | - $new_get_array[] = "$k=$v"; |
|
| 779 | - $params_of_the_options_sel[] = "$k=$v"; |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * Adding the new params of the pagenav |
|
| 785 | - */ |
|
| 786 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 787 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 788 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 789 | - $otherParams = implode('&', $new_get_array); |
|
| 790 | - |
|
| 791 | - $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 792 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 793 | - } |
|
| 794 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 795 | - |
|
| 796 | - // retreive the current url and the query string |
|
| 797 | - $current_urls = smart_getCurrentUrls(); |
|
| 798 | - $current_url = $current_urls['full_phpself']; |
|
| 799 | - $query_string = $current_urls['querystring']; |
|
| 800 | - if ($query_string) { |
|
| 801 | - $query_string = str_replace('?', '', $query_string); |
|
| 802 | - } |
|
| 803 | - $query_stringArray = explode('&', $query_string); |
|
| 804 | - $new_query_stringArray = array(); |
|
| 805 | - foreach ($query_stringArray as $query_string) { |
|
| 806 | - if (strpos($query_string, 'sortsel') === false && strpos($query_string, 'ordersel') === false) { |
|
| 807 | - $new_query_stringArray[] = $query_string; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - $new_query_string = implode('&', $new_query_stringArray); |
|
| 811 | - |
|
| 812 | - $orderArray = array(); |
|
| 813 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
| 814 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 815 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
| 816 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 817 | - |
|
| 818 | - $aColumns = array(); |
|
| 819 | - |
|
| 820 | - foreach ($this->_columns as $column) { |
|
| 821 | - $qs_param = ''; |
|
| 822 | - $aColumn = array(); |
|
| 823 | - $aColumn['width'] = $column->getWidth(); |
|
| 824 | - $aColumn['align'] = $column->getAlign(); |
|
| 825 | - $aColumn['key'] = $column->getKeyName(); |
|
| 826 | - if ($column->_keyname === 'checked') { |
|
| 827 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 828 | - } elseif ($column->getCustomCaption()) { |
|
| 829 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
| 830 | - } else { |
|
| 831 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 832 | - } |
|
| 833 | - // Are we doing a GET sort on this column ? |
|
| 834 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 835 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 836 | - || ($this->_sortsel == $column->getKeyName()); |
|
| 837 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 838 | - |
|
| 839 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
| 840 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 841 | - } |
|
| 842 | - if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
| 843 | - $aColumn['caption'] = $aColumn['caption']; |
|
| 844 | - } elseif ($getSort) { |
|
| 845 | - $aColumn['caption'] = '<a href="' |
|
| 846 | - . $current_url |
|
| 847 | - . '?' |
|
| 848 | - . $this->_objectHandler->_itemname |
|
| 849 | - . '_' |
|
| 850 | - . 'sortsel=' |
|
| 851 | - . $column->getKeyName() |
|
| 852 | - . '&' |
|
| 853 | - . $this->_objectHandler->_itemname |
|
| 854 | - . '_' |
|
| 855 | - . 'ordersel=' |
|
| 856 | - . $orderArray[$order]['neworder'] |
|
| 857 | - . $qs_param |
|
| 858 | - . '&' |
|
| 859 | - . $new_query_string |
|
| 860 | - . '">' |
|
| 861 | - . $aColumn['caption'] |
|
| 862 | - . ' <img src="' |
|
| 863 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 864 | - . $orderArray[$order]['image'] |
|
| 865 | - . '" alt="ASC"></a>'; |
|
| 866 | - } else { |
|
| 867 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 868 | - } |
|
| 869 | - $aColumns[] = $aColumn; |
|
| 870 | - } |
|
| 871 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 872 | - |
|
| 873 | - if ($this->_quickSearch) { |
|
| 874 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - $this->createTableRows(); |
|
| 878 | - |
|
| 879 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 880 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 881 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 882 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 883 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 884 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 885 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 886 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 887 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 888 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 889 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 890 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 891 | - if (!empty($this->_withSelectedActions)) { |
|
| 892 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 896 | - if ($fetchOnly) { |
|
| 897 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 898 | - } else { |
|
| 899 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - public function disableColumnsSorting() |
|
| 904 | - { |
|
| 905 | - $this->_enableColumnsSorting = false; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * @param bool $debug |
|
| 910 | - * @return mixed|string|void |
|
| 911 | - */ |
|
| 912 | - public function fetch($debug = false) |
|
| 913 | - { |
|
| 914 | - return $this->render(true, $debug); |
|
| 915 | - } |
|
| 115 | + public $_id; |
|
| 116 | + public $_objectHandler; |
|
| 117 | + public $_columns; |
|
| 118 | + public $_criteria; |
|
| 119 | + public $_actions; |
|
| 120 | + public $_objects = false; |
|
| 121 | + public $_aObjects; |
|
| 122 | + public $_custom_actions; |
|
| 123 | + public $_sortsel; |
|
| 124 | + public $_ordersel; |
|
| 125 | + public $_limitsel; |
|
| 126 | + public $_filtersel; |
|
| 127 | + public $_filterseloptions; |
|
| 128 | + public $_filtersel2; |
|
| 129 | + public $_filtersel2options; |
|
| 130 | + public $_filtersel2optionsDefault; |
|
| 131 | + |
|
| 132 | + public $_tempObject; |
|
| 133 | + public $_tpl; |
|
| 134 | + public $_introButtons; |
|
| 135 | + public $_quickSearch = false; |
|
| 136 | + public $_actionButtons = false; |
|
| 137 | + public $_head_css_class = 'bg3'; |
|
| 138 | + public $_hasActions = false; |
|
| 139 | + public $_userSide = false; |
|
| 140 | + public $_printerFriendlyPage = false; |
|
| 141 | + public $_tableHeader = false; |
|
| 142 | + public $_tableFooter = false; |
|
| 143 | + public $_showActionsColumnTitle = true; |
|
| 144 | + public $_isTree = false; |
|
| 145 | + public $_showFilterAndLimit = true; |
|
| 146 | + public $_enableColumnsSorting = true; |
|
| 147 | + public $_customTemplate = false; |
|
| 148 | + public $_withSelectedActions = array(); |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Constructor |
|
| 152 | + * |
|
| 153 | + * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
| 154 | + * @param CriteriaElement $criteria |
|
| 155 | + * @param array $actions array representing the actions to offer |
|
| 156 | + * |
|
| 157 | + * @param bool $userSide |
|
| 158 | + */ |
|
| 159 | + public function __construct( |
|
| 160 | + SmartPersistableObjectHandler $objectHandler, |
|
| 161 | + CriteriaElement $criteria = null, |
|
| 162 | + $actions = array('edit', 'delete'), |
|
| 163 | + $userSide = false |
|
| 164 | + ) { |
|
| 165 | + $this->_id = $objectHandler->className; |
|
| 166 | + $this->_objectHandler = $objectHandler; |
|
| 167 | + |
|
| 168 | + if (!$criteria) { |
|
| 169 | + $criteria = new CriteriaCompo(); |
|
| 170 | + } |
|
| 171 | + $this->_criteria = $criteria; |
|
| 172 | + $this->_actions = $actions; |
|
| 173 | + $this->_custom_actions = array(); |
|
| 174 | + $this->_userSide = $userSide; |
|
| 175 | + if ($userSide) { |
|
| 176 | + $this->_head_css_class = 'head'; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @param $op |
|
| 182 | + * @param bool $caption |
|
| 183 | + * @param bool $text |
|
| 184 | + */ |
|
| 185 | + public function addActionButton($op, $caption = false, $text = false) |
|
| 186 | + { |
|
| 187 | + $action = array( |
|
| 188 | + 'op' => $op, |
|
| 189 | + 'caption' => $caption, |
|
| 190 | + 'text' => $text |
|
| 191 | + ); |
|
| 192 | + $this->_actionButtons[] = $action; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param $columnObj |
|
| 197 | + */ |
|
| 198 | + public function addColumn($columnObj) |
|
| 199 | + { |
|
| 200 | + $this->_columns[] = $columnObj; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param $name |
|
| 205 | + * @param $location |
|
| 206 | + * @param $value |
|
| 207 | + */ |
|
| 208 | + public function addIntroButton($name, $location, $value) |
|
| 209 | + { |
|
| 210 | + $introButton = array(); |
|
| 211 | + $introButton['name'] = $name; |
|
| 212 | + $introButton['location'] = $location; |
|
| 213 | + $introButton['value'] = $value; |
|
| 214 | + $this->_introButtons[] = $introButton; |
|
| 215 | + unset($introButton); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + public function addPrinterFriendlyLink() |
|
| 219 | + { |
|
| 220 | + $current_urls = smart_getCurrentUrls(); |
|
| 221 | + $current_url = $current_urls['full']; |
|
| 222 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param $fields |
|
| 227 | + * @param string $caption |
|
| 228 | + */ |
|
| 229 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 230 | + { |
|
| 231 | + $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @param $content |
|
| 236 | + */ |
|
| 237 | + public function addHeader($content) |
|
| 238 | + { |
|
| 239 | + $this->_tableHeader = $content; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param $content |
|
| 244 | + */ |
|
| 245 | + public function addFooter($content) |
|
| 246 | + { |
|
| 247 | + $this->_tableFooter = $content; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param $caption |
|
| 252 | + */ |
|
| 253 | + public function addDefaultIntroButton($caption) |
|
| 254 | + { |
|
| 255 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * @param $method |
|
| 260 | + */ |
|
| 261 | + public function addCustomAction($method) |
|
| 262 | + { |
|
| 263 | + $this->_custom_actions[] = $method; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param $default_sort |
|
| 268 | + */ |
|
| 269 | + public function setDefaultSort($default_sort) |
|
| 270 | + { |
|
| 271 | + $this->_sortsel = $default_sort; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @return string |
|
| 276 | + */ |
|
| 277 | + public function getDefaultSort() |
|
| 278 | + { |
|
| 279 | + if ($this->_sortsel) { |
|
| 280 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 281 | + } else { |
|
| 282 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param $default_order |
|
| 288 | + */ |
|
| 289 | + public function setDefaultOrder($default_order) |
|
| 290 | + { |
|
| 291 | + $this->_ordersel = $default_order; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @return string |
|
| 296 | + */ |
|
| 297 | + public function getDefaultOrder() |
|
| 298 | + { |
|
| 299 | + if ($this->_ordersel) { |
|
| 300 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 301 | + } else { |
|
| 302 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @param array $actions |
|
| 308 | + */ |
|
| 309 | + public function addWithSelectedActions($actions = array()) |
|
| 310 | + { |
|
| 311 | + $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 312 | + $this->_withSelectedActions = $actions; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Adding a filter in the table |
|
| 317 | + * |
|
| 318 | + * @param string $key key to the field that will be used for sorting |
|
| 319 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 320 | + * @param bool $default |
|
| 321 | + */ |
|
| 322 | + public function addFilter($key, $method, $default = false) |
|
| 323 | + { |
|
| 324 | + $this->_filterseloptions[$key] = $method; |
|
| 325 | + $this->_filtersel2optionsDefault = $default; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @param $default_filter |
|
| 330 | + */ |
|
| 331 | + public function setDefaultFilter($default_filter) |
|
| 332 | + { |
|
| 333 | + $this->_filtersel = $default_filter; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + public function isForUserSide() |
|
| 337 | + { |
|
| 338 | + $this->_userSide = true; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @param $template |
|
| 343 | + */ |
|
| 344 | + public function setCustomTemplate($template) |
|
| 345 | + { |
|
| 346 | + $this->_customTemplate = $template; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + public function setSortOrder() |
|
| 350 | + { |
|
| 351 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 352 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 353 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 354 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 355 | + |
|
| 356 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
| 357 | + && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 358 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 359 | + } else { |
|
| 360 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 364 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 365 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 366 | + $ordersArray = $this->getOrdersArray(); |
|
| 367 | + $this->_criteria->setOrder($this->_ordersel); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * @param $id |
|
| 372 | + */ |
|
| 373 | + public function setTableId($id) |
|
| 374 | + { |
|
| 375 | + $this->_id = $id; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @param $objects |
|
| 380 | + */ |
|
| 381 | + public function setObjects($objects) |
|
| 382 | + { |
|
| 383 | + $this->_objects = $objects; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + public function createTableRows() |
|
| 387 | + { |
|
| 388 | + $this->_aObjects = array(); |
|
| 389 | + |
|
| 390 | + $doWeHaveActions = false; |
|
| 391 | + |
|
| 392 | + $objectclass = 'odd'; |
|
| 393 | + if (count($this->_objects) > 0) { |
|
| 394 | + foreach ($this->_objects as $object) { |
|
| 395 | + $aObject = array(); |
|
| 396 | + |
|
| 397 | + $i = 0; |
|
| 398 | + |
|
| 399 | + $aColumns = array(); |
|
| 400 | + |
|
| 401 | + foreach ($this->_columns as $column) { |
|
| 402 | + $aColumn = array(); |
|
| 403 | + |
|
| 404 | + if ($i == 0) { |
|
| 405 | + $class = 'head'; |
|
| 406 | + } elseif ($i % 2 == 0) { |
|
| 407 | + $class = 'even'; |
|
| 408 | + } else { |
|
| 409 | + $class = 'odd'; |
|
| 410 | + } |
|
| 411 | + if (method_exists($object, 'initiateCustomFields')) { |
|
| 412 | + //$object->initiateCustomFields(); |
|
| 413 | + } |
|
| 414 | + if ($column->_keyname === 'checked') { |
|
| 415 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 416 | + } elseif ($column->_customMethodForValue |
|
| 417 | + && method_exists($object, $column->_customMethodForValue)) { |
|
| 418 | + $method = $column->_customMethodForValue; |
|
| 419 | + if ($column->_param) { |
|
| 420 | + $value = $object->$method($column->_param); |
|
| 421 | + } else { |
|
| 422 | + $value = $object->$method(); |
|
| 423 | + } |
|
| 424 | + } else { |
|
| 425 | + /** |
|
| 426 | + * If the column is the identifier, then put a link on it |
|
| 427 | + */ |
|
| 428 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 429 | + $value = $object->getItemLink(); |
|
| 430 | + } else { |
|
| 431 | + $value = $object->getVar($column->getKeyName()); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + $aColumn['value'] = $value; |
|
| 436 | + $aColumn['class'] = $class; |
|
| 437 | + $aColumn['width'] = $column->getWidth(); |
|
| 438 | + $aColumn['align'] = $column->getAlign(); |
|
| 439 | + |
|
| 440 | + $aColumns[] = $aColumn; |
|
| 441 | + ++$i; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + $aObject['columns'] = $aColumns; |
|
| 445 | + $aObject['id'] = $object->id(); |
|
| 446 | + |
|
| 447 | + $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
| 448 | + |
|
| 449 | + $aObject['class'] = $objectclass; |
|
| 450 | + |
|
| 451 | + $actions = array(); |
|
| 452 | + |
|
| 453 | + // Adding the custom actions if any |
|
| 454 | + foreach ($this->_custom_actions as $action) { |
|
| 455 | + if (method_exists($object, $action)) { |
|
| 456 | + $actions[] = $object->$action(); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 461 | + $controller = new SmartObjectController($this->_objectHandler); |
|
| 462 | + |
|
| 463 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 464 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 465 | + } |
|
| 466 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 467 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 468 | + } |
|
| 469 | + $aObject['actions'] = $actions; |
|
| 470 | + |
|
| 471 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 472 | + |
|
| 473 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 474 | + |
|
| 475 | + $this->_aObjects[] = $aObject; |
|
| 476 | + } |
|
| 477 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 478 | + } else { |
|
| 479 | + $colspan = count($this->_columns) + 1; |
|
| 480 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 481 | + } |
|
| 482 | + $this->_hasActions = $doWeHaveActions; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * @param bool $debug |
|
| 487 | + * @return mixed |
|
| 488 | + */ |
|
| 489 | + public function fetchObjects($debug = false) |
|
| 490 | + { |
|
| 491 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * @return string |
|
| 496 | + */ |
|
| 497 | + public function getDefaultFilter() |
|
| 498 | + { |
|
| 499 | + if ($this->_filtersel) { |
|
| 500 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 501 | + } else { |
|
| 502 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * @return array|bool |
|
| 508 | + */ |
|
| 509 | + public function getFiltersArray() |
|
| 510 | + { |
|
| 511 | + $ret = array(); |
|
| 512 | + $field = array(); |
|
| 513 | + $field['caption'] = _CO_OBJ_NONE; |
|
| 514 | + $field['selected'] = ''; |
|
| 515 | + $ret['default'] = $field; |
|
| 516 | + unset($field); |
|
| 517 | + |
|
| 518 | + if ($this->_filterseloptions) { |
|
| 519 | + foreach ($this->_filterseloptions as $key => $value) { |
|
| 520 | + $field = array(); |
|
| 521 | + if (is_array($value)) { |
|
| 522 | + $field['caption'] = $key; |
|
| 523 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 524 | + } else { |
|
| 525 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 526 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 527 | + } |
|
| 528 | + $ret[$key] = $field; |
|
| 529 | + unset($field); |
|
| 530 | + } |
|
| 531 | + } else { |
|
| 532 | + $ret = false; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + return $ret; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @param $default_filter2 |
|
| 540 | + */ |
|
| 541 | + public function setDefaultFilter2($default_filter2) |
|
| 542 | + { |
|
| 543 | + $this->_filtersel2 = $default_filter2; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * @return string |
|
| 548 | + */ |
|
| 549 | + public function getDefaultFilter2() |
|
| 550 | + { |
|
| 551 | + if ($this->_filtersel2) { |
|
| 552 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 553 | + } else { |
|
| 554 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * @return array |
|
| 560 | + */ |
|
| 561 | + public function getFilters2Array() |
|
| 562 | + { |
|
| 563 | + $ret = array(); |
|
| 564 | + |
|
| 565 | + foreach ($this->_filtersel2options as $key => $value) { |
|
| 566 | + $field = array(); |
|
| 567 | + $field['caption'] = $value; |
|
| 568 | + $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
| 569 | + $ret[$key] = $field; |
|
| 570 | + unset($field); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return $ret; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * @param $limitsArray |
|
| 578 | + * @param $params_of_the_options_sel |
|
| 579 | + */ |
|
| 580 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 581 | + { |
|
| 582 | + // Rendering the form to select options on the table |
|
| 583 | + $current_urls = smart_getCurrentUrls(); |
|
| 584 | + $current_url = $current_urls['full']; |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * What was $params_of_the_options_sel doing again ? |
|
| 588 | + */ |
|
| 589 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 590 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 591 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * @return array |
|
| 596 | + */ |
|
| 597 | + public function getLimitsArray() |
|
| 598 | + { |
|
| 599 | + $ret = array(); |
|
| 600 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 601 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
| 602 | + |
|
| 603 | + $ret['5']['caption'] = '5'; |
|
| 604 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
| 605 | + |
|
| 606 | + $ret['10']['caption'] = '10'; |
|
| 607 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
| 608 | + |
|
| 609 | + $ret['15']['caption'] = '15'; |
|
| 610 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
| 611 | + |
|
| 612 | + $ret['20']['caption'] = '20'; |
|
| 613 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
| 614 | + |
|
| 615 | + $ret['25']['caption'] = '25'; |
|
| 616 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
| 617 | + |
|
| 618 | + $ret['30']['caption'] = '30'; |
|
| 619 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
| 620 | + |
|
| 621 | + $ret['35']['caption'] = '35'; |
|
| 622 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
| 623 | + |
|
| 624 | + $ret['40']['caption'] = '40'; |
|
| 625 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
| 626 | + |
|
| 627 | + return $ret; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * @return bool |
|
| 632 | + */ |
|
| 633 | + public function getObjects() |
|
| 634 | + { |
|
| 635 | + return $this->_objects; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + public function hideActionColumnTitle() |
|
| 639 | + { |
|
| 640 | + $this->_showActionsColumnTitle = false; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + public function hideFilterAndLimit() |
|
| 644 | + { |
|
| 645 | + $this->_showFilterAndLimit = false; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * @return array |
|
| 650 | + */ |
|
| 651 | + public function getOrdersArray() |
|
| 652 | + { |
|
| 653 | + $ret = array(); |
|
| 654 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 655 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
| 656 | + |
|
| 657 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 658 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
| 659 | + |
|
| 660 | + return $ret; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * @return mixed|string|void |
|
| 665 | + */ |
|
| 666 | + public function renderD() |
|
| 667 | + { |
|
| 668 | + return $this->render(false, true); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + public function renderForPrint() |
|
| 672 | + { |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * @param bool $fetchOnly |
|
| 677 | + * @param bool $debug |
|
| 678 | + * @return mixed|string|void |
|
| 679 | + */ |
|
| 680 | + public function render($fetchOnly = false, $debug = false) |
|
| 681 | + { |
|
| 682 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 683 | + |
|
| 684 | + $this->_tpl = new XoopsTpl(); |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 688 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 689 | + * and we will free it after |
|
| 690 | + */ |
|
| 691 | + $this->_tempObject = $this->_objectHandler->create(); |
|
| 692 | + |
|
| 693 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 694 | + |
|
| 695 | + $this->setSortOrder(); |
|
| 696 | + |
|
| 697 | + if (!$this->_isTree) { |
|
| 698 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 699 | + } else { |
|
| 700 | + $this->_limitsel = 'all'; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 704 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 705 | + $limitsArray = $this->getLimitsArray(); |
|
| 706 | + $this->_criteria->setLimit($this->_limitsel); |
|
| 707 | + |
|
| 708 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 709 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 710 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 711 | + $filtersArray = $this->getFiltersArray(); |
|
| 712 | + |
|
| 713 | + if ($filtersArray) { |
|
| 714 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 718 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 719 | + // check if method associate with this filter exists in the handler |
|
| 720 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 721 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 722 | + $this->_criteria->add($filter['criteria']); |
|
| 723 | + } else { |
|
| 724 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 725 | + |
|
| 726 | + // then we will create the selfilter2 options by calling this method |
|
| 727 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 728 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 729 | + |
|
| 730 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 731 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 732 | + |
|
| 733 | + $filters2Array = $this->getFilters2Array(); |
|
| 734 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 735 | + |
|
| 736 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 737 | + if ($this->_filtersel2 !== 'default') { |
|
| 738 | + $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + // Check if we have a quicksearch |
|
| 744 | + |
|
| 745 | + if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
| 746 | + $quicksearch_criteria = new CriteriaCompo(); |
|
| 747 | + if (is_array($this->_quickSearch['fields'])) { |
|
| 748 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
| 749 | + $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 750 | + } |
|
| 751 | + } else { |
|
| 752 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 753 | + } |
|
| 754 | + $this->_criteria->add($quicksearch_criteria); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + $this->_objects = $this->fetchObjects($debug); |
|
| 758 | + |
|
| 759 | + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 760 | + if ($this->_criteria->getLimit() > 0) { |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * Geeting rid of the old params |
|
| 764 | + * $new_get_array is an array containing the new GET parameters |
|
| 765 | + */ |
|
| 766 | + $new_get_array = array(); |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 770 | + * but without the pagenave parameters. This array will be used in the |
|
| 771 | + * OptionsSelection |
|
| 772 | + */ |
|
| 773 | + $params_of_the_options_sel = array(); |
|
| 774 | + |
|
| 775 | + $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
| 776 | + foreach ($_GET as $k => $v) { |
|
| 777 | + if (!in_array($k, $not_needed_params)) { |
|
| 778 | + $new_get_array[] = "$k=$v"; |
|
| 779 | + $params_of_the_options_sel[] = "$k=$v"; |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * Adding the new params of the pagenav |
|
| 785 | + */ |
|
| 786 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 787 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 788 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 789 | + $otherParams = implode('&', $new_get_array); |
|
| 790 | + |
|
| 791 | + $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 792 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 793 | + } |
|
| 794 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 795 | + |
|
| 796 | + // retreive the current url and the query string |
|
| 797 | + $current_urls = smart_getCurrentUrls(); |
|
| 798 | + $current_url = $current_urls['full_phpself']; |
|
| 799 | + $query_string = $current_urls['querystring']; |
|
| 800 | + if ($query_string) { |
|
| 801 | + $query_string = str_replace('?', '', $query_string); |
|
| 802 | + } |
|
| 803 | + $query_stringArray = explode('&', $query_string); |
|
| 804 | + $new_query_stringArray = array(); |
|
| 805 | + foreach ($query_stringArray as $query_string) { |
|
| 806 | + if (strpos($query_string, 'sortsel') === false && strpos($query_string, 'ordersel') === false) { |
|
| 807 | + $new_query_stringArray[] = $query_string; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + $new_query_string = implode('&', $new_query_stringArray); |
|
| 811 | + |
|
| 812 | + $orderArray = array(); |
|
| 813 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
| 814 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 815 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
| 816 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 817 | + |
|
| 818 | + $aColumns = array(); |
|
| 819 | + |
|
| 820 | + foreach ($this->_columns as $column) { |
|
| 821 | + $qs_param = ''; |
|
| 822 | + $aColumn = array(); |
|
| 823 | + $aColumn['width'] = $column->getWidth(); |
|
| 824 | + $aColumn['align'] = $column->getAlign(); |
|
| 825 | + $aColumn['key'] = $column->getKeyName(); |
|
| 826 | + if ($column->_keyname === 'checked') { |
|
| 827 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 828 | + } elseif ($column->getCustomCaption()) { |
|
| 829 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
| 830 | + } else { |
|
| 831 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 832 | + } |
|
| 833 | + // Are we doing a GET sort on this column ? |
|
| 834 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 835 | + && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 836 | + || ($this->_sortsel == $column->getKeyName()); |
|
| 837 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 838 | + |
|
| 839 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
| 840 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 841 | + } |
|
| 842 | + if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
| 843 | + $aColumn['caption'] = $aColumn['caption']; |
|
| 844 | + } elseif ($getSort) { |
|
| 845 | + $aColumn['caption'] = '<a href="' |
|
| 846 | + . $current_url |
|
| 847 | + . '?' |
|
| 848 | + . $this->_objectHandler->_itemname |
|
| 849 | + . '_' |
|
| 850 | + . 'sortsel=' |
|
| 851 | + . $column->getKeyName() |
|
| 852 | + . '&' |
|
| 853 | + . $this->_objectHandler->_itemname |
|
| 854 | + . '_' |
|
| 855 | + . 'ordersel=' |
|
| 856 | + . $orderArray[$order]['neworder'] |
|
| 857 | + . $qs_param |
|
| 858 | + . '&' |
|
| 859 | + . $new_query_string |
|
| 860 | + . '">' |
|
| 861 | + . $aColumn['caption'] |
|
| 862 | + . ' <img src="' |
|
| 863 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 864 | + . $orderArray[$order]['image'] |
|
| 865 | + . '" alt="ASC"></a>'; |
|
| 866 | + } else { |
|
| 867 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 868 | + } |
|
| 869 | + $aColumns[] = $aColumn; |
|
| 870 | + } |
|
| 871 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 872 | + |
|
| 873 | + if ($this->_quickSearch) { |
|
| 874 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + $this->createTableRows(); |
|
| 878 | + |
|
| 879 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 880 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 881 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 882 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 883 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 884 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 885 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 886 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 887 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 888 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 889 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 890 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 891 | + if (!empty($this->_withSelectedActions)) { |
|
| 892 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 896 | + if ($fetchOnly) { |
|
| 897 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 898 | + } else { |
|
| 899 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + public function disableColumnsSorting() |
|
| 904 | + { |
|
| 905 | + $this->_enableColumnsSorting = false; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * @param bool $debug |
|
| 910 | + * @return mixed|string|void |
|
| 911 | + */ |
|
| 912 | + public function fetch($debug = false) |
|
| 913 | + { |
|
| 914 | + return $this->render(true, $debug); |
|
| 915 | + } |
|
| 916 | 916 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function addActionButton($op, $caption = false, $text = false) |
| 186 | 186 | { |
| 187 | - $action = array( |
|
| 187 | + $action = array( |
|
| 188 | 188 | 'op' => $op, |
| 189 | 189 | 'caption' => $caption, |
| 190 | 190 | 'text' => $text |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | { |
| 220 | 220 | $current_urls = smart_getCurrentUrls(); |
| 221 | 221 | $current_url = $current_urls['full']; |
| 222 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 222 | + $this->_printerFriendlyPage = $current_url.'&print'; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | public function addDefaultIntroButton($caption) |
| 254 | 254 | { |
| 255 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 255 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page.'?op=mod', $caption); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -277,9 +277,9 @@ discard block |
||
| 277 | 277 | public function getDefaultSort() |
| 278 | 278 | { |
| 279 | 279 | if ($this->_sortsel) { |
| 280 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 280 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
| 281 | 281 | } else { |
| 282 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 282 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_objectHandler->identifierName); |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | public function getDefaultOrder() |
| 298 | 298 | { |
| 299 | 299 | if ($this->_ordersel) { |
| 300 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 300 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
| 301 | 301 | } else { |
| 302 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 302 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', 'ASC'); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
@@ -348,21 +348,21 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | public function setSortOrder() |
| 350 | 350 | { |
| 351 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 351 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] : $this->getDefaultSort(); |
|
| 352 | 352 | //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
| 353 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 353 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
| 354 | 354 | $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
| 355 | 355 | |
| 356 | 356 | if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
| 357 | 357 | && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
| 358 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 358 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'].'.'.$this->_sortsel); |
|
| 359 | 359 | } else { |
| 360 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 360 | + $this->_criteria->setSort($this->_objectHandler->_itemname.'.'.$this->_sortsel); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 363 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : $this->getDefaultOrder(); |
|
| 364 | 364 | //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
| 365 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 365 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
| 366 | 366 | $ordersArray = $this->getOrdersArray(); |
| 367 | 367 | $this->_criteria->setOrder($this->_ordersel); |
| 368 | 368 | } |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | //$object->initiateCustomFields(); |
| 413 | 413 | } |
| 414 | 414 | if ($column->_keyname === 'checked') { |
| 415 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 415 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'">'; |
|
| 416 | 416 | } elseif ($column->_customMethodForValue |
| 417 | 417 | && method_exists($object, $column->_customMethodForValue)) { |
| 418 | 418 | $method = $column->_customMethodForValue; |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 460 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
| 461 | 461 | $controller = new SmartObjectController($this->_objectHandler); |
| 462 | 462 | |
| 463 | 463 | if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
@@ -497,9 +497,9 @@ discard block |
||
| 497 | 497 | public function getDefaultFilter() |
| 498 | 498 | { |
| 499 | 499 | if ($this->_filtersel) { |
| 500 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 500 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
| 501 | 501 | } else { |
| 502 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 502 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', 'default'); |
|
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
@@ -549,9 +549,9 @@ discard block |
||
| 549 | 549 | public function getDefaultFilter2() |
| 550 | 550 | { |
| 551 | 551 | if ($this->_filtersel2) { |
| 552 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 552 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
| 553 | 553 | } else { |
| 554 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 554 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', 'default'); |
|
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | */ |
| 680 | 680 | public function render($fetchOnly = false, $debug = false) |
| 681 | 681 | { |
| 682 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 682 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
| 683 | 683 | |
| 684 | 684 | $this->_tpl = new XoopsTpl(); |
| 685 | 685 | |
@@ -690,24 +690,24 @@ discard block |
||
| 690 | 690 | */ |
| 691 | 691 | $this->_tempObject = $this->_objectHandler->create(); |
| 692 | 692 | |
| 693 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 693 | + $this->_criteria->setStart(isset($_GET['start'.$this->_objectHandler->keyName]) ? (int) $_GET['start'.$this->_objectHandler->keyName] : 0); |
|
| 694 | 694 | |
| 695 | 695 | $this->setSortOrder(); |
| 696 | 696 | |
| 697 | 697 | if (!$this->_isTree) { |
| 698 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 698 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'].'_limitsel', '15'); |
|
| 699 | 699 | } else { |
| 700 | 700 | $this->_limitsel = 'all'; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
| 704 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 704 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_limitsel', $this->_limitsel); |
|
| 705 | 705 | $limitsArray = $this->getLimitsArray(); |
| 706 | 706 | $this->_criteria->setLimit($this->_limitsel); |
| 707 | 707 | |
| 708 | 708 | $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
| 709 | 709 | $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
| 710 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 710 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
| 711 | 711 | $filtersArray = $this->getFiltersArray(); |
| 712 | 712 | |
| 713 | 713 | if ($filtersArray) { |
@@ -733,7 +733,7 @@ discard block |
||
| 733 | 733 | $filters2Array = $this->getFilters2Array(); |
| 734 | 734 | $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
| 735 | 735 | |
| 736 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 736 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
| 737 | 737 | if ($this->_filtersel2 !== 'default') { |
| 738 | 738 | $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
| 739 | 739 | } |
@@ -742,21 +742,21 @@ discard block |
||
| 742 | 742 | } |
| 743 | 743 | // Check if we have a quicksearch |
| 744 | 744 | |
| 745 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
| 745 | + if (isset($_POST['quicksearch_'.$this->_id]) && $_POST['quicksearch_'.$this->_id] != '') { |
|
| 746 | 746 | $quicksearch_criteria = new CriteriaCompo(); |
| 747 | 747 | if (is_array($this->_quickSearch['fields'])) { |
| 748 | 748 | foreach ($this->_quickSearch['fields'] as $v) { |
| 749 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 749 | + $quicksearch_criteria->add(new Criteria($v, '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'), 'OR'); |
|
| 750 | 750 | } |
| 751 | 751 | } else { |
| 752 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 752 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE')); |
|
| 753 | 753 | } |
| 754 | 754 | $this->_criteria->add($quicksearch_criteria); |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | $this->_objects = $this->fetchObjects($debug); |
| 758 | 758 | |
| 759 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 759 | + require_once XOOPS_ROOT_PATH.'/class/pagenav.php'; |
|
| 760 | 760 | if ($this->_criteria->getLimit() > 0) { |
| 761 | 761 | |
| 762 | 762 | /** |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | */ |
| 773 | 773 | $params_of_the_options_sel = array(); |
| 774 | 774 | |
| 775 | - $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
| 775 | + $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start'.$this->_objectHandler->keyName); |
|
| 776 | 776 | foreach ($_GET as $k => $v) { |
| 777 | 777 | if (!in_array($k, $not_needed_params)) { |
| 778 | 778 | $new_get_array[] = "$k=$v"; |
@@ -783,12 +783,12 @@ discard block |
||
| 783 | 783 | /** |
| 784 | 784 | * Adding the new params of the pagenav |
| 785 | 785 | */ |
| 786 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 787 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 788 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 786 | + $new_get_array[] = 'sortsel='.$this->_sortsel; |
|
| 787 | + $new_get_array[] = 'ordersel='.$this->_ordersel; |
|
| 788 | + $new_get_array[] = 'limitsel='.$this->_limitsel; |
|
| 789 | 789 | $otherParams = implode('&', $new_get_array); |
| 790 | 790 | |
| 791 | - $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 791 | + $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start'.$this->_objectHandler->keyName, $otherParams); |
|
| 792 | 792 | $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
| 793 | 793 | } |
| 794 | 794 | $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
@@ -824,20 +824,20 @@ discard block |
||
| 824 | 824 | $aColumn['align'] = $column->getAlign(); |
| 825 | 825 | $aColumn['key'] = $column->getKeyName(); |
| 826 | 826 | if ($column->_keyname === 'checked') { |
| 827 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 827 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"'.' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_'.$this->_id.', \'selected_smartobjects\');">'; |
|
| 828 | 828 | } elseif ($column->getCustomCaption()) { |
| 829 | 829 | $aColumn['caption'] = $column->getCustomCaption(); |
| 830 | 830 | } else { |
| 831 | 831 | $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
| 832 | 832 | } |
| 833 | 833 | // Are we doing a GET sort on this column ? |
| 834 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 835 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 834 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) |
|
| 835 | + && $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] == $column->getKeyName()) |
|
| 836 | 836 | || ($this->_sortsel == $column->getKeyName()); |
| 837 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 837 | + $order = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : 'DESC'; |
|
| 838 | 838 | |
| 839 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
| 840 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 839 | + if (isset($_REQUEST['quicksearch_'.$this->_id]) && $_REQUEST['quicksearch_'.$this->_id] != '') { |
|
| 840 | + $qs_param = '&quicksearch_'.$this->_id.'='.$_REQUEST['quicksearch_'.$this->_id]; |
|
| 841 | 841 | } |
| 842 | 842 | if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
| 843 | 843 | $aColumn['caption'] = $aColumn['caption']; |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | . $orderArray[$order]['image'] |
| 865 | 865 | . '" alt="ASC"></a>'; |
| 866 | 866 | } else { |
| 867 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 867 | + $aColumn['caption'] = '<a href="'.$current_url.'?'.$this->_objectHandler->_itemname.'_'.'sortsel='.$column->getKeyName().'&'.$this->_objectHandler->_itemname.'_'.'ordersel=ASC'.$qs_param.'&'.$new_query_string.'">'.$aColumn['caption'].'</a>'; |
|
| 868 | 868 | } |
| 869 | 869 | $aColumns[] = $aColumn; |
| 870 | 870 | } |
@@ -894,9 +894,9 @@ discard block |
||
| 894 | 894 | |
| 895 | 895 | $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
| 896 | 896 | if ($fetchOnly) { |
| 897 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 897 | + return $this->_tpl->fetch('db:'.$smartobjectTable_template); |
|
| 898 | 898 | } else { |
| 899 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 899 | + $this->_tpl->display('db:'.$smartobjectTable_template); |
|
| 900 | 900 | } |
| 901 | 901 | } |
| 902 | 902 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @param $javascript |
| 30 | - * @return mixed|string |
|
| 30 | + * @return string |
|
| 31 | 31 | */ |
| 32 | 32 | public function escape($javascript) |
| 33 | 33 | { |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @param $name |
| 51 | - * @param $function |
|
| 51 | + * @param string $function |
|
| 52 | 52 | * @param null $html_options |
| 53 | 53 | * @return string |
| 54 | 54 | */ |
@@ -15,90 +15,90 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class JavaScript |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param $name |
|
| 20 | - * @param null $function |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function button_to_function($name, $function = null) |
|
| 24 | - { |
|
| 25 | - return '<input type="button" value="' . $name . '" onclick="' . $function . '">'; |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * @param $name |
|
| 20 | + * @param null $function |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function button_to_function($name, $function = null) |
|
| 24 | + { |
|
| 25 | + return '<input type="button" value="' . $name . '" onclick="' . $function . '">'; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param $javascript |
|
| 30 | - * @return mixed|string |
|
| 31 | - */ |
|
| 32 | - public function escape($javascript) |
|
| 33 | - { |
|
| 34 | - $javascript = addslashes($javascript); |
|
| 35 | - $javascript = str_replace(array("\r\n", "\n", "\r"), array("\n"), $javascript); |
|
| 28 | + /** |
|
| 29 | + * @param $javascript |
|
| 30 | + * @return mixed|string |
|
| 31 | + */ |
|
| 32 | + public function escape($javascript) |
|
| 33 | + { |
|
| 34 | + $javascript = addslashes($javascript); |
|
| 35 | + $javascript = str_replace(array("\r\n", "\n", "\r"), array("\n"), $javascript); |
|
| 36 | 36 | |
| 37 | - return $javascript; |
|
| 38 | - } |
|
| 37 | + return $javascript; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param $content |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function tag($content) |
|
| 45 | - { |
|
| 46 | - return '<script type="text/javascript">' . $content . '</script>'; |
|
| 47 | - } |
|
| 40 | + /** |
|
| 41 | + * @param $content |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function tag($content) |
|
| 45 | + { |
|
| 46 | + return '<script type="text/javascript">' . $content . '</script>'; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param $name |
|
| 51 | - * @param $function |
|
| 52 | - * @param null $html_options |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - public function link_to_function($name, $function, $html_options = null) |
|
| 56 | - { |
|
| 57 | - return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>'; |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * @param $name |
|
| 51 | + * @param $function |
|
| 52 | + * @param null $html_options |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + public function link_to_function($name, $function, $html_options = null) |
|
| 56 | + { |
|
| 57 | + return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>'; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 61 | - // Private functions |
|
| 62 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 60 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 61 | + // Private functions |
|
| 62 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param $option |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function _array_or_string_for_javascript($option) |
|
| 69 | - { |
|
| 70 | - $return_val = ''; |
|
| 71 | - if (is_array($option)) { |
|
| 72 | - foreach ($option as $value) { |
|
| 73 | - if (!empty($return_val)) { |
|
| 74 | - $ret_val .= ', '; |
|
| 75 | - } |
|
| 76 | - $return_val .= $value; |
|
| 77 | - } |
|
| 64 | + /** |
|
| 65 | + * @param $option |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function _array_or_string_for_javascript($option) |
|
| 69 | + { |
|
| 70 | + $return_val = ''; |
|
| 71 | + if (is_array($option)) { |
|
| 72 | + foreach ($option as $value) { |
|
| 73 | + if (!empty($return_val)) { |
|
| 74 | + $ret_val .= ', '; |
|
| 75 | + } |
|
| 76 | + $return_val .= $value; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return '[' . $return_val . ']'; |
|
| 80 | - } |
|
| 79 | + return '[' . $return_val . ']'; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - return "'$option'"; |
|
| 83 | - } |
|
| 82 | + return "'$option'"; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param $options |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function _options_for_javascript($options) |
|
| 90 | - { |
|
| 91 | - $return_val = ''; |
|
| 85 | + /** |
|
| 86 | + * @param $options |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function _options_for_javascript($options) |
|
| 90 | + { |
|
| 91 | + $return_val = ''; |
|
| 92 | 92 | |
| 93 | - if (is_array($options)) { |
|
| 94 | - foreach ($options as $var => $val) { |
|
| 95 | - if (!empty($return_val)) { |
|
| 96 | - $return_val .= ', '; |
|
| 97 | - } |
|
| 98 | - $return_val .= "$var:$val"; |
|
| 99 | - } |
|
| 100 | - } |
|
| 93 | + if (is_array($options)) { |
|
| 94 | + foreach ($options as $var => $val) { |
|
| 95 | + if (!empty($return_val)) { |
|
| 96 | + $return_val .= ', '; |
|
| 97 | + } |
|
| 98 | + $return_val .= "$var:$val"; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return '{' . $return_val . '}'; |
|
| 103 | - } |
|
| 102 | + return '{' . $return_val . '}'; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function button_to_function($name, $function = null) |
| 24 | 24 | { |
| 25 | - return '<input type="button" value="' . $name . '" onclick="' . $function . '">'; |
|
| 25 | + return '<input type="button" value="'.$name.'" onclick="'.$function.'">'; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function tag($content) |
| 45 | 45 | { |
| 46 | - return '<script type="text/javascript">' . $content . '</script>'; |
|
| 46 | + return '<script type="text/javascript">'.$content.'</script>'; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function link_to_function($name, $function, $html_options = null) |
| 56 | 56 | { |
| 57 | - return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>'; |
|
| 57 | + return '<a href="'.(isset($html_options['href']) ? $html_options['href'] : '#').'" onclick="'.(isset($html_options['onclick']) ? $html_options['onclick'].';' : '').$function.'; return false;">'.$name.'</a>'; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | ///////////////////////////////////////////////////////////////////////////////////// |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $return_val .= $value; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - return '[' . $return_val . ']'; |
|
| 79 | + return '['.$return_val.']'; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return "'$option'"; |
@@ -99,6 +99,6 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - return '{' . $return_val . '}'; |
|
| 102 | + return '{'.$return_val.'}'; |
|
| 103 | 103 | } |
| 104 | 104 | } |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | - * @param $klass |
|
| 215 | + * @param string $klass |
|
| 216 | 216 | * @param $name |
| 217 | 217 | * @param null $options |
| 218 | 218 | * @return string |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
| 314 | - * @param $variable |
|
| 314 | + * @param string $variable |
|
| 315 | 315 | * @param $value |
| 316 | 316 | * @return string |
| 317 | 317 | */ |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
| 324 | - * @param $function |
|
| 324 | + * @param string $function |
|
| 325 | 325 | * @param null $args |
| 326 | 326 | * @return string |
| 327 | 327 | */ |
@@ -15,452 +15,452 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Prototype extends JavaScript |
| 17 | 17 | { |
| 18 | - public $CALLBACKS = array( |
|
| 19 | - 'uninitialized', |
|
| 20 | - 'loading', |
|
| 21 | - 'loaded', |
|
| 22 | - 'interactive', |
|
| 23 | - 'complete', |
|
| 24 | - 'failure', |
|
| 25 | - 'success' |
|
| 26 | - ); |
|
| 27 | - |
|
| 28 | - public $AJAX_OPTIONS = array( |
|
| 29 | - 'before', |
|
| 30 | - 'after', |
|
| 31 | - 'condition', |
|
| 32 | - 'url', |
|
| 33 | - 'asynchronous', |
|
| 34 | - 'method', |
|
| 35 | - 'insertion', |
|
| 36 | - 'position', |
|
| 37 | - 'form', |
|
| 38 | - 'with', |
|
| 39 | - 'update', |
|
| 40 | - 'script', |
|
| 41 | - 'uninitialized', |
|
| 42 | - 'loading', |
|
| 43 | - 'loaded', |
|
| 44 | - 'interactive', |
|
| 45 | - 'complete', |
|
| 46 | - 'failure', |
|
| 47 | - 'success' |
|
| 48 | - ); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function evaluate_remote_response() |
|
| 54 | - { |
|
| 55 | - return 'eval(request.responseText)'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param $options |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function form_remote_tag($options) |
|
| 63 | - { |
|
| 64 | - $options['form'] = true; |
|
| 65 | - |
|
| 66 | - return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param $name |
|
| 71 | - * @param null $options |
|
| 72 | - * @param null $html_options |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - public function link_to_remote($name, $options = null, $html_options = null) |
|
| 76 | - { |
|
| 77 | - return $this->link_to_function($name, $this->remote_function($options), $html_options); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param $field_id |
|
| 82 | - * @param null $options |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function observe_field($field_id, $options = null) |
|
| 86 | - { |
|
| 87 | - if (isset($options['frequency']) && $options['frequency'] > 0) { |
|
| 88 | - return $this->_build_observer('Form.Element.Observer', $field_id, $options); |
|
| 89 | - } else { |
|
| 90 | - return $this->_build_observer('Form.Element.EventObserver', $field_id, $options); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param $form_id |
|
| 96 | - * @param null $options |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function observe_form($form_id, $options = null) |
|
| 100 | - { |
|
| 101 | - if (isset($options['frequency'])) { |
|
| 102 | - return $this->_build_observer('Form.Observer', $form_id, $options); |
|
| 103 | - } else { |
|
| 104 | - return $this->_build_observer('Form.EventObserver', $form_id, $options); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param null $options |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function periodically_call_remote($options = null) |
|
| 113 | - { |
|
| 114 | - $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|
| 115 | - $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
| 116 | - |
|
| 117 | - return $code; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param $options |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public function remote_function($options) |
|
| 125 | - { |
|
| 126 | - $javascript_options = $this->_options_for_ajax($options); |
|
| 127 | - |
|
| 128 | - $update = ''; |
|
| 129 | - |
|
| 130 | - if (isset($options['update']) && is_array($options['update'])) { |
|
| 131 | - $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
| 132 | - $update .= empty($update) ? '' : ','; |
|
| 133 | - $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
| 134 | - } else { |
|
| 135 | - $update .= isset($options['update']) ? $options['update'] : ''; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
| 139 | - |
|
| 140 | - $ajax_function .= "'" . $options['url'] . "'"; |
|
| 141 | - $ajax_function .= ',' . $javascript_options . ')'; |
|
| 142 | - |
|
| 143 | - $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
| 144 | - $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
| 145 | - $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
| 146 | - $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
| 147 | - |
|
| 148 | - return $ajax_function; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param $name |
|
| 153 | - * @param $value |
|
| 154 | - * @param $options |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function submit_to_remote($name, $value, $options) |
|
| 158 | - { |
|
| 159 | - if (isset($options['with'])) { |
|
| 160 | - $options['with'] = 'Form.serialize(this.form)'; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">'; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param $element_id |
|
| 168 | - * @param null $options |
|
| 169 | - * @param $block |
|
| 170 | - */ |
|
| 171 | - public function update_element_function($element_id, $options = null, $block) |
|
| 172 | - { |
|
| 173 | - $content = isset($options['content']) ? $options['content'] : ''; |
|
| 174 | - $content = $this->escape($content); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param $block |
|
| 179 | - */ |
|
| 180 | - public function update_page($block) |
|
| 181 | - { |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param $block |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - public function update_page_tag(& $block) |
|
| 189 | - { |
|
| 190 | - return $this->tag($block); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 194 | - // Private functions |
|
| 195 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param $options |
|
| 199 | - * @return array |
|
| 200 | - */ |
|
| 201 | - public function _build_callbacks($options) |
|
| 202 | - { |
|
| 203 | - $callbacks = array(); |
|
| 204 | - foreach ($options as $callback => $code) { |
|
| 205 | - if (in_array($callback, $this->CALLBACKS)) { |
|
| 206 | - $name = 'on' . ucfirst($callback); |
|
| 207 | - $callbacks[$name] = 'function(request){' . $code . '}'; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return $callbacks; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param $klass |
|
| 216 | - * @param $name |
|
| 217 | - * @param null $options |
|
| 218 | - * @return string |
|
| 219 | - */ |
|
| 220 | - public function _build_observer($klass, $name, $options = null) |
|
| 221 | - { |
|
| 222 | - if (isset($options['with']) && false === strpos($options['with'], '=')) { |
|
| 223 | - $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
| 224 | - } elseif (isset($options['with']) && isset($options['update'])) { |
|
| 225 | - $options['with'] = 'value'; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $callback = $options['function'] ?: $this->remote_function($options); |
|
| 229 | - |
|
| 230 | - $javascript = "new $klass('$name', "; |
|
| 231 | - $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
| 232 | - $javascript .= 'function (element,value) { '; |
|
| 233 | - $javascript .= $callback; |
|
| 234 | - $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
| 235 | - $javascript .= '})'; |
|
| 236 | - |
|
| 237 | - return $javascript; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param $method |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - public function _method_option_to_s($method) |
|
| 245 | - { |
|
| 246 | - return strstr($method, "'") ? $method : "'$method'"; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param $options |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public function _options_for_ajax($options) |
|
| 254 | - { |
|
| 255 | - $js_options = is_array($options) ? $this->_build_callbacks($options) : array(); |
|
| 256 | - |
|
| 257 | - if (isset($options['type']) && $option['type'] === 'synchronous') { |
|
| 258 | - $js_options['asynchronous'] = 'false'; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if (isset($options['method'])) { |
|
| 262 | - $js_options['method'] = $this->_method_option_to_s($options['method']); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if (isset($options['position'])) { |
|
| 266 | - $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
|
| 270 | - |
|
| 271 | - if (isset($options['form'])) { |
|
| 272 | - $js_options['parameters'] = 'Form.serialize(this)'; |
|
| 273 | - } elseif (isset($options['parameters'])) { |
|
| 274 | - $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
| 275 | - } elseif (isset($options['with'])) { |
|
| 276 | - $js_options['parameters'] = $options['with']; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return $this->_options_for_javascript($js_options); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 283 | - // Mergerd Javascript Generator helpers |
|
| 284 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param $javascript |
|
| 288 | - */ |
|
| 289 | - public function dump($javascript) |
|
| 290 | - { |
|
| 291 | - echo $javascript; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @param $id |
|
| 296 | - * @param null $extend |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - public function ID($id, $extend = null) |
|
| 300 | - { |
|
| 301 | - return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param $message |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 308 | - public function alert($message) |
|
| 309 | - { |
|
| 310 | - return $this->call('alert', $message); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @param $variable |
|
| 315 | - * @param $value |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - public function assign($variable, $value) |
|
| 319 | - { |
|
| 320 | - return "$variable = $value;"; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @param $function |
|
| 325 | - * @param null $args |
|
| 326 | - * @return string |
|
| 327 | - */ |
|
| 328 | - public function call($function, $args = null) |
|
| 329 | - { |
|
| 330 | - $arg_str = ''; |
|
| 331 | - if (is_array($args)) { |
|
| 332 | - foreach ($args as $arg) { |
|
| 333 | - if (!empty($arg_str)) { |
|
| 334 | - $arg_str .= ', '; |
|
| 335 | - } |
|
| 336 | - if (is_string($arg)) { |
|
| 337 | - $arg_str .= "'$arg'"; |
|
| 338 | - } else { |
|
| 339 | - $arg_str .= $arg; |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } else { |
|
| 343 | - if (is_string($args)) { |
|
| 344 | - $arg_str .= "'$args'"; |
|
| 345 | - } else { |
|
| 346 | - $arg_str .= $args; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return "$function($arg_str)"; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @param int $seconds |
|
| 355 | - * @param string $script |
|
| 356 | - * @return string |
|
| 357 | - */ |
|
| 358 | - public function delay($seconds = 1, $script = '') |
|
| 359 | - { |
|
| 360 | - return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * @param $id |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 367 | - public function hide($id) |
|
| 368 | - { |
|
| 369 | - return $this->call('Element.hide', $id); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @param $position |
|
| 374 | - * @param $id |
|
| 375 | - * @param null $options_for_render |
|
| 376 | - * @return string |
|
| 377 | - */ |
|
| 378 | - public function insert_html($position, $id, $options_for_render = null) |
|
| 379 | - { |
|
| 380 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 381 | - |
|
| 382 | - return $this->call('new Insertion.' . ucfirst($position), $args); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @param $location |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - public function redirect_to($location) |
|
| 390 | - { |
|
| 391 | - return $this->assign('window.location.href', $location); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * @param $id |
|
| 396 | - * @return string |
|
| 397 | - */ |
|
| 398 | - public function remove($id) |
|
| 399 | - { |
|
| 400 | - if (is_array($id)) { |
|
| 401 | - $arr_str = ''; |
|
| 402 | - foreach ($id as $obj) { |
|
| 403 | - if (!empty($arg_str)) { |
|
| 404 | - $arg_str .= ', '; |
|
| 405 | - } |
|
| 406 | - $arg_str .= "'$arg'"; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return "$A[$arg_str].each(Element.remove)"; |
|
| 410 | - } else { |
|
| 411 | - return "Element.remove('$id')"; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @param $id |
|
| 417 | - * @param $options_for_render |
|
| 418 | - * @return string |
|
| 419 | - */ |
|
| 420 | - public function replace($id, $options_for_render) |
|
| 421 | - { |
|
| 422 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 423 | - |
|
| 424 | - return $this->call('Element.replace', $args); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @param $id |
|
| 429 | - * @param $options_for_render |
|
| 430 | - * @return string |
|
| 431 | - */ |
|
| 432 | - public function replace_html($id, $options_for_render) |
|
| 433 | - { |
|
| 434 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 435 | - |
|
| 436 | - return $this->call('Element.update', $args); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @param $pattern |
|
| 441 | - * @param null $extend |
|
| 442 | - * @return string |
|
| 443 | - */ |
|
| 444 | - public function select($pattern, $extend = null) |
|
| 445 | - { |
|
| 446 | - return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @param $id |
|
| 451 | - * @return string |
|
| 452 | - */ |
|
| 453 | - public function show($id) |
|
| 454 | - { |
|
| 455 | - return $this->call('Element.show', $id); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @param $id |
|
| 460 | - * @return string |
|
| 461 | - */ |
|
| 462 | - public function toggle($id) |
|
| 463 | - { |
|
| 464 | - return $this->call('Element.toggle', $id); |
|
| 465 | - } |
|
| 18 | + public $CALLBACKS = array( |
|
| 19 | + 'uninitialized', |
|
| 20 | + 'loading', |
|
| 21 | + 'loaded', |
|
| 22 | + 'interactive', |
|
| 23 | + 'complete', |
|
| 24 | + 'failure', |
|
| 25 | + 'success' |
|
| 26 | + ); |
|
| 27 | + |
|
| 28 | + public $AJAX_OPTIONS = array( |
|
| 29 | + 'before', |
|
| 30 | + 'after', |
|
| 31 | + 'condition', |
|
| 32 | + 'url', |
|
| 33 | + 'asynchronous', |
|
| 34 | + 'method', |
|
| 35 | + 'insertion', |
|
| 36 | + 'position', |
|
| 37 | + 'form', |
|
| 38 | + 'with', |
|
| 39 | + 'update', |
|
| 40 | + 'script', |
|
| 41 | + 'uninitialized', |
|
| 42 | + 'loading', |
|
| 43 | + 'loaded', |
|
| 44 | + 'interactive', |
|
| 45 | + 'complete', |
|
| 46 | + 'failure', |
|
| 47 | + 'success' |
|
| 48 | + ); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function evaluate_remote_response() |
|
| 54 | + { |
|
| 55 | + return 'eval(request.responseText)'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param $options |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function form_remote_tag($options) |
|
| 63 | + { |
|
| 64 | + $options['form'] = true; |
|
| 65 | + |
|
| 66 | + return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param $name |
|
| 71 | + * @param null $options |
|
| 72 | + * @param null $html_options |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + public function link_to_remote($name, $options = null, $html_options = null) |
|
| 76 | + { |
|
| 77 | + return $this->link_to_function($name, $this->remote_function($options), $html_options); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param $field_id |
|
| 82 | + * @param null $options |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function observe_field($field_id, $options = null) |
|
| 86 | + { |
|
| 87 | + if (isset($options['frequency']) && $options['frequency'] > 0) { |
|
| 88 | + return $this->_build_observer('Form.Element.Observer', $field_id, $options); |
|
| 89 | + } else { |
|
| 90 | + return $this->_build_observer('Form.Element.EventObserver', $field_id, $options); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param $form_id |
|
| 96 | + * @param null $options |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function observe_form($form_id, $options = null) |
|
| 100 | + { |
|
| 101 | + if (isset($options['frequency'])) { |
|
| 102 | + return $this->_build_observer('Form.Observer', $form_id, $options); |
|
| 103 | + } else { |
|
| 104 | + return $this->_build_observer('Form.EventObserver', $form_id, $options); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param null $options |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function periodically_call_remote($options = null) |
|
| 113 | + { |
|
| 114 | + $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|
| 115 | + $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
| 116 | + |
|
| 117 | + return $code; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param $options |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public function remote_function($options) |
|
| 125 | + { |
|
| 126 | + $javascript_options = $this->_options_for_ajax($options); |
|
| 127 | + |
|
| 128 | + $update = ''; |
|
| 129 | + |
|
| 130 | + if (isset($options['update']) && is_array($options['update'])) { |
|
| 131 | + $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
| 132 | + $update .= empty($update) ? '' : ','; |
|
| 133 | + $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
| 134 | + } else { |
|
| 135 | + $update .= isset($options['update']) ? $options['update'] : ''; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
| 139 | + |
|
| 140 | + $ajax_function .= "'" . $options['url'] . "'"; |
|
| 141 | + $ajax_function .= ',' . $javascript_options . ')'; |
|
| 142 | + |
|
| 143 | + $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
| 144 | + $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
| 145 | + $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
| 146 | + $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
| 147 | + |
|
| 148 | + return $ajax_function; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param $name |
|
| 153 | + * @param $value |
|
| 154 | + * @param $options |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function submit_to_remote($name, $value, $options) |
|
| 158 | + { |
|
| 159 | + if (isset($options['with'])) { |
|
| 160 | + $options['with'] = 'Form.serialize(this.form)'; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">'; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param $element_id |
|
| 168 | + * @param null $options |
|
| 169 | + * @param $block |
|
| 170 | + */ |
|
| 171 | + public function update_element_function($element_id, $options = null, $block) |
|
| 172 | + { |
|
| 173 | + $content = isset($options['content']) ? $options['content'] : ''; |
|
| 174 | + $content = $this->escape($content); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param $block |
|
| 179 | + */ |
|
| 180 | + public function update_page($block) |
|
| 181 | + { |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param $block |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + public function update_page_tag(& $block) |
|
| 189 | + { |
|
| 190 | + return $this->tag($block); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 194 | + // Private functions |
|
| 195 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param $options |
|
| 199 | + * @return array |
|
| 200 | + */ |
|
| 201 | + public function _build_callbacks($options) |
|
| 202 | + { |
|
| 203 | + $callbacks = array(); |
|
| 204 | + foreach ($options as $callback => $code) { |
|
| 205 | + if (in_array($callback, $this->CALLBACKS)) { |
|
| 206 | + $name = 'on' . ucfirst($callback); |
|
| 207 | + $callbacks[$name] = 'function(request){' . $code . '}'; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return $callbacks; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param $klass |
|
| 216 | + * @param $name |
|
| 217 | + * @param null $options |
|
| 218 | + * @return string |
|
| 219 | + */ |
|
| 220 | + public function _build_observer($klass, $name, $options = null) |
|
| 221 | + { |
|
| 222 | + if (isset($options['with']) && false === strpos($options['with'], '=')) { |
|
| 223 | + $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
| 224 | + } elseif (isset($options['with']) && isset($options['update'])) { |
|
| 225 | + $options['with'] = 'value'; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $callback = $options['function'] ?: $this->remote_function($options); |
|
| 229 | + |
|
| 230 | + $javascript = "new $klass('$name', "; |
|
| 231 | + $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
| 232 | + $javascript .= 'function (element,value) { '; |
|
| 233 | + $javascript .= $callback; |
|
| 234 | + $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
| 235 | + $javascript .= '})'; |
|
| 236 | + |
|
| 237 | + return $javascript; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param $method |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + public function _method_option_to_s($method) |
|
| 245 | + { |
|
| 246 | + return strstr($method, "'") ? $method : "'$method'"; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param $options |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + public function _options_for_ajax($options) |
|
| 254 | + { |
|
| 255 | + $js_options = is_array($options) ? $this->_build_callbacks($options) : array(); |
|
| 256 | + |
|
| 257 | + if (isset($options['type']) && $option['type'] === 'synchronous') { |
|
| 258 | + $js_options['asynchronous'] = 'false'; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if (isset($options['method'])) { |
|
| 262 | + $js_options['method'] = $this->_method_option_to_s($options['method']); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if (isset($options['position'])) { |
|
| 266 | + $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
|
| 270 | + |
|
| 271 | + if (isset($options['form'])) { |
|
| 272 | + $js_options['parameters'] = 'Form.serialize(this)'; |
|
| 273 | + } elseif (isset($options['parameters'])) { |
|
| 274 | + $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
| 275 | + } elseif (isset($options['with'])) { |
|
| 276 | + $js_options['parameters'] = $options['with']; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return $this->_options_for_javascript($js_options); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 283 | + // Mergerd Javascript Generator helpers |
|
| 284 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param $javascript |
|
| 288 | + */ |
|
| 289 | + public function dump($javascript) |
|
| 290 | + { |
|
| 291 | + echo $javascript; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @param $id |
|
| 296 | + * @param null $extend |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + public function ID($id, $extend = null) |
|
| 300 | + { |
|
| 301 | + return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param $message |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | + public function alert($message) |
|
| 309 | + { |
|
| 310 | + return $this->call('alert', $message); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @param $variable |
|
| 315 | + * @param $value |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + public function assign($variable, $value) |
|
| 319 | + { |
|
| 320 | + return "$variable = $value;"; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @param $function |
|
| 325 | + * @param null $args |
|
| 326 | + * @return string |
|
| 327 | + */ |
|
| 328 | + public function call($function, $args = null) |
|
| 329 | + { |
|
| 330 | + $arg_str = ''; |
|
| 331 | + if (is_array($args)) { |
|
| 332 | + foreach ($args as $arg) { |
|
| 333 | + if (!empty($arg_str)) { |
|
| 334 | + $arg_str .= ', '; |
|
| 335 | + } |
|
| 336 | + if (is_string($arg)) { |
|
| 337 | + $arg_str .= "'$arg'"; |
|
| 338 | + } else { |
|
| 339 | + $arg_str .= $arg; |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } else { |
|
| 343 | + if (is_string($args)) { |
|
| 344 | + $arg_str .= "'$args'"; |
|
| 345 | + } else { |
|
| 346 | + $arg_str .= $args; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return "$function($arg_str)"; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @param int $seconds |
|
| 355 | + * @param string $script |
|
| 356 | + * @return string |
|
| 357 | + */ |
|
| 358 | + public function delay($seconds = 1, $script = '') |
|
| 359 | + { |
|
| 360 | + return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * @param $id |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | + public function hide($id) |
|
| 368 | + { |
|
| 369 | + return $this->call('Element.hide', $id); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @param $position |
|
| 374 | + * @param $id |
|
| 375 | + * @param null $options_for_render |
|
| 376 | + * @return string |
|
| 377 | + */ |
|
| 378 | + public function insert_html($position, $id, $options_for_render = null) |
|
| 379 | + { |
|
| 380 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 381 | + |
|
| 382 | + return $this->call('new Insertion.' . ucfirst($position), $args); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @param $location |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + public function redirect_to($location) |
|
| 390 | + { |
|
| 391 | + return $this->assign('window.location.href', $location); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * @param $id |
|
| 396 | + * @return string |
|
| 397 | + */ |
|
| 398 | + public function remove($id) |
|
| 399 | + { |
|
| 400 | + if (is_array($id)) { |
|
| 401 | + $arr_str = ''; |
|
| 402 | + foreach ($id as $obj) { |
|
| 403 | + if (!empty($arg_str)) { |
|
| 404 | + $arg_str .= ', '; |
|
| 405 | + } |
|
| 406 | + $arg_str .= "'$arg'"; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return "$A[$arg_str].each(Element.remove)"; |
|
| 410 | + } else { |
|
| 411 | + return "Element.remove('$id')"; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @param $id |
|
| 417 | + * @param $options_for_render |
|
| 418 | + * @return string |
|
| 419 | + */ |
|
| 420 | + public function replace($id, $options_for_render) |
|
| 421 | + { |
|
| 422 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 423 | + |
|
| 424 | + return $this->call('Element.replace', $args); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @param $id |
|
| 429 | + * @param $options_for_render |
|
| 430 | + * @return string |
|
| 431 | + */ |
|
| 432 | + public function replace_html($id, $options_for_render) |
|
| 433 | + { |
|
| 434 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 435 | + |
|
| 436 | + return $this->call('Element.update', $args); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @param $pattern |
|
| 441 | + * @param null $extend |
|
| 442 | + * @return string |
|
| 443 | + */ |
|
| 444 | + public function select($pattern, $extend = null) |
|
| 445 | + { |
|
| 446 | + return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @param $id |
|
| 451 | + * @return string |
|
| 452 | + */ |
|
| 453 | + public function show($id) |
|
| 454 | + { |
|
| 455 | + return $this->call('Element.show', $id); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @param $id |
|
| 460 | + * @return string |
|
| 461 | + */ |
|
| 462 | + public function toggle($id) |
|
| 463 | + { |
|
| 464 | + return $this->call('Element.toggle', $id); |
|
| 465 | + } |
|
| 466 | 466 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | $options['form'] = true; |
| 65 | 65 | |
| 66 | - return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
| 66 | + return '<form action="'.$options['url'].'" onsubmit="'.$this->remote_function($options).'; return false;" method="'.(isset($options['method']) ? $options['method'] : 'post').'" >'; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | public function periodically_call_remote($options = null) |
| 113 | 113 | { |
| 114 | 114 | $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
| 115 | - $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
| 115 | + $code = 'new PeriodicalExecuter(function() {'.$this->remote_function($options).'},'.$frequency.')'; |
|
| 116 | 116 | |
| 117 | 117 | return $code; |
| 118 | 118 | } |
@@ -128,22 +128,22 @@ discard block |
||
| 128 | 128 | $update = ''; |
| 129 | 129 | |
| 130 | 130 | if (isset($options['update']) && is_array($options['update'])) { |
| 131 | - $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
| 131 | + $update = isset($options['update']['success']) ? 'success: '.$options['update']['success'] : ''; |
|
| 132 | 132 | $update .= empty($update) ? '' : ','; |
| 133 | - $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
| 133 | + $update .= isset($options['update']['failure']) ? 'failure: '.$options['update']['failure'] : ''; |
|
| 134 | 134 | } else { |
| 135 | 135 | $update .= isset($options['update']) ? $options['update'] : ''; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
| 138 | + $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\''.$update.'\','; |
|
| 139 | 139 | |
| 140 | - $ajax_function .= "'" . $options['url'] . "'"; |
|
| 141 | - $ajax_function .= ',' . $javascript_options . ')'; |
|
| 140 | + $ajax_function .= "'".$options['url']."'"; |
|
| 141 | + $ajax_function .= ','.$javascript_options.')'; |
|
| 142 | 142 | |
| 143 | - $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
| 144 | - $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
| 145 | - $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
| 146 | - $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
| 143 | + $ajax_function = isset($options['before']) ? $options['before'].';'.$ajax_function : $ajax_function; |
|
| 144 | + $ajax_function = isset($options['after']) ? $ajax_function.';'.$options['after'] : $ajax_function; |
|
| 145 | + $ajax_function = isset($options['condition']) ? 'if ('.$options['condition'].') {'.$ajax_function.'}' : $ajax_function; |
|
| 146 | + $ajax_function = isset($options['confirm']) ? 'if ( confirm(\''.$options['confirm'].'\' ) ) { '.$ajax_function.' } ' : $ajax_function; |
|
| 147 | 147 | |
| 148 | 148 | return $ajax_function; |
| 149 | 149 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $options['with'] = 'Form.serialize(this.form)'; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">'; |
|
| 163 | + return '<input type="button" onclick="'.$this->remote_function($options).'" name="'.$name.'" value ="'.$value.'">'; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | $callbacks = array(); |
| 204 | 204 | foreach ($options as $callback => $code) { |
| 205 | 205 | if (in_array($callback, $this->CALLBACKS)) { |
| 206 | - $name = 'on' . ucfirst($callback); |
|
| 207 | - $callbacks[$name] = 'function(request){' . $code . '}'; |
|
| 206 | + $name = 'on'.ucfirst($callback); |
|
| 207 | + $callbacks[$name] = 'function(request){'.$code.'}'; |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | public function _build_observer($klass, $name, $options = null) |
| 221 | 221 | { |
| 222 | 222 | if (isset($options['with']) && false === strpos($options['with'], '=')) { |
| 223 | - $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
| 223 | + $options['with'] = '\''.$options['with'].'=\' + value'; |
|
| 224 | 224 | } elseif (isset($options['with']) && isset($options['update'])) { |
| 225 | 225 | $options['with'] = 'value'; |
| 226 | 226 | } |
@@ -228,10 +228,10 @@ discard block |
||
| 228 | 228 | $callback = $options['function'] ?: $this->remote_function($options); |
| 229 | 229 | |
| 230 | 230 | $javascript = "new $klass('$name', "; |
| 231 | - $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
| 231 | + $javascript .= isset($options['frequency']) ? $options['frequency'].', ' : ''; |
|
| 232 | 232 | $javascript .= 'function (element,value) { '; |
| 233 | 233 | $javascript .= $callback; |
| 234 | - $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
| 234 | + $javascript .= isset($options['on']) ? ', '.$options['on'] : ''; |
|
| 235 | 235 | $javascript .= '})'; |
| 236 | 236 | |
| 237 | 237 | return $javascript; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | if (isset($options['position'])) { |
| 266 | - $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
| 266 | + $js_options['insertion'] = 'Insertion.'.ucfirst($options['position']); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | if (isset($options['form'])) { |
| 272 | 272 | $js_options['parameters'] = 'Form.serialize(this)'; |
| 273 | 273 | } elseif (isset($options['parameters'])) { |
| 274 | - $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
| 274 | + $js_options['parameters'] = 'Form.serialize(\''.$options['submit'].'\')'; |
|
| 275 | 275 | } elseif (isset($options['with'])) { |
| 276 | 276 | $js_options['parameters'] = $options['with']; |
| 277 | 277 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function ID($id, $extend = null) |
| 300 | 300 | { |
| 301 | - return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
| 301 | + return "$('$id')".(!empty($extend)) ? '.'.$extend.'()' : ''; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | public function delay($seconds = 1, $script = '') |
| 359 | 359 | { |
| 360 | - return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
| 360 | + return "setTimeout( function() { $script } , ".($seconds * 1000).' )'; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | { |
| 380 | 380 | $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
| 381 | 381 | |
| 382 | - return $this->call('new Insertion.' . ucfirst($position), $args); |
|
| 382 | + return $this->call('new Insertion.'.ucfirst($position), $args); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | public function select($pattern, $extend = null) |
| 445 | 445 | { |
| 446 | - return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
| 446 | + return "$$('$pattern')".(!empty($extend)) ? '.'.$extend : ''; |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @param $javascript |
| 30 | - * @return mixed|string |
|
| 30 | + * @return string |
|
| 31 | 31 | */ |
| 32 | 32 | public function escape($javascript) |
| 33 | 33 | { |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @param $name |
| 51 | - * @param $function |
|
| 51 | + * @param string $function |
|
| 52 | 52 | * @param null $html_options |
| 53 | 53 | * @return string |
| 54 | 54 | */ |
@@ -15,90 +15,90 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class JavaScript |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param $name |
|
| 20 | - * @param null $function |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function button_to_function($name, $function = null) |
|
| 24 | - { |
|
| 25 | - return '<input type="button" value="' . $name . '" onclick="' . $function . '">'; |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * @param $name |
|
| 20 | + * @param null $function |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function button_to_function($name, $function = null) |
|
| 24 | + { |
|
| 25 | + return '<input type="button" value="' . $name . '" onclick="' . $function . '">'; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param $javascript |
|
| 30 | - * @return mixed|string |
|
| 31 | - */ |
|
| 32 | - public function escape($javascript) |
|
| 33 | - { |
|
| 34 | - $javascript = addslashes($javascript); |
|
| 35 | - $javascript = str_replace(array("\r\n", "\n", "\r"), array("\n"), $javascript); |
|
| 28 | + /** |
|
| 29 | + * @param $javascript |
|
| 30 | + * @return mixed|string |
|
| 31 | + */ |
|
| 32 | + public function escape($javascript) |
|
| 33 | + { |
|
| 34 | + $javascript = addslashes($javascript); |
|
| 35 | + $javascript = str_replace(array("\r\n", "\n", "\r"), array("\n"), $javascript); |
|
| 36 | 36 | |
| 37 | - return $javascript; |
|
| 38 | - } |
|
| 37 | + return $javascript; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param $content |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function tag($content) |
|
| 45 | - { |
|
| 46 | - return '<script type="text/javascript">' . $content . '</script>'; |
|
| 47 | - } |
|
| 40 | + /** |
|
| 41 | + * @param $content |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function tag($content) |
|
| 45 | + { |
|
| 46 | + return '<script type="text/javascript">' . $content . '</script>'; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param $name |
|
| 51 | - * @param $function |
|
| 52 | - * @param null $html_options |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - public function link_to_function($name, $function, $html_options = null) |
|
| 56 | - { |
|
| 57 | - return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>'; |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * @param $name |
|
| 51 | + * @param $function |
|
| 52 | + * @param null $html_options |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + public function link_to_function($name, $function, $html_options = null) |
|
| 56 | + { |
|
| 57 | + return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>'; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 61 | - // Private functions |
|
| 62 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 60 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 61 | + // Private functions |
|
| 62 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param $option |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function _array_or_string_for_javascript($option) |
|
| 69 | - { |
|
| 70 | - $return_val = ''; |
|
| 71 | - if (is_array($option)) { |
|
| 72 | - foreach ($option as $value) { |
|
| 73 | - if (!empty($return_val)) { |
|
| 74 | - $ret_val .= ', '; |
|
| 75 | - } |
|
| 76 | - $return_val .= $value; |
|
| 77 | - } |
|
| 64 | + /** |
|
| 65 | + * @param $option |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function _array_or_string_for_javascript($option) |
|
| 69 | + { |
|
| 70 | + $return_val = ''; |
|
| 71 | + if (is_array($option)) { |
|
| 72 | + foreach ($option as $value) { |
|
| 73 | + if (!empty($return_val)) { |
|
| 74 | + $ret_val .= ', '; |
|
| 75 | + } |
|
| 76 | + $return_val .= $value; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return '[' . $return_val . ']'; |
|
| 80 | - } |
|
| 79 | + return '[' . $return_val . ']'; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - return "'$option'"; |
|
| 83 | - } |
|
| 82 | + return "'$option'"; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param $options |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function _options_for_javascript($options) |
|
| 90 | - { |
|
| 91 | - $return_val = ''; |
|
| 85 | + /** |
|
| 86 | + * @param $options |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function _options_for_javascript($options) |
|
| 90 | + { |
|
| 91 | + $return_val = ''; |
|
| 92 | 92 | |
| 93 | - if (is_array($options)) { |
|
| 94 | - foreach ($options as $var => $val) { |
|
| 95 | - if (!empty($return_val)) { |
|
| 96 | - $return_val .= ', '; |
|
| 97 | - } |
|
| 98 | - $return_val .= "$var:$val"; |
|
| 99 | - } |
|
| 100 | - } |
|
| 93 | + if (is_array($options)) { |
|
| 94 | + foreach ($options as $var => $val) { |
|
| 95 | + if (!empty($return_val)) { |
|
| 96 | + $return_val .= ', '; |
|
| 97 | + } |
|
| 98 | + $return_val .= "$var:$val"; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return '{' . $return_val . '}'; |
|
| 103 | - } |
|
| 102 | + return '{' . $return_val . '}'; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function button_to_function($name, $function = null) |
| 24 | 24 | { |
| 25 | - return '<input type="button" value="' . $name . '" onclick="' . $function . '">'; |
|
| 25 | + return '<input type="button" value="'.$name.'" onclick="'.$function.'">'; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function tag($content) |
| 45 | 45 | { |
| 46 | - return '<script type="text/javascript">' . $content . '</script>'; |
|
| 46 | + return '<script type="text/javascript">'.$content.'</script>'; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function link_to_function($name, $function, $html_options = null) |
| 56 | 56 | { |
| 57 | - return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>'; |
|
| 57 | + return '<a href="'.(isset($html_options['href']) ? $html_options['href'] : '#').'" onclick="'.(isset($html_options['onclick']) ? $html_options['onclick'].';' : '').$function.'; return false;">'.$name.'</a>'; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | ///////////////////////////////////////////////////////////////////////////////////// |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $return_val .= $value; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - return '[' . $return_val . ']'; |
|
| 79 | + return '['.$return_val.']'; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return "'$option'"; |
@@ -99,6 +99,6 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - return '{' . $return_val . '}'; |
|
| 102 | + return '{'.$return_val.'}'; |
|
| 103 | 103 | } |
| 104 | 104 | } |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | - * @param $klass |
|
| 215 | + * @param string $klass |
|
| 216 | 216 | * @param $name |
| 217 | 217 | * @param null $options |
| 218 | 218 | * @return string |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
| 314 | - * @param $variable |
|
| 314 | + * @param string $variable |
|
| 315 | 315 | * @param $value |
| 316 | 316 | * @return string |
| 317 | 317 | */ |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
| 324 | - * @param $function |
|
| 324 | + * @param string $function |
|
| 325 | 325 | * @param null $args |
| 326 | 326 | * @return string |
| 327 | 327 | */ |
@@ -15,452 +15,452 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Prototype extends JavaScript |
| 17 | 17 | { |
| 18 | - public $CALLBACKS = array( |
|
| 19 | - 'uninitialized', |
|
| 20 | - 'loading', |
|
| 21 | - 'loaded', |
|
| 22 | - 'interactive', |
|
| 23 | - 'complete', |
|
| 24 | - 'failure', |
|
| 25 | - 'success' |
|
| 26 | - ); |
|
| 27 | - |
|
| 28 | - public $AJAX_OPTIONS = array( |
|
| 29 | - 'before', |
|
| 30 | - 'after', |
|
| 31 | - 'condition', |
|
| 32 | - 'url', |
|
| 33 | - 'asynchronous', |
|
| 34 | - 'method', |
|
| 35 | - 'insertion', |
|
| 36 | - 'position', |
|
| 37 | - 'form', |
|
| 38 | - 'with', |
|
| 39 | - 'update', |
|
| 40 | - 'script', |
|
| 41 | - 'uninitialized', |
|
| 42 | - 'loading', |
|
| 43 | - 'loaded', |
|
| 44 | - 'interactive', |
|
| 45 | - 'complete', |
|
| 46 | - 'failure', |
|
| 47 | - 'success' |
|
| 48 | - ); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function evaluate_remote_response() |
|
| 54 | - { |
|
| 55 | - return 'eval(request.responseText)'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param $options |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function form_remote_tag($options) |
|
| 63 | - { |
|
| 64 | - $options['form'] = true; |
|
| 65 | - |
|
| 66 | - return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param $name |
|
| 71 | - * @param null $options |
|
| 72 | - * @param null $html_options |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - public function link_to_remote($name, $options = null, $html_options = null) |
|
| 76 | - { |
|
| 77 | - return $this->link_to_function($name, $this->remote_function($options), $html_options); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param $field_id |
|
| 82 | - * @param null $options |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function observe_field($field_id, $options = null) |
|
| 86 | - { |
|
| 87 | - if (isset($options['frequency']) && $options['frequency'] > 0) { |
|
| 88 | - return $this->_build_observer('Form.Element.Observer', $field_id, $options); |
|
| 89 | - } else { |
|
| 90 | - return $this->_build_observer('Form.Element.EventObserver', $field_id, $options); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param $form_id |
|
| 96 | - * @param null $options |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function observe_form($form_id, $options = null) |
|
| 100 | - { |
|
| 101 | - if (isset($options['frequency'])) { |
|
| 102 | - return $this->_build_observer('Form.Observer', $form_id, $options); |
|
| 103 | - } else { |
|
| 104 | - return $this->_build_observer('Form.EventObserver', $form_id, $options); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param null $options |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function periodically_call_remote($options = null) |
|
| 113 | - { |
|
| 114 | - $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|
| 115 | - $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
| 116 | - |
|
| 117 | - return $code; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param $options |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public function remote_function($options) |
|
| 125 | - { |
|
| 126 | - $javascript_options = $this->_options_for_ajax($options); |
|
| 127 | - |
|
| 128 | - $update = ''; |
|
| 129 | - |
|
| 130 | - if (isset($options['update']) && is_array($options['update'])) { |
|
| 131 | - $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
| 132 | - $update .= empty($update) ? '' : ','; |
|
| 133 | - $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
| 134 | - } else { |
|
| 135 | - $update .= isset($options['update']) ? $options['update'] : ''; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
| 139 | - |
|
| 140 | - $ajax_function .= "'" . $options['url'] . "'"; |
|
| 141 | - $ajax_function .= ',' . $javascript_options . ')'; |
|
| 142 | - |
|
| 143 | - $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
| 144 | - $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
| 145 | - $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
| 146 | - $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
| 147 | - |
|
| 148 | - return $ajax_function; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param $name |
|
| 153 | - * @param $value |
|
| 154 | - * @param $options |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function submit_to_remote($name, $value, $options) |
|
| 158 | - { |
|
| 159 | - if (isset($options['with'])) { |
|
| 160 | - $options['with'] = 'Form.serialize(this.form)'; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">'; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param $element_id |
|
| 168 | - * @param null $options |
|
| 169 | - * @param $block |
|
| 170 | - */ |
|
| 171 | - public function update_element_function($element_id, $options = null, $block) |
|
| 172 | - { |
|
| 173 | - $content = isset($options['content']) ? $options['content'] : ''; |
|
| 174 | - $content = $this->escape($content); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param $block |
|
| 179 | - */ |
|
| 180 | - public function update_page($block) |
|
| 181 | - { |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param $block |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - public function update_page_tag(& $block) |
|
| 189 | - { |
|
| 190 | - return $this->tag($block); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 194 | - // Private functions |
|
| 195 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param $options |
|
| 199 | - * @return array |
|
| 200 | - */ |
|
| 201 | - public function _build_callbacks($options) |
|
| 202 | - { |
|
| 203 | - $callbacks = array(); |
|
| 204 | - foreach ($options as $callback => $code) { |
|
| 205 | - if (in_array($callback, $this->CALLBACKS)) { |
|
| 206 | - $name = 'on' . ucfirst($callback); |
|
| 207 | - $callbacks[$name] = 'function(request){' . $code . '}'; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return $callbacks; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param $klass |
|
| 216 | - * @param $name |
|
| 217 | - * @param null $options |
|
| 218 | - * @return string |
|
| 219 | - */ |
|
| 220 | - public function _build_observer($klass, $name, $options = null) |
|
| 221 | - { |
|
| 222 | - if (isset($options['with']) && false === strpos($options['with'], '=')) { |
|
| 223 | - $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
| 224 | - } elseif (isset($options['with']) && isset($options['update'])) { |
|
| 225 | - $options['with'] = 'value'; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $callback = $options['function'] ?: $this->remote_function($options); |
|
| 229 | - |
|
| 230 | - $javascript = "new $klass('$name', "; |
|
| 231 | - $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
| 232 | - $javascript .= 'function (element,value) { '; |
|
| 233 | - $javascript .= $callback; |
|
| 234 | - $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
| 235 | - $javascript .= '})'; |
|
| 236 | - |
|
| 237 | - return $javascript; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param $method |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - public function _method_option_to_s($method) |
|
| 245 | - { |
|
| 246 | - return strstr($method, "'") ? $method : "'$method'"; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param $options |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public function _options_for_ajax($options) |
|
| 254 | - { |
|
| 255 | - $js_options = is_array($options) ? $this->_build_callbacks($options) : array(); |
|
| 256 | - |
|
| 257 | - if (isset($options['type']) && $option['type'] === 'synchronous') { |
|
| 258 | - $js_options['asynchronous'] = 'false'; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if (isset($options['method'])) { |
|
| 262 | - $js_options['method'] = $this->_method_option_to_s($options['method']); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if (isset($options['position'])) { |
|
| 266 | - $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
|
| 270 | - |
|
| 271 | - if (isset($options['form'])) { |
|
| 272 | - $js_options['parameters'] = 'Form.serialize(this)'; |
|
| 273 | - } elseif (isset($options['parameters'])) { |
|
| 274 | - $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
| 275 | - } elseif (isset($options['with'])) { |
|
| 276 | - $js_options['parameters'] = $options['with']; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return $this->_options_for_javascript($js_options); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 283 | - // Mergerd Javascript Generator helpers |
|
| 284 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param $javascript |
|
| 288 | - */ |
|
| 289 | - public function dump($javascript) |
|
| 290 | - { |
|
| 291 | - echo $javascript; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @param $id |
|
| 296 | - * @param null $extend |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - public function ID($id, $extend = null) |
|
| 300 | - { |
|
| 301 | - return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param $message |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 308 | - public function alert($message) |
|
| 309 | - { |
|
| 310 | - return $this->call('alert', $message); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @param $variable |
|
| 315 | - * @param $value |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - public function assign($variable, $value) |
|
| 319 | - { |
|
| 320 | - return "$variable = $value;"; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @param $function |
|
| 325 | - * @param null $args |
|
| 326 | - * @return string |
|
| 327 | - */ |
|
| 328 | - public function call($function, $args = null) |
|
| 329 | - { |
|
| 330 | - $arg_str = ''; |
|
| 331 | - if (is_array($args)) { |
|
| 332 | - foreach ($args as $arg) { |
|
| 333 | - if (!empty($arg_str)) { |
|
| 334 | - $arg_str .= ', '; |
|
| 335 | - } |
|
| 336 | - if (is_string($arg)) { |
|
| 337 | - $arg_str .= "'$arg'"; |
|
| 338 | - } else { |
|
| 339 | - $arg_str .= $arg; |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } else { |
|
| 343 | - if (is_string($args)) { |
|
| 344 | - $arg_str .= "'$args'"; |
|
| 345 | - } else { |
|
| 346 | - $arg_str .= $args; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return "$function($arg_str)"; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @param int $seconds |
|
| 355 | - * @param string $script |
|
| 356 | - * @return string |
|
| 357 | - */ |
|
| 358 | - public function delay($seconds = 1, $script = '') |
|
| 359 | - { |
|
| 360 | - return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * @param $id |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 367 | - public function hide($id) |
|
| 368 | - { |
|
| 369 | - return $this->call('Element.hide', $id); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @param $position |
|
| 374 | - * @param $id |
|
| 375 | - * @param null $options_for_render |
|
| 376 | - * @return string |
|
| 377 | - */ |
|
| 378 | - public function insert_html($position, $id, $options_for_render = null) |
|
| 379 | - { |
|
| 380 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 381 | - |
|
| 382 | - return $this->call('new Insertion.' . ucfirst($position), $args); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @param $location |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - public function redirect_to($location) |
|
| 390 | - { |
|
| 391 | - return $this->assign('window.location.href', $location); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * @param $id |
|
| 396 | - * @return string |
|
| 397 | - */ |
|
| 398 | - public function remove($id) |
|
| 399 | - { |
|
| 400 | - if (is_array($id)) { |
|
| 401 | - $arr_str = ''; |
|
| 402 | - foreach ($id as $obj) { |
|
| 403 | - if (!empty($arg_str)) { |
|
| 404 | - $arg_str .= ', '; |
|
| 405 | - } |
|
| 406 | - $arg_str .= "'$arg'"; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return "$A[$arg_str].each(Element.remove)"; |
|
| 410 | - } else { |
|
| 411 | - return "Element.remove('$id')"; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @param $id |
|
| 417 | - * @param $options_for_render |
|
| 418 | - * @return string |
|
| 419 | - */ |
|
| 420 | - public function replace($id, $options_for_render) |
|
| 421 | - { |
|
| 422 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 423 | - |
|
| 424 | - return $this->call('Element.replace', $args); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @param $id |
|
| 429 | - * @param $options_for_render |
|
| 430 | - * @return string |
|
| 431 | - */ |
|
| 432 | - public function replace_html($id, $options_for_render) |
|
| 433 | - { |
|
| 434 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 435 | - |
|
| 436 | - return $this->call('Element.update', $args); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @param $pattern |
|
| 441 | - * @param null $extend |
|
| 442 | - * @return string |
|
| 443 | - */ |
|
| 444 | - public function select($pattern, $extend = null) |
|
| 445 | - { |
|
| 446 | - return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @param $id |
|
| 451 | - * @return string |
|
| 452 | - */ |
|
| 453 | - public function show($id) |
|
| 454 | - { |
|
| 455 | - return $this->call('Element.show', $id); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @param $id |
|
| 460 | - * @return string |
|
| 461 | - */ |
|
| 462 | - public function toggle($id) |
|
| 463 | - { |
|
| 464 | - return $this->call('Element.toggle', $id); |
|
| 465 | - } |
|
| 18 | + public $CALLBACKS = array( |
|
| 19 | + 'uninitialized', |
|
| 20 | + 'loading', |
|
| 21 | + 'loaded', |
|
| 22 | + 'interactive', |
|
| 23 | + 'complete', |
|
| 24 | + 'failure', |
|
| 25 | + 'success' |
|
| 26 | + ); |
|
| 27 | + |
|
| 28 | + public $AJAX_OPTIONS = array( |
|
| 29 | + 'before', |
|
| 30 | + 'after', |
|
| 31 | + 'condition', |
|
| 32 | + 'url', |
|
| 33 | + 'asynchronous', |
|
| 34 | + 'method', |
|
| 35 | + 'insertion', |
|
| 36 | + 'position', |
|
| 37 | + 'form', |
|
| 38 | + 'with', |
|
| 39 | + 'update', |
|
| 40 | + 'script', |
|
| 41 | + 'uninitialized', |
|
| 42 | + 'loading', |
|
| 43 | + 'loaded', |
|
| 44 | + 'interactive', |
|
| 45 | + 'complete', |
|
| 46 | + 'failure', |
|
| 47 | + 'success' |
|
| 48 | + ); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function evaluate_remote_response() |
|
| 54 | + { |
|
| 55 | + return 'eval(request.responseText)'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param $options |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function form_remote_tag($options) |
|
| 63 | + { |
|
| 64 | + $options['form'] = true; |
|
| 65 | + |
|
| 66 | + return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param $name |
|
| 71 | + * @param null $options |
|
| 72 | + * @param null $html_options |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + public function link_to_remote($name, $options = null, $html_options = null) |
|
| 76 | + { |
|
| 77 | + return $this->link_to_function($name, $this->remote_function($options), $html_options); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param $field_id |
|
| 82 | + * @param null $options |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function observe_field($field_id, $options = null) |
|
| 86 | + { |
|
| 87 | + if (isset($options['frequency']) && $options['frequency'] > 0) { |
|
| 88 | + return $this->_build_observer('Form.Element.Observer', $field_id, $options); |
|
| 89 | + } else { |
|
| 90 | + return $this->_build_observer('Form.Element.EventObserver', $field_id, $options); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param $form_id |
|
| 96 | + * @param null $options |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function observe_form($form_id, $options = null) |
|
| 100 | + { |
|
| 101 | + if (isset($options['frequency'])) { |
|
| 102 | + return $this->_build_observer('Form.Observer', $form_id, $options); |
|
| 103 | + } else { |
|
| 104 | + return $this->_build_observer('Form.EventObserver', $form_id, $options); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param null $options |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function periodically_call_remote($options = null) |
|
| 113 | + { |
|
| 114 | + $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|
| 115 | + $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
| 116 | + |
|
| 117 | + return $code; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param $options |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public function remote_function($options) |
|
| 125 | + { |
|
| 126 | + $javascript_options = $this->_options_for_ajax($options); |
|
| 127 | + |
|
| 128 | + $update = ''; |
|
| 129 | + |
|
| 130 | + if (isset($options['update']) && is_array($options['update'])) { |
|
| 131 | + $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
| 132 | + $update .= empty($update) ? '' : ','; |
|
| 133 | + $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
| 134 | + } else { |
|
| 135 | + $update .= isset($options['update']) ? $options['update'] : ''; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
| 139 | + |
|
| 140 | + $ajax_function .= "'" . $options['url'] . "'"; |
|
| 141 | + $ajax_function .= ',' . $javascript_options . ')'; |
|
| 142 | + |
|
| 143 | + $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
| 144 | + $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
| 145 | + $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
| 146 | + $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
| 147 | + |
|
| 148 | + return $ajax_function; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param $name |
|
| 153 | + * @param $value |
|
| 154 | + * @param $options |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function submit_to_remote($name, $value, $options) |
|
| 158 | + { |
|
| 159 | + if (isset($options['with'])) { |
|
| 160 | + $options['with'] = 'Form.serialize(this.form)'; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">'; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param $element_id |
|
| 168 | + * @param null $options |
|
| 169 | + * @param $block |
|
| 170 | + */ |
|
| 171 | + public function update_element_function($element_id, $options = null, $block) |
|
| 172 | + { |
|
| 173 | + $content = isset($options['content']) ? $options['content'] : ''; |
|
| 174 | + $content = $this->escape($content); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param $block |
|
| 179 | + */ |
|
| 180 | + public function update_page($block) |
|
| 181 | + { |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param $block |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + public function update_page_tag(& $block) |
|
| 189 | + { |
|
| 190 | + return $this->tag($block); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 194 | + // Private functions |
|
| 195 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param $options |
|
| 199 | + * @return array |
|
| 200 | + */ |
|
| 201 | + public function _build_callbacks($options) |
|
| 202 | + { |
|
| 203 | + $callbacks = array(); |
|
| 204 | + foreach ($options as $callback => $code) { |
|
| 205 | + if (in_array($callback, $this->CALLBACKS)) { |
|
| 206 | + $name = 'on' . ucfirst($callback); |
|
| 207 | + $callbacks[$name] = 'function(request){' . $code . '}'; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return $callbacks; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param $klass |
|
| 216 | + * @param $name |
|
| 217 | + * @param null $options |
|
| 218 | + * @return string |
|
| 219 | + */ |
|
| 220 | + public function _build_observer($klass, $name, $options = null) |
|
| 221 | + { |
|
| 222 | + if (isset($options['with']) && false === strpos($options['with'], '=')) { |
|
| 223 | + $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
| 224 | + } elseif (isset($options['with']) && isset($options['update'])) { |
|
| 225 | + $options['with'] = 'value'; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $callback = $options['function'] ?: $this->remote_function($options); |
|
| 229 | + |
|
| 230 | + $javascript = "new $klass('$name', "; |
|
| 231 | + $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
| 232 | + $javascript .= 'function (element,value) { '; |
|
| 233 | + $javascript .= $callback; |
|
| 234 | + $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
| 235 | + $javascript .= '})'; |
|
| 236 | + |
|
| 237 | + return $javascript; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param $method |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + public function _method_option_to_s($method) |
|
| 245 | + { |
|
| 246 | + return strstr($method, "'") ? $method : "'$method'"; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param $options |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + public function _options_for_ajax($options) |
|
| 254 | + { |
|
| 255 | + $js_options = is_array($options) ? $this->_build_callbacks($options) : array(); |
|
| 256 | + |
|
| 257 | + if (isset($options['type']) && $option['type'] === 'synchronous') { |
|
| 258 | + $js_options['asynchronous'] = 'false'; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if (isset($options['method'])) { |
|
| 262 | + $js_options['method'] = $this->_method_option_to_s($options['method']); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if (isset($options['position'])) { |
|
| 266 | + $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
|
| 270 | + |
|
| 271 | + if (isset($options['form'])) { |
|
| 272 | + $js_options['parameters'] = 'Form.serialize(this)'; |
|
| 273 | + } elseif (isset($options['parameters'])) { |
|
| 274 | + $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
| 275 | + } elseif (isset($options['with'])) { |
|
| 276 | + $js_options['parameters'] = $options['with']; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return $this->_options_for_javascript($js_options); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 283 | + // Mergerd Javascript Generator helpers |
|
| 284 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param $javascript |
|
| 288 | + */ |
|
| 289 | + public function dump($javascript) |
|
| 290 | + { |
|
| 291 | + echo $javascript; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @param $id |
|
| 296 | + * @param null $extend |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + public function ID($id, $extend = null) |
|
| 300 | + { |
|
| 301 | + return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param $message |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | + public function alert($message) |
|
| 309 | + { |
|
| 310 | + return $this->call('alert', $message); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @param $variable |
|
| 315 | + * @param $value |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + public function assign($variable, $value) |
|
| 319 | + { |
|
| 320 | + return "$variable = $value;"; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @param $function |
|
| 325 | + * @param null $args |
|
| 326 | + * @return string |
|
| 327 | + */ |
|
| 328 | + public function call($function, $args = null) |
|
| 329 | + { |
|
| 330 | + $arg_str = ''; |
|
| 331 | + if (is_array($args)) { |
|
| 332 | + foreach ($args as $arg) { |
|
| 333 | + if (!empty($arg_str)) { |
|
| 334 | + $arg_str .= ', '; |
|
| 335 | + } |
|
| 336 | + if (is_string($arg)) { |
|
| 337 | + $arg_str .= "'$arg'"; |
|
| 338 | + } else { |
|
| 339 | + $arg_str .= $arg; |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } else { |
|
| 343 | + if (is_string($args)) { |
|
| 344 | + $arg_str .= "'$args'"; |
|
| 345 | + } else { |
|
| 346 | + $arg_str .= $args; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return "$function($arg_str)"; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @param int $seconds |
|
| 355 | + * @param string $script |
|
| 356 | + * @return string |
|
| 357 | + */ |
|
| 358 | + public function delay($seconds = 1, $script = '') |
|
| 359 | + { |
|
| 360 | + return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * @param $id |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | + public function hide($id) |
|
| 368 | + { |
|
| 369 | + return $this->call('Element.hide', $id); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @param $position |
|
| 374 | + * @param $id |
|
| 375 | + * @param null $options_for_render |
|
| 376 | + * @return string |
|
| 377 | + */ |
|
| 378 | + public function insert_html($position, $id, $options_for_render = null) |
|
| 379 | + { |
|
| 380 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 381 | + |
|
| 382 | + return $this->call('new Insertion.' . ucfirst($position), $args); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @param $location |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + public function redirect_to($location) |
|
| 390 | + { |
|
| 391 | + return $this->assign('window.location.href', $location); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * @param $id |
|
| 396 | + * @return string |
|
| 397 | + */ |
|
| 398 | + public function remove($id) |
|
| 399 | + { |
|
| 400 | + if (is_array($id)) { |
|
| 401 | + $arr_str = ''; |
|
| 402 | + foreach ($id as $obj) { |
|
| 403 | + if (!empty($arg_str)) { |
|
| 404 | + $arg_str .= ', '; |
|
| 405 | + } |
|
| 406 | + $arg_str .= "'$arg'"; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return "$A[$arg_str].each(Element.remove)"; |
|
| 410 | + } else { |
|
| 411 | + return "Element.remove('$id')"; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @param $id |
|
| 417 | + * @param $options_for_render |
|
| 418 | + * @return string |
|
| 419 | + */ |
|
| 420 | + public function replace($id, $options_for_render) |
|
| 421 | + { |
|
| 422 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 423 | + |
|
| 424 | + return $this->call('Element.replace', $args); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @param $id |
|
| 429 | + * @param $options_for_render |
|
| 430 | + * @return string |
|
| 431 | + */ |
|
| 432 | + public function replace_html($id, $options_for_render) |
|
| 433 | + { |
|
| 434 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
| 435 | + |
|
| 436 | + return $this->call('Element.update', $args); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @param $pattern |
|
| 441 | + * @param null $extend |
|
| 442 | + * @return string |
|
| 443 | + */ |
|
| 444 | + public function select($pattern, $extend = null) |
|
| 445 | + { |
|
| 446 | + return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @param $id |
|
| 451 | + * @return string |
|
| 452 | + */ |
|
| 453 | + public function show($id) |
|
| 454 | + { |
|
| 455 | + return $this->call('Element.show', $id); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @param $id |
|
| 460 | + * @return string |
|
| 461 | + */ |
|
| 462 | + public function toggle($id) |
|
| 463 | + { |
|
| 464 | + return $this->call('Element.toggle', $id); |
|
| 465 | + } |
|
| 466 | 466 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | $options['form'] = true; |
| 65 | 65 | |
| 66 | - return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
| 66 | + return '<form action="'.$options['url'].'" onsubmit="'.$this->remote_function($options).'; return false;" method="'.(isset($options['method']) ? $options['method'] : 'post').'" >'; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | public function periodically_call_remote($options = null) |
| 113 | 113 | { |
| 114 | 114 | $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
| 115 | - $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
| 115 | + $code = 'new PeriodicalExecuter(function() {'.$this->remote_function($options).'},'.$frequency.')'; |
|
| 116 | 116 | |
| 117 | 117 | return $code; |
| 118 | 118 | } |
@@ -128,22 +128,22 @@ discard block |
||
| 128 | 128 | $update = ''; |
| 129 | 129 | |
| 130 | 130 | if (isset($options['update']) && is_array($options['update'])) { |
| 131 | - $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
| 131 | + $update = isset($options['update']['success']) ? 'success: '.$options['update']['success'] : ''; |
|
| 132 | 132 | $update .= empty($update) ? '' : ','; |
| 133 | - $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
| 133 | + $update .= isset($options['update']['failure']) ? 'failure: '.$options['update']['failure'] : ''; |
|
| 134 | 134 | } else { |
| 135 | 135 | $update .= isset($options['update']) ? $options['update'] : ''; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
| 138 | + $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\''.$update.'\','; |
|
| 139 | 139 | |
| 140 | - $ajax_function .= "'" . $options['url'] . "'"; |
|
| 141 | - $ajax_function .= ',' . $javascript_options . ')'; |
|
| 140 | + $ajax_function .= "'".$options['url']."'"; |
|
| 141 | + $ajax_function .= ','.$javascript_options.')'; |
|
| 142 | 142 | |
| 143 | - $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
| 144 | - $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
| 145 | - $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
| 146 | - $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
| 143 | + $ajax_function = isset($options['before']) ? $options['before'].';'.$ajax_function : $ajax_function; |
|
| 144 | + $ajax_function = isset($options['after']) ? $ajax_function.';'.$options['after'] : $ajax_function; |
|
| 145 | + $ajax_function = isset($options['condition']) ? 'if ('.$options['condition'].') {'.$ajax_function.'}' : $ajax_function; |
|
| 146 | + $ajax_function = isset($options['confirm']) ? 'if ( confirm(\''.$options['confirm'].'\' ) ) { '.$ajax_function.' } ' : $ajax_function; |
|
| 147 | 147 | |
| 148 | 148 | return $ajax_function; |
| 149 | 149 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $options['with'] = 'Form.serialize(this.form)'; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">'; |
|
| 163 | + return '<input type="button" onclick="'.$this->remote_function($options).'" name="'.$name.'" value ="'.$value.'">'; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | $callbacks = array(); |
| 204 | 204 | foreach ($options as $callback => $code) { |
| 205 | 205 | if (in_array($callback, $this->CALLBACKS)) { |
| 206 | - $name = 'on' . ucfirst($callback); |
|
| 207 | - $callbacks[$name] = 'function(request){' . $code . '}'; |
|
| 206 | + $name = 'on'.ucfirst($callback); |
|
| 207 | + $callbacks[$name] = 'function(request){'.$code.'}'; |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | public function _build_observer($klass, $name, $options = null) |
| 221 | 221 | { |
| 222 | 222 | if (isset($options['with']) && false === strpos($options['with'], '=')) { |
| 223 | - $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
| 223 | + $options['with'] = '\''.$options['with'].'=\' + value'; |
|
| 224 | 224 | } elseif (isset($options['with']) && isset($options['update'])) { |
| 225 | 225 | $options['with'] = 'value'; |
| 226 | 226 | } |
@@ -228,10 +228,10 @@ discard block |
||
| 228 | 228 | $callback = $options['function'] ?: $this->remote_function($options); |
| 229 | 229 | |
| 230 | 230 | $javascript = "new $klass('$name', "; |
| 231 | - $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
| 231 | + $javascript .= isset($options['frequency']) ? $options['frequency'].', ' : ''; |
|
| 232 | 232 | $javascript .= 'function (element,value) { '; |
| 233 | 233 | $javascript .= $callback; |
| 234 | - $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
| 234 | + $javascript .= isset($options['on']) ? ', '.$options['on'] : ''; |
|
| 235 | 235 | $javascript .= '})'; |
| 236 | 236 | |
| 237 | 237 | return $javascript; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | if (isset($options['position'])) { |
| 266 | - $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
| 266 | + $js_options['insertion'] = 'Insertion.'.ucfirst($options['position']); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | if (isset($options['form'])) { |
| 272 | 272 | $js_options['parameters'] = 'Form.serialize(this)'; |
| 273 | 273 | } elseif (isset($options['parameters'])) { |
| 274 | - $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
| 274 | + $js_options['parameters'] = 'Form.serialize(\''.$options['submit'].'\')'; |
|
| 275 | 275 | } elseif (isset($options['with'])) { |
| 276 | 276 | $js_options['parameters'] = $options['with']; |
| 277 | 277 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function ID($id, $extend = null) |
| 300 | 300 | { |
| 301 | - return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
| 301 | + return "$('$id')".(!empty($extend)) ? '.'.$extend.'()' : ''; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | public function delay($seconds = 1, $script = '') |
| 359 | 359 | { |
| 360 | - return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
| 360 | + return "setTimeout( function() { $script } , ".($seconds * 1000).' )'; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | { |
| 380 | 380 | $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
| 381 | 381 | |
| 382 | - return $this->call('new Insertion.' . ucfirst($position), $args); |
|
| 382 | + return $this->call('new Insertion.'.ucfirst($position), $args); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | public function select($pattern, $extend = null) |
| 445 | 445 | { |
| 446 | - return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
| 446 | + return "$$('$pattern')".(!empty($extend)) ? '.'.$extend : ''; |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -152,11 +152,11 @@ |
||
| 152 | 152 | define('_CO_SOBJECT_UPLOAD_IMAGE', 'Upload a new image:'); |
| 153 | 153 | define('_CO_SOBJECT_VERSION_HISTORY', 'Version History'); |
| 154 | 154 | define('_CO_SOBJECT_WARNING_BETA', |
| 155 | - 'This module comes as is, without any guarantees whatsoever. This module is BETA, meaning it is still under active development. This release is meant for <b>testing purposes only</b> and we <b>strongly</b> recommend that you do not use it on a live website or in a production environment.'); |
|
| 155 | + 'This module comes as is, without any guarantees whatsoever. This module is BETA, meaning it is still under active development. This release is meant for <b>testing purposes only</b> and we <b>strongly</b> recommend that you do not use it on a live website or in a production environment.'); |
|
| 156 | 156 | define('_CO_SOBJECT_WARNING_FINAL', |
| 157 | - 'This module comes as is, without any guarantees whatsoever. Although this module is not beta, it is still under active development. This release can be used in a live website or a production environment, but its use is under your own responsibility, which means the author is not responsible.'); |
|
| 157 | + 'This module comes as is, without any guarantees whatsoever. Although this module is not beta, it is still under active development. This release can be used in a live website or a production environment, but its use is under your own responsibility, which means the author is not responsible.'); |
|
| 158 | 158 | define('_CO_SOBJECT_WARNING_RC', |
| 159 | - 'This module comes as is, without any guarantees whatsoever. This module is a Release Candidate and should not be used on a production web site. The module is still under active development and its use is under your own responsibility, which means the author is not responsible.'); |
|
| 159 | + 'This module comes as is, without any guarantees whatsoever. This module is a Release Candidate and should not be used on a production web site. The module is still under active development and its use is under your own responsibility, which means the author is not responsible.'); |
|
| 160 | 160 | define('_CO_SOBJECT_WEIGHT_FORM_CAPTION', 'Weight'); |
| 161 | 161 | define('_CO_SOBJECT_WEIGHT_FORM_DSC', ''); |
| 162 | 162 | |