@@ -6,120 +6,120 @@ discard block |
||
6 | 6 | * Licence: GNU |
7 | 7 | */ |
8 | 8 | if (!defined("XOOPS_ROOT_PATH")) { |
9 | - die("XOOPS root path not defined"); |
|
9 | + die("XOOPS root path not defined"); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | function smart_get_css_link($cssfile) { |
13 | - $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '" />'; |
|
14 | - return $ret; |
|
13 | + $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '" />'; |
|
14 | + return $ret; |
|
15 | 15 | } |
16 | 16 | function smart_get_page_before_form() { |
17 | - global $smart_previous_page; |
|
18 | - return isset ($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page; |
|
17 | + global $smart_previous_page; |
|
18 | + return isset ($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page; |
|
19 | 19 | } |
20 | 20 | /** |
21 | - * Checks if a user is admin of $module |
|
22 | - * |
|
23 | - * @return boolean : true if user is admin |
|
24 | - */ |
|
21 | + * Checks if a user is admin of $module |
|
22 | + * |
|
23 | + * @return boolean : true if user is admin |
|
24 | + */ |
|
25 | 25 | function smart_userIsAdmin($module = false) { |
26 | - global $xoopsUser; |
|
27 | - static $smart_isAdmin; |
|
28 | - if (!$module) { |
|
29 | - global $xoopsModule; |
|
30 | - $module = $xoopsModule->getVar('dirname'); |
|
31 | - } |
|
32 | - if (isset ($smart_isAdmin[$module])) { |
|
33 | - return $smart_isAdmin[$module]; |
|
34 | - } |
|
35 | - if (!$xoopsUser) { |
|
36 | - $smart_isAdmin[$module] = false; |
|
37 | - return $smart_isAdmin[$module]; |
|
38 | - } |
|
39 | - $smart_isAdmin[$module] = false; |
|
40 | - $smartModule = smart_getModuleInfo($module); |
|
41 | - if (!is_object($smartModule)) { |
|
42 | - return false; |
|
43 | - } |
|
44 | - $module_id = $smartModule->getVar('mid'); |
|
45 | - $smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id); |
|
46 | - return $smart_isAdmin[$module]; |
|
26 | + global $xoopsUser; |
|
27 | + static $smart_isAdmin; |
|
28 | + if (!$module) { |
|
29 | + global $xoopsModule; |
|
30 | + $module = $xoopsModule->getVar('dirname'); |
|
31 | + } |
|
32 | + if (isset ($smart_isAdmin[$module])) { |
|
33 | + return $smart_isAdmin[$module]; |
|
34 | + } |
|
35 | + if (!$xoopsUser) { |
|
36 | + $smart_isAdmin[$module] = false; |
|
37 | + return $smart_isAdmin[$module]; |
|
38 | + } |
|
39 | + $smart_isAdmin[$module] = false; |
|
40 | + $smartModule = smart_getModuleInfo($module); |
|
41 | + if (!is_object($smartModule)) { |
|
42 | + return false; |
|
43 | + } |
|
44 | + $module_id = $smartModule->getVar('mid'); |
|
45 | + $smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id); |
|
46 | + return $smart_isAdmin[$module]; |
|
47 | 47 | } |
48 | 48 | function smart_isXoops22() { |
49 | - $xoops22 = false; |
|
50 | - $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
|
51 | - if (substr($xv, 2, 1) == '2') { |
|
52 | - $xoops22 = true; |
|
53 | - } |
|
54 | - return $xoops22; |
|
49 | + $xoops22 = false; |
|
50 | + $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
|
51 | + if (substr($xv, 2, 1) == '2') { |
|
52 | + $xoops22 = true; |
|
53 | + } |
|
54 | + return $xoops22; |
|
55 | 55 | } |
56 | 56 | function smart_getModuleName($withLink = true, $forBreadCrumb = false, $moduleName = false) { |
57 | - if (!$moduleName) { |
|
58 | - global $xoopsModule; |
|
59 | - $moduleName = $xoopsModule->getVar('dirname'); |
|
60 | - } |
|
61 | - $smartModule = & smart_getModuleInfo($moduleName); |
|
62 | - $smartModuleConfig = & smart_getModuleConfig($moduleName); |
|
63 | - if (!isset ($smartModule)) { |
|
64 | - return ''; |
|
65 | - } |
|
66 | - |
|
67 | - if ($forBreadCrumb && (isset ($smartModuleConfig['show_mod_name_breadcrumb']) && !$smartModuleConfig['show_mod_name_breadcrumb'])) { |
|
68 | - return ''; |
|
69 | - } |
|
70 | - if (!$withLink) { |
|
71 | - return $smartModule->getVar('name'); |
|
72 | - } else { |
|
73 | - $seoMode = smart_getModuleModeSEO($moduleName); |
|
74 | - if ($seoMode == 'rewrite') { |
|
75 | - $seoModuleName = smart_getModuleNameForSEO($moduleName); |
|
76 | - $ret = XOOPS_URL . '/' . $seoModuleName . '/'; |
|
77 | - } elseif ($seoMode == 'pathinfo') { |
|
78 | - $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/'; |
|
79 | - } else { |
|
80 | - $ret = XOOPS_URL . '/modules/' . $moduleName . '/'; |
|
81 | - } |
|
82 | - |
|
83 | - return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>'; |
|
84 | - } |
|
57 | + if (!$moduleName) { |
|
58 | + global $xoopsModule; |
|
59 | + $moduleName = $xoopsModule->getVar('dirname'); |
|
60 | + } |
|
61 | + $smartModule = & smart_getModuleInfo($moduleName); |
|
62 | + $smartModuleConfig = & smart_getModuleConfig($moduleName); |
|
63 | + if (!isset ($smartModule)) { |
|
64 | + return ''; |
|
65 | + } |
|
66 | + |
|
67 | + if ($forBreadCrumb && (isset ($smartModuleConfig['show_mod_name_breadcrumb']) && !$smartModuleConfig['show_mod_name_breadcrumb'])) { |
|
68 | + return ''; |
|
69 | + } |
|
70 | + if (!$withLink) { |
|
71 | + return $smartModule->getVar('name'); |
|
72 | + } else { |
|
73 | + $seoMode = smart_getModuleModeSEO($moduleName); |
|
74 | + if ($seoMode == 'rewrite') { |
|
75 | + $seoModuleName = smart_getModuleNameForSEO($moduleName); |
|
76 | + $ret = XOOPS_URL . '/' . $seoModuleName . '/'; |
|
77 | + } elseif ($seoMode == 'pathinfo') { |
|
78 | + $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/'; |
|
79 | + } else { |
|
80 | + $ret = XOOPS_URL . '/modules/' . $moduleName . '/'; |
|
81 | + } |
|
82 | + |
|
83 | + return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>'; |
|
84 | + } |
|
85 | 85 | } |
86 | 86 | function smart_getModuleNameForSEO($moduleName = false) { |
87 | - $smartModule = & smart_getModuleInfo($moduleName); |
|
88 | - $smartModuleConfig = & smart_getModuleConfig($moduleName); |
|
89 | - if (isset ($smartModuleConfig['seo_module_name'])) { |
|
90 | - return $smartModuleConfig['seo_module_name']; |
|
91 | - } |
|
92 | - $ret = smart_getModuleName(false, false, $moduleName); |
|
93 | - return (strtolower($ret)); |
|
87 | + $smartModule = & smart_getModuleInfo($moduleName); |
|
88 | + $smartModuleConfig = & smart_getModuleConfig($moduleName); |
|
89 | + if (isset ($smartModuleConfig['seo_module_name'])) { |
|
90 | + return $smartModuleConfig['seo_module_name']; |
|
91 | + } |
|
92 | + $ret = smart_getModuleName(false, false, $moduleName); |
|
93 | + return (strtolower($ret)); |
|
94 | 94 | } |
95 | 95 | function smart_getModuleModeSEO($moduleName = false) { |
96 | - $smartModule = & smart_getModuleInfo($moduleName); |
|
97 | - $smartModuleConfig = & smart_getModuleConfig($moduleName); |
|
98 | - return isset ($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false; |
|
96 | + $smartModule = & smart_getModuleInfo($moduleName); |
|
97 | + $smartModuleConfig = & smart_getModuleConfig($moduleName); |
|
98 | + return isset ($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false; |
|
99 | 99 | } |
100 | 100 | function smart_getModuleIncludeIdSEO($moduleName = false) { |
101 | - $smartModule = & smart_getModuleInfo($moduleName); |
|
102 | - $smartModuleConfig = & smart_getModuleConfig($moduleName); |
|
103 | - return !empty ($smartModuleConfig['seo_inc_id']); |
|
101 | + $smartModule = & smart_getModuleInfo($moduleName); |
|
102 | + $smartModuleConfig = & smart_getModuleConfig($moduleName); |
|
103 | + return !empty ($smartModuleConfig['seo_inc_id']); |
|
104 | 104 | } |
105 | 105 | function smart_getenv($key) { |
106 | - $ret = ''; |
|
107 | - $ret = isset ($_SERVER[$key]) ? $_SERVER[$key] : (isset ($_ENV[$key]) ? $_ENV[$key] : ''); |
|
108 | - return $ret; |
|
106 | + $ret = ''; |
|
107 | + $ret = isset ($_SERVER[$key]) ? $_SERVER[$key] : (isset ($_ENV[$key]) ? $_ENV[$key] : ''); |
|
108 | + return $ret; |
|
109 | 109 | } |
110 | 110 | function smart_xoops_cp_header() { |
111 | - xoops_cp_header(); |
|
112 | - global $xoopsModule, $xoopsConfig; |
|
113 | - /** |
|
114 | - * include SmartObject admin language file |
|
115 | - */ |
|
116 | - $fileName = XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
117 | - if (file_exists($fileName)) { |
|
118 | - include_once $fileName; |
|
119 | - } else { |
|
120 | - include_once XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->getVar('dirname') . '/language/english/admin.php'; |
|
121 | - } |
|
122 | - ?> |
|
111 | + xoops_cp_header(); |
|
112 | + global $xoopsModule, $xoopsConfig; |
|
113 | + /** |
|
114 | + * include SmartObject admin language file |
|
115 | + */ |
|
116 | + $fileName = XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
117 | + if (file_exists($fileName)) { |
|
118 | + include_once $fileName; |
|
119 | + } else { |
|
120 | + include_once XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->getVar('dirname') . '/language/english/admin.php'; |
|
121 | + } |
|
122 | + ?> |
|
123 | 123 | <script type='text/javascript'> |
124 | 124 | <!-- |
125 | 125 | var smart_url='<?php echo SMARTOBJECT_URL ?>'; |
@@ -132,388 +132,388 @@ discard block |
||
132 | 132 | src='<?php echo SMARTOBJECT_URL ?>include/smart.js'></script> |
133 | 133 | <?php |
134 | 134 | |
135 | - /** |
|
136 | - * Include the admin language constants for the SmartObject Framework |
|
137 | - */ |
|
138 | - $admin_file = SMARTOBJECT_ROOT_PATH . "language/" . $xoopsConfig['language'] . "/admin.php"; |
|
139 | - if (!file_exists($admin_file)) { |
|
140 | - $admin_file = SMARTOBJECT_ROOT_PATH . "language/english/admin.php"; |
|
141 | - } |
|
142 | - include_once ($admin_file); |
|
135 | + /** |
|
136 | + * Include the admin language constants for the SmartObject Framework |
|
137 | + */ |
|
138 | + $admin_file = SMARTOBJECT_ROOT_PATH . "language/" . $xoopsConfig['language'] . "/admin.php"; |
|
139 | + if (!file_exists($admin_file)) { |
|
140 | + $admin_file = SMARTOBJECT_ROOT_PATH . "language/english/admin.php"; |
|
141 | + } |
|
142 | + include_once ($admin_file); |
|
143 | 143 | } |
144 | 144 | /** |
145 | - * Detemines if a table exists in the current db |
|
146 | - * |
|
147 | - * @param string $table the table name (without XOOPS prefix) |
|
148 | - * @return bool True if table exists, false if not |
|
149 | - * |
|
150 | - * @access public |
|
151 | - * @author xhelp development team |
|
152 | - */ |
|
145 | + * Detemines if a table exists in the current db |
|
146 | + * |
|
147 | + * @param string $table the table name (without XOOPS prefix) |
|
148 | + * @return bool True if table exists, false if not |
|
149 | + * |
|
150 | + * @access public |
|
151 | + * @author xhelp development team |
|
152 | + */ |
|
153 | 153 | function smart_TableExists($table) { |
154 | - $bRetVal = false; |
|
155 | - //Verifies that a MySQL table exists |
|
156 | - $xoopsDB = & XoopsDatabaseFactory::getDatabaseConnection(); |
|
157 | - $realname = $xoopsDB->prefix($table); |
|
158 | - $sql = "SHOW TABLES FROM ".XOOPS_DB_NAME; |
|
159 | - $ret = $xoopsDB->queryF($sql); |
|
160 | - while (list ($m_table) = $xoopsDB->fetchRow($ret)) { |
|
161 | - if ($m_table == $realname) { |
|
162 | - $bRetVal = true; |
|
163 | - break; |
|
164 | - } |
|
165 | - } |
|
166 | - $xoopsDB->freeRecordSet($ret); |
|
167 | - return ($bRetVal); |
|
154 | + $bRetVal = false; |
|
155 | + //Verifies that a MySQL table exists |
|
156 | + $xoopsDB = & XoopsDatabaseFactory::getDatabaseConnection(); |
|
157 | + $realname = $xoopsDB->prefix($table); |
|
158 | + $sql = "SHOW TABLES FROM ".XOOPS_DB_NAME; |
|
159 | + $ret = $xoopsDB->queryF($sql); |
|
160 | + while (list ($m_table) = $xoopsDB->fetchRow($ret)) { |
|
161 | + if ($m_table == $realname) { |
|
162 | + $bRetVal = true; |
|
163 | + break; |
|
164 | + } |
|
165 | + } |
|
166 | + $xoopsDB->freeRecordSet($ret); |
|
167 | + return ($bRetVal); |
|
168 | 168 | } |
169 | 169 | /** |
170 | - * Gets a value from a key in the xhelp_meta table |
|
171 | - * |
|
172 | - * @param string $key |
|
173 | - * @return string $value |
|
174 | - * |
|
175 | - * @access public |
|
176 | - * @author xhelp development team |
|
177 | - */ |
|
170 | + * Gets a value from a key in the xhelp_meta table |
|
171 | + * |
|
172 | + * @param string $key |
|
173 | + * @return string $value |
|
174 | + * |
|
175 | + * @access public |
|
176 | + * @author xhelp development team |
|
177 | + */ |
|
178 | 178 | function smart_GetMeta($key, $moduleName = false) { |
179 | - if (!$moduleName) { |
|
180 | - $moduleName = smart_getCurrentModuleName(); |
|
181 | - } |
|
182 | - $xoopsDB = & XoopsDatabaseFactory::getDatabaseConnection(); |
|
183 | - $sql = sprintf("SELECT metavalue FROM %s WHERE metakey=%s", $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key)); |
|
184 | - $ret = $xoopsDB->query($sql); |
|
185 | - if (!$ret) { |
|
186 | - $value = false; |
|
187 | - } else { |
|
188 | - list ($value) = $xoopsDB->fetchRow($ret); |
|
189 | - } |
|
190 | - return $value; |
|
179 | + if (!$moduleName) { |
|
180 | + $moduleName = smart_getCurrentModuleName(); |
|
181 | + } |
|
182 | + $xoopsDB = & XoopsDatabaseFactory::getDatabaseConnection(); |
|
183 | + $sql = sprintf("SELECT metavalue FROM %s WHERE metakey=%s", $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key)); |
|
184 | + $ret = $xoopsDB->query($sql); |
|
185 | + if (!$ret) { |
|
186 | + $value = false; |
|
187 | + } else { |
|
188 | + list ($value) = $xoopsDB->fetchRow($ret); |
|
189 | + } |
|
190 | + return $value; |
|
191 | 191 | } |
192 | 192 | function smart_getCurrentModuleName() { |
193 | - global $xoopsModule; |
|
194 | - if (is_object($xoopsModule)) { |
|
195 | - return $xoopsModule->getVar('dirname'); |
|
196 | - } else { |
|
197 | - return false; |
|
198 | - } |
|
193 | + global $xoopsModule; |
|
194 | + if (is_object($xoopsModule)) { |
|
195 | + return $xoopsModule->getVar('dirname'); |
|
196 | + } else { |
|
197 | + return false; |
|
198 | + } |
|
199 | 199 | } |
200 | 200 | /** |
201 | - * Sets a value for a key in the xhelp_meta table |
|
202 | - * |
|
203 | - * @param string $key |
|
204 | - * @param string $value |
|
205 | - * @return bool TRUE if success, FALSE if failure |
|
206 | - * |
|
207 | - * @access public |
|
208 | - * @author xhelp development team |
|
209 | - */ |
|
201 | + * Sets a value for a key in the xhelp_meta table |
|
202 | + * |
|
203 | + * @param string $key |
|
204 | + * @param string $value |
|
205 | + * @return bool TRUE if success, FALSE if failure |
|
206 | + * |
|
207 | + * @access public |
|
208 | + * @author xhelp development team |
|
209 | + */ |
|
210 | 210 | function smart_SetMeta($key, $value, $moduleName = false) { |
211 | - if (!$moduleName) { |
|
212 | - $moduleName = smart_getCurrentModuleName(); |
|
213 | - } |
|
214 | - $xoopsDB = & XoopsDatabaseFactory::getDatabaseConnection(); |
|
215 | - $ret = smart_GetMeta($key, $moduleName); |
|
216 | - if ($ret === '0' || $ret > 0) { |
|
217 | - $sql = sprintf("UPDATE %s SET metavalue = %s WHERE metakey = %s", $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key)); |
|
218 | - } else { |
|
219 | - $sql = sprintf("INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)", $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value)); |
|
220 | - } |
|
221 | - $ret = $xoopsDB->queryF($sql); |
|
222 | - if (!$ret) { |
|
223 | - return false; |
|
224 | - } |
|
225 | - return true; |
|
211 | + if (!$moduleName) { |
|
212 | + $moduleName = smart_getCurrentModuleName(); |
|
213 | + } |
|
214 | + $xoopsDB = & XoopsDatabaseFactory::getDatabaseConnection(); |
|
215 | + $ret = smart_GetMeta($key, $moduleName); |
|
216 | + if ($ret === '0' || $ret > 0) { |
|
217 | + $sql = sprintf("UPDATE %s SET metavalue = %s WHERE metakey = %s", $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key)); |
|
218 | + } else { |
|
219 | + $sql = sprintf("INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)", $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value)); |
|
220 | + } |
|
221 | + $ret = $xoopsDB->queryF($sql); |
|
222 | + if (!$ret) { |
|
223 | + return false; |
|
224 | + } |
|
225 | + return true; |
|
226 | 226 | } |
227 | 227 | // Thanks to Mithrandir :-) |
228 | 228 | function smart_substr($str, $start, $length, $trimmarker = '...') { |
229 | - // if the string is empty, let's get out ;-) |
|
230 | - if ($str == '') { |
|
231 | - return $str; |
|
232 | - } |
|
233 | - // reverse a string that is shortened with '' as trimmarker |
|
234 | - $reversed_string = strrev(xoops_substr($str, $start, $length, '')); |
|
235 | - // find first space in reversed string |
|
236 | - $position_of_space = strpos($reversed_string, " ", 0); |
|
237 | - // truncate the original string to a length of $length |
|
238 | - // minus the position of the last space |
|
239 | - // plus the length of the $trimmarker |
|
240 | - $truncated_string = xoops_substr($str, $start, $length - $position_of_space +strlen($trimmarker), $trimmarker); |
|
241 | - return $truncated_string; |
|
229 | + // if the string is empty, let's get out ;-) |
|
230 | + if ($str == '') { |
|
231 | + return $str; |
|
232 | + } |
|
233 | + // reverse a string that is shortened with '' as trimmarker |
|
234 | + $reversed_string = strrev(xoops_substr($str, $start, $length, '')); |
|
235 | + // find first space in reversed string |
|
236 | + $position_of_space = strpos($reversed_string, " ", 0); |
|
237 | + // truncate the original string to a length of $length |
|
238 | + // minus the position of the last space |
|
239 | + // plus the length of the $trimmarker |
|
240 | + $truncated_string = xoops_substr($str, $start, $length - $position_of_space +strlen($trimmarker), $trimmarker); |
|
241 | + return $truncated_string; |
|
242 | 242 | } |
243 | 243 | function smart_getConfig($key, $moduleName = false, $default = 'default_is_undefined') { |
244 | - if (!$moduleName) { |
|
245 | - $moduleName = smart_getCurrentModuleName(); |
|
246 | - } |
|
247 | - $configs = smart_getModuleConfig($moduleName); |
|
248 | - if (isset ($configs[$key])) { |
|
249 | - return $configs[$key]; |
|
250 | - } else { |
|
251 | - if ($default === 'default_is_undefined') { |
|
252 | - return null; |
|
253 | - } else { |
|
254 | - return $default; |
|
255 | - } |
|
256 | - } |
|
244 | + if (!$moduleName) { |
|
245 | + $moduleName = smart_getCurrentModuleName(); |
|
246 | + } |
|
247 | + $configs = smart_getModuleConfig($moduleName); |
|
248 | + if (isset ($configs[$key])) { |
|
249 | + return $configs[$key]; |
|
250 | + } else { |
|
251 | + if ($default === 'default_is_undefined') { |
|
252 | + return null; |
|
253 | + } else { |
|
254 | + return $default; |
|
255 | + } |
|
256 | + } |
|
257 | 257 | } |
258 | 258 | /** |
259 | - * Copy a file, or a folder and its contents |
|
260 | - * |
|
261 | - * @author Aidan Lister <[email protected]> |
|
262 | - * @version 1.0.0 |
|
263 | - * @param string $source The source |
|
264 | - * @param string $dest The destination |
|
265 | - * @return bool Returns true on success, false on failure |
|
266 | - */ |
|
259 | + * Copy a file, or a folder and its contents |
|
260 | + * |
|
261 | + * @author Aidan Lister <[email protected]> |
|
262 | + * @version 1.0.0 |
|
263 | + * @param string $source The source |
|
264 | + * @param string $dest The destination |
|
265 | + * @return bool Returns true on success, false on failure |
|
266 | + */ |
|
267 | 267 | function smart_copyr($source, $dest) { |
268 | - // Simple copy for a file |
|
269 | - if (is_file($source)) { |
|
270 | - return copy($source, $dest); |
|
271 | - } |
|
272 | - // Make destination directory |
|
273 | - if (!is_dir($dest)) { |
|
274 | - mkdir($dest); |
|
275 | - } |
|
276 | - // Loop through the folder |
|
277 | - $dir = dir($source); |
|
278 | - while (false !== $entry = $dir->read()) { |
|
279 | - // Skip pointers |
|
280 | - if ($entry == '.' || $entry == '..') { |
|
281 | - continue; |
|
282 | - } |
|
283 | - // Deep copy directories |
|
284 | - if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) { |
|
285 | - copyr("$source/$entry", "$dest/$entry"); |
|
286 | - } else { |
|
287 | - copy("$source/$entry", "$dest/$entry"); |
|
288 | - } |
|
289 | - } |
|
290 | - // Clean up |
|
291 | - $dir->close(); |
|
292 | - return true; |
|
268 | + // Simple copy for a file |
|
269 | + if (is_file($source)) { |
|
270 | + return copy($source, $dest); |
|
271 | + } |
|
272 | + // Make destination directory |
|
273 | + if (!is_dir($dest)) { |
|
274 | + mkdir($dest); |
|
275 | + } |
|
276 | + // Loop through the folder |
|
277 | + $dir = dir($source); |
|
278 | + while (false !== $entry = $dir->read()) { |
|
279 | + // Skip pointers |
|
280 | + if ($entry == '.' || $entry == '..') { |
|
281 | + continue; |
|
282 | + } |
|
283 | + // Deep copy directories |
|
284 | + if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) { |
|
285 | + copyr("$source/$entry", "$dest/$entry"); |
|
286 | + } else { |
|
287 | + copy("$source/$entry", "$dest/$entry"); |
|
288 | + } |
|
289 | + } |
|
290 | + // Clean up |
|
291 | + $dir->close(); |
|
292 | + return true; |
|
293 | 293 | } |
294 | 294 | /** |
295 | - * Thanks to the NewBB2 Development Team |
|
296 | - */ |
|
295 | + * Thanks to the NewBB2 Development Team |
|
296 | + */ |
|
297 | 297 | function smart_admin_mkdir($target) { |
298 | - // http://www.php.net/manual/en/function.mkdir.php |
|
299 | - // saint at corenova.com |
|
300 | - // bart at cdasites dot com |
|
301 | - if (is_dir($target) || empty ($target)) { |
|
302 | - return true; // best case check first |
|
303 | - } |
|
304 | - if (file_exists($target) && !is_dir($target)) { |
|
305 | - return false; |
|
306 | - } |
|
307 | - if (smart_admin_mkdir(substr($target, 0, strrpos($target, '/')))) { |
|
308 | - if (!file_exists($target)) { |
|
309 | - $res = mkdir($target, 0777); // crawl back up & create dir tree |
|
310 | - smart_admin_chmod($target); |
|
311 | - return $res; |
|
312 | - } |
|
313 | - } |
|
314 | - $res = is_dir($target); |
|
315 | - return $res; |
|
298 | + // http://www.php.net/manual/en/function.mkdir.php |
|
299 | + // saint at corenova.com |
|
300 | + // bart at cdasites dot com |
|
301 | + if (is_dir($target) || empty ($target)) { |
|
302 | + return true; // best case check first |
|
303 | + } |
|
304 | + if (file_exists($target) && !is_dir($target)) { |
|
305 | + return false; |
|
306 | + } |
|
307 | + if (smart_admin_mkdir(substr($target, 0, strrpos($target, '/')))) { |
|
308 | + if (!file_exists($target)) { |
|
309 | + $res = mkdir($target, 0777); // crawl back up & create dir tree |
|
310 | + smart_admin_chmod($target); |
|
311 | + return $res; |
|
312 | + } |
|
313 | + } |
|
314 | + $res = is_dir($target); |
|
315 | + return $res; |
|
316 | 316 | } |
317 | 317 | /** |
318 | - * Thanks to the NewBB2 Development Team |
|
319 | - */ |
|
318 | + * Thanks to the NewBB2 Development Team |
|
319 | + */ |
|
320 | 320 | function smart_admin_chmod($target, $mode = 0777) { |
321 | - return @ chmod($target, $mode); |
|
321 | + return @ chmod($target, $mode); |
|
322 | 322 | } |
323 | 323 | function smart_imageResize($src, $maxWidth, $maxHeight) { |
324 | - $width = ''; |
|
325 | - $height = ''; |
|
326 | - $type = ''; |
|
327 | - $attr = ''; |
|
328 | - if (file_exists($src)) { |
|
329 | - list ($width, $height, $type, $attr) = getimagesize($src); |
|
330 | - if ($width > $maxWidth) { |
|
331 | - $originalWidth = $width; |
|
332 | - $width = $maxWidth; |
|
333 | - $height = $width * $height / $originalWidth; |
|
334 | - } |
|
335 | - if ($height > $maxHeight) { |
|
336 | - $originalHeight = $height; |
|
337 | - $height = $maxHeight; |
|
338 | - $width = $height * $width / $originalHeight; |
|
339 | - } |
|
340 | - $attr = " width='$width' height='$height'"; |
|
341 | - } |
|
342 | - return array ( |
|
343 | - $width, |
|
344 | - $height, |
|
345 | - $type, |
|
346 | - $attr |
|
347 | - ); |
|
324 | + $width = ''; |
|
325 | + $height = ''; |
|
326 | + $type = ''; |
|
327 | + $attr = ''; |
|
328 | + if (file_exists($src)) { |
|
329 | + list ($width, $height, $type, $attr) = getimagesize($src); |
|
330 | + if ($width > $maxWidth) { |
|
331 | + $originalWidth = $width; |
|
332 | + $width = $maxWidth; |
|
333 | + $height = $width * $height / $originalWidth; |
|
334 | + } |
|
335 | + if ($height > $maxHeight) { |
|
336 | + $originalHeight = $height; |
|
337 | + $height = $maxHeight; |
|
338 | + $width = $height * $width / $originalHeight; |
|
339 | + } |
|
340 | + $attr = " width='$width' height='$height'"; |
|
341 | + } |
|
342 | + return array ( |
|
343 | + $width, |
|
344 | + $height, |
|
345 | + $type, |
|
346 | + $attr |
|
347 | + ); |
|
348 | 348 | } |
349 | 349 | function &smart_getModuleInfo($moduleName = false) { |
350 | - static $smartModules; |
|
351 | - if (isset ($smartModules[$moduleName])) { |
|
352 | - $ret =& $smartModules[$moduleName]; |
|
353 | - return $ret; |
|
354 | - } |
|
355 | - global $xoopsModule; |
|
356 | - if (!$moduleName) { |
|
357 | - if (isset ($xoopsModule) && is_object($xoopsModule)) { |
|
358 | - $smartModules[$xoopsModule->getVar('dirname')] = & $xoopsModule; |
|
359 | - return $smartModules[$xoopsModule->getVar('dirname')]; |
|
360 | - } |
|
361 | - } |
|
362 | - if (!isset ($smartModules[$moduleName])) { |
|
363 | - if (isset ($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
364 | - $smartModules[$moduleName] = & $xoopsModule; |
|
365 | - } else { |
|
366 | - $hModule = & xoops_gethandler('module'); |
|
367 | - if ($moduleName != 'xoops') { |
|
368 | - $smartModules[$moduleName] = & $hModule->getByDirname($moduleName); |
|
369 | - |
|
370 | - } else { |
|
371 | - $smartModules[$moduleName] = & $hModule->getByDirname('system'); |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
375 | - return $smartModules[$moduleName]; |
|
350 | + static $smartModules; |
|
351 | + if (isset ($smartModules[$moduleName])) { |
|
352 | + $ret =& $smartModules[$moduleName]; |
|
353 | + return $ret; |
|
354 | + } |
|
355 | + global $xoopsModule; |
|
356 | + if (!$moduleName) { |
|
357 | + if (isset ($xoopsModule) && is_object($xoopsModule)) { |
|
358 | + $smartModules[$xoopsModule->getVar('dirname')] = & $xoopsModule; |
|
359 | + return $smartModules[$xoopsModule->getVar('dirname')]; |
|
360 | + } |
|
361 | + } |
|
362 | + if (!isset ($smartModules[$moduleName])) { |
|
363 | + if (isset ($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
364 | + $smartModules[$moduleName] = & $xoopsModule; |
|
365 | + } else { |
|
366 | + $hModule = & xoops_gethandler('module'); |
|
367 | + if ($moduleName != 'xoops') { |
|
368 | + $smartModules[$moduleName] = & $hModule->getByDirname($moduleName); |
|
369 | + |
|
370 | + } else { |
|
371 | + $smartModules[$moduleName] = & $hModule->getByDirname('system'); |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | + return $smartModules[$moduleName]; |
|
376 | 376 | } |
377 | 377 | function &smart_getModuleConfig($moduleName = false) { |
378 | - static $smartConfigs; |
|
379 | - if (isset ($smartConfigs[$moduleName])) { |
|
380 | - $ret = & $smartConfigs[$moduleName]; |
|
381 | - return $ret; |
|
382 | - } |
|
383 | - global $xoopsModule, $xoopsModuleConfig; |
|
384 | - if (!$moduleName) { |
|
385 | - if (isset ($xoopsModule) && is_object($xoopsModule)) { |
|
386 | - $smartConfigs[$xoopsModule->getVar('dirname')] = & $xoopsModuleConfig; |
|
387 | - return $smartConfigs[$xoopsModule->getVar('dirname')]; |
|
388 | - } |
|
389 | - } |
|
390 | - // if we still did not found the xoopsModule, this is because there is none |
|
391 | - if (!$moduleName) { |
|
392 | - $ret = false; |
|
393 | - return $ret; |
|
394 | - } |
|
395 | - if (isset ($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
396 | - $smartConfigs[$moduleName] = & $xoopsModuleConfig; |
|
397 | - } else { |
|
398 | - $module = & smart_getModuleInfo($moduleName); |
|
399 | - if (!is_object($module)) { |
|
400 | - $ret = false; |
|
401 | - return $ret; |
|
402 | - } |
|
403 | - $hModConfig = & xoops_gethandler('config'); |
|
404 | - $smartConfigs[$moduleName] = & $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
405 | - } |
|
406 | - return $smartConfigs[$moduleName]; |
|
378 | + static $smartConfigs; |
|
379 | + if (isset ($smartConfigs[$moduleName])) { |
|
380 | + $ret = & $smartConfigs[$moduleName]; |
|
381 | + return $ret; |
|
382 | + } |
|
383 | + global $xoopsModule, $xoopsModuleConfig; |
|
384 | + if (!$moduleName) { |
|
385 | + if (isset ($xoopsModule) && is_object($xoopsModule)) { |
|
386 | + $smartConfigs[$xoopsModule->getVar('dirname')] = & $xoopsModuleConfig; |
|
387 | + return $smartConfigs[$xoopsModule->getVar('dirname')]; |
|
388 | + } |
|
389 | + } |
|
390 | + // if we still did not found the xoopsModule, this is because there is none |
|
391 | + if (!$moduleName) { |
|
392 | + $ret = false; |
|
393 | + return $ret; |
|
394 | + } |
|
395 | + if (isset ($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
396 | + $smartConfigs[$moduleName] = & $xoopsModuleConfig; |
|
397 | + } else { |
|
398 | + $module = & smart_getModuleInfo($moduleName); |
|
399 | + if (!is_object($module)) { |
|
400 | + $ret = false; |
|
401 | + return $ret; |
|
402 | + } |
|
403 | + $hModConfig = & xoops_gethandler('config'); |
|
404 | + $smartConfigs[$moduleName] = & $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
405 | + } |
|
406 | + return $smartConfigs[$moduleName]; |
|
407 | 407 | } |
408 | 408 | function smart_deleteFile($dirname) { |
409 | - // Simple delete for a file |
|
410 | - if (is_file($dirname)) { |
|
411 | - return unlink($dirname); |
|
412 | - } |
|
409 | + // Simple delete for a file |
|
410 | + if (is_file($dirname)) { |
|
411 | + return unlink($dirname); |
|
412 | + } |
|
413 | 413 | } |
414 | 414 | function smart_formatErrors($errors = array ()) { |
415 | - $ret = ''; |
|
416 | - foreach ($errors as $key => $value) { |
|
417 | - $ret .= "<br /> - " . $value; |
|
418 | - } |
|
419 | - return $ret; |
|
415 | + $ret = ''; |
|
416 | + foreach ($errors as $key => $value) { |
|
417 | + $ret .= "<br /> - " . $value; |
|
418 | + } |
|
419 | + return $ret; |
|
420 | 420 | } |
421 | 421 | /** |
422 | - * smart_getLinkedUnameFromId() |
|
423 | - * |
|
424 | - * @param integer $userid Userid of poster etc |
|
425 | - * @param integer $name : 0 Use Usenamer 1 Use realname |
|
426 | - * @return |
|
427 | - */ |
|
422 | + * smart_getLinkedUnameFromId() |
|
423 | + * |
|
424 | + * @param integer $userid Userid of poster etc |
|
425 | + * @param integer $name : 0 Use Usenamer 1 Use realname |
|
426 | + * @return |
|
427 | + */ |
|
428 | 428 | function smart_getLinkedUnameFromId($userid = 0, $name = 0, $users = array (), $withContact = false) { |
429 | - if (!is_numeric($userid)) { |
|
430 | - return $userid; |
|
431 | - } |
|
432 | - $userid = intval($userid); |
|
433 | - if ($userid > 0) { |
|
434 | - if ($users == array ()) { |
|
435 | - //fetching users |
|
436 | - $member_handler = & xoops_gethandler('member'); |
|
437 | - $user = & $member_handler->getUser($userid); |
|
438 | - } else { |
|
439 | - if (!isset ($users[$userid])) { |
|
440 | - return $GLOBALS['xoopsConfig']['anonymous']; |
|
441 | - } |
|
442 | - $user = & $users[$userid]; |
|
443 | - } |
|
444 | - if (is_object($user)) { |
|
445 | - $ts = & MyTextSanitizer :: getInstance(); |
|
446 | - $username = $user->getVar('uname'); |
|
447 | - $fullname = ''; |
|
448 | - $fullname2 = $user->getVar('name'); |
|
449 | - if (($name) && !empty ($fullname2)) { |
|
450 | - $fullname = $user->getVar('name'); |
|
451 | - } |
|
452 | - if (!empty ($fullname)) { |
|
453 | - $linkeduser = "$fullname [<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $userid . "'>" . $ts->htmlSpecialChars($username) . "</a>]"; |
|
454 | - } else { |
|
455 | - $linkeduser = "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . "</a>"; |
|
456 | - } |
|
457 | - // add contact info : email + PM |
|
458 | - if ($withContact) { |
|
459 | - $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"/></a>'; |
|
460 | - $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);"; |
|
461 | - $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"/></a>'; |
|
462 | - } |
|
463 | - return $linkeduser; |
|
464 | - } |
|
465 | - } |
|
466 | - return $GLOBALS['xoopsConfig']['anonymous']; |
|
429 | + if (!is_numeric($userid)) { |
|
430 | + return $userid; |
|
431 | + } |
|
432 | + $userid = intval($userid); |
|
433 | + if ($userid > 0) { |
|
434 | + if ($users == array ()) { |
|
435 | + //fetching users |
|
436 | + $member_handler = & xoops_gethandler('member'); |
|
437 | + $user = & $member_handler->getUser($userid); |
|
438 | + } else { |
|
439 | + if (!isset ($users[$userid])) { |
|
440 | + return $GLOBALS['xoopsConfig']['anonymous']; |
|
441 | + } |
|
442 | + $user = & $users[$userid]; |
|
443 | + } |
|
444 | + if (is_object($user)) { |
|
445 | + $ts = & MyTextSanitizer :: getInstance(); |
|
446 | + $username = $user->getVar('uname'); |
|
447 | + $fullname = ''; |
|
448 | + $fullname2 = $user->getVar('name'); |
|
449 | + if (($name) && !empty ($fullname2)) { |
|
450 | + $fullname = $user->getVar('name'); |
|
451 | + } |
|
452 | + if (!empty ($fullname)) { |
|
453 | + $linkeduser = "$fullname [<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $userid . "'>" . $ts->htmlSpecialChars($username) . "</a>]"; |
|
454 | + } else { |
|
455 | + $linkeduser = "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . "</a>"; |
|
456 | + } |
|
457 | + // add contact info : email + PM |
|
458 | + if ($withContact) { |
|
459 | + $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"/></a>'; |
|
460 | + $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);"; |
|
461 | + $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"/></a>'; |
|
462 | + } |
|
463 | + return $linkeduser; |
|
464 | + } |
|
465 | + } |
|
466 | + return $GLOBALS['xoopsConfig']['anonymous']; |
|
467 | 467 | } |
468 | 468 | function smart_adminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1) { |
469 | - global $xoopsModule, $xoopsConfig; |
|
470 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
471 | - if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) { |
|
472 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
|
473 | - } else { |
|
474 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
475 | - } |
|
476 | - if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) { |
|
477 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
478 | - } else { |
|
479 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php'; |
|
480 | - } |
|
481 | - $headermenu = array(); |
|
482 | - $adminmenu = array(); |
|
483 | - include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php'; |
|
484 | - $tpl = new XoopsTpl(); |
|
485 | - $tpl->assign(array ( |
|
486 | - 'headermenu' => $headermenu, |
|
487 | - 'adminmenu' => $adminmenu, |
|
488 | - 'current' => $currentoption, |
|
489 | - 'breadcrumb' => $breadcrumb, |
|
490 | - 'headermenucount' => count($headermenu |
|
491 | - ), 'submenus' => $submenus, 'currentsub' => $currentsub, 'submenuscount' => count($submenus))); |
|
492 | - $tpl->display('db:smartobject_admin_menu.html'); |
|
469 | + global $xoopsModule, $xoopsConfig; |
|
470 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
471 | + if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) { |
|
472 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
|
473 | + } else { |
|
474 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
475 | + } |
|
476 | + if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) { |
|
477 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
478 | + } else { |
|
479 | + include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php'; |
|
480 | + } |
|
481 | + $headermenu = array(); |
|
482 | + $adminmenu = array(); |
|
483 | + include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php'; |
|
484 | + $tpl = new XoopsTpl(); |
|
485 | + $tpl->assign(array ( |
|
486 | + 'headermenu' => $headermenu, |
|
487 | + 'adminmenu' => $adminmenu, |
|
488 | + 'current' => $currentoption, |
|
489 | + 'breadcrumb' => $breadcrumb, |
|
490 | + 'headermenucount' => count($headermenu |
|
491 | + ), 'submenus' => $submenus, 'currentsub' => $currentsub, 'submenuscount' => count($submenus))); |
|
492 | + $tpl->display('db:smartobject_admin_menu.html'); |
|
493 | 493 | } |
494 | 494 | function smart_collapsableBar($id = '', $title = '', $dsc = '') { |
495 | - global $xoopsModule; |
|
496 | - echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>"; |
|
497 | - echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "images/close12.gif alt='' /></a> " . $title . "</h3>"; |
|
498 | - echo "<div id='" . $id . "'>"; |
|
499 | - if ($dsc != '') { |
|
500 | - echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . "</span>"; |
|
501 | - } |
|
495 | + global $xoopsModule; |
|
496 | + echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>"; |
|
497 | + echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "images/close12.gif alt='' /></a> " . $title . "</h3>"; |
|
498 | + echo "<div id='" . $id . "'>"; |
|
499 | + if ($dsc != '') { |
|
500 | + echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . "</span>"; |
|
501 | + } |
|
502 | 502 | } |
503 | 503 | function smart_ajaxCollapsableBar($id = '', $title = '', $dsc = '') { |
504 | - global $xoopsModule; |
|
505 | - $onClick = "ajaxtogglecollapse('$id')"; |
|
506 | - //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')"; |
|
507 | - echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">'; |
|
508 | - echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "images/close12.gif alt='' /></a> " . $title . "</h3>"; |
|
509 | - echo "<div id='" . $id . "'>"; |
|
510 | - if ($dsc != '') { |
|
511 | - echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . "</span>"; |
|
512 | - } |
|
504 | + global $xoopsModule; |
|
505 | + $onClick = "ajaxtogglecollapse('$id')"; |
|
506 | + //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')"; |
|
507 | + echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">'; |
|
508 | + echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "images/close12.gif alt='' /></a> " . $title . "</h3>"; |
|
509 | + echo "<div id='" . $id . "'>"; |
|
510 | + if ($dsc != '') { |
|
511 | + echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . "</span>"; |
|
512 | + } |
|
513 | 513 | } |
514 | 514 | /** |
515 | - * Ajax testing...... |
|
516 | - */ |
|
515 | + * Ajax testing...... |
|
516 | + */ |
|
517 | 517 | /* |
518 | 518 | function smart_collapsableBar($id = '', $title = '', $dsc='') |
519 | 519 | { |
@@ -533,20 +533,20 @@ discard block |
||
533 | 533 | } |
534 | 534 | */ |
535 | 535 | function smart_openclose_collapsable($name) { |
536 | - $urls = smart_getCurrentUrls(); |
|
537 | - $path = $urls['phpself']; |
|
538 | - $cookie_name = $path . '_smart_collaps_' . $name; |
|
539 | - $cookie_name = str_replace('.', '_', $cookie_name); |
|
540 | - $cookie = smart_getCookieVar($cookie_name, ''); |
|
541 | - if ($cookie == 'none') { |
|
542 | - echo ' |
|
536 | + $urls = smart_getCurrentUrls(); |
|
537 | + $path = $urls['phpself']; |
|
538 | + $cookie_name = $path . '_smart_collaps_' . $name; |
|
539 | + $cookie_name = str_replace('.', '_', $cookie_name); |
|
540 | + $cookie = smart_getCookieVar($cookie_name, ''); |
|
541 | + if ($cookie == 'none') { |
|
542 | + echo ' |
|
543 | 543 | <script type="text/javascript"><!-- |
544 | 544 | togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon"); |
545 | 545 | //--> |
546 | 546 | </script> |
547 | 547 | '; |
548 | - } |
|
549 | - /* if ($cookie == 'none') { |
|
548 | + } |
|
549 | + /* if ($cookie == 'none') { |
|
550 | 550 | echo ' |
551 | 551 | <script type="text/javascript"><!-- |
552 | 552 | hideElement("' . $name . '"); |
@@ -557,63 +557,63 @@ discard block |
||
557 | 557 | */ |
558 | 558 | } |
559 | 559 | function smart_close_collapsable($name) { |
560 | - echo "</div>"; |
|
561 | - smart_openclose_collapsable($name); |
|
562 | - echo "<br />"; |
|
560 | + echo "</div>"; |
|
561 | + smart_openclose_collapsable($name); |
|
562 | + echo "<br />"; |
|
563 | 563 | } |
564 | 564 | function smart_setCookieVar($name, $value, $time = 0) { |
565 | - if ($time == 0) { |
|
566 | - $time = time() + 3600 * 24 * 365; |
|
567 | - //$time = ''; |
|
568 | - } |
|
569 | - setcookie($name, $value, $time, '/'); |
|
565 | + if ($time == 0) { |
|
566 | + $time = time() + 3600 * 24 * 365; |
|
567 | + //$time = ''; |
|
568 | + } |
|
569 | + setcookie($name, $value, $time, '/'); |
|
570 | 570 | } |
571 | 571 | function smart_getCookieVar($name, $default = '') { |
572 | - $name = str_replace('.', '_', $name); |
|
573 | - if ((isset ($_COOKIE[$name])) && ($_COOKIE[$name] > '')) { |
|
574 | - return $_COOKIE[$name]; |
|
575 | - } else { |
|
576 | - return $default; |
|
577 | - } |
|
572 | + $name = str_replace('.', '_', $name); |
|
573 | + if ((isset ($_COOKIE[$name])) && ($_COOKIE[$name] > '')) { |
|
574 | + return $_COOKIE[$name]; |
|
575 | + } else { |
|
576 | + return $default; |
|
577 | + } |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | function smart_getCurrentUrls() { |
581 | - $urls = array(); |
|
582 | - $http = ((strpos(XOOPS_URL, "https://")) === false) ? ("http://") : ("https://"); |
|
583 | - $phpself = $_SERVER['PHP_SELF']; |
|
584 | - $httphost = $_SERVER['HTTP_HOST']; |
|
585 | - $querystring = $_SERVER['QUERY_STRING']; |
|
586 | - if ($querystring != '') { |
|
587 | - $querystring = '?' . $querystring; |
|
588 | - } |
|
589 | - $currenturl = $http . $httphost . $phpself . $querystring; |
|
590 | - $urls = array (); |
|
591 | - $urls['http'] = $http; |
|
592 | - $urls['httphost'] = $httphost; |
|
593 | - $urls['phpself'] = $phpself; |
|
594 | - $urls['querystring'] = $querystring; |
|
595 | - $urls['full_phpself'] = $http . $httphost . $phpself; |
|
596 | - $urls['full'] = $currenturl; |
|
597 | - $urls['isHomePage'] = (XOOPS_URL . "/index.php") == ($http . $httphost . $phpself); |
|
598 | - return $urls; |
|
581 | + $urls = array(); |
|
582 | + $http = ((strpos(XOOPS_URL, "https://")) === false) ? ("http://") : ("https://"); |
|
583 | + $phpself = $_SERVER['PHP_SELF']; |
|
584 | + $httphost = $_SERVER['HTTP_HOST']; |
|
585 | + $querystring = $_SERVER['QUERY_STRING']; |
|
586 | + if ($querystring != '') { |
|
587 | + $querystring = '?' . $querystring; |
|
588 | + } |
|
589 | + $currenturl = $http . $httphost . $phpself . $querystring; |
|
590 | + $urls = array (); |
|
591 | + $urls['http'] = $http; |
|
592 | + $urls['httphost'] = $httphost; |
|
593 | + $urls['phpself'] = $phpself; |
|
594 | + $urls['querystring'] = $querystring; |
|
595 | + $urls['full_phpself'] = $http . $httphost . $phpself; |
|
596 | + $urls['full'] = $currenturl; |
|
597 | + $urls['isHomePage'] = (XOOPS_URL . "/index.php") == ($http . $httphost . $phpself); |
|
598 | + return $urls; |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | function smart_getCurrentPage() { |
602 | - $urls = smart_getCurrentUrls(); |
|
603 | - return $urls['full']; |
|
602 | + $urls = smart_getCurrentUrls(); |
|
603 | + return $urls['full']; |
|
604 | 604 | } |
605 | 605 | /** |
606 | - * Create a title for the short_url field of an article |
|
607 | - * |
|
608 | - * @credit psylove |
|
609 | - * |
|
610 | - * @var string $title title of the article |
|
611 | - * @var string $withExt do we add an html extension or not |
|
612 | - * @return string sort_url for the article |
|
613 | - */ |
|
606 | + * Create a title for the short_url field of an article |
|
607 | + * |
|
608 | + * @credit psylove |
|
609 | + * |
|
610 | + * @var string $title title of the article |
|
611 | + * @var string $withExt do we add an html extension or not |
|
612 | + * @return string sort_url for the article |
|
613 | + */ |
|
614 | 614 | /** |
615 | - * Moved in SmartMetaGenClass |
|
616 | - */ |
|
615 | + * Moved in SmartMetaGenClass |
|
616 | + */ |
|
617 | 617 | /* |
618 | 618 | function smart_seo_title($title='', $withExt=true) |
619 | 619 | { |
@@ -645,210 +645,210 @@ discard block |
||
645 | 645 | } |
646 | 646 | */ |
647 | 647 | function smart_modFooter() { |
648 | - global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
|
648 | + global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
|
649 | 649 | |
650 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
651 | - $tpl = new XoopsTpl(); |
|
650 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
651 | + $tpl = new XoopsTpl(); |
|
652 | 652 | |
653 | - $hModule = & xoops_gethandler('module'); |
|
654 | - $versioninfo = & $hModule->get($xoopsModule->getVar('mid')); |
|
655 | - $modfootertxt = "Module " . $versioninfo->getInfo('name') . " - Version " . $versioninfo->getInfo('version') . ""; |
|
656 | - $modfooter = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . "/modules/" . $xoopsModule->getVar('dirname') . "/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'/></a>"; |
|
657 | - $tpl->assign('modfooter', $modfooter); |
|
653 | + $hModule = & xoops_gethandler('module'); |
|
654 | + $versioninfo = & $hModule->get($xoopsModule->getVar('mid')); |
|
655 | + $modfootertxt = "Module " . $versioninfo->getInfo('name') . " - Version " . $versioninfo->getInfo('version') . ""; |
|
656 | + $modfooter = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . "/modules/" . $xoopsModule->getVar('dirname') . "/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'/></a>"; |
|
657 | + $tpl->assign('modfooter', $modfooter); |
|
658 | 658 | |
659 | - if (!defined('_AM_SOBJECT_XOOPS_PRO')) { |
|
660 | - define("_AM_SOBJECT_XOOPS_PRO", "Do you need help with this module ?<br />Do you need new features not yet available ?"); |
|
661 | - } |
|
662 | - $smartobject_config = smart_getModuleConfig('smartobject'); |
|
663 | - $tpl->assign('smartobject_enable_admin_footer', $smartobject_config['enable_admin_footer']); |
|
664 | - $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.html'); |
|
659 | + if (!defined('_AM_SOBJECT_XOOPS_PRO')) { |
|
660 | + define("_AM_SOBJECT_XOOPS_PRO", "Do you need help with this module ?<br />Do you need new features not yet available ?"); |
|
661 | + } |
|
662 | + $smartobject_config = smart_getModuleConfig('smartobject'); |
|
663 | + $tpl->assign('smartobject_enable_admin_footer', $smartobject_config['enable_admin_footer']); |
|
664 | + $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.html'); |
|
665 | 665 | } |
666 | 666 | function smart_xoops_cp_footer() { |
667 | - smart_modFooter(); |
|
668 | - xoops_cp_footer(); |
|
667 | + smart_modFooter(); |
|
668 | + xoops_cp_footer(); |
|
669 | 669 | } |
670 | 670 | function smart_sanitizeForCommonTags($text) { |
671 | - global $xoopsConfig; |
|
672 | - $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text); |
|
673 | - $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text); |
|
674 | - return $text; |
|
671 | + global $xoopsConfig; |
|
672 | + $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text); |
|
673 | + $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text); |
|
674 | + return $text; |
|
675 | 675 | } |
676 | 676 | function smart_addScript($src) { |
677 | - echo '<script src="' . $src . '" type="text/javascript"></script>'; |
|
677 | + echo '<script src="' . $src . '" type="text/javascript"></script>'; |
|
678 | 678 | } |
679 | 679 | function smart_addStyle($src) { |
680 | - if ($src == 'smartobject') { |
|
681 | - $src = SMARTOBJECT_URL . 'module.css'; |
|
682 | - } |
|
683 | - echo smart_get_css_link($src); |
|
680 | + if ($src == 'smartobject') { |
|
681 | + $src = SMARTOBJECT_URL . 'module.css'; |
|
682 | + } |
|
683 | + echo smart_get_css_link($src); |
|
684 | 684 | } |
685 | 685 | function smart_addAdminAjaxSupport() { |
686 | - smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js'); |
|
687 | - smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js'); |
|
688 | - smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js'); |
|
686 | + smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js'); |
|
687 | + smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js'); |
|
688 | + smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js'); |
|
689 | 689 | } |
690 | 690 | function smart_sanitizeForSmartpopupLink($text) { |
691 | - $patterns[] = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU"; |
|
692 | - $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>"; |
|
693 | - $ret = preg_replace($patterns, $replacements, $text); |
|
694 | - return $ret; |
|
691 | + $patterns[] = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU"; |
|
692 | + $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>"; |
|
693 | + $ret = preg_replace($patterns, $replacements, $text); |
|
694 | + return $ret; |
|
695 | 695 | } |
696 | 696 | /** |
697 | - * Finds the width and height of an image (can also be a flash file) |
|
698 | - * |
|
699 | - * @credit phppp |
|
700 | - * |
|
701 | - * @var string $url path of the image file |
|
702 | - * @var string $width reference to the width |
|
703 | - * @var string $height reference to the height |
|
704 | - * @return bool false if impossible to find dimension |
|
705 | - */ |
|
697 | + * Finds the width and height of an image (can also be a flash file) |
|
698 | + * |
|
699 | + * @credit phppp |
|
700 | + * |
|
701 | + * @var string $url path of the image file |
|
702 | + * @var string $width reference to the width |
|
703 | + * @var string $height reference to the height |
|
704 | + * @return bool false if impossible to find dimension |
|
705 | + */ |
|
706 | 706 | function smart_getImageSize($url, & $width, & $height) { |
707 | - if (empty ($width) || empty ($height)) { |
|
708 | - if (!$dimension = @ getimagesize($url)) { |
|
709 | - return false; |
|
710 | - } |
|
711 | - if (!empty ($width)) { |
|
712 | - $height = $dimension[1] * $width / $dimension[0]; |
|
713 | - } |
|
714 | - elseif (!empty ($height)) { |
|
715 | - $width = $dimension[0] * $height / $dimension[1]; |
|
716 | - } else { |
|
717 | - list ($width, $height) = array ( |
|
718 | - $dimension[0], |
|
719 | - $dimension[1] |
|
720 | - ); |
|
721 | - } |
|
722 | - return true; |
|
723 | - } else { |
|
724 | - return true; |
|
725 | - } |
|
707 | + if (empty ($width) || empty ($height)) { |
|
708 | + if (!$dimension = @ getimagesize($url)) { |
|
709 | + return false; |
|
710 | + } |
|
711 | + if (!empty ($width)) { |
|
712 | + $height = $dimension[1] * $width / $dimension[0]; |
|
713 | + } |
|
714 | + elseif (!empty ($height)) { |
|
715 | + $width = $dimension[0] * $height / $dimension[1]; |
|
716 | + } else { |
|
717 | + list ($width, $height) = array ( |
|
718 | + $dimension[0], |
|
719 | + $dimension[1] |
|
720 | + ); |
|
721 | + } |
|
722 | + return true; |
|
723 | + } else { |
|
724 | + return true; |
|
725 | + } |
|
726 | 726 | } |
727 | 727 | /** |
728 | - * Convert characters to decimal values |
|
729 | - * |
|
730 | - * @author eric.wallet at yahoo.fr |
|
731 | - * @link http://ca.php.net/manual/en/function.htmlentities.php#69913 |
|
732 | - */ |
|
728 | + * Convert characters to decimal values |
|
729 | + * |
|
730 | + * @author eric.wallet at yahoo.fr |
|
731 | + * @link http://ca.php.net/manual/en/function.htmlentities.php#69913 |
|
732 | + */ |
|
733 | 733 | function smart_htmlnumericentities($str) { |
734 | - return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); |
|
734 | + return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); |
|
735 | 735 | } |
736 | 736 | function & smart_getcorehandler($name, $optional = false) { |
737 | - static $handlers; |
|
738 | - $name = strtolower(trim($name)); |
|
739 | - if (!isset ($handlers[$name])) { |
|
740 | - if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { |
|
741 | - require_once $hnd_file; |
|
742 | - } |
|
743 | - $class = 'Xoops' . ucfirst($name) . 'Handler'; |
|
744 | - if (class_exists($class)) { |
|
745 | - $handlers[$name] = new $class ($GLOBALS['xoopsDB'], 'xoops'); |
|
746 | - } |
|
747 | - } |
|
748 | - if (!isset ($handlers[$name]) && !$optional) { |
|
749 | - trigger_error('Class <b>' . $class . '</b> does not exist<br />Handler Name: ' . $name, E_USER_ERROR); |
|
750 | - } |
|
751 | - if (isset ($handlers[$name])) { |
|
752 | - return $handlers[$name]; |
|
753 | - } |
|
754 | - $inst = false; |
|
737 | + static $handlers; |
|
738 | + $name = strtolower(trim($name)); |
|
739 | + if (!isset ($handlers[$name])) { |
|
740 | + if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { |
|
741 | + require_once $hnd_file; |
|
742 | + } |
|
743 | + $class = 'Xoops' . ucfirst($name) . 'Handler'; |
|
744 | + if (class_exists($class)) { |
|
745 | + $handlers[$name] = new $class ($GLOBALS['xoopsDB'], 'xoops'); |
|
746 | + } |
|
747 | + } |
|
748 | + if (!isset ($handlers[$name]) && !$optional) { |
|
749 | + trigger_error('Class <b>' . $class . '</b> does not exist<br />Handler Name: ' . $name, E_USER_ERROR); |
|
750 | + } |
|
751 | + if (isset ($handlers[$name])) { |
|
752 | + return $handlers[$name]; |
|
753 | + } |
|
754 | + $inst = false; |
|
755 | 755 | } |
756 | 756 | function smart_sanitizeAdsenses_callback($matches) { |
757 | - global $smartobject_adsense_handler; |
|
758 | - if (isset($smartobject_adsense_handler->objects[$matches[1]])){ |
|
759 | - $adsenseObj = $smartobject_adsense_handler->objects[$matches[1]]; |
|
760 | - $ret = $adsenseObj->render(); |
|
761 | - return $ret; |
|
762 | - } else { |
|
763 | - return ''; |
|
764 | - } |
|
757 | + global $smartobject_adsense_handler; |
|
758 | + if (isset($smartobject_adsense_handler->objects[$matches[1]])){ |
|
759 | + $adsenseObj = $smartobject_adsense_handler->objects[$matches[1]]; |
|
760 | + $ret = $adsenseObj->render(); |
|
761 | + return $ret; |
|
762 | + } else { |
|
763 | + return ''; |
|
764 | + } |
|
765 | 765 | } |
766 | 766 | function smart_sanitizeAdsenses($text) { |
767 | 767 | |
768 | - $patterns = array (); |
|
769 | - $replacements = array (); |
|
768 | + $patterns = array (); |
|
769 | + $replacements = array (); |
|
770 | 770 | |
771 | - $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU"; |
|
772 | - $text = preg_replace_callback($patterns, 'smart_sanitizeAdsenses_callback', $text); |
|
773 | - return $text; |
|
771 | + $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU"; |
|
772 | + $text = preg_replace_callback($patterns, 'smart_sanitizeAdsenses_callback', $text); |
|
773 | + return $text; |
|
774 | 774 | } |
775 | 775 | function smart_sanitizeCustomtags_callback($matches) { |
776 | - global $smartobject_customtag_handler; |
|
777 | - if (isset($smartobject_customtag_handler->objects[$matches[1]])){ |
|
778 | - $customObj = $smartobject_customtag_handler->objects[$matches[1]]; |
|
779 | - $ret = $customObj->renderWithPhp(); |
|
780 | - return $ret; |
|
781 | - } else { |
|
782 | - return ''; |
|
783 | - } |
|
776 | + global $smartobject_customtag_handler; |
|
777 | + if (isset($smartobject_customtag_handler->objects[$matches[1]])){ |
|
778 | + $customObj = $smartobject_customtag_handler->objects[$matches[1]]; |
|
779 | + $ret = $customObj->renderWithPhp(); |
|
780 | + return $ret; |
|
781 | + } else { |
|
782 | + return ''; |
|
783 | + } |
|
784 | 784 | } |
785 | 785 | function smart_sanitizeCustomtags($text) { |
786 | - $patterns = array (); |
|
787 | - $replacements = array (); |
|
786 | + $patterns = array (); |
|
787 | + $replacements = array (); |
|
788 | 788 | |
789 | - $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU"; |
|
790 | - $text = preg_replace_callback($patterns, 'smart_sanitizeCustomtags_callback', $text); |
|
791 | - return $text; |
|
789 | + $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU"; |
|
790 | + $text = preg_replace_callback($patterns, 'smart_sanitizeCustomtags_callback', $text); |
|
791 | + return $text; |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | function smart_loadLanguageFile($module, $file) { |
795 | - global $xoopsConfig; |
|
795 | + global $xoopsConfig; |
|
796 | 796 | |
797 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php'; |
|
798 | - if (!file_exists($filename)) { |
|
799 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php'; |
|
800 | - } |
|
801 | - if (file_exists($filename)) { |
|
802 | - include_once($filename); |
|
803 | - } |
|
797 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php'; |
|
798 | + if (!file_exists($filename)) { |
|
799 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php'; |
|
800 | + } |
|
801 | + if (file_exists($filename)) { |
|
802 | + include_once($filename); |
|
803 | + } |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | function smart_loadCommonLanguageFile() { |
807 | - smart_loadLanguageFile('smartobject', 'common'); |
|
807 | + smart_loadLanguageFile('smartobject', 'common'); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | function smart_purifyText($text, $keyword = false) |
811 | 811 | { |
812 | - global $myts; |
|
813 | - $text = str_replace(' ', ' ', $text); |
|
814 | - $text = str_replace('<br />', ' ', $text); |
|
815 | - $text = str_replace('<br/>', ' ', $text); |
|
816 | - $text = str_replace('<br', ' ', $text); |
|
817 | - $text = strip_tags($text); |
|
818 | - $text = html_entity_decode($text); |
|
819 | - $text = $myts->undoHtmlSpecialChars($text); |
|
820 | - $text = str_replace(')', ' ', $text); |
|
821 | - $text = str_replace('(', ' ', $text); |
|
822 | - $text = str_replace(':', ' ', $text); |
|
823 | - $text = str_replace('&euro', ' euro ', $text); |
|
824 | - $text = str_replace('&hellip', '...', $text); |
|
825 | - $text = str_replace('&rsquo', ' ', $text); |
|
826 | - $text = str_replace('!', ' ', $text); |
|
827 | - $text = str_replace('?', ' ', $text); |
|
828 | - $text = str_replace('"', ' ', $text); |
|
829 | - $text = str_replace('-', ' ', $text); |
|
830 | - $text = str_replace('\n', ' ', $text); |
|
831 | - $text = str_replace('―', ' ', $text); |
|
832 | - |
|
833 | - if ($keyword){ |
|
834 | - $text = str_replace('.', ' ', $text); |
|
835 | - $text = str_replace(',', ' ', $text); |
|
836 | - $text = str_replace('\'', ' ', $text); |
|
837 | - } |
|
838 | - $text = str_replace(';', ' ', $text); |
|
839 | - |
|
840 | - return $text; |
|
812 | + global $myts; |
|
813 | + $text = str_replace(' ', ' ', $text); |
|
814 | + $text = str_replace('<br />', ' ', $text); |
|
815 | + $text = str_replace('<br/>', ' ', $text); |
|
816 | + $text = str_replace('<br', ' ', $text); |
|
817 | + $text = strip_tags($text); |
|
818 | + $text = html_entity_decode($text); |
|
819 | + $text = $myts->undoHtmlSpecialChars($text); |
|
820 | + $text = str_replace(')', ' ', $text); |
|
821 | + $text = str_replace('(', ' ', $text); |
|
822 | + $text = str_replace(':', ' ', $text); |
|
823 | + $text = str_replace('&euro', ' euro ', $text); |
|
824 | + $text = str_replace('&hellip', '...', $text); |
|
825 | + $text = str_replace('&rsquo', ' ', $text); |
|
826 | + $text = str_replace('!', ' ', $text); |
|
827 | + $text = str_replace('?', ' ', $text); |
|
828 | + $text = str_replace('"', ' ', $text); |
|
829 | + $text = str_replace('-', ' ', $text); |
|
830 | + $text = str_replace('\n', ' ', $text); |
|
831 | + $text = str_replace('―', ' ', $text); |
|
832 | + |
|
833 | + if ($keyword){ |
|
834 | + $text = str_replace('.', ' ', $text); |
|
835 | + $text = str_replace(',', ' ', $text); |
|
836 | + $text = str_replace('\'', ' ', $text); |
|
837 | + } |
|
838 | + $text = str_replace(';', ' ', $text); |
|
839 | + |
|
840 | + return $text; |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | function smart_html2text($document) |
844 | 844 | { |
845 | - // PHP Manual:: function preg_replace |
|
846 | - // $document should contain an HTML document. |
|
847 | - // This will remove HTML tags, javascript sections |
|
848 | - // and white space. It will also convert some |
|
849 | - // common HTML entities to their text equivalent. |
|
850 | - // Credits : newbb2 |
|
851 | - $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript |
|
845 | + // PHP Manual:: function preg_replace |
|
846 | + // $document should contain an HTML document. |
|
847 | + // This will remove HTML tags, javascript sections |
|
848 | + // and white space. It will also convert some |
|
849 | + // common HTML entities to their text equivalent. |
|
850 | + // Credits : newbb2 |
|
851 | + $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript |
|
852 | 852 | "'<img.*?/>'si", // Strip out img tags |
853 | 853 | "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
854 | 854 | "'([\r\n])[\s]+'", // Strip out white space |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | "'&(copy|#169);'i", |
864 | 864 | "'&#(\d+);'e"); // evaluate as php |
865 | 865 | |
866 | - $replace = array ("", |
|
866 | + $replace = array ("", |
|
867 | 867 | "", |
868 | 868 | "", |
869 | 869 | "\\1", |
@@ -872,14 +872,14 @@ discard block |
||
872 | 872 | "<", |
873 | 873 | ">", |
874 | 874 | " ", |
875 | - chr(161), |
|
876 | - chr(162), |
|
877 | - chr(163), |
|
878 | - chr(169), |
|
875 | + chr(161), |
|
876 | + chr(162), |
|
877 | + chr(163), |
|
878 | + chr(169), |
|
879 | 879 | "chr(\\1)"); |
880 | 880 | |
881 | - $text = preg_replace($search, $replace, $document); |
|
882 | - return $text; |
|
881 | + $text = preg_replace($search, $replace, $document); |
|
882 | + return $text; |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -889,91 +889,91 @@ discard block |
||
889 | 889 | * This function should be able to cover almost all floats that appear in an european environment. |
890 | 890 | */ |
891 | 891 | function smart_getfloat($str, $set=FALSE){ |
892 | - if(preg_match("/([0-9\.,-]+)/", $str, $match)) { |
|
893 | - // Found number in $str, so set $str that number |
|
894 | - $str = $match[0]; |
|
895 | - if(strstr($str, ',')){ |
|
896 | - // A comma exists, that makes it easy, cos we assume it separates the decimal part. |
|
897 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
898 | - $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
899 | - return floatval($str); |
|
900 | - }else{ |
|
901 | - // No comma exists, so we have to decide, how a single dot shall be treated |
|
902 | - if(preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) == TRUE && $set['single_dot_as_decimal'] == TRUE){ |
|
903 | - // Treat single dot as decimal separator |
|
904 | - |
|
905 | - return floatval($str); |
|
906 | - } else {//echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br/><br/> "; |
|
907 | - // Else, treat all dots as thousand seps |
|
908 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
909 | - return floatval($str); |
|
910 | - } |
|
911 | - } |
|
912 | - }else{ |
|
913 | - // No number found, return zero |
|
914 | - return 0; |
|
915 | - } |
|
892 | + if(preg_match("/([0-9\.,-]+)/", $str, $match)) { |
|
893 | + // Found number in $str, so set $str that number |
|
894 | + $str = $match[0]; |
|
895 | + if(strstr($str, ',')){ |
|
896 | + // A comma exists, that makes it easy, cos we assume it separates the decimal part. |
|
897 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
898 | + $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
899 | + return floatval($str); |
|
900 | + }else{ |
|
901 | + // No comma exists, so we have to decide, how a single dot shall be treated |
|
902 | + if(preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) == TRUE && $set['single_dot_as_decimal'] == TRUE){ |
|
903 | + // Treat single dot as decimal separator |
|
904 | + |
|
905 | + return floatval($str); |
|
906 | + } else {//echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br/><br/> "; |
|
907 | + // Else, treat all dots as thousand seps |
|
908 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
909 | + return floatval($str); |
|
910 | + } |
|
911 | + } |
|
912 | + }else{ |
|
913 | + // No number found, return zero |
|
914 | + return 0; |
|
915 | + } |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | function smart_currency($var, $currencyObj=false) { |
919 | - $ret = smart_getfloat($var, array('single_dot_as_decimal'=> TRUE)); |
|
920 | - $ret = round($ret, 2); |
|
921 | - // make sur we have at least .00 in the $var |
|
922 | - $decimal_section_original = strstr($ret, '.'); |
|
923 | - $decimal_section = $decimal_section_original; |
|
924 | - if ($decimal_section) { |
|
925 | - if (strlen($decimal_section) == 1) { |
|
926 | - $decimal_section = '.00'; |
|
927 | - } elseif(strlen($decimal_section) == 2) { |
|
928 | - $decimal_section = $decimal_section . '0'; |
|
929 | - } |
|
930 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
931 | - } else { |
|
932 | - $ret = $ret . '.00'; |
|
933 | - } |
|
934 | - if ($currencyObj) { |
|
935 | - $ret = $ret . ' ' . $currencyObj->getCode(); |
|
936 | - } |
|
919 | + $ret = smart_getfloat($var, array('single_dot_as_decimal'=> TRUE)); |
|
920 | + $ret = round($ret, 2); |
|
921 | + // make sur we have at least .00 in the $var |
|
922 | + $decimal_section_original = strstr($ret, '.'); |
|
923 | + $decimal_section = $decimal_section_original; |
|
924 | + if ($decimal_section) { |
|
925 | + if (strlen($decimal_section) == 1) { |
|
926 | + $decimal_section = '.00'; |
|
927 | + } elseif(strlen($decimal_section) == 2) { |
|
928 | + $decimal_section = $decimal_section . '0'; |
|
929 | + } |
|
930 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
931 | + } else { |
|
932 | + $ret = $ret . '.00'; |
|
933 | + } |
|
934 | + if ($currencyObj) { |
|
935 | + $ret = $ret . ' ' . $currencyObj->getCode(); |
|
936 | + } |
|
937 | 937 | return $ret; |
938 | 938 | } |
939 | 939 | |
940 | 940 | function smart_float($var) { |
941 | - return smart_currency($var); |
|
941 | + return smart_currency($var); |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | function smart_getModuleAdminLink($moduleName=false) { |
945 | - global $xoopsModule; |
|
946 | - if (!$moduleName && (isset ($xoopsModule) && is_object($xoopsModule))) { |
|
947 | - $moduleName = $xoopsModule->getVar('dirname'); |
|
948 | - } |
|
949 | - $ret = ''; |
|
950 | - if ($moduleName) { |
|
951 | - $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" ._CO_SOBJECT_ADMIN_PAGE . "</a>"; |
|
952 | - } |
|
953 | - return $ret; |
|
945 | + global $xoopsModule; |
|
946 | + if (!$moduleName && (isset ($xoopsModule) && is_object($xoopsModule))) { |
|
947 | + $moduleName = $xoopsModule->getVar('dirname'); |
|
948 | + } |
|
949 | + $ret = ''; |
|
950 | + if ($moduleName) { |
|
951 | + $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" ._CO_SOBJECT_ADMIN_PAGE . "</a>"; |
|
952 | + } |
|
953 | + return $ret; |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | function smart_getEditors() { |
957 | - $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php'; |
|
958 | - if (!file_exists($filename)) { |
|
959 | - return false; |
|
960 | - } |
|
961 | - include_once $filename; |
|
962 | - $xoopseditor_handler = XoopsEditorHandler::getInstance(); |
|
963 | - $aList = $xoopseditor_handler->getList(); |
|
964 | - $ret = array(); |
|
965 | - foreach($aList as $k=>$v) { |
|
966 | - $ret[$v] = $k; |
|
967 | - } |
|
968 | - return $ret; |
|
957 | + $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php'; |
|
958 | + if (!file_exists($filename)) { |
|
959 | + return false; |
|
960 | + } |
|
961 | + include_once $filename; |
|
962 | + $xoopseditor_handler = XoopsEditorHandler::getInstance(); |
|
963 | + $aList = $xoopseditor_handler->getList(); |
|
964 | + $ret = array(); |
|
965 | + foreach($aList as $k=>$v) { |
|
966 | + $ret[$v] = $k; |
|
967 | + } |
|
968 | + return $ret; |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | function smart_getTablesArray($moduleName, $items) { |
972 | - $ret = array(); |
|
973 | - foreach ($items as $item) { |
|
974 | - $ret[] = $moduleName . '_' . $item; |
|
975 | - } |
|
976 | - $ret[] = $moduleName . '_meta'; |
|
977 | - return $ret; |
|
972 | + $ret = array(); |
|
973 | + foreach ($items as $item) { |
|
974 | + $ret[] = $moduleName . '_' . $item; |
|
975 | + } |
|
976 | + $ret[] = $moduleName . '_meta'; |
|
977 | + return $ret; |
|
978 | 978 | } |
979 | 979 | ?> |
980 | 980 | \ No newline at end of file |
@@ -7,20 +7,20 @@ |
||
7 | 7 | * Licence: GNU |
8 | 8 | */ |
9 | 9 | if (!defined("XOOPS_ROOT_PATH")) { |
10 | - die("XOOPS root path not defined"); |
|
10 | + die("XOOPS root path not defined"); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function smart_adsense_initiate_smartytags() { |
14 | - global $xoopsTpl, $smartobject_adsense_handler; |
|
15 | - if (is_object($xoopsTpl)) { |
|
16 | - foreach($smartobject_adsense_handler->objects as $k=>$v) { |
|
17 | - $xoopsTpl->assign('adsense_' . $k, $v->render()); |
|
18 | - } |
|
19 | - } |
|
14 | + global $xoopsTpl, $smartobject_adsense_handler; |
|
15 | + if (is_object($xoopsTpl)) { |
|
16 | + foreach($smartobject_adsense_handler->objects as $k=>$v) { |
|
17 | + $xoopsTpl->assign('adsense_' . $k, $v->render()); |
|
18 | + } |
|
19 | + } |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | if (!defined('SMARTOBJECT_URL')) { |
23 | - include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
23 | + include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | include_once XOOPS_ROOT_PATH."/modules/smartobject/include/functions.php"; |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * Licence: GNU |
8 | 8 | */ |
9 | 9 | if (!defined("XOOPS_ROOT_PATH")) { |
10 | - die("XOOPS root path not defined"); |
|
10 | + die("XOOPS root path not defined"); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | smart_loadCommonLanguageFile(); |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | $smartobject_currency_handler = xoops_getModuleHandler('currency', 'smartobject'); |
20 | 20 | |
21 | 21 | if (!$smartobject_currenciesObj) { |
22 | - $smartobject_currenciesObj = $smartobject_currency_handler->getCurrencies(); |
|
22 | + $smartobject_currenciesObj = $smartobject_currency_handler->getCurrencies(); |
|
23 | 23 | } |
24 | 24 | if (!$smartobject_currenciesArray) { |
25 | - foreach($smartobject_currenciesObj as $currencyid=>$currencyObj) { |
|
26 | - if ($currencyObj->getVar('default_currency', 'e')) { |
|
27 | - $smartobject_default_currency = $currencyObj; |
|
28 | - } |
|
29 | - $smartobject_currenciesArray[$currencyid] = $currencyObj->getCode(); |
|
30 | - } |
|
25 | + foreach($smartobject_currenciesObj as $currencyid=>$currencyObj) { |
|
26 | + if ($currencyObj->getVar('default_currency', 'e')) { |
|
27 | + $smartobject_default_currency = $currencyObj; |
|
28 | + } |
|
29 | + $smartobject_currenciesArray[$currencyid] = $currencyObj->getCode(); |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | ?> |
34 | 34 | \ No newline at end of file |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * Licence: GNU |
8 | 8 | */ |
9 | 9 | if (!defined("XOOPS_ROOT_PATH")) { |
10 | - die("XOOPS root path not defined"); |
|
10 | + die("XOOPS root path not defined"); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | global $xoopsConfig; |
@@ -16,22 +16,22 @@ discard block |
||
16 | 16 | * SmartObject library path |
17 | 17 | */ |
18 | 18 | if (!defined('SMARTOBJECT_URL')) { |
19 | - define('SMARTOBJECT_URL', XOOPS_URL . "/modules/smartobject/"); |
|
19 | + define('SMARTOBJECT_URL', XOOPS_URL . "/modules/smartobject/"); |
|
20 | 20 | } |
21 | 21 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
22 | - define('SMARTOBJECT_ROOT_PATH', XOOPS_ROOT_PATH . "/modules/smartobject/"); |
|
22 | + define('SMARTOBJECT_ROOT_PATH', XOOPS_ROOT_PATH . "/modules/smartobject/"); |
|
23 | 23 | } |
24 | 24 | if (!defined('SMARTOBJECT_IMAGES_URL')) { |
25 | - define('SMARTOBJECT_IMAGES_URL', SMARTOBJECT_URL . "images/"); |
|
25 | + define('SMARTOBJECT_IMAGES_URL', SMARTOBJECT_URL . "images/"); |
|
26 | 26 | } |
27 | 27 | if (!defined('SMARTOBJECT_IMAGES_ROOT_PATH')) { |
28 | - define('SMARTOBJECT_IMAGES_ROOT_PATH', SMARTOBJECT_ROOT_PATH . "images/"); |
|
28 | + define('SMARTOBJECT_IMAGES_ROOT_PATH', SMARTOBJECT_ROOT_PATH . "images/"); |
|
29 | 29 | } |
30 | 30 | if (!defined('SMARTOBJECT_IMAGES_ACTIONS_URL')) { |
31 | - define('SMARTOBJECT_IMAGES_ACTIONS_URL', SMARTOBJECT_URL . "images/actions/"); |
|
31 | + define('SMARTOBJECT_IMAGES_ACTIONS_URL', SMARTOBJECT_URL . "images/actions/"); |
|
32 | 32 | } |
33 | 33 | if (!defined('SMARTOBJECT_IMAGES_ACTIONS_ROOT_PATH')) { |
34 | - define('SMARTOBJECT_IMAGES_ACTIONS_ROOT_PATH', SMARTOBJECT_ROOT_PATH . "images/actions/"); |
|
34 | + define('SMARTOBJECT_IMAGES_ACTIONS_ROOT_PATH', SMARTOBJECT_ROOT_PATH . "images/actions/"); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -7,20 +7,20 @@ |
||
7 | 7 | * Licence: GNU |
8 | 8 | */ |
9 | 9 | if (!defined("XOOPS_ROOT_PATH")) { |
10 | - die("XOOPS root path not defined"); |
|
10 | + die("XOOPS root path not defined"); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function smart_customtag_initiate() { |
14 | - global $xoopsTpl, $smartobject_customtag_handler; |
|
15 | - if (is_object($xoopsTpl)) { |
|
16 | - foreach($smartobject_customtag_handler->objects as $k=>$v) { |
|
17 | - $xoopsTpl->assign($k, $v->render()); |
|
18 | - } |
|
19 | - } |
|
14 | + global $xoopsTpl, $smartobject_customtag_handler; |
|
15 | + if (is_object($xoopsTpl)) { |
|
16 | + foreach($smartobject_customtag_handler->objects as $k=>$v) { |
|
17 | + $xoopsTpl->assign($k, $v->render()); |
|
18 | + } |
|
19 | + } |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | if (!defined('SMARTOBJECT_URL')) { |
23 | - include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
23 | + include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | smart_loadLanguageFile('smartobject', 'customtag'); |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * Licence: GNU |
8 | 8 | */ |
9 | 9 | if (!defined("XOOPS_ROOT_PATH")) { |
10 | - die("XOOPS root path not defined"); |
|
10 | + die("XOOPS root path not defined"); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -15,43 +15,43 @@ discard block |
||
15 | 15 | * Author : The SmartFactory |
16 | 16 | */ |
17 | 17 | function xoops_debug_dumbQuery($msg='') { |
18 | - global $xoopsDB; |
|
19 | - $xoopsDB->query('SELECT * ' . $msg . ' FROM dudewhereismycar2'); |
|
18 | + global $xoopsDB; |
|
19 | + $xoopsDB->query('SELECT * ' . $msg . ' FROM dudewhereismycar2'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | function xoops_debug_initiateQueryCount() |
23 | 23 | { |
24 | - global $smartfactory_query_count_activated, $smartfactory_query_count; |
|
25 | - $smartfactory_query_count_activated = true; |
|
26 | - $smartfactory_query_count = 0; |
|
24 | + global $smartfactory_query_count_activated, $smartfactory_query_count; |
|
25 | + $smartfactory_query_count_activated = true; |
|
26 | + $smartfactory_query_count = 0; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | function xoops_debug_getQueryCount($msg='') |
30 | 30 | { |
31 | - global $smartfactory_query_count; |
|
32 | - return xoops_debug("xoops debug Query count ($msg): $smartfactory_query_count"); |
|
31 | + global $smartfactory_query_count; |
|
32 | + return xoops_debug("xoops debug Query count ($msg): $smartfactory_query_count"); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | function xoops_debug($msg, $exit=false) |
36 | 36 | { |
37 | - echo "<div style='padding: 5px; color: red; font-weight: bold'>debug :: $msg</div>"; |
|
38 | - if ($exit) { |
|
39 | - die(); |
|
40 | - } |
|
37 | + echo "<div style='padding: 5px; color: red; font-weight: bold'>debug :: $msg</div>"; |
|
38 | + if ($exit) { |
|
39 | + die(); |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | function xoops_comment($msg) |
44 | 44 | { |
45 | - echo "<div style='padding: 5px; color: green; font-weight: bold'>=> $msg</div>"; |
|
45 | + echo "<div style='padding: 5px; color: green; font-weight: bold'>=> $msg</div>"; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | function xoops_debug_vardump($var) |
49 | 49 | { |
50 | - if (class_exists('MyTextSanitizer')) { |
|
51 | - $myts = MyTextSanitizer::getInstance(); |
|
52 | - xoops_debug($myts->displayTarea(var_export($var, true))); |
|
53 | - } else { |
|
54 | - xoops_debug(var_export($var, true)); |
|
55 | - } |
|
50 | + if (class_exists('MyTextSanitizer')) { |
|
51 | + $myts = MyTextSanitizer::getInstance(); |
|
52 | + xoops_debug($myts->displayTarea(var_export($var, true))); |
|
53 | + } else { |
|
54 | + xoops_debug(var_export($var, true)); |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | ?> |
58 | 58 | \ No newline at end of file |
@@ -12,205 +12,205 @@ |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | class XoopsCaptcha { |
15 | - var $active = true; |
|
16 | - var $mode = "text"; // potential values: image, text |
|
17 | - var $config = array(); |
|
18 | - |
|
19 | - var $message = array(); // Logging error messages |
|
20 | - |
|
21 | - function XoopsCaptcha() |
|
22 | - { |
|
23 | - // Loading default preferences |
|
24 | - $this->config = @include dirname(__FILE__)."/config.php"; |
|
25 | - |
|
26 | - $this->setMode($this->config["mode"]); |
|
27 | - } |
|
28 | - |
|
29 | - function &instance() |
|
30 | - { |
|
31 | - static $instance; |
|
32 | - if(!isset($instance)) { |
|
33 | - $instance = new XoopsCaptcha(); |
|
34 | - } |
|
35 | - return $instance; |
|
36 | - } |
|
37 | - |
|
38 | - function setConfig($name, $val) |
|
39 | - { |
|
40 | - if($name == "mode") { |
|
41 | - $this->setMode($val); |
|
42 | - }elseif(isset($this->$name)) { |
|
43 | - $this->$name = $val; |
|
44 | - }else { |
|
45 | - $this->config[$name] = $val; |
|
46 | - } |
|
47 | - return true; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Set CAPTCHA mode |
|
52 | - * |
|
53 | - * For future possible modes, right now force to use text or image |
|
54 | - * |
|
55 | - * @param string $mode if no mode is set, just verify current mode |
|
56 | - */ |
|
57 | - function setMode($mode = null) |
|
58 | - { |
|
59 | - if( !empty($mode) && in_array($mode, array("text", "image")) ) { |
|
60 | - $this->mode = $mode; |
|
61 | - |
|
62 | - if($this->mode != "image") { |
|
63 | - return; |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - // Disable image mode |
|
68 | - if(!extension_loaded('gd')) { |
|
69 | - $this->mode = "text"; |
|
70 | - }else{ |
|
71 | - $required_functions = array("imagecreatetruecolor", "imagecolorallocate", "imagefilledrectangle", "imagejpeg", "imagedestroy", "imageftbbox"); |
|
72 | - foreach($required_functions as $func) { |
|
73 | - if(!function_exists($func)) { |
|
74 | - $this->mode = "text"; |
|
75 | - break; |
|
76 | - } |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Initializing the CAPTCHA class |
|
84 | - */ |
|
85 | - function init($name = 'xoopscaptcha', $skipmember = null, $num_chars = null, $fontsize_min = null, $fontsize_max = null, $background_type = null, $background_num = null) |
|
86 | - { |
|
87 | - // Loading RUN-TIME settings |
|
88 | - foreach(array_keys($this->config) as $key) { |
|
89 | - if(isset(${$key}) && ${$key} !== null) { |
|
90 | - $this->config[$key] = ${$key}; |
|
91 | - } |
|
92 | - } |
|
93 | - $this->config["name"] = $name; |
|
94 | - |
|
95 | - // Skip CAPTCHA for member if set |
|
96 | - if($this->config["skipmember"] && is_object($GLOBALS["xoopsUser"])) { |
|
97 | - $this->active = false; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Verify user submission |
|
103 | - */ |
|
104 | - function verify($skipMember = null) |
|
105 | - { |
|
106 | - $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
107 | - $skipMember = ($skipMember === null) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
108 | - $maxAttempts = intval( @$_SESSION['XoopsCaptcha_maxattempts'] ); |
|
109 | - |
|
110 | - $is_valid = false; |
|
111 | - |
|
112 | - // Skip CAPTCHA for member if set |
|
113 | - if( is_object($GLOBALS["xoopsUser"]) && !empty($skipMember) ) { |
|
114 | - $is_valid = true; |
|
115 | - // Kill too many attempts |
|
116 | - }elseif(!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_'.$sessionName] > $maxAttempts) { |
|
117 | - $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
118 | - |
|
119 | - // Verify the code |
|
120 | - }elseif(!empty($_SESSION['XoopsCaptcha_sessioncode'])){ |
|
121 | - $func = ($this->config["casesensitive"]) ? "strcmp" : "strcasecmp"; |
|
122 | - $is_valid = ! $func( trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
123 | - } |
|
124 | - |
|
125 | - if(!empty($maxAttempts)) { |
|
126 | - if(!$is_valid) { |
|
127 | - // Increase the attempt records on failure |
|
128 | - $_SESSION['XoopsCaptcha_attempt_'.$sessionName]++; |
|
129 | - // Log the error message |
|
130 | - $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
131 | - |
|
132 | - }else{ |
|
133 | - |
|
134 | - // reset attempt records on success |
|
135 | - $_SESSION['XoopsCaptcha_attempt_'.$sessionName] = null; |
|
136 | - } |
|
137 | - } |
|
138 | - $this->destroyGarbage(true); |
|
139 | - |
|
140 | - return $is_valid; |
|
141 | - } |
|
142 | - |
|
143 | - function getCaption() |
|
144 | - { |
|
145 | - return defined("XOOPS_CAPTCHA_CAPTION") ? constant("XOOPS_CAPTCHA_CAPTION") : ""; |
|
146 | - } |
|
147 | - |
|
148 | - function getMessage() |
|
149 | - { |
|
150 | - return implode("<br />", $this->message); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Destory historical stuff |
|
155 | - */ |
|
156 | - function destroyGarbage($clearSession = false) |
|
157 | - { |
|
158 | - require_once dirname(__FILE__)."/".$this->mode.".php"; |
|
159 | - $class = "XoopsCaptcha".ucfirst($this->mode); |
|
160 | - $captcha_handler = new $class(); |
|
161 | - if(method_exists($captcha_handler, "destroyGarbage")) { |
|
162 | - $captcha_handler->loadConfig($this->config); |
|
163 | - $captcha_handler->destroyGarbage(); |
|
164 | - } |
|
165 | - |
|
166 | - if($clearSession) { |
|
167 | - $_SESSION['XoopsCaptcha_name'] = null; |
|
168 | - $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
169 | - $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
170 | - $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
171 | - } |
|
172 | - |
|
173 | - return true; |
|
174 | - } |
|
175 | - |
|
176 | - function render() |
|
177 | - { |
|
178 | - $form = ""; |
|
179 | - |
|
180 | - if( !$this->active || empty($this->config["name"]) ) { |
|
181 | - return $form; |
|
182 | - } |
|
183 | - |
|
184 | - $_SESSION['XoopsCaptcha_name'] = $this->config["name"]; |
|
185 | - $_SESSION['XoopsCaptcha_skipmember'] = $this->config["skipmember"]; |
|
186 | - $maxAttempts = $this->config["maxattempt"]; |
|
187 | - $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
188 | - /* |
|
15 | + var $active = true; |
|
16 | + var $mode = "text"; // potential values: image, text |
|
17 | + var $config = array(); |
|
18 | + |
|
19 | + var $message = array(); // Logging error messages |
|
20 | + |
|
21 | + function XoopsCaptcha() |
|
22 | + { |
|
23 | + // Loading default preferences |
|
24 | + $this->config = @include dirname(__FILE__)."/config.php"; |
|
25 | + |
|
26 | + $this->setMode($this->config["mode"]); |
|
27 | + } |
|
28 | + |
|
29 | + function &instance() |
|
30 | + { |
|
31 | + static $instance; |
|
32 | + if(!isset($instance)) { |
|
33 | + $instance = new XoopsCaptcha(); |
|
34 | + } |
|
35 | + return $instance; |
|
36 | + } |
|
37 | + |
|
38 | + function setConfig($name, $val) |
|
39 | + { |
|
40 | + if($name == "mode") { |
|
41 | + $this->setMode($val); |
|
42 | + }elseif(isset($this->$name)) { |
|
43 | + $this->$name = $val; |
|
44 | + }else { |
|
45 | + $this->config[$name] = $val; |
|
46 | + } |
|
47 | + return true; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Set CAPTCHA mode |
|
52 | + * |
|
53 | + * For future possible modes, right now force to use text or image |
|
54 | + * |
|
55 | + * @param string $mode if no mode is set, just verify current mode |
|
56 | + */ |
|
57 | + function setMode($mode = null) |
|
58 | + { |
|
59 | + if( !empty($mode) && in_array($mode, array("text", "image")) ) { |
|
60 | + $this->mode = $mode; |
|
61 | + |
|
62 | + if($this->mode != "image") { |
|
63 | + return; |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + // Disable image mode |
|
68 | + if(!extension_loaded('gd')) { |
|
69 | + $this->mode = "text"; |
|
70 | + }else{ |
|
71 | + $required_functions = array("imagecreatetruecolor", "imagecolorallocate", "imagefilledrectangle", "imagejpeg", "imagedestroy", "imageftbbox"); |
|
72 | + foreach($required_functions as $func) { |
|
73 | + if(!function_exists($func)) { |
|
74 | + $this->mode = "text"; |
|
75 | + break; |
|
76 | + } |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Initializing the CAPTCHA class |
|
84 | + */ |
|
85 | + function init($name = 'xoopscaptcha', $skipmember = null, $num_chars = null, $fontsize_min = null, $fontsize_max = null, $background_type = null, $background_num = null) |
|
86 | + { |
|
87 | + // Loading RUN-TIME settings |
|
88 | + foreach(array_keys($this->config) as $key) { |
|
89 | + if(isset(${$key}) && ${$key} !== null) { |
|
90 | + $this->config[$key] = ${$key}; |
|
91 | + } |
|
92 | + } |
|
93 | + $this->config["name"] = $name; |
|
94 | + |
|
95 | + // Skip CAPTCHA for member if set |
|
96 | + if($this->config["skipmember"] && is_object($GLOBALS["xoopsUser"])) { |
|
97 | + $this->active = false; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Verify user submission |
|
103 | + */ |
|
104 | + function verify($skipMember = null) |
|
105 | + { |
|
106 | + $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
107 | + $skipMember = ($skipMember === null) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
108 | + $maxAttempts = intval( @$_SESSION['XoopsCaptcha_maxattempts'] ); |
|
109 | + |
|
110 | + $is_valid = false; |
|
111 | + |
|
112 | + // Skip CAPTCHA for member if set |
|
113 | + if( is_object($GLOBALS["xoopsUser"]) && !empty($skipMember) ) { |
|
114 | + $is_valid = true; |
|
115 | + // Kill too many attempts |
|
116 | + }elseif(!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_'.$sessionName] > $maxAttempts) { |
|
117 | + $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
118 | + |
|
119 | + // Verify the code |
|
120 | + }elseif(!empty($_SESSION['XoopsCaptcha_sessioncode'])){ |
|
121 | + $func = ($this->config["casesensitive"]) ? "strcmp" : "strcasecmp"; |
|
122 | + $is_valid = ! $func( trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
123 | + } |
|
124 | + |
|
125 | + if(!empty($maxAttempts)) { |
|
126 | + if(!$is_valid) { |
|
127 | + // Increase the attempt records on failure |
|
128 | + $_SESSION['XoopsCaptcha_attempt_'.$sessionName]++; |
|
129 | + // Log the error message |
|
130 | + $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
131 | + |
|
132 | + }else{ |
|
133 | + |
|
134 | + // reset attempt records on success |
|
135 | + $_SESSION['XoopsCaptcha_attempt_'.$sessionName] = null; |
|
136 | + } |
|
137 | + } |
|
138 | + $this->destroyGarbage(true); |
|
139 | + |
|
140 | + return $is_valid; |
|
141 | + } |
|
142 | + |
|
143 | + function getCaption() |
|
144 | + { |
|
145 | + return defined("XOOPS_CAPTCHA_CAPTION") ? constant("XOOPS_CAPTCHA_CAPTION") : ""; |
|
146 | + } |
|
147 | + |
|
148 | + function getMessage() |
|
149 | + { |
|
150 | + return implode("<br />", $this->message); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Destory historical stuff |
|
155 | + */ |
|
156 | + function destroyGarbage($clearSession = false) |
|
157 | + { |
|
158 | + require_once dirname(__FILE__)."/".$this->mode.".php"; |
|
159 | + $class = "XoopsCaptcha".ucfirst($this->mode); |
|
160 | + $captcha_handler = new $class(); |
|
161 | + if(method_exists($captcha_handler, "destroyGarbage")) { |
|
162 | + $captcha_handler->loadConfig($this->config); |
|
163 | + $captcha_handler->destroyGarbage(); |
|
164 | + } |
|
165 | + |
|
166 | + if($clearSession) { |
|
167 | + $_SESSION['XoopsCaptcha_name'] = null; |
|
168 | + $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
169 | + $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
170 | + $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
171 | + } |
|
172 | + |
|
173 | + return true; |
|
174 | + } |
|
175 | + |
|
176 | + function render() |
|
177 | + { |
|
178 | + $form = ""; |
|
179 | + |
|
180 | + if( !$this->active || empty($this->config["name"]) ) { |
|
181 | + return $form; |
|
182 | + } |
|
183 | + |
|
184 | + $_SESSION['XoopsCaptcha_name'] = $this->config["name"]; |
|
185 | + $_SESSION['XoopsCaptcha_skipmember'] = $this->config["skipmember"]; |
|
186 | + $maxAttempts = $this->config["maxattempt"]; |
|
187 | + $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
188 | + /* |
|
189 | 189 | if(!empty($maxAttempts)) { |
190 | 190 | $_SESSION['XoopsCaptcha_maxattempts_'.$_SESSION['XoopsCaptcha_name']] = $maxAttempts; |
191 | 191 | } |
192 | 192 | */ |
193 | 193 | |
194 | - // Fail on too many attempts |
|
195 | - if(!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_'.$this->config["name"]] > $maxAttempts) { |
|
196 | - $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
197 | - // Load the form element |
|
198 | - }else{ |
|
199 | - $form = $this->loadForm(); |
|
200 | - } |
|
201 | - |
|
202 | - return $form; |
|
203 | - } |
|
204 | - |
|
205 | - function loadForm() |
|
206 | - { |
|
207 | - require_once dirname(__FILE__)."/".$this->mode.".php"; |
|
208 | - $class = "XoopsCaptcha".ucfirst($this->mode); |
|
209 | - $captcha_handler = new $class(); |
|
210 | - $captcha_handler->loadConfig($this->config); |
|
211 | - |
|
212 | - $form = $captcha_handler->render(); |
|
213 | - return $form; |
|
214 | - } |
|
194 | + // Fail on too many attempts |
|
195 | + if(!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_'.$this->config["name"]] > $maxAttempts) { |
|
196 | + $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
197 | + // Load the form element |
|
198 | + }else{ |
|
199 | + $form = $this->loadForm(); |
|
200 | + } |
|
201 | + |
|
202 | + return $form; |
|
203 | + } |
|
204 | + |
|
205 | + function loadForm() |
|
206 | + { |
|
207 | + require_once dirname(__FILE__)."/".$this->mode.".php"; |
|
208 | + $class = "XoopsCaptcha".ucfirst($this->mode); |
|
209 | + $captcha_handler = new $class(); |
|
210 | + $captcha_handler->loadConfig($this->config); |
|
211 | + |
|
212 | + $form = $captcha_handler->render(); |
|
213 | + return $form; |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | ?> |
217 | 217 | \ No newline at end of file |
@@ -1,56 +1,56 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Image Creation class for CAPTCHA |
|
4 | - * |
|
5 | - * D.J. |
|
6 | - */ |
|
3 | + * Image Creation class for CAPTCHA |
|
4 | + * |
|
5 | + * D.J. |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | class XoopsCaptchaImage { |
9 | - var $config = array(); |
|
10 | - |
|
11 | - function XoopsCaptchaImage() |
|
12 | - { |
|
13 | - //$this->name = md5( session_id() ); |
|
14 | - } |
|
15 | - |
|
16 | - function &instance() |
|
17 | - { |
|
18 | - static $instance; |
|
19 | - if(!isset($instance)) { |
|
20 | - $instance = new XoopsCaptchaImage(); |
|
21 | - } |
|
22 | - return $instance; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Loading configs from CAPTCHA class |
|
27 | - */ |
|
28 | - function loadConfig($config = array()) |
|
29 | - { |
|
30 | - // Loading default preferences |
|
31 | - $this->config =& $config; |
|
32 | - } |
|
33 | - |
|
34 | - function render() |
|
35 | - { |
|
36 | - $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(); |
|
37 | - $rule = htmlspecialchars(XOOPS_CAPTCHA_REFRESH, ENT_QUOTES); |
|
38 | - if($this->config["maxattempt"]) { |
|
39 | - $rule .= " | ". sprintf( constant("XOOPS_CAPTCHA_MAXATTEMPTS"), $this->config["maxattempt"] ); |
|
40 | - } |
|
41 | - $form .= " <small>{$rule}</small>"; |
|
42 | - |
|
43 | - return $form; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - function loadImage() |
|
48 | - { |
|
49 | - $rule = $this->config["casesensitive"] ? constant("XOOPS_CAPTCHA_RULE_CASESENSITIVE") : constant("XOOPS_CAPTCHA_RULE_CASEINSENSITIVE"); |
|
50 | - $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)."' />"; |
|
51 | - |
|
52 | - return $ret; |
|
53 | - } |
|
9 | + var $config = array(); |
|
10 | + |
|
11 | + function XoopsCaptchaImage() |
|
12 | + { |
|
13 | + //$this->name = md5( session_id() ); |
|
14 | + } |
|
15 | + |
|
16 | + function &instance() |
|
17 | + { |
|
18 | + static $instance; |
|
19 | + if(!isset($instance)) { |
|
20 | + $instance = new XoopsCaptchaImage(); |
|
21 | + } |
|
22 | + return $instance; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Loading configs from CAPTCHA class |
|
27 | + */ |
|
28 | + function loadConfig($config = array()) |
|
29 | + { |
|
30 | + // Loading default preferences |
|
31 | + $this->config =& $config; |
|
32 | + } |
|
33 | + |
|
34 | + function render() |
|
35 | + { |
|
36 | + $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(); |
|
37 | + $rule = htmlspecialchars(XOOPS_CAPTCHA_REFRESH, ENT_QUOTES); |
|
38 | + if($this->config["maxattempt"]) { |
|
39 | + $rule .= " | ". sprintf( constant("XOOPS_CAPTCHA_MAXATTEMPTS"), $this->config["maxattempt"] ); |
|
40 | + } |
|
41 | + $form .= " <small>{$rule}</small>"; |
|
42 | + |
|
43 | + return $form; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + function loadImage() |
|
48 | + { |
|
49 | + $rule = $this->config["casesensitive"] ? constant("XOOPS_CAPTCHA_RULE_CASESENSITIVE") : constant("XOOPS_CAPTCHA_RULE_CASEINSENSITIVE"); |
|
50 | + $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)."' />"; |
|
51 | + |
|
52 | + return $ret; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | ?> |
57 | 57 | \ No newline at end of file |
@@ -10,174 +10,174 @@ 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 | class XoopsCaptchaImageHandler { |
17 | - var $config = array(); |
|
18 | - //var $mode = "gd"; // GD or bmp |
|
19 | - var $code; |
|
20 | - var $invalid = false; |
|
21 | - |
|
22 | - var $font; |
|
23 | - var $spacing; |
|
24 | - var $width; |
|
25 | - var $height; |
|
26 | - |
|
27 | - function XoopsCaptchaImageHandler() |
|
28 | - { |
|
29 | - if(empty($_SESSION['XoopsCaptcha_name'])) { |
|
30 | - $this->invalid = true; |
|
31 | - } |
|
32 | - |
|
33 | - if(!extension_loaded('gd')) { |
|
34 | - $this->mode = "bmp"; |
|
35 | - }else{ |
|
36 | - $required_functions = array("imagecreatetruecolor", "imagecolorallocate", "imagefilledrectangle", "imagejpeg", "imagedestroy", "imageftbbox"); |
|
37 | - foreach($required_functions as $func) { |
|
38 | - if(!function_exists($func)) { |
|
39 | - $this->mode = "bmp"; |
|
40 | - break; |
|
41 | - } |
|
42 | - } |
|
43 | - } |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Loading configs from CAPTCHA class |
|
48 | - */ |
|
49 | - function setConfig($config = array()) |
|
50 | - { |
|
51 | - // Loading default preferences |
|
52 | - $this->config =& $config; |
|
53 | - } |
|
54 | - |
|
55 | - function loadImage() |
|
56 | - { |
|
57 | - $this->createCode(); |
|
58 | - $this->setCode(); |
|
59 | - $this->createImage(); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Create Code |
|
64 | - */ |
|
65 | - function createCode() |
|
66 | - { |
|
67 | - if($this->invalid) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - if($this->mode == "bmp") { |
|
72 | - $this->config["num_chars"] = 4; |
|
73 | - $this->code = rand( pow(10, $this->config["num_chars"] - 1), intval( str_pad("9", $this->config["num_chars"], "9") ) ); |
|
74 | - }else{ |
|
75 | - $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config["num_chars"] ); |
|
76 | - if (!$this->config["casesensitive"]) { |
|
77 | - $this->code = strtoupper( $this->code ); |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - function setCode() |
|
83 | - { |
|
84 | - if($this->invalid) { |
|
85 | - return; |
|
86 | - } |
|
87 | - |
|
88 | - $_SESSION['XoopsCaptcha_sessioncode'] = strval( $this->code ); |
|
89 | - $maxAttempts = intval( @$_SESSION['XoopsCaptcha_maxattempts'] ); |
|
90 | - |
|
91 | - // Increase the attempt records on refresh |
|
92 | - if(!empty($maxAttempts)) { |
|
93 | - $_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']]++; |
|
94 | - if($_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
95 | - $this->invalid = true; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - function createImage($file = "") |
|
101 | - { |
|
102 | - if($this->invalid) { |
|
103 | - header("Content-type: image/gif"); |
|
104 | - readfile(XOOPS_ROOT_PATH."/images/subject/icon2.gif"); |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - if($this->mode == "bmp") { |
|
109 | - return $this->createImageBmp(); |
|
110 | - }else{ |
|
111 | - return $this->createImageGd(); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Create CAPTCHA iamge with GD |
|
117 | - * Originated from DuGris' SecurityImage |
|
118 | - */ |
|
119 | - // --------------------------------------------------------------------------- // |
|
120 | - // Class : SecurityImage 1.5 // |
|
121 | - // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
122 | - // Email : [email protected] // |
|
123 | - // Licence: GNU // |
|
124 | - // Project: The XOOPS Project // |
|
125 | - // --------------------------------------------------------------------------- // |
|
126 | - function createImageGd($file = "") |
|
127 | - { |
|
128 | - $this->loadFont(); |
|
129 | - $this->setImageSize(); |
|
130 | - |
|
131 | - $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
132 | - $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
133 | - imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
134 | - |
|
135 | - switch ($this->config["background_type"]) { |
|
136 | - default: |
|
137 | - case 0: |
|
138 | - $this->drawBars(); |
|
139 | - break; |
|
140 | - |
|
141 | - case 1: |
|
142 | - $this->drawCircles(); |
|
143 | - break; |
|
144 | - |
|
145 | - case 2: |
|
146 | - $this->drawLines(); |
|
147 | - break; |
|
148 | - |
|
149 | - case 3: |
|
150 | - $this->drawRectangles(); |
|
151 | - break; |
|
152 | - |
|
153 | - case 4: |
|
154 | - $this->drawEllipses(); |
|
155 | - break; |
|
156 | - |
|
157 | - case 5: |
|
158 | - $this->drawPolygons(); |
|
159 | - break; |
|
160 | - |
|
161 | - case 100: |
|
162 | - $this->createFromFile(); |
|
163 | - break; |
|
164 | - } |
|
165 | - $this->drawBorder(); |
|
166 | - $this->drawCode(); |
|
167 | - |
|
168 | - if(empty($file)) { |
|
169 | - header("Content-type: image/jpeg"); |
|
170 | - imagejpeg ($this->oImage); |
|
171 | - }else{ |
|
172 | - imagejpeg ($this->oImage, XOOPS_ROOT_PATH. "/". $this->config["imagepath"]. "/". $file . ".jpg"); |
|
173 | - } |
|
174 | - imagedestroy($this->oImage); |
|
175 | - } |
|
176 | - |
|
177 | - function _getList($name, $extension = "") |
|
178 | - { |
|
179 | - $items = array(); |
|
180 | - /* |
|
17 | + var $config = array(); |
|
18 | + //var $mode = "gd"; // GD or bmp |
|
19 | + var $code; |
|
20 | + var $invalid = false; |
|
21 | + |
|
22 | + var $font; |
|
23 | + var $spacing; |
|
24 | + var $width; |
|
25 | + var $height; |
|
26 | + |
|
27 | + function XoopsCaptchaImageHandler() |
|
28 | + { |
|
29 | + if(empty($_SESSION['XoopsCaptcha_name'])) { |
|
30 | + $this->invalid = true; |
|
31 | + } |
|
32 | + |
|
33 | + if(!extension_loaded('gd')) { |
|
34 | + $this->mode = "bmp"; |
|
35 | + }else{ |
|
36 | + $required_functions = array("imagecreatetruecolor", "imagecolorallocate", "imagefilledrectangle", "imagejpeg", "imagedestroy", "imageftbbox"); |
|
37 | + foreach($required_functions as $func) { |
|
38 | + if(!function_exists($func)) { |
|
39 | + $this->mode = "bmp"; |
|
40 | + break; |
|
41 | + } |
|
42 | + } |
|
43 | + } |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Loading configs from CAPTCHA class |
|
48 | + */ |
|
49 | + function setConfig($config = array()) |
|
50 | + { |
|
51 | + // Loading default preferences |
|
52 | + $this->config =& $config; |
|
53 | + } |
|
54 | + |
|
55 | + function loadImage() |
|
56 | + { |
|
57 | + $this->createCode(); |
|
58 | + $this->setCode(); |
|
59 | + $this->createImage(); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Create Code |
|
64 | + */ |
|
65 | + function createCode() |
|
66 | + { |
|
67 | + if($this->invalid) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + if($this->mode == "bmp") { |
|
72 | + $this->config["num_chars"] = 4; |
|
73 | + $this->code = rand( pow(10, $this->config["num_chars"] - 1), intval( str_pad("9", $this->config["num_chars"], "9") ) ); |
|
74 | + }else{ |
|
75 | + $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config["num_chars"] ); |
|
76 | + if (!$this->config["casesensitive"]) { |
|
77 | + $this->code = strtoupper( $this->code ); |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + function setCode() |
|
83 | + { |
|
84 | + if($this->invalid) { |
|
85 | + return; |
|
86 | + } |
|
87 | + |
|
88 | + $_SESSION['XoopsCaptcha_sessioncode'] = strval( $this->code ); |
|
89 | + $maxAttempts = intval( @$_SESSION['XoopsCaptcha_maxattempts'] ); |
|
90 | + |
|
91 | + // Increase the attempt records on refresh |
|
92 | + if(!empty($maxAttempts)) { |
|
93 | + $_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']]++; |
|
94 | + if($_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
95 | + $this->invalid = true; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + function createImage($file = "") |
|
101 | + { |
|
102 | + if($this->invalid) { |
|
103 | + header("Content-type: image/gif"); |
|
104 | + readfile(XOOPS_ROOT_PATH."/images/subject/icon2.gif"); |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + if($this->mode == "bmp") { |
|
109 | + return $this->createImageBmp(); |
|
110 | + }else{ |
|
111 | + return $this->createImageGd(); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Create CAPTCHA iamge with GD |
|
117 | + * Originated from DuGris' SecurityImage |
|
118 | + */ |
|
119 | + // --------------------------------------------------------------------------- // |
|
120 | + // Class : SecurityImage 1.5 // |
|
121 | + // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
122 | + // Email : [email protected] // |
|
123 | + // Licence: GNU // |
|
124 | + // Project: The XOOPS Project // |
|
125 | + // --------------------------------------------------------------------------- // |
|
126 | + function createImageGd($file = "") |
|
127 | + { |
|
128 | + $this->loadFont(); |
|
129 | + $this->setImageSize(); |
|
130 | + |
|
131 | + $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
132 | + $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
133 | + imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
134 | + |
|
135 | + switch ($this->config["background_type"]) { |
|
136 | + default: |
|
137 | + case 0: |
|
138 | + $this->drawBars(); |
|
139 | + break; |
|
140 | + |
|
141 | + case 1: |
|
142 | + $this->drawCircles(); |
|
143 | + break; |
|
144 | + |
|
145 | + case 2: |
|
146 | + $this->drawLines(); |
|
147 | + break; |
|
148 | + |
|
149 | + case 3: |
|
150 | + $this->drawRectangles(); |
|
151 | + break; |
|
152 | + |
|
153 | + case 4: |
|
154 | + $this->drawEllipses(); |
|
155 | + break; |
|
156 | + |
|
157 | + case 5: |
|
158 | + $this->drawPolygons(); |
|
159 | + break; |
|
160 | + |
|
161 | + case 100: |
|
162 | + $this->createFromFile(); |
|
163 | + break; |
|
164 | + } |
|
165 | + $this->drawBorder(); |
|
166 | + $this->drawCode(); |
|
167 | + |
|
168 | + if(empty($file)) { |
|
169 | + header("Content-type: image/jpeg"); |
|
170 | + imagejpeg ($this->oImage); |
|
171 | + }else{ |
|
172 | + imagejpeg ($this->oImage, XOOPS_ROOT_PATH. "/". $this->config["imagepath"]. "/". $file . ".jpg"); |
|
173 | + } |
|
174 | + imagedestroy($this->oImage); |
|
175 | + } |
|
176 | + |
|
177 | + function _getList($name, $extension = "") |
|
178 | + { |
|
179 | + $items = array(); |
|
180 | + /* |
|
181 | 181 | if(@ include_once XOOPS_ROOT_PATH."/Frameworks/art/functions.ini.php") { |
182 | 182 | load_functions("cache"); |
183 | 183 | if($items = mod_loadCacheFile("captcha_{$name}", "captcha")) { |
@@ -185,227 +185,227 @@ discard block |
||
185 | 185 | } |
186 | 186 | } |
187 | 187 | */ |
188 | - require_once XOOPS_ROOT_PATH."/class/xoopslists.php"; |
|
189 | - $file_path = $this->config["rootpath"]."/{$name}"; |
|
190 | - $files = XoopsLists::getFileListAsArray($file_path); |
|
191 | - foreach( $files as $item) { |
|
192 | - if ( empty($extension) || preg_match("/(\.{$extension})$/i",$item) ) { |
|
193 | - $items[] = $item; |
|
194 | - } |
|
195 | - } |
|
196 | - if(function_exists("mod_createCacheFile")) { |
|
197 | - mod_createCacheFile($items, "captcha_{$name}", "captcha"); |
|
198 | - } |
|
199 | - return $items; |
|
200 | - } |
|
201 | - |
|
202 | - function loadFont() |
|
203 | - { |
|
204 | - $fonts = $this->_getList("fonts", "ttf"); |
|
205 | - $this->font = $this->config["rootpath"]."/fonts/".$fonts[array_rand($fonts)]; |
|
206 | - } |
|
207 | - |
|
208 | - function setImageSize() |
|
209 | - { |
|
210 | - $MaxCharWidth = 0; |
|
211 | - $MaxCharHeight = 0; |
|
212 | - $oImage = imagecreatetruecolor(100, 100); |
|
213 | - $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
214 | - $FontSize = $this->config["fontsize_max"]; |
|
215 | - for ($Angle = -30; $Angle <= 30; $Angle++) { |
|
216 | - for ($i = 65; $i <= 90; $i++) { |
|
217 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), array()); |
|
218 | - $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
219 | - if ($_MaxCharWidth > $MaxCharWidth ) { |
|
220 | - $MaxCharWidth = $_MaxCharWidth; |
|
221 | - } |
|
222 | - $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
223 | - if ($_MaxCharHeight > $MaxCharHeight ) { |
|
224 | - $MaxCharHeight = $_MaxCharHeight; |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - imagedestroy($oImage); |
|
229 | - |
|
230 | - $this->height = $MaxCharHeight + 2; |
|
231 | - $this->spacing = (int)( ($this->config["num_chars"] * $MaxCharWidth) / $this->config["num_chars"]); |
|
232 | - $this->width = ($this->config["num_chars"] * $MaxCharWidth) + ($this->spacing/2); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Return random background |
|
237 | - * |
|
238 | - * @return array |
|
239 | - */ |
|
240 | - function loadBackground() |
|
241 | - { |
|
242 | - $RandBackground = null; |
|
243 | - if( $backgrounds = $this->_getList("backgrounds", "(gif|jpg|png)") ) { |
|
244 | - $RandBackground = $this->config["rootpath"]."/backgrounds/".$backgrounds[array_rand($backgrounds)]; |
|
245 | - } |
|
246 | - return $RandBackground; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Draw Image background |
|
251 | - */ |
|
252 | - function createFromFile() |
|
253 | - { |
|
254 | - if ( $RandImage = $this->loadBackground() ) { |
|
255 | - $ImageType = @getimagesize($RandImage); |
|
256 | - switch ( @$ImageType[2] ) { |
|
257 | - case 1: |
|
258 | - $BackgroundImage = imagecreatefromgif($RandImage); |
|
259 | - break; |
|
260 | - |
|
261 | - case 2: |
|
262 | - $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
263 | - break; |
|
264 | - |
|
265 | - case 3: |
|
266 | - $BackgroundImage = imagecreatefrompng($RandImage); |
|
267 | - break; |
|
268 | - } |
|
269 | - } |
|
270 | - if(!empty($BackgroundImage)){ |
|
271 | - imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
272 | - imagedestroy($BackgroundImage); |
|
273 | - } else { |
|
274 | - $this->drawBars(); |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Draw Code |
|
280 | - */ |
|
281 | - function drawCode() |
|
282 | - { |
|
283 | - for ($i = 0; $i < $this->config["num_chars"] ; $i++) { |
|
284 | - // select random greyscale colour |
|
285 | - $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
286 | - |
|
287 | - // write text to image |
|
288 | - $Angle = mt_rand(10, 30); |
|
289 | - if (($i % 2)) { |
|
290 | - $Angle = mt_rand(-10, -30); |
|
291 | - } |
|
292 | - |
|
293 | - // select random font size |
|
294 | - $FontSize = mt_rand($this->config["fontsize_min"], $this->config["fontsize_max"]); |
|
295 | - |
|
296 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], array()); |
|
297 | - $CharHeight = abs( $CharDetails[1] + $CharDetails[5] ); |
|
298 | - |
|
299 | - // calculate character starting coordinates |
|
300 | - $posX = ($this->spacing/2) + ($i * $this->spacing); |
|
301 | - $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
302 | - |
|
303 | - imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Draw Border |
|
309 | - */ |
|
310 | - function drawBorder() |
|
311 | - { |
|
312 | - $rgb = rand(50, 150); |
|
313 | - $border_color = imagecolorallocate ($this->oImage, $rgb, $rgb, $rgb); |
|
314 | - imagerectangle($this->oImage, 0, 0, $this->width-1, $this->height-1, $border_color); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Draw Circles background |
|
319 | - */ |
|
320 | - function drawCircles() |
|
321 | - { |
|
322 | - for($i = 1; $i <= $this->config["background_num"]; $i++){ |
|
323 | - $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
324 | - imagefilledellipse($this->oImage, mt_rand(0,$this->width-10), mt_rand(0,$this->height-3), mt_rand(10,20), mt_rand(20,30),$randomcolor); |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Draw Lines background |
|
330 | - */ |
|
331 | - function drawLines() |
|
332 | - { |
|
333 | - for ($i = 0; $i < $this->config["background_num"]; $i++) { |
|
334 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
335 | - imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Draw Rectangles background |
|
341 | - */ |
|
342 | - function drawRectangles() |
|
343 | - { |
|
344 | - for ($i = 1; $i <= $this->config["background_num"]; $i++) { |
|
345 | - $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
346 | - imagefilledrectangle($this->oImage, mt_rand(0,$this->width), mt_rand(0,$this->height), mt_rand(0, $this->width), mt_rand(0,$this->height), $randomcolor); |
|
347 | - } |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Draw Bars background |
|
352 | - */ |
|
353 | - function drawBars() |
|
354 | - { |
|
355 | - for ($i= 0 ; $i <= $this->height;) { |
|
356 | - $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
357 | - imageline( $this->oImage, 0, $i, $this->width, $i, $randomcolor ); |
|
358 | - $i = $i + 2.5; |
|
359 | - } |
|
360 | - for ($i = 0;$i <= $this->width;) { |
|
361 | - $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
362 | - imageline( $this->oImage, $i, 0, $i, $this->height, $randomcolor ); |
|
363 | - $i = $i + 2.5; |
|
364 | - } |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Draw Ellipses background |
|
369 | - */ |
|
370 | - function drawEllipses() |
|
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 | - imageellipse($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 polygons background |
|
380 | - */ |
|
381 | - function drawPolygons() |
|
382 | - { |
|
383 | - for($i = 1; $i <= $this->config["background_num"]; $i++){ |
|
384 | - $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
385 | - $coords = array(); |
|
386 | - for ($j=1; $j <= $this->config["polygon_point"]; $j++) { |
|
387 | - $coords[] = mt_rand(0,$this->width); |
|
388 | - $coords[] = mt_rand(0,$this->height); |
|
389 | - } |
|
390 | - imagefilledpolygon($this->oImage, $coords, $this->config["polygon_point"], $randomcolor); |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Create CAPTCHA iamge with BMP |
|
396 | - * TODO |
|
397 | - */ |
|
398 | - function createImageBmp($file = "") |
|
399 | - { |
|
400 | - $image = ""; |
|
401 | - |
|
402 | - if(empty($file)) { |
|
403 | - header("Content-type: image/bmp"); |
|
404 | - echo $image; |
|
405 | - }else{ |
|
406 | - return $image; |
|
407 | - } |
|
408 | - } |
|
188 | + require_once XOOPS_ROOT_PATH."/class/xoopslists.php"; |
|
189 | + $file_path = $this->config["rootpath"]."/{$name}"; |
|
190 | + $files = XoopsLists::getFileListAsArray($file_path); |
|
191 | + foreach( $files as $item) { |
|
192 | + if ( empty($extension) || preg_match("/(\.{$extension})$/i",$item) ) { |
|
193 | + $items[] = $item; |
|
194 | + } |
|
195 | + } |
|
196 | + if(function_exists("mod_createCacheFile")) { |
|
197 | + mod_createCacheFile($items, "captcha_{$name}", "captcha"); |
|
198 | + } |
|
199 | + return $items; |
|
200 | + } |
|
201 | + |
|
202 | + function loadFont() |
|
203 | + { |
|
204 | + $fonts = $this->_getList("fonts", "ttf"); |
|
205 | + $this->font = $this->config["rootpath"]."/fonts/".$fonts[array_rand($fonts)]; |
|
206 | + } |
|
207 | + |
|
208 | + function setImageSize() |
|
209 | + { |
|
210 | + $MaxCharWidth = 0; |
|
211 | + $MaxCharHeight = 0; |
|
212 | + $oImage = imagecreatetruecolor(100, 100); |
|
213 | + $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
214 | + $FontSize = $this->config["fontsize_max"]; |
|
215 | + for ($Angle = -30; $Angle <= 30; $Angle++) { |
|
216 | + for ($i = 65; $i <= 90; $i++) { |
|
217 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), array()); |
|
218 | + $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
219 | + if ($_MaxCharWidth > $MaxCharWidth ) { |
|
220 | + $MaxCharWidth = $_MaxCharWidth; |
|
221 | + } |
|
222 | + $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
223 | + if ($_MaxCharHeight > $MaxCharHeight ) { |
|
224 | + $MaxCharHeight = $_MaxCharHeight; |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + imagedestroy($oImage); |
|
229 | + |
|
230 | + $this->height = $MaxCharHeight + 2; |
|
231 | + $this->spacing = (int)( ($this->config["num_chars"] * $MaxCharWidth) / $this->config["num_chars"]); |
|
232 | + $this->width = ($this->config["num_chars"] * $MaxCharWidth) + ($this->spacing/2); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Return random background |
|
237 | + * |
|
238 | + * @return array |
|
239 | + */ |
|
240 | + function loadBackground() |
|
241 | + { |
|
242 | + $RandBackground = null; |
|
243 | + if( $backgrounds = $this->_getList("backgrounds", "(gif|jpg|png)") ) { |
|
244 | + $RandBackground = $this->config["rootpath"]."/backgrounds/".$backgrounds[array_rand($backgrounds)]; |
|
245 | + } |
|
246 | + return $RandBackground; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Draw Image background |
|
251 | + */ |
|
252 | + function createFromFile() |
|
253 | + { |
|
254 | + if ( $RandImage = $this->loadBackground() ) { |
|
255 | + $ImageType = @getimagesize($RandImage); |
|
256 | + switch ( @$ImageType[2] ) { |
|
257 | + case 1: |
|
258 | + $BackgroundImage = imagecreatefromgif($RandImage); |
|
259 | + break; |
|
260 | + |
|
261 | + case 2: |
|
262 | + $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
263 | + break; |
|
264 | + |
|
265 | + case 3: |
|
266 | + $BackgroundImage = imagecreatefrompng($RandImage); |
|
267 | + break; |
|
268 | + } |
|
269 | + } |
|
270 | + if(!empty($BackgroundImage)){ |
|
271 | + imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
272 | + imagedestroy($BackgroundImage); |
|
273 | + } else { |
|
274 | + $this->drawBars(); |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Draw Code |
|
280 | + */ |
|
281 | + function drawCode() |
|
282 | + { |
|
283 | + for ($i = 0; $i < $this->config["num_chars"] ; $i++) { |
|
284 | + // select random greyscale colour |
|
285 | + $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
286 | + |
|
287 | + // write text to image |
|
288 | + $Angle = mt_rand(10, 30); |
|
289 | + if (($i % 2)) { |
|
290 | + $Angle = mt_rand(-10, -30); |
|
291 | + } |
|
292 | + |
|
293 | + // select random font size |
|
294 | + $FontSize = mt_rand($this->config["fontsize_min"], $this->config["fontsize_max"]); |
|
295 | + |
|
296 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], array()); |
|
297 | + $CharHeight = abs( $CharDetails[1] + $CharDetails[5] ); |
|
298 | + |
|
299 | + // calculate character starting coordinates |
|
300 | + $posX = ($this->spacing/2) + ($i * $this->spacing); |
|
301 | + $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
302 | + |
|
303 | + imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Draw Border |
|
309 | + */ |
|
310 | + function drawBorder() |
|
311 | + { |
|
312 | + $rgb = rand(50, 150); |
|
313 | + $border_color = imagecolorallocate ($this->oImage, $rgb, $rgb, $rgb); |
|
314 | + imagerectangle($this->oImage, 0, 0, $this->width-1, $this->height-1, $border_color); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Draw Circles background |
|
319 | + */ |
|
320 | + function drawCircles() |
|
321 | + { |
|
322 | + for($i = 1; $i <= $this->config["background_num"]; $i++){ |
|
323 | + $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
324 | + imagefilledellipse($this->oImage, mt_rand(0,$this->width-10), mt_rand(0,$this->height-3), mt_rand(10,20), mt_rand(20,30),$randomcolor); |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Draw Lines background |
|
330 | + */ |
|
331 | + function drawLines() |
|
332 | + { |
|
333 | + for ($i = 0; $i < $this->config["background_num"]; $i++) { |
|
334 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
335 | + imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Draw Rectangles background |
|
341 | + */ |
|
342 | + function drawRectangles() |
|
343 | + { |
|
344 | + for ($i = 1; $i <= $this->config["background_num"]; $i++) { |
|
345 | + $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
346 | + imagefilledrectangle($this->oImage, mt_rand(0,$this->width), mt_rand(0,$this->height), mt_rand(0, $this->width), mt_rand(0,$this->height), $randomcolor); |
|
347 | + } |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Draw Bars background |
|
352 | + */ |
|
353 | + function drawBars() |
|
354 | + { |
|
355 | + for ($i= 0 ; $i <= $this->height;) { |
|
356 | + $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
357 | + imageline( $this->oImage, 0, $i, $this->width, $i, $randomcolor ); |
|
358 | + $i = $i + 2.5; |
|
359 | + } |
|
360 | + for ($i = 0;$i <= $this->width;) { |
|
361 | + $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
362 | + imageline( $this->oImage, $i, 0, $i, $this->height, $randomcolor ); |
|
363 | + $i = $i + 2.5; |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Draw Ellipses background |
|
369 | + */ |
|
370 | + function drawEllipses() |
|
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 | + imageellipse($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 polygons background |
|
380 | + */ |
|
381 | + function drawPolygons() |
|
382 | + { |
|
383 | + for($i = 1; $i <= $this->config["background_num"]; $i++){ |
|
384 | + $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190,255), mt_rand(190,255), mt_rand(190,255)); |
|
385 | + $coords = array(); |
|
386 | + for ($j=1; $j <= $this->config["polygon_point"]; $j++) { |
|
387 | + $coords[] = mt_rand(0,$this->width); |
|
388 | + $coords[] = mt_rand(0,$this->height); |
|
389 | + } |
|
390 | + imagefilledpolygon($this->oImage, $coords, $this->config["polygon_point"], $randomcolor); |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Create CAPTCHA iamge with BMP |
|
396 | + * TODO |
|
397 | + */ |
|
398 | + function createImageBmp($file = "") |
|
399 | + { |
|
400 | + $image = ""; |
|
401 | + |
|
402 | + if(empty($file)) { |
|
403 | + header("Content-type: image/bmp"); |
|
404 | + echo $image; |
|
405 | + }else{ |
|
406 | + return $image; |
|
407 | + } |
|
408 | + } |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | $config = @include "../config.php"; |