/**
  * Run SQL files
  * 
  * @access	public
  * @param	int
  */
 public function _importTemplates()
 {
     $templates = array();
     $this->DB->build(array('select' => '*', 'from' => 'ccs_template_blocks'));
     $outer = $this->DB->execute();
     while ($r = $this->DB->fetch($outer)) {
         if (!preg_match("/_(\\d+)\$/", $r['tpb_name'])) {
             $templates[$r['tpb_name']] = $r;
         }
     }
     $content = file_get_contents(IPSLib::getAppDir('ccs') . '/xml/block_templates.xml');
     require_once IPS_KERNEL_PATH . 'classXML.php';
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     foreach ($xml->fetchElements('template') as $template) {
         $_template = $xml->fetchElementsFromRecord($template);
         if ($_template['tpb_name']) {
             unset($_template['tpb_id']);
             if (array_key_exists($_template['tpb_name'], $templates)) {
                 $this->DB->update("ccs_template_blocks", $_template, "tpb_id={$templates[$_template['tpb_name']]['tpb_id']}");
             } else {
                 $this->DB->insert("ccs_template_blocks", $_template);
             }
         }
     }
 }
 /**
  * Now we get to import the default site.  Fun!
  *
  * @access	protected
  * @return	void
  */
 protected function _importSite()
 {
     $content = file_get_contents(IPS_ROOT_PATH . 'applications_addon/ips/ccs/xml/demosite.xml');
     require_once IPS_KERNEL_PATH . 'classXML.php';
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     foreach ($xml->fetchElements('block') as $block) {
         $_block = $xml->fetchElementsFromRecord($block);
         $this->DB->insert("ccs_blocks", $_block);
     }
     foreach ($xml->fetchElements('container') as $container) {
         $_container = $xml->fetchElementsFromRecord($container);
         $this->DB->insert("ccs_containers", $_container);
     }
     foreach ($xml->fetchElements('folder') as $folder) {
         $_folder = $xml->fetchElementsFromRecord($folder);
         $this->DB->insert("ccs_folders", $_folder);
     }
     foreach ($xml->fetchElements('template') as $template) {
         $_template = $xml->fetchElementsFromRecord($template);
         $this->DB->insert("ccs_page_templates", $_template);
     }
     foreach ($xml->fetchElements('page') as $page) {
         $_page = $xml->fetchElementsFromRecord($page);
         $this->DB->insert("ccs_pages", $_page);
     }
     foreach ($xml->fetchElements('tblock') as $tblock) {
         $_tblock = $xml->fetchElementsFromRecord($tblock);
         $this->DB->insert("ccs_template_blocks", $_tblock);
     }
     foreach ($xml->fetchElements('cache') as $cache) {
         $_cache = $xml->fetchElementsFromRecord($cache);
         $this->DB->insert("ccs_template_cache", $_cache);
     }
 }
コード例 #3
0
 /**
  * Execute selected method
  *
  * @param	object		Registry object
  * @return	@e void
  */
 public function _restoreXmlSkin()
 {
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPSSetUp::charSet);
     /* Skin Set Data */
     $xml->load(IPS_ROOT_PATH . 'setup/xml/skins/setsData.xml');
     foreach ($xml->fetchElements('set') as $xmlelement) {
         $data = $xml->fetchElementsFromRecord($xmlelement);
         if ($data['set_key'] == 'xmlskin') {
             $data['set_order'] = intval($data['set_order']);
             unset($data['set_id']);
             $this->DB->delete('skin_collections', "set_key='xmlskin'");
             $this->DB->insert('skin_collections', $data);
         }
     }
     $this->registry->output->addMessage("XML стиль восстановлен");
     $this->request['workact'] = '';
 }
コード例 #4
0
 /**
  * Finish up conversion stuff
  * 
  * @return	@e void
  */
 public function finish()
 {
     $options = IPSSetUp::getSavedData('custom_options');
     $skipPms = $options['core'][30001]['skipPms'];
     $output = array();
     /* Emoticons */
     if (file_exists(DOC_IPS_ROOT_PATH . 'style_emoticons/default')) {
         try {
             foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . 'style_emoticons/default') as $file) {
                 if (!$file->isDot()) {
                     $_name = $file->getFileName();
                     /* Annoyingly, isDot doesn't match .svn, etc */
                     if (substr($_name, 0, 1) == '.') {
                         continue;
                     }
                     if (@copy(DOC_IPS_ROOT_PATH . 'style_emoticons/default/' . $_name, IPS_PUBLIC_PATH . 'style_emoticons/default/' . $_name)) {
                         $output[] = "Смайлики: скопирован {$_name}...";
                     } else {
                         $output[] = "Не удалось скопировать {$_name} - после обновления перенесите его самостоятельно";
                     }
                 }
             }
         } catch (Exception $e) {
         }
     }
     /* LOG IN METHODS */
     $this->DB->build(array('select' => '*', 'from' => 'login_methods'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $loginMethods[$row['login_folder_name']] = $row;
     }
     $count = 6;
     $recount = array('internal' => 1, 'ipconverge' => 2, 'ldap' => 3, 'external' => 4);
     /* Fetch XML */
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPSSetUp::charSet);
     $xml->load(IPS_ROOT_PATH . 'setup/xml/loginauth.xml');
     foreach ($xml->fetchElements('login_methods') as $xmlelement) {
         $data = $xml->fetchElementsFromRecord($xmlelement);
         $data['login_order'] = isset($recount[$data['login_folder_name']]) ? $recount[$data['login_folder_name']] : ++$count;
         unset($data['login_id']);
         if (!$loginMethods[$data['login_folder_name']]) {
             $this->DB->insert('login_methods', $data);
         } else {
             $this->DB->update('login_methods', array('login_order' => $data['login_order']), 'login_folder_name=\'' . $data['login_folder_name'] . '\'');
         }
     }
     /* Reset member languages and skins */
     $this->DB->update('members', array('language' => IPSLib::getDefaultLanguage(), 'skin' => 0));
     /* Empty caches */
     $this->DB->delete('cache_store', "cs_key='forum_cache'");
     $this->DB->delete('cache_store', "cs_key='skin_id_cache'");
     /* Empty other tables */
     $this->DB->delete('skin_cache');
     $this->DB->delete('skin_templates_cache');
     /* Reset admin permissions */
     $this->DB->update('admin_permission_rows', array('row_perm_cache' => ''));
     /* Drop Tables */
     $this->DB->dropTable('contacts');
     $this->DB->dropTable('skin_macro');
     $this->DB->dropTable('skin_template_links');
     $this->DB->dropTable('skin_templates_old');
     $this->DB->dropTable('skin_sets');
     $this->DB->dropTable('languages');
     $this->DB->dropTable('topics_read');
     $this->DB->dropTable('topic_markers');
     $this->DB->dropTable('acp_help');
     $this->DB->dropTable('members_converge');
     $this->DB->dropTable('member_extra');
     $this->DB->dropTable('custom_bbcode_old');
     $this->DB->dropTable('admin_sessions');
     $this->DB->dropTable('components');
     $this->DB->dropTable('admin_permission_keys');
     $this->DB->dropTable('conf_settings');
     $this->DB->dropTable('conf_settings_titles');
     $this->DB->dropTable('reg_antispam');
     if (!$skipPms) {
         $this->DB->dropTable('message_text');
         $this->DB->dropTable('message_topics_old');
     }
     $message = (is_array($output) and count($output)) ? implode("<br />", $output) . '<br />' : '';
     $this->registry->output->addMessage($message . "очистка SQL завершена...");
     /* Last function, so unset workact */
     $this->request['workact'] = '';
 }
コード例 #5
0
 /**
  * Abstracted import routine for installer
  *
  * @access	public
  * @param	string		XML file content
  * @return	void
  */
 public function doMediaImport($content)
 {
     //-----------------------------------------
     // Get xml mah-do-dah
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     //-----------------------------------------
     // Get current custom bbcodes
     //-----------------------------------------
     $tags = array();
     $this->DB->build(array('select' => '*', 'from' => 'bbcode_mediatag'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $tags[$r['mediatag_name']] = $r['mediatag_id'];
     }
     //-----------------------------------------
     // pArse
     //-----------------------------------------
     foreach ($xml->fetchElements('mediatag') as $mediatag) {
         $entry = $xml->fetchElementsFromRecord($mediatag);
         $name = $entry['mediatag_name'];
         $match = $entry['mediatag_match'];
         $replace = $entry['mediatag_replace'];
         $array = array('mediatag_name' => $name, 'mediatag_match' => $match, 'mediatag_replace' => $replace);
         if ($tags[$name]) {
             $this->DB->update('bbcode_mediatag', $array, "mediatag_id=" . $tags[$name]);
             continue;
         }
         if ($name) {
             $this->DB->insert('bbcode_mediatag', $array);
         }
     }
     $this->recacheMediaTag();
 }
コード例 #6
0
ファイル: setup.php プロジェクト: ConnorChristie/GrabViews
 /**
  * Fetch Apps XML Modules File
  *
  * @access	public
  * @param	string		Application Directory
  * @param	string		Charset (post install)
  * @return	array 		..of data
  */
 public static function fetchXmlAppModules($app, $charset = '')
 {
     //-----------------------------------------
     // No modules?
     //-----------------------------------------
     if (!is_file(IPSLib::getAppDir($app) . '/xml/' . $app . '_modules.xml')) {
         return array();
     }
     /* INIT */
     $modules = array();
     try {
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML($charset ? $charset : IPSSetUp::charSet);
         $xml->load(IPSLib::getAppDir($app) . '/xml/' . $app . '_modules.xml');
         /* Fetch info */
         foreach ($xml->fetchElements('module') as $xmlelement) {
             $data = $xml->fetchElementsFromRecord($xmlelement);
             if ($data['sys_module_id']) {
                 unset($data['sys_module_id']);
             }
             /* Remove fields removed from 3.1.3+ to avoid driver errors */
             unset($data['sys_module_parent']);
             unset($data['sys_module_tables']);
             unset($data['sys_module_hooks']);
             $modules[$data['sys_module_key'] . intval($data['sys_module_admin'])] = $data;
         }
         return $modules;
     } catch (Exception $error) {
         return FALSE;
     }
 }
コード例 #7
0
ファイル: login.php プロジェクト: ConnorChristie/GrabViews
 /**
  * Install a login method
  *
  * @return	@e void		[Outputs to screen]
  */
 protected function _loginInstall()
 {
     //-----------------------------------------
     // Get xml class
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $login_id = basename(ipsRegistry::$request['login_folder']);
     //-----------------------------------------
     // Now get the XML data
     //-----------------------------------------
     $dh = opendir(IPS_PATH_CUSTOM_LOGIN);
     if ($dh !== false) {
         while (false !== ($file = readdir($dh))) {
             if (is_dir(IPS_PATH_CUSTOM_LOGIN . '/' . $file) and $file == $login_id) {
                 if (is_file(IPS_PATH_CUSTOM_LOGIN . '/' . $file . '/loginauth_install.xml')) {
                     $file_content = file_get_contents(IPS_PATH_CUSTOM_LOGIN . '/' . $file . '/loginauth_install.xml');
                     $xml->loadXML($file_content);
                     foreach ($xml->fetchElements('row') as $record) {
                         $data = $xml->fetchElementsFromRecord($record);
                     }
                 } else {
                     closedir($dh);
                     ipsRegistry::getClass('output')->global_message = $this->lang->words['l_installer404'];
                     $this->_loginList();
                     return;
                 }
                 $dir_methods[$file] = $data;
                 break;
             }
         }
         closedir($dh);
     }
     if (!is_array($dir_methods) or !count($dir_methods)) {
         ipsRegistry::getClass('output')->global_message = $this->lang->words['l_installer404'];
         $this->_loginList();
         return;
     }
     //-----------------------------------------
     // Now verify it isn't installed
     //-----------------------------------------
     $login = $this->DB->buildAndFetch(array('select' => 'login_id', 'from' => 'login_methods', 'where' => "login_folder_name='" . $login_id . "'"));
     if ($login['login_id']) {
         ipsRegistry::getClass('output')->global_message = $this->lang->words['l_already'];
         $this->_loginList();
         return;
     }
     //-----------------------------------------
     // Get the highest order and insert method
     //-----------------------------------------
     $max = $this->DB->buildAndFetch(array('select' => 'MAX(login_order) as highest_order', 'from' => 'login_methods'));
     $dir_methods[$login_id]['login_order'] = $max['highest_order'] + 1;
     $this->DB->insert('login_methods', $dir_methods[$login_id]);
     //-----------------------------------------
     // Recache
     //-----------------------------------------
     $this->loginsRecache();
     ipsRegistry::getClass('output')->redirect($this->settings['base_url'] . $this->form_code . "", $this->lang->words['l_yesinstalled']);
 }
コード例 #8
0
 /**
  * Rebuilds the mobile user agents from the skin set data
  */
 public function rebuildMobileSkinUserAgentsFromSetDataXml()
 {
     /* Init */
     $mobileSkinSet = $this->fetchSkinData($this->fetchSetIdByKey('mobile', true), true);
     $xmlData = array();
     /* Grab xml */
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML('UTF-8');
     /* Skin Set Data */
     $xml->load(IPS_ROOT_PATH . 'setup/xml/skins/setsData.xml');
     foreach ($xml->fetchElements('set') as $xmlelement) {
         $data = $xml->fetchElementsFromRecord($xmlelement);
         if ($data['set_key'] == 'mobile') {
             $xmlData = $data;
             break;
         }
     }
     /* Update */
     if ($xmlData['set_key'] && IPSLib::isSerialized($xmlData['set_locked_uagent']) && IPSLib::isSerialized($mobileSkinSet['set_locked_uagent'])) {
         $new = unserialize($xmlData['set_locked_uagent']);
         $old = unserialize($mobileSkinSet['set_locked_uagent']);
         /* Merge them */
         foreach ($new['groups'] as $group) {
             if (!in_array($group, $old['groups'])) {
                 $old['groups'][] = $group;
             }
         }
         foreach ($new['uagents'] as $agent => $version) {
             if (!in_array($agent, $new['uagents'])) {
                 $old['uagents'][$agent] = $version;
             }
         }
     }
     if (is_array($old) && count($old)) {
         $this->DB->update('skin_collections', array('set_locked_uagent' => serialize($old)), "set_key='mobile'");
     }
 }
コード例 #9
0
ファイル: index.php プロジェクト: ConnorChristie/GrabViews
 /**
  * Execute selected method
  *
  * @access	public
  * @param	object		Registry object
  * @return	@e void
  */
 public function doExecute(ipsRegistry $registry)
 {
     /* INIT */
     $filesOK = NULL;
     $extensions = get_loaded_extensions();
     $extensionsOK = TRUE;
     $extensionData = array();
     /* Test Extensions */
     $INSTALLDATA = array();
     include IPS_ROOT_PATH . 'setup/xml/requiredextensions.php';
     /*noLibHook*/
     if (is_array($INSTALLDATA) && count($INSTALLDATA)) {
         foreach ($INSTALLDATA as $data) {
             if (!in_array($data['testfor'], $extensions)) {
                 //-----------------------------------------
                 // Added 'nohault' key which will show a
                 // warning but not prohibit installation
                 //-----------------------------------------
                 if ($data['nohault']) {
                     $data['_ok'] = 1;
                     // Anything but true or false
                     $extensionsOK = 1;
                     // Anything but true or false
                 } else {
                     $extensionsOK = FALSE;
                 }
             } else {
                 $data['_ok'] = TRUE;
             }
             $extensionData[] = $data;
         }
     }
     /* Check for conf_global.dist.php */
     if (is_file(DOC_IPS_ROOT_PATH . 'conf_global.dist.php') and !is_file(DOC_IPS_ROOT_PATH . 'conf_global.php')) {
         if (!@rename(DOC_IPS_ROOT_PATH . 'conf_global.dist.php', DOC_IPS_ROOT_PATH . 'conf_global.php')) {
             $filesOK = FALSE;
             $this->registry->output->addError("<strong>You MUST rename the file 'conf_global.<b style='color:red'>dist.php</b>' TO 'conf_global.<b style='color:red'>php</b>' before continuing.</strong>\r\r\n\t\t\t\t\t\t\t  \t\t\t\t\t\t This file can be found in the 'root' directory on your IP.Board install.");
         }
     }
     /* All extensions loaded OK? */
     if ($extensionsOK == TRUE and $filesOK === NULL) {
         $filesOK = FALSE;
         /* Fetch core writeable files */
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML(IPSSetUp::charSet);
         try {
             $xml->load(IPS_ROOT_PATH . 'setup/xml/writeablefiles.xml');
             foreach ($xml->fetchElements('file') as $xmlelement) {
                 $data = $xml->fetchElementsFromRecord($xmlelement);
                 if ($data['path']) {
                     $_path = DOC_IPS_ROOT_PATH . $data['path'];
                     if (!file_exists($_path)) {
                         if ($data['dir']) {
                             if (!@mkdir($_path, IPS_FOLDER_PERMISSION, TRUE)) {
                                 $this->registry->output->addError('Directory does not exist: "' . $data['path'] . '", please create it via FTP');
                             }
                         } else {
                             $this->registry->output->addError('File does not exist: "' . $data['path'] . '", please create it via FTP');
                         }
                     }
                     if (!is_writeable($_path)) {
                         if (!@chmod($_path, is_dir($_path) ? IPS_FOLDER_PERMISSION : IPS_FILE_PERMISSION)) {
                             if (is_dir($_path)) {
                                 $this->registry->output->addError('Can not write to directory: "' . $data['path'] . '", please CHMOD to 777');
                             } else {
                                 $this->registry->output->addError('Can not write to file: "' . $data['path'] . '", please CHMOD to 777');
                             }
                         }
                     }
                 }
             }
             if (!count($this->registry->output->fetchErrors())) {
                 $filesOK = TRUE;
             }
         } catch (Exception $error) {
             $filesOK = FALSE;
             $this->registry->output->addError("Cannot locate: " . IPS_ROOT_PATH . 'setup/xml/writeablefiles.xml');
         }
     }
     /* Hide buttons? */
     if ($filesOK !== TRUE or $extensionsOK != TRUE) {
         $this->registry->output->setNextAction('');
         $this->registry->output->setHideButton(TRUE);
     }
     /* Simply return the requirements page */
     $this->registry->output->setTitle("Requirements");
     $this->registry->output->addContent($this->registry->output->template()->page_requirements($filesOK, $extensionsOK, $extensionData));
     $this->registry->output->sendOutput();
 }
コード例 #10
0
 /**
  * Remove an application
  *
  * @return	@e void		[Outputs to screen]
  */
 public function applicationRemove()
 {
     //--------------------------------------------
     // INIT
     //--------------------------------------------
     $app_id = intval($this->request['app_id']);
     //-----------------------------------------
     // Got an application?
     //-----------------------------------------
     $application = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_applications', 'where' => 'app_id=' . $app_id));
     if (!$application['app_id']) {
         $this->registry->output->global_message = $this->lang->words['a_noid'];
         $this->applicationsOverview();
         return;
     }
     //-----------------------------------------
     // Protected?
     //-----------------------------------------
     if (!IN_DEV and $application['app_protected']) {
         $this->registry->output->global_message = $this->lang->words['a_protectapp'];
         $this->applicationsOverview();
         return;
     }
     //-----------------------------------------
     // Remove Settings
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'core_sys_settings_titles', 'where' => "conf_title_app='{$application['app_directory']}'"));
     $this->DB->execute();
     $conf_title_id = array();
     while ($r = $this->DB->fetch()) {
         $conf_title_id[] = $r['conf_title_id'];
     }
     if (count($conf_title_id)) {
         $this->DB->delete('core_sys_conf_settings', 'conf_group IN(' . implode(',', $conf_title_id) . ')');
     }
     $this->DB->delete('core_sys_settings_titles', "conf_title_app='{$application['app_directory']}'");
     $settingsFile = IPSLib::getAppDir($application['app_directory']) . '/xml/' . $application['app_directory'] . '_settings.xml';
     if (is_file($settingsFile)) {
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML(IPS_DOC_CHAR_SET);
         $xml->load($settingsFile);
         $keys = array();
         foreach ($xml->fetchElements('setting') as $setting) {
             $entry = $xml->fetchElementsFromRecord($setting);
             if ($entry['conf_is_title']) {
                 continue;
             }
             $keys[] = "'{$entry['conf_key']}'";
         }
         if (!empty($keys)) {
             $this->DB->delete('core_sys_conf_settings', 'conf_key IN(' . implode(',', $keys) . ')');
         }
     }
     //-----------------------------------------
     // Remove Application Caches
     //-----------------------------------------
     $_file = IPSLib::getAppDir($application['app_directory']) . '/extensions/coreVariables.php';
     if (is_file($_file)) {
         $CACHE = array();
         require $_file;
         /*noLibHook*/
         if (is_array($CACHE) and count($CACHE)) {
             foreach ($CACHE as $key => $data) {
                 $this->DB->delete('cache_store', "cs_key='{$key}'");
             }
         }
     }
     //-----------------------------------------
     // Remove tables
     //-----------------------------------------
     $_file = IPSLib::getAppDir($application['app_directory']) . '/setup/versions/install/sql/' . $application['app_directory'] . '_' . ipsRegistry::dbFunctions()->getDriverType() . '_tables.php';
     if (is_file($_file)) {
         $TABLE = array();
         require $_file;
         /*noLibHook*/
         foreach ($TABLE as $q) {
             //-----------------------------------------
             // Capture create tables first
             //-----------------------------------------
             preg_match("/CREATE TABLE (\\S+)(\\s)?\\(/", $q, $match);
             if ($match[1]) {
                 $_table = preg_replace('#^' . ipsRegistry::dbFunctions()->getPrefix() . "(\\S+)#", "\\1", $match[1]);
                 $this->DB->dropTable($_table);
             } else {
                 //-----------------------------------------
                 // Then capture alter tables
                 //-----------------------------------------
                 preg_match("/ALTER TABLE (\\S+)\\sADD\\s(\\S+)\\s/i", $q, $match);
                 if ($match[1] and $match[2]) {
                     $_table = preg_replace('#^' . ipsRegistry::dbFunctions()->getPrefix() . "(\\S+)#", "\\1", $match[1]);
                     $_field = $match[2];
                     /* check for field */
                     if ($this->DB->checkForField($_field, $_table)) {
                         $this->DB->dropField($_table, $_field);
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Check for uninstall sql
     //-----------------------------------------
     /* Any "extra" configs required for this driver? */
     if (is_file(IPS_ROOT_PATH . 'setup/sql/' . $this->settings['sql_driver'] . '_install.php')) {
         require_once IPS_ROOT_PATH . 'setup/sql/' . $this->settings['sql_driver'] . '_install.php';
         /*noLibHook*/
         $extra_install = new install_extra($this->registry);
     }
     $_file = IPSLib::getAppDir($application['app_directory']) . '/setup/versions/install/sql/' . $application['app_directory'] . '_' . ipsRegistry::dbFunctions()->getDriverType() . '_uninstall.php';
     if (is_file($_file)) {
         $QUERY = array();
         require $_file;
         /*noLibHook*/
         if (is_array($QUERY) and count($QUERY)) {
             foreach ($QUERY as $q) {
                 if ($extra_install and method_exists($extra_install, 'process_query_create')) {
                     $q = $extra_install->process_query_create($q);
                 }
                 $this->DB->query($q);
             }
         }
     }
     //-----------------------------------------
     // Remove Misc Stuff
     //-----------------------------------------
     $this->DB->delete('core_sys_lang_words', "word_app='{$application['app_directory']}'");
     $this->DB->delete('task_manager', "task_application='{$application['app_directory']}'");
     $this->DB->delete('permission_index', "app='{$application['app_directory']}'");
     $this->DB->delete('reputation_index', "app='{$application['app_directory']}'");
     $this->DB->delete('reputation_cache', "app='{$application['app_directory']}'");
     $this->DB->delete('core_tags', "tag_meta_app='{$application['app_directory']}'");
     $this->DB->delete('faq', "app='{$application['app_directory']}'");
     $this->DB->delete('custom_bbcode', "bbcode_app='{$application['app_directory']}'");
     $this->DB->delete('upgrade_history', "upgrade_app='{$application['app_directory']}'");
     $this->DB->delete('core_like_cache', "like_cache_app='{$application['app_directory']}'");
     $this->DB->delete('core_like', "like_app='{$application['app_directory']}'");
     $this->DB->delete('core_item_markers', "item_app='{$application['app_directory']}'");
     //-----------------------------------------
     // Report center..
     //-----------------------------------------
     $plugin = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'rc_classes', 'where' => "app='{$application['app_directory']}'"));
     if ($plugin['com_id']) {
         $this->DB->build(array('select' => '*', 'from' => 'rc_reports_index', 'where' => 'rc_class=' . $plugin['com_id']));
         $outer = $this->DB->execute();
         while ($r = $this->DB->fetch($outer)) {
             $this->DB->delete('rc_reports', "rid=" . $r['id']);
             $this->DB->delete('rc_comments', "rid=" . $r['id']);
         }
         $this->DB->delete('rc_reports_index', 'rc_class=' . $plugin['com_id']);
         $this->DB->delete('rc_classes', 'com_id=' . $plugin['com_id']);
     }
     //-----------------------------------------
     // Attachments
     //-----------------------------------------
     $_plugins = array();
     try {
         foreach (new DirectoryIterator(IPSLib::getAppDir($application['app_directory']) . '/extensions/attachments/') as $file) {
             if (!$file->isDot() && $file->isFile()) {
                 if (preg_match("/^plugin_(.+?)\\.php\$/", $file->getFileName(), $matches)) {
                     $_plugins[] = $matches[1];
                 }
             }
         }
         if (count($_plugins)) {
             foreach ($_plugins as $_plugin) {
                 $this->DB->build(array('select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module='{$_plugin}'"));
                 $outer = $this->DB->execute();
                 while ($r = $this->DB->fetch($outer)) {
                     if (is_file($this->settings['upload_dir'] . "/" . $r['attach_location'])) {
                         @unlink($this->settings['upload_dir'] . "/" . $r['attach_location']);
                     }
                 }
                 $this->DB->delete('attachments', "attach_rel_module='{$_plugin}'");
             }
         }
     } catch (Exception $e) {
     }
     //-----------------------------------------
     // Get all hook files
     //-----------------------------------------
     if (is_dir(IPSLib::getAppDir($application['app_directory']) . '/xml/hooks')) {
         $files = scandir(IPSLib::getAppDir($application['app_directory']) . '/xml/hooks');
         $hooks = array();
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML(IPS_DOC_CHAR_SET);
         if (count($files) and is_array($files)) {
             foreach ($files as $_hookFile) {
                 if ($_hookFile != '.' and $_hookFile != '..' and preg_match("/(\\.xml)\$/", $_hookFile)) {
                     $xml->loadXML(file_get_contents(IPSLib::getAppDir($application['app_directory']) . '/xml/hooks/' . $_hookFile));
                     foreach ($xml->fetchElements('config') as $data) {
                         $config = $xml->fetchElementsFromRecord($data);
                         if (!count($config)) {
                             continue;
                         } else {
                             $hooks[] = $config['hook_key'];
                         }
                     }
                 }
             }
         }
         if (count($hooks)) {
             foreach ($hooks as $hook) {
                 $hook = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_hooks', 'where' => "hook_key='" . $hook . "'"));
                 if (!$hook['hook_id']) {
                     continue;
                 }
                 $this->DB->delete('core_hooks', "hook_id={$hook['hook_id']}");
                 /* Get associated files */
                 $this->DB->build(array('select' => 'hook_file_stored', 'from' => 'core_hooks_files', 'where' => 'hook_hook_id=' . $hook['hook_id']));
                 $this->DB->execute();
                 while ($r = $this->DB->fetch()) {
                     @unlink(IPS_HOOKS_PATH . $r['hook_file_stored']);
                 }
                 /* Delete hook file entries */
                 $this->DB->delete('core_hooks_files', "hook_hook_id={$hook['hook_id']}");
             }
             $this->cache->rebuildCache('hooks', 'global');
         }
     }
     //-----------------------------------------
     // Remove Files
     //-----------------------------------------
     /* Languages */
     try {
         foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . 'cache/lang_cache/') as $dir) {
             if (!$dir->isDot() && intval($dir->getFileName())) {
                 foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . 'cache/lang_cache/' . $dir->getFileName() . '/') as $file) {
                     if (!$file->isDot()) {
                         if (preg_match("/^({$application['app_directory']}_)/", $file->getFileName())) {
                             unlink($file->getPathName());
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     /* Remove Skins */
     if (is_file(IPSLib::getAppDir($application['app_directory']) . '/xml/information.xml')) {
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML($this->settings['gb_char_set']);
         $xml->load(IPSLib::getAppDir($application['app_directory']) . '/xml/information.xml');
         if (is_object($xml->fetchElements('template'))) {
             foreach ($xml->fetchElements('template') as $template) {
                 $name = $xml->fetchItem($template);
                 $match = $xml->fetchAttribute($template, 'match');
                 if ($name) {
                     $templateGroups[$name] = $match;
                 }
             }
         }
         if (is_array($templateGroups) and count($templateGroups)) {
             /* Loop through skin directories */
             try {
                 foreach (new DirectoryIterator(IPS_CACHE_PATH . 'cache/skin_cache/') as $dir) {
                     if (preg_match("/^(cacheid_)/", $dir->getFileName())) {
                         foreach (new DirectoryIterator(IPS_CACHE_PATH . 'cache/skin_cache/' . $dir->getFileName() . '/') as $file) {
                             if (!$file->isDot()) {
                                 foreach ($templateGroups as $name => $match) {
                                     if ($match == 'contains') {
                                         if (stristr($file->getFileName(), $name)) {
                                             unlink($file->getPathName());
                                         }
                                     } else {
                                         if ($file->getFileName() == $name . '.php') {
                                             unlink($file->getPathName());
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } catch (Exception $e) {
             }
             /* Delete from database */
             foreach ($templateGroups as $name => $match) {
                 if ($match == 'contains') {
                     $this->DB->delete('skin_templates', "template_group LIKE '%{$name}%'");
                     $this->DB->delete('skin_templates_previous', "p_template_group LIKE '%{$name}%'");
                     $this->DB->delete('skin_cache', "cache_type='phptemplate' AND cache_value_1 LIKE '%{$name}%'");
                 } else {
                     $this->DB->delete('skin_templates', "template_group='{$name}'");
                     $this->DB->delete('skin_templates_previous', "p_template_group='{$name}'");
                     $this->DB->delete('skin_cache', "cache_type='phptemplate' AND cache_value_1='{$name}'");
                 }
             }
         }
     }
     /* CSS files */
     $css_files = array();
     $this->DB->build(array('select' => '*', 'from' => 'skin_css', 'where' => "css_app='" . $application['app_directory'] . "'"));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $css_files[$r['css_group']] = $r['css_group'];
     }
     if (count($css_files)) {
         $this->DB->delete('skin_css', "css_app='" . $application['app_directory'] . "'");
         $this->DB->delete('skin_cache', "cache_type='css' AND cache_value_1 IN('" . implode("','", $css_files) . "')");
         try {
             foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_css/') as $dir) {
                 if (preg_match("/^(css_)/", $dir->getFileName())) {
                     foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_css/' . $dir->getFileName() . '/') as $file) {
                         if (!$file->isDot()) {
                             foreach ($css_files as $css_file) {
                                 if ($file->getFileName() == $css_file . '.css') {
                                     unlink($file->getPathName());
                                 }
                             }
                         }
                     }
                 }
             }
         } catch (Exception $e) {
         }
     }
     //-----------------------------------------
     // Remove Modules
     //-----------------------------------------
     $this->DB->delete('core_sys_module', "sys_module_application='{$application['app_directory']}'");
     //-----------------------------------------
     // Remove Application
     //-----------------------------------------
     $this->DB->delete('core_applications', 'app_id=' . $app_id);
     //-----------------------------------------
     // Recache
     //-----------------------------------------
     $this->moduleRecacheAll(1);
     $this->cache->rebuildCache('settings', 'global');
     $this->cache->rebuildCache('notifications', 'global');
     /* Delete from upgrade */
     $this->DB->delete('upgrade_history', "upgrade_app='{$application['app_directory']}'");
     //-----------------------------------------
     // FURL templates
     //-----------------------------------------
     try {
         IPSLib::cacheFurlTemplates();
         IPSLib::cacheGlobalCaches();
     } catch (Exception $e) {
     }
     //-----------------------------------------
     // Sphinx involved?
     //-----------------------------------------
     if ($this->settings['search_method'] == 'sphinx') {
         $this->registry->output->global_message .= sprintf($this->lang->words['rebuild_sphinx'], $this->settings['_base_url']);
     }
     //-----------------------------------------
     // Done...
     //-----------------------------------------
     $this->registry->output->global_message = $this->lang->words['a_appremoved'];
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&amp;do=applications_overview');
 }
 /**
  * Import a single app
  *
  * @access	public
  * @param	string		App
  * @param	string		Skin key to import
  * @param	int			Set ID
  * @param	boolean		Set the edited / added flags to 0 (from install, upgrade)
  * @return	mixed		bool, or array of info
  */
 public function importTemplateAppXML($app, $skinKey, $setID = 0, $ignoreAddedEditedFlag = false)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $templateGroups = array();
     $templates = array();
     $fileXML = IPSLib::getAppDir($app) . '/xml/' . $app . '_' . $skinKey . '_templates.xml';
     $infoXML = IPSLib::getAppDir($app) . '/xml/information.xml';
     $return = array('updateCount' => 0, 'insertCount' => 0, 'updateBits' => array(), 'insertBits' => array());
     if (!file_exists($fileXML)) {
         return $return;
     }
     if (!$setID and $skinKey != 'root') {
         /* Figure out correct set ID based on key */
         $skinSetData = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'skin_collections', 'where' => "set_key='" . $skinKey . "'"));
         $setID = $skinSetData['set_id'];
     }
     /* Set ignore flag correctly */
     if (!empty($skinKey) and in_array($skinKey, array('root', 'lofi', 'xmlskin'))) {
         $ignoreAddedEditedFlag = true;
     }
     //-----------------------------------------
     // XML
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     $xml = new classXML(IPS_DOC_CHAR_SET);
     //-----------------------------------------
     // Get information file
     //-----------------------------------------
     $xml->load($infoXML);
     foreach ($xml->fetchElements('template') as $template) {
         $name = $xml->fetchItem($template);
         $match = $xml->fetchAttribute($template, 'match');
         if ($name) {
             $templateGroups[$name] = $match;
         }
     }
     if (!is_array($templateGroups) or !count($templateGroups)) {
         $this->_addMessage("Nothing to export for " . $app);
         return FALSE;
     }
     //-----------------------------------------
     // Fetch templates
     //-----------------------------------------
     $_templates = $this->fetchTemplates($setID, 'allNoContent');
     $_MASTER = $this->fetchTemplates(0, 'allNoContent');
     //-----------------------------------------
     // Loop through...
     //-----------------------------------------
     foreach ($_templates as $group => $data) {
         $_okToGo = FALSE;
         foreach ($templateGroups as $name => $match) {
             if ($match == 'contains') {
                 if (stristr($group, $name)) {
                     $_okToGo = TRUE;
                     break;
                 }
             } else {
                 if ($group == $name) {
                     $_okToGo = TRUE;
                 }
             }
         }
         if ($_okToGo === TRUE) {
             foreach ($data as $name => $templateData) {
                 $templates[$group][$name] = $templateData;
             }
         }
     }
     //-----------------------------------------
     // Wipe the master skins
     //-----------------------------------------
     if ($setID == 0) {
         $this->DB->delete('skin_templates', "template_set_id=0 AND template_group IN ('" . implode("','", array_keys($templates)) . "') AND template_user_added=0 AND template_added_to=0");
         /* Now wipe the array so we enforce creation */
         unset($templates);
     }
     //-----------------------------------------
     // Now grab the actual XML files
     //-----------------------------------------
     $xml->load($fileXML);
     foreach ($xml->fetchElements('template') as $templatexml) {
         $data = $xml->fetchElementsFromRecord($templatexml);
         /* Figure out if this is added by a user or not */
         if ($ignoreAddedEditedFlag === TRUE) {
             $isAdded = 0;
             $isEdited = 0;
         } else {
             $isAdded = (is_array($_MASTER[$data['template_group']][strtolower($data['template_name'])]) and !$_MASTER[$data['template_group']][strtolower($data['template_name'])]['template_user_added']) ? 0 : 1;
             $isEdited = 1;
         }
         if (is_array($templates[$data['template_group']][strtolower($data['template_name'])]) and $templates[$data['template_group']][strtolower($data['template_name'])]['template_set_id'] == $setID) {
             /* Update.. */
             $return['updateCount']++;
             $return['updateBits'][] = $data['template_name'];
             $this->DB->update('skin_templates', array('template_content' => $data['template_content'], 'template_data' => $data['template_data'], 'template_user_edited' => $isEdited, 'template_user_added' => $isAdded, 'template_updated' => time()), 'template_set_id=' . $setID . " AND template_group='" . $data['template_group'] . "' AND template_name='" . $data['template_name'] . "'");
         } else {
             /* Add... */
             $return['insertCount']++;
             $return['insertBits'][] = $data['template_name'];
             $this->DB->insert('skin_templates', array('template_set_id' => $setID, 'template_group' => $data['template_group'], 'template_content' => $data['template_content'], 'template_name' => $data['template_name'], 'template_data' => $data['template_data'], 'template_removable' => $setID ? $data['template_removable'] : 0, 'template_added_to' => $setID, 'template_user_edited' => $isEdited, 'template_user_added' => $isAdded, 'template_updated' => time()));
         }
     }
     return $return;
 }
コード例 #12
0
ファイル: cs.php プロジェクト: mover5/imobackup
 /**
  * Convert Polls
  *
  * @access	private
  * @return void
  **/
 private function convert_polls()
 {
     print 'Need data to finish this section';
     exit;
     //---------------------------
     // Set up
     //---------------------------
     $main = array('select' => 'PostID, ThreadID, PostAuthor, UserID, CAST(Subject AS varchar) as Subject, PostDate, IsApproved, CAST(Body AS TEXT) as Body, IPAddress, SectionID', 'from' => 'cs_Posts', 'where' => "PostType = '2'", 'order' => 't.pollid ASC');
     $loop = $this->lib->load('polls', $main, array('voters'));
     //---------------------------
     // Loop
     //---------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     while ($row = ipsRegistry::DB('hb')->fetch($this->lib->queryRes)) {
         $xml = new classXML(IPSSetUp::charSet);
         $xml->loadXML($row['Body']);
         foreach ($xml->fetchElements('VoteOptions') as $option) {
             $data = $this->_xml->fetchElementsFromRecord($_el);
             if ($data['appears'] and intval($data['frequency']) > $this->_minF) {
                 return TRUE;
             }
         }
         //-----------------------------------------
         // Convert votes
         //-----------------------------------------
         $votes = array();
         ipsRegistry::DB('hb')->build(array('select' => '*', 'from' => 'pollvoted', 'where' => "pollid='{$row['pollid']}' AND registered='1'"));
         $voterRes = ipsRegistry::DB('hb')->execute();
         while ($voter = ipsRegistry::DB('hb')->fetch($voterRes)) {
             $vsave = array('vote_date' => time(), 'tid' => $row['threadid'], 'member_id' => $voter['memberid'], 'forum_id' => $row['forumid'], 'member_choices' => serialize(array(1 => $row['optionid'])));
             $this->lib->convertPollVoter($voter['voteid'], $vsave);
         }
         //-----------------------------------------
         // Options are stored in one place...
         //-----------------------------------------
         $choices = array();
         $votes = array();
         $totalVotes = 0;
         ipsRegistry::DB('hb')->build(array('select' => '*', 'from' => 'polloptions', 'where' => "pollid='{$row['pollid']}'"));
         $choiceRes = ipsRegistry::DB('hb')->execute();
         while ($choice = ipsRegistry::DB('hb')->fetch($choiceRes)) {
             $choices[$choice['optionid']] = $choice['description'];
             $votes[$choice['optionid']] = $choice['votes'];
             $totalVotes += $choice['votes'];
         }
         //-----------------------------------------
         // Then we can do the actual poll
         //-----------------------------------------
         $poll_array = array(1 => array('question' => $row['threadsubject'], 'choice' => $choices, 'votes' => $votes));
         $save = array('tid' => $row['threadid'], 'start_date' => strtotime($row['datecreated']), 'choices' => addslashes(serialize($poll_array)), 'starter_id' => $row['memberid'] == '-1' ? 0 : $row['memberid'], 'votes' => $totalVotes, 'forum_id' => $row['forumid'], 'poll_question' => $row['threadsubject']);
         $this->lib->convertPoll($row['pollid'], $save);
     }
     $this->lib->next();
 }
 /**
  * Imports language packs from an xml file and updates the database and recaches the languages
  *
  * @access	public
  * @param	integer	$lang_id	ID of the language pack to import
  * @param	bool	$in_dev		Set to 1 for developer language import
  * @param	bool	$no_return	If set to 1, this function will return a value, rather than outputting data
  * @param	string	$app_override	Overrides the application for which languages are being imported
  * @return	mixed
  */
 public function imprtFromXML($lang_id = 0, $in_dev = 0, $no_return = 0, $app_override = '')
 {
     //-----------------------------------------
     // Set version..
     //-----------------------------------------
     $LATESTVERSION = IPSLib::fetchVersionNumber();
     //-----------------------------------------
     // INDEV?
     //-----------------------------------------
     if ($in_dev) {
         $_FILES['FILE_UPLOAD']['name'] = '';
     } else {
         if ($this->request['file_location']) {
             $this->request['file_location'] = IPS_ROOT_PATH . $this->request['file_location'];
         }
     }
     //-----------------------------------------
     // Not an upload?
     //-----------------------------------------
     if ($_FILES['FILE_UPLOAD']['name'] == "" or !$_FILES['FILE_UPLOAD']['name'] or $_FILES['FILE_UPLOAD']['name'] == "none") {
         //-----------------------------------------
         // Check and load from server
         //-----------------------------------------
         if (!$this->request['file_location']) {
             $this->registry->output->global_message = $this->lang->words['l_nofile'];
             $this->languagesList();
             return;
         }
         if (!file_exists($this->request['file_location'])) {
             $this->registry->output->global_message = $this->lang->words['l_noopen'] . $this->request['file_location'];
             $this->languagesList();
             return;
         }
         if (preg_match("#\\.gz\$#", $this->request['file_location'])) {
             if ($FH = @gzopen($this->request['file_location'], 'rb')) {
                 while (!@gzeof($FH)) {
                     $content .= @gzread($FH, 1024);
                 }
                 @gzclose($FH);
             }
         } else {
             $content = file_get_contents($this->request['file_location']);
         }
         $originalContent = $content;
         //-----------------------------------------
         // Extract archive
         //-----------------------------------------
         require_once IPS_KERNEL_PATH . 'classXMLArchive.php';
         $xmlarchive = new classXMLArchive();
         //-----------------------------------------
         // Read the archive
         //-----------------------------------------
         $xmlarchive->readXML($content);
         //-----------------------------------------
         // Get the data
         //-----------------------------------------
         $content = '';
         foreach ($xmlarchive->asArray() as $k => $f) {
             if ($k == 'language_entries.xml') {
                 $content = $f['content'];
                 break;
             }
         }
         //-----------------------------------------
         // No content from de-archiving, must not
         // be archive, but rather raw XML file
         //-----------------------------------------
         if ($content == '' and strpos($originalContent, "<languageexport") !== false) {
             $content = $originalContent;
         }
     } else {
         //-----------------------------------------
         // Get uploaded schtuff
         //-----------------------------------------
         $tmp_name = $_FILES['FILE_UPLOAD']['name'];
         $tmp_name = preg_replace("#\\.gz\$#", "", $tmp_name);
         if ($_FILES['FILE_UPLOAD']['error']) {
             switch ($_FILES['FILE_UPLOAD']['error']) {
                 case 1:
                     $this->registry->output->global_message = sprintf($this->lang->words['lang_upload_too_large'], ini_get('upload_max_filesize'));
                     $this->languagesList();
                     return;
                     break;
                 default:
                     $this->registry->output->global_message = $this->lang->words['lang_upload_other_error'];
                     $this->languagesList();
                     return;
                     break;
             }
         }
         //-----------------------------------------
         // Get content
         //-----------------------------------------
         $uploadedContent = $this->registry->adminFunctions->importXml($tmp_name);
         //-----------------------------------------
         // Extract archive
         //-----------------------------------------
         require_once IPS_KERNEL_PATH . 'classXMLArchive.php';
         $xmlarchive = new classXMLArchive();
         //-----------------------------------------
         // Read the archive
         //-----------------------------------------
         $xmlarchive->readXML($uploadedContent);
         //-----------------------------------------
         // Get the data
         //-----------------------------------------
         $content = '';
         foreach ($xmlarchive->asArray() as $k => $f) {
             if ($k == 'language_entries.xml') {
                 $content = $f['content'];
                 break;
             }
         }
         //-----------------------------------------
         // No content from de-archiving, must not
         // be archive, but rather raw XML file
         //-----------------------------------------
         if ($content == '' and strpos($uploadedContent, "<languageexport") !== false) {
             $content = $uploadedContent;
         }
     }
     //-----------------------------------------
     // Make sure we have content
     //-----------------------------------------
     if (!$content) {
         $this->registry->output->global_message = $this->lang->words['l_badfile'];
         $this->languagesList();
         return;
     }
     //-----------------------------------------
     // Get xml class
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     //-----------------------------------------
     // Is this full language pack?...
     //-----------------------------------------
     foreach ($xml->fetchElements('langinfo') as $lang_data) {
         $lang_info = $xml->fetchElementsFromRecord($lang_data);
         $lang_data = array('lang_short' => $lang_info['lang_short'], 'lang_title' => $lang_info['lang_title']);
     }
     $lang_ids = array();
     $insertId = 0;
     //-----------------------------------------
     // Do we have language pack info?
     //-----------------------------------------
     if ($lang_data['lang_short']) {
         //-----------------------------------------
         // Does this pack already exist
         //-----------------------------------------
         $update_lang = $this->DB->buildAndFetch(array('select' => 'lang_id', 'from' => 'core_sys_lang', 'where' => "lang_short='{$lang_data['lang_short']}'"));
         //-----------------------------------------
         // If doesn't exist, then create new pack
         //-----------------------------------------
         if (!$update_lang['lang_id']) {
             $this->DB->insert('core_sys_lang', $lang_data);
             $insertId = $this->DB->getInsertId();
             if (@mkdir(IPS_CACHE_PATH . '/cache/lang_cache/' . $insertId)) {
                 @file_put_contents(IPS_CACHE_PATH . 'cache/lang_cache/' . $insertId . '/index.html', '');
                 @chmod(IPS_CACHE_PATH . '/cache/lang_cache/' . $insertId, 0777);
             }
             //-----------------------------------------
             // Copy over language bits from default lang
             //-----------------------------------------
             $default = $this->DB->buildAndFetch(array('select' => 'lang_id', 'from' => 'core_sys_lang', 'where' => "lang_default=1"));
             $this->DB->build(array('select' => 'word_app,word_pack,word_key,word_default', 'from' => 'core_sys_lang_words', 'where' => "lang_id={$default['lang_id']}"));
             $q = $this->DB->execute();
             while ($r = $this->DB->fetch($q)) {
                 $r['lang_id'] = $insertId;
                 $this->DB->insert('core_sys_lang_words', $r);
             }
             //-----------------------------------------
             // Rebuild IPB and disk caches
             //-----------------------------------------
             $this->registry->class_localization->rebuildLanguagesCache();
         }
     }
     //-----------------------------------------
     // We need to add language bits to every pack..
     //-----------------------------------------
     if (count($this->caches['lang_data'])) {
         foreach ($this->caches['lang_data'] as $langData) {
             $lang_ids[] = $langData['lang_id'];
         }
     } else {
         $this->DB->build(array('select' => 'lang_id', 'from' => 'core_sys_lang'));
         $this->DB->execute();
         while ($r = $this->DB->fetch()) {
             $lang_ids[] = $r['lang_id'];
         }
     }
     //-----------------------------------------
     // Init counts array
     //-----------------------------------------
     $counts = array('updates' => 0, 'inserts' => 0);
     //-----------------------------------------
     // Init a cache array to save entries
     //-----------------------------------------
     $lang_entries = array();
     if ($app_override) {
         $this->DB->build(array('select' => '*', 'from' => 'core_sys_lang_words', 'where' => "word_app='{$app_override}'"));
         $this->DB->execute();
         while ($r = $this->DB->fetch()) {
             $lang_entries[$r['lang_id']][$r['word_app']][$r['word_pack']][$r['word_key']] = $r;
         }
     }
     //-----------------------------------------
     // Start looping
     //-----------------------------------------
     foreach ($xml->fetchElements('lang') as $entry) {
         $lang = $xml->fetchElementsFromRecord($entry);
         foreach ($lang_ids as $_lang_id) {
             //-----------------------------------------
             // Build db array
             //-----------------------------------------
             $db_array = array('lang_id' => $_lang_id, 'word_app' => $app_override ? $app_override : $lang['word_app'], 'word_pack' => $lang['word_pack'], 'word_key' => $lang['word_key'], 'word_default' => stripslashes($lang['word_default']), 'word_custom' => $in_dev ? '' : stripslashes($lang['word_custom']), 'word_js' => $lang['word_js'], 'word_default_version' => $lang['word_default_version'] >= 30000 ? $lang['word_default_version'] : $LATESTVERSION['long'], 'word_custom_version' => $lang['word_custom_version']);
             //-----------------------------------------
             // If cached, get from cache
             //-----------------------------------------
             if ($lang_entries[$_lang_id][$db_array['word_app']][$db_array['word_pack']]) {
                 $lang_entry = $lang_entries[$_lang_id][$db_array['word_app']][$db_array['word_pack']][$db_array['word_key']];
             } else {
                 if (!$app_override) {
                     $this->DB->build(array('select' => '*', 'from' => 'core_sys_lang_words', 'where' => "lang_id={$_lang_id} AND word_app='{$db_array['word_app']}' AND word_pack='{$db_array['word_pack']}'"));
                     $this->DB->execute();
                     while ($r = $this->DB->fetch()) {
                         $lang_entries[$r['lang_id']][$r['word_app']][$r['word_pack']][$r['word_key']] = $r;
                     }
                     if ($lang_entries[$_lang_id][$db_array['word_app']][$db_array['word_pack']][$db_array['word_key']]) {
                         $lang_entry = $lang_entries[$_lang_id][$db_array['word_app']][$db_array['word_pack']][$db_array['word_key']];
                     }
                 }
             }
             //-----------------------------------------
             // If there is no new custom lang bit to insert
             // don't delete what is already there.
             //-----------------------------------------
             if (!$db_array['word_custom']) {
                 unset($db_array['word_custom']);
                 unset($db_array['word_custom_version']);
             }
             //-----------------------------------------
             // Lang bit already exists, update
             //-----------------------------------------
             if ($lang_entry['word_id'] and (!$insertId or $insertId == $_lang_id)) {
                 //-----------------------------------------
                 // Don't update default version
                 //-----------------------------------------
                 unset($db_array['word_default_version']);
                 $counts['updates']++;
                 $this->DB->update('core_sys_lang_words', $db_array, "word_id={$lang_entry['word_id']}");
             } else {
                 if (!$lang_entry['word_id']) {
                     $counts['inserts']++;
                     $this->DB->insert('core_sys_lang_words', $db_array);
                 }
             }
         }
     }
     //-----------------------------------------
     // Recache all our lang packs
     //-----------------------------------------
     foreach ($lang_ids as $_lang_id) {
         $this->cacheToDisk($_lang_id);
     }
     //-----------------------------------------
     // Set output message
     //-----------------------------------------
     $this->registry->output->global_message = sprintf($this->lang->words['l_updatedcount'], $counts['updates'], $counts['inserts']);
     if (is_array($this->cache_errors) and count($this->cache_errors)) {
         $this->registry->output->global_message .= "<br />" . implode("<br />", $this->cache_errors);
     }
     //-----------------------------------------
     // Free a little memory
     //-----------------------------------------
     unset($xml);
     //-----------------------------------------
     // Update IPB cache
     //-----------------------------------------
     $this->registry->class_localization->rebuildLanguagesCache();
     //-----------------------------------------
     // Return! Now!
     //-----------------------------------------
     if (!$no_return) {
         $this->languagesList();
         return;
     }
 }
コード例 #14
0
 /**
  * Import skin templates for a plugin block
  *
  * @access	protected
  * @return	void
  */
 protected function _importBlock()
 {
     //-----------------------------------------
     // Developer reimporting templates?
     //-----------------------------------------
     if ($this->request['dev']) {
         $templates = array();
         $this->DB->build(array('select' => '*', 'from' => 'ccs_template_blocks'));
         $outer = $this->DB->execute();
         while ($r = $this->DB->fetch($outer)) {
             if (!preg_match("/_(\\d+)\$/", $r['tpb_name'])) {
                 $templates[$r['tpb_name']] = $r;
             }
         }
         $content = file_get_contents(IPSLib::getAppDir('ccs') . '/xml/block_templates.xml');
         require_once IPS_KERNEL_PATH . 'classXML.php';
         $xml = new classXML(IPS_DOC_CHAR_SET);
         $xml->loadXML($content);
         foreach ($xml->fetchElements('template') as $template) {
             $_template = $xml->fetchElementsFromRecord($template);
             if ($_template['tpb_name']) {
                 unset($_template['tpb_id']);
                 if (array_key_exists($_template['tpb_name'], $templates)) {
                     $this->DB->update("ccs_template_blocks", $_template, "tpb_id={$templates[$_template['tpb_name']]['tpb_id']}");
                 } else {
                     $this->DB->insert("ccs_template_blocks", $_template);
                 }
             }
         }
         $this->registry->output->global_message = $this->lang->words['block_import_devgood'];
         $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . '&module=blocks&section=blocks');
     }
     $content = $this->registry->getClass('adminFunctions')->importXml();
     //-----------------------------------------
     // Get xml class
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     //-----------------------------------------
     // First, found out if this is just a plugin
     //-----------------------------------------
     $_fullBlock = false;
     $_block = array();
     $_blockId = 0;
     foreach ($xml->fetchElements('block') as $block) {
         $_block = $xml->fetchElementsFromRecord($block);
     }
     if (count($_block)) {
         $_fullBlock = true;
     }
     //-----------------------------------------
     // If full block, insert block first to get id
     //-----------------------------------------
     if ($_fullBlock) {
         unset($_block['block_id']);
         unset($_block['block_cache_last']);
         unset($_block['block_position']);
         unset($_block['block_category']);
         $check = $this->DB->buildAndFetch(array('select' => 'block_id', 'from' => 'ccs_blocks', 'where' => "block_key='{$_block['block_key']}'"));
         //-----------------------------------------
         // Instead of updating, just change key to prevent
         // overwriting someone's configured block
         //-----------------------------------------
         if ($check['block_id']) {
             $_block['block_key'] = $_block['block_key'] . md5(uniqid(microtime()));
         }
         $this->DB->insert('ccs_blocks', $_block);
         $_blockId = $this->DB->getInsertId();
     }
     //-----------------------------------------
     // Do the template regardless
     //-----------------------------------------
     $tpbId = 0;
     foreach ($xml->fetchElements('template') as $template) {
         $entry = $xml->fetchElementsFromRecord($template);
         if (!$entry['tpb_name']) {
             continue;
         }
         $templatebit = array('tpb_name' => $entry['tpb_name'], 'tpb_params' => $entry['tpb_params'], 'tpb_content' => $entry['tpb_content']);
         //-----------------------------------------
         // Fix name if full block
         //-----------------------------------------
         if ($_fullBlock) {
             $templatebit['tpb_name'] = preg_replace("/^(.+?)_(\\d+)\$/", "\\1_{$_blockId}", $templatebit['tpb_name']);
         }
         $check = $this->DB->buildAndFetch(array('select' => 'tpb_id', 'from' => 'ccs_template_blocks', 'where' => "tpb_name='{$entry['tpb_name']}'"));
         if ($check['tpb_id']) {
             $this->DB->update('ccs_template_blocks', $templatebit, 'tpb_id=' . $check['tpb_id']);
             $tpbId = $check['tpb_id'];
         } else {
             $this->DB->insert('ccs_template_blocks', $templatebit);
             $tpbId = $this->DB->getInsertId();
         }
     }
     //-----------------------------------------
     // Recache skin if full block
     //-----------------------------------------
     if ($_fullBlock and $tpbId) {
         $cache = array('cache_type' => 'block', 'cache_type_id' => $tpbId);
         require_once IPS_KERNEL_PATH . 'classTemplateEngine.php';
         $engine = new classTemplate(IPS_ROOT_PATH . 'sources/template_plugins');
         $cache['cache_content'] = $engine->convertHtmlToPhp("{$templatebit['tpb_name']}", $templatebit['tpb_params'], $templatebit['tpb_content'], '', false, true);
         $hasIt = $this->DB->buildAndFetch(array('select' => 'cache_id', 'from' => 'ccs_template_cache', 'where' => "cache_type='block' AND cache_type_id={$tpbId}"));
         if ($hasIt['cache_id']) {
             $this->DB->update('ccs_template_cache', $cache, "cache_type='block' AND cache_type_id={$tpbId}");
         } else {
             $this->DB->insert('ccs_template_cache', $cache);
         }
         //-----------------------------------------
         // Recache the "skin" file
         //-----------------------------------------
         require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
         $_pagesClass = new pageBuilder($this->registry);
         $_pagesClass->recacheTemplateCache($engine);
     }
     if ($_fullBlock) {
         $this->registry->output->global_message = $this->lang->words['block_full_import_good'];
     } else {
         $this->registry->output->global_message = $this->lang->words['block_import_good'];
     }
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . '&module=blocks&section=blocks');
 }
 /**
  * Create new session
  *
  * @access	public
  * @param	string		Diff session title
  * @param	string		Compare HTML
  * @param	boolean		Ignore new bits
  * @return	int			New session ID
  */
 public function createSession($title, $content, $ignoreBits = FALSE)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $templateBits = array();
     //-----------------------------------------
     // Get number for missing template bits
     //-----------------------------------------
     $_bits = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'skin_templates', 'where' => 'template_set_id=0'));
     //-----------------------------------------
     // Create session
     //-----------------------------------------
     $this->DB->allow_sub_select = 1;
     $this->DB->insert('template_diff_session', array('diff_session_togo' => intval($_bits['count']), 'diff_session_done' => 0, 'diff_session_title' => $title, 'diff_session_updated' => time(), 'diff_session_ignore_missing' => $ignoreBits === TRUE ? 1 : 0));
     $diffSesssionID = $this->DB->getInsertId();
     //-----------------------------------------
     // XML
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     $xml = new classXML(IPS_DOC_CHAR_SET);
     //-----------------------------------------
     // Check to see if its an archive...
     //-----------------------------------------
     if (strstr($content, "<xmlarchive")) {
         /* It's an archive... */
         require IPS_KERNEL_PATH . 'classXMLArchive.php';
         $xmlArchive = new classXMLArchive(IPS_KERNEL_PATH);
         $xmlArchive->readXML($content);
         /* We just want the templates.. */
         foreach ($xmlArchive->asArray() as $path => $fileData) {
             if ($fileData['path'] == 'templates') {
                 $xml->loadXML($fileData['content']);
                 foreach ($xml->fetchElements('template') as $xmlelement) {
                     $data = $xml->fetchElementsFromRecord($xmlelement);
                     if (is_array($data)) {
                         $templateBits[] = $data;
                     }
                 }
             }
         }
     } else {
         $xml->loadXML($content);
         foreach ($xml->fetchElements('template') as $xmlelement) {
             $data = $xml->fetchElementsFromRecord($xmlelement);
             if (is_array($data)) {
                 $templateBits[] = $data;
             }
         }
     }
     //-----------------------------------------
     // Got anything?
     //-----------------------------------------
     if (!count($templateBits)) {
         return FALSE;
     }
     //-----------------------------------------
     // Build session data
     //-----------------------------------------
     foreach ($templateBits as $bit) {
         $diffKey = $diffSesssionID . ':' . $bit['template_group'] . ':' . $bit['template_name'];
         if (!$seen[$diffKey]) {
             $this->DB->allow_sub_select = 1;
             $this->DB->insert('templates_diff_import', array('diff_key' => $diffKey, 'diff_func_group' => $bit['template_group'], 'diff_func_data' => $bit['template_data'], 'diff_func_name' => $bit['template_name'], 'diff_func_content' => $bit['template_content'], 'diff_session_id' => $diffSesssionID));
             $seen[$diffKey] = 1;
         }
     }
     return $diffSesssionID;
 }
コード例 #16
0
ファイル: badwords.php プロジェクト: ConnorChristie/GrabViews
 /**
  * Import badwords from an xml file
  *
  * @return	@e void
  */
 public function badwordsImport()
 {
     /* Get Badwords XML */
     try {
         $content = $this->registry->adminFunctions->importXml('ipb_badwords.xml');
     } catch (Exception $e) {
         $this->registry->output->showError($e->getMessage());
     }
     /* Check for content */
     if (!$content) {
         $this->registry->output->global_message = $this->lang->words['bwl_upload_failed'];
         $this->badwordsOvervew();
         return;
     }
     //-----------------------------------------
     // Get xml class
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     if (!count($xml->fetchElements('badword'))) {
         $this->registry->output->global_message = $this->lang->words['bwl_upload_wrong'];
         $this->badwordsOvervew();
         return;
     }
     /* Get a list of current badwords */
     $words = array();
     $this->DB->build(array('select' => '*', 'from' => 'badwords', 'order' => 'type'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $words[$r['type']] = 1;
     }
     /* Loop through the xml document and insert new bad words */
     foreach ($xml->fetchElements('badword') as $badword) {
         $entry = $xml->fetchElementsFromRecord($badword);
         /* Get the filter settings */
         $type = $entry['type'];
         $swop = $entry['swop'];
         $m_exact = $entry['m_exact'];
         /* Skip if it's already in the db */
         if ($words[$type]) {
             continue;
         }
         /* Add to the db */
         if ($type) {
             $this->DB->insert('badwords', array('type' => $type, 'swop' => $swop, 'm_exact' => $m_exact));
         }
     }
     /* Rebuild cache and bounce */
     $this->badwordsRebuildCache();
     $this->registry->output->global_message = $this->lang->words['bwl_upload_good'];
     $this->badwordsOvervew();
 }
コード例 #17
0
    /**
     * Public install hook so we can use it in the installer and elsewhere
     *
     * @access	public
     * @param	string		XML data
     * @param	boolean		Add message to output->global_message
     * @param	boolean		Allow skins to recache
     * @param	int			Install enabled
     * @return	void
     */
    public function installHook($content, $addMessage = FALSE, $allowSkinRecache = TRUE, $enabled = 1)
    {
        //-----------------------------------------
        // Hooks directory writable?
        //-----------------------------------------
        if (!is_writable(IPS_HOOKS_PATH)) {
            if (!$addMessage) {
                return false;
            }
            $this->registry->output->showError($this->lang->words['h_dir_notwritable'], 111159);
        }
        //-----------------------------------------
        // Got our hooks?
        //-----------------------------------------
        if (!is_array($this->hooks) or !count($this->hooks)) {
            $this->DB->build(array('select' => '*', 'from' => 'core_hooks'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $this->hooks[$r['hook_key']] = $r;
            }
        }
        //-----------------------------------------
        // Get xml mah-do-dah
        //-----------------------------------------
        require_once IPS_KERNEL_PATH . 'classXML.php';
        $xml = new classXML(IPS_DOC_CHAR_SET);
        //-----------------------------------------
        // Unpack the datafile
        //-----------------------------------------
        $xml->loadXML($content);
        foreach ($xml->fetchElements('config') as $data) {
            $config = $xml->fetchElementsFromRecord($data);
            if (!count($config)) {
                $this->registry->output->showError($this->lang->words['h_xmlwrong'], 1111);
            }
        }
        //-----------------------------------------
        // Temp
        //-----------------------------------------
        $tempExtraData = unserialize($config['hook_extra_data']);
        //-----------------------------------------
        // Set config
        //-----------------------------------------
        $config = array('hook_name' => $config['hook_name'], 'hook_desc' => $config['hook_desc'], 'hook_author' => $config['hook_author'], 'hook_email' => $config['hook_email'], 'hook_website' => $config['hook_website'], 'hook_update_check' => $config['hook_update_check'], 'hook_requirements' => $config['hook_requirements'], 'hook_version_human' => $config['hook_version_human'], 'hook_version_long' => $config['hook_version_long'], 'hook_key' => $config['hook_key'], 'hook_enabled' => $enabled, 'hook_updated' => time());
        $extra_data = array();
        //-----------------------------------------
        // Set files
        //-----------------------------------------
        $files = array();
        foreach ($xml->fetchElements('hookfiles') as $node) {
            foreach ($xml->fetchElements('file', $node) as $_file) {
                $file = $xml->fetchElementsFromRecord($_file);
                if ($file['hook_type']) {
                    $files[] = array('hook_file_real' => $file['hook_file_real'], 'hook_type' => $file['hook_type'], 'hook_classname' => $file['hook_classname'], 'hook_data' => $file['hook_data'], 'hooks_source' => $file['hooks_source']);
                }
            }
        }
        //-----------------------------------------
        // Set the custom script
        //-----------------------------------------
        $custom = array();
        foreach ($xml->fetchElements('hookextras_custom') as $node) {
            foreach ($xml->fetchElements('file', $node) as $_file) {
                $file = $xml->fetchElementsFromRecord($_file);
                if (count($file)) {
                    $custom = array('filename' => $file['filename'], 'source' => $file['source']);
                }
            }
        }
        //-----------------------------------------
        // Set the settings
        //-----------------------------------------
        $settings = array();
        $settingGroups = array();
        foreach ($xml->fetchElements('hookextras_settings') as $node) {
            foreach ($xml->fetchElements('setting', $node) as $_setting) {
                $setting = $xml->fetchElementsFromRecord($_setting);
                if ($setting['conf_is_title'] == 1) {
                    $settingGroups[] = array('conf_title_title' => $setting['conf_title_title'], 'conf_title_desc' => $setting['conf_title_desc'], 'conf_title_noshow' => $setting['conf_title_noshow'], 'conf_title_keyword' => $setting['conf_title_keyword'], 'conf_title_app' => $setting['conf_title_app'], 'conf_title_tab' => $setting['conf_title_tab']);
                } else {
                    $settings[] = array('conf_title' => $setting['conf_title'], 'conf_description' => $setting['conf_description'], 'conf_group' => $setting['conf_group'], 'conf_type' => $setting['conf_type'], 'conf_key' => $setting['conf_key'], 'conf_default' => $setting['conf_default'], 'conf_extra' => $setting['conf_extra'], 'conf_evalphp' => $setting['conf_evalphp'], 'conf_protected' => $setting['conf_protected'], 'conf_position' => $setting['conf_position'], 'conf_start_group' => $setting['conf_start_group'], 'conf_end_group' => $setting['conf_end_group'], 'conf_add_cache' => $setting['conf_add_cache'], 'conf_title_keyword' => $setting['conf_title_keyword']);
                }
            }
        }
        //-----------------------------------------
        // Set the lang bits
        //-----------------------------------------
        $language = array();
        foreach ($xml->fetchElements('hookextras_language') as $node) {
            foreach ($xml->fetchElements('language', $node) as $_langbit) {
                $langbit = $xml->fetchElementsFromRecord($_langbit);
                $language[] = array('word_app' => $langbit['word_app'], 'word_pack' => $langbit['word_pack'], 'word_key' => $langbit['word_key'], 'word_default' => $langbit['word_default'], 'word_custom' => $langbit['word_custom'], 'word_js' => $langbit['word_js']);
            }
        }
        //-----------------------------------------
        // Set the modules
        //-----------------------------------------
        $modules = array();
        foreach ($xml->fetchElements('hookextras_modules') as $node) {
            foreach ($xml->fetchElements('module', $node) as $_module) {
                $module = $xml->fetchElementsFromRecord($_module);
                $modules[] = array('sys_module_title' => $module['sys_module_title'], 'sys_module_application' => $module['sys_module_application'], 'sys_module_key' => $module['sys_module_key'], 'sys_module_description' => $module['sys_module_description'], 'sys_module_version' => $module['sys_module_version'], 'sys_module_parent' => $module['sys_module_parent'], 'sys_module_protected' => $module['sys_module_protected'], 'sys_module_visible' => $module['sys_module_visible'], 'sys_module_tables' => $module['sys_module_tables'], 'sys_module_hooks' => $module['sys_module_hooks'], 'sys_module_position' => $module['sys_module_position'], 'sys_module_admin' => $module['sys_module_admin']);
            }
        }
        //-----------------------------------------
        // Set the help files
        //-----------------------------------------
        $help = array();
        foreach ($xml->fetchElements('hookextras_help') as $node) {
            foreach ($xml->fetchElements('help', $node) as $_helpfile) {
                $helpfile = $xml->fetchElementsFromRecord($_helpfile);
                $help[] = array('title' => $helpfile['title'], 'text' => $helpfile['text'], 'description' => $helpfile['description'], 'position' => $helpfile['position']);
            }
        }
        //-----------------------------------------
        // Set the templates
        //-----------------------------------------
        $templates = array();
        foreach ($xml->fetchElements('hookextras_templates') as $node) {
            foreach ($xml->fetchElements('templates', $node) as $_template) {
                $template = $xml->fetchElementsFromRecord($_template);
                $templates[] = array('template_set_id' => 0, 'template_group' => $template['template_group'], 'template_content' => $template['template_content'], 'template_name' => $template['template_name'], 'template_data' => $template['template_data'], 'template_updated' => $template['template_updated'], 'template_removable' => $template['template_removable'], 'template_added_to' => $template['template_added_to'], 'template_user_added' => 1, 'template_user_edited' => 0);
            }
        }
        //-----------------------------------------
        // Set the tasks
        //-----------------------------------------
        $tasks = array();
        foreach ($xml->fetchElements('hookextras_tasks') as $node) {
            foreach ($xml->fetchElements('tasks', $node) as $_task) {
                $task = $xml->fetchElementsFromRecord($_task);
                $tasks[] = array('task_title' => $task['task_title'], 'task_file' => $task['task_file'], 'task_week_day' => $task['task_week_day'], 'task_month_day' => $task['task_month_day'], 'task_hour' => $task['task_hour'], 'task_minute' => $task['task_minute'], 'task_cronkey' => $task['task_cronkey'], 'task_log' => $task['task_log'], 'task_description' => $task['task_description'], 'task_enabled' => $task['task_enabled'], 'task_key' => $task['task_key'], 'task_safemode' => $task['task_safemode'], 'task_locked' => $task['task_locked'], 'task_application' => $task['task_application']);
            }
        }
        //-----------------------------------------
        // Set the database changes
        //-----------------------------------------
        $database = array('create' => array(), 'alter' => array(), 'update' => array(), 'insert' => array());
        foreach ($xml->fetchElements('hookextras_database_create') as $node) {
            foreach ($xml->fetchElements('create', $node) as $_table) {
                $table = $xml->fetchElementsFromRecord($_table);
                $database['create'][] = array('name' => $table['name'], 'fields' => $table['fields'], 'tabletype' => $table['tabletype']);
            }
        }
        foreach ($xml->fetchElements('hookextras_database_alter') as $node) {
            foreach ($xml->fetchElements('alter', $node) as $_table) {
                $table = $xml->fetchElementsFromRecord($_table);
                $database['alter'][] = array('altertype' => $table['altertype'], 'table' => $table['table'], 'field' => $table['field'], 'newfield' => $table['newfield'], 'fieldtype' => $table['fieldtype'], 'default' => $table['default']);
            }
        }
        foreach ($xml->fetchElements('hookextras_database_update') as $node) {
            foreach ($xml->fetchElements('update', $node) as $_table) {
                $table = $xml->fetchElementsFromRecord($_table);
                $database['update'][] = array('table' => $table['table'], 'field' => $table['field'], 'newvalue' => $table['newvalue'], 'oldvalue' => $table['oldvalue'], 'where' => $table['where']);
            }
        }
        foreach ($xml->fetchElements('hookextras_database_insert') as $node) {
            foreach ($xml->fetchElements('insert', $node) as $_table) {
                $table = $xml->fetchElementsFromRecord($_table);
                $database['insert'][] = array('table' => $table['table'], 'updates' => $table['updates'], 'fordelete' => $table['fordelete']);
            }
        }
        //-----------------------------------------
        // Set some vars for display tallies
        //-----------------------------------------
        $filesInserted = 0;
        $settingGroupsInserted = 0;
        $settingsInserted = 0;
        $settingsUpdated = 0;
        $languageInserted = 0;
        $languageUpdated = 0;
        $modulesInserted = 0;
        $modulesUpdated = 0;
        $helpInserted = 0;
        $helpUpdated = 0;
        $templatesInserted = 0;
        $templatesUpdated = 0;
        $templateHooks = 0;
        $tasksInserted = 0;
        $tasksUpdated = 0;
        $createQueries = 0;
        $alterQueries = 0;
        $updateQueries = 0;
        $insertQueries = 0;
        //-----------------------------------------
        // Need to recache skins?
        //-----------------------------------------
        foreach ($files as $_f) {
            if ($_f['hook_type'] and $_f['hook_type'] == 'templateHooks') {
                $templateHooks++;
            }
        }
        //-----------------------------------------
        // Insert/update DB records
        //-----------------------------------------
        if ($this->hooks[$config['hook_key']]['hook_id']) {
            //-----------------------------------------
            // Don't change enabled/disabled status
            //-----------------------------------------
            unset($config['hook_enabled']);
            $this->DB->update('core_hooks', $config, 'hook_id=' . $this->hooks[$config['hook_key']]['hook_id']);
            $hook_id = $this->hooks[$config['hook_key']]['hook_id'];
            $extra_data = unserialize($this->hooks[$config['hook_key']]['hook_extra_data']);
        } else {
            $config['hook_installed'] = time();
            $this->hook[$config['hook_key']] = $config;
            $this->DB->insert('core_hooks', $config);
            $hook_id = $this->DB->getInsertId();
            $this->hook[$config['hook_key']]['hook_id'] = $hook_id;
            $extra_data['display'] = $tempExtraData['display'];
        }
        if (count($files)) {
            //-----------------------------------------
            // If we are updating, remove old files
            //-----------------------------------------
            if ($this->hooks[$config['hook_key']]['hook_id']) {
                $this->DB->build(array('select' => 'hook_file_id, hook_file_stored', 'from' => 'core_hooks_files', 'where' => 'hook_hook_id=' . $this->hooks[$config['hook_key']]['hook_id']));
                $outer = $this->DB->execute();
                while ($r = $this->DB->fetch($outer)) {
                    @unlink(IPS_HOOKS_PATH . $r['hook_file_stored']);
                    $this->DB->delete('core_hooks_files', 'hook_file_id=' . $r['hook_file_id']);
                }
            }
            foreach ($files as $file) {
                //-----------------------------------------
                // Store new files
                //-----------------------------------------
                $filename = $file['hook_classname'] . '_' . md5(uniqid(microtime(), true)) . '.php';
                file_put_contents(IPS_HOOKS_PATH . $filename, $file['hooks_source']);
                chmod(IPS_HOOKS_PATH . $filename, 0777);
                $file['hook_file_stored'] = $filename;
                $file['hook_hook_id'] = $hook_id;
                $this->DB->insert('core_hooks_files', $file);
                $filesInserted++;
            }
        }
        //-----------------------------------------
        // Put custom install/uninstall file
        //-----------------------------------------
        if ($custom['source'] and $custom['filename']) {
            file_put_contents(IPS_HOOKS_PATH . "install_" . $custom['filename'], $custom['source']);
        }
        //-----------------------------------------
        // (1) Settings
        //-----------------------------------------
        if (count($settingGroups) or count($settings)) {
            $setting_groups = array();
            $this->DB->build(array('select' => '*', 'from' => 'core_sys_settings_titles', 'order' => 'conf_title_title'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $setting_groups[$r['conf_title_id']] = $r;
                $setting_groups_by_key[$r['conf_title_keyword']] = $r;
            }
            //-----------------------------------------
            // Get current settings.
            //-----------------------------------------
            $this->DB->build(array('select' => 'conf_id, conf_key', 'from' => 'core_sys_conf_settings', 'order' => 'conf_id'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $cur_settings[$r['conf_key']] = $r['conf_id'];
            }
        }
        if (count($settingGroups)) {
            $need_to_update = array();
            foreach ($settingGroups as $data) {
                if ($data['conf_title_title'] and $data['conf_title_keyword']) {
                    //-----------------------------------------
                    // Get ID based on key
                    //-----------------------------------------
                    $conf_id = $setting_groups_by_key[$data['conf_title_keyword']]['conf_title_id'];
                    $save = array('conf_title_title' => $data['conf_title_title'], 'conf_title_desc' => $data['conf_title_desc'], 'conf_title_keyword' => $data['conf_title_keyword'], 'conf_title_app' => $data['conf_title_app'], 'conf_title_tab' => $data['conf_title_tab'], 'conf_title_noshow' => $data['conf_title_noshow']);
                    //-----------------------------------------
                    // Not got a row, insert first!
                    //-----------------------------------------
                    if (!$conf_id) {
                        $this->DB->insert('core_sys_settings_titles', $save);
                        $conf_id = $this->DB->getInsertId();
                        $settingGroupsInserted++;
                        $extra_data['settingGroups'][] = $conf_id;
                    } else {
                        //-----------------------------------------
                        // Update...
                        //-----------------------------------------
                        $this->DB->update('core_sys_settings_titles', $save, 'conf_title_id=' . $conf_id);
                    }
                    //-----------------------------------------
                    // Update settings cache
                    //-----------------------------------------
                    $save['conf_title_id'] = $conf_id;
                    $setting_groups_by_key[$save['conf_title_keyword']] = $save;
                    $setting_groups[$save['conf_title_id']] = $save;
                    //-----------------------------------------
                    // Set need update...
                    //-----------------------------------------
                    $need_update[] = $conf_id;
                }
            }
        }
        if (count($settings)) {
            foreach ($settings as $idx => $data) {
                $data['conf_group'] = $setting_groups_by_key[$data['conf_title_keyword']]['conf_title_id'];
                //-----------------------------------------
                // Remove from array
                //-----------------------------------------
                unset($data['conf_title_keyword']);
                if ($cur_settings[$data['conf_key']]) {
                    $this->DB->update('core_sys_conf_settings', $data, 'conf_id=' . $cur_settings[$data['conf_key']]);
                    $settingsUpdated++;
                } else {
                    $this->DB->insert('core_sys_conf_settings', $data);
                    $settingsInserted++;
                    $conf_id = $this->DB->getInsertId();
                    $extra_data['settings'][] = $conf_id;
                }
            }
        }
        //-----------------------------------------
        // Update group counts...
        //-----------------------------------------
        if (count($need_update)) {
            foreach ($need_update as $i => $idx) {
                $conf = $this->DB->buildAndFetch(array('select' => 'count(*) as count', 'from' => 'core_sys_conf_settings', 'where' => 'conf_group=' . $idx));
                $count = intval($conf['count']);
                $this->DB->update('core_sys_settings_titles', array('conf_title_count' => $count), 'conf_title_id=' . $idx);
            }
        }
        if (count($settingGroups) or count($settings)) {
            $this->cache->rebuildCache('settings', 'global');
        }
        //-----------------------------------------
        // (2) Languages
        //-----------------------------------------
        if (count($language)) {
            $langPacks = array();
            $this->DB->build(array('select' => 'lang_id', 'from' => 'core_sys_lang'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $langPacks[] = $r['lang_id'];
            }
            foreach ($language as $langbit) {
                foreach ($langPacks as $lang_id) {
                    $langbit['lang_id'] = $lang_id;
                    // See if it exists
                    $cnt = $this->DB->buildAndFetch(array('select' => 'word_id', 'from' => 'core_sys_lang_words', 'where' => "lang_id={$lang_id} AND word_app='{$langbit['word_app']}' AND word_key='{$langbit['word_key']}' AND word_pack='{$langbit['word_pack']}'"));
                    if ($cnt['word_id']) {
                        $this->DB->update('core_sys_lang_words', $langbit, 'word_id=' . $cnt['word_id']);
                        $languageUpdated++;
                    } else {
                        $this->DB->insert('core_sys_lang_words', $langbit);
                        $languageInserted++;
                        $word_id = $this->DB->getInsertId();
                        $extra_data['language'][$langbit['word_pack']][] = $langbit['word_key'];
                    }
                }
            }
            require_once IPSLib::getAppDir('core') . '/modules_admin/languages/manage_languages.php';
            $langLib = new admin_core_languages_manage_languages($this->registry);
            $langLib->makeRegistryShortcuts($this->registry);
            foreach ($langPacks as $langId) {
                $langLib->cacheToDisk($langId);
            }
        }
        //-----------------------------------------
        // (3) Modules
        //-----------------------------------------
        if (count($modules)) {
            //-----------------------------------------
            // Get current modules
            //-----------------------------------------
            $this->DB->build(array('select' => '*', 'from' => 'core_sys_module', 'order' => 'sys_module_id'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $cur_modules[$r['sys_module_application']][$r['sys_module_key']] = $r['sys_module_id'];
            }
            foreach ($modules as $module) {
                //-----------------------------------------
                // Insert or update?
                //-----------------------------------------
                if ($cur_modules[$module['sys_module_application']][$module['sys_module_key']]) {
                    $this->DB->update('core_sys_module', $module, "sys_module_id=" . $cur_modules[$module['sys_module_application']][$module['sys_module_key']]);
                    $modulesUpdated++;
                } else {
                    $this->DB->insert('core_sys_module', $module);
                    $modulesInserted++;
                    $module_id = $this->DB->getInsertId();
                    $extra_data['modules'][] = $module_id;
                }
            }
            require_once IPSLib::getAppDir('core') . '/modules_admin/applications/applications.php';
            $moduleLib = new admin_core_applications_applications($this->registry);
            $moduleLib->makeRegistryShortcuts($this->registry);
            $moduleLib->moduleRecache();
            $moduleLib->applicationsMenuDataRecache();
        }
        //-----------------------------------------
        // (4) Help Files
        //-----------------------------------------
        if (count($help)) {
            $keys = array();
            $this->DB->build(array('select' => 'title', 'from' => 'faq'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $keys[] = $r['title'];
            }
            foreach ($help as $entry) {
                if (in_array($entry['title'], $keys)) {
                    $this->DB->update('faq', $entry, "title='{$entry['title']}'");
                    $helpUpdated++;
                } else {
                    $this->DB->insert('faq', $entry);
                    $helpInserted++;
                    $help_id = $this->DB->getInsertId();
                    $extra_data['help'][] = $help_id;
                }
            }
        }
        //-----------------------------------------
        // (6) Templates
        //-----------------------------------------
        if (count($templates)) {
            $bits = array();
            $this->DB->build(array('select' => 'template_name,template_group', 'from' => 'skin_templates', 'where' => 'template_set_id=0'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $bits[$r['template_group']][] = $r['template_name'];
            }
            foreach ($templates as $template) {
                if (is_array($bits[$template['template_group']]) and in_array($template['template_name'], $bits[$template['template_group']])) {
                    $this->DB->update('skin_templates', $template, "template_group='{$template['template_group']}' AND template_name='{$template['template_name']}'");
                    $templatesUpdated++;
                } else {
                    $this->DB->insert('skin_templates', $template);
                    $templatesInserted++;
                    $template_id = $this->DB->getInsertId();
                    $extra_data['templates'][$template['template_group']][] = $template['template_name'];
                }
            }
        }
        //-----------------------------------------
        // (7) Tasks
        //-----------------------------------------
        if (count($tasks)) {
            $keys = array();
            $this->DB->build(array('select' => 'task_key', 'from' => 'task_manager'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $keys[] = $r['task_key'];
            }
            foreach ($tasks as $entry) {
                if (in_array($entry['task_key'], $keys)) {
                    $this->DB->update('task_manager', $entry, "task_key='{$entry['task_key']}'");
                    $tasksUpdated++;
                } else {
                    $this->DB->insert('task_manager', $entry);
                    $tasksInserted++;
                    $task_id = $this->DB->getInsertId();
                    $extra_data['tasks'][] = $task_id;
                }
            }
        }
        //-----------------------------------------
        // (8) Create new tables
        //-----------------------------------------
        if (count($database['create'])) {
            foreach ($database['create'] as $create) {
                $query = "CREATE TABLE {$create['name']} (\n\t\t\t\t\t\t\t{$create['fields']}\n\t\t\t\t\t\t\t)";
                if ($tabletype) {
                    $query .= " TYPE=" . $create['tabletype'];
                }
                //-----------------------------------------
                // Fix prefix
                //-----------------------------------------
                $query = preg_replace("#^CREATE TABLE(?:\\s+?)?(\\S+?)#s", "CREATE TABLE " . $this->settings['sql_tbl_prefix'] . "\\1", $query);
                $this->DB->return_die = true;
                $this->DB->query($query);
                $this->DB->return_die = false;
                $createQueries++;
                $extra_data['database']['create'][] = $create;
            }
        }
        //-----------------------------------------
        // (9) Alter tables
        //-----------------------------------------
        if (count($database['alter'])) {
            foreach ($database['alter'] as $alter) {
                $this->DB->return_die = true;
                switch ($alter['altertype']) {
                    case 'remove':
                        $this->DB->dropField($alter['table'], $alter['field']);
                        break;
                    case 'add':
                        $this->DB->addField($alter['table'], $alter['field'], $alter['fieldtype'], $alter['default']);
                        break;
                    case 'change':
                        $this->DB->changeField($alter['table'], $alter['field'], $alter['newfield'], $alter['fieldtype'], $alter['default']);
                        break;
                }
                $this->DB->return_die = false;
                $alterQueries++;
                $extra_data['database']['alter'][] = $alter;
            }
        }
        //-----------------------------------------
        // (10) Run update queries
        //-----------------------------------------
        if (count($database['update'])) {
            foreach ($database['update'] as $update) {
                $this->DB->return_die = true;
                $this->DB->update($update['table'], array($update['field'] => $update['newvalue']), html_entity_decode($update['where'], ENT_QUOTES));
                $this->DB->return_die = false;
                $updateQueries++;
                $extra_data['database']['update'][] = $update;
            }
        }
        //-----------------------------------------
        // (11) Run insert queries
        //-----------------------------------------
        if (!$this->hooks[$config['hook_key']]['hook_id']) {
            if (count($database['insert'])) {
                foreach ($database['insert'] as $insert) {
                    $fields = array();
                    $content = explode(',', $insert['updates']);
                    foreach ($content as $value) {
                        list($field, $toInsert) = explode('=', $value);
                        $fields[$field] = $toInsert;
                    }
                    $this->DB->return_die = true;
                    $this->DB->insert($insert['table'], $fields);
                    $this->DB->return_die = false;
                    $insertQueries++;
                    $extra_data['database']['insert'][] = $insert;
                }
            }
        }
        if ($custom['filename'] and file_exists(IPS_HOOKS_PATH . 'install_' . $custom['filename'])) {
            require_once IPS_HOOKS_PATH . 'install_' . $custom['filename'];
            $classname = str_replace('.php', '', $custom['filename']);
            if (class_exists($classname)) {
                $install = new $classname($this->registry);
                if (method_exists($install, 'install')) {
                    $install->install();
                }
            }
        }
        if (count($extra_data)) {
            $this->DB->update('core_hooks', array('hook_extra_data' => serialize($extra_data)), 'hook_id=' . $hook_id);
        }
        //print_r($config);
        //print_r($files);
        //print_r($custom);
        //print_r($settingGroups);
        //print_r($settings);
        //print_r($language);
        //print_r($modules);
        //print_r($templates);
        //print_r($tasks);
        //print_r($help);
        //print_r($database);
        if ($addMessage) {
            $this->registry->output->global_message = <<<EOF
\t\t{$this->lang->words['h_followacts']}
\t\t<ul>
\t\t\t<li>{$this->lang->words['h_newhookin']}</li>
\t\t\t<li>{$filesInserted} {$this->lang->words['h_filesin']}</li>
\t\t\t<li>{$settingGroupsInserted} {$this->lang->words['h_settinggin']}</li>
\t\t\t<li>{$settingsInserted} {$this->lang->words['h_settingin']}</li>
\t\t\t<li>{$settingsUpdated} {$this->lang->words['h_settingup']}</li>
\t\t\t<li>{$languageInserted} {$this->lang->words['h_langbitin']}</li>
\t\t\t<li>{$languageUpdated} {$this->lang->words['h_langbitup']}</li>
\t\t\t<li>{$modulesInserted} {$this->lang->words['h_modin']}</li>
\t\t\t<li>{$modulesUpdated} {$this->lang->words['h_modup']}</li>
\t\t\t<li>{$helpInserted} {$this->lang->words['h_helpin']}</li>
\t\t\t<li>{$helpUpdated} {$this->lang->words['h_helpup']}</li>
\t\t\t<li>{$templatesInserted} {$this->lang->words['h_tempin']}</li>
\t\t\t<li>{$templatesUpdated} {$this->lang->words['h_tempup']}</li>
\t\t\t<li>{$tasksInserted} {$this->lang->words['h_taskin']}</li>
\t\t\t<li>{$tasksUpdated} {$this->lang->words['h_taskup']}</li>
\t\t\t<li>{$createQueries} {$this->lang->words['h_dbcreated']}</li>
\t\t\t<li>{$alterQueries} {$this->lang->words['h_dbaltered']}</li>
\t\t\t<li>{$updateQueries} {$this->lang->words['h_updateran']}</li>
\t\t\t<li>{$insertQueries} {$this->lang->words['h_insertran']}</li>
\t\t</ul>
EOF;
            //-----------------------------------------
            // Got some skin recaching to do...
            //-----------------------------------------
            if ($allowSkinRecache === TRUE and ($templatesInserted or $templatesUpdated or $templateHooks)) {
                //-----------------------------------------
                // Recache hooks so templates know that there
                // are comments to preserve
                //-----------------------------------------
                $this->rebuildHooksCache();
                //-----------------------------------------
                // Get the libs
                //-----------------------------------------
                require_once IPS_ROOT_PATH . 'sources/classes/skins/skinFunctions.php';
                require_once IPS_ROOT_PATH . 'sources/classes/skins/skinCaching.php';
                $skinCaching = new skinCaching($this->registry);
                //-----------------------------------------
                // Find first skin id
                //-----------------------------------------
                ksort($this->registry->output->allSkins);
                $_skins = $this->registry->output->allSkins;
                $_set = array_shift($_skins);
                $setID = $_set['set_id'];
                $skinCaching->rebuildPHPTemplates($setID);
                /* Fetch next id */
                $nextID = $setID;
                ksort($this->registry->output->allSkins);
                foreach ($this->registry->output->allSkins as $id => $data) {
                    if ($id > $nextID) {
                        $nextID = $id;
                        break;
                    }
                }
                //-----------------------------------------
                // Have more than one skin
                //-----------------------------------------
                if ($nextID != $setID) {
                    //-----------------------------------------
                    // Save hook import messages
                    //-----------------------------------------
                    ipsRegistry::getClass('adminFunctions')->staffSaveCookie('hookResult', $this->registry->output->global_message);
                    //-----------------------------------------
                    // Wipe out the messages
                    //-----------------------------------------
                    $this->registry->output->global_message = '';
                    //-----------------------------------------
                    // Redirect to rebuild skins
                    //-----------------------------------------
                    $this->registry->getClass('class_localization')->loadLanguageFile(array('admin_templates'));
                    $this->registry->output->redirect($this->settings['base_url'] . 'app=core&module=applications&section=hooks&do=skinsRebuild&setID=' . $nextID, $this->lang->words['to_recachedset'] . $this->registry->output->allSkins[$setID]['set_name']);
                }
            }
        }
    }
コード例 #18
0
ファイル: install.php プロジェクト: Advanture/Online-RolePlay
 /**
  * Install Other stuff
  *
  * @return void
  */
 public function install_other()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $previous = $_REQUEST['previous'];
     //-----------------------------------------
     // HOOKS: Fetch next 'un
     //-----------------------------------------
     $next = IPSSetUp::fetchNextApplication($previous, 'hooks.xml', $this->settings['gb_char_set']);
     /* Set up DB driver */
     $extra_install = $this->_setUpDBDriver(FALSE);
     //-----------------------------------------
     // Insert tasks
     //-----------------------------------------
     if ($next['key']) {
         $output[] = $next['title'] . ": Добавление модификаций";
         $_PATH = IPSLib::getAppDir($next['key']) . '/xml/';
         if (is_file($_PATH . 'hooks.xml')) {
             //-----------------------------------------
             // Adjust the table?
             //-----------------------------------------
             if ($extra_install and method_exists($extra_install, 'before_inserts_run')) {
                 $q = $extra_install->before_inserts_run('hooks');
             }
             //-----------------------------------------
             // Continue
             //-----------------------------------------
             require_once IPS_ROOT_PATH . 'applications/core/modules_admin/applications/hooks.php';
             /*noLibHook*/
             $hooks = new admin_core_applications_hooks();
             $hooks->makeRegistryShortcuts($this->registry);
             $result = $hooks->installAppHooks($next['key']);
             $output[] = "Модификации " . $next['title'] . ": " . $result['inserted'] . " добавлено";
             //-----------------------------------------
             // Adjust the table?
             //-----------------------------------------
             if ($extra_install and method_exists($extra_install, 'after_inserts_run')) {
                 $q = $extra_install->after_inserts_run('hooks');
             }
         }
         //-----------------------------------------
         // Done.. so get some more!
         //-----------------------------------------
         $this->_finishStep($output, "Установка: Модификации", 'install&do=other&previous=' . $next['key']);
     } else {
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         //-----------------------------------------
         // ****** LOG IN MODULES
         //-----------------------------------------
         $output[] = "Добавление модулей авторизации";
         $xml = new classXML(IPSSetUp::charSet);
         //-----------------------------------------
         // Adjust the table?
         //-----------------------------------------
         if ($extra_install and method_exists($extra_install, 'before_inserts_run')) {
             $q = $extra_install->before_inserts_run('login');
         }
         //-----------------------------------------
         // Continue
         //-----------------------------------------
         $xml->load(IPS_ROOT_PATH . 'setup/xml/loginauth.xml');
         foreach ($xml->fetchElements('login_methods') as $xmlelement) {
             $data = $xml->fetchElementsFromRecord($xmlelement);
             unset($data['login_id']);
             unset($data['login_date']);
             $this->DB->insert('login_methods', $data);
         }
         //-----------------------------------------
         // Adjust the table?
         //-----------------------------------------
         if ($extra_install and method_exists($extra_install, 'after_inserts_run')) {
             $q = $extra_install->after_inserts_run('login');
         }
         //-----------------------------------------
         // ****** USER AGENTS
         //-----------------------------------------
         $output[] = "Добавление user-agent`ов по-умолчанию";
         $xml = new classXML(IPSSetUp::charSet);
         if ($extra_install and method_exists($extra_install, 'before_inserts_run')) {
             $q = $extra_install->before_inserts_run('useragents');
         }
         require_once IPS_ROOT_PATH . 'sources/classes/useragents/userAgentFunctions.php';
         /*noLibHook*/
         $userAgentFunctions = new userAgentFunctions($this->registry);
         $userAgentFunctions->rebuildMasterUserAgents();
         if ($extra_install and method_exists($extra_install, 'after_inserts_run')) {
             $q = $extra_install->after_inserts_run('useragents');
         }
         //-----------------------------------------
         // ****** ATTACHMENTS
         //-----------------------------------------
         $output[] = "Добавление типов прикрепляемых файлов";
         if ($extra_install and method_exists($extra_install, 'before_inserts_run')) {
             $q = $extra_install->before_inserts_run('attachments');
         }
         $xml = new classXML(IPSSetUp::charSet);
         $xml->load(IPS_ROOT_PATH . 'setup/xml/attachments.xml');
         foreach ($xml->fetchElements('attachtype') as $xmlelement) {
             $data = $xml->fetchElementsFromRecord($xmlelement);
             unset($data['atype_id']);
             $this->DB->insert('attachments_type', $data);
         }
         if ($extra_install and method_exists($extra_install, 'after_inserts_run')) {
             $q = $extra_install->after_inserts_run('attachments');
         }
         //-----------------------------------------
         // Build Calendar RSS
         //-----------------------------------------
         if (IPSLib::appIsInstalled('calendar')) {
             require_once IPSLib::getAppDir('calendar') . '/modules_admin/calendar/calendars.php';
             /*noLibHook*/
             $cal = new admin_calendar_calendar_calendars();
             $cal->makeRegistryShortcuts($this->registry);
             $output[] = "Обновление RSS календаря";
             $cal->calendarRSSCache();
         }
         /* If this is windows, change the locale for the language pack */
         if (strpos(strtolower(PHP_OS), 'win') === 0) {
             $this->DB->update('core_sys_lang', array('lang_short' => 'Russian_Russia.65001'), 'lang_id=1');
         } else {
             $this->DB->update('core_sys_lang', array('lang_short' => 'ru_RU.UTF-8'), 'lang_id=1');
         }
     }
     //-----------------------------------------
     // Next...
     //-----------------------------------------
     $this->_finishStep($output, "Установка: Другие данные", 'install&do=caches');
 }
コード例 #19
0
ファイル: hooks.php プロジェクト: ConnorChristie/GrabViews
    /**
     * Public install hook so we can use it in the installer and elsewhere
     *
     * @param	string		XML data
     * @param	boolean		Add message to output->global_message
     * @param	boolean		Allow skins to recache
     * @param	int			Install enabled
     * @return	@e void
     */
    public function installHook($content, $addMessage = FALSE, $allowSkinRecache = TRUE, $enabled = 1)
    {
        //-----------------------------------------
        // Hooks directory writable?
        //-----------------------------------------
        if (!is_writable(IPS_HOOKS_PATH)) {
            if (!$addMessage) {
                return false;
            }
            $this->registry->output->showError($this->lang->words['h_dir_notwritable'], 111159);
        }
        //-----------------------------------------
        // Got our hooks?
        //-----------------------------------------
        if (!is_array($this->hooks) or !count($this->hooks)) {
            $this->DB->build(array('select' => '*', 'from' => 'core_hooks'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $this->hooks[$r['hook_key']] = $r;
            }
        }
        //-----------------------------------------
        // Get xml mah-do-dah
        //-----------------------------------------
        require_once IPS_KERNEL_PATH . 'classXML.php';
        /*noLibHook*/
        $xml = new classXML(IPS_DOC_CHAR_SET);
        //-----------------------------------------
        // Unpack the datafile
        //-----------------------------------------
        $xml->loadXML($content);
        foreach ($xml->fetchElements('config') as $data) {
            $config = $xml->fetchElementsFromRecord($data);
            if (!count($config)) {
                $this->registry->output->showError($this->lang->words['h_xmlwrong'], 1111);
            }
        }
        //-----------------------------------------
        // Temp
        //-----------------------------------------
        $tempExtraData = unserialize($config['hook_extra_data']);
        //-----------------------------------------
        // Set config
        //-----------------------------------------
        $config = array('hook_name' => $config['hook_name'], 'hook_desc' => $config['hook_desc'], 'hook_author' => $config['hook_author'], 'hook_email' => $config['hook_email'], 'hook_website' => $config['hook_website'], 'hook_update_check' => $config['hook_update_check'], 'hook_requirements' => $config['hook_requirements'], 'hook_version_human' => $config['hook_version_human'], 'hook_version_long' => $config['hook_version_long'], 'hook_key' => $config['hook_key'], 'hook_global_caches' => $config['hook_global_caches'], 'hook_enabled' => $enabled, 'hook_updated' => IPS_UNIX_TIME_NOW);
        $extra_data = array();
        //-----------------------------------------
        // Set files
        //-----------------------------------------
        $files = array();
        foreach ($xml->fetchElements('hookfiles') as $node) {
            foreach ($xml->fetchElements('file', $node) as $_file) {
                $file = $xml->fetchElementsFromRecord($_file);
                if ($file['hook_type']) {
                    $files[] = array('hook_file_real' => $file['hook_file_real'], 'hook_type' => $file['hook_type'], 'hook_classname' => $file['hook_classname'], 'hook_data' => $file['hook_data'], 'hooks_source' => $file['hooks_source']);
                }
            }
        }
        //-----------------------------------------
        // Set the custom script
        //-----------------------------------------
        $custom = array();
        $customClass = null;
        foreach ($xml->fetchElements('hookextras_custom') as $node) {
            foreach ($xml->fetchElements('file', $node) as $_file) {
                $file = $xml->fetchElementsFromRecord($_file);
                if (count($file)) {
                    $custom = array('filename' => $file['filename'], 'source' => $file['source']);
                }
            }
        }
        /* Got any custom file to initialize? */
        if ($custom['filename'] && $custom['source']) {
            # Our dirty trick to avoid saving the file on disk just yet...
            $_custom = preg_replace('#^(\\s*)<\\?(php)+#i', '', $custom['source']);
            eval($_custom);
            $classname = str_replace('.php', '', $custom['filename']);
            if (class_exists($classname)) {
                $customClass = new $classname($this->registry);
                if (method_exists($customClass, 'pre_install')) {
                    $customClass->pre_install();
                }
            }
        }
        //-----------------------------------------
        // Set the settings
        //-----------------------------------------
        $settings = array();
        $settingGroups = array();
        foreach ($xml->fetchElements('hookextras_settings') as $node) {
            foreach ($xml->fetchElements('setting', $node) as $_setting) {
                $setting = $xml->fetchElementsFromRecord($_setting);
                if ($setting['conf_is_title'] == 1) {
                    $settingGroups[] = array('conf_title_title' => $setting['conf_title_title'], 'conf_title_desc' => $setting['conf_title_desc'], 'conf_title_noshow' => $setting['conf_title_noshow'], 'conf_title_keyword' => $setting['conf_title_keyword'], 'conf_title_app' => $setting['conf_title_app'], 'conf_title_tab' => $setting['conf_title_tab']);
                } else {
                    $settings[] = array('conf_title' => $setting['conf_title'], 'conf_description' => $setting['conf_description'], 'conf_group' => $setting['conf_group'], 'conf_type' => $setting['conf_type'], 'conf_key' => $setting['conf_key'], 'conf_default' => $setting['conf_default'], 'conf_extra' => $setting['conf_extra'], 'conf_evalphp' => $setting['conf_evalphp'], 'conf_protected' => $setting['conf_protected'], 'conf_position' => $setting['conf_position'], 'conf_start_group' => $setting['conf_start_group'], 'conf_add_cache' => $setting['conf_add_cache'], 'conf_title_keyword' => $setting['conf_title_keyword']);
                }
            }
        }
        //-----------------------------------------
        // Set the lang bits
        //-----------------------------------------
        $language = array();
        foreach ($xml->fetchElements('hookextras_language') as $node) {
            foreach ($xml->fetchElements('language', $node) as $_langbit) {
                $langbit = $xml->fetchElementsFromRecord($_langbit);
                $language[] = array('word_app' => $langbit['word_app'], 'word_pack' => $langbit['word_pack'], 'word_key' => $langbit['word_key'], 'word_default' => $langbit['word_default'], 'word_custom' => $langbit['word_custom'], 'word_js' => intval($langbit['word_js']));
            }
        }
        //-----------------------------------------
        // Set the modules
        //-----------------------------------------
        $modules = array();
        foreach ($xml->fetchElements('hookextras_modules') as $node) {
            foreach ($xml->fetchElements('module', $node) as $_module) {
                $module = $xml->fetchElementsFromRecord($_module);
                $modules[] = array('sys_module_title' => $module['sys_module_title'], 'sys_module_application' => $module['sys_module_application'], 'sys_module_key' => $module['sys_module_key'], 'sys_module_description' => $module['sys_module_description'], 'sys_module_version' => $module['sys_module_version'], 'sys_module_protected' => $module['sys_module_protected'], 'sys_module_visible' => $module['sys_module_visible'], 'sys_module_position' => $module['sys_module_position'], 'sys_module_admin' => $module['sys_module_admin']);
            }
        }
        //-----------------------------------------
        // Set the help files
        //-----------------------------------------
        $help = array();
        foreach ($xml->fetchElements('hookextras_help') as $node) {
            foreach ($xml->fetchElements('help', $node) as $_helpfile) {
                $helpfile = $xml->fetchElementsFromRecord($_helpfile);
                $help[] = array('title' => $helpfile['title'], 'text' => $helpfile['text'], 'description' => $helpfile['description'], 'position' => $helpfile['position']);
            }
        }
        //-----------------------------------------
        // Set the templates
        //-----------------------------------------
        $templates = array();
        foreach ($xml->fetchElements('hookextras_templates') as $node) {
            foreach ($xml->fetchElements('templates', $node) as $_template) {
                $template = $xml->fetchElementsFromRecord($_template);
                $templates[] = array('template_set_id' => 0, 'template_group' => $template['template_group'], 'template_content' => $template['template_content'], 'template_name' => $template['template_name'], 'template_data' => $template['template_data'], 'template_updated' => $template['template_updated'], 'template_removable' => $template['template_removable'], 'template_added_to' => intval($template['template_added_to']), 'template_user_added' => 1, 'template_user_edited' => 0, 'template_master_key' => $template['template_master_key'] ? $template['template_master_key'] : 'root');
            }
        }
        //-----------------------------------------
        // Set the CSS
        //-----------------------------------------
        $css = array();
        foreach ($xml->fetchElements('hookextras_css') as $node) {
            foreach ($xml->fetchElements('css', $node) as $_css) {
                $_css = $xml->fetchElementsFromRecord($_css);
                $css[] = array('css_set_id' => 0, 'css_group' => $_css['css_group'], 'css_content' => $_css['css_content'], 'css_position' => $_css['css_position'], 'css_added_to' => 1, 'css_app' => $_css['css_app'], 'css_app_hide' => $_css['css_app_hide'], 'css_attributes' => $_css['css_attributes'], 'css_removed' => $_css['css_removed'], 'css_modules' => $_css['css_modules'], 'css_master_key' => $_css['css_master_key']);
            }
        }
        //-----------------------------------------
        // Set the Replacements
        //-----------------------------------------
        $replacements = array();
        foreach ($xml->fetchElements('hookextras_replacements') as $node) {
            foreach ($xml->fetchElements('replacements', $node) as $_r) {
                $_r = $xml->fetchElementsFromRecord($_r);
                $replacements[] = array('replacement_key' => $_r['replacement_key'], 'replacement_content' => $_r['replacement_content']);
            }
        }
        //-----------------------------------------
        // Set the tasks
        //-----------------------------------------
        $tasks = array();
        foreach ($xml->fetchElements('hookextras_tasks') as $node) {
            foreach ($xml->fetchElements('tasks', $node) as $_task) {
                $task = $xml->fetchElementsFromRecord($_task);
                $tasks[] = array('task_title' => $task['task_title'], 'task_file' => $task['task_file'], 'task_week_day' => $task['task_week_day'], 'task_month_day' => $task['task_month_day'], 'task_hour' => $task['task_hour'], 'task_minute' => $task['task_minute'], 'task_cronkey' => $task['task_cronkey'], 'task_log' => $task['task_log'], 'task_description' => $task['task_description'], 'task_enabled' => $task['task_enabled'], 'task_key' => $task['task_key'], 'task_safemode' => $task['task_safemode'], 'task_locked' => $task['task_locked'], 'task_application' => $task['task_application']);
            }
        }
        //-----------------------------------------
        // Set the database changes
        //-----------------------------------------
        $database = array('create' => array(), 'alter' => array(), 'update' => array(), 'insert' => array());
        foreach ($xml->fetchElements('hookextras_database_create') as $node) {
            foreach ($xml->fetchElements('create', $node) as $_table) {
                $table = $xml->fetchElementsFromRecord($_table);
                $database['create'][] = array('name' => $table['name'], 'fields' => $table['fields'], 'tabletype' => $table['tabletype']);
            }
        }
        foreach ($xml->fetchElements('hookextras_database_alter') as $node) {
            foreach ($xml->fetchElements('alter', $node) as $_table) {
                $table = $xml->fetchElementsFromRecord($_table);
                $database['alter'][] = array('altertype' => $table['altertype'], 'table' => $table['table'], 'field' => $table['field'], 'newfield' => $table['newfield'], 'fieldtype' => $table['fieldtype'], 'default' => $table['default']);
            }
        }
        foreach ($xml->fetchElements('hookextras_database_update') as $node) {
            foreach ($xml->fetchElements('update', $node) as $_table) {
                $table = $xml->fetchElementsFromRecord($_table);
                $database['update'][] = array('table' => $table['table'], 'field' => $table['field'], 'newvalue' => $table['newvalue'], 'oldvalue' => $table['oldvalue'], 'where' => $table['where']);
            }
        }
        foreach ($xml->fetchElements('hookextras_database_insert') as $node) {
            foreach ($xml->fetchElements('insert', $node) as $_table) {
                $table = $xml->fetchElementsFromRecord($_table);
                $database['insert'][] = array('table' => $table['table'], 'updates' => $table['updates'], 'fordelete' => $table['fordelete']);
            }
        }
        //-----------------------------------------
        // Set some vars for display tallies
        //-----------------------------------------
        $filesInserted = 0;
        $settingGroupsInserted = 0;
        $settingsInserted = 0;
        $settingsUpdated = 0;
        $languageInserted = 0;
        $languageUpdated = 0;
        $modulesInserted = 0;
        $modulesUpdated = 0;
        $helpInserted = 0;
        $helpUpdated = 0;
        $templatesInserted = 0;
        $templatesUpdated = 0;
        $templateHooks = false;
        $tasksInserted = 0;
        $tasksUpdated = 0;
        $createQueries = 0;
        $alterQueries = 0;
        $updateQueries = 0;
        $insertQueries = 0;
        $cssInserted = 0;
        $cssUpdated = 0;
        $replacementsInserted = 0;
        $replacementsUpdated = 0;
        //-----------------------------------------
        // Insert/update DB records
        //-----------------------------------------
        if ($this->hooks[$config['hook_key']]['hook_id']) {
            //-----------------------------------------
            // Don't change enabled/disabled status
            //-----------------------------------------
            unset($config['hook_enabled']);
            $this->DB->update('core_hooks', $config, 'hook_id=' . $this->hooks[$config['hook_key']]['hook_id']);
            $hook_id = $this->hooks[$config['hook_key']]['hook_id'];
            $extra_data = unserialize($this->hooks[$config['hook_key']]['hook_extra_data']);
            /* Reset DB */
            $extra_data['database'] = array();
        } else {
            $config['hook_installed'] = IPS_UNIX_TIME_NOW;
            $this->hook[$config['hook_key']] = $config;
            $this->DB->insert('core_hooks', $config);
            $hook_id = $this->DB->getInsertId();
            $this->hook[$config['hook_key']]['hook_id'] = $hook_id;
            $extra_data['display'] = $tempExtraData['display'];
        }
        if (count($files)) {
            //-----------------------------------------
            // If we are updating, remove old files
            //-----------------------------------------
            if ($this->hooks[$config['hook_key']]['hook_id']) {
                $this->DB->build(array('select' => 'hook_file_id, hook_file_stored', 'from' => 'core_hooks_files', 'where' => 'hook_hook_id=' . $this->hooks[$config['hook_key']]['hook_id']));
                $outer = $this->DB->execute();
                while ($r = $this->DB->fetch($outer)) {
                    @unlink(IPS_HOOKS_PATH . $r['hook_file_stored']);
                    $this->DB->delete('core_hooks_files', 'hook_file_id=' . $r['hook_file_id']);
                }
            }
            foreach ($files as $file) {
                //-----------------------------------------
                // Store new files
                //-----------------------------------------
                $filename = $file['hook_classname'] . '_' . md5(uniqid(microtime(), true)) . '.php';
                file_put_contents(IPS_HOOKS_PATH . $filename, $file['hooks_source']);
                chmod(IPS_HOOKS_PATH . $filename, IPS_FILE_PERMISSION);
                $file['hook_file_stored'] = $filename;
                $file['hook_hook_id'] = $hook_id;
                $this->DB->insert('core_hooks_files', $file);
                $filesInserted++;
                /* Need to recache skins? */
                if ($file['hook_type'] == 'templateHooks') {
                    $templateHooks = true;
                }
            }
        }
        //-----------------------------------------
        // Put custom install/uninstall file
        //-----------------------------------------
        if (is_object($customClass)) {
            $extra_data['display']['custom'] = $custom['filename'];
            file_put_contents(IPS_HOOKS_PATH . 'install_' . $custom['filename'], $custom['source']);
            chmod(IPS_HOOKS_PATH . 'install_' . $custom['filename'], IPS_FILE_PERMISSION);
        }
        //-----------------------------------------
        // (1) Settings
        //-----------------------------------------
        if (count($settingGroups) or count($settings)) {
            $setting_groups = array();
            $this->DB->build(array('select' => '*', 'from' => 'core_sys_settings_titles'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $setting_groups[$r['conf_title_id']] = $r;
                $setting_groups_by_key[$r['conf_title_keyword']] = $r;
            }
            //-----------------------------------------
            // Get current settings.
            //-----------------------------------------
            $this->DB->build(array('select' => 'conf_id, conf_key', 'from' => 'core_sys_conf_settings'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $cur_settings[$r['conf_key']] = $r['conf_id'];
            }
        }
        if (count($settingGroups)) {
            $need_to_update = array();
            foreach ($settingGroups as $data) {
                if ($data['conf_title_title'] and $data['conf_title_keyword']) {
                    //-----------------------------------------
                    // Get ID based on key
                    //-----------------------------------------
                    $conf_id = $setting_groups_by_key[$data['conf_title_keyword']]['conf_title_id'];
                    $save = array('conf_title_title' => $data['conf_title_title'], 'conf_title_desc' => $data['conf_title_desc'], 'conf_title_keyword' => $data['conf_title_keyword'], 'conf_title_app' => $data['conf_title_app'], 'conf_title_tab' => $data['conf_title_tab'], 'conf_title_noshow' => $data['conf_title_noshow']);
                    //-----------------------------------------
                    // Not got a row, insert first!
                    //-----------------------------------------
                    if (!$conf_id) {
                        $this->DB->insert('core_sys_settings_titles', $save);
                        $conf_id = $this->DB->getInsertId();
                        $settingGroupsInserted++;
                        $extra_data['settingGroups'][] = $save['conf_title_keyword'];
                    } else {
                        //-----------------------------------------
                        // Update...
                        //-----------------------------------------
                        $this->DB->update('core_sys_settings_titles', $save, 'conf_title_id=' . $conf_id);
                    }
                    //-----------------------------------------
                    // Update settings cache
                    //-----------------------------------------
                    $save['conf_title_id'] = $conf_id;
                    $setting_groups_by_key[$save['conf_title_keyword']] = $save;
                    $setting_groups[$save['conf_title_id']] = $save;
                    //-----------------------------------------
                    // Set need update...
                    //-----------------------------------------
                    $need_update[] = $conf_id;
                }
            }
        }
        if (count($settings)) {
            foreach ($settings as $idx => $data) {
                $data['conf_group'] = $setting_groups_by_key[$data['conf_title_keyword']]['conf_title_id'];
                //-----------------------------------------
                // Remove from array
                //-----------------------------------------
                unset($data['conf_title_keyword']);
                if ($cur_settings[$data['conf_key']]) {
                    $this->DB->update('core_sys_conf_settings', $data, 'conf_id=' . $cur_settings[$data['conf_key']]);
                    $settingsUpdated++;
                } else {
                    $this->DB->insert('core_sys_conf_settings', $data);
                    $settingsInserted++;
                    $extra_data['settings'][] = $data['conf_key'];
                }
            }
        }
        //-----------------------------------------
        // Update group counts...
        //-----------------------------------------
        if (count($need_update)) {
            foreach ($need_update as $i => $idx) {
                $conf = $this->DB->buildAndFetch(array('select' => 'count(*) as count', 'from' => 'core_sys_conf_settings', 'where' => 'conf_group=' . $idx));
                $count = intval($conf['count']);
                $this->DB->update('core_sys_settings_titles', array('conf_title_count' => $count), 'conf_title_id=' . $idx);
            }
        }
        if (count($settingGroups) or count($settings)) {
            $this->cache->rebuildCache('settings', 'global');
        }
        //-----------------------------------------
        // (2) Languages
        //-----------------------------------------
        if (count($language)) {
            $langPacks = array();
            $this->DB->build(array('select' => 'lang_id', 'from' => 'core_sys_lang'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $langPacks[] = $r['lang_id'];
            }
            foreach ($language as $langbit) {
                foreach ($langPacks as $lang_id) {
                    $langbit['lang_id'] = $lang_id;
                    // See if it exists
                    $cnt = $this->DB->buildAndFetch(array('select' => 'word_id', 'from' => 'core_sys_lang_words', 'where' => "lang_id={$lang_id} AND word_app='{$langbit['word_app']}' AND word_key='{$langbit['word_key']}' AND word_pack='{$langbit['word_pack']}'"));
                    if ($cnt['word_id']) {
                        $this->DB->update('core_sys_lang_words', $langbit, 'word_id=' . $cnt['word_id']);
                        $languageUpdated++;
                    } else {
                        $this->DB->insert('core_sys_lang_words', $langbit);
                        $languageInserted++;
                        $word_id = $this->DB->getInsertId();
                    }
                    $extra_data['language'][$langbit['word_app'] . "_" . $langbit['word_pack']][] = $langbit['word_key'];
                }
            }
            $classToLoad = IPSLib::loadActionOverloader(IPSLib::getAppDir('core') . '/modules_admin/languages/manage_languages.php', 'admin_core_languages_manage_languages');
            $langLib = new $classToLoad();
            $langLib->makeRegistryShortcuts($this->registry);
            foreach ($langPacks as $langId) {
                $langLib->cacheToDisk($langId);
            }
        }
        //-----------------------------------------
        // (3) Modules
        //-----------------------------------------
        if (count($modules)) {
            //-----------------------------------------
            // Get current modules
            //-----------------------------------------
            $cur_modules = array();
            $this->DB->build(array('select' => '*', 'from' => 'core_sys_module', 'order' => 'sys_module_id'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $cur_modules[$r['sys_module_application']][$r['sys_module_key']] = $r['sys_module_id'];
            }
            foreach ($modules as $module) {
                //-----------------------------------------
                // Insert or update?
                //-----------------------------------------
                if ($cur_modules[$module['sys_module_application']][$module['sys_module_key']]) {
                    $this->DB->update('core_sys_module', $module, "sys_module_id=" . $cur_modules[$module['sys_module_application']][$module['sys_module_key']]);
                    $modulesUpdated++;
                } else {
                    $this->DB->insert('core_sys_module', $module);
                    $modulesInserted++;
                    $extra_data['modules'][] = ($module['sys_module_admin'] ? 'admin' : 'public') . '-' . $module['sys_module_application'] . '-' . $module['sys_module_key'];
                }
            }
            $classToLoad = IPSLib::loadActionOverloader(IPSLib::getAppDir('core') . '/modules_admin/applications/applications.php', 'admin_core_applications_applications');
            $moduleLib = new $classToLoad();
            $moduleLib->makeRegistryShortcuts($this->registry);
            $moduleLib->moduleRecache();
            $moduleLib->applicationsMenuDataRecache();
        }
        //-----------------------------------------
        // (4) Help Files
        //-----------------------------------------
        if (count($help)) {
            $keys = array();
            $this->DB->build(array('select' => 'title', 'from' => 'faq'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $keys[] = $r['title'];
            }
            foreach ($help as $entry) {
                if (in_array($entry['title'], $keys)) {
                    $this->DB->update('faq', $entry, "title='{$entry['title']}'");
                    $helpUpdated++;
                } else {
                    $this->DB->insert('faq', $entry);
                    $helpInserted++;
                    $help_id = $this->DB->getInsertId();
                    $extra_data['help'][] = $entry['title'];
                }
            }
        }
        //-----------------------------------------
        // (6) Templates
        //-----------------------------------------
        if (count($templates)) {
            $bits = array();
            /* Root will always be updated */
            $this->DB->build(array('select' => 'template_name,template_group,template_master_key', 'from' => 'skin_templates'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $bits[$r['template_master_key']][$r['template_group']][] = $r['template_name'];
            }
            foreach ($templates as $template) {
                //-----------------------------------------
                // If template is not in root set, add it to
                // prevent fatal error selecting other skins
                //-----------------------------------------
                if ($template['template_master_key'] != 'root' && (!isset($bits['root'][$template['template_group']]) or !in_array($template['template_name'], $bits['root'][$template['template_group']]))) {
                    $this->DB->insert('skin_templates', array_merge($template, array('template_set_id' => 0, 'template_master_key' => 'root', 'template_content' => '')));
                    $extra_data['templates'][$template['template_group']][$template['template_name']] = $template['template_name'];
                    $bits['root'][$template['template_group']][] = $template['template_name'];
                }
                //-----------------------------------------
                // Ignore unknown skin sets
                //-----------------------------------------
                if (!isset($bits[$template['template_master_key']])) {
                    continue;
                }
                if (isset($bits[$template['template_master_key']][$template['template_group']]) and in_array($template['template_name'], $bits[$template['template_master_key']][$template['template_group']])) {
                    $template['template_updated'] = IPS_UNIX_TIME_NOW;
                    $this->DB->update('skin_templates', $template, "template_master_key='{$template['template_master_key']}' AND template_group='{$template['template_group']}' AND template_name='{$template['template_name']}'");
                    $templatesUpdated++;
                } else {
                    $this->DB->insert('skin_templates', $template);
                    $templatesInserted++;
                    $extra_data['templates'][$template['template_group']][$template['template_name']] = $template['template_name'];
                    $bits[$template['template_master_key']][$template['template_group']][] = $template['template_name'];
                }
            }
        }
        //-----------------------------------------
        // CSS
        //-----------------------------------------
        if (count($css)) {
            $bits = array();
            $this->DB->build(array('select' => 'css_master_key, css_group', 'from' => 'skin_css'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $bits[$r['css_master_key']][$r['css_group']] = $r['css_group'];
            }
            foreach ($css as $entry) {
                //-----------------------------------------
                // Ignore unknown skin sets
                //-----------------------------------------
                if (!isset($bits[$entry['css_master_key']])) {
                    continue;
                }
                if (in_array($entry['css_group'], $bits[$entry['css_master_key']])) {
                    $entry['css_updated'] = IPS_UNIX_TIME_NOW;
                    $this->DB->update('skin_css', $entry, "css_master_key='{$entry['css_master_key']}' AND css_group='{$entry['css_group']}'");
                    $cssUpdated++;
                } else {
                    $this->DB->insert('skin_css', $entry);
                    $cssInserted++;
                    $extra_data['css'][$entry['css_group']] = $entry['css_group'];
                    $bits[$entry['css_master_key']][$entry['css_group']] = $entry['css_group'];
                }
            }
        }
        //-----------------------------------------
        // Skin Replacements
        //-----------------------------------------
        if (count($replacements)) {
            $bits = array();
            $this->DB->build(array('select' => 'replacement_master_key, replacement_key', 'from' => 'skin_replacements'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $bits[$r['replacement_master_key']][$r['replacement_key']] = $r['replacement_key'];
            }
            foreach ($replacements as $entry) {
                if (!isset($bits[$entry['replacement_master_key']])) {
                    $entry['replacement_master_key'] = 'root';
                }
                if (in_array($entry['replacement_key'], $bits[$entry['replacement_master_key']])) {
                    $this->DB->update('skin_replacements', $entry, "replacement_master_key='{$entry['replacement_master_key']}' AND replacement_key='{$entry['replacement_key']}'");
                    $replacementsUpdated++;
                } else {
                    $this->DB->insert('skin_replacements', $entry);
                    $replacementsInserted++;
                    $extra_data['replacements'][$entry['replacement_key']] = $entry['replacement_key'];
                }
            }
        }
        //-----------------------------------------
        // (7) Tasks
        //-----------------------------------------
        if (count($tasks)) {
            $keys = array();
            $this->DB->build(array('select' => 'task_key', 'from' => 'task_manager'));
            $this->DB->execute();
            while ($r = $this->DB->fetch()) {
                $keys[] = $r['task_key'];
            }
            foreach ($tasks as $entry) {
                if (in_array($entry['task_key'], $keys)) {
                    $this->DB->update('task_manager', $entry, "task_key='{$entry['task_key']}'");
                    $tasksUpdated++;
                } else {
                    $this->DB->insert('task_manager', $entry);
                    $tasksInserted++;
                    $task_id = $this->DB->getInsertId();
                    $extra_data['tasks'][] = $entry['task_key'];
                }
            }
        }
        //-----------------------------------------
        // (8) Create new tables
        //-----------------------------------------
        if (count($database['create'])) {
            foreach ($database['create'] as $create) {
                $query = "CREATE TABLE {$this->settings['sql_tbl_prefix']}{$create['name']} (\r\r\n\t\t\t\t\t\t\t{$create['fields']}\r\r\n\t\t\t\t\t\t\t)";
                if ($create['tabletype']) {
                    $query .= " ENGINE=" . $create['tabletype'];
                } else {
                    if ($this->settings['sql_driver'] == 'mysql' and $this->settings['mysql_tbl_type']) {
                        $query .= " ENGINE=" . $this->settings['mysql_tbl_type'];
                    }
                }
                //-----------------------------------------
                // Fix prefix
                //-----------------------------------------
                $this->DB->return_die = true;
                $this->DB->query($query);
                $this->DB->return_die = false;
                $createQueries++;
                $extra_data['database']['create'][] = $create;
            }
        }
        //-----------------------------------------
        // (9) Alter tables
        //-----------------------------------------
        if (count($database['alter'])) {
            foreach ($database['alter'] as $alter) {
                $this->DB->return_die = true;
                $alter['default'] = !isset($alter['default']) || $alter['default'] === "" ? NULL : $alter['default'];
                switch ($alter['altertype']) {
                    case 'remove':
                        $this->DB->dropField($alter['table'], $alter['field']);
                        break;
                    case 'add':
                        $this->DB->addField($alter['table'], $alter['field'], $alter['fieldtype'], $alter['default']);
                        break;
                    case 'change':
                        $this->DB->changeField($alter['table'], $alter['field'], $alter['newfield'], $alter['fieldtype'], $alter['default']);
                        break;
                }
                $this->DB->return_die = false;
                $alterQueries++;
                $extra_data['database']['alter'][] = $alter;
            }
        }
        //-----------------------------------------
        // (10) Run update queries
        //-----------------------------------------
        if (count($database['update'])) {
            foreach ($database['update'] as $update) {
                $this->DB->return_die = true;
                $this->DB->update($update['table'], array($update['field'] => $update['newvalue']), html_entity_decode($update['where'], ENT_QUOTES));
                $this->DB->return_die = false;
                $updateQueries++;
                $extra_data['database']['update'][] = $update;
            }
        }
        //-----------------------------------------
        // (11) Run insert queries
        //-----------------------------------------
        //	if( !$this->hooks[ $config['hook_key'] ]['hook_id'] )
        //	{
        if (count($database['insert'])) {
            foreach ($database['insert'] as $insert) {
                $fields = array();
                $content = explode(',', $insert['updates']);
                foreach ($content as $value) {
                    list($field, $toInsert) = explode('=', $value);
                    $fields[trim($field)] = str_replace('~C~', ',', $toInsert);
                }
                $this->DB->return_die = true;
                $this->DB->insert($insert['table'], $fields);
                $this->DB->return_die = false;
                $insertQueries++;
                $extra_data['database']['insert'][] = $insert;
            }
        }
        //	}
        /* Got an install function to run too? */
        if (is_object($customClass)) {
            if (method_exists($customClass, 'install')) {
                $customClass->install();
            }
        }
        if (count($extra_data)) {
            $this->DB->update('core_hooks', array('hook_extra_data' => serialize($extra_data)), 'hook_id=' . $hook_id);
        }
        //print_r($config);
        //print_r($files);
        //print_r($custom);
        //print_r($settingGroups);
        //print_r($settings);
        //print_r($language);
        //print_r($modules);
        //print_r($templates);
        //print_r($tasks);
        //print_r($help);
        //print_r($database);
        if ($addMessage) {
            $_tempMsg = <<<EOF

\t\t<strong>{$this->lang->words['h_newhookin']}</strong>
\t\t<ul>
\t\t\t<li>{$filesInserted} {$this->lang->words['h_filesin']}</li>
\t\t\t<li>{$settingGroupsInserted} {$this->lang->words['h_settinggin']}</li>
\t\t\t<li>{$settingsInserted} {$this->lang->words['h_settingin']}</li>
\t\t\t<li>{$settingsUpdated} {$this->lang->words['h_settingup']}</li>
\t\t\t<li>{$languageInserted} {$this->lang->words['h_langbitin']}</li>
\t\t\t<li>{$languageUpdated} {$this->lang->words['h_langbitup']}</li>
\t\t\t<li>{$modulesInserted} {$this->lang->words['h_modin']}</li>
\t\t\t<li>{$modulesUpdated} {$this->lang->words['h_modup']}</li>
\t\t\t<li>{$helpInserted} {$this->lang->words['h_helpin']}</li>
\t\t\t<li>{$helpUpdated} {$this->lang->words['h_helpup']}</li>
\t\t\t<li>{$templatesInserted} {$this->lang->words['h_tempin']}</li>
\t\t\t<li>{$templatesUpdated} {$this->lang->words['h_tempup']}</li>
\t\t\t<li>{$cssInserted} {$this->lang->words['h_cssin']}</li>
\t\t\t<li>{$cssUpdated} {$this->lang->words['h_cssup']}</li>
\t\t\t<li>{$replacementsInserted} {$this->lang->words['h_replacementsin']}</li>
\t\t\t<li>{$replacementsUpdated} {$this->lang->words['h_replacementsup']}</li>
\t\t\t<li>{$tasksInserted} {$this->lang->words['h_taskin']}</li>
\t\t\t<li>{$tasksUpdated} {$this->lang->words['h_taskup']}</li>
\t\t\t<li>{$createQueries} {$this->lang->words['h_dbcreated']}</li>
\t\t\t<li>{$alterQueries} {$this->lang->words['h_dbaltered']}</li>
\t\t\t<li>{$updateQueries} {$this->lang->words['h_updateran']}</li>
\t\t\t<li>{$insertQueries} {$this->lang->words['h_insertran']}</li>
\t\t</ul>
EOF;
            $this->registry->output->setMessage($_tempMsg, 1);
        }
        //-----------------------------------------
        // Got some skin recaching to do...
        //-----------------------------------------
        if ($allowSkinRecache === TRUE and ($templatesInserted or $templatesUpdated or $templateHooks or $cssUpdated or $cssInserted)) {
            /* Rebuild cache */
            $this->rebuildHooksCache();
            /* Flag skins for recache */
            require_once IPS_ROOT_PATH . 'sources/classes/skins/skinFunctions.php';
            /*noLibHook*/
            require_once IPS_ROOT_PATH . 'sources/classes/skins/skinCaching.php';
            /*noLibHook*/
            $skinCaching = new skinCaching($this->registry);
            $skinCaching->flagSetForRecache();
        }
    }
コード例 #20
0
 /**
  * Import XML Settings
  *
  * @access	private
  * @param	string		XML Data
  * @param	string		Application (should be set by XML file, however)
  * @param	array 		Array of any known settings and their values
  * @return	array 		array( 'insertedCount' => x, 'updatedCount' => x, 'updatedKeys' => array(..), 'insertedKeys' => array() )
  */
 private function _importXML($content, $app = 'core', $knownSettings = array())
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $cur_settings = array();
     $updated = 0;
     $inserted = 0;
     $updatedKeys = array();
     $insertedKeys = array();
     $known = array();
     //-----------------------------------------
     // Get current settings.
     //-----------------------------------------
     $this->DB->build(array('select' => 'conf_id, conf_key', 'from' => 'core_sys_conf_settings', 'order' => 'conf_id'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $cur_settings[$r['conf_key']] = $r['conf_id'];
     }
     //-----------------------------------------
     // Get current titles
     //-----------------------------------------
     $this->_settingsGetGroups(true);
     //-----------------------------------------
     // Get xml class
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     //-----------------------------------------
     // Loop through and sort out settings...
     //-----------------------------------------
     foreach ($xml->fetchElements('setting') as $setting) {
         $entry = $xml->fetchElementsFromRecord($setting);
         //-----------------------------------------
         // Is setting?
         //-----------------------------------------
         if (!$entry['conf_is_title']) {
             unset($entry['conf_is_title']);
             unset($entry['conf_help_key']);
             unset($entry['conf_id']);
             $new_settings[] = $entry;
         } else {
             $new_titles[] = $entry;
         }
     }
     //-----------------------------------------
     // Sort out titles...
     //-----------------------------------------
     if (is_array($new_titles) and count($new_titles)) {
         foreach ($new_titles as $idx => $data) {
             if ($data['conf_title_title'] and $data['conf_title_keyword']) {
                 //-----------------------------------------
                 // Get ID based on key
                 //-----------------------------------------
                 $conf_id = $this->setting_groups_by_key[$data['conf_title_keyword']]['conf_title_id'];
                 $save = array('conf_title_title' => $data['conf_title_title'], 'conf_title_desc' => $data['conf_title_desc'], 'conf_title_keyword' => $data['conf_title_keyword'], 'conf_title_tab' => $data['conf_title_tab'], 'conf_title_app' => $data['conf_title_app'] ? $data['conf_title_app'] : $app, 'conf_title_noshow' => $data['conf_title_noshow']);
                 //-----------------------------------------
                 // Not got a row, insert first!
                 //-----------------------------------------
                 if (!$conf_id) {
                     $this->DB->insert('core_sys_settings_titles', $save);
                     $conf_id = $this->DB->getInsertId();
                 } else {
                     //-----------------------------------------
                     // Update...
                     //-----------------------------------------
                     $this->DB->update('core_sys_settings_titles', $save, 'conf_title_id=' . $conf_id);
                 }
                 //-----------------------------------------
                 // Update settings cache
                 //-----------------------------------------
                 $save['conf_title_id'] = $conf_id;
                 $this->setting_groups_by_key[$save['conf_title_keyword']] = $save;
                 $this->setting_groups[$save['conf_title_id']] = $save;
                 //-----------------------------------------
                 // Remove need update...
                 //-----------------------------------------
                 $need_update[] = $conf_id;
             }
         }
     }
     //-----------------------------------------
     // Sort out settings
     //-----------------------------------------
     if (is_array($new_settings) and count($new_settings)) {
         foreach ($new_settings as $idx => $data) {
             //-----------------------------------------
             // Insert known
             //-----------------------------------------
             $data['conf_value'] = '';
             if (is_array($knownSettings) and count($knownSettings)) {
                 if (!$data['conf_value'] and in_array($data['conf_key'], array_keys($knownSettings))) {
                     $data['conf_value'] = $knownSettings[$data['conf_key']];
                 }
             }
             $data['conf_group'] = $this->setting_groups_by_key[$data['conf_title_keyword']]['conf_title_id'];
             //-----------------------------------------
             // Remove from array
             //-----------------------------------------
             unset($data['conf_title_keyword']);
             if ($cur_settings[$data['conf_key']]) {
                 //-----------------------------------------
                 // Don't change the setting value
                 //-----------------------------------------
                 unset($data['conf_value']);
                 //-----------------------------------------
                 // Update
                 //-----------------------------------------
                 $this->DB->update('core_sys_conf_settings', $data, 'conf_id=' . $cur_settings[$data['conf_key']]);
                 $updatedKeys[] = $data['conf_key'];
                 $updated++;
             } else {
                 //-----------------------------------------
                 // INSERT
                 //-----------------------------------------
                 $this->DB->insert('core_sys_conf_settings', $data);
                 $insertedKeys[] = $data['conf_key'];
                 $inserted++;
             }
         }
     }
     //-----------------------------------------
     // Update group counts...
     //-----------------------------------------
     if (count($need_update)) {
         foreach ($need_update as $i => $idx) {
             $conf = $this->DB->buildAndFetch(array('select' => 'count(*) as count', 'from' => 'core_sys_conf_settings', 'where' => 'conf_group=' . $idx));
             $count = intval($conf['count']);
             $this->DB->update('core_sys_settings_titles', array('conf_title_count' => $count), 'conf_title_id=' . $idx);
         }
     }
     //-----------------------------------------
     // Resync
     //-----------------------------------------
     $this->settingsRebuildCache();
     //-----------------------------------------
     // Return
     //-----------------------------------------
     return array('insertedCount' => $inserted, 'updatedCount' => $updated, 'insertedKeys' => $insertedKeys, 'updatedKeys' => $updatedKeys);
 }
コード例 #21
0
 /**
  * Import all tasks from XML
  *
  * @return	@e void
  */
 public function tasksImportAllApps()
 {
     /* INIT */
     $tasks = array();
     $_gmsg = array();
     /* Grab current tasks */
     $this->DB->build(array('select' => '*', 'from' => 'task_manager'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $tasks[$row['task_key']] = $row;
     }
     /* Grab XML class */
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     /* Loop through all the applications */
     foreach ($this->registry->getApplications() as $app => $__data) {
         $stats = array('inserted' => 0, 'updated' => 0);
         $xml = new classXML(IPS_DOC_CHAR_SET);
         $file = IPSLib::getAppDir($app) . '/xml/' . $app . '_tasks.xml';
         if (is_file($file)) {
             $xml->load($file);
             foreach ($xml->fetchElements('row') as $task) {
                 $entry = $xml->fetchElementsFromRecord($task);
                 /* Remove unneeded */
                 unset($entry['task_id']);
                 unset($entry['task_next_run']);
                 /* Update */
                 $entry['task_cronkey'] = $entry['task_cronkey'] ? $entry['task_cronkey'] : md5(uniqid(microtime()));
                 $entry['task_next_run'] = $entry['task_next_run'] ? $entry['task_next_run'] : time();
                 $entry['task_description'] = $entry['task_description'] ? $entry['task_description'] : '';
                 $entry['task_locked'] = intval($entry['task_locked']);
                 if ($tasks[$entry['task_key']]['task_key']) {
                     unset($entry['task_cronkey']);
                     unset($entry['task_enabled']);
                     $stats['updated']++;
                     $this->DB->update('task_manager', $entry, "task_key='" . $entry['task_key'] . "'");
                 } else {
                     $stats['inserted']++;
                     $this->DB->insert('task_manager', $entry);
                     $tasks[$entry['task_key']] = $entry;
                 }
             }
         }
         $_gmsg[] = $app . ': ' . sprintf($this->lang->words['t_inserted'], $stats['inserted'], $stats['updated']);
         /* In dev time stamp? */
         if (IN_DEV) {
             $cache = $this->caches['indev'];
             $cache['import']['tasks'][$app] = time();
             $this->cache->setCache('indev', $cache, array('donow' => 1, 'array' => 1));
         }
     }
     /* Got a global message? */
     if (count($_gmsg)) {
         $this->registry->output->setMessage(implode('<br />', $_gmsg), 1);
     }
     /* Return */
     $this->taskManagerOverview();
 }
コード例 #22
0
 /**
  * Import an emoticon pack
  *
  * @return	@e void
  */
 public function emoticonsPackImport()
 {
     /* Make sure all emoticon directories are writable */
     $this->DB->build(array('select' => $this->DB->buildDistinct('emo_set') . ' as folder', 'from' => 'emoticons'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $_folders[] = $r['folder'];
     }
     if (count($_folders)) {
         foreach ($_folders as $folder) {
             if (!IPSLib::isWritable(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $folder)) {
                 $this->registry->output->global_error = sprintf($this->lang->words['emodir_not_write'], PUBLIC_DIRECTORY . '/style_emoticons/' . $folder);
                 return $this->emoticonsPackSplash();
             }
         }
     }
     /* Get the xml file */
     try {
         $content = $this->registry->adminFunctions->importXml('ipb_emoticons.xml');
     } catch (Exception $e) {
         $this->registry->output->showError($e->getMessage());
     }
     /* Check for content */
     if (!$content) {
         $this->registry->output->global_error = $this->lang->words['emo_fail'];
         return $this->emoticonsPackSplash();
     }
     /* Setup XML */
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPS_DOC_CHAR_SET);
     require_once IPS_KERNEL_PATH . 'classXMLArchive.php';
     /*noLibHook*/
     $xmlarchive = new classXMLArchive();
     /* Read the archive */
     $xmlarchive->readXML($content);
     /* Get the data file */
     $emoticons = array();
     $emoticon_data = array();
     foreach ($xmlarchive->asArray() as $k => $f) {
         if ($k == 'emoticon_data.xml') {
             $emoticon_data = $f;
         } else {
             $emoticons[$f['filename']] = $f['content'];
         }
     }
     /* Parse the XML Document */
     $xml->loadXML($emoticon_data['content']);
     /* Make sure we have a destination for these emoicons */
     if (!$this->request['emo_set'] and !$this->request['new_emo_set']) {
         $this->registry->output->global_error = $this->lang->words['emo_specify'];
     }
     /* Current emoticon set directory */
     $emo_set_dir = trim($this->request['emo_set']);
     /* New emoticon set directory */
     $this->request['new_emo_set'] = preg_replace('/[^a-zA-Z0-9\\-_]/', "", $this->request['new_emo_set']);
     /* Create the new set */
     if ($this->request['new_emo_set']) {
         $emo_set_dir = trim($this->request['new_emo_set']);
         /* Check to see if the directory already exists */
         if (file_exists(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $emo_set_dir)) {
             $this->registry->output->global_error = sprintf($this->lang->words['emo_already'], $emo_set_dir);
             return $this->emoticonsPackSplash();
         }
         /* Create the directory */
         if (@mkdir(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $emo_set_dir, IPS_FOLDER_PERMISSION)) {
             @chmod(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $emo_set_dir, IPS_FOLDER_PERMISSION);
             @file_put_contents(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $emo_set_dir . '/index.html', '');
         } else {
             $this->registry->output->global_error = $this->lang->words['emo_ftp'];
             return $this->emoticonsPackSplash();
         }
     }
     /* Get a list of current emoticons, if we are not overwriting */
     $emo_image = array();
     $emo_typed = array();
     if ($this->request['overwrite'] != 1) {
         $this->DB->build(array('select' => '*', 'from' => 'emoticons', 'where' => "emo_set='" . $emo_set_dir . "'"));
         $this->DB->execute();
         while ($r = $this->DB->fetch()) {
             $emo_image[$r['image']] = 1;
             $emo_typed[$r['typed']] = 1;
         }
     }
     /* Loop through the emoticons in the xml document */
     foreach ($xml->fetchElements('emoticon') as $emoticon) {
         $entry = $xml->fetchElementsFromRecord($emoticon);
         /* Emoticon Data */
         $image = $entry['image'];
         $typed = $entry['typed'];
         $click = $entry['clickable'];
         /* Skip if we're not overwriting */
         if ($emo_image[$image] or $emo_typed[$typed]) {
             continue;
         }
         /* Get the extension */
         $file_extension = preg_replace('#^.*\\.(.+?)$#si', "\\1", strtolower($image));
         /* Make sure it's allowed */
         if (!in_array($file_extension, $this->allowed_files)) {
             continue;
         }
         /* Remove any existing emoticon */
         @unlink(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $emo_set_dir . '/' . $image);
         $this->DB->delete('emoticons', "typed='{$typed}' and image='{$image}' and emo_set='{$emo_set_dir}'");
         /* Create the image in the file system */
         if ($FH = fopen(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $emo_set_dir . '/' . $image, 'wb')) {
             if (fwrite($FH, $emoticons[$image])) {
                 fclose($FH);
                 /* Insert the emoticon record */
                 $this->DB->insert('emoticons', array('typed' => $typed, 'image' => $image, 'clickable' => $click, 'emo_set' => $emo_set_dir));
             }
         }
         /* Add the emoticon to all the other directories */
         try {
             foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/') as $file) {
                 if (!$file->isDot() && $file->isDir()) {
                     if (substr($file->getFilename(), 0, 1) == '.') {
                         continue;
                     }
                     if (!is_file(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $file->getFilename() . '/' . $image)) {
                         $this->DB->delete('emoticons', "typed='{$typed}' and image='{$image}' and emo_set='{$file->getFilename()}'");
                         if ($FH = @fopen(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_emoticons/' . $file->getFilename() . '/' . $image, 'wb')) {
                             if (fwrite($FH, $emoticons[$image])) {
                                 fclose($FH);
                                 $this->DB->insert('emoticons', array('typed' => $typed, 'image' => $image, 'clickable' => $click, 'emo_set' => $file->getFilename()));
                             }
                         }
                     }
                 }
             }
         } catch (Exception $e) {
         }
     }
     /* Recache and bounce */
     $this->emoticonsRebuildCache();
     $this->registry->output->global_message = $this->lang->words['emo_xml_good'];
     $this->emoticonsOverview();
 }
コード例 #23
0
ファイル: overview.php プロジェクト: mover5/imobackup
 /**
  * Execute selected method
  *
  * @access	public
  * @param	object		Registry object
  * @return	@e void
  */
 public function doExecute(ipsRegistry $registry)
 {
     /* INIT */
     $filesOK = NULL;
     $extensions = get_loaded_extensions();
     $extensionsOK = TRUE;
     $extensionData = array();
     /* Test to make sure core.php is up-to-date. Large file may not always upload cleanly */
     if (!method_exists('IPSLib', 'loadLibrary')) {
         $filesOK = false;
         $this->registry->output->addError('Please ensure that "' . CP_DIRECTORY . '/sources/base/core.php" is up-to-date. Re-upload via FTP if necessary');
     }
     /* Test Extensions */
     $INSTALLDATA = array();
     include IPS_ROOT_PATH . 'setup/xml/requiredextensions.php';
     /*noLibHook*/
     if (is_array($INSTALLDATA) && count($INSTALLDATA)) {
         foreach ($INSTALLDATA as $data) {
             if (!in_array($data['testfor'], $extensions)) {
                 //-----------------------------------------
                 // Added 'nohault' key which will show a
                 // warning but not prohibit installation
                 //-----------------------------------------
                 if ($data['nohault']) {
                     $data['_ok'] = 1;
                     // Anything but true or false
                     $extensionsOK = 1;
                     // Anything but true or false
                 } else {
                     $extensionsOK = FALSE;
                 }
             } else {
                 $data['_ok'] = TRUE;
             }
             $extensionData[] = $data;
         }
     }
     /* All extensions loaded OK? */
     if ($extensionsOK == TRUE and $filesOK === NULL) {
         $filesOK = FALSE;
         /* Fetch core writeable files */
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML(IPSSetUp::charSet);
         try {
             $xml->load(IPS_ROOT_PATH . 'setup/xml/writeablefiles.xml');
             foreach ($xml->fetchElements('file') as $xmlelement) {
                 $data = $xml->fetchElementsFromRecord($xmlelement);
                 if ($data['path']) {
                     /* If we overrode hooks path in constants.php, check that instead */
                     if ($data['path'] == 'hooks') {
                         $_path = IPS_HOOKS_PATH;
                     } else {
                         $_path = DOC_IPS_ROOT_PATH . $data['path'];
                     }
                     if (!file_exists($_path)) {
                         if ($data['dir']) {
                             if (!@mkdir($_path, IPS_FOLDER_PERMISSION, TRUE)) {
                                 $this->registry->output->addError('Directory does not exist: "' . $data['path'] . '", please create it via FTP');
                             }
                         } else {
                             $this->registry->output->addError('File does not exist: "' . $data['path'] . '", please create it via FTP');
                         }
                     }
                     if (!is_writeable($_path)) {
                         //-----------------------------------------
                         // If we're upgrading, don't do this to conf_global
                         // @link	http://community.invisionpower.com/tracker/issue-20478-config-file-premission/
                         //-----------------------------------------
                         if (strpos($_path, 'conf_global.php') !== false) {
                             continue;
                         }
                         if (!@chmod($_path, is_dir($_path) ? IPS_FOLDER_PERMISSION : IPS_FILE_PERMISSION)) {
                             if (is_dir($_path)) {
                                 $this->registry->output->addError('Can not write to directory: "' . $data['path'] . '", please CHMOD to 777');
                             } else {
                                 $this->registry->output->addError('Can not write to file: "' . $data['path'] . '", please CHMOD to 777');
                             }
                         }
                     }
                 }
             }
             if (!count($this->registry->output->fetchErrors())) {
                 $filesOK = TRUE;
             }
         } catch (Exception $error) {
             $filesOK = FALSE;
             $this->registry->output->addError("Cannot locate: " . IPS_ROOT_PATH . 'setup/xml/writeablefiles.xml');
         }
     }
     /* Set next action */
     $this->registry->output->setNextAction('apps');
     /* Hide buttons? */
     if ($filesOK !== TRUE or $extensionsOK != TRUE) {
         $this->registry->output->setNextAction('');
         $this->registry->output->setHideButton(TRUE);
     }
     /* Simply return the requirements page */
     $this->registry->output->setTitle("Requirements");
     $this->registry->output->addContent($this->registry->output->template()->page_requirements($filesOK, $extensionsOK, $extensionData, 'upgrade'));
     $this->registry->output->sendOutput();
 }
コード例 #24
0
 /**
  * Read conf_global
  *
  * @access	public
  * @return	bool
  */
 public static function readGlobalConfig()
 {
     /* Fetch core writeable files */
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPSSetUp::charSet);
     try {
         $xml->load(IPS_ROOT_PATH . 'setup/xml/config.xml');
         foreach ($xml->fetchElements('package') as $xmlelement) {
             $data = $xml->fetchElementsFromRecord($xmlelement);
             self::$_config = $data;
         }
         return TRUE;
     } catch (Exception $error) {
         return FALSE;
     }
 }
コード例 #25
0
 /**
  * Imports language packs from an xml file and updates the database and recaches the languages
  *
  * @param	integer	$lang_id		ID of the language pack to import
  * @param	bool	$in_dev			Set to 1 for developer language import
  * @param	bool	$no_return		If set to 1, this function will return a value, rather than outputting data
  * @param	string	$app_override	Overrides the application for which languages are being imported
  * @param	bool	$skip_charset	Skips charset conversion in the XML file (useful during upgrade routine as strings don't need to be converted)
  * @return	mixed
  */
 public function imprtFromXML($lang_id = 0, $in_dev = 0, $no_return = 0, $app_override = '', $skip_charset = false)
 {
     //-----------------------------------------
     // Set version..
     //-----------------------------------------
     $LATESTVERSION = IPSLib::fetchVersionNumber();
     //-----------------------------------------
     // INDEV?
     //-----------------------------------------
     if ($in_dev) {
         $_FILES['FILE_UPLOAD']['name'] = '';
     } else {
         if ($this->request['file_location']) {
             $this->request['file_location'] = IPS_ROOT_PATH . $this->request['file_location'];
         }
     }
     //-----------------------------------------
     // Not an upload?
     //-----------------------------------------
     if ($_FILES['FILE_UPLOAD']['name'] == "" or !$_FILES['FILE_UPLOAD']['name'] or $_FILES['FILE_UPLOAD']['name'] == "none") {
         //-----------------------------------------
         // Check and load from server
         //-----------------------------------------
         if (!$this->request['file_location']) {
             $this->registry->output->global_message = $this->lang->words['l_nofile'];
             $this->languagesList();
             return;
         }
         if (!is_file($this->request['file_location'])) {
             $this->registry->output->global_message = $this->lang->words['l_noopen'] . $this->request['file_location'];
             $this->languagesList();
             return;
         }
         if (preg_match('#\\.gz$#', $this->request['file_location'])) {
             if ($FH = @gzopen($this->request['file_location'], 'rb')) {
                 while (!@gzeof($FH)) {
                     $content .= @gzread($FH, 1024);
                 }
                 @gzclose($FH);
             }
         } else {
             $content = file_get_contents($this->request['file_location']);
         }
         $originalContent = $content;
         //-----------------------------------------
         // Extract archive
         //-----------------------------------------
         require_once IPS_KERNEL_PATH . 'classXMLArchive.php';
         /*noLibHook*/
         $xmlarchive = new classXMLArchive();
         //-----------------------------------------
         // Read the archive
         //-----------------------------------------
         $xmlarchive->readXML($content);
         //-----------------------------------------
         // Get the data
         //-----------------------------------------
         $content = '';
         foreach ($xmlarchive->asArray() as $k => $f) {
             if ($k == 'language_entries.xml') {
                 $content = $f['content'];
                 break;
             }
         }
         //-----------------------------------------
         // No content from de-archiving, must not
         // be archive, but rather raw XML file
         //-----------------------------------------
         if ($content == '' and strpos($originalContent, "<languageexport") !== false) {
             $content = $originalContent;
         }
     } else {
         //-----------------------------------------
         // Get uploaded schtuff
         //-----------------------------------------
         $tmp_name = $_FILES['FILE_UPLOAD']['name'];
         $tmp_name = preg_replace('#\\.gz$#', "", $tmp_name);
         if ($_FILES['FILE_UPLOAD']['error']) {
             switch ($_FILES['FILE_UPLOAD']['error']) {
                 case 1:
                     $this->registry->output->global_message = sprintf($this->lang->words['lang_upload_too_large'], ini_get('upload_max_filesize'));
                     $this->languagesList();
                     return;
                     break;
                 default:
                     $this->registry->output->global_message = $this->lang->words['lang_upload_other_error'];
                     $this->languagesList();
                     return;
                     break;
             }
         }
         //-----------------------------------------
         // Get content
         //-----------------------------------------
         try {
             $uploadedContent = $this->registry->adminFunctions->importXml($tmp_name);
         } catch (Exception $e) {
             $this->registry->output->showError($e->getMessage());
         }
         //-----------------------------------------
         // Extract archive
         //-----------------------------------------
         require_once IPS_KERNEL_PATH . 'classXMLArchive.php';
         /*noLibHook*/
         $xmlarchive = new classXMLArchive();
         //-----------------------------------------
         // Read the archive
         //-----------------------------------------
         $xmlarchive->readXML($uploadedContent);
         //-----------------------------------------
         // Get the data
         //-----------------------------------------
         $content = '';
         foreach ($xmlarchive->asArray() as $k => $f) {
             if ($k == 'language_entries.xml') {
                 $content = $f['content'];
                 break;
             }
         }
         //-----------------------------------------
         // No content from de-archiving, must not
         // be archive, but rather raw XML file
         //-----------------------------------------
         if ($content == '' and strpos($uploadedContent, "<languageexport") !== false) {
             $content = $uploadedContent;
         }
     }
     //-----------------------------------------
     // Make sure we have content
     //-----------------------------------------
     if (!$content) {
         if ($no_return) {
             return;
         }
         $this->registry->output->global_message = $this->lang->words['l_badfile'];
         $this->languagesList();
         return;
     }
     //-----------------------------------------
     // Get xml class
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML($skip_charset ? 'utf-8' : IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     //-----------------------------------------
     // Is this full language pack?...
     //-----------------------------------------
     foreach ($xml->fetchElements('langinfo') as $lang_data) {
         $lang_info = $xml->fetchElementsFromRecord($lang_data);
         $lang_data = array('lang_short' => $lang_info['lang_short'], 'lang_title' => $lang_info['lang_title']);
     }
     $lang_ids = array();
     $insertId = 0;
     //-----------------------------------------
     // Do we have language pack info?
     //-----------------------------------------
     if ($lang_data['lang_short']) {
         //-----------------------------------------
         // Does this pack already exist
         //-----------------------------------------
         $update_lang = $this->DB->buildAndFetch(array('select' => 'lang_id', 'from' => 'core_sys_lang', 'where' => "lang_short='{$lang_data['lang_short']}'"));
         //-----------------------------------------
         // If doesn't exist, then create new pack
         //-----------------------------------------
         if (!$update_lang['lang_id']) {
             $this->DB->insert('core_sys_lang', $lang_data);
             $insertId = $this->DB->getInsertId();
             if (@mkdir(IPS_CACHE_PATH . '/cache/lang_cache/' . $insertId)) {
                 @file_put_contents(IPS_CACHE_PATH . 'cache/lang_cache/' . $insertId . '/index.html', '');
                 @chmod(IPS_CACHE_PATH . '/cache/lang_cache/' . $insertId, IPS_FOLDER_PERMISSION);
             }
             //-----------------------------------------
             // Copy over language bits from default lang
             //-----------------------------------------
             $default = $this->DB->buildAndFetch(array('select' => 'lang_id', 'from' => 'core_sys_lang', 'where' => "lang_default=1"));
             $this->DB->build(array('select' => 'word_app,word_pack,word_key,word_default,word_js', 'from' => 'core_sys_lang_words', 'where' => "lang_id={$default['lang_id']}"));
             $q = $this->DB->execute();
             while ($r = $this->DB->fetch($q)) {
                 $r['lang_id'] = $insertId;
                 $r['word_custom'] = '';
                 $this->DB->insert('core_sys_lang_words', $r);
             }
             //-----------------------------------------
             // Rebuild IPB and disk caches
             //-----------------------------------------
             $this->registry->class_localization->rebuildLanguagesCache();
         } else {
             $insertId = $update_lang['lang_id'];
         }
     }
     //-----------------------------------------
     // We need to add language bits to every pack..
     //-----------------------------------------
     $this->DB->build(array('select' => 'lang_id', 'from' => 'core_sys_lang'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $lang_ids[] = $r['lang_id'];
     }
     //-----------------------------------------
     // Init counts array
     //-----------------------------------------
     $counts = array('updates' => 0, 'inserts' => 0);
     //-----------------------------------------
     // Init a cache array to save entries
     //-----------------------------------------
     $lang_entries = array();
     if ($app_override) {
         $this->DB->build(array('select' => "MD5( CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) as word_lookup, word_id, md5(word_default) as word_default, word_default_version", 'from' => 'core_sys_lang_words', 'where' => "word_app='{$app_override}' AND lang_id IN(" . implode(",", $lang_ids) . ")"));
         $this->DB->execute();
         while ($r = $this->DB->fetch()) {
             $lang_entries[$r['word_lookup']] = $r;
         }
     }
     //-----------------------------------------
     // Start looping
     //-----------------------------------------
     $_lastLookup = '';
     foreach ($xml->fetchElements('lang') as $entry) {
         $lang = $xml->fetchElementsFromRecord($entry);
         foreach ($lang_ids as $_lang_id) {
             $lang_entry = array();
             //-----------------------------------------
             // Build db array
             //-----------------------------------------
             $db_array = array('lang_id' => $_lang_id, 'word_app' => $app_override ? $app_override : $lang['word_app'], 'word_pack' => $lang['word_pack'], 'word_key' => $lang['word_key'], 'word_default' => $lang['word_default'], 'word_custom' => $in_dev ? '' : $lang['word_custom'], 'word_js' => intval($lang['word_js']), 'word_default_version' => $lang['word_default_version'] ? $lang['word_default_version'] : $LATESTVERSION['long'], 'word_custom_version' => $lang['word_custom_version']);
             $dbKey = md5($db_array['lang_id'] . '-' . $db_array['word_app'] . '-' . $db_array['word_pack'] . '-' . $db_array['word_key']);
             $langIdKey = md5($_lang_id . '-' . $db_array['word_app'] . '-' . $db_array['word_pack'] . '-' . $db_array['word_key']);
             // If the default value hasn't changed, we don't need to update the word_default_version (see bug report 19172)
             if (md5($lang['word_default']) == $lang_entries[$dbKey]['word_default']) {
                 $db_array['word_default_version'] = $lang_entries[$dbKey]['word_default_version'];
             }
             //-----------------------------------------
             // If cached, get from cache
             //-----------------------------------------
             if ($lang_entries[$langIdKey]) {
                 $lang_entry = $lang_entries[$langIdKey];
             } else {
                 if (!$app_override) {
                     if ($_lastLookup != md5($db_array['word_app'] . '-' . $db_array['word_pack'])) {
                         unset($lang_entries);
                     }
                     $_lastLookup = md5($db_array['word_app'] . '-' . $db_array['word_pack']);
                     $this->DB->build(array('select' => '*', 'from' => 'core_sys_lang_words', 'where' => "lang_id={$_lang_id} AND word_app='{$db_array['word_app']}' AND word_pack='{$db_array['word_pack']}'"));
                     $this->DB->execute();
                     while ($r = $this->DB->fetch()) {
                         $lang_entries[md5($r['lang_id'] . '-' . $r['word_app'] . '-' . $r['word_pack'] . '-' . $r['word_key'])] = $r;
                     }
                     if ($lang_entries[$langIdKey]) {
                         $lang_entry = $lang_entries[$langIdKey];
                     }
                 }
             }
             //-----------------------------------------
             // Didn't find any match?  Must be importing
             // a new language pack, huh?
             //-----------------------------------------
             if (!isset($lang_entry['word_id'])) {
                 //continue 2;
             }
             //-----------------------------------------
             // If there is no new custom lang bit to insert
             // don't delete what is already there.
             //-----------------------------------------
             if (!$db_array['word_custom'] || $insertId > 0 && $insertId != $_lang_id) {
                 unset($db_array['word_custom']);
                 unset($db_array['word_custom_version']);
             }
             //-----------------------------------------
             // Lang bit already exists, update
             //-----------------------------------------
             if ($lang_entry['word_id'] and (!$insertId or $insertId == $_lang_id)) {
                 //-----------------------------------------
                 // Don't update default version
                 //-----------------------------------------
                 // This causes no languages to show "out of date" on upgrade
                 // @link	http://community.invisionpower.com/tracker/issue-31637-no-out-of-date-entries-for-language-string-updates
                 // This WAS added to fix a previously reported bug, however, so need to watch out for this
                 // unset( $db_array['word_default_version'] );
                 $counts['updates']++;
                 $this->DB->update('core_sys_lang_words', $db_array, "word_id={$lang_entry['word_id']}");
             } else {
                 if (!$lang_entry['word_id']) {
                     /* Ensure there is a value to avoid null */
                     if (!$db_array['word_custom']) {
                         $db_array['word_custom'] = '';
                     }
                     /* Ensure custom word but isn't added to other packs that simply had missing strings */
                     if ($insertId and $insertId != $_lang_id) {
                         $db_array['word_custom'] = '';
                     }
                     $counts['inserts']++;
                     $this->DB->insert('core_sys_lang_words', $db_array);
                 }
             }
             unset($lang_entry, $db_array);
         }
     }
     /* Save some memory */
     unset($lang_entries);
     //-----------------------------------------
     // Recache all our lang packs
     //-----------------------------------------
     foreach ($lang_ids as $_lang_id) {
         $this->cacheToDisk($_lang_id, $app_override);
     }
     //-----------------------------------------
     // Set output message
     //-----------------------------------------
     $this->registry->output->global_message = sprintf($this->lang->words['l_updatedcount'], $counts['updates'], $counts['inserts']);
     if (is_array($this->cache_errors) and count($this->cache_errors)) {
         $this->registry->output->global_message .= "<br />" . implode("<br />", $this->cache_errors);
     }
     //-----------------------------------------
     // Free a little memory
     //-----------------------------------------
     unset($xml);
     //-----------------------------------------
     // Update IPB cache
     //-----------------------------------------
     $this->registry->class_localization->rebuildLanguagesCache();
     //-----------------------------------------
     // Return! Now!
     //-----------------------------------------
     if (!$no_return) {
         $this->languagesList();
         return;
     }
 }
コード例 #26
0
ファイル: help.php プロジェクト: mover5/imobackup
 /**
  * Import help files XML helper. Abstracted so
  * it can be used outside of this file.
  *
  * @param	string		App Directory
  * @param	bool		Allow overwrite. If FALSE, it will not update.
  * @return	array		Number of items added / updated
  */
 public function helpFilesXMLImport_app($app, $overwrite = TRUE)
 {
     /* INIT */
     $file = IPSLib::getAppDir($app) . '/xml/' . $app . '_help.xml';
     $processed = array('added' => 0, 'updated' => 0);
     /* Got anything to import? */
     if (is_file($file)) {
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML(IPS_DOC_CHAR_SET);
         $xml->load($file);
         foreach ($xml->fetchElements('row') as $row) {
             $entry = $xml->fetchElementsFromRecord($row);
             $db = array('title' => $entry['title'], 'text' => $entry['text'], 'description' => $entry['description'], 'position' => $entry['position'], 'app' => $app);
             if ($entry['title']) {
                 $curFaq = $this->DB->buildAndFetch(array('select' => 'id', 'from' => 'faq', 'where' => "app='" . $app . "' AND title = '" . $this->DB->addSlashes($entry['title']) . "'"));
                 if ($curFaq['id']) {
                     if ($overwrite === TRUE) {
                         $processed['updated']++;
                         $this->DB->update('faq', $db, "id = " . $curFaq['id']);
                     }
                 } else {
                     $processed['added']++;
                     $this->DB->insert('faq', $db);
                 }
             }
         }
     }
     return $processed;
 }
コード例 #27
0
 /**
  * Perform the BBcode import
  * Abstracted here so the installer can use it (and potentially other apps)
  *
  * @param	string		Raw XML code
  * @return	array 		[ 'inserted' => int, 'updated' => int ]
  */
 public function bbcodeImportDo($content, $app = 'core')
 {
     /* Init vars */
     $tags = array();
     $return = array('updated' => 0, 'inserted' => 0);
     //-----------------------------------------
     // Got anything?
     //-----------------------------------------
     $content = trim($content);
     if (empty($content)) {
         return $return;
     }
     //-----------------------------------------
     // Get xml class
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     //-----------------------------------------
     // Get current custom bbcodes
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'custom_bbcode'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $tags[$r['bbcode_tag']] = 1;
     }
     //-----------------------------------------
     // pArse
     //-----------------------------------------
     foreach ($xml->fetchElements('bbcode') as $bbcode) {
         $entry = $xml->fetchElementsFromRecord($bbcode);
         $bbcode_title = $entry['bbcode_title'];
         $bbcode_desc = $entry['bbcode_desc'];
         $bbcode_tag = $entry['bbcode_tag'];
         $bbcode_replace = $entry['bbcode_replace'];
         $bbcode_useoption = $entry['bbcode_useoption'];
         $bbcode_example = $entry['bbcode_example'];
         $bbcode_switch_option = $entry['bbcode_switch_option'];
         $bbcode_menu_option_text = $entry['bbcode_menu_option_text'];
         $bbcode_menu_content_text = $entry['bbcode_menu_content_text'];
         $bbcode_single_tag = $entry['bbcode_single_tag'];
         $bbcode_php_plugin = $entry['bbcode_php_plugin'];
         $bbcode_no_parsing = $entry['bbcode_no_parsing'];
         $bbcode_optional_option = $entry['bbcode_optional_option'];
         $bbcode_aliases = $entry['bbcode_aliases'];
         $bbcode_image = $entry['bbcode_image'];
         $bbcode_app = $entry['bbcode_app'] ? $entry['bbcode_app'] : $app;
         $bbcode_protected = $entry['bbcode_protected'] ? $entry['bbcode_protected'] : 0;
         $bbcode_sections = $entry['bbcode_sections'] ? $entry['bbcode_sections'] : 'all';
         $bbcode_regex = $entry['bbcode_custom_regex'] ? $entry['bbcode_custom_regex'] : '';
         if ($tags[$bbcode_tag]) {
             $bbarray = array('bbcode_title' => $bbcode_title, 'bbcode_desc' => $bbcode_desc, 'bbcode_tag' => $bbcode_tag, 'bbcode_replace' => IPSText::safeslashes($bbcode_replace), 'bbcode_useoption' => $bbcode_useoption, 'bbcode_example' => $bbcode_example, 'bbcode_switch_option' => $bbcode_switch_option, 'bbcode_menu_option_text' => $bbcode_menu_option_text, 'bbcode_menu_content_text' => $bbcode_menu_content_text, 'bbcode_php_plugin' => $bbcode_php_plugin, 'bbcode_no_parsing' => $bbcode_no_parsing, 'bbcode_optional_option' => $bbcode_optional_option, 'bbcode_aliases' => $bbcode_aliases, 'bbcode_image' => $bbcode_image, 'bbcode_single_tag' => $bbcode_single_tag, 'bbcode_app' => $bbcode_app, 'bbcode_protected' => $bbcode_protected, 'bbcode_custom_regex' => $bbcode_regex);
             $this->DB->update('custom_bbcode', $bbarray, "bbcode_tag='" . $bbcode_tag . "'");
             $return['updated']++;
             continue;
         }
         if ($bbcode_tag) {
             $bbarray = array('bbcode_title' => $bbcode_title, 'bbcode_desc' => $bbcode_desc, 'bbcode_tag' => $bbcode_tag, 'bbcode_replace' => IPSText::safeslashes($bbcode_replace), 'bbcode_useoption' => $bbcode_useoption, 'bbcode_example' => $bbcode_example, 'bbcode_switch_option' => $bbcode_switch_option, 'bbcode_menu_option_text' => $bbcode_menu_option_text, 'bbcode_menu_content_text' => $bbcode_menu_content_text, 'bbcode_groups' => 'all', 'bbcode_sections' => $bbcode_sections, 'bbcode_php_plugin' => $bbcode_php_plugin, 'bbcode_no_parsing' => $bbcode_no_parsing, 'bbcode_optional_option' => $bbcode_optional_option, 'bbcode_aliases' => $bbcode_aliases, 'bbcode_image' => $bbcode_image, 'bbcode_single_tag' => $bbcode_single_tag, 'bbcode_app' => $bbcode_app, 'bbcode_protected' => $bbcode_protected, 'bbcode_custom_regex' => $bbcode_regex);
             $this->DB->insert('custom_bbcode', $bbarray);
             $return['inserted']++;
         }
     }
     $this->bbcodeRebuildCache();
     return $return;
 }
コード例 #28
0
ファイル: output.php プロジェクト: ConnorChristie/GrabViews
 /**
  * Construct
  *
  * @access	public
  * @param	object	ipsRegistry reference
  * @param	bool	Whether to init
  * @return	@e void
  */
 public function __construct(ipsRegistry $registry, $init = FALSE)
 {
     /* Make object */
     $this->registry = $registry;
     $this->DB = $this->registry->DB();
     $this->settings =& $this->registry->fetchSettings();
     $this->request =& $this->registry->fetchRequest();
     $this->member = $this->registry->member();
     $this->memberData =& $this->registry->member()->fetchMemberData();
     $this->cache = $this->registry->cache();
     $this->caches =& $this->registry->cache()->fetchCaches();
     if ($init === TRUE) {
         /* Load 'template' */
         require_once IPS_ROOT_PATH . 'setup/templates/skin_setup.php';
         /*noLibHook*/
         $this->template = new skin_setup($registry);
         /* Images URL */
         $this->imageUrl = '../setup/' . PUBLIC_DIRECTORY . '/images';
         /* Fetch sequence data */
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML(IPSSetUp::charSet);
         $file = IPS_IS_UPGRADER ? IPS_ROOT_PATH . 'setup/xml/upgrade_sequence.xml' : IPS_ROOT_PATH . 'setup/xml/sequence.xml';
         try {
             $xml->load($file);
             foreach ($xml->fetchElements('action') as $xmlelement) {
                 $data = $xml->fetchElementsFromRecord($xmlelement);
                 $_tmp[$data['position']] = $data;
                 ksort($_tmp);
                 foreach ($_tmp as $pos => $data) {
                     $this->sequenceData[$data['file']] = $data['menu'];
                 }
             }
         } catch (Exception $error) {
             $this->addError("Could not locate: " . $file);
         }
         /* Set up URLs */
         $this->settings['base_url'] = $this->settings['base_url'] ? $this->settings['base_url'] : IPSSetUp::getSavedData('install_url');
         $this->settings['public_dir'] = $this->settings['base_url'] . '/' . PUBLIC_DIRECTORY . '/';
         $this->settings['img_url_no_dir'] = $this->settings['base_url'] . '/' . PUBLIC_DIRECTORY . '/style_images/';
         /* Set Current Page */
         $this->currentPage = $this->request['section'] ? $this->request['section'] : 'index';
         if (!$this->sequenceData[$this->currentPage]) {
             $this->currentPage = 'index';
         }
         /* Set default next action */
         $_hit = 0;
         foreach ($this->sequenceData as $file => $text) {
             if ($_hit) {
                 $this->nextAction = $file;
                 break;
             }
             if ($file == $this->currentPage) {
                 $_hit = 1;
             }
         }
         /* Build all skins array */
         if (IPS_IS_UPGRADER) {
             /* For < 3.0.0 upgrades, they won't have this table, so check for it */
             if ($this->DB->checkForTable('skin_collections')) {
                 $this->DB->build(array('select' => '*', 'from' => 'skin_collections', 'order' => 'set_id ASC'));
                 $this->DB->execute();
                 while ($_skinSets = $this->DB->fetch()) {
                     $id = $_skinSets['set_id'];
                     $this->allSkins[$id] = $_skinSets;
                     $this->allSkins[$id]['_parentTree'] = unserialize($_skinSets['set_parent_array']);
                     $this->allSkins[$id]['_childTree'] = unserialize($_skinSets['set_child_array']);
                     $this->allSkins[$id]['_userAgents'] = unserialize($_skinSets['set_locked_uagent']);
                     $this->allSkins[$id]['_cssGroupsArray'] = unserialize($_skinSets['set_css_groups']);
                     $this->allSkins[$id]['_youCanUse'] = TRUE;
                     $this->allSkins[$id]['_gatewayExclude'] = FALSE;
                     /* Array groups */
                     if (is_array($this->allSkins[$id]['_cssGroupsArray'])) {
                         ksort($this->allSkins[$id]['_cssGroupsArray'], SORT_NUMERIC);
                     } else {
                         $this->allSkins[$id]['_cssGroupsArray'] = array();
                     }
                 }
             }
         }
     }
 }
コード例 #29
0
ファイル: types.php プロジェクト: Advanture/Online-RolePlay
 /**
  * Imports attachment types from an xml document
  *
  * @return	@e void
  */
 public function attachmentTypeImport()
 {
     /* Get the XML Content */
     $content = $this->registry->adminFunctions->importXml('ipb_attachtypes.xml');
     /* Check to make sure we have content */
     if (!$content) {
         $this->registry->output->global_message = $this->lang->words['ty_failed'];
         $this->attachmentTypesOverview();
     }
     /* Get the XML class */
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPS_DOC_CHAR_SET);
     $xml->loadXML($content);
     /* Get a list of the types already installed */
     $types = array();
     $this->DB->build(array('select' => '*', 'from' => 'attachments_type', 'order' => "atype_extension"));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $types[$r['atype_extension']] = 1;
     }
     /* Loop through the xml document and insert new types */
     foreach ($xml->fetchElements('attachtype') as $record) {
         $entry = $xml->fetchElementsFromRecord($record);
         /* Build the insert array */
         $insert_array = array('atype_extension' => $entry['atype_extension'], 'atype_mimetype' => $entry['atype_mimetype'], 'atype_post' => $entry['atype_post'], 'atype_img' => $entry['atype_img']);
         /* Bypass if this type has already been added */
         if ($types[$entry['atype_extension']]) {
             continue;
         }
         /* Insert the new type */
         if ($entry['atype_extension'] and $entry['atype_mimetype']) {
             $this->DB->insert('attachments_type', $insert_array);
         }
     }
     /* Rebuild the cache and bounce */
     $this->attachmentTypeCacheRebuild();
     $this->registry->output->global_message = $this->lang->words['ty_imported'];
     $this->attachmentTypesOverview();
 }
コード例 #30
0
ファイル: upgrade.php プロジェクト: Advanture/Online-RolePlay
 /**
  * Install templates
  *
  * @return void
  */
 public function install_templates()
 {
     ipsRegistry::getClass('class_localization')->loadLanguageFile(array('admin_templates'), 'core');
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $previous = $_REQUEST['previous'];
     if (is_file(IPS_ROOT_PATH . 'setup/sql/' . strtolower($this->registry->dbFunctions()->getDriverType()) . '_install.php')) {
         require_once IPS_ROOT_PATH . 'setup/sql/' . strtolower($this->registry->dbFunctions()->getDriverType()) . '_install.php';
         /*noLibHook*/
         $extra_install = new install_extra($this->registry);
     }
     //-----------------------------------------
     // Fetch next 'un
     //-----------------------------------------
     $next = IPSSetUp::fetchNextApplication($previous, '', $this->settings['gb_char_set']);
     /* Got any skin sets? */
     $count = $this->DB->buildAndFetch(array('select' => 'count(*) as count', 'from' => 'skin_collections'));
     if (!$count['count']) {
         //-----------------------------------------
         // Next...
         //-----------------------------------------
         $output[] = "Добавление шаблонов";
         require_once IPS_KERNEL_PATH . 'classXML.php';
         /*noLibHook*/
         $xml = new classXML(IPSSetUp::charSet);
         //-----------------------------------------
         // Adjust the table?
         //-----------------------------------------
         if ($extra_install and method_exists($extra_install, 'before_inserts_run')) {
             $q = $extra_install->before_inserts_run('skinset');
         }
         /* Skin Set Data */
         $xml->load(IPS_ROOT_PATH . 'setup/xml/skins/setsData.xml');
         foreach ($xml->fetchElements('set') as $xmlelement) {
             $data = $xml->fetchElementsFromRecord($xmlelement);
             $this->DB->insert('skin_collections', $data);
         }
         //-----------------------------------------
         // Adjust the table?
         //-----------------------------------------
         if ($extra_install and method_exists($extra_install, 'after_inserts_run')) {
             $q = $extra_install->after_inserts_run('skinset');
         }
     }
     /* Load skin classes */
     require_once IPS_ROOT_PATH . 'sources/classes/skins/skinFunctions.php';
     /*noLibHook*/
     require_once IPS_ROOT_PATH . 'sources/classes/skins/skinCaching.php';
     /*noLibHook*/
     require_once IPS_ROOT_PATH . 'sources/classes/skins/skinImportExport.php';
     /*noLibHook*/
     $skinFunctions = new skinImportExport($this->registry);
     /* Grab skin data */
     $this->DB->build(array('select' => '*', 'from' => 'skin_collections'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         /* Bit of jiggery pokery... */
         if ($row['set_key'] == 'default') {
             $row['set_key'] = 'root';
             $row['set_id'] = 0;
         }
         $skinSets[$row['set_key']] = $row;
     }
     //-----------------------------------------
     // InstallTemplates
     //-----------------------------------------
     if ($next['key']) {
         foreach ($skinSets as $skinKey => $skinData) {
             $_PATH = IPSLib::getAppDir($next['key']) . '/xml/';
             $output[] = $next['title'] . ": Обновление шаблонов {$skinData['set_name']}";
             if (is_file($_PATH . $next['key'] . '_' . $skinKey . '_templates.xml')) {
                 //-----------------------------------------
                 // Install
                 //-----------------------------------------
                 $return = $skinFunctions->importTemplateAppXML($next['key'], $skinKey, $skinData['set_id'], TRUE);
                 $output[] = $next['title'] . ": " . intval($return['insertCount']) . " шаблонов добавлено";
             }
             if (is_file($_PATH . $next['key'] . '_' . $skinKey . '_css.xml')) {
                 //-----------------------------------------
                 // Install
                 //-----------------------------------------
                 $return = $skinFunctions->importCSSAppXML($next['key'], $skinKey, $skinData['set_id']);
                 $output[] = $next['title'] . ": " . intval($return['insertCount']) . " {$skinData['set_name']} CSS файлов добавлено";
             }
         }
         //-----------------------------------------
         // Done.. so get some more!
         //-----------------------------------------
         $this->_finishStep($output, "Обновление: Шаблоны", 'upgrade&do=templates&previous=' . $next['key']);
     } else {
         //-----------------------------------------
         // Recache templates
         //-----------------------------------------
         $output[] = "Кеширование шаблонов";
         foreach ($skinSets as $skinKey => $skinData) {
             /* Replacements */
             if (is_file(IPS_ROOT_PATH . 'setup/xml/skins/replacements_' . $skinKey . '.xml')) {
                 $skinFunctions->importReplacementsXMLArchive(file_get_contents(IPS_ROOT_PATH . 'setup/xml/skins/replacements_' . $skinKey . '.xml'), $skinKey);
             }
         }
         $skinFunctions->rebuildMobileSkinUserAgentsFromSetDataXml();
         $skinFunctions->rebuildSkinSetsCache();
         $output[] = "Все шаблоны обновлены";
         $this->_finishStep($output, "Обновление: Шаблоны", 'upgrade&do=tasks');
     }
 }