/umil/root/umil/umil.php
PHP | 3027 lines | 2163 code | 365 blank | 499 comment | 274 complexity | 22f696eb80c3a9b853b942ab00dfaefe MD5 | raw file
Possible License(s): AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- *
- * @author Nathan Guse (EXreaction) http://lithiumstudios.org
- * @author David Lewis (Highway of Life) highwayoflife@gmail.com
- * @package umil
- * @version $Id$
- * @copyright (c) 2008 phpBB Group
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- *
- */
- /**
- * @ignore
- */
- if (!defined('IN_PHPBB'))
- {
- exit;
- }
- define('UMIL_VERSION', '1.0.3');
- /**
- * Multicall instructions
- *
- * With the "multicall" (as I am calling it) you can make a single function call and have it repeat the actions multiple times on information sent from an array.
- *
- * To do this (it does not work on the _exists functions), all you must do is send the first variable in the function call as an array and for each item, send an array for each of the variables in order.
- *
- * Example:
- * $umil->config_add(array(
- * array('config_name', 'config_value'),
- * array('config_name1', 'config_value1'),
- * array('config_name2', 'config_value2', true),
- * array('config_name3', 'config_value3', true),
- * );
- */
- /**
- * UMIL - Unified MOD Installation Library class
- *
- * Cache Functions
- * cache_purge($type = '', $style_id = 0)
- *
- * Config Functions:
- * config_exists($config_name, $return_result = false)
- * config_add($config_name, $config_value = '', $is_dynamic = false)
- * config_update($config_name, $config_value, $is_dynamic = false)
- * config_remove($config_name)
- *
- * Module Functions
- * module_exists($class, $parent, $module)
- * module_add($class, $parent = 0, $data = array())
- * module_remove($class, $parent = 0, $module = '')
- *
- * Permissions/Auth Functions
- * permission_exists($auth_option, $global = true)
- * permission_add($auth_option, $global = true)
- * permission_remove($auth_option, $global = true)
- * permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true)
- * permission_unset($name, $auth_option = array(), $type = 'role', $global = true)
- *
- * Table Functions
- * table_exists($table_name)
- * table_add($table_name, $table_data = array())
- * table_remove($table_name)
- *
- * Table Column Functions
- * table_column_exists($table_name, $column_name)
- * table_column_add($table_name, $column_name = '', $column_data = array())
- * table_column_update($table_name, $column_name = '', $column_data = array())
- * table_column_remove($table_name, $column_name = '')
- *
- * Table Key/Index Functions
- * table_index_exists($table_name, $index_name)
- * table_index_add($table_name, $index_name = '', $column = array())
- * table_index_remove($table_name, $index_name = '')
- *
- * Table Row Functions (note that these actions are not reversed automatically during uninstallation)
- * table_row_insert($table_name, $data = array())
- * table_row_remove($table_name, $data = array())
- * table_row_update($table_name, $data = array(), $new_data = array())
- *
- * Version Check Function
- * version_check($url, $path, $file)
- */
- class umil
- {
- /**
- * 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 umil($stand_alone = false, $db = false)
- {
- // 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('phpbb_db_tools'))
- {
- global $phpbb_root_path, $phpEx;
- include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
- }
- $this->db_tools = new phpbb_db_tools($this->db);
- $this->stand_alone = $stand_alone;
- if (!$stand_alone)
- {
- global $config, $user, $phpbb_root_path, $phpEx;
- /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed.
- if (method_exists('user', 'set_custom_lang_path'))
- {
- $user->set_custom_lang_path($phpbb_root_path . 'umil/language/');
- $user->add_lang('umil');
- $user->set_custom_lang_path($phpbb_root_path . 'language/');
- }
- else
- {*/
- // Include the umil language file. 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.
- if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx"))
- {
- $path = $user->data['user_lang'];
- }
- else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx"))
- {
- $path = basename($config['default_lang']);
- }
- else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx"))
- {
- $path = 'en';
- }
- else
- {
- trigger_error('Language Files Missing.<br /><br />Please download the latest UMIL (Unified MOD Install Library) from: <a href="http://www.phpbb.com/mods/umil/">phpBB.com/mods/umil</a>', E_USER_ERROR);
- }
- $user->add_lang('./../../umil/language/' . $path . '/umil');
- //}
- $user->add_lang(array('acp/common', 'acp/permissions'));
- // Check to see if a newer version is available.
- $info = $this->version_check('www.phpbb.com', '/updatecheck', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt'));
- if (is_array($info) && isset($info[0]) && isset($info[1]))
- {
- if (version_compare(UMIL_VERSION, $info[0], '<'))
- {
- global $template;
- // Make sure user->setup() has been called
- if (empty($user->lang))
- {
- $user->setup();
- }
- page_header('', false);
- $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.<br /><br />Please download the latest UMIL (Unified MOD Install Library) from: <a href="%1$s">%1$s</a>';
- $template->assign_vars(array(
- 'S_BOARD_DISABLED' => true,
- 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]),
- ));
- }
- }
- }
- }
- /**
- * umil_start
- *
- * A function which runs (almost) every time a function here is ran
- */
- function umil_start()
- {
- global $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($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS';
- $this->db->sql_return_on_error(true);
- //$this->db->sql_transaction('begin');
- }
- /**
- * umil_end
- *
- * A function which runs (almost) every time a function here is ran
- */
- function umil_end()
- {
- global $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($user->lang['SUCCESS'])) ? $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;
- }
- /**
- * Get text for output
- *
- * Takes the given arguments and prepares them for the UI
- *
- * First argument sent is used as the language key
- * Further arguments (if send) are used on the language key through vsprintf()
- *
- * @return string Returns the prepared string for output
- */
- function get_output_text()
- {
- global $user;
- // Set up the command. This will get the arguments sent to the function.
- $args = func_get_args();
- if (sizeof($args))
- {
- $lang_key = array_shift($args);
- if (sizeof($args))
- {
- $lang_args = array();
- foreach ($args as $arg)
- {
- $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg;
- }
- return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args);
- }
- else
- {
- return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key);
- }
- }
- return '';
- }
- /**
- * Run Actions
- *
- * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions.
- *
- * @param string $action The action. install|update|uninstall
- * @param array $versions The array of versions and the actions for each
- * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version
- * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to.
- */
- function run_actions($action, $versions, $version_config_name, $version_select = '')
- {
- // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers
- uksort($versions, 'version_compare');
- // Find the current version to install
- $current_version = '0.0.0';
- foreach ($versions as $version => $actions)
- {
- $current_version = $version;
- }
- $db_version = '';
- if ($this->config_exists($version_config_name))
- {
- global $config;
- $db_version = $config[$version_config_name];
- }
- // Set the action to install from update if nothing is currently installed
- if ($action == 'update' && !$db_version)
- {
- $action = 'install';
- }
- if ($action == 'install' || $action == 'update')
- {
- $version_installed = $db_version;
- foreach ($versions as $version => $version_actions)
- {
- // If we are updating
- if ($db_version && version_compare($version, $db_version, '<='))
- {
- continue;
- }
- if ($version_select && version_compare($version, $version_select, '>'))
- {
- break;
- }
- foreach ($version_actions as $method => $params)
- {
- if ($method == 'custom')
- {
- $this->_call_custom_function($params, $action, $version);
- }
- else
- {
- if (method_exists($this, $method))
- {
- call_user_func(array($this, $method), $params);
- }
- }
- }
- $version_installed = $version;
- }
- // update the version number or add it
- if ($this->config_exists($version_config_name))
- {
- $this->config_update($version_config_name, $version_installed);
- }
- else
- {
- $this->config_add($version_config_name, $version_installed);
- }
- }
- else if ($action == 'uninstall' && $db_version)
- {
- // reverse version list
- $versions = array_reverse($versions);
- foreach ($versions as $version => $version_actions)
- {
- // Uninstalling and this listed version is newer than installed
- if (version_compare($version, $db_version, '>'))
- {
- continue;
- }
- // Version selection stuff
- if ($version_select && version_compare($version, $version_select, '<='))
- {
- // update the version number
- $this->config_update($version_config_name, $version);
- break;
- }
- $cache_purge = false;
- $version_actions = array_reverse($version_actions);
- foreach ($version_actions as $method => $params)
- {
- if ($method == 'custom')
- {
- $this->_call_custom_function($params, $action, $version);
- }
- else
- {
- // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end).
- if ($method == 'cache_purge')
- {
- $cache_purge = $params;
- continue;
- }
- // A few things are not possible for uninstallations update actions and table_row actions
- if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false)
- {
- continue;
- }
- // reverse function call
- $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method);
- $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method);
- if (method_exists($this, $method))
- {
- call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params)));
- }
- }
- }
- if ($cache_purge !== false)
- {
- $this->cache_purge($cache_purge);
- }
- }
- if (!$version_select)
- {
- // Unset the version number
- $this->config_remove($version_config_name);
- }
- }
- }
- /**
- * Call custom function helper
- */
- function _call_custom_function($functions, $action, $version)
- {
- if (!is_array($functions))
- {
- $functions = array($functions);
- }
- $return = '';
- foreach ($functions as $function)
- {
- if (function_exists($function))
- {
- // Must reset before calling the function
- $this->umil_start();
- $returned = call_user_func($function, $action, $version);
- if (is_string($returned))
- {
- $this->command = $this->get_output_text($returned);
- }
- else if (is_array($returned) && isset($returned['command']))
- {
- if (is_array($returned['command']))
- {
- $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']);
- }
- else
- {
- $this->command = $this->get_output_text($returned['command']);
- }
- if (isset($returned['result']))
- {
- $this->result = $this->get_output_text($returned['result']);
- }
- }
- else
- {
- $this->command = $this->get_output_text('UNKNOWN');
- }
- $return .= $this->umil_end() . '<br />';
- }
- }
- return $return;
- }
- /**
- * Multicall Helper
- *
- * @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;
- }
- /**
- * Cache Purge
- *
- * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache.
- *
- * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache.
- * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section)
- */
- function cache_purge($type = '', $style_id = 0)
- {
- global $auth, $cache, $user, $phpbb_root_path, $phpEx;
- // Multicall
- if ($this->multicall(__FUNCTION__, $type))
- {
- return;
- }
- $style_id = (int) $style_id;
- $type = (string) $type; // Prevent PHP bug.
- switch ($type)
- {
- case 'auth' :
- $this->umil_start('AUTH_CACHE_PURGE');
- $cache->destroy('_acl_options');
- $auth->acl_clear_prefetch();
- return $this->umil_end();
- break;
- case 'imageset' :
- if ($style_id == 0)
- {
- $return = array();
- $sql = 'SELECT imageset_id
- FROM ' . STYLES_IMAGESET_TABLE;
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $return[] = $this->cache_purge('imageset', $row['imageset_id']);
- }
- $this->db->sql_freeresult($result);
- return implode('<br /><br />', $return);
- }
- else
- {
- $sql = 'SELECT *
- FROM ' . STYLES_IMAGESET_TABLE . "
- WHERE imageset_id = $style_id";
- $result = $this->db->sql_query($sql);
- $imageset_row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if (!$imageset_row)
- {
- $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
- $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']);
- // The following is from includes/acp/acp_styles.php (edited)
- $sql_ary = array();
- $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg");
- $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
- WHERE imageset_id = ' . $style_id;
- $result = $this->db->sql_query($sql);
- foreach ($cfg_data_imageset as $image_name => $value)
- {
- if (strpos($value, '*') !== false)
- {
- if (substr($value, -1, 1) === '*')
- {
- list($image_filename, $image_height) = explode('*', $value);
- $image_width = 0;
- }
- else
- {
- list($image_filename, $image_height, $image_width) = explode('*', $value);
- }
- }
- else
- {
- $image_filename = $value;
- $image_height = $image_width = 0;
- }
- if (strpos($image_name, 'img_') === 0 && $image_filename)
- {
- $image_name = substr($image_name, 4);
- $sql_ary[] = array(
- 'image_name' => (string) $image_name,
- 'image_filename' => (string) $image_filename,
- 'image_height' => (int) $image_height,
- 'image_width' => (int) $image_width,
- 'imageset_id' => (int) $style_id,
- 'image_lang' => '',
- );
- }
- }
- $sql = 'SELECT lang_dir
- FROM ' . LANG_TABLE;
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"))
- {
- $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg");
- foreach ($cfg_data_imageset_data as $image_name => $value)
- {
- if (strpos($value, '*') !== false)
- {
- if (substr($value, -1, 1) === '*')
- {
- list($image_filename, $image_height) = explode('*', $value);
- $image_width = 0;
- }
- else
- {
- list($image_filename, $image_height, $image_width) = explode('*', $value);
- }
- }
- else
- {
- $image_filename = $value;
- $image_height = $image_width = 0;
- }
- if (strpos($image_name, 'img_') === 0 && $image_filename)
- {
- $image_name = substr($image_name, 4);
- $sql_ary[] = array(
- 'image_name' => (string) $image_name,
- 'image_filename' => (string) $image_filename,
- 'image_height' => (int) $image_height,
- 'image_width' => (int) $image_width,
- 'imageset_id' => (int) $style_id,
- 'image_lang' => (string) $row['lang_dir'],
- );
- }
- }
- }
- }
- $this->db->sql_freeresult($result);
- $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
- $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
- return $this->umil_end();
- }
- break;
- //case 'imageset' :
- case 'template' :
- if ($style_id == 0)
- {
- $return = array();
- $sql = 'SELECT template_id
- FROM ' . STYLES_TEMPLATE_TABLE;
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $return[] = $this->cache_purge('template', $row['template_id']);
- }
- $this->db->sql_freeresult($result);
- return implode('<br /><br />', $return);
- }
- else
- {
- $sql = 'SELECT *
- FROM ' . STYLES_TEMPLATE_TABLE . "
- WHERE template_id = $style_id";
- $result = $this->db->sql_query($sql);
- $template_row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if (!$template_row)
- {
- $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
- $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']);
- // The following is from includes/acp/acp_styles.php
- if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/"))
- {
- $filelist = array('' => array());
- $sql = 'SELECT template_filename, template_mtime
- FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
- WHERE template_id = $style_id";
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- // if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime'])
- // {
- // get folder info from the filename
- if (($slash_pos = strrpos($row['template_filename'], '/')) === false)
- {
- $filelist[''][] = $row['template_filename'];
- }
- else
- {
- $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1);
- }
- // }
- }
- $this->db->sql_freeresult($result);
- $includes = array();
- foreach ($filelist as $pathfile => $file_ary)
- {
- foreach ($file_ary as $file)
- {
- if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r')))
- {
- return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file");
- }
- $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"));
- fclose($fp);
- if (preg_match_all('#<!-- INCLUDE (.*?\.html) -->#is', $template_data, $matches))
- {
- foreach ($matches[1] as $match)
- {
- $includes[trim($match)][] = $file;
- }
- }
- }
- }
- foreach ($filelist as $pathfile => $file_ary)
- {
- foreach ($file_ary as $file)
- {
- // Skip index.
- if (strpos($file, 'index.') === 0)
- {
- continue;
- }
- // We could do this using extended inserts ... but that could be one
- // heck of a lot of data ...
- $sql_ary = array(
- 'template_id' => (int) $style_id,
- 'template_filename' => "$pathfile$file",
- 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '',
- 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"),
- 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"),
- );
- $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "
- WHERE template_id = $style_id
- AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'";
- $this->db->sql_query($sql);
- }
- }
- unset($filelist);
- }
- // Purge the forum's cache as well.
- $cache->purge();
- return $this->umil_end();
- }
- break;
- //case 'template' :
- case 'theme' :
- if ($style_id == 0)
- {
- $return = array();
- $sql = 'SELECT theme_id
- FROM ' . STYLES_THEME_TABLE;
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $return[] = $this->cache_purge('theme', $row['theme_id']);
- }
- $this->db->sql_freeresult($result);
- return implode('<br /><br />', $return);
- }
- else
- {
- $sql = 'SELECT *
- FROM ' . STYLES_THEME_TABLE . "
- WHERE theme_id = $style_id";
- $result = $this->db->sql_query($sql);
- $theme_row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if (!$theme_row)
- {
- $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
- $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']);
- // The following is from includes/acp/acp_styles.php
- if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"))
- {
- $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css');
- // Match CSS imports
- $matches = array();
- preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches);
- if (sizeof($matches))
- {
- foreach ($matches[0] as $idx => $match)
- {
- if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}"))
- {
- continue;
- }
- $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}"));
- $stylesheet = str_replace($match, $content, $stylesheet);
- }
- }
- // adjust paths
- $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet);
- // Save CSS contents
- $sql_ary = array(
- 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"),
- 'theme_data' => $db_theme_data,
- );
- $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "
- WHERE theme_id = $style_id";
- $this->db->sql_query($sql);
- $cache->destroy('sql', STYLES_THEME_TABLE);
- }
- return $this->umil_end();
- }
- break;
- //case 'theme' :
- default:
- $this->umil_start('CACHE_PURGE');
- $cache->purge();
- return $this->umil_end();
- break;
- }
- }
- /**
- * Config Exists
- *
- * This function is to check to see if a config variable exists or if it does not.
- *
- * @param string $config_name The name of the config setting you wish to check for.
- * @param bool $return_result - return the config value/default if true : default false.
- *
- * @return bool true/false if config exists
- */
- function config_exists($config_name, $return_result = false)
- {
- global $config, $cache;
- $sql = 'SELECT *
- FROM ' . CONFIG_TABLE . "
- WHERE config_name = '" . $this->db->sql_escape($config_name) . "'";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if ($row)
- {
- if (!isset($config[$config_name]))
- {
- $config[$config_name] = $row['config_value'];
- if (!$row['is_dynamic'])
- {
- $cache->destroy('config');
- }
- }
- return ($return_result) ? $row : true;
- }
- // this should never happen, but if it does, we need to remove the config from the array
- if (isset($config[$config_name]))
- {
- unset($config[$config_name]);
- $cache->destroy('config');
- }
- return false;
- }
- /**
- * Config Add
- *
- * This function allows you to add a config setting.
- *
- * @param string $config_name The name of the config setting you would like to add
- * @param mixed $config_value The value of the config setting
- * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not.
- *
- * @return result
- */
- function config_add($config_name, $config_value = '', $is_dynamic = false)
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $config_name))
- {
- return;
- }
- $this->umil_start('CONFIG_ADD', $config_name);
- if ($this->config_exists($config_name))
- {
- return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name);
- }
- set_config($config_name, $config_value, $is_dynamic);
- return $this->umil_end();
- }
- /**
- * Config Update
- *
- * This function allows you to update an existing config setting.
- *
- * @param string $config_name The name of the config setting you would like to update
- * @param mixed $config_value The value of the config setting
- * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not.
- *
- * @return result
- */
- function config_update($config_name, $config_value = '', $is_dynamic = false)
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $config_name))
- {
- return;
- }
- $this->umil_start('CONFIG_UPDATE', $config_name);
- if (!$this->config_exists($config_name))
- {
- return $this->umil_end('CONFIG_NOT_EXIST', $config_name);
- }
- set_config($config_name, $config_value, $is_dynamic);
- return $this->umil_end();
- }
- /**
- * Config Remove
- *
- * This function allows you to remove an existing config setting.
- *
- * @param string $config_name The name of the config setting you would like to remove
- *
- * @return result
- */
- function config_remove($config_name)
- {
- global $cache, $config;
- // Multicall
- if ($this->multicall(__FUNCTION__, $config_name))
- {
- return;
- }
- $this->umil_start('CONFIG_REMOVE', $config_name);
- if (!$this->config_exists($config_name))
- {
- return $this->umil_end('CONFIG_NOT_EXIST', $config_name);
- }
- $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'";
- $this->db->sql_query($sql);
- unset($config[$config_name]);
- $cache->destroy('config');
- return $this->umil_end();
- }
- /**
- * Module Exists
- *
- * Check if a module exists
- *
- * @param string $class The module class(acp|mcp|ucp)
- * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide.
- * @param int|string $module The module_id|module_langname you would like to check for to see if it exists
- */
- function module_exists($class, $parent, $module)
- {
- // the main root directory should return true
- if (!$module)
- {
- return true;
- }
- $class = $this->db->sql_escape($class);
- $module = $this->db->sql_escape($module);
- $parent_sql = '';
- if ($parent !== false)
- {
- // Allows '' to be sent as 0
- $parent = (!$parent) ? 0 : $parent;
- if (!is_numeric($parent))
- {
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
- AND module_class = '$class'";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if (!$row)
- {
- return false;
- }
- $parent_sql = 'AND parent_id = ' . (int) $row['module_id'];
- }
- else
- {
- $parent_sql = 'AND parent_id = ' . (int) $parent;
- }
- }
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_class = '$class'
- $parent_sql
- AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'");
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if ($row)
- {
- return true;
- }
- return false;
- }
- /**
- * Module Add
- *
- * Add a new module
- *
- * @param string $class The module class(acp|mcp|ucp)
- * @param int|string $parent The parent module_id|module_langname (0 for no parent)
- * @param array $data an array of the data on the new module. This can be setup in two different ways.
- * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below,
- * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode.
- * array(
- * 'module_enabled' => 1,
- * 'module_display' => 1,
- * 'module_basename' => '',
- * 'module_class' => $class,
- * 'parent_id' => (int) $parent,
- * 'module_langname' => '',
- * 'module_mode' => '',
- * 'module_auth' => '',
- * )
- * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file.
- * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file):
- * array(
- * 'module_basename' => 'asacp',
- * 'modes' => array('settings', 'log', 'flag'),
- * )
- * Optionally you may not send 'modes' and it will insert all of the modules in that info file.
- * @param string|bool $include_path If you would like to use a custom include path, specify that here
- */
- function module_add($class, $parent = 0, $data = array(), $include_path = false)
- {
- global $cache, $user, $phpbb_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->umil_start('MODULE_ADD', $class, 'UNKNOWN');
- return $this->umil_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) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file))
- {
- $this->umil_start('MODULE_ADD', $class, $info_file);
- return $this->umil_end('FAIL');
- }
- $classname = "{$class}_{$basename}_info";
- if (!class_exists($classname))
- {
- include((($include_path === false) ? $phpbb_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 $result;
- }
- // The "manual" way
- $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname']));
- add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname']));
- $class = $this->db->sql_escape($class);
- if (!is_numeric($parent))
- {
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
- AND module_class = '$class'";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if (!$row)
- {
- return $this->umil_end('PARENT_NOT_EXIST');
- }
- $parent = $data['parent_id'] = $row['module_id'];
- }
- else if (!$this->module_exists($class, false, $parent))
- {
- return $this->umil_end('PARENT_NOT_EXIST');
- }
- if ($this->module_exists($class, $parent, $data['module_langname']))
- {
- return $this->umil_end('MODULE_ALREADY_EXIST');
- }
- if (!class_exists('acp_modules'))
- {
- include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
- $user->add_lang('acp/modules');
- }
- $acp_modules = new acp_modules();
- $module_data = array(
- 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1,
- 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1,
- 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '',
- 'module_class' => $class,
- 'parent_id' => (int) $parent,
- 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '',
- 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '',
- 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '',
- );
- $result = $acp_modules->update_module_data($module_data, true);
- // update_module_data can either return a string or an empty array...
- if (is_string($result))
- {
- // Error
- $this->result = $this->get_output_text($result);
- }
- else
- {
- // Success
- // Move the module if requested above/below an existing one
- if (isset($data['before']) && $data['before'])
- {
- $sql = 'SELECT left_id FROM ' . MODULES_TABLE . '
- WHERE module_class = \'' . $class . '\'
- AND parent_id = ' . (int) $parent . '
- AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\'';
- $this->db->sql_query($sql);
- $to_left = $this->db->sql_fetchfield('left_id');
- $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2
- WHERE module_class = '$class'
- AND left_id >= $to_left
- AND left_id < {$module_data['left_id']}";
- $this->db->sql_query($sql);
- $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . "
- WHERE module_class = '$class'
- AND module_id = {$module_data['module_id']}";
- $this->db->sql_query($sql);
- }
- else if (isset($data['after']) && $data['after'])
- {
- $sql = 'SELECT right_id FROM ' . MODULES_TABLE . '
- WHERE module_class = \'' . $class . '\'
- AND parent_id = ' . (int) $parent . '
- AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\'';
- $this->db->sql_query($sql);
- $to_right = $this->db->sql_fetchfield('right_id');
- $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2
- WHERE module_class = '$class'
- AND left_id >= $to_right
- AND left_id < {$module_data['left_id']}";
- $this->db->sql_query($sql);
- $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . "
- WHERE module_class = '$class'
- AND module_id = {$module_data['module_id']}";
- $this->db->sql_query($sql);
- }
- }
- // Clear the Modules Cache
- $cache->destroy("_modules_$class");
- return $this->umil_end();
- }
- /**
- * Module Remove
- *
- * Remove a module
- *
- * @param string $class The module class(acp|mcp|ucp)
- * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide.
- * @param int|string $module The module id|module_langname
- * @param string|bool $include_path If you would like to use a custom include path, specify that here
- */
- function module_remove($class, $parent = 0, $module = '', $include_path = false)
- {
- global $cache, $user, $phpbb_root_path, $phpEx;
- // Multicall
- if ($this->multicall(__FUNCTION__, $class))
- {
- return;
- }
- // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto
- if (is_array($module))
- {
- if (isset($module['module_langname']))
- {
- // Manual Method
- return $this->module_remove($class, $parent, $module['module_langname'], $include_path);
- }
- // Failed.
- if (!isset($module['module_basename']))
- {
- $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
- // Automatic method
- $basename = str_replace(array('/', '\\'), '', $module['module_basename']);
- $class = str_replace(array('/', '\\'), '', $class);
- $info_file = "$class/info/{$class}_$basename.$phpEx";
- if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file))
- {
- $this->umil_start('MODULE_REMOVE', $class, $info_file);
- return $this->umil_end('FAIL');
- }
- $classname = "{$class}_{$basename}_info";
- if (!class_exists($classname))
- {
- include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file);
- }
- $info = new $classname;
- $module_info = $info->module();
- unset($info);
- $result = '';
- foreach ($module_info['modes'] as $mode => $info)
- {
- if (!isset($module['modes']) || in_array($mode, $module['modes']))
- {
- $result .= $this->module_remove($class, $parent, $info['title']) . '<br />';
- }
- }
- return $result;
- }
- else
- {
- $class = $this->db->sql_escape($class);
- if (!$this->module_exists($class, $parent, $module))
- {
- $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module));
- return $this->umil_end('MODULE_NOT_EXIST');
- }
- $parent_sql = '';
- if ($parent !== false)
- {
- // Allows '' to be sent as 0
- $parent = (!$parent) ? 0 : $parent;
- if (!is_numeric($parent))
- {
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
- AND module_class = '$class'";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- // we know it exists from the module_exists check
- $parent_sql = 'AND parent_id = ' . (int) $row['module_id'];
- }
- else
- {
- $parent_sql = 'AND parent_id = ' . (int) $parent;
- }
- }
- $module_ids = array();
- if (!is_numeric($module))
- {
- $module = $this->db->sql_escape($module);
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_langname = '$module'
- AND module_class = '$class'
- $parent_sql";
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $module_ids[] = (int) $row['module_id'];
- }
- $this->db->sql_freeresult($result);
- $module_name = $module;
- }
- else
- {
- $module = (int) $module;
- $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . "
- WHERE module_id = $module
- AND module_class = '$class'
- $parent_sql";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- $module_name = $row['module_langname'];
- $module_ids[] = $module;
- }
- $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name));
- add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name));
- if (!class_exists('acp_modules'))
- {
- include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
- $user->add_lang('acp/modules');
- }
- $acp_modules = new acp_modules();
- $acp_modules->module_class = $class;
- foreach ($module_ids as $module_id)
- {
- $result = $acp_modules->delete_module($module_id);
- if (!empty($result))
- {
- if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'))
- {
- $this->result = implode('<br />', $result);
- }
- else
- {
- $this->result .= '<br />' . implode('<br />', $result);
- }
- }
- }
- $cache->destroy("_modules_$class");
- return $this->umil_end();
- }
- }
- /**
- * Permission Exists
- *
- * Check if a permission (auth) setting exists
- *
- * @param string $auth_option The name of the permission (auth) option
- * @param bool $global True for checking a global permission setting, False for a local permission setting
- *
- * @return bool true if it exists, false if not
- */
- function permission_exists($auth_option, $global = true)
- {
- if ($global)
- {
- $type_sql = ' AND is_global = 1';
- }
- else
- {
- $type_sql = ' AND is_local = 1';
- }
- $sql = 'SELECT auth_option_id
- FROM ' . ACL_OPTIONS_TABLE . "
- WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'"
- . $type_sql;
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if ($row)
- {
- return true;
- }
- return false;
- }
- /**
- * Permission Add
- *
- * Add a permission (auth) option
- *
- * @param string $auth_option The name of the permission (auth) option
- * @param bool $global True for checking a global permission setting, False for a local permission setting
- *
- * @return result
- */
- function permission_add($auth_option, $global = true)
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $auth_option))
- {
- return;
- }
- $this->umil_start('PERMISSION_ADD', $auth_option);
- if ($this->permission_exists($auth_option, $global))
- {
- return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option);
- }
- // We've added permissions, so set to true to notify the user.
- $this->permissions_added = true;
- if (!class_exists('auth_admin'))
- {
- global $phpbb_root_path, $phpEx;
- include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
- }
- $auth_admin = new auth_admin();
- // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here.
- if ($this->permission_exists($auth_option, !$global))
- {
- $sql_ary = array(
- 'is_global' => 1,
- 'is_local' => 1,
- );
- $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
- SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
- WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'";
- $this->db->sql_query($sql);
- }
- else
- {
- if ($global)
- {
- $auth_admin->acl_add_option(array('global' => array($auth_option)));
- }
- else
- {
- $auth_admin->acl_add_option(array('local' => array($auth_option)));
- }
- }
- return $this->umil_end();
- }
- /**
- * Permission Remove
- *
- * Remove a permission (auth) option
- *
- * @param string $auth_option The name of the permission (auth) option
- * @param bool $global True for checking a global permission setting, False for a local permission setting
- *
- * @return result
- */
- function permission_remove($auth_option, $global = true)
- {
- global $auth, $cache;
- // Multicall
- if ($this->multicall(__FUNCTION__, $auth_option))
- {
- return;
- }
- $this->umil_start('PERMISSION_REMOVE', $auth_option);
- if (!$this->permission_exists($auth_option, $global))
- {
- return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option);
- }
- if ($global)
- {
- $type_sql = ' AND is_global = 1';
- }
- else
- {
- $type_sql = ' AND is_local = 1';
- }
- $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . "
- WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" .
- $type_sql;
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- $id = $row['auth_option_id'];
- // If it is a local and global permission, do not remove the row! :P
- if ($row['is_global'] && $row['is_local'])
- {
- $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
- SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . '
- WHERE auth_option_id = ' . $id;
- $this->db->sql_query($sql);
- }
- else
- {
- // Delete time
- $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id);
- $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id);
- $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id);
- $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id);
- }
- // Purge the auth cache
- $cache->destroy('_acl_options');
- $auth->acl_clear_prefetch();
- return $this->umil_end();
- }
- /**
- * Add a new permission role
- *
- * @param string $role_name The new role name
- * @param sting $role_type The type (u_, m_, a_)
- */
- function permission_role_add($role_name, $role_type = '', $role_description = '')
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $role_name))
- {
- return;
- }
- $this->umil_start('PERMISSION_ROLE_ADD', $role_name);
- $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . '
- WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\'';
- $this->db->sql_query($sql);
- $role_id = $this->db->sql_fetchfield('role_id');
- if ($role_id)
- {
- return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name);
- }
- $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . '
- WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\'';
- $this->db->sql_query($sql);
- $role_order = $this->db->sql_fetchfield('max');
- $role_order = (!$role_order) ? 1 : $role_order + 1;
- $sql_ary = array(
- 'role_name' => $role_name,
- 'role_description' => $role_description,
- 'role_type' => $role_type,
- 'role_order' => $role_order,
- );
- $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
- $this->db->sql_query($s…
Large files files are truncated, but you can click here to view the full file