/**
  * Get form instance
  *
  * @return object
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // add extra options for the title
         $this->formElements['title']['description_params'] = [$this->widgetDescription];
         // add extra options for the cache ttl
         if ($this->showCacheSettings) {
             $this->formElements['cache_ttl']['description_params'] = [(int) SettingService::getSetting('application_dynamic_cache_life_time')];
             // add extra validators
             $this->formElements['cache_ttl']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateCacheTtl'], 'message' => 'Enter a correct value']]];
         } else {
             unset($this->formElements['cache_ttl']);
         }
         // add extra options for the visibility settings
         if ($this->showVisibilitySettings) {
             // add visibility settings
             $this->formElements['visibility_settings']['values'] = AclService::getAclRoles(false, true);
         } else {
             unset($this->formElements['visibility_settings']);
         }
         // fill the form with default values
         $this->formElements['layout']['values'] = $this->model->getWidgetLayouts();
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
 /**
  * Is allowed view page
  * 
  * @param array $privacyOptions
  * @param boolean $trustedData
  * @return boolean
  */
 public function isAllowedViewPage(array $privacyOptions = [], $trustedData = false)
 {
     // check a permission
     if (UserIdentityService::isDefaultUser() || !AclService::checkPermission('memberships_view_buy_page', false)) {
         return false;
     }
     return true;
 }
 /**
  * Is allowed view page
  * 
  * @param array $privacyOptions
  * @param boolean $trustedData
  * @return boolean
  */
 public function isAllowedViewPage(array $privacyOptions = [], $trustedData = false)
 {
     // check a permission
     if (!AclService::checkPermission('news_view_news', false)) {
         return false;
     }
     return true;
 }
 /**
  * Get list of localizations
  *
  * @throws XmlRpc\Exception\XmlRpcActionDenied
  * @return array
  */
 public function getLocalizations()
 {
     // check user permission
     if (!AclService::checkPermission('xmlrpc_get_localizations')) {
         throw new XmlRpcActionDenied(self::REQUEST_DENIED);
     }
     // fire the get localizations via XmlRpc event
     LocalizationEvent::fireGetLocalizationsViaXmlRpcEvent();
     return LocalizationService::getLocalizations();
 }
Beispiel #5
0
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // fill the form with default values
         $this->formElements['role']['values'] = AclService::getAclRoles();
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
 /**
  * Check current user's permission.
  *
  * @param string $resource
  * @param boolean $increaseActions
  * @param boolean $showAccessDenied
  * @return boolean
  */
 public function __invoke($resource = null, $increaseActions = true, $showAccessDenied = true)
 {
     // get an ACL resource name
     $resource = !$resource ? $this->getController()->params('controller') . ' ' . $this->getController()->params('action') : $resource;
     // check the permission
     if (false === ($result = AclService::checkPermission($resource, $increaseActions)) && $showAccessDenied) {
         // redirect to access a forbidden page
         $this->getController()->showErrorPage();
     }
     return $result;
 }
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     if (AclService::checkPermission('slideshow_view', false) && null != ($category = $this->getWidgetSetting('slideshow_category'))) {
         $images = $this->getModel()->getImages($category);
         if (count($images)) {
             AclService::checkPermission('slideshow_view', true);
             return $this->getView()->partial('slideshow/widget/slideshow', ['enable_slideshow' => (int) $this->getWidgetSetting('slideshow_on'), 'images_width' => (int) $this->getWidgetSetting('slideshow_image_width'), 'images_height' => (int) $this->getWidgetSetting('slideshow_image_height'), 'images' => $images]);
         }
     }
     return false;
 }
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     // check a permission
     if (AclService::checkPermission('news_view_news', false) && false !== $this->getView()->pageUrl('news', [], null, true)) {
         // get widget settings
         $this->newsCategories = $this->getWidgetSetting('news_categories_last_news');
         $this->newsCount = (int) $this->getWidgetSetting('news_count_last_news');
         // select the widget mode
         return !$this->newsCount ? $this->paginationMode() : $this->simpleMode();
     }
     return false;
 }
Beispiel #9
0
 /**
  * Get user info
  *
  * @param integer $userId
  * @return array
  */
 public function getUserInfo($userId)
 {
     // check user permissions
     if (!AclService::checkPermission('xmlrpc_view_user_info')) {
         throw new XmlRpcActionDenied(self::REQUEST_DENIED);
     }
     $viewerNickName = !UserIdentityService::isGuest() ? $this->userIdentity['nick_name'] : null;
     // get user info
     if (false !== ($userInfo = $this->getModel()->getXmlRpcUserInfo($userId, $this->userIdentity['user_id'], $viewerNickName))) {
         return $userInfo;
     }
     return [];
 }
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     if (AclService::checkPermission('comment_view', false)) {
         // get last comments
         $comments = $this->getModel()->getLastComments($this->getCurrentLanguage(), (int) $this->getWidgetSetting('comment_count'));
         if (count($comments)) {
             // increase ACL track
             AclService::checkPermission('comment_view');
             return $this->getView()->partial('comment/widget/last-comments-list', ['visible_chars' => (int) $this->getWidgetSetting('comment_visible_chars'), 'show_thumbs' => (int) $this->getWidgetSetting('comment_show_thumbs'), 'comments' => $comments]);
         }
     }
     return false;
 }
Beispiel #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'));
     }
 }
 /**
  * Index page
  */
 public function indexAction()
 {
     if (!UserIdentityService::isGuest()) {
         return $this->createHttpNotFoundModel($this->getResponse());
     }
     $this->layout($this->layout);
     $loginForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\UserLogin');
     if ($this->getRequest()->isPost()) {
         // fill form with received values
         $loginForm->getForm()->setData($this->getRequest()->getPost());
         if ($loginForm->getForm()->isValid()) {
             $userName = $this->getRequest()->getPost('nickname');
             $password = $this->getRequest()->getPost('password');
             // check an authentication
             $authErrors = [];
             $result = UserAuthenticateUtility::isAuthenticateDataValid($userName, $password, $authErrors);
             if (false === $result) {
                 $this->flashMessenger()->setNamespace('error');
                 // add auth error messages
                 foreach ($authErrors as $message) {
                     $this->flashMessenger()->addMessage($this->getTranslator()->translate($message));
                 }
                 return $this->reloadPage();
             }
             $rememberMe = null != ($remember = $this->getRequest()->getPost('remember')) ? true : false;
             // login a user
             UserAuthenticateUtility::loginUser($result['user_id'], $result['nick_name'], $rememberMe);
             // make a redirect
             if (null !== ($backUrl = $this->getRequest()->getQuery('back_url', null))) {
                 return $this->redirect()->toUrl($backUrl);
             }
             // search a first allowed admin page
             $adminMenu = $this->getAdminMenuModel()->getMenu();
             foreach ($adminMenu as $menuItems) {
                 foreach ($menuItems['items'] as $item) {
                     if (AclService::checkPermission($item['controller'] . ' ' . $item['action'], false)) {
                         return $this->redirectTo($item['controller'], $item['action']);
                     }
                 }
             }
             // redirect to the public home page
             $this->flashMessenger()->setNamespace('error');
             $this->flashMessenger()->addMessage($this->getTranslator()->translate('There are no admin pages allowed for you!'));
             return $this->redirectTo('page', 'index', [], false, [], 'page');
         }
     }
     return new ViewModel(['loginForm' => $loginForm->getForm()]);
 }
 /**
  * Is allowed view page
  * 
  * @param array $privacyOptions
  * @param boolean $trustedData
  * @return boolean
  */
 public function isAllowedViewPage(array $privacyOptions = [], $trustedData = false)
 {
     // check a permission
     if (!AclService::checkPermission('news_view_news', false)) {
         return false;
     }
     // get a news id from the route or params
     if (!$trustedData) {
         $newsId = $this->objectId ? $this->objectId : RouteParamUtility::getParam('slug', -1);
         // check an existing news
         if (null == ($newsInfo = $this->getModel()->getNewsInfo($newsId, true, false, 'slug', true))) {
             return false;
         }
     }
     return true;
 }
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     if (AclService::checkPermission('comment_view', false)) {
         // get the current user's info
         if (null != ($userInfo = UserIdentityService::getUserInfo($this->getSlug(), BaseModel::USER_INFO_BY_SLUG))) {
             // get last comments
             $comments = $this->getModel()->getLastComments($this->getCurrentLanguage(), (int) $this->getWidgetSetting('comment_count'), $userInfo['user_id']);
             if (count($comments)) {
                 // increase ACL track
                 AclService::checkPermission('comment_view');
                 return $this->getView()->partial('comment/widget/user-last-comments-list', ['visible_chars' => $this->getWidgetSetting('comment_visible_chars'), 'comments' => $comments]);
             }
         }
     }
     return false;
 }
 /**
  * Set event manager
  *
  * @param \Zend\EventManager\EventManagerInterface $events
  * @return void
  */
 public function setEventManager(EventManagerInterface $events)
 {
     parent::setEventManager($events);
     $controller = $this;
     // execute before executing action logic
     $events->attach('dispatch', function ($e) use($controller) {
         // check permission
         if (!AclService::checkPermission($controller->params('controller') . ' ' . $controller->params('action'), false)) {
             return UserIdentityService::isGuest() ? $this->redirectTo('login-administration', 'index', [], false, ['back_url' => $this->getRequest()->getRequestUri()]) : $controller->showErrorPage();
         }
         // set an admin layout
         if (!$e->getRequest()->isXmlHttpRequest()) {
             $controller->layout($this->layout);
         }
     }, 100);
 }
Beispiel #16
0
 /**
  * Is allowed view page
  * 
  * @param array $privacyOptions
  * @param boolean $trusted
  * @return boolean
  */
 public function isAllowedViewPage(array $privacyOptions = [], $trustedData = false)
 {
     // check a permission
     if (!AclService::checkPermission('users_view_profile', false)) {
         return false;
     }
     if (!$trustedData) {
         $userId = !empty($privacyOptions['user_id']) || $this->objectId ? !empty($privacyOptions['user_id']) ? $privacyOptions['user_id'] : $this->objectId : RouteParamUtility::getParam('slug', -1);
         $userField = !empty($privacyOptions['user_id']) ? UserWidgetModel::USER_INFO_BY_ID : UserWidgetModel::USER_INFO_BY_SLUG;
         // check an existing user
         $userInfo = $this->getModel()->getUserInfo($userId, $userField);
         if (!$userInfo || $userInfo['status'] != UserWidgetModel::STATUS_APPROVED) {
             return false;
         }
     }
     return true;
 }
Beispiel #17
0
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     // check a permission
     if (AclService::checkPermission('users_view_profile')) {
         // get the current user's info
         if (null != ($userInfo = $this->getModel()->getUserInfo($this->getSlug(), UserWidgetModel::USER_INFO_BY_SLUG))) {
             $viewerNickName = !UserIdentityService::isGuest() ? UserIdentityService::getCurrentUserIdentity()['nick_name'] : null;
             // fire the get user's info event
             UserEvent::fireGetUserInfoEvent($userInfo['user_id'], $userInfo['nick_name'], UserIdentityService::getCurrentUserIdentity()['user_id'], $viewerNickName);
             // breadcrumb
             $this->getView()->pageBreadcrumb()->setCurrentPageTitle($userInfo['nick_name']);
             $this->getView()->headMeta()->setName('description', $userInfo['nick_name']);
             return $this->getView()->partial('user/widget/info', ['user' => $userInfo]);
         }
     }
     return false;
 }
Beispiel #18
0
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     $disableRating = !AclService::checkPermission('pages_use_rating') || $this->getModel()->isPageRated($this->pageId, $this->getPageSlug());
     // process actions
     if ($this->getRequest()->isPost() && ApplicationCsrf::isTokenValid($this->getRequest()->getPost('csrf'))) {
         if (false !== ($action = $this->getRequest()->getPost('widget_action', false)) && $this->getRequest()->isXmlHttpRequest()) {
             switch ($action) {
                 case 'add_rating':
                     return $this->getView()->json($this->addPageRating($disableRating));
                 default:
             }
         }
     }
     // get current page's rating info
     $pageRating = $this->getModel()->getPageRatingInfo($this->pageId, $this->getPageSlug());
     $currentRating = $pageRating ? $this->processRatingValue($pageRating['total_rating'] / $pageRating['total_count']) : 0;
     return $this->getView()->partial('page/widget/rating', ['csrf' => ApplicationCsrf::getToken(), 'rating' => $currentRating, 'widget_url' => $this->getWidgetConnectionUrl(), 'big_rating' => $this->getWidgetSetting('page_rating_size') == 'big_rating', 'step_rating' => (double) $this->getWidgetSetting('page_rating_min_step'), 'disable_rating' => $disableRating]);
 }
 /**
  * Class constructor
  *
  * @param array $menu
  */
 public function __construct(array $menu = [])
 {
     if ($menu) {
         // check menu permissions
         foreach ($menu as $menuPart => $menuInfo) {
             foreach ($menuInfo['items'] as $menuItem) {
                 // check a permission
                 if (!AclService::checkPermission($menuItem['controller'] . ' ' . $menuItem['action'], false)) {
                     continue;
                 }
                 if (!isset($this->menu[$menuPart])) {
                     $this->menu[$menuPart] = ['part' => $menuInfo['part'], 'icon' => $menuInfo['icon'], 'module' => $menuInfo['module'], 'items' => [0 => ['name' => $menuItem['name'], 'controller' => $menuItem['controller'], 'action' => $menuItem['action'], 'category' => $menuItem['category'], 'category_icon' => $menuItem['category_icon'], 'category_module' => $menuItem['category_module']]]];
                 } else {
                     $this->menu[$menuPart]['items'][] = ['name' => $menuItem['name'], 'controller' => $menuItem['controller'], 'action' => $menuItem['action'], 'category' => $menuItem['category'], 'category_icon' => $menuItem['category_icon'], 'category_module' => $menuItem['category_module']];
                 }
             }
         }
     }
 }
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // get list of all ACL roles
         $aclRoles = [];
         foreach (AclService::getAclRoles() as $roleId => $roleName) {
             // skip all system ACL roles
             if (in_array($roleId, [AclBaseModel::DEFAULT_ROLE_ADMIN, AclBaseModel::DEFAULT_ROLE_GUEST, AclBaseModel::DEFAULT_ROLE_MEMBER])) {
                 continue;
             }
             $aclRoles[$roleId] = $roleName;
         }
         // get list of acl roles
         $this->formElements['role']['values'] = $aclRoles;
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     // check a permission
     if (AclService::checkPermission('news_view_news', false)) {
         $calendar = $this->getView()->applicationCalendar();
         // set calendar options
         $calendar->setUrl($this->getWidgetConnectionUrl(['month', 'year']))->setWrapperId('news-calendar');
         if (null !== ($month = $this->getRequest()->getQuery('month', null))) {
             $calendar->setMonth($month);
         }
         if (null !== ($year = $this->getRequest()->getQuery('year', null))) {
             $calendar->setYear($year);
         }
         $categoryFilter = $this->isNewsListPage() ? $this->getRouteParam('category') : null;
         // get calendar news
         if (null != ($news = $this->getModel()->getCalendarNews($calendar->getStartDate(), $calendar->getEndDate(), $categoryFilter))) {
             $calendarLinks = [];
             $pageName = $this->getView()->pageUrl(self::NEWS_LIST_PAGE);
             $routeParams = [];
             $routeQueries = [];
             // save all router params and queries on the 'news-list' page
             if ($this->isNewsListPage()) {
                 $routeParams = $this->getView()->applicationRoute()->getAllDefaultRouteParams();
                 $routeQueries = $this->getView()->applicationRoute()->getQuery();
                 // remove this widget's specific params from queries
                 $routeQueries = array_merge($routeQueries, ['month' => null, 'year' => null, 'widget_connection' => null, 'widget_position' => null, '_' => null]);
             }
             // process list of news
             foreach ($news as $newsInfo) {
                 $date = str_replace('-', '/', $newsInfo->news_date);
                 $title = sprintf($this->getView()->translatePlural('count one news', 'count many news', $newsInfo->news_count), $newsInfo->news_count);
                 $calendarLinks[$newsInfo->news_date] = ['title' => $title, 'url' => $this->getView()->url('page', array_merge($routeParams, ['page_name' => $pageName, 'date' => $date]), ['force_canonical' => true, 'query' => $routeQueries])];
             }
             $calendar->setLinks($calendarLinks);
         }
         if ($this->getRequest()->isXmlHttpRequest()) {
             return $calendar->getCalendar();
         }
         return $this->getView()->partial('news/widget/calendar', ['calendar' => $calendar->getCalendar()]);
     }
     return false;
 }
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     if (null != ($questionId = $this->getWidgetSetting('poll_question'))) {
         // get a question info
         if (null != ($questionInfo = $this->getModel()->getQuestionInfo($questionId))) {
             // get list of answers
             $answers = $this->getModel()->getAnswers($questionId);
             $isVotingDisabled = $this->getModel()->isAnswerVoteExist($questionId) || !AclService::checkPermission('polls_make_votes', false);
             if (count($answers) > 1) {
                 // process post actions
                 if ($this->getRequest()->isPost() && ApplicationCsrf::isTokenValid($this->getRequest()->getPost('csrf'))) {
                     if (false !== ($action = $this->getRequest()->getPost('widget_action', false)) && $this->getRequest()->isXmlHttpRequest()) {
                         switch ($action) {
                             case 'make_vote':
                                 if (false !== ($answerId = $this->getRequest()->getPost('answer_id', false)) && !$isVotingDisabled) {
                                     if (true === ($result = $this->getModel()->addAnswerVote($questionId, $answerId))) {
                                         // increase acl track
                                         AclService::checkPermission('polls_make_votes');
                                     }
                                 }
                                 return $this->getView()->json(['data' => $this->getPollResult($questionId, $answers)]);
                             default:
                         }
                     }
                 }
                 // process get actions
                 if (false !== ($action = $this->getRequest()->getQuery('widget_action', false)) && $this->getRequest()->isXmlHttpRequest()) {
                     switch ($action) {
                         case 'get_answers':
                             return $this->getView()->json(['data' => $this->getPollAnswers($answers, $isVotingDisabled)]);
                         case 'get_results':
                         default:
                             return $this->getView()->json(['data' => $this->getPollResult($questionId, $answers)]);
                     }
                 }
                 return $this->getView()->partial('poll/widget/poll-init', ['csrf' => ApplicationCsrf::getToken(), 'widget_url' => $this->getWidgetConnectionUrl(), 'connection_id' => $this->widgetConnectionId, 'question_info' => $questionInfo, 'answers' => $this->getPollAnswers($answers, $isVotingDisabled)]);
             }
         }
     }
     return false;
 }
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     // check a permission
     if (AclService::checkPermission('news_view_news')) {
         //  get a news info
         if (null != ($newsInfo = $this->getModel()->getNewsInfo($this->getSlug(), true, false, 'slug', true))) {
             // set breadcrumb and default metas
             $this->getView()->pageBreadcrumb()->setCurrentPageTitle($newsInfo['title']);
             $this->getView()->layout()->setVariables(['defaultMetaDescription' => $newsInfo['title'], 'defaultMetaKeywords' => $newsInfo['title']]);
             // set meta keywords
             if ($newsInfo['meta_keywords']) {
                 $this->getView()->headMeta()->setName('keywords', $newsInfo['meta_keywords']);
             }
             // set meta description
             if ($newsInfo['meta_description']) {
                 $this->getView()->headMeta()->setName('description', $newsInfo['meta_description']);
             }
             return $this->getView()->partial('news/widget/news-info', ['news' => $newsInfo, 'categories' => $this->getModel()->getNewsCategories($newsInfo['id'])]);
         }
     }
     return false;
 }
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     if (AclService::checkPermission('miniphotogallery_view', false) && null != ($category = $this->getWidgetSetting('miniphotogallery_category'))) {
         // get a pagination page number
         $pageParamName = 'page_' . $this->widgetConnectionId;
         $page = $this->getView()->applicationRoute()->getQueryParam($pageParamName, 1);
         $paginator = $this->getModel()->getImages($page, $category, (int) $this->getWidgetSetting('miniphotogallery_per_page'));
         if ($paginator->count()) {
             AclService::checkPermission('miniphotogallery_view', true);
             $galleryWrapperId = 'mini-photo-gallery-list-' . $this->widgetConnectionId;
             // get data list
             $dataList = $this->getView()->partial('partial/data-list', ['ajax' => ['wrapper_id' => $galleryWrapperId, 'widget_connection' => $this->widgetConnectionId, 'widget_position' => $this->widgetPosition], 'paginator' => $paginator, 'paginator_page_query' => $pageParamName, 'unit' => 'mini-photo-gallery/partial/_photo-unit', 'unit_params' => ['thumbs_width_medium' => $this->getWidgetSetting('miniphotogallery_thumbs_width_medium'), 'thumbs_width_small' => $this->getWidgetSetting('miniphotogallery_thumbs_width_small'), 'thumbs_width_extra_small' => $this->getWidgetSetting('miniphotogallery_thumbs_width_extra_small')], 'uniform_height' => '#' . $galleryWrapperId . ' .thumbnail']);
             // add an init script
             $content = $this->getView()->partial('mini-photo-gallery/widget/_photos-list-init', ['wrapper' => $galleryWrapperId, 'data' => $dataList, 'title_type' => $this->getWidgetSetting('miniphotogallery_title_type')]);
             if ($this->getRequest()->isXmlHttpRequest()) {
                 return $content;
             }
             // wrap all data
             return $this->getView()->partial('mini-photo-gallery/widget/photos-list', ['wrapper' => $galleryWrapperId, 'data' => $content]);
         }
     }
     return false;
 }
 /**
  * Check routes permission
  *
  * @param array $routes
  *      string controller required
  *      string action required
  *      boolean check_acl optional
  *      string acl_resource optional
  * @param boolean $increaseActions
  * @param boolean $collectDisallowed
  * @return array
  */
 public function __invoke(array $routes, $increaseActions = false, $collectDisallowed = false)
 {
     $processedRoutes = [];
     // process routes
     foreach ($routes as $route) {
         // check a route acl
         if (isset($route['check_acl']) && $route['check_acl'] === true) {
             $aclResource = !empty($route['acl_resource']) ? $route['acl_resource'] : $route['controller'] . ' ' . $route['action'];
             // check permission for the specific controller and action
             // check a permission
             if (!AclService::checkPermission($aclResource, $increaseActions)) {
                 if (!$collectDisallowed) {
                     continue;
                 } else {
                     $route['permission'] = false;
                 }
             }
         }
         // fill actions
         $processedRoutes[] = $route;
     }
     return $processedRoutes;
 }
 /**
  * Edit the user's role
  */
 public function editRoleAction()
 {
     // get the user info
     if (null == ($user = $this->getModel()->getUserInfo($this->getSlug())) || $user['user_id'] == UserAdministrationModel::DEFAULT_USER_ID) {
         return $this->createHttpNotFoundModel($this->getResponse());
     }
     // get a role form
     $roleForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\UserRole');
     // fill the form with default values
     $roleForm->getForm()->setData($user);
     $request = $this->getRequest();
     // validate the form
     if ($request->isPost()) {
         // fill the form with received values
         $roleForm->getForm()->setData($request->getPost(), false);
         // save data
         if ($roleForm->getForm()->isValid()) {
             // check the permission and increase permission's actions track
             if (true !== ($result = $this->aclCheckPermission())) {
                 return $result;
             }
             // get the role name
             $roleName = AclService::getAclRoles()[$roleForm->getForm()->getData()['role']];
             if (true === ($result = $this->getModel()->editUserRole($user['user_id'], $roleForm->getForm()->getData()['role'], $roleName, (array) $user))) {
                 $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('User\'s role has been edited'));
             } else {
                 $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate($result));
             }
             return $this->redirectTo('users-administration', 'edit-role', ['slug' => $user['user_id']]);
         }
     }
     return new ViewModel(['csrf_token' => $this->applicationCsrf()->getToken(), 'role_form' => $roleForm->getForm(), 'user' => $user]);
 }
Beispiel #27
0
 /**
  * Test acl by date
  */
 public function testAclByDate()
 {
     $role = AclModelBase::DEFAULT_ROLE_MEMBER;
     $testResources = ['test_application_settings_administration', 'test_application_modules_administration'];
     $this->addAclResources($testResources, true, $role);
     $currentTime = time();
     // add acl resources connections settings
     foreach ($this->aclResourcesConnections as $connectId) {
         $query = $this->aclModelBase->insert()->into('acl_resource_connection_setting')->values(['connection_id' => $connectId, 'user_id' => $this->userId, 'date_start' => $currentTime, 'date_end' => $currentTime + 1]);
         $statement = $this->aclModelBase->prepareStatementForSqlObject($query);
         $statement->execute();
     }
     $this->initAcl($role);
     // all created acl resources must be active
     foreach ($testResources as $resource) {
         $this->assertTrue(AclService::checkPermission($resource));
     }
     // wait two seconds and check acl resources again
     sleep(2);
     $this->initAcl($role);
     // now all created acl resources must be expired
     foreach ($testResources as $resource) {
         $this->assertFalse(AclService::checkPermission($resource));
     }
 }
 /**
  * Get comments list
  *
  * @param boolean $allowApprove
  * @param boolean $getTree
  * @param integer $lastRightKey
  * @param boolean $asArray
  * @param array $ownReplies
  * @return string|array
  */
 protected function getCommentsList($allowApprove, $getTree = true, $lastRightKey = null, $asArray = false, $ownReplies = null)
 {
     // get comments
     $commentsList = $this->getModel()->getComments($allowApprove, $this->pageId, (int) $this->getWidgetSetting('comment_per_page'), $this->getPageSlug(), $getTree, $lastRightKey, $ownReplies);
     // process comments
     if (null != ($commentsList = $this->processComments($commentsList, $asArray))) {
         // increase ACL track
         AclService::checkPermission('comment_view');
     }
     return $commentsList;
 }
 /**
  * Get system pages map
  *
  * @param array $pagesIds
  * @param array $dependentPagesFilter
  * @param integer $order
  * @return array
  */
 protected function getDependentSystemPages(array $pagesIds, array $dependentPagesFilter = [], $order = 0)
 {
     // we need to get recursively all selected pages and their dependent pages
     $pages = [];
     // get selected system pages
     $select = $this->select();
     $select->from(['a' => 'page_system'])->columns(['id', 'slug', 'module', 'disable_user_menu', 'disable_menu', 'disable_site_map', 'disable_footer_menu', 'disable_xml_map', 'dynamic_page', 'forced_visibility'])->join(['d' => 'page_structure'], new Expression('a.slug = d.slug and d.language = ?', [$this->getCurrentLanguage()]), [], 'left')->join(['i' => 'application_module'], new Expression('i.id = a.module and i.status = ?', [self::MODULE_STATUS_ACTIVE]), [])->where->in('a.id', $pagesIds)->where->isNull('d.id');
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     // get home page
     $homePage = $this->serviceLocator->get('Config')['home_page'];
     // get default values
     $defaultPageLayout = $this->getPageLayout(SettingService::getSetting('page_new_pages_layout'));
     $defaultWidgetLayout = SettingService::getSetting('page_new_widgets_layout');
     $defaultShowInMainMenu = (int) SettingService::getSetting('page_new_pages_in_main_menu');
     $defaultShowInSiteMap = (int) SettingService::getSetting('page_new_pages_in_site_map');
     $defaultShowInFooterMenu = (int) SettingService::getSetting('page_new_pages_in_footer_menu');
     $defaultShowInUserMenu = (int) SettingService::getSetting('page_new_pages_in_user_menu');
     $defaultShowInXmlMap = (int) SettingService::getSetting('page_new_pages_in_xml_map');
     $defaultPageVisibility = SettingService::getSetting('page_new_pages_hidden_for');
     // check the roles
     if ($defaultPageVisibility) {
         // get all ACL roles
         $aclRoles = AclService::getAclRoles(false, true);
         // compare them with a setting value
         foreach ($defaultPageVisibility as $index => $roleId) {
             if (!array_key_exists($roleId, $aclRoles)) {
                 unset($defaultPageVisibility[$index]);
             }
         }
     }
     foreach ($resultSet as $page) {
         $dependentPagesFilter[] = $page->id;
         $pages[$page->id] = ['slug' => $page->slug, 'module' => $page->module, 'visibility_settings' => !$page->forced_visibility && $defaultPageVisibility ? $defaultPageVisibility : null, 'user_menu' => !$page->disable_user_menu && $defaultShowInUserMenu ? 1 : null, 'user_menu_order' => (int) SettingService::getSetting('page_new_pages_user_menu_order'), 'menu' => !$page->disable_menu && $defaultShowInMainMenu || $page->slug == $homePage ? 1 : null, 'site_map' => !$page->disable_site_map && $defaultShowInSiteMap || $page->slug == $homePage ? 1 : null, 'xml_map' => !$page->disable_xml_map && $defaultShowInXmlMap ? 1 : null, 'xml_map_update' => SettingService::getSetting('page_new_pages_xml_map_update'), 'xml_map_priority' => SettingService::getSetting('page_new_pages_xml_map_priority'), 'footer_menu' => !$page->disable_footer_menu && $defaultShowInFooterMenu ? 1 : null, 'footer_menu_order' => (int) SettingService::getSetting('page_new_pages_footer_menu_order'), 'layout' => !empty($defaultPageLayout['id']) ? $defaultPageLayout['id'] : null, 'layout_default_position' => !empty($defaultPageLayout['default_position']) ? $defaultPageLayout['default_position'] : null, 'widget_default_layout' => $defaultWidgetLayout ? $defaultWidgetLayout : null, 'order' => $order, 'system_page' => $page->id, 'dynamic_page' => $page->dynamic_page, 'active' => (int) SettingService::getSetting('page_new_pages_active') ? PageNestedSet::PAGE_STATUS_ACTIVE : null];
     }
     // check dependent pages
     if ($pages) {
         $select = $this->select();
         $select->from(['a' => 'page_system_page_depend'])->columns([])->join(['b' => 'page_system'], 'a.depend_page_id = b.id', ['id'])->join(['c' => 'page_structure'], new Expression('b.slug = c.slug and c.language = ?', [$this->getCurrentLanguage()]), [], 'left')->group('b.id')->where->in('a.page_id', array_keys($pages))->where->isNull('c.id');
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         $dependentPagesIds = [];
         foreach ($resultSet as $page) {
             if (in_array($page->id, $dependentPagesFilter)) {
                 continue;
             }
             $dependentPagesIds[] = $page->id;
         }
         // get dependent pages
         if ($dependentPagesIds) {
             $pages = $pages + $this->getDependentSystemPages($dependentPagesIds, $dependentPagesFilter, $order + 1);
         }
     }
     return $pages;
 }
 /**
  * Check permission
  *
  * @param string $resource
  * @param boolean $increaseActions
  * @return boolean
  */
 public function __invoke($resource, $increaseActions = false)
 {
     return AclService::checkPermission($resource, $increaseActions);
 }