Ejemplo n.º 1
0
 /**
  * Construct
  *
  * @access	public
  * @param	object		ipsRegistry reference
  * @param	bool		Whether to init or not
  * @return	@e void
  */
 public function __construct(ipsRegistry $registry, $initialize = FALSE)
 {
     /* Make object */
     $this->registry = $registry;
     $this->DB = $this->registry->DB();
     $this->settings =& $this->registry->fetchSettings();
     $this->request =& $this->registry->fetchRequest();
     $this->lang = $this->registry->getClass('class_localization');
     $this->member = $this->registry->member();
     $this->memberData =& $this->registry->member()->fetchMemberData();
     $this->cache = $this->registry->cache();
     $this->caches =& $this->registry->cache()->fetchCaches();
     /* Safe mode skins... */
     $this->_usingSafeModeSkins = ($this->settings['safe_mode_skins'] == 0 and $this->settings['safe_mode'] == 0 or IN_DEV) ? FALSE : TRUE;
     if ($initialize === TRUE) {
         //-----------------------------------------
         // INIT
         //-----------------------------------------
         $_outputFormat = 'html';
         $_outputClassName = 'htmlOutput';
         $this->allSkins = $this->_fetchAllSkins();
         $skinSetID = $this->_fetchUserSkin();
         $this->skin = $this->allSkins[$skinSetID];
         /* Does it need a recache? */
         if ($this->skin['set_updated'] == -2) {
             /* 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);
             /* Set it as caching */
             $skinCaching->flagSetAsRecaching($skinSetID);
             /* Just recache this one skin set */
             $skinCaching->setIgnoreChildrenWhenRecaching(true);
             $skinCaching->rebuildPHPTemplates($skinSetID);
             $skinCaching->rebuildCSS($skinSetID);
             $skinCaching->rebuildReplacementsCache($skinSetID);
             IPSDebug::addMessage("Recached skin set: " . $skinSetID);
         }
         //-----------------------------------------
         // Get the skin caches
         //-----------------------------------------
         $skinCaches = $this->cache->getWithCacheLib('Skin_Store_' . $skinSetID);
         if (!is_array($skinCaches) or !count($skinCaches)) {
             $_grab = "'css', 'replacements'";
             $this->DB->build(array('select' => '*', 'from' => 'skin_cache', 'where' => "cache_set_id=" . intval($skinSetID) . " AND cache_type IN (" . $_grab . ")"));
             $this->DB->execute();
             while ($row = $this->DB->fetch()) {
                 $skinCaches[$row['cache_value_2'] . '.' . $row['cache_id']] = $row;
             }
             /* Put skin cache back if needed */
             $this->cache->putWithCacheLib('Skin_Store_' . $skinSetID, $skinCaches, 86400);
         }
         /* Avoid SQL filesort */
         ksort($skinCaches);
         /* Loop and build */
         foreach ($skinCaches as $row) {
             switch ($row['cache_type']) {
                 default:
                     break;
                 case 'css':
                     $appDir = '';
                     $appHide = 0;
                     if (strstr($row['cache_value_4'], '-')) {
                         list($appDir, $appHide) = explode('-', $row['cache_value_4']);
                         if ($appDir and $appDir != IPS_APP_COMPONENT and $appHide) {
                             continue;
                         } else {
                             if ($appDir and !IPSLib::appIsInstalled($appDir)) {
                                 continue;
                             }
                         }
                     }
                     /* Tied to specific modules within the app? */
                     if ($row['cache_value_6'] and $this->request['module']) {
                         if (!in_array($this->request['module'], explode(',', str_replace(' ', '', $row['cache_value_6'])))) {
                             continue;
                         }
                     }
                     $skinCaches['css'][$row['cache_value_1']] = array('content' => $row['cache_content'], 'attributes' => $row['cache_value_5']);
                     break;
                 case 'replacements':
                     $skinCaches['replacements'] = $row['cache_content'];
                     break;
             }
         }
         $this->skin['_css'] = is_array($skinCaches['css']) ? $skinCaches['css'] : array();
         $this->skin['_replacements'] = unserialize($skinCaches['replacements']);
         $this->skin['_skincacheid'] = $this->skin['set_id'];
         $this->skin['_csscacheid'] = 'css_' . $this->skin['set_id'];
         // Set a hash we can use to prevent client caching of CSS/JS
         $this->antiCacheHash = md5(IPB_VERSION . $this->settings['board_url'] . md5($this->settings['sql_tbl_prefix'] . $this->settings['sql_pass']) . $this->skin['set_updated']);
         /* IN_DEV Stuff */
         if (IN_DEV) {
             $this->skin['_css'] = array();
             if (is_file(IPS_CACHE_PATH . 'cache/skin_cache/masterMap.php')) {
                 $REMAP = $this->buildRemapData();
                 $_setId = intval($REMAP['inDevDefault']);
                 $_dir = $REMAP['templates'][$REMAP['inDevDefault']];
                 $_cdir = $REMAP['css'][$REMAP['inDevDefault']];
                 /* Reset master dir */
                 $this->skin['set_image_dir'] = $REMAP['images'][$REMAP['inDevDefault']];
                 $this->skin['set_key'] = $REMAP['inDevDefault'];
             } else {
                 $_setId = 0;
                 $_dir = 'master_skin';
                 $_cdir = 'master_css';
             }
             /* Using a custom master skin */
             if ($_setId) {
                 $this->skin = $this->allSkins[$_setId];
                 $this->skin['_replacements'] = unserialize($skinCaches['replacements']);
             }
             /* Sort out CSS */
             if (!isset($this->_skinFunctions) || !is_object($this->_skinFunctions)) {
                 require_once IPS_ROOT_PATH . 'sources/classes/skins/skinFunctions.php';
                 /*noLibHook*/
                 require_once IPS_ROOT_PATH . 'sources/classes/skins/skinCaching.php';
                 /*noLibHook*/
                 $this->_skinFunctions = new skinCaching($this->registry);
             }
             $css = $this->_skinFunctions->fetchDirectoryCSS($_cdir);
             $tmp = array();
             $ord = array();
             foreach ($css as $name => $data) {
                 /* Tied to app? */
                 if ($data['css_app'] and $data['css_app'] != IPS_APP_COMPONENT and $data['css_app_hide']) {
                     continue;
                 }
                 /* Tied to specific modules within the app? */
                 if ($data['css_modules'] and !in_array($this->request['module'], explode(',', str_replace(' ', '', $data['css_modules'])))) {
                     continue;
                 }
                 $tmp[$data['css_position'] . '.' . $data['css_group']][$name] = array('content' => $data['css_content'], 'attributes' => $data['css_attributes']);
             }
             ksort($tmp);
             foreach ($tmp as $blah => $data) {
                 foreach ($data as $name => $data) {
                     $ord[$blah] = array('css_group' => $name, 'css_position' => 1);
                     $this->skin['_css'][$name] = $data;
                 }
             }
             /* Other data */
             $this->skin['_cssGroupsArray'] = $ord;
             $this->skin['_skincacheid'] = is_dir(IPS_CACHE_PATH . 'cache/skin_cache/' . $_dir) ? $_setId : $this->skin['set_id'];
             $this->skin['_csscacheid'] = $_cdir;
             $this->skin['set_css_inline'] = is_dir(IPS_PUBLIC_PATH . 'style_css/' . $_cdir) ? 1 : 0;
             if (is_file(IPS_CACHE_PATH . 'cache/skin_cache/' . $_dir . '/_replacements.inc')) {
                 $replacements = array();
                 include_once IPS_CACHE_PATH . 'cache/skin_cache/' . $_dir . '/_replacements.inc';
                 /*noLibHook*/
                 $this->skin['_replacements'] = $replacements;
             }
         }
         /* Is this a mobile skin? */
         if ($this->skin['set_key'] == 'mobile') {
             $this->setAsMobileSkin(true);
         }
         //-----------------------------------------
         // Which output engine?
         //-----------------------------------------
         if ($this->skin['set_output_format']) {
             if (file_exists(IPS_ROOT_PATH . 'sources/classes/output/formats/' . $this->skin['set_output_format'])) {
                 $_outputFormat = $this->skin['set_output_format'];
                 $_outputClassName = $this->skin['set_output_format'] . 'Output';
             }
         }
         require_once IPS_ROOT_PATH . 'sources/classes/output/formats/coreOutput.php';
         /*noLibHook*/
         $outputClassToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/output/formats/' . $_outputFormat . '/' . $_outputClassName . '.php', $_outputClassName);
         $this->outputFormatClass = new $outputClassToLoad($this);
         /* Build URLs */
         $this->_buildUrls();
         /* Special set up for mobile skin */
         if ($this->getAsMobileSkin() === true) {
             $this->_mobileSkinSetUp();
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Restore IPB default skin as default
  * 
  * @return	@e void
  */
 public function setDefaultSkin()
 {
     /* Get skin functions library */
     require_once IPS_ROOT_PATH . 'sources/classes/skins/skinFunctions.php';
     /*noLibHook*/
     require_once IPS_ROOT_PATH . 'sources/classes/skins/skinCaching.php';
     /*noLibHook*/
     $skinFunctions = new skinCaching($this->registry);
     /* Update members to use default skin */
     $this->DB->update('members', array('skin' => 0));
     /* Update forums to use default skin */
     $this->DB->update('forums', array('skin_id' => 0));
     /* Reset any default skin(s) */
     $this->DB->update('skin_collections', array('set_is_default' => 0));
     /* Set IPB default skin as default */
     $this->DB->update('skin_collections', array('set_is_default' => 1), "set_key='default'");
     /* Verify we have a skin set as default */
     $_check = $this->DB->buildAndFetch(array('select' => 'count(*) as total', 'from' => 'skin_collections', 'where' => 'set_is_default=1'));
     if ($_check['total'] < 1) {
         $this->DB->build(array('update' => 'skin_collections', 'set' => 'set_is_default=1', 'where' => "set_output_format='html'", 'limit' => array(0, 1)));
         $this->DB->execute();
     }
     /* Check for any modifications in IPB default skin */
     $_master = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'skin_collections', 'where' => "set_key='default'"));
     $_master['set_id'] = intval($_master['set_id']);
     $_modifiedTemplates = $this->DB->buildAndFetch(array('select' => 'count(*) as total', 'from' => 'skin_templates', 'where' => "template_set_id={$_master['set_id']} AND template_removable=1 OR template_user_edited=1"));
     $_modifiedCSS = $this->DB->buildAndFetch(array('select' => 'count(*) as total', 'from' => 'skin_css', 'where' => "css_set_id={$_master['set_id']} AND css_master_key=''"));
     if ($_modifiedTemplates['total'] or $_modifiedCSS['total']) {
         /* Create a new skin with IPB default as parent */
         $curPos = $skinFunctions->fetchHighestSetPosition();
         $_master['set_key'] = 'default_modified';
         $_master['set_parent_id'] = $_master['set_id'];
         $_master['set_is_default'] = 0;
         $_master['set_name'] = $_master['set_name'] . ' (Pre 3.2)';
         $_master['set_order'] = (int) $curPos++;
         unset($_master['set_id']);
         $this->DB->insert('skin_collections', $_master);
         $set_id = $this->DB->getInsertId();
         $this->DB->update('skin_templates', array('template_set_id' => $set_id), "template_set_id={$_master['set_parent_id']} AND template_removable=1 OR template_user_edited=1");
         $this->DB->update('skin_css', array('css_set_id' => $set_id), "css_set_id={$_master['set_parent_id']} AND css_master_key=''");
         $skinFunctions->rebuildSkinSetsCache();
         $skinFunctions->rebuildTreeInformation($set_id);
         //$skinFunctions->flushSkinData();
         $skinFunctions->rebuildCSS($set_id);
         $skinFunctions->rebuildPHPTemplates($set_id);
         $skinFunctions->rebuildReplacementsCache($set_id);
     }
     /* Message */
     $this->registry->output->addMessage("Восстановлен новый базовый стиль....");
     /* Next Page */
     $this->request['workact'] = 'hooks';
 }
Ejemplo n.º 3
0
 /**
  * Uninstall a hook
  *
  * @return	@e void		[Outputs to screen]
  */
 protected function _uninstallHook()
 {
     /* Init vars */
     $hook_id = intval($this->request['id']);
     $hook = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_hooks', 'where' => 'hook_id=' . $hook_id));
     $extra_data = unserialize($hook['hook_extra_data']);
     if (!$hook['hook_id']) {
         $this->registry->output->global_message = $this->lang->words['h_hasbeenun'];
         $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&amp;do=hooks_overview');
     }
     /* Got any custom file to initialize? */
     $_customFile = '';
     $customClass = null;
     if ($extra_data['display']['custom']) {
         $_customFile = IPS_HOOKS_PATH . 'install_' . $extra_data['display']['custom'];
         if (is_file($_customFile)) {
             require_once $_customFile;
             /*noLibHook*/
             $classname = str_replace('.php', '', $extra_data['display']['custom']);
             if (class_exists($classname)) {
                 $customClass = new $classname($this->registry);
                 if (method_exists($customClass, 'pre_uninstall')) {
                     $customClass->pre_uninstall();
                 }
             }
         }
     }
     /* Get associated files */
     $this->DB->build(array('select' => 'hook_file_stored', 'from' => 'core_hooks_files', 'where' => 'hook_hook_id=' . $hook_id));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         @unlink(IPS_HOOKS_PATH . $r['hook_file_stored']);
     }
     /* Delete hook file entries */
     $this->DB->delete('core_hooks_files', "hook_hook_id={$hook_id}");
     //-----------------------------------------
     // Settings or setting groups?
     //-----------------------------------------
     if (count($extra_data['settingGroups'])) {
         $this->DB->delete('core_sys_settings_titles', "conf_title_keyword IN('" . implode("','", $extra_data['settingGroups']) . "')");
     }
     if (count($extra_data['settings'])) {
         $this->DB->delete('core_sys_conf_settings', "conf_key IN('" . implode("','", $extra_data['settings']) . "')");
     }
     $this->cache->rebuildCache('settings', 'global');
     //-----------------------------------------
     // Language strings/files
     //-----------------------------------------
     if (count($extra_data['language'])) {
         foreach ($extra_data['language'] as $file => $bit) {
             $this->DB->delete('core_sys_lang_words', "word_pack='{$file}' AND word_key IN('" . implode("','", $bit) . "')");
         }
         $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'];
         }
         $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);
         }
     }
     //-----------------------------------------
     // Modules
     //-----------------------------------------
     if (count($extra_data['modules'])) {
         foreach ($extra_data['modules'] as $module) {
             list($_side, $_app, $_module) = explode('-', $module);
             $_is_admin = $_side == 'admin' ? 1 : 0;
             $this->DB->delete('core_sys_module', "sys_module_application='{$_app}' AND sys_module_key='{$_module}' AND sys_module_admin={$_is_admin}");
         }
         $this->cache->rebuildCache('module_cache', 'global');
         $this->cache->rebuildCache('app_menu_cache', 'global');
     }
     //-----------------------------------------
     // Help files
     //-----------------------------------------
     if (count($extra_data['help'])) {
         $this->DB->delete('faq', "title IN('" . implode("','", $extra_data['help']) . "')");
     }
     //-----------------------------------------
     // Skin templates
     //-----------------------------------------
     if (count($extra_data['templates'])) {
         foreach ($extra_data['templates'] as $group => $bits) {
             $this->DB->delete('skin_templates', "template_group='{$group}' AND template_name IN('" . implode("','", $bits) . "')");
         }
         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->rebuildPHPTemplates(0);
     }
     //-----------------------------------------
     // CSS
     //-----------------------------------------
     if (count($extra_data['css'])) {
         $this->DB->delete('skin_css', "css_group IN('" . implode("','", $extra_data['css']) . "')");
         if (!$skinCaching) {
             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->rebuildCSSCache(0);
     }
     //-----------------------------------------
     // Tasks
     //-----------------------------------------
     if (count($extra_data['tasks'])) {
         $this->DB->delete('task_manager', "task_key IN('" . implode("','", $extra_data['tasks']) . "')");
     }
     //-----------------------------------------
     // Database changes
     //-----------------------------------------
     if (is_array($extra_data['database']['create']) and count($extra_data['database']['create'])) {
         foreach ($extra_data['database']['create'] as $create_query) {
             $this->DB->return_die = true;
             $this->DB->dropTable($create_query['name']);
             $this->DB->return_die = false;
         }
     }
     if (is_array($extra_data['database']['alter']) and count($extra_data['database']['alter'])) {
         foreach ($extra_data['database']['alter'] as $alter_query) {
             $this->DB->return_die = true;
             if ($alter_query['altertype'] == 'add') {
                 if ($this->DB->checkForField($alter_query['field'], $alter_query['table'])) {
                     $this->DB->dropField($alter_query['table'], $alter_query['field']);
                 }
             } else {
                 if ($alter_query['altertype'] == 'change') {
                     if ($this->DB->checkForField($alter_query['newfield'], $alter_query['table'])) {
                         $this->DB->changeField($alter_query['table'], $alter_query['newfield'], $alter_query['field'], $alter_query['fieldtype'], $alter_query['default']);
                     }
                 }
             }
             $this->DB->return_die = false;
         }
     }
     if (is_array($extra_data['database']['update']) and count($extra_data['database']['update'])) {
         foreach ($extra_data['database']['update'] as $update_query) {
             $this->DB->return_die = true;
             $this->DB->update($update_query['table'], array($update_query['field'] => $update_query['oldvalue']), $update_query['where']);
             $this->DB->return_die = false;
         }
     }
     if (is_array($extra_data['database']['insert']) and count($extra_data['database']['insert'])) {
         foreach ($extra_data['database']['insert'] as $insert_query) {
             if ($insert_query['fordelete']) {
                 $this->DB->return_die = true;
                 $this->DB->delete($insert_query['table'], $insert_query['fordelete']);
                 $this->DB->return_die = false;
             }
         }
     }
     //-----------------------------------------
     // Custom install/uninstall script?
     //-----------------------------------------
     if ($_customFile) {
         if (is_object($customClass) && method_exists($customClass, 'uninstall')) {
             $customClass->uninstall();
         }
         @unlink($_customFile);
     }
     /* Delete main hook entry */
     $this->DB->delete('core_hooks', "hook_id={$hook_id}");
     $this->rebuildHooksCache();
     /* Done */
     $this->registry->output->global_message = $this->lang->words['h_hasbeenun'];
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&amp;do=hooks_overview');
 }