Ejemplo n.º 1
0
 /**
  * Perform some actions after the "login" action
  *
  * @return void
  */
 public function redirectFromLogin()
 {
     $url = $this->getRedirectFromLoginURL();
     if (isset($url)) {
         \XLite\Core\CMSConnector::isCMSStarted() ? \XLite\Core\Operator::redirect($url, true) : $this->setReturnURL($url);
     }
 }
Ejemplo n.º 2
0
 /**
  * Register new shipping processor. All processors classes must be
  * derived from \XLite\Model\Shipping\Processor\AProcessor class
  *
  * @param string $processorClass Processor class
  *
  * @return void
  */
 public static function registerProcessor($processorClass)
 {
     if (!isset(static::$registeredProcessors[$processorClass]) && \XLite\Core\Operator::isClassExists($processorClass)) {
         static::$registeredProcessors[$processorClass] = new $processorClass();
         uasort(static::$registeredProcessors, array(\XLite\Model\Shipping::getInstance(), 'compareProcessors'));
     }
 }
Ejemplo n.º 3
0
 /**
  * Find all active modifiers
  *
  * @return array
  */
 public function findActive()
 {
     $list = $this->createQueryBuilder()->getResult();
     $list = is_array($list) ? new \XLite\DataSet\Collection\OrderModifier($list) : null;
     if ($list) {
         foreach ($list as $i => $item) {
             if (!\XLite\Core\Operator::isClassExists($item->getClass())) {
                 unset($list[$i]);
             }
         }
     }
     return $list;
 }
Ejemplo n.º 4
0
 /**
  * Get storage 
  * 
  * @return \XLite\Model\Base\Storage
  */
 protected function getStorage()
 {
     if (!isset($this->storage) || !is_object($this->storage) || !$this->storage instanceof \XLite\Model\Base\Storage) {
         $class = \XLite\Core\Request::getInstance()->storage;
         if (\XLite\Core\Operator::isClassExists($class)) {
             $id = \XLite\Core\Request::getInstance()->id;
             $this->storage = \XLite\Core\Database::getRepo($class)->find($id);
             if (!$this->storage->isFileExists()) {
                 $this->storage = null;
             }
         }
     }
     return $this->storage;
 }
Ejemplo n.º 5
0
Archivo: Main.php Proyecto: kingsj/core
 /**
  * Returns repository class for model class of current node
  *
  * @param \Includes\Decorator\DataStructure\Graph\Classes $node Current node
  *
  * @return string
  */
 protected function getRepositoryClass(\Includes\Decorator\DataStructure\Graph\Classes $node)
 {
     $repositoryClass = null;
     if (!($node->isLowLevelNode() || $node->isTopLevelNode() || !$node->isDecorator())) {
         $children = $node->getChildren();
         $repositoryClass = isset($children[0]) ? $this->getRepositoryClass($children[0]) : $this->getDefaultRepositoryClass('');
     } else {
         $repositoryClass = \Includes\Utils\Converter::getPureClassName($node->getClass());
         $repositoryClass = \Includes\Utils\Converter::prepareClassName(str_replace('\\Model\\', '\\Model\\Repo\\', $repositoryClass), false);
         if (!\XLite\Core\Operator::isClassExists($repositoryClass)) {
             $repositoryClass = $this->getDefaultRepositoryClass($repositoryClass);
         }
     }
     return $repositoryClass;
 }
Ejemplo n.º 6
0
 /**
  * Get storage by a link
  *
  * @return \XLite\Model\Base\Storage|\XLite\Module\XC\CanadaPost\Model\Base\Link|null
  */
 protected function getCapostStorageByLink()
 {
     if (!isset($this->storage) || !is_object($this->storage) || !$this->storage instanceof \XLite\Model\Base\Storage) {
         $class = \XLite\Core\Request::getInstance()->storage;
         if (\XLite\Core\Operator::isClassExists($class)) {
             $link = \XLite\Core\Database::getRepo($class)->find($this->getCapostLinkId());
             if (isset($link)) {
                 $this->storage = $link->getStorage();
                 if (!isset($this->storage) && $link->callApiGetArtifact(true)) {
                     // Download artifact
                     $this->storage = $link->getStorage();
                     if (!$this->storage->isFileExists()) {
                         $this->storage = null;
                     }
                 }
             }
         }
     }
     return $this->storage;
 }
Ejemplo n.º 7
0
 /**
  * Get payment processor class
  *
  * @return string
  */
 public function getClass()
 {
     $class = parent::getClass();
     if (Paypal\Main::PP_METHOD_EC == $this->getServiceName()) {
         $className = 'XLite\\' . $class;
         /** @var \XLite\Model\Payment\Base\Processor $processor */
         $processor = \XLite\Core\Operator::isClassExists($className) ? $className::getInstance() : null;
         if ($this->isForceMerchantAPI($processor)) {
             $class = 'Module\\CDev\\Paypal\\Model\\Payment\\Processor\\ExpressCheckoutMerchantAPI';
         }
     }
     if (Paypal\Main::PP_METHOD_PC == $this->getServiceName()) {
         $className = 'XLite\\' . $class;
         /** @var \XLite\Model\Payment\Base\Processor $processor */
         $processor = \XLite\Core\Operator::isClassExists($className) ? $className::getInstance() : null;
         if ($this->getExpressCheckoutPaymentMethod()->isForceMerchantAPI($processor)) {
             $class = 'Module\\CDev\\Paypal\\Model\\Payment\\Processor\\PaypalCreditMerchantAPI';
         }
     }
     return $class;
 }
Ejemplo n.º 8
0
 /**
  * Check if current page is accessible
  *
  * @return boolean
  */
 public function checkAccess()
 {
     return parent::checkAccess() && $this->checkRequest() && \XLite\Core\Operator::isClassExists($this->getClass());
 }
Ejemplo n.º 9
0
 /**
  * Generate unique parcel number and set it to current parcel
  * 
  * @return void
  */
 public function autoGenerateNumber()
 {
     $number = \XLite\Core\Operator::getInstance()->generateToken(static::PARCEL_NUMBER_LENGTH, static::$chars);
     $this->setNumber($number);
 }
Ejemplo n.º 10
0
 /**
  * Prepare processors
  *
  * @return void
  */
 protected function prepareProcessors()
 {
     foreach ($this->processors as $i => $processor) {
         if (\XLite\Core\Operator::isClassExists($processor)) {
             $this->processors[$i] = new $processor($this);
         } else {
             unset($this->processors[$i]);
         }
     }
     $this->processors = array_values($this->processors);
 }
Ejemplo n.º 11
0
 /**
  * Prepare back trace
  *
  * @param array $trace Back trace raw data
  *
  * @return array
  */
 protected function prepareBackTrace(array $trace)
 {
     return \XLite\Core\Operator::getInstance()->prepareBackTrace($trace);
 }
Ejemplo n.º 12
0
 /**
  * Display widget as Standalone-specific
  *
  * @return boolean
  */
 protected function isIncludeController()
 {
     return \XLite\Core\Operator::isClassExists('\\XLite\\Module\\CDev\\DrupalConnector\\Handler') && \XLite\Module\CDev\DrupalConnector\Handler::getInstance()->checkCurrentCMS() && function_exists('googleanalytics_theme');
 }
Ejemplo n.º 13
0
 /**
  * Run test
  *
  * @return void
  * @access protected
  * @see    ____func_see____
  * @since  1.0.0
  */
 protected function runTest()
 {
     try {
         $shortName = lcfirst(substr($this->getName(), 4));
         if (self::$testsRange && !in_array($shortName, self::$testsRange)) {
             $this->markTestSkipped();
         } elseif ($this->temporarySkipped) {
             $this->markTestSkipped('Temporary skipped - fix test ASAP!');
         } else {
             parent::runTest();
         }
     } catch (\Exception $exception) {
         if (isset($this->drivers[0]) && $this->drivers[0]->getSessionId()) {
             try {
                 $location = preg_replace('/[^\\w]/Ss', '-', $this->getLocation());
                 $location = preg_replace('/-+/Ss', '-', $location);
                 $html = $this->getHtmlSource();
                 $trace = array();
                 if (!defined('DEPLOYMENT_TEST')) {
                     $trace = \XLite\Core\Operator::getInstance()->getBackTrace();
                 }
                 file_put_contents(TESTS_LOG_DIR . 'selenium.' . $location . '.' . date('Ymd-His') . '.html', '<!--' . PHP_EOL . 'Exception: ' . $exception->getMessage() . ';' . PHP_EOL . ($trace ? 'Back trace: ' . var_export($trace, true) . PHP_EOL : '') . '-->' . PHP_EOL . $html);
             } catch (\RuntimeException $e) {
             }
         }
         $backtrace = array();
         foreach ($exception->getTrace() as $t) {
             $b = null;
             if (isset($t['file'])) {
                 $b = $t['file'] . ' : ' . $t['line'];
             } elseif (isset($t['function'])) {
                 $b = 'function ' . $t['function'] . '()';
                 if (isset($t['line'])) {
                     $b .= ' : ' . $t['line'];
                 }
             }
             if ($b) {
                 $backtrace[] = $b;
             }
         }
         file_put_contents(TESTS_LOG_DIR . 'selenium.' . date('Ymd-His') . '.backtrace', 'Exception: ' . $exception->getMessage() . ';' . PHP_EOL . PHP_EOL . 'Backtrace: ' . PHP_EOL . implode(PHP_EOL, $backtrace) . PHP_EOL);
         throw $exception;
     }
 }
Ejemplo n.º 14
0
 /**
  * Check if wholesale prices are enabled for the specified product.
  * Return true if product is not on sale (Sale module)
  *
  * @return boolean
  */
 public function isWholesalePricesEnabled()
 {
     return !\XLite\Core\Operator::isClassExists('\\XLite\\Module\\CDev\\Sale\\Main') || !$this->getParticipateSale();
 }
Ejemplo n.º 15
0
 /**
  * Load import file from URL 
  * 
  * @param string $url URL
  *  
  * @return string
  */
 protected function loadFromURLImport($url)
 {
     $result = null;
     $content = \XLite\Core\Operator::getURLContent($url);
     $path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, basename($path));
     if ($content && file_put_contents($path, $content)) {
         $result = $path;
     }
     return $result;
 }
Ejemplo n.º 16
0
 /**
  * Get view class name as keys list
  *
  * @return array
  */
 protected function getViewClassKeys()
 {
     return \XLite\Core\Operator::getInstance()->getClassNameAsKeys(get_called_class());
 }
Ejemplo n.º 17
0
 /**
  * Process callback-based patch
  *
  * @param \XLite\Model\TemplatePatch $patch Patch record
  *
  * @return void
  */
 protected function processCustomPatch(\XLite\Model\TemplatePatch $patch)
 {
     list($class, $method) = explode('::', $patch->custom_callback, 2);
     if (\XLite\Core\Operator::isClassExists($class)) {
         $this->source = $class::$method($this->source);
     }
 }
Ejemplo n.º 18
0
 /**
  * Get modifier object
  *
  * @return \XLite\Logic\Order\Modifier\AModifier
  */
 public function getModifier()
 {
     if (!isset($this->modifier) && \XLite\Core\Operator::isClassExists($this->getClass())) {
         $class = $this->getClass();
         $this->modifier = new $class($this);
     }
     return $this->modifier;
 }
Ejemplo n.º 19
0
 /**
  * Return widget
  *
  * @param string  $class  Widget class name
  * @param array   $params Widget params OPTIONAL
  * @param integer $delta  Drupal-specific param - so called "delta" OPTIONAL
  *
  * @return \XLite\Core\WidgetDataTransport
  */
 public function getWidget($class, array $params = array(), $delta = 0)
 {
     return new \XLite\Core\WidgetDataTransport(\XLite\Core\Operator::isClassExists($class) ? $this->getViewer()->getWidget($params, $class) : null);
 }
Ejemplo n.º 20
0
$searchFields = macro_get_named_argument('search');
$pagination = !is_null(macro_get_named_argument('pagination'));
$sortFields = macro_get_named_argument('sort');
$createInline = !is_null(macro_get_named_argument('createInline'));
$menu = macro_get_named_argument('menu');
// {{{ Check arguments
// --entity
if (!$entityClass) {
    macro_error('Entity class (--entity) argument is empty');
} elseif (\Includes\Utils\FileManager::isExists($entityClass)) {
    $entityClassPath = realpath($entityClass);
    $entityClass = str_replace(LC_DS, '\\', substr($entityClassPath, strlen(LC_DIR_CLASSES)));
} elseif (\Includes\Utils\FileManager::isExists(LC_DIR_CLASSES . $entityClass)) {
    $entityClassPath = realpath(LC_DIR_CLASSES . $entityClass);
    $entityClass = str_replace(LC_DS, '\\', $entityClass);
} elseif (\XLite\Core\Operator::isClassExists($entityClass)) {
    $entityClass = ltrim($entityClass, '\\');
    $entityClassPath = LC_DIR_CLASSES . str_replace('\\', LC_DS, $entityClass);
} else {
    macro_error('Entity class (--entity) \'' . $entityClass . '\' not found');
}
if (!is_subclass_of($entityClass, 'XLite\\Model\\AEntity')) {
    macro_error('Class \'' . $entityClass . '\' is not child of XLite\\Model\\AEntity');
}
$entityRepoClass = str_replace('\\Model\\', '\\Model\\Repo\\', $entityClass);
preg_match('/\\\\Model\\\\(.+)$/Ss', $entityClass, $match);
$entityRelativeClass = $match[1];
$entityShortClass = macro_get_class_short_name($entityClass);
$moduleAuthor = null;
$moduleName = null;
if (preg_match('/XLite\\\\Module\\\\([a-z0-9]+)\\\\([a-z0-9]+)\\\\Model/iSs', $entityClass, $match)) {
Ejemplo n.º 21
0
 /**
  * "URL" handler for category images.
  * Returns path of the temporary file
  * fixme: $path is undefined
  *
  * @return void
  */
 protected function doActionSelectUrlLanguageFile()
 {
     $result = null;
     $url = \XLite\Core\Request::getInstance()->url;
     $content = \XLite\Core\Operator::getURLContent($url);
     $path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, basename($path));
     if ($content && file_put_contents($path, $content)) {
         $result = $path;
     }
     $this->doActionSelectLanguageFile($result);
 }
Ejemplo n.º 22
0
 /**
  * Process steps
  *
  * @return void
  */
 protected function processSteps()
 {
     if ($this->getOptions()->include) {
         foreach ($this->steps as $i => $step) {
             if (!in_array($step, $this->getOptions()->include)) {
                 unset($this->steps[$i]);
             }
         }
     }
     foreach ($this->steps as $i => $step) {
         if (\XLite\Core\Operator::isClassExists($step)) {
             $this->steps[$i] = new $step($this);
         } else {
             unset($this->steps[$i]);
         }
     }
     $this->steps = array_values($this->steps);
 }
Ejemplo n.º 23
0
 /**
  * Get query builder
  *
  * @return \XLite\Model\QueryBuilder\AQueryBuilder
  */
 protected function getQueryBuilder()
 {
     if (null === $this->queryBuilderClass) {
         $this->queryBuilderClass = str_replace('\\Repo\\', '\\QueryBuilder\\', get_called_class());
         if (!\XLite\Core\Operator::isClassExists($this->queryBuilderClass)) {
             $this->queryBuilderClass = '\\XLite\\Model\\QueryBuilder\\Base\\Common';
         }
     }
     $class = $this->queryBuilderClass;
     return new $class($this->_em);
 }
Ejemplo n.º 24
0
 /**
  * Apply 
  * 
  * @param float                $value     Property value
  * @param \XLite\Model\AEntity $model     Model
  * @param string               $property  Model's property
  * @param array                $behaviors Behaviors
  * @param string               $purpose   Purpose
  *  
  * @return float
  */
 public function apply($value, \XLite\Model\AEntity $model, $property, array $behaviors, $purpose)
 {
     $class = $this->getClass();
     if (\XLite\Core\Operator::isClassExists($class)) {
         $validationMethod = $this->getValidator();
         $calculateMethod = $this->getModificator();
         if (!$validationMethod || $class::$validationMethod($model, $property, $behaviors, $purpose)) {
             $value = $class::$calculateMethod($value, $model, $property, $behaviors, $purpose);
         }
     }
     return $value;
 }
Ejemplo n.º 25
0
 /**
  * Dispatch request
  *
  * @return string
  */
 protected static function dispatchRequest()
 {
     $result = static::TARGET_DEFAULT;
     if (isset(\XLite\Core\Request::getInstance()->url)) {
         if (LC_USE_CLEAN_URLS) {
             // Get target
             $result = static::getTargetByCleanURL();
             // Get canonical redirect URL
             $canonicalURL = \XLite\Core\Database::getRepo('XLite\\Model\\CleanURL')->getRedirectCanonicalURL($result);
             if ($canonicalURL) {
                 // Redirect
                 \XLite\Core\Operator::redirect($canonicalURL);
             }
         } else {
             $result = static::isCheckForCleanURL() ? $result : null;
         }
     }
     return $result;
 }
Ejemplo n.º 26
0
 /**
  * Load from URL
  *
  * @param string  $url     URL
  * @param boolean $copy2fs Copy file to file system or not OPTIONAL
  *
  * @return boolean
  */
 public function loadFromURL($url, $copy2fs = false)
 {
     $result = $this->isURL($url);
     if ($result) {
         $name = basename(parse_url($url, PHP_URL_PATH));
         if ($copy2fs) {
             $file = \XLite\Core\Operator::getURLContent($url);
             $result = !empty($file);
             if ($result) {
                 $tmp = LC_DIR_TMP . $name;
                 $result = \Includes\Utils\FileManager::write($tmp, $file);
                 if ($result) {
                     $result = $this->loadFromLocalFile($tmp);
                 } else {
                     \XLite\Logger::getInstance()->log('Unable to write data to file \'' . $tmp . '\'.', LOG_ERR);
                 }
                 if ($result) {
                     \Includes\Utils\FileManager::deleteFile($tmp);
                 }
             } else {
                 \XLite\Logger::getInstance()->log('Unable to get at the contents of \'' . $url . '\'.', LOG_ERR);
             }
         } else {
             $savedPath = $this->getPath();
             $this->setPath($url);
             $this->setFileName($name);
             $result = $this->renew();
             if ($result) {
                 $this->removeFile($savedPath);
                 $this->setStorageType(static::STORAGE_URL);
             }
         }
     }
     return $result;
 }
Ejemplo n.º 27
0
 /**
  * getFieldBySchema
  * TODO - should use the Factory class
  *
  * @param string $name Field name
  * @param array  $data Field description
  *
  * @return \XLite\View\FormField\AFormField
  */
 protected function getFieldBySchema($name, array $data)
 {
     $result = null;
     $class = $data[self::SCHEMA_CLASS];
     if (\XLite\Core\Operator::isClassExists($class)) {
         $method = 'prepareFieldParams' . \XLite\Core\Converter::convertToCamelCase($name);
         if (method_exists($this, $method)) {
             // Call the corresponded method
             $data = $this->{$method}($data);
         }
         $result = new $class($this->getFieldSchemaArgs($name, $data));
     }
     return $result;
 }
Ejemplo n.º 28
0
 /**
  * Return controller for current page
  *
  * @param string $target Controller target
  * @param array  $params Controller params OPTIONAL
  *
  * @return \XLite\Core\WidgetDataTransport
  */
 public function getPageInstance($target, array $params = array())
 {
     $class = \XLite\Core\Converter::getControllerClass($target);
     return new \XLite\Core\WidgetDataTransport(\XLite\Core\Operator::isClassExists($class) ? new $class(array('target' => $target) + $params) : null);
 }
Ejemplo n.º 29
0
 /**
  * Print AJAX request output
  *
  * @param mixed $viewer Viewer to display in AJAX
  *
  * @return void
  */
 protected function printAJAXOutput($viewer)
 {
     $content = $viewer->getContent();
     $class = 'ajax-container-loadable' . ' ctrl-' . implode('-', \XLite\Core\Operator::getInstance()->getClassNameAsKeys(get_called_class())) . ' widget-' . implode('-', \XLite\Core\Operator::getInstance()->getClassNameAsKeys($viewer));
     echo '<div' . ' class="' . $class . '"' . ' title="' . func_htmlspecialchars(static::t($this->getTitle())) . '">' . $content . '</div>';
 }
Ejemplo n.º 30
0
 /**
  * Compose controller class name using target
  *
  * @param string $target Current target
  *
  * @return string
  */
 public static function getControllerClass($target)
 {
     $zone = 'Customer';
     if (\XLite\Core\Request::getInstance()->isCLI()) {
         $zone = 'Console';
     } elseif (\XLite::isAdminZone()) {
         $zone = 'Admin';
     }
     $target = static::convertToCamelCase($target);
     // Initialize cache
     if (null === static::$cacheControllers) {
         static::$cacheControllers = static::getSystemCacheDriver()->fetch('controllers');
         if (!is_array(static::$cacheControllers)) {
             static::$cacheControllers = array();
         }
     }
     // Check cache
     $class = isset(static::$cacheControllers[$zone . '.' . $target]) ? static::$cacheControllers[$zone . '.' . $target] : null;
     if (!$class) {
         // Detect
         $prefix = 'Controller\\' . $zone . '\\' . static::convertToCamelCase($target);
         $class = 'XLite\\' . $prefix;
         // If non core controller
         if (!\XLite\Core\Operator::isClassExists($class)) {
             $class = null;
             $base = LC_DIR_CACHE_CLASSES;
             $path = $base . 'XLite' . LC_DS . 'Module' . LC_DS . '*' . LC_DS . '*' . LC_DS . 'Controller' . LC_DS . $zone . LC_DS . $target . '.php';
             $list = glob($path);
             if ($list) {
                 $length = strlen(LC_DIR_CACHE_CLASSES);
                 foreach ($list as $path) {
                     $preclass = str_replace(LC_DS, '\\', substr($path, $length, -4));
                     $reflection = new \ReflectionClass($preclass);
                     // Check - decorator or not
                     if (!$reflection->isAbstract()) {
                         $class = $preclass;
                         break;
                     }
                 }
             }
         }
         if ($class) {
             static::$cacheControllers[$zone . '.' . $target] = $class;
             static::getSystemCacheDriver()->save('controllers', static::$cacheControllers);
         }
     }
     return $class;
 }