public function getDataByIdAction() { // check for lock if (\Pimcore\Model\Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => \Pimcore\Model\Element\Editlock::getByElement($this->getParam("id"), "document")]); } \Pimcore\Model\Element\Editlock::lock($this->getParam("id"), "document"); $page = Document\Printpage::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->getVersions(); $page->getScheduledTasks(); $page->idPath = Service::getIdPath($page); $page->userPermissions = $page->getUserPermissions(); $page->setLocked($page->isLocked()); if ($page->getContentMasterDocument()) { $page->contentMasterDocumentPath = $page->getContentMasterDocument()->getRealFullPath(); } $this->addTranslationsData($page); // unset useless data $page->setElements(null); $page->childs = null; // cleanup properties $this->minimizeProperties($page); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($page)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $page, "returnValueContainer" => $returnValueContainer]); if ($page->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]); } Element\Editlock::lock($this->getParam("id"), "document"); $email = Document\Newsletter::getById($this->getParam("id")); $email = clone $email; $email = $this->getLatestVersion($email); $versions = Element\Service::getSafeVersionInfo($email->getVersions()); $email->setVersions(array_splice($versions, 0, 1)); $email->idPath = Element\Service::getIdPath($email); $email->userPermissions = $email->getUserPermissions(); $email->setLocked($email->isLocked()); $email->setParent(null); // unset useless data $email->setElements(null); $email->childs = null; $this->addTranslationsData($email); $this->minimizeProperties($email); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($email)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $email, "returnValueContainer" => $returnValueContainer]); if ($email->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]); } Element\Editlock::lock($this->getParam("id"), "document"); $link = Document\Hardlink::getById($this->getParam("id")); $link = clone $link; $link->idPath = Element\Service::getIdPath($link); $link->userPermissions = $link->getUserPermissions(); $link->setLocked($link->isLocked()); $link->setParent(null); if ($link->getSourceDocument()) { $link->sourcePath = $link->getSourceDocument()->getRealFullPath(); } $this->addTranslationsData($link); $this->minimizeProperties($link); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($link)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $link, "returnValueContainer" => $returnValueContainer]); if ($link->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
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)); }); }
protected function execute(InputInterface $input, OutputInterface $output) { $validJobs = array(); if ($input->getOption("job")) { $validJobs = explode(",", $input->getOption("job")); } // create manager $manager = Schedule\Manager\Factory::getManager("maintenance.pid"); $manager->setValidJobs($validJobs); $manager->setForce((bool) $input->getOption("force")); // register scheduled tasks $manager->registerJob(new Schedule\Maintenance\Job("scheduledtasks", new Schedule\Task\Executor(), "execute")); $manager->registerJob(new Schedule\Maintenance\Job("logmaintenance", new \Pimcore\Log\Maintenance(), "mail")); $manager->registerJob(new Schedule\Maintenance\Job("cleanuplogfiles", new \Pimcore\Log\Maintenance(), "cleanupLogFiles")); $manager->registerJob(new Schedule\Maintenance\Job("httperrorlog", new \Pimcore\Log\Maintenance(), "httpErrorLogCleanup")); $manager->registerJob(new Schedule\Maintenance\Job("usagestatistics", new \Pimcore\Log\Maintenance(), "usageStatistics")); $manager->registerJob(new Schedule\Maintenance\Job("checkErrorLogsDb", new \Pimcore\Log\Maintenance(), "checkErrorLogsDb")); $manager->registerJob(new Schedule\Maintenance\Job("archiveLogEntries", new \Pimcore\Log\Maintenance(), "archiveLogEntries")); $manager->registerJob(new Schedule\Maintenance\Job("sanitycheck", "\\Pimcore\\Model\\Element\\Service", "runSanityCheck")); $manager->registerJob(new Schedule\Maintenance\Job("versioncleanup", new \Pimcore\Model\Version(), "maintenanceCleanUp")); $manager->registerJob(new Schedule\Maintenance\Job("versioncompress", new \Pimcore\Model\Version(), "maintenanceCompress")); $manager->registerJob(new Schedule\Maintenance\Job("redirectcleanup", "\\Pimcore\\Model\\Redirect", "maintenanceCleanUp")); $manager->registerJob(new Schedule\Maintenance\Job("cleanupbrokenviews", "\\Pimcore\\Db", "cleanupBrokenViews")); $manager->registerJob(new Schedule\Maintenance\Job("downloadmaxminddb", "\\Pimcore\\Update", "updateMaxmindDb")); $manager->registerJob(new Schedule\Maintenance\Job("cleanupcache", "\\Pimcore\\Model\\Cache", "maintenance")); $manager->registerJob(new Schedule\Maintenance\Job("tmpstorecleanup", "\\Pimcore\\Model\\Tool\\TmpStore", "cleanup")); $manager->registerJob(new Schedule\Maintenance\Job("imageoptimize", "\\Pimcore\\Model\\Asset\\Image\\Thumbnail\\Processor", "processOptimizeQueue")); \Pimcore::getEventManager()->trigger("system.maintenance", $manager); $manager->run(); \Logger::info("All maintenance-jobs finished!"); }
/** * @return string */ public function getHref() { $this->updatePathFromInternal(); $url = $this->data['path']; if ($this->data['internalType'] == 'object') { $objectInfo = explode('::', $url); if (count($objectInfo) == 2) { $path = FALSE; $cmdEv = \Pimcore::getEventManager()->trigger('toolbox.url.objectFrontendUrl', null, array('className' => $objectInfo[0], 'path' => $objectInfo[1])); if ($cmdEv->stopped()) { $path = $cmdEv->last(); if (!empty($path)) { $path = \Toolbox\Tools\GlobalLink::parse($path); } } return $path; } else { return FALSE; } } if (strlen($this->data['parameters']) > 0) { $url .= "?" . str_replace("?", "", $this->getParameters()); } if (strlen($this->data['anchor']) > 0) { $url .= "#" . str_replace("#", "", $this->getAnchor()); } return $url; }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function attachEvents() { self::getInstall()->attachEvents(); \Pimcore::getEventManager()->attach('coreshop.payment.getProvider', function ($e) { return $this; }); }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function init() { // attach event-listener foreach (["asset", "object", "document", "object.class"] as $type) { \Pimcore::getEventManager()->attach($type . ".postAdd", array($this, "createUuid")); \Pimcore::getEventManager()->attach($type . ".postDelete", array($this, "deleteUuid")); } }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function attachEvents() { self::getInstall()->attachEvents(); $shopProvider = new Provider(); \Pimcore::getEventManager()->attach("coreshop.payment.getProvider", function ($e) use($shopProvider) { return $shopProvider; }); }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function attachEvents() { self::getInstall()->attachEvents(); \Pimcore::getEventManager()->attach("coreshop.payment.getProvider", function ($e) { //$cart = $e->getParam("cart"); return $this; }); }
/** * Constructor. * * @param string $name The name of the application * @param string $version The version of the application * * @api */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { parent::__construct('Pimcore CLI', Version::getVersion()); // init default autoload namespaces $this->initDefaultAutoloadNamespaces(); // allow to register commands here (e.g. through plugins) \Pimcore::getEventManager()->trigger('system.console.init', $this); }
/** * Constructor. * * @param string $name The name of the application * @param string $version The version of the application * * @api */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { parent::__construct('Pimcore CLI', Version::getVersion()); foreach ($this->defaultAutoloadNamespaces as $namespace => $directory) { $this->addAutoloadNamespace($namespace, $directory); } // allow to register commands here (e.g. through plugins) \Pimcore::getEventManager()->trigger('system.console.init', $this); }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function init() { parent::init(); \Pimcore::getEventManager()->attach('system.maintenance', array($this, 'maintenanceJob')); \Pimcore::getEventManager()->attach('system.console.init', function (\Zend_EventManager_Event $e) { $application = $e->getTarget(); $application->add(new \LuceneSearch\Console\Command\FrontendCrawlCommand()); }); }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function init() { // attach event-listener foreach (["asset", "object", "document"] as $type) { \Pimcore::getEventManager()->attach($type . ".postAdd", array($this, "postAddElement")); \Pimcore::getEventManager()->attach($type . ".postUpdate", array($this, "postUpdateElement")); \Pimcore::getEventManager()->attach($type . ".preDelete", array($this, "preDeleteElement")); } }
/** * Init Plugin. * * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function init() { parent::init(); \Pimcore::getEventManager()->attach('system.startup', function (\Zend_EventManager_Event $e) { $frontController = $e->getTarget(); if ($frontController instanceof \Zend_Controller_Front) { $frontController->registerPlugin(new Controller\Plugin\GatewayRouter()); } }); }
/** * Init Plugin. */ public function init() { parent::init(); \Pimcore::getEventManager()->attach('system.console.init', function (\Zend_EventManager_Event $e) { /** @var \Pimcore\Console\Application $application */ $application = $e->getTarget(); // add a namespace to autoload commands from $application->addAutoloadNamespace('Manager\\Console', PIMCORE_PLUGINS_PATH . '/Manager/lib/Manager/Console'); }); }
public function init() { parent::init(); \Pimcore::getEventManager()->attach('system.startup', function (\Zend_EventManager_Event $e) { /** @var \Zend_Controller_Front $front */ $front = $e->getTarget(); // system.startup occurs too early to register view scripts path // we need to do it through controller plugin in preDispatch() $front->registerPlugin(new Controller\Plugin\Frontend()); }); }
private function getEventData() { $viewRenderer = \Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view; if (!$viewRenderer) { return FALSE; } $assetHelper = new \Toolbox\Tools\Asset(); $assetHelper->setIsBackEnd($viewRenderer->editmode)->setIsFrontEnd(!$viewRenderer->editmode)->setBaseUrl(''); \Pimcore::getEventManager()->trigger('toolbox.addAsset', $assetHelper); return $assetHelper->getHtmlData(); }
public function init() { parent::init(); \Zend_Controller_Action_HelperBroker::addPrefix('Member_Controller_Action_Helper'); // attach default listeners \Pimcore::getEventManager()->attach('member.register.validate', ['\\Member\\Listener\\Register', 'validate'], 0); \Pimcore::getEventManager()->attach('member.password.reset', ['\\Member\\Listener\\Password', 'reset'], 0); if (Config::get('actions')->postRegister) { \Pimcore::getEventManager()->attach('member.register.post', ['\\Member\\Listener\\Register', Config::get('actions')->postRegister], 0); } }
public function getDataByIdAction() { $document = Document::getById($this->getParam("id")); $document = clone $document; //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($document)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $document, "returnValueContainer" => $returnValueContainer]); if ($document->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(["success" => false, "message" => "missing_permission"]); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "asset")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "asset")]); } Element\Editlock::lock($this->getParam("id"), "asset"); $asset = Asset::getById(intval($this->getParam("id"))); $asset = clone $asset; if (!$asset instanceof Asset) { $this->_helper->json(["success" => false, "message" => "asset doesn't exist"]); } $asset->setMetadata(Asset\Service::expandMetadataForEditmode($asset->getMetadata())); $asset->setProperties(Element\Service::minimizePropertiesForEditmode($asset->getProperties())); //$asset->getVersions(); $asset->getScheduledTasks(); $asset->idPath = Element\Service::getIdPath($asset); $asset->userPermissions = $asset->getUserPermissions(); $asset->setLocked($asset->isLocked()); $asset->setParent(null); if ($asset instanceof Asset\Text) { $asset->data = $asset->getData(); } if ($asset instanceof Asset\Image) { $imageInfo = []; if ($asset->getWidth() && $asset->getHeight()) { $imageInfo["dimensions"] = []; $imageInfo["dimensions"]["width"] = $asset->getWidth(); $imageInfo["dimensions"]["height"] = $asset->getHeight(); } $exifData = $asset->getEXIFData(); if (!empty($exifData)) { $imageInfo["exif"] = $exifData; } $iptcData = $asset->getIPTCData(); if (!empty($exifData)) { $imageInfo["iptc"] = $iptcData; } $imageInfo["exiftoolAvailable"] = (bool) \Pimcore\Tool\Console::getExecutable("exiftool"); $asset->imageInfo = $imageInfo; } $asset->setStream(null); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new Model\Tool\Admin\EventDataContainer(object2array($asset)); \Pimcore::getEventManager()->trigger("admin.asset.get.preSendData", $this, ["asset" => $asset, "returnValueContainer" => $returnValueContainer]); if ($asset->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(["success" => false, "message" => "missing_permission"]); }
public function postDispatch(\Zend_Controller_Request_Abstract $request) { parent::postDispatch($request); $layout = \Zend_Layout::getMvcInstance(); if ($layout && $layout->isEnabled() !== FALSE) { \Pimcore::getEventManager()->attach('toolbox.addAsset', function (\Zend_EventManager_Event $e) { $assetHandler = $e->getTarget(); $assetHandler->appendScript('toolbox-wysiwyg', '/plugins/Toolbox/static/js/wysiwyg.js', array(), array('showInFrontEnd' => false)); $assetHandler->appendScript('toolbox-parallax', '/plugins/Toolbox/static/js/frontend/jquery.parallax-scroll.min.js', array(), array('showInFrontEnd' => true)); $assetHandler->appendScript('vimeo-api', '/plugins/Toolbox/static/js/frontend/vimeo-api.min.js', array(), array('showInFrontEnd' => true)); $assetHandler->appendScript('toolbox-frontend', '/plugins/Toolbox/static/js/frontend/toolbox.js', array(), array('showInFrontEnd' => true)); }); } }
/** * */ private function registerLegacyEvents() { $mappings = self::$legacyMappings; $eventManager = \Pimcore::getEventManager(); $plugin = $this; $myMethods = get_class_methods($this); foreach ($myMethods as $method) { if (array_key_exists($method, $mappings)) { $event = $mappings[$method]; if ($method == "maintenanceForce") { $eventManager->attach("system.maintenance", function ($e) use($plugin) { $e->getTarget()->registerJob(new Schedule\Maintenance\Job(get_class($plugin), $plugin, "maintenanceForce"), true); }); } else { if (in_array($method, ["maintenance", "maintainance"])) { $eventManager->attach("system.maintenance", function ($e) use($plugin, $method) { $e->getTarget()->registerJob(new Schedule\Maintenance\Job(get_class($plugin), $plugin, $method)); }); } else { if ($method == "authenticateUser") { $eventManager->attach($event, function ($e) use($plugin, $method) { $user = $plugin->authenticateUser($e->getParam("username"), $e->getParam("password")); if ($user) { $e->getTarget()->setUser($user); } }); } else { if ($method == "preLogoutUser") { $eventManager->attach($event, function ($e) use($plugin, $method) { $plugin->preLogoutUser($e->getParam("user")); }); } else { if (preg_match("/(pre|post)(update|add|delete)/i", $method)) { // this is for Document/Asset/\Object\Abstract/\Object\ClassDefinition/... $eventManager->attach($event, function ($e) use($plugin, $method) { $plugin->{$method}($e->getTarget()); }); } else { // for all events that don't have parameters or targets (eg. preDispatch/pimcore.startup) $eventManager->attach($event, array($plugin, $method)); } } } } } } } }
public function init() { parent::init(); // register your events here // using anonymous function \Pimcore::getEventManager()->attach("document.postAdd", function ($event) { // do something $document = $event->getTarget(); }); // using methods \Pimcore::getEventManager()->attach("document.postUpdate", [$this, "handleDocument"]); // for more information regarding events, please visit: // http://www.pimcore.org/wiki/display/PIMCORE/Event+API+%28EventManager%29+since+2.1.1 // http://framework.zend.com/manual/1.12/de/zend.event-manager.event-manager.html // http://www.pimcore.org/wiki/pages/viewpage.action?pageId=12124202 }
public function init() { parent::init(); // register your events here // using anonymous function \Pimcore::getEventManager()->attach("document.postAdd", function ($event) { // do something $document = $event->getTarget(); }); // using methods \Pimcore::getEventManager()->attach("document.postUpdate", [$this, "handleDocument"]); // for more information regarding events, please visit: // https://www.pimcore.org/docs/latest/Extending_Pimcore/Event_API_and_Event_Manager.html // http://framework.zend.com/manual/1.12/de/zend.event-manager.event-manager.html // https://www.pimcore.org/docs/latest/Extending_Pimcore/Plugin_Developers_Guide/Plugin_Class.html }
/** * Render link elements as string * * @param string|int $indent * @return string */ public function toString($indent = null) { foreach ($this as &$item) { if ($this->isCacheBuster()) { // adds the automatic cache buster functionality if (isset($item->href)) { $realFile = PIMCORE_DOCUMENT_ROOT . $item->href; if (file_exists($realFile)) { $item->href = "/cache-buster-" . filemtime($realFile) . $item->href; } } } \Pimcore::getEventManager()->trigger("frontend.view.helper.head-link", $this, ["item" => $item]); } return parent::toString($indent); }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function attachEvents() { self::getInstall()->attachEvents(); $activeProviders = Configuration::get("OMNIPAY.ACTIVEPROVIDERS"); if (!is_array($activeProviders)) { $activeProviders = []; } foreach ($activeProviders as $provider) { $gateway = \Omnipay\Omnipay::getFactory()->create($provider); $config = Configuration::get("OMNIPAY." . strtoupper($provider)); if (is_null($config)) { $config = []; } $shopProvider = new Provider($gateway, $config); \Pimcore::getEventManager()->attach("coreshop.payment.getProvider", function ($e) use($shopProvider) { return $shopProvider; }); } }
/** * @param $documentId * @throws \Exception */ public function startPdfGeneration($documentId) { $jobConfigFile = $this->loadJobConfigObject($documentId); $document = $this->getPrintDocument($documentId); // check if there is already a generating process running, wait if so ... Model\Tool\Lock::acquire($document->getLockKey(), 0); try { $pdf = $this->buildPdf($document, $jobConfigFile->config); file_put_contents($document->getPdfFileName(), $pdf); \Pimcore::getEventManager()->trigger("document.print.postPdfGeneration", $document, ["filename" => $document->getPdfFileName(), "pdf" => $pdf]); $creationDate = \Zend_Date::now(); $document->setLastGenerated($creationDate->get() + 1); $document->save(); } catch (\Exception $e) { $document->save(); \Logger::err($e); } Model\Tool\Lock::release($document->getLockKey()); Model\Tool\TmpStore::delete($document->getLockKey()); @unlink($this->getJobConfigFile($documentId)); }
/** * Retrieve string representation * * @param string|int $indent * @return string */ public function toString($indent = null) { foreach ($this as &$item) { if (!$this->_isValid($item)) { continue; } if ($this->isCacheBuster()) { // adds the automatic cache buster functionality if (is_array($item->attributes)) { if (isset($item->attributes["src"])) { $realFile = PIMCORE_DOCUMENT_ROOT . $item->attributes["src"]; if (file_exists($realFile)) { $item->attributes["src"] = "/cache-buster-" . filemtime($realFile) . $item->attributes["src"]; } } } } \Pimcore::getEventManager()->trigger("frontend.view.helper.head-script", $this, ["item" => $item]); } return parent::toString($indent); }
public function resetPassword(array $data) { $argv = compact('data'); $results = \Pimcore::getEventManager()->triggerUntil('member.password.reset', $this, $argv, function ($v) { return $v instanceof \Zend_Filter_Input; }); $input = $results->last(); if (!$input instanceof \Zend_Filter_Input) { throw new \Exception('No validate listener attached to "member.password.reset" event'); } if (!$input->isValid()) { return $input; } $this->setPassword($input->getUnescaped('password')); $this->setResetHash(null); $this->save(); if (!$this->isPublished()) { // password reset is confirmed by email so we can activate account as well $this->confirm(); } return $input; }