XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
install_updateModules_go.inc.php
1<?php
10
11unset( $xoopsOption['nocommon'] );
12
13include_once '../mainfile.php';
14
15error_reporting( E_ERROR );
16
17ob_start();
18
19echo '<h2>wizard/install_updateModules_go.inc</h2>';
20
21$module_handler =& xoops_gethandler( 'module' );
22$modules =& $module_handler->getObjects( null, true );
23foreach ( array_keys( $modules ) as $mid ) {
24 echo '<h5>' . $modules[ $mid ]->getVar( 'name' ) . '</h5>';
25 $dirname = $modules[ $mid ]->getVar( 'dirname' );
26 if ( is_dir( XOOPS_ROOT_PATH . '/modules/' . $dirname ) ) {
27 $modules[ $mid ]->loadInfoAsVar( $dirname, false );
28 if ( ! $module_handler->insert( $modules[ $mid ] ) ) {
29 echo '<p>Could not update ' . $modules[ $mid ]->getVar( 'name' ) . '</p>';
30 } else {
31 $newmid = $modules[ $mid ]->getVar( 'mid' );
32 $msgs = [];
33 $msgs[] = 'Module data updated.';
34 $tplfile_handler =& xoops_gethandler( 'tplfile' );
35 $templates = $modules[ $mid ]->getInfo( 'templates' );
36 if ( false !== $templates ) {
37 $msgs[] = 'Generating templates...';
38 foreach ( $templates as $tpl ) {
39 $tpl['file'] = trim( $tpl['file'] );
40 $tpldata =& xoops_module_gettemplate( $dirname, $tpl['file'] );
41 $tplfile =& $tplfile_handler->create();
42 $tplfile->setVar( 'tpl_refid', $newmid );
43 $tplfile->setVar( 'tpl_lastimported', 0 );
44 $tplfile->setVar( 'tpl_lastmodified', time() );
45 if ( preg_match( "/\.css$/i", $tpl['file'] ) ) {
46 $tplfile->setVar( 'tpl_type', 'css' );
47 } else {
48 $tplfile->setVar( 'tpl_type', 'module' );
49 }
50 $tplfile->setVar( 'tpl_source', $tpldata, true );
51 $tplfile->setVar( 'tpl_module', $dirname );
52 $tplfile->setVar( 'tpl_tplset', 'default' );
53 $tplfile->setVar( 'tpl_file', $tpl['file'], true );
54 $tplfile->setVar( 'tpl_desc', $tpl['description'], true );
55 if ( ! $tplfile_handler->insert( $tplfile ) ) {
56 $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $tpl['file'] . '</b> to the database.</span>';
57 } else {
58 $msgs[] = '&nbsp;&nbsp;Template <b>' . $tpl['file'] . '</b> inserted to the database.';
59 }
60 unset( $tpldata );
61 }
62 }
63 $blocks = $modules[ $mid ]->getInfo( 'blocks' );
64 $msgs[] = 'Rebuilding blocks...';
65 $showfuncs = [];
66 $funcfiles = [];
67 if ( false != $blocks ) {
68 $count = is_countable($blocks) ? count( $blocks ) : 0;
69 include_once( XOOPS_ROOT_PATH . '/class/xoopsblock.php' );
70 for ( $i = 1; $i <= $count; $i ++ ) {
71 if ( isset( $blocks[ $i ]['show_func'] ) && '' !== $blocks[ $i ]['show_func'] && isset( $blocks[ $i ]['file'] ) && ( '' !== $blocks[ $i ]['file'] ) ) {
72 $editfunc = $blocks[ $i ]['edit_func'] ?? '';
73 $showfuncs[] = $blocks[ $i ]['show_func'];
74 $funcfiles[] = $blocks[ $i ]['file'];
75 $template = '';
76 if ( ( isset( $blocks[ $i ]['template'] ) && ( '' !== trim( $blocks[ $i ]['template'] ) ) ) ) {
77 $content =& xoops_module_gettemplate( $dirname, $blocks[ $i ]['template'], true );
78 $template = $blocks[ $i ]['template'];
79 }
80 if ( ! $content ) {
81 $content = '';
82 }
83 $options = '';
84 if ( isset( $blocks[ $i ]['options'] ) && ( $blocks[ $i ]['options'] !== '' ) ) {
85 $options = $blocks[ $i ]['options'];
86 }
87 $sql = 'SELECT bid, name FROM ' . $xoopsDB->prefix( 'newblocks' ) . ' WHERE mid=' . $mid . ' AND func_num=' . $i;
88 $fresult = $xoopsDB->query( $sql );
89 $fcount = 0;
90 while ( $fblock = $xoopsDB->fetchArray( $fresult ) ) {
91 $fcount ++;
92 $sql = 'UPDATE '
93 . $xoopsDB->prefix( 'newblocks' ) . " SET name='" . addslashes( $blocks[ $i ]['name'] ) . "', title='" . addslashes( $blocks[ $i ]['name'] ) . "', dirname='" . addslashes( $dirname ) . "', func_file='" . addslashes( $blocks[ $i ]['file'] ) . "', show_func='" . addslashes( $blocks[ $i ]['show_func'] ) . "', template='" . addslashes( $template ) . "', edit_func='" . addslashes( $editfunc ) . "', options='" . addslashes( $options ) . "', content='', template='" . $template . "', last_modified=" . time() . ' WHERE bid='
94 . $fblock['bid'];
95 $result = $xoopsDB->query( $sql );
96 if ( ! $result ) {
97 $msgs[] = '&nbsp;&nbsp;ERROR: Could not update ' . $fblock['name'];
98 } else {
99 $msgs[] = '&nbsp;&nbsp;Block <b>' . $fblock['name'] . '</b> updated. Block ID: <b>' . $fblock['bid'] . '</b>';
100 if ( '' != $template ) {
101 $tplfile =& $tplfile_handler->create();
102 $tplfile->setVar( 'tpl_refid', $fblock['bid'] );
103 $tplfile->setVar( 'tpl_source', $content, true );
104 $tplfile->setVar( 'tpl_tplset', 'default' );
105 $tplfile->setVar( 'tpl_file', $blocks[ $i ]['template'] );
106 $tplfile->setVar( 'tpl_module', $dirname );
107 $tplfile->setVar( 'tpl_type', 'block' );
108 $tplfile->setVar( 'tpl_desc', $blocks[ $i ]['description'], true );
109 $tplfile->setVar( 'tpl_lastimported', 0 );
110 $tplfile->setVar( 'tpl_lastmodified', time() );
111 if ( ! $tplfile_handler->insert( $tplfile ) ) {
112 $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $blocks[ $i ]['template'] . '</b> to the database.</span>';
113 } else {
114 $msgs[] = '&nbsp;&nbsp;Template <b>' . $blocks[ $i ]['template'] . '</b> inserted to the database.';
115 }
116 }
117 }
118 }
119 if ( 0 === $fcount ) {
120 $newbid = $xoopsDB->genId( $xoopsDB->prefix( 'newblocks' ) . '_bid_seq' );
121 $block_name = addslashes( $blocks[ $i ]['name'] );
122 $sql = 'INSERT INTO '
123 . $xoopsDB->prefix( 'newblocks' ) . ' (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES ('
124 . $newbid . ', '
125 . $mid . ', '
126 . $i . ",'" . addslashes( $options ) . "','" . $block_name . "', '" . $block_name . "', '', 0, 0, 0, 'M', 1, '" . addslashes( $dirname ) . "', '" . addslashes( $blocks[ $i ]['file'] ) . "', '" . addslashes( $blocks[ $i ]['show_func'] ) . "', '" . addslashes( $editfunc ) . "', '" . $template . "', " . time() . ')';
127 $result = $xoopsDB->query( $sql );
128 if ( ! $result ) {
129 $msgs[] = '&nbsp;&nbsp;ERROR: Could not create ' . $blocks[ $i ]['name'];
130 } else {
131 if ( empty( $newbid ) ) {
132 $newbid = $xoopsDB->getInsertId();
133 }
134 if ( '' !== $template ) {
135 $tplfile =& $tplfile_handler->create();
136 $tplfile->setVar( 'tpl_module', $dirname );
137 $tplfile->setVar( 'tpl_refid', $newbid );
138 $tplfile->setVar( 'tpl_source', $content, true );
139 $tplfile->setVar( 'tpl_tplset', 'default' );
140 $tplfile->setVar( 'tpl_file', $blocks[ $i ]['template'], true );
141 $tplfile->setVar( 'tpl_type', 'block' );
142 $tplfile->setVar( 'tpl_lastimported', 0 );
143 $tplfile->setVar( 'tpl_lastmodified', time() );
144 $tplfile->setVar( 'tpl_desc', $blocks[ $i ]['description'], true );
145 if ( ! $tplfile_handler->insert( $tplfile ) ) {
146 $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $blocks[ $i ]['template'] . '</b> to the database.</span>';
147 } else {
148 $msgs[] = '&nbsp;&nbsp;Template <b>' . $blocks[ $i ]['template'] . '</b> inserted to the database.';
149 }
150 }
151 $msgs[] = '&nbsp;&nbsp;Block <b>' . $blocks[ $i ]['name'] . '</b> created. Block ID: <b>' . $newbid . '</b>';
152 }
153 }
154 }
155 }
156 }
157 $block_arr = XoopsBlock::sGetByModule( $mid );
158 foreach ( $block_arr as $block ) {
159 if ( ! in_array( $block->getVar( 'show_func' ), $showfuncs, true ) || ! in_array( $block->getVar( 'func_file' ), $funcfiles, true ) ) {
160 $sql = sprintf( 'DELETE FROM %s WHERE bid = %u', $xoopsDB->prefix( 'newblocks' ), $block->getVar( 'bid' ) );
161 if ( ! $xoopsDB->query( $sql ) ) {
162 $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block <b>' . $block->getVar( 'name' ) . '</b>. Block ID: <b>' . $block->getVar( 'bid' ) . '</b></span>';
163 } else {
164 $msgs[] = '&nbsp;&nbsp;Block <b>' . $block->getVar( 'name' ) . ' deleted. Block ID: <b>' . $block->getVar( 'bid' ) . '</b>';
165 }
166 }
167 }
168
169 $configs = $modules[ $mid ]->getInfo( 'config' );
170 if ( false !== $configs ) {
171 if ( 0 !== $modules[ $mid ]->getVar( 'hascomments' ) ) {
172
173 include_once( XOOPS_ROOT_PATH . '/include/comment_constants.php' );
174
175 $configs[] = [ 'name' => 'com_rule',
176 'title' => '_CM_COMRULES',
177 'description' => '',
178 'formtype' => 'select',
179 'valuetype' => 'int',
180 'default' => 1,
181 'options' => [ '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL,
182 '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER,
183 '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN
184 ]
185 ];
186 $configs[] = [ 'name' => 'com_anonpost',
187 'title' => '_CM_COMANONPOST',
188 'description' => '',
189 'formtype' => 'yesno',
190 'valuetype' => 'int',
191 'default' => 0
192 ];
193 }
194 } else {
195 if ( 0 != $modules[ $mid ]->getVar( 'hascomments' ) ) {
196 $configs = [];
197
198 include_once( XOOPS_ROOT_PATH . '/include/comment_constants.php' );
199
200 $configs[] = [ 'name' => 'com_rule',
201 'title' => '_CM_COMRULES',
202 'description' => '',
203 'formtype' => 'select',
204 'valuetype' => 'int',
205 'default' => 1,
206 'options' => [ '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL,
207 '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER,
208 '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN
209 ]
210 ];
211 $configs[] = [ 'name' => 'com_anonpost',
212 'title' => '_CM_COMANONPOST',
213 'description' => '',
214 'formtype' => 'yesno',
215 'valuetype' => 'int',
216 'default' => 0
217 ];
218 }
219 }
220 // RMV-NOTIFY
221 if ( 0 !== $modules[ $mid ]->getVar( 'hasnotification' ) ) {
222 if ( empty( $configs ) ) {
223 $configs = [];
224 }
225 include_once( XOOPS_ROOT_PATH . '/include/notification_constants.php' );
226 $configs[] = [ 'name' => 'notification_enabled',
227 'title' => '_NOT_CONFIG_ENABLED',
228 'description' => '_NOT_CONFIG_ENABLEDDSC',
229 'formtype' => 'select',
230 'valuetype' => 'int',
231 'default' => XOOPS_NOTIFICATION_ENABLEBOTH,
232 'options' => $options
233 ];
234 }
235
236 if ( false != $configs ) {
237 $msgs[] = 'Adding module config data...';
238 $config_handler =& xoops_gethandler( 'config' );
239 $order = 0;
240 foreach ( $configs as $config ) {
241 $confobj =& $config_handler->createConfig();
242 $confobj->setVar( 'conf_modid', $newmid );
243 $confobj->setVar( 'conf_catid', 0 );
244 $confobj->setVar( 'conf_name', $config['name'] );
245 $confobj->setVar( 'conf_title', $config['title'], true );
246 $confobj->setVar( 'conf_desc', $config['description'], true );
247 $confobj->setVar( 'conf_formtype', $config['formtype'] );
248 $confobj->setVar( 'conf_valuetype', $config['valuetype'] );
249 $confobj->setVar( 'conf_value', $config['default'], true );
250 $confobj->setVar( 'conf_order', $order );
251 $confop_msgs = '';
252 if ( isset( $config['options'] ) && is_array( $config['options'] ) ) {
253 foreach ( $config['options'] as $key => $value ) {
254 $confop =& $config_handler->createConfigOption();
255 $confop->setVar( 'confop_name', $key, true );
256 $confop->setVar( 'confop_value', $value, true );
257 $confobj->setConfOptions( $confop );
258 $confop_msgs .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>';
259 unset( $confop );
260 }
261 }
262 $order ++;
263 if ( false !== $config_handler->insertConfig( $confobj ) ) {
264 $msgs[] = '&nbsp;&nbsp;Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs;
265 } else {
266 $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>';
267 }
268 unset( $confobj );
269 }
270 unset( $configs );
271 }
272 foreach ( $msgs as $msg ) {
273 echo '<code>' . $msg . '</code><br>';
274 }
275 }
276 // data for table 'block_module_link'
277 include_once './class/dbmanager.php';
278
279 $dbm = new db_manager();
280 $sql = 'SELECT bid, side FROM ' . $dbm->prefix( 'newblocks' );
281 $result = $dbm->query( $sql );
282
283 while ( $myrow = $dbm->fetchArray( $result ) ) {
284 if ( 0 === $myrow['side'] ) {
285 $dbm->insert( 'block_module_link', ' VALUES (' . $myrow['bid'] . ', 0)' );
286 } else {
287 $dbm->insert( 'block_module_link', ' VALUES (' . $myrow['bid'] . ', -1)' );
288 }
289 }
290 }
291 echo '<br>';
292 flush();
293 sleep( 1 );
294}
295
296$title = _INSTALL_L142;
297$content = "<table width='80%' align='center'><tr><td align='left'>\n";
298$content .= ob_get_contents();
299$content .= "</td></tr></table>\n";
300ob_end_clean();
301
302$b_next = [ 'updateComments', _INSTALL_L14 ];
303
304include './install_tpl.php';