Example #1
0
 /**
  * Forgery constructor
  */
 public function __forge()
 {
     $this->setGetSetTargetArray($this->config);
     $this->config = array_merge($this->config, (array) \Magelight\Config::getInstance()->getConfig('global/document/captcha', []));
     $this->font_file = \Magelight\App::getInstance()->getRealPathInModules($this->font_file);
     $this->cleanup();
 }
Example #2
0
 /**
  * Get login form
  *
  * @return \Magelight\Webform\Blocks\Form
  */
 public function getLoginForm()
 {
     $form = Form::forge()->setHorizontal()->setConfigs('remindpass-form', $this->url(\Magelight\Config::getInstance()->getConfigString('global/auth/urls/login_url')));
     $fieldset = Fieldset::forge();
     $fieldset->addRowField(Elements\Input::forge()->setName('email'), __('E-Mail'));
     $fieldset->addRowField(Elements\PasswordInput::forge()->setName('password'), __('Password'));
     return $form->addFieldset($fieldset)->createResultRow(true)->addButtonsRow([Elements\Button::forge()->setContent(__('Enter'))->addClass('btn-primary'), Elements\Abstraction\Element::forge()->setTag('a')->setAttribute('href', $this->url('auth/remindpass'))->setContent(__('Remind password'))->setClass('btn')])->loadFromRequest(\Magelight\Http\Request::getInstance())->setValidator($this->getLoginFormValidator());
 }
Example #3
0
 /**
  * Get for for password recovery page
  *
  * @return \Magelight\Webform\Blocks\Form
  */
 public function getForgotPasswordForm()
 {
     $form = Form::forge()->setHorizontal()->setConfigs('remindpass-form', $this->url(\Magelight\Config::getInstance()->getConfigString('global/auth/urls/forgot_password_url')));
     $fieldset = Fieldset::forge();
     $fieldset->addRowField(Elements\Input::forge()->setName('email'), __('E-Mail', [], 1, 'default'));
     $validator = \Magelight\Webform\Models\Validator::forge();
     $validator->fieldRules('email')->required()->setCustomError(__("Please enter a valid e-mail!", 1))->chainRule()->email()->setCustomError(__("Please enter a valid e-mail!", 1));
     return $form->addFieldset($fieldset)->createResultRow(true)->addButtonsRow([Elements\Button::forge()->setContent(__('Send new password'))->addClass('btn-primary')])->loadFromRequest()->setValidator($validator)->validateOnFront();
 }
Example #4
0
 /**
  * Get sample form
  *
  * @return Form
  */
 public function getSampleForm()
 {
     $form = Form::forge()->setHorizontal()->setConfigs('sample', $this->url('sample/form'));
     $fieldset = Fieldset::forge();
     $fieldset->setLegend('Register new user');
     $fieldset->addRowField(Elements\Input::forge()->setName('name'), __('Name'));
     $fieldset->addRowField(Elements\Input::forge()->setName('email'), __('E-Mail'));
     $fieldset->addRowField(Elements\PasswordInput::forge()->setName('password'), __('Password'));
     $fieldset->addRowField(Elements\Captcha::forge($this->url(\Magelight\Config::getInstance()->getConfigString('global/auth/urls/render_captcha_url')))->setName('captcha')->addClass('col-md-6'), __('Enter protection code'));
     return $form->addFieldset($fieldset)->createResultRow(true)->addButtonsRow(Elements\Button::forge()->setContent(__('Register'))->addClass('btn-primary'))->loadFromRequest()->setValidator($this->getSampleFormValidator())->validateOnFront();
 }
Example #5
0
 /**
  * Get url by match
  * 
  * @param string $match
  * @param array  $params
  * @param string $type
  * @param bool $addOnlyMaskParams - add to url only params that are present in URL match mask
  *
  * @return string
  * @throws \Magelight\Exception
  */
 public function getUrl($match, $params = [], $type = null, $addOnlyMaskParams = false)
 {
     if (!$type) {
         $type = \Magelight\Config::getInstance()->getConfigString('global/app/default_url_type', self::TYPE_HTTP);
     }
     $match = '/' . trim($match, '\\/');
     if (!$addOnlyMaskParams) {
         if (\Magelight\App::getInstance()->isInDeveloperMode() && !$this->checkParamsWithPlaceholderMask($match, $params)) {
             throw new \Magelight\Exception("Passed url params don`t match mask that is set for parameter or default mask: " . \Magelight\Components\Loaders\Routes::DEFAULT_REGEX . ". Change the mask for parameter or use concatenation for complex URLs", E_USER_NOTICE);
         }
     }
     $params = $this->flatternParams($params);
     return $this->getBaseUrl($type) . $this->makeRequestUri($match, $params, $addOnlyMaskParams);
 }
Example #6
0
 /**
  * Forgery constructor
  *
  * @param \SimpleXMLElement $config
  * @throws \Magelight\Exception
  */
 public function __forge($config)
 {
     $this->config = $config;
     if (isset($config->cache_key_prefix)) {
         $this->cacheKeyPrefix = (string) $config->cache_key_prefix;
     } else {
         $this->cacheKeyPrefix = (string) \Magelight\Config::getInstance()->getConfig('global/base_domain');
         if (!$this->cacheKeyPrefix) {
             $this->cacheKeyPrefix = md5(\Magelight\App::getInstance()->getAppDir());
             if (!$this->cacheKeyPrefix) {
                 throw new \Magelight\Exception('Cache key prefix not set, and base domain too. Cache conflicts can appear.');
             }
         }
     }
     $this->init();
 }
Example #7
0
 /**
  * Dispatch application event (executes all observers that were bound to this event)
  *
  * @param string $eventName
  * @param array $arguments
  * @throws \Magelight\Exception
  */
 public function dispatchEvent($eventName, $arguments = [])
 {
     $observers = (array) \Magelight\Config::getInstance()->getConfigSet('global/events/' . $eventName . '/observer');
     if (!empty($observers)) {
         foreach ($observers as $observerClass) {
             $observerClass = explode('::', (string) $observerClass);
             $class = $observerClass[0];
             $method = isset($observerClass[1]) ? $observerClass[1] : 'execute';
             $observer = call_user_func_array([$class, 'forge'], [$arguments]);
             /* @var $observer \Magelight\Observer*/
             if (!method_exists($observer, $method)) {
                 throw new \Magelight\Exception("Observer '{$class}' method '{$method}' does not exist or is not callable!");
             }
             $observer->{$method}();
         }
     }
 }
Example #8
0
 /**
  * Run app
  *
  * @throws \Exception|Exception
  */
 public function run()
 {
     try {
         \Magelight\Event\Manager::getInstance()->dispatchEvent('app_start', []);
         $request = \Magelight\Http\Request::getInstance();
         $resource = $request->getGet('resource');
         $staticDir = realpath($this->getAppDir() . DS . \Magelight\Config::getInstance()->getConfigString('global/view/published_static_dir', 'pub/static'));
         foreach (array_reverse($this->getModuleDirectories()) as $modulesPath) {
             $resource = str_replace('\\/', DS, $resource);
             $filename = $modulesPath . DS . $resource;
             $targetFilename = $staticDir . DS . $resource;
             if (file_exists($filename)) {
                 if (!is_dir(dirname($targetFilename))) {
                     mkdir(dirname($targetFilename), 0777, true);
                 }
                 if (\Magelight\Config::getInstance()->getConfigBool('global/app/developer_mode', false)) {
                     $pathinfo = pathinfo($filename, PATHINFO_EXTENSION);
                     if (isset($this->mimeTypes[$pathinfo])) {
                         $mimeType = $this->mimeTypes[$pathinfo];
                         header('Content-type: ' . $mimeType);
                     }
                     echo file_get_contents($filename);
                     break;
                 }
                 copy($filename, $targetFilename);
                 header('Location: ' . \Magelight\Helpers\UrlHelper::getInstance()->getUrl($resource));
                 break;
             }
         }
     } catch (\Exception $e) {
         \Magelight\Log::getInstance()->add($e->getMessage());
         if ($this->developerMode) {
             throw $e;
         }
     }
 }
Example #9
0
 /**
  * Flush all application caches
  *
  * @return App
  */
 public function flushAllCache()
 {
     $config = \Magelight\Config::getInstance()->getConfig('global/cache');
     foreach ($config->children() as $index => $cache) {
         $adapters[] = \Magelight\Cache\AdapterPool::getInstance()->getAdapter($index)->clear();
     }
     return $this;
 }
Example #10
0
 /**
  * Get Ulogin JS url
  *
  * @return string
  */
 public function getUloginScriptUrl()
 {
     return (string) \Magelight\Config::getInstance()->getConfig('global/auth/ulogin/ulogin_script_url');
 }
Example #11
0
 /**
  * Initialize application logger
  */
 protected function init()
 {
     $this->file = (string) \Magelight\Config::getInstance()->getConfig('global/log/file', self::DEFAUL_LOG_FILE);
     $this->initialized = true;
     return $this;
 }
Example #12
0
 /**
  * Load block layout from config node
  *
  * @param string $layoutIndex - path to perspective in config
  * @return Block
  */
 public function loadLayout($layoutIndex = 'global/layouts/default')
 {
     return $this->processLayout(\Magelight\Config::getInstance()->getConfig($layoutIndex));
 }
Example #13
0
 /**
  * Get adapter by index
  *
  * @param string $index
  * @return \Magelight\Cache\AdapterAbstract
  */
 public function getAdapter($index = \Magelight\App::DEFAULT_INDEX)
 {
     $config = \Magelight\Config::getInstance()->getConfig('global/cache/' . $index);
     $type = $this->getAdapterClassByType((bool) $config->disabled ? 'dummy' : $config->type);
     return call_user_func_array([$type, 'getInstance'], [$config->config]);
 }
Example #14
0
 /**
  * Before To HTML
  *
  * @return \Magelight\Block|void
  */
 public function beforeToHtml()
 {
     $lang = \Magelight\Config::getInstance()->getConfigString('global/document/default_lang');
     $this->setLang($lang);
     $this->head->addContent($this->renderTitle());
     $this->head->addContent($this->renderMeta());
     $this->head->addContent($this->renderCss());
     $this->head->addContent($this->renderJs());
     $this->body->addContent($this->section('body'));
     return $this;
 }
Example #15
0
 /**
  * Load items
  */
 protected function loadItems()
 {
     $items = \Magelight\Config::getInstance()->getConfig('admin/navbar/items');
     $this->items = $this->getItemForgery()->forgeItems($items);
 }
Example #16
0
 /**
  * Get entities configuration
  *
  * @return mixed|\SimpleXMLElement
  */
 public function getEntitiesConfig()
 {
     if (empty($this->entitiesConfig)) {
         $entitiesConfig = clone \Magelight\Config::getInstance()->getConfig('admin/scaffold/entities');
         $this->defaultEntityConfig = clone $entitiesConfig->default;
         unset($entitiesConfig->default);
         foreach ($entitiesConfig->children() as $child) {
             /** @var $child \SimpleXMLElement */
             /** @var $draft \SimpleXMLElement */
             /** @var $fieldDraft \SimpleXMLElement */
             $draft = clone $this->defaultEntityConfig;
             \Magelight\Components\Loaders\Config::mergeConfig($draft, $child);
             \Magelight\Components\Loaders\Config::mergeConfig($entitiesConfig->{$child->getName()}, $draft);
             $defaultFieldConfig = clone $entitiesConfig->{$child->getName()}->fields->default;
             unset($entitiesConfig->{$child->getName()}->fields->default);
             foreach ($entitiesConfig->{$child->getName()}->fields->children() as $field) {
                 $fieldDraft = clone $defaultFieldConfig;
                 \Magelight\Components\Loaders\Config::mergeConfig($fieldDraft, $field);
                 \Magelight\Components\Loaders\Config::mergeConfig($entitiesConfig->{$child->getName()}->fields->{$field->getName()}, $fieldDraft);
             }
         }
         $this->entitiesConfig = $entitiesConfig;
     }
     return $this->entitiesConfig;
 }
Example #17
0
 /**
  * Logout action handler
  */
 public function logoutAction()
 {
     $this->session()->unsetData('user_id');
     $this->redirect($this->url(\Magelight\Config::getInstance()->getConfig('global/auth/urls/success_url')));
 }
Example #18
0
 /**
  * Minify document static entry
  *
  * @param string $type
  * @param array $staticEntries
  * @return array
  * @throws \Magelight\Exception
  */
 protected function minifyDocumentStatic($type = 'css', $staticEntries = [])
 {
     $minifier = $this->getMinifierByType($type);
     $content = '';
     $path = $this->getEntriesStaticPath($staticEntries, $type);
     $dir = dirname($path);
     if (!is_writable($dir)) {
         trigger_error(__("Static cache directory %s is not writable or does not exist!", [$dir]));
         return $staticEntries;
     }
     if ($isAlreadyMinified = $this->cache()->get($this->buildCacheKey($path), false)) {
         $ok = true;
         if (\Magelight\Config::getInstance()->getConfigBool('global/minifier/check_readability')) {
             $ok = is_readable($path);
         }
         if ($ok) {
             return ['path' => $path, 'content' => '', 'url' => \Magelight\Helpers\UrlHelper::getInstance()->getUrl($path), 'inline' => false];
         }
     }
     foreach ($staticEntries as $entry) {
         if ($entry['inline']) {
             $content .= $minifier->minify($entry['content']);
         } else {
             $buffer = file_get_contents(\Magelight\App::getInstance()->getRealPathInModules($entry['path']));
             if ($buffer === false) {
                 trigger_error(__("File %s for minifier cannot be read", [$entry['path']]), E_USER_WARNING);
             }
             if (\Magelight\Config::getInstance()->getConfigBool('global/minifier/compress_' . $type)) {
                 $buffer = $minifier->minify($buffer);
             }
             switch ($type) {
                 case 'css':
                     $content .= $this->fixCssUrls($buffer, $entry['path']);
                     break;
                 case 'js':
                     $content .= $buffer;
                     break;
                 default:
                     break;
             }
             unset($buffer);
         }
     }
     if (file_put_contents($path, $content)) {
         $this->cache()->set($this->buildCacheKey($path), 1, \Magelight\Config::getInstance()->getConfigInt('global/minifier/cache_ttl_' . $type));
         return ['path' => $path, 'content' => '', 'url' => \Magelight\Helpers\UrlHelper::getInstance()->getUrl($path), 'inline' => false];
     } else {
         return $staticEntries;
     }
 }
Example #19
0
 /**
  * Forgery constructor
  */
 public function __forge()
 {
     $this->setPrivateKey((string) \Magelight\Config::getInstance()->getConfigString('global/document/re_captcha/private_key'));
     $this->setPublicKey((string) \Magelight\Config::getInstance()->getConfigString('global/document/re_captcha/public_key'));
 }