作者:jjpeters6
项目:pimcor
/**
*
*/
public function dispatchLoopShutdown()
{
if (!Tool::isHtmlResponse($this->getResponse())) {
return;
}
$siteKey = \Pimcore\Tool\Frontend::getSiteKey();
$reportConfig = \Pimcore\Config::getReportConfig();
if ($this->enabled && isset($reportConfig->tagmanager->sites->{$siteKey}->containerId)) {
$containerId = $reportConfig->tagmanager->sites->{$siteKey}->containerId;
if ($containerId) {
$code = <<<CODE
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id={$containerId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{$containerId}');</script>
<!-- End Google Tag Manager -->
CODE;
$body = $this->getResponse()->getBody();
// insert code after the opening <body> tag
$body = preg_replace("@<body(>|.*?[^?]>)@", "<body\$1\n\n" . $code, $body);
$this->getResponse()->setBody($body);
}
}
}
作者:Gerhard1
项目:pimcor
/**
* @throws \Exception
*/
public function init()
{
$conf = Config::getSystemConfig();
if (!$conf->webservice->enabled) {
throw new \Exception("Webservice API isn't enabled");
}
if (!$this->getParam("apikey") && $_COOKIE["pimcore_admin_sid"]) {
$user = Authentication::authenticateSession();
if (!$user instanceof User) {
throw new \Exception("User is not valid");
}
} else {
if (!$this->getParam("apikey")) {
throw new \Exception("API key missing");
} else {
$apikey = $this->getParam("apikey");
$userList = new User\Listing();
$userList->setCondition("apiKey = ? AND type = ? AND active = 1", array($apikey, "user"));
$users = $userList->load();
if (!is_array($users) or count($users) !== 1) {
throw new \Exception("API key error.");
}
if (!$users[0]->getApiKey()) {
throw new \Exception("Couldn't get API key for user.");
}
$user = $users[0];
}
}
\Zend_Registry::set("pimcore_admin_user", $user);
parent::init();
}
作者:pimcor
项目:pimcor
/**
* @param array $config
*/
public function config($config = [])
{
$settings = null;
// check for an initial configuration template
// used eg. by the demo installer
$configTemplatePath = PIMCORE_CONFIGURATION_DIRECTORY . "/system.template.php";
if (file_exists($configTemplatePath)) {
try {
$configTemplate = new \Zend_Config(include $configTemplatePath);
if ($configTemplate->general) {
// check if the template contains a valid configuration
$settings = $configTemplate->toArray();
// unset database configuration
unset($settings["database"]["params"]["host"]);
unset($settings["database"]["params"]["port"]);
}
} catch (\Exception $e) {
}
}
// set default configuration if no template is present
if (!$settings) {
// write configuration file
$settings = ["general" => ["timezone" => "Europe/Berlin", "language" => "en", "validLanguages" => "en", "debug" => "1", "debugloglevel" => "debug", "custom_php_logfile" => "1", "extjs6" => "1"], "database" => ["adapter" => "Mysqli", "params" => ["username" => "root", "password" => "", "dbname" => ""]], "documents" => ["versions" => ["steps" => "10"], "default_controller" => "default", "default_action" => "default", "error_pages" => ["default" => "/"], "createredirectwhenmoved" => "", "allowtrailingslash" => "no", "generatepreview" => "1"], "objects" => ["versions" => ["steps" => "10"]], "assets" => ["versions" => ["steps" => "10"]], "services" => [], "cache" => ["excludeCookie" => ""], "httpclient" => ["adapter" => "Zend_Http_Client_Adapter_Socket"]];
}
$settings = array_replace_recursive($settings, $config);
// create initial /website/var folder structure
// @TODO: should use values out of startup.php (Constants)
$varFolders = ["areas", "assets", "backup", "cache", "classes", "config", "email", "log", "plugins", "recyclebin", "search", "system", "tmp", "versions", "webdav"];
foreach ($varFolders as $folder) {
\Pimcore\File::mkdir(PIMCORE_WEBSITE_VAR . "/" . $folder);
}
$configFile = \Pimcore\Config::locateConfigFile("system.php");
File::putPhpFile($configFile, to_php_data_file_format($settings));
}
作者:pimcor
项目:pimcor
/**
* @param $documentId
* @param $config
* @throws \Exception
*/
public function preparePdfGeneration($documentId, $config)
{
$document = $this->getPrintDocument($documentId);
if (Model\Tool\TmpStore::get($document->getLockKey())) {
throw new \Exception("Process with given document alredy running.");
}
Model\Tool\TmpStore::add($document->getLockKey(), true);
$jobConfig = new \stdClass();
$jobConfig->documentId = $documentId;
$jobConfig->config = $config;
$this->saveJobConfigObjectFile($jobConfig);
$this->updateStatus($documentId, 0, "prepare_pdf_generation");
$args = ["-p " . $jobConfig->documentId];
$env = \Pimcore\Config::getEnvironment();
if ($env !== false) {
$args[] = "--environment=" . $env;
}
$cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " web2print:pdf-creation " . implode(" ", $args);
Logger::info($cmd);
if (!$config['disableBackgroundExecution']) {
Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "web2print-output.log");
} else {
Processor::getInstance()->startPdfGeneration($jobConfig->documentId);
}
}
作者:studioemm
项目:multilingua
public function addLanguage($languageToAdd)
{
// Check if language is not already added
if (in_array($languageToAdd, Tool::getValidLanguages())) {
$result = false;
} else {
// Read all the documents from the first language
$availableLanguages = Tool::getValidLanguages();
$firstLanguageDocument = \Pimcore\Model\Document::getByPath('/' . reset($availableLanguages));
\Zend_Registry::set('SEI18N_add', 1);
// Add the language main folder
$document = Page::create(1, array('key' => $languageToAdd, "userOwner" => 1, "userModification" => 1, "published" => true, "controller" => 'default', "action" => 'go-to-first-child'));
$document->setProperty('language', 'text', $languageToAdd);
// Set the language to this folder and let it inherit to the child pages
$document->setProperty('isLanguageRoot', 'text', 1, false, false);
// Set as language root document
$document->save();
// Add Link to other languages
$t = new Keys();
$t->insert(array("document_id" => $document->getId(), "language" => $languageToAdd, "sourcePath" => $firstLanguageDocument->getFullPath()));
// Lets add all the docs
$this->addDocuments($firstLanguageDocument->getId(), $languageToAdd);
\Zend_Registry::set('SEI18N_add', 0);
$oldConfig = Config::getSystemConfig();
$settings = $oldConfig->toArray();
$languages = explode(',', $settings['general']['validLanguages']);
$languages[] = $languageToAdd;
$settings['general']['validLanguages'] = implode(',', $languages);
$config = new \Zend_Config($settings, true);
$writer = new \Zend_Config_Writer_Xml(array("config" => $config, "filename" => PIMCORE_CONFIGURATION_SYSTEM));
$writer->write();
$result = true;
}
return $result;
}
作者:shanky011
项目:pimcore-plugin-subdomain-admi
public function init()
{
// Disable plugin if the allowed domain is not yet set
$settingDomain = WebsiteSetting::getByName("subdomainAdmin");
if (!is_object($settingDomain) || $settingDomain->getData() == "") {
return;
}
// Create temporary request object - not available yet in front controller
$currentUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$request = new \Zend_Controller_Request_Http($currentUrl);
// Disable main domain setting to allow admin access on another domain
$conf = Config::getSystemConfig();
$mainDomain = $conf->general->domain;
if (Tool::isRequestToAdminBackend($request) && Tool::isDomainAllowedToAdminBackend($request)) {
$confArr = $conf->toArray();
$mainDomain = $confArr['general']['domain'];
$confArr['general']['domain'] = "";
Config::setSystemConfig(new \Zend_Config($confArr));
}
// Register plugin
\Pimcore::getEventManager()->attach("system.startup", function ($event) use(&$mainDomain) {
$front = \Zend_Controller_Front::getInstance();
$frontControllerPlugin = new FrontControllerPlugin();
$front->registerPlugin($frontControllerPlugin);
// Restore main domain
$conf = Config::getSystemConfig();
$confArr = $conf->toArray();
$confArr['general']['domain'] = $mainDomain;
Config::setSystemConfig(new \Zend_Config($confArr));
});
}
作者:emanuel-londo
项目:pimcor
public function saveAction()
{
$this->checkPermission("system_settings");
$values = \Zend_Json::decode($this->getParam("data"));
$configFile = \Pimcore\Config::locateConfigFile("reports.php");
File::put($configFile, to_php_data_file_format($values));
$this->_helper->json(array("success" => true));
}
作者:emanuel-londo
项目:pimcor
/**
* @param null $site
* @return bool
*/
public static function getSiteConfig($site = null)
{
$siteKey = \Pimcore\Tool\Frontend::getSiteKey($site);
if (Config::getReportConfig()->webmastertools->sites->{$siteKey}->verification) {
return Config::getReportConfig()->webmastertools->sites->{$siteKey};
}
return false;
}
作者:solvera
项目:pimcor
/**
* @param \Zend_Controller_Request_Abstract $request
* @throws mixed
*/
protected function _handleError(\Zend_Controller_Request_Abstract $request)
{
// remove zend error handler
$front = \Zend_Controller_Front::getInstance();
$front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler");
$response = $this->getResponse();
if ($response->isException() && !$this->_isInsideErrorHandlerLoop) {
// get errorpage
try {
// enable error handler
$front->setParam('noErrorHandler', false);
$errorPath = Config::getSystemConfig()->documents->error_pages->default;
if (Site::isSiteRequest()) {
$site = Site::getCurrentSite();
$errorPath = $site->getErrorDocument();
}
if (empty($errorPath)) {
$errorPath = "/";
}
$document = Document::getByPath($errorPath);
if (!$document instanceof Document\Page) {
// default is home
$document = Document::getById(1);
}
if ($document instanceof Document\Page) {
$params = Tool::getRoutingDefaults();
if ($module = $document->getModule()) {
$params["module"] = $module;
}
if ($controller = $document->getController()) {
$params["controller"] = $controller;
$params["action"] = "index";
}
if ($action = $document->getAction()) {
$params["action"] = $action;
}
$this->setErrorHandler($params);
$request->setParam("document", $document);
\Zend_Registry::set("pimcore_error_document", $document);
// ensure that a viewRenderer exists, and is enabled
if (!\Zend_Controller_Action_HelperBroker::hasHelper("viewRenderer")) {
$viewRenderer = new \Pimcore\Controller\Action\Helper\ViewRenderer();
\Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
}
$viewRenderer = \Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer");
$viewRenderer->setNoRender(false);
if ($viewRenderer->view === null) {
$viewRenderer->initView(PIMCORE_WEBSITE_PATH . "/views");
}
}
} catch (\Exception $e) {
\Logger::emergency("error page not found");
}
}
// call default ZF error handler
parent::_handleError($request);
}
作者:solvera
项目:pimcor
public function setSystemInstanceIdentifier()
{
$instanceIdentifier = \Pimcore\Config::getSystemConfig()->general->instanceIdentifier;
if (!$instanceIdentifier) {
throw new \Exception("No instance identifier set in system config!");
}
$this->setInstanceIdentifier($instanceIdentifier);
return $this;
}
作者:sfi
项目:pimcor
/**
*
*/
public function dispatchLoopShutdown()
{
$config = \Pimcore\Config::getSystemConfig();
if (!$config->general->show_cookie_notice || !Tool::useFrontendOutputFilters($this->getRequest()) || !Tool::isHtmlResponse($this->getResponse())) {
return;
}
$template = file_get_contents(__DIR__ . "/EuCookieLawNotice/template.html");
# cleanup code
$template = preg_replace('/[\\r\\n\\t]+/', ' ', $template);
#remove new lines, spaces, tabs
$template = preg_replace('/>[\\s]+</', '><', $template);
#remove new lines, spaces, tabs
$template = preg_replace('/[\\s]+/', ' ', $template);
#remove new lines, spaces, tabs
$translations = $this->getTranslations();
foreach ($translations as $key => &$value) {
$value = htmlentities($value, ENT_COMPAT, "UTF-8");
$template = str_replace("%" . $key . "%", $value, $template);
}
$linkContent = "";
if (array_key_exists("linkTarget", $translations)) {
$linkContent = '<a href="' . $translations["linkTarget"] . '" data-content="' . $translations["linkText"] . '"></a>';
}
$template = str_replace("%link%", $linkContent, $template);
$templateCode = \Zend_Json::encode($template);
$code = '
<script>
(function () {
var ls = window["localStorage"];
if(ls && !ls.getItem("pc-cookie-accepted")) {
var code = ' . $templateCode . ';
var ci = window.setInterval(function () {
if(document.body) {
clearInterval(ci);
document.body.insertAdjacentHTML("beforeend", code);
document.getElementById("pc-button").onclick = function () {
document.getElementById("pc-cookie-notice").style.display = "none";
ls.setItem("pc-cookie-accepted", "true");
};
}
}, 100);
}
})();
</script>
';
$body = $this->getResponse()->getBody();
// search for the end <head> tag, and insert the google analytics code before
// this method is much faster than using simple_html_dom and uses less memory
$headEndPosition = stripos($body, "</head>");
if ($headEndPosition !== false) {
$body = substr_replace($body, $code . "</head>", $headEndPosition, 7);
}
$this->getResponse()->setBody($body);
}
作者:pimcor
项目:pimcor
public function adminerAction()
{
$conf = \Pimcore\Config::getSystemConfig()->database->params;
if (empty($_SERVER["QUERY_STRING"])) {
$this->redirect("/admin/external_adminer/adminer/?username=" . $conf->username . "&db=" . $conf->dbname);
exit;
}
chdir($this->adminerHome . "adminer");
include $this->adminerHome . "adminer/index.php";
$this->removeViewRenderer();
}
作者:solvera
项目:pimcor
/**
* @return PdfReactor8|WkHtmlToPdf
* @throws \Exception
*/
public static function getInstance()
{
$config = Config::getWeb2PrintConfig();
if ($config->generalTool == "pdfreactor") {
return new PdfReactor8();
} elseif ($config->generalTool == "wkhtmltopdf") {
return new WkHtmlToPdf();
} else {
throw new \Exception("Invalid Configuation - " . $config->generalTool);
}
}
作者:pimcor
项目:pimcor
/**
* @param null $site
* @return bool
*/
public static function getSiteConfig($site = null)
{
$siteKey = \Pimcore\Tool\Frontend::getSiteKey($site);
$config = Config::getReportConfig();
if (!$config->analytics) {
return false;
}
if ($config->analytics->sites->{$siteKey}) {
return Config::getReportConfig()->analytics->sites->{$siteKey};
}
return false;
}
作者:shanky011
项目:pimcore-plugin-subdomain-admi
private function getErrorDocument()
{
$config = Config::getSystemConfig();
$errorDocPath = $config->documents->error_pages->default;
if (Site::isSiteRequest()) {
$site = Site::getCurrentSite();
$errorDocPath = $site->getErrorDocument();
}
$errorDoc = Document::getByPath($errorDocPath);
\Zend_Registry::set("pimcore_error_document", $errorDoc);
return $errorDoc;
}
作者:pimcor
项目:pimcor
/**
* @return mixed|null
* @throws \Exception
*/
public static function getConfiguration()
{
$config = null;
$configFile = \Pimcore\Config::locateConfigFile("hybridauth.php");
if (is_file($configFile)) {
$config = (include $configFile);
$config["base_url"] = \Pimcore\Tool::getHostUrl() . "/hybridauth/endpoint";
} else {
throw new \Exception("HybridAuth configuration not found. Please place it into this file: {$configFile}");
}
return $config;
}
作者:ChristophWurs
项目:pimcor
/**
* @param \Zend_Controller_Request_Abstract $request
* @return bool|void
*/
public function routeStartup(\Zend_Controller_Request_Abstract $request)
{
$this->conf = \Pimcore\Config::getSystemConfig();
if ($request->getParam('disable_less_compiler') || $_COOKIE["disable_less_compiler"]) {
return $this->disable();
}
if (!$this->conf->outputfilters) {
return $this->disable();
}
if (!$this->conf->outputfilters->less) {
return $this->disable();
}
}
作者:yonetic
项目:pimcore-coreshop-dem
/**
* @param bool $raw
* @param bool $writeOnly
* @return Wrapper|\Zend_Db_Adapter_Abstract
* @throws \Exception
* @throws \Zend_Db_Profiler_Exception
*/
public static function getConnection($raw = false, $writeOnly = false)
{
// just return the wrapper (for compatibility reasons)
// the wrapper itself get's then the connection using $raw = true
if (!$raw) {
return new Wrapper();
}
$charset = "UTF8";
// explicit set charset for connection (to the adapter)
$config = Config::getSystemConfig()->database->toArray();
// write only handling
if ($writeOnly && isset($config["writeOnly"])) {
// overwrite params with write only configuration
$config["params"] = $config["writeOnly"]["params"];
} else {
if ($writeOnly) {
throw new \Exception("writeOnly connection is requested but not configured");
}
}
$config["params"]["charset"] = $charset;
try {
$db = \Zend_Db::factory($config["adapter"], $config["params"]);
$db->query("SET NAMES " . $charset);
} catch (\Exception $e) {
\Logger::emerg($e);
\Pimcore\Tool::exitWithError("Database Error! See debug.log for details");
}
// try to set innodb as default storage-engine
try {
$db->query("SET storage_engine=InnoDB;");
} catch (\Exception $e) {
\Logger::warn($e);
}
// try to set mysql mode
try {
$db->query("SET sql_mode = '';");
} catch (\Exception $e) {
\Logger::warn($e);
}
$connectionId = $db->fetchOne("SELECT CONNECTION_ID()");
// enable the db-profiler if the devmode is on and there is no custom profiler set (eg. in system.xml)
if (PIMCORE_DEVMODE && !$db->getProfiler()->getEnabled() || array_key_exists("pimcore_log", $_REQUEST) && \Pimcore::inDebugMode()) {
$profiler = new \Pimcore\Db\Profiler('All DB Queries');
$profiler->setEnabled(true);
$profiler->setConnectionId($connectionId);
$db->setProfiler($profiler);
}
\Logger::debug(get_class($db) . ": Successfully established connection to MySQL-Server, Process-ID: " . $connectionId);
return $db;
}
作者:jjpeters6
项目:pimcor
public function init()
{
parent::init();
if (is_file(\Pimcore\Config::locateConfigFile("system.php"))) {
// session authentication, only possible if user is logged in
$user = \Pimcore\Tool\Authentication::authenticateSession();
if (!$user instanceof User) {
die("Authentication failed!<br />If you don't have access to the admin interface any more, and you want to find out if the server configuration matches the requirements you have to rename the the system.php for the time of the check.");
}
} elseif ($this->getParam("mysql_adapter")) {
} else {
die("Not possible... no database settings given.<br />Parameters: mysql_adapter,mysql_host,mysql_username,mysql_password,mysql_database");
}
}
作者:emanuel-londo
项目:pimcor
/**
* @param $id
* @param bool $create
* @param bool $returnIdIfEmpty
* @param null $language
* @return array
* @throws \Exception
* @throws \Zend_Exception
*/
public static function getByKeyLocalized($id, $create = false, $returnIdIfEmpty = false, $language = null)
{
if ($user = Tool\Admin::getCurrentUser()) {
$language = $user->getLanguage();
} elseif ($user = Tool\Authentication::authenticateSession()) {
$language = $user->getLanguage();
} elseif (\Zend_Registry::isRegistered("Zend_Locale")) {
$language = (string) \Zend_Registry::get("Zend_Locale");
}
if (!in_array($language, Tool\Admin::getLanguages())) {
$config = \Pimcore\Config::getSystemConfig();
$language = $config->general->language;
}
return self::getByKey($id, $create, $returnIdIfEmpty)->getTranslation($language);
}