예제 #1
0
 /**
  * Hook add/edit save
  * Save the new (or updated) hook record
  *
  * @param	string		[add|edit]
  * @return	@e void		[Outputs to screen]
  */
 protected function _hookSave($type = 'add')
 {
     /* Init vars */
     $hookData = array();
     $newFiles = array();
     $requireApp = array();
     $_hookFiles = array();
     $extraKey = '';
     /* Get data if we are editing */
     if ($type == 'edit') {
         $id = intval($this->request['hook_id']);
         if (!$id) {
             $this->registry->output->showError($this->lang->words['h_noedit'], 1118);
         }
         $hookData = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_hooks', 'where' => 'hook_id=' . $id));
         if (!$hookData['hook_id']) {
             $this->registry->output->showError($this->lang->words['h_noedit'], 1119);
         }
         $extraKey = ' AND hook_id != ' . $hookData['hook_id'];
     }
     /* Error Checking */
     if (!$this->request['hook_name']) {
         $errors[] = $this->lang->words['hook_form_no_title'];
     }
     if (empty($this->request['hook_key'])) {
         $errors[] = $this->lang->words['hook_form_no_key'];
     } else {
         $keyCheck = $this->DB->buildAndFetch(array('select' => 'count(*) as found', 'from' => 'core_hooks', 'where' => "hook_key='" . $this->DB->addSlashes($this->request['hook_key']) . "'" . $extraKey));
         if ($keyCheck['found'] > 0) {
             $errors[] = $this->lang->words['hook_form_dupe_key'];
         }
     }
     /* Got any errors? */
     if (is_array($errors) && count($errors)) {
         $this->registry->output->global_error = implode('<br />', $errors);
         $this->_hookForm();
         return;
     }
     /* Not IN_DEV? */
     if (!IN_DEV) {
         $this->DB->build(array('select' => '*', 'from' => 'core_hooks_files', 'where' => 'hook_hook_id=' . intval($this->request['hook_id'])));
         $this->DB->execute();
         while ($_r = $this->DB->fetch()) {
             $_hookFiles[$_r['hook_classname']] = $_r['hook_file_stored'];
         }
     }
     /* Check for requirements */
     if (is_array($this->request['requireApp']) and count($this->request['requireApp'])) {
         foreach ($this->request['requireApp'] as $_index => $app_key) {
             if ($app_key) {
                 $minVersion = intval($this->request['minVersion'][$_index]);
                 $maxVersion = intval($this->request['maxVersion'][$_index]);
                 $requireApp[$app_key] = array('app_name' => ipsRegistry::$applications[$app_key]['app_title'], 'min_version' => $minVersion, 'max_version' => $maxVersion);
             }
         }
     }
     /* Check for files */
     if (is_array($this->request['file']) and count($this->request['file'])) {
         foreach ($this->request['file'] as $index => $file) {
             if ($file) {
                 $newFiles[$index] = array('hook_file_real' => $file, 'hook_type' => $this->request['hook_type'][$index], 'hook_classname' => $this->request['hook_classname'][$index], 'hook_data' => serialize(array('dataLocation' => trim($this->request['dataLocation'][$index]), 'libApplication' => trim($this->request['libApplication'][$index]), 'classToOverload' => trim($this->request['classToOverload'][$index]), 'skinGroup' => $this->request['skinGroup'][$index], 'skinFunction' => $this->request['skinFunction'][$index], 'type' => $this->request['type'][$index], 'id' => $this->request['id'][$index], 'position' => $this->request['position'][$index])));
                 /**
                  * @link	http://community.invisionpower.com/tracker/issue-22084-hook-edit-does-not-preserve-correct-name/
                  * We don't want to reset the stored name if you are not in developer mode
                  */
                 if (IN_DEV) {
                     $newFiles[$index]['hook_file_stored'] = $file;
                     // During import this is a random name, but for devs it's actual file
                 } else {
                     $newFiles[$index]['hook_file_stored'] = $_hookFiles[$this->request['hook_classname'][$index]] ? $_hookFiles[$this->request['hook_classname'][$index]] : $file;
                 }
             }
         }
     }
     /* Get position */
     if ($type == 'add') {
         $position = $this->DB->buildAndFetch(array('select' => 'MAX(hook_position) as newPos', 'from' => 'core_hooks'));
         $position['newPos'] = intval($position['newPos']) + 1;
     } else {
         $position['newPos'] = $hookData['hook_position'];
     }
     $mainHookRecord = array('hook_name' => trim($this->request['hook_name']), 'hook_key' => substr(trim($this->request['hook_key']), 0, 32), 'hook_global_caches' => is_array($this->request['hook_global_caches']) && count($this->request['hook_global_caches']) ? implode(',', $this->request['hook_global_caches']) : '', 'hook_desc' => trim($this->request['hook_desc']), 'hook_version_human' => trim($this->request['hook_version_human']), 'hook_version_long' => trim($this->request['hook_version_long']), 'hook_author' => trim($this->request['hook_author']), 'hook_email' => trim($this->request['hook_email']), 'hook_website' => trim($this->request['hook_website']), 'hook_update_check' => trim($this->request['hook_update_check']), 'hook_enabled' => $type == 'add' ? 1 : $hookData['hook_enabled'], 'hook_installed' => $type == 'add' ? IPS_UNIX_TIME_NOW : $hookData['hook_installed'], 'hook_updated' => $type == 'add' ? 0 : IPS_UNIX_TIME_NOW, 'hook_position' => $position['newPos'], 'hook_requirements' => serialize(array('required_applications' => $requireApp, 'hook_php_version_min' => trim($this->request['hook_php_version_min']), 'hook_php_version_max' => trim($this->request['hook_php_version_max']))));
     if ($type == 'edit') {
         $this->DB->update('core_hooks', $mainHookRecord, 'hook_id=' . $hookData['hook_id']);
         $this->DB->delete('core_hooks_files', 'hook_hook_id=' . $hookData['hook_id']);
     } else {
         $this->DB->insert('core_hooks', $mainHookRecord);
         $hookData['hook_id'] = $this->DB->getInsertId();
     }
     foreach ($newFiles as $index => $toInsert) {
         $toInsert['hook_hook_id'] = $hookData['hook_id'];
         $this->DB->insert('core_hooks_files', $toInsert);
     }
     /* Rebuild cache */
     $this->rebuildHooksCache();
     /* Rebuild global caches */
     try {
         IPSLib::cacheGlobalCaches();
     } catch (Exception $e) {
     }
     /* 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();
     /* Redirect */
     $this->registry->output->setMessage($this->lang->words['h_saved']);
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&amp;do=hooks_overview');
 }
예제 #2
0
 /**
  * Rebuild PHP Templates Cache
  *
  * @return	@e void
  */
 public function recacheTemplates()
 {
     /* 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);
     /* Flag all for recache */
     $skinCaching->flagSetForRecache();
     $data = $this->getVars();
     $this->showRedirectScreen($data['app_directory'], array($this->lang->words['install_skins_flag_recache']), '', $this->getNextURL('finish', $data));
 }
예제 #3
0
 /**
  * Edit Settings
  */
 public function editSettings()
 {
     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(ipsRegistry::instance());
     if (ipsRegistry::$request['recache']) {
         $skinFunctions->flushipscdn();
         ipsRegistry::getClass('output')->redirect(ipsRegistry::$settings['_base_url'] . "app=core&amp;module=applications&amp;section=enhancements&amp;do=edit&amp;service=enhancements_core_ipscdn", ipsRegistry::getClass('class_localization')->words['cdn_recached']);
     }
     if (ipsRegistry::$request['disable']) {
         IPSLib::updateSettings(array('ips_cdn' => FALSE, 'ipb_img_url' => '', 'ipb_css_url' => '', 'ipb_js_url' => '', 'upload_url' => ''));
         if (IPSLib::appIsInstalled('gallery')) {
             $this_script = str_replace('\\', '/', getenv('SCRIPT_FILENAME'));
             $url = ipsRegistry::$settings['_original_base_url'];
             if ($this_script) {
                 $this_script = str_replace('/' . CP_DIRECTORY . '/index.php', '', $this_script);
                 if (substr(ipsRegistry::$settings['gallery_images_path'], 0, strlen($this_script)) === $this_script) {
                     $url = str_replace('\\', '/', str_replace($this_script, $url, ipsRegistry::$settings['gallery_images_path']));
                 }
             } else {
                 $url .= '/uploads';
             }
             IPSLib::updateSettings(array('gallery_images_path' => $url));
         }
         IPSContentCache::truncate('post');
         IPSContentCache::truncate('sig');
         /* Set skin sets to recache */
         $skinFunctions->flagSetForRecache();
         ipsRegistry::getClass('output')->redirect(ipsRegistry::$settings['_base_url'] . "app=core&amp;module=applications&amp;section=enhancements", ipsRegistry::getClass('class_localization')->words['cdn_disabled']);
         return;
     }
     if (!ipsRegistry::$settings['ipb_reg_number']) {
         ipsRegistry::getClass('output')->showError(sprintf(ipsRegistry::getClass('class_localization')->words['enhancements_ipscdn_error_nokey'], ipsRegistry::getClass('output')->buildUrl('app=core&module=tools&section=licensekey', 'admin')));
     }
     $classToLoad = IPSLib::loadLibrary(IPS_KERNEL_PATH . 'classFileManagement.php', 'classFileManagement');
     $file = new $classToLoad();
     $return = NULL;
     if ($json = @json_decode($ping, TRUE)) {
         if ($json['ENABLED'] and $json['BYTES'] > 0) {
             if (!ipsRegistry::$settings['ips_cdn'] and !ipsRegistry::$request['enable']) {
                 return $this->html->cdnInactive($json);
             } else {
                 $settings = array('ips_cdn' => TRUE, 'ipb_img_url' => $json['URL'], 'ipb_css_url' => rtrim($json['URL'], '/') . '/', 'ipb_js_url' => rtrim($json['URL'], '/') . '/', 'upload_url' => $json['URL'] . '/uploads');
                 if (IPSLib::appIsInstalled('downloads')) {
                     if (substr(ipsRegistry::$settings['idm_localsspath'], 0, 11) === '{root_path}') {
                         $settings['idm_screenshot_url'] = str_replace('{root_path}', $json['URL'], ipsRegistry::$settings['idm_localsspath']);
                     }
                 }
                 if (IPSLib::appIsInstalled('gallery')) {
                     $this_script = str_replace('\\', '/', getenv('SCRIPT_FILENAME'));
                     if ($this_script) {
                         $this_script = str_replace('/' . CP_DIRECTORY . '/index.php', '', $this_script);
                         if (substr(ipsRegistry::$settings['gallery_images_path'], 0, strlen($this_script)) === $this_script) {
                             $settings['gallery_images_url'] = str_replace('\\', '/', str_replace($this_script, $json['URL'], ipsRegistry::$settings['gallery_images_path']));
                         }
                     }
                 }
                 $_settings = array();
                 foreach ($settings as $k => $v) {
                     if (ipsRegistry::$settings[$k] != $v) {
                         $_settings[$k] = $v;
                     }
                 }
                 if (!empty($_settings)) {
                     IPSLib::updateSettings($settings);
                 }
                 /* Set skin sets to recache */
                 $skinFunctions->flagSetForRecache();
             }
         } else {
             $licenseData = ipsRegistry::cache()->getCache('licenseData');
             if ($licenseData['key']['url'] != ipsRegistry::$settings['board_url']) {
                 ipsRegistry::getClass('output')->showError(ipsRegistry::getClass('class_localization')->words['enhancements_ipscdn_error_url']);
             }
             /* Set skin sets to recache */
             $skinFunctions->flagSetForRecache();
             return $this->html->cdnNotEnabled($json);
         }
     } else {
         ipsRegistry::getClass('output')->showError(sprintf(ipsRegistry::getClass('class_localization')->words['enhancements_ipscdn_error_key'], ipsRegistry::getClass('output')->buildUrl('app=core&module=tools&section=licensekey', 'admin')));
     }
     return $this->html->cdnOverview($json);
 }