/** * 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); } }
/** * 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); } } } }
/** * Write Default Values */ public function writeDefaults() { $defaultTemplates = file_get_contents(IPS_ROOT_PATH . 'setup/xml/system_templates.xml'); if (!class_exists('classXML')) { require_once IPS_KERNEL_PATH . 'classXML.php'; } $xml = new classXML('utf-8'); $xml->loadXML($defaultTemplates); $array = $xml->fetchXMLAsArray(); foreach ($array['system_templates']['template'] as $template) { $params = array(); foreach ($template['params']['param'] as $p) { $params[] = $p['#alltext']; } $this->write($template['key']['#alltext'], $params, $template['content']['#alltext']); } }
/** * Perform the task import * * @access public * @param string Raw XML code * @return void */ public function taskImport() { $content = $this->registry->getClass('adminFunctions')->importXml(); //----------------------------------------- // Got anything? //----------------------------------------- if (!$content) { $this->registry->output->global_message = $this->lang->words['tupload_failed']; $this->_bbcodeStart(); return; } //----------------------------------------- // Get xml class //----------------------------------------- require_once IPS_KERNEL_PATH . 'classXML.php'; $xml = new classXML(IPS_DOC_CHAR_SET); $xml->loadXML($content); //----------------------------------------- // Get current custom bbcodes //----------------------------------------- $tasks = array(); $this->DB->build(array('select' => '*', 'from' => 'task_manager')); $this->DB->execute(); while ($r = $this->DB->fetch()) { $tasks[$r['task_key']] = 1; } //----------------------------------------- // pArse //----------------------------------------- foreach ($xml->fetchElements('row') as $task) { $entry = $xml->fetchElementsFromRecord($task); 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'] : ''; if ($tasks[$entry['task_key']]) { $this->DB->update('task_manager', $entry, "task_key='" . $entry['task_key'] . "'"); } else { $this->DB->insert('task_manager', $entry); } } //----------------------------------------- // Output //----------------------------------------- /* Bounce */ $this->registry->output->global_message = $this->lang->words['t_simport_success']; $this->taskManagerOverview(); }
/** * 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(); } }
/** * 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§ion=hooks&do=skinsRebuild&setID=' . $nextID, $this->lang->words['to_recachedset'] . $this->registry->output->allSkins[$setID]['set_name']); } } } }
/** * 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; }
/** * 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; } }
/** * Recache menu data * * @return @e void */ public function applicationsMenuDataRecache() { $app_menu_cache = array(); $modules_cache = array(); //----------------------------------------- // Get module data first in one query //----------------------------------------- $this->DB->build(array('select' => '*', 'from' => 'core_sys_module', 'where' => 'sys_module_visible=1 AND sys_module_admin=1', 'order' => 'sys_module_position ASC')); $this->DB->execute(); while ($module = $this->DB->fetch()) { $modules_cache[$module['sys_module_application']][] = $module['sys_module_key']; } //----------------------------------------- // Now get applications and loop //----------------------------------------- $this->DB->build(array('select' => '*', 'from' => 'core_applications', 'order' => 'app_position ASC')); $outer = $this->DB->execute(); while ($row = $this->DB->fetch($outer)) { $app_dir = $row['app_directory']; $main_items = $modules_cache[$app_dir]; //----------------------------------------- // Continue... //----------------------------------------- if (count($main_items)) { foreach ($main_items as $_current_module) { $_file = IPSLib::getAppDir($app_dir) . "/modules_admin/" . $_current_module . '/xml/menu.xml'; if (is_file($_file)) { //----------------------------------------- // Get xml mah-do-dah //----------------------------------------- require_once IPS_KERNEL_PATH . 'classXML.php'; /*noLibHook*/ $xml = new classXML(IPS_DOC_CHAR_SET); $content = @file_get_contents($_file); if ($content) { $xml->loadXML($content); $menu = $xml->fetchXMLAsArray(); $item = array(); $subItemIndex = 0; $itemIndex = 0; /** * Easiest way I could find to get the data in a proper multi-dimensional array */ foreach ($menu as $id => $data) { foreach ($data as $dataKey => $dataValue) { if ($dataKey == 'tabitems') { foreach ($dataValue as $tabitemsKey => $tabItemsValue) { if ($tabitemsKey == 'item') { foreach ($tabItemsValue as $itemKey => $itemValue) { if (is_int($itemKey)) { foreach ($itemValue as $_itemKey => $_itemValue) { $subItemIndex = 0; if ($_itemKey == 'title' or $_itemKey == 'condition') { $item[$itemIndex][$_itemKey] = $_itemValue['#alltext']; } else { if ($_itemKey == 'subitems') { foreach ($_itemValue as $subitemKey => $subitemValue) { if ($subitemKey != '#alltext') { foreach ($subitemValue as $subitemRealKey => $subitemRealValue) { if (is_int($subitemRealKey)) { foreach ($subitemRealValue as $_subitemRealKey => $_subitemRealValue) { if ($_subitemRealKey != '#alltext') { $item[$itemIndex][$_itemKey][$subitemKey][$subItemIndex][$_subitemRealKey] = $_subitemRealValue['#alltext']; } } } else { if ($subitemRealKey != '#alltext') { $item[$itemIndex][$_itemKey][$subitemKey][$subItemIndex][$subitemRealKey] = $subitemRealValue['#alltext']; } } if (is_int($subitemRealKey)) { $subItemIndex++; } } $subItemIndex++; } } } } } $itemIndex++; } else { if ($itemKey == 'title') { $item[$itemIndex][$itemKey] = $itemValue['#alltext']; } else { if ($itemKey == 'subitems') { foreach ($itemValue as $subitemKey => $subitemValue) { if ($subitemKey != '#alltext') { foreach ($subitemValue as $subitemRealKey => $subitemRealValue) { if (is_int($subitemRealKey)) { foreach ($subitemRealValue as $_subitemRealKey => $_subitemRealValue) { if ($_subitemRealKey != '#alltext') { $item[$itemIndex][$itemKey][$subitemKey][$subItemIndex][$_subitemRealKey] = $_subitemRealValue['#alltext']; } } } else { if ($subitemRealKey != '#alltext') { $item[$itemIndex][$itemKey][$subitemKey][$subItemIndex][$subitemRealKey] = $subitemRealValue['#alltext']; } } if (is_int($subitemRealKey)) { $subItemIndex++; } } $subItemIndex++; } } } } } } $itemIndex++; } } } } } foreach ($item as $id => $data) { //----------------------------------------- // INIT //----------------------------------------- if ($data['condition']) { $func = create_function('', $data['condition']); if (!$func()) { continue; } } $_cat_title = $data['title']; $_cat_title = str_replace('&', '&', $_cat_title); // Validation thing $_nav_main_done = 0; if (is_array($data['subitems'])) { //----------------------------------------- // Loop.... //----------------------------------------- foreach ($data['subitems'] as $__data) { foreach ($__data as $_id => $_data) { $_sub_item_title = $_data['subitemtitle']; $_sub_item_url = $_data['subitemurl']; $_sub_is_redirect = $_data['subisredirect']; $_sub_section = $_data['subsection']; $_sub_keywords = $_data['subitemkeywords']; $_sub_item_role_key = isset($_data['subitemrolekey']) ? $_data['subitemrolekey'] : ''; $_sub_language = $_data['subitemlang']; //----------------------------------------- // Continue... //----------------------------------------- if ($_sub_item_title and $_sub_section) { $app_menu_cache[$app_dir][$id . '_' . $_current_module]['title'] = $_cat_title; $app_menu_cache[$app_dir][$id . '_' . $_current_module]['items'][$_id] = array('title' => $_sub_item_title, 'module' => $_current_module, 'langkey' => $_sub_language, 'keywords' => $_sub_keywords, 'section' => $_sub_section, 'url' => $_sub_item_url, 'rolekey' => $_sub_item_role_key, 'redirect' => $_sub_is_redirect); } } } } } } } } } } $this->cache->setCache('app_menu_cache', $app_menu_cache, array('array' => 1)); }
/** * Parses an info XML file * * @access public * @param string XML * @return array */ public function parseInfoXML($xmlContents) { //----------------------------------------- // XML //----------------------------------------- require_once IPS_KERNEL_PATH . 'classXML.php'; $xml = new classXML(IPS_DOC_CHAR_SET); //----------------------------------------- // Get information file //----------------------------------------- $xml->loadXML($xmlContents); foreach ($xml->fetchElements('data') as $xmlelement) { $data = $xml->fetchElementsFromRecord($xmlelement); } return $data; }
/** * 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; } }
/** * 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§ion=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§ion=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; }
/** * Imports tasks from XML * * @param string $file Filename to import tasks from * @param boolean $no_return Set to return true/false, instead of displaying results * @return @e mixed True if $no_return is enabled, otherwise void */ public function tasksImportFromXML($file = '', $no_return = false) { /* INIT */ $file = $file ? $file : IPS_PUBLIC_PATH . 'resources/tasks.xml'; $inserted = 0; $updated = 0; $tasks = array(); /* Check to see if the file exists */ if (!is_file($file)) { $this->registry->output->global_message = sprintf($this->lang->words['t_import404'], $file); $this->taskManagerOverview(); return; } $content = @file_get_contents($file); /* Grab current tasks */ $this->DB->build(array('select' => '*', 'from' => 'task_manager')); $this->DB->execute(); while ($row = $this->DB->fetch()) { $tasks[$row['task_key']] = $row; } /* Get the XML class */ require_once IPS_KERNEL_PATH . 'classXML.php'; /*noLibHook*/ $xml = new classXML(IPS_DOC_CHAR_SET); $xml->loadXML($content); /* Loop through the tasks */ foreach ($xml->fetchElements('row') as $record) { $entry = $xml->fetchElementsFromRecord($record); $_key = $entry['task_key']; $entry['task_cronkey'] = $tasks[$_key]['task_cronkey'] ? $tasks[$_key]['task_cronkey'] : md5(uniqid(microtime())); $entry['task_next_run'] = $tasks[$_key]['task_next_run'] ? $tasks[$_key]['task_next_run'] : time(); $entry['task_description'] = $entry['task_description'] ? $entry['task_description'] : ''; unset($entry['task_id']); if ($tasks[$_key]['task_key']) { unset($entry['task_cronkey']); unset($entry['task_enabled']); $updated++; $this->DB->update('task_manager', $entry, "task_key='" . $tasks[$_key]['task_key'] . "'"); } else { $inserted++; $this->DB->insert('task_manager', $entry); $tasks[$_key] = $entry; } } /* Return or Bounce */ if ($no_return) { $this->registry->output->global_message = sprintf($this->lang->words['t_inserted'], $inserted, $updated); return TRUE; } else { $this->registry->output->global_message = sprintf($this->lang->words['t_inserted'], $inserted, $updated); $this->taskManagerOverview(); } }
/** * 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']); }
/** * 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); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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(); }