@@ -22,153 +22,153 @@ |
||
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(SmartPersistableObjectHandler $objectHandler, $criteria = false, $actions = array('edit', 'delete'), $userSide = false) |
|
33 | - { |
|
34 | - $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
35 | - $this->_isTree = true; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Get children objects given a specific parentid |
|
40 | - * |
|
41 | - * @var int $parentid id of the parent which children we want to retreive |
|
42 | - * @return array of SmartObject |
|
43 | - */ |
|
44 | - public function getChildrenOf($parentid = 0) |
|
45 | - { |
|
46 | - return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @param $object |
|
51 | - * @param int $level |
|
52 | - */ |
|
53 | - public function createTableRow($object, $level = 0) |
|
54 | - { |
|
55 | - $aObject = array(); |
|
56 | - |
|
57 | - $i = 0; |
|
58 | - |
|
59 | - $aColumns = array(); |
|
60 | - $doWeHaveActions = false; |
|
61 | - |
|
62 | - foreach ($this->_columns as $column) { |
|
63 | - $aColumn = array(); |
|
64 | - |
|
65 | - if ($i == 0) { |
|
66 | - $class = 'head'; |
|
67 | - } elseif ($i % 2 == 0) { |
|
68 | - $class = 'even'; |
|
69 | - } else { |
|
70 | - $class = 'odd'; |
|
71 | - } |
|
72 | - |
|
73 | - if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
74 | - $method = $column->_customMethodForValue; |
|
75 | - $value = $object->$method(); |
|
76 | - } else { |
|
77 | - /** |
|
78 | - * If the column is the identifier, then put a link on it |
|
79 | - */ |
|
80 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
81 | - $value = $object->getItemLink(); |
|
82 | - } else { |
|
83 | - $value = $object->getVar($column->getKeyName()); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - $space = ''; |
|
88 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
89 | - for ($i = 0; $i < $level; ++$i) { |
|
90 | - $space .= '--'; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - if ($space !== '') { |
|
95 | - $space .= ' '; |
|
96 | - } |
|
97 | - |
|
98 | - $aColumn['value'] = $space . $value; |
|
99 | - $aColumn['class'] = $class; |
|
100 | - $aColumn['width'] = $column->getWidth(); |
|
101 | - $aColumn['align'] = $column->getAlign(); |
|
102 | - $aColumn['key'] = $column->getKeyName(); |
|
103 | - |
|
104 | - $aColumns[] = $aColumn; |
|
105 | - ++$i; |
|
106 | - } |
|
107 | - |
|
108 | - $aObject['columns'] = $aColumns; |
|
109 | - |
|
110 | - $class = $class === 'even' ? 'odd' : 'even'; |
|
111 | - $aObject['class'] = $class; |
|
112 | - |
|
113 | - $actions = array(); |
|
114 | - |
|
115 | - // Adding the custom actions if any |
|
116 | - foreach ($this->_custom_actions as $action) { |
|
117 | - if (method_exists($object, $action)) { |
|
118 | - $actions[] = $object->$action(); |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
123 | - $controller = new SmartObjectController($this->_objectHandler); |
|
124 | - |
|
125 | - if (in_array('edit', $this->_actions)) { |
|
126 | - $actions[] = $controller->getEditItemLink($object, false, true); |
|
127 | - } |
|
128 | - if (in_array('delete', $this->_actions)) { |
|
129 | - $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
130 | - } |
|
131 | - $aObject['actions'] = $actions; |
|
132 | - |
|
133 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
134 | - $aObject['id'] = $object->id(); |
|
135 | - $this->_aObjects[] = $aObject; |
|
136 | - |
|
137 | - $childrenObjects = $this->getChildrenOf($object->id()); |
|
138 | - |
|
139 | - $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
|
140 | - |
|
141 | - if ($childrenObjects) { |
|
142 | - ++$level; |
|
143 | - foreach ($childrenObjects as $subObject) { |
|
144 | - $this->createTableRow($subObject, $level); |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - public function createTableRows() |
|
150 | - { |
|
151 | - $this->_aObjects = array(); |
|
152 | - |
|
153 | - if (count($this->_objects) > 0) { |
|
154 | - foreach ($this->getChildrenOf() as $object) { |
|
155 | - $this->createTableRow($object); |
|
156 | - } |
|
157 | - |
|
158 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
159 | - } else { |
|
160 | - $colspan = count($this->_columns) + 1; |
|
161 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return mixed |
|
167 | - */ |
|
168 | - public function fetchObjects() |
|
169 | - { |
|
170 | - $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
171 | - |
|
172 | - return $ret; |
|
173 | - } |
|
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(SmartPersistableObjectHandler $objectHandler, $criteria = false, $actions = array('edit', 'delete'), $userSide = false) |
|
33 | + { |
|
34 | + $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
35 | + $this->_isTree = true; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Get children objects given a specific parentid |
|
40 | + * |
|
41 | + * @var int $parentid id of the parent which children we want to retreive |
|
42 | + * @return array of SmartObject |
|
43 | + */ |
|
44 | + public function getChildrenOf($parentid = 0) |
|
45 | + { |
|
46 | + return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @param $object |
|
51 | + * @param int $level |
|
52 | + */ |
|
53 | + public function createTableRow($object, $level = 0) |
|
54 | + { |
|
55 | + $aObject = array(); |
|
56 | + |
|
57 | + $i = 0; |
|
58 | + |
|
59 | + $aColumns = array(); |
|
60 | + $doWeHaveActions = false; |
|
61 | + |
|
62 | + foreach ($this->_columns as $column) { |
|
63 | + $aColumn = array(); |
|
64 | + |
|
65 | + if ($i == 0) { |
|
66 | + $class = 'head'; |
|
67 | + } elseif ($i % 2 == 0) { |
|
68 | + $class = 'even'; |
|
69 | + } else { |
|
70 | + $class = 'odd'; |
|
71 | + } |
|
72 | + |
|
73 | + if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
74 | + $method = $column->_customMethodForValue; |
|
75 | + $value = $object->$method(); |
|
76 | + } else { |
|
77 | + /** |
|
78 | + * If the column is the identifier, then put a link on it |
|
79 | + */ |
|
80 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
81 | + $value = $object->getItemLink(); |
|
82 | + } else { |
|
83 | + $value = $object->getVar($column->getKeyName()); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + $space = ''; |
|
88 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
89 | + for ($i = 0; $i < $level; ++$i) { |
|
90 | + $space .= '--'; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + if ($space !== '') { |
|
95 | + $space .= ' '; |
|
96 | + } |
|
97 | + |
|
98 | + $aColumn['value'] = $space . $value; |
|
99 | + $aColumn['class'] = $class; |
|
100 | + $aColumn['width'] = $column->getWidth(); |
|
101 | + $aColumn['align'] = $column->getAlign(); |
|
102 | + $aColumn['key'] = $column->getKeyName(); |
|
103 | + |
|
104 | + $aColumns[] = $aColumn; |
|
105 | + ++$i; |
|
106 | + } |
|
107 | + |
|
108 | + $aObject['columns'] = $aColumns; |
|
109 | + |
|
110 | + $class = $class === 'even' ? 'odd' : 'even'; |
|
111 | + $aObject['class'] = $class; |
|
112 | + |
|
113 | + $actions = array(); |
|
114 | + |
|
115 | + // Adding the custom actions if any |
|
116 | + foreach ($this->_custom_actions as $action) { |
|
117 | + if (method_exists($object, $action)) { |
|
118 | + $actions[] = $object->$action(); |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
123 | + $controller = new SmartObjectController($this->_objectHandler); |
|
124 | + |
|
125 | + if (in_array('edit', $this->_actions)) { |
|
126 | + $actions[] = $controller->getEditItemLink($object, false, true); |
|
127 | + } |
|
128 | + if (in_array('delete', $this->_actions)) { |
|
129 | + $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
130 | + } |
|
131 | + $aObject['actions'] = $actions; |
|
132 | + |
|
133 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
134 | + $aObject['id'] = $object->id(); |
|
135 | + $this->_aObjects[] = $aObject; |
|
136 | + |
|
137 | + $childrenObjects = $this->getChildrenOf($object->id()); |
|
138 | + |
|
139 | + $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
|
140 | + |
|
141 | + if ($childrenObjects) { |
|
142 | + ++$level; |
|
143 | + foreach ($childrenObjects as $subObject) { |
|
144 | + $this->createTableRow($subObject, $level); |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + public function createTableRows() |
|
150 | + { |
|
151 | + $this->_aObjects = array(); |
|
152 | + |
|
153 | + if (count($this->_objects) > 0) { |
|
154 | + foreach ($this->getChildrenOf() as $object) { |
|
155 | + $this->createTableRow($object); |
|
156 | + } |
|
157 | + |
|
158 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
159 | + } else { |
|
160 | + $colspan = count($this->_columns) + 1; |
|
161 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return mixed |
|
167 | + */ |
|
168 | + public function fetchObjects() |
|
169 | + { |
|
170 | + $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
171 | + |
|
172 | + return $ret; |
|
173 | + } |
|
174 | 174 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @subpackage SmartObjectTable |
10 | 10 | */ |
11 | 11 | |
12 | -include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php'); |
|
12 | +include_once(SMARTOBJECT_ROOT_PATH.'class/smartobjecttable.php'); |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * SmartObjectTreeTable class |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $space .= ' '; |
96 | 96 | } |
97 | 97 | |
98 | - $aColumn['value'] = $space . $value; |
|
98 | + $aColumn['value'] = $space.$value; |
|
99 | 99 | $aColumn['class'] = $class; |
100 | 100 | $aColumn['width'] = $column->getWidth(); |
101 | 101 | $aColumn['align'] = $column->getAlign(); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
122 | + include_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
123 | 123 | $controller = new SmartObjectController($this->_objectHandler); |
124 | 124 | |
125 | 125 | if (in_array('edit', $this->_actions)) { |
@@ -35,164 +35,164 @@ discard block |
||
35 | 35 | */ |
36 | 36 | class SmartobjectLink extends SmartObject |
37 | 37 | { |
38 | - /** |
|
39 | - * SmartobjectLink constructor. |
|
40 | - */ |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
44 | - $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
45 | - $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
46 | - $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
47 | - $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
48 | - $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
49 | - $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
50 | - $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
51 | - $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
52 | - $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
53 | - $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
54 | - $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
55 | - $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * returns a specific variable for the object in a proper format |
|
60 | - * |
|
61 | - * @access public |
|
62 | - * @param string $key key of the object's variable to be returned |
|
63 | - * @param string $format format to use for the output |
|
64 | - * @return mixed formatted value of the variable |
|
65 | - */ |
|
66 | - public function getVar($key, $format = 's') |
|
67 | - { |
|
68 | - if ($format === 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) { |
|
69 | - // return call_user_func(array($this, $key)); |
|
70 | - return $this->{$key}(); |
|
71 | - } |
|
72 | - |
|
73 | - return parent::getVar($key, $format); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function from_uid() |
|
80 | - { |
|
81 | - $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
82 | - |
|
83 | - return $ret; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param bool $withContact |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function to_uid($withContact = false) |
|
91 | - { |
|
92 | - $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
93 | - |
|
94 | - return $ret; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function date() |
|
101 | - { |
|
102 | - $ret = formatTimestamp($this->getVar('date', 'e')); |
|
103 | - |
|
104 | - return $ret; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param bool $full |
|
109 | - * @return mixed|string |
|
110 | - */ |
|
111 | - public function link($full = false) |
|
112 | - { |
|
113 | - $ret = $this->getVar('link', 'e'); |
|
114 | - if ($full) { |
|
115 | - $myts = MyTextSanitizer::getInstance(); |
|
116 | - $ret = $myts->displayTarea($ret); |
|
117 | - |
|
118 | - return $ret; |
|
119 | - } else { |
|
120 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
121 | - |
|
122 | - return $ret; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getViewItemLink() |
|
130 | - { |
|
131 | - $ret = '<a href="' . |
|
132 | - SMARTOBJECT_URL . |
|
133 | - 'admin/link.php?op=view&linkid=' . |
|
134 | - $this->getVar('linkid') . |
|
135 | - '"><img src="' . |
|
136 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
137 | - 'mail_find.png" alt="' . |
|
138 | - _AM_SOBJECT_SENT_LINK_VIEW . |
|
139 | - '" title="' . |
|
140 | - _AM_SOBJECT_SENT_LINK_VIEW . |
|
141 | - '" /></a>'; |
|
142 | - |
|
143 | - return $ret; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function getFromInfo() |
|
150 | - { |
|
151 | - // check if from_uid represent a user |
|
152 | - |
|
153 | - if ($this->getVar('from_uid')) { |
|
154 | - $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
155 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
156 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
157 | - } |
|
158 | - } else { |
|
159 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
160 | - } |
|
161 | - |
|
162 | - return $user; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - public function toArray() |
|
169 | - { |
|
170 | - $ret = parent::toArray(); |
|
171 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
172 | - $ret['toInfo'] = $this->getToInfo(); |
|
173 | - $ret['fullLink'] = $this->link(true); |
|
174 | - |
|
175 | - return $ret; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function getToInfo() |
|
182 | - { |
|
183 | - // check if from_uid represent a user |
|
184 | - |
|
185 | - if ($this->getVar('to_uid')) { |
|
186 | - $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
187 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
188 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
189 | - } |
|
190 | - } else { |
|
191 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
192 | - } |
|
193 | - |
|
194 | - return $user; |
|
195 | - } |
|
38 | + /** |
|
39 | + * SmartobjectLink constructor. |
|
40 | + */ |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
44 | + $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
45 | + $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
46 | + $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
47 | + $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
48 | + $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
49 | + $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
50 | + $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
51 | + $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
52 | + $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
53 | + $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
54 | + $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
55 | + $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * returns a specific variable for the object in a proper format |
|
60 | + * |
|
61 | + * @access public |
|
62 | + * @param string $key key of the object's variable to be returned |
|
63 | + * @param string $format format to use for the output |
|
64 | + * @return mixed formatted value of the variable |
|
65 | + */ |
|
66 | + public function getVar($key, $format = 's') |
|
67 | + { |
|
68 | + if ($format === 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) { |
|
69 | + // return call_user_func(array($this, $key)); |
|
70 | + return $this->{$key}(); |
|
71 | + } |
|
72 | + |
|
73 | + return parent::getVar($key, $format); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function from_uid() |
|
80 | + { |
|
81 | + $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
82 | + |
|
83 | + return $ret; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param bool $withContact |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function to_uid($withContact = false) |
|
91 | + { |
|
92 | + $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
93 | + |
|
94 | + return $ret; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function date() |
|
101 | + { |
|
102 | + $ret = formatTimestamp($this->getVar('date', 'e')); |
|
103 | + |
|
104 | + return $ret; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param bool $full |
|
109 | + * @return mixed|string |
|
110 | + */ |
|
111 | + public function link($full = false) |
|
112 | + { |
|
113 | + $ret = $this->getVar('link', 'e'); |
|
114 | + if ($full) { |
|
115 | + $myts = MyTextSanitizer::getInstance(); |
|
116 | + $ret = $myts->displayTarea($ret); |
|
117 | + |
|
118 | + return $ret; |
|
119 | + } else { |
|
120 | + $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
121 | + |
|
122 | + return $ret; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getViewItemLink() |
|
130 | + { |
|
131 | + $ret = '<a href="' . |
|
132 | + SMARTOBJECT_URL . |
|
133 | + 'admin/link.php?op=view&linkid=' . |
|
134 | + $this->getVar('linkid') . |
|
135 | + '"><img src="' . |
|
136 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
137 | + 'mail_find.png" alt="' . |
|
138 | + _AM_SOBJECT_SENT_LINK_VIEW . |
|
139 | + '" title="' . |
|
140 | + _AM_SOBJECT_SENT_LINK_VIEW . |
|
141 | + '" /></a>'; |
|
142 | + |
|
143 | + return $ret; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function getFromInfo() |
|
150 | + { |
|
151 | + // check if from_uid represent a user |
|
152 | + |
|
153 | + if ($this->getVar('from_uid')) { |
|
154 | + $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
155 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
156 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
157 | + } |
|
158 | + } else { |
|
159 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
160 | + } |
|
161 | + |
|
162 | + return $user; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + public function toArray() |
|
169 | + { |
|
170 | + $ret = parent::toArray(); |
|
171 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
172 | + $ret['toInfo'] = $this->getToInfo(); |
|
173 | + $ret['fullLink'] = $this->link(true); |
|
174 | + |
|
175 | + return $ret; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function getToInfo() |
|
182 | + { |
|
183 | + // check if from_uid represent a user |
|
184 | + |
|
185 | + if ($this->getVar('to_uid')) { |
|
186 | + $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
187 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
188 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
189 | + } |
|
190 | + } else { |
|
191 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
192 | + } |
|
193 | + |
|
194 | + return $user; |
|
195 | + } |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | */ |
201 | 201 | class SmartobjectLinkHandler extends SmartPersistableObjectHandler |
202 | 202 | { |
203 | - /** |
|
204 | - * SmartobjectLinkHandler constructor. |
|
205 | - * @param XoopsDatabase $db |
|
206 | - */ |
|
207 | - public function __construct(XoopsDatabase $db) |
|
208 | - { |
|
209 | - parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
210 | - } |
|
203 | + /** |
|
204 | + * SmartobjectLinkHandler constructor. |
|
205 | + * @param XoopsDatabase $db |
|
206 | + */ |
|
207 | + public function __construct(XoopsDatabase $db) |
|
208 | + { |
|
209 | + parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
210 | + } |
|
211 | 211 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | // -------------------------------------------------------------------------// |
29 | 29 | |
30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
31 | -include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
31 | +include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Class SmartobjectLink |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | return $ret; |
119 | 119 | } else { |
120 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
120 | + $ret = '<a href="'.$ret.'" alt="'.$this->getVar('link', 'e').'" title="'.$this->getVar('link', 'e').'">'._AM_SOBJECT_SENT_LINKS_GOTO.'</a>'; |
|
121 | 121 | |
122 | 122 | return $ret; |
123 | 123 | } |
@@ -128,16 +128,16 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function getViewItemLink() |
130 | 130 | { |
131 | - $ret = '<a href="' . |
|
132 | - SMARTOBJECT_URL . |
|
133 | - 'admin/link.php?op=view&linkid=' . |
|
134 | - $this->getVar('linkid') . |
|
135 | - '"><img src="' . |
|
136 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
137 | - 'mail_find.png" alt="' . |
|
138 | - _AM_SOBJECT_SENT_LINK_VIEW . |
|
139 | - '" title="' . |
|
140 | - _AM_SOBJECT_SENT_LINK_VIEW . |
|
131 | + $ret = '<a href="'. |
|
132 | + SMARTOBJECT_URL. |
|
133 | + 'admin/link.php?op=view&linkid='. |
|
134 | + $this->getVar('linkid'). |
|
135 | + '"><img src="'. |
|
136 | + SMARTOBJECT_IMAGES_ACTIONS_URL. |
|
137 | + 'mail_find.png" alt="'. |
|
138 | + _AM_SOBJECT_SENT_LINK_VIEW. |
|
139 | + '" title="'. |
|
140 | + _AM_SOBJECT_SENT_LINK_VIEW. |
|
141 | 141 | '" /></a>'; |
142 | 142 | |
143 | 143 | return $ret; |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | if ($this->getVar('from_uid')) { |
154 | 154 | $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
155 | 155 | if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
156 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
156 | + $user = '<a href="mailto:'.$this->getVar('from_email').'">'.$this->getVar('from_email').'</a>'; |
|
157 | 157 | } |
158 | 158 | } else { |
159 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
159 | + $user = '<a href="mailto:'.$this->getVar('from_email').'">'.$this->getVar('from_email').'</a>'; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return $user; |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | if ($this->getVar('to_uid')) { |
186 | 186 | $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
187 | 187 | if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
188 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
188 | + $user = '<a href="mailto:'.$this->getVar('to_email').'">'.$this->getVar('to_email').'</a>'; |
|
189 | 189 | } |
190 | 190 | } else { |
191 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
191 | + $user = '<a href="mailto:'.$this->getVar('to_email').'">'.$this->getVar('to_email').'</a>'; |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | return $user; |
@@ -36,208 +36,208 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class SmartobjectCustomtag extends SmartObject |
38 | 38 | { |
39 | - public $content = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * SmartobjectCustomtag constructor. |
|
43 | - */ |
|
44 | - public function __construct() |
|
45 | - { |
|
46 | - $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
|
47 | - $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
|
48 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
|
49 | - $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
|
50 | - $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
|
51 | - |
|
52 | - $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
|
53 | - $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
|
54 | - $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
|
55 | - $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
|
56 | - |
|
57 | - $this->setControl('content', array( |
|
58 | - 'name' => 'textarea', |
|
59 | - 'form_editor' => 'textarea', |
|
60 | - 'form_rows' => 25 |
|
61 | - )); |
|
62 | - $this->setControl('language', array( |
|
63 | - 'name' => 'language', |
|
64 | - 'all' => true |
|
65 | - )); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param string $key |
|
70 | - * @param string $format |
|
71 | - * @return mixed |
|
72 | - */ |
|
73 | - public function getVar($key, $format = 's') |
|
74 | - { |
|
75 | - if ($format === 's' && in_array($key, array())) { |
|
76 | - // return call_user_func(array($this, $key)); |
|
77 | - return $this->{$key}(); |
|
78 | - } |
|
79 | - |
|
80 | - return parent::getVar($key, $format); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return bool|mixed |
|
85 | - */ |
|
86 | - public function render() |
|
87 | - { |
|
88 | - if (!$this->content) { |
|
89 | - $ret = $this->getVar('content'); |
|
90 | - $this->content = $ret; |
|
91 | - } |
|
92 | - |
|
93 | - return $this->content; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return bool|mixed|string |
|
98 | - */ |
|
99 | - public function renderWithPhp() |
|
100 | - { |
|
101 | - if (!$this->content) { |
|
102 | - $ret = $this->getVar('content'); |
|
103 | - $this->content = $ret; |
|
104 | - } else { |
|
105 | - $ret = $this->content; |
|
106 | - } |
|
107 | - |
|
108 | - // check for PHP if we are not on admin side |
|
109 | - if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
|
110 | - $ret = str_replace('[php]', '', $ret); |
|
111 | - // we have PHP code, let's evaluate |
|
112 | - eval($ret); |
|
113 | - |
|
114 | - return ''; |
|
115 | - } |
|
116 | - |
|
117 | - return $this->content; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getXoopsCode() |
|
124 | - { |
|
125 | - $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
126 | - |
|
127 | - return $ret; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function getCloneLink() |
|
134 | - { |
|
135 | - $ret = '<a href="' . |
|
136 | - SMARTOBJECT_URL . |
|
137 | - 'admin/customtag.php?op=clone&customtagid=' . |
|
138 | - $this->id() . |
|
139 | - '"><img src="' . |
|
140 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
141 | - 'editcopy.png" style="vertical-align: middle;" alt="' . |
|
142 | - _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
143 | - '" title="' . |
|
144 | - _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
145 | - '" /></a>'; |
|
146 | - |
|
147 | - return $ret; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param $var |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - public function emptyString($var) |
|
155 | - { |
|
156 | - return (strlen($var) > 0); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return mixed|string |
|
161 | - */ |
|
162 | - public function generateTag() |
|
163 | - { |
|
164 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
165 | - $title = xoops_substr($title, 0, 10, ''); |
|
166 | - // Transformation des ponctuations |
|
167 | - $pattern = array( |
|
168 | - '/%09/', // Tab |
|
169 | - '/%20/', // Space |
|
170 | - '/%21/', // ! |
|
171 | - '/%22/', // " |
|
172 | - '/%23/', // # |
|
173 | - '/%25/', // % |
|
174 | - '/%26/', // & |
|
175 | - '/%27/', // ' |
|
176 | - '/%28/', // ( |
|
177 | - '/%29/', // ) |
|
178 | - '/%2C/', // , |
|
179 | - '/%2F/', // / |
|
180 | - '/%3A/', // : |
|
181 | - '/%3B/', // ; |
|
182 | - '/%3C/', // < |
|
183 | - '/%3D/', // = |
|
184 | - '/%3E/', // > |
|
185 | - '/%3F/', // ? |
|
186 | - '/%40/', // @ |
|
187 | - '/%5B/', // [ |
|
188 | - '/%5C/', // \ |
|
189 | - '/%5D/', // ] |
|
190 | - '/%5E/', // ^ |
|
191 | - '/%7B/', // { |
|
192 | - '/%7C/', // | |
|
193 | - '/%7D/', // } |
|
194 | - '/%7E/', // ~ |
|
195 | - "/\./" // . |
|
196 | - ); |
|
197 | - $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
198 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
199 | - |
|
200 | - // Transformation des caract�res accentu�s |
|
201 | - $pattern = array( |
|
202 | - '/%B0/', // ° |
|
203 | - '/%E8/', // è |
|
204 | - '/%E9/', // é |
|
205 | - '/%EA/', // ê |
|
206 | - '/%EB/', // ë |
|
207 | - '/%E7/', // ç |
|
208 | - '/%E0/', // à |
|
209 | - '/%E2/', // â |
|
210 | - '/%E4/', // ä |
|
211 | - '/%EE/', // î |
|
212 | - '/%EF/', // ï |
|
213 | - '/%F9/', // ù |
|
214 | - '/%FC/', // ü |
|
215 | - '/%FB/', // û |
|
216 | - '/%F4/', // ô |
|
217 | - '/%F6/', // ö |
|
218 | - ); |
|
219 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
220 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
221 | - |
|
222 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
223 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
224 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
225 | - |
|
226 | - $title .= time(); |
|
227 | - $title = md5($title); |
|
228 | - |
|
229 | - return $title; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @return mixed |
|
234 | - */ |
|
235 | - public function getCustomtagName() |
|
236 | - { |
|
237 | - $ret = $this->getVar('name'); |
|
238 | - |
|
239 | - return $ret; |
|
240 | - } |
|
39 | + public $content = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * SmartobjectCustomtag constructor. |
|
43 | + */ |
|
44 | + public function __construct() |
|
45 | + { |
|
46 | + $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
|
47 | + $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
|
48 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
|
49 | + $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
|
50 | + $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
|
51 | + |
|
52 | + $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
|
53 | + $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
|
54 | + $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
|
55 | + $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
|
56 | + |
|
57 | + $this->setControl('content', array( |
|
58 | + 'name' => 'textarea', |
|
59 | + 'form_editor' => 'textarea', |
|
60 | + 'form_rows' => 25 |
|
61 | + )); |
|
62 | + $this->setControl('language', array( |
|
63 | + 'name' => 'language', |
|
64 | + 'all' => true |
|
65 | + )); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param string $key |
|
70 | + * @param string $format |
|
71 | + * @return mixed |
|
72 | + */ |
|
73 | + public function getVar($key, $format = 's') |
|
74 | + { |
|
75 | + if ($format === 's' && in_array($key, array())) { |
|
76 | + // return call_user_func(array($this, $key)); |
|
77 | + return $this->{$key}(); |
|
78 | + } |
|
79 | + |
|
80 | + return parent::getVar($key, $format); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return bool|mixed |
|
85 | + */ |
|
86 | + public function render() |
|
87 | + { |
|
88 | + if (!$this->content) { |
|
89 | + $ret = $this->getVar('content'); |
|
90 | + $this->content = $ret; |
|
91 | + } |
|
92 | + |
|
93 | + return $this->content; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return bool|mixed|string |
|
98 | + */ |
|
99 | + public function renderWithPhp() |
|
100 | + { |
|
101 | + if (!$this->content) { |
|
102 | + $ret = $this->getVar('content'); |
|
103 | + $this->content = $ret; |
|
104 | + } else { |
|
105 | + $ret = $this->content; |
|
106 | + } |
|
107 | + |
|
108 | + // check for PHP if we are not on admin side |
|
109 | + if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
|
110 | + $ret = str_replace('[php]', '', $ret); |
|
111 | + // we have PHP code, let's evaluate |
|
112 | + eval($ret); |
|
113 | + |
|
114 | + return ''; |
|
115 | + } |
|
116 | + |
|
117 | + return $this->content; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getXoopsCode() |
|
124 | + { |
|
125 | + $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
126 | + |
|
127 | + return $ret; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function getCloneLink() |
|
134 | + { |
|
135 | + $ret = '<a href="' . |
|
136 | + SMARTOBJECT_URL . |
|
137 | + 'admin/customtag.php?op=clone&customtagid=' . |
|
138 | + $this->id() . |
|
139 | + '"><img src="' . |
|
140 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
141 | + 'editcopy.png" style="vertical-align: middle;" alt="' . |
|
142 | + _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
143 | + '" title="' . |
|
144 | + _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
145 | + '" /></a>'; |
|
146 | + |
|
147 | + return $ret; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param $var |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + public function emptyString($var) |
|
155 | + { |
|
156 | + return (strlen($var) > 0); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return mixed|string |
|
161 | + */ |
|
162 | + public function generateTag() |
|
163 | + { |
|
164 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
165 | + $title = xoops_substr($title, 0, 10, ''); |
|
166 | + // Transformation des ponctuations |
|
167 | + $pattern = array( |
|
168 | + '/%09/', // Tab |
|
169 | + '/%20/', // Space |
|
170 | + '/%21/', // ! |
|
171 | + '/%22/', // " |
|
172 | + '/%23/', // # |
|
173 | + '/%25/', // % |
|
174 | + '/%26/', // & |
|
175 | + '/%27/', // ' |
|
176 | + '/%28/', // ( |
|
177 | + '/%29/', // ) |
|
178 | + '/%2C/', // , |
|
179 | + '/%2F/', // / |
|
180 | + '/%3A/', // : |
|
181 | + '/%3B/', // ; |
|
182 | + '/%3C/', // < |
|
183 | + '/%3D/', // = |
|
184 | + '/%3E/', // > |
|
185 | + '/%3F/', // ? |
|
186 | + '/%40/', // @ |
|
187 | + '/%5B/', // [ |
|
188 | + '/%5C/', // \ |
|
189 | + '/%5D/', // ] |
|
190 | + '/%5E/', // ^ |
|
191 | + '/%7B/', // { |
|
192 | + '/%7C/', // | |
|
193 | + '/%7D/', // } |
|
194 | + '/%7E/', // ~ |
|
195 | + "/\./" // . |
|
196 | + ); |
|
197 | + $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
198 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
199 | + |
|
200 | + // Transformation des caract�res accentu�s |
|
201 | + $pattern = array( |
|
202 | + '/%B0/', // ° |
|
203 | + '/%E8/', // è |
|
204 | + '/%E9/', // é |
|
205 | + '/%EA/', // ê |
|
206 | + '/%EB/', // ë |
|
207 | + '/%E7/', // ç |
|
208 | + '/%E0/', // à |
|
209 | + '/%E2/', // â |
|
210 | + '/%E4/', // ä |
|
211 | + '/%EE/', // î |
|
212 | + '/%EF/', // ï |
|
213 | + '/%F9/', // ù |
|
214 | + '/%FC/', // ü |
|
215 | + '/%FB/', // û |
|
216 | + '/%F4/', // ô |
|
217 | + '/%F6/', // ö |
|
218 | + ); |
|
219 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
220 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
221 | + |
|
222 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
223 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
224 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
225 | + |
|
226 | + $title .= time(); |
|
227 | + $title = md5($title); |
|
228 | + |
|
229 | + return $title; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @return mixed |
|
234 | + */ |
|
235 | + public function getCustomtagName() |
|
236 | + { |
|
237 | + $ret = $this->getVar('name'); |
|
238 | + |
|
239 | + return $ret; |
|
240 | + } |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -245,48 +245,48 @@ discard block |
||
245 | 245 | */ |
246 | 246 | class SmartobjectCustomtagHandler extends SmartPersistableObjectHandler |
247 | 247 | { |
248 | - public $objects = false; |
|
249 | - |
|
250 | - /** |
|
251 | - * SmartobjectCustomtagHandler constructor. |
|
252 | - * @param XoopsDatabase $db |
|
253 | - */ |
|
254 | - public function __construct(XoopsDatabase $db) |
|
255 | - { |
|
256 | - parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
257 | - $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @return array|bool |
|
262 | - */ |
|
263 | - public function getCustomtagsByName() |
|
264 | - { |
|
265 | - if (!$this->objects) { |
|
266 | - global $xoopsConfig; |
|
267 | - |
|
268 | - $ret = array(); |
|
269 | - |
|
270 | - $criteria = new CriteriaCompo(); |
|
271 | - |
|
272 | - $criteria_language = new CriteriaCompo(); |
|
273 | - $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
274 | - $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
275 | - $criteria->add($criteria_language); |
|
276 | - |
|
277 | - $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
278 | - $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
279 | - |
|
280 | - if ($granted_ids && count($granted_ids) > 0) { |
|
281 | - $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
282 | - $customtagsObj = $this->getObjects($criteria, true); |
|
283 | - foreach ($customtagsObj as $customtagObj) { |
|
284 | - $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
285 | - } |
|
286 | - } |
|
287 | - $this->objects = $ret; |
|
288 | - } |
|
289 | - |
|
290 | - return $this->objects; |
|
291 | - } |
|
248 | + public $objects = false; |
|
249 | + |
|
250 | + /** |
|
251 | + * SmartobjectCustomtagHandler constructor. |
|
252 | + * @param XoopsDatabase $db |
|
253 | + */ |
|
254 | + public function __construct(XoopsDatabase $db) |
|
255 | + { |
|
256 | + parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
257 | + $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @return array|bool |
|
262 | + */ |
|
263 | + public function getCustomtagsByName() |
|
264 | + { |
|
265 | + if (!$this->objects) { |
|
266 | + global $xoopsConfig; |
|
267 | + |
|
268 | + $ret = array(); |
|
269 | + |
|
270 | + $criteria = new CriteriaCompo(); |
|
271 | + |
|
272 | + $criteria_language = new CriteriaCompo(); |
|
273 | + $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
274 | + $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
275 | + $criteria->add($criteria_language); |
|
276 | + |
|
277 | + $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
278 | + $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
279 | + |
|
280 | + if ($granted_ids && count($granted_ids) > 0) { |
|
281 | + $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
282 | + $customtagsObj = $this->getObjects($criteria, true); |
|
283 | + foreach ($customtagsObj as $customtagObj) { |
|
284 | + $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
285 | + } |
|
286 | + } |
|
287 | + $this->objects = $ret; |
|
288 | + } |
|
289 | + |
|
290 | + return $this->objects; |
|
291 | + } |
|
292 | 292 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
31 | 31 | |
32 | -include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
32 | +include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Class SmartobjectCustomtag |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getXoopsCode() |
124 | 124 | { |
125 | - $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
125 | + $ret = '[customtag]'.$this->getVar('tag', 'n').'[/customtag]'; |
|
126 | 126 | |
127 | 127 | return $ret; |
128 | 128 | } |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function getCloneLink() |
134 | 134 | { |
135 | - $ret = '<a href="' . |
|
136 | - SMARTOBJECT_URL . |
|
137 | - 'admin/customtag.php?op=clone&customtagid=' . |
|
138 | - $this->id() . |
|
139 | - '"><img src="' . |
|
140 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
141 | - 'editcopy.png" style="vertical-align: middle;" alt="' . |
|
142 | - _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
143 | - '" title="' . |
|
144 | - _CO_SOBJECT_CUSTOMTAG_CLONE . |
|
135 | + $ret = '<a href="'. |
|
136 | + SMARTOBJECT_URL. |
|
137 | + 'admin/customtag.php?op=clone&customtagid='. |
|
138 | + $this->id(). |
|
139 | + '"><img src="'. |
|
140 | + SMARTOBJECT_IMAGES_ACTIONS_URL. |
|
141 | + 'editcopy.png" style="vertical-align: middle;" alt="'. |
|
142 | + _CO_SOBJECT_CUSTOMTAG_CLONE. |
|
143 | + '" title="'. |
|
144 | + _CO_SOBJECT_CUSTOMTAG_CLONE. |
|
145 | 145 | '" /></a>'; |
146 | 146 | |
147 | 147 | return $ret; |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
279 | 279 | |
280 | 280 | if ($granted_ids && count($granted_ids) > 0) { |
281 | - $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
281 | + $criteria->add(new Criteria('customtagid', '('.implode(', ', $granted_ids).')', 'IN')); |
|
282 | 282 | $customtagsObj = $this->getObjects($criteria, true); |
283 | 283 | foreach ($customtagsObj as $customtagObj) { |
284 | 284 | $ret[$customtagObj->getVar('name')] = $customtagObj; |
@@ -19,164 +19,164 @@ |
||
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 | - include_once $fileName; |
|
55 | - } else { |
|
56 | - include_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 | - $moduleHandler = xoops_getHandler('module'); |
|
103 | - $versioninfo = $moduleHandler->get($xoopsModule->getVar('mid')); |
|
104 | - |
|
105 | - //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
|
106 | - |
|
107 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
108 | - |
|
109 | - // --- |
|
110 | - // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
111 | - // $this->_tpl =& new XoopsTpl(); |
|
112 | - $this->_tpl = new XoopsTpl(); |
|
113 | - // --- |
|
114 | - |
|
115 | - $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
116 | - $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
|
117 | - $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
|
118 | - $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
|
119 | - $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version')); |
|
120 | - |
|
121 | - // Left headings... |
|
122 | - if ($versioninfo->getInfo('author_realname') !== '') { |
|
123 | - $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
124 | - } else { |
|
125 | - $author_name = $versioninfo->getInfo('author'); |
|
126 | - } |
|
127 | - $this->_tpl->assign('module_author_name', $author_name); |
|
128 | - |
|
129 | - $this->_tpl->assign('module_license', $versioninfo->getInfo('license')); |
|
130 | - |
|
131 | - $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits')); |
|
132 | - |
|
133 | - // Developers Information |
|
134 | - $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead')); |
|
135 | - $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor')); |
|
136 | - $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url')); |
|
137 | - $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name')); |
|
138 | - $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email')); |
|
139 | - |
|
140 | - $people = $versioninfo->getInfo('people'); |
|
141 | - if ($people) { |
|
142 | - $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map(array($this, 'sanitize'), $people['developers']) : false); |
|
143 | - $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map(array($this, 'sanitize'), $people['testers']) : false); |
|
144 | - $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map(array($this, 'sanitize'), $people['translators']) : false); |
|
145 | - $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map(array($this, 'sanitize'), $people['documenters']) : false); |
|
146 | - $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map(array($this, 'sanitize'), $people['other']) : false); |
|
147 | - } |
|
148 | - //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email')); |
|
149 | - |
|
150 | - // Module Development information |
|
151 | - $this->_tpl->assign('module_date', $versioninfo->getInfo('date')); |
|
152 | - $this->_tpl->assign('module_status', $versioninfo->getInfo('status')); |
|
153 | - $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url')); |
|
154 | - $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name')); |
|
155 | - $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url')); |
|
156 | - $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name')); |
|
157 | - $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug')); |
|
158 | - $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature')); |
|
159 | - |
|
160 | - // Warning |
|
161 | - $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning'))); |
|
162 | - |
|
163 | - // Author's note |
|
164 | - $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
|
165 | - |
|
166 | - // For changelog thanks to 3Dev |
|
167 | - global $xoopsModule; |
|
168 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
169 | - if (is_file($filename)) { |
|
170 | - $filesize = filesize($filename); |
|
171 | - $handle = fopen($filename, 'r'); |
|
172 | - $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
173 | - fclose($handle); |
|
174 | - } |
|
175 | - |
|
176 | - $this->_tpl->display('db:smartobject_about.tpl'); |
|
177 | - |
|
178 | - smart_modFooter(); |
|
179 | - |
|
180 | - xoops_cp_footer(); |
|
181 | - } |
|
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 | + include_once $fileName; |
|
55 | + } else { |
|
56 | + include_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 | + $moduleHandler = xoops_getHandler('module'); |
|
103 | + $versioninfo = $moduleHandler->get($xoopsModule->getVar('mid')); |
|
104 | + |
|
105 | + //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
|
106 | + |
|
107 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
108 | + |
|
109 | + // --- |
|
110 | + // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
111 | + // $this->_tpl =& new XoopsTpl(); |
|
112 | + $this->_tpl = new XoopsTpl(); |
|
113 | + // --- |
|
114 | + |
|
115 | + $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
116 | + $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
|
117 | + $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
|
118 | + $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
|
119 | + $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version')); |
|
120 | + |
|
121 | + // Left headings... |
|
122 | + if ($versioninfo->getInfo('author_realname') !== '') { |
|
123 | + $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
124 | + } else { |
|
125 | + $author_name = $versioninfo->getInfo('author'); |
|
126 | + } |
|
127 | + $this->_tpl->assign('module_author_name', $author_name); |
|
128 | + |
|
129 | + $this->_tpl->assign('module_license', $versioninfo->getInfo('license')); |
|
130 | + |
|
131 | + $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits')); |
|
132 | + |
|
133 | + // Developers Information |
|
134 | + $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead')); |
|
135 | + $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor')); |
|
136 | + $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url')); |
|
137 | + $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name')); |
|
138 | + $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email')); |
|
139 | + |
|
140 | + $people = $versioninfo->getInfo('people'); |
|
141 | + if ($people) { |
|
142 | + $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map(array($this, 'sanitize'), $people['developers']) : false); |
|
143 | + $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map(array($this, 'sanitize'), $people['testers']) : false); |
|
144 | + $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map(array($this, 'sanitize'), $people['translators']) : false); |
|
145 | + $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map(array($this, 'sanitize'), $people['documenters']) : false); |
|
146 | + $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map(array($this, 'sanitize'), $people['other']) : false); |
|
147 | + } |
|
148 | + //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email')); |
|
149 | + |
|
150 | + // Module Development information |
|
151 | + $this->_tpl->assign('module_date', $versioninfo->getInfo('date')); |
|
152 | + $this->_tpl->assign('module_status', $versioninfo->getInfo('status')); |
|
153 | + $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url')); |
|
154 | + $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name')); |
|
155 | + $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url')); |
|
156 | + $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name')); |
|
157 | + $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug')); |
|
158 | + $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature')); |
|
159 | + |
|
160 | + // Warning |
|
161 | + $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning'))); |
|
162 | + |
|
163 | + // Author's note |
|
164 | + $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
|
165 | + |
|
166 | + // For changelog thanks to 3Dev |
|
167 | + global $xoopsModule; |
|
168 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
169 | + if (is_file($filename)) { |
|
170 | + $filesize = filesize($filename); |
|
171 | + $handle = fopen($filename, 'r'); |
|
172 | + $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
173 | + fclose($handle); |
|
174 | + } |
|
175 | + |
|
176 | + $this->_tpl->display('db:smartobject_about.tpl'); |
|
177 | + |
|
178 | + smart_modFooter(); |
|
179 | + |
|
180 | + xoops_cp_footer(); |
|
181 | + } |
|
182 | 182 | } |
@@ -49,11 +49,11 @@ discard block |
||
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 | include_once $fileName; |
55 | 55 | } else { |
56 | - include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php'; |
|
56 | + include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/english/modinfo.php'; |
|
57 | 57 | } |
58 | 58 | $this->_aboutTitle = $aboutTitle; |
59 | 59 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | //smart_adminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
106 | 106 | |
107 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
107 | + include_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
108 | 108 | |
109 | 109 | // --- |
110 | 110 | // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $this->_tpl = new XoopsTpl(); |
113 | 113 | // --- |
114 | 114 | |
115 | - $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
115 | + $this->_tpl->assign('module_url', XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/'); |
|
116 | 116 | $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
117 | 117 | $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
118 | 118 | $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | // Left headings... |
122 | 122 | if ($versioninfo->getInfo('author_realname') !== '') { |
123 | - $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
123 | + $author_name = $versioninfo->getInfo('author').' ('.$versioninfo->getInfo('author_realname').')'; |
|
124 | 124 | } else { |
125 | 125 | $author_name = $versioninfo->getInfo('author'); |
126 | 126 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | // For changelog thanks to 3Dev |
167 | 167 | global $xoopsModule; |
168 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
168 | + $filename = XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/changelog.txt'; |
|
169 | 169 | if (is_file($filename)) { |
170 | 170 | $filesize = filesize($filename); |
171 | 171 | $handle = fopen($filename, 'r'); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
20 | 20 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
21 | - include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
21 | + include_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 |
||
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,500 +35,500 @@ discard block |
||
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) && ($existing_field['Default'] || $existing_field['Default'] === '' || $existing_field['Default'] == 0)) { |
|
136 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $fields; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param $field |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function fieldExists($field) |
|
148 | - { |
|
149 | - $existingFields = $this->getExistingFieldsArray(); |
|
150 | - |
|
151 | - return isset($existingFields[$field]); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Set the table structure |
|
156 | - * |
|
157 | - * Example: |
|
158 | - * |
|
159 | - * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
160 | - * `date` int(11) NOT NULL default '0', |
|
161 | - * `status` int(1) NOT NULL default '-1', |
|
162 | - * `itemid` int(11) NOT NULL default '0', |
|
163 | - * `uid` int(11) NOT NULL default '0', |
|
164 | - * `price` float NOT NULL default '0', |
|
165 | - * `currency` varchar(100) NOT NULL default '', |
|
166 | - * PRIMARY KEY (`transactionid`)"); |
|
167 | - * |
|
168 | - * @param string $structure table structure |
|
169 | - * |
|
170 | - */ |
|
171 | - public function setStructure($structure) |
|
172 | - { |
|
173 | - $this->_structure = $structure; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Return the table structure |
|
178 | - * |
|
179 | - * @return string table structure |
|
180 | - * |
|
181 | - */ |
|
182 | - public function getStructure() |
|
183 | - { |
|
184 | - return sprintf($this->_structure, $this->name()); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Add values of a record to be added |
|
189 | - * |
|
190 | - * @param string $data values of a record |
|
191 | - * |
|
192 | - */ |
|
193 | - public function setData($data) |
|
194 | - { |
|
195 | - $this->_data[] = $data; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Get the data array |
|
200 | - * |
|
201 | - * @return array containing the records values to be added |
|
202 | - * |
|
203 | - */ |
|
204 | - public function getData() |
|
205 | - { |
|
206 | - return $this->_data; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Use to insert data in a table |
|
211 | - * |
|
212 | - * @return bool true if success, false if an error occured |
|
213 | - * |
|
214 | - */ |
|
215 | - public function addData() |
|
216 | - { |
|
217 | - global $xoopsDB; |
|
218 | - foreach ($this->getData() as $data) { |
|
219 | - $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
220 | - $ret = $xoopsDB->query($query); |
|
221 | - if (!$ret) { |
|
222 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
223 | - } else { |
|
224 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - return $ret; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Add a field to be added |
|
233 | - * |
|
234 | - * @param string $name name of the field |
|
235 | - * @param string $properties properties of the field |
|
236 | - * @param bool $newname |
|
237 | - * @param bool $showerror |
|
238 | - */ |
|
239 | - public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
240 | - { |
|
241 | - $field['name'] = $name; |
|
242 | - $field['properties'] = $properties; |
|
243 | - $field['showerror'] = $showerror; |
|
244 | - $field['newname'] = $newname; |
|
245 | - $this->_alteredFields[] = $field; |
|
246 | - } |
|
247 | - /** |
|
248 | - * Invert values 0 to 1 and 1 to 0 |
|
249 | - * |
|
250 | - * @param string $name name of the field |
|
251 | - * @param $newValue |
|
252 | - * @param $oldValue |
|
253 | - * @internal param string $old old propertie |
|
254 | - * @internal param string $new new propertie |
|
255 | - */ //felix |
|
256 | - public function addUpdatedWhere($name, $newValue, $oldValue) |
|
257 | - { |
|
258 | - $field['name'] = $name; |
|
259 | - $field['value'] = $newValue; |
|
260 | - $field['where'] = $oldValue; |
|
261 | - $this->_updatedWhere[] = $field; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Add new field of a record to be added |
|
266 | - * |
|
267 | - * @param string $name name of the field |
|
268 | - * @param string $properties properties of the field |
|
269 | - * |
|
270 | - */ |
|
271 | - public function addNewField($name, $properties) |
|
272 | - { |
|
273 | - $field['name'] = $name; |
|
274 | - $field['properties'] = $properties; |
|
275 | - $this->_newFields[] = $field; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Get fields that need to be altered |
|
280 | - * |
|
281 | - * @return array fields that need to be altered |
|
282 | - * |
|
283 | - */ |
|
284 | - public function getAlteredFields() |
|
285 | - { |
|
286 | - return $this->_alteredFields; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Add field for which the value will be updated |
|
291 | - * |
|
292 | - * @param string $name name of the field |
|
293 | - * @param string $value value to be set |
|
294 | - * |
|
295 | - */ |
|
296 | - public function addUpdatedField($name, $value) |
|
297 | - { |
|
298 | - $field['name'] = $name; |
|
299 | - $field['value'] = $value; |
|
300 | - $this->_updatedFields[] = $field; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Get new fields to be added |
|
305 | - * |
|
306 | - * @return array fields to be added |
|
307 | - * |
|
308 | - */ |
|
309 | - public function getNewFields() |
|
310 | - { |
|
311 | - return $this->_newFields; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Get fields which values need to be updated |
|
316 | - * |
|
317 | - * @return array fields which values need to be updated |
|
318 | - * |
|
319 | - */ |
|
320 | - public function getUpdatedFields() |
|
321 | - { |
|
322 | - return $this->_updatedFields; |
|
323 | - } |
|
324 | - /** |
|
325 | - * Get fields which values need to be updated |
|
326 | - * |
|
327 | - * @return array fields which values need to be updated |
|
328 | - * |
|
329 | - */ //felix |
|
330 | - public function getUpdatedWhere() |
|
331 | - { |
|
332 | - return $this->_updatedWhere; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Add values of a record to be added |
|
337 | - * |
|
338 | - * @param string $name name of the field |
|
339 | - * |
|
340 | - */ |
|
341 | - public function addDroppedField($name) |
|
342 | - { |
|
343 | - $this->_droppedFields[] = $name; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get fields that need to be dropped |
|
348 | - * |
|
349 | - * @return array fields that need to be dropped |
|
350 | - * |
|
351 | - */ |
|
352 | - public function getDroppedFields() |
|
353 | - { |
|
354 | - return $this->_droppedFields; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Set the flag to drop the table |
|
359 | - * |
|
360 | - */ |
|
361 | - public function setFlagForDrop() |
|
362 | - { |
|
363 | - $this->_flagForDrop = true; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Use to create a table |
|
368 | - * |
|
369 | - * @return bool true if success, false if an error occured |
|
370 | - * |
|
371 | - */ |
|
372 | - public function createTable() |
|
373 | - { |
|
374 | - global $xoopsDB; |
|
375 | - $query = $this->getStructure(); |
|
376 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
377 | - //xoops_debug($query); |
|
378 | - $ret = $xoopsDB->query($query); |
|
379 | - if (!$ret) { |
|
380 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
381 | - } else { |
|
382 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
383 | - } |
|
384 | - |
|
385 | - return $ret; |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Use to drop a table |
|
390 | - * |
|
391 | - * @return bool true if success, false if an error occured |
|
392 | - * |
|
393 | - */ |
|
394 | - public function dropTable() |
|
395 | - { |
|
396 | - global $xoopsDB; |
|
397 | - $query = sprintf('DROP TABLE %s', $this->name()); |
|
398 | - $ret = $xoopsDB->query($query); |
|
399 | - if (!$ret) { |
|
400 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
401 | - |
|
402 | - return false; |
|
403 | - } else { |
|
404 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
405 | - |
|
406 | - return true; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Use to alter a table |
|
412 | - * |
|
413 | - * @return bool true if success, false if an error occured |
|
414 | - * |
|
415 | - */ |
|
416 | - public function alterTable() |
|
417 | - { |
|
418 | - global $xoopsDB; |
|
419 | - $ret = true; |
|
420 | - |
|
421 | - foreach ($this->getAlteredFields() as $alteredField) { |
|
422 | - if (!$alteredField['newname']) { |
|
423 | - $alteredField['newname'] = $alteredField['name']; |
|
424 | - } |
|
425 | - |
|
426 | - $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
427 | - $ret = $ret && $xoopsDB->query($query); |
|
428 | - if ($alteredField['showerror']) { |
|
429 | - if (!$ret) { |
|
430 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
431 | - } else { |
|
432 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
433 | - } |
|
434 | - } |
|
435 | - } |
|
436 | - |
|
437 | - return $ret; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Use to add new fileds in the table |
|
442 | - * |
|
443 | - * @return bool true if success, false if an error occured |
|
444 | - * |
|
445 | - */ |
|
446 | - public function addNewFields() |
|
447 | - { |
|
448 | - global $xoopsDB; |
|
449 | - $ret = true; |
|
450 | - foreach ($this->getNewFields() as $newField) { |
|
451 | - $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
452 | - //echo $query; |
|
453 | - $ret = $ret && $xoopsDB->query($query); |
|
454 | - if (!$ret) { |
|
455 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
456 | - } else { |
|
457 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - return $ret; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Use to update fields values |
|
466 | - * |
|
467 | - * @return bool true if success, false if an error occured |
|
468 | - * |
|
469 | - */ |
|
470 | - public function updateFieldsValues() |
|
471 | - { |
|
472 | - global $xoopsDB; |
|
473 | - $ret = true; |
|
474 | - foreach ($this->getUpdatedFields() as $updatedField) { |
|
475 | - $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
476 | - $ret = $ret && $xoopsDB->query($query); |
|
477 | - if (!$ret) { |
|
478 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
479 | - } else { |
|
480 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
481 | - } |
|
482 | - } |
|
483 | - |
|
484 | - return $ret; |
|
485 | - } |
|
486 | - /** |
|
487 | - * Use to update fields values |
|
488 | - * |
|
489 | - * @return bool true if success, false if an error occured |
|
490 | - * |
|
491 | - */ //felix |
|
492 | - public function updateWhereValues() |
|
493 | - { |
|
494 | - global $xoopsDB; |
|
495 | - $ret = true; |
|
496 | - foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
497 | - $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
498 | - //echo $query."<br>"; |
|
499 | - $ret = $ret && $xoopsDB->query($query); |
|
500 | - if (!$ret) { |
|
501 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
502 | - } else { |
|
503 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - return $ret; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Use to drop fields |
|
512 | - * |
|
513 | - * @return bool true if success, false if an error occured |
|
514 | - * |
|
515 | - */ |
|
516 | - public function dropFields() |
|
517 | - { |
|
518 | - global $xoopsDB; |
|
519 | - $ret = true; |
|
520 | - foreach ($this->getDroppedFields() as $droppedField) { |
|
521 | - $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
522 | - $ret = $ret && $xoopsDB->query($query); |
|
523 | - if (!$ret) { |
|
524 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
525 | - } else { |
|
526 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - return $ret; |
|
531 | - } |
|
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) && ($existing_field['Default'] || $existing_field['Default'] === '' || $existing_field['Default'] == 0)) { |
|
136 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $fields; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param $field |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function fieldExists($field) |
|
148 | + { |
|
149 | + $existingFields = $this->getExistingFieldsArray(); |
|
150 | + |
|
151 | + return isset($existingFields[$field]); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Set the table structure |
|
156 | + * |
|
157 | + * Example: |
|
158 | + * |
|
159 | + * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
160 | + * `date` int(11) NOT NULL default '0', |
|
161 | + * `status` int(1) NOT NULL default '-1', |
|
162 | + * `itemid` int(11) NOT NULL default '0', |
|
163 | + * `uid` int(11) NOT NULL default '0', |
|
164 | + * `price` float NOT NULL default '0', |
|
165 | + * `currency` varchar(100) NOT NULL default '', |
|
166 | + * PRIMARY KEY (`transactionid`)"); |
|
167 | + * |
|
168 | + * @param string $structure table structure |
|
169 | + * |
|
170 | + */ |
|
171 | + public function setStructure($structure) |
|
172 | + { |
|
173 | + $this->_structure = $structure; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Return the table structure |
|
178 | + * |
|
179 | + * @return string table structure |
|
180 | + * |
|
181 | + */ |
|
182 | + public function getStructure() |
|
183 | + { |
|
184 | + return sprintf($this->_structure, $this->name()); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Add values of a record to be added |
|
189 | + * |
|
190 | + * @param string $data values of a record |
|
191 | + * |
|
192 | + */ |
|
193 | + public function setData($data) |
|
194 | + { |
|
195 | + $this->_data[] = $data; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Get the data array |
|
200 | + * |
|
201 | + * @return array containing the records values to be added |
|
202 | + * |
|
203 | + */ |
|
204 | + public function getData() |
|
205 | + { |
|
206 | + return $this->_data; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Use to insert data in a table |
|
211 | + * |
|
212 | + * @return bool true if success, false if an error occured |
|
213 | + * |
|
214 | + */ |
|
215 | + public function addData() |
|
216 | + { |
|
217 | + global $xoopsDB; |
|
218 | + foreach ($this->getData() as $data) { |
|
219 | + $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
220 | + $ret = $xoopsDB->query($query); |
|
221 | + if (!$ret) { |
|
222 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
223 | + } else { |
|
224 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + return $ret; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Add a field to be added |
|
233 | + * |
|
234 | + * @param string $name name of the field |
|
235 | + * @param string $properties properties of the field |
|
236 | + * @param bool $newname |
|
237 | + * @param bool $showerror |
|
238 | + */ |
|
239 | + public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
240 | + { |
|
241 | + $field['name'] = $name; |
|
242 | + $field['properties'] = $properties; |
|
243 | + $field['showerror'] = $showerror; |
|
244 | + $field['newname'] = $newname; |
|
245 | + $this->_alteredFields[] = $field; |
|
246 | + } |
|
247 | + /** |
|
248 | + * Invert values 0 to 1 and 1 to 0 |
|
249 | + * |
|
250 | + * @param string $name name of the field |
|
251 | + * @param $newValue |
|
252 | + * @param $oldValue |
|
253 | + * @internal param string $old old propertie |
|
254 | + * @internal param string $new new propertie |
|
255 | + */ //felix |
|
256 | + public function addUpdatedWhere($name, $newValue, $oldValue) |
|
257 | + { |
|
258 | + $field['name'] = $name; |
|
259 | + $field['value'] = $newValue; |
|
260 | + $field['where'] = $oldValue; |
|
261 | + $this->_updatedWhere[] = $field; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Add new field of a record to be added |
|
266 | + * |
|
267 | + * @param string $name name of the field |
|
268 | + * @param string $properties properties of the field |
|
269 | + * |
|
270 | + */ |
|
271 | + public function addNewField($name, $properties) |
|
272 | + { |
|
273 | + $field['name'] = $name; |
|
274 | + $field['properties'] = $properties; |
|
275 | + $this->_newFields[] = $field; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Get fields that need to be altered |
|
280 | + * |
|
281 | + * @return array fields that need to be altered |
|
282 | + * |
|
283 | + */ |
|
284 | + public function getAlteredFields() |
|
285 | + { |
|
286 | + return $this->_alteredFields; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Add field for which the value will be updated |
|
291 | + * |
|
292 | + * @param string $name name of the field |
|
293 | + * @param string $value value to be set |
|
294 | + * |
|
295 | + */ |
|
296 | + public function addUpdatedField($name, $value) |
|
297 | + { |
|
298 | + $field['name'] = $name; |
|
299 | + $field['value'] = $value; |
|
300 | + $this->_updatedFields[] = $field; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Get new fields to be added |
|
305 | + * |
|
306 | + * @return array fields to be added |
|
307 | + * |
|
308 | + */ |
|
309 | + public function getNewFields() |
|
310 | + { |
|
311 | + return $this->_newFields; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Get fields which values need to be updated |
|
316 | + * |
|
317 | + * @return array fields which values need to be updated |
|
318 | + * |
|
319 | + */ |
|
320 | + public function getUpdatedFields() |
|
321 | + { |
|
322 | + return $this->_updatedFields; |
|
323 | + } |
|
324 | + /** |
|
325 | + * Get fields which values need to be updated |
|
326 | + * |
|
327 | + * @return array fields which values need to be updated |
|
328 | + * |
|
329 | + */ //felix |
|
330 | + public function getUpdatedWhere() |
|
331 | + { |
|
332 | + return $this->_updatedWhere; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Add values of a record to be added |
|
337 | + * |
|
338 | + * @param string $name name of the field |
|
339 | + * |
|
340 | + */ |
|
341 | + public function addDroppedField($name) |
|
342 | + { |
|
343 | + $this->_droppedFields[] = $name; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get fields that need to be dropped |
|
348 | + * |
|
349 | + * @return array fields that need to be dropped |
|
350 | + * |
|
351 | + */ |
|
352 | + public function getDroppedFields() |
|
353 | + { |
|
354 | + return $this->_droppedFields; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Set the flag to drop the table |
|
359 | + * |
|
360 | + */ |
|
361 | + public function setFlagForDrop() |
|
362 | + { |
|
363 | + $this->_flagForDrop = true; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Use to create a table |
|
368 | + * |
|
369 | + * @return bool true if success, false if an error occured |
|
370 | + * |
|
371 | + */ |
|
372 | + public function createTable() |
|
373 | + { |
|
374 | + global $xoopsDB; |
|
375 | + $query = $this->getStructure(); |
|
376 | + $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
377 | + //xoops_debug($query); |
|
378 | + $ret = $xoopsDB->query($query); |
|
379 | + if (!$ret) { |
|
380 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
381 | + } else { |
|
382 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
383 | + } |
|
384 | + |
|
385 | + return $ret; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Use to drop a table |
|
390 | + * |
|
391 | + * @return bool true if success, false if an error occured |
|
392 | + * |
|
393 | + */ |
|
394 | + public function dropTable() |
|
395 | + { |
|
396 | + global $xoopsDB; |
|
397 | + $query = sprintf('DROP TABLE %s', $this->name()); |
|
398 | + $ret = $xoopsDB->query($query); |
|
399 | + if (!$ret) { |
|
400 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
401 | + |
|
402 | + return false; |
|
403 | + } else { |
|
404 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
405 | + |
|
406 | + return true; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Use to alter a table |
|
412 | + * |
|
413 | + * @return bool true if success, false if an error occured |
|
414 | + * |
|
415 | + */ |
|
416 | + public function alterTable() |
|
417 | + { |
|
418 | + global $xoopsDB; |
|
419 | + $ret = true; |
|
420 | + |
|
421 | + foreach ($this->getAlteredFields() as $alteredField) { |
|
422 | + if (!$alteredField['newname']) { |
|
423 | + $alteredField['newname'] = $alteredField['name']; |
|
424 | + } |
|
425 | + |
|
426 | + $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
427 | + $ret = $ret && $xoopsDB->query($query); |
|
428 | + if ($alteredField['showerror']) { |
|
429 | + if (!$ret) { |
|
430 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
431 | + } else { |
|
432 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
433 | + } |
|
434 | + } |
|
435 | + } |
|
436 | + |
|
437 | + return $ret; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Use to add new fileds in the table |
|
442 | + * |
|
443 | + * @return bool true if success, false if an error occured |
|
444 | + * |
|
445 | + */ |
|
446 | + public function addNewFields() |
|
447 | + { |
|
448 | + global $xoopsDB; |
|
449 | + $ret = true; |
|
450 | + foreach ($this->getNewFields() as $newField) { |
|
451 | + $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
452 | + //echo $query; |
|
453 | + $ret = $ret && $xoopsDB->query($query); |
|
454 | + if (!$ret) { |
|
455 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
456 | + } else { |
|
457 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + return $ret; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Use to update fields values |
|
466 | + * |
|
467 | + * @return bool true if success, false if an error occured |
|
468 | + * |
|
469 | + */ |
|
470 | + public function updateFieldsValues() |
|
471 | + { |
|
472 | + global $xoopsDB; |
|
473 | + $ret = true; |
|
474 | + foreach ($this->getUpdatedFields() as $updatedField) { |
|
475 | + $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
476 | + $ret = $ret && $xoopsDB->query($query); |
|
477 | + if (!$ret) { |
|
478 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
479 | + } else { |
|
480 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
481 | + } |
|
482 | + } |
|
483 | + |
|
484 | + return $ret; |
|
485 | + } |
|
486 | + /** |
|
487 | + * Use to update fields values |
|
488 | + * |
|
489 | + * @return bool true if success, false if an error occured |
|
490 | + * |
|
491 | + */ //felix |
|
492 | + public function updateWhereValues() |
|
493 | + { |
|
494 | + global $xoopsDB; |
|
495 | + $ret = true; |
|
496 | + foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
497 | + $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
498 | + //echo $query."<br>"; |
|
499 | + $ret = $ret && $xoopsDB->query($query); |
|
500 | + if (!$ret) { |
|
501 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
502 | + } else { |
|
503 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + return $ret; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Use to drop fields |
|
512 | + * |
|
513 | + * @return bool true if success, false if an error occured |
|
514 | + * |
|
515 | + */ |
|
516 | + public function dropFields() |
|
517 | + { |
|
518 | + global $xoopsDB; |
|
519 | + $ret = true; |
|
520 | + foreach ($this->getDroppedFields() as $droppedField) { |
|
521 | + $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
522 | + $ret = $ret && $xoopsDB->query($query); |
|
523 | + if (!$ret) { |
|
524 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
525 | + } else { |
|
526 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + return $ret; |
|
531 | + } |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
@@ -542,328 +542,328 @@ discard block |
||
542 | 542 | */ |
543 | 543 | class SmartobjectDbupdater |
544 | 544 | { |
545 | - public $_dbTypesArray; |
|
546 | - |
|
547 | - /** |
|
548 | - * SmartobjectDbupdater constructor. |
|
549 | - */ |
|
550 | - public function __construct() |
|
551 | - { |
|
552 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
553 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
554 | - $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
555 | - $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
556 | - $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
557 | - $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
558 | - $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
559 | - $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
560 | - $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
561 | - $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
562 | - $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
563 | - $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
564 | - $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
565 | - $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
566 | - $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
567 | - $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
568 | - $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
569 | - $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Use to execute a general query |
|
574 | - * |
|
575 | - * @param string $query query that will be executed |
|
576 | - * @param string $goodmsg message displayed on success |
|
577 | - * @param string $badmsg message displayed on error |
|
578 | - * |
|
579 | - * @return bool true if success, false if an error occured |
|
580 | - * |
|
581 | - */ |
|
582 | - public function runQuery($query, $goodmsg, $badmsg) |
|
583 | - { |
|
584 | - global $xoopsDB; |
|
585 | - $ret = $xoopsDB->query($query); |
|
586 | - if (!$ret) { |
|
587 | - echo " $badmsg<br>"; |
|
588 | - |
|
589 | - return false; |
|
590 | - } else { |
|
591 | - echo " $goodmsg<br>"; |
|
592 | - |
|
593 | - return true; |
|
594 | - } |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Use to rename a table |
|
599 | - * |
|
600 | - * @param string $from name of the table to rename |
|
601 | - * @param string $to new name of the renamed table |
|
602 | - * |
|
603 | - * @return bool true if success, false if an error occured |
|
604 | - */ |
|
605 | - public function renameTable($from, $to) |
|
606 | - { |
|
607 | - global $xoopsDB; |
|
608 | - $from = $xoopsDB->prefix($from); |
|
609 | - $to = $xoopsDB->prefix($to); |
|
610 | - $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
611 | - $ret = $xoopsDB->query($query); |
|
612 | - if (!$ret) { |
|
613 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
614 | - |
|
615 | - return false; |
|
616 | - } else { |
|
617 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
618 | - |
|
619 | - return true; |
|
620 | - } |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * Use to update a table |
|
625 | - * |
|
626 | - * @param object $table {@link SmartDbTable} that will be updated |
|
627 | - * |
|
628 | - * @see SmartDbTable |
|
629 | - * |
|
630 | - * @return bool true if success, false if an error occured |
|
631 | - */ |
|
632 | - public function updateTable($table) |
|
633 | - { |
|
634 | - global $xoopsDB; |
|
635 | - $ret = true; |
|
636 | - // If table has a structure, create the table |
|
637 | - if ($table->getStructure()) { |
|
638 | - $ret = $table->createTable() && $ret; |
|
639 | - } |
|
640 | - // If table is flag for drop, drop it |
|
641 | - if ($table->_flagForDrop) { |
|
642 | - $ret = $table->dropTable() && $ret; |
|
643 | - } |
|
644 | - // If table has data, insert it |
|
645 | - if ($table->getData()) { |
|
646 | - $ret = $table->addData() && $ret; |
|
647 | - } |
|
648 | - // If table has new fields to be added, add them |
|
649 | - if ($table->getNewFields()) { |
|
650 | - $ret = $table->addNewFields() && $ret; |
|
651 | - } |
|
652 | - // If table has altered field, alter the table |
|
653 | - if ($table->getAlteredFields()) { |
|
654 | - $ret = $table->alterTable() && $ret; |
|
655 | - } |
|
656 | - // If table has updated field values, update the table |
|
657 | - if ($table->getUpdatedFields()) { |
|
658 | - $ret = $table->updateFieldsValues($table) && $ret; |
|
659 | - } |
|
660 | - // If table has dropped field, alter the table |
|
661 | - if ($table->getDroppedFields()) { |
|
662 | - $ret = $table->dropFields($table) && $ret; |
|
663 | - } |
|
664 | - //felix |
|
665 | - // If table has updated field values, update the table |
|
666 | - if ($table->getUpdatedWhere()) { |
|
667 | - $ret = $table->UpdateWhereValues($table) && $ret; |
|
668 | - } |
|
669 | - |
|
670 | - return $ret; |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * @param $module |
|
675 | - * @param $item |
|
676 | - */ |
|
677 | - public function automaticUpgrade($module, $item) |
|
678 | - { |
|
679 | - if (is_array($item)) { |
|
680 | - foreach ($item as $v) { |
|
681 | - $this->upgradeObjectItem($module, $v); |
|
682 | - } |
|
683 | - } else { |
|
684 | - $this->upgradeObjectItem($module, $item); |
|
685 | - } |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * @param $var |
|
690 | - * @return string |
|
691 | - */ |
|
692 | - public function getFieldTypeFromVar($var) |
|
693 | - { |
|
694 | - $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
695 | - |
|
696 | - return $ret; |
|
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * @param $var |
|
701 | - * @param bool $key |
|
702 | - * @return string |
|
703 | - */ |
|
704 | - public function getFieldDefaultFromVar($var, $key = false) |
|
705 | - { |
|
706 | - if ($var['value']) { |
|
707 | - return $var['value']; |
|
708 | - } else { |
|
709 | - if (in_array($var['data_type'], array( |
|
710 | - XOBJ_DTYPE_INT, |
|
711 | - XOBJ_DTYPE_STIME, |
|
712 | - XOBJ_DTYPE_MTIME, |
|
713 | - XOBJ_DTYPE_LTIME, |
|
714 | - XOBJ_DTYPE_TIME_ONLY, |
|
715 | - XOBJ_DTYPE_URLLINK, |
|
716 | - XOBJ_DTYPE_FILE |
|
717 | - ))) { |
|
718 | - return '0'; |
|
719 | - } else { |
|
720 | - return ''; |
|
721 | - } |
|
722 | - } |
|
723 | - } |
|
724 | - |
|
725 | - /** |
|
726 | - * @param $module |
|
727 | - * @param $item |
|
728 | - * @return bool |
|
729 | - */ |
|
730 | - public function upgradeObjectItem($module, $item) |
|
731 | - { |
|
732 | - $moduleHandler = xoops_getModuleHandler($item, $module); |
|
733 | - if (!$moduleHandler) { |
|
734 | - return false; |
|
735 | - } |
|
736 | - |
|
737 | - $table = new SmartDbTable($module . '_' . $item); |
|
738 | - $object = $moduleHandler->create(); |
|
739 | - $objectVars = $object->getVars(); |
|
740 | - |
|
741 | - if (!$table->exists()) { |
|
742 | - // table was never created, let's do it |
|
743 | - $structure = ''; |
|
744 | - foreach ($objectVars as $key => $var) { |
|
745 | - if ($var['persistent']) { |
|
746 | - $type = $this->getFieldTypeFromVar($var); |
|
747 | - if ($key == $moduleHandler->keyName) { |
|
748 | - $extra = 'auto_increment'; |
|
749 | - } else { |
|
750 | - $default = $this->getFieldDefaultFromVar($var); |
|
751 | - $extra = "default '$default' |
|
545 | + public $_dbTypesArray; |
|
546 | + |
|
547 | + /** |
|
548 | + * SmartobjectDbupdater constructor. |
|
549 | + */ |
|
550 | + public function __construct() |
|
551 | + { |
|
552 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
553 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
554 | + $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
555 | + $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
556 | + $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
557 | + $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
558 | + $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
559 | + $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
560 | + $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
561 | + $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
562 | + $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
563 | + $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
564 | + $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
565 | + $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
566 | + $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
567 | + $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
568 | + $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
569 | + $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Use to execute a general query |
|
574 | + * |
|
575 | + * @param string $query query that will be executed |
|
576 | + * @param string $goodmsg message displayed on success |
|
577 | + * @param string $badmsg message displayed on error |
|
578 | + * |
|
579 | + * @return bool true if success, false if an error occured |
|
580 | + * |
|
581 | + */ |
|
582 | + public function runQuery($query, $goodmsg, $badmsg) |
|
583 | + { |
|
584 | + global $xoopsDB; |
|
585 | + $ret = $xoopsDB->query($query); |
|
586 | + if (!$ret) { |
|
587 | + echo " $badmsg<br>"; |
|
588 | + |
|
589 | + return false; |
|
590 | + } else { |
|
591 | + echo " $goodmsg<br>"; |
|
592 | + |
|
593 | + return true; |
|
594 | + } |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Use to rename a table |
|
599 | + * |
|
600 | + * @param string $from name of the table to rename |
|
601 | + * @param string $to new name of the renamed table |
|
602 | + * |
|
603 | + * @return bool true if success, false if an error occured |
|
604 | + */ |
|
605 | + public function renameTable($from, $to) |
|
606 | + { |
|
607 | + global $xoopsDB; |
|
608 | + $from = $xoopsDB->prefix($from); |
|
609 | + $to = $xoopsDB->prefix($to); |
|
610 | + $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
611 | + $ret = $xoopsDB->query($query); |
|
612 | + if (!$ret) { |
|
613 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
614 | + |
|
615 | + return false; |
|
616 | + } else { |
|
617 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
618 | + |
|
619 | + return true; |
|
620 | + } |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * Use to update a table |
|
625 | + * |
|
626 | + * @param object $table {@link SmartDbTable} that will be updated |
|
627 | + * |
|
628 | + * @see SmartDbTable |
|
629 | + * |
|
630 | + * @return bool true if success, false if an error occured |
|
631 | + */ |
|
632 | + public function updateTable($table) |
|
633 | + { |
|
634 | + global $xoopsDB; |
|
635 | + $ret = true; |
|
636 | + // If table has a structure, create the table |
|
637 | + if ($table->getStructure()) { |
|
638 | + $ret = $table->createTable() && $ret; |
|
639 | + } |
|
640 | + // If table is flag for drop, drop it |
|
641 | + if ($table->_flagForDrop) { |
|
642 | + $ret = $table->dropTable() && $ret; |
|
643 | + } |
|
644 | + // If table has data, insert it |
|
645 | + if ($table->getData()) { |
|
646 | + $ret = $table->addData() && $ret; |
|
647 | + } |
|
648 | + // If table has new fields to be added, add them |
|
649 | + if ($table->getNewFields()) { |
|
650 | + $ret = $table->addNewFields() && $ret; |
|
651 | + } |
|
652 | + // If table has altered field, alter the table |
|
653 | + if ($table->getAlteredFields()) { |
|
654 | + $ret = $table->alterTable() && $ret; |
|
655 | + } |
|
656 | + // If table has updated field values, update the table |
|
657 | + if ($table->getUpdatedFields()) { |
|
658 | + $ret = $table->updateFieldsValues($table) && $ret; |
|
659 | + } |
|
660 | + // If table has dropped field, alter the table |
|
661 | + if ($table->getDroppedFields()) { |
|
662 | + $ret = $table->dropFields($table) && $ret; |
|
663 | + } |
|
664 | + //felix |
|
665 | + // If table has updated field values, update the table |
|
666 | + if ($table->getUpdatedWhere()) { |
|
667 | + $ret = $table->UpdateWhereValues($table) && $ret; |
|
668 | + } |
|
669 | + |
|
670 | + return $ret; |
|
671 | + } |
|
672 | + |
|
673 | + /** |
|
674 | + * @param $module |
|
675 | + * @param $item |
|
676 | + */ |
|
677 | + public function automaticUpgrade($module, $item) |
|
678 | + { |
|
679 | + if (is_array($item)) { |
|
680 | + foreach ($item as $v) { |
|
681 | + $this->upgradeObjectItem($module, $v); |
|
682 | + } |
|
683 | + } else { |
|
684 | + $this->upgradeObjectItem($module, $item); |
|
685 | + } |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * @param $var |
|
690 | + * @return string |
|
691 | + */ |
|
692 | + public function getFieldTypeFromVar($var) |
|
693 | + { |
|
694 | + $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
695 | + |
|
696 | + return $ret; |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * @param $var |
|
701 | + * @param bool $key |
|
702 | + * @return string |
|
703 | + */ |
|
704 | + public function getFieldDefaultFromVar($var, $key = false) |
|
705 | + { |
|
706 | + if ($var['value']) { |
|
707 | + return $var['value']; |
|
708 | + } else { |
|
709 | + if (in_array($var['data_type'], array( |
|
710 | + XOBJ_DTYPE_INT, |
|
711 | + XOBJ_DTYPE_STIME, |
|
712 | + XOBJ_DTYPE_MTIME, |
|
713 | + XOBJ_DTYPE_LTIME, |
|
714 | + XOBJ_DTYPE_TIME_ONLY, |
|
715 | + XOBJ_DTYPE_URLLINK, |
|
716 | + XOBJ_DTYPE_FILE |
|
717 | + ))) { |
|
718 | + return '0'; |
|
719 | + } else { |
|
720 | + return ''; |
|
721 | + } |
|
722 | + } |
|
723 | + } |
|
724 | + |
|
725 | + /** |
|
726 | + * @param $module |
|
727 | + * @param $item |
|
728 | + * @return bool |
|
729 | + */ |
|
730 | + public function upgradeObjectItem($module, $item) |
|
731 | + { |
|
732 | + $moduleHandler = xoops_getModuleHandler($item, $module); |
|
733 | + if (!$moduleHandler) { |
|
734 | + return false; |
|
735 | + } |
|
736 | + |
|
737 | + $table = new SmartDbTable($module . '_' . $item); |
|
738 | + $object = $moduleHandler->create(); |
|
739 | + $objectVars = $object->getVars(); |
|
740 | + |
|
741 | + if (!$table->exists()) { |
|
742 | + // table was never created, let's do it |
|
743 | + $structure = ''; |
|
744 | + foreach ($objectVars as $key => $var) { |
|
745 | + if ($var['persistent']) { |
|
746 | + $type = $this->getFieldTypeFromVar($var); |
|
747 | + if ($key == $moduleHandler->keyName) { |
|
748 | + $extra = 'auto_increment'; |
|
749 | + } else { |
|
750 | + $default = $this->getFieldDefaultFromVar($var); |
|
751 | + $extra = "default '$default' |
|
752 | 752 | "; |
753 | - } |
|
754 | - $structure .= "`$key` $type not null $extra, |
|
753 | + } |
|
754 | + $structure .= "`$key` $type not null $extra, |
|
755 | 755 | "; |
756 | - } |
|
757 | - } |
|
758 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
756 | + } |
|
757 | + } |
|
758 | + $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
759 | 759 | '; |
760 | - $table->setStructure($structure); |
|
761 | - if (!$this->updateTable($table)) { |
|
762 | - /** |
|
763 | - * @todo trap the errors |
|
764 | - */ |
|
765 | - } |
|
766 | - } else { |
|
767 | - $existingFieldsArray = $table->getExistingFieldsArray(); |
|
768 | - foreach ($objectVars as $key => $var) { |
|
769 | - if ($var['persistent']) { |
|
770 | - if (!isset($existingFieldsArray[$key])) { |
|
771 | - // the fiels does not exist, let's create it |
|
772 | - $type = $this->getFieldTypeFromVar($var); |
|
773 | - $default = $this->getFieldDefaultFromVar($var); |
|
774 | - $table->addNewField($key, "$type not null default '$default'"); |
|
775 | - } else { |
|
776 | - // if field already exists, let's check if the definition is correct |
|
777 | - $definition = strtolower($existingFieldsArray[$key]); |
|
778 | - $type = $this->getFieldTypeFromVar($var); |
|
779 | - if ($key == $moduleHandler->keyName) { |
|
780 | - $extra = 'auto_increment'; |
|
781 | - } else { |
|
782 | - $default = $this->getFieldDefaultFromVar($var, $key); |
|
783 | - $extra = "default '$default'"; |
|
784 | - } |
|
785 | - $actual_definition = "$type not null $extra"; |
|
786 | - if ($definition != $actual_definition) { |
|
787 | - $table->addAlteredField($key, $actual_definition); |
|
788 | - } |
|
789 | - } |
|
790 | - } |
|
791 | - } |
|
792 | - |
|
793 | - // check to see if there are some unused fields left in the table |
|
794 | - foreach ($existingFieldsArray as $key => $v) { |
|
795 | - if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
796 | - $table->addDroppedField($key); |
|
797 | - } |
|
798 | - } |
|
799 | - |
|
800 | - if (!$this->updateTable($table)) { |
|
801 | - /** |
|
802 | - * @todo trap the errors |
|
803 | - */ |
|
804 | - } |
|
805 | - } |
|
806 | - } |
|
807 | - |
|
808 | - /** |
|
809 | - * @param $module |
|
810 | - * @return bool |
|
811 | - */ |
|
812 | - public function moduleUpgrade(&$module) |
|
813 | - { |
|
814 | - $dirname = $module->getVar('dirname'); |
|
815 | - |
|
816 | - ob_start(); |
|
817 | - |
|
818 | - $table = new SmartDbTable($dirname . '_meta'); |
|
819 | - if (!$table->exists()) { |
|
820 | - $table->setStructure(" |
|
760 | + $table->setStructure($structure); |
|
761 | + if (!$this->updateTable($table)) { |
|
762 | + /** |
|
763 | + * @todo trap the errors |
|
764 | + */ |
|
765 | + } |
|
766 | + } else { |
|
767 | + $existingFieldsArray = $table->getExistingFieldsArray(); |
|
768 | + foreach ($objectVars as $key => $var) { |
|
769 | + if ($var['persistent']) { |
|
770 | + if (!isset($existingFieldsArray[$key])) { |
|
771 | + // the fiels does not exist, let's create it |
|
772 | + $type = $this->getFieldTypeFromVar($var); |
|
773 | + $default = $this->getFieldDefaultFromVar($var); |
|
774 | + $table->addNewField($key, "$type not null default '$default'"); |
|
775 | + } else { |
|
776 | + // if field already exists, let's check if the definition is correct |
|
777 | + $definition = strtolower($existingFieldsArray[$key]); |
|
778 | + $type = $this->getFieldTypeFromVar($var); |
|
779 | + if ($key == $moduleHandler->keyName) { |
|
780 | + $extra = 'auto_increment'; |
|
781 | + } else { |
|
782 | + $default = $this->getFieldDefaultFromVar($var, $key); |
|
783 | + $extra = "default '$default'"; |
|
784 | + } |
|
785 | + $actual_definition = "$type not null $extra"; |
|
786 | + if ($definition != $actual_definition) { |
|
787 | + $table->addAlteredField($key, $actual_definition); |
|
788 | + } |
|
789 | + } |
|
790 | + } |
|
791 | + } |
|
792 | + |
|
793 | + // check to see if there are some unused fields left in the table |
|
794 | + foreach ($existingFieldsArray as $key => $v) { |
|
795 | + if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
796 | + $table->addDroppedField($key); |
|
797 | + } |
|
798 | + } |
|
799 | + |
|
800 | + if (!$this->updateTable($table)) { |
|
801 | + /** |
|
802 | + * @todo trap the errors |
|
803 | + */ |
|
804 | + } |
|
805 | + } |
|
806 | + } |
|
807 | + |
|
808 | + /** |
|
809 | + * @param $module |
|
810 | + * @return bool |
|
811 | + */ |
|
812 | + public function moduleUpgrade(&$module) |
|
813 | + { |
|
814 | + $dirname = $module->getVar('dirname'); |
|
815 | + |
|
816 | + ob_start(); |
|
817 | + |
|
818 | + $table = new SmartDbTable($dirname . '_meta'); |
|
819 | + if (!$table->exists()) { |
|
820 | + $table->setStructure(" |
|
821 | 821 | `metakey` varchar(50) NOT NULL default '', |
822 | 822 | `metavalue` varchar(255) NOT NULL default '', |
823 | 823 | PRIMARY KEY (`metakey`)"); |
824 | - $table->setData("'version',0"); |
|
825 | - if (!$this->updateTable($table)) { |
|
826 | - /** |
|
827 | - * @todo trap the errors |
|
828 | - */ |
|
829 | - } |
|
830 | - } |
|
831 | - |
|
832 | - $dbVersion = smart_GetMeta('version', $dirname); |
|
833 | - if (!$dbVersion) { |
|
834 | - $dbVersion = 0; |
|
835 | - } |
|
836 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
837 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
838 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
839 | - |
|
840 | - if ($newDbVersion > $dbVersion) { |
|
841 | - for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
842 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
843 | - if (function_exists($upgrade_function)) { |
|
844 | - $upgrade_function(); |
|
845 | - } |
|
846 | - } |
|
847 | - } |
|
848 | - |
|
849 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
850 | - |
|
851 | - // if there is a function to execute for this DB version, let's do it |
|
852 | - //$function_ |
|
853 | - |
|
854 | - $module_info = smart_getModuleInfo($dirname); |
|
855 | - $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
856 | - |
|
857 | - echo '</code>'; |
|
858 | - |
|
859 | - $feedback = ob_get_clean(); |
|
860 | - if (method_exists($module, 'setMessage')) { |
|
861 | - $module->setMessage($feedback); |
|
862 | - } else { |
|
863 | - echo $feedback; |
|
864 | - } |
|
865 | - smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
866 | - |
|
867 | - return true; |
|
868 | - } |
|
824 | + $table->setData("'version',0"); |
|
825 | + if (!$this->updateTable($table)) { |
|
826 | + /** |
|
827 | + * @todo trap the errors |
|
828 | + */ |
|
829 | + } |
|
830 | + } |
|
831 | + |
|
832 | + $dbVersion = smart_GetMeta('version', $dirname); |
|
833 | + if (!$dbVersion) { |
|
834 | + $dbVersion = 0; |
|
835 | + } |
|
836 | + $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
837 | + echo 'Database version: ' . $dbVersion . '<br>'; |
|
838 | + echo 'New database version: ' . $newDbVersion . '<br>'; |
|
839 | + |
|
840 | + if ($newDbVersion > $dbVersion) { |
|
841 | + for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
842 | + $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
843 | + if (function_exists($upgrade_function)) { |
|
844 | + $upgrade_function(); |
|
845 | + } |
|
846 | + } |
|
847 | + } |
|
848 | + |
|
849 | + echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
850 | + |
|
851 | + // if there is a function to execute for this DB version, let's do it |
|
852 | + //$function_ |
|
853 | + |
|
854 | + $module_info = smart_getModuleInfo($dirname); |
|
855 | + $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
856 | + |
|
857 | + echo '</code>'; |
|
858 | + |
|
859 | + $feedback = ob_get_clean(); |
|
860 | + if (method_exists($module, 'setMessage')) { |
|
861 | + $module->setMessage($feedback); |
|
862 | + } else { |
|
863 | + echo $feedback; |
|
864 | + } |
|
865 | + smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
866 | + |
|
867 | + return true; |
|
868 | + } |
|
869 | 869 | } |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | */ |
19 | 19 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
20 | 20 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
21 | - include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
21 | + include_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,17 +123,17 @@ discard block |
||
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) && ($existing_field['Default'] || $existing_field['Default'] === '' || $existing_field['Default'] == 0)) { |
136 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
136 | + $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'"; |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
@@ -219,9 +219,9 @@ discard block |
||
219 | 219 | $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
220 | 220 | $ret = $xoopsDB->query($query); |
221 | 221 | if (!$ret) { |
222 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
222 | + echo ' '.sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()).'<br>'; |
|
223 | 223 | } else { |
224 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
224 | + echo ' '.sprintf(_SDU_MSG_ADD_DATA, $this->name()).'<br>'; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -373,13 +373,13 @@ discard block |
||
373 | 373 | { |
374 | 374 | global $xoopsDB; |
375 | 375 | $query = $this->getStructure(); |
376 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
376 | + $query = 'CREATE TABLE `'.$this->name().'` ('.$query.") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
377 | 377 | //xoops_debug($query); |
378 | 378 | $ret = $xoopsDB->query($query); |
379 | 379 | if (!$ret) { |
380 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
380 | + echo ' '.sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
381 | 381 | } else { |
382 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
382 | + echo ' '.sprintf(_SDU_MSG_CREATE_TABLE, $this->name()).'<br>'; |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | return $ret; |
@@ -397,11 +397,11 @@ discard block |
||
397 | 397 | $query = sprintf('DROP TABLE %s', $this->name()); |
398 | 398 | $ret = $xoopsDB->query($query); |
399 | 399 | if (!$ret) { |
400 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
400 | + echo ' '.sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
401 | 401 | |
402 | 402 | return false; |
403 | 403 | } else { |
404 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
404 | + echo ' '.sprintf(_SDU_MSG_DROP_TABLE, $this->name()).'<br>'; |
|
405 | 405 | |
406 | 406 | return true; |
407 | 407 | } |
@@ -427,9 +427,9 @@ discard block |
||
427 | 427 | $ret = $ret && $xoopsDB->query($query); |
428 | 428 | if ($alteredField['showerror']) { |
429 | 429 | if (!$ret) { |
430 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
430 | + echo ' '.sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
431 | 431 | } else { |
432 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
432 | + echo ' '.sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()).'<br>'; |
|
433 | 433 | } |
434 | 434 | } |
435 | 435 | } |
@@ -452,9 +452,9 @@ discard block |
||
452 | 452 | //echo $query; |
453 | 453 | $ret = $ret && $xoopsDB->query($query); |
454 | 454 | if (!$ret) { |
455 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
455 | + echo ' '.sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()).'<br>'; |
|
456 | 456 | } else { |
457 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
457 | + echo ' '.sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()).'<br>'; |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
@@ -475,9 +475,9 @@ discard block |
||
475 | 475 | $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
476 | 476 | $ret = $ret && $xoopsDB->query($query); |
477 | 477 | if (!$ret) { |
478 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
478 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
479 | 479 | } else { |
480 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
480 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>'; |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | //echo $query."<br>"; |
499 | 499 | $ret = $ret && $xoopsDB->query($query); |
500 | 500 | if (!$ret) { |
501 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
501 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
502 | 502 | } else { |
503 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
503 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>'; |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
@@ -521,9 +521,9 @@ discard block |
||
521 | 521 | $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
522 | 522 | $ret = $ret && $xoopsDB->query($query); |
523 | 523 | if (!$ret) { |
524 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
524 | + echo ' '.sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
525 | 525 | } else { |
526 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
526 | + echo ' '.sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()).'<br>'; |
|
527 | 527 | } |
528 | 528 | } |
529 | 529 | |
@@ -610,11 +610,11 @@ discard block |
||
610 | 610 | $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
611 | 611 | $ret = $xoopsDB->query($query); |
612 | 612 | if (!$ret) { |
613 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
613 | + echo ' '.sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from).'<br>'; |
|
614 | 614 | |
615 | 615 | return false; |
616 | 616 | } else { |
617 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
617 | + echo ' '.sprintf(_SDU_MSG_RENAME_TABLE, $from, $to).'<br>'; |
|
618 | 618 | |
619 | 619 | return true; |
620 | 620 | } |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | return false; |
735 | 735 | } |
736 | 736 | |
737 | - $table = new SmartDbTable($module . '_' . $item); |
|
737 | + $table = new SmartDbTable($module.'_'.$item); |
|
738 | 738 | $object = $moduleHandler->create(); |
739 | 739 | $objectVars = $object->getVars(); |
740 | 740 | |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | "; |
756 | 756 | } |
757 | 757 | } |
758 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
758 | + $structure .= 'PRIMARY KEY (`'.$moduleHandler->keyName.'`) |
|
759 | 759 | '; |
760 | 760 | $table->setStructure($structure); |
761 | 761 | if (!$this->updateTable($table)) { |
@@ -815,7 +815,7 @@ discard block |
||
815 | 815 | |
816 | 816 | ob_start(); |
817 | 817 | |
818 | - $table = new SmartDbTable($dirname . '_meta'); |
|
818 | + $table = new SmartDbTable($dirname.'_meta'); |
|
819 | 819 | if (!$table->exists()) { |
820 | 820 | $table->setStructure(" |
821 | 821 | `metakey` varchar(50) NOT NULL default '', |
@@ -833,20 +833,20 @@ discard block |
||
833 | 833 | if (!$dbVersion) { |
834 | 834 | $dbVersion = 0; |
835 | 835 | } |
836 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
837 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
838 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
836 | + $newDbVersion = constant(strtoupper($dirname.'_db_version')) ?: 0; |
|
837 | + echo 'Database version: '.$dbVersion.'<br>'; |
|
838 | + echo 'New database version: '.$newDbVersion.'<br>'; |
|
839 | 839 | |
840 | 840 | if ($newDbVersion > $dbVersion) { |
841 | 841 | for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
842 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
842 | + $upgrade_function = $dirname.'_db_upgrade_'.$i; |
|
843 | 843 | if (function_exists($upgrade_function)) { |
844 | 844 | $upgrade_function(); |
845 | 845 | } |
846 | 846 | } |
847 | 847 | } |
848 | 848 | |
849 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
849 | + echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>'; |
|
850 | 850 | |
851 | 851 | // if there is a function to execute for this DB version, let's do it |
852 | 852 | //$function_ |
@@ -37,125 +37,125 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class SmartobjectRating extends SmartObject |
39 | 39 | { |
40 | - public $_modulePlugin = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * SmartobjectRating constructor. |
|
44 | - */ |
|
45 | - public function __construct() |
|
46 | - { |
|
47 | - $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
48 | - $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
49 | - $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
50 | - $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
51 | - $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
52 | - $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
53 | - $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
54 | - |
|
55 | - $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
56 | - |
|
57 | - $this->setControl('dirname', array( |
|
58 | - 'handler' => 'rating', |
|
59 | - 'method' => 'getModuleList', |
|
60 | - 'onSelect' => 'submit' |
|
61 | - )); |
|
62 | - |
|
63 | - $this->setControl('item', array( |
|
64 | - 'object' => &$this, |
|
65 | - 'method' => 'getItemList' |
|
66 | - )); |
|
67 | - |
|
68 | - $this->setControl('uid', 'user'); |
|
69 | - |
|
70 | - $this->setControl('rate', array( |
|
71 | - 'handler' => 'rating', |
|
72 | - 'method' => 'getRateList' |
|
73 | - )); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $key |
|
78 | - * @param string $format |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - public function getVar($key, $format = 's') |
|
82 | - { |
|
83 | - if ($format === 's' && in_array($key, array('name', 'dirname'))) { |
|
84 | - // return call_user_func(array($this, $key)); |
|
85 | - return $this->{$key}(); |
|
86 | - } |
|
87 | - |
|
88 | - return parent::getVar($key, $format); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function name() |
|
95 | - { |
|
96 | - $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array()); |
|
97 | - |
|
98 | - return $ret; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - public function dirname() |
|
105 | - { |
|
106 | - global $smartobjectRatingHandler; |
|
107 | - $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
108 | - |
|
109 | - return $moduleArray[$this->getVar('dirname', 'n')]; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return mixed |
|
114 | - */ |
|
115 | - public function getItemList() |
|
116 | - { |
|
117 | - $plugin = $this->getModulePlugin(); |
|
118 | - |
|
119 | - return $plugin->getItemList(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public function getItemValue() |
|
126 | - { |
|
127 | - $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
128 | - $plugin = $this->getModulePlugin(); |
|
129 | - $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
130 | - if (!$pluginItemInfo) { |
|
131 | - return ''; |
|
132 | - } |
|
133 | - $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
134 | - $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
135 | - |
|
136 | - return $ret; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return mixed |
|
141 | - */ |
|
142 | - public function getRateValue() |
|
143 | - { |
|
144 | - return $this->getVar('rate'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public function getModulePlugin() |
|
151 | - { |
|
152 | - if (!$this->_modulePlugin) { |
|
153 | - global $smartobjectRatingHandler; |
|
154 | - $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
155 | - } |
|
156 | - |
|
157 | - return $this->_modulePlugin; |
|
158 | - } |
|
40 | + public $_modulePlugin = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * SmartobjectRating constructor. |
|
44 | + */ |
|
45 | + public function __construct() |
|
46 | + { |
|
47 | + $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
48 | + $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
49 | + $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
50 | + $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
51 | + $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
52 | + $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
53 | + $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
54 | + |
|
55 | + $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
56 | + |
|
57 | + $this->setControl('dirname', array( |
|
58 | + 'handler' => 'rating', |
|
59 | + 'method' => 'getModuleList', |
|
60 | + 'onSelect' => 'submit' |
|
61 | + )); |
|
62 | + |
|
63 | + $this->setControl('item', array( |
|
64 | + 'object' => &$this, |
|
65 | + 'method' => 'getItemList' |
|
66 | + )); |
|
67 | + |
|
68 | + $this->setControl('uid', 'user'); |
|
69 | + |
|
70 | + $this->setControl('rate', array( |
|
71 | + 'handler' => 'rating', |
|
72 | + 'method' => 'getRateList' |
|
73 | + )); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $key |
|
78 | + * @param string $format |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + public function getVar($key, $format = 's') |
|
82 | + { |
|
83 | + if ($format === 's' && in_array($key, array('name', 'dirname'))) { |
|
84 | + // return call_user_func(array($this, $key)); |
|
85 | + return $this->{$key}(); |
|
86 | + } |
|
87 | + |
|
88 | + return parent::getVar($key, $format); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function name() |
|
95 | + { |
|
96 | + $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array()); |
|
97 | + |
|
98 | + return $ret; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + public function dirname() |
|
105 | + { |
|
106 | + global $smartobjectRatingHandler; |
|
107 | + $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
108 | + |
|
109 | + return $moduleArray[$this->getVar('dirname', 'n')]; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return mixed |
|
114 | + */ |
|
115 | + public function getItemList() |
|
116 | + { |
|
117 | + $plugin = $this->getModulePlugin(); |
|
118 | + |
|
119 | + return $plugin->getItemList(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public function getItemValue() |
|
126 | + { |
|
127 | + $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
128 | + $plugin = $this->getModulePlugin(); |
|
129 | + $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
130 | + if (!$pluginItemInfo) { |
|
131 | + return ''; |
|
132 | + } |
|
133 | + $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
134 | + $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
135 | + |
|
136 | + return $ret; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return mixed |
|
141 | + */ |
|
142 | + public function getRateValue() |
|
143 | + { |
|
144 | + return $this->getVar('rate'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public function getModulePlugin() |
|
151 | + { |
|
152 | + if (!$this->_modulePlugin) { |
|
153 | + global $smartobjectRatingHandler; |
|
154 | + $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
155 | + } |
|
156 | + |
|
157 | + return $this->_modulePlugin; |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,93 +163,93 @@ discard block |
||
163 | 163 | */ |
164 | 164 | class SmartobjectRatingHandler extends SmartPersistableObjectHandler |
165 | 165 | { |
166 | - public $_rateOptions = array(); |
|
167 | - public $_moduleList = false; |
|
168 | - public $pluginsObject; |
|
169 | - |
|
170 | - /** |
|
171 | - * SmartobjectRatingHandler constructor. |
|
172 | - * @param XoopsDatabase $db |
|
173 | - */ |
|
174 | - public function __construct(XoopsDatabase $db) |
|
175 | - { |
|
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'; |
|
178 | - |
|
179 | - $this->_rateOptions[1] = 1; |
|
180 | - $this->_rateOptions[2] = 2; |
|
181 | - $this->_rateOptions[3] = 3; |
|
182 | - $this->_rateOptions[4] = 4; |
|
183 | - $this->_rateOptions[5] = 5; |
|
184 | - |
|
185 | - $this->pluginsObject = new SmartPluginHandler(); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public function getModuleList() |
|
192 | - { |
|
193 | - if (!$this->_moduleList) { |
|
194 | - $moduleArray = $this->pluginsObject->getPluginsArray(); |
|
195 | - $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION; |
|
196 | - foreach ($moduleArray as $k => $v) { |
|
197 | - $this->_moduleList[$k] = $v; |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - return $this->_moduleList; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - public function getRateList() |
|
208 | - { |
|
209 | - return $this->_rateOptions; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param $itemid |
|
214 | - * @param $dirname |
|
215 | - * @param $item |
|
216 | - * @return int |
|
217 | - */ |
|
218 | - public function getRatingAverageByItemId($itemid, $dirname, $item) |
|
219 | - { |
|
220 | - $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | - $result = $this->db->query($sql); |
|
222 | - if (!$result) { |
|
223 | - return 0; |
|
224 | - } |
|
225 | - list($average, $sum) = $this->db->fetchRow($result); |
|
226 | - $ret['average'] = isset($average) ? $average : 0; |
|
227 | - $ret['sum'] = isset($sum) ? $sum : 0; |
|
228 | - |
|
229 | - return $ret; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param $item |
|
234 | - * @param $itemid |
|
235 | - * @param $dirname |
|
236 | - * @param $uid |
|
237 | - * @return bool |
|
238 | - */ |
|
239 | - public function already_rated($item, $itemid, $dirname, $uid) |
|
240 | - { |
|
241 | - $criteria = new CriteriaCompo(); |
|
242 | - $criteria->add(new Criteria('item', $item)); |
|
243 | - $criteria->add(new Criteria('itemid', $itemid)); |
|
244 | - $criteria->add(new Criteria('dirname', $dirname)); |
|
245 | - $criteria->add(new Criteria('user.uid', $uid)); |
|
246 | - |
|
247 | - $ret = $this->getObjects($criteria); |
|
248 | - |
|
249 | - if (!$ret) { |
|
250 | - return false; |
|
251 | - } else { |
|
252 | - return $ret[0]; |
|
253 | - } |
|
254 | - } |
|
166 | + public $_rateOptions = array(); |
|
167 | + public $_moduleList = false; |
|
168 | + public $pluginsObject; |
|
169 | + |
|
170 | + /** |
|
171 | + * SmartobjectRatingHandler constructor. |
|
172 | + * @param XoopsDatabase $db |
|
173 | + */ |
|
174 | + public function __construct(XoopsDatabase $db) |
|
175 | + { |
|
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'; |
|
178 | + |
|
179 | + $this->_rateOptions[1] = 1; |
|
180 | + $this->_rateOptions[2] = 2; |
|
181 | + $this->_rateOptions[3] = 3; |
|
182 | + $this->_rateOptions[4] = 4; |
|
183 | + $this->_rateOptions[5] = 5; |
|
184 | + |
|
185 | + $this->pluginsObject = new SmartPluginHandler(); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public function getModuleList() |
|
192 | + { |
|
193 | + if (!$this->_moduleList) { |
|
194 | + $moduleArray = $this->pluginsObject->getPluginsArray(); |
|
195 | + $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION; |
|
196 | + foreach ($moduleArray as $k => $v) { |
|
197 | + $this->_moduleList[$k] = $v; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + return $this->_moduleList; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + public function getRateList() |
|
208 | + { |
|
209 | + return $this->_rateOptions; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param $itemid |
|
214 | + * @param $dirname |
|
215 | + * @param $item |
|
216 | + * @return int |
|
217 | + */ |
|
218 | + public function getRatingAverageByItemId($itemid, $dirname, $item) |
|
219 | + { |
|
220 | + $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | + $result = $this->db->query($sql); |
|
222 | + if (!$result) { |
|
223 | + return 0; |
|
224 | + } |
|
225 | + list($average, $sum) = $this->db->fetchRow($result); |
|
226 | + $ret['average'] = isset($average) ? $average : 0; |
|
227 | + $ret['sum'] = isset($sum) ? $sum : 0; |
|
228 | + |
|
229 | + return $ret; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param $item |
|
234 | + * @param $itemid |
|
235 | + * @param $dirname |
|
236 | + * @param $uid |
|
237 | + * @return bool |
|
238 | + */ |
|
239 | + public function already_rated($item, $itemid, $dirname, $uid) |
|
240 | + { |
|
241 | + $criteria = new CriteriaCompo(); |
|
242 | + $criteria->add(new Criteria('item', $item)); |
|
243 | + $criteria->add(new Criteria('itemid', $itemid)); |
|
244 | + $criteria->add(new Criteria('dirname', $dirname)); |
|
245 | + $criteria->add(new Criteria('user.uid', $uid)); |
|
246 | + |
|
247 | + $ret = $this->getObjects($criteria); |
|
248 | + |
|
249 | + if (!$ret) { |
|
250 | + return false; |
|
251 | + } else { |
|
252 | + return $ret[0]; |
|
253 | + } |
|
254 | + } |
|
255 | 255 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | |
30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
31 | 31 | |
32 | -include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
33 | -include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartplugins.php'; |
|
32 | +include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
33 | +include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartplugins.php'; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Class SmartobjectRating |
@@ -124,14 +124,14 @@ discard block |
||
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 |
||
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 |
||
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; |
@@ -8,22 +8,22 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class SmartobjectUrlLink extends SmartobjectBasedUrl |
10 | 10 | { |
11 | - /** |
|
12 | - * SmartobjectUrlLink constructor. |
|
13 | - */ |
|
14 | - public function __construct() |
|
15 | - { |
|
16 | - parent::__construct(); |
|
17 | - $this->quickInitVar('urllinkid', XOBJ_DTYPE_TXTBOX, true); |
|
18 | - $this->quickInitVar('target', XOBJ_DTYPE_TXTBOX, true); |
|
11 | + /** |
|
12 | + * SmartobjectUrlLink constructor. |
|
13 | + */ |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + parent::__construct(); |
|
17 | + $this->quickInitVar('urllinkid', XOBJ_DTYPE_TXTBOX, true); |
|
18 | + $this->quickInitVar('target', XOBJ_DTYPE_TXTBOX, true); |
|
19 | 19 | |
20 | - $this->setControl('target', array( |
|
21 | - 'options' => array( |
|
22 | - '_self' => _CO_SOBJECT_URLLINK_SELF, |
|
23 | - '_blank' => _CO_SOBJECT_URLLINK_BLANK |
|
24 | - ) |
|
25 | - )); |
|
26 | - } |
|
20 | + $this->setControl('target', array( |
|
21 | + 'options' => array( |
|
22 | + '_self' => _CO_SOBJECT_URLLINK_SELF, |
|
23 | + '_blank' => _CO_SOBJECT_URLLINK_BLANK |
|
24 | + ) |
|
25 | + )); |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | */ |
32 | 32 | class SmartobjectUrlLinkHandler extends SmartPersistableObjectHandler |
33 | 33 | { |
34 | - /** |
|
35 | - * SmartobjectUrlLinkHandler constructor. |
|
36 | - * @param XoopsDatabase $db |
|
37 | - */ |
|
38 | - public function __construct(XoopsDatabase $db) |
|
39 | - { |
|
40 | - parent::__construct($db, 'urllink', 'urllinkid', 'caption', 'desc', 'smartobject'); |
|
41 | - } |
|
34 | + /** |
|
35 | + * SmartobjectUrlLinkHandler constructor. |
|
36 | + * @param XoopsDatabase $db |
|
37 | + */ |
|
38 | + public function __construct(XoopsDatabase $db) |
|
39 | + { |
|
40 | + parent::__construct($db, 'urllink', 'urllinkid', 'caption', 'desc', 'smartobject'); |
|
41 | + } |
|
42 | 42 | } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
3 | 3 | |
4 | -include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/basedurl.php'; |
|
4 | +include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/basedurl.php'; |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * Class SmartobjectUrlLink |
@@ -19,96 +19,96 @@ |
||
19 | 19 | */ |
20 | 20 | class SmartHighlighter |
21 | 21 | { |
22 | - /** |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - public $preg_keywords = ''; |
|
26 | - /** |
|
27 | - * @access private |
|
28 | - */ |
|
29 | - public $keywords = ''; |
|
30 | - /** |
|
31 | - * @access private |
|
32 | - */ |
|
33 | - public $singlewords = false; |
|
34 | - /** |
|
35 | - * @access private |
|
36 | - */ |
|
37 | - public $replace_callback = null; |
|
22 | + /** |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + public $preg_keywords = ''; |
|
26 | + /** |
|
27 | + * @access private |
|
28 | + */ |
|
29 | + public $keywords = ''; |
|
30 | + /** |
|
31 | + * @access private |
|
32 | + */ |
|
33 | + public $singlewords = false; |
|
34 | + /** |
|
35 | + * @access private |
|
36 | + */ |
|
37 | + public $replace_callback = null; |
|
38 | 38 | |
39 | - public $content; |
|
39 | + public $content; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Main constructor |
|
43 | - * |
|
44 | - * This is the main constructor of keyhighlighter class. <br> |
|
45 | - * It's the only public method of the class. |
|
46 | - * @param string $keywords the keywords you want to highlight |
|
47 | - * @param boolean $singlewords specify if it has to highlight also the single words. |
|
48 | - * @param callback $replace_callback a custom callback for keyword highlight. |
|
49 | - * <code> |
|
50 | - * <?php |
|
51 | - * require ('keyhighlighter.class.php'); |
|
52 | - * |
|
53 | - * function my_highlighter ($matches) { |
|
54 | - * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
55 | - * } |
|
56 | - * |
|
57 | - * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
58 | - * readfile ('http://www.w3c.org/'); |
|
59 | - * ?> |
|
60 | - * </code> |
|
61 | - */ |
|
62 | - // public function __construct () |
|
63 | - public function __construct($keywords, $singlewords = false, $replace_callback = null) |
|
64 | - { |
|
65 | - $this->keywords = $keywords; |
|
66 | - $this->singlewords = $singlewords; |
|
67 | - $this->replace_callback = $replace_callback; |
|
68 | - } |
|
41 | + /** |
|
42 | + * Main constructor |
|
43 | + * |
|
44 | + * This is the main constructor of keyhighlighter class. <br> |
|
45 | + * It's the only public method of the class. |
|
46 | + * @param string $keywords the keywords you want to highlight |
|
47 | + * @param boolean $singlewords specify if it has to highlight also the single words. |
|
48 | + * @param callback $replace_callback a custom callback for keyword highlight. |
|
49 | + * <code> |
|
50 | + * <?php |
|
51 | + * require ('keyhighlighter.class.php'); |
|
52 | + * |
|
53 | + * function my_highlighter ($matches) { |
|
54 | + * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
55 | + * } |
|
56 | + * |
|
57 | + * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
58 | + * readfile ('http://www.w3c.org/'); |
|
59 | + * ?> |
|
60 | + * </code> |
|
61 | + */ |
|
62 | + // public function __construct () |
|
63 | + public function __construct($keywords, $singlewords = false, $replace_callback = null) |
|
64 | + { |
|
65 | + $this->keywords = $keywords; |
|
66 | + $this->singlewords = $singlewords; |
|
67 | + $this->replace_callback = $replace_callback; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @access private |
|
72 | - * @param $replace_matches |
|
73 | - * @return mixed |
|
74 | - */ |
|
75 | - public function replace($replace_matches) |
|
76 | - { |
|
77 | - $patterns = array(); |
|
78 | - if ($this->singlewords) { |
|
79 | - $keywords = explode(' ', $this->preg_keywords); |
|
80 | - foreach ($keywords as $keyword) { |
|
81 | - $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
82 | - } |
|
83 | - } else { |
|
84 | - $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
85 | - } |
|
70 | + /** |
|
71 | + * @access private |
|
72 | + * @param $replace_matches |
|
73 | + * @return mixed |
|
74 | + */ |
|
75 | + public function replace($replace_matches) |
|
76 | + { |
|
77 | + $patterns = array(); |
|
78 | + if ($this->singlewords) { |
|
79 | + $keywords = explode(' ', $this->preg_keywords); |
|
80 | + foreach ($keywords as $keyword) { |
|
81 | + $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
82 | + } |
|
83 | + } else { |
|
84 | + $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
85 | + } |
|
86 | 86 | |
87 | - $result = $replace_matches[0]; |
|
87 | + $result = $replace_matches[0]; |
|
88 | 88 | |
89 | - foreach ($patterns as $pattern) { |
|
90 | - if (null !== $this->replace_callback) { |
|
91 | - $result = preg_replace_callback($pattern, $this->replace_callback, $result); |
|
92 | - } else { |
|
93 | - $result = preg_replace($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
94 | - } |
|
95 | - } |
|
89 | + foreach ($patterns as $pattern) { |
|
90 | + if (null !== $this->replace_callback) { |
|
91 | + $result = preg_replace_callback($pattern, $this->replace_callback, $result); |
|
92 | + } else { |
|
93 | + $result = preg_replace($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - return $result; |
|
98 | - } |
|
97 | + return $result; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @access private |
|
102 | - * @param $buffer |
|
103 | - * @return mixed|string |
|
104 | - */ |
|
105 | - public function highlight($buffer) |
|
106 | - { |
|
107 | - $buffer = '>' . $buffer . '<'; |
|
108 | - $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
|
109 | - $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", array(&$this, 'replace'), $buffer); |
|
110 | - $buffer = substr($buffer, 1, -1); |
|
100 | + /** |
|
101 | + * @access private |
|
102 | + * @param $buffer |
|
103 | + * @return mixed|string |
|
104 | + */ |
|
105 | + public function highlight($buffer) |
|
106 | + { |
|
107 | + $buffer = '>' . $buffer . '<'; |
|
108 | + $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
|
109 | + $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", array(&$this, 'replace'), $buffer); |
|
110 | + $buffer = substr($buffer, 1, -1); |
|
111 | 111 | |
112 | - return $buffer; |
|
113 | - } |
|
112 | + return $buffer; |
|
113 | + } |
|
114 | 114 | } |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | if ($this->singlewords) { |
79 | 79 | $keywords = explode(' ', $this->preg_keywords); |
80 | 80 | foreach ($keywords as $keyword) { |
81 | - $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
81 | + $patterns[] = '/(?'.'>'.$keyword.'+)/si'; |
|
82 | 82 | } |
83 | 83 | } else { |
84 | - $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
84 | + $patterns[] = '/(?'.'>'.$this->preg_keywords.'+)/si'; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | $result = $replace_matches[0]; |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function highlight($buffer) |
106 | 106 | { |
107 | - $buffer = '>' . $buffer . '<'; |
|
107 | + $buffer = '>'.$buffer.'<'; |
|
108 | 108 | $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
109 | - $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", array(&$this, 'replace'), $buffer); |
|
109 | + $buffer = preg_replace_callback("/(\>(((?".">[^><]+)|(?R))*)\<)/is", array(&$this, 'replace'), $buffer); |
|
110 | 110 | $buffer = substr($buffer, 1, -1); |
111 | 111 | |
112 | 112 | return $buffer; |
@@ -18,123 +18,123 @@ discard block |
||
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 | - include_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 | + include_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 |
||
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 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
14 | -include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartseoobject.php'; |
|
14 | +include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartseoobject.php'; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Class SmartobjectCategory |
@@ -95,7 +95,7 @@ discard block |
||
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 |
||
111 | 111 | */ |
112 | 112 | public function getCategoryPath($withAllLink = true, $currentCategory = false) |
113 | 113 | { |
114 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
114 | + include_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 |
||
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 |
||
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 |