Example #1
0
 /**
  * Get a reference to the only instance of database class and connects to DB
  *
  * if the class has not been instantiated yet, this will also take
  * care of that
  *
  * @static
  * @return      object  Reference to the only instance of database class
  */
 public static function instance()
 {
     if (self::$xoopsInstance !== false) {
         return self::$xoopsInstance;
     }
     $allowWebChanges = defined('XOOPS_DB_PROXY') ? false : true;
     if (substr(XOOPS_DB_TYPE, 0, 4) == 'pdo.') {
         self::$xoopsInstance = new icms_db_legacy_PdoDatabase(self::$pdoInstance, $allowWebChanges);
     } else {
         if (defined('XOOPS_DB_ALTERNATIVE') && class_exists(XOOPS_DB_ALTERNATIVE)) {
             $class = XOOPS_DB_ALTERNATIVE;
         } else {
             $class = 'icms_db_legacy_' . XOOPS_DB_TYPE;
             $class .= $allowWebChanges ? '_Safe' : '_Proxy';
         }
         self::$xoopsInstance = new $class();
         self::$xoopsInstance->setLogger(icms::$logger);
         if (!self::$xoopsInstance->connect()) {
             icms_loadLanguageFile('core', 'core');
             trigger_error(_CORE_DB_NOTRACEDB, E_USER_ERROR);
         }
     }
     self::$xoopsInstance->setPrefix(XOOPS_DB_PREFIX);
     return self::$xoopsInstance;
 }
Example #2
0
/**
 * Logic and rendering for editing a smilie
 * 
 * @param int $id
 */
function SmilesEdit($id)
{
    $db =& icms_db_Factory::instance();
    icms_cp_header();
    echo '<a href="admin.php?fct=smilies">' . _AM_SMILESCONTROL . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_EDITSMILE . '<br /><br />';
    if ($getsmiles = $db->query("SELECT * FROM " . $db->prefix("smiles") . " WHERE id = '" . (int) $id . "'")) {
        $numsmiles = $db->getRowsNum($getsmiles);
        if ($numsmiles == 0) {
            //EMPTY
        } else {
            if ($smiles = $db->fetchArray($getsmiles)) {
                $smiles['smile_code'] = icms_core_DataFilter::htmlSpecialChars($smiles['code']);
                $smiles['smile_url'] = icms_core_DataFilter::htmlSpecialChars($smiles['smile_url']);
                $smiles['smile_desc'] = icms_core_DataFilter::htmlSpecialChars($smiles['emotion']);
                $smiles['smile_display'] = $smiles['display'];
                $smiles['smile_form'] = _AM_EDITSMILE;
                $smiles['op'] = 'SmilesSave';
                include ICMS_MODULES_PATH . '/system/admin/smilies/smileform.php';
                $smile_form->addElement(new icms_form_elements_Hidden('old_smile', $smiles['smile_url']));
                $smile_form->display();
            }
        }
    } else {
        echo _AM_CNRFTSD;
    }
    icms_cp_footer();
}
Example #3
0
 /**
  * Constructor of class icms_view_Tree
  * Sets the names of table, unique id, and parent id
  * @param string $table_name Name of table containing the parent-child structure
  * @param string $id_name Name of the unique id field in the table
  * @param $pid_name Name of the parent id field in the table
  **/
 public function __construct($table_name, $id_name, $pid_name)
 {
     $this->db =& icms_db_Factory::instance();
     $this->table = $table_name;
     $this->id = $id_name;
     $this->pid = $pid_name;
 }
Example #4
0
/**
 * Deletes users who registered but aren't yet active for X days.
 *
 * To be used in ImpressCMS 1.2
 * @return mixed Did the query succeed or not? Returns nothing if succeeded, false if not succeeded
 **/
function remove_usersxdays() {
	$db =& icms_db_Factory::instance();
	global $icmsConfigUser;
	$days = $icmsConfigUser['delusers'];
	$delete_regdate= time() - ($days * 24 * 60 * 60);  // X days/month * 24 hrs/day
	$sql = sprintf("DELETE FROM %s WHERE (level = '0' AND user_regdate < '%s')", $db->prefix('users'), $delete_regdate);
	if (!$result = $db->queryF($sql)) {
		return FALSE;
	}
}
Example #5
0
 /**
  * Contstructor
  *
  * @param   int      $storyid
  **/
 function Story($storyid = -1)
 {
     $this->db = icms_db_Factory::instance();
     $this->table = '';
     $this->topicstable = '';
     if (is_array($storyid)) {
         $this->makeStory($storyid);
     } elseif ($storyid != -1) {
         $this->getStory((int) $storyid);
     }
 }
Example #6
0
 function protector_onuninstall_base($module, $mydirname)
 {
     // transations on module uninstall
     global $ret;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUninstall.' . ucfirst($mydirname) . '.Success', 'protector_message_append_onuninstall');
         $ret = array();
     } else {
         if (!is_array($ret)) {
             $ret = array();
         }
     }
     $db =& icms_db_Factory::instance();
     $mid = $module->getVar('mid');
     // TABLES (loading mysql.sql)
     $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
     $prefix_mod = $db->prefix() . '_' . $mydirname;
     if (file_exists($sql_file_path)) {
         $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br  /> Deleting tables...<br />";
         $sql_lines = file($sql_file_path);
         foreach ($sql_lines as $sql_line) {
             if (preg_match('/^CREATE TABLE \\`?([a-zA-Z0-9_-]+)\\`? /i', $sql_line, $regs)) {
                 $sql = 'DROP TABLE ' . addslashes($prefix_mod . '_' . $regs[1]);
                 if (!$db->query($sql)) {
                     $ret[] = '<span style="color:#ff0000;">ERROR: Could not drop table <b>' . htmlspecialchars($prefix_mod . '_' . $regs[1]) . '<b>.</span><br />';
                 } else {
                     $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $regs[1]) . '</b> dropped.<br />';
                 }
             }
         }
     }
     // TEMPLATES (Not necessary because modulesadmin removes all templates)
     /* $tplfile_handler =& icms::handler('icms_view_template_file') ;
     	$templates =& $tplfile_handler->find( null , 'module' , $mid ) ;
     	$tcount = count( $templates ) ;
     	if( $tcount > 0 ) {
     		$ret[] = 'Deleting templates...' ;
     		for( $i = 0 ; $i < $tcount ; $i ++ ) {
     			if( ! $tplfile_handler->delete( $templates[$i] ) ) {
     				$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 />';
     			} else {
     				$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 />';
     			}
     		}
     	}
     	unset($templates); */
     if (defined(ICMS_PRELOAD_PATH) && file_exists(ICMS_PRELOAD_PATH . '/protector.php') && function_exists('icms_deleteFile')) {
         icms_deleteFile(ICMS_PRELOAD_PATH . '/protector.php');
     }
     return true;
 }
Example #7
0
 /**
  * Constructor
  *
  * @param   string   $table      the table with all the topics
  * @param   int      $topicid    the current topicid
  **/
 function XoopsTopic($table, $topicid = 0)
 {
     $this->db =& icms_db_Factory::instance();
     $this->table = $table;
     if (is_array($topicid)) {
         $this->makeTopic($topicid);
     } elseif ($topicid != 0) {
         $this->getTopic((int) $topicid);
     } else {
         $this->topic_id = $topicid;
     }
 }
 function protector_notify_base($mydirname, $category, $item_id)
 {
     include_once dirname(__FILE__) . '/include/common_functions.php';
     $db =& icms_db_Factory::instance();
     $module_handler = icms::handler('icms_module');
     $module =& $module_handler->getByDirname($mydirname);
     if ($category == 'global') {
         $item['name'] = '';
         $item['url'] = '';
         return $item;
     }
 }
function icms_module_update($dirname)
{
    $dirname = trim($dirname);
    $db =& icms_db_Factory::instance();
    $module_handler = icms::handler('icms_module');
    $module =& $module_handler->getByDirname($dirname);
    // Save current version for use in the update function
    $prev_version = $module->getVar('version');
    $prev_dbversion = $module->getVar('dbversion');
    xoops_template_clear_module_cache($module->getVar('mid'));
    // we dont want to change the module name set by admin
    $temp_name = $module->getVar('name');
    $module->loadInfoAsVar($dirname);
    $module->setVar('name', $temp_name);
    if (!$module_handler->insert($module)) {
        echo '<p>Could not update ' . $module->getVar('name') . '</p>';
        echo "<br /><a href='admin.php?fct=modulesadmin'>" . _MD_AM_BTOMADMIN . "</a>";
    } else {
        $newmid = $module->getVar('mid');
        $msgs = array();
        $msgs[] = _MD_AM_MOD_DATA_UPDATED;
        $tplfile_handler =& icms::handler('icms_view_template_file');
        $deltpl =& $tplfile_handler->find('default', 'module', $module->getVar('mid'));
        $delng = array();
        if (is_array($deltpl)) {
            $xoopsDelTpl = new icms_view_Tpl();
            // clear cache files
            $xoopsDelTpl->clear_cache(null, 'mod_' . $dirname);
            // delete template file entry in db
            $dcount = count($deltpl);
            for ($i = 0; $i < $dcount; $i++) {
                if (!$tplfile_handler->delete($deltpl[$i])) {
                    $delng[] = $deltpl[$i]->getVar('tpl_file');
                }
            }
        }
        $templates = $module->getInfo('templates');
        if ($templates != false) {
            $msgs[] = _MD_AM_MOD_UP_TEM;
            foreach ($templates as $tpl) {
                $tpl['file'] = trim($tpl['file']);
                if (!in_array($tpl['file'], $delng)) {
                    $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
                    $tplfile =& $tplfile_handler->create();
                    $tplfile->setVar('tpl_refid', $newmid);
                    $tplfile->setVar('tpl_lastimported', 0);
                    $tplfile->setVar('tpl_lastmodified', time());
                    if (preg_match("/\\.css\$/i", $tpl['file'])) {
                        $tplfile->setVar('tpl_type', 'css');
                    } else {
                        $tplfile->setVar('tpl_type', 'module');
                    }
                    $tplfile->setVar('tpl_source', $tpldata, true);
                    $tplfile->setVar('tpl_module', $dirname);
                    $tplfile->setVar('tpl_tplset', 'default');
                    $tplfile->setVar('tpl_file', $tpl['file'], true);
                    $tplfile->setVar('tpl_desc', $tpl['description'], true);
                    if (!$tplfile_handler->insert($tplfile)) {
                        $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_INSERT_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                    } else {
                        $newid = $tplfile->getVar('tpl_id');
                        $msgs[] = sprintf('&nbsp;&nbsp;<span>' . _MD_AM_TEMPLATE_INSERTED . '</span>', '<strong>' . $tpl['file'] . '</strong>', '<strong>' . $newid . '</strong>');
                        if ($icmsConfig['template_set'] == 'default') {
                            if (!icms_view_Tpl::template_touch($newid)) {
                                $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                            } else {
                                $msgs[] = sprintf('&nbsp;&nbsp;<span>' . _MD_AM_TEMPLATE_RECOMPILED . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                            }
                        }
                    }
                    unset($tpldata);
                } else {
                    $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_DELETE_FAIL . '</span>', $tpl['file']);
                }
            }
        }
        $blocks = $module->getInfo('blocks');
        $msgs[] = _MD_AM_MOD_REBUILD_BLOCKS;
        if ($blocks != false) {
            $count = count($blocks);
            $showfuncs = array();
            $funcfiles = array();
            for ($i = 1; $i <= $count; $i++) {
                if (isset($blocks[$i]['show_func']) && $blocks[$i]['show_func'] != '' && isset($blocks[$i]['file']) && $blocks[$i]['file'] != '') {
                    $editfunc = isset($blocks[$i]['edit_func']) ? $blocks[$i]['edit_func'] : '';
                    $showfuncs[] = $blocks[$i]['show_func'];
                    $funcfiles[] = $blocks[$i]['file'];
                    $template = '';
                    if (isset($blocks[$i]['template']) && trim($blocks[$i]['template']) != '') {
                        $content =& xoops_module_gettemplate($dirname, $blocks[$i]['template'], true);
                    }
                    if (!$content) {
                        $content = '';
                    } else {
                        $template = $blocks[$i]['template'];
                    }
                    $options = '';
                    if (!empty($blocks[$i]['options'])) {
                        $options = $blocks[$i]['options'];
                    }
                    $sql = "SELECT bid, name FROM " . $db->prefix('newblocks') . " WHERE mid='" . (int) $module->getVar('mid') . "' AND func_num='" . (int) $i . "' AND show_func='" . addslashes($blocks[$i]['show_func']) . "' AND func_file='" . addslashes($blocks[$i]['file']) . "'";
                    $fresult = $db->query($sql);
                    $fcount = 0;
                    while ($fblock = $db->fetchArray($fresult)) {
                        $fcount++;
                        $sql = "UPDATE " . $db->prefix("newblocks") . " SET name='" . addslashes($blocks[$i]['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . " WHERE bid='" . (int) $fblock['bid'] . "'";
                        $result = $db->query($sql);
                        if (!$result) {
                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_UPDATE_FAIL, $fblock['name']);
                        } else {
                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_UPDATED, '<strong>' . $fblock['name'] . '</strong>', '<strong>' . icms_conv_nr2local($fblock['bid']) . '</strong>');
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->find('default', 'block', $fblock['bid']);
                                if (count($tplfile) == 0) {
                                    $tplfile_new =& $tplfile_handler->create();
                                    $tplfile_new->setVar('tpl_module', $dirname);
                                    $tplfile_new->setVar('tpl_refid', (int) $fblock['bid']);
                                    $tplfile_new->setVar('tpl_tplset', 'default');
                                    $tplfile_new->setVar('tpl_file', $blocks[$i]['template'], true);
                                    $tplfile_new->setVar('tpl_type', 'block');
                                } else {
                                    $tplfile_new = $tplfile[0];
                                }
                                $tplfile_new->setVar('tpl_source', $content, true);
                                $tplfile_new->setVar('tpl_desc', $blocks[$i]['description'], true);
                                $tplfile_new->setVar('tpl_lastmodified', time());
                                $tplfile_new->setVar('tpl_lastimported', 0);
                                if (!$tplfile_handler->insert($tplfile_new)) {
                                    $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_UPDATE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;Template <b>' . $blocks[$i]['template'] . '</b> updated.';
                                    if ($icmsConfig['template_set'] == 'default') {
                                        if (!icms_view_Tpl::template_touch($tplfile_new->getVar('tpl_id'))) {
                                            $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        } else {
                                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_RECOMPILED, '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ($fcount == 0) {
                        $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq');
                        $block_name = addslashes($blocks[$i]['name']);
                        $sql = "INSERT INTO " . $db->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ('" . (int) $newbid . "', '" . (int) $module->getVar('mid') . "', '" . (int) $i . "','" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', '1', '0', '0', 'M', 'H', '1', '" . addslashes($dirname) . "', '" . addslashes($blocks[$i]['file']) . "', '" . addslashes($blocks[$i]['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', '0', '" . time() . "')";
                        $result = $db->query($sql);
                        if (!$result) {
                            $msgs[] = '&nbsp;&nbsp;ERROR: Could not create ' . $blocks[$i]['name'];
                            echo $sql;
                        } else {
                            if (empty($newbid)) {
                                $newbid = $db->getInsertId();
                            }
                            $groups =& icms::$user->getGroups();
                            $gperm_handler = icms::handler('icms_member_groupperm');
                            foreach ($groups as $mygroup) {
                                $bperm =& $gperm_handler->create();
                                $bperm->setVar('gperm_groupid', (int) $mygroup);
                                $bperm->setVar('gperm_itemid', (int) $newbid);
                                $bperm->setVar('gperm_name', 'block_read');
                                $bperm->setVar('gperm_modid', 1);
                                if (!$gperm_handler->insert($bperm)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>' . $newbid . '</b> Group ID: <b>' . $mygroup . '</b></span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;Added block access right. Block ID: <b>' . $newbid . '</b> Group ID: <b>' . $mygroup . '</b>';
                                }
                            }
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->create();
                                $tplfile->setVar('tpl_module', $dirname);
                                $tplfile->setVar('tpl_refid', (int) $newbid);
                                $tplfile->setVar('tpl_source', $content, true);
                                $tplfile->setVar('tpl_tplset', 'default');
                                $tplfile->setVar('tpl_file', $blocks[$i]['template'], true);
                                $tplfile->setVar('tpl_type', 'block');
                                $tplfile->setVar('tpl_lastimported', 0);
                                $tplfile->setVar('tpl_lastmodified', time());
                                $tplfile->setVar('tpl_desc', $blocks[$i]['description'], true);
                                if (!$tplfile_handler->insert($tplfile)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $blocks[$i]['template'] . '</b> to the database.</span>';
                                } else {
                                    $newid = $tplfile->getVar('tpl_id');
                                    $msgs[] = '&nbsp;&nbsp;Template <b>' . $blocks[$i]['template'] . '</b> added to the database.';
                                    if ($icmsConfig['template_set'] == 'default') {
                                        if (!icms_view_Tpl::template_touch($newid)) {
                                            $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        } else {
                                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_RECOMPILED, '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        }
                                    }
                                }
                            }
                            $msgs[] = '&nbsp;&nbsp;Block <b>' . $blocks[$i]['name'] . '</b> created. Block ID: <b>' . $newbid . '</b>';
                            $sql = "INSERT INTO " . $db->prefix('block_module_link') . " (block_id, module_id, page_id) VALUES ('" . (int) $newbid . "', '0', '1')";
                            $db->query($sql);
                        }
                    }
                }
            }
            $icms_block_handler = icms::handler('icms_view_block');
            $block_arr = $icms_block_handler->getByModule($module->getVar('mid'));
            foreach ($block_arr as $block) {
                if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
                    $sql = sprintf("DELETE FROM %s WHERE bid = '%u'", $db->prefix('newblocks'), (int) $block->getVar('bid'));
                    if (!$db->query($sql)) {
                        $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>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Block <b>' . $block->getVar('name') . ' deleted. Block ID: <b>' . $block->getVar('bid') . '</b>';
                        if ($block->getVar('template') != '') {
                            $tplfiles =& $tplfile_handler->find(null, 'block', $block->getVar('bid'));
                            if (is_array($tplfiles)) {
                                $btcount = count($tplfiles);
                                for ($k = 0; $k < $btcount; $k++) {
                                    if (!$tplfile_handler->delete($tplfiles[$k])) {
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not remove deprecated block template. (ID: <b>' . $tplfiles[$k]->getVar('tpl_id') . '</b>)</span>';
                                    } else {
                                        $msgs[] = '&nbsp;&nbsp;Block template <b>' . $tplfiles[$k]->getVar('tpl_file') . '</b> deprecated.';
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // first delete all config entries
        $config_handler = icms::handler('icms_config');
        $configs =& $config_handler->getConfigs(new icms_db_criteria_Item('conf_modid', $module->getVar('mid')));
        $confcount = count($configs);
        $config_delng = array();
        if ($confcount > 0) {
            $msgs[] = 'Deleting module config options...';
            for ($i = 0; $i < $confcount; $i++) {
                if (!$config_handler->deleteConfig($configs[$i])) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete config data from the database. Config ID: <b>' . $configs[$i]->getvar('conf_id') . '</b></span>';
                    // save the name of config failed to delete for later use
                    $config_delng[] = $configs[$i]->getvar('conf_name');
                } else {
                    $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
                    $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
                    $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
                    $msgs[] = '&nbsp;&nbsp;Config data deleted from the database. Config ID: <b>' . $configs[$i]->getVar('conf_id') . '</b>';
                }
            }
        }
        // now reinsert them with the new settings
        $configs = $module->getInfo('config');
        if ($configs != false) {
            if ($module->getVar('hascomments') != 0) {
                include_once ICMS_ROOT_PATH . '/include/comment_constants.php';
                array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
                array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
            }
        } else {
            if ($module->getVar('hascomments') != 0) {
                $configs = array();
                include_once ICMS_ROOT_PATH . '/include/comment_constants.php';
                $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
                $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
            }
        }
        // RMV-NOTIFY
        if ($module->getVar('hasnotification') != 0) {
            if (empty($configs)) {
                $configs = array();
            }
            // Main notification options
            include_once ICMS_ROOT_PATH . '/include/notification_constants.php';
            include_once ICMS_ROOT_PATH . '/include/notification_functions.php';
            $options = array();
            $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
            $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
            $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
            $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
            //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
            $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options);
            // Event specific notification options
            // FIXME: for some reason the default doesn't come up properly
            //  initially is ok, but not when 'update' module..
            $options = array();
            $categories =& icms_data_notification_Handler::categoryInfo('', $module->getVar('mid'));
            foreach ($categories as $category) {
                $events =& icms_data_notification_Handler::categoryEvents($category['name'], false, $module->getVar('mid'));
                foreach ($events as $event) {
                    if (!empty($event['invisible'])) {
                        continue;
                    }
                    $option_name = $category['title'] . ' : ' . $event['title'];
                    $option_value = $category['name'] . '-' . $event['name'];
                    $options[$option_name] = $option_value;
                    //$configs[] = array ('name' => icms_data_notification_Handler::generateConfig($category,$event,'name'), 'title' => icms_data_notification_Handler::generateConfig($category,$event,'title_constant'), 'description' => icms_data_notification_Handler::generateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
                }
            }
            $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
        }
        if ($configs != false) {
            $msgs[] = 'Adding module config data...';
            $config_handler = icms::handler('icms_config');
            $order = 0;
            foreach ($configs as $config) {
                // only insert ones that have been deleted previously with success
                if (!in_array($config['name'], $config_delng)) {
                    $confobj =& $config_handler->createConfig();
                    $confobj->setVar('conf_modid', (int) $newmid);
                    $confobj->setVar('conf_catid', 0);
                    $confobj->setVar('conf_name', $config['name']);
                    $confobj->setVar('conf_title', $config['title'], true);
                    $confobj->setVar('conf_desc', $config['description'], true);
                    $confobj->setVar('conf_formtype', $config['formtype']);
                    $confobj->setVar('conf_valuetype', $config['valuetype']);
                    if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
                        // preserver the old value if any
                        // form type and value type must be the same
                        $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
                    } else {
                        $confobj->setConfValueForInput($config['default'], true);
                        //$confobj->setVar('conf_value', $config['default'], true);
                    }
                    $confobj->setVar('conf_order', $order);
                    $confop_msgs = '';
                    if (isset($config['options']) && is_array($config['options'])) {
                        foreach ($config['options'] as $key => $value) {
                            $confop =& $config_handler->createConfigOption();
                            $confop->setVar('confop_name', $key, true);
                            $confop->setVar('confop_value', $value, true);
                            $confobj->setConfOptions($confop);
                            $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>';
                            unset($confop);
                        }
                    }
                    $order++;
                    if (false != $config_handler->insertConfig($confobj)) {
                        $msgs[] = '&nbsp;&nbsp;Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs;
                    } else {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>';
                    }
                    unset($confobj);
                }
            }
            unset($configs);
        }
        // add module specific tasks to system autotasks list
        $atasks = $module->getInfo('autotasks');
        $atasks_handler =& icms_getModuleHandler('autotasks', 'system');
        if (count($atasks) > 0) {
            $msgs[] = 'Updating autotasks...';
            $criteria = new icms_db_criteria_Compo();
            $criteria->add(new icms_db_criteria_Item('sat_type', 'addon/' . $module->getInfo('dirname')));
            $items_atasks = $atasks_handler->getObjects($criteria, false);
            foreach ($items_atasks as $task) {
                $taskID = (int) $task->getVar('sat_addon_id');
                $atasks[$taskID]['enabled'] = $task->getVar('sat_enabled');
                $atasks[$taskID]['repeat'] = $task->getVar('sat_repeat');
                $atasks[$taskID]['interval'] = $task->getVar('sat_interval');
                $atasks[$taskID]['name'] = $task->getVar('sat_name');
            }
            $atasks_handler->deleteAll($criteria);
            foreach ($atasks as $taskID => $taskData) {
                if (!isset($taskData['code']) || trim($taskData['code']) == '') {
                    continue;
                }
                $task =& $atasks_handler->create();
                if (isset($taskData['enabled'])) {
                    $task->setVar('sat_enabled', $taskData['enabled']);
                }
                if (isset($taskData['repeat'])) {
                    $task->setVar('sat_repeat', $taskData['repeat']);
                }
                if (isset($taskData['interval'])) {
                    $task->setVar('sat_interval', $taskData['interval']);
                }
                if (isset($taskData['onfinish'])) {
                    $task->setVar('sat_onfinish', $taskData['onfinish']);
                }
                $task->setVar('sat_name', $taskData['name']);
                $task->setVar('sat_code', sprintf("require ICMS_ROOT_PATH . \"/modules/%s/%s\";", $module->getInfo('dirname'), addslashes($taskData['code'])));
                $task->setVar('sat_type', 'addon/' . $module->getInfo('dirname'));
                $task->setVar('sat_addon_id', (int) $taskID);
                if (!$atasks_handler->insert($task)) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert autotask to db. Name: <b>' . $taskData['name'] . '</b></span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;Updated task from autotasks list. Task Name: <b>' . $taskData['name'] . '</b>';
                }
            }
            unset($atasks, $atasks_handler, $task, $taskData, $criteria, $items, $taskID);
        }
        // execute module specific update script if any
        $update_script = $module->getInfo('onUpdate');
        $ModName = $module->getInfo('modname') != '' ? trim($module->getInfo('modname')) : $dirname;
        if (false != $update_script && trim($update_script) != '') {
            include_once ICMS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script);
            $is_IPF = $module->getInfo('object_items');
            if (!empty($is_IPF)) {
                $icmsDatabaseUpdater = icms_db_legacy_Factory::getDatabaseUpdater();
                $icmsDatabaseUpdater->moduleUpgrade($module, true);
                foreach ($icmsDatabaseUpdater->_messages as $msg) {
                    $msgs[] = $msg;
                }
            }
            if (function_exists('xoops_module_update_' . $ModName)) {
                $func = 'xoops_module_update_' . $ModName;
                if (!$func($module, $prev_version, $prev_dbversion)) {
                    $msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
                } else {
                    $msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
                }
            } elseif (function_exists('icms_module_update_' . $ModName)) {
                $func = 'icms_module_update_' . $ModName;
                if (!$func($module, $prev_version, $prev_dbversion)) {
                    $msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
                } else {
                    $msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
                }
            }
        }
        $msgs[] = '</code><p>' . sprintf(_MD_AM_OKUPD, '<b>' . $module->getVar('name') . '</b>') . '</p>';
    }
    $ret = '<code>';
    foreach ($msgs as $msg) {
        $ret .= $msg . '<br />';
    }
    return $ret;
}
Example #10
0
/**
 * @todo Move to a static class method - user
 * Enter description here ...
 * @param $email
 */
function icms_getUnameFromUserEmail($email = '')
{
    $db = icms_db_Factory::instance();
    if ($email !== '') {
        $sql = $db->query("SELECT uname, email FROM " . $db->prefix('users') . " WHERE email = '" . @htmlspecialchars($email, ENT_QUOTES, _CHARSET) . "'");
        list($uname, $email) = $db->fetchRow($sql);
    } else {
        redirect_header('user.php', 2, _US_SORRYNOTFOUND);
    }
    return $uname;
}
Example #11
0
<?php

require_once dirname(dirname(__FILE__)) . '/class/gtickets.php';
$myts =& icms_core_Textsanitizer::getInstance();
$db =& icms_db_Factory::instance();
// GET vars
$pos = empty($_GET['pos']) ? 0 : intval($_GET['pos']);
$num = empty($_GET['num']) ? 20 : intval($_GET['num']);
// for RTL users
@define('_GLOBAL_LEFT', @_ADM_USE_RTL == 1 ? 'right' : 'left');
@define('_GLOBAL_RIGHT', @_ADM_USE_RTL == 1 ? 'left' : 'right');
// Table Name
$log_table = $db->prefix($mydirname . "_log");
// Protector object
require_once dirname(dirname(__FILE__)) . '/class/protector.php';
$db =& icms_db_Factory::instance();
$protector =& Protector::getInstance($db->conn);
$conf = $protector->getConf();
//
// transaction stage
//
if (!empty($_POST['action'])) {
    // Ticket check
    if (!$xoopsGTicket->check(true, 'protector_admin')) {
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
    }
    if ($_POST['action'] == 'update_ips') {
        $error_msg = '';
        $lines = empty($_POST['bad_ips']) ? array() : explode("\n", trim($_POST['bad_ips']));
        $bad_ips = array();
        foreach ($lines as $line) {
function protector_postcommon()
{
    global $xoopsModule;
    // patch for 2.2.x from xoops.org (I know this is not so beautiful...)
    if (substr(@XOOPS_VERSION, 6, 3) > 2.0 && stristr(@$_SERVER['REQUEST_URI'], 'modules/system/admin.php?fct=preferences')) {
        $module_handler = icms::handler('icms_module');
        $module =& $module_handler->get(intval(@$_GET['mod']));
        if (is_object($module)) {
            $module->getInfo();
        }
    }
    // configs writable check
    if (@$_SERVER['REQUEST_URI'] == '/admin.php' && !is_writable(dirname(dirname(__FILE__)) . '/configs')) {
        trigger_error('You should turn the directory ' . dirname(dirname(__FILE__)) . '/configs writable', E_USER_WARNING);
    }
    // Protector object
    require_once dirname(dirname(__FILE__)) . '/class/protector.php';
    $db =& icms_db_Factory::instance();
    $protector =& Protector::getInstance();
    $protector->setConn($db->conn);
    $protector->updateConfFromDb();
    $conf = $protector->getConf();
    if (empty($conf)) {
        return true;
    }
    // not installed yet
    // phpmailer vulnerability
    // http://larholm.com/2007/06/11/phpmailer-0day-remote-execution/
    if (in_array(substr(XOOPS_VERSION, 0, 12), array('XOOPS 2.0.16', 'XOOPS 2.0.13', 'XOOPS 2.2.4'))) {
        $config_handler = icms::handler('icms_config');
        $xoopsMailerConfig =& $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
        if ($xoopsMailerConfig['mailmethod'] == 'sendmail' && md5_file(XOOPS_ROOT_PATH . '/class/mail/phpmailer/class.phpmailer.php') == 'ee1c09a8e579631f0511972f929fe36a') {
            echo '<strong>phpmailer security hole! Change the preferences of mail from "sendmail" to another, or upgrade the core right now! (message by protector)</strong>';
        }
    }
    // global enabled or disabled
    if (!empty($conf['global_disabled'])) {
        return true;
    }
    // group1_ips (groupid=1)
    if (is_object(icms::$user) && in_array(1, icms::$user->getGroups())) {
        $group1_ips = $protector->get_group1_ips(true);
        if (implode('', array_keys($group1_ips))) {
            $group1_allow = $protector->ip_match($group1_ips);
            if (empty($group1_allow)) {
                die('This account is disabled for your IP by Protector.<br />Clear cookie if you want to access this site as a guest.');
            }
        }
    }
    // reliable ips
    $reliable_ips = @unserialize(@$conf['reliable_ips']);
    if (is_array($reliable_ips)) {
        foreach ($reliable_ips as $reliable_ip) {
            if (!empty($reliable_ip) && preg_match('/' . $reliable_ip . '/', $_SERVER['REMOTE_ADDR'])) {
                return true;
            }
        }
    }
    // user information (uid and can be banned)
    if (is_object(@icms::$user)) {
        $uid = icms::$user->getVar('uid');
        $can_ban = count(@array_intersect(icms::$user->getGroups(), @unserialize(@$conf['bip_except']))) ? false : true;
    } else {
        // login failed check
        if (!empty($_POST['uname']) && !empty($_POST['pass']) || !empty($_COOKIE['autologin_uname']) && !empty($_COOKIE['autologin_pass'])) {
            $protector->check_brute_force();
        }
        $uid = 0;
        $can_ban = true;
    }
    // If precheck has already judged that he should be banned
    if ($can_ban && $protector->_should_be_banned) {
        $protector->register_bad_ips();
    } else {
        if ($can_ban && $protector->_should_be_banned_time0) {
            $protector->register_bad_ips(time() + $protector->_conf['banip_time0']);
        }
    }
    // DOS/CRAWLER skipping based on 'dirname' or getcwd()
    $dos_skipping = false;
    $skip_dirnames = explode('|', @$conf['dos_skipmodules']);
    if (!is_array($skip_dirnames)) {
        $skip_dirnames = array();
    }
    if (is_object(@$xoopsModule)) {
        if (in_array($xoopsModule->getVar('dirname'), $skip_dirnames)) {
            $dos_skipping = true;
        }
    } else {
        foreach ($skip_dirnames as $skip_dirname) {
            if ($skip_dirname && strstr(getcwd(), $skip_dirname)) {
                $dos_skipping = true;
                break;
            }
        }
    }
    // module can controll DoS skipping
    if (defined('PROTECTOR_SKIP_DOS_CHECK')) {
        $dos_skipping = true;
    }
    // DoS Attack
    if (empty($dos_skipping) && !$protector->check_dos_attack($uid, $can_ban)) {
        $protector->output_log($protector->last_error_type, $uid, true, 16);
    }
    // check session hi-jacking
    $ips = explode('.', @$_SESSION['protector_last_ip']);
    $protector_last_numip = @$ips[0] * 0x1000000 + @$ips[1] * 0x10000 + @$ips[2] * 0x100 + @$ips[3];
    $ips = explode('.', $_SERVER['REMOTE_ADDR']);
    $remote_numip = @$ips[0] * 0x1000000 + @$ips[1] * 0x10000 + @$ips[2] * 0x100 + @$ips[3];
    $shift = 32 - @$conf['session_fixed_topbit'];
    if ($shift < 32 && $shift >= 0 && !empty($_SESSION['protector_last_ip']) && $protector_last_numip >> $shift != $remote_numip >> $shift) {
        if (is_object(icms::$user) && count(array_intersect(icms::$user->getGroups(), unserialize($conf['groups_denyipmove'])))) {
            $protector->purge(true);
        }
    }
    $_SESSION['protector_last_ip'] = $_SERVER['REMOTE_ADDR'];
    // SQL Injection "Isolated /*"
    if (!$protector->check_sql_isolatedcommentin(@$conf['isocom_action'] & 1)) {
        if ($conf['isocom_action'] & 8 && $can_ban) {
            $protector->register_bad_ips();
        } else {
            if ($conf['isocom_action'] & 4 && $can_ban) {
                $protector->register_bad_ips(time() + $protector->_conf['banip_time0']);
            }
        }
        $protector->output_log('ISOCOM', $uid, true, 32);
        if ($conf['isocom_action'] & 2) {
            $protector->purge();
        }
    }
    // SQL Injection "UNION"
    if (!$protector->check_sql_union(@$conf['union_action'] & 1)) {
        if ($conf['union_action'] & 8 && $can_ban) {
            $protector->register_bad_ips();
        } else {
            if ($conf['union_action'] & 4 && $can_ban) {
                $protector->register_bad_ips(time() + $protector->_conf['banip_time0']);
            }
        }
        $protector->output_log('UNION', $uid, true, 32);
        if ($conf['union_action'] & 2) {
            $protector->purge();
        }
    }
    if (!empty($_POST)) {
        // SPAM Check
        if (is_object(icms::$user)) {
            if (!icms::$user->isAdmin() && $conf['spamcount_uri4user']) {
                $protector->spam_check(intval($conf['spamcount_uri4user']), icms::$user->getVar('uid'));
            }
        } else {
            if ($conf['spamcount_uri4guest']) {
                $protector->spam_check(intval($conf['spamcount_uri4guest']), 0);
            }
        }
        // filter plugins for POST on postcommon stage
        $protector->call_filter('postcommon_post');
    }
    // register.php Protection
    if ($_SERVER['SCRIPT_FILENAME'] == XOOPS_ROOT_PATH . '/register.php') {
        $protector->call_filter('postcommon_register');
    }
    // Simple check for manupilations by FTP worm etc.
    if (!empty($conf['enable_manip_check'])) {
        $protector->check_manipulation();
    }
}
Example #13
0
 function &getCategories($respond = true)
 {
     if (!$this->_checkUser($this->params[1], $this->params[2])) {
         $this->response->add(new XoopsXmlRpcFault(104));
     } else {
         include_once ICMS_ROOT_PATH . '/class/xoopstopic.php';
         $db =& icms_db_Factory::instance();
         $xt = new XoopsTopic($db->prefix('topics'));
         $ret = $xt->getTopicsList();
         if (!$respond) {
             return $ret;
         } else {
             if (count($ret) == 0) {
                 $this->response->add(new XoopsXmlRpcFault(106, 'Found 0 Entries'));
             } else {
                 $arr = new XoopsXmlRpcArray();
                 foreach ($ret as $topic_id => $topic_vars) {
                     $struct = new XoopsXmlRpcStruct();
                     $struct->add('categoryId', new XoopsXmlRpcString($topic_id));
                     $struct->add('categoryName', new XoopsXmlRpcString($topic_vars['title']));
                     $struct->add('categoryPid', new XoopsXmlRpcString($topic_vars['pid']));
                     $arr->add($struct);
                     unset($struct);
                 }
                 $this->response->add($arr);
             }
         }
     }
 }
Example #14
0
 function protector_oninstall_base($module, $mydirname)
 {
     // transations on module install
     global $ret;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'protector_message_append_oninstall');
         $ret = array();
     } else {
         if (!is_array($ret)) {
             $ret = array();
         }
     }
     $db =& icms_db_Factory::instance();
     $mid = $module->getVar('mid');
     // TABLES (loading mysql.sql)
     $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
     $prefix_mod = $db->prefix() . '_' . $mydirname;
     if (file_exists($sql_file_path)) {
         $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...";
         $sqlutil = new icms_db_legacy_mysql_Utility();
         $sql_query = trim(file_get_contents($sql_file_path));
         $sqlutil->splitMySqlFile($pieces, $sql_query);
         $created_tables = array();
         foreach ($pieces as $piece) {
             $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
             if (!$prefixed_query) {
                 $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
                 return false;
             }
             if (!$db->query($prefixed_query[0])) {
                 $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
                 //var_dump( $db->error() ) ;
                 return false;
             } else {
                 if (!in_array($prefixed_query[4], $created_tables)) {
                     $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
                     $created_tables[] = $prefixed_query[4];
                 } else {
                     $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
                 }
             }
         }
     }
     // TEMPLATES
     $tplfile_handler =& new icms_view_template_file_Handler(icms::$xoopsDB);
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
                     // generate compiled file
                     if (!icms_view_Tpl::template_touch($tplid)) {
                         $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
                     } else {
                         $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
                     }
                 }
             }
         }
         closedir($handler);
     }
     /*
     Fixes Bug #619 : parse Error
     */
     if (defined('ICMS_PRELOAD_PATH') && !file_exists(ICMS_PRELOAD_PATH . '/protector.php') && (!defined('PROTECTOR_POSTCHECK_INCLUDED') || !defined('PROTECTOR_PRECHECK_INCLUDED'))) {
         if (icms_core_Filesystem::copyRecursive(ICMS_TRUST_PATH . '/modules/protector/patches/ImpressCMS1.1/preload_protector.php', ICMS_PRELOAD_PATH . '/protector.php')) {
             $ret[] = 'Successfully moved protector preload<br />';
         } else {
             $ret[] = icms_core_Message::error("Failed to move protector preload - your site is not protected.", "", FALSE);
         }
     }
     icms_view_Tpl::template_clear_module_cache($mid);
     return true;
 }
Example #15
0
 function protector_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'protector_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& icms_db_Factory::instance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     list(, $create_string) = $db->fetchRow($db->query("SHOW CREATE TABLE " . $db->prefix("config")));
     foreach (explode('KEY', $create_string) as $line) {
         if (preg_match('/(\\`conf\\_title_\\d+\\`) \\(\\`conf\\_title\\`\\)/', $line, $regs)) {
             $db->query("ALTER TABLE " . $db->prefix("config") . " DROP KEY " . $regs[1]);
         }
     }
     $db->query("ALTER TABLE " . $db->prefix("config") . " ADD KEY `conf_title` (`conf_title`)");
     // 2.x -> 3.0
     list(, $create_string) = $db->fetchRow($db->query("SHOW CREATE TABLE " . $db->prefix($mydirname . "_log")));
     if (preg_match('/timestamp\\(/i', $create_string)) {
         $db->query("ALTER TABLE " . $db->prefix($mydirname . "_log") . " MODIFY `timestamp` DATETIME");
     }
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler =& icms::handler('icms_view_template_file');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     if (!icms_view_Tpl::template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     if (defined(ICMS_PRELOAD_PATH) && !file_exists(ICMS_PRELOAD_PATH . '/protector.php') && (!defined('PROTECTOR_POSTCHECK_INCLUDED') || !defined('PROTECTOR_PRECHECK_INCLUDED')) && function_exists('icms_copyr')) {
         icms_core_Filesystem::copyRecursive(ICMS_TRUST_PATH . '/modules/protector/patches/ImpressCMS1.1/preload_protector.php', ICMS_PRELOAD_PATH . '/protector.php');
     }
     icms_view_Tpl::template_clear_module_cache($mid);
     return true;
 }
Example #16
0
/**
 * Logic for uninstalling a module
 *
 * @todo	add installation_notify(), send status
 *
 * @param unknown_type $dirname
 * @return	string	Result messages for uninstallation
 */
function xoops_module_uninstall($dirname) {
	global $icmsConfig, $icmsAdminTpl;

	$reservedTables = array(
		'avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config',
		'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset',
		'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission',
		'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session',
		'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource',
		'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');

	$db =& icms_db_Factory::instance();
	$module_handler = icms::handler('icms_module');
	$module =& $module_handler->getByDirname($dirname);
	$module->registerClassPath();
	$icmsAdminTpl->template_clear_module_cache($module->getVar('mid'));
	if ($module->getVar('dirname') == 'system') {
		return "<p>" . sprintf(_MD_AM_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>")
		. "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_SYSNO . "</p>";
	} elseif ($module->getVar('dirname') == $icmsConfig['startpage']) {
		return "<p>" . sprintf(_MD_AM_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>")
		. "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO . "</p>";
	} else {
		$msgs = array();

		$member_handler = icms::handler('icms_member');
		$grps = $member_handler->getGroupList();
		foreach ($grps as $k => $v) {
			$stararr = explode('-', $icmsConfig['startpage'][$k]);
			if (count($stararr) > 0) {
				if ($module->getVar('mid') == $stararr[0]) {
					return "<p>" . sprintf(_MD_AM_FAILDEACT, "<strong>" . $module->getVar('name')
					. "</strong>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO
					. "</p>";
				}
			}
		}
		if (in_array($module->getVar('dirname'), $icmsConfig ['startpage'])) {
			return "<p>" . sprintf(_MD_AM_FAILDEACT, "<strong>" . $module->getVar('name') . "</strong>")
			. "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO . "</p>";
		}

		$page_handler = icms::handler('icms_data_page');
		$criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('page_moduleid', $module->getVar('mid')));
		$pages = $page_handler->getCount($criteria);

		if ($pages > 0) {
			$pages = $page_handler->getObjects($criteria);
			$msgs[] = _MD_AM_SYMLINKS_DELETE;
			foreach ($pages as $page) {
				if (!$page_handler->delete($page)) {
					$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_SYMLINK_DELETE_FAIL . '</span>',
					$page->getVar('page_title'),  '<strong>'. $page->getVar('page_id') . '</strong>');
				} else {
					$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_SYMLINK_DELETED,
						'<strong>' . $page->getVar('page_title') . '</strong>', '<strong>' . $page->getVar('page_id') . '</strong>');
				}
			}
		}

		if (!$module_handler->delete($module)) {
			$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_DELETE_FAIL . '</span>', $module->getVar('name'));
		} else {
			// delete template files
			$tplfile_handler = icms::handler('icms_view_template_file');
			$templates =& $tplfile_handler->find(NULL, 'module', $module->getVar('mid'));
			$tcount = count($templates);
			if ($tcount > 0) {
				$msgs[] = _MD_AM_TEMPLATES_DELETE;
				for ($i = 0; $i < $tcount; $i++) {
					if (!$tplfile_handler->delete($templates[$i])) {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_DELETE_FAIL . '</span>',
						$templates[$i]->getVar('tpl_file') , '<strong>' . icms_conv_nr2local($templates[$i]->getVar('tpl_id')) . '</strong>');
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_DELETED,
							'<strong>' . icms_conv_nr2local($templates[$i]->getVar('tpl_file')) . '</strong>',
							'<strong>' . icms_conv_nr2local($templates[$i]->getVar('tpl_id')) . '</strong>'
							);
					}
				}
			}
			unset($templates);

			// delete blocks and block template files
			$icms_block_handler = icms::handler('icms_view_block');
			$block_arr =& $icms_block_handler->getByModule($module->getVar('mid'));
			if (is_array($block_arr)) {
				$bcount = count($block_arr);
				$msgs[] = _MD_AM_BLOCKS_DELETE;
				for ($i = 0; $i < $bcount; $i++) {
					if (!$icms_block_handler->delete($block_arr[$i])) {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_BLOCK_DELETE_FAIL . '</span>',
							'<strong>' . $block_arr[$i]->getVar('name') . '</strong>',
							'<strong>' . icms_conv_nr2local($block_arr[$i]->getVar('bid')) . '</strong>'
							);
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_DELETED,
							'<strong>' . $block_arr[$i]->getVar('name')	. '</strong>',
							'<strong>' . icms_conv_nr2local($block_arr[$i]->getVar('bid')) . '</strong>'
							);
					}
					if ($block_arr[$i]->getVar('template') != '') {
						$templates =& $tplfile_handler->find(NULL, 'block', $block_arr[$i]->getVar('bid'));
						$btcount = count($templates);
						if ($btcount > 0) {
							for ($j = 0; $j < $btcount; $j++) {
								if (!$tplfile_handler->delete($templates[$j])) {
									$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_BLOCK_TMPLT_DELETE_FAILED . '</span>',
									$templates[$j]->getVar('tpl_file'),
										'<strong>' . icms_conv_nr2local($templates[$j]->getVar('tpl_id')) . '</strong>'
										);
								} else {
									$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_TMPLT_DELETED,
										'<strong>' . $templates[$j]->getVar('tpl_file') . '</strong>',
										'<strong>' . icms_conv_nr2local($templates[$j]->getVar('tpl_id')) . '</strong>'
										);
								}
							}
						}
						unset($templates);
					}
				}
			}

			// delete tables used by this module
			$modtables = $module->getInfo('tables');
			if ($modtables !== FALSE && is_array($modtables)) {
				$msgs[] = _MD_AM_MOD_TABLES_DELETE;
				foreach ($modtables as $table) {
					// prevent deletion of reserved core tables!
					if (!in_array($table, $reservedTables)) {
						$sql = 'DROP TABLE ' . $db->prefix($table);
						if (!$db->query($sql)) {
							$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_MOD_TABLE_DELETE_FAIL . '</span>',
								'<strong>'. $db->prefix($table) . '<strong> . '
								);
						} else {
							$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_MOD_TABLE_DELETED,
								'<strong>' . $db->prefix($table) . '</strong>'
								);
						}
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_MOD_TABLE_DELETE_NOTALLOWED . '</span>',
							'<strong>' . $db->prefix($table) . '</strong>'
							);
					}
				}
			}

			// delete comments if any
			if ($module->getVar('hascomments') != 0) {
				$msgs[] = _MD_AM_COMMENTS_DELETE;
				$comment_handler = icms::handler('icms_data_comment');
				if (!$comment_handler->deleteByModule($module->getVar('mid'))) {
					$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_COMMENT_DELETE_FAIL . '</span>';
				} else {
					$msgs[] = '&nbsp;&nbsp;' . _MD_AM_COMMENT_DELETED;
				}
			}

			// delete notifications if any
			if ($module->getVar('hasnotification') != 0) {
				$msgs[] = _MD_AM_NOTIFICATIONS_DELETE;
				if (!xoops_notification_deletebymodule($module->getVar('mid'))) {
					$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_NOTIFICATION_DELETE_FAIL .'</span>';
				} else {
					$msgs[] = '&nbsp;&nbsp;' . _MD_AM_NOTIFICATION_DELETED;
				}
			}

			// delete permissions if any
			$msgs[] = _MD_AM_GROUPPERM_DELETE;
			$gperm_handler = icms::handler('icms_member_groupperm');
			if (!$gperm_handler->deleteByModule($module->getVar('mid'))) {
				$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_GROUPPERM_DELETE_FAIL . '</span>';
			} else {
				$msgs[] = '&nbsp;&nbsp;' . _MD_AM_GROUPPERM_DELETED;
			}

			// delete module config options if any
			if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
				$config_handler = icms::handler('icms_config');
				$configs =& $config_handler->getConfigs(new icms_db_criteria_Item('conf_modid', $module->getVar('mid')));
				$confcount = count($configs);
				if ($confcount > 0) {
					$msgs[] = _MD_AM_CONFIGOPTIONS_DELETE;
					for ($i = 0; $i < $confcount; $i++) {
						if (!$config_handler->deleteConfig($configs[$i])) {
							$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_CONFIGOPTION_DELETE_FAIL .'</span>',
								'<strong>' . icms_conv_nr2local($configs[$i]->getvar('conf_id')) . '</strong>');
						} else {
							$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_CONFIGOPTION_DELETED,
								'<strong>' . icms_conv_nr2local($configs[$i]->getVar('conf_id')) . '</strong>');
						}
					}
				}
			}

			// delete autotasks
			$atasks = $module->getInfo('autotasks');
			if (isset($atasks) && is_array($atasks) && (count($atasks) > 0)) {
				$msgs[] = _MD_AM_AUTOTASKS_DELETE;
				$atasks_handler = &icms_getModuleHandler('autotasks', 'system');
				$criteria = new icms_db_criteria_Compo();
				$criteria->add(new icms_db_criteria_Item('sat_type', 'addon/' . $module->getInfo('dirname')));
				$atasks_handler->deleteAll($criteria);
				unset($atasks_handler, $criteria, $taskData);
			}
			unset($atasks);

			// delete urllinks
			$urllink_handler = icms::handler('icms_data_urllink');
			$urllink_handler->deleteAll(icms_buildCriteria(array("mid" => $module->getVar("mid"))));

			// delete files
			$file_handler = icms::handler('icms_data_file');
			$file_handler->deleteAll(icms_buildCriteria(array("mid" => $module->getVar("mid"))));

			// execute module specific install script if any
			$uninstall_script = $module->getInfo('onUninstall');
			$ModName = ($module->getInfo('modname') != '') ? trim($module->getInfo('modname')) : $dirname;
			if (FALSE !== $uninstall_script && trim($uninstall_script) != '') {
				include_once ICMS_MODULES_PATH . '/' . $dirname . '/' . trim($uninstall_script);
				if (function_exists('xoops_module_uninstall_' . $ModName)) {
					$func = 'xoops_module_uninstall_' . $ModName;
					if (!$func($module)) {
						$msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
					} else {
						$msgs[] = $module->messages;
						$msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
					}
				} elseif (function_exists('icms_module_uninstall_' . $ModName)) {
					$func = 'icms_module_uninstall_' . $ModName;
					if (!$func($module)) {
						$msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
					} else {
						$msgs[] = $module->messages;
						$msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
					}
				}
			}

			$msgs[] = '</code><p>' . sprintf(_MD_AM_OKUNINS, "<strong>" . $module->getVar('name') . "</strong>") . '</p>';
		}
		$ret = '<code>' . implode('<br />', $msgs);
		return $ret;
	}
}