@@ -228,7 +228,7 @@ |
||
| 228 | 228 | * Creates a random number with a specified number of $digits |
| 229 | 229 | * |
| 230 | 230 | * @param int $digits number of digits |
| 231 | - * @return int random number |
|
| 231 | + * @return string random number |
|
| 232 | 232 | * @author xHelp Team |
| 233 | 233 | * |
| 234 | 234 | * @access public |
@@ -37,227 +37,227 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class SmartobjectMemberHandler extends \XoopsMemberHandler |
| 39 | 39 | { |
| 40 | - /** |
|
| 41 | - * constructor |
|
| 42 | - * @param \XoopsDatabase $db |
|
| 43 | - */ |
|
| 44 | - public function __construct(\XoopsDatabase $db) |
|
| 45 | - { |
|
| 46 | - parent::__construct($db); |
|
| 47 | - $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * constructor |
|
| 42 | + * @param \XoopsDatabase $db |
|
| 43 | + */ |
|
| 44 | + public function __construct(\XoopsDatabase $db) |
|
| 45 | + { |
|
| 46 | + parent::__construct($db); |
|
| 47 | + $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param $userObj |
|
| 52 | - * @param bool $groups |
|
| 53 | - * @param bool $notifyUser |
|
| 54 | - * @param bool $password |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
| 58 | - { |
|
| 59 | - $email = $userObj->getVar('email'); |
|
| 60 | - if (!$userObj->getVar('email') || '' === $email) { |
|
| 61 | - $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
| 50 | + /** |
|
| 51 | + * @param $userObj |
|
| 52 | + * @param bool $groups |
|
| 53 | + * @param bool $notifyUser |
|
| 54 | + * @param bool $password |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
| 58 | + { |
|
| 59 | + $email = $userObj->getVar('email'); |
|
| 60 | + if (!$userObj->getVar('email') || '' === $email) { |
|
| 61 | + $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
| 62 | 62 | |
| 63 | - return false; |
|
| 64 | - } |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $password = $userObj->getVar('pass'); |
|
| 67 | - // randomly generating the password if not already set |
|
| 68 | - if ('' === $password) { |
|
| 69 | - $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
| 70 | - } |
|
| 71 | - $userObj->setVar('pass', md5($password)); |
|
| 66 | + $password = $userObj->getVar('pass'); |
|
| 67 | + // randomly generating the password if not already set |
|
| 68 | + if ('' === $password) { |
|
| 69 | + $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
| 70 | + } |
|
| 71 | + $userObj->setVar('pass', md5($password)); |
|
| 72 | 72 | |
| 73 | - // if no username is set, let's generate one |
|
| 74 | - $unamecount = 20; |
|
| 75 | - $uname = $userObj->getVar('uname'); |
|
| 76 | - if (!$uname || '' === $uname) { |
|
| 77 | - $usernames = $this->genUserNames($email, $unamecount); |
|
| 78 | - $newuser = false; |
|
| 79 | - $i = 0; |
|
| 80 | - while (false === $newuser) { |
|
| 81 | - $crit = new \Criteria('uname', $usernames[$i]); |
|
| 82 | - $count = $this->getUserCount($crit); |
|
| 83 | - if (0 == $count) { |
|
| 84 | - $newuser = true; |
|
| 85 | - } else { |
|
| 86 | - //Move to next username |
|
| 87 | - ++$i; |
|
| 88 | - if ($i == $unamecount) { |
|
| 89 | - //Get next batch of usernames to try, reset counter |
|
| 90 | - $usernames = $this->genUserNames($email, $unamecount); |
|
| 91 | - $i = 0; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 73 | + // if no username is set, let's generate one |
|
| 74 | + $unamecount = 20; |
|
| 75 | + $uname = $userObj->getVar('uname'); |
|
| 76 | + if (!$uname || '' === $uname) { |
|
| 77 | + $usernames = $this->genUserNames($email, $unamecount); |
|
| 78 | + $newuser = false; |
|
| 79 | + $i = 0; |
|
| 80 | + while (false === $newuser) { |
|
| 81 | + $crit = new \Criteria('uname', $usernames[$i]); |
|
| 82 | + $count = $this->getUserCount($crit); |
|
| 83 | + if (0 == $count) { |
|
| 84 | + $newuser = true; |
|
| 85 | + } else { |
|
| 86 | + //Move to next username |
|
| 87 | + ++$i; |
|
| 88 | + if ($i == $unamecount) { |
|
| 89 | + //Get next batch of usernames to try, reset counter |
|
| 90 | + $usernames = $this->genUserNames($email, $unamecount); |
|
| 91 | + $i = 0; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - global $xoopsConfig; |
|
| 97 | + global $xoopsConfig; |
|
| 98 | 98 | |
| 99 | - $configHandler = xoops_getHandler('config'); |
|
| 100 | - $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
| 101 | - switch ($xoopsConfigUser['activation_type']) { |
|
| 102 | - case 0: |
|
| 103 | - $level = 0; |
|
| 104 | - $mailtemplate = 'smartmail_activate_user.tpl'; |
|
| 105 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
| 106 | - break; |
|
| 107 | - case 1: |
|
| 108 | - $level = 1; |
|
| 109 | - $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
| 110 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
| 111 | - break; |
|
| 112 | - case 2: |
|
| 113 | - default: |
|
| 114 | - $level = 0; |
|
| 115 | - $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
| 116 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
| 117 | - } |
|
| 99 | + $configHandler = xoops_getHandler('config'); |
|
| 100 | + $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
| 101 | + switch ($xoopsConfigUser['activation_type']) { |
|
| 102 | + case 0: |
|
| 103 | + $level = 0; |
|
| 104 | + $mailtemplate = 'smartmail_activate_user.tpl'; |
|
| 105 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
| 106 | + break; |
|
| 107 | + case 1: |
|
| 108 | + $level = 1; |
|
| 109 | + $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
| 110 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
| 111 | + break; |
|
| 112 | + case 2: |
|
| 113 | + default: |
|
| 114 | + $level = 0; |
|
| 115 | + $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
| 116 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $userObj->setVar('uname', $usernames[$i]); |
|
| 120 | - $userObj->setVar('user_avatar', 'blank.gif'); |
|
| 121 | - $userObj->setVar('user_regdate', time()); |
|
| 122 | - $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
| 123 | - $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
| 124 | - $userObj->setVar('actkey', $actkey); |
|
| 125 | - $userObj->setVar('email', $email); |
|
| 126 | - $userObj->setVar('notify_method', 2); |
|
| 127 | - $userObj->setVar('level', $userObj); |
|
| 119 | + $userObj->setVar('uname', $usernames[$i]); |
|
| 120 | + $userObj->setVar('user_avatar', 'blank.gif'); |
|
| 121 | + $userObj->setVar('user_regdate', time()); |
|
| 122 | + $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
| 123 | + $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
| 124 | + $userObj->setVar('actkey', $actkey); |
|
| 125 | + $userObj->setVar('email', $email); |
|
| 126 | + $userObj->setVar('notify_method', 2); |
|
| 127 | + $userObj->setVar('level', $userObj); |
|
| 128 | 128 | |
| 129 | - if ($this->insertUser($userObj)) { |
|
| 129 | + if ($this->insertUser($userObj)) { |
|
| 130 | 130 | |
| 131 | - // if $groups=false, Add the user to Registered Users group |
|
| 132 | - if (!$groups) { |
|
| 133 | - $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
| 134 | - } else { |
|
| 135 | - foreach ($groups as $groupid) { |
|
| 136 | - $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - } else { |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 131 | + // if $groups=false, Add the user to Registered Users group |
|
| 132 | + if (!$groups) { |
|
| 133 | + $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
| 134 | + } else { |
|
| 135 | + foreach ($groups as $groupid) { |
|
| 136 | + $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if ($notifyUser) { |
|
| 144 | - // send some notifications |
|
| 145 | - $xoopsMailer = xoops_getMailer(); |
|
| 146 | - $xoopsMailer->useMail(); |
|
| 147 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 148 | - $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
| 149 | - $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
| 150 | - $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
| 151 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
| 152 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 153 | - $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
| 154 | - $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
| 155 | - $xoopsMailer->setToUsers($userObj); |
|
| 156 | - $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
| 157 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
| 158 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
| 143 | + if ($notifyUser) { |
|
| 144 | + // send some notifications |
|
| 145 | + $xoopsMailer = xoops_getMailer(); |
|
| 146 | + $xoopsMailer->useMail(); |
|
| 147 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 148 | + $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
| 149 | + $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
| 150 | + $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
| 151 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
| 152 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 153 | + $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
| 154 | + $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
| 155 | + $xoopsMailer->setToUsers($userObj); |
|
| 156 | + $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
| 157 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
| 158 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
| 159 | 159 | |
| 160 | - if (!$xoopsMailer->send(true)) { |
|
| 161 | - /** |
|
| 162 | - * @todo trap error if email was not sent |
|
| 163 | - */ |
|
| 164 | - $xoopsMailer->getErrors(true); |
|
| 165 | - } |
|
| 166 | - } |
|
| 160 | + if (!$xoopsMailer->send(true)) { |
|
| 161 | + /** |
|
| 162 | + * @todo trap error if email was not sent |
|
| 163 | + */ |
|
| 164 | + $xoopsMailer->getErrors(true); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - return true; |
|
| 169 | - } |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Generates an array of usernames |
|
| 173 | - * |
|
| 174 | - * @param string $email email of user |
|
| 175 | - * @param int $count number of names to generate |
|
| 176 | - * @return array $names |
|
| 177 | - * @internal param string $name name of user |
|
| 178 | - * @author xHelp Team |
|
| 179 | - * |
|
| 180 | - * @access public |
|
| 181 | - */ |
|
| 182 | - public function genUserNames($email, $count = 20) |
|
| 183 | - { |
|
| 184 | - $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
| 171 | + /** |
|
| 172 | + * Generates an array of usernames |
|
| 173 | + * |
|
| 174 | + * @param string $email email of user |
|
| 175 | + * @param int $count number of names to generate |
|
| 176 | + * @return array $names |
|
| 177 | + * @internal param string $name name of user |
|
| 178 | + * @author xHelp Team |
|
| 179 | + * |
|
| 180 | + * @access public |
|
| 181 | + */ |
|
| 182 | + public function genUserNames($email, $count = 20) |
|
| 183 | + { |
|
| 184 | + $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
| 185 | 185 | |
| 186 | - $names = []; |
|
| 187 | - $userid = explode('@', $email); |
|
| 186 | + $names = []; |
|
| 187 | + $userid = explode('@', $email); |
|
| 188 | 188 | |
| 189 | - $basename = ''; |
|
| 190 | - $hasbasename = false; |
|
| 191 | - $emailname = $userid[0]; |
|
| 189 | + $basename = ''; |
|
| 190 | + $hasbasename = false; |
|
| 191 | + $emailname = $userid[0]; |
|
| 192 | 192 | |
| 193 | - $names[] = $emailname; |
|
| 193 | + $names[] = $emailname; |
|
| 194 | 194 | |
| 195 | - if (strlen($name) > 0) { |
|
| 196 | - $name = explode(' ', trim($name)); |
|
| 197 | - if (count($name) > 1) { |
|
| 198 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 199 | - } else { |
|
| 200 | - $basename = strtolower($name[0]); |
|
| 201 | - } |
|
| 202 | - $basename = xoops_substr($basename, 0, 60, ''); |
|
| 203 | - //Prevent Duplication of Email Username and Name |
|
| 204 | - if (!in_array($basename, $names)) { |
|
| 205 | - $names[] = $basename; |
|
| 206 | - $hasbasename = true; |
|
| 207 | - } |
|
| 208 | - } |
|
| 195 | + if (strlen($name) > 0) { |
|
| 196 | + $name = explode(' ', trim($name)); |
|
| 197 | + if (count($name) > 1) { |
|
| 198 | + $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 199 | + } else { |
|
| 200 | + $basename = strtolower($name[0]); |
|
| 201 | + } |
|
| 202 | + $basename = xoops_substr($basename, 0, 60, ''); |
|
| 203 | + //Prevent Duplication of Email Username and Name |
|
| 204 | + if (!in_array($basename, $names)) { |
|
| 205 | + $names[] = $basename; |
|
| 206 | + $hasbasename = true; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - $i = count($names); |
|
| 211 | - $onbasename = 1; |
|
| 212 | - while ($i < $count) { |
|
| 213 | - $num = $this->genRandNumber(); |
|
| 214 | - if ($onbasename < 0 && $hasbasename) { |
|
| 215 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 216 | - } else { |
|
| 217 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 218 | - } |
|
| 219 | - $i = count($names); |
|
| 220 | - $onbasename = ~$onbasename; |
|
| 221 | - $num = ''; |
|
| 222 | - } |
|
| 210 | + $i = count($names); |
|
| 211 | + $onbasename = 1; |
|
| 212 | + while ($i < $count) { |
|
| 213 | + $num = $this->genRandNumber(); |
|
| 214 | + if ($onbasename < 0 && $hasbasename) { |
|
| 215 | + $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 216 | + } else { |
|
| 217 | + $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 218 | + } |
|
| 219 | + $i = count($names); |
|
| 220 | + $onbasename = ~$onbasename; |
|
| 221 | + $num = ''; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - return $names; |
|
| 225 | - } |
|
| 224 | + return $names; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Creates a random number with a specified number of $digits |
|
| 229 | - * |
|
| 230 | - * @param int $digits number of digits |
|
| 231 | - * @return int random number |
|
| 232 | - * @author xHelp Team |
|
| 233 | - * |
|
| 234 | - * @access public |
|
| 235 | - */ |
|
| 236 | - public function genRandNumber($digits = 2) |
|
| 237 | - { |
|
| 238 | - $this->initRand(); |
|
| 239 | - $tmp = []; |
|
| 227 | + /** |
|
| 228 | + * Creates a random number with a specified number of $digits |
|
| 229 | + * |
|
| 230 | + * @param int $digits number of digits |
|
| 231 | + * @return int random number |
|
| 232 | + * @author xHelp Team |
|
| 233 | + * |
|
| 234 | + * @access public |
|
| 235 | + */ |
|
| 236 | + public function genRandNumber($digits = 2) |
|
| 237 | + { |
|
| 238 | + $this->initRand(); |
|
| 239 | + $tmp = []; |
|
| 240 | 240 | |
| 241 | - for ($i = 0; $i < $digits; ++$i) { |
|
| 242 | - $tmp[$i] = (mt_rand() % 9); |
|
| 243 | - } |
|
| 241 | + for ($i = 0; $i < $digits; ++$i) { |
|
| 242 | + $tmp[$i] = (mt_rand() % 9); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return implode('', $tmp); |
|
| 246 | - } |
|
| 245 | + return implode('', $tmp); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Gives the random number generator a seed to start from |
|
| 250 | - * |
|
| 251 | - * @return void |
|
| 252 | - * |
|
| 253 | - * @access public |
|
| 254 | - */ |
|
| 255 | - public function initRand() |
|
| 256 | - { |
|
| 257 | - static $randCalled = false; |
|
| 258 | - if (!$randCalled) { |
|
| 259 | - mt_srand((double)microtime() * 1000000); |
|
| 260 | - $randCalled = true; |
|
| 261 | - } |
|
| 262 | - } |
|
| 248 | + /** |
|
| 249 | + * Gives the random number generator a seed to start from |
|
| 250 | + * |
|
| 251 | + * @return void |
|
| 252 | + * |
|
| 253 | + * @access public |
|
| 254 | + */ |
|
| 255 | + public function initRand() |
|
| 256 | + { |
|
| 257 | + static $randCalled = false; |
|
| 258 | + if (!$randCalled) { |
|
| 259 | + mt_srand((double)microtime() * 1000000); |
|
| 260 | + $randCalled = true; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | 263 | } |
@@ -21,9 +21,9 @@ discard block |
||
| 21 | 21 | use XoopsModules\Smartobject; |
| 22 | 22 | |
| 23 | 23 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
| 24 | -require_once XOOPS_ROOT_PATH . '/kernel/user.php'; |
|
| 25 | -require_once XOOPS_ROOT_PATH . '/kernel/group.php'; |
|
| 26 | -require_once XOOPS_ROOT_PATH . '/kernel/member.php'; |
|
| 24 | +require_once XOOPS_ROOT_PATH.'/kernel/user.php'; |
|
| 25 | +require_once XOOPS_ROOT_PATH.'/kernel/group.php'; |
|
| 26 | +require_once XOOPS_ROOT_PATH.'/kernel/member.php'; |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * XOOPS member handler class. |
@@ -144,12 +144,12 @@ discard block |
||
| 144 | 144 | // send some notifications |
| 145 | 145 | $xoopsMailer = xoops_getMailer(); |
| 146 | 146 | $xoopsMailer->useMail(); |
| 147 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 147 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/mail_template'); |
|
| 148 | 148 | $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
| 149 | 149 | $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
| 150 | 150 | $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
| 151 | 151 | $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
| 152 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 152 | + $xoopsMailer->assign('SITEURL', XOOPS_URL.'/'); |
|
| 153 | 153 | $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
| 154 | 154 | $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
| 155 | 155 | $xoopsMailer->setToUsers($userObj); |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | if (strlen($name) > 0) { |
| 196 | 196 | $name = explode(' ', trim($name)); |
| 197 | 197 | if (count($name) > 1) { |
| 198 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 198 | + $basename = strtolower(substr($name[0], 0, 1).$name[count($name) - 1]); |
|
| 199 | 199 | } else { |
| 200 | 200 | $basename = strtolower($name[0]); |
| 201 | 201 | } |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | while ($i < $count) { |
| 213 | 213 | $num = $this->genRandNumber(); |
| 214 | 214 | if ($onbasename < 0 && $hasbasename) { |
| 215 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 215 | + $names[] = xoops_substr($basename, 0, 58, '').$num; |
|
| 216 | 216 | } else { |
| 217 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 217 | + $names[] = xoops_substr($emailname, 0, 58, '').$num; |
|
| 218 | 218 | } |
| 219 | 219 | $i = count($names); |
| 220 | 220 | $onbasename = ~$onbasename; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | { |
| 257 | 257 | static $randCalled = false; |
| 258 | 258 | if (!$randCalled) { |
| 259 | - mt_srand((double)microtime() * 1000000); |
|
| 259 | + mt_srand((double) microtime() * 1000000); |
|
| 260 | 260 | $randCalled = true; |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | /** |
| 34 | 34 | * @param $gperm_name |
| 35 | - * @param null $id |
|
| 35 | + * @param integer $id |
|
| 36 | 36 | * @return array |
| 37 | 37 | */ |
| 38 | 38 | public function getGrantedGroups($gperm_name, $id = null) |
@@ -19,18 +19,18 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class SmartobjectPermissionHandler extends \XoopsObjectHandler |
| 21 | 21 | { |
| 22 | - public $handler; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * SmartobjectPermissionHandler constructor. |
|
| 26 | - * @param \XoopsDatabase $handler |
|
| 27 | - */ |
|
| 28 | - public function __construct($handler) |
|
| 29 | - { |
|
| 30 | - $this->handler = $handler; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /* |
|
| 22 | + public $handler; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * SmartobjectPermissionHandler constructor. |
|
| 26 | + * @param \XoopsDatabase $handler |
|
| 27 | + */ |
|
| 28 | + public function __construct($handler) |
|
| 29 | + { |
|
| 30 | + $this->handler = $handler; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /* |
|
| 34 | 34 | * Returns permissions for a certain type |
| 35 | 35 | * |
| 36 | 36 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -38,74 +38,74 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | - /** |
|
| 42 | - * @param $gperm_name |
|
| 43 | - * @param null $id |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function getGrantedGroups($gperm_name, $id = null) |
|
| 47 | - { |
|
| 48 | - static $groups; |
|
| 49 | - |
|
| 50 | - if (!isset($groups[$gperm_name]) || (null !== $id && !isset($groups[$gperm_name][$id]))) { |
|
| 51 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 52 | - //Get group permissions handler |
|
| 53 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 54 | - |
|
| 55 | - //Get groups allowed for an item id |
|
| 56 | - $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 57 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - //Return the permission array |
|
| 61 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param $item_ids_array |
|
| 66 | - * @param bool $gperm_name |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 70 | - { |
|
| 71 | - static $groups; |
|
| 72 | - |
|
| 73 | - if ($gperm_name) { |
|
| 74 | - if (isset($groups[$gperm_name])) { |
|
| 75 | - return $groups[$gperm_name]; |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 79 | - return $groups; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 83 | - |
|
| 84 | - $criteria = new \CriteriaCompo(); |
|
| 85 | - $criteria->add(new \Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 86 | - |
|
| 87 | - if ($gperm_name) { |
|
| 88 | - $criteria->add(new \Criteria('gperm_name', $gperm_name)); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - //Get group permissions handler |
|
| 92 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 93 | - |
|
| 94 | - $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 95 | - |
|
| 96 | - foreach ($permissionsObj as $permissionObj) { |
|
| 97 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - //Return the permission array |
|
| 101 | - if ($gperm_name) { |
|
| 102 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
| 103 | - } else { |
|
| 104 | - return isset($groups) ? $groups : []; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /* |
|
| 41 | + /** |
|
| 42 | + * @param $gperm_name |
|
| 43 | + * @param null $id |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function getGrantedGroups($gperm_name, $id = null) |
|
| 47 | + { |
|
| 48 | + static $groups; |
|
| 49 | + |
|
| 50 | + if (!isset($groups[$gperm_name]) || (null !== $id && !isset($groups[$gperm_name][$id]))) { |
|
| 51 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 52 | + //Get group permissions handler |
|
| 53 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 54 | + |
|
| 55 | + //Get groups allowed for an item id |
|
| 56 | + $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 57 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + //Return the permission array |
|
| 61 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param $item_ids_array |
|
| 66 | + * @param bool $gperm_name |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 70 | + { |
|
| 71 | + static $groups; |
|
| 72 | + |
|
| 73 | + if ($gperm_name) { |
|
| 74 | + if (isset($groups[$gperm_name])) { |
|
| 75 | + return $groups[$gperm_name]; |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 79 | + return $groups; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 83 | + |
|
| 84 | + $criteria = new \CriteriaCompo(); |
|
| 85 | + $criteria->add(new \Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 86 | + |
|
| 87 | + if ($gperm_name) { |
|
| 88 | + $criteria->add(new \Criteria('gperm_name', $gperm_name)); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + //Get group permissions handler |
|
| 92 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 93 | + |
|
| 94 | + $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 95 | + |
|
| 96 | + foreach ($permissionsObj as $permissionObj) { |
|
| 97 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + //Return the permission array |
|
| 101 | + if ($gperm_name) { |
|
| 102 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
| 103 | + } else { |
|
| 104 | + return isset($groups) ? $groups : []; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /* |
|
| 109 | 109 | * Returns permissions for a certain type |
| 110 | 110 | * |
| 111 | 111 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -113,123 +113,123 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return array |
| 115 | 115 | */ |
| 116 | - /** |
|
| 117 | - * @param $gperm_name |
|
| 118 | - * @param null $id |
|
| 119 | - * @return array |
|
| 120 | - */ |
|
| 121 | - public function getGrantedItems($gperm_name, $id = null) |
|
| 122 | - { |
|
| 123 | - global $xoopsUser; |
|
| 124 | - static $permissions; |
|
| 125 | - |
|
| 126 | - if (!isset($permissions[$gperm_name]) || (null !== $id && !isset($permissions[$gperm_name][$id]))) { |
|
| 127 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 128 | - |
|
| 129 | - if (is_object($smartModule)) { |
|
| 130 | - |
|
| 131 | - //Get group permissions handler |
|
| 132 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 133 | - |
|
| 134 | - //Get user's groups |
|
| 135 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 136 | - |
|
| 137 | - //Get all allowed item ids in this module and for this user's groups |
|
| 138 | - $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 139 | - $permissions[$gperm_name] = $userpermissions; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - //Return the permission array |
|
| 144 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param $id |
|
| 149 | - */ |
|
| 150 | - public function storeAllPermissionsForId($id) |
|
| 151 | - { |
|
| 152 | - foreach ($this->handler->getPermissions() as $permission) { |
|
| 153 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Saves permissions for the selected item |
|
| 159 | - * |
|
| 160 | - * saveItem_Permissions() |
|
| 161 | - * |
|
| 162 | - * @param array $groups : group with granted permission |
|
| 163 | - * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
| 164 | - * @param string $perm_name : name of the permission |
|
| 165 | - * @return bool : TRUE if the no errors occured |
|
| 166 | - */ |
|
| 167 | - |
|
| 168 | - public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 169 | - { |
|
| 170 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 171 | - |
|
| 172 | - $result = true; |
|
| 173 | - $module_id = $smartModule->getVar('mid'); |
|
| 174 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 175 | - |
|
| 176 | - // First, if the permissions are already there, delete them |
|
| 177 | - $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 178 | - //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 179 | - //exit; |
|
| 180 | - // Save the new permissions |
|
| 181 | - |
|
| 182 | - if (count($groups) > 0) { |
|
| 183 | - foreach ($groups as $group_id) { |
|
| 184 | - $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $result; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Delete all permission for a specific item |
|
| 193 | - * |
|
| 194 | - * deletePermissions() |
|
| 195 | - * |
|
| 196 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
| 197 | - * @param $gperm_name |
|
| 198 | - * @return bool: TRUE if the no errors occured |
|
| 199 | - */ |
|
| 200 | - public function deletePermissions($itemid, $gperm_name) |
|
| 201 | - { |
|
| 202 | - global $xoopsModule; |
|
| 203 | - |
|
| 204 | - $smartModule = smartsection_getModuleInfo(); |
|
| 205 | - |
|
| 206 | - $result = true; |
|
| 207 | - $module_id = $smartModule->getVar('mid'); |
|
| 208 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 209 | - |
|
| 210 | - $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 211 | - |
|
| 212 | - return $result; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Checks if the user has access to a specific permission on a given object |
|
| 217 | - * |
|
| 218 | - * @param string $gperm_name name of the permission to test |
|
| 219 | - * @param int $gperm_itemid id of the object to check |
|
| 220 | - * @return boolean: TRUE if user has access, FALSE if not |
|
| 221 | - **/ |
|
| 222 | - public function accessGranted($gperm_name, $gperm_itemid) |
|
| 223 | - { |
|
| 224 | - global $xoopsUser; |
|
| 225 | - |
|
| 226 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 227 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 228 | - $gperm_modid = $smartModule->getVar('mid'); |
|
| 229 | - |
|
| 230 | - //Get group permissions handler |
|
| 231 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 232 | - |
|
| 233 | - return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 234 | - } |
|
| 116 | + /** |
|
| 117 | + * @param $gperm_name |
|
| 118 | + * @param null $id |
|
| 119 | + * @return array |
|
| 120 | + */ |
|
| 121 | + public function getGrantedItems($gperm_name, $id = null) |
|
| 122 | + { |
|
| 123 | + global $xoopsUser; |
|
| 124 | + static $permissions; |
|
| 125 | + |
|
| 126 | + if (!isset($permissions[$gperm_name]) || (null !== $id && !isset($permissions[$gperm_name][$id]))) { |
|
| 127 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 128 | + |
|
| 129 | + if (is_object($smartModule)) { |
|
| 130 | + |
|
| 131 | + //Get group permissions handler |
|
| 132 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 133 | + |
|
| 134 | + //Get user's groups |
|
| 135 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 136 | + |
|
| 137 | + //Get all allowed item ids in this module and for this user's groups |
|
| 138 | + $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 139 | + $permissions[$gperm_name] = $userpermissions; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + //Return the permission array |
|
| 144 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param $id |
|
| 149 | + */ |
|
| 150 | + public function storeAllPermissionsForId($id) |
|
| 151 | + { |
|
| 152 | + foreach ($this->handler->getPermissions() as $permission) { |
|
| 153 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Saves permissions for the selected item |
|
| 159 | + * |
|
| 160 | + * saveItem_Permissions() |
|
| 161 | + * |
|
| 162 | + * @param array $groups : group with granted permission |
|
| 163 | + * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
| 164 | + * @param string $perm_name : name of the permission |
|
| 165 | + * @return bool : TRUE if the no errors occured |
|
| 166 | + */ |
|
| 167 | + |
|
| 168 | + public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 169 | + { |
|
| 170 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 171 | + |
|
| 172 | + $result = true; |
|
| 173 | + $module_id = $smartModule->getVar('mid'); |
|
| 174 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 175 | + |
|
| 176 | + // First, if the permissions are already there, delete them |
|
| 177 | + $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 178 | + //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 179 | + //exit; |
|
| 180 | + // Save the new permissions |
|
| 181 | + |
|
| 182 | + if (count($groups) > 0) { |
|
| 183 | + foreach ($groups as $group_id) { |
|
| 184 | + $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $result; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Delete all permission for a specific item |
|
| 193 | + * |
|
| 194 | + * deletePermissions() |
|
| 195 | + * |
|
| 196 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
| 197 | + * @param $gperm_name |
|
| 198 | + * @return bool: TRUE if the no errors occured |
|
| 199 | + */ |
|
| 200 | + public function deletePermissions($itemid, $gperm_name) |
|
| 201 | + { |
|
| 202 | + global $xoopsModule; |
|
| 203 | + |
|
| 204 | + $smartModule = smartsection_getModuleInfo(); |
|
| 205 | + |
|
| 206 | + $result = true; |
|
| 207 | + $module_id = $smartModule->getVar('mid'); |
|
| 208 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 209 | + |
|
| 210 | + $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 211 | + |
|
| 212 | + return $result; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Checks if the user has access to a specific permission on a given object |
|
| 217 | + * |
|
| 218 | + * @param string $gperm_name name of the permission to test |
|
| 219 | + * @param int $gperm_itemid id of the object to check |
|
| 220 | + * @return boolean: TRUE if user has access, FALSE if not |
|
| 221 | + **/ |
|
| 222 | + public function accessGranted($gperm_name, $gperm_itemid) |
|
| 223 | + { |
|
| 224 | + global $xoopsUser; |
|
| 225 | + |
|
| 226 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 227 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 228 | + $gperm_modid = $smartModule->getVar('mid'); |
|
| 229 | + |
|
| 230 | + //Get group permissions handler |
|
| 231 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 232 | + |
|
| 233 | + return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Constructor |
| 35 | - * @param $object |
|
| 35 | + * @param BaseSmartObject $object |
|
| 36 | 36 | * @param bool $userSide |
| 37 | 37 | * @param array $actions |
| 38 | 38 | * @param bool $headerAsRow |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * @param $rowObj |
|
| 49 | + * @param SmartObjectRow $rowObj |
|
| 50 | 50 | */ |
| 51 | 51 | public function addRow($rowObj) |
| 52 | 52 | { |
@@ -23,94 +23,94 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class SmartObjectSingleView |
| 25 | 25 | { |
| 26 | - public $_object; |
|
| 27 | - public $_userSide; |
|
| 28 | - public $_tpl; |
|
| 29 | - public $_rows; |
|
| 30 | - public $_actions; |
|
| 31 | - public $_headerAsRow = true; |
|
| 26 | + public $_object; |
|
| 27 | + public $_userSide; |
|
| 28 | + public $_tpl; |
|
| 29 | + public $_rows; |
|
| 30 | + public $_actions; |
|
| 31 | + public $_headerAsRow = true; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor |
|
| 35 | - * @param $object |
|
| 36 | - * @param bool $userSide |
|
| 37 | - * @param array $actions |
|
| 38 | - * @param bool $headerAsRow |
|
| 39 | - */ |
|
| 40 | - public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
| 41 | - { |
|
| 42 | - $this->_object = $object; |
|
| 43 | - $this->_userSide = $userSide; |
|
| 44 | - $this->_actions = $actions; |
|
| 45 | - $this->_headerAsRow = $headerAsRow; |
|
| 46 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor |
|
| 35 | + * @param $object |
|
| 36 | + * @param bool $userSide |
|
| 37 | + * @param array $actions |
|
| 38 | + * @param bool $headerAsRow |
|
| 39 | + */ |
|
| 40 | + public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
| 41 | + { |
|
| 42 | + $this->_object = $object; |
|
| 43 | + $this->_userSide = $userSide; |
|
| 44 | + $this->_actions = $actions; |
|
| 45 | + $this->_headerAsRow = $headerAsRow; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param $rowObj |
|
| 50 | - */ |
|
| 51 | - public function addRow($rowObj) |
|
| 52 | - { |
|
| 53 | - $this->_rows[] = $rowObj; |
|
| 54 | - } |
|
| 48 | + /** |
|
| 49 | + * @param $rowObj |
|
| 50 | + */ |
|
| 51 | + public function addRow($rowObj) |
|
| 52 | + { |
|
| 53 | + $this->_rows[] = $rowObj; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param bool $fetchOnly |
|
| 58 | - * @param bool $debug |
|
| 59 | - * @return mixed|string|void |
|
| 60 | - */ |
|
| 61 | - public function render($fetchOnly = false, $debug = false) |
|
| 62 | - { |
|
| 63 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 56 | + /** |
|
| 57 | + * @param bool $fetchOnly |
|
| 58 | + * @param bool $debug |
|
| 59 | + * @return mixed|string|void |
|
| 60 | + */ |
|
| 61 | + public function render($fetchOnly = false, $debug = false) |
|
| 62 | + { |
|
| 63 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 64 | 64 | |
| 65 | - $this->_tpl = new \XoopsTpl(); |
|
| 66 | - $vars = $this->_object->vars; |
|
| 67 | - $smartobjectObjectArray = []; |
|
| 65 | + $this->_tpl = new \XoopsTpl(); |
|
| 66 | + $vars = $this->_object->vars; |
|
| 67 | + $smartobjectObjectArray = []; |
|
| 68 | 68 | |
| 69 | - foreach ($this->_rows as $row) { |
|
| 70 | - $key = $row->getKeyName(); |
|
| 71 | - if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
| 72 | - $method = $row->_customMethodForValue; |
|
| 73 | - $value = $this->_object->$method(); |
|
| 74 | - } else { |
|
| 75 | - $value = $this->_object->getVar($row->getKeyName()); |
|
| 76 | - } |
|
| 77 | - if ($row->isHeader()) { |
|
| 78 | - $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
| 79 | - $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
| 80 | - } else { |
|
| 81 | - $smartobjectObjectArray[$key]['value'] = $value; |
|
| 82 | - $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
| 83 | - $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - $action_row = ''; |
|
| 87 | - if (in_array('edit', $this->_actions)) { |
|
| 88 | - $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
| 89 | - } |
|
| 90 | - if (in_array('delete', $this->_actions)) { |
|
| 91 | - $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
| 92 | - } |
|
| 93 | - if ($action_row) { |
|
| 94 | - $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
| 95 | - $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
| 96 | - } |
|
| 69 | + foreach ($this->_rows as $row) { |
|
| 70 | + $key = $row->getKeyName(); |
|
| 71 | + if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
| 72 | + $method = $row->_customMethodForValue; |
|
| 73 | + $value = $this->_object->$method(); |
|
| 74 | + } else { |
|
| 75 | + $value = $this->_object->getVar($row->getKeyName()); |
|
| 76 | + } |
|
| 77 | + if ($row->isHeader()) { |
|
| 78 | + $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
| 79 | + $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
| 80 | + } else { |
|
| 81 | + $smartobjectObjectArray[$key]['value'] = $value; |
|
| 82 | + $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
| 83 | + $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + $action_row = ''; |
|
| 87 | + if (in_array('edit', $this->_actions)) { |
|
| 88 | + $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
| 89 | + } |
|
| 90 | + if (in_array('delete', $this->_actions)) { |
|
| 91 | + $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
| 92 | + } |
|
| 93 | + if ($action_row) { |
|
| 94 | + $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
| 95 | + $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
| 99 | - $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
| 98 | + $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
| 99 | + $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
| 100 | 100 | |
| 101 | - if ($fetchOnly) { |
|
| 102 | - return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
| 103 | - } else { |
|
| 104 | - $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
| 105 | - } |
|
| 106 | - } |
|
| 101 | + if ($fetchOnly) { |
|
| 102 | + return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
| 103 | + } else { |
|
| 104 | + $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @param bool $debug |
|
| 110 | - * @return mixed|string|void |
|
| 111 | - */ |
|
| 112 | - public function fetch($debug = false) |
|
| 113 | - { |
|
| 114 | - return $this->render(true, $debug); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * @param bool $debug |
|
| 110 | + * @return mixed|string|void |
|
| 111 | + */ |
|
| 112 | + public function fetch($debug = false) |
|
| 113 | + { |
|
| 114 | + return $this->render(true, $debug); |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | public function render($fetchOnly = false, $debug = false) |
| 62 | 62 | { |
| 63 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 63 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
| 64 | 64 | |
| 65 | 65 | $this->_tpl = new \XoopsTpl(); |
| 66 | 66 | $vars = $this->_object->vars; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | - * @param $columnObj |
|
| 109 | + * @param SmartObjectColumn $columnObj |
|
| 110 | 110 | */ |
| 111 | 111 | public function addColumn($columnObj) |
| 112 | 112 | { |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | - * @param $name |
|
| 118 | - * @param $location |
|
| 117 | + * @param string $name |
|
| 118 | + * @param string $location |
|
| 119 | 119 | * @param $value |
| 120 | 120 | */ |
| 121 | 121 | public function addIntroButton($name, $location, $value) |
@@ -25,805 +25,805 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class SmartObjectTable |
| 27 | 27 | { |
| 28 | - public $_id; |
|
| 29 | - public $_objectHandler; |
|
| 30 | - public $_columns; |
|
| 31 | - public $_criteria; |
|
| 32 | - public $_actions; |
|
| 33 | - public $_objects = false; |
|
| 34 | - public $_aObjects; |
|
| 35 | - public $_custom_actions; |
|
| 36 | - public $_sortsel; |
|
| 37 | - public $_ordersel; |
|
| 38 | - public $_limitsel; |
|
| 39 | - public $_filtersel; |
|
| 40 | - public $_filterseloptions; |
|
| 41 | - public $_filtersel2; |
|
| 42 | - public $_filtersel2options; |
|
| 43 | - public $_filtersel2optionsDefault; |
|
| 44 | - |
|
| 45 | - public $_tempObject; |
|
| 46 | - public $_tpl; |
|
| 47 | - public $_introButtons; |
|
| 48 | - public $_quickSearch = false; |
|
| 49 | - public $_actionButtons = false; |
|
| 50 | - public $_head_css_class = 'bg3'; |
|
| 51 | - public $_hasActions = false; |
|
| 52 | - public $_userSide = false; |
|
| 53 | - public $_printerFriendlyPage = false; |
|
| 54 | - public $_tableHeader = false; |
|
| 55 | - public $_tableFooter = false; |
|
| 56 | - public $_showActionsColumnTitle = true; |
|
| 57 | - public $_isTree = false; |
|
| 58 | - public $_showFilterAndLimit = true; |
|
| 59 | - public $_enableColumnsSorting = true; |
|
| 60 | - public $_customTemplate = false; |
|
| 61 | - public $_withSelectedActions = []; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Constructor |
|
| 65 | - * |
|
| 66 | - * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
| 67 | - * @param CriteriaElement $criteria |
|
| 68 | - * @param array $actions array representing the actions to offer |
|
| 69 | - * |
|
| 70 | - * @param bool $userSide |
|
| 71 | - */ |
|
| 72 | - public function __construct( |
|
| 73 | - SmartPersistableObjectHandler $objectHandler, |
|
| 74 | - CriteriaElement $criteria = null, |
|
| 75 | - $actions = ['edit', 'delete'], |
|
| 76 | - $userSide = false |
|
| 77 | - ) { |
|
| 78 | - $this->_id = $objectHandler->className; |
|
| 79 | - $this->_objectHandler = $objectHandler; |
|
| 80 | - |
|
| 81 | - if (!$criteria) { |
|
| 82 | - $criteria = new \CriteriaCompo(); |
|
| 83 | - } |
|
| 84 | - $this->_criteria = $criteria; |
|
| 85 | - $this->_actions = $actions; |
|
| 86 | - $this->_custom_actions = []; |
|
| 87 | - $this->_userSide = $userSide; |
|
| 88 | - if ($userSide) { |
|
| 89 | - $this->_head_css_class = 'head'; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param $op |
|
| 95 | - * @param bool $caption |
|
| 96 | - * @param bool $text |
|
| 97 | - */ |
|
| 98 | - public function addActionButton($op, $caption = false, $text = false) |
|
| 99 | - { |
|
| 100 | - $action = [ |
|
| 101 | - 'op' => $op, |
|
| 102 | - 'caption' => $caption, |
|
| 103 | - 'text' => $text |
|
| 104 | - ]; |
|
| 105 | - $this->_actionButtons[] = $action; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param $columnObj |
|
| 110 | - */ |
|
| 111 | - public function addColumn($columnObj) |
|
| 112 | - { |
|
| 113 | - $this->_columns[] = $columnObj; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param $name |
|
| 118 | - * @param $location |
|
| 119 | - * @param $value |
|
| 120 | - */ |
|
| 121 | - public function addIntroButton($name, $location, $value) |
|
| 122 | - { |
|
| 123 | - $introButton = []; |
|
| 124 | - $introButton['name'] = $name; |
|
| 125 | - $introButton['location'] = $location; |
|
| 126 | - $introButton['value'] = $value; |
|
| 127 | - $this->_introButtons[] = $introButton; |
|
| 128 | - unset($introButton); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function addPrinterFriendlyLink() |
|
| 132 | - { |
|
| 133 | - $current_urls = smart_getCurrentUrls(); |
|
| 134 | - $current_url = $current_urls['full']; |
|
| 135 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param $fields |
|
| 140 | - * @param string $caption |
|
| 141 | - */ |
|
| 142 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 143 | - { |
|
| 144 | - $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param $content |
|
| 149 | - */ |
|
| 150 | - public function addHeader($content) |
|
| 151 | - { |
|
| 152 | - $this->_tableHeader = $content; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param $content |
|
| 157 | - */ |
|
| 158 | - public function addFooter($content) |
|
| 159 | - { |
|
| 160 | - $this->_tableFooter = $content; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param $caption |
|
| 165 | - */ |
|
| 166 | - public function addDefaultIntroButton($caption) |
|
| 167 | - { |
|
| 168 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param $method |
|
| 173 | - */ |
|
| 174 | - public function addCustomAction($method) |
|
| 175 | - { |
|
| 176 | - $this->_custom_actions[] = $method; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @param $default_sort |
|
| 181 | - */ |
|
| 182 | - public function setDefaultSort($default_sort) |
|
| 183 | - { |
|
| 184 | - $this->_sortsel = $default_sort; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - public function getDefaultSort() |
|
| 191 | - { |
|
| 192 | - if ($this->_sortsel) { |
|
| 193 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 194 | - } else { |
|
| 195 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param $default_order |
|
| 201 | - */ |
|
| 202 | - public function setDefaultOrder($default_order) |
|
| 203 | - { |
|
| 204 | - $this->_ordersel = $default_order; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @return string |
|
| 209 | - */ |
|
| 210 | - public function getDefaultOrder() |
|
| 211 | - { |
|
| 212 | - if ($this->_ordersel) { |
|
| 213 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 214 | - } else { |
|
| 215 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param array $actions |
|
| 221 | - */ |
|
| 222 | - public function addWithSelectedActions($actions = []) |
|
| 223 | - { |
|
| 224 | - $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 225 | - $this->_withSelectedActions = $actions; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Adding a filter in the table |
|
| 230 | - * |
|
| 231 | - * @param string $key key to the field that will be used for sorting |
|
| 232 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 233 | - * @param bool $default |
|
| 234 | - */ |
|
| 235 | - public function addFilter($key, $method, $default = false) |
|
| 236 | - { |
|
| 237 | - $this->_filterseloptions[$key] = $method; |
|
| 238 | - $this->_filtersel2optionsDefault = $default; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @param $default_filter |
|
| 243 | - */ |
|
| 244 | - public function setDefaultFilter($default_filter) |
|
| 245 | - { |
|
| 246 | - $this->_filtersel = $default_filter; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - public function isForUserSide() |
|
| 250 | - { |
|
| 251 | - $this->_userSide = true; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param $template |
|
| 256 | - */ |
|
| 257 | - public function setCustomTemplate($template) |
|
| 258 | - { |
|
| 259 | - $this->_customTemplate = $template; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - public function setSortOrder() |
|
| 263 | - { |
|
| 264 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 265 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 266 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 267 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 268 | - |
|
| 269 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
| 270 | - && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 271 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 272 | - } else { |
|
| 273 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 277 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 278 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 279 | - $ordersArray = $this->getOrdersArray(); |
|
| 280 | - $this->_criteria->setOrder($this->_ordersel); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @param $id |
|
| 285 | - */ |
|
| 286 | - public function setTableId($id) |
|
| 287 | - { |
|
| 288 | - $this->_id = $id; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * @param $objects |
|
| 293 | - */ |
|
| 294 | - public function setObjects($objects) |
|
| 295 | - { |
|
| 296 | - $this->_objects = $objects; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - public function createTableRows() |
|
| 300 | - { |
|
| 301 | - $this->_aObjects = []; |
|
| 302 | - |
|
| 303 | - $doWeHaveActions = false; |
|
| 304 | - |
|
| 305 | - $objectclass = 'odd'; |
|
| 306 | - if (count($this->_objects) > 0) { |
|
| 307 | - foreach ($this->_objects as $object) { |
|
| 308 | - $aObject = []; |
|
| 309 | - |
|
| 310 | - $i = 0; |
|
| 311 | - |
|
| 312 | - $aColumns = []; |
|
| 313 | - |
|
| 314 | - foreach ($this->_columns as $column) { |
|
| 315 | - $aColumn = []; |
|
| 316 | - |
|
| 317 | - if (0 == $i) { |
|
| 318 | - $class = 'head'; |
|
| 319 | - } elseif (0 == $i % 2) { |
|
| 320 | - $class = 'even'; |
|
| 321 | - } else { |
|
| 322 | - $class = 'odd'; |
|
| 323 | - } |
|
| 324 | - if (method_exists($object, 'initiateCustomFields')) { |
|
| 325 | - //$object->initiateCustomFields(); |
|
| 326 | - } |
|
| 327 | - if ('checked' === $column->_keyname) { |
|
| 328 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 329 | - } elseif ($column->_customMethodForValue |
|
| 330 | - && method_exists($object, $column->_customMethodForValue)) { |
|
| 331 | - $method = $column->_customMethodForValue; |
|
| 332 | - if ($column->_param) { |
|
| 333 | - $value = $object->$method($column->_param); |
|
| 334 | - } else { |
|
| 335 | - $value = $object->$method(); |
|
| 336 | - } |
|
| 337 | - } else { |
|
| 338 | - /** |
|
| 339 | - * If the column is the identifier, then put a link on it |
|
| 340 | - */ |
|
| 341 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 342 | - $value = $object->getItemLink(); |
|
| 343 | - } else { |
|
| 344 | - $value = $object->getVar($column->getKeyName()); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $aColumn['value'] = $value; |
|
| 349 | - $aColumn['class'] = $class; |
|
| 350 | - $aColumn['width'] = $column->getWidth(); |
|
| 351 | - $aColumn['align'] = $column->getAlign(); |
|
| 352 | - |
|
| 353 | - $aColumns[] = $aColumn; |
|
| 354 | - ++$i; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $aObject['columns'] = $aColumns; |
|
| 358 | - $aObject['id'] = $object->id(); |
|
| 359 | - |
|
| 360 | - $objectclass = ('even' === $objectclass) ? 'odd' : 'even'; |
|
| 361 | - |
|
| 362 | - $aObject['class'] = $objectclass; |
|
| 363 | - |
|
| 364 | - $actions = []; |
|
| 365 | - |
|
| 366 | - // Adding the custom actions if any |
|
| 367 | - foreach ($this->_custom_actions as $action) { |
|
| 368 | - if (method_exists($object, $action)) { |
|
| 369 | - $actions[] = $object->$action(); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 374 | - $controller = new SmartObjectController($this->_objectHandler); |
|
| 375 | - |
|
| 376 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 377 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 378 | - } |
|
| 379 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 380 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 381 | - } |
|
| 382 | - $aObject['actions'] = $actions; |
|
| 383 | - |
|
| 384 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 385 | - |
|
| 386 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 387 | - |
|
| 388 | - $this->_aObjects[] = $aObject; |
|
| 389 | - } |
|
| 390 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 391 | - } else { |
|
| 392 | - $colspan = count($this->_columns) + 1; |
|
| 393 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 394 | - } |
|
| 395 | - $this->_hasActions = $doWeHaveActions; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * @param bool $debug |
|
| 400 | - * @return mixed |
|
| 401 | - */ |
|
| 402 | - public function fetchObjects($debug = false) |
|
| 403 | - { |
|
| 404 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @return string |
|
| 409 | - */ |
|
| 410 | - public function getDefaultFilter() |
|
| 411 | - { |
|
| 412 | - if ($this->_filtersel) { |
|
| 413 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 414 | - } else { |
|
| 415 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * @return array|bool |
|
| 421 | - */ |
|
| 422 | - public function getFiltersArray() |
|
| 423 | - { |
|
| 424 | - $ret = []; |
|
| 425 | - $field = []; |
|
| 426 | - $field['caption'] = _CO_OBJ_NONE; |
|
| 427 | - $field['selected'] = ''; |
|
| 428 | - $ret['default'] = $field; |
|
| 429 | - unset($field); |
|
| 430 | - |
|
| 431 | - if ($this->_filterseloptions) { |
|
| 432 | - foreach ($this->_filterseloptions as $key => $value) { |
|
| 433 | - $field = []; |
|
| 434 | - if (is_array($value)) { |
|
| 435 | - $field['caption'] = $key; |
|
| 436 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 437 | - } else { |
|
| 438 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 439 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 440 | - } |
|
| 441 | - $ret[$key] = $field; |
|
| 442 | - unset($field); |
|
| 443 | - } |
|
| 444 | - } else { |
|
| 445 | - $ret = false; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return $ret; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @param $default_filter2 |
|
| 453 | - */ |
|
| 454 | - public function setDefaultFilter2($default_filter2) |
|
| 455 | - { |
|
| 456 | - $this->_filtersel2 = $default_filter2; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @return string |
|
| 461 | - */ |
|
| 462 | - public function getDefaultFilter2() |
|
| 463 | - { |
|
| 464 | - if ($this->_filtersel2) { |
|
| 465 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 466 | - } else { |
|
| 467 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @return array |
|
| 473 | - */ |
|
| 474 | - public function getFilters2Array() |
|
| 475 | - { |
|
| 476 | - $ret = []; |
|
| 477 | - |
|
| 478 | - foreach ($this->_filtersel2options as $key => $value) { |
|
| 479 | - $field = []; |
|
| 480 | - $field['caption'] = $value; |
|
| 481 | - $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
| 482 | - $ret[$key] = $field; |
|
| 483 | - unset($field); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $ret; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @param $limitsArray |
|
| 491 | - * @param $params_of_the_options_sel |
|
| 492 | - */ |
|
| 493 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 494 | - { |
|
| 495 | - // Rendering the form to select options on the table |
|
| 496 | - $current_urls = smart_getCurrentUrls(); |
|
| 497 | - $current_url = $current_urls['full']; |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * What was $params_of_the_options_sel doing again ? |
|
| 501 | - */ |
|
| 502 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 503 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 504 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * @return array |
|
| 509 | - */ |
|
| 510 | - public function getLimitsArray() |
|
| 511 | - { |
|
| 512 | - $ret = []; |
|
| 513 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 514 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
| 515 | - |
|
| 516 | - $ret['5']['caption'] = '5'; |
|
| 517 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
| 518 | - |
|
| 519 | - $ret['10']['caption'] = '10'; |
|
| 520 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
| 521 | - |
|
| 522 | - $ret['15']['caption'] = '15'; |
|
| 523 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
| 524 | - |
|
| 525 | - $ret['20']['caption'] = '20'; |
|
| 526 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
| 527 | - |
|
| 528 | - $ret['25']['caption'] = '25'; |
|
| 529 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
| 530 | - |
|
| 531 | - $ret['30']['caption'] = '30'; |
|
| 532 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
| 533 | - |
|
| 534 | - $ret['35']['caption'] = '35'; |
|
| 535 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
| 536 | - |
|
| 537 | - $ret['40']['caption'] = '40'; |
|
| 538 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
| 539 | - |
|
| 540 | - return $ret; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * @return bool |
|
| 545 | - */ |
|
| 546 | - public function getObjects() |
|
| 547 | - { |
|
| 548 | - return $this->_objects; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - public function hideActionColumnTitle() |
|
| 552 | - { |
|
| 553 | - $this->_showActionsColumnTitle = false; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - public function hideFilterAndLimit() |
|
| 557 | - { |
|
| 558 | - $this->_showFilterAndLimit = false; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @return array |
|
| 563 | - */ |
|
| 564 | - public function getOrdersArray() |
|
| 565 | - { |
|
| 566 | - $ret = []; |
|
| 567 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 568 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
| 569 | - |
|
| 570 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 571 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
| 572 | - |
|
| 573 | - return $ret; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * @return mixed|string|void |
|
| 578 | - */ |
|
| 579 | - public function renderD() |
|
| 580 | - { |
|
| 581 | - return $this->render(false, true); |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - public function renderForPrint() |
|
| 585 | - { |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * @param bool $fetchOnly |
|
| 590 | - * @param bool $debug |
|
| 591 | - * @return mixed|string|void |
|
| 592 | - */ |
|
| 593 | - public function render($fetchOnly = false, $debug = false) |
|
| 594 | - { |
|
| 595 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 596 | - |
|
| 597 | - $this->_tpl = new \XoopsTpl(); |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 601 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 602 | - * and we will free it after |
|
| 603 | - */ |
|
| 604 | - $this->_tempObject = $this->_objectHandler->create(); |
|
| 605 | - |
|
| 606 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 607 | - |
|
| 608 | - $this->setSortOrder(); |
|
| 609 | - |
|
| 610 | - if (!$this->_isTree) { |
|
| 611 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 612 | - } else { |
|
| 613 | - $this->_limitsel = 'all'; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 617 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 618 | - $limitsArray = $this->getLimitsArray(); |
|
| 619 | - $this->_criteria->setLimit($this->_limitsel); |
|
| 620 | - |
|
| 621 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 622 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 623 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 624 | - $filtersArray = $this->getFiltersArray(); |
|
| 625 | - |
|
| 626 | - if ($filtersArray) { |
|
| 627 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 631 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 632 | - // check if method associate with this filter exists in the handler |
|
| 633 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 634 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 635 | - $this->_criteria->add($filter['criteria']); |
|
| 636 | - } else { |
|
| 637 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 638 | - |
|
| 639 | - // then we will create the selfilter2 options by calling this method |
|
| 640 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 641 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 642 | - |
|
| 643 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 644 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 645 | - |
|
| 646 | - $filters2Array = $this->getFilters2Array(); |
|
| 647 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 648 | - |
|
| 649 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 650 | - if ('default' !== $this->_filtersel2) { |
|
| 651 | - $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - // Check if we have a quicksearch |
|
| 657 | - |
|
| 658 | - if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
| 659 | - $quicksearch_criteria = new \CriteriaCompo(); |
|
| 660 | - if (is_array($this->_quickSearch['fields'])) { |
|
| 661 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
| 662 | - $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 666 | - } |
|
| 667 | - $this->_criteria->add($quicksearch_criteria); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - $this->_objects = $this->fetchObjects($debug); |
|
| 671 | - |
|
| 672 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 673 | - if ($this->_criteria->getLimit() > 0) { |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Geeting rid of the old params |
|
| 677 | - * $new_get_array is an array containing the new GET parameters |
|
| 678 | - */ |
|
| 679 | - $new_get_array = []; |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 683 | - * but without the pagenave parameters. This array will be used in the |
|
| 684 | - * OptionsSelection |
|
| 685 | - */ |
|
| 686 | - $params_of_the_options_sel = []; |
|
| 687 | - |
|
| 688 | - $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
| 689 | - foreach ($_GET as $k => $v) { |
|
| 690 | - if (!in_array($k, $not_needed_params)) { |
|
| 691 | - $new_get_array[] = "$k=$v"; |
|
| 692 | - $params_of_the_options_sel[] = "$k=$v"; |
|
| 693 | - } |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Adding the new params of the pagenav |
|
| 698 | - */ |
|
| 699 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 700 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 701 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 702 | - $otherParams = implode('&', $new_get_array); |
|
| 703 | - |
|
| 704 | - $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 705 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 706 | - } |
|
| 707 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 708 | - |
|
| 709 | - // retreive the current url and the query string |
|
| 710 | - $current_urls = smart_getCurrentUrls(); |
|
| 711 | - $current_url = $current_urls['full_phpself']; |
|
| 712 | - $query_string = $current_urls['querystring']; |
|
| 713 | - if ($query_string) { |
|
| 714 | - $query_string = str_replace('?', '', $query_string); |
|
| 715 | - } |
|
| 716 | - $query_stringArray = explode('&', $query_string); |
|
| 717 | - $new_query_stringArray = []; |
|
| 718 | - foreach ($query_stringArray as $query_string) { |
|
| 719 | - if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { |
|
| 720 | - $new_query_stringArray[] = $query_string; |
|
| 721 | - } |
|
| 722 | - } |
|
| 723 | - $new_query_string = implode('&', $new_query_stringArray); |
|
| 724 | - |
|
| 725 | - $orderArray = []; |
|
| 726 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
| 727 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 728 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
| 729 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 730 | - |
|
| 731 | - $aColumns = []; |
|
| 732 | - |
|
| 733 | - foreach ($this->_columns as $column) { |
|
| 734 | - $qs_param = ''; |
|
| 735 | - $aColumn = []; |
|
| 736 | - $aColumn['width'] = $column->getWidth(); |
|
| 737 | - $aColumn['align'] = $column->getAlign(); |
|
| 738 | - $aColumn['key'] = $column->getKeyName(); |
|
| 739 | - if ('checked' === $column->_keyname) { |
|
| 740 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 741 | - } elseif ($column->getCustomCaption()) { |
|
| 742 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
| 743 | - } else { |
|
| 744 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 745 | - } |
|
| 746 | - // Are we doing a GET sort on this column ? |
|
| 747 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 748 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 749 | - || ($this->_sortsel == $column->getKeyName()); |
|
| 750 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 751 | - |
|
| 752 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
| 753 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 754 | - } |
|
| 755 | - if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
|
| 756 | - $aColumn['caption'] = $aColumn['caption']; |
|
| 757 | - } elseif ($getSort) { |
|
| 758 | - $aColumn['caption'] = '<a href="' |
|
| 759 | - . $current_url |
|
| 760 | - . '?' |
|
| 761 | - . $this->_objectHandler->_itemname |
|
| 762 | - . '_' |
|
| 763 | - . 'sortsel=' |
|
| 764 | - . $column->getKeyName() |
|
| 765 | - . '&' |
|
| 766 | - . $this->_objectHandler->_itemname |
|
| 767 | - . '_' |
|
| 768 | - . 'ordersel=' |
|
| 769 | - . $orderArray[$order]['neworder'] |
|
| 770 | - . $qs_param |
|
| 771 | - . '&' |
|
| 772 | - . $new_query_string |
|
| 773 | - . '">' |
|
| 774 | - . $aColumn['caption'] |
|
| 775 | - . ' <img src="' |
|
| 776 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 777 | - . $orderArray[$order]['image'] |
|
| 778 | - . '" alt="ASC"></a>'; |
|
| 779 | - } else { |
|
| 780 | - $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>'; |
|
| 781 | - } |
|
| 782 | - $aColumns[] = $aColumn; |
|
| 783 | - } |
|
| 784 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 785 | - |
|
| 786 | - if ($this->_quickSearch) { |
|
| 787 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - $this->createTableRows(); |
|
| 791 | - |
|
| 792 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 793 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 794 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 795 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 796 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 797 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 798 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 799 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 800 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 801 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 802 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 803 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 804 | - if (!empty($this->_withSelectedActions)) { |
|
| 805 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 809 | - if ($fetchOnly) { |
|
| 810 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 811 | - } else { |
|
| 812 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 813 | - } |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - public function disableColumnsSorting() |
|
| 817 | - { |
|
| 818 | - $this->_enableColumnsSorting = false; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * @param bool $debug |
|
| 823 | - * @return mixed|string|void |
|
| 824 | - */ |
|
| 825 | - public function fetch($debug = false) |
|
| 826 | - { |
|
| 827 | - return $this->render(true, $debug); |
|
| 828 | - } |
|
| 28 | + public $_id; |
|
| 29 | + public $_objectHandler; |
|
| 30 | + public $_columns; |
|
| 31 | + public $_criteria; |
|
| 32 | + public $_actions; |
|
| 33 | + public $_objects = false; |
|
| 34 | + public $_aObjects; |
|
| 35 | + public $_custom_actions; |
|
| 36 | + public $_sortsel; |
|
| 37 | + public $_ordersel; |
|
| 38 | + public $_limitsel; |
|
| 39 | + public $_filtersel; |
|
| 40 | + public $_filterseloptions; |
|
| 41 | + public $_filtersel2; |
|
| 42 | + public $_filtersel2options; |
|
| 43 | + public $_filtersel2optionsDefault; |
|
| 44 | + |
|
| 45 | + public $_tempObject; |
|
| 46 | + public $_tpl; |
|
| 47 | + public $_introButtons; |
|
| 48 | + public $_quickSearch = false; |
|
| 49 | + public $_actionButtons = false; |
|
| 50 | + public $_head_css_class = 'bg3'; |
|
| 51 | + public $_hasActions = false; |
|
| 52 | + public $_userSide = false; |
|
| 53 | + public $_printerFriendlyPage = false; |
|
| 54 | + public $_tableHeader = false; |
|
| 55 | + public $_tableFooter = false; |
|
| 56 | + public $_showActionsColumnTitle = true; |
|
| 57 | + public $_isTree = false; |
|
| 58 | + public $_showFilterAndLimit = true; |
|
| 59 | + public $_enableColumnsSorting = true; |
|
| 60 | + public $_customTemplate = false; |
|
| 61 | + public $_withSelectedActions = []; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Constructor |
|
| 65 | + * |
|
| 66 | + * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
| 67 | + * @param CriteriaElement $criteria |
|
| 68 | + * @param array $actions array representing the actions to offer |
|
| 69 | + * |
|
| 70 | + * @param bool $userSide |
|
| 71 | + */ |
|
| 72 | + public function __construct( |
|
| 73 | + SmartPersistableObjectHandler $objectHandler, |
|
| 74 | + CriteriaElement $criteria = null, |
|
| 75 | + $actions = ['edit', 'delete'], |
|
| 76 | + $userSide = false |
|
| 77 | + ) { |
|
| 78 | + $this->_id = $objectHandler->className; |
|
| 79 | + $this->_objectHandler = $objectHandler; |
|
| 80 | + |
|
| 81 | + if (!$criteria) { |
|
| 82 | + $criteria = new \CriteriaCompo(); |
|
| 83 | + } |
|
| 84 | + $this->_criteria = $criteria; |
|
| 85 | + $this->_actions = $actions; |
|
| 86 | + $this->_custom_actions = []; |
|
| 87 | + $this->_userSide = $userSide; |
|
| 88 | + if ($userSide) { |
|
| 89 | + $this->_head_css_class = 'head'; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param $op |
|
| 95 | + * @param bool $caption |
|
| 96 | + * @param bool $text |
|
| 97 | + */ |
|
| 98 | + public function addActionButton($op, $caption = false, $text = false) |
|
| 99 | + { |
|
| 100 | + $action = [ |
|
| 101 | + 'op' => $op, |
|
| 102 | + 'caption' => $caption, |
|
| 103 | + 'text' => $text |
|
| 104 | + ]; |
|
| 105 | + $this->_actionButtons[] = $action; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param $columnObj |
|
| 110 | + */ |
|
| 111 | + public function addColumn($columnObj) |
|
| 112 | + { |
|
| 113 | + $this->_columns[] = $columnObj; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param $name |
|
| 118 | + * @param $location |
|
| 119 | + * @param $value |
|
| 120 | + */ |
|
| 121 | + public function addIntroButton($name, $location, $value) |
|
| 122 | + { |
|
| 123 | + $introButton = []; |
|
| 124 | + $introButton['name'] = $name; |
|
| 125 | + $introButton['location'] = $location; |
|
| 126 | + $introButton['value'] = $value; |
|
| 127 | + $this->_introButtons[] = $introButton; |
|
| 128 | + unset($introButton); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function addPrinterFriendlyLink() |
|
| 132 | + { |
|
| 133 | + $current_urls = smart_getCurrentUrls(); |
|
| 134 | + $current_url = $current_urls['full']; |
|
| 135 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param $fields |
|
| 140 | + * @param string $caption |
|
| 141 | + */ |
|
| 142 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 143 | + { |
|
| 144 | + $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param $content |
|
| 149 | + */ |
|
| 150 | + public function addHeader($content) |
|
| 151 | + { |
|
| 152 | + $this->_tableHeader = $content; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param $content |
|
| 157 | + */ |
|
| 158 | + public function addFooter($content) |
|
| 159 | + { |
|
| 160 | + $this->_tableFooter = $content; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param $caption |
|
| 165 | + */ |
|
| 166 | + public function addDefaultIntroButton($caption) |
|
| 167 | + { |
|
| 168 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param $method |
|
| 173 | + */ |
|
| 174 | + public function addCustomAction($method) |
|
| 175 | + { |
|
| 176 | + $this->_custom_actions[] = $method; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @param $default_sort |
|
| 181 | + */ |
|
| 182 | + public function setDefaultSort($default_sort) |
|
| 183 | + { |
|
| 184 | + $this->_sortsel = $default_sort; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + public function getDefaultSort() |
|
| 191 | + { |
|
| 192 | + if ($this->_sortsel) { |
|
| 193 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 194 | + } else { |
|
| 195 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param $default_order |
|
| 201 | + */ |
|
| 202 | + public function setDefaultOrder($default_order) |
|
| 203 | + { |
|
| 204 | + $this->_ordersel = $default_order; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @return string |
|
| 209 | + */ |
|
| 210 | + public function getDefaultOrder() |
|
| 211 | + { |
|
| 212 | + if ($this->_ordersel) { |
|
| 213 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 214 | + } else { |
|
| 215 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param array $actions |
|
| 221 | + */ |
|
| 222 | + public function addWithSelectedActions($actions = []) |
|
| 223 | + { |
|
| 224 | + $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 225 | + $this->_withSelectedActions = $actions; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Adding a filter in the table |
|
| 230 | + * |
|
| 231 | + * @param string $key key to the field that will be used for sorting |
|
| 232 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 233 | + * @param bool $default |
|
| 234 | + */ |
|
| 235 | + public function addFilter($key, $method, $default = false) |
|
| 236 | + { |
|
| 237 | + $this->_filterseloptions[$key] = $method; |
|
| 238 | + $this->_filtersel2optionsDefault = $default; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @param $default_filter |
|
| 243 | + */ |
|
| 244 | + public function setDefaultFilter($default_filter) |
|
| 245 | + { |
|
| 246 | + $this->_filtersel = $default_filter; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + public function isForUserSide() |
|
| 250 | + { |
|
| 251 | + $this->_userSide = true; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param $template |
|
| 256 | + */ |
|
| 257 | + public function setCustomTemplate($template) |
|
| 258 | + { |
|
| 259 | + $this->_customTemplate = $template; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + public function setSortOrder() |
|
| 263 | + { |
|
| 264 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 265 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 266 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 267 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 268 | + |
|
| 269 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
| 270 | + && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 271 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 272 | + } else { |
|
| 273 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 277 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 278 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 279 | + $ordersArray = $this->getOrdersArray(); |
|
| 280 | + $this->_criteria->setOrder($this->_ordersel); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @param $id |
|
| 285 | + */ |
|
| 286 | + public function setTableId($id) |
|
| 287 | + { |
|
| 288 | + $this->_id = $id; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * @param $objects |
|
| 293 | + */ |
|
| 294 | + public function setObjects($objects) |
|
| 295 | + { |
|
| 296 | + $this->_objects = $objects; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + public function createTableRows() |
|
| 300 | + { |
|
| 301 | + $this->_aObjects = []; |
|
| 302 | + |
|
| 303 | + $doWeHaveActions = false; |
|
| 304 | + |
|
| 305 | + $objectclass = 'odd'; |
|
| 306 | + if (count($this->_objects) > 0) { |
|
| 307 | + foreach ($this->_objects as $object) { |
|
| 308 | + $aObject = []; |
|
| 309 | + |
|
| 310 | + $i = 0; |
|
| 311 | + |
|
| 312 | + $aColumns = []; |
|
| 313 | + |
|
| 314 | + foreach ($this->_columns as $column) { |
|
| 315 | + $aColumn = []; |
|
| 316 | + |
|
| 317 | + if (0 == $i) { |
|
| 318 | + $class = 'head'; |
|
| 319 | + } elseif (0 == $i % 2) { |
|
| 320 | + $class = 'even'; |
|
| 321 | + } else { |
|
| 322 | + $class = 'odd'; |
|
| 323 | + } |
|
| 324 | + if (method_exists($object, 'initiateCustomFields')) { |
|
| 325 | + //$object->initiateCustomFields(); |
|
| 326 | + } |
|
| 327 | + if ('checked' === $column->_keyname) { |
|
| 328 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 329 | + } elseif ($column->_customMethodForValue |
|
| 330 | + && method_exists($object, $column->_customMethodForValue)) { |
|
| 331 | + $method = $column->_customMethodForValue; |
|
| 332 | + if ($column->_param) { |
|
| 333 | + $value = $object->$method($column->_param); |
|
| 334 | + } else { |
|
| 335 | + $value = $object->$method(); |
|
| 336 | + } |
|
| 337 | + } else { |
|
| 338 | + /** |
|
| 339 | + * If the column is the identifier, then put a link on it |
|
| 340 | + */ |
|
| 341 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 342 | + $value = $object->getItemLink(); |
|
| 343 | + } else { |
|
| 344 | + $value = $object->getVar($column->getKeyName()); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $aColumn['value'] = $value; |
|
| 349 | + $aColumn['class'] = $class; |
|
| 350 | + $aColumn['width'] = $column->getWidth(); |
|
| 351 | + $aColumn['align'] = $column->getAlign(); |
|
| 352 | + |
|
| 353 | + $aColumns[] = $aColumn; |
|
| 354 | + ++$i; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $aObject['columns'] = $aColumns; |
|
| 358 | + $aObject['id'] = $object->id(); |
|
| 359 | + |
|
| 360 | + $objectclass = ('even' === $objectclass) ? 'odd' : 'even'; |
|
| 361 | + |
|
| 362 | + $aObject['class'] = $objectclass; |
|
| 363 | + |
|
| 364 | + $actions = []; |
|
| 365 | + |
|
| 366 | + // Adding the custom actions if any |
|
| 367 | + foreach ($this->_custom_actions as $action) { |
|
| 368 | + if (method_exists($object, $action)) { |
|
| 369 | + $actions[] = $object->$action(); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 374 | + $controller = new SmartObjectController($this->_objectHandler); |
|
| 375 | + |
|
| 376 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 377 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 378 | + } |
|
| 379 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 380 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 381 | + } |
|
| 382 | + $aObject['actions'] = $actions; |
|
| 383 | + |
|
| 384 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 385 | + |
|
| 386 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 387 | + |
|
| 388 | + $this->_aObjects[] = $aObject; |
|
| 389 | + } |
|
| 390 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 391 | + } else { |
|
| 392 | + $colspan = count($this->_columns) + 1; |
|
| 393 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 394 | + } |
|
| 395 | + $this->_hasActions = $doWeHaveActions; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * @param bool $debug |
|
| 400 | + * @return mixed |
|
| 401 | + */ |
|
| 402 | + public function fetchObjects($debug = false) |
|
| 403 | + { |
|
| 404 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @return string |
|
| 409 | + */ |
|
| 410 | + public function getDefaultFilter() |
|
| 411 | + { |
|
| 412 | + if ($this->_filtersel) { |
|
| 413 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 414 | + } else { |
|
| 415 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * @return array|bool |
|
| 421 | + */ |
|
| 422 | + public function getFiltersArray() |
|
| 423 | + { |
|
| 424 | + $ret = []; |
|
| 425 | + $field = []; |
|
| 426 | + $field['caption'] = _CO_OBJ_NONE; |
|
| 427 | + $field['selected'] = ''; |
|
| 428 | + $ret['default'] = $field; |
|
| 429 | + unset($field); |
|
| 430 | + |
|
| 431 | + if ($this->_filterseloptions) { |
|
| 432 | + foreach ($this->_filterseloptions as $key => $value) { |
|
| 433 | + $field = []; |
|
| 434 | + if (is_array($value)) { |
|
| 435 | + $field['caption'] = $key; |
|
| 436 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 437 | + } else { |
|
| 438 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 439 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 440 | + } |
|
| 441 | + $ret[$key] = $field; |
|
| 442 | + unset($field); |
|
| 443 | + } |
|
| 444 | + } else { |
|
| 445 | + $ret = false; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return $ret; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @param $default_filter2 |
|
| 453 | + */ |
|
| 454 | + public function setDefaultFilter2($default_filter2) |
|
| 455 | + { |
|
| 456 | + $this->_filtersel2 = $default_filter2; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @return string |
|
| 461 | + */ |
|
| 462 | + public function getDefaultFilter2() |
|
| 463 | + { |
|
| 464 | + if ($this->_filtersel2) { |
|
| 465 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 466 | + } else { |
|
| 467 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @return array |
|
| 473 | + */ |
|
| 474 | + public function getFilters2Array() |
|
| 475 | + { |
|
| 476 | + $ret = []; |
|
| 477 | + |
|
| 478 | + foreach ($this->_filtersel2options as $key => $value) { |
|
| 479 | + $field = []; |
|
| 480 | + $field['caption'] = $value; |
|
| 481 | + $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
| 482 | + $ret[$key] = $field; |
|
| 483 | + unset($field); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $ret; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @param $limitsArray |
|
| 491 | + * @param $params_of_the_options_sel |
|
| 492 | + */ |
|
| 493 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 494 | + { |
|
| 495 | + // Rendering the form to select options on the table |
|
| 496 | + $current_urls = smart_getCurrentUrls(); |
|
| 497 | + $current_url = $current_urls['full']; |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * What was $params_of_the_options_sel doing again ? |
|
| 501 | + */ |
|
| 502 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 503 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 504 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * @return array |
|
| 509 | + */ |
|
| 510 | + public function getLimitsArray() |
|
| 511 | + { |
|
| 512 | + $ret = []; |
|
| 513 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 514 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
| 515 | + |
|
| 516 | + $ret['5']['caption'] = '5'; |
|
| 517 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
| 518 | + |
|
| 519 | + $ret['10']['caption'] = '10'; |
|
| 520 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
| 521 | + |
|
| 522 | + $ret['15']['caption'] = '15'; |
|
| 523 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
| 524 | + |
|
| 525 | + $ret['20']['caption'] = '20'; |
|
| 526 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
| 527 | + |
|
| 528 | + $ret['25']['caption'] = '25'; |
|
| 529 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
| 530 | + |
|
| 531 | + $ret['30']['caption'] = '30'; |
|
| 532 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
| 533 | + |
|
| 534 | + $ret['35']['caption'] = '35'; |
|
| 535 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
| 536 | + |
|
| 537 | + $ret['40']['caption'] = '40'; |
|
| 538 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
| 539 | + |
|
| 540 | + return $ret; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * @return bool |
|
| 545 | + */ |
|
| 546 | + public function getObjects() |
|
| 547 | + { |
|
| 548 | + return $this->_objects; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + public function hideActionColumnTitle() |
|
| 552 | + { |
|
| 553 | + $this->_showActionsColumnTitle = false; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + public function hideFilterAndLimit() |
|
| 557 | + { |
|
| 558 | + $this->_showFilterAndLimit = false; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @return array |
|
| 563 | + */ |
|
| 564 | + public function getOrdersArray() |
|
| 565 | + { |
|
| 566 | + $ret = []; |
|
| 567 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 568 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
| 569 | + |
|
| 570 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 571 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
| 572 | + |
|
| 573 | + return $ret; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * @return mixed|string|void |
|
| 578 | + */ |
|
| 579 | + public function renderD() |
|
| 580 | + { |
|
| 581 | + return $this->render(false, true); |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + public function renderForPrint() |
|
| 585 | + { |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * @param bool $fetchOnly |
|
| 590 | + * @param bool $debug |
|
| 591 | + * @return mixed|string|void |
|
| 592 | + */ |
|
| 593 | + public function render($fetchOnly = false, $debug = false) |
|
| 594 | + { |
|
| 595 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 596 | + |
|
| 597 | + $this->_tpl = new \XoopsTpl(); |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 601 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 602 | + * and we will free it after |
|
| 603 | + */ |
|
| 604 | + $this->_tempObject = $this->_objectHandler->create(); |
|
| 605 | + |
|
| 606 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 607 | + |
|
| 608 | + $this->setSortOrder(); |
|
| 609 | + |
|
| 610 | + if (!$this->_isTree) { |
|
| 611 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 612 | + } else { |
|
| 613 | + $this->_limitsel = 'all'; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 617 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 618 | + $limitsArray = $this->getLimitsArray(); |
|
| 619 | + $this->_criteria->setLimit($this->_limitsel); |
|
| 620 | + |
|
| 621 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 622 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 623 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 624 | + $filtersArray = $this->getFiltersArray(); |
|
| 625 | + |
|
| 626 | + if ($filtersArray) { |
|
| 627 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 631 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 632 | + // check if method associate with this filter exists in the handler |
|
| 633 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 634 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 635 | + $this->_criteria->add($filter['criteria']); |
|
| 636 | + } else { |
|
| 637 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 638 | + |
|
| 639 | + // then we will create the selfilter2 options by calling this method |
|
| 640 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 641 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 642 | + |
|
| 643 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 644 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 645 | + |
|
| 646 | + $filters2Array = $this->getFilters2Array(); |
|
| 647 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 648 | + |
|
| 649 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 650 | + if ('default' !== $this->_filtersel2) { |
|
| 651 | + $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + // Check if we have a quicksearch |
|
| 657 | + |
|
| 658 | + if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
| 659 | + $quicksearch_criteria = new \CriteriaCompo(); |
|
| 660 | + if (is_array($this->_quickSearch['fields'])) { |
|
| 661 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
| 662 | + $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 666 | + } |
|
| 667 | + $this->_criteria->add($quicksearch_criteria); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + $this->_objects = $this->fetchObjects($debug); |
|
| 671 | + |
|
| 672 | + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 673 | + if ($this->_criteria->getLimit() > 0) { |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Geeting rid of the old params |
|
| 677 | + * $new_get_array is an array containing the new GET parameters |
|
| 678 | + */ |
|
| 679 | + $new_get_array = []; |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 683 | + * but without the pagenave parameters. This array will be used in the |
|
| 684 | + * OptionsSelection |
|
| 685 | + */ |
|
| 686 | + $params_of_the_options_sel = []; |
|
| 687 | + |
|
| 688 | + $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
| 689 | + foreach ($_GET as $k => $v) { |
|
| 690 | + if (!in_array($k, $not_needed_params)) { |
|
| 691 | + $new_get_array[] = "$k=$v"; |
|
| 692 | + $params_of_the_options_sel[] = "$k=$v"; |
|
| 693 | + } |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Adding the new params of the pagenav |
|
| 698 | + */ |
|
| 699 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 700 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 701 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 702 | + $otherParams = implode('&', $new_get_array); |
|
| 703 | + |
|
| 704 | + $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 705 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 706 | + } |
|
| 707 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 708 | + |
|
| 709 | + // retreive the current url and the query string |
|
| 710 | + $current_urls = smart_getCurrentUrls(); |
|
| 711 | + $current_url = $current_urls['full_phpself']; |
|
| 712 | + $query_string = $current_urls['querystring']; |
|
| 713 | + if ($query_string) { |
|
| 714 | + $query_string = str_replace('?', '', $query_string); |
|
| 715 | + } |
|
| 716 | + $query_stringArray = explode('&', $query_string); |
|
| 717 | + $new_query_stringArray = []; |
|
| 718 | + foreach ($query_stringArray as $query_string) { |
|
| 719 | + if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { |
|
| 720 | + $new_query_stringArray[] = $query_string; |
|
| 721 | + } |
|
| 722 | + } |
|
| 723 | + $new_query_string = implode('&', $new_query_stringArray); |
|
| 724 | + |
|
| 725 | + $orderArray = []; |
|
| 726 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
| 727 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 728 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
| 729 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 730 | + |
|
| 731 | + $aColumns = []; |
|
| 732 | + |
|
| 733 | + foreach ($this->_columns as $column) { |
|
| 734 | + $qs_param = ''; |
|
| 735 | + $aColumn = []; |
|
| 736 | + $aColumn['width'] = $column->getWidth(); |
|
| 737 | + $aColumn['align'] = $column->getAlign(); |
|
| 738 | + $aColumn['key'] = $column->getKeyName(); |
|
| 739 | + if ('checked' === $column->_keyname) { |
|
| 740 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 741 | + } elseif ($column->getCustomCaption()) { |
|
| 742 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
| 743 | + } else { |
|
| 744 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 745 | + } |
|
| 746 | + // Are we doing a GET sort on this column ? |
|
| 747 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 748 | + && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 749 | + || ($this->_sortsel == $column->getKeyName()); |
|
| 750 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 751 | + |
|
| 752 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
| 753 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 754 | + } |
|
| 755 | + if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
|
| 756 | + $aColumn['caption'] = $aColumn['caption']; |
|
| 757 | + } elseif ($getSort) { |
|
| 758 | + $aColumn['caption'] = '<a href="' |
|
| 759 | + . $current_url |
|
| 760 | + . '?' |
|
| 761 | + . $this->_objectHandler->_itemname |
|
| 762 | + . '_' |
|
| 763 | + . 'sortsel=' |
|
| 764 | + . $column->getKeyName() |
|
| 765 | + . '&' |
|
| 766 | + . $this->_objectHandler->_itemname |
|
| 767 | + . '_' |
|
| 768 | + . 'ordersel=' |
|
| 769 | + . $orderArray[$order]['neworder'] |
|
| 770 | + . $qs_param |
|
| 771 | + . '&' |
|
| 772 | + . $new_query_string |
|
| 773 | + . '">' |
|
| 774 | + . $aColumn['caption'] |
|
| 775 | + . ' <img src="' |
|
| 776 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 777 | + . $orderArray[$order]['image'] |
|
| 778 | + . '" alt="ASC"></a>'; |
|
| 779 | + } else { |
|
| 780 | + $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>'; |
|
| 781 | + } |
|
| 782 | + $aColumns[] = $aColumn; |
|
| 783 | + } |
|
| 784 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 785 | + |
|
| 786 | + if ($this->_quickSearch) { |
|
| 787 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + $this->createTableRows(); |
|
| 791 | + |
|
| 792 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 793 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 794 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 795 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 796 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 797 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 798 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 799 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 800 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 801 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 802 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 803 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 804 | + if (!empty($this->_withSelectedActions)) { |
|
| 805 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 809 | + if ($fetchOnly) { |
|
| 810 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 811 | + } else { |
|
| 812 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 813 | + } |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + public function disableColumnsSorting() |
|
| 817 | + { |
|
| 818 | + $this->_enableColumnsSorting = false; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * @param bool $debug |
|
| 823 | + * @return mixed|string|void |
|
| 824 | + */ |
|
| 825 | + public function fetch($debug = false) |
|
| 826 | + { |
|
| 827 | + return $this->render(true, $debug); |
|
| 828 | + } |
|
| 829 | 829 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function addActionButton($op, $caption = false, $text = false) |
| 99 | 99 | { |
| 100 | - $action = [ |
|
| 100 | + $action = [ |
|
| 101 | 101 | 'op' => $op, |
| 102 | 102 | 'caption' => $caption, |
| 103 | 103 | 'text' => $text |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | $current_urls = smart_getCurrentUrls(); |
| 134 | 134 | $current_url = $current_urls['full']; |
| 135 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 135 | + $this->_printerFriendlyPage = $current_url.'&print'; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function addDefaultIntroButton($caption) |
| 167 | 167 | { |
| 168 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 168 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page.'?op=mod', $caption); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -190,9 +190,9 @@ discard block |
||
| 190 | 190 | public function getDefaultSort() |
| 191 | 191 | { |
| 192 | 192 | if ($this->_sortsel) { |
| 193 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 193 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
| 194 | 194 | } else { |
| 195 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 195 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_objectHandler->identifierName); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
@@ -210,9 +210,9 @@ discard block |
||
| 210 | 210 | public function getDefaultOrder() |
| 211 | 211 | { |
| 212 | 212 | if ($this->_ordersel) { |
| 213 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 213 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
| 214 | 214 | } else { |
| 215 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 215 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', 'ASC'); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
@@ -261,21 +261,21 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | public function setSortOrder() |
| 263 | 263 | { |
| 264 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 264 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] : $this->getDefaultSort(); |
|
| 265 | 265 | //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
| 266 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 266 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
| 267 | 267 | $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
| 268 | 268 | |
| 269 | 269 | if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
| 270 | 270 | && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
| 271 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 271 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'].'.'.$this->_sortsel); |
|
| 272 | 272 | } else { |
| 273 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 273 | + $this->_criteria->setSort($this->_objectHandler->_itemname.'.'.$this->_sortsel); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 276 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : $this->getDefaultOrder(); |
|
| 277 | 277 | //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
| 278 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 278 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
| 279 | 279 | $ordersArray = $this->getOrdersArray(); |
| 280 | 280 | $this->_criteria->setOrder($this->_ordersel); |
| 281 | 281 | } |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | //$object->initiateCustomFields(); |
| 326 | 326 | } |
| 327 | 327 | if ('checked' === $column->_keyname) { |
| 328 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 328 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'">'; |
|
| 329 | 329 | } elseif ($column->_customMethodForValue |
| 330 | 330 | && method_exists($object, $column->_customMethodForValue)) { |
| 331 | 331 | $method = $column->_customMethodForValue; |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 373 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
| 374 | 374 | $controller = new SmartObjectController($this->_objectHandler); |
| 375 | 375 | |
| 376 | 376 | if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
@@ -410,9 +410,9 @@ discard block |
||
| 410 | 410 | public function getDefaultFilter() |
| 411 | 411 | { |
| 412 | 412 | if ($this->_filtersel) { |
| 413 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 413 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
| 414 | 414 | } else { |
| 415 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 415 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', 'default'); |
|
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | |
@@ -462,9 +462,9 @@ discard block |
||
| 462 | 462 | public function getDefaultFilter2() |
| 463 | 463 | { |
| 464 | 464 | if ($this->_filtersel2) { |
| 465 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 465 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
| 466 | 466 | } else { |
| 467 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 467 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', 'default'); |
|
| 468 | 468 | } |
| 469 | 469 | } |
| 470 | 470 | |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | */ |
| 593 | 593 | public function render($fetchOnly = false, $debug = false) |
| 594 | 594 | { |
| 595 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 595 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
| 596 | 596 | |
| 597 | 597 | $this->_tpl = new \XoopsTpl(); |
| 598 | 598 | |
@@ -603,24 +603,24 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | $this->_tempObject = $this->_objectHandler->create(); |
| 605 | 605 | |
| 606 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 606 | + $this->_criteria->setStart(isset($_GET['start'.$this->_objectHandler->keyName]) ? (int) $_GET['start'.$this->_objectHandler->keyName] : 0); |
|
| 607 | 607 | |
| 608 | 608 | $this->setSortOrder(); |
| 609 | 609 | |
| 610 | 610 | if (!$this->_isTree) { |
| 611 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 611 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'].'_limitsel', '15'); |
|
| 612 | 612 | } else { |
| 613 | 613 | $this->_limitsel = 'all'; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
| 617 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 617 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_limitsel', $this->_limitsel); |
|
| 618 | 618 | $limitsArray = $this->getLimitsArray(); |
| 619 | 619 | $this->_criteria->setLimit($this->_limitsel); |
| 620 | 620 | |
| 621 | 621 | $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
| 622 | 622 | $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
| 623 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 623 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
| 624 | 624 | $filtersArray = $this->getFiltersArray(); |
| 625 | 625 | |
| 626 | 626 | if ($filtersArray) { |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | $filters2Array = $this->getFilters2Array(); |
| 647 | 647 | $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
| 648 | 648 | |
| 649 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 649 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
| 650 | 650 | if ('default' !== $this->_filtersel2) { |
| 651 | 651 | $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
| 652 | 652 | } |
@@ -655,21 +655,21 @@ discard block |
||
| 655 | 655 | } |
| 656 | 656 | // Check if we have a quicksearch |
| 657 | 657 | |
| 658 | - if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
| 658 | + if (isset($_POST['quicksearch_'.$this->_id]) && '' != $_POST['quicksearch_'.$this->_id]) { |
|
| 659 | 659 | $quicksearch_criteria = new \CriteriaCompo(); |
| 660 | 660 | if (is_array($this->_quickSearch['fields'])) { |
| 661 | 661 | foreach ($this->_quickSearch['fields'] as $v) { |
| 662 | - $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 662 | + $quicksearch_criteria->add(new \Criteria($v, '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'), 'OR'); |
|
| 663 | 663 | } |
| 664 | 664 | } else { |
| 665 | - $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 665 | + $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE')); |
|
| 666 | 666 | } |
| 667 | 667 | $this->_criteria->add($quicksearch_criteria); |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | $this->_objects = $this->fetchObjects($debug); |
| 671 | 671 | |
| 672 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 672 | + require_once XOOPS_ROOT_PATH.'/class/pagenav.php'; |
|
| 673 | 673 | if ($this->_criteria->getLimit() > 0) { |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | */ |
| 686 | 686 | $params_of_the_options_sel = []; |
| 687 | 687 | |
| 688 | - $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
| 688 | + $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start'.$this->_objectHandler->keyName]; |
|
| 689 | 689 | foreach ($_GET as $k => $v) { |
| 690 | 690 | if (!in_array($k, $not_needed_params)) { |
| 691 | 691 | $new_get_array[] = "$k=$v"; |
@@ -696,12 +696,12 @@ discard block |
||
| 696 | 696 | /** |
| 697 | 697 | * Adding the new params of the pagenav |
| 698 | 698 | */ |
| 699 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 700 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 701 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 699 | + $new_get_array[] = 'sortsel='.$this->_sortsel; |
|
| 700 | + $new_get_array[] = 'ordersel='.$this->_ordersel; |
|
| 701 | + $new_get_array[] = 'limitsel='.$this->_limitsel; |
|
| 702 | 702 | $otherParams = implode('&', $new_get_array); |
| 703 | 703 | |
| 704 | - $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 704 | + $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start'.$this->_objectHandler->keyName, $otherParams); |
|
| 705 | 705 | $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
| 706 | 706 | } |
| 707 | 707 | $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
@@ -737,20 +737,20 @@ discard block |
||
| 737 | 737 | $aColumn['align'] = $column->getAlign(); |
| 738 | 738 | $aColumn['key'] = $column->getKeyName(); |
| 739 | 739 | if ('checked' === $column->_keyname) { |
| 740 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 740 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"'.' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_'.$this->_id.', \'selected_smartobjects\');">'; |
|
| 741 | 741 | } elseif ($column->getCustomCaption()) { |
| 742 | 742 | $aColumn['caption'] = $column->getCustomCaption(); |
| 743 | 743 | } else { |
| 744 | 744 | $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
| 745 | 745 | } |
| 746 | 746 | // Are we doing a GET sort on this column ? |
| 747 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 748 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 747 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) |
|
| 748 | + && $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] == $column->getKeyName()) |
|
| 749 | 749 | || ($this->_sortsel == $column->getKeyName()); |
| 750 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 750 | + $order = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : 'DESC'; |
|
| 751 | 751 | |
| 752 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
| 753 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 752 | + if (isset($_REQUEST['quicksearch_'.$this->_id]) && '' != $_REQUEST['quicksearch_'.$this->_id]) { |
|
| 753 | + $qs_param = '&quicksearch_'.$this->_id.'='.$_REQUEST['quicksearch_'.$this->_id]; |
|
| 754 | 754 | } |
| 755 | 755 | if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
| 756 | 756 | $aColumn['caption'] = $aColumn['caption']; |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | . $orderArray[$order]['image'] |
| 778 | 778 | . '" alt="ASC"></a>'; |
| 779 | 779 | } else { |
| 780 | - $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>'; |
|
| 780 | + $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>'; |
|
| 781 | 781 | } |
| 782 | 782 | $aColumns[] = $aColumn; |
| 783 | 783 | } |
@@ -807,9 +807,9 @@ discard block |
||
| 807 | 807 | |
| 808 | 808 | $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
| 809 | 809 | if ($fetchOnly) { |
| 810 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 810 | + return $this->_tpl->fetch('db:'.$smartobjectTable_template); |
|
| 811 | 811 | } else { |
| 812 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 812 | + $this->_tpl->display('db:'.$smartobjectTable_template); |
|
| 813 | 813 | } |
| 814 | 814 | } |
| 815 | 815 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | 195 | * @param $criteria |
| 196 | - * @param $perm_name |
|
| 196 | + * @param boolean $perm_name |
|
| 197 | 197 | * @return bool |
| 198 | 198 | */ |
| 199 | 199 | public function setGrantedObjectsCriteria($criteria, $perm_name) |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
| 390 | - * @param $sql |
|
| 390 | + * @param string $sql |
|
| 391 | 391 | * @param $criteria |
| 392 | 392 | * @param bool $force |
| 393 | 393 | * @param bool $debug |
@@ -29,980 +29,980 @@ |
||
| 29 | 29 | |
| 30 | 30 | class SmartPersistableObjectHandler extends \XoopsObjectHandler |
| 31 | 31 | { |
| 32 | - public $_itemname; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Name of the table use to store this {@link SmartObject} |
|
| 36 | - * |
|
| 37 | - * Note that the name of the table needs to be free of the database prefix. |
|
| 38 | - * For example "smartsection_categories" |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - public $table; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Name of the table key that uniquely identify each {@link SmartObject} |
|
| 45 | - * |
|
| 46 | - * For example: "categoryid" |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - public $keyName; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Name of the class derived from {@link SmartObject} and which this handler is handling |
|
| 53 | - * |
|
| 54 | - * Note that this string needs to be lowercase |
|
| 55 | - * |
|
| 56 | - * For example: "smartsectioncategory" |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - public $className; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Name of the field which properly identify the {@link SmartObject} |
|
| 63 | - * |
|
| 64 | - * For example: "name" (this will be the category's name) |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - public $identifierName; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Name of the field which will be use as a summary for the object |
|
| 71 | - * |
|
| 72 | - * For example: "summary" |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $summaryName; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Page name use to basically manage and display the {@link SmartObject} |
|
| 79 | - * |
|
| 80 | - * This page needs to be the same in user side and admin side |
|
| 81 | - * |
|
| 82 | - * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php |
|
| 83 | - * @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 |
|
| 84 | - * @var string |
|
| 85 | - */ |
|
| 86 | - public $_page; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Full path of the module using this {@link SmartObject} |
|
| 90 | - * |
|
| 91 | - * <code>XOOPS_URL . "/modules/smartsection/"</code> |
|
| 92 | - * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name |
|
| 93 | - * @var string |
|
| 94 | - */ |
|
| 95 | - public $_modulePath; |
|
| 96 | - |
|
| 97 | - public $_moduleUrl; |
|
| 98 | - |
|
| 99 | - public $_moduleName; |
|
| 100 | - |
|
| 101 | - public $_uploadUrl; |
|
| 102 | - |
|
| 103 | - public $_uploadPath; |
|
| 104 | - |
|
| 105 | - public $_allowedMimeTypes = 0; |
|
| 106 | - |
|
| 107 | - public $_maxFileSize = 1000000; |
|
| 108 | - |
|
| 109 | - public $_maxWidth = 500; |
|
| 110 | - |
|
| 111 | - public $_maxHeight = 500; |
|
| 112 | - |
|
| 113 | - public $highlightFields = []; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Array containing the events name and functions |
|
| 117 | - * |
|
| 118 | - * @var array |
|
| 119 | - */ |
|
| 120 | - public $eventArray = []; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Array containing the permissions that this handler will manage on the objects |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - public $permissionsArray = false; |
|
| 128 | - |
|
| 129 | - public $generalSQL = false; |
|
| 130 | - |
|
| 131 | - public $_eventHooks = []; |
|
| 132 | - public $_disabledEvents = []; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Constructor - called from child classes |
|
| 136 | - * |
|
| 137 | - * @param \XoopsDatabase $db {@link XoopsDatabase} |
|
| 138 | - * @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 |
|
| 139 | - * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
| 140 | - * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
| 141 | - * @param string $summaryName |
|
| 142 | - * @param string $modulename |
|
| 143 | - * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 144 | - * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 145 | - * @internal param string $moduleName name of the module |
|
| 146 | - */ |
|
| 147 | - public function __construct(\XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
| 148 | - { |
|
| 149 | - parent::__construct($db); |
|
| 150 | - |
|
| 151 | - $this->_itemname = $itemname; |
|
| 152 | - $this->_moduleName = $modulename; |
|
| 153 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 154 | - $this->keyName = $keyname; |
|
| 155 | - $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 156 | - $this->identifierName = $idenfierName; |
|
| 157 | - $this->summaryName = $summaryName; |
|
| 158 | - $this->_page = $itemname . '.php'; |
|
| 159 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 160 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 161 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 162 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param $event |
|
| 167 | - * @param $method |
|
| 168 | - */ |
|
| 169 | - public function addEventHook($event, $method) |
|
| 170 | - { |
|
| 171 | - $this->_eventHooks[$event] = $method; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Add a permission that this handler will manage for its objects |
|
| 176 | - * |
|
| 177 | - * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
| 178 | - * |
|
| 179 | - * @param string $perm_name name of the permission |
|
| 180 | - * @param string $caption caption of the control that will be displayed in the form |
|
| 181 | - * @param bool|string $description description of the control that will be displayed in the form |
|
| 182 | - */ |
|
| 183 | - public function addPermission($perm_name, $caption, $description = false) |
|
| 184 | - { |
|
| 185 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
|
| 186 | - |
|
| 187 | - $this->permissionsArray[] = [ |
|
| 188 | - 'perm_name' => $perm_name, |
|
| 189 | - 'caption' => $caption, |
|
| 190 | - 'description' => $description |
|
| 191 | - ]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param $criteria |
|
| 196 | - * @param $perm_name |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function setGrantedObjectsCriteria($criteria, $perm_name) |
|
| 200 | - { |
|
| 201 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
| 202 | - $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 203 | - if (count($grantedItems) > 0) { |
|
| 204 | - $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 205 | - |
|
| 206 | - return true; |
|
| 207 | - } else { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @param bool $_uploadPath |
|
| 214 | - * @param bool $_allowedMimeTypes |
|
| 215 | - * @param bool $_maxFileSize |
|
| 216 | - * @param bool $_maxWidth |
|
| 217 | - * @param bool $_maxHeight |
|
| 218 | - */ |
|
| 219 | - public function setUploaderConfig( |
|
| 220 | - $_uploadPath = false, |
|
| 221 | - $_allowedMimeTypes = false, |
|
| 222 | - $_maxFileSize = false, |
|
| 223 | - $_maxWidth = false, |
|
| 224 | - $_maxHeight = false |
|
| 225 | - ) { |
|
| 226 | - $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
| 227 | - $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
| 228 | - $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
| 229 | - $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
| 230 | - $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * create a new {@link SmartObject} |
|
| 235 | - * |
|
| 236 | - * @param bool $isNew Flag the new objects as "new"? |
|
| 237 | - * |
|
| 238 | - * @return Smartobject\SmartObject {@link SmartObject} |
|
| 239 | - */ |
|
| 240 | - public function create($isNew = true) |
|
| 241 | - { |
|
| 242 | - $obj = new $this->className($this); |
|
| 243 | - $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
| 244 | - if (!$obj->handler) { |
|
| 245 | - $obj->Handler = $this; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if (true === $isNew) { |
|
| 249 | - $obj->setNew(); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return $obj; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function getImageUrl() |
|
| 259 | - { |
|
| 260 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @return string |
|
| 265 | - */ |
|
| 266 | - public function getImagePath() |
|
| 267 | - { |
|
| 268 | - $dir = $this->_uploadPath . $this->_itemname; |
|
| 269 | - if (!file_exists($dir)) { |
|
| 270 | - smart_admin_mkdir($dir); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - return $dir . '/'; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * retrieve a {@link SmartObject} |
|
| 278 | - * |
|
| 279 | - * @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 |
|
| 280 | - * @param bool $as_object whether to return an object or an array |
|
| 281 | - * @param bool $debug |
|
| 282 | - * @param bool $criteria |
|
| 283 | - * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
| 284 | - * FALSE if failed |
|
| 285 | - */ |
|
| 286 | - public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
| 287 | - { |
|
| 288 | - if (!$criteria) { |
|
| 289 | - $criteria = new \CriteriaCompo(); |
|
| 290 | - } |
|
| 291 | - if (is_array($this->keyName)) { |
|
| 292 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 293 | - /** |
|
| 294 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 295 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
| 296 | - */ |
|
| 297 | - //$criteria->add(new \Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
| 298 | - $criteria->add(new \Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
| 299 | - } |
|
| 300 | - } else { |
|
| 301 | - //$criteria = new \Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
| 302 | - /** |
|
| 303 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 304 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
| 305 | - */ |
|
| 306 | - $criteria->add(new \Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
| 307 | - } |
|
| 308 | - $criteria->setLimit(1); |
|
| 309 | - if ($debug) { |
|
| 310 | - $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
| 311 | - } else { |
|
| 312 | - $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
| 313 | - //patch: weird bug of indexing by id even if id_as_key = false; |
|
| 314 | - if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
| 315 | - $obj_array[0] = $obj_array[$id]; |
|
| 316 | - unset($obj_array[$id]); |
|
| 317 | - $obj_array[0]->unsetNew(); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - if (1 != count($obj_array)) { |
|
| 322 | - $obj = $this->create(); |
|
| 323 | - |
|
| 324 | - return $obj; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return $obj_array[0]; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * retrieve a {@link SmartObject} |
|
| 332 | - * |
|
| 333 | - * @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 |
|
| 334 | - * @param bool $as_object whether to return an object or an array |
|
| 335 | - * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
| 336 | - */ |
|
| 337 | - public function &getD($id, $as_object = true) |
|
| 338 | - { |
|
| 339 | - return $this->get($id, $as_object, true); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * retrieve objects from the database |
|
| 344 | - * |
|
| 345 | - * @param null|\CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 346 | - * @param bool $id_as_key use the ID as key for the array? |
|
| 347 | - * @param bool $as_object return an array of objects? |
|
| 348 | - * |
|
| 349 | - * @param bool $sql |
|
| 350 | - * @param bool $debug |
|
| 351 | - * @return array |
|
| 352 | - */ |
|
| 353 | - public function getObjects( |
|
| 354 | - \CriteriaElement $criteria = null, |
|
| 355 | - $id_as_key = false, |
|
| 356 | - $as_object = true, |
|
| 357 | - $sql = false, |
|
| 358 | - $debug = false |
|
| 359 | - ) { |
|
| 360 | - $ret = []; |
|
| 361 | - $limit = $start = 0; |
|
| 362 | - |
|
| 363 | - if ($this->generalSQL) { |
|
| 364 | - $sql = $this->generalSQL; |
|
| 365 | - } elseif (!$sql) { |
|
| 366 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 370 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 371 | - if ('' !== $criteria->getSort()) { |
|
| 372 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 373 | - } |
|
| 374 | - $limit = $criteria->getLimit(); |
|
| 375 | - $start = $criteria->getStart(); |
|
| 376 | - } |
|
| 377 | - if ($debug) { |
|
| 378 | - xoops_debug($sql); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - $result = $this->db->query($sql, $limit, $start); |
|
| 382 | - if (!$result) { |
|
| 383 | - return $ret; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - return $this->convertResultSet($result, $id_as_key, $as_object); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * @param $sql |
|
| 391 | - * @param $criteria |
|
| 392 | - * @param bool $force |
|
| 393 | - * @param bool $debug |
|
| 394 | - * @return array |
|
| 395 | - */ |
|
| 396 | - public function query($sql, $criteria, $force = false, $debug = false) |
|
| 397 | - { |
|
| 398 | - $ret = []; |
|
| 399 | - |
|
| 400 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 401 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 402 | - if ($criteria->groupby) { |
|
| 403 | - $sql .= $criteria->getGroupby(); |
|
| 404 | - } |
|
| 405 | - if ('' !== $criteria->getSort()) { |
|
| 406 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - if ($debug) { |
|
| 410 | - xoops_debug($sql); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - if ($force) { |
|
| 414 | - $result = $this->db->queryF($sql); |
|
| 415 | - } else { |
|
| 416 | - $result = $this->db->query($sql); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - if (!$result) { |
|
| 420 | - return $ret; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 424 | - $ret[] = $myrow; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - return $ret; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * retrieve objects with debug mode - so will show the query |
|
| 432 | - * |
|
| 433 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 434 | - * @param bool $id_as_key use the ID as key for the array? |
|
| 435 | - * @param bool $as_object return an array of objects? |
|
| 436 | - * |
|
| 437 | - * @param bool $sql |
|
| 438 | - * @return array |
|
| 439 | - */ |
|
| 440 | - public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
| 441 | - { |
|
| 442 | - return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * @param $arrayObjects |
|
| 447 | - * @return array|bool |
|
| 448 | - */ |
|
| 449 | - public function getObjectsAsArray($arrayObjects) |
|
| 450 | - { |
|
| 451 | - $ret = []; |
|
| 452 | - foreach ($arrayObjects as $key => $object) { |
|
| 453 | - $ret[$key] = $object->toArray(); |
|
| 454 | - } |
|
| 455 | - if (count($ret > 0)) { |
|
| 456 | - return $ret; |
|
| 457 | - } else { |
|
| 458 | - return false; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Convert a database resultset to a returnable array |
|
| 464 | - * |
|
| 465 | - * @param object $result database resultset |
|
| 466 | - * @param bool $id_as_key - should NOT be used with joint keys |
|
| 467 | - * @param bool $as_object |
|
| 468 | - * |
|
| 469 | - * @return array |
|
| 470 | - */ |
|
| 471 | - public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
| 472 | - { |
|
| 473 | - $ret = []; |
|
| 474 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 475 | - $obj = $this->create(false); |
|
| 476 | - $obj->assignVars($myrow); |
|
| 477 | - if (!$id_as_key) { |
|
| 478 | - if ($as_object) { |
|
| 479 | - $ret[] =& $obj; |
|
| 480 | - } else { |
|
| 481 | - $ret[] = $obj->toArray(); |
|
| 482 | - } |
|
| 483 | - } else { |
|
| 484 | - if ($as_object) { |
|
| 485 | - $value =& $obj; |
|
| 486 | - } else { |
|
| 487 | - $value = $obj->toArray(); |
|
| 488 | - } |
|
| 489 | - if ('parentid' === $id_as_key) { |
|
| 490 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 491 | - } else { |
|
| 492 | - $ret[$obj->getVar($this->keyName)] = $value; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - unset($obj); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - return $ret; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param null $criteria |
|
| 503 | - * @param int $limit |
|
| 504 | - * @param int $start |
|
| 505 | - * @return array |
|
| 506 | - */ |
|
| 507 | - public function getListD($criteria = null, $limit = 0, $start = 0) |
|
| 508 | - { |
|
| 509 | - return $this->getList($criteria, $limit, $start, true); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
| 514 | - * |
|
| 515 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 516 | - * @param int $limit Max number of objects to fetch |
|
| 517 | - * @param int $start Which record to start at |
|
| 518 | - * |
|
| 519 | - * @param bool $debug |
|
| 520 | - * @return array |
|
| 521 | - */ |
|
| 522 | - public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
| 523 | - { |
|
| 524 | - $ret = []; |
|
| 525 | - if (null === $criteria) { |
|
| 526 | - $criteria = new \CriteriaCompo(); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - if ('' === $criteria->getSort()) { |
|
| 530 | - $criteria->setSort($this->getIdentifierName()); |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 534 | - if (!empty($this->identifierName)) { |
|
| 535 | - $sql .= ', ' . $this->getIdentifierName(); |
|
| 536 | - } |
|
| 537 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 538 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 539 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 540 | - if ('' !== $criteria->getSort()) { |
|
| 541 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 542 | - } |
|
| 543 | - $limit = $criteria->getLimit(); |
|
| 544 | - $start = $criteria->getStart(); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - if ($debug) { |
|
| 548 | - xoops_debug($sql); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $result = $this->db->query($sql, $limit, $start); |
|
| 552 | - if (!$result) { |
|
| 553 | - return $ret; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 557 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 558 | - //identifiers should be textboxes, so sanitize them like that |
|
| 559 | - $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return $ret; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * count objects matching a condition |
|
| 567 | - * |
|
| 568 | - * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
| 569 | - * @return int count of objects |
|
| 570 | - */ |
|
| 571 | - public function getCount(CriteriaElement $criteria = null) |
|
| 572 | - { |
|
| 573 | - $field = ''; |
|
| 574 | - $groupby = false; |
|
| 575 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 576 | - if ('' !== $criteria->groupby) { |
|
| 577 | - $groupby = true; |
|
| 578 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - /** |
|
| 582 | - * if we have a generalSQL, lets used this one. |
|
| 583 | - * This needs to be improved... |
|
| 584 | - */ |
|
| 585 | - if ($this->generalSQL) { |
|
| 586 | - $sql = $this->generalSQL; |
|
| 587 | - $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
| 588 | - } else { |
|
| 589 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 590 | - } |
|
| 591 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 592 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 593 | - if ('' !== $criteria->groupby) { |
|
| 594 | - $sql .= $criteria->getGroupby(); |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - $result = $this->db->query($sql); |
|
| 599 | - if (!$result) { |
|
| 600 | - return 0; |
|
| 601 | - } |
|
| 602 | - if (false === $groupby) { |
|
| 603 | - list($count) = $this->db->fetchRow($result); |
|
| 604 | - |
|
| 605 | - return $count; |
|
| 606 | - } else { |
|
| 607 | - $ret = []; |
|
| 608 | - while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
| 609 | - $ret[$id] = $count; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - return $ret; |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * delete an object from the database |
|
| 618 | - * |
|
| 619 | - * @param \XoopsObject $obj reference to the object to delete |
|
| 620 | - * @param bool $force |
|
| 621 | - * @return bool FALSE if failed. |
|
| 622 | - */ |
|
| 623 | - public function delete(\XoopsObject $obj, $force = false) |
|
| 624 | - { |
|
| 625 | - $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
| 626 | - if (!$eventResult) { |
|
| 627 | - $obj->setErrors('An error occured during the BeforeDelete event'); |
|
| 628 | - |
|
| 629 | - return false; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - if (is_array($this->keyName)) { |
|
| 633 | - $clause = []; |
|
| 634 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 635 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 636 | - } |
|
| 637 | - $whereclause = implode(' AND ', $clause); |
|
| 638 | - } else { |
|
| 639 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 640 | - } |
|
| 641 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 642 | - if (false !== $force) { |
|
| 643 | - $result = $this->db->queryF($sql); |
|
| 644 | - } else { |
|
| 645 | - $result = $this->db->query($sql); |
|
| 646 | - } |
|
| 647 | - if (!$result) { |
|
| 648 | - return false; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - $eventResult = $this->executeEvent('afterDelete', $obj); |
|
| 652 | - if (!$eventResult) { |
|
| 653 | - $obj->setErrors('An error occured during the AfterDelete event'); |
|
| 654 | - |
|
| 655 | - return false; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - return true; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param $event |
|
| 663 | - */ |
|
| 664 | - public function disableEvent($event) |
|
| 665 | - { |
|
| 666 | - if (is_array($event)) { |
|
| 667 | - foreach ($event as $v) { |
|
| 668 | - $this->_disabledEvents[] = $v; |
|
| 669 | - } |
|
| 670 | - } else { |
|
| 671 | - $this->_disabledEvents[] = $event; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * @return array |
|
| 677 | - */ |
|
| 678 | - public function getPermissions() |
|
| 679 | - { |
|
| 680 | - return $this->permissionsArray; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * insert a new object in the database |
|
| 685 | - * |
|
| 686 | - * @param \XoopsObject $obj reference to the object |
|
| 687 | - * @param bool $force whether to force the query execution despite security settings |
|
| 688 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
| 689 | - * @param bool $debug |
|
| 690 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 691 | - */ |
|
| 692 | - public function insert(\XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
| 693 | - { |
|
| 694 | - if (false !== $checkObject) { |
|
| 695 | - if (!is_object($obj)) { |
|
| 696 | - return false; |
|
| 697 | - } |
|
| 698 | - /** |
|
| 699 | - * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
| 700 | - */ |
|
| 701 | - if (!is_a($obj, $this->className)) { |
|
| 702 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 703 | - |
|
| 704 | - return false; |
|
| 705 | - } |
|
| 706 | - if (!$obj->isDirty()) { |
|
| 707 | - $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 |
|
| 708 | - |
|
| 709 | - return true; |
|
| 710 | - } |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - if ($obj->seoEnabled) { |
|
| 714 | - // Auto create meta tags if empty |
|
| 715 | - $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
| 716 | - |
|
| 717 | - if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
| 718 | - if (!$obj->meta_keywords()) { |
|
| 719 | - $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - if (!$obj->meta_description()) { |
|
| 723 | - $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - // Auto create short_url if empty |
|
| 728 | - if (!$obj->short_url()) { |
|
| 729 | - $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
| 730 | - } |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - $eventResult = $this->executeEvent('beforeSave', $obj); |
|
| 734 | - if (!$eventResult) { |
|
| 735 | - $obj->setErrors('An error occured during the BeforeSave event'); |
|
| 736 | - |
|
| 737 | - return false; |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - if ($obj->isNew()) { |
|
| 741 | - $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
| 742 | - if (!$eventResult) { |
|
| 743 | - $obj->setErrors('An error occured during the BeforeInsert event'); |
|
| 744 | - |
|
| 745 | - return false; |
|
| 746 | - } |
|
| 747 | - } else { |
|
| 748 | - $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
| 749 | - if (!$eventResult) { |
|
| 750 | - $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
| 751 | - |
|
| 752 | - return false; |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - if (!$obj->cleanVars()) { |
|
| 756 | - $obj->setErrors('Variables were not cleaned properly.'); |
|
| 757 | - |
|
| 758 | - return false; |
|
| 759 | - } |
|
| 760 | - $fieldsToStoreInDB = []; |
|
| 761 | - foreach ($obj->cleanVars as $k => $v) { |
|
| 762 | - if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) { |
|
| 763 | - $cleanvars[$k] = (int)$v; |
|
| 764 | - } elseif (is_array($v)) { |
|
| 765 | - $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
| 766 | - } else { |
|
| 767 | - $cleanvars[$k] = $this->db->quoteString($v); |
|
| 768 | - } |
|
| 769 | - if ($obj->vars[$k]['persistent']) { |
|
| 770 | - $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - if ($obj->isNew()) { |
|
| 774 | - if (!is_array($this->keyName)) { |
|
| 775 | - if ($cleanvars[$this->keyName] < 1) { |
|
| 776 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 781 | - } else { |
|
| 782 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 783 | - foreach ($fieldsToStoreInDB as $key => $value) { |
|
| 784 | - if ((!is_array($this->keyName) && $key == $this->keyName) |
|
| 785 | - || (is_array($this->keyName) |
|
| 786 | - && in_array($key, $this->keyName))) { |
|
| 787 | - continue; |
|
| 788 | - } |
|
| 789 | - if (isset($notfirst)) { |
|
| 790 | - $sql .= ','; |
|
| 791 | - } |
|
| 792 | - $sql .= ' ' . $key . ' = ' . $value; |
|
| 793 | - $notfirst = true; |
|
| 794 | - } |
|
| 795 | - if (is_array($this->keyName)) { |
|
| 796 | - $whereclause = ''; |
|
| 797 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 798 | - if ($i > 0) { |
|
| 799 | - $whereclause .= ' AND '; |
|
| 800 | - } |
|
| 801 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 802 | - } |
|
| 803 | - } else { |
|
| 804 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 805 | - } |
|
| 806 | - $sql .= ' WHERE ' . $whereclause; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if ($debug) { |
|
| 810 | - xoops_debug($sql); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - if (false != $force) { |
|
| 814 | - $result = $this->db->queryF($sql); |
|
| 815 | - } else { |
|
| 816 | - $result = $this->db->query($sql); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - if (!$result) { |
|
| 820 | - $obj->setErrors($this->db->error()); |
|
| 821 | - |
|
| 822 | - return false; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - if ($obj->isNew() && !is_array($this->keyName)) { |
|
| 826 | - $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
| 827 | - } |
|
| 828 | - $eventResult = $this->executeEvent('afterSave', $obj); |
|
| 829 | - if (!$eventResult) { |
|
| 830 | - $obj->setErrors('An error occured during the AfterSave event'); |
|
| 831 | - |
|
| 832 | - return false; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - if ($obj->isNew()) { |
|
| 836 | - $obj->unsetNew(); |
|
| 837 | - $eventResult = $this->executeEvent('afterInsert', $obj); |
|
| 838 | - if (!$eventResult) { |
|
| 839 | - $obj->setErrors('An error occured during the AfterInsert event'); |
|
| 840 | - |
|
| 841 | - return false; |
|
| 842 | - } |
|
| 843 | - } else { |
|
| 844 | - $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
| 845 | - if (!$eventResult) { |
|
| 846 | - $obj->setErrors('An error occured during the AfterUpdate event'); |
|
| 847 | - |
|
| 848 | - return false; |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - return true; |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * @param $obj |
|
| 857 | - * @param bool $force |
|
| 858 | - * @param bool $checkObject |
|
| 859 | - * @param bool $debug |
|
| 860 | - * @return bool |
|
| 861 | - */ |
|
| 862 | - public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
| 863 | - { |
|
| 864 | - return $this->insert($obj, $force, $checkObject, true); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * Change a value for objects with a certain criteria |
|
| 869 | - * |
|
| 870 | - * @param string $fieldname Name of the field |
|
| 871 | - * @param string $fieldvalue Value to write |
|
| 872 | - * @param CriteriaElement $criteria {@link CriteriaElement} |
|
| 873 | - * |
|
| 874 | - * @param bool $force |
|
| 875 | - * @return bool |
|
| 876 | - */ |
|
| 877 | - public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
| 878 | - { |
|
| 879 | - $set_clause = $fieldname . ' = '; |
|
| 880 | - if (is_numeric($fieldvalue)) { |
|
| 881 | - $set_clause .= $fieldvalue; |
|
| 882 | - } elseif (is_array($fieldvalue)) { |
|
| 883 | - $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
| 884 | - } else { |
|
| 885 | - $set_clause .= $this->db->quoteString($fieldvalue); |
|
| 886 | - } |
|
| 887 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 888 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 889 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 890 | - } |
|
| 891 | - if (false != $force) { |
|
| 892 | - $result = $this->db->queryF($sql); |
|
| 893 | - } else { |
|
| 894 | - $result = $this->db->query($sql); |
|
| 895 | - } |
|
| 896 | - if (!$result) { |
|
| 897 | - return false; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - return true; |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * delete all objects meeting the conditions |
|
| 905 | - * |
|
| 906 | - * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
| 907 | - * @return bool |
|
| 908 | - */ |
|
| 909 | - |
|
| 910 | - public function deleteAll(CriteriaElement $criteria = null) |
|
| 911 | - { |
|
| 912 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 913 | - $sql = 'DELETE FROM ' . $this->table; |
|
| 914 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 915 | - if (!$this->db->query($sql)) { |
|
| 916 | - return false; |
|
| 917 | - } |
|
| 918 | - $rows = $this->db->getAffectedRows(); |
|
| 919 | - |
|
| 920 | - return $rows > 0 ? $rows : true; |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - return false; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * @return mixed |
|
| 928 | - */ |
|
| 929 | - public function getModuleInfo() |
|
| 930 | - { |
|
| 931 | - return smart_getModuleInfo($this->_moduleName); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * @return bool |
|
| 936 | - */ |
|
| 937 | - public function getModuleConfig() |
|
| 938 | - { |
|
| 939 | - return smart_getModuleConfig($this->_moduleName); |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * @return string |
|
| 944 | - */ |
|
| 945 | - public function getModuleItemString() |
|
| 946 | - { |
|
| 947 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 948 | - |
|
| 949 | - return $ret; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * @param $object |
|
| 954 | - */ |
|
| 955 | - public function updateCounter($object) |
|
| 956 | - { |
|
| 957 | - if (isset($object->vars['counter'])) { |
|
| 958 | - $new_counter = $object->getVar('counter') + 1; |
|
| 959 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 960 | - $this->query($sql, null, true); |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - /** |
|
| 965 | - * Execute the function associated with an event |
|
| 966 | - * This method will check if the function is available |
|
| 967 | - * |
|
| 968 | - * @param string $event name of the event |
|
| 969 | - * @param $executeEventObj |
|
| 970 | - * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
| 971 | - * @internal param object $obj $object on which is performed the event |
|
| 972 | - */ |
|
| 973 | - public function executeEvent($event, &$executeEventObj) |
|
| 974 | - { |
|
| 975 | - if (!in_array($event, $this->_disabledEvents)) { |
|
| 976 | - if (method_exists($this, $event)) { |
|
| 977 | - $ret = $this->$event($executeEventObj); |
|
| 978 | - } else { |
|
| 979 | - // check to see if there is a hook for this event |
|
| 980 | - if (isset($this->_eventHooks[$event])) { |
|
| 981 | - $method = $this->_eventHooks[$event]; |
|
| 982 | - // check to see if the method specified by this hook exists |
|
| 983 | - if (method_exists($this, $method)) { |
|
| 984 | - $ret = $this->$method($executeEventObj); |
|
| 985 | - } |
|
| 986 | - } |
|
| 987 | - $ret = true; |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - return $ret; |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - return true; |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - /** |
|
| 997 | - * @param bool $withprefix |
|
| 998 | - * @return string |
|
| 999 | - */ |
|
| 1000 | - public function getIdentifierName($withprefix = true) |
|
| 1001 | - { |
|
| 1002 | - if ($withprefix) { |
|
| 1003 | - return $this->_itemname . '.' . $this->identifierName; |
|
| 1004 | - } else { |
|
| 1005 | - return $this->identifierName; |
|
| 1006 | - } |
|
| 1007 | - } |
|
| 32 | + public $_itemname; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Name of the table use to store this {@link SmartObject} |
|
| 36 | + * |
|
| 37 | + * Note that the name of the table needs to be free of the database prefix. |
|
| 38 | + * For example "smartsection_categories" |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + public $table; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Name of the table key that uniquely identify each {@link SmartObject} |
|
| 45 | + * |
|
| 46 | + * For example: "categoryid" |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + public $keyName; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Name of the class derived from {@link SmartObject} and which this handler is handling |
|
| 53 | + * |
|
| 54 | + * Note that this string needs to be lowercase |
|
| 55 | + * |
|
| 56 | + * For example: "smartsectioncategory" |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + public $className; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Name of the field which properly identify the {@link SmartObject} |
|
| 63 | + * |
|
| 64 | + * For example: "name" (this will be the category's name) |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + public $identifierName; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Name of the field which will be use as a summary for the object |
|
| 71 | + * |
|
| 72 | + * For example: "summary" |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $summaryName; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Page name use to basically manage and display the {@link SmartObject} |
|
| 79 | + * |
|
| 80 | + * This page needs to be the same in user side and admin side |
|
| 81 | + * |
|
| 82 | + * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php |
|
| 83 | + * @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 |
|
| 84 | + * @var string |
|
| 85 | + */ |
|
| 86 | + public $_page; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Full path of the module using this {@link SmartObject} |
|
| 90 | + * |
|
| 91 | + * <code>XOOPS_URL . "/modules/smartsection/"</code> |
|
| 92 | + * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name |
|
| 93 | + * @var string |
|
| 94 | + */ |
|
| 95 | + public $_modulePath; |
|
| 96 | + |
|
| 97 | + public $_moduleUrl; |
|
| 98 | + |
|
| 99 | + public $_moduleName; |
|
| 100 | + |
|
| 101 | + public $_uploadUrl; |
|
| 102 | + |
|
| 103 | + public $_uploadPath; |
|
| 104 | + |
|
| 105 | + public $_allowedMimeTypes = 0; |
|
| 106 | + |
|
| 107 | + public $_maxFileSize = 1000000; |
|
| 108 | + |
|
| 109 | + public $_maxWidth = 500; |
|
| 110 | + |
|
| 111 | + public $_maxHeight = 500; |
|
| 112 | + |
|
| 113 | + public $highlightFields = []; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Array containing the events name and functions |
|
| 117 | + * |
|
| 118 | + * @var array |
|
| 119 | + */ |
|
| 120 | + public $eventArray = []; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Array containing the permissions that this handler will manage on the objects |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + public $permissionsArray = false; |
|
| 128 | + |
|
| 129 | + public $generalSQL = false; |
|
| 130 | + |
|
| 131 | + public $_eventHooks = []; |
|
| 132 | + public $_disabledEvents = []; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Constructor - called from child classes |
|
| 136 | + * |
|
| 137 | + * @param \XoopsDatabase $db {@link XoopsDatabase} |
|
| 138 | + * @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 |
|
| 139 | + * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
| 140 | + * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
| 141 | + * @param string $summaryName |
|
| 142 | + * @param string $modulename |
|
| 143 | + * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 144 | + * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
| 145 | + * @internal param string $moduleName name of the module |
|
| 146 | + */ |
|
| 147 | + public function __construct(\XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
| 148 | + { |
|
| 149 | + parent::__construct($db); |
|
| 150 | + |
|
| 151 | + $this->_itemname = $itemname; |
|
| 152 | + $this->_moduleName = $modulename; |
|
| 153 | + $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 154 | + $this->keyName = $keyname; |
|
| 155 | + $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 156 | + $this->identifierName = $idenfierName; |
|
| 157 | + $this->summaryName = $summaryName; |
|
| 158 | + $this->_page = $itemname . '.php'; |
|
| 159 | + $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 160 | + $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 161 | + $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 162 | + $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param $event |
|
| 167 | + * @param $method |
|
| 168 | + */ |
|
| 169 | + public function addEventHook($event, $method) |
|
| 170 | + { |
|
| 171 | + $this->_eventHooks[$event] = $method; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Add a permission that this handler will manage for its objects |
|
| 176 | + * |
|
| 177 | + * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
| 178 | + * |
|
| 179 | + * @param string $perm_name name of the permission |
|
| 180 | + * @param string $caption caption of the control that will be displayed in the form |
|
| 181 | + * @param bool|string $description description of the control that will be displayed in the form |
|
| 182 | + */ |
|
| 183 | + public function addPermission($perm_name, $caption, $description = false) |
|
| 184 | + { |
|
| 185 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
|
| 186 | + |
|
| 187 | + $this->permissionsArray[] = [ |
|
| 188 | + 'perm_name' => $perm_name, |
|
| 189 | + 'caption' => $caption, |
|
| 190 | + 'description' => $description |
|
| 191 | + ]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param $criteria |
|
| 196 | + * @param $perm_name |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function setGrantedObjectsCriteria($criteria, $perm_name) |
|
| 200 | + { |
|
| 201 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
|
| 202 | + $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
| 203 | + if (count($grantedItems) > 0) { |
|
| 204 | + $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 205 | + |
|
| 206 | + return true; |
|
| 207 | + } else { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @param bool $_uploadPath |
|
| 214 | + * @param bool $_allowedMimeTypes |
|
| 215 | + * @param bool $_maxFileSize |
|
| 216 | + * @param bool $_maxWidth |
|
| 217 | + * @param bool $_maxHeight |
|
| 218 | + */ |
|
| 219 | + public function setUploaderConfig( |
|
| 220 | + $_uploadPath = false, |
|
| 221 | + $_allowedMimeTypes = false, |
|
| 222 | + $_maxFileSize = false, |
|
| 223 | + $_maxWidth = false, |
|
| 224 | + $_maxHeight = false |
|
| 225 | + ) { |
|
| 226 | + $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
| 227 | + $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
| 228 | + $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
| 229 | + $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
| 230 | + $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * create a new {@link SmartObject} |
|
| 235 | + * |
|
| 236 | + * @param bool $isNew Flag the new objects as "new"? |
|
| 237 | + * |
|
| 238 | + * @return Smartobject\SmartObject {@link SmartObject} |
|
| 239 | + */ |
|
| 240 | + public function create($isNew = true) |
|
| 241 | + { |
|
| 242 | + $obj = new $this->className($this); |
|
| 243 | + $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
| 244 | + if (!$obj->handler) { |
|
| 245 | + $obj->Handler = $this; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if (true === $isNew) { |
|
| 249 | + $obj->setNew(); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return $obj; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function getImageUrl() |
|
| 259 | + { |
|
| 260 | + return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * @return string |
|
| 265 | + */ |
|
| 266 | + public function getImagePath() |
|
| 267 | + { |
|
| 268 | + $dir = $this->_uploadPath . $this->_itemname; |
|
| 269 | + if (!file_exists($dir)) { |
|
| 270 | + smart_admin_mkdir($dir); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + return $dir . '/'; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * retrieve a {@link SmartObject} |
|
| 278 | + * |
|
| 279 | + * @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 |
|
| 280 | + * @param bool $as_object whether to return an object or an array |
|
| 281 | + * @param bool $debug |
|
| 282 | + * @param bool $criteria |
|
| 283 | + * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
| 284 | + * FALSE if failed |
|
| 285 | + */ |
|
| 286 | + public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
| 287 | + { |
|
| 288 | + if (!$criteria) { |
|
| 289 | + $criteria = new \CriteriaCompo(); |
|
| 290 | + } |
|
| 291 | + if (is_array($this->keyName)) { |
|
| 292 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 293 | + /** |
|
| 294 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 295 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
| 296 | + */ |
|
| 297 | + //$criteria->add(new \Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
| 298 | + $criteria->add(new \Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
| 299 | + } |
|
| 300 | + } else { |
|
| 301 | + //$criteria = new \Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
| 302 | + /** |
|
| 303 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
| 304 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
| 305 | + */ |
|
| 306 | + $criteria->add(new \Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
| 307 | + } |
|
| 308 | + $criteria->setLimit(1); |
|
| 309 | + if ($debug) { |
|
| 310 | + $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
| 311 | + } else { |
|
| 312 | + $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
| 313 | + //patch: weird bug of indexing by id even if id_as_key = false; |
|
| 314 | + if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
| 315 | + $obj_array[0] = $obj_array[$id]; |
|
| 316 | + unset($obj_array[$id]); |
|
| 317 | + $obj_array[0]->unsetNew(); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + if (1 != count($obj_array)) { |
|
| 322 | + $obj = $this->create(); |
|
| 323 | + |
|
| 324 | + return $obj; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return $obj_array[0]; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * retrieve a {@link SmartObject} |
|
| 332 | + * |
|
| 333 | + * @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 |
|
| 334 | + * @param bool $as_object whether to return an object or an array |
|
| 335 | + * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
| 336 | + */ |
|
| 337 | + public function &getD($id, $as_object = true) |
|
| 338 | + { |
|
| 339 | + return $this->get($id, $as_object, true); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * retrieve objects from the database |
|
| 344 | + * |
|
| 345 | + * @param null|\CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 346 | + * @param bool $id_as_key use the ID as key for the array? |
|
| 347 | + * @param bool $as_object return an array of objects? |
|
| 348 | + * |
|
| 349 | + * @param bool $sql |
|
| 350 | + * @param bool $debug |
|
| 351 | + * @return array |
|
| 352 | + */ |
|
| 353 | + public function getObjects( |
|
| 354 | + \CriteriaElement $criteria = null, |
|
| 355 | + $id_as_key = false, |
|
| 356 | + $as_object = true, |
|
| 357 | + $sql = false, |
|
| 358 | + $debug = false |
|
| 359 | + ) { |
|
| 360 | + $ret = []; |
|
| 361 | + $limit = $start = 0; |
|
| 362 | + |
|
| 363 | + if ($this->generalSQL) { |
|
| 364 | + $sql = $this->generalSQL; |
|
| 365 | + } elseif (!$sql) { |
|
| 366 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 370 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 371 | + if ('' !== $criteria->getSort()) { |
|
| 372 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 373 | + } |
|
| 374 | + $limit = $criteria->getLimit(); |
|
| 375 | + $start = $criteria->getStart(); |
|
| 376 | + } |
|
| 377 | + if ($debug) { |
|
| 378 | + xoops_debug($sql); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + $result = $this->db->query($sql, $limit, $start); |
|
| 382 | + if (!$result) { |
|
| 383 | + return $ret; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + return $this->convertResultSet($result, $id_as_key, $as_object); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * @param $sql |
|
| 391 | + * @param $criteria |
|
| 392 | + * @param bool $force |
|
| 393 | + * @param bool $debug |
|
| 394 | + * @return array |
|
| 395 | + */ |
|
| 396 | + public function query($sql, $criteria, $force = false, $debug = false) |
|
| 397 | + { |
|
| 398 | + $ret = []; |
|
| 399 | + |
|
| 400 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 401 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 402 | + if ($criteria->groupby) { |
|
| 403 | + $sql .= $criteria->getGroupby(); |
|
| 404 | + } |
|
| 405 | + if ('' !== $criteria->getSort()) { |
|
| 406 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + if ($debug) { |
|
| 410 | + xoops_debug($sql); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + if ($force) { |
|
| 414 | + $result = $this->db->queryF($sql); |
|
| 415 | + } else { |
|
| 416 | + $result = $this->db->query($sql); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + if (!$result) { |
|
| 420 | + return $ret; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 424 | + $ret[] = $myrow; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + return $ret; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * retrieve objects with debug mode - so will show the query |
|
| 432 | + * |
|
| 433 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 434 | + * @param bool $id_as_key use the ID as key for the array? |
|
| 435 | + * @param bool $as_object return an array of objects? |
|
| 436 | + * |
|
| 437 | + * @param bool $sql |
|
| 438 | + * @return array |
|
| 439 | + */ |
|
| 440 | + public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
| 441 | + { |
|
| 442 | + return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * @param $arrayObjects |
|
| 447 | + * @return array|bool |
|
| 448 | + */ |
|
| 449 | + public function getObjectsAsArray($arrayObjects) |
|
| 450 | + { |
|
| 451 | + $ret = []; |
|
| 452 | + foreach ($arrayObjects as $key => $object) { |
|
| 453 | + $ret[$key] = $object->toArray(); |
|
| 454 | + } |
|
| 455 | + if (count($ret > 0)) { |
|
| 456 | + return $ret; |
|
| 457 | + } else { |
|
| 458 | + return false; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Convert a database resultset to a returnable array |
|
| 464 | + * |
|
| 465 | + * @param object $result database resultset |
|
| 466 | + * @param bool $id_as_key - should NOT be used with joint keys |
|
| 467 | + * @param bool $as_object |
|
| 468 | + * |
|
| 469 | + * @return array |
|
| 470 | + */ |
|
| 471 | + public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
| 472 | + { |
|
| 473 | + $ret = []; |
|
| 474 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 475 | + $obj = $this->create(false); |
|
| 476 | + $obj->assignVars($myrow); |
|
| 477 | + if (!$id_as_key) { |
|
| 478 | + if ($as_object) { |
|
| 479 | + $ret[] =& $obj; |
|
| 480 | + } else { |
|
| 481 | + $ret[] = $obj->toArray(); |
|
| 482 | + } |
|
| 483 | + } else { |
|
| 484 | + if ($as_object) { |
|
| 485 | + $value =& $obj; |
|
| 486 | + } else { |
|
| 487 | + $value = $obj->toArray(); |
|
| 488 | + } |
|
| 489 | + if ('parentid' === $id_as_key) { |
|
| 490 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 491 | + } else { |
|
| 492 | + $ret[$obj->getVar($this->keyName)] = $value; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + unset($obj); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + return $ret; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param null $criteria |
|
| 503 | + * @param int $limit |
|
| 504 | + * @param int $start |
|
| 505 | + * @return array |
|
| 506 | + */ |
|
| 507 | + public function getListD($criteria = null, $limit = 0, $start = 0) |
|
| 508 | + { |
|
| 509 | + return $this->getList($criteria, $limit, $start, true); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
| 514 | + * |
|
| 515 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
| 516 | + * @param int $limit Max number of objects to fetch |
|
| 517 | + * @param int $start Which record to start at |
|
| 518 | + * |
|
| 519 | + * @param bool $debug |
|
| 520 | + * @return array |
|
| 521 | + */ |
|
| 522 | + public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
| 523 | + { |
|
| 524 | + $ret = []; |
|
| 525 | + if (null === $criteria) { |
|
| 526 | + $criteria = new \CriteriaCompo(); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + if ('' === $criteria->getSort()) { |
|
| 530 | + $criteria->setSort($this->getIdentifierName()); |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 534 | + if (!empty($this->identifierName)) { |
|
| 535 | + $sql .= ', ' . $this->getIdentifierName(); |
|
| 536 | + } |
|
| 537 | + $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 538 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 539 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 540 | + if ('' !== $criteria->getSort()) { |
|
| 541 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 542 | + } |
|
| 543 | + $limit = $criteria->getLimit(); |
|
| 544 | + $start = $criteria->getStart(); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + if ($debug) { |
|
| 548 | + xoops_debug($sql); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $result = $this->db->query($sql, $limit, $start); |
|
| 552 | + if (!$result) { |
|
| 553 | + return $ret; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 557 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
| 558 | + //identifiers should be textboxes, so sanitize them like that |
|
| 559 | + $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return $ret; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * count objects matching a condition |
|
| 567 | + * |
|
| 568 | + * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
| 569 | + * @return int count of objects |
|
| 570 | + */ |
|
| 571 | + public function getCount(CriteriaElement $criteria = null) |
|
| 572 | + { |
|
| 573 | + $field = ''; |
|
| 574 | + $groupby = false; |
|
| 575 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 576 | + if ('' !== $criteria->groupby) { |
|
| 577 | + $groupby = true; |
|
| 578 | + $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + /** |
|
| 582 | + * if we have a generalSQL, lets used this one. |
|
| 583 | + * This needs to be improved... |
|
| 584 | + */ |
|
| 585 | + if ($this->generalSQL) { |
|
| 586 | + $sql = $this->generalSQL; |
|
| 587 | + $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
| 588 | + } else { |
|
| 589 | + $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 590 | + } |
|
| 591 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 592 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 593 | + if ('' !== $criteria->groupby) { |
|
| 594 | + $sql .= $criteria->getGroupby(); |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + $result = $this->db->query($sql); |
|
| 599 | + if (!$result) { |
|
| 600 | + return 0; |
|
| 601 | + } |
|
| 602 | + if (false === $groupby) { |
|
| 603 | + list($count) = $this->db->fetchRow($result); |
|
| 604 | + |
|
| 605 | + return $count; |
|
| 606 | + } else { |
|
| 607 | + $ret = []; |
|
| 608 | + while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
| 609 | + $ret[$id] = $count; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + return $ret; |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * delete an object from the database |
|
| 618 | + * |
|
| 619 | + * @param \XoopsObject $obj reference to the object to delete |
|
| 620 | + * @param bool $force |
|
| 621 | + * @return bool FALSE if failed. |
|
| 622 | + */ |
|
| 623 | + public function delete(\XoopsObject $obj, $force = false) |
|
| 624 | + { |
|
| 625 | + $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
| 626 | + if (!$eventResult) { |
|
| 627 | + $obj->setErrors('An error occured during the BeforeDelete event'); |
|
| 628 | + |
|
| 629 | + return false; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + if (is_array($this->keyName)) { |
|
| 633 | + $clause = []; |
|
| 634 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 635 | + $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 636 | + } |
|
| 637 | + $whereclause = implode(' AND ', $clause); |
|
| 638 | + } else { |
|
| 639 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 640 | + } |
|
| 641 | + $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 642 | + if (false !== $force) { |
|
| 643 | + $result = $this->db->queryF($sql); |
|
| 644 | + } else { |
|
| 645 | + $result = $this->db->query($sql); |
|
| 646 | + } |
|
| 647 | + if (!$result) { |
|
| 648 | + return false; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + $eventResult = $this->executeEvent('afterDelete', $obj); |
|
| 652 | + if (!$eventResult) { |
|
| 653 | + $obj->setErrors('An error occured during the AfterDelete event'); |
|
| 654 | + |
|
| 655 | + return false; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + return true; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param $event |
|
| 663 | + */ |
|
| 664 | + public function disableEvent($event) |
|
| 665 | + { |
|
| 666 | + if (is_array($event)) { |
|
| 667 | + foreach ($event as $v) { |
|
| 668 | + $this->_disabledEvents[] = $v; |
|
| 669 | + } |
|
| 670 | + } else { |
|
| 671 | + $this->_disabledEvents[] = $event; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * @return array |
|
| 677 | + */ |
|
| 678 | + public function getPermissions() |
|
| 679 | + { |
|
| 680 | + return $this->permissionsArray; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * insert a new object in the database |
|
| 685 | + * |
|
| 686 | + * @param \XoopsObject $obj reference to the object |
|
| 687 | + * @param bool $force whether to force the query execution despite security settings |
|
| 688 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
| 689 | + * @param bool $debug |
|
| 690 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 691 | + */ |
|
| 692 | + public function insert(\XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
| 693 | + { |
|
| 694 | + if (false !== $checkObject) { |
|
| 695 | + if (!is_object($obj)) { |
|
| 696 | + return false; |
|
| 697 | + } |
|
| 698 | + /** |
|
| 699 | + * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
| 700 | + */ |
|
| 701 | + if (!is_a($obj, $this->className)) { |
|
| 702 | + $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 703 | + |
|
| 704 | + return false; |
|
| 705 | + } |
|
| 706 | + if (!$obj->isDirty()) { |
|
| 707 | + $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 |
|
| 708 | + |
|
| 709 | + return true; |
|
| 710 | + } |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + if ($obj->seoEnabled) { |
|
| 714 | + // Auto create meta tags if empty |
|
| 715 | + $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
| 716 | + |
|
| 717 | + if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
| 718 | + if (!$obj->meta_keywords()) { |
|
| 719 | + $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + if (!$obj->meta_description()) { |
|
| 723 | + $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + // Auto create short_url if empty |
|
| 728 | + if (!$obj->short_url()) { |
|
| 729 | + $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
| 730 | + } |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + $eventResult = $this->executeEvent('beforeSave', $obj); |
|
| 734 | + if (!$eventResult) { |
|
| 735 | + $obj->setErrors('An error occured during the BeforeSave event'); |
|
| 736 | + |
|
| 737 | + return false; |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + if ($obj->isNew()) { |
|
| 741 | + $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
| 742 | + if (!$eventResult) { |
|
| 743 | + $obj->setErrors('An error occured during the BeforeInsert event'); |
|
| 744 | + |
|
| 745 | + return false; |
|
| 746 | + } |
|
| 747 | + } else { |
|
| 748 | + $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
| 749 | + if (!$eventResult) { |
|
| 750 | + $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
| 751 | + |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + if (!$obj->cleanVars()) { |
|
| 756 | + $obj->setErrors('Variables were not cleaned properly.'); |
|
| 757 | + |
|
| 758 | + return false; |
|
| 759 | + } |
|
| 760 | + $fieldsToStoreInDB = []; |
|
| 761 | + foreach ($obj->cleanVars as $k => $v) { |
|
| 762 | + if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) { |
|
| 763 | + $cleanvars[$k] = (int)$v; |
|
| 764 | + } elseif (is_array($v)) { |
|
| 765 | + $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
| 766 | + } else { |
|
| 767 | + $cleanvars[$k] = $this->db->quoteString($v); |
|
| 768 | + } |
|
| 769 | + if ($obj->vars[$k]['persistent']) { |
|
| 770 | + $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + if ($obj->isNew()) { |
|
| 774 | + if (!is_array($this->keyName)) { |
|
| 775 | + if ($cleanvars[$this->keyName] < 1) { |
|
| 776 | + $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 781 | + } else { |
|
| 782 | + $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 783 | + foreach ($fieldsToStoreInDB as $key => $value) { |
|
| 784 | + if ((!is_array($this->keyName) && $key == $this->keyName) |
|
| 785 | + || (is_array($this->keyName) |
|
| 786 | + && in_array($key, $this->keyName))) { |
|
| 787 | + continue; |
|
| 788 | + } |
|
| 789 | + if (isset($notfirst)) { |
|
| 790 | + $sql .= ','; |
|
| 791 | + } |
|
| 792 | + $sql .= ' ' . $key . ' = ' . $value; |
|
| 793 | + $notfirst = true; |
|
| 794 | + } |
|
| 795 | + if (is_array($this->keyName)) { |
|
| 796 | + $whereclause = ''; |
|
| 797 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
| 798 | + if ($i > 0) { |
|
| 799 | + $whereclause .= ' AND '; |
|
| 800 | + } |
|
| 801 | + $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 802 | + } |
|
| 803 | + } else { |
|
| 804 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 805 | + } |
|
| 806 | + $sql .= ' WHERE ' . $whereclause; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if ($debug) { |
|
| 810 | + xoops_debug($sql); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + if (false != $force) { |
|
| 814 | + $result = $this->db->queryF($sql); |
|
| 815 | + } else { |
|
| 816 | + $result = $this->db->query($sql); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + if (!$result) { |
|
| 820 | + $obj->setErrors($this->db->error()); |
|
| 821 | + |
|
| 822 | + return false; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + if ($obj->isNew() && !is_array($this->keyName)) { |
|
| 826 | + $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
| 827 | + } |
|
| 828 | + $eventResult = $this->executeEvent('afterSave', $obj); |
|
| 829 | + if (!$eventResult) { |
|
| 830 | + $obj->setErrors('An error occured during the AfterSave event'); |
|
| 831 | + |
|
| 832 | + return false; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + if ($obj->isNew()) { |
|
| 836 | + $obj->unsetNew(); |
|
| 837 | + $eventResult = $this->executeEvent('afterInsert', $obj); |
|
| 838 | + if (!$eventResult) { |
|
| 839 | + $obj->setErrors('An error occured during the AfterInsert event'); |
|
| 840 | + |
|
| 841 | + return false; |
|
| 842 | + } |
|
| 843 | + } else { |
|
| 844 | + $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
| 845 | + if (!$eventResult) { |
|
| 846 | + $obj->setErrors('An error occured during the AfterUpdate event'); |
|
| 847 | + |
|
| 848 | + return false; |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + return true; |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * @param $obj |
|
| 857 | + * @param bool $force |
|
| 858 | + * @param bool $checkObject |
|
| 859 | + * @param bool $debug |
|
| 860 | + * @return bool |
|
| 861 | + */ |
|
| 862 | + public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
| 863 | + { |
|
| 864 | + return $this->insert($obj, $force, $checkObject, true); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * Change a value for objects with a certain criteria |
|
| 869 | + * |
|
| 870 | + * @param string $fieldname Name of the field |
|
| 871 | + * @param string $fieldvalue Value to write |
|
| 872 | + * @param CriteriaElement $criteria {@link CriteriaElement} |
|
| 873 | + * |
|
| 874 | + * @param bool $force |
|
| 875 | + * @return bool |
|
| 876 | + */ |
|
| 877 | + public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
| 878 | + { |
|
| 879 | + $set_clause = $fieldname . ' = '; |
|
| 880 | + if (is_numeric($fieldvalue)) { |
|
| 881 | + $set_clause .= $fieldvalue; |
|
| 882 | + } elseif (is_array($fieldvalue)) { |
|
| 883 | + $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
| 884 | + } else { |
|
| 885 | + $set_clause .= $this->db->quoteString($fieldvalue); |
|
| 886 | + } |
|
| 887 | + $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 888 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 889 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 890 | + } |
|
| 891 | + if (false != $force) { |
|
| 892 | + $result = $this->db->queryF($sql); |
|
| 893 | + } else { |
|
| 894 | + $result = $this->db->query($sql); |
|
| 895 | + } |
|
| 896 | + if (!$result) { |
|
| 897 | + return false; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + return true; |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * delete all objects meeting the conditions |
|
| 905 | + * |
|
| 906 | + * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
| 907 | + * @return bool |
|
| 908 | + */ |
|
| 909 | + |
|
| 910 | + public function deleteAll(CriteriaElement $criteria = null) |
|
| 911 | + { |
|
| 912 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
| 913 | + $sql = 'DELETE FROM ' . $this->table; |
|
| 914 | + $sql .= ' ' . $criteria->renderWhere(); |
|
| 915 | + if (!$this->db->query($sql)) { |
|
| 916 | + return false; |
|
| 917 | + } |
|
| 918 | + $rows = $this->db->getAffectedRows(); |
|
| 919 | + |
|
| 920 | + return $rows > 0 ? $rows : true; |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + return false; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * @return mixed |
|
| 928 | + */ |
|
| 929 | + public function getModuleInfo() |
|
| 930 | + { |
|
| 931 | + return smart_getModuleInfo($this->_moduleName); |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * @return bool |
|
| 936 | + */ |
|
| 937 | + public function getModuleConfig() |
|
| 938 | + { |
|
| 939 | + return smart_getModuleConfig($this->_moduleName); |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * @return string |
|
| 944 | + */ |
|
| 945 | + public function getModuleItemString() |
|
| 946 | + { |
|
| 947 | + $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 948 | + |
|
| 949 | + return $ret; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * @param $object |
|
| 954 | + */ |
|
| 955 | + public function updateCounter($object) |
|
| 956 | + { |
|
| 957 | + if (isset($object->vars['counter'])) { |
|
| 958 | + $new_counter = $object->getVar('counter') + 1; |
|
| 959 | + $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 960 | + $this->query($sql, null, true); |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + /** |
|
| 965 | + * Execute the function associated with an event |
|
| 966 | + * This method will check if the function is available |
|
| 967 | + * |
|
| 968 | + * @param string $event name of the event |
|
| 969 | + * @param $executeEventObj |
|
| 970 | + * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
| 971 | + * @internal param object $obj $object on which is performed the event |
|
| 972 | + */ |
|
| 973 | + public function executeEvent($event, &$executeEventObj) |
|
| 974 | + { |
|
| 975 | + if (!in_array($event, $this->_disabledEvents)) { |
|
| 976 | + if (method_exists($this, $event)) { |
|
| 977 | + $ret = $this->$event($executeEventObj); |
|
| 978 | + } else { |
|
| 979 | + // check to see if there is a hook for this event |
|
| 980 | + if (isset($this->_eventHooks[$event])) { |
|
| 981 | + $method = $this->_eventHooks[$event]; |
|
| 982 | + // check to see if the method specified by this hook exists |
|
| 983 | + if (method_exists($this, $method)) { |
|
| 984 | + $ret = $this->$method($executeEventObj); |
|
| 985 | + } |
|
| 986 | + } |
|
| 987 | + $ret = true; |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + return $ret; |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + return true; |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * @param bool $withprefix |
|
| 998 | + * @return string |
|
| 999 | + */ |
|
| 1000 | + public function getIdentifierName($withprefix = true) |
|
| 1001 | + { |
|
| 1002 | + if ($withprefix) { |
|
| 1003 | + return $this->_itemname . '.' . $this->identifierName; |
|
| 1004 | + } else { |
|
| 1005 | + return $this->identifierName; |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1008 | 1008 | } |
@@ -150,16 +150,16 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | $this->_itemname = $itemname; |
| 152 | 152 | $this->_moduleName = $modulename; |
| 153 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
| 153 | + $this->table = $db->prefix($modulename.'_'.$itemname); |
|
| 154 | 154 | $this->keyName = $keyname; |
| 155 | - $this->className = ucfirst($modulename) . ucfirst($itemname); |
|
| 155 | + $this->className = ucfirst($modulename).ucfirst($itemname); |
|
| 156 | 156 | $this->identifierName = $idenfierName; |
| 157 | 157 | $this->summaryName = $summaryName; |
| 158 | - $this->_page = $itemname . '.php'; |
|
| 159 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
| 160 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
| 161 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
| 162 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
| 158 | + $this->_page = $itemname.'.php'; |
|
| 159 | + $this->_modulePath = XOOPS_ROOT_PATH.'/modules/'.$this->_moduleName.'/'; |
|
| 160 | + $this->_moduleUrl = XOOPS_URL.'/modules/'.$this->_moduleName.'/'; |
|
| 161 | + $this->_uploadPath = XOOPS_UPLOAD_PATH.'/'.$this->_moduleName.'/'; |
|
| 162 | + $this->_uploadUrl = XOOPS_UPLOAD_URL.'/'.$this->_moduleName.'/'; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function addPermission($perm_name, $caption, $description = false) |
| 184 | 184 | { |
| 185 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
|
| 185 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectpermission.php'; |
|
| 186 | 186 | |
| 187 | 187 | $this->permissionsArray[] = [ |
| 188 | 188 | 'perm_name' => $perm_name, |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
| 202 | 202 | $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
| 203 | 203 | if (count($grantedItems) > 0) { |
| 204 | - $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
| 204 | + $criteria->add(new \Criteria($this->keyName, '('.implode(', ', $grantedItems).')', 'IN')); |
|
| 205 | 205 | |
| 206 | 206 | return true; |
| 207 | 207 | } else { |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function getImageUrl() |
| 259 | 259 | { |
| 260 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
| 260 | + return $this->_uploadUrl.$this->_itemname.'/'; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | public function getImagePath() |
| 267 | 267 | { |
| 268 | - $dir = $this->_uploadPath . $this->_itemname; |
|
| 268 | + $dir = $this->_uploadPath.$this->_itemname; |
|
| 269 | 269 | if (!file_exists($dir)) { |
| 270 | 270 | smart_admin_mkdir($dir); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - return $dir . '/'; |
|
| 273 | + return $dir.'/'; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | if ($debug) { |
| 310 | 310 | $obj_array = $this->getObjectsD($criteria, false, $as_object); |
| 311 | 311 | } else { |
| 312 | - $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
| 312 | + $obj_array = & $this->getObjects($criteria, false, $as_object); |
|
| 313 | 313 | //patch: weird bug of indexing by id even if id_as_key = false; |
| 314 | 314 | if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
| 315 | 315 | $obj_array[0] = $obj_array[$id]; |
@@ -363,13 +363,13 @@ discard block |
||
| 363 | 363 | if ($this->generalSQL) { |
| 364 | 364 | $sql = $this->generalSQL; |
| 365 | 365 | } elseif (!$sql) { |
| 366 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 366 | + $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
| 370 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 370 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 371 | 371 | if ('' !== $criteria->getSort()) { |
| 372 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 372 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
| 373 | 373 | } |
| 374 | 374 | $limit = $criteria->getLimit(); |
| 375 | 375 | $start = $criteria->getStart(); |
@@ -398,12 +398,12 @@ discard block |
||
| 398 | 398 | $ret = []; |
| 399 | 399 | |
| 400 | 400 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
| 401 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 401 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 402 | 402 | if ($criteria->groupby) { |
| 403 | 403 | $sql .= $criteria->getGroupby(); |
| 404 | 404 | } |
| 405 | 405 | if ('' !== $criteria->getSort()) { |
| 406 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 406 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | if ($debug) { |
@@ -476,18 +476,18 @@ discard block |
||
| 476 | 476 | $obj->assignVars($myrow); |
| 477 | 477 | if (!$id_as_key) { |
| 478 | 478 | if ($as_object) { |
| 479 | - $ret[] =& $obj; |
|
| 479 | + $ret[] = & $obj; |
|
| 480 | 480 | } else { |
| 481 | 481 | $ret[] = $obj->toArray(); |
| 482 | 482 | } |
| 483 | 483 | } else { |
| 484 | 484 | if ($as_object) { |
| 485 | - $value =& $obj; |
|
| 485 | + $value = & $obj; |
|
| 486 | 486 | } else { |
| 487 | 487 | $value = $obj->toArray(); |
| 488 | 488 | } |
| 489 | 489 | if ('parentid' === $id_as_key) { |
| 490 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
| 490 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value; |
|
| 491 | 491 | } else { |
| 492 | 492 | $ret[$obj->getVar($this->keyName)] = $value; |
| 493 | 493 | } |
@@ -530,15 +530,15 @@ discard block |
||
| 530 | 530 | $criteria->setSort($this->getIdentifierName()); |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 533 | + $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
| 534 | 534 | if (!empty($this->identifierName)) { |
| 535 | - $sql .= ', ' . $this->getIdentifierName(); |
|
| 535 | + $sql .= ', '.$this->getIdentifierName(); |
|
| 536 | 536 | } |
| 537 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 537 | + $sql .= ' FROM '.$this->table.' AS '.$this->_itemname; |
|
| 538 | 538 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
| 539 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 539 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 540 | 540 | if ('' !== $criteria->getSort()) { |
| 541 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
| 541 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
| 542 | 542 | } |
| 543 | 543 | $limit = $criteria->getLimit(); |
| 544 | 544 | $start = $criteria->getStart(); |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
| 576 | 576 | if ('' !== $criteria->groupby) { |
| 577 | 577 | $groupby = true; |
| 578 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 578 | + $field = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | /** |
@@ -586,10 +586,10 @@ discard block |
||
| 586 | 586 | $sql = $this->generalSQL; |
| 587 | 587 | $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
| 588 | 588 | } else { |
| 589 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
| 589 | + $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table.' AS '.$this->_itemname; |
|
| 590 | 590 | } |
| 591 | 591 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
| 592 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 592 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 593 | 593 | if ('' !== $criteria->groupby) { |
| 594 | 594 | $sql .= $criteria->getGroupby(); |
| 595 | 595 | } |
@@ -632,13 +632,13 @@ discard block |
||
| 632 | 632 | if (is_array($this->keyName)) { |
| 633 | 633 | $clause = []; |
| 634 | 634 | for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
| 635 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 635 | + $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]); |
|
| 636 | 636 | } |
| 637 | 637 | $whereclause = implode(' AND ', $clause); |
| 638 | 638 | } else { |
| 639 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 639 | + $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName); |
|
| 640 | 640 | } |
| 641 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
| 641 | + $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause; |
|
| 642 | 642 | if (false !== $force) { |
| 643 | 643 | $result = $this->db->queryF($sql); |
| 644 | 644 | } else { |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
| 700 | 700 | */ |
| 701 | 701 | if (!is_a($obj, $this->className)) { |
| 702 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
| 702 | + $obj->setError(get_class($obj).' Differs from '.$this->className); |
|
| 703 | 703 | |
| 704 | 704 | return false; |
| 705 | 705 | } |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | $fieldsToStoreInDB = []; |
| 761 | 761 | foreach ($obj->cleanVars as $k => $v) { |
| 762 | 762 | if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) { |
| 763 | - $cleanvars[$k] = (int)$v; |
|
| 763 | + $cleanvars[$k] = (int) $v; |
|
| 764 | 764 | } elseif (is_array($v)) { |
| 765 | 765 | $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
| 766 | 766 | } else { |
@@ -773,13 +773,13 @@ discard block |
||
| 773 | 773 | if ($obj->isNew()) { |
| 774 | 774 | if (!is_array($this->keyName)) { |
| 775 | 775 | if ($cleanvars[$this->keyName] < 1) { |
| 776 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
| 776 | + $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq'); |
|
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
| 780 | + $sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($fieldsToStoreInDB)).') VALUES ('.implode(',', array_values($fieldsToStoreInDB)).')'; |
|
| 781 | 781 | } else { |
| 782 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
| 782 | + $sql = 'UPDATE '.$this->table.' SET'; |
|
| 783 | 783 | foreach ($fieldsToStoreInDB as $key => $value) { |
| 784 | 784 | if ((!is_array($this->keyName) && $key == $this->keyName) |
| 785 | 785 | || (is_array($this->keyName) |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | if (isset($notfirst)) { |
| 790 | 790 | $sql .= ','; |
| 791 | 791 | } |
| 792 | - $sql .= ' ' . $key . ' = ' . $value; |
|
| 792 | + $sql .= ' '.$key.' = '.$value; |
|
| 793 | 793 | $notfirst = true; |
| 794 | 794 | } |
| 795 | 795 | if (is_array($this->keyName)) { |
@@ -798,12 +798,12 @@ discard block |
||
| 798 | 798 | if ($i > 0) { |
| 799 | 799 | $whereclause .= ' AND '; |
| 800 | 800 | } |
| 801 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
| 801 | + $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]); |
|
| 802 | 802 | } |
| 803 | 803 | } else { |
| 804 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
| 804 | + $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName); |
|
| 805 | 805 | } |
| 806 | - $sql .= ' WHERE ' . $whereclause; |
|
| 806 | + $sql .= ' WHERE '.$whereclause; |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | if ($debug) { |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | */ |
| 877 | 877 | public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
| 878 | 878 | { |
| 879 | - $set_clause = $fieldname . ' = '; |
|
| 879 | + $set_clause = $fieldname.' = '; |
|
| 880 | 880 | if (is_numeric($fieldvalue)) { |
| 881 | 881 | $set_clause .= $fieldvalue; |
| 882 | 882 | } elseif (is_array($fieldvalue)) { |
@@ -884,9 +884,9 @@ discard block |
||
| 884 | 884 | } else { |
| 885 | 885 | $set_clause .= $this->db->quoteString($fieldvalue); |
| 886 | 886 | } |
| 887 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
| 887 | + $sql = 'UPDATE '.$this->table.' SET '.$set_clause; |
|
| 888 | 888 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
| 889 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 889 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 890 | 890 | } |
| 891 | 891 | if (false != $force) { |
| 892 | 892 | $result = $this->db->queryF($sql); |
@@ -910,8 +910,8 @@ discard block |
||
| 910 | 910 | public function deleteAll(CriteriaElement $criteria = null) |
| 911 | 911 | { |
| 912 | 912 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
| 913 | - $sql = 'DELETE FROM ' . $this->table; |
|
| 914 | - $sql .= ' ' . $criteria->renderWhere(); |
|
| 913 | + $sql = 'DELETE FROM '.$this->table; |
|
| 914 | + $sql .= ' '.$criteria->renderWhere(); |
|
| 915 | 915 | if (!$this->db->query($sql)) { |
| 916 | 916 | return false; |
| 917 | 917 | } |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | */ |
| 945 | 945 | public function getModuleItemString() |
| 946 | 946 | { |
| 947 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
| 947 | + $ret = $this->_moduleName.'_'.$this->_itemname; |
|
| 948 | 948 | |
| 949 | 949 | return $ret; |
| 950 | 950 | } |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | { |
| 957 | 957 | if (isset($object->vars['counter'])) { |
| 958 | 958 | $new_counter = $object->getVar('counter') + 1; |
| 959 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
| 959 | + $sql = 'UPDATE '.$this->table.' SET counter='.$new_counter.' WHERE '.$this->keyName.'='.$object->id(); |
|
| 960 | 960 | $this->query($sql, null, true); |
| 961 | 961 | } |
| 962 | 962 | } |
@@ -1000,7 +1000,7 @@ discard block |
||
| 1000 | 1000 | public function getIdentifierName($withprefix = true) |
| 1001 | 1001 | { |
| 1002 | 1002 | if ($withprefix) { |
| 1003 | - return $this->_itemname . '.' . $this->identifierName; |
|
| 1003 | + return $this->_itemname.'.'.$this->identifierName; |
|
| 1004 | 1004 | } else { |
| 1005 | 1005 | return $this->identifierName; |
| 1006 | 1006 | } |
@@ -196,7 +196,7 @@ |
||
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | - * @param $name |
|
| 199 | + * @param string $name |
|
| 200 | 200 | * @param string $extension |
| 201 | 201 | * @return array |
| 202 | 202 | */ |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | $xoopsLogger->activated = false; |
| 11 | 11 | |
| 12 | 12 | if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', $_SERVER['HTTP_REFERER'])) { |
| 13 | - exit(); |
|
| 13 | + exit(); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -18,192 +18,192 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class XoopsCaptchaImageHandler |
| 20 | 20 | { |
| 21 | - public $config = []; |
|
| 22 | - //var $mode = "gd"; // GD or bmp |
|
| 23 | - public $code; |
|
| 24 | - public $invalid = false; |
|
| 25 | - |
|
| 26 | - public $font; |
|
| 27 | - public $spacing; |
|
| 28 | - public $width; |
|
| 29 | - public $height; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * XoopsCaptchaImageHandler constructor. |
|
| 33 | - */ |
|
| 34 | - public function __construct() |
|
| 35 | - { |
|
| 36 | - if (empty($_SESSION['XoopsCaptcha_name'])) { |
|
| 37 | - $this->invalid = true; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (!extension_loaded('gd')) { |
|
| 41 | - $this->mode = 'bmp'; |
|
| 42 | - } else { |
|
| 43 | - $required_functions = [ |
|
| 44 | - 'imagecreatetruecolor', |
|
| 45 | - 'imagecolorallocate', |
|
| 46 | - 'imagefilledrectangle', |
|
| 47 | - 'imagejpeg', |
|
| 48 | - 'imagedestroy', |
|
| 49 | - 'imageftbbox' |
|
| 50 | - ]; |
|
| 51 | - foreach ($required_functions as $func) { |
|
| 52 | - if (!function_exists($func)) { |
|
| 53 | - $this->mode = 'bmp'; |
|
| 54 | - break; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Loading configs from CAPTCHA class |
|
| 62 | - * @param array $config |
|
| 63 | - */ |
|
| 64 | - public function setConfig($config = []) |
|
| 65 | - { |
|
| 66 | - // Loading default preferences |
|
| 67 | - $this->config = $config; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function loadImage() |
|
| 71 | - { |
|
| 72 | - $this->createCode(); |
|
| 73 | - $this->setCode(); |
|
| 74 | - $this->createImage(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Create Code |
|
| 79 | - */ |
|
| 80 | - public function createCode() |
|
| 81 | - { |
|
| 82 | - if ($this->invalid) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ('bmp' === $this->mode) { |
|
| 87 | - $this->config['num_chars'] = 4; |
|
| 88 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
| 89 | - } else { |
|
| 90 | - $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
| 91 | - if (!$this->config['casesensitive']) { |
|
| 92 | - $this->code = strtoupper($this->code); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function setCode() |
|
| 98 | - { |
|
| 99 | - if ($this->invalid) { |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 104 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 105 | - |
|
| 106 | - // Increase the attempt records on refresh |
|
| 107 | - if (!empty($maxAttempts)) { |
|
| 108 | - $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
| 109 | - if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
| 110 | - $this->invalid = true; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param string $file |
|
| 117 | - * @return string|void |
|
| 118 | - */ |
|
| 119 | - public function createImage($file = '') |
|
| 120 | - { |
|
| 121 | - if ($this->invalid) { |
|
| 122 | - header('Content-type: image/gif'); |
|
| 123 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
| 124 | - |
|
| 125 | - return; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ('bmp' === $this->mode) { |
|
| 129 | - return $this->createImageBmp(); |
|
| 130 | - } else { |
|
| 131 | - return $this->createImageGd(); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Create CAPTCHA iamge with GD |
|
| 137 | - * Originated from DuGris' SecurityImage |
|
| 138 | - * @param string $file |
|
| 139 | - */ |
|
| 140 | - // --------------------------------------------------------------------------- // |
|
| 141 | - // Class: SecurityImage 1.5 // |
|
| 142 | - // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
| 143 | - // Email: [email protected] // |
|
| 144 | - // Licence: GNU // |
|
| 145 | - // Project: XOOPS Project // |
|
| 146 | - // --------------------------------------------------------------------------- // |
|
| 147 | - public function createImageGd($file = '') |
|
| 148 | - { |
|
| 149 | - $this->loadFont(); |
|
| 150 | - $this->setImageSize(); |
|
| 151 | - |
|
| 152 | - $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
| 153 | - $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
| 154 | - imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
| 155 | - |
|
| 156 | - switch ($this->config['background_type']) { |
|
| 157 | - default: |
|
| 158 | - case 0: |
|
| 159 | - $this->drawBars(); |
|
| 160 | - break; |
|
| 161 | - |
|
| 162 | - case 1: |
|
| 163 | - $this->drawCircles(); |
|
| 164 | - break; |
|
| 165 | - |
|
| 166 | - case 2: |
|
| 167 | - $this->drawLines(); |
|
| 168 | - break; |
|
| 169 | - |
|
| 170 | - case 3: |
|
| 171 | - $this->drawRectangles(); |
|
| 172 | - break; |
|
| 173 | - |
|
| 174 | - case 4: |
|
| 175 | - $this->drawEllipses(); |
|
| 176 | - break; |
|
| 177 | - |
|
| 178 | - case 5: |
|
| 179 | - $this->drawPolygons(); |
|
| 180 | - break; |
|
| 181 | - |
|
| 182 | - case 100: |
|
| 183 | - $this->createFromFile(); |
|
| 184 | - break; |
|
| 185 | - } |
|
| 186 | - $this->drawBorder(); |
|
| 187 | - $this->drawCode(); |
|
| 188 | - |
|
| 189 | - if (empty($file)) { |
|
| 190 | - header('Content-type: image/jpeg'); |
|
| 191 | - imagejpeg($this->oImage); |
|
| 192 | - } else { |
|
| 193 | - imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
| 194 | - } |
|
| 195 | - imagedestroy($this->oImage); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * @param $name |
|
| 200 | - * @param string $extension |
|
| 201 | - * @return array |
|
| 202 | - */ |
|
| 203 | - public function _getList($name, $extension = '') |
|
| 204 | - { |
|
| 205 | - $items = []; |
|
| 206 | - /* |
|
| 21 | + public $config = []; |
|
| 22 | + //var $mode = "gd"; // GD or bmp |
|
| 23 | + public $code; |
|
| 24 | + public $invalid = false; |
|
| 25 | + |
|
| 26 | + public $font; |
|
| 27 | + public $spacing; |
|
| 28 | + public $width; |
|
| 29 | + public $height; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * XoopsCaptchaImageHandler constructor. |
|
| 33 | + */ |
|
| 34 | + public function __construct() |
|
| 35 | + { |
|
| 36 | + if (empty($_SESSION['XoopsCaptcha_name'])) { |
|
| 37 | + $this->invalid = true; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (!extension_loaded('gd')) { |
|
| 41 | + $this->mode = 'bmp'; |
|
| 42 | + } else { |
|
| 43 | + $required_functions = [ |
|
| 44 | + 'imagecreatetruecolor', |
|
| 45 | + 'imagecolorallocate', |
|
| 46 | + 'imagefilledrectangle', |
|
| 47 | + 'imagejpeg', |
|
| 48 | + 'imagedestroy', |
|
| 49 | + 'imageftbbox' |
|
| 50 | + ]; |
|
| 51 | + foreach ($required_functions as $func) { |
|
| 52 | + if (!function_exists($func)) { |
|
| 53 | + $this->mode = 'bmp'; |
|
| 54 | + break; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Loading configs from CAPTCHA class |
|
| 62 | + * @param array $config |
|
| 63 | + */ |
|
| 64 | + public function setConfig($config = []) |
|
| 65 | + { |
|
| 66 | + // Loading default preferences |
|
| 67 | + $this->config = $config; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function loadImage() |
|
| 71 | + { |
|
| 72 | + $this->createCode(); |
|
| 73 | + $this->setCode(); |
|
| 74 | + $this->createImage(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Create Code |
|
| 79 | + */ |
|
| 80 | + public function createCode() |
|
| 81 | + { |
|
| 82 | + if ($this->invalid) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ('bmp' === $this->mode) { |
|
| 87 | + $this->config['num_chars'] = 4; |
|
| 88 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
| 89 | + } else { |
|
| 90 | + $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
| 91 | + if (!$this->config['casesensitive']) { |
|
| 92 | + $this->code = strtoupper($this->code); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function setCode() |
|
| 98 | + { |
|
| 99 | + if ($this->invalid) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 104 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 105 | + |
|
| 106 | + // Increase the attempt records on refresh |
|
| 107 | + if (!empty($maxAttempts)) { |
|
| 108 | + $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
| 109 | + if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
| 110 | + $this->invalid = true; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param string $file |
|
| 117 | + * @return string|void |
|
| 118 | + */ |
|
| 119 | + public function createImage($file = '') |
|
| 120 | + { |
|
| 121 | + if ($this->invalid) { |
|
| 122 | + header('Content-type: image/gif'); |
|
| 123 | + readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
| 124 | + |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ('bmp' === $this->mode) { |
|
| 129 | + return $this->createImageBmp(); |
|
| 130 | + } else { |
|
| 131 | + return $this->createImageGd(); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Create CAPTCHA iamge with GD |
|
| 137 | + * Originated from DuGris' SecurityImage |
|
| 138 | + * @param string $file |
|
| 139 | + */ |
|
| 140 | + // --------------------------------------------------------------------------- // |
|
| 141 | + // Class: SecurityImage 1.5 // |
|
| 142 | + // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
| 143 | + // Email: [email protected] // |
|
| 144 | + // Licence: GNU // |
|
| 145 | + // Project: XOOPS Project // |
|
| 146 | + // --------------------------------------------------------------------------- // |
|
| 147 | + public function createImageGd($file = '') |
|
| 148 | + { |
|
| 149 | + $this->loadFont(); |
|
| 150 | + $this->setImageSize(); |
|
| 151 | + |
|
| 152 | + $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
| 153 | + $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
| 154 | + imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
| 155 | + |
|
| 156 | + switch ($this->config['background_type']) { |
|
| 157 | + default: |
|
| 158 | + case 0: |
|
| 159 | + $this->drawBars(); |
|
| 160 | + break; |
|
| 161 | + |
|
| 162 | + case 1: |
|
| 163 | + $this->drawCircles(); |
|
| 164 | + break; |
|
| 165 | + |
|
| 166 | + case 2: |
|
| 167 | + $this->drawLines(); |
|
| 168 | + break; |
|
| 169 | + |
|
| 170 | + case 3: |
|
| 171 | + $this->drawRectangles(); |
|
| 172 | + break; |
|
| 173 | + |
|
| 174 | + case 4: |
|
| 175 | + $this->drawEllipses(); |
|
| 176 | + break; |
|
| 177 | + |
|
| 178 | + case 5: |
|
| 179 | + $this->drawPolygons(); |
|
| 180 | + break; |
|
| 181 | + |
|
| 182 | + case 100: |
|
| 183 | + $this->createFromFile(); |
|
| 184 | + break; |
|
| 185 | + } |
|
| 186 | + $this->drawBorder(); |
|
| 187 | + $this->drawCode(); |
|
| 188 | + |
|
| 189 | + if (empty($file)) { |
|
| 190 | + header('Content-type: image/jpeg'); |
|
| 191 | + imagejpeg($this->oImage); |
|
| 192 | + } else { |
|
| 193 | + imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
| 194 | + } |
|
| 195 | + imagedestroy($this->oImage); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @param $name |
|
| 200 | + * @param string $extension |
|
| 201 | + * @return array |
|
| 202 | + */ |
|
| 203 | + public function _getList($name, $extension = '') |
|
| 204 | + { |
|
| 205 | + $items = []; |
|
| 206 | + /* |
|
| 207 | 207 | if (@ require_once XOOPS_ROOT_PATH."/Frameworks/art/functions.ini.php") { |
| 208 | 208 | load_functions("cache"); |
| 209 | 209 | if ($items = mod_loadCacheFile("captcha_{$name}", "captcha")) { |
@@ -211,231 +211,231 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | */ |
| 214 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 215 | - $file_path = $this->config['rootpath'] . "/{$name}"; |
|
| 216 | - $files = XoopsLists::getFileListAsArray($file_path); |
|
| 217 | - foreach ($files as $item) { |
|
| 218 | - if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
| 219 | - $items[] = $item; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - if (function_exists('mod_createCacheFile')) { |
|
| 223 | - mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - return $items; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - public function loadFont() |
|
| 230 | - { |
|
| 231 | - $fonts = $this->_getList('fonts', 'ttf'); |
|
| 232 | - $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - public function setImageSize() |
|
| 236 | - { |
|
| 237 | - $MaxCharWidth = 0; |
|
| 238 | - $MaxCharHeight = 0; |
|
| 239 | - $oImage = imagecreatetruecolor(100, 100); |
|
| 240 | - $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 241 | - $FontSize = $this->config['fontsize_max']; |
|
| 242 | - for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
| 243 | - for ($i = 65; $i <= 90; ++$i) { |
|
| 244 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), []); |
|
| 245 | - $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
| 246 | - if ($_MaxCharWidth > $MaxCharWidth) { |
|
| 247 | - $MaxCharWidth = $_MaxCharWidth; |
|
| 248 | - } |
|
| 249 | - $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 250 | - if ($_MaxCharHeight > $MaxCharHeight) { |
|
| 251 | - $MaxCharHeight = $_MaxCharHeight; |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - imagedestroy($oImage); |
|
| 256 | - |
|
| 257 | - $this->height = $MaxCharHeight + 2; |
|
| 258 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 259 | - $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Return random background |
|
| 264 | - * |
|
| 265 | - * @return null|string |
|
| 266 | - */ |
|
| 267 | - public function loadBackground() |
|
| 268 | - { |
|
| 269 | - $RandBackground = null; |
|
| 270 | - if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
| 271 | - $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - return $RandBackground; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Draw Image background |
|
| 279 | - */ |
|
| 280 | - public function createFromFile() |
|
| 281 | - { |
|
| 282 | - if ($RandImage = $this->loadBackground()) { |
|
| 283 | - $ImageType = @getimagesize($RandImage); |
|
| 284 | - switch (@$ImageType[2]) { |
|
| 285 | - case 1: |
|
| 286 | - $BackgroundImage = imagecreatefromgif($RandImage); |
|
| 287 | - break; |
|
| 288 | - |
|
| 289 | - case 2: |
|
| 290 | - $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
| 291 | - break; |
|
| 292 | - |
|
| 293 | - case 3: |
|
| 294 | - $BackgroundImage = imagecreatefrompng($RandImage); |
|
| 295 | - break; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if (!empty($BackgroundImage)) { |
|
| 299 | - imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
| 300 | - imagedestroy($BackgroundImage); |
|
| 301 | - } else { |
|
| 302 | - $this->drawBars(); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Draw Code |
|
| 308 | - */ |
|
| 309 | - public function drawCode() |
|
| 310 | - { |
|
| 311 | - for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
| 312 | - // select random greyscale colour |
|
| 313 | - $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 314 | - |
|
| 315 | - // write text to image |
|
| 316 | - $Angle = mt_rand(10, 30); |
|
| 317 | - if ($i % 2) { |
|
| 318 | - $Angle = mt_rand(-10, -30); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - // select random font size |
|
| 322 | - $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
| 323 | - |
|
| 324 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], []); |
|
| 325 | - $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 326 | - |
|
| 327 | - // calculate character starting coordinates |
|
| 328 | - $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
| 329 | - $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
| 330 | - |
|
| 331 | - imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], []); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Draw Border |
|
| 337 | - */ |
|
| 338 | - public function drawBorder() |
|
| 339 | - { |
|
| 340 | - $rgb = mt_rand(50, 150); |
|
| 341 | - $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
| 342 | - imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Draw Circles background |
|
| 347 | - */ |
|
| 348 | - public function drawCircles() |
|
| 349 | - { |
|
| 350 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 351 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 352 | - imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Draw Lines background |
|
| 358 | - */ |
|
| 359 | - public function drawLines() |
|
| 360 | - { |
|
| 361 | - for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
| 362 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 363 | - imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Draw Rectangles background |
|
| 369 | - */ |
|
| 370 | - public function drawRectangles() |
|
| 371 | - { |
|
| 372 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 373 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 374 | - imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Draw Bars background |
|
| 380 | - */ |
|
| 381 | - public function drawBars() |
|
| 382 | - { |
|
| 383 | - for ($i = 0; $i <= $this->height;) { |
|
| 384 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 385 | - imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
| 386 | - $i += 2.5; |
|
| 387 | - } |
|
| 388 | - for ($i = 0; $i <= $this->width;) { |
|
| 389 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 390 | - imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
| 391 | - $i += 2.5; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Draw Ellipses background |
|
| 397 | - */ |
|
| 398 | - public function drawEllipses() |
|
| 399 | - { |
|
| 400 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 401 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 402 | - imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Draw polygons background |
|
| 408 | - */ |
|
| 409 | - public function drawPolygons() |
|
| 410 | - { |
|
| 411 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 412 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 413 | - $coords = []; |
|
| 414 | - for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
| 415 | - $coords[] = mt_rand(0, $this->width); |
|
| 416 | - $coords[] = mt_rand(0, $this->height); |
|
| 417 | - } |
|
| 418 | - imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Create CAPTCHA iamge with BMP |
|
| 424 | - * TODO |
|
| 425 | - * @param string $file |
|
| 426 | - * @return string |
|
| 427 | - */ |
|
| 428 | - public function createImageBmp($file = '') |
|
| 429 | - { |
|
| 430 | - $image = ''; |
|
| 431 | - |
|
| 432 | - if (empty($file)) { |
|
| 433 | - header('Content-type: image/bmp'); |
|
| 434 | - echo $image; |
|
| 435 | - } else { |
|
| 436 | - return $image; |
|
| 437 | - } |
|
| 438 | - } |
|
| 214 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 215 | + $file_path = $this->config['rootpath'] . "/{$name}"; |
|
| 216 | + $files = XoopsLists::getFileListAsArray($file_path); |
|
| 217 | + foreach ($files as $item) { |
|
| 218 | + if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
| 219 | + $items[] = $item; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + if (function_exists('mod_createCacheFile')) { |
|
| 223 | + mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + return $items; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + public function loadFont() |
|
| 230 | + { |
|
| 231 | + $fonts = $this->_getList('fonts', 'ttf'); |
|
| 232 | + $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + public function setImageSize() |
|
| 236 | + { |
|
| 237 | + $MaxCharWidth = 0; |
|
| 238 | + $MaxCharHeight = 0; |
|
| 239 | + $oImage = imagecreatetruecolor(100, 100); |
|
| 240 | + $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 241 | + $FontSize = $this->config['fontsize_max']; |
|
| 242 | + for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
| 243 | + for ($i = 65; $i <= 90; ++$i) { |
|
| 244 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), []); |
|
| 245 | + $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
| 246 | + if ($_MaxCharWidth > $MaxCharWidth) { |
|
| 247 | + $MaxCharWidth = $_MaxCharWidth; |
|
| 248 | + } |
|
| 249 | + $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 250 | + if ($_MaxCharHeight > $MaxCharHeight) { |
|
| 251 | + $MaxCharHeight = $_MaxCharHeight; |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + imagedestroy($oImage); |
|
| 256 | + |
|
| 257 | + $this->height = $MaxCharHeight + 2; |
|
| 258 | + $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 259 | + $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Return random background |
|
| 264 | + * |
|
| 265 | + * @return null|string |
|
| 266 | + */ |
|
| 267 | + public function loadBackground() |
|
| 268 | + { |
|
| 269 | + $RandBackground = null; |
|
| 270 | + if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
| 271 | + $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + return $RandBackground; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Draw Image background |
|
| 279 | + */ |
|
| 280 | + public function createFromFile() |
|
| 281 | + { |
|
| 282 | + if ($RandImage = $this->loadBackground()) { |
|
| 283 | + $ImageType = @getimagesize($RandImage); |
|
| 284 | + switch (@$ImageType[2]) { |
|
| 285 | + case 1: |
|
| 286 | + $BackgroundImage = imagecreatefromgif($RandImage); |
|
| 287 | + break; |
|
| 288 | + |
|
| 289 | + case 2: |
|
| 290 | + $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
| 291 | + break; |
|
| 292 | + |
|
| 293 | + case 3: |
|
| 294 | + $BackgroundImage = imagecreatefrompng($RandImage); |
|
| 295 | + break; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if (!empty($BackgroundImage)) { |
|
| 299 | + imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
| 300 | + imagedestroy($BackgroundImage); |
|
| 301 | + } else { |
|
| 302 | + $this->drawBars(); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Draw Code |
|
| 308 | + */ |
|
| 309 | + public function drawCode() |
|
| 310 | + { |
|
| 311 | + for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
| 312 | + // select random greyscale colour |
|
| 313 | + $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 314 | + |
|
| 315 | + // write text to image |
|
| 316 | + $Angle = mt_rand(10, 30); |
|
| 317 | + if ($i % 2) { |
|
| 318 | + $Angle = mt_rand(-10, -30); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + // select random font size |
|
| 322 | + $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
| 323 | + |
|
| 324 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], []); |
|
| 325 | + $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 326 | + |
|
| 327 | + // calculate character starting coordinates |
|
| 328 | + $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
| 329 | + $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
| 330 | + |
|
| 331 | + imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], []); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Draw Border |
|
| 337 | + */ |
|
| 338 | + public function drawBorder() |
|
| 339 | + { |
|
| 340 | + $rgb = mt_rand(50, 150); |
|
| 341 | + $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
| 342 | + imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Draw Circles background |
|
| 347 | + */ |
|
| 348 | + public function drawCircles() |
|
| 349 | + { |
|
| 350 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 351 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 352 | + imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Draw Lines background |
|
| 358 | + */ |
|
| 359 | + public function drawLines() |
|
| 360 | + { |
|
| 361 | + for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
| 362 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 363 | + imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Draw Rectangles background |
|
| 369 | + */ |
|
| 370 | + public function drawRectangles() |
|
| 371 | + { |
|
| 372 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 373 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 374 | + imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Draw Bars background |
|
| 380 | + */ |
|
| 381 | + public function drawBars() |
|
| 382 | + { |
|
| 383 | + for ($i = 0; $i <= $this->height;) { |
|
| 384 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 385 | + imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
| 386 | + $i += 2.5; |
|
| 387 | + } |
|
| 388 | + for ($i = 0; $i <= $this->width;) { |
|
| 389 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 390 | + imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
| 391 | + $i += 2.5; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Draw Ellipses background |
|
| 397 | + */ |
|
| 398 | + public function drawEllipses() |
|
| 399 | + { |
|
| 400 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 401 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 402 | + imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Draw polygons background |
|
| 408 | + */ |
|
| 409 | + public function drawPolygons() |
|
| 410 | + { |
|
| 411 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 412 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 413 | + $coords = []; |
|
| 414 | + for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
| 415 | + $coords[] = mt_rand(0, $this->width); |
|
| 416 | + $coords[] = mt_rand(0, $this->height); |
|
| 417 | + } |
|
| 418 | + imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Create CAPTCHA iamge with BMP |
|
| 424 | + * TODO |
|
| 425 | + * @param string $file |
|
| 426 | + * @return string |
|
| 427 | + */ |
|
| 428 | + public function createImageBmp($file = '') |
|
| 429 | + { |
|
| 430 | + $image = ''; |
|
| 431 | + |
|
| 432 | + if (empty($file)) { |
|
| 433 | + header('Content-type: image/bmp'); |
|
| 434 | + echo $image; |
|
| 435 | + } else { |
|
| 436 | + return $image; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | $config = @include __DIR__ . '/../config.php'; |
@@ -5,11 +5,11 @@ discard block |
||
| 5 | 5 | * D.J. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -include dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/mainfile.php'; |
|
| 8 | +include dirname(dirname(dirname(dirname(dirname(__DIR__))))).'/mainfile.php'; |
|
| 9 | 9 | error_reporting(0); |
| 10 | 10 | $xoopsLogger->activated = false; |
| 11 | 11 | |
| 12 | -if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', $_SERVER['HTTP_REFERER'])) { |
|
| 12 | +if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^'.preg_quote(XOOPS_URL, '/').'/', $_SERVER['HTTP_REFERER'])) { |
|
| 13 | 13 | exit(); |
| 14 | 14 | } |
| 15 | 15 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | if ('bmp' === $this->mode) { |
| 87 | 87 | $this->config['num_chars'] = 4; |
| 88 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
| 88 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int) str_pad('9', $this->config['num_chars'], '9')); |
|
| 89 | 89 | } else { |
| 90 | 90 | $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
| 91 | 91 | if (!$this->config['casesensitive']) { |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | return; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 104 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 103 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string) $this->code; |
|
| 104 | + $maxAttempts = (int) (@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 105 | 105 | |
| 106 | 106 | // Increase the attempt records on refresh |
| 107 | 107 | if (!empty($maxAttempts)) { |
| 108 | - $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
| 109 | - if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
| 108 | + $_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']]++; |
|
| 109 | + if ($_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
| 110 | 110 | $this->invalid = true; |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | if ($this->invalid) { |
| 122 | 122 | header('Content-type: image/gif'); |
| 123 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
| 123 | + readfile(XOOPS_ROOT_PATH.'/images/subject/icon2.gif'); |
|
| 124 | 124 | |
| 125 | 125 | return; |
| 126 | 126 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | header('Content-type: image/jpeg'); |
| 191 | 191 | imagejpeg($this->oImage); |
| 192 | 192 | } else { |
| 193 | - imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
| 193 | + imagejpeg($this->oImage, XOOPS_ROOT_PATH.'/'.$this->config['imagepath'].'/'.$file.'.jpg'); |
|
| 194 | 194 | } |
| 195 | 195 | imagedestroy($this->oImage); |
| 196 | 196 | } |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | */ |
| 214 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 215 | - $file_path = $this->config['rootpath'] . "/{$name}"; |
|
| 214 | + require_once XOOPS_ROOT_PATH.'/class/xoopslists.php'; |
|
| 215 | + $file_path = $this->config['rootpath']."/{$name}"; |
|
| 216 | 216 | $files = XoopsLists::getFileListAsArray($file_path); |
| 217 | 217 | foreach ($files as $item) { |
| 218 | 218 | if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | public function loadFont() |
| 230 | 230 | { |
| 231 | 231 | $fonts = $this->_getList('fonts', 'ttf'); |
| 232 | - $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
| 232 | + $this->font = $this->config['rootpath'].'/fonts/'.$fonts[array_rand($fonts)]; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | public function setImageSize() |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | imagedestroy($oImage); |
| 256 | 256 | |
| 257 | 257 | $this->height = $MaxCharHeight + 2; |
| 258 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 258 | + $this->spacing = (int) (($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 259 | 259 | $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
| 260 | 260 | } |
| 261 | 261 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | { |
| 269 | 269 | $RandBackground = null; |
| 270 | 270 | if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
| 271 | - $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
| 271 | + $RandBackground = $this->config['rootpath'].'/backgrounds/'.$backgrounds[array_rand($backgrounds)]; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | return $RandBackground; |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | -$config = @include __DIR__ . '/../config.php'; |
|
| 441 | +$config = @include __DIR__.'/../config.php'; |
|
| 442 | 442 | $imageHandler = new \XoopsCaptchaImageHandler(); |
| 443 | 443 | $imageHandler->setConfig($config); |
| 444 | 444 | $imageHandler->loadImage(); |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | function smartobject_addto_show($options) |
| 10 | 10 | { |
| 11 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 12 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartaddto.php'; |
|
| 13 | - $smartaddto = new XoopsModules\Smartobject\SmartAddTo($options[0]); |
|
| 14 | - $block = $smartaddto->renderForBlock(); |
|
| 11 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 12 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartaddto.php'; |
|
| 13 | + $smartaddto = new XoopsModules\Smartobject\SmartAddTo($options[0]); |
|
| 14 | + $block = $smartaddto->renderForBlock(); |
|
| 15 | 15 | |
| 16 | - return $block; |
|
| 16 | + return $block; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -22,16 +22,16 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | function smartobject_addto_edit($options) |
| 24 | 24 | { |
| 25 | - require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 25 | + require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 26 | 26 | |
| 27 | - $form = ''; |
|
| 27 | + $form = ''; |
|
| 28 | 28 | |
| 29 | - $layout_select = new \XoopsFormSelect(_MB_SOBJECT_BLOCKS_ADDTO_LAYOUT, 'options[]', $options[0]); |
|
| 30 | - $layout_select->addOption(0, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION0); |
|
| 31 | - $layout_select->addOption(1, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION1); |
|
| 32 | - $layout_select->addOption(2, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION2); |
|
| 33 | - $layout_select->addOption(3, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION3); |
|
| 34 | - $form .= $layout_select->getCaption() . ' ' . $layout_select->render() . '<br>'; |
|
| 29 | + $layout_select = new \XoopsFormSelect(_MB_SOBJECT_BLOCKS_ADDTO_LAYOUT, 'options[]', $options[0]); |
|
| 30 | + $layout_select->addOption(0, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION0); |
|
| 31 | + $layout_select->addOption(1, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION1); |
|
| 32 | + $layout_select->addOption(2, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION2); |
|
| 33 | + $layout_select->addOption(3, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION3); |
|
| 34 | + $form .= $layout_select->getCaption() . ' ' . $layout_select->render() . '<br>'; |
|
| 35 | 35 | |
| 36 | - return $form; |
|
| 36 | + return $form; |
|
| 37 | 37 | } |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | function smartobject_addto_show($options) |
| 10 | 10 | { |
| 11 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 12 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartaddto.php'; |
|
| 11 | + require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
| 12 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartaddto.php'; |
|
| 13 | 13 | $smartaddto = new XoopsModules\Smartobject\SmartAddTo($options[0]); |
| 14 | 14 | $block = $smartaddto->renderForBlock(); |
| 15 | 15 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | function smartobject_addto_edit($options) |
| 24 | 24 | { |
| 25 | - require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 25 | + require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
| 26 | 26 | |
| 27 | 27 | $form = ''; |
| 28 | 28 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $layout_select->addOption(1, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION1); |
| 32 | 32 | $layout_select->addOption(2, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION2); |
| 33 | 33 | $layout_select->addOption(3, _MB_SOBJECT_BLOCKS_ADDTO_LAYOUT_OPTION3); |
| 34 | - $form .= $layout_select->getCaption() . ' ' . $layout_select->render() . '<br>'; |
|
| 34 | + $form .= $layout_select->getCaption().' '.$layout_select->render().'<br>'; |
|
| 35 | 35 | |
| 36 | 36 | return $form; |
| 37 | 37 | } |
@@ -25,81 +25,81 @@ |
||
| 25 | 25 | $op = ''; |
| 26 | 26 | |
| 27 | 27 | if (isset($_GET['op'])) { |
| 28 | - $op = $_GET['op']; |
|
| 28 | + $op = $_GET['op']; |
|
| 29 | 29 | } |
| 30 | 30 | if (isset($_POST['op'])) { |
| 31 | - $op = $_POST['op']; |
|
| 31 | + $op = $_POST['op']; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | switch ($op) { |
| 35 | 35 | |
| 36 | - case 'del': |
|
| 37 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php'; |
|
| 38 | - $controller = new XoopsModules\Smartobject\SmartObjectController($smartobjectLinkHandler); |
|
| 39 | - $controller->handleObjectDeletion(_AM_SOBJECT_SENT_LINK_DELETE_CONFIRM); |
|
| 36 | + case 'del': |
|
| 37 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php'; |
|
| 38 | + $controller = new XoopsModules\Smartobject\SmartObjectController($smartobjectLinkHandler); |
|
| 39 | + $controller->handleObjectDeletion(_AM_SOBJECT_SENT_LINK_DELETE_CONFIRM); |
|
| 40 | 40 | |
| 41 | - break; |
|
| 41 | + break; |
|
| 42 | 42 | |
| 43 | - case 'view': |
|
| 44 | - $linkid = isset($_GET['linkid']) ? $_GET['linkid'] : 0; |
|
| 45 | - $linkObj = $smartobjectLinkHandler->get($linkid); |
|
| 43 | + case 'view': |
|
| 44 | + $linkid = isset($_GET['linkid']) ? $_GET['linkid'] : 0; |
|
| 45 | + $linkObj = $smartobjectLinkHandler->get($linkid); |
|
| 46 | 46 | |
| 47 | - if ($linkObj->isNew()) { |
|
| 48 | - redirect_header(SMARTOBJECT_URL . 'admin/link.php', 3, _AM_SOBJECT_LINK_NOT_FOUND); |
|
| 49 | - } |
|
| 47 | + if ($linkObj->isNew()) { |
|
| 48 | + redirect_header(SMARTOBJECT_URL . 'admin/link.php', 3, _AM_SOBJECT_LINK_NOT_FOUND); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - smart_xoops_cp_header(); |
|
| 51 | + smart_xoops_cp_header(); |
|
| 52 | 52 | |
| 53 | - //smart_adminMenu(1, _AM_SOBJECT_SENT_LINK_DISPLAY); |
|
| 53 | + //smart_adminMenu(1, _AM_SOBJECT_SENT_LINK_DISPLAY); |
|
| 54 | 54 | |
| 55 | - smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINK_DISPLAY, _AM_SOBJECT_SENT_LINK_DISPLAY_INFO); |
|
| 55 | + smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINK_DISPLAY, _AM_SOBJECT_SENT_LINK_DISPLAY_INFO); |
|
| 56 | 56 | |
| 57 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 57 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 58 | 58 | |
| 59 | - // --- |
|
| 60 | - // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
| 61 | - // $xoopsTpl = new \XoopsTpl(); |
|
| 62 | - $xoopsTpl = new \XoopsTpl(); |
|
| 63 | - //--- |
|
| 59 | + // --- |
|
| 60 | + // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
| 61 | + // $xoopsTpl = new \XoopsTpl(); |
|
| 62 | + $xoopsTpl = new \XoopsTpl(); |
|
| 63 | + //--- |
|
| 64 | 64 | |
| 65 | - $xoopsTpl->assign('link', $linkObj->toArray()); |
|
| 66 | - $xoopsTpl->display('db:smartobject_sentlink_display.tpl'); |
|
| 65 | + $xoopsTpl->assign('link', $linkObj->toArray()); |
|
| 66 | + $xoopsTpl->display('db:smartobject_sentlink_display.tpl'); |
|
| 67 | 67 | |
| 68 | - echo '<br>'; |
|
| 69 | - smart_close_collapsable('sentlinks'); |
|
| 70 | - echo '<br>'; |
|
| 68 | + echo '<br>'; |
|
| 69 | + smart_close_collapsable('sentlinks'); |
|
| 70 | + echo '<br>'; |
|
| 71 | 71 | |
| 72 | - break; |
|
| 72 | + break; |
|
| 73 | 73 | |
| 74 | - default: |
|
| 74 | + default: |
|
| 75 | 75 | |
| 76 | - smart_xoops_cp_header(); |
|
| 76 | + smart_xoops_cp_header(); |
|
| 77 | 77 | |
| 78 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
| 78 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
| 79 | 79 | |
| 80 | - //smart_adminMenu(1, _AM_SOBJECT_SENT_LINKS); |
|
| 80 | + //smart_adminMenu(1, _AM_SOBJECT_SENT_LINKS); |
|
| 81 | 81 | |
| 82 | - smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINKS, _AM_SOBJECT_SENT_LINKS_INFO); |
|
| 82 | + smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINKS, _AM_SOBJECT_SENT_LINKS_INFO); |
|
| 83 | 83 | |
| 84 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php'; |
|
| 85 | - $objectTable = new XoopsModules\Smartobject\SmartObjectTable($smartobjectLinkHandler, null, ['delete']); |
|
| 86 | - $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('date')); |
|
| 87 | - $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_FROM, $align = 'left', $width = false, 'getFromInfo')); |
|
| 88 | - $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_TO, $align = 'left', $width = false, 'getToInfo')); |
|
| 89 | - $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('link')); |
|
| 84 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php'; |
|
| 85 | + $objectTable = new XoopsModules\Smartobject\SmartObjectTable($smartobjectLinkHandler, null, ['delete']); |
|
| 86 | + $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('date')); |
|
| 87 | + $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_FROM, $align = 'left', $width = false, 'getFromInfo')); |
|
| 88 | + $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_TO, $align = 'left', $width = false, 'getToInfo')); |
|
| 89 | + $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('link')); |
|
| 90 | 90 | |
| 91 | - $objectTable->addCustomAction('getViewItemLink'); |
|
| 91 | + $objectTable->addCustomAction('getViewItemLink'); |
|
| 92 | 92 | |
| 93 | - $objectTable->setDefaultSort('date'); |
|
| 94 | - $objectTable->setDefaultOrder('DESC'); |
|
| 93 | + $objectTable->setDefaultSort('date'); |
|
| 94 | + $objectTable->setDefaultOrder('DESC'); |
|
| 95 | 95 | |
| 96 | - $objectTable->render(); |
|
| 96 | + $objectTable->render(); |
|
| 97 | 97 | |
| 98 | - echo '<br>'; |
|
| 99 | - smart_close_collapsable('sentlinks'); |
|
| 100 | - echo '<br>'; |
|
| 98 | + echo '<br>'; |
|
| 99 | + smart_close_collapsable('sentlinks'); |
|
| 100 | + echo '<br>'; |
|
| 101 | 101 | |
| 102 | - break; |
|
| 102 | + break; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | //smart_modFooter(); |
@@ -33,73 +33,73 @@ |
||
| 33 | 33 | |
| 34 | 34 | switch ($op) { |
| 35 | 35 | |
| 36 | - case 'del': |
|
| 37 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php'; |
|
| 38 | - $controller = new XoopsModules\Smartobject\SmartObjectController($smartobjectLinkHandler); |
|
| 39 | - $controller->handleObjectDeletion(_AM_SOBJECT_SENT_LINK_DELETE_CONFIRM); |
|
| 36 | + case 'del': |
|
| 37 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php'; |
|
| 38 | + $controller = new XoopsModules\Smartobject\SmartObjectController($smartobjectLinkHandler); |
|
| 39 | + $controller->handleObjectDeletion(_AM_SOBJECT_SENT_LINK_DELETE_CONFIRM); |
|
| 40 | 40 | |
| 41 | - break; |
|
| 41 | + break; |
|
| 42 | 42 | |
| 43 | - case 'view': |
|
| 44 | - $linkid = isset($_GET['linkid']) ? $_GET['linkid'] : 0; |
|
| 45 | - $linkObj = $smartobjectLinkHandler->get($linkid); |
|
| 43 | + case 'view': |
|
| 44 | + $linkid = isset($_GET['linkid']) ? $_GET['linkid'] : 0; |
|
| 45 | + $linkObj = $smartobjectLinkHandler->get($linkid); |
|
| 46 | 46 | |
| 47 | - if ($linkObj->isNew()) { |
|
| 48 | - redirect_header(SMARTOBJECT_URL . 'admin/link.php', 3, _AM_SOBJECT_LINK_NOT_FOUND); |
|
| 49 | - } |
|
| 47 | + if ($linkObj->isNew()) { |
|
| 48 | + redirect_header(SMARTOBJECT_URL . 'admin/link.php', 3, _AM_SOBJECT_LINK_NOT_FOUND); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - smart_xoops_cp_header(); |
|
| 51 | + smart_xoops_cp_header(); |
|
| 52 | 52 | |
| 53 | - //smart_adminMenu(1, _AM_SOBJECT_SENT_LINK_DISPLAY); |
|
| 53 | + //smart_adminMenu(1, _AM_SOBJECT_SENT_LINK_DISPLAY); |
|
| 54 | 54 | |
| 55 | - smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINK_DISPLAY, _AM_SOBJECT_SENT_LINK_DISPLAY_INFO); |
|
| 55 | + smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINK_DISPLAY, _AM_SOBJECT_SENT_LINK_DISPLAY_INFO); |
|
| 56 | 56 | |
| 57 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 57 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 58 | 58 | |
| 59 | - // --- |
|
| 60 | - // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
| 61 | - // $xoopsTpl = new \XoopsTpl(); |
|
| 62 | - $xoopsTpl = new \XoopsTpl(); |
|
| 63 | - //--- |
|
| 59 | + // --- |
|
| 60 | + // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
| 61 | + // $xoopsTpl = new \XoopsTpl(); |
|
| 62 | + $xoopsTpl = new \XoopsTpl(); |
|
| 63 | + //--- |
|
| 64 | 64 | |
| 65 | - $xoopsTpl->assign('link', $linkObj->toArray()); |
|
| 66 | - $xoopsTpl->display('db:smartobject_sentlink_display.tpl'); |
|
| 65 | + $xoopsTpl->assign('link', $linkObj->toArray()); |
|
| 66 | + $xoopsTpl->display('db:smartobject_sentlink_display.tpl'); |
|
| 67 | 67 | |
| 68 | - echo '<br>'; |
|
| 69 | - smart_close_collapsable('sentlinks'); |
|
| 70 | - echo '<br>'; |
|
| 68 | + echo '<br>'; |
|
| 69 | + smart_close_collapsable('sentlinks'); |
|
| 70 | + echo '<br>'; |
|
| 71 | 71 | |
| 72 | - break; |
|
| 72 | + break; |
|
| 73 | 73 | |
| 74 | - default: |
|
| 74 | + default: |
|
| 75 | 75 | |
| 76 | - smart_xoops_cp_header(); |
|
| 76 | + smart_xoops_cp_header(); |
|
| 77 | 77 | |
| 78 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
| 78 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
| 79 | 79 | |
| 80 | - //smart_adminMenu(1, _AM_SOBJECT_SENT_LINKS); |
|
| 80 | + //smart_adminMenu(1, _AM_SOBJECT_SENT_LINKS); |
|
| 81 | 81 | |
| 82 | - smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINKS, _AM_SOBJECT_SENT_LINKS_INFO); |
|
| 82 | + smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINKS, _AM_SOBJECT_SENT_LINKS_INFO); |
|
| 83 | 83 | |
| 84 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php'; |
|
| 85 | - $objectTable = new XoopsModules\Smartobject\SmartObjectTable($smartobjectLinkHandler, null, ['delete']); |
|
| 86 | - $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('date')); |
|
| 87 | - $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_FROM, $align = 'left', $width = false, 'getFromInfo')); |
|
| 88 | - $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_TO, $align = 'left', $width = false, 'getToInfo')); |
|
| 89 | - $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('link')); |
|
| 84 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php'; |
|
| 85 | + $objectTable = new XoopsModules\Smartobject\SmartObjectTable($smartobjectLinkHandler, null, ['delete']); |
|
| 86 | + $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('date')); |
|
| 87 | + $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_FROM, $align = 'left', $width = false, 'getFromInfo')); |
|
| 88 | + $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_TO, $align = 'left', $width = false, 'getToInfo')); |
|
| 89 | + $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('link')); |
|
| 90 | 90 | |
| 91 | - $objectTable->addCustomAction('getViewItemLink'); |
|
| 91 | + $objectTable->addCustomAction('getViewItemLink'); |
|
| 92 | 92 | |
| 93 | - $objectTable->setDefaultSort('date'); |
|
| 94 | - $objectTable->setDefaultOrder('DESC'); |
|
| 93 | + $objectTable->setDefaultSort('date'); |
|
| 94 | + $objectTable->setDefaultOrder('DESC'); |
|
| 95 | 95 | |
| 96 | - $objectTable->render(); |
|
| 96 | + $objectTable->render(); |
|
| 97 | 97 | |
| 98 | - echo '<br>'; |
|
| 99 | - smart_close_collapsable('sentlinks'); |
|
| 100 | - echo '<br>'; |
|
| 98 | + echo '<br>'; |
|
| 99 | + smart_close_collapsable('sentlinks'); |
|
| 100 | + echo '<br>'; |
|
| 101 | 101 | |
| 102 | - break; |
|
| 102 | + break; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | //smart_modFooter(); |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | use XoopsModules\Smartobject\SmartObjectController; |
| 16 | 16 | use XoopsModules\Smartobject\SmartObjectTable; |
| 17 | 17 | |
| 18 | -require_once __DIR__ . '/admin_header.php'; |
|
| 19 | -require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php'; |
|
| 20 | -require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectlink.php'; |
|
| 18 | +require_once __DIR__.'/admin_header.php'; |
|
| 19 | +require_once SMARTOBJECT_ROOT_PATH.'class/smartobjecttable.php'; |
|
| 20 | +require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectlink.php'; |
|
| 21 | 21 | $adminObject = \Xmf\Module\Admin::getInstance(); |
| 22 | 22 | |
| 23 | 23 | $smartobjectLinkHandler = xoops_getModuleHandler('link'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | switch ($op) { |
| 35 | 35 | |
| 36 | 36 | case 'del': |
| 37 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php'; |
|
| 37 | + require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobjectcontroller.php'; |
|
| 38 | 38 | $controller = new XoopsModules\Smartobject\SmartObjectController($smartobjectLinkHandler); |
| 39 | 39 | $controller->handleObjectDeletion(_AM_SOBJECT_SENT_LINK_DELETE_CONFIRM); |
| 40 | 40 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | $linkObj = $smartobjectLinkHandler->get($linkid); |
| 46 | 46 | |
| 47 | 47 | if ($linkObj->isNew()) { |
| 48 | - redirect_header(SMARTOBJECT_URL . 'admin/link.php', 3, _AM_SOBJECT_LINK_NOT_FOUND); |
|
| 48 | + redirect_header(SMARTOBJECT_URL.'admin/link.php', 3, _AM_SOBJECT_LINK_NOT_FOUND); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | smart_xoops_cp_header(); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINK_DISPLAY, _AM_SOBJECT_SENT_LINK_DISPLAY_INFO); |
| 56 | 56 | |
| 57 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 57 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
| 58 | 58 | |
| 59 | 59 | // --- |
| 60 | 60 | // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | smart_collapsableBar('sentlinks', _AM_SOBJECT_SENT_LINKS, _AM_SOBJECT_SENT_LINKS_INFO); |
| 83 | 83 | |
| 84 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php'; |
|
| 84 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjecttable.php'; |
|
| 85 | 85 | $objectTable = new XoopsModules\Smartobject\SmartObjectTable($smartobjectLinkHandler, null, ['delete']); |
| 86 | 86 | $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn('date')); |
| 87 | 87 | $objectTable->addColumn(new XoopsModules\Smartobject\SmartObjectColumn(_AM_SOBJECT_SENT_LINKS_FROM, $align = 'left', $width = false, 'getFromInfo')); |
@@ -104,4 +104,4 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | //smart_modFooter(); |
| 106 | 106 | //xoops_cp_footer(); |
| 107 | -require_once __DIR__ . '/admin_footer.php'; |
|
| 107 | +require_once __DIR__.'/admin_footer.php'; |
|
@@ -19,180 +19,180 @@ discard block |
||
| 19 | 19 | // ========================================================================================= |
| 20 | 20 | function update_tables_to_300() |
| 21 | 21 | { |
| 22 | - $dbupdater = new Wfdownloads\Dbupdater(); |
|
| 22 | + $dbupdater = new Wfdownloads\Dbupdater(); |
|
| 23 | 23 | |
| 24 | - if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
| 25 | - // Create table wfdownloads_meta |
|
| 26 | - $table = new Wfdownloads\DbupdaterTable('wfdownloads_meta'); |
|
| 27 | - $table->setStructure("CREATE TABLE `%s` ( |
|
| 24 | + if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
| 25 | + // Create table wfdownloads_meta |
|
| 26 | + $table = new Wfdownloads\DbupdaterTable('wfdownloads_meta'); |
|
| 27 | + $table->setStructure("CREATE TABLE `%s` ( |
|
| 28 | 28 | metakey varchar(50) NOT NULL default '', |
| 29 | 29 | metavalue varchar(255) NOT NULL default '', |
| 30 | 30 | PRIMARY KEY (metakey)) |
| 31 | 31 | ENGINE=MyISAM;"); |
| 32 | 32 | |
| 33 | - $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2))); |
|
| 34 | - if ($dbupdater->updateTable($table)) { |
|
| 35 | - echo 'wfdownloads_meta table created<br>'; |
|
| 36 | - } |
|
| 37 | - } |
|
| 33 | + $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2))); |
|
| 34 | + if ($dbupdater->updateTable($table)) { |
|
| 35 | + echo 'wfdownloads_meta table created<br>'; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $download_fields = [ |
|
| 40 | - 'lid' => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false], |
|
| 41 | - 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 42 | - 'title' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
| 43 | - 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 44 | - 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
| 45 | - 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
| 46 | - 'homepage' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
| 47 | - 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
| 48 | - 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
| 49 | - 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
| 50 | - 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 51 | - 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 52 | - 'publisher' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 53 | - 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
| 54 | - 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 55 | - 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 56 | - 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
| 57 | - 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 58 | - 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 59 | - 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 60 | - 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 61 | - 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
| 62 | - 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 63 | - 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 64 | - 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 65 | - 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 66 | - 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 67 | - 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
| 68 | - 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 69 | - 'published' => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true], |
|
| 70 | - 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 71 | - 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 72 | - 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
| 73 | - 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 74 | - 'ipaddress' => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true], |
|
| 75 | - 'notifypub' => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true], |
|
| 76 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false] |
|
| 77 | - ]; |
|
| 39 | + $download_fields = [ |
|
| 40 | + 'lid' => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false], |
|
| 41 | + 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 42 | + 'title' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
| 43 | + 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 44 | + 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
| 45 | + 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
| 46 | + 'homepage' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
| 47 | + 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
| 48 | + 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
| 49 | + 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
| 50 | + 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 51 | + 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 52 | + 'publisher' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 53 | + 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
| 54 | + 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 55 | + 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 56 | + 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
| 57 | + 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 58 | + 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 59 | + 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 60 | + 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 61 | + 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
| 62 | + 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 63 | + 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 64 | + 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 65 | + 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 66 | + 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 67 | + 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
| 68 | + 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 69 | + 'published' => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true], |
|
| 70 | + 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 71 | + 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 72 | + 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
| 73 | + 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 74 | + 'ipaddress' => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true], |
|
| 75 | + 'notifypub' => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true], |
|
| 76 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false] |
|
| 77 | + ]; |
|
| 78 | 78 | |
| 79 | - $renamed_fields = [ |
|
| 80 | - 'logourl' => 'screenshot' |
|
| 81 | - ]; |
|
| 79 | + $renamed_fields = [ |
|
| 80 | + 'logourl' => 'screenshot' |
|
| 81 | + ]; |
|
| 82 | 82 | |
| 83 | - echo '<br><b>Checking Download table</b><br>'; |
|
| 84 | - $downloadHandler = xoops_getModuleHandler('download', 'wfdownloads'); |
|
| 85 | - $download_table = new Wfdownloads\DbupdaterTable('wfdownloads_downloads'); |
|
| 86 | - $fields = get_table_info($downloadHandler->table, $download_fields); |
|
| 87 | - // Check for renamed fields |
|
| 88 | - rename_fields($download_table, $renamed_fields, $fields, $download_fields); |
|
| 89 | - update_table($download_fields, $fields, $download_table); |
|
| 90 | - if ($dbupdater->updateTable($download_table)) { |
|
| 91 | - echo 'Downloads table updated<br>'; |
|
| 92 | - } |
|
| 93 | - unset($fields); |
|
| 83 | + echo '<br><b>Checking Download table</b><br>'; |
|
| 84 | + $downloadHandler = xoops_getModuleHandler('download', 'wfdownloads'); |
|
| 85 | + $download_table = new Wfdownloads\DbupdaterTable('wfdownloads_downloads'); |
|
| 86 | + $fields = get_table_info($downloadHandler->table, $download_fields); |
|
| 87 | + // Check for renamed fields |
|
| 88 | + rename_fields($download_table, $renamed_fields, $fields, $download_fields); |
|
| 89 | + update_table($download_fields, $fields, $download_table); |
|
| 90 | + if ($dbupdater->updateTable($download_table)) { |
|
| 91 | + echo 'Downloads table updated<br>'; |
|
| 92 | + } |
|
| 93 | + unset($fields); |
|
| 94 | 94 | |
| 95 | - $mod_fields = [ |
|
| 96 | - 'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false], |
|
| 97 | - 'lid' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 98 | - 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 99 | - 'title' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 100 | - 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 101 | - 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
| 102 | - 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
| 103 | - 'homepage' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 104 | - 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
| 105 | - 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
| 106 | - 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
| 107 | - 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 108 | - 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 109 | - 'publisher' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 110 | - 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
| 111 | - 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 112 | - 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 113 | - 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
| 114 | - 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 115 | - 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 116 | - 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 117 | - 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 118 | - 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
| 119 | - 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 120 | - 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 121 | - 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 122 | - 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 123 | - 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 124 | - 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
| 125 | - 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 126 | - 'published' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 127 | - 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 128 | - 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 129 | - 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
| 130 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 131 | - 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 132 | - 'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 133 | - 'requestdate' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
| 134 | - ]; |
|
| 95 | + $mod_fields = [ |
|
| 96 | + 'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false], |
|
| 97 | + 'lid' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 98 | + 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 99 | + 'title' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 100 | + 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 101 | + 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
| 102 | + 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
| 103 | + 'homepage' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 104 | + 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
| 105 | + 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
| 106 | + 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
| 107 | + 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 108 | + 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 109 | + 'publisher' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 110 | + 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
| 111 | + 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 112 | + 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 113 | + 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
| 114 | + 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 115 | + 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 116 | + 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 117 | + 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 118 | + 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
| 119 | + 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 120 | + 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 121 | + 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 122 | + 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 123 | + 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 124 | + 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
| 125 | + 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 126 | + 'published' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 127 | + 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
| 128 | + 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 129 | + 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
| 130 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 131 | + 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 132 | + 'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 133 | + 'requestdate' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
| 134 | + ]; |
|
| 135 | 135 | |
| 136 | - $renamed_fields = [ |
|
| 137 | - 'logourl' => 'screenshot' |
|
| 138 | - ]; |
|
| 136 | + $renamed_fields = [ |
|
| 137 | + 'logourl' => 'screenshot' |
|
| 138 | + ]; |
|
| 139 | 139 | |
| 140 | - echo '<br><b>Checking Modified Downloads table</b><br>'; |
|
| 141 | - $moduleHandler = xoops_getModuleHandler('modification', 'wfdownloads'); |
|
| 142 | - $mod_table = new Wfdownloads\DbupdaterTable('wfdownloads_mod'); |
|
| 143 | - $fields = get_table_info($moduleHandler->table, $mod_fields); |
|
| 144 | - rename_fields($mod_table, $renamed_fields, $fields, $mod_fields); |
|
| 145 | - update_table($mod_fields, $fields, $mod_table); |
|
| 146 | - if ($dbupdater->updateTable($mod_table)) { |
|
| 147 | - echo 'Modified Downloads table updated <br>'; |
|
| 148 | - } |
|
| 149 | - unset($fields); |
|
| 140 | + echo '<br><b>Checking Modified Downloads table</b><br>'; |
|
| 141 | + $moduleHandler = xoops_getModuleHandler('modification', 'wfdownloads'); |
|
| 142 | + $mod_table = new Wfdownloads\DbupdaterTable('wfdownloads_mod'); |
|
| 143 | + $fields = get_table_info($moduleHandler->table, $mod_fields); |
|
| 144 | + rename_fields($mod_table, $renamed_fields, $fields, $mod_fields); |
|
| 145 | + update_table($mod_fields, $fields, $mod_table); |
|
| 146 | + if ($dbupdater->updateTable($mod_table)) { |
|
| 147 | + echo 'Modified Downloads table updated <br>'; |
|
| 148 | + } |
|
| 149 | + unset($fields); |
|
| 150 | 150 | |
| 151 | - $cat_fields = [ |
|
| 152 | - 'cid' => ['Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false], |
|
| 153 | - 'pid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 154 | - 'title' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
| 155 | - 'imgurl' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 156 | - 'description' => ['Type' => 'text NULL', 'Default' => true], |
|
| 157 | - 'total' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 158 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 159 | - 'spotlighttop' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 160 | - 'spotlighthis' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 161 | - 'dohtml' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 162 | - 'dosmiley' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 163 | - 'doxcode' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 164 | - 'doimage' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 165 | - 'dobr' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 166 | - 'weight' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
| 167 | - ]; |
|
| 168 | - echo '<br><b>Checking Category table</b><br>'; |
|
| 169 | - $catHandler = xoops_getModuleHandler('category', 'wfdownloads'); |
|
| 170 | - $cat_table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
| 171 | - $fields = get_table_info($catHandler->table, $cat_fields); |
|
| 172 | - update_table($cat_fields, $fields, $cat_table); |
|
| 173 | - if ($dbupdater->updateTable($cat_table)) { |
|
| 174 | - echo 'Category table updated<br>'; |
|
| 175 | - } |
|
| 176 | - unset($fields); |
|
| 151 | + $cat_fields = [ |
|
| 152 | + 'cid' => ['Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false], |
|
| 153 | + 'pid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
| 154 | + 'title' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
| 155 | + 'imgurl' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
| 156 | + 'description' => ['Type' => 'text NULL', 'Default' => true], |
|
| 157 | + 'total' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 158 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
| 159 | + 'spotlighttop' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 160 | + 'spotlighthis' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 161 | + 'dohtml' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 162 | + 'dosmiley' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 163 | + 'doxcode' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 164 | + 'doimage' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 165 | + 'dobr' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
| 166 | + 'weight' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
| 167 | + ]; |
|
| 168 | + echo '<br><b>Checking Category table</b><br>'; |
|
| 169 | + $catHandler = xoops_getModuleHandler('category', 'wfdownloads'); |
|
| 170 | + $cat_table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
| 171 | + $fields = get_table_info($catHandler->table, $cat_fields); |
|
| 172 | + update_table($cat_fields, $fields, $cat_table); |
|
| 173 | + if ($dbupdater->updateTable($cat_table)) { |
|
| 174 | + echo 'Category table updated<br>'; |
|
| 175 | + } |
|
| 176 | + unset($fields); |
|
| 177 | 177 | |
| 178 | - $broken_fields = [ |
|
| 179 | - 'reportid' => ['Type' => 'int(5) NOT NULL auto_increment', 'Default' => false], |
|
| 180 | - 'lid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 181 | - 'sender' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 182 | - 'ip' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
| 183 | - 'date' => ['Type' => "varchar(11) NOT NULL default '0'", 'Default' => true], |
|
| 184 | - 'confirmed' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true], |
|
| 185 | - 'acknowledged' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true] |
|
| 186 | - ]; |
|
| 187 | - echo '<br><b>Checking Broken Report table</b><br>'; |
|
| 188 | - $brokenHandler = xoops_getModuleHandler('report', 'wfdownloads'); |
|
| 189 | - $broken_table = new Wfdownloads\DbupdaterTable('wfdownloads_broken'); |
|
| 190 | - $fields = get_table_info($brokenHandler->table, $broken_fields); |
|
| 191 | - update_table($broken_fields, $fields, $broken_table); |
|
| 192 | - if ($dbupdater->updateTable($broken_table)) { |
|
| 193 | - echo 'Broken Reports table updated<br>'; |
|
| 194 | - } |
|
| 195 | - unset($fields); |
|
| 178 | + $broken_fields = [ |
|
| 179 | + 'reportid' => ['Type' => 'int(5) NOT NULL auto_increment', 'Default' => false], |
|
| 180 | + 'lid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 181 | + 'sender' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
| 182 | + 'ip' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
| 183 | + 'date' => ['Type' => "varchar(11) NOT NULL default '0'", 'Default' => true], |
|
| 184 | + 'confirmed' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true], |
|
| 185 | + 'acknowledged' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true] |
|
| 186 | + ]; |
|
| 187 | + echo '<br><b>Checking Broken Report table</b><br>'; |
|
| 188 | + $brokenHandler = xoops_getModuleHandler('report', 'wfdownloads'); |
|
| 189 | + $broken_table = new Wfdownloads\DbupdaterTable('wfdownloads_broken'); |
|
| 190 | + $fields = get_table_info($brokenHandler->table, $broken_fields); |
|
| 191 | + update_table($broken_fields, $fields, $broken_table); |
|
| 192 | + if ($dbupdater->updateTable($broken_table)) { |
|
| 193 | + echo 'Broken Reports table updated<br>'; |
|
| 194 | + } |
|
| 195 | + unset($fields); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // ========================================================================================= |
@@ -205,48 +205,48 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | function invert_nohtm_dohtml_values() |
| 207 | 207 | { |
| 208 | - $ret = []; |
|
| 209 | - global $xoopsDB; |
|
| 210 | - $catHandler = xoops_getModuleHandler('category', 'wfdownloads'); |
|
| 211 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
| 212 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
| 213 | - $fields[$existing_field['field']] = $existing_field['type']; |
|
| 214 | - } |
|
| 215 | - if (in_array('nohtml', array_keys($fields))) { |
|
| 216 | - $dbupdater = new Wfdownloads\Dbupdater(); |
|
| 217 | - //Invert column values |
|
| 218 | - // alter options in wfdownloads_cat |
|
| 219 | - $table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
| 220 | - $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 221 | - $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 222 | - $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 223 | - $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 224 | - $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 208 | + $ret = []; |
|
| 209 | + global $xoopsDB; |
|
| 210 | + $catHandler = xoops_getModuleHandler('category', 'wfdownloads'); |
|
| 211 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
| 212 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
| 213 | + $fields[$existing_field['field']] = $existing_field['type']; |
|
| 214 | + } |
|
| 215 | + if (in_array('nohtml', array_keys($fields))) { |
|
| 216 | + $dbupdater = new Wfdownloads\Dbupdater(); |
|
| 217 | + //Invert column values |
|
| 218 | + // alter options in wfdownloads_cat |
|
| 219 | + $table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
| 220 | + $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 221 | + $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 222 | + $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 223 | + $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 224 | + $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'"); |
|
| 225 | 225 | |
| 226 | - //inverting values no=1 <=> do=0 |
|
| 227 | - // have to store teporarly as value = 2 to |
|
| 228 | - // avoid putting everithing to same value |
|
| 229 | - // if you change 1 to 0, then 0 to one, |
|
| 230 | - // every value will be 1, follow me? |
|
| 231 | - $table->addUpdatedWhere('dohtml', 2, '=1'); |
|
| 232 | - $table->addUpdatedWhere('dohtml', 1, '=0'); |
|
| 233 | - $table->addUpdatedWhere('dohtml', 0, '=2'); |
|
| 226 | + //inverting values no=1 <=> do=0 |
|
| 227 | + // have to store teporarly as value = 2 to |
|
| 228 | + // avoid putting everithing to same value |
|
| 229 | + // if you change 1 to 0, then 0 to one, |
|
| 230 | + // every value will be 1, follow me? |
|
| 231 | + $table->addUpdatedWhere('dohtml', 2, '=1'); |
|
| 232 | + $table->addUpdatedWhere('dohtml', 1, '=0'); |
|
| 233 | + $table->addUpdatedWhere('dohtml', 0, '=2'); |
|
| 234 | 234 | |
| 235 | - $table->addUpdatedWhere('dosmiley', 2, '=1'); |
|
| 236 | - $table->addUpdatedWhere('dosmiley', 1, '=0'); |
|
| 237 | - $table->addUpdatedWhere('dosmiley', 0, '=2'); |
|
| 235 | + $table->addUpdatedWhere('dosmiley', 2, '=1'); |
|
| 236 | + $table->addUpdatedWhere('dosmiley', 1, '=0'); |
|
| 237 | + $table->addUpdatedWhere('dosmiley', 0, '=2'); |
|
| 238 | 238 | |
| 239 | - $table->addUpdatedWhere('doxcode', 2, '=1'); |
|
| 240 | - $table->addUpdatedWhere('doxcode', 1, '=0'); |
|
| 241 | - $table->addUpdatedWhere('doxcode', 0, '=2'); |
|
| 239 | + $table->addUpdatedWhere('doxcode', 2, '=1'); |
|
| 240 | + $table->addUpdatedWhere('doxcode', 1, '=0'); |
|
| 241 | + $table->addUpdatedWhere('doxcode', 0, '=2'); |
|
| 242 | 242 | |
| 243 | - $table->addUpdatedWhere('doimage', 2, '=1'); |
|
| 244 | - $table->addUpdatedWhere('doimage', 1, '=0'); |
|
| 245 | - $table->addUpdatedWhere('doimage', 0, '=2'); |
|
| 246 | - $ret = $dbupdater->updateTable($table); |
|
| 247 | - } |
|
| 243 | + $table->addUpdatedWhere('doimage', 2, '=1'); |
|
| 244 | + $table->addUpdatedWhere('doimage', 1, '=0'); |
|
| 245 | + $table->addUpdatedWhere('doimage', 0, '=2'); |
|
| 246 | + $ret = $dbupdater->updateTable($table); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - return $ret; |
|
| 249 | + return $ret; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -259,22 +259,22 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | function update_table($new_fields, $existing_fields, &$table) |
| 261 | 261 | { |
| 262 | - foreach ($new_fields as $field => $fieldinfo) { |
|
| 263 | - $type = $fieldinfo['Type']; |
|
| 264 | - if (!in_array($field, array_keys($existing_fields))) { |
|
| 265 | - //Add field as it is missing |
|
| 266 | - $table->addNewField($field, $type); |
|
| 267 | - //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
|
| 268 | - //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
|
| 269 | - } elseif ($existing_fields[$field] != $type) { |
|
| 270 | - $table->addAlteredField($field, $field . ' ' . $type); |
|
| 271 | - // check $fields[$field]['type'] for things like "int(10) unsigned" |
|
| 272 | - //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
|
| 273 | - //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
|
| 274 | - } else { |
|
| 275 | - //echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br>"; |
|
| 276 | - } |
|
| 277 | - } |
|
| 262 | + foreach ($new_fields as $field => $fieldinfo) { |
|
| 263 | + $type = $fieldinfo['Type']; |
|
| 264 | + if (!in_array($field, array_keys($existing_fields))) { |
|
| 265 | + //Add field as it is missing |
|
| 266 | + $table->addNewField($field, $type); |
|
| 267 | + //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
|
| 268 | + //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
|
| 269 | + } elseif ($existing_fields[$field] != $type) { |
|
| 270 | + $table->addAlteredField($field, $field . ' ' . $type); |
|
| 271 | + // check $fields[$field]['type'] for things like "int(10) unsigned" |
|
| 272 | + //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
|
| 273 | + //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
|
| 274 | + } else { |
|
| 275 | + //echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br>"; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -287,22 +287,22 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | function get_table_info($table, $default_fields) |
| 289 | 289 | { |
| 290 | - global $xoopsDB; |
|
| 291 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
| 292 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
| 293 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 294 | - if ('YES' !== $existing_field['Null']) { |
|
| 295 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 296 | - } |
|
| 297 | - if ($existing_field['Extra']) { |
|
| 298 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 299 | - } |
|
| 300 | - if ($default_fields[$existing_field['Field']]['Default']) { |
|
| 301 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 302 | - } |
|
| 303 | - } |
|
| 290 | + global $xoopsDB; |
|
| 291 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
| 292 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
| 293 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 294 | + if ('YES' !== $existing_field['Null']) { |
|
| 295 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 296 | + } |
|
| 297 | + if ($existing_field['Extra']) { |
|
| 298 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 299 | + } |
|
| 300 | + if ($default_fields[$existing_field['Field']]['Default']) { |
|
| 301 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - return $fields; |
|
| 305 | + return $fields; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -316,60 +316,60 @@ discard block |
||
| 316 | 316 | */ |
| 317 | 317 | function rename_fields(&$table, $renamed_fields, &$fields, $new_fields) |
| 318 | 318 | { |
| 319 | - foreach (array_keys($fields) as $field) { |
|
| 320 | - if (in_array($field, array_keys($renamed_fields))) { |
|
| 321 | - $new_field_name = $renamed_fields[$field]; |
|
| 322 | - $new_field_type = $new_fields[$new_field_name]['Type']; |
|
| 323 | - $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
| 324 | - //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
|
| 325 | - //echo $field." Renamed to ".$new_field_name."<br>"; |
|
| 326 | - $fields[$new_field_name] = $new_field_type; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - //return $fields; |
|
| 319 | + foreach (array_keys($fields) as $field) { |
|
| 320 | + if (in_array($field, array_keys($renamed_fields))) { |
|
| 321 | + $new_field_name = $renamed_fields[$field]; |
|
| 322 | + $new_field_type = $new_fields[$new_field_name]['Type']; |
|
| 323 | + $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
| 324 | + //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
|
| 325 | + //echo $field." Renamed to ".$new_field_name."<br>"; |
|
| 326 | + $fields[$new_field_name] = $new_field_type; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + //return $fields; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | $op = isset($_REQUEST['op']) ? (int)$_REQUEST['op'] : 0; |
| 333 | 333 | switch ($op) { |
| 334 | - case 1: |
|
| 335 | - // Make sure that nohtml is properly changed to dohtml |
|
| 336 | - invert_nohtm_dohtml_values(); |
|
| 337 | - // Ensure that the proper tables are present |
|
| 338 | - update_tables_to_300(); |
|
| 339 | - // Import data from MyDownloads |
|
| 340 | - import_mydownloads_to_wfdownloads(); |
|
| 341 | - break; |
|
| 334 | + case 1: |
|
| 335 | + // Make sure that nohtml is properly changed to dohtml |
|
| 336 | + invert_nohtm_dohtml_values(); |
|
| 337 | + // Ensure that the proper tables are present |
|
| 338 | + update_tables_to_300(); |
|
| 339 | + // Import data from MyDownloads |
|
| 340 | + import_mydownloads_to_wfdownloads(); |
|
| 341 | + break; |
|
| 342 | 342 | |
| 343 | - case 2: |
|
| 344 | - // Update WF-Downloads |
|
| 345 | - $log = invert_nohtm_dohtml_values(); |
|
| 346 | - update_tables_to_300(); |
|
| 347 | - break; |
|
| 343 | + case 2: |
|
| 344 | + // Update WF-Downloads |
|
| 345 | + $log = invert_nohtm_dohtml_values(); |
|
| 346 | + update_tables_to_300(); |
|
| 347 | + break; |
|
| 348 | 348 | |
| 349 | - default: |
|
| 350 | - //ask what to do |
|
| 351 | - include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 352 | - $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
|
| 349 | + default: |
|
| 350 | + //ask what to do |
|
| 351 | + include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 352 | + $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
|
| 353 | 353 | |
| 354 | - //Is MyDownloads installed? |
|
| 355 | - /** @var XoopsModuleHandler $moduleHandler */ |
|
| 356 | - $moduleHandler = xoops_getHandler('module'); |
|
| 357 | - $mydownloadsModule = $moduleHandler->getByDirname('mydownloads'); |
|
| 358 | - if (is_object($mydownloadsModule)) { |
|
| 359 | - $mydownloadsButton = new \XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit'); |
|
| 360 | - $mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'"); |
|
| 361 | - $form->addElement($mydownloadsButton); |
|
| 362 | - } |
|
| 354 | + //Is MyDownloads installed? |
|
| 355 | + /** @var XoopsModuleHandler $moduleHandler */ |
|
| 356 | + $moduleHandler = xoops_getHandler('module'); |
|
| 357 | + $mydownloadsModule = $moduleHandler->getByDirname('mydownloads'); |
|
| 358 | + if (is_object($mydownloadsModule)) { |
|
| 359 | + $mydownloadsButton = new \XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit'); |
|
| 360 | + $mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'"); |
|
| 361 | + $form->addElement($mydownloadsButton); |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | - if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
| 365 | - $updateButton = new \XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit'); |
|
| 366 | - $updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'"); |
|
| 367 | - $form->addElement($updateButton); |
|
| 368 | - } |
|
| 364 | + if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
| 365 | + $updateButton = new \XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit'); |
|
| 366 | + $updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'"); |
|
| 367 | + $form->addElement($updateButton); |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | - $form->addElement(new \XoopsFormHidden('op', 0)); |
|
| 371 | - $form->display(); |
|
| 372 | - break; |
|
| 370 | + $form->addElement(new \XoopsFormHidden('op', 0)); |
|
| 371 | + $form->display(); |
|
| 372 | + break; |
|
| 373 | 373 | } |
| 374 | 374 | //wfdownloads_modFooter(); |
| 375 | 375 | //xoops_cp_footer(); |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | use XoopsModules\Wfdownloads; |
| 11 | -require_once __DIR__ . '/admin_header.php'; |
|
| 12 | -require_once SMARTCONTENT_ROOT_PATH . 'class/dbupdater.php'; |
|
| 11 | +require_once __DIR__.'/admin_header.php'; |
|
| 12 | +require_once SMARTCONTENT_ROOT_PATH.'class/dbupdater.php'; |
|
| 13 | 13 | |
| 14 | 14 | smartcontent_xoops_cp_header(); |
| 15 | 15 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $ret = []; |
| 209 | 209 | global $xoopsDB; |
| 210 | 210 | $catHandler = xoops_getModuleHandler('category', 'wfdownloads'); |
| 211 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
| 211 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$catHandler->table); |
|
| 212 | 212 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
| 213 | 213 | $fields[$existing_field['field']] = $existing_field['type']; |
| 214 | 214 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
| 268 | 268 | //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
| 269 | 269 | } elseif ($existing_fields[$field] != $type) { |
| 270 | - $table->addAlteredField($field, $field . ' ' . $type); |
|
| 270 | + $table->addAlteredField($field, $field.' '.$type); |
|
| 271 | 271 | // check $fields[$field]['type'] for things like "int(10) unsigned" |
| 272 | 272 | //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
| 273 | 273 | //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
@@ -288,17 +288,17 @@ discard block |
||
| 288 | 288 | function get_table_info($table, $default_fields) |
| 289 | 289 | { |
| 290 | 290 | global $xoopsDB; |
| 291 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
| 291 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$table); |
|
| 292 | 292 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
| 293 | 293 | $fields[$existing_field['Field']] = $existing_field['Type']; |
| 294 | 294 | if ('YES' !== $existing_field['Null']) { |
| 295 | 295 | $fields[$existing_field['Field']] .= ' NOT NULL'; |
| 296 | 296 | } |
| 297 | 297 | if ($existing_field['Extra']) { |
| 298 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 298 | + $fields[$existing_field['Field']] .= ' '.$existing_field['Extra']; |
|
| 299 | 299 | } |
| 300 | 300 | if ($default_fields[$existing_field['Field']]['Default']) { |
| 301 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 301 | + $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'"; |
|
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | if (in_array($field, array_keys($renamed_fields))) { |
| 321 | 321 | $new_field_name = $renamed_fields[$field]; |
| 322 | 322 | $new_field_type = $new_fields[$new_field_name]['Type']; |
| 323 | - $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
| 323 | + $table->addAltered($field, $new_field_name.' '.$new_field_type); |
|
| 324 | 324 | //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
| 325 | 325 | //echo $field." Renamed to ".$new_field_name."<br>"; |
| 326 | 326 | $fields[$new_field_name] = $new_field_type; |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | //return $fields; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | -$op = isset($_REQUEST['op']) ? (int)$_REQUEST['op'] : 0; |
|
| 332 | +$op = isset($_REQUEST['op']) ? (int) $_REQUEST['op'] : 0; |
|
| 333 | 333 | switch ($op) { |
| 334 | 334 | case 1: |
| 335 | 335 | // Make sure that nohtml is properly changed to dohtml |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | default: |
| 350 | 350 | //ask what to do |
| 351 | - include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 351 | + include XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
| 352 | 352 | $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
| 353 | 353 | |
| 354 | 354 | //Is MyDownloads installed? |
@@ -373,4 +373,4 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | //wfdownloads_modFooter(); |
| 375 | 375 | //xoops_cp_footer(); |
| 376 | -require_once __DIR__ . '/admin_footer.php'; |
|
| 376 | +require_once __DIR__.'/admin_footer.php'; |
|