Completed
Push — master ( bf34f3...88111b )
by Michael
03:08
created
class/Common/Breadcrumb.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -31,48 +31,48 @@
 block discarded – undo
31 31
  */
32 32
 class Breadcrumb
33 33
 {
34
-    public $dirname;
35
-    private $bread = [];
34
+	public $dirname;
35
+	private $bread = [];
36 36
 
37
-    /**
38
-     *
39
-     */
40
-    public function __construct()
41
-    {
42
-        $this->dirname = basename(dirname(__DIR__));
43
-    }
37
+	/**
38
+	 *
39
+	 */
40
+	public function __construct()
41
+	{
42
+		$this->dirname = basename(dirname(__DIR__));
43
+	}
44 44
 
45
-    /**
46
-     * Add link to breadcrumb
47
-     *
48
-     * @param string $title
49
-     * @param string $link
50
-     */
51
-    public function addLink($title = '', $link = '')
52
-    {
53
-        $this->bread[] = [
54
-            'link'  => $link,
55
-            'title' => $title
56
-        ];
57
-    }
45
+	/**
46
+	 * Add link to breadcrumb
47
+	 *
48
+	 * @param string $title
49
+	 * @param string $link
50
+	 */
51
+	public function addLink($title = '', $link = '')
52
+	{
53
+		$this->bread[] = [
54
+			'link'  => $link,
55
+			'title' => $title
56
+		];
57
+	}
58 58
 
59
-    /**
60
-     * Render Pedigree BreadCrumb
61
-     *
62
-     */
63
-    public function render()
64
-    {
65
-        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
66
-            require_once $GLOBALS['xoops']->path('class/theme.php');
67
-            $GLOBALS['xoTheme'] = new \xos_opal_Theme();
68
-        }
59
+	/**
60
+	 * Render Pedigree BreadCrumb
61
+	 *
62
+	 */
63
+	public function render()
64
+	{
65
+		if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
66
+			require_once $GLOBALS['xoops']->path('class/theme.php');
67
+			$GLOBALS['xoTheme'] = new \xos_opal_Theme();
68
+		}
69 69
 
70
-        require_once $GLOBALS['xoops']->path('class/template.php');
71
-        $breadcrumbTpl = new \XoopsTpl();
72
-        $breadcrumbTpl->assign('breadcrumb', $this->bread);
73
-        $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
74
-        unset($breadcrumbTpl);
70
+		require_once $GLOBALS['xoops']->path('class/template.php');
71
+		$breadcrumbTpl = new \XoopsTpl();
72
+		$breadcrumbTpl->assign('breadcrumb', $this->bread);
73
+		$html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
74
+		unset($breadcrumbTpl);
75 75
 
76
-        return $html;
77
-    }
76
+		return $html;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
         require_once $GLOBALS['xoops']->path('class/template.php');
71 71
         $breadcrumbTpl = new \XoopsTpl();
72 72
         $breadcrumbTpl->assign('breadcrumb', $this->bread);
73
-        $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
73
+        $html = $breadcrumbTpl->fetch('db:'.$this->dirname.'_common_breadcrumb.tpl');
74 74
         unset($breadcrumbTpl);
75 75
 
76 76
         return $html;
Please login to merge, or discard this patch.
class/Common/FilesManagement.php 2 patches
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -17,229 +17,229 @@
 block discarded – undo
17 17
  */
18 18
 trait FilesManagement
19 19
 {
20
-    /**
21
-     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
22
-     *
23
-     * @param string $folder The full path of the directory to check
24
-     *
25
-     * @return void
26
-     * @throws \RuntimeException
27
-     */
28
-    public static function createFolder($folder)
29
-    {
30
-        try {
31
-            if (!file_exists($folder)) {
32
-                if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) {
33
-                    throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
34
-                }
35
-
36
-                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
37
-            }
38
-        } catch (\Exception $e) {
39
-            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
40
-        }
41
-    }
42
-
43
-    /**
44
-     * @param $file
45
-     * @param $folder
46
-     * @return bool
47
-     */
48
-    public static function copyFile($file, $folder)
49
-    {
50
-        return copy($file, $folder);
51
-    }
52
-
53
-    /**
54
-     * @param $src
55
-     * @param $dst
56
-     */
57
-    public static function recurseCopy($src, $dst)
58
-    {
59
-        $dir = opendir($src);
60
-        //        @mkdir($dst);
61
-        if (!mkdir($dst) && !is_dir($dst)) {
62
-            while (false !== ($file = readdir($dir))) {
63
-                if (('.' !== $file) && ('..' !== $file)) {
64
-                    if (is_dir($src . '/' . $file)) {
65
-                        self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
66
-                    } else {
67
-                        copy($src . '/' . $file, $dst . '/' . $file);
68
-                    }
69
-                }
70
-            }
71
-        }
72
-        closedir($dir);
73
-    }
74
-
75
-    /**
76
-     *
77
-     * Remove files and (sub)directories
78
-     *
79
-     * @param string $src source directory to delete
80
-     *
81
-     * @uses \Xmf\Module\Helper::getHelper()
82
-     * @uses \Xmf\Module\Helper::isUserAdmin()
83
-     *
84
-     * @return bool true on success
85
-     */
86
-    public static function deleteDirectory($src)
87
-    {
88
-        // Only continue if user is a 'global' Admin
89
-        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
90
-            return false;
91
-        }
92
-
93
-        $success = true;
94
-        // remove old files
95
-        $dirInfo = new \SplFileInfo($src);
96
-        // validate is a directory
97
-        if ($dirInfo->isDir()) {
98
-            $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']);
99
-            foreach ($fileList as $k => $v) {
100
-                $fileInfo = new \SplFileInfo("{$src}/{$v}");
101
-                if ($fileInfo->isDir()) {
102
-                    // recursively handle subdirectories
103
-                    if (!$success = self::deleteDirectory($fileInfo->getRealPath())) {
104
-                        break;
105
-                    }
106
-                } else {
107
-                    // delete the file
108
-                    if (!($success = unlink($fileInfo->getRealPath()))) {
109
-                        break;
110
-                    }
111
-                }
112
-            }
113
-            // now delete this (sub)directory if all the files are gone
114
-            if ($success) {
115
-                $success = rmdir($dirInfo->getRealPath());
116
-            }
117
-        } else {
118
-            // input is not a valid directory
119
-            $success = false;
120
-        }
121
-        return $success;
122
-    }
123
-
124
-    /**
125
-     *
126
-     * Recursively remove directory
127
-     *
128
-     * @todo currently won't remove directories with hidden files, should it?
129
-     *
130
-     * @param string $src directory to remove (delete)
131
-     *
132
-     * @return bool true on success
133
-     */
134
-    public static function rrmdir($src)
135
-    {
136
-        // Only continue if user is a 'global' Admin
137
-        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
138
-            return false;
139
-        }
140
-
141
-        // If source is not a directory stop processing
142
-        if (!is_dir($src)) {
143
-            return false;
144
-        }
145
-
146
-        $success = true;
147
-
148
-        // Open the source directory to read in files
149
-        $iterator = new \DirectoryIterator($src);
150
-        foreach ($iterator as $fObj) {
151
-            if ($fObj->isFile()) {
152
-                $filename = $fObj->getPathname();
153
-                $fObj     = null; // clear this iterator object to close the file
154
-                if (!unlink($filename)) {
155
-                    return false; // couldn't delete the file
156
-                }
157
-            } elseif (!$fObj->isDot() && $fObj->isDir()) {
158
-                // Try recursively on directory
159
-                self::rrmdir($fObj->getPathname());
160
-            }
161
-        }
162
-        $iterator = null;   // clear iterator Obj to close file/directory
163
-        return rmdir($src); // remove the directory & return results
164
-    }
165
-
166
-    /**
167
-     * Recursively move files from one directory to another
168
-     *
169
-     * @param string $src  - Source of files being moved
170
-     * @param string $dest - Destination of files being moved
171
-     *
172
-     * @return bool true on success
173
-     */
174
-    public static function rmove($src, $dest)
175
-    {
176
-        // Only continue if user is a 'global' Admin
177
-        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
178
-            return false;
179
-        }
180
-
181
-        // If source is not a directory stop processing
182
-        if (!is_dir($src)) {
183
-            return false;
184
-        }
185
-
186
-        // If the destination directory does not exist and could not be created stop processing
187
-        if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) {
188
-            return false;
189
-        }
190
-
191
-        // Open the source directory to read in files
192
-        $iterator = new \DirectoryIterator($src);
193
-        foreach ($iterator as $fObj) {
194
-            if ($fObj->isFile()) {
195
-                rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
196
-            } elseif (!$fObj->isDot() && $fObj->isDir()) {
197
-                // Try recursively on directory
198
-                self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
199
-                //                rmdir($fObj->getPath()); // now delete the directory
200
-            }
201
-        }
202
-        $iterator = null;   // clear iterator Obj to close file/directory
203
-        return rmdir($src); // remove the directory & return results
204
-    }
205
-
206
-    /**
207
-     * Recursively copy directories and files from one directory to another
208
-     *
209
-     * @param string $src  - Source of files being moved
210
-     * @param string $dest - Destination of files being moved
211
-     *
212
-     * @uses \Xmf\Module\Helper::getHelper()
213
-     * @uses \Xmf\Module\Helper::isUserAdmin()
214
-     *
215
-     * @return bool true on success
216
-     */
217
-    public static function rcopy($src, $dest)
218
-    {
219
-        // Only continue if user is a 'global' Admin
220
-        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
221
-            return false;
222
-        }
223
-
224
-        // If source is not a directory stop processing
225
-        if (!is_dir($src)) {
226
-            return false;
227
-        }
228
-
229
-        // If the destination directory does not exist and could not be created stop processing
230
-        if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) {
231
-            return false;
232
-        }
233
-
234
-        // Open the source directory to read in files
235
-        $iterator = new \DirectoryIterator($src);
236
-        foreach ($iterator as $fObj) {
237
-            if ($fObj->isFile()) {
238
-                copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
239
-            } elseif (!$fObj->isDot() && $fObj->isDir()) {
240
-                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
241
-            }
242
-        }
243
-        return true;
244
-    }
20
+	/**
21
+	 * Function responsible for checking if a directory exists, we can also write in and create an index.html file
22
+	 *
23
+	 * @param string $folder The full path of the directory to check
24
+	 *
25
+	 * @return void
26
+	 * @throws \RuntimeException
27
+	 */
28
+	public static function createFolder($folder)
29
+	{
30
+		try {
31
+			if (!file_exists($folder)) {
32
+				if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) {
33
+					throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
34
+				}
35
+
36
+				file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
37
+			}
38
+		} catch (\Exception $e) {
39
+			echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
40
+		}
41
+	}
42
+
43
+	/**
44
+	 * @param $file
45
+	 * @param $folder
46
+	 * @return bool
47
+	 */
48
+	public static function copyFile($file, $folder)
49
+	{
50
+		return copy($file, $folder);
51
+	}
52
+
53
+	/**
54
+	 * @param $src
55
+	 * @param $dst
56
+	 */
57
+	public static function recurseCopy($src, $dst)
58
+	{
59
+		$dir = opendir($src);
60
+		//        @mkdir($dst);
61
+		if (!mkdir($dst) && !is_dir($dst)) {
62
+			while (false !== ($file = readdir($dir))) {
63
+				if (('.' !== $file) && ('..' !== $file)) {
64
+					if (is_dir($src . '/' . $file)) {
65
+						self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
66
+					} else {
67
+						copy($src . '/' . $file, $dst . '/' . $file);
68
+					}
69
+				}
70
+			}
71
+		}
72
+		closedir($dir);
73
+	}
74
+
75
+	/**
76
+	 *
77
+	 * Remove files and (sub)directories
78
+	 *
79
+	 * @param string $src source directory to delete
80
+	 *
81
+	 * @uses \Xmf\Module\Helper::getHelper()
82
+	 * @uses \Xmf\Module\Helper::isUserAdmin()
83
+	 *
84
+	 * @return bool true on success
85
+	 */
86
+	public static function deleteDirectory($src)
87
+	{
88
+		// Only continue if user is a 'global' Admin
89
+		if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
90
+			return false;
91
+		}
92
+
93
+		$success = true;
94
+		// remove old files
95
+		$dirInfo = new \SplFileInfo($src);
96
+		// validate is a directory
97
+		if ($dirInfo->isDir()) {
98
+			$fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']);
99
+			foreach ($fileList as $k => $v) {
100
+				$fileInfo = new \SplFileInfo("{$src}/{$v}");
101
+				if ($fileInfo->isDir()) {
102
+					// recursively handle subdirectories
103
+					if (!$success = self::deleteDirectory($fileInfo->getRealPath())) {
104
+						break;
105
+					}
106
+				} else {
107
+					// delete the file
108
+					if (!($success = unlink($fileInfo->getRealPath()))) {
109
+						break;
110
+					}
111
+				}
112
+			}
113
+			// now delete this (sub)directory if all the files are gone
114
+			if ($success) {
115
+				$success = rmdir($dirInfo->getRealPath());
116
+			}
117
+		} else {
118
+			// input is not a valid directory
119
+			$success = false;
120
+		}
121
+		return $success;
122
+	}
123
+
124
+	/**
125
+	 *
126
+	 * Recursively remove directory
127
+	 *
128
+	 * @todo currently won't remove directories with hidden files, should it?
129
+	 *
130
+	 * @param string $src directory to remove (delete)
131
+	 *
132
+	 * @return bool true on success
133
+	 */
134
+	public static function rrmdir($src)
135
+	{
136
+		// Only continue if user is a 'global' Admin
137
+		if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
138
+			return false;
139
+		}
140
+
141
+		// If source is not a directory stop processing
142
+		if (!is_dir($src)) {
143
+			return false;
144
+		}
145
+
146
+		$success = true;
147
+
148
+		// Open the source directory to read in files
149
+		$iterator = new \DirectoryIterator($src);
150
+		foreach ($iterator as $fObj) {
151
+			if ($fObj->isFile()) {
152
+				$filename = $fObj->getPathname();
153
+				$fObj     = null; // clear this iterator object to close the file
154
+				if (!unlink($filename)) {
155
+					return false; // couldn't delete the file
156
+				}
157
+			} elseif (!$fObj->isDot() && $fObj->isDir()) {
158
+				// Try recursively on directory
159
+				self::rrmdir($fObj->getPathname());
160
+			}
161
+		}
162
+		$iterator = null;   // clear iterator Obj to close file/directory
163
+		return rmdir($src); // remove the directory & return results
164
+	}
165
+
166
+	/**
167
+	 * Recursively move files from one directory to another
168
+	 *
169
+	 * @param string $src  - Source of files being moved
170
+	 * @param string $dest - Destination of files being moved
171
+	 *
172
+	 * @return bool true on success
173
+	 */
174
+	public static function rmove($src, $dest)
175
+	{
176
+		// Only continue if user is a 'global' Admin
177
+		if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
178
+			return false;
179
+		}
180
+
181
+		// If source is not a directory stop processing
182
+		if (!is_dir($src)) {
183
+			return false;
184
+		}
185
+
186
+		// If the destination directory does not exist and could not be created stop processing
187
+		if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) {
188
+			return false;
189
+		}
190
+
191
+		// Open the source directory to read in files
192
+		$iterator = new \DirectoryIterator($src);
193
+		foreach ($iterator as $fObj) {
194
+			if ($fObj->isFile()) {
195
+				rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
196
+			} elseif (!$fObj->isDot() && $fObj->isDir()) {
197
+				// Try recursively on directory
198
+				self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
199
+				//                rmdir($fObj->getPath()); // now delete the directory
200
+			}
201
+		}
202
+		$iterator = null;   // clear iterator Obj to close file/directory
203
+		return rmdir($src); // remove the directory & return results
204
+	}
205
+
206
+	/**
207
+	 * Recursively copy directories and files from one directory to another
208
+	 *
209
+	 * @param string $src  - Source of files being moved
210
+	 * @param string $dest - Destination of files being moved
211
+	 *
212
+	 * @uses \Xmf\Module\Helper::getHelper()
213
+	 * @uses \Xmf\Module\Helper::isUserAdmin()
214
+	 *
215
+	 * @return bool true on success
216
+	 */
217
+	public static function rcopy($src, $dest)
218
+	{
219
+		// Only continue if user is a 'global' Admin
220
+		if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
221
+			return false;
222
+		}
223
+
224
+		// If source is not a directory stop processing
225
+		if (!is_dir($src)) {
226
+			return false;
227
+		}
228
+
229
+		// If the destination directory does not exist and could not be created stop processing
230
+		if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) {
231
+			return false;
232
+		}
233
+
234
+		// Open the source directory to read in files
235
+		$iterator = new \DirectoryIterator($src);
236
+		foreach ($iterator as $fObj) {
237
+			if ($fObj->isFile()) {
238
+				copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
239
+			} elseif (!$fObj->isDot() && $fObj->isDir()) {
240
+				self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
241
+			}
242
+		}
243
+		return true;
244
+	}
245 245
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
                     throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
34 34
                 }
35 35
 
36
-                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
36
+                file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>');
37 37
             }
38 38
         } catch (\Exception $e) {
39 39
             echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
         if (!mkdir($dst) && !is_dir($dst)) {
62 62
             while (false !== ($file = readdir($dir))) {
63 63
                 if (('.' !== $file) && ('..' !== $file)) {
64
-                    if (is_dir($src . '/' . $file)) {
65
-                        self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
64
+                    if (is_dir($src.'/'.$file)) {
65
+                        self::recurseCopy($src.'/'.$file, $dst.'/'.$file);
66 66
                     } else {
67
-                        copy($src . '/' . $file, $dst . '/' . $file);
67
+                        copy($src.'/'.$file, $dst.'/'.$file);
68 68
                     }
69 69
                 }
70 70
             }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                 self::rrmdir($fObj->getPathname());
160 160
             }
161 161
         }
162
-        $iterator = null;   // clear iterator Obj to close file/directory
162
+        $iterator = null; // clear iterator Obj to close file/directory
163 163
         return rmdir($src); // remove the directory & return results
164 164
     }
165 165
 
@@ -192,14 +192,14 @@  discard block
 block discarded – undo
192 192
         $iterator = new \DirectoryIterator($src);
193 193
         foreach ($iterator as $fObj) {
194 194
             if ($fObj->isFile()) {
195
-                rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
195
+                rename($fObj->getPathname(), "{$dest}/".$fObj->getFilename());
196 196
             } elseif (!$fObj->isDot() && $fObj->isDir()) {
197 197
                 // Try recursively on directory
198
-                self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
198
+                self::rmove($fObj->getPathname(), "{$dest}/".$fObj->getFilename());
199 199
                 //                rmdir($fObj->getPath()); // now delete the directory
200 200
             }
201 201
         }
202
-        $iterator = null;   // clear iterator Obj to close file/directory
202
+        $iterator = null; // clear iterator Obj to close file/directory
203 203
         return rmdir($src); // remove the directory & return results
204 204
     }
205 205
 
@@ -235,9 +235,9 @@  discard block
 block discarded – undo
235 235
         $iterator = new \DirectoryIterator($src);
236 236
         foreach ($iterator as $fObj) {
237 237
             if ($fObj->isFile()) {
238
-                copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
238
+                copy($fObj->getPathname(), "{$dest}/".$fObj->getFilename());
239 239
             } elseif (!$fObj->isDot() && $fObj->isDir()) {
240
-                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
240
+                self::rcopy($fObj->getPathname(), "{$dest}/".$fObj->getFilename());
241 241
             }
242 242
         }
243 243
         return true;
Please login to merge, or discard this patch.
class/SmartobjectCategoryHandler.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -21,91 +21,91 @@
 block discarded – undo
21 21
  */
22 22
 class SmartobjectCategoryHandler extends Smartobject\SmartPersistableObjectHandler
23 23
 {
24
-    public $allCategoriesObj = false;
25
-    public $_allCategoriesId = false;
26
-
27
-    /**
28
-     * SmartobjectCategoryHandler constructor.
29
-     * @param \XoopsDatabase       $db
30
-     * @param                      $modulename
31
-     */
32
-    public function __construct(\XoopsDatabase $db, $modulename)
33
-    {
34
-        parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename);
35
-    }
36
-
37
-    /**
38
-     * @param  int    $parentid
39
-     * @param  bool   $perm_name
40
-     * @param  string $sort
41
-     * @param  string $order
42
-     * @return array|bool
43
-     */
44
-    public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC')
45
-    {
46
-        if (!$this->allCategoriesObj) {
47
-            $criteria = new \CriteriaCompo();
48
-            $criteria->setSort($sort);
49
-            $criteria->setOrder($order);
50
-            global $xoopsUser;
51
-            $userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin();
52
-
53
-            if ($perm_name && !$userIsAdmin) {
54
-                if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) {
55
-                    return false;
56
-                }
57
-            }
58
-
59
-            $this->allCategoriesObj =& $this->getObjects($criteria, 'parentid');
60
-        }
61
-
62
-        $ret = [];
63
-        if (isset($this->allCategoriesObj[$parentid])) {
64
-            foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) {
65
-                $ret[$categoryid]['self'] = $categoryObj->toArray();
66
-                if (isset($this->allCategoriesObj[$categoryid])) {
67
-                    $ret[$categoryid]['sub']          = $this->getAllCategoriesArray($categoryid);
68
-                    $ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']);
69
-                }
70
-            }
71
-        }
72
-
73
-        return $ret;
74
-    }
75
-
76
-    /**
77
-     * @param               $parentid
78
-     * @param  bool         $asString
79
-     * @return array|string
80
-     */
81
-    public function getParentIds($parentid, $asString = true)
82
-    {
83
-        if (!$this->allCategoriesId) {
84
-            $ret = [];
85
-            $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid';
86
-
87
-            $result = $this->db->query($sql);
88
-
89
-            if (!$result) {
90
-                return $ret;
91
-            }
92
-
93
-            while (false !== ($myrow = $this->db->fetchArray($result))) {
94
-                $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid'];
95
-            }
96
-        }
97
-
98
-        $retArray = [$parentid];
99
-        while (0 != $parentid) {
100
-            $parentid = $this->allCategoriesId[$parentid];
101
-            if (0 != $parentid) {
102
-                $retArray[] = $parentid;
103
-            }
104
-        }
105
-        if ($asString) {
106
-            return implode(', ', $retArray);
107
-        } else {
108
-            return $retArray;
109
-        }
110
-    }
24
+	public $allCategoriesObj = false;
25
+	public $_allCategoriesId = false;
26
+
27
+	/**
28
+	 * SmartobjectCategoryHandler constructor.
29
+	 * @param \XoopsDatabase       $db
30
+	 * @param                      $modulename
31
+	 */
32
+	public function __construct(\XoopsDatabase $db, $modulename)
33
+	{
34
+		parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename);
35
+	}
36
+
37
+	/**
38
+	 * @param  int    $parentid
39
+	 * @param  bool   $perm_name
40
+	 * @param  string $sort
41
+	 * @param  string $order
42
+	 * @return array|bool
43
+	 */
44
+	public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC')
45
+	{
46
+		if (!$this->allCategoriesObj) {
47
+			$criteria = new \CriteriaCompo();
48
+			$criteria->setSort($sort);
49
+			$criteria->setOrder($order);
50
+			global $xoopsUser;
51
+			$userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin();
52
+
53
+			if ($perm_name && !$userIsAdmin) {
54
+				if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) {
55
+					return false;
56
+				}
57
+			}
58
+
59
+			$this->allCategoriesObj =& $this->getObjects($criteria, 'parentid');
60
+		}
61
+
62
+		$ret = [];
63
+		if (isset($this->allCategoriesObj[$parentid])) {
64
+			foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) {
65
+				$ret[$categoryid]['self'] = $categoryObj->toArray();
66
+				if (isset($this->allCategoriesObj[$categoryid])) {
67
+					$ret[$categoryid]['sub']          = $this->getAllCategoriesArray($categoryid);
68
+					$ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']);
69
+				}
70
+			}
71
+		}
72
+
73
+		return $ret;
74
+	}
75
+
76
+	/**
77
+	 * @param               $parentid
78
+	 * @param  bool         $asString
79
+	 * @return array|string
80
+	 */
81
+	public function getParentIds($parentid, $asString = true)
82
+	{
83
+		if (!$this->allCategoriesId) {
84
+			$ret = [];
85
+			$sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid';
86
+
87
+			$result = $this->db->query($sql);
88
+
89
+			if (!$result) {
90
+				return $ret;
91
+			}
92
+
93
+			while (false !== ($myrow = $this->db->fetchArray($result))) {
94
+				$this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid'];
95
+			}
96
+		}
97
+
98
+		$retArray = [$parentid];
99
+		while (0 != $parentid) {
100
+			$parentid = $this->allCategoriesId[$parentid];
101
+			if (0 != $parentid) {
102
+				$retArray[] = $parentid;
103
+			}
104
+		}
105
+		if ($asString) {
106
+			return implode(', ', $retArray);
107
+		} else {
108
+			return $retArray;
109
+		}
110
+	}
111 111
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
                 }
57 57
             }
58 58
 
59
-            $this->allCategoriesObj =& $this->getObjects($criteria, 'parentid');
59
+            $this->allCategoriesObj = & $this->getObjects($criteria, 'parentid');
60 60
         }
61 61
 
62 62
         $ret = [];
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     {
83 83
         if (!$this->allCategoriesId) {
84 84
             $ret = [];
85
-            $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid';
85
+            $sql = 'SELECT categoryid, parentid FROM '.$this->table.' AS '.$this->_itemname.' ORDER BY parentid';
86 86
 
87 87
             $result = $this->db->query($sql);
88 88
 
Please login to merge, or discard this patch.
print.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@
 block discarded – undo
6 6
  * Licence: GNU
7 7
  */
8 8
 
9
-require_once __DIR__ . '/header.php';
10
-require_once SMARTOBJECT_ROOT_PATH . 'class/smartloader.php';
11
-require_once XOOPS_ROOT_PATH . '/class/template.php';
9
+require_once __DIR__.'/header.php';
10
+require_once SMARTOBJECT_ROOT_PATH.'class/smartloader.php';
11
+require_once XOOPS_ROOT_PATH.'/class/template.php';
12 12
 
13 13
 $xoopsTpl                = new \XoopsTpl();
14 14
 $myts                    = \MyTextSanitizer::getInstance();
Please login to merge, or discard this patch.
include/projax_/classes/Prototype.php 1 patch
Indentation   +448 added lines, -448 removed lines patch added patch discarded remove patch
@@ -15,452 +15,452 @@
 block discarded – undo
15 15
  */
16 16
 class Prototype extends JavaScript
17 17
 {
18
-    public $CALLBACKS = [
19
-        'uninitialized',
20
-        'loading',
21
-        'loaded',
22
-        'interactive',
23
-        'complete',
24
-        'failure',
25
-        'success'
26
-    ];
27
-
28
-    public $AJAX_OPTIONS = [
29
-        'before',
30
-        'after',
31
-        'condition',
32
-        'url',
33
-        'asynchronous',
34
-        'method',
35
-        'insertion',
36
-        'position',
37
-        'form',
38
-        'with',
39
-        'update',
40
-        'script',
41
-        'uninitialized',
42
-        'loading',
43
-        'loaded',
44
-        'interactive',
45
-        'complete',
46
-        'failure',
47
-        'success'
48
-    ];
49
-
50
-    /**
51
-     * @return string
52
-     */
53
-    public function evaluate_remote_response()
54
-    {
55
-        return 'eval(request.responseText)';
56
-    }
57
-
58
-    /**
59
-     * @param $options
60
-     * @return string
61
-     */
62
-    public function form_remote_tag($options)
63
-    {
64
-        $options['form'] = true;
65
-
66
-        return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
67
-    }
68
-
69
-    /**
70
-     * @param         $name
71
-     * @param  null   $options
72
-     * @param  null   $html_options
73
-     * @return string
74
-     */
75
-    public function link_to_remote($name, $options = null, $html_options = null)
76
-    {
77
-        return $this->link_to_function($name, $this->remote_function($options), $html_options);
78
-    }
79
-
80
-    /**
81
-     * @param         $field_id
82
-     * @param  null   $options
83
-     * @return string
84
-     */
85
-    public function observe_field($field_id, $options = null)
86
-    {
87
-        if (isset($options['frequency']) && $options['frequency'] > 0) {
88
-            return $this->_build_observer('Form.Element.Observer', $field_id, $options);
89
-        } else {
90
-            return $this->_build_observer('Form.Element.EventObserver', $field_id, $options);
91
-        }
92
-    }
93
-
94
-    /**
95
-     * @param         $form_id
96
-     * @param  null   $options
97
-     * @return string
98
-     */
99
-    public function observe_form($form_id, $options = null)
100
-    {
101
-        if (isset($options['frequency'])) {
102
-            return $this->_build_observer('Form.Observer', $form_id, $options);
103
-        } else {
104
-            return $this->_build_observer('Form.EventObserver', $form_id, $options);
105
-        }
106
-    }
107
-
108
-    /**
109
-     * @param  null $options
110
-     * @return string
111
-     */
112
-    public function periodically_call_remote($options = null)
113
-    {
114
-        $frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
-        $code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
116
-
117
-        return $code;
118
-    }
119
-
120
-    /**
121
-     * @param $options
122
-     * @return string
123
-     */
124
-    public function remote_function($options)
125
-    {
126
-        $javascript_options = $this->_options_for_ajax($options);
127
-
128
-        $update = '';
129
-
130
-        if (isset($options['update']) && is_array($options['update'])) {
131
-            $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
132
-            $update .= empty($update) ? '' : ',';
133
-            $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
134
-        } else {
135
-            $update .= isset($options['update']) ? $options['update'] : '';
136
-        }
137
-
138
-        $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
139
-
140
-        $ajax_function .= "'" . $options['url'] . "'";
141
-        $ajax_function .= ',' . $javascript_options . ')';
142
-
143
-        $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
-        $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
-        $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
-        $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
147
-
148
-        return $ajax_function;
149
-    }
150
-
151
-    /**
152
-     * @param $name
153
-     * @param $value
154
-     * @param $options
155
-     * @return string
156
-     */
157
-    public function submit_to_remote($name, $value, $options)
158
-    {
159
-        if (isset($options['with'])) {
160
-            $options['with'] = 'Form.serialize(this.form)';
161
-        }
162
-
163
-        return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
164
-    }
165
-
166
-    /**
167
-     * @param      $element_id
168
-     * @param null $options
169
-     * @param      $block
170
-     */
171
-    public function update_element_function($element_id, $options = null, $block)
172
-    {
173
-        $content = isset($options['content']) ? $options['content'] : '';
174
-        $content = $this->escape($content);
175
-    }
176
-
177
-    /**
178
-     * @param $block
179
-     */
180
-    public function update_page($block)
181
-    {
182
-    }
183
-
184
-    /**
185
-     * @param $block
186
-     * @return string
187
-     */
188
-    public function update_page_tag(& $block)
189
-    {
190
-        return $this->tag($block);
191
-    }
192
-
193
-    /////////////////////////////////////////////////////////////////////////////////////
194
-    //                             Private functions
195
-    /////////////////////////////////////////////////////////////////////////////////////
196
-
197
-    /**
198
-     * @param $options
199
-     * @return array
200
-     */
201
-    public function _build_callbacks($options)
202
-    {
203
-        $callbacks = [];
204
-        foreach ($options as $callback => $code) {
205
-            if (in_array($callback, $this->CALLBACKS)) {
206
-                $name             = 'on' . ucfirst($callback);
207
-                $callbacks[$name] = 'function(request){' . $code . '}';
208
-            }
209
-        }
210
-
211
-        return $callbacks;
212
-    }
213
-
214
-    /**
215
-     * @param         $klass
216
-     * @param         $name
217
-     * @param  null   $options
218
-     * @return string
219
-     */
220
-    public function _build_observer($klass, $name, $options = null)
221
-    {
222
-        if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
-            $options['with'] = '\'' . $options['with'] . '=\' + value';
224
-        } elseif (isset($options['with']) && isset($options['update'])) {
225
-            $options['with'] = 'value';
226
-        }
227
-
228
-        $callback = $options['function'] ?: $this->remote_function($options);
229
-
230
-        $javascript = "new $klass('$name', ";
231
-        $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
232
-        $javascript .= 'function (element,value) { ';
233
-        $javascript .= $callback;
234
-        $javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
235
-        $javascript .= '})';
236
-
237
-        return $javascript;
238
-    }
239
-
240
-    /**
241
-     * @param $method
242
-     * @return string
243
-     */
244
-    public function _method_option_to_s($method)
245
-    {
246
-        return false !== strpos($method, "'") ? $method : "'$method'";
247
-    }
248
-
249
-    /**
250
-     * @param $options
251
-     * @return string
252
-     */
253
-    public function _options_for_ajax($options)
254
-    {
255
-        $js_options = is_array($options) ? $this->_build_callbacks($options) : [];
256
-
257
-        if (isset($options['type']) && 'synchronous' === $option['type']) {
258
-            $js_options['asynchronous'] = 'false';
259
-        }
260
-
261
-        if (isset($options['method'])) {
262
-            $js_options['method'] = $this->_method_option_to_s($options['method']);
263
-        }
264
-
265
-        if (isset($options['position'])) {
266
-            $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
267
-        }
268
-
269
-        $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
270
-
271
-        if (isset($options['form'])) {
272
-            $js_options['parameters'] = 'Form.serialize(this)';
273
-        } elseif (isset($options['parameters'])) {
274
-            $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
275
-        } elseif (isset($options['with'])) {
276
-            $js_options['parameters'] = $options['with'];
277
-        }
278
-
279
-        return $this->_options_for_javascript($js_options);
280
-    }
281
-
282
-    /////////////////////////////////////////////////////////////////////////////////////
283
-    //                            Mergerd Javascript Generator helpers
284
-    /////////////////////////////////////////////////////////////////////////////////////
285
-
286
-    /**
287
-     * @param $javascript
288
-     */
289
-    public function dump($javascript)
290
-    {
291
-        echo $javascript;
292
-    }
293
-
294
-    /**
295
-     * @param         $id
296
-     * @param  null   $extend
297
-     * @return string
298
-     */
299
-    public function ID($id, $extend = null)
300
-    {
301
-        return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
302
-    }
303
-
304
-    /**
305
-     * @param $message
306
-     * @return string
307
-     */
308
-    public function alert($message)
309
-    {
310
-        return $this->call('alert', $message);
311
-    }
312
-
313
-    /**
314
-     * @param $variable
315
-     * @param $value
316
-     * @return string
317
-     */
318
-    public function assign($variable, $value)
319
-    {
320
-        return "$variable = $value;";
321
-    }
322
-
323
-    /**
324
-     * @param         $function
325
-     * @param  null   $args
326
-     * @return string
327
-     */
328
-    public function call($function, $args = null)
329
-    {
330
-        $arg_str = '';
331
-        if (is_array($args)) {
332
-            foreach ($args as $arg) {
333
-                if (!empty($arg_str)) {
334
-                    $arg_str .= ', ';
335
-                }
336
-                if (is_string($arg)) {
337
-                    $arg_str .= "'$arg'";
338
-                } else {
339
-                    $arg_str .= $arg;
340
-                }
341
-            }
342
-        } else {
343
-            if (is_string($args)) {
344
-                $arg_str .= "'$args'";
345
-            } else {
346
-                $arg_str .= $args;
347
-            }
348
-        }
349
-
350
-        return "$function($arg_str)";
351
-    }
352
-
353
-    /**
354
-     * @param  int    $seconds
355
-     * @param  string $script
356
-     * @return string
357
-     */
358
-    public function delay($seconds = 1, $script = '')
359
-    {
360
-        return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
361
-    }
362
-
363
-    /**
364
-     * @param $id
365
-     * @return string
366
-     */
367
-    public function hide($id)
368
-    {
369
-        return $this->call('Element.hide', $id);
370
-    }
371
-
372
-    /**
373
-     * @param         $position
374
-     * @param         $id
375
-     * @param  null   $options_for_render
376
-     * @return string
377
-     */
378
-    public function insert_html($position, $id, $options_for_render = null)
379
-    {
380
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381
-
382
-        return $this->call('new Insertion.' . ucfirst($position), $args);
383
-    }
384
-
385
-    /**
386
-     * @param $location
387
-     * @return string
388
-     */
389
-    public function redirect_to($location)
390
-    {
391
-        return $this->assign('window.location.href', $location);
392
-    }
393
-
394
-    /**
395
-     * @param $id
396
-     * @return string
397
-     */
398
-    public function remove($id)
399
-    {
400
-        if (is_array($id)) {
401
-            $arr_str = '';
402
-            foreach ($id as $obj) {
403
-                if (!empty($arg_str)) {
404
-                    $arg_str .= ', ';
405
-                }
406
-                $arg_str .= "'$arg'";
407
-            }
408
-
409
-            return "$A[$arg_str].each(Element.remove)";
410
-        } else {
411
-            return "Element.remove('$id')";
412
-        }
413
-    }
414
-
415
-    /**
416
-     * @param $id
417
-     * @param $options_for_render
418
-     * @return string
419
-     */
420
-    public function replace($id, $options_for_render)
421
-    {
422
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
423
-
424
-        return $this->call('Element.replace', $args);
425
-    }
426
-
427
-    /**
428
-     * @param $id
429
-     * @param $options_for_render
430
-     * @return string
431
-     */
432
-    public function replace_html($id, $options_for_render)
433
-    {
434
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
435
-
436
-        return $this->call('Element.update', $args);
437
-    }
438
-
439
-    /**
440
-     * @param         $pattern
441
-     * @param  null   $extend
442
-     * @return string
443
-     */
444
-    public function select($pattern, $extend = null)
445
-    {
446
-        return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
447
-    }
448
-
449
-    /**
450
-     * @param $id
451
-     * @return string
452
-     */
453
-    public function show($id)
454
-    {
455
-        return $this->call('Element.show', $id);
456
-    }
457
-
458
-    /**
459
-     * @param $id
460
-     * @return string
461
-     */
462
-    public function toggle($id)
463
-    {
464
-        return $this->call('Element.toggle', $id);
465
-    }
18
+	public $CALLBACKS = [
19
+		'uninitialized',
20
+		'loading',
21
+		'loaded',
22
+		'interactive',
23
+		'complete',
24
+		'failure',
25
+		'success'
26
+	];
27
+
28
+	public $AJAX_OPTIONS = [
29
+		'before',
30
+		'after',
31
+		'condition',
32
+		'url',
33
+		'asynchronous',
34
+		'method',
35
+		'insertion',
36
+		'position',
37
+		'form',
38
+		'with',
39
+		'update',
40
+		'script',
41
+		'uninitialized',
42
+		'loading',
43
+		'loaded',
44
+		'interactive',
45
+		'complete',
46
+		'failure',
47
+		'success'
48
+	];
49
+
50
+	/**
51
+	 * @return string
52
+	 */
53
+	public function evaluate_remote_response()
54
+	{
55
+		return 'eval(request.responseText)';
56
+	}
57
+
58
+	/**
59
+	 * @param $options
60
+	 * @return string
61
+	 */
62
+	public function form_remote_tag($options)
63
+	{
64
+		$options['form'] = true;
65
+
66
+		return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
67
+	}
68
+
69
+	/**
70
+	 * @param         $name
71
+	 * @param  null   $options
72
+	 * @param  null   $html_options
73
+	 * @return string
74
+	 */
75
+	public function link_to_remote($name, $options = null, $html_options = null)
76
+	{
77
+		return $this->link_to_function($name, $this->remote_function($options), $html_options);
78
+	}
79
+
80
+	/**
81
+	 * @param         $field_id
82
+	 * @param  null   $options
83
+	 * @return string
84
+	 */
85
+	public function observe_field($field_id, $options = null)
86
+	{
87
+		if (isset($options['frequency']) && $options['frequency'] > 0) {
88
+			return $this->_build_observer('Form.Element.Observer', $field_id, $options);
89
+		} else {
90
+			return $this->_build_observer('Form.Element.EventObserver', $field_id, $options);
91
+		}
92
+	}
93
+
94
+	/**
95
+	 * @param         $form_id
96
+	 * @param  null   $options
97
+	 * @return string
98
+	 */
99
+	public function observe_form($form_id, $options = null)
100
+	{
101
+		if (isset($options['frequency'])) {
102
+			return $this->_build_observer('Form.Observer', $form_id, $options);
103
+		} else {
104
+			return $this->_build_observer('Form.EventObserver', $form_id, $options);
105
+		}
106
+	}
107
+
108
+	/**
109
+	 * @param  null $options
110
+	 * @return string
111
+	 */
112
+	public function periodically_call_remote($options = null)
113
+	{
114
+		$frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
+		$code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
116
+
117
+		return $code;
118
+	}
119
+
120
+	/**
121
+	 * @param $options
122
+	 * @return string
123
+	 */
124
+	public function remote_function($options)
125
+	{
126
+		$javascript_options = $this->_options_for_ajax($options);
127
+
128
+		$update = '';
129
+
130
+		if (isset($options['update']) && is_array($options['update'])) {
131
+			$update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
132
+			$update .= empty($update) ? '' : ',';
133
+			$update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
134
+		} else {
135
+			$update .= isset($options['update']) ? $options['update'] : '';
136
+		}
137
+
138
+		$ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
139
+
140
+		$ajax_function .= "'" . $options['url'] . "'";
141
+		$ajax_function .= ',' . $javascript_options . ')';
142
+
143
+		$ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
+		$ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
+		$ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
+		$ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
147
+
148
+		return $ajax_function;
149
+	}
150
+
151
+	/**
152
+	 * @param $name
153
+	 * @param $value
154
+	 * @param $options
155
+	 * @return string
156
+	 */
157
+	public function submit_to_remote($name, $value, $options)
158
+	{
159
+		if (isset($options['with'])) {
160
+			$options['with'] = 'Form.serialize(this.form)';
161
+		}
162
+
163
+		return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
164
+	}
165
+
166
+	/**
167
+	 * @param      $element_id
168
+	 * @param null $options
169
+	 * @param      $block
170
+	 */
171
+	public function update_element_function($element_id, $options = null, $block)
172
+	{
173
+		$content = isset($options['content']) ? $options['content'] : '';
174
+		$content = $this->escape($content);
175
+	}
176
+
177
+	/**
178
+	 * @param $block
179
+	 */
180
+	public function update_page($block)
181
+	{
182
+	}
183
+
184
+	/**
185
+	 * @param $block
186
+	 * @return string
187
+	 */
188
+	public function update_page_tag(& $block)
189
+	{
190
+		return $this->tag($block);
191
+	}
192
+
193
+	/////////////////////////////////////////////////////////////////////////////////////
194
+	//                             Private functions
195
+	/////////////////////////////////////////////////////////////////////////////////////
196
+
197
+	/**
198
+	 * @param $options
199
+	 * @return array
200
+	 */
201
+	public function _build_callbacks($options)
202
+	{
203
+		$callbacks = [];
204
+		foreach ($options as $callback => $code) {
205
+			if (in_array($callback, $this->CALLBACKS)) {
206
+				$name             = 'on' . ucfirst($callback);
207
+				$callbacks[$name] = 'function(request){' . $code . '}';
208
+			}
209
+		}
210
+
211
+		return $callbacks;
212
+	}
213
+
214
+	/**
215
+	 * @param         $klass
216
+	 * @param         $name
217
+	 * @param  null   $options
218
+	 * @return string
219
+	 */
220
+	public function _build_observer($klass, $name, $options = null)
221
+	{
222
+		if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
+			$options['with'] = '\'' . $options['with'] . '=\' + value';
224
+		} elseif (isset($options['with']) && isset($options['update'])) {
225
+			$options['with'] = 'value';
226
+		}
227
+
228
+		$callback = $options['function'] ?: $this->remote_function($options);
229
+
230
+		$javascript = "new $klass('$name', ";
231
+		$javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
232
+		$javascript .= 'function (element,value) { ';
233
+		$javascript .= $callback;
234
+		$javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
235
+		$javascript .= '})';
236
+
237
+		return $javascript;
238
+	}
239
+
240
+	/**
241
+	 * @param $method
242
+	 * @return string
243
+	 */
244
+	public function _method_option_to_s($method)
245
+	{
246
+		return false !== strpos($method, "'") ? $method : "'$method'";
247
+	}
248
+
249
+	/**
250
+	 * @param $options
251
+	 * @return string
252
+	 */
253
+	public function _options_for_ajax($options)
254
+	{
255
+		$js_options = is_array($options) ? $this->_build_callbacks($options) : [];
256
+
257
+		if (isset($options['type']) && 'synchronous' === $option['type']) {
258
+			$js_options['asynchronous'] = 'false';
259
+		}
260
+
261
+		if (isset($options['method'])) {
262
+			$js_options['method'] = $this->_method_option_to_s($options['method']);
263
+		}
264
+
265
+		if (isset($options['position'])) {
266
+			$js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
267
+		}
268
+
269
+		$js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
270
+
271
+		if (isset($options['form'])) {
272
+			$js_options['parameters'] = 'Form.serialize(this)';
273
+		} elseif (isset($options['parameters'])) {
274
+			$js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
275
+		} elseif (isset($options['with'])) {
276
+			$js_options['parameters'] = $options['with'];
277
+		}
278
+
279
+		return $this->_options_for_javascript($js_options);
280
+	}
281
+
282
+	/////////////////////////////////////////////////////////////////////////////////////
283
+	//                            Mergerd Javascript Generator helpers
284
+	/////////////////////////////////////////////////////////////////////////////////////
285
+
286
+	/**
287
+	 * @param $javascript
288
+	 */
289
+	public function dump($javascript)
290
+	{
291
+		echo $javascript;
292
+	}
293
+
294
+	/**
295
+	 * @param         $id
296
+	 * @param  null   $extend
297
+	 * @return string
298
+	 */
299
+	public function ID($id, $extend = null)
300
+	{
301
+		return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
302
+	}
303
+
304
+	/**
305
+	 * @param $message
306
+	 * @return string
307
+	 */
308
+	public function alert($message)
309
+	{
310
+		return $this->call('alert', $message);
311
+	}
312
+
313
+	/**
314
+	 * @param $variable
315
+	 * @param $value
316
+	 * @return string
317
+	 */
318
+	public function assign($variable, $value)
319
+	{
320
+		return "$variable = $value;";
321
+	}
322
+
323
+	/**
324
+	 * @param         $function
325
+	 * @param  null   $args
326
+	 * @return string
327
+	 */
328
+	public function call($function, $args = null)
329
+	{
330
+		$arg_str = '';
331
+		if (is_array($args)) {
332
+			foreach ($args as $arg) {
333
+				if (!empty($arg_str)) {
334
+					$arg_str .= ', ';
335
+				}
336
+				if (is_string($arg)) {
337
+					$arg_str .= "'$arg'";
338
+				} else {
339
+					$arg_str .= $arg;
340
+				}
341
+			}
342
+		} else {
343
+			if (is_string($args)) {
344
+				$arg_str .= "'$args'";
345
+			} else {
346
+				$arg_str .= $args;
347
+			}
348
+		}
349
+
350
+		return "$function($arg_str)";
351
+	}
352
+
353
+	/**
354
+	 * @param  int    $seconds
355
+	 * @param  string $script
356
+	 * @return string
357
+	 */
358
+	public function delay($seconds = 1, $script = '')
359
+	{
360
+		return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
361
+	}
362
+
363
+	/**
364
+	 * @param $id
365
+	 * @return string
366
+	 */
367
+	public function hide($id)
368
+	{
369
+		return $this->call('Element.hide', $id);
370
+	}
371
+
372
+	/**
373
+	 * @param         $position
374
+	 * @param         $id
375
+	 * @param  null   $options_for_render
376
+	 * @return string
377
+	 */
378
+	public function insert_html($position, $id, $options_for_render = null)
379
+	{
380
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381
+
382
+		return $this->call('new Insertion.' . ucfirst($position), $args);
383
+	}
384
+
385
+	/**
386
+	 * @param $location
387
+	 * @return string
388
+	 */
389
+	public function redirect_to($location)
390
+	{
391
+		return $this->assign('window.location.href', $location);
392
+	}
393
+
394
+	/**
395
+	 * @param $id
396
+	 * @return string
397
+	 */
398
+	public function remove($id)
399
+	{
400
+		if (is_array($id)) {
401
+			$arr_str = '';
402
+			foreach ($id as $obj) {
403
+				if (!empty($arg_str)) {
404
+					$arg_str .= ', ';
405
+				}
406
+				$arg_str .= "'$arg'";
407
+			}
408
+
409
+			return "$A[$arg_str].each(Element.remove)";
410
+		} else {
411
+			return "Element.remove('$id')";
412
+		}
413
+	}
414
+
415
+	/**
416
+	 * @param $id
417
+	 * @param $options_for_render
418
+	 * @return string
419
+	 */
420
+	public function replace($id, $options_for_render)
421
+	{
422
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
423
+
424
+		return $this->call('Element.replace', $args);
425
+	}
426
+
427
+	/**
428
+	 * @param $id
429
+	 * @param $options_for_render
430
+	 * @return string
431
+	 */
432
+	public function replace_html($id, $options_for_render)
433
+	{
434
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
435
+
436
+		return $this->call('Element.update', $args);
437
+	}
438
+
439
+	/**
440
+	 * @param         $pattern
441
+	 * @param  null   $extend
442
+	 * @return string
443
+	 */
444
+	public function select($pattern, $extend = null)
445
+	{
446
+		return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
447
+	}
448
+
449
+	/**
450
+	 * @param $id
451
+	 * @return string
452
+	 */
453
+	public function show($id)
454
+	{
455
+		return $this->call('Element.show', $id);
456
+	}
457
+
458
+	/**
459
+	 * @param $id
460
+	 * @return string
461
+	 */
462
+	public function toggle($id)
463
+	{
464
+		return $this->call('Element.toggle', $id);
465
+	}
466 466
 }
Please login to merge, or discard this patch.
include/update.php 2 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -28,26 +28,26 @@  discard block
 block discarded – undo
28 28
  */
29 29
 function xoops_module_update_smartobject(\XoopsModule $module)
30 30
 {
31
-    ob_start();
31
+	ob_start();
32 32
 
33
-    $dbVersion = smart_GetMeta('version', 'smartobject');
34
-    if (!$dbVersion) {
35
-        $dbVersion = 0;
36
-    }
33
+	$dbVersion = smart_GetMeta('version', 'smartobject');
34
+	if (!$dbVersion) {
35
+		$dbVersion = 0;
36
+	}
37 37
 
38
-    $dbupdater = new XoopsModules\Smartobject\SmartObjectDbupdater();
38
+	$dbupdater = new XoopsModules\Smartobject\SmartObjectDbupdater();
39 39
 
40
-    echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
40
+	echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
41 41
 
42
-    // db migrate version = 1
43
-    $newDbVersion = 1;
44
-    if ($dbVersion < $newDbVersion) {
45
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
42
+	// db migrate version = 1
43
+	$newDbVersion = 1;
44
+	if ($dbVersion < $newDbVersion) {
45
+		echo 'Database migrate to version ' . $newDbVersion . '<br>';
46 46
 
47
-        // Create table smartobject_link
48
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_link');
49
-        if (!$table->exists()) {
50
-            $table->setStructure("CREATE TABLE `%s` (
47
+		// Create table smartobject_link
48
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_link');
49
+		if (!$table->exists()) {
50
+			$table->setStructure("CREATE TABLE `%s` (
51 51
               `linkid` int(11) NOT NULL auto_increment,
52 52
               `from_uid` int(11) NOT NULL default '0',
53 53
               `from_email` varchar(255) NOT NULL default '',
@@ -64,63 +64,63 @@  discard block
 block discarded – undo
64 64
               PRIMARY KEY  (`linkid`)
65 65
             ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
66 66
 
67
-            if (!$dbupdater->updateTable($table)) {
68
-                /**
69
-                 * @todo trap the errors
70
-                 */
71
-            }
72
-        }
73
-        unset($table);
74
-        // Create table smartobject_link
75
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_link');
76
-        if (!$table->fieldExists('date')) {
77
-            $table->addNewField('date', "int(11) NOT NULL default '0'");
78
-            if (!$dbupdater->updateTable($table)) {
79
-                /**
80
-                 * @todo trap the errors
81
-                 */
82
-            }
83
-        }
84
-        unset($table);
85
-
86
-        // Create table smartobject_tag
87
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_tag');
88
-        if (!$table->exists()) {
89
-            $table->setStructure("CREATE TABLE %s (
67
+			if (!$dbupdater->updateTable($table)) {
68
+				/**
69
+				 * @todo trap the errors
70
+				 */
71
+			}
72
+		}
73
+		unset($table);
74
+		// Create table smartobject_link
75
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_link');
76
+		if (!$table->fieldExists('date')) {
77
+			$table->addNewField('date', "int(11) NOT NULL default '0'");
78
+			if (!$dbupdater->updateTable($table)) {
79
+				/**
80
+				 * @todo trap the errors
81
+				 */
82
+			}
83
+		}
84
+		unset($table);
85
+
86
+		// Create table smartobject_tag
87
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_tag');
88
+		if (!$table->exists()) {
89
+			$table->setStructure("CREATE TABLE %s (
90 90
               `tagid` int(11) NOT NULL auto_increment,
91 91
               `name` varchar(255) NOT NULL default '',
92 92
               `description` TEXT NOT NULL,
93 93
               PRIMARY KEY  (`id`)
94 94
             ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
95 95
 
96
-            if (!$dbupdater->updateTable($table)) {
97
-                /**
98
-                 * @todo trap the errors
99
-                 */
100
-            }
101
-        }
102
-
103
-        // Create table smartobject_tag_text
104
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_tag_text');
105
-        if (!$table->exists()) {
106
-            $table->setStructure("CREATE TABLE %s (
96
+			if (!$dbupdater->updateTable($table)) {
97
+				/**
98
+				 * @todo trap the errors
99
+				 */
100
+			}
101
+		}
102
+
103
+		// Create table smartobject_tag_text
104
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_tag_text');
105
+		if (!$table->exists()) {
106
+			$table->setStructure("CREATE TABLE %s (
107 107
               `tagid` int(11) NOT NULL default 0,
108 108
               `language` varchar(255) NOT NULL default '',
109 109
               `value` TEXT NOT NULL,
110 110
               PRIMARY KEY  (`id`, `language`)
111 111
             ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
112 112
 
113
-            if (!$dbupdater->updateTable($table)) {
114
-                /**
115
-                 * @todo trap the errors
116
-                 */
117
-            }
118
-        }
119
-
120
-        // Create table smartobject_adsense
121
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_adsense');
122
-        if (!$table->exists()) {
123
-            $table->setStructure("
113
+			if (!$dbupdater->updateTable($table)) {
114
+				/**
115
+				 * @todo trap the errors
116
+				 */
117
+			}
118
+		}
119
+
120
+		// Create table smartobject_adsense
121
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_adsense');
122
+		if (!$table->exists()) {
123
+			$table->setStructure("
124 124
   `adsenseid` int(11) NOT NULL auto_increment,
125 125
   `format` VARCHAR(100) NOT NULL,
126 126
   `description` TEXT NOT NULL,
@@ -134,23 +134,23 @@  discard block
 block discarded – undo
134 134
   `tag` varchar(50) NOT NULL default '',
135 135
   PRIMARY KEY  (`adsenseid`)
136 136
             ");
137
-        }
138
-
139
-        if (!$dbupdater->updateTable($table)) {
140
-            /**
141
-             * @todo trap the errors
142
-             */
143
-        }
144
-    }
145
-    // db migrate version = 2
146
-    $newDbVersion = 2;
147
-    if ($dbVersion < $newDbVersion) {
148
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
149
-
150
-        // Create table smartobject_rating
151
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_rating');
152
-        if (!$table->exists()) {
153
-            $table->setStructure('
137
+		}
138
+
139
+		if (!$dbupdater->updateTable($table)) {
140
+			/**
141
+			 * @todo trap the errors
142
+			 */
143
+		}
144
+	}
145
+	// db migrate version = 2
146
+	$newDbVersion = 2;
147
+	if ($dbVersion < $newDbVersion) {
148
+		echo 'Database migrate to version ' . $newDbVersion . '<br>';
149
+
150
+		// Create table smartobject_rating
151
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_rating');
152
+		if (!$table->exists()) {
153
+			$table->setStructure('
154 154
   `ratingid` int(11) NOT NULL auto_increment,
155 155
   `dirname` VARCHAR(255) NOT NULL,
156 156
   `item` VARCHAR(255) NOT NULL,
@@ -161,36 +161,36 @@  discard block
 block discarded – undo
161 161
   PRIMARY KEY  (`ratingid`),
162 162
   UNIQUE (`dirname`, `item`, `itemid`, `uid`)
163 163
             ');
164
-        }
165
-
166
-        if (!$dbupdater->updateTable($table)) {
167
-            /**
168
-             * @todo trap the errors
169
-             */
170
-        }
171
-
172
-        // Create table smartobject_currency
173
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_currency');
174
-        $table->setData("2, 'EUR', 'Euro', '�', 0.65, 0");
175
-        $table->setData("3, 'USD', 'American dollar', '$', 0.9, 0");
176
-        $table->setData("1, 'CAD', 'Canadian dollar', '$', 1, 1");
177
-
178
-        if (!$dbupdater->updateTable($table)) {
179
-            /**
180
-             * @todo trap the errors
181
-             */
182
-        }
183
-    }
184
-
185
-    // db migrate version = 3
186
-    $newDbVersion = 3;
187
-    if ($dbVersion < $newDbVersion) {
188
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
189
-
190
-        // Create table smartobject_customtag
191
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_customtag');
192
-        if (!$table->exists()) {
193
-            $table->setStructure('
164
+		}
165
+
166
+		if (!$dbupdater->updateTable($table)) {
167
+			/**
168
+			 * @todo trap the errors
169
+			 */
170
+		}
171
+
172
+		// Create table smartobject_currency
173
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_currency');
174
+		$table->setData("2, 'EUR', 'Euro', '�', 0.65, 0");
175
+		$table->setData("3, 'USD', 'American dollar', '$', 0.9, 0");
176
+		$table->setData("1, 'CAD', 'Canadian dollar', '$', 1, 1");
177
+
178
+		if (!$dbupdater->updateTable($table)) {
179
+			/**
180
+			 * @todo trap the errors
181
+			 */
182
+		}
183
+	}
184
+
185
+	// db migrate version = 3
186
+	$newDbVersion = 3;
187
+	if ($dbVersion < $newDbVersion) {
188
+		echo 'Database migrate to version ' . $newDbVersion . '<br>';
189
+
190
+		// Create table smartobject_customtag
191
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_customtag');
192
+		if (!$table->exists()) {
193
+			$table->setStructure('
194 194
               `customtagid` int(11) NOT NULL auto_increment,
195 195
               `name` VARCHAR(255) NOT NULL,
196 196
               `description` TEXT NOT NULL,
@@ -198,24 +198,24 @@  discard block
 block discarded – undo
198 198
               `language` TEXT NOT NULL,
199 199
               PRIMARY KEY  (`customtagid`)
200 200
             ');
201
-        }
202
-
203
-        if (!$dbupdater->updateTable($table)) {
204
-            /**
205
-             * @todo trap the errors
206
-             */
207
-        }
208
-    }
209
-
210
-    // db migrate version = 4
211
-    $newDbVersion = 4;
212
-    if ($dbVersion < $newDbVersion) {
213
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
214
-
215
-        // Create table smartobject_currency
216
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_currency');
217
-        if (!$table->exists()) {
218
-            $table->setStructure('
201
+		}
202
+
203
+		if (!$dbupdater->updateTable($table)) {
204
+			/**
205
+			 * @todo trap the errors
206
+			 */
207
+		}
208
+	}
209
+
210
+	// db migrate version = 4
211
+	$newDbVersion = 4;
212
+	if ($dbVersion < $newDbVersion) {
213
+		echo 'Database migrate to version ' . $newDbVersion . '<br>';
214
+
215
+		// Create table smartobject_currency
216
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_currency');
217
+		if (!$table->exists()) {
218
+			$table->setStructure('
219 219
               `currencyid` int(11) NOT NULL auto_increment,
220 220
               `iso4217` VARCHAR(5) NOT NULL,
221 221
               `name` VARCHAR(255) NOT NULL,
@@ -224,46 +224,46 @@  discard block
 block discarded – undo
224 224
               `default_currency` int(1) NOT NULL,
225 225
               PRIMARY KEY  (`currencyid`)
226 226
             ');
227
-        }
228
-
229
-        if (!$dbupdater->updateTable($table)) {
230
-            /**
231
-             * @todo trap the errors
232
-             */
233
-        }
234
-    }
235
-
236
-    // db migrate version = 6
237
-    $newDbVersion = 6;
238
-    if ($dbVersion < $newDbVersion) {
239
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
240
-    }
241
-
242
-    $newDbVersion = 7;
243
-    if ($dbVersion < $newDbVersion) {
244
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
245
-
246
-        // Create table smartobject_file
247
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_file');
248
-        if (!$table->exists()) {
249
-            $table->setStructure('
227
+		}
228
+
229
+		if (!$dbupdater->updateTable($table)) {
230
+			/**
231
+			 * @todo trap the errors
232
+			 */
233
+		}
234
+	}
235
+
236
+	// db migrate version = 6
237
+	$newDbVersion = 6;
238
+	if ($dbVersion < $newDbVersion) {
239
+		echo 'Database migrate to version ' . $newDbVersion . '<br>';
240
+	}
241
+
242
+	$newDbVersion = 7;
243
+	if ($dbVersion < $newDbVersion) {
244
+		echo 'Database migrate to version ' . $newDbVersion . '<br>';
245
+
246
+		// Create table smartobject_file
247
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_file');
248
+		if (!$table->exists()) {
249
+			$table->setStructure('
250 250
               `fileid` int(11) NOT NULL auto_increment,
251 251
               `caption` varchar(255) collate latin1_general_ci NOT NULL,
252 252
               `url` varchar(255) collate latin1_general_ci NOT NULL,
253 253
               `description` text collate latin1_general_ci NOT NULL,
254 254
                PRIMARY KEY  (`fileid`)
255 255
             ');
256
-            if (!$dbupdater->updateTable($table)) {
257
-                /**
258
-                 * @todo trap the errors
259
-                 */
260
-            }
261
-        }
262
-        unset($table);
263
-        // Create table smartobject_urllink
264
-        $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_urllink');
265
-        if (!$table->exists()) {
266
-            $table->setStructure('
256
+			if (!$dbupdater->updateTable($table)) {
257
+				/**
258
+				 * @todo trap the errors
259
+				 */
260
+			}
261
+		}
262
+		unset($table);
263
+		// Create table smartobject_urllink
264
+		$table = new XoopsModules\Smartobject\SmartDbTable('smartobject_urllink');
265
+		if (!$table->exists()) {
266
+			$table->setStructure('
267 267
               `urllinkid` int(11) NOT NULL auto_increment,
268 268
               `caption` varchar(255) collate latin1_general_ci NOT NULL,
269 269
               `url` varchar(255) collate latin1_general_ci NOT NULL,
@@ -271,25 +271,25 @@  discard block
 block discarded – undo
271 271
               `target` varchar(10) collate latin1_general_ci NOT NULL,
272 272
                 PRIMARY KEY  (`urllinkid`)
273 273
             ');
274
-            if (!$dbupdater->updateTable($table)) {
275
-                /**
276
-                 * @todo trap the errors
277
-                 */
278
-            }
279
-        }
280
-        unset($table);
281
-    }
282
-    echo '</code>';
283
-
284
-    $feedback = ob_get_clean();
285
-    if (method_exists($module, 'setMessage')) {
286
-        $module->setMessage($feedback);
287
-    } else {
288
-        echo $feedback;
289
-    }
290
-    smart_SetMeta('version', $newDbVersion, 'smartobject'); //Set meta version to current
291
-
292
-    return true;
274
+			if (!$dbupdater->updateTable($table)) {
275
+				/**
276
+				 * @todo trap the errors
277
+				 */
278
+			}
279
+		}
280
+		unset($table);
281
+	}
282
+	echo '</code>';
283
+
284
+	$feedback = ob_get_clean();
285
+	if (method_exists($module, 'setMessage')) {
286
+		$module->setMessage($feedback);
287
+	} else {
288
+		echo $feedback;
289
+	}
290
+	smart_SetMeta('version', $newDbVersion, 'smartobject'); //Set meta version to current
291
+
292
+	return true;
293 293
 }
294 294
 
295 295
 /**
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
  */
299 299
 function xoops_module_install_smartobject(\XoopsModule $module)
300 300
 {
301
-    ob_start();
301
+	ob_start();
302 302
 
303
-    echo 'Using the ImpressCMS onInstall event';
304
-    $feedback = ob_get_clean();
303
+	echo 'Using the ImpressCMS onInstall event';
304
+	$feedback = ob_get_clean();
305 305
 
306
-    return $feedback;
306
+	return $feedback;
307 307
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 
20 20
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
21 21
 
22
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
23
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartdbupdater.php';
22
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
23
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartdbupdater.php';
24 24
 
25 25
 /**
26 26
  * @param  XoopsModule $module
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 
38 38
     $dbupdater = new XoopsModules\Smartobject\SmartObjectDbupdater();
39 39
 
40
-    echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
40
+    echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>';
41 41
 
42 42
     // db migrate version = 1
43 43
     $newDbVersion = 1;
44 44
     if ($dbVersion < $newDbVersion) {
45
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
45
+        echo 'Database migrate to version '.$newDbVersion.'<br>';
46 46
 
47 47
         // Create table smartobject_link
48 48
         $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_link');
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     // db migrate version = 2
146 146
     $newDbVersion = 2;
147 147
     if ($dbVersion < $newDbVersion) {
148
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
148
+        echo 'Database migrate to version '.$newDbVersion.'<br>';
149 149
 
150 150
         // Create table smartobject_rating
151 151
         $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_rating');
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     // db migrate version = 3
186 186
     $newDbVersion = 3;
187 187
     if ($dbVersion < $newDbVersion) {
188
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
188
+        echo 'Database migrate to version '.$newDbVersion.'<br>';
189 189
 
190 190
         // Create table smartobject_customtag
191 191
         $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_customtag');
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
     // db migrate version = 4
211 211
     $newDbVersion = 4;
212 212
     if ($dbVersion < $newDbVersion) {
213
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
213
+        echo 'Database migrate to version '.$newDbVersion.'<br>';
214 214
 
215 215
         // Create table smartobject_currency
216 216
         $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_currency');
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
     // db migrate version = 6
237 237
     $newDbVersion = 6;
238 238
     if ($dbVersion < $newDbVersion) {
239
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
239
+        echo 'Database migrate to version '.$newDbVersion.'<br>';
240 240
     }
241 241
 
242 242
     $newDbVersion = 7;
243 243
     if ($dbVersion < $newDbVersion) {
244
-        echo 'Database migrate to version ' . $newDbVersion . '<br>';
244
+        echo 'Database migrate to version '.$newDbVersion.'<br>';
245 245
 
246 246
         // Create table smartobject_file
247 247
         $table = new XoopsModules\Smartobject\SmartDbTable('smartobject_file');
Please login to merge, or discard this patch.
include/captcha/captcha.php 2 patches
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -13,253 +13,253 @@
 block discarded – undo
13 13
  */
14 14
 class XoopsCaptcha
15 15
 {
16
-    public $active = true;
17
-    public $mode   = 'text';    // potential values: image, text
18
-    public $config = [];
19
-
20
-    public $message = []; // Logging error messages
21
-
22
-    /**
23
-     * XoopsCaptcha constructor.
24
-     */
25
-    public function __construct()
26
-    {
27
-        // Loading default preferences
28
-        $this->config = @include __DIR__ . '/config.php';
29
-
30
-        $this->setMode($this->config['mode']);
31
-    }
32
-
33
-    /**
34
-     * @return XoopsCaptcha
35
-     */
36
-    public static function getInstance()
37
-    {
38
-        static $instance;
39
-        if (null === $instance) {
40
-            $instance = new static();
41
-        }
42
-
43
-        return $instance;
44
-    }
45
-
46
-    /**
47
-     * @param $name
48
-     * @param $val
49
-     * @return bool
50
-     */
51
-    public function setConfig($name, $val)
52
-    {
53
-        if ('mode' === $name) {
54
-            $this->setMode($val);
55
-        } elseif (isset($this->$name)) {
56
-            $this->$name = $val;
57
-        } else {
58
-            $this->config[$name] = $val;
59
-        }
60
-
61
-        return true;
62
-    }
63
-
64
-    /**
65
-     * Set CAPTCHA mode
66
-     *
67
-     * For future possible modes, right now force to use text or image
68
-     *
69
-     * @param string $mode if no mode is set, just verify current mode
70
-     */
71
-    public function setMode($mode = null)
72
-    {
73
-        if (!empty($mode) && in_array($mode, ['text', 'image'])) {
74
-            $this->mode = $mode;
75
-
76
-            if ('image' !== $this->mode) {
77
-                return;
78
-            }
79
-        }
80
-
81
-        // Disable image mode
82
-        if (!extension_loaded('gd')) {
83
-            $this->mode = 'text';
84
-        } else {
85
-            $required_functions = [
86
-                'imagecreatetruecolor',
87
-                'imagecolorallocate',
88
-                'imagefilledrectangle',
89
-                'imagejpeg',
90
-                'imagedestroy',
91
-                'imageftbbox'
92
-            ];
93
-            foreach ($required_functions as $func) {
94
-                if (!function_exists($func)) {
95
-                    $this->mode = 'text';
96
-                    break;
97
-                }
98
-            }
99
-        }
100
-    }
101
-
102
-    /**
103
-     * Initializing the CAPTCHA class
104
-     * @param string $name
105
-     * @param null   $skipmember
106
-     * @param null   $num_chars
107
-     * @param null   $fontsize_min
108
-     * @param null   $fontsize_max
109
-     * @param null   $background_type
110
-     * @param null   $background_num
111
-     */
112
-    public function init(
113
-        $name = 'xoopscaptcha',
114
-        $skipmember = null,
115
-        $num_chars = null,
116
-        $fontsize_min = null,
117
-        $fontsize_max = null,
118
-        $background_type = null,
119
-        $background_num = null
120
-    ) {
121
-        // Loading RUN-TIME settings
122
-        foreach (array_keys($this->config) as $key) {
123
-            if (isset(${$key}) && null !== ${$key}) {
124
-                $this->config[$key] = ${$key};
125
-            }
126
-        }
127
-        $this->config['name'] = $name;
128
-
129
-        // Skip CAPTCHA for member if set
130
-        if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) {
131
-            $this->active = false;
132
-        }
133
-    }
134
-
135
-    /**
136
-     * Verify user submission
137
-     * @param  null $skipMember
138
-     * @return bool
139
-     */
140
-    public function verify($skipMember = null)
141
-    {
142
-        $sessionName = @$_SESSION['XoopsCaptcha_name'];
143
-        $skipMember  = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember;
144
-        $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
145
-
146
-        $is_valid = false;
147
-
148
-        // Skip CAPTCHA for member if set
149
-        if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) {
150
-            $is_valid = true;
151
-        // Kill too many attempts
152
-        } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) {
153
-            $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
154
-
155
-        // Verify the code
156
-        } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) {
157
-            $func     = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp';
158
-            $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']);
159
-        }
160
-
161
-        if (!empty($maxAttempts)) {
162
-            if (!$is_valid) {
163
-                // Increase the attempt records on failure
164
-                $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++;
165
-                // Log the error message
166
-                $this->message[] = XOOPS_CAPTCHA_INVALID_CODE;
167
-            } else {
168
-
169
-                // reset attempt records on success
170
-                $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null;
171
-            }
172
-        }
173
-        $this->destroyGarbage(true);
174
-
175
-        return $is_valid;
176
-    }
177
-
178
-    /**
179
-     * @return mixed|string
180
-     */
181
-    public function getCaption()
182
-    {
183
-        return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : '';
184
-    }
185
-
186
-    /**
187
-     * @return string
188
-     */
189
-    public function getMessage()
190
-    {
191
-        return implode('<br>', $this->message);
192
-    }
193
-
194
-    /**
195
-     * Destory historical stuff
196
-     * @param  bool $clearSession
197
-     * @return bool
198
-     */
199
-    public function destroyGarbage($clearSession = false)
200
-    {
201
-        require_once __DIR__ . '/' . $this->mode . '.php';
202
-        $class          = 'XoopsCaptcha' . ucfirst($this->mode);
203
-        $captchaHandler = new $class();
204
-        if (method_exists($captchaHandler, 'destroyGarbage')) {
205
-            $captchaHandler->loadConfig($this->config);
206
-            $captchaHandler->destroyGarbage();
207
-        }
208
-
209
-        if ($clearSession) {
210
-            $_SESSION['XoopsCaptcha_name']        = null;
211
-            $_SESSION['XoopsCaptcha_skipmember']  = null;
212
-            $_SESSION['XoopsCaptcha_sessioncode'] = null;
213
-            $_SESSION['XoopsCaptcha_maxattempts'] = null;
214
-        }
215
-
216
-        return true;
217
-    }
218
-
219
-    /**
220
-     * @return mixed|string
221
-     */
222
-    public function render()
223
-    {
224
-        $form = '';
225
-
226
-        if (!$this->active || empty($this->config['name'])) {
227
-            return $form;
228
-        }
229
-
230
-        $_SESSION['XoopsCaptcha_name']        = $this->config['name'];
231
-        $_SESSION['XoopsCaptcha_skipmember']  = $this->config['skipmember'];
232
-        $maxAttempts                          = $this->config['maxattempt'];
233
-        $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts;
234
-        /*
16
+	public $active = true;
17
+	public $mode   = 'text';    // potential values: image, text
18
+	public $config = [];
19
+
20
+	public $message = []; // Logging error messages
21
+
22
+	/**
23
+	 * XoopsCaptcha constructor.
24
+	 */
25
+	public function __construct()
26
+	{
27
+		// Loading default preferences
28
+		$this->config = @include __DIR__ . '/config.php';
29
+
30
+		$this->setMode($this->config['mode']);
31
+	}
32
+
33
+	/**
34
+	 * @return XoopsCaptcha
35
+	 */
36
+	public static function getInstance()
37
+	{
38
+		static $instance;
39
+		if (null === $instance) {
40
+			$instance = new static();
41
+		}
42
+
43
+		return $instance;
44
+	}
45
+
46
+	/**
47
+	 * @param $name
48
+	 * @param $val
49
+	 * @return bool
50
+	 */
51
+	public function setConfig($name, $val)
52
+	{
53
+		if ('mode' === $name) {
54
+			$this->setMode($val);
55
+		} elseif (isset($this->$name)) {
56
+			$this->$name = $val;
57
+		} else {
58
+			$this->config[$name] = $val;
59
+		}
60
+
61
+		return true;
62
+	}
63
+
64
+	/**
65
+	 * Set CAPTCHA mode
66
+	 *
67
+	 * For future possible modes, right now force to use text or image
68
+	 *
69
+	 * @param string $mode if no mode is set, just verify current mode
70
+	 */
71
+	public function setMode($mode = null)
72
+	{
73
+		if (!empty($mode) && in_array($mode, ['text', 'image'])) {
74
+			$this->mode = $mode;
75
+
76
+			if ('image' !== $this->mode) {
77
+				return;
78
+			}
79
+		}
80
+
81
+		// Disable image mode
82
+		if (!extension_loaded('gd')) {
83
+			$this->mode = 'text';
84
+		} else {
85
+			$required_functions = [
86
+				'imagecreatetruecolor',
87
+				'imagecolorallocate',
88
+				'imagefilledrectangle',
89
+				'imagejpeg',
90
+				'imagedestroy',
91
+				'imageftbbox'
92
+			];
93
+			foreach ($required_functions as $func) {
94
+				if (!function_exists($func)) {
95
+					$this->mode = 'text';
96
+					break;
97
+				}
98
+			}
99
+		}
100
+	}
101
+
102
+	/**
103
+	 * Initializing the CAPTCHA class
104
+	 * @param string $name
105
+	 * @param null   $skipmember
106
+	 * @param null   $num_chars
107
+	 * @param null   $fontsize_min
108
+	 * @param null   $fontsize_max
109
+	 * @param null   $background_type
110
+	 * @param null   $background_num
111
+	 */
112
+	public function init(
113
+		$name = 'xoopscaptcha',
114
+		$skipmember = null,
115
+		$num_chars = null,
116
+		$fontsize_min = null,
117
+		$fontsize_max = null,
118
+		$background_type = null,
119
+		$background_num = null
120
+	) {
121
+		// Loading RUN-TIME settings
122
+		foreach (array_keys($this->config) as $key) {
123
+			if (isset(${$key}) && null !== ${$key}) {
124
+				$this->config[$key] = ${$key};
125
+			}
126
+		}
127
+		$this->config['name'] = $name;
128
+
129
+		// Skip CAPTCHA for member if set
130
+		if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) {
131
+			$this->active = false;
132
+		}
133
+	}
134
+
135
+	/**
136
+	 * Verify user submission
137
+	 * @param  null $skipMember
138
+	 * @return bool
139
+	 */
140
+	public function verify($skipMember = null)
141
+	{
142
+		$sessionName = @$_SESSION['XoopsCaptcha_name'];
143
+		$skipMember  = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember;
144
+		$maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
145
+
146
+		$is_valid = false;
147
+
148
+		// Skip CAPTCHA for member if set
149
+		if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) {
150
+			$is_valid = true;
151
+		// Kill too many attempts
152
+		} elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) {
153
+			$this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
154
+
155
+		// Verify the code
156
+		} elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) {
157
+			$func     = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp';
158
+			$is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']);
159
+		}
160
+
161
+		if (!empty($maxAttempts)) {
162
+			if (!$is_valid) {
163
+				// Increase the attempt records on failure
164
+				$_SESSION['XoopsCaptcha_attempt_' . $sessionName]++;
165
+				// Log the error message
166
+				$this->message[] = XOOPS_CAPTCHA_INVALID_CODE;
167
+			} else {
168
+
169
+				// reset attempt records on success
170
+				$_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null;
171
+			}
172
+		}
173
+		$this->destroyGarbage(true);
174
+
175
+		return $is_valid;
176
+	}
177
+
178
+	/**
179
+	 * @return mixed|string
180
+	 */
181
+	public function getCaption()
182
+	{
183
+		return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : '';
184
+	}
185
+
186
+	/**
187
+	 * @return string
188
+	 */
189
+	public function getMessage()
190
+	{
191
+		return implode('<br>', $this->message);
192
+	}
193
+
194
+	/**
195
+	 * Destory historical stuff
196
+	 * @param  bool $clearSession
197
+	 * @return bool
198
+	 */
199
+	public function destroyGarbage($clearSession = false)
200
+	{
201
+		require_once __DIR__ . '/' . $this->mode . '.php';
202
+		$class          = 'XoopsCaptcha' . ucfirst($this->mode);
203
+		$captchaHandler = new $class();
204
+		if (method_exists($captchaHandler, 'destroyGarbage')) {
205
+			$captchaHandler->loadConfig($this->config);
206
+			$captchaHandler->destroyGarbage();
207
+		}
208
+
209
+		if ($clearSession) {
210
+			$_SESSION['XoopsCaptcha_name']        = null;
211
+			$_SESSION['XoopsCaptcha_skipmember']  = null;
212
+			$_SESSION['XoopsCaptcha_sessioncode'] = null;
213
+			$_SESSION['XoopsCaptcha_maxattempts'] = null;
214
+		}
215
+
216
+		return true;
217
+	}
218
+
219
+	/**
220
+	 * @return mixed|string
221
+	 */
222
+	public function render()
223
+	{
224
+		$form = '';
225
+
226
+		if (!$this->active || empty($this->config['name'])) {
227
+			return $form;
228
+		}
229
+
230
+		$_SESSION['XoopsCaptcha_name']        = $this->config['name'];
231
+		$_SESSION['XoopsCaptcha_skipmember']  = $this->config['skipmember'];
232
+		$maxAttempts                          = $this->config['maxattempt'];
233
+		$_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts;
234
+		/*
235 235
          if (!empty($maxAttempts)) {
236 236
          $_SESSION['XoopsCaptcha_maxattempts_'.$_SESSION['XoopsCaptcha_name']] = $maxAttempts;
237 237
          }
238 238
          */
239 239
 
240
-        // Fail on too many attempts
241
-        if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) {
242
-            $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
243
-        // Load the form element
244
-        } else {
245
-            $form = $this->loadForm();
246
-        }
247
-
248
-        return $form;
249
-    }
250
-
251
-    /**
252
-     * @return mixed
253
-     */
254
-    public function loadForm()
255
-    {
256
-        require_once __DIR__ . '/' . $this->mode . '.php';
257
-        $class          = 'XoopsCaptcha' . ucfirst($this->mode);
258
-        $captchaHandler = new $class();
259
-        $captchaHandler->loadConfig($this->config);
260
-
261
-        $form = $captchaHandler->render();
262
-
263
-        return $form;
264
-    }
240
+		// Fail on too many attempts
241
+		if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) {
242
+			$form = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
243
+		// Load the form element
244
+		} else {
245
+			$form = $this->loadForm();
246
+		}
247
+
248
+		return $form;
249
+	}
250
+
251
+	/**
252
+	 * @return mixed
253
+	 */
254
+	public function loadForm()
255
+	{
256
+		require_once __DIR__ . '/' . $this->mode . '.php';
257
+		$class          = 'XoopsCaptcha' . ucfirst($this->mode);
258
+		$captchaHandler = new $class();
259
+		$captchaHandler->loadConfig($this->config);
260
+
261
+		$form = $captchaHandler->render();
262
+
263
+		return $form;
264
+	}
265 265
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 class XoopsCaptcha
15 15
 {
16 16
     public $active = true;
17
-    public $mode   = 'text';    // potential values: image, text
17
+    public $mode   = 'text'; // potential values: image, text
18 18
     public $config = [];
19 19
 
20 20
     public $message = []; // Logging error messages
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     public function __construct()
26 26
     {
27 27
         // Loading default preferences
28
-        $this->config = @include __DIR__ . '/config.php';
28
+        $this->config = @include __DIR__.'/config.php';
29 29
 
30 30
         $this->setMode($this->config['mode']);
31 31
     }
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     {
142 142
         $sessionName = @$_SESSION['XoopsCaptcha_name'];
143 143
         $skipMember  = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember;
144
-        $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
144
+        $maxAttempts = (int) (@$_SESSION['XoopsCaptcha_maxattempts']);
145 145
 
146 146
         $is_valid = false;
147 147
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) {
150 150
             $is_valid = true;
151 151
         // Kill too many attempts
152
-        } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) {
152
+        } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_'.$sessionName] > $maxAttempts) {
153 153
             $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
154 154
 
155 155
         // Verify the code
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
         if (!empty($maxAttempts)) {
162 162
             if (!$is_valid) {
163 163
                 // Increase the attempt records on failure
164
-                $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++;
164
+                $_SESSION['XoopsCaptcha_attempt_'.$sessionName]++;
165 165
                 // Log the error message
166 166
                 $this->message[] = XOOPS_CAPTCHA_INVALID_CODE;
167 167
             } else {
168 168
 
169 169
                 // reset attempt records on success
170
-                $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null;
170
+                $_SESSION['XoopsCaptcha_attempt_'.$sessionName] = null;
171 171
             }
172 172
         }
173 173
         $this->destroyGarbage(true);
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
      */
199 199
     public function destroyGarbage($clearSession = false)
200 200
     {
201
-        require_once __DIR__ . '/' . $this->mode . '.php';
202
-        $class          = 'XoopsCaptcha' . ucfirst($this->mode);
201
+        require_once __DIR__.'/'.$this->mode.'.php';
202
+        $class          = 'XoopsCaptcha'.ucfirst($this->mode);
203 203
         $captchaHandler = new $class();
204 204
         if (method_exists($captchaHandler, 'destroyGarbage')) {
205 205
             $captchaHandler->loadConfig($this->config);
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
          */
239 239
 
240 240
         // Fail on too many attempts
241
-        if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) {
241
+        if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_'.$this->config['name']] > $maxAttempts) {
242 242
             $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
243 243
         // Load the form element
244 244
         } else {
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
      */
254 254
     public function loadForm()
255 255
     {
256
-        require_once __DIR__ . '/' . $this->mode . '.php';
257
-        $class          = 'XoopsCaptcha' . ucfirst($this->mode);
256
+        require_once __DIR__.'/'.$this->mode.'.php';
257
+        $class          = 'XoopsCaptcha'.ucfirst($this->mode);
258 258
         $captchaHandler = new $class();
259 259
         $captchaHandler->loadConfig($this->config);
260 260
 
Please login to merge, or discard this patch.
include/captcha/formcaptcha.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -38,60 +38,60 @@
 block discarded – undo
38 38
  */
39 39
 class XoopsFormCaptcha extends \XoopsFormElement
40 40
 {
41
-    public $_captchaHandler;
41
+	public $_captchaHandler;
42 42
 
43
-    /**
44
-     * @param string  $caption        Caption of the form element, default value is defined in captcha/language/
45
-     * @param string  $name           Name for the input box
46
-     * @param boolean $skipmember     Skip CAPTCHA check for members
47
-     * @param int     $numchar        Number of characters in image mode, and input box size for text mode
48
-     * @param int     $minfontsize    Minimum font-size of characters in image mode
49
-     * @param int     $maxfontsize    Maximum font-size of characters in image mode
50
-     * @param int     $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files
51
-     * @param int     $backgroundnum  Number of background images in image mode
52
-     *
53
-     */
54
-    public function __construct(
55
-        $caption = '',
56
-        $name = 'xoopscaptcha',
57
-        $skipmember = null,
58
-        $numchar = null,
59
-        $minfontsize = null,
60
-        $maxfontsize = null,
61
-        $backgroundtype = null,
62
-        $backgroundnum = null
63
-    ) {
64
-        if (!class_exists('XoopsCaptcaha')) {
65
-            require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php';
66
-        }
43
+	/**
44
+	 * @param string  $caption        Caption of the form element, default value is defined in captcha/language/
45
+	 * @param string  $name           Name for the input box
46
+	 * @param boolean $skipmember     Skip CAPTCHA check for members
47
+	 * @param int     $numchar        Number of characters in image mode, and input box size for text mode
48
+	 * @param int     $minfontsize    Minimum font-size of characters in image mode
49
+	 * @param int     $maxfontsize    Maximum font-size of characters in image mode
50
+	 * @param int     $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files
51
+	 * @param int     $backgroundnum  Number of background images in image mode
52
+	 *
53
+	 */
54
+	public function __construct(
55
+		$caption = '',
56
+		$name = 'xoopscaptcha',
57
+		$skipmember = null,
58
+		$numchar = null,
59
+		$minfontsize = null,
60
+		$maxfontsize = null,
61
+		$backgroundtype = null,
62
+		$backgroundnum = null
63
+	) {
64
+		if (!class_exists('XoopsCaptcaha')) {
65
+			require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php';
66
+		}
67 67
 
68
-        $this->_captchaHandler = XoopsCaptcha::getInstance();
69
-        $this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum);
70
-        if (!$this->_captchaHandler->active) {
71
-            $this->setHidden();
72
-        } else {
73
-            $caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption();
74
-            $this->setCaption($caption);
75
-        }
76
-    }
68
+		$this->_captchaHandler = XoopsCaptcha::getInstance();
69
+		$this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum);
70
+		if (!$this->_captchaHandler->active) {
71
+			$this->setHidden();
72
+		} else {
73
+			$caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption();
74
+			$this->setCaption($caption);
75
+		}
76
+	}
77 77
 
78
-    /**
79
-     * @param $name
80
-     * @param $val
81
-     * @return bool
82
-     */
83
-    public function setConfig($name, $val)
84
-    {
85
-        return $this->_captchaHandler->setConfig($name, $val);
86
-    }
78
+	/**
79
+	 * @param $name
80
+	 * @param $val
81
+	 * @return bool
82
+	 */
83
+	public function setConfig($name, $val)
84
+	{
85
+		return $this->_captchaHandler->setConfig($name, $val);
86
+	}
87 87
 
88
-    /**
89
-     * @return mixed|string
90
-     */
91
-    public function render()
92
-    {
93
-        if (!$this->isHidden()) {
94
-            return $this->_captchaHandler->render();
95
-        }
96
-    }
88
+	/**
89
+	 * @return mixed|string
90
+	 */
91
+	public function render()
92
+	{
93
+		if (!$this->isHidden()) {
94
+			return $this->_captchaHandler->render();
95
+		}
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
15 15
 
16
-require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelement.php';
16
+require_once XOOPS_ROOT_PATH.'/class/xoopsform/formelement.php';
17 17
 
18 18
 /*
19 19
  * Usage
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $backgroundnum = null
63 63
     ) {
64 64
         if (!class_exists('XoopsCaptcaha')) {
65
-            require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php';
65
+            require_once SMARTOBJECT_ROOT_PATH.'/include/captcha/captcha.php';
66 66
         }
67 67
 
68 68
         $this->_captchaHandler = XoopsCaptcha::getInstance();
Please login to merge, or discard this patch.
include/rating.rate.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use XoopsModules\Smartobject\SmartPluginHandler;
12 12
 
13 13
 if (!defined('SMARTOBJECT_URL')) {
14
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
14
+	require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
15 15
 }
16 16
 require_once SMARTOBJECT_ROOT_PATH . 'class/rating.php';
17 17
 require_once SMARTOBJECT_ROOT_PATH . 'include/functions.php';
@@ -25,52 +25,52 @@  discard block
 block discarded – undo
25 25
 $smartobjectPluginHandler = new XoopsModules\Smartobject\SmartPluginHandler();
26 26
 $pluginObj                = $smartobjectPluginHandler->getPlugin($module_dirname);
27 27
 if ($pluginObj) {
28
-    $rating_item = $pluginObj->getItem();
29
-    if ($rating_item) {
30
-        $rating_itemid = $pluginObj->getItemIdForItem($rating_item);
31
-        $stats         = $smartobjectRatingHandler->getRatingAverageByItemId($rating_itemid, $module_dirname, $rating_item);
32
-        $xoopsTpl->assign('smartobject_rating_stats_total', $stats['sum']);
33
-        $xoopsTpl->assign('smartobject_rating_stats_average', $stats['average']);
34
-        $xoopsTpl->assign('smartobject_rating_item', $rating_item);
35
-        if (is_object($xoopsUser)) {
36
-            $ratingObj = $smartobjectRatingHandler->already_rated($rating_item, $rating_itemid, $module_dirname, $xoopsUser->getVar('uid'));
37
-            $xoopsTpl->assign('smartobject_user_can_rate', true);
38
-        }
39
-        if (isset($ratingObj) && is_object($ratingObj)) {
40
-            $xoopsTpl->assign('smartobject_user_rate', $ratingObj->getVar('rate'));
41
-            $xoopsTpl->assign('smartobject_rated', true);
42
-        } else {
43
-            $xoopsTpl->assign('smartobject_rating_dirname', $module_dirname);
44
-            $xoopsTpl->assign('smartobject_rating_itemid', $rating_itemid);
45
-            $urls = smart_getCurrentUrls();
46
-            $xoopsTpl->assign('smartobject_rating_current_page', $urls['full']);
47
-            if (isset($xoTheme) && is_object($xoTheme)) {
48
-                $xoTheme->addStylesheet(SMARTOBJECT_URL . 'assets/css/module.css');
49
-            } else {
50
-                //probleme d'inclusion de css apres le flashplayer. Style plac� dans css du theme
51
-                //$xoopsTpl->assign('smartobject_css',"<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/smartobject/assets/css/module.css'>");
52
-            }
53
-        }
54
-    }
28
+	$rating_item = $pluginObj->getItem();
29
+	if ($rating_item) {
30
+		$rating_itemid = $pluginObj->getItemIdForItem($rating_item);
31
+		$stats         = $smartobjectRatingHandler->getRatingAverageByItemId($rating_itemid, $module_dirname, $rating_item);
32
+		$xoopsTpl->assign('smartobject_rating_stats_total', $stats['sum']);
33
+		$xoopsTpl->assign('smartobject_rating_stats_average', $stats['average']);
34
+		$xoopsTpl->assign('smartobject_rating_item', $rating_item);
35
+		if (is_object($xoopsUser)) {
36
+			$ratingObj = $smartobjectRatingHandler->already_rated($rating_item, $rating_itemid, $module_dirname, $xoopsUser->getVar('uid'));
37
+			$xoopsTpl->assign('smartobject_user_can_rate', true);
38
+		}
39
+		if (isset($ratingObj) && is_object($ratingObj)) {
40
+			$xoopsTpl->assign('smartobject_user_rate', $ratingObj->getVar('rate'));
41
+			$xoopsTpl->assign('smartobject_rated', true);
42
+		} else {
43
+			$xoopsTpl->assign('smartobject_rating_dirname', $module_dirname);
44
+			$xoopsTpl->assign('smartobject_rating_itemid', $rating_itemid);
45
+			$urls = smart_getCurrentUrls();
46
+			$xoopsTpl->assign('smartobject_rating_current_page', $urls['full']);
47
+			if (isset($xoTheme) && is_object($xoTheme)) {
48
+				$xoTheme->addStylesheet(SMARTOBJECT_URL . 'assets/css/module.css');
49
+			} else {
50
+				//probleme d'inclusion de css apres le flashplayer. Style plac� dans css du theme
51
+				//$xoopsTpl->assign('smartobject_css',"<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/smartobject/assets/css/module.css'>");
52
+			}
53
+		}
54
+	}
55 55
 }
56 56
 
57 57
 if (isset($_POST['smartobject_rating_submit'])) {
58
-    // The rating form has just been posted. Let's save the info
59
-    $ratingObj = $smartobjectRatingHandler->create();
60
-    $ratingObj->setVar('dirname', $module_dirname);
61
-    $ratingObj->setVar('item', $rating_item);
62
-    $ratingObj->setVar('itemid', $rating_itemid);
63
-    $ratingObj->setVar('uid', $xoopsUser->getVar('uid'));
64
-    $ratingObj->setVar('date', time());
65
-    $ratingObj->setVar('rate', $_POST['smartobject_rating_value']);
66
-    if (!$smartobjectRatingHandler->insert($ratingObj)) {
67
-        if (1062 == $xoopsDB->errno()) {
68
-            $message = _SOBJECT_RATING_DUPLICATE_ENTRY;
69
-        } else {
70
-            $message = _SOBJECT_RATING_ERROR;
71
-        }
72
-    } else {
73
-        $message = _SOBJECT_RATING_SUCCESS;
74
-    }
75
-    redirect_header('', 3, $message);
58
+	// The rating form has just been posted. Let's save the info
59
+	$ratingObj = $smartobjectRatingHandler->create();
60
+	$ratingObj->setVar('dirname', $module_dirname);
61
+	$ratingObj->setVar('item', $rating_item);
62
+	$ratingObj->setVar('itemid', $rating_itemid);
63
+	$ratingObj->setVar('uid', $xoopsUser->getVar('uid'));
64
+	$ratingObj->setVar('date', time());
65
+	$ratingObj->setVar('rate', $_POST['smartobject_rating_value']);
66
+	if (!$smartobjectRatingHandler->insert($ratingObj)) {
67
+		if (1062 == $xoopsDB->errno()) {
68
+			$message = _SOBJECT_RATING_DUPLICATE_ENTRY;
69
+		} else {
70
+			$message = _SOBJECT_RATING_ERROR;
71
+		}
72
+	} else {
73
+		$message = _SOBJECT_RATING_SUCCESS;
74
+	}
75
+	redirect_header('', 3, $message);
76 76
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@  discard block
 block discarded – undo
11 11
 use XoopsModules\Smartobject\SmartPluginHandler;
12 12
 
13 13
 if (!defined('SMARTOBJECT_URL')) {
14
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
14
+    require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
15 15
 }
16
-require_once SMARTOBJECT_ROOT_PATH . 'class/rating.php';
17
-require_once SMARTOBJECT_ROOT_PATH . 'include/functions.php';
16
+require_once SMARTOBJECT_ROOT_PATH.'class/rating.php';
17
+require_once SMARTOBJECT_ROOT_PATH.'include/functions.php';
18 18
 
19 19
 smart_loadLanguageFile('smartobject', 'rating');
20 20
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
             $urls = smart_getCurrentUrls();
46 46
             $xoopsTpl->assign('smartobject_rating_current_page', $urls['full']);
47 47
             if (isset($xoTheme) && is_object($xoTheme)) {
48
-                $xoTheme->addStylesheet(SMARTOBJECT_URL . 'assets/css/module.css');
48
+                $xoTheme->addStylesheet(SMARTOBJECT_URL.'assets/css/module.css');
49 49
             } else {
50 50
                 //probleme d'inclusion de css apres le flashplayer. Style plac� dans css du theme
51 51
                 //$xoopsTpl->assign('smartobject_css',"<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/smartobject/assets/css/module.css'>");
Please login to merge, or discard this patch.