|
From: Florin C B. <ory...@us...> - 2013-06-23 21:46:52
|
Update of /cvsroot/mxbb/core/includes In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv6571 Modified Files: mx_functions_admincp.php Log Message: Index: mx_functions_admincp.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions_admincp.php,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** mx_functions_admincp.php 27 Jul 2011 19:44:58 -0000 1.68 --- mx_functions_admincp.php 23 Jun 2013 21:46:49 -0000 1.69 *************** *** 82,85 **** --- 82,170 ---- class mx_admin { + /** + * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) + * + * @var string + */ + var $command = ''; + + /** + * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. + * + * @var string + */ + var $result = ''; + + /** + * Auto run $this->display_results after running a command + */ + var $auto_display_results = false; + + /** + * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff + */ + var $stand_alone = false; + + /** + * Were any new permissions added (used in umil_frontend)? + */ + var $permissions_added = false; + + /** + * Database Object + */ + var $db = false; + + /** + * Database Tools Object + */ + var $db_tools = false; + + /** + * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... + */ + var $table_prefix = false; + + /**#@-*/ + + /** + * Constructor + */ + function mx_admin($stand_alone = true, $db = true) + { + // Setup $this->db + if ($db !== false) + { + if (!is_object($db) || !method_exists($db, 'sql_query')) + { + trigger_error('Invalid $db Object'); + } + + $this->db = $db; + } + else + { + global $db; + $this->db = $db; + } + + // Setup $this->db_tools + if (!class_exists('mx_db_tools')) + { + global $mx_root_path, $phpEx; + include($mx_root_path . 'includes/db/db_tools.' . $phpEx); + } + $this->db_tools = new mx_db_tools($this->db); + + $this->stand_alone = $stand_alone; + + if (!$stand_alone) + { + global $portal_config, $mx_user, $mx_root_path, $phpEx; + // Include the language keys. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. + //todo@ Dont foget to add any lang keys required to lang_admin.php + } + } + // ------------------------------ // Private Methods *************** *** 3532,3535 **** --- 3617,3809 ---- } } + /** + * _start from umil_start + * + * A function which runs (almost) every time a function here is ran + */ + function _start() + { + global $mx_user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + $this->command = call_user_func_array(array($this, 'get_output_text'), $args); + + $this->result = (isset($mx_user->lang['SUCCESS'])) ? $mx_user->lang['SUCCESS'] : 'SUCCESS'; + $this->db->sql_return_on_error(true); + + //$this->db->sql_transaction('begin'); + } + + /** + * _end from umil_end + * + * A function which runs (almost) every time a function here is ran + */ + function _end() + { + global $mx_user; + + // Set up the result. This will get the arguments sent to the function. + $args = func_get_args(); + $result = call_user_func_array(array($this, 'get_output_text'), $args); + $this->result = ($result) ? $result : $this->result; + + if ($this->db->sql_error_triggered) + { + if ($this->result == ((isset($mx_user->lang['SUCCESS'])) ? $mx_user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; + } + else + { + $this->result .= '<br /><br />SQL ERROR ' . $this->db->sql_error_returned['message']; + } + + //$this->db->sql_transaction('rollback'); + } + else + { + //$this->db->sql_transaction('commit'); + } + + $this->db->sql_return_on_error(false); + + // Auto output if requested. + if ($this->auto_display_results && method_exists($this, 'display_results')) + { + $this->display_results(); + } + + return '<strong>' . $this->command . '</strong><br />' . $this->result; + } + + /** + * Multicall Helper from umil + * + * @param mixed $function Function name to call + * @param mixed $params The parameters array + * + * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) + */ + function multicall($function, $params) + { + if (is_array($params) && !empty($params)) + { + foreach ($params as $param) + { + if (!is_array($param)) + { + call_user_func(array($this, $function), $param); + } + else + { + call_user_func_array(array($this, $function), $param); + } + } + return true; + } + + return false; + } + + /** + * Enter description here... + * from umil module_add() + * @access public + * @param unknown_type $module_id + */ + function module_select($class, $parent = 0, $data = array(), $include_path = false) + { + global $mx_cache, $mx_user, $mx_root_path, $module_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Prevent stupid things like trying to add a module with no name or any data on it + if (empty($data)) + { + $this->_start('MODULE_ADD', $class, 'UNKNOWN'); + return $this->_end('FAIL'); + } + + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $module_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->_start('MODULE_ADD', $class, $info_file); + return $this->_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $module_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + //$result .= ((isset($data['spacer'])) ? $data['spacer'] : '<br />') . $this->module_add($class, $parent, $new_module); + return $new_module; + } + } + + //return $result; + } + + // The "manual" way + //$this->_start('MODULE_ADD', $class, ((isset($mx_user->lang[$data['module_langname']])) ? $mx_user->lang[$data['module_langname']] : $data['module_langname'])); + //add_log('admin', 'LOG_MODULE_ADD', ((isset($mx_user->lang[$data['module_langname']])) ? $mx_user->lang[$data['module_langname']] : $data['module_langname'])); + + $new_module = array( + 'module_basename' => $data['module_basename'], + 'module_langname' => $data['module_langname'], + 'module_mode' => $data['module_mode'], + 'module_auth' => $data['module_auth'], + 'module_display' => (isset($data['display'])) ? $data['display'] : true, + 'before' => (isset($data['before'])) ? $data['before'] : false, + 'after' => (isset($data['after'])) ? $data['after'] : false, + ); + + return $new_module; + } } // class mx_admin *************** *** 3563,3568 **** var $modules = array(); var $moduleFunctions = array(); ! var $functionBlocks = array(); ! /**#@-*/ // ------------------------------ --- 3837,3841 ---- var $modules = array(); var $moduleFunctions = array(); ! var $functionBlocks = array(); // ------------------------------ *************** *** 3948,3952 **** $this->_get_data($all_functions); $this->_generate_tpl($block_id); ! } } --- 4221,4225 ---- $this->_get_data($all_functions); $this->_generate_tpl($block_id); ! } } |