@@ -17,13 +17,13 @@ |
||
| 17 | 17 | $smartobjectCurrencyHandler = xoops_getModuleHandler('currency', 'smartobject'); |
| 18 | 18 | |
| 19 | 19 | if (!$smartobjectCurrenciesObj) { |
| 20 | - $smartobjectCurrenciesObj = $smartobjectCurrencyHandler->getCurrencies(); |
|
| 20 | + $smartobjectCurrenciesObj = $smartobjectCurrencyHandler->getCurrencies(); |
|
| 21 | 21 | } |
| 22 | 22 | if (!$smartobjectCurrenciesArray) { |
| 23 | - foreach ($smartobjectCurrenciesObj as $currencyid => $currencyObj) { |
|
| 24 | - if ($currencyObj->getVar('default_currency', 'e')) { |
|
| 25 | - $smartobjectDefaultCurrency = $currencyObj; |
|
| 26 | - } |
|
| 27 | - $smartobjectCurrenciesArray[$currencyid] = $currencyObj->getCode(); |
|
| 28 | - } |
|
| 23 | + foreach ($smartobjectCurrenciesObj as $currencyid => $currencyObj) { |
|
| 24 | + if ($currencyObj->getVar('default_currency', 'e')) { |
|
| 25 | + $smartobjectDefaultCurrency = $currencyObj; |
|
| 26 | + } |
|
| 27 | + $smartobjectCurrenciesArray[$currencyid] = $currencyObj->getCode(); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -35,26 +35,26 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function xoops_module_update_smartobject($module) |
| 37 | 37 | { |
| 38 | - ob_start(); |
|
| 38 | + ob_start(); |
|
| 39 | 39 | |
| 40 | - $dbVersion = smart_GetMeta('version', 'smartobject'); |
|
| 41 | - if (!$dbVersion) { |
|
| 42 | - $dbVersion = 0; |
|
| 43 | - } |
|
| 40 | + $dbVersion = smart_GetMeta('version', 'smartobject'); |
|
| 41 | + if (!$dbVersion) { |
|
| 42 | + $dbVersion = 0; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $dbupdater = new SmartobjectDbupdater(); |
|
| 45 | + $dbupdater = new SmartobjectDbupdater(); |
|
| 46 | 46 | |
| 47 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br />'; |
|
| 47 | + echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br />'; |
|
| 48 | 48 | |
| 49 | - // db migrate version = 1 |
|
| 50 | - $newDbVersion = 1; |
|
| 51 | - if ($dbVersion < $newDbVersion) { |
|
| 52 | - echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 49 | + // db migrate version = 1 |
|
| 50 | + $newDbVersion = 1; |
|
| 51 | + if ($dbVersion < $newDbVersion) { |
|
| 52 | + echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 53 | 53 | |
| 54 | - // Create table smartobject_link |
|
| 55 | - $table = new SmartDbTable('smartobject_link'); |
|
| 56 | - if (!$table->exists()) { |
|
| 57 | - $table->setStructure("CREATE TABLE %s ( |
|
| 54 | + // Create table smartobject_link |
|
| 55 | + $table = new SmartDbTable('smartobject_link'); |
|
| 56 | + if (!$table->exists()) { |
|
| 57 | + $table->setStructure("CREATE TABLE %s ( |
|
| 58 | 58 | `linkid` int(11) NOT NULL auto_increment, |
| 59 | 59 | `from_uid` int(11) NOT NULL default '0', |
| 60 | 60 | `from_email` varchar(255) NOT NULL default '', |
@@ -71,63 +71,63 @@ discard block |
||
| 71 | 71 | PRIMARY KEY (`linkid`) |
| 72 | 72 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
| 73 | 73 | |
| 74 | - if (!$dbupdater->updateTable($table)) { |
|
| 75 | - /** |
|
| 76 | - * @todo trap the errors |
|
| 77 | - */ |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - unset($table); |
|
| 81 | - // Create table smartobject_link |
|
| 82 | - $table = new SmartDbTable('smartobject_link'); |
|
| 83 | - if (!$table->fieldExists('date')) { |
|
| 84 | - $table->addNewField('date', "int(11) NOT NULL default '0'"); |
|
| 85 | - if (!$dbupdater->updateTable($table)) { |
|
| 86 | - /** |
|
| 87 | - * @todo trap the errors |
|
| 88 | - */ |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - unset($table); |
|
| 92 | - |
|
| 93 | - // Create table smartobject_tag |
|
| 94 | - $table = new SmartDbTable('smartobject_tag'); |
|
| 95 | - if (!$table->exists()) { |
|
| 96 | - $table->setStructure("CREATE TABLE %s ( |
|
| 74 | + if (!$dbupdater->updateTable($table)) { |
|
| 75 | + /** |
|
| 76 | + * @todo trap the errors |
|
| 77 | + */ |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + unset($table); |
|
| 81 | + // Create table smartobject_link |
|
| 82 | + $table = new SmartDbTable('smartobject_link'); |
|
| 83 | + if (!$table->fieldExists('date')) { |
|
| 84 | + $table->addNewField('date', "int(11) NOT NULL default '0'"); |
|
| 85 | + if (!$dbupdater->updateTable($table)) { |
|
| 86 | + /** |
|
| 87 | + * @todo trap the errors |
|
| 88 | + */ |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + unset($table); |
|
| 92 | + |
|
| 93 | + // Create table smartobject_tag |
|
| 94 | + $table = new SmartDbTable('smartobject_tag'); |
|
| 95 | + if (!$table->exists()) { |
|
| 96 | + $table->setStructure("CREATE TABLE %s ( |
|
| 97 | 97 | `tagid` int(11) NOT NULL auto_increment, |
| 98 | 98 | `name` varchar(255) NOT NULL default '', |
| 99 | 99 | `description` TEXT NOT NULL, |
| 100 | 100 | PRIMARY KEY (`id`) |
| 101 | 101 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
| 102 | 102 | |
| 103 | - if (!$dbupdater->updateTable($table)) { |
|
| 104 | - /** |
|
| 105 | - * @todo trap the errors |
|
| 106 | - */ |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Create table smartobject_tag_text |
|
| 111 | - $table = new SmartDbTable('smartobject_tag_text'); |
|
| 112 | - if (!$table->exists()) { |
|
| 113 | - $table->setStructure("CREATE TABLE %s ( |
|
| 103 | + if (!$dbupdater->updateTable($table)) { |
|
| 104 | + /** |
|
| 105 | + * @todo trap the errors |
|
| 106 | + */ |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Create table smartobject_tag_text |
|
| 111 | + $table = new SmartDbTable('smartobject_tag_text'); |
|
| 112 | + if (!$table->exists()) { |
|
| 113 | + $table->setStructure("CREATE TABLE %s ( |
|
| 114 | 114 | `tagid` int(11) NOT NULL default 0, |
| 115 | 115 | `language` varchar(255) NOT NULL default '', |
| 116 | 116 | `value` TEXT NOT NULL, |
| 117 | 117 | PRIMARY KEY (`id`, `language`) |
| 118 | 118 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
| 119 | 119 | |
| 120 | - if (!$dbupdater->updateTable($table)) { |
|
| 121 | - /** |
|
| 122 | - * @todo trap the errors |
|
| 123 | - */ |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Create table smartobject_adsense |
|
| 128 | - $table = new SmartDbTable('smartobject_adsense'); |
|
| 129 | - if (!$table->exists()) { |
|
| 130 | - $table->setStructure(" |
|
| 120 | + if (!$dbupdater->updateTable($table)) { |
|
| 121 | + /** |
|
| 122 | + * @todo trap the errors |
|
| 123 | + */ |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Create table smartobject_adsense |
|
| 128 | + $table = new SmartDbTable('smartobject_adsense'); |
|
| 129 | + if (!$table->exists()) { |
|
| 130 | + $table->setStructure(" |
|
| 131 | 131 | `adsenseid` int(11) NOT NULL auto_increment, |
| 132 | 132 | `format` VARCHAR(100) NOT NULL, |
| 133 | 133 | `description` TEXT NOT NULL, |
@@ -141,23 +141,23 @@ discard block |
||
| 141 | 141 | `tag` varchar(50) NOT NULL default '', |
| 142 | 142 | PRIMARY KEY (`adsenseid`) |
| 143 | 143 | "); |
| 144 | - } |
|
| 145 | - |
|
| 146 | - if (!$dbupdater->updateTable($table)) { |
|
| 147 | - /** |
|
| 148 | - * @todo trap the errors |
|
| 149 | - */ |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - // db migrate version = 2 |
|
| 153 | - $newDbVersion = 2; |
|
| 154 | - if ($dbVersion < $newDbVersion) { |
|
| 155 | - echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 156 | - |
|
| 157 | - // Create table smartobject_rating |
|
| 158 | - $table = new SmartDbTable('smartobject_rating'); |
|
| 159 | - if (!$table->exists()) { |
|
| 160 | - $table->setStructure(' |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if (!$dbupdater->updateTable($table)) { |
|
| 147 | + /** |
|
| 148 | + * @todo trap the errors |
|
| 149 | + */ |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + // db migrate version = 2 |
|
| 153 | + $newDbVersion = 2; |
|
| 154 | + if ($dbVersion < $newDbVersion) { |
|
| 155 | + echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 156 | + |
|
| 157 | + // Create table smartobject_rating |
|
| 158 | + $table = new SmartDbTable('smartobject_rating'); |
|
| 159 | + if (!$table->exists()) { |
|
| 160 | + $table->setStructure(' |
|
| 161 | 161 | `ratingid` int(11) NOT NULL auto_increment, |
| 162 | 162 | `dirname` VARCHAR(255) NOT NULL, |
| 163 | 163 | `item` VARCHAR(255) NOT NULL, |
@@ -168,36 +168,36 @@ discard block |
||
| 168 | 168 | PRIMARY KEY (`ratingid`), |
| 169 | 169 | UNIQUE (`dirname`, `item`, `itemid`, `uid`) |
| 170 | 170 | '); |
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (!$dbupdater->updateTable($table)) { |
|
| 174 | - /** |
|
| 175 | - * @todo trap the errors |
|
| 176 | - */ |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // Create table smartobject_currency |
|
| 180 | - $table = new SmartDbTable('smartobject_currency'); |
|
| 181 | - $table->setData("2, 'EUR', 'Euro', '�', 0.65, 0"); |
|
| 182 | - $table->setData("3, 'USD', 'American dollar', '$', 0.9, 0"); |
|
| 183 | - $table->setData("1, 'CAD', 'Canadian dollar', '$', 1, 1"); |
|
| 184 | - |
|
| 185 | - if (!$dbupdater->updateTable($table)) { |
|
| 186 | - /** |
|
| 187 | - * @todo trap the errors |
|
| 188 | - */ |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // db migrate version = 3 |
|
| 193 | - $newDbVersion = 3; |
|
| 194 | - if ($dbVersion < $newDbVersion) { |
|
| 195 | - echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 196 | - |
|
| 197 | - // Create table smartobject_customtag |
|
| 198 | - $table = new SmartDbTable('smartobject_customtag'); |
|
| 199 | - if (!$table->exists()) { |
|
| 200 | - $table->setStructure(' |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (!$dbupdater->updateTable($table)) { |
|
| 174 | + /** |
|
| 175 | + * @todo trap the errors |
|
| 176 | + */ |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // Create table smartobject_currency |
|
| 180 | + $table = new SmartDbTable('smartobject_currency'); |
|
| 181 | + $table->setData("2, 'EUR', 'Euro', '�', 0.65, 0"); |
|
| 182 | + $table->setData("3, 'USD', 'American dollar', '$', 0.9, 0"); |
|
| 183 | + $table->setData("1, 'CAD', 'Canadian dollar', '$', 1, 1"); |
|
| 184 | + |
|
| 185 | + if (!$dbupdater->updateTable($table)) { |
|
| 186 | + /** |
|
| 187 | + * @todo trap the errors |
|
| 188 | + */ |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // db migrate version = 3 |
|
| 193 | + $newDbVersion = 3; |
|
| 194 | + if ($dbVersion < $newDbVersion) { |
|
| 195 | + echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 196 | + |
|
| 197 | + // Create table smartobject_customtag |
|
| 198 | + $table = new SmartDbTable('smartobject_customtag'); |
|
| 199 | + if (!$table->exists()) { |
|
| 200 | + $table->setStructure(' |
|
| 201 | 201 | `customtagid` int(11) NOT NULL auto_increment, |
| 202 | 202 | `name` VARCHAR(255) NOT NULL, |
| 203 | 203 | `description` TEXT NOT NULL, |
@@ -205,24 +205,24 @@ discard block |
||
| 205 | 205 | `language` TEXT NOT NULL, |
| 206 | 206 | PRIMARY KEY (`customtagid`) |
| 207 | 207 | '); |
| 208 | - } |
|
| 209 | - |
|
| 210 | - if (!$dbupdater->updateTable($table)) { |
|
| 211 | - /** |
|
| 212 | - * @todo trap the errors |
|
| 213 | - */ |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // db migrate version = 4 |
|
| 218 | - $newDbVersion = 4; |
|
| 219 | - if ($dbVersion < $newDbVersion) { |
|
| 220 | - echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 221 | - |
|
| 222 | - // Create table smartobject_currency |
|
| 223 | - $table = new SmartDbTable('smartobject_currency'); |
|
| 224 | - if (!$table->exists()) { |
|
| 225 | - $table->setStructure(' |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if (!$dbupdater->updateTable($table)) { |
|
| 211 | + /** |
|
| 212 | + * @todo trap the errors |
|
| 213 | + */ |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // db migrate version = 4 |
|
| 218 | + $newDbVersion = 4; |
|
| 219 | + if ($dbVersion < $newDbVersion) { |
|
| 220 | + echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 221 | + |
|
| 222 | + // Create table smartobject_currency |
|
| 223 | + $table = new SmartDbTable('smartobject_currency'); |
|
| 224 | + if (!$table->exists()) { |
|
| 225 | + $table->setStructure(' |
|
| 226 | 226 | `currencyid` int(11) NOT NULL auto_increment, |
| 227 | 227 | `iso4217` VARCHAR(5) NOT NULL, |
| 228 | 228 | `name` VARCHAR(255) NOT NULL, |
@@ -231,46 +231,46 @@ discard block |
||
| 231 | 231 | `default_currency` int(1) NOT NULL, |
| 232 | 232 | PRIMARY KEY (`currencyid`) |
| 233 | 233 | '); |
| 234 | - } |
|
| 235 | - |
|
| 236 | - if (!$dbupdater->updateTable($table)) { |
|
| 237 | - /** |
|
| 238 | - * @todo trap the errors |
|
| 239 | - */ |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // db migrate version = 6 |
|
| 244 | - $newDbVersion = 6; |
|
| 245 | - if ($dbVersion < $newDbVersion) { |
|
| 246 | - echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $newDbVersion = 7; |
|
| 250 | - if ($dbVersion < $newDbVersion) { |
|
| 251 | - echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 252 | - |
|
| 253 | - // Create table smartobject_file |
|
| 254 | - $table = new SmartDbTable('smartobject_file'); |
|
| 255 | - if (!$table->exists()) { |
|
| 256 | - $table->setStructure(' |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if (!$dbupdater->updateTable($table)) { |
|
| 237 | + /** |
|
| 238 | + * @todo trap the errors |
|
| 239 | + */ |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // db migrate version = 6 |
|
| 244 | + $newDbVersion = 6; |
|
| 245 | + if ($dbVersion < $newDbVersion) { |
|
| 246 | + echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $newDbVersion = 7; |
|
| 250 | + if ($dbVersion < $newDbVersion) { |
|
| 251 | + echo 'Database migrate to version ' . $newDbVersion . '<br />'; |
|
| 252 | + |
|
| 253 | + // Create table smartobject_file |
|
| 254 | + $table = new SmartDbTable('smartobject_file'); |
|
| 255 | + if (!$table->exists()) { |
|
| 256 | + $table->setStructure(' |
|
| 257 | 257 | `fileid` int(11) NOT NULL auto_increment, |
| 258 | 258 | `caption` varchar(255) collate latin1_general_ci NOT NULL, |
| 259 | 259 | `url` varchar(255) collate latin1_general_ci NOT NULL, |
| 260 | 260 | `description` text collate latin1_general_ci NOT NULL, |
| 261 | 261 | PRIMARY KEY (`fileid`) |
| 262 | 262 | '); |
| 263 | - if (!$dbupdater->updateTable($table)) { |
|
| 264 | - /** |
|
| 265 | - * @todo trap the errors |
|
| 266 | - */ |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - unset($table); |
|
| 270 | - // Create table smartobject_urllink |
|
| 271 | - $table = new SmartDbTable('smartobject_urllink'); |
|
| 272 | - if (!$table->exists()) { |
|
| 273 | - $table->setStructure(' |
|
| 263 | + if (!$dbupdater->updateTable($table)) { |
|
| 264 | + /** |
|
| 265 | + * @todo trap the errors |
|
| 266 | + */ |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + unset($table); |
|
| 270 | + // Create table smartobject_urllink |
|
| 271 | + $table = new SmartDbTable('smartobject_urllink'); |
|
| 272 | + if (!$table->exists()) { |
|
| 273 | + $table->setStructure(' |
|
| 274 | 274 | `urllinkid` int(11) NOT NULL auto_increment, |
| 275 | 275 | `caption` varchar(255) collate latin1_general_ci NOT NULL, |
| 276 | 276 | `url` varchar(255) collate latin1_general_ci NOT NULL, |
@@ -278,25 +278,25 @@ discard block |
||
| 278 | 278 | `target` varchar(10) collate latin1_general_ci NOT NULL, |
| 279 | 279 | PRIMARY KEY (`urllinkid`) |
| 280 | 280 | '); |
| 281 | - if (!$dbupdater->updateTable($table)) { |
|
| 282 | - /** |
|
| 283 | - * @todo trap the errors |
|
| 284 | - */ |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - unset($table); |
|
| 288 | - } |
|
| 289 | - echo '</code>'; |
|
| 290 | - |
|
| 291 | - $feedback = ob_get_clean(); |
|
| 292 | - if (method_exists($module, 'setMessage')) { |
|
| 293 | - $module->setMessage($feedback); |
|
| 294 | - } else { |
|
| 295 | - echo $feedback; |
|
| 296 | - } |
|
| 297 | - smart_SetMeta('version', $newDbVersion, 'smartobject'); //Set meta version to current |
|
| 298 | - |
|
| 299 | - return true; |
|
| 281 | + if (!$dbupdater->updateTable($table)) { |
|
| 282 | + /** |
|
| 283 | + * @todo trap the errors |
|
| 284 | + */ |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + unset($table); |
|
| 288 | + } |
|
| 289 | + echo '</code>'; |
|
| 290 | + |
|
| 291 | + $feedback = ob_get_clean(); |
|
| 292 | + if (method_exists($module, 'setMessage')) { |
|
| 293 | + $module->setMessage($feedback); |
|
| 294 | + } else { |
|
| 295 | + echo $feedback; |
|
| 296 | + } |
|
| 297 | + smart_SetMeta('version', $newDbVersion, 'smartobject'); //Set meta version to current |
|
| 298 | + |
|
| 299 | + return true; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -305,10 +305,10 @@ discard block |
||
| 305 | 305 | */ |
| 306 | 306 | function xoops_module_install_smartobject($module) |
| 307 | 307 | { |
| 308 | - ob_start(); |
|
| 308 | + ob_start(); |
|
| 309 | 309 | |
| 310 | - echo 'Using the ImpressCMS onInstall event'; |
|
| 311 | - $feedback = ob_get_clean(); |
|
| 310 | + echo 'Using the ImpressCMS onInstall event'; |
|
| 311 | + $feedback = ob_get_clean(); |
|
| 312 | 312 | |
| 313 | - return $feedback; |
|
| 313 | + return $feedback; |
|
| 314 | 314 | } |
@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function xoops_debug_dumbQuery($msg = '') |
| 16 | 16 | { |
| 17 | - global $xoopsDB; |
|
| 18 | - $xoopsDB->query('SELECT * ' . $msg . ' FROM dudewhereismycar2'); |
|
| 17 | + global $xoopsDB; |
|
| 18 | + $xoopsDB->query('SELECT * ' . $msg . ' FROM dudewhereismycar2'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | function xoops_debug_initiateQueryCount() |
| 22 | 22 | { |
| 23 | - global $smartfactory_query_count_activated, $smartfactory_query_count; |
|
| 24 | - $smartfactory_query_count_activated = true; |
|
| 25 | - $smartfactory_query_count = 0; |
|
| 23 | + global $smartfactory_query_count_activated, $smartfactory_query_count; |
|
| 24 | + $smartfactory_query_count_activated = true; |
|
| 25 | + $smartfactory_query_count = 0; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | function xoops_debug_getQueryCount($msg = '') |
| 32 | 32 | { |
| 33 | - global $smartfactory_query_count; |
|
| 33 | + global $smartfactory_query_count; |
|
| 34 | 34 | |
| 35 | - return xoops_debug("xoops debug Query count ($msg): $smartfactory_query_count"); |
|
| 35 | + return xoops_debug("xoops debug Query count ($msg): $smartfactory_query_count"); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,10 +41,10 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function xoops_debug($msg, $exit = false) |
| 43 | 43 | { |
| 44 | - echo "<div style='padding: 5px; color: red; font-weight: bold'>debug:: $msg</div>"; |
|
| 45 | - if ($exit) { |
|
| 46 | - die(); |
|
| 47 | - } |
|
| 44 | + echo "<div style='padding: 5px; color: red; font-weight: bold'>debug:: $msg</div>"; |
|
| 45 | + if ($exit) { |
|
| 46 | + die(); |
|
| 47 | + } |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | function xoops_comment($msg) |
| 54 | 54 | { |
| 55 | - echo "<div style='padding: 5px; color: green; font-weight: bold'>=> $msg</div>"; |
|
| 55 | + echo "<div style='padding: 5px; color: green; font-weight: bold'>=> $msg</div>"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function xoops_debug_vardump($var) |
| 62 | 62 | { |
| 63 | - if (class_exists('MyTextSanitizer')) { |
|
| 64 | - $myts = MyTextSanitizer::getInstance(); |
|
| 65 | - xoops_debug($myts->displayTarea(var_export($var, true))); |
|
| 66 | - } else { |
|
| 67 | - xoops_debug(var_export($var, true)); |
|
| 68 | - } |
|
| 63 | + if (class_exists('MyTextSanitizer')) { |
|
| 64 | + $myts = MyTextSanitizer::getInstance(); |
|
| 65 | + xoops_debug($myts->displayTarea(var_export($var, true))); |
|
| 66 | + } else { |
|
| 67 | + xoops_debug(var_export($var, true)); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Image Creation script |
|
| 4 | - * |
|
| 5 | - * D.J. |
|
| 6 | - */ |
|
| 3 | + * Image Creation script |
|
| 4 | + * |
|
| 5 | + * D.J. |
|
| 6 | + */ |
|
| 7 | 7 | |
| 8 | 8 | include dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/mainfile.php'; |
| 9 | 9 | error_reporting(0); |
| 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,185 +18,185 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class XoopsCaptchaImageHandler |
| 20 | 20 | { |
| 21 | - public $config = array(); |
|
| 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 = array('imagecreatetruecolor', 'imagecolorallocate', 'imagefilledrectangle', 'imagejpeg', 'imagedestroy', 'imageftbbox'); |
|
| 44 | - foreach ($required_functions as $func) { |
|
| 45 | - if (!function_exists($func)) { |
|
| 46 | - $this->mode = 'bmp'; |
|
| 47 | - break; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Loading configs from CAPTCHA class |
|
| 55 | - * @param array $config |
|
| 56 | - */ |
|
| 57 | - public function setConfig($config = array()) |
|
| 58 | - { |
|
| 59 | - // Loading default preferences |
|
| 60 | - $this->config = $config; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function loadImage() |
|
| 64 | - { |
|
| 65 | - $this->createCode(); |
|
| 66 | - $this->setCode(); |
|
| 67 | - $this->createImage(); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Create Code |
|
| 72 | - */ |
|
| 73 | - public function createCode() |
|
| 74 | - { |
|
| 75 | - if ($this->invalid) { |
|
| 76 | - return; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ($this->mode === 'bmp') { |
|
| 80 | - $this->config['num_chars'] = 4; |
|
| 81 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
| 82 | - } else { |
|
| 83 | - $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
| 84 | - if (!$this->config['casesensitive']) { |
|
| 85 | - $this->code = strtoupper($this->code); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - public function setCode() |
|
| 91 | - { |
|
| 92 | - if ($this->invalid) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 97 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 98 | - |
|
| 99 | - // Increase the attempt records on refresh |
|
| 100 | - if (!empty($maxAttempts)) { |
|
| 101 | - $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
| 102 | - if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
| 103 | - $this->invalid = true; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $file |
|
| 110 | - * @return string|void |
|
| 111 | - */ |
|
| 112 | - public function createImage($file = '') |
|
| 113 | - { |
|
| 114 | - if ($this->invalid) { |
|
| 115 | - header('Content-type: image/gif'); |
|
| 116 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
| 117 | - |
|
| 118 | - return; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ($this->mode === 'bmp') { |
|
| 122 | - return $this->createImageBmp(); |
|
| 123 | - } else { |
|
| 124 | - return $this->createImageGd(); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Create CAPTCHA iamge with GD |
|
| 130 | - * Originated from DuGris' SecurityImage |
|
| 131 | - * @param string $file |
|
| 132 | - */ |
|
| 133 | - // --------------------------------------------------------------------------- // |
|
| 134 | - // Class: SecurityImage 1.5 // |
|
| 135 | - // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
| 136 | - // Email: [email protected] // |
|
| 137 | - // Licence: GNU // |
|
| 138 | - // Project: XOOPS Project // |
|
| 139 | - // --------------------------------------------------------------------------- // |
|
| 140 | - public function createImageGd($file = '') |
|
| 141 | - { |
|
| 142 | - $this->loadFont(); |
|
| 143 | - $this->setImageSize(); |
|
| 144 | - |
|
| 145 | - $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
| 146 | - $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
| 147 | - imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
| 148 | - |
|
| 149 | - switch ($this->config['background_type']) { |
|
| 150 | - default: |
|
| 151 | - case 0: |
|
| 152 | - $this->drawBars(); |
|
| 153 | - break; |
|
| 154 | - |
|
| 155 | - case 1: |
|
| 156 | - $this->drawCircles(); |
|
| 157 | - break; |
|
| 158 | - |
|
| 159 | - case 2: |
|
| 160 | - $this->drawLines(); |
|
| 161 | - break; |
|
| 162 | - |
|
| 163 | - case 3: |
|
| 164 | - $this->drawRectangles(); |
|
| 165 | - break; |
|
| 166 | - |
|
| 167 | - case 4: |
|
| 168 | - $this->drawEllipses(); |
|
| 169 | - break; |
|
| 170 | - |
|
| 171 | - case 5: |
|
| 172 | - $this->drawPolygons(); |
|
| 173 | - break; |
|
| 174 | - |
|
| 175 | - case 100: |
|
| 176 | - $this->createFromFile(); |
|
| 177 | - break; |
|
| 178 | - } |
|
| 179 | - $this->drawBorder(); |
|
| 180 | - $this->drawCode(); |
|
| 181 | - |
|
| 182 | - if (empty($file)) { |
|
| 183 | - header('Content-type: image/jpeg'); |
|
| 184 | - imagejpeg($this->oImage); |
|
| 185 | - } else { |
|
| 186 | - imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
| 187 | - } |
|
| 188 | - imagedestroy($this->oImage); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @param $name |
|
| 193 | - * @param string $extension |
|
| 194 | - * @return array |
|
| 195 | - */ |
|
| 196 | - public function _getList($name, $extension = '') |
|
| 197 | - { |
|
| 198 | - $items = array(); |
|
| 199 | - /* |
|
| 21 | + public $config = array(); |
|
| 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 = array('imagecreatetruecolor', 'imagecolorallocate', 'imagefilledrectangle', 'imagejpeg', 'imagedestroy', 'imageftbbox'); |
|
| 44 | + foreach ($required_functions as $func) { |
|
| 45 | + if (!function_exists($func)) { |
|
| 46 | + $this->mode = 'bmp'; |
|
| 47 | + break; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Loading configs from CAPTCHA class |
|
| 55 | + * @param array $config |
|
| 56 | + */ |
|
| 57 | + public function setConfig($config = array()) |
|
| 58 | + { |
|
| 59 | + // Loading default preferences |
|
| 60 | + $this->config = $config; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function loadImage() |
|
| 64 | + { |
|
| 65 | + $this->createCode(); |
|
| 66 | + $this->setCode(); |
|
| 67 | + $this->createImage(); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Create Code |
|
| 72 | + */ |
|
| 73 | + public function createCode() |
|
| 74 | + { |
|
| 75 | + if ($this->invalid) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ($this->mode === 'bmp') { |
|
| 80 | + $this->config['num_chars'] = 4; |
|
| 81 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
| 82 | + } else { |
|
| 83 | + $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
| 84 | + if (!$this->config['casesensitive']) { |
|
| 85 | + $this->code = strtoupper($this->code); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + public function setCode() |
|
| 91 | + { |
|
| 92 | + if ($this->invalid) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 97 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 98 | + |
|
| 99 | + // Increase the attempt records on refresh |
|
| 100 | + if (!empty($maxAttempts)) { |
|
| 101 | + $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
| 102 | + if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
| 103 | + $this->invalid = true; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $file |
|
| 110 | + * @return string|void |
|
| 111 | + */ |
|
| 112 | + public function createImage($file = '') |
|
| 113 | + { |
|
| 114 | + if ($this->invalid) { |
|
| 115 | + header('Content-type: image/gif'); |
|
| 116 | + readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
| 117 | + |
|
| 118 | + return; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ($this->mode === 'bmp') { |
|
| 122 | + return $this->createImageBmp(); |
|
| 123 | + } else { |
|
| 124 | + return $this->createImageGd(); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Create CAPTCHA iamge with GD |
|
| 130 | + * Originated from DuGris' SecurityImage |
|
| 131 | + * @param string $file |
|
| 132 | + */ |
|
| 133 | + // --------------------------------------------------------------------------- // |
|
| 134 | + // Class: SecurityImage 1.5 // |
|
| 135 | + // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
| 136 | + // Email: [email protected] // |
|
| 137 | + // Licence: GNU // |
|
| 138 | + // Project: XOOPS Project // |
|
| 139 | + // --------------------------------------------------------------------------- // |
|
| 140 | + public function createImageGd($file = '') |
|
| 141 | + { |
|
| 142 | + $this->loadFont(); |
|
| 143 | + $this->setImageSize(); |
|
| 144 | + |
|
| 145 | + $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
| 146 | + $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
| 147 | + imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
| 148 | + |
|
| 149 | + switch ($this->config['background_type']) { |
|
| 150 | + default: |
|
| 151 | + case 0: |
|
| 152 | + $this->drawBars(); |
|
| 153 | + break; |
|
| 154 | + |
|
| 155 | + case 1: |
|
| 156 | + $this->drawCircles(); |
|
| 157 | + break; |
|
| 158 | + |
|
| 159 | + case 2: |
|
| 160 | + $this->drawLines(); |
|
| 161 | + break; |
|
| 162 | + |
|
| 163 | + case 3: |
|
| 164 | + $this->drawRectangles(); |
|
| 165 | + break; |
|
| 166 | + |
|
| 167 | + case 4: |
|
| 168 | + $this->drawEllipses(); |
|
| 169 | + break; |
|
| 170 | + |
|
| 171 | + case 5: |
|
| 172 | + $this->drawPolygons(); |
|
| 173 | + break; |
|
| 174 | + |
|
| 175 | + case 100: |
|
| 176 | + $this->createFromFile(); |
|
| 177 | + break; |
|
| 178 | + } |
|
| 179 | + $this->drawBorder(); |
|
| 180 | + $this->drawCode(); |
|
| 181 | + |
|
| 182 | + if (empty($file)) { |
|
| 183 | + header('Content-type: image/jpeg'); |
|
| 184 | + imagejpeg($this->oImage); |
|
| 185 | + } else { |
|
| 186 | + imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
| 187 | + } |
|
| 188 | + imagedestroy($this->oImage); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @param $name |
|
| 193 | + * @param string $extension |
|
| 194 | + * @return array |
|
| 195 | + */ |
|
| 196 | + public function _getList($name, $extension = '') |
|
| 197 | + { |
|
| 198 | + $items = array(); |
|
| 199 | + /* |
|
| 200 | 200 | if (@ include_once XOOPS_ROOT_PATH."/Frameworks/art/functions.ini.php") { |
| 201 | 201 | load_functions("cache"); |
| 202 | 202 | if ($items = mod_loadCacheFile("captcha_{$name}", "captcha")) { |
@@ -204,231 +204,231 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | */ |
| 207 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 208 | - $file_path = $this->config['rootpath'] . "/{$name}"; |
|
| 209 | - $files = XoopsLists::getFileListAsArray($file_path); |
|
| 210 | - foreach ($files as $item) { |
|
| 211 | - if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
| 212 | - $items[] = $item; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - if (function_exists('mod_createCacheFile')) { |
|
| 216 | - mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - return $items; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - public function loadFont() |
|
| 223 | - { |
|
| 224 | - $fonts = $this->_getList('fonts', 'ttf'); |
|
| 225 | - $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - public function setImageSize() |
|
| 229 | - { |
|
| 230 | - $MaxCharWidth = 0; |
|
| 231 | - $MaxCharHeight = 0; |
|
| 232 | - $oImage = imagecreatetruecolor(100, 100); |
|
| 233 | - $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 234 | - $FontSize = $this->config['fontsize_max']; |
|
| 235 | - for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
| 236 | - for ($i = 65; $i <= 90; ++$i) { |
|
| 237 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), array()); |
|
| 238 | - $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
| 239 | - if ($_MaxCharWidth > $MaxCharWidth) { |
|
| 240 | - $MaxCharWidth = $_MaxCharWidth; |
|
| 241 | - } |
|
| 242 | - $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 243 | - if ($_MaxCharHeight > $MaxCharHeight) { |
|
| 244 | - $MaxCharHeight = $_MaxCharHeight; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - imagedestroy($oImage); |
|
| 249 | - |
|
| 250 | - $this->height = $MaxCharHeight + 2; |
|
| 251 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 252 | - $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Return random background |
|
| 257 | - * |
|
| 258 | - * @return array |
|
| 259 | - */ |
|
| 260 | - public function loadBackground() |
|
| 261 | - { |
|
| 262 | - $RandBackground = null; |
|
| 263 | - if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
| 264 | - $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return $RandBackground; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Draw Image background |
|
| 272 | - */ |
|
| 273 | - public function createFromFile() |
|
| 274 | - { |
|
| 275 | - if ($RandImage = $this->loadBackground()) { |
|
| 276 | - $ImageType = @getimagesize($RandImage); |
|
| 277 | - switch (@$ImageType[2]) { |
|
| 278 | - case 1: |
|
| 279 | - $BackgroundImage = imagecreatefromgif($RandImage); |
|
| 280 | - break; |
|
| 281 | - |
|
| 282 | - case 2: |
|
| 283 | - $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
| 284 | - break; |
|
| 285 | - |
|
| 286 | - case 3: |
|
| 287 | - $BackgroundImage = imagecreatefrompng($RandImage); |
|
| 288 | - break; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - if (!empty($BackgroundImage)) { |
|
| 292 | - imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
| 293 | - imagedestroy($BackgroundImage); |
|
| 294 | - } else { |
|
| 295 | - $this->drawBars(); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Draw Code |
|
| 301 | - */ |
|
| 302 | - public function drawCode() |
|
| 303 | - { |
|
| 304 | - for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
| 305 | - // select random greyscale colour |
|
| 306 | - $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 307 | - |
|
| 308 | - // write text to image |
|
| 309 | - $Angle = mt_rand(10, 30); |
|
| 310 | - if ($i % 2) { |
|
| 311 | - $Angle = mt_rand(-10, -30); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // select random font size |
|
| 315 | - $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
| 316 | - |
|
| 317 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], array()); |
|
| 318 | - $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 319 | - |
|
| 320 | - // calculate character starting coordinates |
|
| 321 | - $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
| 322 | - $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
| 323 | - |
|
| 324 | - imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()); |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Draw Border |
|
| 330 | - */ |
|
| 331 | - public function drawBorder() |
|
| 332 | - { |
|
| 333 | - $rgb = mt_rand(50, 150); |
|
| 334 | - $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
| 335 | - imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Draw Circles background |
|
| 340 | - */ |
|
| 341 | - public function drawCircles() |
|
| 342 | - { |
|
| 343 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 344 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 345 | - imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Draw Lines background |
|
| 351 | - */ |
|
| 352 | - public function drawLines() |
|
| 353 | - { |
|
| 354 | - for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
| 355 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 356 | - imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Draw Rectangles background |
|
| 362 | - */ |
|
| 363 | - public function drawRectangles() |
|
| 364 | - { |
|
| 365 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 366 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 367 | - imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Draw Bars background |
|
| 373 | - */ |
|
| 374 | - public function drawBars() |
|
| 375 | - { |
|
| 376 | - for ($i = 0; $i <= $this->height;) { |
|
| 377 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 378 | - imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
| 379 | - $i = $i + 2.5; |
|
| 380 | - } |
|
| 381 | - for ($i = 0; $i <= $this->width;) { |
|
| 382 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 383 | - imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
| 384 | - $i = $i + 2.5; |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Draw Ellipses background |
|
| 390 | - */ |
|
| 391 | - public function drawEllipses() |
|
| 392 | - { |
|
| 393 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 394 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 395 | - imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Draw polygons background |
|
| 401 | - */ |
|
| 402 | - public function drawPolygons() |
|
| 403 | - { |
|
| 404 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 405 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 406 | - $coords = array(); |
|
| 407 | - for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
| 408 | - $coords[] = mt_rand(0, $this->width); |
|
| 409 | - $coords[] = mt_rand(0, $this->height); |
|
| 410 | - } |
|
| 411 | - imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Create CAPTCHA iamge with BMP |
|
| 417 | - * TODO |
|
| 418 | - * @param string $file |
|
| 419 | - * @return string |
|
| 420 | - */ |
|
| 421 | - public function createImageBmp($file = '') |
|
| 422 | - { |
|
| 423 | - $image = ''; |
|
| 424 | - |
|
| 425 | - if (empty($file)) { |
|
| 426 | - header('Content-type: image/bmp'); |
|
| 427 | - echo $image; |
|
| 428 | - } else { |
|
| 429 | - return $image; |
|
| 430 | - } |
|
| 431 | - } |
|
| 207 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 208 | + $file_path = $this->config['rootpath'] . "/{$name}"; |
|
| 209 | + $files = XoopsLists::getFileListAsArray($file_path); |
|
| 210 | + foreach ($files as $item) { |
|
| 211 | + if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
| 212 | + $items[] = $item; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + if (function_exists('mod_createCacheFile')) { |
|
| 216 | + mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + return $items; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + public function loadFont() |
|
| 223 | + { |
|
| 224 | + $fonts = $this->_getList('fonts', 'ttf'); |
|
| 225 | + $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + public function setImageSize() |
|
| 229 | + { |
|
| 230 | + $MaxCharWidth = 0; |
|
| 231 | + $MaxCharHeight = 0; |
|
| 232 | + $oImage = imagecreatetruecolor(100, 100); |
|
| 233 | + $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 234 | + $FontSize = $this->config['fontsize_max']; |
|
| 235 | + for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
| 236 | + for ($i = 65; $i <= 90; ++$i) { |
|
| 237 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), array()); |
|
| 238 | + $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
| 239 | + if ($_MaxCharWidth > $MaxCharWidth) { |
|
| 240 | + $MaxCharWidth = $_MaxCharWidth; |
|
| 241 | + } |
|
| 242 | + $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 243 | + if ($_MaxCharHeight > $MaxCharHeight) { |
|
| 244 | + $MaxCharHeight = $_MaxCharHeight; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + imagedestroy($oImage); |
|
| 249 | + |
|
| 250 | + $this->height = $MaxCharHeight + 2; |
|
| 251 | + $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
| 252 | + $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Return random background |
|
| 257 | + * |
|
| 258 | + * @return array |
|
| 259 | + */ |
|
| 260 | + public function loadBackground() |
|
| 261 | + { |
|
| 262 | + $RandBackground = null; |
|
| 263 | + if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
| 264 | + $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return $RandBackground; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Draw Image background |
|
| 272 | + */ |
|
| 273 | + public function createFromFile() |
|
| 274 | + { |
|
| 275 | + if ($RandImage = $this->loadBackground()) { |
|
| 276 | + $ImageType = @getimagesize($RandImage); |
|
| 277 | + switch (@$ImageType[2]) { |
|
| 278 | + case 1: |
|
| 279 | + $BackgroundImage = imagecreatefromgif($RandImage); |
|
| 280 | + break; |
|
| 281 | + |
|
| 282 | + case 2: |
|
| 283 | + $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
| 284 | + break; |
|
| 285 | + |
|
| 286 | + case 3: |
|
| 287 | + $BackgroundImage = imagecreatefrompng($RandImage); |
|
| 288 | + break; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + if (!empty($BackgroundImage)) { |
|
| 292 | + imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
| 293 | + imagedestroy($BackgroundImage); |
|
| 294 | + } else { |
|
| 295 | + $this->drawBars(); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Draw Code |
|
| 301 | + */ |
|
| 302 | + public function drawCode() |
|
| 303 | + { |
|
| 304 | + for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
| 305 | + // select random greyscale colour |
|
| 306 | + $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
| 307 | + |
|
| 308 | + // write text to image |
|
| 309 | + $Angle = mt_rand(10, 30); |
|
| 310 | + if ($i % 2) { |
|
| 311 | + $Angle = mt_rand(-10, -30); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // select random font size |
|
| 315 | + $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
| 316 | + |
|
| 317 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], array()); |
|
| 318 | + $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
| 319 | + |
|
| 320 | + // calculate character starting coordinates |
|
| 321 | + $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
| 322 | + $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
| 323 | + |
|
| 324 | + imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()); |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Draw Border |
|
| 330 | + */ |
|
| 331 | + public function drawBorder() |
|
| 332 | + { |
|
| 333 | + $rgb = mt_rand(50, 150); |
|
| 334 | + $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
| 335 | + imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Draw Circles background |
|
| 340 | + */ |
|
| 341 | + public function drawCircles() |
|
| 342 | + { |
|
| 343 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 344 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 345 | + imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Draw Lines background |
|
| 351 | + */ |
|
| 352 | + public function drawLines() |
|
| 353 | + { |
|
| 354 | + for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
| 355 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 356 | + imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Draw Rectangles background |
|
| 362 | + */ |
|
| 363 | + public function drawRectangles() |
|
| 364 | + { |
|
| 365 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 366 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 367 | + imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Draw Bars background |
|
| 373 | + */ |
|
| 374 | + public function drawBars() |
|
| 375 | + { |
|
| 376 | + for ($i = 0; $i <= $this->height;) { |
|
| 377 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 378 | + imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
| 379 | + $i = $i + 2.5; |
|
| 380 | + } |
|
| 381 | + for ($i = 0; $i <= $this->width;) { |
|
| 382 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 383 | + imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
| 384 | + $i = $i + 2.5; |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Draw Ellipses background |
|
| 390 | + */ |
|
| 391 | + public function drawEllipses() |
|
| 392 | + { |
|
| 393 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 394 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 395 | + imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Draw polygons background |
|
| 401 | + */ |
|
| 402 | + public function drawPolygons() |
|
| 403 | + { |
|
| 404 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
| 405 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
| 406 | + $coords = array(); |
|
| 407 | + for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
| 408 | + $coords[] = mt_rand(0, $this->width); |
|
| 409 | + $coords[] = mt_rand(0, $this->height); |
|
| 410 | + } |
|
| 411 | + imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Create CAPTCHA iamge with BMP |
|
| 417 | + * TODO |
|
| 418 | + * @param string $file |
|
| 419 | + * @return string |
|
| 420 | + */ |
|
| 421 | + public function createImageBmp($file = '') |
|
| 422 | + { |
|
| 423 | + $image = ''; |
|
| 424 | + |
|
| 425 | + if (empty($file)) { |
|
| 426 | + header('Content-type: image/bmp'); |
|
| 427 | + echo $image; |
|
| 428 | + } else { |
|
| 429 | + return $image; |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | $config = @include '../config.php'; |
@@ -7,75 +7,75 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class XoopsCaptchaText |
| 9 | 9 | { |
| 10 | - public $config = array(); |
|
| 11 | - public $code; |
|
| 10 | + public $config = array(); |
|
| 11 | + public $code; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * XoopsCaptchaText constructor. |
|
| 15 | - */ |
|
| 16 | - public function __construct() |
|
| 17 | - { |
|
| 18 | - } |
|
| 13 | + /** |
|
| 14 | + * XoopsCaptchaText constructor. |
|
| 15 | + */ |
|
| 16 | + public function __construct() |
|
| 17 | + { |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return XoopsCaptchaText |
|
| 22 | - */ |
|
| 23 | - public function &instance() |
|
| 24 | - { |
|
| 25 | - static $instance; |
|
| 26 | - if (!isset($instance)) { |
|
| 27 | - $instance = new XoopsCaptchaText(); |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * @return XoopsCaptchaText |
|
| 22 | + */ |
|
| 23 | + public function &instance() |
|
| 24 | + { |
|
| 25 | + static $instance; |
|
| 26 | + if (!isset($instance)) { |
|
| 27 | + $instance = new XoopsCaptchaText(); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - return $instance; |
|
| 31 | - } |
|
| 30 | + return $instance; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Loading configs from CAPTCHA class |
|
| 35 | - * @param array $config |
|
| 36 | - */ |
|
| 37 | - public function loadConfig($config = array()) |
|
| 38 | - { |
|
| 39 | - // Loading default preferences |
|
| 40 | - $this->config = $config; |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Loading configs from CAPTCHA class |
|
| 35 | + * @param array $config |
|
| 36 | + */ |
|
| 37 | + public function loadConfig($config = array()) |
|
| 38 | + { |
|
| 39 | + // Loading default preferences |
|
| 40 | + $this->config = $config; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function setCode() |
|
| 44 | - { |
|
| 45 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 46 | - } |
|
| 43 | + public function setCode() |
|
| 44 | + { |
|
| 45 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function render() |
|
| 52 | - { |
|
| 53 | - $form = $this->loadText() . " <input type='text' name='" . $this->config['name'] . "' id='" . $this->config['name'] . "' size='" . $this->config['num_chars'] . "' maxlength='" . $this->config['num_chars'] . "' value='' />"; |
|
| 54 | - $rule = constant('XOOPS_CAPTCHA_RULE_TEXT'); |
|
| 55 | - if (!empty($rule)) { |
|
| 56 | - $form .= " <small>{$rule}</small>"; |
|
| 57 | - } |
|
| 48 | + /** |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function render() |
|
| 52 | + { |
|
| 53 | + $form = $this->loadText() . " <input type='text' name='" . $this->config['name'] . "' id='" . $this->config['name'] . "' size='" . $this->config['num_chars'] . "' maxlength='" . $this->config['num_chars'] . "' value='' />"; |
|
| 54 | + $rule = constant('XOOPS_CAPTCHA_RULE_TEXT'); |
|
| 55 | + if (!empty($rule)) { |
|
| 56 | + $form .= " <small>{$rule}</small>"; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $this->setCode(); |
|
| 59 | + $this->setCode(); |
|
| 60 | 60 | |
| 61 | - return $form; |
|
| 62 | - } |
|
| 61 | + return $form; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function loadText() |
|
| 68 | - { |
|
| 69 | - $val_a = mt_rand(0, 9); |
|
| 70 | - $val_b = mt_rand(0, 9); |
|
| 71 | - if ($val_a > $val_b) { |
|
| 72 | - $expression = "{$val_a} - {$val_b} = ?"; |
|
| 73 | - $this->code = $val_a - $val_b; |
|
| 74 | - } else { |
|
| 75 | - $expression = "{$val_a} + {$val_b} = ?"; |
|
| 76 | - $this->code = $val_a + $val_b; |
|
| 77 | - } |
|
| 64 | + /** |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function loadText() |
|
| 68 | + { |
|
| 69 | + $val_a = mt_rand(0, 9); |
|
| 70 | + $val_b = mt_rand(0, 9); |
|
| 71 | + if ($val_a > $val_b) { |
|
| 72 | + $expression = "{$val_a} - {$val_b} = ?"; |
|
| 73 | + $this->code = $val_a - $val_b; |
|
| 74 | + } else { |
|
| 75 | + $expression = "{$val_a} + {$val_b} = ?"; |
|
| 76 | + $this->code = $val_a + $val_b; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return "<span style='font-style: normal; font-weight: bold; font-size: 100%; font-color: #333; border: 1px solid #333; padding: 1px 5px;'>{$expression}</span>"; |
|
| 80 | - } |
|
| 79 | + return "<span style='font-style: normal; font-weight: bold; font-size: 100%; font-color: #333; border: 1px solid #333; padding: 1px 5px;'>{$expression}</span>"; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -1,40 +1,40 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * CAPTCHA class For XOOPS |
|
| 4 | - * |
|
| 5 | - * Currently there are two types of CAPTCHA forms, text and image |
|
| 6 | - * The default mode is "text", it can be changed in the priority: |
|
| 7 | - * 1 If mode is set through XoopsFormCaptcha::setMode(), take it |
|
| 8 | - * 2 Elseif mode is set though captcha/config.php, take it |
|
| 9 | - * 3 Else, take "text" |
|
| 10 | - * |
|
| 11 | - * D.J. |
|
| 12 | - */ |
|
| 3 | + * CAPTCHA class For XOOPS |
|
| 4 | + * |
|
| 5 | + * Currently there are two types of CAPTCHA forms, text and image |
|
| 6 | + * The default mode is "text", it can be changed in the priority: |
|
| 7 | + * 1 If mode is set through XoopsFormCaptcha::setMode(), take it |
|
| 8 | + * 2 Elseif mode is set though captcha/config.php, take it |
|
| 9 | + * 3 Else, take "text" |
|
| 10 | + * |
|
| 11 | + * D.J. |
|
| 12 | + */ |
|
| 13 | 13 | |
| 14 | 14 | $config = array( |
| 15 | - 'mode' => 'image', |
|
| 16 | - 'name' => 'xoopscaptcha', |
|
| 17 | - 'skipmember' => true, // Skip CAPTCHA check for members |
|
| 18 | - 'maxattempt' => 100, // Maximum attempts for each session |
|
| 15 | + 'mode' => 'image', |
|
| 16 | + 'name' => 'xoopscaptcha', |
|
| 17 | + 'skipmember' => true, // Skip CAPTCHA check for members |
|
| 18 | + 'maxattempt' => 100, // Maximum attempts for each session |
|
| 19 | 19 | |
| 20 | - 'num_chars' => 4, // Maximum characters |
|
| 20 | + 'num_chars' => 4, // Maximum characters |
|
| 21 | 21 | |
| 22 | - // For image mode, based on DuGris' SecurityImage |
|
| 23 | - 'rootpath' => __DIR__, // __Absolute__ Path to the root of fonts and backgrounds |
|
| 24 | - 'imagepath' => 'uploads/captcha', // Path to temporary image files, __relative__ to XOOPS_ROOT_PATH |
|
| 25 | - 'imageurl' => 'modules/smartobject/include/captcha/scripts/img.php', // Path to the script for creating image, __relative__ to XOOPS_ROOT_PATH |
|
| 26 | - 'casesensitive' => false, // Characters in image mode is case-sensitive |
|
| 27 | - 'fontsize_min' => 12, // Minimum font-size |
|
| 28 | - 'fontsize_max' => 12, // Maximum font-size |
|
| 29 | - 'background_type' => 0, // Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
|
| 30 | - 'background_num' => 50, // Number of background images to generate |
|
| 31 | - 'polygon_point' => 3 |
|
| 22 | + // For image mode, based on DuGris' SecurityImage |
|
| 23 | + 'rootpath' => __DIR__, // __Absolute__ Path to the root of fonts and backgrounds |
|
| 24 | + 'imagepath' => 'uploads/captcha', // Path to temporary image files, __relative__ to XOOPS_ROOT_PATH |
|
| 25 | + 'imageurl' => 'modules/smartobject/include/captcha/scripts/img.php', // Path to the script for creating image, __relative__ to XOOPS_ROOT_PATH |
|
| 26 | + 'casesensitive' => false, // Characters in image mode is case-sensitive |
|
| 27 | + 'fontsize_min' => 12, // Minimum font-size |
|
| 28 | + 'fontsize_max' => 12, // Maximum font-size |
|
| 29 | + 'background_type' => 0, // Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
|
| 30 | + 'background_num' => 50, // Number of background images to generate |
|
| 31 | + 'polygon_point' => 3 |
|
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | 34 | $language = preg_replace("/[^a-z0-9_\-]/i", '', $GLOBALS['xoopsConfig']['language']); |
| 35 | 35 | |
| 36 | 36 | if (!@include_once __DIR__ . "/language/{$language}.php") { |
| 37 | - require_once __DIR__ . '/language/english.php'; |
|
| 37 | + require_once __DIR__ . '/language/english.php'; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | return $config; |
@@ -7,62 +7,62 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class XoopsCaptchaImage |
| 9 | 9 | { |
| 10 | - public $config = array(); |
|
| 10 | + public $config = array(); |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * XoopsCaptchaImage constructor. |
|
| 14 | - */ |
|
| 15 | - public function __construct() |
|
| 16 | - { |
|
| 17 | - //$this->name = md5( session_id() ); |
|
| 18 | - } |
|
| 12 | + /** |
|
| 13 | + * XoopsCaptchaImage constructor. |
|
| 14 | + */ |
|
| 15 | + public function __construct() |
|
| 16 | + { |
|
| 17 | + //$this->name = md5( session_id() ); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return XoopsCaptchaImage |
|
| 22 | - */ |
|
| 23 | - public function &instance() |
|
| 24 | - { |
|
| 25 | - static $instance; |
|
| 26 | - if (!isset($instance)) { |
|
| 27 | - $instance = new XoopsCaptchaImage(); |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * @return XoopsCaptchaImage |
|
| 22 | + */ |
|
| 23 | + public function &instance() |
|
| 24 | + { |
|
| 25 | + static $instance; |
|
| 26 | + if (!isset($instance)) { |
|
| 27 | + $instance = new XoopsCaptchaImage(); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - return $instance; |
|
| 31 | - } |
|
| 30 | + return $instance; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Loading configs from CAPTCHA class |
|
| 35 | - * @param array $config |
|
| 36 | - */ |
|
| 37 | - public function loadConfig($config = array()) |
|
| 38 | - { |
|
| 39 | - // Loading default preferences |
|
| 40 | - $this->config = $config; |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Loading configs from CAPTCHA class |
|
| 35 | + * @param array $config |
|
| 36 | + */ |
|
| 37 | + public function loadConfig($config = array()) |
|
| 38 | + { |
|
| 39 | + // Loading default preferences |
|
| 40 | + $this->config = $config; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public function render() |
|
| 47 | - { |
|
| 48 | - $form = "<input type='text' name='" . $this->config['name'] . "' id='" . $this->config['name'] . "' size='" . $this->config['num_chars'] . "' maxlength='" . $this->config['num_chars'] . "' value='' /> " . $this->loadImage(); |
|
| 49 | - $rule = htmlspecialchars(XOOPS_CAPTCHA_REFRESH, ENT_QUOTES); |
|
| 50 | - if ($this->config['maxattempt']) { |
|
| 51 | - $rule .= ' | ' . sprintf(constant('XOOPS_CAPTCHA_MAXATTEMPTS'), $this->config['maxattempt']); |
|
| 52 | - } |
|
| 53 | - $form .= " <small>{$rule}</small>"; |
|
| 43 | + /** |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public function render() |
|
| 47 | + { |
|
| 48 | + $form = "<input type='text' name='" . $this->config['name'] . "' id='" . $this->config['name'] . "' size='" . $this->config['num_chars'] . "' maxlength='" . $this->config['num_chars'] . "' value='' /> " . $this->loadImage(); |
|
| 49 | + $rule = htmlspecialchars(XOOPS_CAPTCHA_REFRESH, ENT_QUOTES); |
|
| 50 | + if ($this->config['maxattempt']) { |
|
| 51 | + $rule .= ' | ' . sprintf(constant('XOOPS_CAPTCHA_MAXATTEMPTS'), $this->config['maxattempt']); |
|
| 52 | + } |
|
| 53 | + $form .= " <small>{$rule}</small>"; |
|
| 54 | 54 | |
| 55 | - return $form; |
|
| 56 | - } |
|
| 55 | + return $form; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function loadImage() |
|
| 62 | - { |
|
| 63 | - $rule = $this->config['casesensitive'] ? constant('XOOPS_CAPTCHA_RULE_CASESENSITIVE') : constant('XOOPS_CAPTCHA_RULE_CASEINSENSITIVE'); |
|
| 64 | - $ret = "<img id='captcha' src='" . XOOPS_URL . '/' . $this->config['imageurl'] . "' onclick=\"this.src='" . XOOPS_URL . '/' . $this->config['imageurl'] . "?refresh='+Math.random()" . "\" align='absmiddle' style='cursor: pointer;' alt='" . htmlspecialchars($rule, ENT_QUOTES) . "' />"; |
|
| 58 | + /** |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function loadImage() |
|
| 62 | + { |
|
| 63 | + $rule = $this->config['casesensitive'] ? constant('XOOPS_CAPTCHA_RULE_CASESENSITIVE') : constant('XOOPS_CAPTCHA_RULE_CASEINSENSITIVE'); |
|
| 64 | + $ret = "<img id='captcha' src='" . XOOPS_URL . '/' . $this->config['imageurl'] . "' onclick=\"this.src='" . XOOPS_URL . '/' . $this->config['imageurl'] . "?refresh='+Math.random()" . "\" align='absmiddle' style='cursor: pointer;' alt='" . htmlspecialchars($rule, ENT_QUOTES) . "' />"; |
|
| 65 | 65 | |
| 66 | - return $ret; |
|
| 67 | - } |
|
| 66 | + return $ret; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -13,239 +13,239 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class XoopsCaptcha |
| 15 | 15 | { |
| 16 | - public $active = true; |
|
| 17 | - public $mode = 'text'; // potential values: image, text |
|
| 18 | - public $config = array(); |
|
| 19 | - |
|
| 20 | - public $message = array(); // Logging error messages |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * XoopsCaptcha constructor. |
|
| 24 | - */ |
|
| 25 | - public function __construct() |
|
| 26 | - { |
|
| 27 | - // Loading default preferences |
|
| 28 | - $this->config = @include __DIR__ . '/config.php'; |
|
| 29 | - |
|
| 30 | - $this->setMode($this->config['mode']); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return XoopsCaptcha |
|
| 35 | - */ |
|
| 36 | - public static function instance() |
|
| 37 | - { |
|
| 38 | - static $instance; |
|
| 39 | - if (!isset($instance)) { |
|
| 40 | - $instance = new XoopsCaptcha(); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - return $instance; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param $name |
|
| 48 | - * @param $val |
|
| 49 | - * @return bool |
|
| 50 | - */ |
|
| 51 | - public function setConfig($name, $val) |
|
| 52 | - { |
|
| 53 | - if ($name === 'mode') { |
|
| 54 | - $this->setMode($val); |
|
| 55 | - } elseif (isset($this->$name)) { |
|
| 56 | - $this->$name = $val; |
|
| 57 | - } else { |
|
| 58 | - $this->config[$name] = $val; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return true; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Set CAPTCHA mode |
|
| 66 | - * |
|
| 67 | - * For future possible modes, right now force to use text or image |
|
| 68 | - * |
|
| 69 | - * @param string $mode if no mode is set, just verify current mode |
|
| 70 | - */ |
|
| 71 | - public function setMode($mode = null) |
|
| 72 | - { |
|
| 73 | - if (!empty($mode) && in_array($mode, array('text', 'image'))) { |
|
| 74 | - $this->mode = $mode; |
|
| 75 | - |
|
| 76 | - if ($this->mode !== 'image') { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // Disable image mode |
|
| 82 | - if (!extension_loaded('gd')) { |
|
| 83 | - $this->mode = 'text'; |
|
| 84 | - } else { |
|
| 85 | - $required_functions = array('imagecreatetruecolor', 'imagecolorallocate', 'imagefilledrectangle', 'imagejpeg', 'imagedestroy', 'imageftbbox'); |
|
| 86 | - foreach ($required_functions as $func) { |
|
| 87 | - if (!function_exists($func)) { |
|
| 88 | - $this->mode = 'text'; |
|
| 89 | - break; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Initializing the CAPTCHA class |
|
| 97 | - * @param string $name |
|
| 98 | - * @param null $skipmember |
|
| 99 | - * @param null $num_chars |
|
| 100 | - * @param null $fontsize_min |
|
| 101 | - * @param null $fontsize_max |
|
| 102 | - * @param null $background_type |
|
| 103 | - * @param null $background_num |
|
| 104 | - */ |
|
| 105 | - public function init($name = 'xoopscaptcha', $skipmember = null, $num_chars = null, $fontsize_min = null, $fontsize_max = null, $background_type = null, $background_num = null) |
|
| 106 | - { |
|
| 107 | - // Loading RUN-TIME settings |
|
| 108 | - foreach (array_keys($this->config) as $key) { |
|
| 109 | - if (isset(${$key}) && ${$key} !== null) { |
|
| 110 | - $this->config[$key] = ${$key}; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - $this->config['name'] = $name; |
|
| 114 | - |
|
| 115 | - // Skip CAPTCHA for member if set |
|
| 116 | - if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) { |
|
| 117 | - $this->active = false; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Verify user submission |
|
| 123 | - * @param null $skipMember |
|
| 124 | - * @return bool |
|
| 125 | - */ |
|
| 126 | - public function verify($skipMember = null) |
|
| 127 | - { |
|
| 128 | - $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
| 129 | - $skipMember = ($skipMember === null) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
| 130 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 131 | - |
|
| 132 | - $is_valid = false; |
|
| 133 | - |
|
| 134 | - // Skip CAPTCHA for member if set |
|
| 135 | - if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
|
| 136 | - $is_valid = true; |
|
| 137 | - // Kill too many attempts |
|
| 138 | - } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
| 139 | - $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
| 140 | - |
|
| 141 | - // Verify the code |
|
| 142 | - } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) { |
|
| 143 | - $func = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp'; |
|
| 144 | - $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if (!empty($maxAttempts)) { |
|
| 148 | - if (!$is_valid) { |
|
| 149 | - // Increase the attempt records on failure |
|
| 150 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
| 151 | - // Log the error message |
|
| 152 | - $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
| 153 | - } else { |
|
| 154 | - |
|
| 155 | - // reset attempt records on success |
|
| 156 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - $this->destroyGarbage(true); |
|
| 160 | - |
|
| 161 | - return $is_valid; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @return mixed|string |
|
| 166 | - */ |
|
| 167 | - public function getCaption() |
|
| 168 | - { |
|
| 169 | - return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : ''; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function getMessage() |
|
| 176 | - { |
|
| 177 | - return implode('<br />', $this->message); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Destory historical stuff |
|
| 182 | - * @param bool $clearSession |
|
| 183 | - * @return bool |
|
| 184 | - */ |
|
| 185 | - public function destroyGarbage($clearSession = false) |
|
| 186 | - { |
|
| 187 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
| 188 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
| 189 | - $captchaHandler = new $class(); |
|
| 190 | - if (method_exists($captchaHandler, 'destroyGarbage')) { |
|
| 191 | - $captchaHandler->loadConfig($this->config); |
|
| 192 | - $captchaHandler->destroyGarbage(); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($clearSession) { |
|
| 196 | - $_SESSION['XoopsCaptcha_name'] = null; |
|
| 197 | - $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
| 198 | - $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
| 199 | - $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return true; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @return mixed|string |
|
| 207 | - */ |
|
| 208 | - public function render() |
|
| 209 | - { |
|
| 210 | - $form = ''; |
|
| 211 | - |
|
| 212 | - if (!$this->active || empty($this->config['name'])) { |
|
| 213 | - return $form; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $_SESSION['XoopsCaptcha_name'] = $this->config['name']; |
|
| 217 | - $_SESSION['XoopsCaptcha_skipmember'] = $this->config['skipmember']; |
|
| 218 | - $maxAttempts = $this->config['maxattempt']; |
|
| 219 | - $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
| 220 | - /* |
|
| 16 | + public $active = true; |
|
| 17 | + public $mode = 'text'; // potential values: image, text |
|
| 18 | + public $config = array(); |
|
| 19 | + |
|
| 20 | + public $message = array(); // Logging error messages |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * XoopsCaptcha constructor. |
|
| 24 | + */ |
|
| 25 | + public function __construct() |
|
| 26 | + { |
|
| 27 | + // Loading default preferences |
|
| 28 | + $this->config = @include __DIR__ . '/config.php'; |
|
| 29 | + |
|
| 30 | + $this->setMode($this->config['mode']); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return XoopsCaptcha |
|
| 35 | + */ |
|
| 36 | + public static function instance() |
|
| 37 | + { |
|
| 38 | + static $instance; |
|
| 39 | + if (!isset($instance)) { |
|
| 40 | + $instance = new XoopsCaptcha(); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + return $instance; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param $name |
|
| 48 | + * @param $val |
|
| 49 | + * @return bool |
|
| 50 | + */ |
|
| 51 | + public function setConfig($name, $val) |
|
| 52 | + { |
|
| 53 | + if ($name === 'mode') { |
|
| 54 | + $this->setMode($val); |
|
| 55 | + } elseif (isset($this->$name)) { |
|
| 56 | + $this->$name = $val; |
|
| 57 | + } else { |
|
| 58 | + $this->config[$name] = $val; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return true; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Set CAPTCHA mode |
|
| 66 | + * |
|
| 67 | + * For future possible modes, right now force to use text or image |
|
| 68 | + * |
|
| 69 | + * @param string $mode if no mode is set, just verify current mode |
|
| 70 | + */ |
|
| 71 | + public function setMode($mode = null) |
|
| 72 | + { |
|
| 73 | + if (!empty($mode) && in_array($mode, array('text', 'image'))) { |
|
| 74 | + $this->mode = $mode; |
|
| 75 | + |
|
| 76 | + if ($this->mode !== 'image') { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // Disable image mode |
|
| 82 | + if (!extension_loaded('gd')) { |
|
| 83 | + $this->mode = 'text'; |
|
| 84 | + } else { |
|
| 85 | + $required_functions = array('imagecreatetruecolor', 'imagecolorallocate', 'imagefilledrectangle', 'imagejpeg', 'imagedestroy', 'imageftbbox'); |
|
| 86 | + foreach ($required_functions as $func) { |
|
| 87 | + if (!function_exists($func)) { |
|
| 88 | + $this->mode = 'text'; |
|
| 89 | + break; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Initializing the CAPTCHA class |
|
| 97 | + * @param string $name |
|
| 98 | + * @param null $skipmember |
|
| 99 | + * @param null $num_chars |
|
| 100 | + * @param null $fontsize_min |
|
| 101 | + * @param null $fontsize_max |
|
| 102 | + * @param null $background_type |
|
| 103 | + * @param null $background_num |
|
| 104 | + */ |
|
| 105 | + public function init($name = 'xoopscaptcha', $skipmember = null, $num_chars = null, $fontsize_min = null, $fontsize_max = null, $background_type = null, $background_num = null) |
|
| 106 | + { |
|
| 107 | + // Loading RUN-TIME settings |
|
| 108 | + foreach (array_keys($this->config) as $key) { |
|
| 109 | + if (isset(${$key}) && ${$key} !== null) { |
|
| 110 | + $this->config[$key] = ${$key}; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + $this->config['name'] = $name; |
|
| 114 | + |
|
| 115 | + // Skip CAPTCHA for member if set |
|
| 116 | + if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) { |
|
| 117 | + $this->active = false; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Verify user submission |
|
| 123 | + * @param null $skipMember |
|
| 124 | + * @return bool |
|
| 125 | + */ |
|
| 126 | + public function verify($skipMember = null) |
|
| 127 | + { |
|
| 128 | + $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
| 129 | + $skipMember = ($skipMember === null) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
| 130 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 131 | + |
|
| 132 | + $is_valid = false; |
|
| 133 | + |
|
| 134 | + // Skip CAPTCHA for member if set |
|
| 135 | + if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
|
| 136 | + $is_valid = true; |
|
| 137 | + // Kill too many attempts |
|
| 138 | + } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
| 139 | + $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
| 140 | + |
|
| 141 | + // Verify the code |
|
| 142 | + } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) { |
|
| 143 | + $func = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp'; |
|
| 144 | + $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if (!empty($maxAttempts)) { |
|
| 148 | + if (!$is_valid) { |
|
| 149 | + // Increase the attempt records on failure |
|
| 150 | + $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
| 151 | + // Log the error message |
|
| 152 | + $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
| 153 | + } else { |
|
| 154 | + |
|
| 155 | + // reset attempt records on success |
|
| 156 | + $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + $this->destroyGarbage(true); |
|
| 160 | + |
|
| 161 | + return $is_valid; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @return mixed|string |
|
| 166 | + */ |
|
| 167 | + public function getCaption() |
|
| 168 | + { |
|
| 169 | + return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : ''; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function getMessage() |
|
| 176 | + { |
|
| 177 | + return implode('<br />', $this->message); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Destory historical stuff |
|
| 182 | + * @param bool $clearSession |
|
| 183 | + * @return bool |
|
| 184 | + */ |
|
| 185 | + public function destroyGarbage($clearSession = false) |
|
| 186 | + { |
|
| 187 | + require_once __DIR__ . '/' . $this->mode . '.php'; |
|
| 188 | + $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
| 189 | + $captchaHandler = new $class(); |
|
| 190 | + if (method_exists($captchaHandler, 'destroyGarbage')) { |
|
| 191 | + $captchaHandler->loadConfig($this->config); |
|
| 192 | + $captchaHandler->destroyGarbage(); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($clearSession) { |
|
| 196 | + $_SESSION['XoopsCaptcha_name'] = null; |
|
| 197 | + $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
| 198 | + $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
| 199 | + $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return true; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @return mixed|string |
|
| 207 | + */ |
|
| 208 | + public function render() |
|
| 209 | + { |
|
| 210 | + $form = ''; |
|
| 211 | + |
|
| 212 | + if (!$this->active || empty($this->config['name'])) { |
|
| 213 | + return $form; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $_SESSION['XoopsCaptcha_name'] = $this->config['name']; |
|
| 217 | + $_SESSION['XoopsCaptcha_skipmember'] = $this->config['skipmember']; |
|
| 218 | + $maxAttempts = $this->config['maxattempt']; |
|
| 219 | + $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
| 220 | + /* |
|
| 221 | 221 | if (!empty($maxAttempts)) { |
| 222 | 222 | $_SESSION['XoopsCaptcha_maxattempts_'.$_SESSION['XoopsCaptcha_name']] = $maxAttempts; |
| 223 | 223 | } |
| 224 | 224 | */ |
| 225 | 225 | |
| 226 | - // Fail on too many attempts |
|
| 227 | - if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
| 228 | - $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
| 229 | - // Load the form element |
|
| 230 | - } else { |
|
| 231 | - $form = $this->loadForm(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return $form; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * @return mixed |
|
| 239 | - */ |
|
| 240 | - public function loadForm() |
|
| 241 | - { |
|
| 242 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
| 243 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
| 244 | - $captchaHandler = new $class(); |
|
| 245 | - $captchaHandler->loadConfig($this->config); |
|
| 246 | - |
|
| 247 | - $form = $captchaHandler->render(); |
|
| 248 | - |
|
| 249 | - return $form; |
|
| 250 | - } |
|
| 226 | + // Fail on too many attempts |
|
| 227 | + if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
| 228 | + $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
| 229 | + // Load the form element |
|
| 230 | + } else { |
|
| 231 | + $form = $this->loadForm(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + return $form; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * @return mixed |
|
| 239 | + */ |
|
| 240 | + public function loadForm() |
|
| 241 | + { |
|
| 242 | + require_once __DIR__ . '/' . $this->mode . '.php'; |
|
| 243 | + $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
| 244 | + $captchaHandler = new $class(); |
|
| 245 | + $captchaHandler->loadConfig($this->config); |
|
| 246 | + |
|
| 247 | + $form = $captchaHandler->render(); |
|
| 248 | + |
|
| 249 | + return $form; |
|
| 250 | + } |
|
| 251 | 251 | } |
@@ -1,15 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Adding CAPTCHA |
|
| 4 | - * |
|
| 5 | - * Currently there are two types of CAPTCHA forms, text and image |
|
| 6 | - * The default mode is "text", it can be changed in the priority: |
|
| 7 | - * 1 If mode is set through XoopsFormCaptcha::setMode(), take it |
|
| 8 | - * 2 Elseif mode is set though captcha/config.php, take it |
|
| 9 | - * 3 Else, take "text" |
|
| 10 | - * |
|
| 11 | - * D.J. |
|
| 12 | - */ |
|
| 3 | + * Adding CAPTCHA |
|
| 4 | + * |
|
| 5 | + * Currently there are two types of CAPTCHA forms, text and image |
|
| 6 | + * The default mode is "text", it can be changed in the priority: |
|
| 7 | + * 1 If mode is set through XoopsFormCaptcha::setMode(), take it |
|
| 8 | + * 2 Elseif mode is set though captcha/config.php, take it |
|
| 9 | + * 3 Else, take "text" |
|
| 10 | + * |
|
| 11 | + * D.J. |
|
| 12 | + */ |
|
| 13 | 13 | |
| 14 | 14 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
| 15 | 15 | |
@@ -38,52 +38,52 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | class XoopsFormCaptcha extends XoopsFormElement |
| 40 | 40 | { |
| 41 | - public $_captchaHandler; |
|
| 41 | + public $_captchaHandler; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param string $caption Caption of the form element, default value is defined in captcha/language/ |
|
| 45 | - * @param string $name Name for the input box |
|
| 46 | - * @param boolean $skipmember Skip CAPTCHA check for members |
|
| 47 | - * @param int $numchar Number of characters in image mode, and input box size for text mode |
|
| 48 | - * @param int $minfontsize Minimum font-size of characters in image mode |
|
| 49 | - * @param int $maxfontsize Maximum font-size of characters in image mode |
|
| 50 | - * @param int $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
|
| 51 | - * @param int $backgroundnum Number of background images in image mode |
|
| 52 | - * |
|
| 53 | - */ |
|
| 54 | - public function __construct($caption = '', $name = 'xoopscaptcha', $skipmember = null, $numchar = null, $minfontsize = null, $maxfontsize = null, $backgroundtype = null, $backgroundnum = null) |
|
| 55 | - { |
|
| 56 | - if (!class_exists('XoopsCaptcaha')) { |
|
| 57 | - require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php'; |
|
| 58 | - } |
|
| 43 | + /** |
|
| 44 | + * @param string $caption Caption of the form element, default value is defined in captcha/language/ |
|
| 45 | + * @param string $name Name for the input box |
|
| 46 | + * @param boolean $skipmember Skip CAPTCHA check for members |
|
| 47 | + * @param int $numchar Number of characters in image mode, and input box size for text mode |
|
| 48 | + * @param int $minfontsize Minimum font-size of characters in image mode |
|
| 49 | + * @param int $maxfontsize Maximum font-size of characters in image mode |
|
| 50 | + * @param int $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
|
| 51 | + * @param int $backgroundnum Number of background images in image mode |
|
| 52 | + * |
|
| 53 | + */ |
|
| 54 | + public function __construct($caption = '', $name = 'xoopscaptcha', $skipmember = null, $numchar = null, $minfontsize = null, $maxfontsize = null, $backgroundtype = null, $backgroundnum = null) |
|
| 55 | + { |
|
| 56 | + if (!class_exists('XoopsCaptcaha')) { |
|
| 57 | + require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php'; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $this->_captchaHandler = XoopsCaptcha::instance(); |
|
| 61 | - $this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum); |
|
| 62 | - if (!$this->_captchaHandler->active) { |
|
| 63 | - $this->setHidden(); |
|
| 64 | - } else { |
|
| 65 | - $caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption(); |
|
| 66 | - $this->setCaption($caption); |
|
| 67 | - } |
|
| 68 | - } |
|
| 60 | + $this->_captchaHandler = XoopsCaptcha::instance(); |
|
| 61 | + $this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum); |
|
| 62 | + if (!$this->_captchaHandler->active) { |
|
| 63 | + $this->setHidden(); |
|
| 64 | + } else { |
|
| 65 | + $caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption(); |
|
| 66 | + $this->setCaption($caption); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @param $name |
|
| 72 | - * @param $val |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 75 | - public function setConfig($name, $val) |
|
| 76 | - { |
|
| 77 | - return $this->_captchaHandler->setConfig($name, $val); |
|
| 78 | - } |
|
| 70 | + /** |
|
| 71 | + * @param $name |
|
| 72 | + * @param $val |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | + public function setConfig($name, $val) |
|
| 76 | + { |
|
| 77 | + return $this->_captchaHandler->setConfig($name, $val); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return mixed|string |
|
| 82 | - */ |
|
| 83 | - public function render() |
|
| 84 | - { |
|
| 85 | - if (!$this->isHidden()) { |
|
| 86 | - return $this->_captchaHandler->render(); |
|
| 87 | - } |
|
| 88 | - } |
|
| 80 | + /** |
|
| 81 | + * @return mixed|string |
|
| 82 | + */ |
|
| 83 | + public function render() |
|
| 84 | + { |
|
| 85 | + if (!$this->isHidden()) { |
|
| 86 | + return $this->_captchaHandler->render(); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | } |