1: <?php
2: // start hack by Trabis
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: // end hack by Trabis
12:
13: eval(' function xoops_module_uninstall_' . $mydirname . '( $module ) { return protector_onuninstall_base( $module , "' . $mydirname . '" ) ; } ');
14:
15: if (!function_exists('protector_onuninstall_base')) {
16:
17: /**
18: * @param $module
19: * @param $mydirname
20: *
21: * @return bool
22: */
23: function protector_onuninstall_base($module, $mydirname)
24: {
25: /** @var XoopsModule $module */
26: // translations on module uninstall
27:
28: global $ret; // TODO :-D
29:
30: if (!is_array($ret)) {
31: $ret = array();
32: }
33:
34: /** @var XoopsMySQLDatabase $db */
35: $db = XoopsDatabaseFactory::getDatabaseConnection();
36: $mid = $module->getVar('mid');
37: if (!is_array($ret)) {
38: $ret = array();
39: }
40:
41: // TABLES (loading mysql.sql)
42: $sql_file_path = __DIR__ . '/sql/mysql.sql';
43: $prefix_mod = $db->prefix() . '_' . $mydirname;
44: if (file_exists($sql_file_path)) {
45: $ret[] = 'SQL file found at <b>' . htmlspecialchars($sql_file_path, ENT_QUOTES) . '</b>.<br /> Deleting tables...<br>';
46: $sql_lines = file($sql_file_path);
47: foreach ($sql_lines as $sql_line) {
48: if (preg_match('/^CREATE TABLE \`?([a-zA-Z0-9_-]+)\`? /i', $sql_line, $regs)) {
49: $sql = 'DROP TABLE ' . addslashes($prefix_mod . '_' . $regs[1]);
50: if (!$db->query($sql)) {
51: $ret[] = '<span style="color:#ff0000;">ERROR: Could not drop table <b>' . htmlspecialchars($prefix_mod . '_' . $regs[1], ENT_QUOTES) . '<b>.</span><br>';
52: } else {
53: $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $regs[1], ENT_QUOTES) . '</b> dropped.<br>';
54: }
55: }
56: }
57: }
58:
59: // TEMPLATES (Not necessary because modulesadmin removes all templates)
60: /** @var XoopsTplfileHandler $tplfile_handler */
61: /* $tplfile_handler = xoops_getHandler( 'tplfile' ) ;
62: $templates =& $tplfile_handler->find( null , 'module' , $mid ) ;
63: $tcount = count( $templates ) ;
64: if ($tcount > 0) {
65: $ret[] = 'Deleting templates...' ;
66: for ($i = 0 ; $i < $tcount ; ++$i) {
67: if ( ! $tplfile_handler->delete( $templates[$i] ) ) {
68: $ret[] = '<span style="color:#ff0000;">ERROR: Could not delete template '.$templates[$i]->getVar('tpl_file','s').' from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id','s').'</b></span><br>';
69: } else {
70: $ret[] = 'Template <b>'.$templates[$i]->getVar('tpl_file','s').'</b> deleted from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id','s').'</b><br>';
71: }
72: }
73: }
74: unset($templates); */
75:
76: return true;
77: }
78:
79: /**
80: * @param $module_obj
81: * @param $log
82: */
83: function protector_message_append_onuninstall(&$module_obj, &$log)
84: {
85: if (isset($GLOBALS['ret']) && is_array($GLOBALS['ret'])) {
86: foreach ($GLOBALS['ret'] as $message) {
87: $log->add(strip_tags($message));
88: }
89: }
90:
91: // use mLog->addWarning() or mLog->addError() if necessary
92: }
93: }
94: