Completed
Push — master ( c5aa4f...a09810 )
by Michael
02:13
created
class/smartobjectcategory.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -18,123 +18,123 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class SmartobjectCategory extends SmartSeoObject
20 20
 {
21
-    public $_categoryPath;
22
-
23
-    /**
24
-     * SmartobjectCategory constructor.
25
-     */
26
-    public function __construct()
27
-    {
28
-        $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true);
29
-        $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC);
30
-        $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC);
31
-        $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC);
32
-        $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC);
33
-
34
-        $this->initCommonVar('doxcode');
35
-
36
-        $this->setControl('image', array('name' => 'image'));
37
-        $this->setControl('parentid', array('name' => 'parentcategory'));
38
-        $this->setControl('description', array(
39
-            'name'        => 'textarea',
40
-            'itemHandler' => false,
41
-            'method'      => false,
42
-            'module'      => false,
43
-            'form_editor' => 'default'
44
-        ));
45
-
46
-        // call parent constructor to get SEO fields initiated
47
-        parent::__construct();
48
-    }
49
-
50
-    /**
51
-     * returns a specific variable for the object in a proper format
52
-     *
53
-     * @access public
54
-     * @param  string $key    key of the object's variable to be returned
55
-     * @param  string $format format to use for the output
56
-     * @return mixed  formatted value of the variable
57
-     */
58
-    public function getVar($key, $format = 's')
59
-    {
60
-        if ($format === 's' && in_array($key, array('description', 'image'))) {
61
-            //            return call_user_func(array($this, $key));
62
-            return $this->{$key}();
63
-        }
64
-
65
-        return parent::getVar($key, $format);
66
-    }
67
-
68
-    /**
69
-     * @return string
70
-     */
71
-    public function description()
72
-    {
73
-        return $this->getValueFor('description', false);
74
-    }
75
-
76
-    /**
77
-     * @return bool|mixed
78
-     */
79
-    public function image()
80
-    {
81
-        $ret = $this->getVar('image', 'e');
82
-        if ($ret == '-1') {
83
-            return false;
84
-        } else {
85
-            return $ret;
86
-        }
87
-    }
88
-
89
-    /**
90
-     * @return array
91
-     */
92
-    public function toArray()
93
-    {
94
-        $this->setVar('doxcode', true);
95
-        global $myts;
96
-        $objectArray = parent::toArray();
97
-        if ($objectArray['image']) {
98
-            $objectArray['image'] = $this->getImageDir() . $objectArray['image'];
99
-        }
100
-
101
-        return $objectArray;
102
-    }
103
-
104
-    /**
105
-     * Create the complete path of a category
106
-     *
107
-     * @todo this could be improved as it uses multiple queries
108
-     * @param  bool $withAllLink make all name clickable
109
-     * @param  bool $currentCategory
110
-     * @return string complete path (breadcrumb)
111
-     */
112
-    public function getCategoryPath($withAllLink = true, $currentCategory = false)
113
-    {
114
-        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
115
-        $controller = new SmartObjectController($this->handler);
116
-
117
-        if (!$this->_categoryPath) {
118
-            if ($withAllLink && !$currentCategory) {
119
-                $ret = $controller->getItemLink($this);
120
-            } else {
121
-                $currentCategory = false;
122
-                $ret             = $this->getVar('name');
123
-            }
124
-            $parentid = $this->getVar('parentid');
125
-            if ($parentid != 0) {
126
-                $parentObj = $this->handler->get($parentid);
127
-                if ($parentObj->isNew()) {
128
-                    exit;
129
-                }
130
-                $parentid = $parentObj->getVar('parentid');
131
-                $ret      = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret;
132
-            }
133
-            $this->_categoryPath = $ret;
134
-        }
135
-
136
-        return $this->_categoryPath;
137
-    }
21
+	public $_categoryPath;
22
+
23
+	/**
24
+	 * SmartobjectCategory constructor.
25
+	 */
26
+	public function __construct()
27
+	{
28
+		$this->initVar('categoryid', XOBJ_DTYPE_INT, '', true);
29
+		$this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC);
30
+		$this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC);
31
+		$this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC);
32
+		$this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC);
33
+
34
+		$this->initCommonVar('doxcode');
35
+
36
+		$this->setControl('image', array('name' => 'image'));
37
+		$this->setControl('parentid', array('name' => 'parentcategory'));
38
+		$this->setControl('description', array(
39
+			'name'        => 'textarea',
40
+			'itemHandler' => false,
41
+			'method'      => false,
42
+			'module'      => false,
43
+			'form_editor' => 'default'
44
+		));
45
+
46
+		// call parent constructor to get SEO fields initiated
47
+		parent::__construct();
48
+	}
49
+
50
+	/**
51
+	 * returns a specific variable for the object in a proper format
52
+	 *
53
+	 * @access public
54
+	 * @param  string $key    key of the object's variable to be returned
55
+	 * @param  string $format format to use for the output
56
+	 * @return mixed  formatted value of the variable
57
+	 */
58
+	public function getVar($key, $format = 's')
59
+	{
60
+		if ($format === 's' && in_array($key, array('description', 'image'))) {
61
+			//            return call_user_func(array($this, $key));
62
+			return $this->{$key}();
63
+		}
64
+
65
+		return parent::getVar($key, $format);
66
+	}
67
+
68
+	/**
69
+	 * @return string
70
+	 */
71
+	public function description()
72
+	{
73
+		return $this->getValueFor('description', false);
74
+	}
75
+
76
+	/**
77
+	 * @return bool|mixed
78
+	 */
79
+	public function image()
80
+	{
81
+		$ret = $this->getVar('image', 'e');
82
+		if ($ret == '-1') {
83
+			return false;
84
+		} else {
85
+			return $ret;
86
+		}
87
+	}
88
+
89
+	/**
90
+	 * @return array
91
+	 */
92
+	public function toArray()
93
+	{
94
+		$this->setVar('doxcode', true);
95
+		global $myts;
96
+		$objectArray = parent::toArray();
97
+		if ($objectArray['image']) {
98
+			$objectArray['image'] = $this->getImageDir() . $objectArray['image'];
99
+		}
100
+
101
+		return $objectArray;
102
+	}
103
+
104
+	/**
105
+	 * Create the complete path of a category
106
+	 *
107
+	 * @todo this could be improved as it uses multiple queries
108
+	 * @param  bool $withAllLink make all name clickable
109
+	 * @param  bool $currentCategory
110
+	 * @return string complete path (breadcrumb)
111
+	 */
112
+	public function getCategoryPath($withAllLink = true, $currentCategory = false)
113
+	{
114
+		require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
115
+		$controller = new SmartObjectController($this->handler);
116
+
117
+		if (!$this->_categoryPath) {
118
+			if ($withAllLink && !$currentCategory) {
119
+				$ret = $controller->getItemLink($this);
120
+			} else {
121
+				$currentCategory = false;
122
+				$ret             = $this->getVar('name');
123
+			}
124
+			$parentid = $this->getVar('parentid');
125
+			if ($parentid != 0) {
126
+				$parentObj = $this->handler->get($parentid);
127
+				if ($parentObj->isNew()) {
128
+					exit;
129
+				}
130
+				$parentid = $parentObj->getVar('parentid');
131
+				$ret      = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret;
132
+			}
133
+			$this->_categoryPath = $ret;
134
+		}
135
+
136
+		return $this->_categoryPath;
137
+	}
138 138
 }
139 139
 
140 140
 /**
@@ -142,91 +142,91 @@  discard block
 block discarded – undo
142 142
  */
143 143
 class SmartobjectCategoryHandler extends SmartPersistableObjectHandler
144 144
 {
145
-    public $allCategoriesObj = false;
146
-    public $_allCategoriesId = false;
147
-
148
-    /**
149
-     * SmartobjectCategoryHandler constructor.
150
-     * @param XoopsDatabase        $db
151
-     * @param                      $modulename
152
-     */
153
-    public function __construct(XoopsDatabase $db, $modulename)
154
-    {
155
-        parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename);
156
-    }
157
-
158
-    /**
159
-     * @param  int    $parentid
160
-     * @param  bool   $perm_name
161
-     * @param  string $sort
162
-     * @param  string $order
163
-     * @return array|bool
164
-     */
165
-    public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC')
166
-    {
167
-        if (!$this->allCategoriesObj) {
168
-            $criteria = new CriteriaCompo();
169
-            $criteria->setSort($sort);
170
-            $criteria->setOrder($order);
171
-            global $xoopsUser;
172
-            $userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin();
173
-
174
-            if ($perm_name && !$userIsAdmin) {
175
-                if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) {
176
-                    return false;
177
-                }
178
-            }
179
-
180
-            $this->allCategoriesObj = $this->getObjects($criteria, 'parentid');
181
-        }
182
-
183
-        $ret = array();
184
-        if (isset($this->allCategoriesObj[$parentid])) {
185
-            foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) {
186
-                $ret[$categoryid]['self'] = $categoryObj->toArray();
187
-                if (isset($this->allCategoriesObj[$categoryid])) {
188
-                    $ret[$categoryid]['sub']          = $this->getAllCategoriesArray($categoryid);
189
-                    $ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']);
190
-                }
191
-            }
192
-        }
193
-
194
-        return $ret;
195
-    }
196
-
197
-    /**
198
-     * @param               $parentid
199
-     * @param  bool         $asString
200
-     * @return array|string
201
-     */
202
-    public function getParentIds($parentid, $asString = true)
203
-    {
204
-        if (!$this->allCategoriesId) {
205
-            $ret = array();
206
-            $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid';
207
-
208
-            $result = $this->db->query($sql);
209
-
210
-            if (!$result) {
211
-                return $ret;
212
-            }
213
-
214
-            while ($myrow = $this->db->fetchArray($result)) {
215
-                $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid'];
216
-            }
217
-        }
218
-
219
-        $retArray = array($parentid);
220
-        while ($parentid != 0) {
221
-            $parentid = $this->allCategoriesId[$parentid];
222
-            if ($parentid != 0) {
223
-                $retArray[] = $parentid;
224
-            }
225
-        }
226
-        if ($asString) {
227
-            return implode(', ', $retArray);
228
-        } else {
229
-            return $retArray;
230
-        }
231
-    }
145
+	public $allCategoriesObj = false;
146
+	public $_allCategoriesId = false;
147
+
148
+	/**
149
+	 * SmartobjectCategoryHandler constructor.
150
+	 * @param XoopsDatabase        $db
151
+	 * @param                      $modulename
152
+	 */
153
+	public function __construct(XoopsDatabase $db, $modulename)
154
+	{
155
+		parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename);
156
+	}
157
+
158
+	/**
159
+	 * @param  int    $parentid
160
+	 * @param  bool   $perm_name
161
+	 * @param  string $sort
162
+	 * @param  string $order
163
+	 * @return array|bool
164
+	 */
165
+	public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC')
166
+	{
167
+		if (!$this->allCategoriesObj) {
168
+			$criteria = new CriteriaCompo();
169
+			$criteria->setSort($sort);
170
+			$criteria->setOrder($order);
171
+			global $xoopsUser;
172
+			$userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin();
173
+
174
+			if ($perm_name && !$userIsAdmin) {
175
+				if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) {
176
+					return false;
177
+				}
178
+			}
179
+
180
+			$this->allCategoriesObj = $this->getObjects($criteria, 'parentid');
181
+		}
182
+
183
+		$ret = array();
184
+		if (isset($this->allCategoriesObj[$parentid])) {
185
+			foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) {
186
+				$ret[$categoryid]['self'] = $categoryObj->toArray();
187
+				if (isset($this->allCategoriesObj[$categoryid])) {
188
+					$ret[$categoryid]['sub']          = $this->getAllCategoriesArray($categoryid);
189
+					$ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']);
190
+				}
191
+			}
192
+		}
193
+
194
+		return $ret;
195
+	}
196
+
197
+	/**
198
+	 * @param               $parentid
199
+	 * @param  bool         $asString
200
+	 * @return array|string
201
+	 */
202
+	public function getParentIds($parentid, $asString = true)
203
+	{
204
+		if (!$this->allCategoriesId) {
205
+			$ret = array();
206
+			$sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid';
207
+
208
+			$result = $this->db->query($sql);
209
+
210
+			if (!$result) {
211
+				return $ret;
212
+			}
213
+
214
+			while ($myrow = $this->db->fetchArray($result)) {
215
+				$this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid'];
216
+			}
217
+		}
218
+
219
+		$retArray = array($parentid);
220
+		while ($parentid != 0) {
221
+			$parentid = $this->allCategoriesId[$parentid];
222
+			if ($parentid != 0) {
223
+				$retArray[] = $parentid;
224
+			}
225
+		}
226
+		if ($asString) {
227
+			return implode(', ', $retArray);
228
+		} else {
229
+			return $retArray;
230
+		}
231
+	}
232 232
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
14
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartseoobject.php';
14
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartseoobject.php';
15 15
 
16 16
 /**
17 17
  * Class SmartobjectCategory
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         global $myts;
96 96
         $objectArray = parent::toArray();
97 97
         if ($objectArray['image']) {
98
-            $objectArray['image'] = $this->getImageDir() . $objectArray['image'];
98
+            $objectArray['image'] = $this->getImageDir().$objectArray['image'];
99 99
         }
100 100
 
101 101
         return $objectArray;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function getCategoryPath($withAllLink = true, $currentCategory = false)
113 113
     {
114
-        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
114
+        require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php';
115 115
         $controller = new SmartObjectController($this->handler);
116 116
 
117 117
         if (!$this->_categoryPath) {
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                     exit;
129 129
                 }
130 130
                 $parentid = $parentObj->getVar('parentid');
131
-                $ret      = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret;
131
+                $ret      = $parentObj->getCategoryPath($withAllLink, $currentCategory).' > '.$ret;
132 132
             }
133 133
             $this->_categoryPath = $ret;
134 134
         }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
     {
204 204
         if (!$this->allCategoriesId) {
205 205
             $ret = array();
206
-            $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid';
206
+            $sql = 'SELECT categoryid, parentid FROM '.$this->table.' AS '.$this->_itemname.' ORDER BY parentid';
207 207
 
208 208
             $result = $this->db->query($sql);
209 209
 
Please login to merge, or discard this patch.
class/smartobjecttreetable.php 2 patches
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -22,157 +22,157 @@
 block discarded – undo
22 22
  */
23 23
 class SmartObjectTreeTable extends SmartObjectTable
24 24
 {
25
-    /**
26
-     * SmartObjectTreeTable constructor.
27
-     * @param SmartPersistableObjectHandler $objectHandler
28
-     * @param bool                          $criteria
29
-     * @param array                         $actions
30
-     * @param bool                          $userSide
31
-     */
32
-    public function __construct(
33
-        SmartPersistableObjectHandler $objectHandler,
34
-        $criteria = false,
35
-        $actions = array('edit', 'delete'),
36
-        $userSide = false
37
-    ) {
38
-        $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide);
39
-        $this->_isTree = true;
40
-    }
41
-
42
-    /**
43
-     * Get children objects given a specific parentid
44
-     *
45
-     * @var    int $parentid id of the parent which children we want to retreive
46
-     * @return array of SmartObject
47
-     */
48
-    public function getChildrenOf($parentid = 0)
49
-    {
50
-        return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false;
51
-    }
52
-
53
-    /**
54
-     * @param     $object
55
-     * @param int $level
56
-     */
57
-    public function createTableRow($object, $level = 0)
58
-    {
59
-        $aObject = array();
60
-
61
-        $i = 0;
62
-
63
-        $aColumns        = array();
64
-        $doWeHaveActions = false;
65
-
66
-        foreach ($this->_columns as $column) {
67
-            $aColumn = array();
68
-
69
-            if ($i == 0) {
70
-                $class = 'head';
71
-            } elseif ($i % 2 == 0) {
72
-                $class = 'even';
73
-            } else {
74
-                $class = 'odd';
75
-            }
76
-
77
-            if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) {
78
-                $method = $column->_customMethodForValue;
79
-                $value  = $object->$method();
80
-            } else {
81
-                /**
82
-                 * If the column is the identifier, then put a link on it
83
-                 */
84
-                if ($column->getKeyName() == $this->_objectHandler->identifierName) {
85
-                    $value = $object->getItemLink();
86
-                } else {
87
-                    $value = $object->getVar($column->getKeyName());
88
-                }
89
-            }
90
-
91
-            $space = '';
92
-            if ($column->getKeyName() == $this->_objectHandler->identifierName) {
93
-                for ($i = 0; $i < $level; ++$i) {
94
-                    $space .= '--';
95
-                }
96
-            }
97
-
98
-            if ($space !== '') {
99
-                $space .= '&nbsp;';
100
-            }
101
-
102
-            $aColumn['value'] = $space . $value;
103
-            $aColumn['class'] = $class;
104
-            $aColumn['width'] = $column->getWidth();
105
-            $aColumn['align'] = $column->getAlign();
106
-            $aColumn['key']   = $column->getKeyName();
107
-
108
-            $aColumns[] = $aColumn;
109
-            ++$i;
110
-        }
111
-
112
-        $aObject['columns'] = $aColumns;
113
-
114
-        $class            = $class === 'even' ? 'odd' : 'even';
115
-        $aObject['class'] = $class;
116
-
117
-        $actions = array();
118
-
119
-        // Adding the custom actions if any
120
-        foreach ($this->_custom_actions as $action) {
121
-            if (method_exists($object, $action)) {
122
-                $actions[] = $object->$action();
123
-            }
124
-        }
125
-
126
-        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
127
-        $controller = new SmartObjectController($this->_objectHandler);
128
-
129
-        if (in_array('edit', $this->_actions)) {
130
-            $actions[] = $controller->getEditItemLink($object, false, true);
131
-        }
132
-        if (in_array('delete', $this->_actions)) {
133
-            $actions[] = $controller->getDeleteItemLink($object, false, true);
134
-        }
135
-        $aObject['actions'] = $actions;
136
-
137
-        $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30);
138
-        $aObject['id']     = $object->id();
139
-        $this->_aObjects[] = $aObject;
140
-
141
-        $childrenObjects = $this->getChildrenOf($object->id());
142
-
143
-        $this->_hasActions = $this->_hasActions ? true : count($actions) > 0;
144
-
145
-        if ($childrenObjects) {
146
-            ++$level;
147
-            foreach ($childrenObjects as $subObject) {
148
-                $this->createTableRow($subObject, $level);
149
-            }
150
-        }
151
-    }
152
-
153
-    public function createTableRows()
154
-    {
155
-        $this->_aObjects = array();
156
-
157
-        if (count($this->_objects) > 0) {
158
-            foreach ($this->getChildrenOf() as $object) {
159
-                $this->createTableRow($object);
160
-            }
161
-
162
-            $this->_tpl->assign('smartobject_objects', $this->_aObjects);
163
-        } else {
164
-            $colspan = count($this->_columns) + 1;
165
-            $this->_tpl->assign('smartobject_colspan', $colspan);
166
-        }
167
-    }
168
-
169
-    /**
170
-     * @return mixed
171
-     */
172
-    public function fetchObjects()
173
-    {
174
-        $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid');
175
-
176
-        return $ret;
177
-    }
25
+	/**
26
+	 * SmartObjectTreeTable constructor.
27
+	 * @param SmartPersistableObjectHandler $objectHandler
28
+	 * @param bool                          $criteria
29
+	 * @param array                         $actions
30
+	 * @param bool                          $userSide
31
+	 */
32
+	public function __construct(
33
+		SmartPersistableObjectHandler $objectHandler,
34
+		$criteria = false,
35
+		$actions = array('edit', 'delete'),
36
+		$userSide = false
37
+	) {
38
+		$this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide);
39
+		$this->_isTree = true;
40
+	}
41
+
42
+	/**
43
+	 * Get children objects given a specific parentid
44
+	 *
45
+	 * @var    int $parentid id of the parent which children we want to retreive
46
+	 * @return array of SmartObject
47
+	 */
48
+	public function getChildrenOf($parentid = 0)
49
+	{
50
+		return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false;
51
+	}
52
+
53
+	/**
54
+	 * @param     $object
55
+	 * @param int $level
56
+	 */
57
+	public function createTableRow($object, $level = 0)
58
+	{
59
+		$aObject = array();
60
+
61
+		$i = 0;
62
+
63
+		$aColumns        = array();
64
+		$doWeHaveActions = false;
65
+
66
+		foreach ($this->_columns as $column) {
67
+			$aColumn = array();
68
+
69
+			if ($i == 0) {
70
+				$class = 'head';
71
+			} elseif ($i % 2 == 0) {
72
+				$class = 'even';
73
+			} else {
74
+				$class = 'odd';
75
+			}
76
+
77
+			if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) {
78
+				$method = $column->_customMethodForValue;
79
+				$value  = $object->$method();
80
+			} else {
81
+				/**
82
+				 * If the column is the identifier, then put a link on it
83
+				 */
84
+				if ($column->getKeyName() == $this->_objectHandler->identifierName) {
85
+					$value = $object->getItemLink();
86
+				} else {
87
+					$value = $object->getVar($column->getKeyName());
88
+				}
89
+			}
90
+
91
+			$space = '';
92
+			if ($column->getKeyName() == $this->_objectHandler->identifierName) {
93
+				for ($i = 0; $i < $level; ++$i) {
94
+					$space .= '--';
95
+				}
96
+			}
97
+
98
+			if ($space !== '') {
99
+				$space .= '&nbsp;';
100
+			}
101
+
102
+			$aColumn['value'] = $space . $value;
103
+			$aColumn['class'] = $class;
104
+			$aColumn['width'] = $column->getWidth();
105
+			$aColumn['align'] = $column->getAlign();
106
+			$aColumn['key']   = $column->getKeyName();
107
+
108
+			$aColumns[] = $aColumn;
109
+			++$i;
110
+		}
111
+
112
+		$aObject['columns'] = $aColumns;
113
+
114
+		$class            = $class === 'even' ? 'odd' : 'even';
115
+		$aObject['class'] = $class;
116
+
117
+		$actions = array();
118
+
119
+		// Adding the custom actions if any
120
+		foreach ($this->_custom_actions as $action) {
121
+			if (method_exists($object, $action)) {
122
+				$actions[] = $object->$action();
123
+			}
124
+		}
125
+
126
+		require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
127
+		$controller = new SmartObjectController($this->_objectHandler);
128
+
129
+		if (in_array('edit', $this->_actions)) {
130
+			$actions[] = $controller->getEditItemLink($object, false, true);
131
+		}
132
+		if (in_array('delete', $this->_actions)) {
133
+			$actions[] = $controller->getDeleteItemLink($object, false, true);
134
+		}
135
+		$aObject['actions'] = $actions;
136
+
137
+		$this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30);
138
+		$aObject['id']     = $object->id();
139
+		$this->_aObjects[] = $aObject;
140
+
141
+		$childrenObjects = $this->getChildrenOf($object->id());
142
+
143
+		$this->_hasActions = $this->_hasActions ? true : count($actions) > 0;
144
+
145
+		if ($childrenObjects) {
146
+			++$level;
147
+			foreach ($childrenObjects as $subObject) {
148
+				$this->createTableRow($subObject, $level);
149
+			}
150
+		}
151
+	}
152
+
153
+	public function createTableRows()
154
+	{
155
+		$this->_aObjects = array();
156
+
157
+		if (count($this->_objects) > 0) {
158
+			foreach ($this->getChildrenOf() as $object) {
159
+				$this->createTableRow($object);
160
+			}
161
+
162
+			$this->_tpl->assign('smartobject_objects', $this->_aObjects);
163
+		} else {
164
+			$colspan = count($this->_columns) + 1;
165
+			$this->_tpl->assign('smartobject_colspan', $colspan);
166
+		}
167
+	}
168
+
169
+	/**
170
+	 * @return mixed
171
+	 */
172
+	public function fetchObjects()
173
+	{
174
+		$ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid');
175
+
176
+		return $ret;
177
+	}
178 178
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @subpackage SmartObjectTable
10 10
  */
11 11
 
12
-require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
12
+require_once SMARTOBJECT_ROOT_PATH.'class/smartobjecttable.php';
13 13
 
14 14
 /**
15 15
  * SmartObjectTreeTable class
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
                 $space .= '&nbsp;';
100 100
             }
101 101
 
102
-            $aColumn['value'] = $space . $value;
102
+            $aColumn['value'] = $space.$value;
103 103
             $aColumn['class'] = $class;
104 104
             $aColumn['width'] = $column->getWidth();
105 105
             $aColumn['align'] = $column->getAlign();
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
             }
124 124
         }
125 125
 
126
-        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
126
+        require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php';
127 127
         $controller = new SmartObjectController($this->_objectHandler);
128 128
 
129 129
         if (in_array('edit', $this->_actions)) {
Please login to merge, or discard this patch.
class/smartdbupdater.php 2 patches
Indentation   +817 added lines, -817 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
20 20
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
21
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
21
+	require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
22 22
 }
23 23
 /**
24 24
  * Include the language constants for the SmartObjectDBUpdater
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 global $xoopsConfig;
27 27
 $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php';
28 28
 if (!file_exists($common_file)) {
29
-    $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
29
+	$common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
30 30
 }
31 31
 include $common_file;
32 32
 
@@ -35,503 +35,503 @@  discard block
 block discarded – undo
35 35
  */
36 36
 class SmartDbTable
37 37
 {
38
-    /**
39
-     * @var string $_name name of the table
40
-     */
41
-    public $_name;
42
-    /**
43
-     * @var string $_structure structure of the table
44
-     */
45
-    public $_structure;
46
-
47
-    /**
48
-     * @var array $_data containing valued of each records to be added
49
-     */
50
-    public $_data;
51
-
52
-    /**
53
-     * @var array $_alteredFields containing fields to be altered
54
-     */
55
-    public $_alteredFields;
56
-
57
-    /**
58
-     * @var array $_newFields containing new fields to be added
59
-     */
60
-    public $_newFields;
61
-
62
-    /**
63
-     * @var array $_droppedFields containing fields to be dropped
64
-     */
65
-    public $_droppedFields;
66
-
67
-    /**
68
-     * @var array $_flagForDrop flag table to drop it
69
-     */
70
-    public $_flagForDrop = false;
71
-
72
-    /**
73
-     * @var array $_updatedFields containing fields which values will be updated
74
-     */
75
-    public $_updatedFields;
76
-
77
-    /**
78
-     * @var array $_updatedFields containing fields which values will be updated
79
-     */ //felix
80
-    public $_updatedWhere;
81
-
82
-    public $_existingFieldsArray = false;
83
-
84
-    /**
85
-     * Constructor
86
-     *
87
-     * @param string $name name of the table
88
-     *
89
-     */
90
-    public function __construct($name)
91
-    {
92
-        $this->_name = $name;
93
-        $this->_data = array();
94
-    }
95
-
96
-    /**
97
-     * Return the table name, prefixed with site table prefix
98
-     *
99
-     * @return string table name
100
-     *
101
-     */
102
-    public function name()
103
-    {
104
-        global $xoopsDB;
105
-
106
-        return $xoopsDB->prefix($this->_name);
107
-    }
108
-
109
-    /**
110
-     * Checks if the table already exists in the database
111
-     *
112
-     * @return bool TRUE if it exists, FALSE if not
113
-     *
114
-     */
115
-    public function exists()
116
-    {
117
-        return smart_TableExists($this->_name);
118
-    }
119
-
120
-    /**
121
-     * @return mixed
122
-     */
123
-    public function getExistingFieldsArray()
124
-    {
125
-        global $xoopsDB;
126
-        $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
127
-        while ($existing_field = $xoopsDB->fetchArray($result)) {
128
-            $fields[$existing_field['Field']] = $existing_field['Type'];
129
-            if ($existing_field['Null'] !== 'YES') {
130
-                $fields[$existing_field['Field']] .= ' NOT NULL';
131
-            }
132
-            if ($existing_field['Extra']) {
133
-                $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
134
-            }
135
-            if (!($existing_field['Default'] === null)
136
-                && ($existing_field['Default']
137
-                    || $existing_field['Default'] === ''
138
-                    || $existing_field['Default'] == 0)) {
139
-                $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
140
-            }
141
-        }
142
-
143
-        return $fields;
144
-    }
145
-
146
-    /**
147
-     * @param $field
148
-     * @return bool
149
-     */
150
-    public function fieldExists($field)
151
-    {
152
-        $existingFields = $this->getExistingFieldsArray();
153
-
154
-        return isset($existingFields[$field]);
155
-    }
156
-
157
-    /**
158
-     * Set the table structure
159
-     *
160
-     * Example:
161
-     *
162
-     *      $table->setStructure("`transactionid` int(11) NOT NULL auto_increment,
163
-     *                `date` int(11) NOT NULL default '0',
164
-     *                `status` int(1) NOT NULL default '-1',
165
-     *                `itemid` int(11) NOT NULL default '0',
166
-     *                `uid` int(11) NOT NULL default '0',
167
-     *                `price` float NOT NULL default '0',
168
-     *                `currency` varchar(100) NOT NULL default '',
169
-     *                PRIMARY KEY  (`transactionid`)");
170
-     *
171
-     * @param string $structure table structure
172
-     *
173
-     */
174
-    public function setStructure($structure)
175
-    {
176
-        $this->_structure = $structure;
177
-    }
178
-
179
-    /**
180
-     * Return the table structure
181
-     *
182
-     * @return string table structure
183
-     *
184
-     */
185
-    public function getStructure()
186
-    {
187
-        return sprintf($this->_structure, $this->name());
188
-    }
189
-
190
-    /**
191
-     * Add values of a record to be added
192
-     *
193
-     * @param string $data values of a record
194
-     *
195
-     */
196
-    public function setData($data)
197
-    {
198
-        $this->_data[] = $data;
199
-    }
200
-
201
-    /**
202
-     * Get the data array
203
-     *
204
-     * @return array containing the records values to be added
205
-     *
206
-     */
207
-    public function getData()
208
-    {
209
-        return $this->_data;
210
-    }
211
-
212
-    /**
213
-     * Use to insert data in a table
214
-     *
215
-     * @return bool true if success, false if an error occured
216
-     *
217
-     */
218
-    public function addData()
219
-    {
220
-        global $xoopsDB;
221
-        foreach ($this->getData() as $data) {
222
-            $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
223
-            $ret   = $xoopsDB->query($query);
224
-            if (!$ret) {
225
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
226
-            } else {
227
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
228
-            }
229
-        }
230
-
231
-        return $ret;
232
-    }
233
-
234
-    /**
235
-     * Add a field to be added
236
-     *
237
-     * @param string $name       name of the field
238
-     * @param string $properties properties of the field
239
-     * @param bool   $newname
240
-     * @param bool   $showerror
241
-     */
242
-    public function addAlteredField($name, $properties, $newname = false, $showerror = true)
243
-    {
244
-        $field['name']          = $name;
245
-        $field['properties']    = $properties;
246
-        $field['showerror']     = $showerror;
247
-        $field['newname']       = $newname;
248
-        $this->_alteredFields[] = $field;
249
-    }
250
-    /**
251
-     * Invert values 0 to 1 and 1 to 0
252
-     *
253
-     * @param string $name name of the field
254
-     * @param        $newValue
255
-     * @param        $oldValue
256
-     * @internal param string $old old propertie
257
-     * @internal param string $new new propertie
258
-     */ //felix
259
-    public function addUpdatedWhere($name, $newValue, $oldValue)
260
-    {
261
-        $field['name']         = $name;
262
-        $field['value']        = $newValue;
263
-        $field['where']        = $oldValue;
264
-        $this->_updatedWhere[] = $field;
265
-    }
266
-
267
-    /**
268
-     * Add new field of a record to be added
269
-     *
270
-     * @param string $name       name of the field
271
-     * @param string $properties properties of the field
272
-     *
273
-     */
274
-    public function addNewField($name, $properties)
275
-    {
276
-        $field['name']       = $name;
277
-        $field['properties'] = $properties;
278
-        $this->_newFields[]  = $field;
279
-    }
280
-
281
-    /**
282
-     * Get fields that need to be altered
283
-     *
284
-     * @return array fields that need to be altered
285
-     *
286
-     */
287
-    public function getAlteredFields()
288
-    {
289
-        return $this->_alteredFields;
290
-    }
291
-
292
-    /**
293
-     * Add field for which the value will be updated
294
-     *
295
-     * @param string $name  name of the field
296
-     * @param string $value value to be set
297
-     *
298
-     */
299
-    public function addUpdatedField($name, $value)
300
-    {
301
-        $field['name']          = $name;
302
-        $field['value']         = $value;
303
-        $this->_updatedFields[] = $field;
304
-    }
305
-
306
-    /**
307
-     * Get new fields to be added
308
-     *
309
-     * @return array fields to be added
310
-     *
311
-     */
312
-    public function getNewFields()
313
-    {
314
-        return $this->_newFields;
315
-    }
316
-
317
-    /**
318
-     * Get fields which values need to be updated
319
-     *
320
-     * @return array fields which values need to be updated
321
-     *
322
-     */
323
-    public function getUpdatedFields()
324
-    {
325
-        return $this->_updatedFields;
326
-    }
327
-    /**
328
-     * Get fields which values need to be updated
329
-     *
330
-     * @return array fields which values need to be updated
331
-     *
332
-     */ //felix
333
-    public function getUpdatedWhere()
334
-    {
335
-        return $this->_updatedWhere;
336
-    }
337
-
338
-    /**
339
-     * Add values of a record to be added
340
-     *
341
-     * @param string $name name of the field
342
-     *
343
-     */
344
-    public function addDroppedField($name)
345
-    {
346
-        $this->_droppedFields[] = $name;
347
-    }
348
-
349
-    /**
350
-     * Get fields that need to be dropped
351
-     *
352
-     * @return array fields that need to be dropped
353
-     *
354
-     */
355
-    public function getDroppedFields()
356
-    {
357
-        return $this->_droppedFields;
358
-    }
359
-
360
-    /**
361
-     * Set the flag to drop the table
362
-     *
363
-     */
364
-    public function setFlagForDrop()
365
-    {
366
-        $this->_flagForDrop = true;
367
-    }
368
-
369
-    /**
370
-     * Use to create a table
371
-     *
372
-     * @return bool true if success, false if an error occured
373
-     *
374
-     */
375
-    public function createTable()
376
-    {
377
-        global $xoopsDB;
378
-        $query = $this->getStructure();
379
-        $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
380
-        //xoops_debug($query);
381
-        $ret = $xoopsDB->query($query);
382
-        if (!$ret) {
383
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
384
-        } else {
385
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
386
-        }
387
-
388
-        return $ret;
389
-    }
390
-
391
-    /**
392
-     * Use to drop a table
393
-     *
394
-     * @return bool true if success, false if an error occured
395
-     *
396
-     */
397
-    public function dropTable()
398
-    {
399
-        global $xoopsDB;
400
-        $query = sprintf('DROP TABLE %s', $this->name());
401
-        $ret   = $xoopsDB->query($query);
402
-        if (!$ret) {
403
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
404
-
405
-            return false;
406
-        } else {
407
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
408
-
409
-            return true;
410
-        }
411
-    }
412
-
413
-    /**
414
-     * Use to alter a table
415
-     *
416
-     * @return bool true if success, false if an error occured
417
-     *
418
-     */
419
-    public function alterTable()
420
-    {
421
-        global $xoopsDB;
422
-        $ret = true;
423
-
424
-        foreach ($this->getAlteredFields() as $alteredField) {
425
-            if (!$alteredField['newname']) {
426
-                $alteredField['newname'] = $alteredField['name'];
427
-            }
428
-
429
-            $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']);
430
-            $ret   = $ret && $xoopsDB->query($query);
431
-            if ($alteredField['showerror']) {
432
-                if (!$ret) {
433
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
434
-                } else {
435
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
436
-                }
437
-            }
438
-        }
439
-
440
-        return $ret;
441
-    }
442
-
443
-    /**
444
-     * Use to add new fileds in the table
445
-     *
446
-     * @return bool true if success, false if an error occured
447
-     *
448
-     */
449
-    public function addNewFields()
450
-    {
451
-        global $xoopsDB;
452
-        $ret = true;
453
-        foreach ($this->getNewFields() as $newField) {
454
-            $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']);
455
-            //echo $query;
456
-            $ret = $ret && $xoopsDB->query($query);
457
-            if (!$ret) {
458
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
459
-            } else {
460
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
461
-            }
462
-        }
463
-
464
-        return $ret;
465
-    }
466
-
467
-    /**
468
-     * Use to update fields values
469
-     *
470
-     * @return bool true if success, false if an error occured
471
-     *
472
-     */
473
-    public function updateFieldsValues()
474
-    {
475
-        global $xoopsDB;
476
-        $ret = true;
477
-        foreach ($this->getUpdatedFields() as $updatedField) {
478
-            $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
479
-            $ret   = $ret && $xoopsDB->query($query);
480
-            if (!$ret) {
481
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
482
-            } else {
483
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
484
-            }
485
-        }
486
-
487
-        return $ret;
488
-    }
489
-    /**
490
-     * Use to update fields values
491
-     *
492
-     * @return bool true if success, false if an error occured
493
-     *
494
-     */ //felix
495
-    public function updateWhereValues()
496
-    {
497
-        global $xoopsDB;
498
-        $ret = true;
499
-        foreach ($this->getUpdatedWhere() as $updatedWhere) {
500
-            $query = sprintf('UPDATE %s SET %s = %s WHERE %s  %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']);
501
-            //echo $query."<br>";
502
-            $ret = $ret && $xoopsDB->query($query);
503
-            if (!$ret) {
504
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
505
-            } else {
506
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
507
-            }
508
-        }
509
-
510
-        return $ret;
511
-    }
512
-
513
-    /**
514
-     * Use to drop fields
515
-     *
516
-     * @return bool true if success, false if an error occured
517
-     *
518
-     */
519
-    public function dropFields()
520
-    {
521
-        global $xoopsDB;
522
-        $ret = true;
523
-        foreach ($this->getDroppedFields() as $droppedField) {
524
-            $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
525
-            $ret   = $ret && $xoopsDB->query($query);
526
-            if (!$ret) {
527
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
528
-            } else {
529
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
530
-            }
531
-        }
532
-
533
-        return $ret;
534
-    }
38
+	/**
39
+	 * @var string $_name name of the table
40
+	 */
41
+	public $_name;
42
+	/**
43
+	 * @var string $_structure structure of the table
44
+	 */
45
+	public $_structure;
46
+
47
+	/**
48
+	 * @var array $_data containing valued of each records to be added
49
+	 */
50
+	public $_data;
51
+
52
+	/**
53
+	 * @var array $_alteredFields containing fields to be altered
54
+	 */
55
+	public $_alteredFields;
56
+
57
+	/**
58
+	 * @var array $_newFields containing new fields to be added
59
+	 */
60
+	public $_newFields;
61
+
62
+	/**
63
+	 * @var array $_droppedFields containing fields to be dropped
64
+	 */
65
+	public $_droppedFields;
66
+
67
+	/**
68
+	 * @var array $_flagForDrop flag table to drop it
69
+	 */
70
+	public $_flagForDrop = false;
71
+
72
+	/**
73
+	 * @var array $_updatedFields containing fields which values will be updated
74
+	 */
75
+	public $_updatedFields;
76
+
77
+	/**
78
+	 * @var array $_updatedFields containing fields which values will be updated
79
+	 */ //felix
80
+	public $_updatedWhere;
81
+
82
+	public $_existingFieldsArray = false;
83
+
84
+	/**
85
+	 * Constructor
86
+	 *
87
+	 * @param string $name name of the table
88
+	 *
89
+	 */
90
+	public function __construct($name)
91
+	{
92
+		$this->_name = $name;
93
+		$this->_data = array();
94
+	}
95
+
96
+	/**
97
+	 * Return the table name, prefixed with site table prefix
98
+	 *
99
+	 * @return string table name
100
+	 *
101
+	 */
102
+	public function name()
103
+	{
104
+		global $xoopsDB;
105
+
106
+		return $xoopsDB->prefix($this->_name);
107
+	}
108
+
109
+	/**
110
+	 * Checks if the table already exists in the database
111
+	 *
112
+	 * @return bool TRUE if it exists, FALSE if not
113
+	 *
114
+	 */
115
+	public function exists()
116
+	{
117
+		return smart_TableExists($this->_name);
118
+	}
119
+
120
+	/**
121
+	 * @return mixed
122
+	 */
123
+	public function getExistingFieldsArray()
124
+	{
125
+		global $xoopsDB;
126
+		$result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
127
+		while ($existing_field = $xoopsDB->fetchArray($result)) {
128
+			$fields[$existing_field['Field']] = $existing_field['Type'];
129
+			if ($existing_field['Null'] !== 'YES') {
130
+				$fields[$existing_field['Field']] .= ' NOT NULL';
131
+			}
132
+			if ($existing_field['Extra']) {
133
+				$fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
134
+			}
135
+			if (!($existing_field['Default'] === null)
136
+				&& ($existing_field['Default']
137
+					|| $existing_field['Default'] === ''
138
+					|| $existing_field['Default'] == 0)) {
139
+				$fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
140
+			}
141
+		}
142
+
143
+		return $fields;
144
+	}
145
+
146
+	/**
147
+	 * @param $field
148
+	 * @return bool
149
+	 */
150
+	public function fieldExists($field)
151
+	{
152
+		$existingFields = $this->getExistingFieldsArray();
153
+
154
+		return isset($existingFields[$field]);
155
+	}
156
+
157
+	/**
158
+	 * Set the table structure
159
+	 *
160
+	 * Example:
161
+	 *
162
+	 *      $table->setStructure("`transactionid` int(11) NOT NULL auto_increment,
163
+	 *                `date` int(11) NOT NULL default '0',
164
+	 *                `status` int(1) NOT NULL default '-1',
165
+	 *                `itemid` int(11) NOT NULL default '0',
166
+	 *                `uid` int(11) NOT NULL default '0',
167
+	 *                `price` float NOT NULL default '0',
168
+	 *                `currency` varchar(100) NOT NULL default '',
169
+	 *                PRIMARY KEY  (`transactionid`)");
170
+	 *
171
+	 * @param string $structure table structure
172
+	 *
173
+	 */
174
+	public function setStructure($structure)
175
+	{
176
+		$this->_structure = $structure;
177
+	}
178
+
179
+	/**
180
+	 * Return the table structure
181
+	 *
182
+	 * @return string table structure
183
+	 *
184
+	 */
185
+	public function getStructure()
186
+	{
187
+		return sprintf($this->_structure, $this->name());
188
+	}
189
+
190
+	/**
191
+	 * Add values of a record to be added
192
+	 *
193
+	 * @param string $data values of a record
194
+	 *
195
+	 */
196
+	public function setData($data)
197
+	{
198
+		$this->_data[] = $data;
199
+	}
200
+
201
+	/**
202
+	 * Get the data array
203
+	 *
204
+	 * @return array containing the records values to be added
205
+	 *
206
+	 */
207
+	public function getData()
208
+	{
209
+		return $this->_data;
210
+	}
211
+
212
+	/**
213
+	 * Use to insert data in a table
214
+	 *
215
+	 * @return bool true if success, false if an error occured
216
+	 *
217
+	 */
218
+	public function addData()
219
+	{
220
+		global $xoopsDB;
221
+		foreach ($this->getData() as $data) {
222
+			$query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
223
+			$ret   = $xoopsDB->query($query);
224
+			if (!$ret) {
225
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
226
+			} else {
227
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
228
+			}
229
+		}
230
+
231
+		return $ret;
232
+	}
233
+
234
+	/**
235
+	 * Add a field to be added
236
+	 *
237
+	 * @param string $name       name of the field
238
+	 * @param string $properties properties of the field
239
+	 * @param bool   $newname
240
+	 * @param bool   $showerror
241
+	 */
242
+	public function addAlteredField($name, $properties, $newname = false, $showerror = true)
243
+	{
244
+		$field['name']          = $name;
245
+		$field['properties']    = $properties;
246
+		$field['showerror']     = $showerror;
247
+		$field['newname']       = $newname;
248
+		$this->_alteredFields[] = $field;
249
+	}
250
+	/**
251
+	 * Invert values 0 to 1 and 1 to 0
252
+	 *
253
+	 * @param string $name name of the field
254
+	 * @param        $newValue
255
+	 * @param        $oldValue
256
+	 * @internal param string $old old propertie
257
+	 * @internal param string $new new propertie
258
+	 */ //felix
259
+	public function addUpdatedWhere($name, $newValue, $oldValue)
260
+	{
261
+		$field['name']         = $name;
262
+		$field['value']        = $newValue;
263
+		$field['where']        = $oldValue;
264
+		$this->_updatedWhere[] = $field;
265
+	}
266
+
267
+	/**
268
+	 * Add new field of a record to be added
269
+	 *
270
+	 * @param string $name       name of the field
271
+	 * @param string $properties properties of the field
272
+	 *
273
+	 */
274
+	public function addNewField($name, $properties)
275
+	{
276
+		$field['name']       = $name;
277
+		$field['properties'] = $properties;
278
+		$this->_newFields[]  = $field;
279
+	}
280
+
281
+	/**
282
+	 * Get fields that need to be altered
283
+	 *
284
+	 * @return array fields that need to be altered
285
+	 *
286
+	 */
287
+	public function getAlteredFields()
288
+	{
289
+		return $this->_alteredFields;
290
+	}
291
+
292
+	/**
293
+	 * Add field for which the value will be updated
294
+	 *
295
+	 * @param string $name  name of the field
296
+	 * @param string $value value to be set
297
+	 *
298
+	 */
299
+	public function addUpdatedField($name, $value)
300
+	{
301
+		$field['name']          = $name;
302
+		$field['value']         = $value;
303
+		$this->_updatedFields[] = $field;
304
+	}
305
+
306
+	/**
307
+	 * Get new fields to be added
308
+	 *
309
+	 * @return array fields to be added
310
+	 *
311
+	 */
312
+	public function getNewFields()
313
+	{
314
+		return $this->_newFields;
315
+	}
316
+
317
+	/**
318
+	 * Get fields which values need to be updated
319
+	 *
320
+	 * @return array fields which values need to be updated
321
+	 *
322
+	 */
323
+	public function getUpdatedFields()
324
+	{
325
+		return $this->_updatedFields;
326
+	}
327
+	/**
328
+	 * Get fields which values need to be updated
329
+	 *
330
+	 * @return array fields which values need to be updated
331
+	 *
332
+	 */ //felix
333
+	public function getUpdatedWhere()
334
+	{
335
+		return $this->_updatedWhere;
336
+	}
337
+
338
+	/**
339
+	 * Add values of a record to be added
340
+	 *
341
+	 * @param string $name name of the field
342
+	 *
343
+	 */
344
+	public function addDroppedField($name)
345
+	{
346
+		$this->_droppedFields[] = $name;
347
+	}
348
+
349
+	/**
350
+	 * Get fields that need to be dropped
351
+	 *
352
+	 * @return array fields that need to be dropped
353
+	 *
354
+	 */
355
+	public function getDroppedFields()
356
+	{
357
+		return $this->_droppedFields;
358
+	}
359
+
360
+	/**
361
+	 * Set the flag to drop the table
362
+	 *
363
+	 */
364
+	public function setFlagForDrop()
365
+	{
366
+		$this->_flagForDrop = true;
367
+	}
368
+
369
+	/**
370
+	 * Use to create a table
371
+	 *
372
+	 * @return bool true if success, false if an error occured
373
+	 *
374
+	 */
375
+	public function createTable()
376
+	{
377
+		global $xoopsDB;
378
+		$query = $this->getStructure();
379
+		$query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
380
+		//xoops_debug($query);
381
+		$ret = $xoopsDB->query($query);
382
+		if (!$ret) {
383
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
384
+		} else {
385
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
386
+		}
387
+
388
+		return $ret;
389
+	}
390
+
391
+	/**
392
+	 * Use to drop a table
393
+	 *
394
+	 * @return bool true if success, false if an error occured
395
+	 *
396
+	 */
397
+	public function dropTable()
398
+	{
399
+		global $xoopsDB;
400
+		$query = sprintf('DROP TABLE %s', $this->name());
401
+		$ret   = $xoopsDB->query($query);
402
+		if (!$ret) {
403
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
404
+
405
+			return false;
406
+		} else {
407
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
408
+
409
+			return true;
410
+		}
411
+	}
412
+
413
+	/**
414
+	 * Use to alter a table
415
+	 *
416
+	 * @return bool true if success, false if an error occured
417
+	 *
418
+	 */
419
+	public function alterTable()
420
+	{
421
+		global $xoopsDB;
422
+		$ret = true;
423
+
424
+		foreach ($this->getAlteredFields() as $alteredField) {
425
+			if (!$alteredField['newname']) {
426
+				$alteredField['newname'] = $alteredField['name'];
427
+			}
428
+
429
+			$query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']);
430
+			$ret   = $ret && $xoopsDB->query($query);
431
+			if ($alteredField['showerror']) {
432
+				if (!$ret) {
433
+					echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
434
+				} else {
435
+					echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
436
+				}
437
+			}
438
+		}
439
+
440
+		return $ret;
441
+	}
442
+
443
+	/**
444
+	 * Use to add new fileds in the table
445
+	 *
446
+	 * @return bool true if success, false if an error occured
447
+	 *
448
+	 */
449
+	public function addNewFields()
450
+	{
451
+		global $xoopsDB;
452
+		$ret = true;
453
+		foreach ($this->getNewFields() as $newField) {
454
+			$query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']);
455
+			//echo $query;
456
+			$ret = $ret && $xoopsDB->query($query);
457
+			if (!$ret) {
458
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
459
+			} else {
460
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
461
+			}
462
+		}
463
+
464
+		return $ret;
465
+	}
466
+
467
+	/**
468
+	 * Use to update fields values
469
+	 *
470
+	 * @return bool true if success, false if an error occured
471
+	 *
472
+	 */
473
+	public function updateFieldsValues()
474
+	{
475
+		global $xoopsDB;
476
+		$ret = true;
477
+		foreach ($this->getUpdatedFields() as $updatedField) {
478
+			$query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
479
+			$ret   = $ret && $xoopsDB->query($query);
480
+			if (!$ret) {
481
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
482
+			} else {
483
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
484
+			}
485
+		}
486
+
487
+		return $ret;
488
+	}
489
+	/**
490
+	 * Use to update fields values
491
+	 *
492
+	 * @return bool true if success, false if an error occured
493
+	 *
494
+	 */ //felix
495
+	public function updateWhereValues()
496
+	{
497
+		global $xoopsDB;
498
+		$ret = true;
499
+		foreach ($this->getUpdatedWhere() as $updatedWhere) {
500
+			$query = sprintf('UPDATE %s SET %s = %s WHERE %s  %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']);
501
+			//echo $query."<br>";
502
+			$ret = $ret && $xoopsDB->query($query);
503
+			if (!$ret) {
504
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
505
+			} else {
506
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
507
+			}
508
+		}
509
+
510
+		return $ret;
511
+	}
512
+
513
+	/**
514
+	 * Use to drop fields
515
+	 *
516
+	 * @return bool true if success, false if an error occured
517
+	 *
518
+	 */
519
+	public function dropFields()
520
+	{
521
+		global $xoopsDB;
522
+		$ret = true;
523
+		foreach ($this->getDroppedFields() as $droppedField) {
524
+			$query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
525
+			$ret   = $ret && $xoopsDB->query($query);
526
+			if (!$ret) {
527
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
528
+			} else {
529
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
530
+			}
531
+		}
532
+
533
+		return $ret;
534
+	}
535 535
 }
536 536
 
537 537
 /**
@@ -545,328 +545,328 @@  discard block
 block discarded – undo
545 545
  */
546 546
 class SmartobjectDbupdater
547 547
 {
548
-    public $_dbTypesArray;
549
-
550
-    /**
551
-     * SmartobjectDbupdater constructor.
552
-     */
553
-    public function __construct()
554
-    {
555
-        $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX]       = 'varchar(255)';
556
-        $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA]      = 'text';
557
-        $this->_dbTypesArray[XOBJ_DTYPE_INT]          = 'int(11)';
558
-        $this->_dbTypesArray[XOBJ_DTYPE_URL]          = 'varchar(255)';
559
-        $this->_dbTypesArray[XOBJ_DTYPE_EMAIL]        = 'varchar(255)';
560
-        $this->_dbTypesArray[XOBJ_DTYPE_ARRAY]        = 'text';
561
-        $this->_dbTypesArray[XOBJ_DTYPE_OTHER]        = 'text';
562
-        $this->_dbTypesArray[XOBJ_DTYPE_SOURCE]       = 'text';
563
-        $this->_dbTypesArray[XOBJ_DTYPE_STIME]        = 'int(11)';
564
-        $this->_dbTypesArray[XOBJ_DTYPE_MTIME]        = 'int(11)';
565
-        $this->_dbTypesArray[XOBJ_DTYPE_LTIME]        = 'int(11)';
566
-        $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text';
567
-        $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY]     = 'text';
568
-        $this->_dbTypesArray[XOBJ_DTYPE_FLOAT]        = 'float';
569
-        $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY]    = 'int(11)';
570
-        $this->_dbTypesArray[XOBJ_DTYPE_URLLINK]      = 'int(11)';
571
-        $this->_dbTypesArray[XOBJ_DTYPE_FILE]         = 'int(11)';
572
-        $this->_dbTypesArray[XOBJ_DTYPE_IMAGE]        = 'varchar(255)';
573
-    }
574
-
575
-    /**
576
-     * Use to execute a general query
577
-     *
578
-     * @param string $query   query that will be executed
579
-     * @param string $goodmsg message displayed on success
580
-     * @param string $badmsg  message displayed on error
581
-     *
582
-     * @return bool true if success, false if an error occured
583
-     *
584
-     */
585
-    public function runQuery($query, $goodmsg, $badmsg)
586
-    {
587
-        global $xoopsDB;
588
-        $ret = $xoopsDB->query($query);
589
-        if (!$ret) {
590
-            echo "&nbsp;&nbsp;$badmsg<br>";
591
-
592
-            return false;
593
-        } else {
594
-            echo "&nbsp;&nbsp;$goodmsg<br>";
595
-
596
-            return true;
597
-        }
598
-    }
599
-
600
-    /**
601
-     * Use to rename a table
602
-     *
603
-     * @param string $from name of the table to rename
604
-     * @param string $to   new name of the renamed table
605
-     *
606
-     * @return bool true if success, false if an error occured
607
-     */
608
-    public function renameTable($from, $to)
609
-    {
610
-        global $xoopsDB;
611
-        $from  = $xoopsDB->prefix($from);
612
-        $to    = $xoopsDB->prefix($to);
613
-        $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
614
-        $ret   = $xoopsDB->query($query);
615
-        if (!$ret) {
616
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
617
-
618
-            return false;
619
-        } else {
620
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
621
-
622
-            return true;
623
-        }
624
-    }
625
-
626
-    /**
627
-     * Use to update a table
628
-     *
629
-     * @param object $table {@link SmartDbTable} that will be updated
630
-     *
631
-     * @see SmartDbTable
632
-     *
633
-     * @return bool true if success, false if an error occured
634
-     */
635
-    public function updateTable($table)
636
-    {
637
-        global $xoopsDB;
638
-        $ret = true;
639
-        // If table has a structure, create the table
640
-        if ($table->getStructure()) {
641
-            $ret = $table->createTable() && $ret;
642
-        }
643
-        // If table is flag for drop, drop it
644
-        if ($table->_flagForDrop) {
645
-            $ret = $table->dropTable() && $ret;
646
-        }
647
-        // If table has data, insert it
648
-        if ($table->getData()) {
649
-            $ret = $table->addData() && $ret;
650
-        }
651
-        // If table has new fields to be added, add them
652
-        if ($table->getNewFields()) {
653
-            $ret = $table->addNewFields() && $ret;
654
-        }
655
-        // If table has altered field, alter the table
656
-        if ($table->getAlteredFields()) {
657
-            $ret = $table->alterTable() && $ret;
658
-        }
659
-        // If table has updated field values, update the table
660
-        if ($table->getUpdatedFields()) {
661
-            $ret = $table->updateFieldsValues($table) && $ret;
662
-        }
663
-        // If table has dropped field, alter the table
664
-        if ($table->getDroppedFields()) {
665
-            $ret = $table->dropFields($table) && $ret;
666
-        }
667
-        //felix
668
-        // If table has updated field values, update the table
669
-        if ($table->getUpdatedWhere()) {
670
-            $ret = $table->UpdateWhereValues($table) && $ret;
671
-        }
672
-
673
-        return $ret;
674
-    }
675
-
676
-    /**
677
-     * @param $module
678
-     * @param $item
679
-     */
680
-    public function automaticUpgrade($module, $item)
681
-    {
682
-        if (is_array($item)) {
683
-            foreach ($item as $v) {
684
-                $this->upgradeObjectItem($module, $v);
685
-            }
686
-        } else {
687
-            $this->upgradeObjectItem($module, $item);
688
-        }
689
-    }
690
-
691
-    /**
692
-     * @param $var
693
-     * @return string
694
-     */
695
-    public function getFieldTypeFromVar($var)
696
-    {
697
-        $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text';
698
-
699
-        return $ret;
700
-    }
701
-
702
-    /**
703
-     * @param         $var
704
-     * @param  bool   $key
705
-     * @return string
706
-     */
707
-    public function getFieldDefaultFromVar($var, $key = false)
708
-    {
709
-        if ($var['value']) {
710
-            return $var['value'];
711
-        } else {
712
-            if (in_array($var['data_type'], array(
713
-                XOBJ_DTYPE_INT,
714
-                XOBJ_DTYPE_STIME,
715
-                XOBJ_DTYPE_MTIME,
716
-                XOBJ_DTYPE_LTIME,
717
-                XOBJ_DTYPE_TIME_ONLY,
718
-                XOBJ_DTYPE_URLLINK,
719
-                XOBJ_DTYPE_FILE
720
-            ))) {
721
-                return '0';
722
-            } else {
723
-                return '';
724
-            }
725
-        }
726
-    }
727
-
728
-    /**
729
-     * @param $module
730
-     * @param $item
731
-     * @return bool
732
-     */
733
-    public function upgradeObjectItem($module, $item)
734
-    {
735
-        $moduleHandler = xoops_getModuleHandler($item, $module);
736
-        if (!$moduleHandler) {
737
-            return false;
738
-        }
739
-
740
-        $table      = new SmartDbTable($module . '_' . $item);
741
-        $object     = $moduleHandler->create();
742
-        $objectVars = $object->getVars();
743
-
744
-        if (!$table->exists()) {
745
-            // table was never created, let's do it
746
-            $structure = '';
747
-            foreach ($objectVars as $key => $var) {
748
-                if ($var['persistent']) {
749
-                    $type = $this->getFieldTypeFromVar($var);
750
-                    if ($key == $moduleHandler->keyName) {
751
-                        $extra = 'auto_increment';
752
-                    } else {
753
-                        $default = $this->getFieldDefaultFromVar($var);
754
-                        $extra   = "default '$default'
548
+	public $_dbTypesArray;
549
+
550
+	/**
551
+	 * SmartobjectDbupdater constructor.
552
+	 */
553
+	public function __construct()
554
+	{
555
+		$this->_dbTypesArray[XOBJ_DTYPE_TXTBOX]       = 'varchar(255)';
556
+		$this->_dbTypesArray[XOBJ_DTYPE_TXTAREA]      = 'text';
557
+		$this->_dbTypesArray[XOBJ_DTYPE_INT]          = 'int(11)';
558
+		$this->_dbTypesArray[XOBJ_DTYPE_URL]          = 'varchar(255)';
559
+		$this->_dbTypesArray[XOBJ_DTYPE_EMAIL]        = 'varchar(255)';
560
+		$this->_dbTypesArray[XOBJ_DTYPE_ARRAY]        = 'text';
561
+		$this->_dbTypesArray[XOBJ_DTYPE_OTHER]        = 'text';
562
+		$this->_dbTypesArray[XOBJ_DTYPE_SOURCE]       = 'text';
563
+		$this->_dbTypesArray[XOBJ_DTYPE_STIME]        = 'int(11)';
564
+		$this->_dbTypesArray[XOBJ_DTYPE_MTIME]        = 'int(11)';
565
+		$this->_dbTypesArray[XOBJ_DTYPE_LTIME]        = 'int(11)';
566
+		$this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text';
567
+		$this->_dbTypesArray[XOBJ_DTYPE_CURRENCY]     = 'text';
568
+		$this->_dbTypesArray[XOBJ_DTYPE_FLOAT]        = 'float';
569
+		$this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY]    = 'int(11)';
570
+		$this->_dbTypesArray[XOBJ_DTYPE_URLLINK]      = 'int(11)';
571
+		$this->_dbTypesArray[XOBJ_DTYPE_FILE]         = 'int(11)';
572
+		$this->_dbTypesArray[XOBJ_DTYPE_IMAGE]        = 'varchar(255)';
573
+	}
574
+
575
+	/**
576
+	 * Use to execute a general query
577
+	 *
578
+	 * @param string $query   query that will be executed
579
+	 * @param string $goodmsg message displayed on success
580
+	 * @param string $badmsg  message displayed on error
581
+	 *
582
+	 * @return bool true if success, false if an error occured
583
+	 *
584
+	 */
585
+	public function runQuery($query, $goodmsg, $badmsg)
586
+	{
587
+		global $xoopsDB;
588
+		$ret = $xoopsDB->query($query);
589
+		if (!$ret) {
590
+			echo "&nbsp;&nbsp;$badmsg<br>";
591
+
592
+			return false;
593
+		} else {
594
+			echo "&nbsp;&nbsp;$goodmsg<br>";
595
+
596
+			return true;
597
+		}
598
+	}
599
+
600
+	/**
601
+	 * Use to rename a table
602
+	 *
603
+	 * @param string $from name of the table to rename
604
+	 * @param string $to   new name of the renamed table
605
+	 *
606
+	 * @return bool true if success, false if an error occured
607
+	 */
608
+	public function renameTable($from, $to)
609
+	{
610
+		global $xoopsDB;
611
+		$from  = $xoopsDB->prefix($from);
612
+		$to    = $xoopsDB->prefix($to);
613
+		$query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
614
+		$ret   = $xoopsDB->query($query);
615
+		if (!$ret) {
616
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
617
+
618
+			return false;
619
+		} else {
620
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
621
+
622
+			return true;
623
+		}
624
+	}
625
+
626
+	/**
627
+	 * Use to update a table
628
+	 *
629
+	 * @param object $table {@link SmartDbTable} that will be updated
630
+	 *
631
+	 * @see SmartDbTable
632
+	 *
633
+	 * @return bool true if success, false if an error occured
634
+	 */
635
+	public function updateTable($table)
636
+	{
637
+		global $xoopsDB;
638
+		$ret = true;
639
+		// If table has a structure, create the table
640
+		if ($table->getStructure()) {
641
+			$ret = $table->createTable() && $ret;
642
+		}
643
+		// If table is flag for drop, drop it
644
+		if ($table->_flagForDrop) {
645
+			$ret = $table->dropTable() && $ret;
646
+		}
647
+		// If table has data, insert it
648
+		if ($table->getData()) {
649
+			$ret = $table->addData() && $ret;
650
+		}
651
+		// If table has new fields to be added, add them
652
+		if ($table->getNewFields()) {
653
+			$ret = $table->addNewFields() && $ret;
654
+		}
655
+		// If table has altered field, alter the table
656
+		if ($table->getAlteredFields()) {
657
+			$ret = $table->alterTable() && $ret;
658
+		}
659
+		// If table has updated field values, update the table
660
+		if ($table->getUpdatedFields()) {
661
+			$ret = $table->updateFieldsValues($table) && $ret;
662
+		}
663
+		// If table has dropped field, alter the table
664
+		if ($table->getDroppedFields()) {
665
+			$ret = $table->dropFields($table) && $ret;
666
+		}
667
+		//felix
668
+		// If table has updated field values, update the table
669
+		if ($table->getUpdatedWhere()) {
670
+			$ret = $table->UpdateWhereValues($table) && $ret;
671
+		}
672
+
673
+		return $ret;
674
+	}
675
+
676
+	/**
677
+	 * @param $module
678
+	 * @param $item
679
+	 */
680
+	public function automaticUpgrade($module, $item)
681
+	{
682
+		if (is_array($item)) {
683
+			foreach ($item as $v) {
684
+				$this->upgradeObjectItem($module, $v);
685
+			}
686
+		} else {
687
+			$this->upgradeObjectItem($module, $item);
688
+		}
689
+	}
690
+
691
+	/**
692
+	 * @param $var
693
+	 * @return string
694
+	 */
695
+	public function getFieldTypeFromVar($var)
696
+	{
697
+		$ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text';
698
+
699
+		return $ret;
700
+	}
701
+
702
+	/**
703
+	 * @param         $var
704
+	 * @param  bool   $key
705
+	 * @return string
706
+	 */
707
+	public function getFieldDefaultFromVar($var, $key = false)
708
+	{
709
+		if ($var['value']) {
710
+			return $var['value'];
711
+		} else {
712
+			if (in_array($var['data_type'], array(
713
+				XOBJ_DTYPE_INT,
714
+				XOBJ_DTYPE_STIME,
715
+				XOBJ_DTYPE_MTIME,
716
+				XOBJ_DTYPE_LTIME,
717
+				XOBJ_DTYPE_TIME_ONLY,
718
+				XOBJ_DTYPE_URLLINK,
719
+				XOBJ_DTYPE_FILE
720
+			))) {
721
+				return '0';
722
+			} else {
723
+				return '';
724
+			}
725
+		}
726
+	}
727
+
728
+	/**
729
+	 * @param $module
730
+	 * @param $item
731
+	 * @return bool
732
+	 */
733
+	public function upgradeObjectItem($module, $item)
734
+	{
735
+		$moduleHandler = xoops_getModuleHandler($item, $module);
736
+		if (!$moduleHandler) {
737
+			return false;
738
+		}
739
+
740
+		$table      = new SmartDbTable($module . '_' . $item);
741
+		$object     = $moduleHandler->create();
742
+		$objectVars = $object->getVars();
743
+
744
+		if (!$table->exists()) {
745
+			// table was never created, let's do it
746
+			$structure = '';
747
+			foreach ($objectVars as $key => $var) {
748
+				if ($var['persistent']) {
749
+					$type = $this->getFieldTypeFromVar($var);
750
+					if ($key == $moduleHandler->keyName) {
751
+						$extra = 'auto_increment';
752
+					} else {
753
+						$default = $this->getFieldDefaultFromVar($var);
754
+						$extra   = "default '$default'
755 755
 ";
756
-                    }
757
-                    $structure .= "`$key` $type not null $extra,
756
+					}
757
+					$structure .= "`$key` $type not null $extra,
758 758
 ";
759
-                }
760
-            }
761
-            $structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
759
+				}
760
+			}
761
+			$structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
762 762
 ';
763
-            $table->setStructure($structure);
764
-            if (!$this->updateTable($table)) {
765
-                /**
766
-                 * @todo trap the errors
767
-                 */
768
-            }
769
-        } else {
770
-            $existingFieldsArray = $table->getExistingFieldsArray();
771
-            foreach ($objectVars as $key => $var) {
772
-                if ($var['persistent']) {
773
-                    if (!isset($existingFieldsArray[$key])) {
774
-                        // the fiels does not exist, let's create it
775
-                        $type    = $this->getFieldTypeFromVar($var);
776
-                        $default = $this->getFieldDefaultFromVar($var);
777
-                        $table->addNewField($key, "$type not null default '$default'");
778
-                    } else {
779
-                        // if field already exists, let's check if the definition is correct
780
-                        $definition = strtolower($existingFieldsArray[$key]);
781
-                        $type       = $this->getFieldTypeFromVar($var);
782
-                        if ($key == $moduleHandler->keyName) {
783
-                            $extra = 'auto_increment';
784
-                        } else {
785
-                            $default = $this->getFieldDefaultFromVar($var, $key);
786
-                            $extra   = "default '$default'";
787
-                        }
788
-                        $actual_definition = "$type not null $extra";
789
-                        if ($definition != $actual_definition) {
790
-                            $table->addAlteredField($key, $actual_definition);
791
-                        }
792
-                    }
793
-                }
794
-            }
795
-
796
-            // check to see if there are some unused fields left in the table
797
-            foreach ($existingFieldsArray as $key => $v) {
798
-                if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) {
799
-                    $table->addDroppedField($key);
800
-                }
801
-            }
802
-
803
-            if (!$this->updateTable($table)) {
804
-                /**
805
-                 * @todo trap the errors
806
-                 */
807
-            }
808
-        }
809
-    }
810
-
811
-    /**
812
-     * @param $module
813
-     * @return bool
814
-     */
815
-    public function moduleUpgrade(XoopsModule $module)
816
-    {
817
-        $dirname = $module->getVar('dirname');
818
-
819
-        ob_start();
820
-
821
-        $table = new SmartDbTable($dirname . '_meta');
822
-        if (!$table->exists()) {
823
-            $table->setStructure("
763
+			$table->setStructure($structure);
764
+			if (!$this->updateTable($table)) {
765
+				/**
766
+				 * @todo trap the errors
767
+				 */
768
+			}
769
+		} else {
770
+			$existingFieldsArray = $table->getExistingFieldsArray();
771
+			foreach ($objectVars as $key => $var) {
772
+				if ($var['persistent']) {
773
+					if (!isset($existingFieldsArray[$key])) {
774
+						// the fiels does not exist, let's create it
775
+						$type    = $this->getFieldTypeFromVar($var);
776
+						$default = $this->getFieldDefaultFromVar($var);
777
+						$table->addNewField($key, "$type not null default '$default'");
778
+					} else {
779
+						// if field already exists, let's check if the definition is correct
780
+						$definition = strtolower($existingFieldsArray[$key]);
781
+						$type       = $this->getFieldTypeFromVar($var);
782
+						if ($key == $moduleHandler->keyName) {
783
+							$extra = 'auto_increment';
784
+						} else {
785
+							$default = $this->getFieldDefaultFromVar($var, $key);
786
+							$extra   = "default '$default'";
787
+						}
788
+						$actual_definition = "$type not null $extra";
789
+						if ($definition != $actual_definition) {
790
+							$table->addAlteredField($key, $actual_definition);
791
+						}
792
+					}
793
+				}
794
+			}
795
+
796
+			// check to see if there are some unused fields left in the table
797
+			foreach ($existingFieldsArray as $key => $v) {
798
+				if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) {
799
+					$table->addDroppedField($key);
800
+				}
801
+			}
802
+
803
+			if (!$this->updateTable($table)) {
804
+				/**
805
+				 * @todo trap the errors
806
+				 */
807
+			}
808
+		}
809
+	}
810
+
811
+	/**
812
+	 * @param $module
813
+	 * @return bool
814
+	 */
815
+	public function moduleUpgrade(XoopsModule $module)
816
+	{
817
+		$dirname = $module->getVar('dirname');
818
+
819
+		ob_start();
820
+
821
+		$table = new SmartDbTable($dirname . '_meta');
822
+		if (!$table->exists()) {
823
+			$table->setStructure("
824 824
               `metakey` varchar(50) NOT NULL default '',
825 825
               `metavalue` varchar(255) NOT NULL default '',
826 826
               PRIMARY KEY (`metakey`)");
827
-            $table->setData("'version',0");
828
-            if (!$this->updateTable($table)) {
829
-                /**
830
-                 * @todo trap the errors
831
-                 */
832
-            }
833
-        }
834
-
835
-        $dbVersion = smart_GetMeta('version', $dirname);
836
-        if (!$dbVersion) {
837
-            $dbVersion = 0;
838
-        }
839
-        $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
840
-        echo 'Database version: ' . $dbVersion . '<br>';
841
-        echo 'New database version: ' . $newDbVersion . '<br>';
842
-
843
-        if ($newDbVersion > $dbVersion) {
844
-            for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
845
-                $upgrade_function = $dirname . '_db_upgrade_' . $i;
846
-                if (function_exists($upgrade_function)) {
847
-                    $upgrade_function();
848
-                }
849
-            }
850
-        }
851
-
852
-        echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
853
-
854
-        // if there is a function to execute for this DB version, let's do it
855
-        //$function_
856
-
857
-        $module_info = smart_getModuleInfo($dirname);
858
-        $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
859
-
860
-        echo '</code>';
861
-
862
-        $feedback = ob_get_clean();
863
-        if (method_exists($module, 'setMessage')) {
864
-            $module->setMessage($feedback);
865
-        } else {
866
-            echo $feedback;
867
-        }
868
-        smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current
869
-
870
-        return true;
871
-    }
827
+			$table->setData("'version',0");
828
+			if (!$this->updateTable($table)) {
829
+				/**
830
+				 * @todo trap the errors
831
+				 */
832
+			}
833
+		}
834
+
835
+		$dbVersion = smart_GetMeta('version', $dirname);
836
+		if (!$dbVersion) {
837
+			$dbVersion = 0;
838
+		}
839
+		$newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
840
+		echo 'Database version: ' . $dbVersion . '<br>';
841
+		echo 'New database version: ' . $newDbVersion . '<br>';
842
+
843
+		if ($newDbVersion > $dbVersion) {
844
+			for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
845
+				$upgrade_function = $dirname . '_db_upgrade_' . $i;
846
+				if (function_exists($upgrade_function)) {
847
+					$upgrade_function();
848
+				}
849
+			}
850
+		}
851
+
852
+		echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
853
+
854
+		// if there is a function to execute for this DB version, let's do it
855
+		//$function_
856
+
857
+		$module_info = smart_getModuleInfo($dirname);
858
+		$this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
859
+
860
+		echo '</code>';
861
+
862
+		$feedback = ob_get_clean();
863
+		if (method_exists($module, 'setMessage')) {
864
+			$module->setMessage($feedback);
865
+		} else {
866
+			echo $feedback;
867
+		}
868
+		smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current
869
+
870
+		return true;
871
+	}
872 872
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
  */
19 19
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
20 20
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
21
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
21
+    require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
22 22
 }
23 23
 /**
24 24
  * Include the language constants for the SmartObjectDBUpdater
25 25
  */
26 26
 global $xoopsConfig;
27
-$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php';
27
+$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php';
28 28
 if (!file_exists($common_file)) {
29
-    $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
29
+    $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php';
30 30
 }
31 31
 include $common_file;
32 32
 
@@ -123,20 +123,20 @@  discard block
 block discarded – undo
123 123
     public function getExistingFieldsArray()
124 124
     {
125 125
         global $xoopsDB;
126
-        $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
126
+        $result = $xoopsDB->query('SHOW COLUMNS FROM '.$this->name());
127 127
         while ($existing_field = $xoopsDB->fetchArray($result)) {
128 128
             $fields[$existing_field['Field']] = $existing_field['Type'];
129 129
             if ($existing_field['Null'] !== 'YES') {
130 130
                 $fields[$existing_field['Field']] .= ' NOT NULL';
131 131
             }
132 132
             if ($existing_field['Extra']) {
133
-                $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
133
+                $fields[$existing_field['Field']] .= ' '.$existing_field['Extra'];
134 134
             }
135 135
             if (!($existing_field['Default'] === null)
136 136
                 && ($existing_field['Default']
137 137
                     || $existing_field['Default'] === ''
138 138
                     || $existing_field['Default'] == 0)) {
139
-                $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
139
+                $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'";
140 140
             }
141 141
         }
142 142
 
@@ -222,9 +222,9 @@  discard block
 block discarded – undo
222 222
             $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
223 223
             $ret   = $xoopsDB->query($query);
224 224
             if (!$ret) {
225
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
225
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()).'<br>';
226 226
             } else {
227
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
227
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_ADD_DATA, $this->name()).'<br>';
228 228
             }
229 229
         }
230 230
 
@@ -376,13 +376,13 @@  discard block
 block discarded – undo
376 376
     {
377 377
         global $xoopsDB;
378 378
         $query = $this->getStructure();
379
-        $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
379
+        $query = 'CREATE TABLE `'.$this->name().'` ('.$query.") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
380 380
         //xoops_debug($query);
381 381
         $ret = $xoopsDB->query($query);
382 382
         if (!$ret) {
383
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
383
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
384 384
         } else {
385
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
385
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CREATE_TABLE, $this->name()).'<br>';
386 386
         }
387 387
 
388 388
         return $ret;
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
         $query = sprintf('DROP TABLE %s', $this->name());
401 401
         $ret   = $xoopsDB->query($query);
402 402
         if (!$ret) {
403
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
403
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
404 404
 
405 405
             return false;
406 406
         } else {
407
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
407
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROP_TABLE, $this->name()).'<br>';
408 408
 
409 409
             return true;
410 410
         }
@@ -430,9 +430,9 @@  discard block
 block discarded – undo
430 430
             $ret   = $ret && $xoopsDB->query($query);
431 431
             if ($alteredField['showerror']) {
432 432
                 if (!$ret) {
433
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
433
+                    echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()).' ('.$xoopsDB->error().')<br>';
434 434
                 } else {
435
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
435
+                    echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()).'<br>';
436 436
                 }
437 437
             }
438 438
         }
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
             //echo $query;
456 456
             $ret = $ret && $xoopsDB->query($query);
457 457
             if (!$ret) {
458
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
458
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()).'<br>';
459 459
             } else {
460
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
460
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()).'<br>';
461 461
             }
462 462
         }
463 463
 
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
             $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
479 479
             $ret   = $ret && $xoopsDB->query($query);
480 480
             if (!$ret) {
481
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
481
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
482 482
             } else {
483
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
483
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>';
484 484
             }
485 485
         }
486 486
 
@@ -501,9 +501,9 @@  discard block
 block discarded – undo
501 501
             //echo $query."<br>";
502 502
             $ret = $ret && $xoopsDB->query($query);
503 503
             if (!$ret) {
504
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
504
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
505 505
             } else {
506
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
506
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>';
507 507
             }
508 508
         }
509 509
 
@@ -524,9 +524,9 @@  discard block
 block discarded – undo
524 524
             $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
525 525
             $ret   = $ret && $xoopsDB->query($query);
526 526
             if (!$ret) {
527
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
527
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()).' ('.$xoopsDB->error().')<br>';
528 528
             } else {
529
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
529
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()).'<br>';
530 530
             }
531 531
         }
532 532
 
@@ -613,11 +613,11 @@  discard block
 block discarded – undo
613 613
         $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
614 614
         $ret   = $xoopsDB->query($query);
615 615
         if (!$ret) {
616
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
616
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from).'<br>';
617 617
 
618 618
             return false;
619 619
         } else {
620
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
620
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_RENAME_TABLE, $from, $to).'<br>';
621 621
 
622 622
             return true;
623 623
         }
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
             return false;
738 738
         }
739 739
 
740
-        $table      = new SmartDbTable($module . '_' . $item);
740
+        $table      = new SmartDbTable($module.'_'.$item);
741 741
         $object     = $moduleHandler->create();
742 742
         $objectVars = $object->getVars();
743 743
 
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 ";
759 759
                 }
760 760
             }
761
-            $structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
761
+            $structure .= 'PRIMARY KEY  (`'.$moduleHandler->keyName.'`)
762 762
 ';
763 763
             $table->setStructure($structure);
764 764
             if (!$this->updateTable($table)) {
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 
819 819
         ob_start();
820 820
 
821
-        $table = new SmartDbTable($dirname . '_meta');
821
+        $table = new SmartDbTable($dirname.'_meta');
822 822
         if (!$table->exists()) {
823 823
             $table->setStructure("
824 824
               `metakey` varchar(50) NOT NULL default '',
@@ -836,20 +836,20 @@  discard block
 block discarded – undo
836 836
         if (!$dbVersion) {
837 837
             $dbVersion = 0;
838 838
         }
839
-        $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
840
-        echo 'Database version: ' . $dbVersion . '<br>';
841
-        echo 'New database version: ' . $newDbVersion . '<br>';
839
+        $newDbVersion = constant(strtoupper($dirname.'_db_version')) ?: 0;
840
+        echo 'Database version: '.$dbVersion.'<br>';
841
+        echo 'New database version: '.$newDbVersion.'<br>';
842 842
 
843 843
         if ($newDbVersion > $dbVersion) {
844 844
             for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
845
-                $upgrade_function = $dirname . '_db_upgrade_' . $i;
845
+                $upgrade_function = $dirname.'_db_upgrade_'.$i;
846 846
                 if (function_exists($upgrade_function)) {
847 847
                     $upgrade_function();
848 848
                 }
849 849
             }
850 850
         }
851 851
 
852
-        echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
852
+        echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>';
853 853
 
854 854
         // if there is a function to execute for this DB version, let's do it
855 855
         //$function_
Please login to merge, or discard this patch.
class/smartobjectabout.php 2 patches
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -19,165 +19,165 @@
 block discarded – undo
19 19
  */
20 20
 class SmartobjectAbout
21 21
 {
22
-    public $_lang_aboutTitle;
23
-    public $_lang_author_info;
24
-    public $_lang_developer_lead;
25
-    public $_lang_developer_contributor;
26
-    public $_lang_developer_website;
27
-    public $_lang_developer_email;
28
-    public $_lang_developer_credits;
29
-    public $_lang_module_info;
30
-    public $_lang_module_status;
31
-    public $_lang_module_release_date;
32
-    public $_lang_module_demo;
33
-    public $_lang_module_support;
34
-    public $_lang_module_bug;
35
-    public $_lang_module_submit_bug;
36
-    public $_lang_module_feature;
37
-    public $_lang_module_submit_feature;
38
-    public $_lang_module_disclaimer;
39
-    public $_lang_author_word;
40
-    public $_lang_version_history;
41
-    public $_lang_by;
42
-    public $_tpl;
43
-
44
-    /**
45
-     * SmartobjectAbout constructor.
46
-     * @param string $aboutTitle
47
-     */
48
-    public function __construct($aboutTitle = 'About')
49
-    {
50
-        global $xoopsModule, $xoopsConfig;
51
-
52
-        $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
53
-        if (file_exists($fileName)) {
54
-            require_once $fileName;
55
-        } else {
56
-            require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
57
-        }
58
-        $this->_aboutTitle = $aboutTitle;
59
-
60
-        $this->_lang_developer_contributor = _CO_SOBJECT_DEVELOPER_CONTRIBUTOR;
61
-        $this->_lang_developer_website     = _CO_SOBJECT_DEVELOPER_WEBSITE;
62
-        $this->_lang_developer_email       = _CO_SOBJECT_DEVELOPER_EMAIL;
63
-        $this->_lang_developer_credits     = _CO_SOBJECT_DEVELOPER_CREDITS;
64
-        $this->_lang_module_info           = _CO_SOBJECT_MODULE_INFO;
65
-        $this->_lang_module_status         = _CO_SOBJECT_MODULE_STATUS;
66
-        $this->_lang_module_release_date   = _CO_SOBJECT_MODULE_RELEASE_DATE;
67
-        $this->_lang_module_demo           = _CO_SOBJECT_MODULE_DEMO;
68
-        $this->_lang_module_support        = _CO_SOBJECT_MODULE_SUPPORT;
69
-        $this->_lang_module_bug            = _CO_SOBJECT_MODULE_BUG;
70
-        $this->_lang_module_submit_bug     = _CO_SOBJECT_MODULE_SUBMIT_BUG;
71
-        $this->_lang_module_feature        = _CO_SOBJECT_MODULE_FEATURE;
72
-        $this->_lang_module_submit_feature = _CO_SOBJECT_MODULE_SUBMIT_FEATURE;
73
-        $this->_lang_module_disclaimer     = _CO_SOBJECT_MODULE_DISCLAIMER;
74
-        $this->_lang_author_word           = _CO_SOBJECT_AUTHOR_WORD;
75
-        $this->_lang_version_history       = _CO_SOBJECT_VERSION_HISTORY;
76
-    }
77
-
78
-    /**
79
-     * @param $value
80
-     * @return mixed
81
-     */
82
-    public function sanitize($value)
83
-    {
84
-        $myts = MyTextSanitizer::getInstance();
85
-
86
-        return $myts->displayTarea($value, 1);
87
-    }
88
-
89
-    public function render()
90
-    {
91
-        /**
92
-         * @todo move the output to a template
93
-         * @todo make the output XHTML compliant
94
-         */
95
-
96
-        $myts = MyTextSanitizer::getInstance();
97
-
98
-        global $xoopsModule;
99
-
100
-        smart_xoops_cp_header();
101
-
102
-        /** @var XoopsModuleHandler $moduleHandler */
103
-        $moduleHandler = xoops_getHandler('module');
104
-        $versioninfo   = $moduleHandler->get($xoopsModule->getVar('mid'));
105
-
106
-        //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name'));
107
-
108
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
109
-
110
-        // ---
111
-        // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated.
112
-        //      $this->_tpl = new XoopsTpl();
113
-        $this->_tpl = new XoopsTpl();
114
-        // ---
115
-
116
-        $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/');
117
-        $this->_tpl->assign('module_image', $versioninfo->getInfo('image'));
118
-        $this->_tpl->assign('module_name', $versioninfo->getInfo('name'));
119
-        $this->_tpl->assign('module_version', $versioninfo->getInfo('version'));
120
-        $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version'));
121
-
122
-        // Left headings...
123
-        if ($versioninfo->getInfo('author_realname') !== '') {
124
-            $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')';
125
-        } else {
126
-            $author_name = $versioninfo->getInfo('author');
127
-        }
128
-        $this->_tpl->assign('module_author_name', $author_name);
129
-
130
-        $this->_tpl->assign('module_license', $versioninfo->getInfo('license'));
131
-
132
-        $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits'));
133
-
134
-        // Developers Information
135
-        $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead'));
136
-        $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor'));
137
-        $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url'));
138
-        $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name'));
139
-        $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email'));
140
-
141
-        $people = $versioninfo->getInfo('people');
142
-        if ($people) {
143
-            $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map(array($this, 'sanitize'), $people['developers']) : false);
144
-            $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map(array($this, 'sanitize'), $people['testers']) : false);
145
-            $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map(array($this, 'sanitize'), $people['translators']) : false);
146
-            $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map(array($this, 'sanitize'), $people['documenters']) : false);
147
-            $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map(array($this, 'sanitize'), $people['other']) : false);
148
-        }
149
-        //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email'));
150
-
151
-        // Module Development information
152
-        $this->_tpl->assign('module_date', $versioninfo->getInfo('date'));
153
-        $this->_tpl->assign('module_status', $versioninfo->getInfo('status'));
154
-        $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url'));
155
-        $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name'));
156
-        $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url'));
157
-        $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name'));
158
-        $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug'));
159
-        $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature'));
160
-
161
-        // Warning
162
-        $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning')));
163
-
164
-        // Author's note
165
-        $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word'));
166
-
167
-        // For changelog thanks to 3Dev
168
-        global $xoopsModule;
169
-        $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt';
170
-        if (is_file($filename)) {
171
-            $filesize = filesize($filename);
172
-            $handle   = fopen($filename, 'r');
173
-            $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true));
174
-            fclose($handle);
175
-        }
176
-
177
-        $this->_tpl->display('db:smartobject_about.tpl');
178
-
179
-        smart_modFooter();
180
-
181
-        xoops_cp_footer();
182
-    }
22
+	public $_lang_aboutTitle;
23
+	public $_lang_author_info;
24
+	public $_lang_developer_lead;
25
+	public $_lang_developer_contributor;
26
+	public $_lang_developer_website;
27
+	public $_lang_developer_email;
28
+	public $_lang_developer_credits;
29
+	public $_lang_module_info;
30
+	public $_lang_module_status;
31
+	public $_lang_module_release_date;
32
+	public $_lang_module_demo;
33
+	public $_lang_module_support;
34
+	public $_lang_module_bug;
35
+	public $_lang_module_submit_bug;
36
+	public $_lang_module_feature;
37
+	public $_lang_module_submit_feature;
38
+	public $_lang_module_disclaimer;
39
+	public $_lang_author_word;
40
+	public $_lang_version_history;
41
+	public $_lang_by;
42
+	public $_tpl;
43
+
44
+	/**
45
+	 * SmartobjectAbout constructor.
46
+	 * @param string $aboutTitle
47
+	 */
48
+	public function __construct($aboutTitle = 'About')
49
+	{
50
+		global $xoopsModule, $xoopsConfig;
51
+
52
+		$fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
53
+		if (file_exists($fileName)) {
54
+			require_once $fileName;
55
+		} else {
56
+			require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
57
+		}
58
+		$this->_aboutTitle = $aboutTitle;
59
+
60
+		$this->_lang_developer_contributor = _CO_SOBJECT_DEVELOPER_CONTRIBUTOR;
61
+		$this->_lang_developer_website     = _CO_SOBJECT_DEVELOPER_WEBSITE;
62
+		$this->_lang_developer_email       = _CO_SOBJECT_DEVELOPER_EMAIL;
63
+		$this->_lang_developer_credits     = _CO_SOBJECT_DEVELOPER_CREDITS;
64
+		$this->_lang_module_info           = _CO_SOBJECT_MODULE_INFO;
65
+		$this->_lang_module_status         = _CO_SOBJECT_MODULE_STATUS;
66
+		$this->_lang_module_release_date   = _CO_SOBJECT_MODULE_RELEASE_DATE;
67
+		$this->_lang_module_demo           = _CO_SOBJECT_MODULE_DEMO;
68
+		$this->_lang_module_support        = _CO_SOBJECT_MODULE_SUPPORT;
69
+		$this->_lang_module_bug            = _CO_SOBJECT_MODULE_BUG;
70
+		$this->_lang_module_submit_bug     = _CO_SOBJECT_MODULE_SUBMIT_BUG;
71
+		$this->_lang_module_feature        = _CO_SOBJECT_MODULE_FEATURE;
72
+		$this->_lang_module_submit_feature = _CO_SOBJECT_MODULE_SUBMIT_FEATURE;
73
+		$this->_lang_module_disclaimer     = _CO_SOBJECT_MODULE_DISCLAIMER;
74
+		$this->_lang_author_word           = _CO_SOBJECT_AUTHOR_WORD;
75
+		$this->_lang_version_history       = _CO_SOBJECT_VERSION_HISTORY;
76
+	}
77
+
78
+	/**
79
+	 * @param $value
80
+	 * @return mixed
81
+	 */
82
+	public function sanitize($value)
83
+	{
84
+		$myts = MyTextSanitizer::getInstance();
85
+
86
+		return $myts->displayTarea($value, 1);
87
+	}
88
+
89
+	public function render()
90
+	{
91
+		/**
92
+		 * @todo move the output to a template
93
+		 * @todo make the output XHTML compliant
94
+		 */
95
+
96
+		$myts = MyTextSanitizer::getInstance();
97
+
98
+		global $xoopsModule;
99
+
100
+		smart_xoops_cp_header();
101
+
102
+		/** @var XoopsModuleHandler $moduleHandler */
103
+		$moduleHandler = xoops_getHandler('module');
104
+		$versioninfo   = $moduleHandler->get($xoopsModule->getVar('mid'));
105
+
106
+		//smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name'));
107
+
108
+		require_once XOOPS_ROOT_PATH . '/class/template.php';
109
+
110
+		// ---
111
+		// 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated.
112
+		//      $this->_tpl = new XoopsTpl();
113
+		$this->_tpl = new XoopsTpl();
114
+		// ---
115
+
116
+		$this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/');
117
+		$this->_tpl->assign('module_image', $versioninfo->getInfo('image'));
118
+		$this->_tpl->assign('module_name', $versioninfo->getInfo('name'));
119
+		$this->_tpl->assign('module_version', $versioninfo->getInfo('version'));
120
+		$this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version'));
121
+
122
+		// Left headings...
123
+		if ($versioninfo->getInfo('author_realname') !== '') {
124
+			$author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')';
125
+		} else {
126
+			$author_name = $versioninfo->getInfo('author');
127
+		}
128
+		$this->_tpl->assign('module_author_name', $author_name);
129
+
130
+		$this->_tpl->assign('module_license', $versioninfo->getInfo('license'));
131
+
132
+		$this->_tpl->assign('module_credits', $versioninfo->getInfo('credits'));
133
+
134
+		// Developers Information
135
+		$this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead'));
136
+		$this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor'));
137
+		$this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url'));
138
+		$this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name'));
139
+		$this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email'));
140
+
141
+		$people = $versioninfo->getInfo('people');
142
+		if ($people) {
143
+			$this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map(array($this, 'sanitize'), $people['developers']) : false);
144
+			$this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map(array($this, 'sanitize'), $people['testers']) : false);
145
+			$this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map(array($this, 'sanitize'), $people['translators']) : false);
146
+			$this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map(array($this, 'sanitize'), $people['documenters']) : false);
147
+			$this->_tpl->assign('module_people_other', isset($people['other']) ? array_map(array($this, 'sanitize'), $people['other']) : false);
148
+		}
149
+		//$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email'));
150
+
151
+		// Module Development information
152
+		$this->_tpl->assign('module_date', $versioninfo->getInfo('date'));
153
+		$this->_tpl->assign('module_status', $versioninfo->getInfo('status'));
154
+		$this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url'));
155
+		$this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name'));
156
+		$this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url'));
157
+		$this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name'));
158
+		$this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug'));
159
+		$this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature'));
160
+
161
+		// Warning
162
+		$this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning')));
163
+
164
+		// Author's note
165
+		$this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word'));
166
+
167
+		// For changelog thanks to 3Dev
168
+		global $xoopsModule;
169
+		$filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt';
170
+		if (is_file($filename)) {
171
+			$filesize = filesize($filename);
172
+			$handle   = fopen($filename, 'r');
173
+			$this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true));
174
+			fclose($handle);
175
+		}
176
+
177
+		$this->_tpl->display('db:smartobject_about.tpl');
178
+
179
+		smart_modFooter();
180
+
181
+		xoops_cp_footer();
182
+	}
183 183
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
     {
50 50
         global $xoopsModule, $xoopsConfig;
51 51
 
52
-        $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
52
+        $fileName = XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/modinfo.php';
53 53
         if (file_exists($fileName)) {
54 54
             require_once $fileName;
55 55
         } else {
56
-            require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
56
+            require_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/english/modinfo.php';
57 57
         }
58 58
         $this->_aboutTitle = $aboutTitle;
59 59
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 
106 106
         //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name'));
107 107
 
108
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
108
+        require_once XOOPS_ROOT_PATH.'/class/template.php';
109 109
 
110 110
         // ---
111 111
         // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated.
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         $this->_tpl = new XoopsTpl();
114 114
         // ---
115 115
 
116
-        $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/');
116
+        $this->_tpl->assign('module_url', XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/');
117 117
         $this->_tpl->assign('module_image', $versioninfo->getInfo('image'));
118 118
         $this->_tpl->assign('module_name', $versioninfo->getInfo('name'));
119 119
         $this->_tpl->assign('module_version', $versioninfo->getInfo('version'));
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 
122 122
         // Left headings...
123 123
         if ($versioninfo->getInfo('author_realname') !== '') {
124
-            $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')';
124
+            $author_name = $versioninfo->getInfo('author').' ('.$versioninfo->getInfo('author_realname').')';
125 125
         } else {
126 126
             $author_name = $versioninfo->getInfo('author');
127 127
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
         // For changelog thanks to 3Dev
168 168
         global $xoopsModule;
169
-        $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt';
169
+        $filename = XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/changelog.txt';
170 170
         if (is_file($filename)) {
171 171
             $filesize = filesize($filename);
172 172
             $handle   = fopen($filename, 'r');
Please login to merge, or discard this patch.
class/smartobjecttag.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
  */
36 36
 class SmartobjectTag extends SmartMlObject
37 37
 {
38
-    /**
39
-     * SmartobjectTag constructor.
40
-     */
41
-    public function __construct()
42
-    {
43
-        $this->initVar('tagid', XOBJ_DTYPE_INT, '', true);
44
-        $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true);
45
-        $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC);
46
-        $this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC);
38
+	/**
39
+	 * SmartobjectTag constructor.
40
+	 */
41
+	public function __construct()
42
+	{
43
+		$this->initVar('tagid', XOBJ_DTYPE_INT, '', true);
44
+		$this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true);
45
+		$this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC);
46
+		$this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC);
47 47
 
48
-        // call parent constructor to get Multilanguage field initiated
49
-        $this->SmartMlObject();
50
-    }
48
+		// call parent constructor to get Multilanguage field initiated
49
+		$this->SmartMlObject();
50
+	}
51 51
 }
52 52
 
53 53
 /**
@@ -55,27 +55,27 @@  discard block
 block discarded – undo
55 55
  */
56 56
 class SmartobjectTagHandler extends SmartPersistableMlObjectHandler
57 57
 {
58
-    /**
59
-     * SmartobjectTagHandler constructor.
60
-     * @param XoopsDatabase $db
61
-     */
62
-    public function __construct(XoopsDatabase $db)
63
-    {
64
-        parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject');
65
-    }
58
+	/**
59
+	 * SmartobjectTagHandler constructor.
60
+	 * @param XoopsDatabase $db
61
+	 */
62
+	public function __construct(XoopsDatabase $db)
63
+	{
64
+		parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject');
65
+	}
66 66
 
67
-    /**
68
-     * @return mixed
69
-     */
70
-    public function getLanguages()
71
-    {
72
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
73
-        $aLanguages     = XoopsLists::getLangList();
74
-        $ret['default'] = _CO_SOBJECT_ALL;
75
-        foreach ($aLanguages as $lang) {
76
-            $ret[$lang] = $lang;
77
-        }
67
+	/**
68
+	 * @return mixed
69
+	 */
70
+	public function getLanguages()
71
+	{
72
+		require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
73
+		$aLanguages     = XoopsLists::getLangList();
74
+		$ret['default'] = _CO_SOBJECT_ALL;
75
+		foreach ($aLanguages as $lang) {
76
+			$ret[$lang] = $lang;
77
+		}
78 78
 
79
-        return $ret;
80
-    }
79
+		return $ret;
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 // -------------------------------------------------------------------------//
29 29
 
30 30
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
31
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartmlobject.php';
31
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartmlobject.php';
32 32
 
33 33
 /**
34 34
  * Class SmartobjectTag
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function getLanguages()
71 71
     {
72
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
72
+        require_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
73 73
         $aLanguages     = XoopsLists::getLangList();
74 74
         $ret['default'] = _CO_SOBJECT_ALL;
75 75
         foreach ($aLanguages as $lang) {
Please login to merge, or discard this patch.
class/smartplugins.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -5,68 +5,68 @@  discard block
 block discarded – undo
5 5
  */
6 6
 class SmartPlugin
7 7
 {
8
-    public $_infoArray;
9
-
10
-    /**
11
-     * SmartPlugin constructor.
12
-     * @param $array
13
-     */
14
-    public function __construct($array)
15
-    {
16
-        $this->_infoArray = $array;
17
-    }
18
-
19
-    /**
20
-     * @param $item
21
-     * @return bool
22
-     */
23
-    public function getItemInfo($item)
24
-    {
25
-        if (isset($this->_infoArray['items'][$item])) {
26
-            return $this->_infoArray['items'][$item];
27
-        } else {
28
-            return false;
29
-        }
30
-    }
31
-
32
-    /**
33
-     * @return mixed
34
-     */
35
-    public function getItemList()
36
-    {
37
-        $itemsArray = $this->_infoArray['items'];
38
-        foreach ($itemsArray as $k => $v) {
39
-            $ret[$k] = $v['caption'];
40
-        }
41
-
42
-        return $ret;
43
-    }
44
-
45
-    /**
46
-     * @return bool|int|string
47
-     */
48
-    public function getItem()
49
-    {
50
-        $ret = false;
51
-        foreach ($this->_infoArray['items'] as $k => $v) {
52
-            $search_str = str_replace('%u', '', $v['url']);
53
-            if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) {
54
-                $ret = $k;
55
-                break;
56
-            }
57
-        }
58
-
59
-        return $ret;
60
-    }
61
-
62
-    /**
63
-     * @param $item
64
-     * @return mixed
65
-     */
66
-    public function getItemIdForItem($item)
67
-    {
68
-        return $_REQUEST[$this->_infoArray['items'][$item]['request']];
69
-    }
8
+	public $_infoArray;
9
+
10
+	/**
11
+	 * SmartPlugin constructor.
12
+	 * @param $array
13
+	 */
14
+	public function __construct($array)
15
+	{
16
+		$this->_infoArray = $array;
17
+	}
18
+
19
+	/**
20
+	 * @param $item
21
+	 * @return bool
22
+	 */
23
+	public function getItemInfo($item)
24
+	{
25
+		if (isset($this->_infoArray['items'][$item])) {
26
+			return $this->_infoArray['items'][$item];
27
+		} else {
28
+			return false;
29
+		}
30
+	}
31
+
32
+	/**
33
+	 * @return mixed
34
+	 */
35
+	public function getItemList()
36
+	{
37
+		$itemsArray = $this->_infoArray['items'];
38
+		foreach ($itemsArray as $k => $v) {
39
+			$ret[$k] = $v['caption'];
40
+		}
41
+
42
+		return $ret;
43
+	}
44
+
45
+	/**
46
+	 * @return bool|int|string
47
+	 */
48
+	public function getItem()
49
+	{
50
+		$ret = false;
51
+		foreach ($this->_infoArray['items'] as $k => $v) {
52
+			$search_str = str_replace('%u', '', $v['url']);
53
+			if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) {
54
+				$ret = $k;
55
+				break;
56
+			}
57
+		}
58
+
59
+		return $ret;
60
+	}
61
+
62
+	/**
63
+	 * @param $item
64
+	 * @return mixed
65
+	 */
66
+	public function getItemIdForItem($item)
67
+	{
68
+		return $_REQUEST[$this->_infoArray['items'][$item]['request']];
69
+	}
70 70
 }
71 71
 
72 72
 /**
@@ -74,57 +74,57 @@  discard block
 block discarded – undo
74 74
  */
75 75
 class SmartPluginHandler
76 76
 {
77
-    public $pluginPatterns = false;
78
-
79
-    /**
80
-     * @param $dirname
81
-     * @return bool|SmartPlugin
82
-     */
83
-    public function getPlugin($dirname)
84
-    {
85
-        $pluginName = SMARTOBJECT_ROOT_PATH . 'plugins/' . $dirname . '.php';
86
-        if (file_exists($pluginName)) {
87
-            require_once $pluginName;
88
-            $function = 'smartobject_plugin_' . $dirname;
89
-            if (function_exists($function)) {
90
-                $array = $function();
91
-                $ret   = new SmartPlugin($array);
92
-
93
-                return $ret;
94
-            }
95
-        }
96
-
97
-        return false;
98
-    }
99
-
100
-    /**
101
-     * @return array
102
-     */
103
-    public function getPluginsArray()
104
-    {
105
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
106
-
107
-        $moduleHandler = xoops_getHandler('module');
108
-        $criteria      = new CriteriaCompo();
109
-        $criteria->add(new Criteria('isactive', 1));
110
-        $tempModulesObj = $moduleHandler->getObjects($criteria);
111
-        $modulesObj     = array();
112
-        foreach ($tempModulesObj as $moduleObj) {
113
-            $modulesObj[$moduleObj->getVar('dirname')] = $moduleObj;
114
-        }
115
-
116
-        $aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH . 'plugins/');
117
-        $ret    = array();
118
-        foreach ($aFiles as $file) {
119
-            if (substr($file, strlen($file) - 4, 4) === '.php') {
120
-                $pluginName                = str_replace('.php', '', $file);
121
-                $module_xoops_version_file = XOOPS_ROOT_PATH . "/modules/$pluginName/xoops_version.php";
122
-                if (file_exists($module_xoops_version_file) && isset($modulesObj[$pluginName])) {
123
-                    $ret[$pluginName] = $modulesObj[$pluginName]->getVar('name');
124
-                }
125
-            }
126
-        }
127
-
128
-        return $ret;
129
-    }
77
+	public $pluginPatterns = false;
78
+
79
+	/**
80
+	 * @param $dirname
81
+	 * @return bool|SmartPlugin
82
+	 */
83
+	public function getPlugin($dirname)
84
+	{
85
+		$pluginName = SMARTOBJECT_ROOT_PATH . 'plugins/' . $dirname . '.php';
86
+		if (file_exists($pluginName)) {
87
+			require_once $pluginName;
88
+			$function = 'smartobject_plugin_' . $dirname;
89
+			if (function_exists($function)) {
90
+				$array = $function();
91
+				$ret   = new SmartPlugin($array);
92
+
93
+				return $ret;
94
+			}
95
+		}
96
+
97
+		return false;
98
+	}
99
+
100
+	/**
101
+	 * @return array
102
+	 */
103
+	public function getPluginsArray()
104
+	{
105
+		require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
106
+
107
+		$moduleHandler = xoops_getHandler('module');
108
+		$criteria      = new CriteriaCompo();
109
+		$criteria->add(new Criteria('isactive', 1));
110
+		$tempModulesObj = $moduleHandler->getObjects($criteria);
111
+		$modulesObj     = array();
112
+		foreach ($tempModulesObj as $moduleObj) {
113
+			$modulesObj[$moduleObj->getVar('dirname')] = $moduleObj;
114
+		}
115
+
116
+		$aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH . 'plugins/');
117
+		$ret    = array();
118
+		foreach ($aFiles as $file) {
119
+			if (substr($file, strlen($file) - 4, 4) === '.php') {
120
+				$pluginName                = str_replace('.php', '', $file);
121
+				$module_xoops_version_file = XOOPS_ROOT_PATH . "/modules/$pluginName/xoops_version.php";
122
+				if (file_exists($module_xoops_version_file) && isset($modulesObj[$pluginName])) {
123
+					$ret[$pluginName] = $modulesObj[$pluginName]->getVar('name');
124
+				}
125
+			}
126
+		}
127
+
128
+		return $ret;
129
+	}
130 130
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         $ret = false;
51 51
         foreach ($this->_infoArray['items'] as $k => $v) {
52 52
             $search_str = str_replace('%u', '', $v['url']);
53
-            if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) {
53
+            if (strpos($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], $search_str) > 0) {
54 54
                 $ret = $k;
55 55
                 break;
56 56
             }
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function getPlugin($dirname)
84 84
     {
85
-        $pluginName = SMARTOBJECT_ROOT_PATH . 'plugins/' . $dirname . '.php';
85
+        $pluginName = SMARTOBJECT_ROOT_PATH.'plugins/'.$dirname.'.php';
86 86
         if (file_exists($pluginName)) {
87 87
             require_once $pluginName;
88
-            $function = 'smartobject_plugin_' . $dirname;
88
+            $function = 'smartobject_plugin_'.$dirname;
89 89
             if (function_exists($function)) {
90 90
                 $array = $function();
91 91
                 $ret   = new SmartPlugin($array);
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     public function getPluginsArray()
104 104
     {
105
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
105
+        require_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
106 106
 
107 107
         $moduleHandler = xoops_getHandler('module');
108 108
         $criteria      = new CriteriaCompo();
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
             $modulesObj[$moduleObj->getVar('dirname')] = $moduleObj;
114 114
         }
115 115
 
116
-        $aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH . 'plugins/');
116
+        $aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH.'plugins/');
117 117
         $ret    = array();
118 118
         foreach ($aFiles as $file) {
119 119
             if (substr($file, strlen($file) - 4, 4) === '.php') {
120 120
                 $pluginName                = str_replace('.php', '', $file);
121
-                $module_xoops_version_file = XOOPS_ROOT_PATH . "/modules/$pluginName/xoops_version.php";
121
+                $module_xoops_version_file = XOOPS_ROOT_PATH."/modules/$pluginName/xoops_version.php";
122 122
                 if (file_exists($module_xoops_version_file) && isset($modulesObj[$pluginName])) {
123 123
                     $ret[$pluginName] = $modulesObj[$pluginName]->getVar('name');
124 124
                 }
Please login to merge, or discard this patch.
class/rating.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 
30 30
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
31 31
 
32
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
33
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartplugins.php';
32
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php';
33
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartplugins.php';
34 34
 
35 35
 /**
36 36
  * Class SmartobjectRating
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function getItemValue()
126 126
     {
127
-        $moduleUrl      = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/';
127
+        $moduleUrl      = XOOPS_URL.'/modules/'.$this->getVar('dirname', 'n').'/';
128 128
         $plugin         = $this->getModulePlugin();
129 129
         $pluginItemInfo = $plugin->getItemInfo($this->getVar('item'));
130 130
         if (!$pluginItemInfo) {
131 131
             return '';
132 132
         }
133 133
         $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid'));
134
-        $ret      = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>';
134
+        $ret      = '<a href="'.$moduleUrl.$itemPath.'">'.$pluginItemInfo['caption'].'</a>';
135 135
 
136 136
         return $ret;
137 137
     }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
     public function __construct(XoopsDatabase $db)
175 175
     {
176 176
         parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject');
177
-        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';
177
+        $this->generalSQL = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname.' INNER JOIN '.$this->db->prefix('users').' AS user ON '.$this->_itemname.'.uid=user.uid';
178 178
 
179 179
         $this->_rateOptions[1] = 1;
180 180
         $this->_rateOptions[2] = 2;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public function getRatingAverageByItemId($itemid, $dirname, $item)
219 219
     {
220
-        $sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
220
+        $sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM '.$this->table." WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
221 221
         $result = $this->db->query($sql);
222 222
         if (!$result) {
223 223
             return 0;
Please login to merge, or discard this patch.
class/smartaddto.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -10,66 +10,66 @@
 block discarded – undo
10 10
 
11 11
 class SmartAddTo
12 12
 {
13
-    public $_layout;
14
-    public $_method;
13
+	public $_layout;
14
+	public $_method;
15 15
 
16
-    /**
17
-     * Constructor of SmartAddTo
18
-     *
19
-     * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons
20
-     * @param int $method 0=directpage, 1=popup
21
-     */
22
-    public function __construct($layout = 0, $method = 1)
23
-    {
24
-        $layout = (int)$layout;
25
-        if ($layout < 0 || $layout > 3) {
26
-            $layout = 0;
27
-        }
28
-        $this->_layout = $layout;
16
+	/**
17
+	 * Constructor of SmartAddTo
18
+	 *
19
+	 * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons
20
+	 * @param int $method 0=directpage, 1=popup
21
+	 */
22
+	public function __construct($layout = 0, $method = 1)
23
+	{
24
+		$layout = (int)$layout;
25
+		if ($layout < 0 || $layout > 3) {
26
+			$layout = 0;
27
+		}
28
+		$this->_layout = $layout;
29 29
 
30
-        $method = (int)$method;
31
-        if ($method < 0 || $method > 1) {
32
-            $method = 1;
33
-        }
34
-        $this->_method = $method;
35
-    }
30
+		$method = (int)$method;
31
+		if ($method < 0 || $method > 1) {
32
+			$method = 1;
33
+		}
34
+		$this->_method = $method;
35
+	}
36 36
 
37
-    /**
38
-     * @param  bool $fetchOnly
39
-     * @return mixed|string|void
40
-     */
41
-    public function render($fetchOnly = false)
42
-    {
43
-        global $xoTheme, $xoopsTpl;
37
+	/**
38
+	 * @param  bool $fetchOnly
39
+	 * @return mixed|string|void
40
+	 */
41
+	public function render($fetchOnly = false)
42
+	{
43
+		global $xoTheme, $xoopsTpl;
44 44
 
45
-        $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
45
+		$xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
46 46
 
47
-        $xoopsTpl->assign('smartobject_addto_method', $this->_method);
48
-        $xoopsTpl->assign('smartobject_addto_layout', $this->_layout);
47
+		$xoopsTpl->assign('smartobject_addto_method', $this->_method);
48
+		$xoopsTpl->assign('smartobject_addto_layout', $this->_layout);
49 49
 
50
-        $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/');
50
+		$xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/');
51 51
 
52
-        if ($fetchOnly) {
53
-            return $xoopsTpl->fetch('db:smartobject_addto.tpl');
54
-        } else {
55
-            $xoopsTpl->display('db:smartobject_addto.tpl');
56
-        }
57
-    }
52
+		if ($fetchOnly) {
53
+			return $xoopsTpl->fetch('db:smartobject_addto.tpl');
54
+		} else {
55
+			$xoopsTpl->display('db:smartobject_addto.tpl');
56
+		}
57
+	}
58 58
 
59
-    /**
60
-     * @return array
61
-     */
62
-    public function renderForBlock()
63
-    {
64
-        global $xoTheme;
59
+	/**
60
+	 * @return array
61
+	 */
62
+	public function renderForBlock()
63
+	{
64
+		global $xoTheme;
65 65
 
66
-        $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
66
+		$xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
67 67
 
68
-        $block                             = array();
69
-        $block['smartobject_addto_method'] = $this->_method;
70
-        $block['smartobject_addto_layout'] = $this->_layout;
71
-        $block['smartobject_addto_url']    = SMARTOBJECT_URL . 'include/addto/';
68
+		$block                             = array();
69
+		$block['smartobject_addto_method'] = $this->_method;
70
+		$block['smartobject_addto_layout'] = $this->_layout;
71
+		$block['smartobject_addto_url']    = SMARTOBJECT_URL . 'include/addto/';
72 72
 
73
-        return $block;
74
-    }
73
+		return $block;
74
+	}
75 75
 }
Please login to merge, or discard this patch.
class/utility.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -5,149 +5,149 @@
 block discarded – undo
5 5
  */
6 6
 class SmartObjectUtility extends XoopsObject
7 7
 {
8
-    /**
9
-     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
10
-     *
11
-     * @param string $folder The full path of the directory to check
12
-     *
13
-     * @return void
14
-     */
15
-    public static function createFolder($folder)
16
-    {
17
-        //        try {
18
-        //            if (!mkdir($folder) && !is_dir($folder)) {
19
-        //                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
20
-        //            } else {
21
-        //                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
22
-        //            }
23
-        //        }
24
-        //        catch (Exception $e) {
25
-        //            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
26
-        //        }
27
-        try {
28
-            if (!file_exists($folder)) {
29
-                if (!mkdir($folder) && !is_dir($folder)) {
30
-                    throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
31
-                } else {
32
-                    file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
33
-                }
34
-            }
35
-        } catch (Exception $e) {
36
-            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
37
-        }
38
-    }
8
+	/**
9
+	 * Function responsible for checking if a directory exists, we can also write in and create an index.html file
10
+	 *
11
+	 * @param string $folder The full path of the directory to check
12
+	 *
13
+	 * @return void
14
+	 */
15
+	public static function createFolder($folder)
16
+	{
17
+		//        try {
18
+		//            if (!mkdir($folder) && !is_dir($folder)) {
19
+		//                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
20
+		//            } else {
21
+		//                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
22
+		//            }
23
+		//        }
24
+		//        catch (Exception $e) {
25
+		//            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
26
+		//        }
27
+		try {
28
+			if (!file_exists($folder)) {
29
+				if (!mkdir($folder) && !is_dir($folder)) {
30
+					throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
31
+				} else {
32
+					file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
33
+				}
34
+			}
35
+		} catch (Exception $e) {
36
+			echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
37
+		}
38
+	}
39 39
 
40
-    /**
41
-     * @param $file
42
-     * @param $folder
43
-     * @return bool
44
-     */
45
-    public static function copyFile($file, $folder)
46
-    {
47
-        return copy($file, $folder);
48
-        //        try {
49
-        //            if (!is_dir($folder)) {
50
-        //                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
51
-        //            } else {
52
-        //                return copy($file, $folder);
53
-        //            }
54
-        //        } catch (Exception $e) {
55
-        //            echo 'Caught exception: ', $e->getMessage(), "\n", "<br>";
56
-        //        }
57
-        //        return false;
58
-    }
40
+	/**
41
+	 * @param $file
42
+	 * @param $folder
43
+	 * @return bool
44
+	 */
45
+	public static function copyFile($file, $folder)
46
+	{
47
+		return copy($file, $folder);
48
+		//        try {
49
+		//            if (!is_dir($folder)) {
50
+		//                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
51
+		//            } else {
52
+		//                return copy($file, $folder);
53
+		//            }
54
+		//        } catch (Exception $e) {
55
+		//            echo 'Caught exception: ', $e->getMessage(), "\n", "<br>";
56
+		//        }
57
+		//        return false;
58
+	}
59 59
 
60
-    /**
61
-     * @param $src
62
-     * @param $dst
63
-     */
64
-    public static function recurseCopy($src, $dst)
65
-    {
66
-        $dir = opendir($src);
67
-        //    @mkdir($dst);
68
-        while (false !== ($file = readdir($dir))) {
69
-            if (($file !== '.') && ($file !== '..')) {
70
-                if (is_dir($src . '/' . $file)) {
71
-                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
72
-                } else {
73
-                    copy($src . '/' . $file, $dst . '/' . $file);
74
-                }
75
-            }
76
-        }
77
-        closedir($dir);
78
-    }
60
+	/**
61
+	 * @param $src
62
+	 * @param $dst
63
+	 */
64
+	public static function recurseCopy($src, $dst)
65
+	{
66
+		$dir = opendir($src);
67
+		//    @mkdir($dst);
68
+		while (false !== ($file = readdir($dir))) {
69
+			if (($file !== '.') && ($file !== '..')) {
70
+				if (is_dir($src . '/' . $file)) {
71
+					self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
72
+				} else {
73
+					copy($src . '/' . $file, $dst . '/' . $file);
74
+				}
75
+			}
76
+		}
77
+		closedir($dir);
78
+	}
79 79
 
80
-    /**
81
-     *
82
-     * Verifies XOOPS version meets minimum requirements for this module
83
-     * @static
84
-     * @param XoopsModule $module
85
-     *
86
-     * @param null|string $requiredVer
87
-     * @return bool true if meets requirements, false if not
88
-     */
89
-    public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null)
90
-    {
91
-        $moduleDirName = basename(dirname(__DIR__));
92
-        if (null === $module) {
93
-            $module = XoopsModule::getByDirname($moduleDirName);
94
-        }
95
-        xoops_loadLanguage('admin', $moduleDirName);
96
-        //check for minimum XOOPS version
97
-        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
98
-        $currArray  = explode('.', $currentVer);
99
-        if (null === $requiredVer) {
100
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
101
-        }
102
-        $reqArray = explode('.', $requiredVer);
103
-        $success  = true;
104
-        foreach ($reqArray as $k => $v) {
105
-            if (isset($currArray[$k])) {
106
-                if ($currArray[$k] > $v) {
107
-                    break;
108
-                } elseif ($currArray[$k] == $v) {
109
-                    continue;
110
-                } else {
111
-                    $success = false;
112
-                    break;
113
-                }
114
-            } else {
115
-                if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
116
-                    $success = false;
117
-                    break;
118
-                }
119
-            }
120
-        }
80
+	/**
81
+	 *
82
+	 * Verifies XOOPS version meets minimum requirements for this module
83
+	 * @static
84
+	 * @param XoopsModule $module
85
+	 *
86
+	 * @param null|string $requiredVer
87
+	 * @return bool true if meets requirements, false if not
88
+	 */
89
+	public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null)
90
+	{
91
+		$moduleDirName = basename(dirname(__DIR__));
92
+		if (null === $module) {
93
+			$module = XoopsModule::getByDirname($moduleDirName);
94
+		}
95
+		xoops_loadLanguage('admin', $moduleDirName);
96
+		//check for minimum XOOPS version
97
+		$currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
98
+		$currArray  = explode('.', $currentVer);
99
+		if (null === $requiredVer) {
100
+			$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
101
+		}
102
+		$reqArray = explode('.', $requiredVer);
103
+		$success  = true;
104
+		foreach ($reqArray as $k => $v) {
105
+			if (isset($currArray[$k])) {
106
+				if ($currArray[$k] > $v) {
107
+					break;
108
+				} elseif ($currArray[$k] == $v) {
109
+					continue;
110
+				} else {
111
+					$success = false;
112
+					break;
113
+				}
114
+			} else {
115
+				if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
116
+					$success = false;
117
+					break;
118
+				}
119
+			}
120
+		}
121 121
 
122
-        if (!$success) {
123
-            $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
124
-        }
122
+		if (!$success) {
123
+			$module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
124
+		}
125 125
 
126
-        return $success;
127
-    }
126
+		return $success;
127
+	}
128 128
 
129
-    /**
130
-     *
131
-     * Verifies PHP version meets minimum requirements for this module
132
-     * @static
133
-     * @param XoopsModule $module
134
-     *
135
-     * @return bool true if meets requirements, false if not
136
-     */
137
-    public static function checkVerPhp(XoopsModule $module)
138
-    {
139
-        xoops_loadLanguage('admin', $module->dirname());
140
-        // check for minimum PHP version
141
-        $success = true;
142
-        $verNum  = PHP_VERSION;
143
-        $reqVer  = $module->getInfo('min_php');
144
-        if (false !== $reqVer && '' !== $reqVer) {
145
-            if (version_compare($verNum, $reqVer, '<')) {
146
-                $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_PHP, $reqVer, $verNum));
147
-                $success = false;
148
-            }
149
-        }
129
+	/**
130
+	 *
131
+	 * Verifies PHP version meets minimum requirements for this module
132
+	 * @static
133
+	 * @param XoopsModule $module
134
+	 *
135
+	 * @return bool true if meets requirements, false if not
136
+	 */
137
+	public static function checkVerPhp(XoopsModule $module)
138
+	{
139
+		xoops_loadLanguage('admin', $module->dirname());
140
+		// check for minimum PHP version
141
+		$success = true;
142
+		$verNum  = PHP_VERSION;
143
+		$reqVer  = $module->getInfo('min_php');
144
+		if (false !== $reqVer && '' !== $reqVer) {
145
+			if (version_compare($verNum, $reqVer, '<')) {
146
+				$module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_PHP, $reqVer, $verNum));
147
+				$success = false;
148
+			}
149
+		}
150 150
 
151
-        return $success;
152
-    }
151
+		return $success;
152
+	}
153 153
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
                 if (!mkdir($folder) && !is_dir($folder)) {
30 30
                     throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
31 31
                 } else {
32
-                    file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
32
+                    file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>');
33 33
                 }
34 34
             }
35 35
         } catch (Exception $e) {
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
         //    @mkdir($dst);
68 68
         while (false !== ($file = readdir($dir))) {
69 69
             if (($file !== '.') && ($file !== '..')) {
70
-                if (is_dir($src . '/' . $file)) {
71
-                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
70
+                if (is_dir($src.'/'.$file)) {
71
+                    self::recurseCopy($src.'/'.$file, $dst.'/'.$file);
72 72
                 } else {
73
-                    copy($src . '/' . $file, $dst . '/' . $file);
73
+                    copy($src.'/'.$file, $dst.'/'.$file);
74 74
                 }
75 75
             }
76 76
         }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
98 98
         $currArray  = explode('.', $currentVer);
99 99
         if (null === $requiredVer) {
100
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
100
+            $requiredVer = ''.$module->getInfo('min_xoops'); //making sure it's a string
101 101
         }
102 102
         $reqArray = explode('.', $requiredVer);
103 103
         $success  = true;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                     break;
113 113
                 }
114 114
             } else {
115
-                if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
115
+                if ((int) $v > 0) { // handles versions like x.x.x.0_RC2
116 116
                     $success = false;
117 117
                     break;
118 118
                 }
Please login to merge, or discard this patch.