Esempio n. 1
0
 /**
  * Create new instance.
  */
 public function __construct(ContainerInterface $container)
 {
     $this->container = $container;
     parent::__construct();
     $this->sets = array();
     $this->alias = array();
     $this->messages = array();
     if (Runtime::isContextMatch('storefront')) {
         // yucky, but easier now than later
         $rootDir = $container->getParameter('zenmagick.root_dir');
         $this->load($rootDir . '/src/ZenMagick/StorefrontBundle/config/validation.php');
     }
 }
Esempio n. 2
0
 /**
  * @todo Move this init back into ZenCartAutoLoader or an event
  * when we can lazy load the shopping cart class.
  */
 public function initClassLoader()
 {
     $isAdmin = Runtime::isContextMatch('admin');
     !defined('IS_ADMIN_FLAG') && define('IS_ADMIN_FLAG', $isAdmin);
     $classLoader = new \Composer\AutoLoad\ClassLoader();
     $classLoader->register();
     $container = $this->container;
     $zcRoot = $this->container->getParameter('zencart.root_dir');
     $zc = $zcRoot . '/includes/classes/';
     $zca = $this->container->getParameter('zencart.admin_dir') . '/includes/classes/';
     $b = __DIR__ . '/bridge/includes/classes/';
     $ba = __DIR__ . '/bridge/admin/includes/classes/';
     $map = array('httpClient' => $zc . 'http_client.php', 'category_tree' => $zc . 'category_tree.php', 'language' => ($isAdmin ? $ba : $b) . 'language.php', 'products' => $zc . 'products.php', 'splitPageResults' => ($isAdmin ? $zca : $zc) . 'split_page_results.php', 'template_func' => $zc . 'template_func.php', 'PHPMailer' => $zc . 'class.phpmailer.php', 'SMTP' => $zc . 'class.smtp.php', 'payment' => $zc . 'payment.php', 'order_total' => $zc . 'order_total.php', 'shipping' => $zc . 'shipping.php', 'order' => ($isAdmin ? $zca : $zc) . 'order.php', 'box' => $zca . 'box.php', 'objectInfo' => $zca . 'object_info.php', 'tableBlock' => $zca . 'table_block.php', 'upload' => $zca . 'upload.php');
     $classLoader->addClassMap($map);
 }
 /**
  * {@inheritDoc}
  */
 public function getStatusMessages()
 {
     $messages = array();
     $settingsService = $this->container->get('settingsService');
     $warnBeforeMaintenance = $settingsService->get('apps.store.warnBeforeMaintenance');
     $downForMaintenance = $settingsService->get('apps.store.downForMaintenance');
     $translator = $this->container->get('translator');
     if ($warnBeforeMaintenance && !$downForMaintenance) {
         $configService = $this->container->get('configService');
         $downForMaintenanceDateTime = $configService->getConfigValue('PERIOD_BEFORE_DOWN_FOR_MAINTENANCE');
         $messages[] = array(StatusCheck::STATUS_NOTICE, $translator->trans('This website is scheduled to be "<em>Down For Maintenance</em>" on: %s.', array('%time_date%' => $downForMaintenanceDateTime->getValue())));
     }
     if ($downForMaintenance && !Runtime::isContextMatch('storefront')) {
         $messages[] = array(StatusCheck::STATUS_WARN, $translator->trans('The website is currently "<em>Down For Maintenance</em>" to the public.'));
     }
     return $messages;
 }
Esempio n. 4
0
 /**
  * Get plugins for the given context.
  *
  * @param int context Optional context flag; default is <code>null</code> for all.
  * @param boolean enabled If <code>true</code>, return only enabled plugins; default is <code>true</code>.
  * @return array List of initialized plugins.
  */
 protected function getPlugins($context = null, $enabled = true)
 {
     $plugins = array();
     foreach ($this->getStatusMap() as $id => $status) {
         if (array_key_exists($id, $this->plugins)) {
             $plugins[$id] = $this->plugins[$id];
             continue;
         }
         $meta = $status['meta'];
         if (($meta['enabled'] || !$enabled) && (null === $context || Runtime::isContextMatch($meta['context'], $context))) {
             $plugin = new $meta['class']($status);
             $plugin->setContainer($this->container);
             if ($plugin->isEnabled() && Runtime::isContextMatch($plugin->getContext(), $context)) {
                 $this->contextConfigLoader->setConfig($status);
                 $config = $this->contextConfigLoader->process();
                 if (array_key_exists('autoload', $config)) {
                     // Fold this into process() once it knows about pluginDir
                     $this->contextConfigLoader->registerAutoLoaders($config['autoload'], $plugin->getPluginDirectory());
                 }
                 // @todo make obsolete
                 $plugin->init();
             }
             $this->plugins[$id] = $plugins[$id] = $plugin;
         }
     }
     return $plugins;
 }
Esempio n. 5
0
 /**
  * {@inheritDoc}
  *
  * @todo Should spiders be detected and marked here or output?
  *       Probably marked on output, but that's not how the current admin works
  * @todo Can we differentiate between spiders and regular guest users without using HTTP_USER_AGENT?
  */
 public function onContainerReady($event)
 {
     $this->setTableMappings();
     $this->removeExpired();
     // @todo cron!
     if (Runtime::isContextMatch('admin')) {
         return;
     }
     $settingsService = $this->container->get('settingsService');
     $request = $event->getArgument('request');
     $session = $request->getSession();
     $accountId = $session->getAccountId();
     $sessionId = $session->getId();
     $ipAddress = $request->getClientIp();
     $fullName = 'Guest';
     // used for zc admin page
     if (!empty($accountId) && !empty($sessionId)) {
         $account = $this->container->get('security.context')->getToken()->getUser();
         $fullName = $account->getLastName() . ', ' . $account->getFirstName();
     }
     if (empty($sessionId)) {
         // create hash
         $token = array($ipAddress, $this->server->get('HTTP_USER_AGENT'));
         $sessionId = md5(implode(':', $token));
     }
     $conn = \ZMRuntime::getDatabase();
     $sql = "SELECT customer_id FROM %table.whos_online%\n                WHERE session_id = :sessionId AND ip_address = :ipAddress";
     $result = $conn->querySingle($sql, array('sessionId' => $sessionId, 'ipAddress' => $ipAddress), 'whos_online');
     $now = time();
     $data = array();
     $data['customer_id'] = (int) $accountId;
     $data['full_name'] = $fullName;
     $data['time_last_click'] = $now;
     $data['last_page_url'] = rtrim($request->getRequestUri(), '?');
     $data['user_agent'] = (string) $request->server->get('HTTP_USER_AGENT');
     if (!empty($result)) {
         $conn->update('whos_online', $data, array('session_id' => $sessionId));
     } else {
         $hostAddress = '';
         if ($settingsService->get('isResolveClientIP')) {
             // @todo we should probably only do this in the admin interface (when one exists)
             $hostAddress = @gethostbyaddr($ipAddress);
         }
         $data['ip_address'] = $ipAddress;
         $data['host_address'] = $hostAddress;
         $data['time_entry'] = $now;
         $data['session_id'] = $sessionId;
         $conn->insert('whos_online', $data);
     }
 }
Esempio n. 6
0
 /**
  * {@inheritDoc}
  * @todo: drop
  */
 public function get($name, $default = null)
 {
     if (null != ($value = parent::get($name, $default))) {
         return $value;
     }
     if (Runtime::isContextMatch('storefront')) {
         if (isset($_SESSION) && array_key_exists($name, $_SESSION)) {
             return $_SESSION[$name];
         }
     }
     return $default;
 }
Esempio n. 7
0
<?php

use ZenMagick\Base\Runtime;
$zcPath = $parameterBag->get('zencart.root_dir');
$adminDir = $parameterBag->get('zencart.admin_dir');
/**
 * admin/storefront configure.php defines
 */
define('DB_TYPE', 'mysql');
if (!defined('IS_ADMIN_FLAG')) {
    define('IS_ADMIN_FLAG', Runtime::isContextMatch('admin'));
}
define('DB_PREFIX', $parameterBag->get('table_prefix'));
// @todo these shouldn't be available by default
define('DB_SERVER', $parameterBag->get('database_host'));
define('DB_SERVER_USERNAME', $parameterBag->get('database_user'));
define('DB_SERVER_PASSWORD', $parameterBag->get('database_password'));
define('DB_DATABASE', $parameterBag->get('database_name'));
// @todo need to fix up for shared certificates
// @todo probably switch out this mechanism once we fully control the system
define('HTTP_SERVER', 'http://' . $httpServer);
define('HTTPS_SERVER', 'https://' . $httpServer);
define('HTTP_CATALOG_SERVER', 'http://' . $httpServer);
define('HTTPS_CATALOG_SERVER', 'https://' . $httpServer);
define('ENABLE_SSL_ADMIN', $settings->get('zenmagick.http.request.secure') ? 'true' : 'false');
define('ENABLE_SSL_CATALOG', $settings->get('zenmagick.http.request.secure') ? 'true' : 'false');
define('ENABLE_SSL', $settings->get('zenmagick.http.request.secure') ? 'true' : 'false');
define('DIR_WS_ADMIN', dirname($adminDir) . '/');
define('DIR_WS_CATALOG', str_replace('//', '/', '/' . $requestContext . '/'));
define('DIR_WS_HTTPS_ADMIN', DIR_WS_ADMIN);
define('DIR_WS_HTTPS_CATALOG', DIR_WS_CATALOG);
Esempio n. 8
0
 /**
  * Build list of paths to search for ZenCart init files.
  *
  * Looks in the bundle bridge directory before ZenCart.
  *
  * @param string base Relative path from ZenCart root directory
  */
 public function buildSearchPaths($base = '')
 {
     $zcPath = $this->getRootDir();
     $dirs = array(dirname(__DIR__) . '/bridge', $zcPath);
     if (Runtime::isContextMatch('admin')) {
         $adminDir = $this->container->getParameter('zencart.admin_dir');
         $adminDirs = array(dirname(__DIR__) . '/bridge/admin', $adminDir);
         if (false !== strpos($base, 'classes') || 0 === strpos($base, 'functions')) {
             $dirs = array_merge($adminDirs, $dirs);
         } else {
             $dirs = $adminDirs;
         }
     }
     $overrides = false !== strpos($base, 'auto_loaders') || false !== strpos($base, 'init_includes');
     $searchPaths = array();
     foreach ($dirs as $dir) {
         if ($overrides) {
             $searchPaths[] = $dir . '/' . $base . '/overrides';
         }
         $searchPaths[] = $dir . '/' . $base;
     }
     return $searchPaths;
 }
 /**
  * Get products for the given manufacturer id.
  *
  * <p>Request parameter:</p>
  * <ul>
  *  <li>manufacturerId The manufacturer id</li>
  *  <li>languageId - The language id</li>
  *  <li>active - Admin only parameter to allow to also retrieve inactive products</li>
  * </ul>
  *
  * @param ZenMagick\Http\Request request The current request.
  * @return void
  */
 public function getProductsForManufacturerIdJSON($request)
 {
     $manufacturerId = $request->getParameter('manufacturerId', 0);
     $languageId = $request->getParameter('languageId', $request->getSession()->getLanguageId());
     $activeOnly = true;
     if (Runtime::isContextMatch('admin')) {
         $activeOnly = $request->getParameter('active', true);
     }
     if (null === ($page = $request->getParameter('page'))) {
         // return all
         $flatObj = $this->flattenObject($this->container->get('productService')->getProductsForManufacturerId($manufacturerId, $activeOnly, $languageId), $this->get('ajaxProductMap'));
     } else {
         // use result list to paginate
         $args = array($manufacturerId, $activeOnly, $languageId);
         $resultSource = new \ZMObjectResultSource('ZenMagick\\StoreBundle\\Entity\\Product', 'productService', "getProductsForManufacturerId", $args);
         $resultList = Beans::getBean('ZMResultList');
         $resultList->setResultSource($resultSource);
         $resultList->setPageNumber($page);
         if (null !== ($pagination = $request->getParameter('pagination'))) {
             $resultList->setPagination($pagination);
         }
         $flatObj = $this->flattenObject($resultList, $this->get('ajaxResultListMap'));
     }
     $json = json_encode($flatObj);
     $this->setJSONHeader($json);
 }
Esempio n. 10
0
 /**
  * Resolve config for the given context.
  *
  * @param string context The contex; default is <code>null</code> to use the current context.
  * @return array The complete configuration for the chosen context.
  */
 public function resolve($context = null)
 {
     $context = $context ?: $this->getContext();
     $cconfig = array();
     foreach ($this->config as $key => $data) {
         if (in_array($key, array('meta', 'routing', 'container'))) {
             $cconfig[$key] = $data;
             // meta is special and is context independent
         } else {
             // context key
             if (Runtime::isContextMatch($key, $context)) {
                 $cconfig = Toolbox::arrayMergeRecursive($cconfig, $data);
             }
         }
     }
     return $cconfig;
 }
Esempio n. 11
0
 public function logAdminPageAccess($event)
 {
     if (Runtime::isContextMatch('admin')) {
         $request = $event->getArgument('request');
         if ('index' != $request->getRequestId()) {
             $params = $request->query->all();
             $data = array('admin_id' => null !== $request->getAccount() ? $request->getAccount()->getId() : 0, 'access_date' => new \DateTime(), 'page_accessed' => $request->getRequestId(), 'page_parameters' => http_build_query($params), 'ip_address' => $request->getClientIp());
             \ZMRuntime::getDatabase()->createModel('admin_activity_log', $data);
         }
     }
 }