예제 #1
0
 public function __construct(LiveCart $application)
 {
     if ($application->getConfig()->get('SSL_BACKEND')) {
         $application->getRouter()->setSslAction('');
     }
     parent::__construct($application);
     if (!isset($_SERVER['HTTP_USER_AGENT'])) {
         $_SERVER['HTTP_USER_AGENT'] = 'Firefox';
     }
     // no IE yet
     if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
         ClassLoader::import('application.controller.backend.UnsupportedBrowserException');
         throw new UnsupportedBrowserException();
     }
     if (!$this->user->hasBackendAccess() && !$this instanceof SessionController) {
         SessionUser::destroy();
         $url = $this->router->createUrl(array('controller' => 'backend.session', 'action' => 'index', 'query' => array('return' => $_SERVER['REQUEST_URI'])));
         if (!$this->isAjax()) {
             header('Location: ' . $url);
         } else {
             header('Content-type: text/javascript');
             echo json_encode(array('__redirect' => $url));
         }
         exit;
     }
 }
예제 #2
0
function createProductUrl($params, LiveCart $application)
{
    $product = $params['product'];
    $router = $application->getRouter();
    // use parent product data for child variations
    if (isset($product['Parent'])) {
        $product = $product['Parent'];
    }
    $handle = createHandleString($product['name_lang']);
    $urlParams = array('controller' => 'product', 'action' => 'index', 'producthandle' => $handle, 'id' => $product['ID']);
    if (isset($params['query'])) {
        $urlParams['query'] = $params['query'];
    }
    if (isset($params['context'])) {
        $urlParams['query'] .= (!empty($urlParams['query']) ? '&' : '') . $router->createUrlParamString($params['context']);
    }
    $url = $router->createUrl($urlParams, true);
    if (!empty($params['full'])) {
        $url = $router->createFullUrl($url);
    }
    if (!empty($params['filterChainHandle'])) {
        $url = $router->setUrlQueryParam($url, 'filters', $params['filterChainHandle']);
    }
    if (!empty($params['category']) && $params['category']['ID'] != $product['categoryID']) {
        $url = $router->setUrlQueryParam($url, 'category', $params['category']['ID']);
    }
    $router->setLangReplace($handle, 'name', $product);
    return $url;
}
예제 #3
0
파일: index.php 프로젝트: saiber/www
function runApp(LiveCart $app)
{
    static $attempts = 0;
    // check if we're not getting into an endless loop
    if (++$attempts > 5) {
        try {
            $app->run();
        } catch (Exception $e) {
            dump_livecart_trace($e);
            die('error');
        }
    }
    try {
        if ($app->isDevMode()) {
            try {
                $app->run();
            } catch (Exception $e) {
                if (!$e instanceof HTTPStatusException) {
                    dump_livecart_trace($e);
                } else {
                    throw $e;
                }
            }
        } else {
            $app->run();
        }
    } catch (HTTPStatusException $e) {
        if ($e->getController() instanceof BackendController) {
            $route = 'backend.err/redirect/' . $e->getStatusCode();
        } else {
            $route = 'err/redirect/' . $e->getStatusCode();
        }
        $app->getRouter()->setRequestedRoute($route);
        runApp($app);
    } catch (ARNotFoundException $e) {
        $app->getRouter()->setRequestedRoute('err/redirect/404');
        runApp($app);
    } catch (ControllerNotFoundException $e) {
        $app->getRouter()->setRequestedRoute('err/redirect/404');
        runApp($app);
    } catch (ActionNotFoundException $e) {
        $app->getRouter()->setRequestedRoute('err/redirect/404');
        runApp($app);
    } catch (UnsupportedBrowserException $e) {
        header('Location: ' . $app->getRouter()->createUrl(array('controller' => 'err', 'action' => 'backendBrowser')));
        exit;
    } catch (SQLException $e) {
        $_REQUEST['exception'] = $e;
        $app->getRouter()->setRequestedRoute('err/database');
        runApp($app);
    } catch (Exception $e) {
        $route = 'err/redirect/500';
        $app->getRouter()->setRequestedRoute($route);
        runApp($app);
    }
}
예제 #4
0
function createNewsPostUrl($params, LiveCart $application)
{
    $news = $params['news'];
    $urlParams = array('controller' => 'news', 'action' => 'view', 'handle' => createHandleString($news['title_lang']), 'id' => $news['ID']);
    $router = $application->getRouter();
    $url = $router->createUrl($urlParams, true);
    if (array_key_exists('full', $params) && $params['full'] == true) {
        $url = $router->createFullUrl($url);
    }
    return $url;
}
예제 #5
0
function createProductUrl($params, LiveCart $application)
{
    $product = $params['product'];
    // use parent product data for child variations
    if (isset($product['Parent'])) {
        $product = $product['Parent'];
    }
    //var_dump($product);
    $handle = !empty($product['URL']) ? createHandleString($product['URL']) : createHandleString($product['name_lang']);
    $urlParams = array('controller' => 'product', 'action' => 'index', 'producthandle' => $handle, 'id' => $product['ID']);
    $url = $application->getRouter()->createUrl($urlParams, true);
    if (!empty($params['full'])) {
        $url = $application->getRouter()->createFullUrl($url);
    }
    if (!empty($params['filterChainHandle'])) {
        $url = $application->getRouter()->setUrlQueryParam($url, 'filters', $params['filterChainHandle']);
    }
    $application->getRouter()->setLangReplace($handle, 'name', $product);
    return $url;
}
예제 #6
0
function createCategoryUrl($params, LiveCart $application)
{
    static $simpleUrlTemplate = null;
    // create URL template
    $router = $application->getRouter();
    if (!$simpleUrlTemplate) {
        $simpleUrlTemplate = $router->createUrl(array('controller' => 'category', 'action' => 'index', 'cathandle' => '---', 'id' => 999));
        $simpleUrlTemplate = strtr($simpleUrlTemplate, array(999 => '#', '---' => '|'));
    }
    $category = $params['data'];
    if (!isset($category['ID'])) {
        $category['ID'] = 1;
    }
    $handle = isset($category['name_lang']) ? createHandleString($category['name_lang']) : '';
    // category names to use in other language links
    $router->setLangReplace($handle, 'name', $category);
    // no extra params, so we don't need to call the router to build the URL
    if (count($params) == 1) {
        return strtr($simpleUrlTemplate, array('#' => $category['ID'], '|' => $handle));
    }
    $filters = array();
    // remove filter (expand search)
    if (isset($params['removeFilter'])) {
        foreach ($params['filters'] as $key => $filter) {
            if ($filter['ID'] == $params['removeFilter']['ID']) {
                unset($params['filters'][$key]);
            }
        }
    }
    if (isset($params['removeFilters'])) {
        foreach ($params['removeFilters'] as $filter) {
            unset($params['filters'][$filter['ID']]);
        }
    }
    // get filters
    if (isset($params['filters'])) {
        foreach ($params['filters'] as $filter) {
            $filters[] = filterHandle($filter);
        }
    }
    // apply new filter (narrow search)
    if (!empty($params['addFilter'])) {
        $filters[] = filterHandle($params['addFilter']);
    }
    if (empty($handle)) {
        $handle = '-';
    }
    $urlParams = array('controller' => 'category', 'action' => empty($params['action']) ? 'index' : $params['action'], 'cathandle' => $handle, 'id' => $category['ID']);
    if (!empty($params['query'])) {
        $urlParams['query'] = $params['query'];
    }
    if (!empty($params['page'])) {
        $urlParams['page'] = $params['page'];
    }
    if ($filters) {
        $urlParams['filters'] = implode(',', $filters);
    }
    if ('index' != $urlParams['action']) {
        unset($urlParams['cathandle']);
        if (isset($urlParams['filters'])) {
            $urlParams['query'] = 'filters=' . $urlParams['filters'];
            unset($urlParams['filters']);
        }
    }
    $url = $application->getRouter()->createUrl($urlParams, true);
    if (!empty($params['full'])) {
        $url = $application->getRouter()->createFullUrl($url);
    }
    // remove empty search query parameter
    return preg_replace('/[\\?&]q=$/', '', $url);
}