public static function createPlugin($name, $options = array(), $toasterOptions = array()) { $pluginClassName = ucfirst($name); if (!Tools_Plugins_Tools::loaderCanExec($name)) { throw new Exceptions_SeotoasterPluginException('Sorry, ' . $pluginClassName . ' plug-in requires Ioncube. Please install the proper Ioncube loader on your web server at <a href="http://www.ioncube.com/loaders.php" target="_blank">www.ioncube.com/loaders.php</a> or request your web host to do it for you.'); } self::_validate($pluginClassName); return new $pluginClassName($options, $toasterOptions); }
public static function createService($plugin, $name, $options = array()) { $serviceClassName = sprintf(self::SERVICE_CLASS_PATTERN, ucfirst(strtolower($plugin)), ucfirst(strtolower($name))); if (!Tools_Plugins_Tools::loaderCanExec($plugin)) { throw new Exceptions_SeotoasterPluginException('Sorry, ' . $serviceClassName . ' plug-in requires Ioncube. Please install the proper Ioncube loader on your web server at <a href="http://www.ioncube.com/loaders.php" target="_blank">www.ioncube.com/loaders.php</a> or request your web host to do it for you.'); } $zendLoader = Zend_Loader_Autoloader::getInstance(); $zendLoader->suppressNotFoundWarnings(true); if ($zendLoader->autoload($serviceClassName)) { $frontController = Zend_Controller_Front::getInstance(); return new $serviceClassName($frontController->getRequest(), $frontController->getResponse()); } return false; }
public function renderAdminPanel($userRole = null) { $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website'); $userRole = preg_replace('/[^\\w\\d_]/', '', $userRole); if (!($additionalMenu = $this->_cache->load('admin_addmenu', $userRole))) { $additionalMenu = Tools_Plugins_Tools::fetchPluginsMenu($userRole); $this->_cache->save('admin_addmenu', $additionalMenu, $userRole, array(), '7200'); } $this->_view->additionalMenu = $additionalMenu; if ($this->_view->placeholder('logoSource')->getValue() == array()) { $this->_view->placeholder('logoSource')->set($websiteHelper->getUrl() . 'system/images/cpanel-img.jpg'); } return $this->_view->render('admin/adminpanel.phtml'); }
/** * Trigger Seotoaster plugins hooks * * @param $method string Method to trigger */ private function _callPlugins($method) { $enabledPlugins = Tools_Plugins_Tools::getEnabledPlugins(); if (is_array($enabledPlugins) && !empty($enabledPlugins)) { array_walk($enabledPlugins, function ($plugin, $key, $data) { try { $name = ucfirst($plugin->getName()); Tools_Factory_PluginFactory::validate($name); $reflection = new Zend_Reflection_Class($name); if ($reflection->hasMethod($data['method'])) { $pluginInstance = Tools_Factory_PluginFactory::createPlugin($plugin->getName(), array(), array('websiteUrl' => $data['websiteUrl'])); $pluginInstance->{$data}['method'](); } } catch (Exceptions_SeotoasterException $se) { error_log($se->getMessage()); error_log($se->getTraceAsString()); } }, array('method' => $method, 'websiteUrl' => Zend_Controller_Action_HelperBroker::getStaticHelper('Website')->getUrl())); } }
/** * Serve sitemaps * */ public function sitemapAction() { //disable renderer $this->_helper->viewRenderer->setNoRender(true); //get sitemap type from the params if (($sitemapType = $this->getRequest()->getParam('type', '')) == Tools_Content_Feed::SMFEED_TYPE_REGULAR) { //regular sitemap.xml requested if (null === ($this->view->pages = $this->_helper->cache->load('sitemappages', 'sitemaps_'))) { if (in_array('newslog', Tools_Plugins_Tools::getEnabledPlugins(true))) { $this->view->newsPageUrlPath = Newslog_Models_Mapper_ConfigurationMapper::getInstance()->fetchConfigParam('folder'); } $pages = Application_Model_Mappers_PageMapper::getInstance()->fetchAll(); if (is_array($pages) && !empty($pages)) { $quoteInstalled = Tools_Plugins_Tools::findPluginByName('quote')->getStatus() == Application_Model_Models_Plugin::ENABLED; $pages = array_filter($pages, function ($page) use($quoteInstalled) { if ($page->getExtraOption(Application_Model_Models_Page::OPT_PROTECTED) || $page->getDraft() || $page->getIs404page() || $quoteInstalled && intval($page->getParentId()) === Quote::QUOTE_CATEGORY_ID) { return false; } return true; }); } else { $pages = array(); } $this->view->pages = $pages; $this->_helper->cache->save('sitemappages', $this->view->pages, 'sitemaps_', array('sitemaps')); } } else { if ($sitemapType == Tools_Content_Feed::SMFEED_TYPE_INDEX) { //default sitemaps $sitemaps = array('sitemap' => array('extension' => 'xml', 'lastmod' => date(DATE_ATOM)), 'sitemapnews' => array('extension' => 'xml', 'lastmod' => date(DATE_ATOM))); //real sitemaps (in the toaster root) $sitemapFiles = Tools_Filesystem_Tools::findFilesByExtension($this->_helper->website->getPath(), 'xml', false, false, false); if (is_array($sitemapFiles) && !empty($sitemapFiles)) { foreach ($sitemapFiles as $sitemapFile) { if (preg_match('~sitemap.*\\.xml.*~', $sitemapFile)) { $fileInfo = pathinfo($this->_helper->website->getPath() . $sitemapFile); if (is_array($fileInfo)) { $sitemaps[$fileInfo['filename']] = array('extension' => $fileInfo['extension'], 'lastmod' => date(DATE_ATOM, fileatime($this->_helper->website->getPath() . $sitemapFile))); } } } } $this->view->sitemaps = $sitemaps; } } $template = 'sitemap' . $sitemapType . '.xml.phtml'; if (null === ($sitemapContent = $this->_helper->cache->load($sitemapType, Helpers_Action_Cache::PREFIX_SITEMAPS))) { try { $sitemapContent = $this->view->render('backend/seo/' . $template); } catch (Zend_View_Exception $zve) { // Try to find plugin's sitemap try { $sitemapContent = Tools_Plugins_Tools::runStatic('getSitemap', $sitemapType); if (!$sitemapContent) { $sitemapContent = Tools_Plugins_Tools::runStatic('getSitemap' . ucfirst($sitemapType)); } } catch (Exception $e) { Tools_System_Tools::debugMode() && error_log($e->getMessage()); $sitemapContent = false; } if ($sitemapContent === false) { $this->getResponse()->setHeader('Content-Type', 'text/html', true); return $this->forward('index', 'index', null, array('page' => 'sitemap' . $sitemapType . '.xml')); } } $this->_helper->cache->save($sitemapType, $sitemapContent, Helpers_Action_Cache::PREFIX_SITEMAPS, array('sitemaps'), Helpers_Action_Cache::CACHE_WEEK); } echo $sitemapContent; }
protected function _runOnCreate() { Tools_Plugins_Tools::registerPluginsIncludePath(true); Application_Model_Mappers_EmailTriggersMapper::getInstance()->registerTriggers($this->_object->getName()); Application_Model_Mappers_EmailTriggersMapper::getInstance()->registerRecipients($this->_object->getName()); }
/** * Method exports zipped theme * @param string $themeName Theme name * @param bool $full Set true to dump data and media files */ protected function _exportTheme($themeName = '', $full = false, $noZip = false) { if (!$themeName) { $themeName = $this->_configHelper->getConfig('currentTheme'); } $themePath = $this->_websiteHelper->getPath() . $this->_themesConfig['path'] . $themeName . DIRECTORY_SEPARATOR; $websitePath = $this->_websiteHelper->getPath(); if ($full) { /** * @var $dbAdapter Zend_Db_Adapter_Abstract */ $dbAdapter = Zend_Registry::get('dbAdapter'); // exporting themes data for the full theme // init empty array for export data $data = array('page' => array()); // and for media files $mediaFiles = array(); // fetching index page and main menu pages $pagesSqlWhere = "SELECT * FROM `page` WHERE system = '0' AND draft = '0' AND (\n\t\t\turl = 'index.html' OR (parent_id = '0' AND show_in_menu = '1') OR (parent_id = '-1' AND show_in_menu = '2')\n\t\t OR (parent_id = '0' OR parent_id IN (SELECT DISTINCT `page`.`id` FROM `page` WHERE (parent_id = '0') AND (system = '0') AND (show_in_menu = '1')) )\n\t\t OR id IN ( SELECT DISTINCT `page_id` FROM `page_fa` )\n\t\t OR id IN ( SELECT DISTINCT `page_id` FROM `page_has_option` )\n\t\t ) ORDER BY `order` ASC"; $pages = $dbAdapter->fetchAll($pagesSqlWhere); if (is_array($pages) && !empty($pages)) { $data['page'] = $pages; unset($pages); } // combining list of queries for export others tables content $queryList = array(); $enabledPlugins = Tools_Plugins_Tools::getEnabledPlugins(true); foreach ($enabledPlugins as $plugin) { $pluginsData = Tools_Plugins_Tools::runStatic(self::PLUGIN_EXPORT_METHOD, $plugin); if (!$pluginsData) { continue; } if (isset($pluginsData['pages']) && is_array($pluginsData['pages']) && !empty($pluginsData['pages'])) { $data['page'] = array_merge($data['page'], $pluginsData['pages']); } if (isset($pluginsData['tables']) && is_array($pluginsData['tables']) && !empty($pluginsData['tables'])) { foreach ($pluginsData['tables'] as $table => $query) { if (array_key_exists($table, $this->_fullThemesSqlMap)) { continue; } $queryList[$table] = $query; unset($table, $query); } } if (isset($pluginsData['media']) && is_array($pluginsData['media']) && !empty($pluginsData['media'])) { $mediaFiles = array_unique(array_merge($mediaFiles, $pluginsData['media'])); } } unset($enabledPlugins); // getting list of pages ids for export $pagesIDs = array_map(function ($page) { return $page['id']; }, $data['page']); // building list of dump queries and executing it with page IDS substitution $queryList = array_merge($this->_fullThemesSqlMap, $queryList); foreach ($queryList as $table => $query) { $data[$table] = $dbAdapter->fetchAll($dbAdapter->quoteInto($query, $pagesIDs)); } unset($queryList, $pagesIDs); if (!empty($data)) { $exportData = new Zend_Config($data); $themeDataFile = new Zend_Config_Writer_Json(array('config' => $exportData, 'filename' => $themePath . self::THEME_DATA_FILE)); $themeDataFile->write(); } // exporting list of media files $totalFileSize = 0; // initializing files size counter $previewFolder = $this->_websiteHelper->getPreview(); $pagePreviews = array_filter(array_map(function ($page) use($previewFolder) { return !empty($page['preview_image']) ? $previewFolder . $page['preview_image'] : false; }, $data['page'])); $contentImages = array(); // list of images from containers if (!empty($data['container'])) { foreach ($data['container'] as $container) { preg_match_all('~media[^"\']*\\.(?:jpe?g|gif|png)~iu', $container['content'], $matches); if (!empty($matches[0])) { $contentImages = array_merge($contentImages, array_map(function ($file) { $file = explode(DIRECTORY_SEPARATOR, $file); if ($file[2] !== 'original') { $file[2] = 'original'; } return implode(DIRECTORY_SEPARATOR, $file); }, $matches[0])); } unset($matches, $container); } } $mediaFiles = array_merge($pagePreviews, $contentImages, $mediaFiles); $mediaFiles = array_unique(array_filter($mediaFiles)); if (!empty($mediaFiles)) { clearstatcache(); foreach ($mediaFiles as $key => $file) { if (!is_file($websitePath . $file)) { $mediaFiles[$key] = null; continue; } $totalFileSize += filesize($websitePath . $file); } } if ($totalFileSize > self::THEME_FULL_MAX_FILESIZE) { $this->_error('Too many images'); } else { $mediaFiles = array_filter($mediaFiles); } } // if requested name is current one we create system file with template types if ($themeName === $this->_configHelper->getConfig('currentTheme')) { // saving template types into theme.ini. @see Tools_Template_Tools::THEME_CONFIGURATION_FILE $themeIniConfig = new Zend_Config(array(), true); foreach (Application_Model_Mappers_TemplateMapper::getInstance()->fetchAll() as $template) { $themeIniConfig->{$template->getName()} = $template->getType(); } if (!empty($themeIniConfig)) { try { $iniWriter = new Zend_Config_Writer_Ini(array('config' => $themeIniConfig, 'filename' => $themePath . Tools_Template_Tools::THEME_CONFIGURATION_FILE)); $iniWriter->write(); } catch (Exception $e) { Tools_System_Tools::debugMode() && error_log($e->getMessage()); } } unset($themeIniConfig, $iniWriter); } //defining list files that needs to be excluded $excludeFiles = array(); if (!$full) { array_push($excludeFiles, self::THEME_DATA_FILE); } if ($noZip === true) { // backup media files to theme subfolder if (!empty($mediaFiles)) { if (!is_dir($themePath . 'previews')) { Tools_Filesystem_Tools::mkDir($themePath . 'previews'); } if (!is_dir($themePath . 'media')) { Tools_Filesystem_Tools::mkDir($themePath . 'media'); } foreach ($mediaFiles as $file) { if (!is_file($websitePath . $file)) { continue; } $path = explode(DIRECTORY_SEPARATOR, $file); if (!is_array($path) || empty($path)) { continue; } switch ($path[0]) { case 'previews': list($folder, $filename) = $path; break; case 'media': $folder = 'media' . DIRECTORY_SEPARATOR . $path[1]; if (!is_dir($themePath . $folder)) { Tools_Filesystem_Tools::mkDir($themePath . $folder); } $filename = end($path); break; default: continue; break; } $destination = $themePath . $folder . DIRECTORY_SEPARATOR . $filename; try { $r = Tools_Filesystem_Tools::copy($websitePath . $file, $destination); } catch (Exception $e) { Tools_System_Tools::debugMode() && error_log($e->getMessage()); } } } return true; } else { //create theme zip archive $themeArchive = Tools_Theme_Tools::zip($themeName, isset($mediaFiles) ? $mediaFiles : false, $excludeFiles); if ($themeArchive) { $body = file_get_contents($themeArchive); if (false !== $body) { Tools_Filesystem_Tools::deleteFile($themeArchive); } else { $this->_error('Unable to read website archive file'); } } else { $this->_error('Can\'t create website archive'); } //outputting theme zip $this->_response->clearAllHeaders()->clearBody(); $this->_response->setHeader('Content-Disposition', 'attachment; filename=' . $themeName . '.zip')->setHeader('Content-Type', 'application/zip', true)->setHeader('Content-Transfer-Encoding', 'binary', true)->setHeader('Expires', date(DATE_RFC1123), true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Pragma', 'public', true)->setBody($body)->sendResponse(); exit; } }
public static function registerPluginsIncludePath($force = false) { $cacheHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('cache')->init(); if ($force) { $cacheHelper->clean(null, null, array('plugins')); } if (null === ($pluginIncludePath = $cacheHelper->load('includePath', 'plugins_')) || $force) { $pluginIncludePath = Tools_Plugins_Tools::fetchPluginsIncludePath(); $cacheHelper->save('includePath', $pluginIncludePath, 'plugins_', array('plugins'), Helpers_Action_Cache::CACHE_NORMAL); } if (!empty($pluginIncludePath)) { set_include_path(implode(PATH_SEPARATOR, $pluginIncludePath) . PATH_SEPARATOR . get_include_path()); } }
public function deleteAction() { if ($this->getRequest()->isPost()) { $plugin = Tools_Plugins_Tools::findPluginByName($this->getRequest()->getParam('id')); $plugin->registerObserver(new Tools_Plugins_GarbageCollector(array('action' => Tools_System_GarbageCollector::CLEAN_ONDELETE))); $miscData = Zend_Registry::get('misc'); $sqlFilePath = $this->_helper->website->getPath() . $miscData['pluginsPath'] . $plugin->getName() . '/system/' . Application_Model_Models_Plugin::UNINSTALL_FILE_NAME; if (file_exists($sqlFilePath)) { $sqlFileContent = Tools_Filesystem_Tools::getFile($sqlFilePath); if (strlen($sqlFileContent)) { $queries = Tools_System_SqlSplitter::split($sqlFileContent); } } $delete = Tools_Filesystem_Tools::deleteDir($this->_helper->website->getPath() . 'plugins/' . $plugin->getName()); if (!$delete) { $this->_helper->response->fail('Can\'t remove plugin\'s directory (not enough permissions). Plugin was uninstalled.'); exit; } if (is_array($queries) && !empty($queries)) { $dbAdapter = Zend_Registry::get('dbAdapter'); try { array_walk($queries, function ($query, $key, $adapter) { if (strlen(trim($query))) { $adapter->query($query); } }, $dbAdapter); Application_Model_Mappers_PluginMapper::getInstance()->delete($plugin); } catch (Exception $e) { error_log($e->getMessage()); $this->_helper->response->fail($e->getMessage()); } } $this->_helper->cache->clean(null, null, array('plugins')); $this->_helper->cache->clean('admin_addmenu', $this->_helper->session->getCurrentUser()->getRoleId()); $this->_helper->response->success('Removed'); } }
public function loadwidgetmakerAction() { $this->_helper->getHelper('layout')->disableLayout(); if ($this->getRequest()->isPost() || $this->getRequest()->isGet()) { if (!($widgetMakerContent = $this->_helper->cache->load('widgetMakerContent', 'wmc_'))) { $this->view->widgetsData = array_merge(Tools_Widgets_Tools::getWidgetmakerContent(), Tools_Plugins_Tools::getWidgetmakerContent()); $widgetMakerContent = $this->view->render('backend/content/widgetmaker.phtml'); $this->_helper->cache->save('widgetMakerContent', $widgetMakerContent, 'wmc_', array(), Helpers_Action_Cache::CACHE_LONG); } //$this->_helper->response->success($widgetMakerContent); echo $widgetMakerContent; } exit; }
/** * @todo Should me moved to the shopping plugin * @static * @return null */ public static function getProductCategoryPage() { // We need to know product category page url // This url specified in the bundle plugin "Shopping" // But this plugin may not be present in the system (not recommended) $shopping = Tools_Plugins_Tools::findPluginByName('shopping'); $pageUrl = $shopping->getStatus() == Application_Model_Models_Plugin::ENABLED ? Shopping::PRODUCT_CATEGORY_URL : null; if ($pageUrl === null) { return null; } return Application_Model_Mappers_PageMapper::getInstance()->findByUrl($pageUrl); }
public function actionmailsAction() { if ($this->getRequest()->isPost()) { $actions = $this->getRequest()->getParam('actions', false); if ($actions !== false) { $removeActions = array(); foreach ($actions as $action) { if (isset($action['delete']) && $action['delete'] === "true") { array_push($removeActions, $action['id']); continue; } //add trigger automatically if not exists //if(($exists = Application_Model_Mappers_EmailTriggersMapper::getInstance()->findByTriggerName($action['trigger'])->current()) === null) { // Application_Model_Mappers_EmailTriggersMapper::getInstance()->registerTrigger($action['trigger']); // } Application_Model_Mappers_EmailTriggersMapper::getInstance()->save($action); } if (!empty($removeActions)) { Application_Model_Mappers_EmailTriggersMapper::getInstance()->delete($removeActions); } $this->_helper->response->success($this->_helper->language->translate('Changes saved')); return true; } } $pluginsTriggers = Tools_Plugins_Tools::fetchPluginsTriggers(); $systemTriggers = Tools_System_Tools::fetchSystemtriggers(); $triggers = is_array($pluginsTriggers) ? array_merge($systemTriggers, $pluginsTriggers) : $systemTriggers; $recipients = Application_Model_Mappers_EmailTriggersMapper::getInstance()->getReceivers(true); $this->view->recipients = array_combine($recipients, $recipients); $this->view->mailTemplates = Tools_Mail_Tools::getMailTemplatesHash(); $this->view->triggers = $triggers; $this->view->actionsOptions = array_merge(array('0' => $this->_helper->language->translate('Select event area')), array_combine(array_keys($triggers), array_map(function ($trigger) { return str_replace('-', ' ', ucfirst($trigger)); }, array_keys($triggers)))); $this->view->actions = Application_Model_Mappers_EmailTriggersMapper::getInstance()->fetchArray(); }