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_install_' . $mydirname . '( $module ) { return protector_oninstall_base( $module , "' . $mydirname . '" ) ; } ');
14:
15: if (!function_exists('protector_oninstall_base')) {
16:
17: 18: 19: 20: 21: 22:
23: function protector_oninstall_base($module, $mydirname)
24: {
25:
26:
27:
28: global $ret;
29:
30:
31: if (defined('XOOPS_CUBE_LEGACY')) {
32: $root =& XCube_Root::getSingleton();
33: $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'protector_message_append_oninstall');
34: $ret = array();
35: } else {
36: if (!is_array($ret)) {
37: $ret = array();
38: }
39: }
40:
41: $db = XoopsDatabaseFactory::getDatabaseConnection();
42: $mid = $module->getVar('mid');
43:
44:
45: $sql_file_path = __DIR__ . '/sql/mysql.sql';
46: $prefix_mod = $db->prefix() . '_' . $mydirname;
47: if (file_exists($sql_file_path)) {
48: $ret[] = 'SQL file found at <b>' . htmlspecialchars($sql_file_path) . '</b>.<br> Creating tables...';
49:
50: if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
51: include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
52: $sqlutil = new OldSqlUtility;
53: } else {
54: include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
55: $sqlutil = new SqlUtility;
56: }
57:
58: $sql_query = trim(file_get_contents($sql_file_path));
59: $sqlutil->splitMySqlFile($pieces, $sql_query);
60: $created_tables = array();
61: foreach ($pieces as $piece) {
62: $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
63: if (!$prefixed_query) {
64: $ret[] = 'Invalid SQL <b>' . htmlspecialchars($piece) . '</b><br>';
65:
66: return false;
67: }
68: if (!$db->query($prefixed_query[0])) {
69: $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br>';
70:
71:
72: return false;
73: } else {
74: if (!in_array($prefixed_query[4], $created_tables)) {
75: $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br>';
76: $created_tables[] = $prefixed_query[4];
77: } else {
78: $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
79: }
80: }
81: }
82: }
83:
84:
85: $tplfile_handler = xoops_getHandler('tplfile');
86: $tpl_path = __DIR__ . '/templates';
87: if ($handler = @opendir($tpl_path . '/')) {
88: while (($file = readdir($handler)) !== false) {
89: if (substr($file, 0, 1) === '.') {
90: continue;
91: }
92: $file_path = $tpl_path . '/' . $file;
93: if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
94: $mtime = (int)(@filemtime($file_path));
95: $tplfile = $tplfile_handler->create();
96: $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
97: $tplfile->setVar('tpl_refid', $mid);
98: $tplfile->setVar('tpl_tplset', 'default');
99: $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
100: $tplfile->setVar('tpl_desc', '', true);
101: $tplfile->setVar('tpl_module', $mydirname);
102: $tplfile->setVar('tpl_lastmodified', $mtime);
103: $tplfile->setVar('tpl_lastimported', 0);
104: $tplfile->setVar('tpl_type', 'module');
105: if (!$tplfile_handler->insert($tplfile)) {
106: $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br>';
107: } else {
108: $tplid = $tplfile->getVar('tpl_id');
109: $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br>';
110:
111: include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
112: include_once XOOPS_ROOT_PATH . '/class/template.php';
113: if (!xoops_template_touch($tplid)) {
114: $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br>';
115: } else {
116: $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br>';
117: }
118: }
119: }
120: }
121: closedir($handler);
122: }
123: include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
124: include_once XOOPS_ROOT_PATH . '/class/template.php';
125: xoops_template_clear_module_cache($mid);
126:
127: return true;
128: }
129:
130: 131: 132: 133:
134: function protector_message_append_oninstall(&$module_obj, &$log)
135: {
136: if (is_array(@$GLOBALS['ret'])) {
137: foreach ($GLOBALS['ret'] as $message) {
138: $log->add(strip_tags($message));
139: }
140: }
141:
142:
143: }
144: }
145: