/** * Init layout */ protected function initlayout() { try { // get a custom template path resolver $templatePathResolver = $this->serviceLocator->get('Layout\\View\\Resolver\\TemplatePathStack'); // replace the default template path stack resolver with one $aggregateResolver = $this->serviceLocator->get('Zend\\View\\Resolver\\AggregateResolver'); $aggregateResolver->attach($templatePathResolver)->getIterator()->remove($this->serviceLocator->get('Zend\\View\\Resolver\\TemplatePathStack')); $layout = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Layout\\Model\\LayoutBase'); $request = $this->serviceLocator->get('Request'); // get a layout from cookies $allowSelectLayouts = (int) SettingService::getSetting('layout_select'); $cookieLayout = isset($request->getCookie()->{self::LAYOUT_COOKIE}) && $allowSelectLayouts ? (int) $request->getCookie()->{self::LAYOUT_COOKIE} : null; // init a user selected layout if ($cookieLayout) { $activeLayouts = $layout->getLayoutsById($cookieLayout); } else { $activeLayouts = !empty(UserIdentityService::getCurrentUserIdentity()['layout']) && $allowSelectLayouts ? $layout->getLayoutsById(UserIdentityService::getCurrentUserIdentity()['layout']) : $layout->getDefaultActiveLayouts(); } // add layouts paths for each module foreach ($this->moduleManager->getModules() as $module) { foreach ($activeLayouts as $layoutInfo) { $templatePathResolver->addPath('module/' . $module . '/view/' . $layoutInfo['name']); } } LayoutService::setCurrentLayouts($activeLayouts); } catch (Exception $e) { ApplicationErrorLogger::log($e); } }
/** * Get widget content * * @return string|boolean */ public function getContent() { if (!UserIdentityService::isGuest()) { // get the user delete form $deleteForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\UserDelete'); $request = $this->getRequest(); // validate the form if ($request->isPost() && $this->getRequest()->getPost('form_name') == $deleteForm->getFormName()) { // fill the form with received values $deleteForm->getForm()->setData($request->getPost(), false); // delete the user's account if ($deleteForm->getForm()->isValid()) { if (true !== ($deleteResult = $this->getModel()->deleteUser(UserIdentityService::getCurrentUserIdentity(), false))) { $this->getFlashMessenger()->setNamespace('error')->addMessage($this->translate('Error occurred')); return $this->reloadPage(); } // clear user's identity $this->logoutUser(UserIdentityService::getCurrentUserIdentity()); return $this->redirectTo(); } } return $this->getView()->partial('user/widget/delete', ['delete_form' => $deleteForm->getForm()]); } return false; }
/** * Get widget content * * @return string|boolean */ public function getContent() { if (!UserIdentityService::isGuest()) { return $this->getView()->partial('user/widget/dashboard', ['user' => UserIdentityService::getCurrentUserIdentity()]); } return false; }
/** * Is allowed to view the site * * @return boolean */ public static function isAllowedViewSite() { if ((int) SettingService::getSetting('application_disable_site')) { $user = UserIdentityService::getCurrentUserIdentity(); if ($user['role'] != AclBaseModel::DEFAULT_ROLE_ADMIN) { // get a visitor IP $remote = new RemoteAddress(); $remote->setUseProxy(true); $userIp = $remote->getIpAddress(); // get list of allowed ACL roles if (null != ($allowedAclRoles = SettingService::getSetting('application_disable_site_acl'))) { if (!is_array($allowedAclRoles)) { $allowedAclRoles = [$allowedAclRoles]; } } // get list of allowed IPs if (null != ($allowedIps = SettingService::getSetting('application_disable_site_ip'))) { $allowedIps = explode(',', $allowedIps); } if ($allowedAclRoles || $allowedIps) { if ($allowedAclRoles && in_array($user['role'], $allowedAclRoles) || $allowedIps && in_array($userIp, $allowedIps)) { return true; } } return false; } } return true; }
/** * Get page url * * @param string $slug * @param string $language * @param array $privacyOptions * @param boolean $trustedPrivacyData * @param string $objectId * @return string|boolean */ protected function getPageUrl($slug, $language, array $privacyOptions = [], $trustedPrivacyData = false, $objectId = null) { if (!isset($this->pagesMap[$language]) || !array_key_exists($slug, $this->pagesMap[$language])) { return false; } // get a page info $page = $this->pagesMap[$language][$slug]; // check the page's status if ($page['active'] != PageNestedSet::PAGE_STATUS_ACTIVE || $page['module_status'] != ApplicationAbstractBaseModel::MODULE_STATUS_ACTIVE) { return false; } // check the page's privacy if (false == ($result = PagePrivacyUtility::checkPagePrivacy($page['privacy'], $privacyOptions, $trustedPrivacyData, $objectId))) { return false; } // check the page's visibility if (!empty($page['hidden']) && in_array(UserIdentityService::getCurrentUserIdentity()['role'], $page['hidden'])) { return false; } // check for a parent and if (!empty($page['parent'])) { if (false === ($parentUrl = $this->getPageUrl($page['parent'], $language, [], false))) { return false; } // build a link (skip the home page) if ($this->pagesMap[$language][$page['parent']]['level'] > 1) { $slug = $parentUrl . '/' . $slug; } } return $slug; }
/** * Fire uninstall localization event * * @param string $language * @return void */ public static function fireUninstallLocalizationEvent($language) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Localization uninstalled by guest' : 'Event - Localization uninstalled by user'; $eventDescParams = UserIdentityService::isGuest() ? [$language] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $language]; self::fireEvent(self::UNINSTALL, $language, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * Fire deactivate action event * * @param $actionId * @return void */ public static function fireDeactivateActionEvent($actionId) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Action deactivated by guest' : 'Event - Action deactivated by user'; $eventDescParams = UserIdentityService::isGuest() ? [$actionId] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $actionId]; self::fireEvent(self::DEACTIVATE_ACTION, $actionId, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * 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; }
/** * View transaction's items */ public function ajaxViewTransactionItemsAction() { $transactionId = $this->params()->fromQuery('id', -1); $userId = UserIdentityService::getCurrentUserIdentity()['user_id']; // get transaction's items if (null == ($items = $this->getModel()->getAllTransactionItems($transactionId, $userId, true))) { return $this->createHttpNotFoundModel($this->getResponse()); } return new ViewModel(['transaction' => $this->getModel()->getTransactionInfo($transactionId, false, 'id', false), 'items' => $items]); }
/** * 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; }
/** * Get widget content * * @return string|boolean */ public function getContent() { $userId = UserIdentityService::getCurrentUserIdentity()['user_id']; // process post actions if ($this->getRequest()->isPost() && ApplicationCsrfUtility::isTokenValid($this->getRequest()->getPost('csrf')) && $this->getRequest()->getPost('form_name') == 'transactions') { $transactions = $this->getRequest()->getPost('transactions'); if ($transactions && is_array($transactions)) { switch ($this->getRequest()->getQuery('action')) { // delete selected transactions case 'delete': return $this->deleteTransactions($transactions, $userId); default: } } } // get pagination options list($pageParamName, $perPageParamName, $orderByParamName, $orderTypeParamName) = $this->getPaginationParams(); $page = $this->getView()->applicationRoute()->getQueryParam($pageParamName, 1); $perPage = $this->getView()->applicationRoute()->getQueryParam($perPageParamName); $orderBy = $this->getView()->applicationRoute()->getQueryParam($orderByParamName); $orderType = $this->getView()->applicationRoute()->getQueryParam($orderTypeParamName); $filters = []; $fieldsPostfix = '_' . $this->widgetConnectionId; // get a filter form $filterForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('Payment\\Form\\PaymentUserTransactionFilter')->setFieldsPostfix($fieldsPostfix); $request = $this->getRequest(); $filterForm->getForm()->setData($request->getQuery(), false); // validate the filter form if ($this->getRequest()->isXmlHttpRequest() || $this->getView()->applicationRoute()->getQueryParam('form_name') == $filterForm->getFormName()) { // check the filter form validation if ($filterForm->getForm()->isValid()) { $filters = $filterForm->getData(); } } // get data $paginator = $this->getModel()->getUserTransactions($userId, $page, $perPage, $orderBy, $orderType, $filters, $fieldsPostfix); $dataGridWrapper = 'transactions-page-wrapper'; // get data grid $dataGrid = $this->getView()->partial('payment/widget/transaction-history', ['current_currency' => PaymentService::getPrimaryCurrency(), 'payment_types' => $this->getModel()->getPaymentsTypes(false, true), 'filter_form' => $filterForm->getForm(), 'paginator' => $paginator, 'order_by' => $orderBy, 'order_type' => $orderType, 'per_page' => $perPage, 'page_param_name' => $pageParamName, 'per_page_param_name' => $perPageParamName, 'order_by_param_name' => $orderByParamName, 'order_type_param_name' => $orderTypeParamName, 'widget_connection' => $this->widgetConnectionId, 'widget_position' => $this->widgetPosition, 'data_grid_wrapper' => $dataGridWrapper]); if ($this->getRequest()->isXmlHttpRequest()) { return $dataGrid; } return $this->getView()->partial('payment/widget/transaction-history-wrapper', ['data_grid_wrapper' => $dataGridWrapper, 'data_grid' => $dataGrid]); }
/** * Select layout */ public function ajaxSelectLayoutAction() { $request = $this->getRequest(); if ($request->isPost()) { if ((int) $this->applicationSetting('layout_select')) { $layoutId = $this->getSlug(-1); $layouts = LayoutService::getLayouts(false); // save selected layout if (array_key_exists($layoutId, $layouts)) { if (!$this->isGuest()) { $user = UserIdentityService::getCurrentUserIdentity(); $this->getModel()->selectLayout($layoutId, $user['user_id']); } LayoutCookieUtility::saveLayout($layoutId); } } } return $this->getResponse(); }
/** * Get widget content * * @return string|boolean */ public function getContent() { if (!UserIdentityService::isGuest()) { // get an user form $userForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\User')->setModel($this->getModel())->setTimeZones(TimeZoneService::getTimeZones())->setUserId(UserIdentityService::getCurrentUserIdentity()['user_id'])->setUserAvatar(UserIdentityService::getCurrentUserIdentity()['avatar']); // fill the form with default values $userForm->getForm()->setData(UserIdentityService::getCurrentUserIdentity()); // validate the form if ($this->getRequest()->isPost() && $this->getRequest()->getPost('form_name') == $userForm->getFormName()) { // make certain to merge the files info! $post = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); // fill the form with received values $userForm->getForm()->setData($post, false); // save data if ($userForm->getForm()->isValid()) { // set status $status = (int) $this->getSetting('user_auto_confirm') || UserIdentityService::getCurrentUserIdentity()['role'] == AclBaseModel::DEFAULT_ROLE_ADMIN ? true : false; $deleteAvatar = (int) $this->getRequest()->getPost('avatar_delete') ? true : false; // edit current user's info $result = $this->getModel()->editUser(UserIdentityService::getCurrentUserIdentity(), $userForm->getForm()->getData(), $status, $this->getRequest()->getFiles()->avatar, $deleteAvatar, true); if (true === $result) { if ($status) { $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('Your account has been edited')); } else { $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('Your account will be active after checking')); // redirect to login page $loginUrl = $this->getView()->pageUrl('login'); return $this->redirectTo(['page_name' => false !== $loginUrl ? $loginUrl : '']); } } else { $this->getFlashMessenger()->setNamespace('error')->addMessage($this->translate('Error occurred')); } return $this->reloadPage(); } } return $this->getView()->partial('user/widget/edit', ['user_form' => $userForm->getForm()]); } return false; }
/** * Get ACL resources */ public function ajaxGetAclResourcesAction() { $view = new ViewModel(['resources' => $this->getAclModel()->getAllowedAclResources($this->getSlug(), UserIdentityService::getCurrentUserIdentity()['user_id'])]); return $view; }
/** * Fire delete question event * * @param integer $questionId * @return void */ public static function fireDeleteQuestionEvent($questionId) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Poll question deleted by guest' : 'Event - Poll question deleted by user'; $eventDescParams = UserIdentityService::isGuest() ? [$questionId] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $questionId]; self::fireEvent(self::DELETE_QUESTION, $questionId, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * Process comments * * @param array $comments * @param boolean $asArray * @return string|array */ protected function processComments(array $comments, $asArray = false) { $processedComments = null; if (count($comments)) { $userId = !UserIdentityService::isGuest() ? UserIdentityService::getCurrentUserIdentity()['user_id'] : $this->getModel()->getCommentModel()->getGuestId(); $maxRepliesNestedLevel = (int) $this->getWidgetSetting('comment_max_nested_level'); $showUsersThumbs = (int) $this->getWidgetSetting('comment_show_thumbs'); // process comments foreach ($comments as $comment) { $content = $this->getView()->partial('comment/widget/_comment-item-start', ['id' => $comment['id'], 'parent_id' => $comment['parent_id'], 'comment' => $comment['comment'], 'approved' => $comment['active'] == CommentNestedSet::COMMENT_STATUS_ACTIVE, 'own_comment' => $userId == $comment['user_id'] || $userId == $comment['guest_id'], 'visible_chars' => (int) $this->getWidgetSetting('comment_visible_chars'), 'registered_nickname' => $comment['registered_nickname'], 'guest_id' => $comment['guest_id'], 'name' => $comment['name'], 'user_id' => $comment['user_id'], 'user_slug' => $comment['registered_slug'], 'user_avatar' => $comment['registered_avatar'], 'created' => $comment['created'], 'show_reply' => $comment['level'] <= $maxRepliesNestedLevel, 'show_thumbs' => $showUsersThumbs]); // check for children if (!$asArray && !empty($comment['children'])) { $content .= $this->processComments($comment['children']); } $content .= $this->getView()->partial('comment/widget/_comment-item-end'); // collect processed comments !$asArray ? $processedComments .= $content : ($processedComments[] = ['id' => $comment['id'], 'parent_id' => $comment['parent_id'], 'comment' => $content]); } } return $processedComments; }
/** * Delete membership * * @param integer $membershipId * @return void */ protected function deleteMembership($membershipId) { $userId = UserIdentityService::getCurrentUserIdentity()['user_id']; // get a membership level info if (null !== ($connectionInfo = $this->getModel()->getMembershipConnectionInfo($membershipId, $userId))) { // delete the membership level if (false !== ($deleteResult = $this->getModel()->deleteMembershipConnection($connectionInfo['id'], false))) { if ($connectionInfo['active'] == MembershipBaseModel::MEMBERSHIP_LEVEL_CONNECTION_ACTIVE) { // get a next membership connection $nextConnection = $this->getModel()->getMembershipConnectionFromQueue($userId); $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($userId, $nextRoleId, $nextRoleName, $connectionInfo, true))) { // activate the next membership connection if ($nextConnection) { $this->getModel()->activateMembershipConnection($nextConnection['id']); } } } } } }
/** * Fire delete acl role event * * @param integer $roleId * @return void */ public static function fireDeleteAclRoleEvent($roleId) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - ACL role deleted by guest' : 'Event - ACL role deleteted by user'; $eventDescParams = UserIdentityService::isGuest() ? [$roleId] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $roleId]; self::fireEvent(self::DELETE_ROLE, $roleId, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * 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'])]]); } }
/** * Init application * * @param \Zend\ModuleManager\ModuleEvent $e * @return void */ public function initApplication(ModuleEvent $e) { $this->userIdentity = UserIdentityService::getCurrentUserIdentity(); // init default localization $this->initDefaultLocalization(); }
/** * Fire delete custom module event * * @param string $module * @return void */ public static function fireDeleteCustomModuleEvent($module) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Custom module deleted by guest' : 'Event - Custom module deleted by user'; $eventDescParams = UserIdentityService::isGuest() ? [$module] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $module]; self::fireEvent(self::DELETE_CUSTOM_MODULE, $module, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * Fire delete category event * * @param integer $categoryId * @return void */ public static function fireDeleteCategoryEvent($categoryId) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Slideshow category deleted by guest' : 'Event - Slideshow category deleted by user'; $eventDescParams = UserIdentityService::isGuest() ? [$categoryId] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $categoryId]; self::fireEvent(self::DELETE_CATEGORY, $categoryId, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * Fire delete file event * * @param string $path * @return void */ public static function fireDeleteFileEvent($path) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - File deleted by guest' : 'Event - File deleted by user'; $eventDescParams = UserIdentityService::isGuest() ? [$path] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $path]; self::fireEvent(self::DELETE_FILE, $path, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * Fire edit payment currency event * * @param integer $currencyId * @return void */ public static function fireEditPaymentCurrencyEvent($currencyId) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Payment currency edited by guest' : 'Event - Payment currency edited by user'; $eventDescParams = UserIdentityService::isGuest() ? [$currencyId] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $currencyId]; self::fireEvent(self::EDIT_PAYMENT_CURRENCY, $currencyId, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * Class constructor * * @param object $serviceLocator */ public function __construct(ServiceLocatorInterface $serviceLocator) { $this->serviceLocator = $serviceLocator; $this->userIdentity = UserIdentityService::getCurrentUserIdentity(); }
/** * Init view helpers */ public function getViewHelperConfig() { return ['invokables' => ['userLoginWidget' => 'User\\View\\Widget\\UserLoginWidget', 'userRegisterWidget' => 'User\\View\\Widget\\UserRegisterWidget', 'userActivateWidget' => 'User\\View\\Widget\\UserActivateWidget', 'userForgotWidget' => 'User\\View\\Widget\\UserForgotWidget', 'userPasswordResetWidget' => 'User\\View\\Widget\\UserPasswordResetWidget', 'userDeleteWidget' => 'User\\View\\Widget\\UserDeleteWidget', 'userInfoWidget' => 'User\\View\\Widget\\UserInfoWidget', 'userAvatarWidget' => 'User\\View\\Widget\\UserAvatarWidget', 'userDashboardWidget' => 'User\\View\\Widget\\UserDashboardWidget', 'userDashboardUserInfoWidget' => 'User\\View\\Widget\\UserDashboardUserInfoWidget', 'userEditWidget' => 'User\\View\\Widget\\UserEditWidget', 'userDashboardAdministrationWidget' => 'User\\View\\Widget\\UserDashboardAdministrationWidget'], 'factories' => ['userAvatarUrl' => function () { $thumbDir = ApplicationService::getResourcesUrl() . UserBaseModel::getThumbnailsDir(); $avatarDir = ApplicationService::getResourcesUrl() . UserBaseModel::getAvatarsDir(); return new \User\View\Helper\UserAvatarUrl($thumbDir, $avatarDir); }, 'userMenu' => function () { $userMenu = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('User\\Model\\UserMenu'); return new \User\View\Helper\UserMenu($userMenu->getMenu()); }, 'userIdentity' => function () { return new \User\View\Helper\UserIdentity(UserIdentityService::getCurrentUserIdentity()); }, 'userIsGuest' => function () { return new \User\View\Helper\UserIsGuest(UserIdentityService::isGuest()); }]]; }
/** * Fire add membership role event * * @param integer $membershipRoleId * @return void */ public static function fireAddMembershipRoleEvent($membershipRoleId) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Membership role added by guest' : 'Event - Membership role added by user'; $eventDescParams = UserIdentityService::isGuest() ? [$membershipRoleId] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $membershipRoleId]; self::fireEvent(self::ADD_MEMBERSHIP_ROLE, $membershipRoleId, UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); }
/** * Check permission * * @param string $resource * @param boolean $increaseActions * @return boolean */ public static function checkPermission($resource, $increaseActions = true) { $currentUserIdentity = UserIdentityService::getCurrentUserIdentity(); // admin can do everything if ($currentUserIdentity['role'] == AclBaseModel::DEFAULT_ROLE_ADMIN) { return true; } // process a resource name $resource = str_replace([' ', '-'], [self::ACL_RESOURCE_SPACE_DEVIDER, self::ACL_RESOURCE_SPACE_DEVIDER], $resource); // init an ACL if (null === self::$currentAcl) { self::initAcl($currentUserIdentity); } $aclModel = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Acl\\Model\\AclBase'); // check the resource existing if (self::$currentAclResources && array_key_exists($resource, self::$currentAclResources)) { // check the resource's dates if (true === ($result = $aclModel->isAclResourceDatesActive(self::$currentAclResources[$resource]))) { // check the permission $permissionResult = self::$currentAcl->isAllowed($currentUserIdentity['role'], $resource); // reset the current resource actions if it needs if (true === ($result = $aclModel->resetAclResource($currentUserIdentity['user_id'], self::$currentAclResources[$resource], $permissionResult, $increaseActions))) { // update ACL resources again self::initAcl($currentUserIdentity); // check the permission again if (true !== ($permissionResult = self::$currentAcl->isAllowed($currentUserIdentity['role'], $resource))) { // check the resource's dates if (true === ($result = $aclModel->isAclResourceDatesActive(self::$currentAclResources[$resource]))) { // a previous action should be finished if ((int) self::$currentAclResources[$resource]['actions_limit'] == (int) self::$currentAclResources[$resource]['actions']) { return true; } } } } return $permissionResult; } } return false; }
/** * Get a user id * * @param boolean $isSystemEvent * @return integer */ protected static function getUserId($isSystemEvent = false) { return $isSystemEvent ? UserBaseModel::DEFAULT_SYSTEM_ID : UserIdentityService::getCurrentUserIdentity()['user_id']; }
/** * Edit a news action */ public function editNewsAction() { // get the news info if (null == ($news = $this->getModel()->getNewsInfo($this->getSlug(), true, true))) { return $this->redirectTo('news-administration', 'list'); } // get a news form $newsForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('News\\Form\\News')->setModel($this->getModel())->setNewsId($news['id'])->setNewsImage($news['image']); // fill the form with default values $newsForm->getForm()->setData($news); $request = $this->getRequest(); // validate the form if ($request->isPost()) { // make certain to merge the files info! $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); // fill the form with received values $newsForm->getForm()->setData($post, false); // save data if ($newsForm->getForm()->isValid()) { // check the permission and increase permission's actions track if (true !== ($result = $this->aclCheckPermission())) { return $result; } // get news status $approved = (int) $this->applicationSetting('news_auto_approve') || UserIdentityService::getCurrentUserIdentity()['role'] == AclBaseModel::DEFAULT_ROLE_ADMIN ? true : false; $deleteImage = (int) $this->getRequest()->getPost('image_delete') ? true : false; // edit the news if (true === ($result = $this->getModel()->editNews($news, $newsForm->getForm()->getData(), $this->params()->fromPost('categories'), $this->params()->fromFiles('image'), $approved, $deleteImage))) { $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('News has been edited')); } else { $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate($result)); } return $this->redirectTo('news-administration', 'edit-news', ['slug' => $news['id']]); } } return new ViewModel(['csrf_token' => $this->applicationCsrf()->getToken(), 'news_form' => $newsForm->getForm(), 'news' => $news]); }