Пример #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
 public function setUp()
 {
     ActiveRecordModel::getApplication()->clearCachedVars();
     ActiveRecordModel::beginTransaction();
     if (empty($this->autoincrements)) {
         foreach ($this->getUsedSchemas() as $table) {
             $res = $this->db->executeQuery("SHOW TABLE STATUS LIKE '{$table}'");
             $res->next();
             $this->autoincrements[$table] = (int) $res->getInt("Auto_increment");
         }
     }
     if ($this instanceof BackendControllerTestCase) {
         ClassLoader::import('application.model.user.SessionUser');
         ClassLoader::import('application.model.user.UserGroup');
         // set up user
         $group = UserGroup::getNewInstance('Unit tester');
         $group->save();
         $group->setAllRoles();
         $group->save();
         $user = User::getNewInstance('*****@*****.**', null, $group);
         $user->save();
         SessionUser::setUser($user);
     }
     if ($this instanceof ControllerTestCase) {
         $this->request = self::getApplication()->getRequest();
     }
 }
Пример #3
0
 public static function run($accessString)
 {
     if (empty($accessString)) {
         return true;
     }
     if (preg_match_all('/([\\w\\.]+)(?:\\(([\\w\\.]*)(?:\\/(\\w*))?\\))?,?/', $accessString, $roles)) {
         ClassLoader::import('application.model.user.SessionUser');
         $currentUser = SessionUser::getUser();
         $controller = Controller::getCurrentController();
         $rolesParser = $controller->getRoles();
         $currentControllerName = $controller->getRequest()->getControllerName();
         $currentActionName = $controller->getRequest()->getActionName();
         $rolesCount = count($roles[0]);
         for ($i = 0; $i < $rolesCount; $i++) {
             $roleString = $roles[0][$i];
             $roleName = $roles[1][$i];
             $roleControllerName = empty($roles[3][$i]) ? $currentControllerName : $roles[2][$i];
             $roleActionName = empty($roles[3][$i]) ? empty($roles[2][$i]) ? $currentActionName : $roles[2][$i] : $currentActionName;
             if ($roleControllerName == $currentControllerName && $roleActionName == $currentActionName) {
                 $aRoleName = $rolesParser->getRole($roleActionName);
                 if ($currentUser->hasAccess($aRoleName) && $currentUser->hasAccess($roleName)) {
                     return true;
                 }
             }
         }
         return false;
     }
     throw new ApplicationException('Access string ("' . $accessString . '") has illegal format');
 }
Пример #4
0
 public static function getGenerator(CustomerOrder $order)
 {
     $class = ActiveRecordModel::getApplication()->getConfig()->get('INVOICE_NUMBER_GENERATOR');
     self::loadGeneratorClass($class);
     ClassLoader::import('application.model.order.invoiceNumber.' . $class);
     return new $class($order);
 }
Пример #5
0
 public function isValid($value)
 {
     ClassLoader::import('application.model.user.User');
     $filter = new ARSelectFilter();
     $cond = new EqualsCond(new ARFieldHandle('User', 'email'), $value);
     $filter->setCondition($cond);
     return ActiveRecordModel::getRecordCount('User', $filter) == 0;
 }
Пример #6
0
/**
 * Display a tip block
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_denied($params, $content, LiveCartSmarty $smarty, &$repeat)
{
    if (!$repeat) {
        ClassLoader::import('application.helper.AccessStringParser');
        if (!AccessStringParser::run($params['role'])) {
            return $content;
        }
    }
}
Пример #7
0
/**
 * Display a tip block
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_allowed($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        ClassLoader::import('application.helper.AccessStringParser');
        if (AccessStringParser::run($params['role'])) {
            return $content;
        }
    }
}
Пример #8
0
 private function loadActionRuleClass($className)
 {
     ClassLoader::import('application.model.businessrule.action.' . $className);
     if (!class_exists($className, false)) {
         foreach (self::getApplication()->getPlugins('businessrule/action/' . $className) as $plugin) {
             include_once $plugin['path'];
         }
     }
     return $className;
 }
Пример #9
0
 public static function canParse(Request $request, $parserClassNames = array())
 {
     foreach ($parserClassNames as $parserClassName) {
         ClassLoader::import('application.model.datasync.api.reader.' . $parserClassName);
         if (call_user_func_array(array($parserClassName, "canParse"), array($request, $parserClassName))) {
             return true;
         }
     }
     return false;
 }
Пример #10
0
/**
 * Generates static page title
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_pageName($params, Smarty_Internal_Template $smarty)
{
    if (!class_exists('StaticPage', false)) {
        ClassLoader::import('application.model.staticpage.StaticPage');
    }
    if (!isset($params['id'])) {
        return '<span style="color: red; font-weight: bold; font-size: larger;">No static page ID provided</span>';
    }
    $page = StaticPage::getInstanceById($params['id'], StaticPage::LOAD_DATA)->toArray();
    return $page[!empty($params['text']) ? 'text_lang' : 'title_lang'];
}
Пример #11
0
/**
 * Generates static page URL
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_pageUrl($params, LiveCartSmarty $smarty)
{
    if (!class_exists('StaticPage', false)) {
        ClassLoader::import('application.model.staticpage.StaticPage');
    }
    if (isset($params['id'])) {
        $params['data'] = StaticPage::getInstanceById($params['id'], StaticPage::LOAD_DATA)->toArray();
    }
    $urlParams = array('controller' => 'staticPage', 'action' => 'view', 'handle' => $params['data']['handle']);
    return $smarty->getApplication()->getRouter()->createUrl($urlParams, true);
}
Пример #12
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_json($params, LiveCartSmarty $smarty)
{
    $array = $params['array'];
    $assign = isset($params['assign']) ? $params['assign'] : false;
    ClassLoader::import('library.json.json');
    $javaObject = @json_encode($array);
    if (!$assign) {
        return $javaObject;
    } else {
        $smarty->assign($assign, $javaObject);
    }
}
Пример #13
0
 private function getShippingMethods()
 {
     ClassLoader::import('application.model.delivery.ShippingService');
     $methods = array();
     $f = select();
     $f->setOrder(f('DeliveryZone.ID'));
     $f->setOrder(f('ShippingService.position'));
     foreach (ActiveRecord::getRecordSetArray('ShippingService', $f, array('DeliveryZone')) as $service) {
         $methods[$service['ID']] = $service['name_lang'] . ' (' . $service['DeliveryZone']['name'] . ')';
     }
     return $methods;
 }
Пример #14
0
 private function processBatch($plugins, $interval = null)
 {
     if ($plugins && !class_exists('CronPlugin', false)) {
         ClassLoader::import('application.CronPlugin');
     }
     foreach ($plugins as $plugin) {
         include_once $plugin['path'];
         $inst = new $plugin['class']($this->application, $plugin['path']);
         if ($inst->isExecutable($interval)) {
             $res = $inst->process();
             $inst->markCompletedExecution();
         }
     }
 }
Пример #15
0
 protected function processPlugins()
 {
     if (!$this->isPluginProcessed) {
         foreach ($this->application->getPlugins('validator/' . $this->getName()) as $plugin) {
             if (!class_exists('ValidatorPlugin', false)) {
                 ClassLoader::import('application.ValidatorPlugin');
             }
             include_once $plugin['path'];
             $inst = new $plugin['class']($this, $this->application);
             $inst->process();
         }
     }
     $this->isPluginProcessed = true;
 }
Пример #16
0
 public function index()
 {
     ClassLoader::import('application.controller.CategoryController');
     $this->request->set('id', Category::ROOT_ID);
     $this->request->set('cathandle', '-');
     $response = parent::index();
     // load site news
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
     $f->setOrder(new ARFieldHandle('NewsPost', 'position'), 'DESC');
     $f->setLimit($this->config->get('NUM_NEWS_INDEX') + 1);
     $news = ActiveRecordModel::getRecordSetArray('NewsPost', $f);
     $response->set('news', $news);
     $response->set('isNewsArchive', count($news) > $this->config->get('NUM_NEWS_INDEX'));
     return $response;
 }
Пример #17
0
 public static function getInstance($application, $defaultCurrencyCode = null, $currencyArray = null, $dataSourceName = null)
 {
     if ($defaultCurrencyCode === null) {
         $defaultCurrencyCode = $application->getDefaultCurrencyCode();
     }
     if ($currencyArray === null) {
         $currencyArray = $application->getCurrencyArray(true);
     }
     if ($dataSourceName === null) {
         $dataSourceName = $application->getConfig()->get('CURRENCY_DATA_SOURCE');
     }
     ClassLoader::import('application.model.currencyrate.' . $dataSourceName);
     $source = new $dataSourceName($defaultCurrencyCode, $currencyArray);
     return $source;
 }
Пример #18
0
/**
 * Tab
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_tab($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        ClassLoader::import('application.helper.AccessStringParser');
        if (!empty($params['role']) && !AccessStringParser::run($params['role'])) {
            return false;
        }
        $user = SessionUser::getUser();
        $userPref = $user->getPreference('tab_' . $params['id']);
        $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false';
        $content = '
<li id="' . $params['id'] . '" rel="' . $params['help'] . '" class="tab ui-state-default ui-corner-top inactive' . ($isHidden ? ' hidden' : '') . '">' . $content . '</li>';
        return $content;
    }
}
Пример #19
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_json($params, Smarty_Internal_Template $smarty)
{
    $array = $params['array'];
    $assign = isset($params['assign']) ? $params['assign'] : false;
    ClassLoader::import('library.json.json');
    $javaObject = @json_encode($array);
    if (!empty($params['escape'])) {
        $javaObject = addslashes($javaObject);
    }
    if (!$assign) {
        return $javaObject;
    } else {
        $smarty->assign($assign, $javaObject);
    }
}
Пример #20
0
/**
 * Tab
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_tab($params, $content, LiveCartSmarty $smarty, &$repeat)
{
    if (!$repeat) {
        ClassLoader::import('application.helper.AccessStringParser');
        if (!empty($params['role']) && !AccessStringParser::run($params['role'])) {
            return false;
        }
        $user = SessionUser::getUser();
        $userPref = $user->getPreference('tab_' . $params['id']);
        $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false';
        $content = '
<li id="' . $params['id'] . '" class="tab inactive' . ($isHidden ? ' hidden' : '') . '">' . $content . '
	<span> </span>
	<span class="tabHelp">' . $params['help'] . '</span>
</li>';
        return $content;
    }
}
Пример #21
0
<?php

/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 3/30/16
 * Time: 04:36
 */
ClassLoader::import('application.model.product.ProductOption');
ClassLoader::import('application.model.datasync.ModelApi');
ClassLoader::import('application.helper.LiveCartSimpleXMLElement');
class ProductOptionApi extends ModelApi
{
    public static function canParse(Request $request)
    {
        return parent::canParse($request, array('XmlProductOptionApiReader'));
    }
    public function __construct(LiveCart $application)
    {
        parent::__construct($application, 'ProductOption', array());
    }
    public function filter($emptyListIsException = false)
    {
        $request = $this->application->getRequest();
        $parser = $this->getParser();
        $apiFieldNames = $parser->getApiFieldNames();
        $parser->loadDataInRequest($request);
        $f = $parser->getARSelectFilter();
        $f->setOrder(new ARExpressionHandle('ProductOption.position'), 'ASC');
        $productOptions = ActiveRecordModel::getRecordSetArray('ProductOption', $f);
        $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
Пример #22
0
<?php

ClassLoader::import("framework.request.validator.check.Check");
/**
 * @package application.helper.check
 * @author Integry Systems
 */
class IsPasswordCorrectCheck extends Check
{
    private $user;
    public function __construct($violationMsg, User $user)
    {
        parent::__construct($violationMsg);
        $this->user = $user;
    }
    public function isValid($value)
    {
        return $this->user->isPasswordValid($value);
    }
}
Пример #23
0
<?php

ClassLoader::import('application.model.system.CssFile');
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_includeCss($params, LiveCartSmarty $smarty)
{
    $fileName = $params['file'];
    $filePath = substr($fileName, 0, 1) != '/' ? ClassLoader::getRealPath('public.stylesheet.') . $fileName : ClassLoader::getRealPath('public') . $fileName;
    // fix slashes
    $filePath = str_replace('\\', DIRECTORY_SEPARATOR, $filePath);
    $filePath = str_replace('/', DIRECTORY_SEPARATOR, $filePath);
    if (!is_file($filePath) && !isset($params['external']) || substr($filePath, -4) != '.css') {
        return;
    }
    $css = CssFile::getInstanceFromPath($filePath, $smarty->getApplication()->getTheme());
    if ($css->isPatched()) {
        $filePath = $css->getPatchedFilePath();
        $fileName = $css->getPatchedFileRelativePath();
    }
    if (isset($params['inline']) && $params['inline'] == 'true') {
        $path = 'stylesheet/' . str_replace(DIRECTORY_SEPARATOR, '/', $fileName) . '?' . filemtime($filePath);
        return '<link href="' . $path . '" media="screen" rel="Stylesheet" type="text/css" />' . "\n";
Пример #24
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'On');
include '../application/Initialize.php';
ClassLoader::import('application.LiveCart');
new LiveCart();
ClassLoader::import('application.model.category.Category');
Category::getInstanceById(1);
Category::recalculateProductsCount();
Пример #25
0
<?php

/**
 * @author Integry Systems
 */
ClassLoader::import('application.model.currencyrate.CurrencyRateSource');
class CurrencyRates extends CronPlugin
{
    public function isExecutable($interval)
    {
        if (parent::isExecutable($interval)) {
            $config = $this->application->getConfig();
            if (!$config->get('CURRENCY_RATE_UPDATE')) {
                return false;
            }
            $currencyRateUpdateTs = $this->application->getCache()->get('currencyRateUpdateTs', 0);
            $interval = $config->get('CURRENCY_RATE_UPDATE_INTERVAL');
            if (time() - 3600 * $interval < $currencyRateUpdateTs) {
                return false;
            }
            // only true if:
            //      isExecutable() now
            //  + is CURRENCY_RATE_UPDATE enabled
            //  + has passed CURRENCY_RATE_UPDATE_INTERVAL hours till last update
            return true;
        }
        return false;
    }
    public function process()
    {
        $source = CurrencyRateSource::getInstance($this->application);
Пример #26
0
session_set_cookie_params(180 * 60 * 60 * 24);
include_once (include 'appdir.php') . '/application/Initialize.php';
ClassLoader::import('application.LiveCart');
ini_set('display_errors', 0);
$app = new LiveCart();
if (isset($stat)) {
    $app->setStatHandler($stat);
    $stat->logStep('Initialization');
}
// Custom initialization tasks
$custom = ClassLoader::getRealPath('storage.configuration.CustomInitialize') . '.php';
if (file_exists($custom)) {
    include $custom;
}
if (version_compare('5.2', PHP_VERSION, '>')) {
    ClassLoader::import('library.json.json');
}
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()) {
Пример #27
0
<?php

ClassLoader::import("application.model.delivery.DeliveryZone");
ClassLoader::import("application.model.tax.Tax");
ClassLoader::import("application.model.tax.TaxClass");
/**
 * Defines a tax rate for a DeliveryZone. Tax rates are applied to order totals and shipping charges as well.
 *
 * @package application.model.tax
 * @author Integry Systems <http://integry.com>
 */
class TaxRate extends MultilingualObject
{
    public static function defineSchema($className = __CLASS__)
    {
        $schema = self::getSchemaInstance($className);
        $schema->setName("TaxRate");
        $schema->registerField(new ARPrimaryKeyField("ID", ARInteger::instance()));
        $schema->registerField(new ARForeignKeyField("deliveryZoneID", "DeliveryZone", "ID", "DeliveryZone", ARInteger::instance()));
        $schema->registerField(new ARForeignKeyField("taxID", "Tax", "ID", "Tax", ARInteger::instance()));
        $schema->registerField(new ARForeignKeyField("taxClassID", "TaxClass", "ID", "TaxClass", ARInteger::instance()));
        $schema->registerField(new ARField("rate", ARFloat::instance()));
        $schema->registerAutoReference('taxClassID');
    }
    /**
     * Gets an existing record instance (persisted on a database).
     * @param mixed $recordID
     * @param bool $loadRecordData
     * @param bool $loadReferencedRecords
     * @param array $data	Record data array (may include referenced record data)
     *
Пример #28
0
<?php

ClassLoader::import('application.model.session.SessionHandler');
ClassLoader::import('application.model.session.SessionData');
/**
 * Session storage and retrieval from database
 *
 * @package application.model.session
 * @author Integry Systems
 */
class DatabaseSessionHandler extends SessionHandler
{
    const KEEPALIVE_INTERVAL = 60;
    protected $db;
    protected $isExistingSession;
    protected $id;
    protected $originalData;
    public function open()
    {
        try {
            $this->db = ActiveRecordModel::getDBConnection();
            $this->db->sessionHandler = $this;
            return true;
        } catch (SQLException $e) {
            return false;
        }
    }
    public function close()
    {
        return true;
    }
Пример #29
0
<?php

/*
include_once('simpletest/unit_tester.php');
include_once('unittest/UnitTest.php');
include_once('simpletest/reporter.php');
*/
include_once 'Initialize.php';
ClassLoader::import('library.payment.TransactionDetails');
/**
 *
 * @package library.payment.test
 * @author Integry Systems
 */
abstract class PaymentTest extends UnitTest
{
    public function tearDown()
    {
    }
    public function setUp()
    {
        $details = new TransactionDetails();
        $details->firstName->set('Rinalds');
        $details->lastName->set('Uzkalns');
        $details->address->set('Taikos 259-55');
        $details->city->set('Vilnius');
        $details->state->set('Vilnius');
        $details->country->set('LT');
        $details->postalCode->set('05214');
        $details->shippingFirstName->set('Rinalds');
        $details->shippingLastName->set('Uzkalns');
Пример #30
0
<?php

ClassLoader::import('application.model.businessrule.RuleAction');
/**
 *
 * @author Integry Systems
 * @package application.model.businessrule.action
 */
class RuleActionSetQuantity extends RuleAction implements RuleItemAction
{
    public function applyToItem(BusinessRuleProductInterface $item)
    {
        if ($item instanceof OrderedItem) {
            $item->count->set($this->getFieldValue('count'));
            $item->save();
        }
    }
    public function getFields()
    {
        return array(array('type' => 'number', 'label' => '_quantity', 'name' => 'count'));
    }
}