/** * Load a template file. * * @throws iMSCP_Exception If template file is not found * @param string|array $fname Template file path or an array where the second item contain the template file path * @return mixed|string */ public function get_file($fname) { static $parentTplDir = null; if (!is_array($fname)) { $this->eventManager->dispatch(iMSCP_Events::onBeforeAssembleTemplateFiles, array('context' => $this, 'templatePath' => $this->root_dir . '/' . $fname)); } else { // INCLUDED file $fname = $parentTplDir !== null ? $parentTplDir . '/' . $fname[1] : $fname[1]; } if ($this->is_safe($fname)) { $prevParentTplDir = $parentTplDir; $parentTplDir = dirname($fname); $this->eventManager->dispatch(iMSCP_Events::onBeforeLoadTemplateFile, array('context' => $this, 'templatePath' => $this->root_dir . '/' . $fname)); ob_start(); include $this->root_dir . '/' . $fname; $fileContent = ob_get_clean(); $this->eventManager->dispatch(iMSCP_Events::onAfterLoadTemplateFile, array('context' => $this, 'templateContent' => $fileContent)); $fileContent = preg_replace_callback($this->tpl_include, array($this, 'get_file'), $fileContent); $parentTplDir = $prevParentTplDir; } else { throw new iMSCP_Exception(sprintf('Unable to find the %s template file', $this->root_dir . '/' . $fname)); } $this->eventManager->dispatch(iMSCP_Events::onAfterAssembleTemplateFiles, array('context' => $this, 'templateContent' => $fileContent)); return $fileContent; }
/** * Protect the given plugin * * @param string $name Name of the plugin to protect * @return bool self::ACTION_SUCCESS|self::ACTION_FAILURE */ public function pluginProtect($name) { if ($this->pluginIsEnabled($name) && !$this->pluginIsProtected($name)) { $responses = $this->eventsManager->dispatch(iMSCP_Events::onBeforeProtectPlugin, array('pluginManager' => $this, 'pluginName' => $name)); if (!$responses->isStopped()) { $protectedPlugins = $this->protectedPlugins; $this->protectedPlugins[] = $name; if ($this->pluginUpdateProtectedFile()) { $this->eventsManager->dispatch(iMSCP_Events::onAfterProtectPlugin, array('pluginManager' => $this, 'pluginName' => $name)); return self::ACTION_SUCCESS; } $this->protectedPlugins = $protectedPlugins; } else { return self::ACTION_STOPPED; } } return self::ACTION_FAILURE; }