Esempio n. 1
0
 /**
  * Page 404
  * 
  * @return string|boolean
  */
 public function __invoke()
 {
     $language = LocalizationService::getCurrentLocalization()['language'];
     $page404 = false;
     // get a custom 404 page's url
     if (true === DisableSiteUtility::isAllowedViewSite() && false !== ($page404 = $this->getView()->pageUrl(self::CUSTOM_404_PAGE, [], $language, true))) {
         $userRole = UserIdentityService::getCurrentUserIdentity()['role'];
         if (false == ($pageInfo = $this->getModel()->getActivePageInfo(self::CUSTOM_404_PAGE, $userRole, $language))) {
             return false;
         }
         // fire the page show event
         PageEvent::firePageShowEvent($pageInfo['slug'], $language);
         // check for redirect
         if ($pageInfo['redirect_url']) {
             $response = ServiceLocatorService::getServiceLocator()->get('Response');
             $response->getHeaders()->addHeaderLine('Location', $pageInfo['redirect_url']);
             $response->setStatusCode(Response::STATUS_CODE_301);
             $response->sendHeaders();
             return false;
         }
         // get the page's breadcrumb
         $breadcrumb = $this->getModel()->getActivePageParents($pageInfo['left_key'], $pageInfo['right_key'], $userRole, $language);
         return $this->getView()->partial($this->getModel()->getLayoutPath() . $pageInfo['layout'], ['page' => $pageInfo, 'breadcrumb' => $breadcrumb]);
     }
     return $page404;
 }
 /**
  * Get service locator
  *
  * @return \Zend\ServiceManager\ServiceManager
  */
 protected function getServiceLocator()
 {
     if (!$this->serviceLocator) {
         $this->serviceLocator = ApplicationServiceLocatorService::getServiceLocator();
     }
     return $this->serviceLocator;
 }
 /**
  * Get route match
  *
  * @return object
  */
 protected static function getRouteMatch()
 {
     if (!self::$routeMatch) {
         self::$routeMatch = ServiceLocatorService::getServiceLocator()->get('Application')->getMvcEvent()->getRouteMatch();
     }
     return self::$routeMatch;
 }
 /**
  * Get model
  *
  * @return \User\Model\UserWidget
  */
 protected function getModel()
 {
     if (!$this->model) {
         $this->model = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('User\\Model\\UserWidget');
     }
     return $this->model;
 }
Esempio n. 5
0
 /**
  * Get widget layouts
  *
  * @return array
  */
 public static function getWidgetLayouts()
 {
     if (null === self::$widgetLayouts) {
         self::$widgetLayouts = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Page\\Model\\PageWidgetSetting')->getWidgetLayouts();
     }
     return self::$widgetLayouts;
 }
Esempio n. 6
0
 /**
  * Get all news categories
  *
  * @return array
  */
 public static function getAllNewsCategories()
 {
     if (null === self::$newsCategories) {
         self::$newsCategories = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('News\\Model\\NewsBase')->getAllCategories();
     }
     return self::$newsCategories;
 }
Esempio n. 7
0
 /**
  * Clear user cache
  *
  * @return boolean
  */
 public static function clearUserCache()
 {
     try {
         return ServiceLocatorService::getServiceLocator()->get('Application\\Cache\\Static')->clearByTags([UserBaseModel::CACHE_USER_DATA_TAG]);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
     return false;
 }
Esempio n. 8
0
 /**
  * Clear localization cache
  *
  * @return boolean
  */
 public static function clearLocalizationCache()
 {
     try {
         return ServiceLocatorService::getServiceLocator()->get('Application\\Cache\\Static')->clearByTags([LocalizationBaseModel::CACHE_LOCALIZATIONS_DATA_TAG]);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
     return false;
 }
Esempio n. 9
0
 /**
  * Get all questions
  *
  * @return array
  */
 public static function getAllQuestions()
 {
     if (null === self::$questions) {
         $questions = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Poll\\Model\\PollBase')->getAllQuestions(LocalizationService::getCurrentLocalization()['language']);
         // process questions
         self::$questions = [];
         foreach ($questions as $question) {
             self::$questions[$question->id] = $question->question;
         }
     }
     return self::$questions;
 }
 /**
  * Get all categories
  *
  * @return array
  */
 public static function getAllCategories()
 {
     if (null === self::$categories) {
         $categories = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('MiniPhotoGallery\\Model\\MiniPhotoGalleryBase')->getAllCategories(LocalizationService::getCurrentLocalization()['language']);
         // process categories
         self::$categories = [];
         foreach ($categories as $category) {
             self::$categories[$category->id] = $category->name;
         }
     }
     return self::$categories;
 }
Esempio n. 11
0
 /**
  * Login user
  *
  * @param integer $userId
  * @param string $nickName
  * @param boolean $rememberMe
  * @return void
  */
 public static function loginUser($userId, $nickName, $rememberMe)
 {
     $user = [];
     $user['user_id'] = $userId;
     // save user id
     UserIdentityService::getAuthService()->getStorage()->write($user);
     UserIdentityService::setCurrentUserIdentity(UserIdentityService::getUserInfo($userId));
     AclService::clearCurrentAcl();
     // fire the user login event
     UserEvent::fireLoginEvent($userId, $nickName);
     if ($rememberMe) {
         ServiceLocatorService::getServiceLocator()->get('Zend\\Session\\SessionManager')->rememberMe((int) SettingService::getSetting('user_session_time'));
     }
 }
 /**
  * Log an error
  *
  * @param string $errorMessage
  * @return boolean
  */
 public static function log($errorMessage)
 {
     try {
         $writer = new LogWriterStream(ServiceLocatorService::getServiceLocator()->get('Config')['paths']['error_log']);
         $logger = new Logger();
         $logger->addWriter($writer);
         $logger->err($errorMessage);
         // do we need send this error via email?
         if (null != ($errorEmail = SettingService::getSetting('application_errors_notification_email'))) {
             ApplicationEmailNotification::sendNotification($errorEmail, SettingService::getSetting('application_error_notification_title', LocalizationService::getDefaultLocalization()['language']), SettingService::getSetting('application_error_notification_message', LocalizationService::getDefaultLocalization()['language']), ['find' => ['ErrorDescription'], 'replace' => [$errorMessage]]);
         }
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
 /**
  * Send a notification
  *
  * @param string $email
  * @param string $title
  * @param string $message
  * @param array $replacements
  *      array find
  *      array replace
  * @param boolean $highPriority
  * @param string $replaceLeftDivider
  * @param string $replaceRightDivider
  * @return boolean
  */
 public static function sendNotification($email, $title, $message, array $replacements = [], $highPriority = false, $replaceLeftDivider = '__', $replaceRightDivider = '__')
 {
     // replace special markers
     if (isset($replacements['find'], $replacements['replace'])) {
         // process replacements
         $replacements['find'] = array_map(function ($value) use($replaceLeftDivider, $replaceRightDivider) {
             return $replaceLeftDivider . $value . $replaceRightDivider;
         }, $replacements['find']);
         $message = str_replace($replacements['find'], $replacements['replace'], $message);
     }
     // immediately send notification
     if ($highPriority) {
         if (true === ($result = self::immediatelySendNotification($email, $title, $message))) {
             return true;
         }
         return false;
     }
     // add message in a queue
     $model = ApplicationServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Application\\Model\\ApplicationEmailQueue');
     if (true !== ($result = $model->createMessage($email, $title, $message))) {
         return false;
     }
     return true;
 }
Esempio n. 14
0
 /**
  * Get setting
  *
  * @param string $settingName
  * @param string $language
  * @return string|boolean
  */
 public static function getSetting($settingName, $language = null)
 {
     $settingsModel = ApplicationServiceLocator::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Application\\Model\\ApplicationSetting');
     return $settingsModel->getSetting($settingName, $language ? $language : LocalizationService::getCurrentLocalization()['language']);
 }
Esempio n. 15
0
 /**
  * Get model
  * 
  * @return \Payment\Model\PaymentBase
  */
 protected static function getModel()
 {
     if (!self::$model) {
         self::$model = ServiceLocator::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Payment\\Model\\PaymentBase');
     }
     return self::$model;
 }
Esempio n. 16
0
 /**
  * Class constructor
  *
  * @param array $menu
  */
 public function __construct(array $widgets = [])
 {
     $this->widgets = $widgets;
     $this->dynamicCache = ServiceLocatorService::getServiceLocator()->get('Application\\Cache\\Dynamic');
     $this->request = ServiceLocatorService::getServiceLocator()->get('Request');
 }
Esempio n. 17
0
 /**
  * Clear dynamic cache
  *
  * @return boolean
  */
 public static function clearDynamicCache()
 {
     if (null == ($dynamicCache = ApplicationSettingService::getSetting('application_dynamic_cache'))) {
         return true;
     }
     try {
         return ServiceLocatorService::getServiceLocator()->get('Application\\Cache\\Dynamic')->flush();
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
     return false;
 }
Esempio n. 18
0
 /**
  * Get layout cache dir
  *
  * @param string $type
  * @return string
  */
 public static function getLayoutCacheDir($type = 'css')
 {
     return $type == 'css' ? ServiceLocatorService::getServiceLocator()->get('Config')['paths']['layout_cache_css'] : ServiceLocatorService::getServiceLocator()->get('Config')['paths']['layout_cache_js'];
 }
 /**
  * Add  module translations
  *
  * @var array $moduleConfig
  * @return void
  */
 public function addModuleTranslations(array $moduleConfig)
 {
     $translator = ServiceLocatorService::getServiceLocator()->get('translator');
     $translationPattern = !empty($moduleConfig['translator']['translation_file_patterns']) ? $moduleConfig['translator']['translation_file_patterns'] : null;
     if ($translationPattern) {
         foreach ($translationPattern as $pattern) {
             $translator->addTranslationFilePattern($pattern['type'], $pattern['base_dir'], $pattern['pattern'], $pattern['text_domain']);
         }
     }
     ApplicationCacheUtility::clearDynamicCache();
 }
Esempio n. 20
0
 /**
  * Class constructor
  *
  * @param \Zend\Db\Adapter\AdapterInterface $adapter
  * @param \Zend\Cache\Storage\StorageInterface $staticCacheInstance
  */
 public function __construct(AdapterInterface $adapter, StorageInterface $staticCacheInstance)
 {
     parent::__construct($adapter);
     $this->serviceLocator = ServiceLocatorService::getServiceLocator();
     $this->staticCacheInstance = $staticCacheInstance;
 }
Esempio n. 21
0
 /**
  * Get pages
  *
  * @return array
  */
 protected function getPages()
 {
     $pages = [];
     if ($this->pageParent) {
         if (false !== ($childrenPages = $this->model->getAllPageStructureChildren($this->pageParent['id'], true))) {
             $activePageId = null;
             $currentDefined = false;
             foreach ($childrenPages as $children) {
                 // don't draw current page
                 if (!empty($this->pageInfo) && $this->pageInfo['id'] == $children['id']) {
                     $currentDefined = true;
                     continue;
                 }
                 $pageOptions = ['title' => $children['title'], 'system_title' => $children['system_title'], 'type' => $children['type']];
                 if (!$currentDefined) {
                     $activePageId = $children['id'];
                 } else {
                     if ($currentDefined && !$activePageId) {
                         $activePageId = $children['id'];
                         $this->formElements['page_direction']['value'] = 'before';
                     }
                 }
                 $pages[$children['id']] = ServiceLocatorService::getServiceLocator()->get('viewHelperManager')->get('pageTitle')->__invoke($pageOptions);
             }
             // set default value
             if ($activePageId) {
                 $this->formElements['page']['value'] = $activePageId;
             }
         }
     }
     return $pages;
 }
Esempio n. 22
0
 /**
  * Init acl
  *
  * @param array $currentUserIdentity
  * @return void
  */
 protected static function initAcl(array $currentUserIdentity)
 {
     // create a new ACL role
     $acl = new AclZend();
     $acl->addRole(new Role($currentUserIdentity['role']));
     $aclModel = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Acl\\Model\\AclBase');
     // get assigned acl resources
     if (null != ($resources = $aclModel->getAclResources($currentUserIdentity['role'], $currentUserIdentity['user_id']))) {
         // process acl resources
         $resourcesInfo = [];
         foreach ($resources as $resource) {
             // add a new resource
             $acl->addResource(new Resource($resource['resource']));
             // add the resource's permission
             $resource['permission'] == AclBaseModel::ACTION_ALLOWED ? $acl->allow($currentUserIdentity['role'], $resource['resource']) : $acl->deny($currentUserIdentity['role'], $resource['resource']);
             $resourcesInfo[$resource['resource']] = $resource;
         }
         self::$currentAclResources = $resourcesInfo;
     }
     self::$currentAcl = $acl;
 }
Esempio n. 23
0
 /**
  * Fire edit role event
  *
  * @param array $user
  *      string language
  *      string email
  *      string nick_name
  *      integer user_id
  * @param string $roleName
  * @param boolean $isSystemEvent
  * @retun void
  */
 public static function fireEditRoleEvent($user, $roleName, $isSystemEvent = false)
 {
     // event's description
     $eventDesc = $isSystemEvent ? 'Event - User\'s role edited by the system' : (UserIdentityService::isGuest() ? 'Event - User\'s role edited by guest' : 'Event - User\'s role edited by user');
     $eventDescParams = $isSystemEvent ? [$user['user_id']] : (UserIdentityService::isGuest() ? [$user['user_id']] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $user['user_id']]);
     self::fireEvent(self::EDIT_ROLE, $user['user_id'], self::getUserId($isSystemEvent), $eventDesc, $eventDescParams);
     // send a notification
     if ((int) SettingService::getSetting('user_role_edited_send')) {
         $notificationLanguage = $user['language'] ? $user['language'] : LocalizationService::getDefaultLocalization()['language'];
         EmailNotificationUtility::sendNotification($user['email'], SettingService::getSetting('user_role_edited_title', $notificationLanguage), SettingService::getSetting('user_role_edited_message', $notificationLanguage), ['find' => ['RealName', 'Role'], 'replace' => [$user['nick_name'], ServiceLocatorService::getServiceLocator()->get('Translator')->translate($roleName, 'default', LocalizationService::getLocalizations()[$notificationLanguage]['locale'])]]);
     }
 }
 /**
  * Clean expired memberships connections
  */
 public function cleanExpiredMembershipsConnectionsAction()
 {
     $request = $this->getRequest();
     $deletedConnections = 0;
     $notifiedConnections = 0;
     // get a list of expired memberships connections
     if (null != ($expiredConnections = $this->getModel()->getExpiredMembershipsConnections(self::ITEMS_LIMIT))) {
         // process expired memberships connections
         foreach ($expiredConnections as $connectionInfo) {
             // delete the connection
             if (false === ($deleteResult = $this->getModel()->deleteMembershipConnection($connectionInfo['id']))) {
                 break;
             }
             // get a next membership connection
             $nextConnection = $this->getModel()->getMembershipConnectionFromQueue($connectionInfo['user_id']);
             $nextRoleId = $nextConnection ? $nextConnection['role_id'] : AclBaseModel::DEFAULT_ROLE_MEMBER;
             $nextRoleName = $nextConnection ? $nextConnection['role_name'] : AclBaseModel::DEFAULT_ROLE_MEMBER_NAME;
             // change the user's role
             if (true === ($result = $this->getUserModel()->editUserRole($connectionInfo['user_id'], $nextRoleId, $nextRoleName, $connectionInfo, true))) {
                 // activate the next membership connection
                 if ($nextConnection) {
                     $this->getModel()->activateMembershipConnection($nextConnection['id']);
                 }
             }
             $deletedConnections++;
         }
     }
     // get list of not notified memberships connections
     if ((int) $this->applicationSetting('membership_expiring_send')) {
         if (null != ($notNotifiedConnections = $this->getModel()->getNotNotifiedMembershipsConnections(self::ITEMS_LIMIT))) {
             // process not notified memberships connections
             foreach ($notNotifiedConnections as $connectionInfo) {
                 if (false === ($markResult = $this->getModel()->markConnectionAsNotified($connectionInfo['id']))) {
                     break;
                 }
                 // send a notification about membership expiring
                 $notificationLanguage = $connectionInfo['language'] ? $connectionInfo['language'] : LocalizationService::getDefaultLocalization()['language'];
                 $locale = LocalizationService::getLocalizations()[$notificationLanguage]['locale'];
                 ApplicationEmailNotification::sendNotification($connectionInfo['email'], $this->applicationSetting('membership_expiring_send_title', $notificationLanguage), $this->applicationSetting('membership_expiring_send_message', $notificationLanguage), ['find' => ['RealName', 'Role', 'ExpireDate'], 'replace' => [$connectionInfo['nick_name'], ApplicationServiceLocatorService::getServiceLocator()->get('Translator')->translate($connectionInfo['role_name'], 'default', $locale), ApplicationServiceLocatorService::getServiceLocator()->get('viewhelpermanager')->get('applicationDate')->__invoke($connectionInfo['expire_date'], [], $locale)]]);
                 $notifiedConnections++;
             }
         }
     }
     // delete not active empty connections
     $this->getModel()->deleteNotActiveEmptyConnections();
     $verbose = $request->getParam('verbose');
     if (!$verbose) {
         return 'All expired  membership connections have been deleted.' . "\n";
     }
     $result = $deletedConnections . ' membership connections  have been deleted.' . "\n";
     $result .= $notifiedConnections . ' membership connections  have been notified.' . "\n";
     return $result;
 }
Esempio n. 25
0
 /**
  * Save layout
  *
  * @param integer $layoutId
  * @return void
  */
 public static function saveLayout($layoutId)
 {
     $header = new SetCookie();
     $header->setName(LayoutModule::LAYOUT_COOKIE)->setValue($layoutId)->setPath('/')->setExpires(time() + (int) SettingService::getSetting('layout_select_cookie_time'));
     ServiceLocatorService::getServiceLocator()->get('Response')->getHeaders()->addHeader($header);
 }
 /**
  * Get service locator
  *
  * @return \Zend\ServiceManager\ServiceManager
  */
 protected function getServiceLocator()
 {
     return ApplicationServiceLocator::getServiceLocator();
 }
Esempio n. 27
0
 /**
  * Get user info
  *
  * @param integer $userId
  * @param string $field
  * @return array
  */
 public static function getUserInfo($userId, $field = null)
 {
     return ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('User\\Model\\UserBase')->getUserInfo($userId, $field);
 }
Esempio n. 28
0
 /**
  * Get model
  *
  * @return \Poll\Model\PollWidget
  */
 protected function getModel()
 {
     if (!$this->model) {
         $this->model = ApplicationServiceLocator::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Poll\\Model\\PollWidget');
     }
     return $this->model;
 }
 /**
  * Class constructor
  */
 public function __construct()
 {
     $this->serviceLocator = ApplicationServiceLocatorService::getServiceLocator();
 }
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get the form builder
     if (!$this->form) {
         // add extra settings for "cost" field
         if ($this->tariffs) {
             $this->formElements['cost']['values'] = $this->tariffs;
         } else {
             unset($this->formElements['cost']);
         }
         // add extra validators for "count" field
         if (!$this->hideCountField) {
             if ($this->countLimit) {
                 $this->formElements['count']['description'] = 'Max items count description';
                 $this->formElements['count']['description_params'] = [$this->countLimit];
             }
             $this->formElements['count']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateItemCount'], 'message' => 'Value should be greater than 0']], ['name' => 'callback', 'options' => ['callback' => [$this, 'validateItemMaxCount'], 'message' => sprintf($this->translator->translate('Item count must be less or equal %d'), $this->countLimit)]]];
         } else {
             unset($this->formElements['count']);
         }
         // add extra settings for "discount" field
         if ($this->discount) {
             $this->formElements['discount']['description_params'] = [ServiceLocatorService::getServiceLocator()->get('viewHelperManager')->get('paymentProcessCost')->__invoke($this->discount)];
         } else {
             unset($this->formElements['discount']);
         }
         $formElements = $this->formElements;
         // add extra form elements
         if ($this->extraFormElements) {
             $formElements = array_merge($formElements, $this->extraFormElements);
         }
         $this->form = new ApplicationCustomFormBuilder($this->formName, $formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }