1: <?php
2:
3: if (!class_exists('ProtectorRegistry')) {
4: exit('Registry not found');
5: }
6:
7: $registry = ProtectorRegistry::getInstance();
8: $mydirname = $registry->getEntry('mydirname');
9: $mydirpath = $registry->getEntry('mydirpath');
10: $language = $registry->getEntry('language');
11:
12:
13: eval(' function xoops_module_update_' . $mydirname . '( $module ) { return protector_onupdate_base( $module , "' . $mydirname . '" ) ; } ');
14:
15: if (!function_exists('protector_onupdate_base')) {
16:
17: 18: 19: 20: 21: 22:
23: function protector_onupdate_base($module, $mydirname)
24: {
25:
26:
27: global $msgs;
28:
29:
30: if (defined('XOOPS_CUBE_LEGACY')) {
31: $root =& XCube_Root::getSingleton();
32: $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'protector_message_append_onupdate');
33: $msgs = array();
34: } else {
35: if (!is_array($msgs)) {
36: $msgs = array();
37: }
38: }
39:
40: $db = XoopsDatabaseFactory::getDatabaseConnection();
41: $mid = $module->getVar('mid');
42:
43:
44:
45:
46: $check_sql = 'SHOW COLUMNS FROM ' . $db->prefix('config') . " LIKE 'conf_title'";
47: if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] === 'varchar(30)') {
48: $db->queryF('ALTER TABLE ' . $db->prefix('config') . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
49: }
50: list(, $create_string) = $db->fetchRow($db->query('SHOW CREATE TABLE ' . $db->prefix('config')));
51: foreach (explode('KEY', $create_string) as $line) {
52: if (preg_match('/(\`conf\_title_\d+\`) \(\`conf\_title\`\)/', $line, $regs)) {
53: $db->query('ALTER TABLE ' . $db->prefix('config') . ' DROP KEY ' . $regs[1]);
54: }
55: }
56: $db->query('ALTER TABLE ' . $db->prefix('config') . ' ADD KEY `conf_title` (`conf_title`)');
57:
58:
59: list(, $create_string) = $db->fetchRow($db->query('SHOW CREATE TABLE ' . $db->prefix($mydirname . '_log')));
60: if (preg_match('/timestamp\(/i', $create_string)) {
61: $db->query('ALTER TABLE ' . $db->prefix($mydirname . '_log') . ' MODIFY `timestamp` DATETIME');
62: }
63:
64:
65: $tplfile_handler = xoops_getHandler('tplfile');
66: $tpl_path = __DIR__ . '/templates';
67: if ($handler = @opendir($tpl_path . '/')) {
68: while (($file = readdir($handler)) !== false) {
69: if (substr($file, 0, 1) === '.') {
70: continue;
71: }
72: $file_path = $tpl_path . '/' . $file;
73: if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
74: $mtime = (int)(@filemtime($file_path));
75: $tplfile = $tplfile_handler->create();
76: $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
77: $tplfile->setVar('tpl_refid', $mid);
78: $tplfile->setVar('tpl_tplset', 'default');
79: $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
80: $tplfile->setVar('tpl_desc', '', true);
81: $tplfile->setVar('tpl_module', $mydirname);
82: $tplfile->setVar('tpl_lastmodified', $mtime);
83: $tplfile->setVar('tpl_lastimported', 0);
84: $tplfile->setVar('tpl_type', 'module');
85: if (!$tplfile_handler->insert($tplfile)) {
86: $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
87: } else {
88: $tplid = $tplfile->getVar('tpl_id');
89: $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
90:
91: include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
92: include_once XOOPS_ROOT_PATH . '/class/template.php';
93: if (!xoops_template_touch($tplid)) {
94: $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
95: } else {
96: $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
97: }
98: }
99: }
100: }
101: closedir($handler);
102: }
103: include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
104: include_once XOOPS_ROOT_PATH . '/class/template.php';
105: xoops_template_clear_module_cache($mid);
106:
107: return true;
108: }
109:
110: 111: 112: 113:
114: function protector_message_append_onupdate(&$module_obj, &$log)
115: {
116: if (is_array(@$GLOBALS['msgs'])) {
117: foreach ($GLOBALS['msgs'] as $message) {
118: $log->add(strip_tags($message));
119: }
120: }
121:
122:
123: }
124: }
125: