Beispiel #1
0
 public function routeAction($action_name)
 {
     if (!is_numeric($action_name)) {
         return $action_name;
     }
     $this->lock_explicit_call = false;
     $group_id = $action_name;
     $group = $this->model->getGroup($group_id);
     if (!$group) {
         cmsCore::error404();
     }
     // кешируем запись для получения ее в виджетах
     cmsModel::cacheResult('current_group', $group);
     cmsModel::cacheResult('group_model', $this->model);
     $this->current_params = $this->cms_core->uri_params;
     $this->current_params[0] = $group;
     $membership = $this->model->getMembership($group['id'], $this->cms_user->id);
     $is_member = $membership !== false;
     if ($group['is_closed'] && !$is_member && !$this->cms_user->is_admin && (empty($this->cms_core->uri_params[0]) || $this->cms_core->uri_params[0] != 'join')) {
         return 'group_closed';
     }
     if (!$this->cms_core->uri_params) {
         return 'group';
     }
     $action_name = $this->cms_core->uri_params[0];
     $action_name = 'group_' . $action_name;
     return $action_name;
 }
Beispiel #2
0
 public function routeAction($action_name)
 {
     if (!is_numeric($action_name)) {
         return $action_name;
     }
     // разблокируем вызов экшенов, которым запрещено вызываться напрямую
     $this->lock_explicit_call = false;
     $user_id = $action_name;
     $is_logged = $this->cms_user->is_logged;
     $profile = $this->model->getUser($user_id);
     if (!$profile) {
         cmsCore::error404();
     }
     if (!$is_logged && $this->options['is_auth_only']) {
         cmsUser::goLogin();
     }
     if ($this->options['is_themes_on']) {
         $this->cms_template->applyProfileStyle($profile);
     }
     $this->current_params = $this->cms_core->uri_params;
     // Статус
     if ($this->options['is_status']) {
         $profile['status'] = $this->model->getUserStatus($profile['status_id']);
     }
     // Репутация
     $profile['is_can_vote_karma'] = $is_logged && cmsUser::isAllowed('users', 'vote_karma') && $this->cms_user->id != $profile['id'] && $this->model->isUserCanVoteKarma($this->cms_user->id, $profile['id'], $this->options['karma_time']);
     // кешируем запись для получения ее в виджетах
     cmsModel::cacheResult('current_profile', $profile);
     // Нет параметров после названия экшена (/users/id) - значит
     // это главная страница профиля, первым параметром добавляем
     // сам профиль
     if (!$this->cms_core->uri_params) {
         array_unshift($this->current_params, $profile);
         return 'profile';
     }
     // Ищем экшен внутри профиля
     if ($this->isActionExists('profile_' . $this->cms_core->uri_params[0])) {
         $this->current_params[0] = $profile;
         return 'profile_' . $this->cms_core->uri_params[0];
     }
     // Если дошли сюда, значит это неизвестный экшен, возможно вкладка
     // от другого контроллера, тогда первым параметром добавляем
     // сам профиль
     array_unshift($this->current_params, $profile);
     return 'profile_tab';
 }
Beispiel #3
0
 public function renderItemsList($ctype, $page_url, $hide_filter = false, $category_id = 0, $filters = array(), $dataset = false, $ext_hidden_params = array())
 {
     $props = $props_fields = false;
     // Получаем поля для данного типа контента
     $fields = cmsCore::getModel('content')->getContentFields($ctype['name']);
     $page = $this->request->get('page', 1);
     $perpage = empty($ctype['options']['limit']) ? self::perpage : $ctype['options']['limit'];
     if ($hide_filter) {
         $ctype['options']['list_show_filter'] = false;
     }
     if ($category_id && $category_id > 1) {
         // Получаем поля-свойства
         $props = cmsCore::getModel('content')->getContentProps($ctype['name'], $category_id);
         $props_fields = $this->getPropsFields($props);
     }
     // проверяем запросы фильтрации по полям
     foreach ($fields as $name => $field) {
         if (!$field['is_in_filter']) {
             continue;
         }
         if (!$this->request->has($name)) {
             continue;
         }
         $value = $this->request->get($name, false, $field['handler']->getDefaultVarType(true));
         if (!$value) {
             continue;
         }
         if ($field['handler']->applyFilter($this->model, $value) !== false) {
             $filters[$name] = $value;
         }
     }
     // проверяем запросы фильтрации по свойствам
     if (isset($props) && is_array($props)) {
         foreach ($props as $prop) {
             $name = "p{$prop['id']}";
             if (!$prop['is_in_filter']) {
                 continue;
             }
             if (!$this->request->has($name)) {
                 continue;
             }
             $prop['handler'] = $props_fields[$prop['id']];
             $value = $this->request->get($name, false, $prop['handler']->getDefaultVarType(true));
             if (!$value) {
                 continue;
             }
             if ($this->model->filterPropValue($ctype['name'], $prop, $value) !== false) {
                 $filters[$name] = $value;
             }
         }
     }
     // Приватность
     // флаг показа только названий
     $hide_except_title = !empty($ctype['options']['privacy_type']) && $ctype['options']['privacy_type'] == 'show_title';
     // Сначала проверяем настройки типа контента
     if (!empty($ctype['options']['privacy_type']) && in_array($ctype['options']['privacy_type'], array('show_title', 'show_all'), true)) {
         $this->model->disablePrivacyFilter();
         if ($ctype['options']['privacy_type'] != 'show_title') {
             $hide_except_title = false;
         }
     }
     // А потом, если разрешено правами доступа, отключаем фильтр приватности
     if (cmsUser::isAllowed($ctype['name'], 'view_all')) {
         $this->model->disablePrivacyFilter();
         $hide_except_title = false;
     }
     // Постраничный вывод
     $this->model->limitPage($page, $perpage);
     list($ctype, $this->model) = cmsEventsManager::hook('content_list_filter', array($ctype, $this->model));
     list($ctype, $this->model) = cmsEventsManager::hook("content_{$ctype['name']}_list_filter", array($ctype, $this->model));
     // Получаем количество и список записей
     $total = $this->model->getContentItemsCount($ctype['name']);
     $items = $this->model->getContentItems($ctype['name']);
     // если запрос через URL
     if ($this->request->isStandard()) {
         if (!$items && $page > 1) {
             cmsCore::error404();
         }
     }
     // Рейтинг
     if ($ctype['is_rating'] && $items && $this->isControllerEnabled('rating')) {
         $rating_controller = cmsCore::getController('rating', new cmsRequest(array('target_controller' => $this->name, 'target_subject' => $ctype['name']), cmsRequest::CTX_INTERNAL));
         $is_rating_allowed = cmsUser::isAllowed($ctype['name'], 'rate');
         foreach ($items as $id => $item) {
             $is_rating_enabled = $is_rating_allowed && $item['user_id'] != $this->cms_user->id;
             $items[$id]['rating_widget'] = $rating_controller->getWidget($item['id'], $item['rating'], $is_rating_enabled);
         }
     }
     list($ctype, $items) = cmsEventsManager::hook('content_before_list', array($ctype, $items));
     list($ctype, $items) = cmsEventsManager::hook("content_{$ctype['name']}_before_list", array($ctype, $items));
     cmsModel::cacheResult('current_ctype_fields', $fields);
     cmsModel::cacheResult('current_ctype_props', $props);
     cmsModel::cacheResult('current_ctype_props_fields', $props_fields);
     $this->cms_template->setContext($this);
     $html = $this->cms_template->renderContentList($ctype, array('category_id' => $category_id, 'page_url' => $page_url, 'ctype' => $ctype, 'fields' => $fields, 'props' => $props, 'props_fields' => $props_fields, 'filters' => $filters, 'ext_hidden_params' => $ext_hidden_params, 'page' => $page, 'perpage' => $perpage, 'total' => $total, 'items' => $items, 'user' => $this->cms_user, 'dataset' => $dataset, 'hide_except_title' => $hide_except_title), new cmsRequest(array(), cmsRequest::CTX_INTERNAL));
     $this->cms_template->restoreContext();
     return $html;
 }
Beispiel #4
0
 public function run()
 {
     // Получаем название типа контента и сам тип
     $ctype_name = $this->request->get('ctype_name', '');
     $ctype = $this->model->getContentTypeByName($ctype_name);
     if (!$ctype) {
         // смотрим, не переопределено ли
         $_ctype_name = $this->getCtypeByAlias($ctype_name);
         if ($_ctype_name) {
             $ctype = $this->model->getContentTypeByName($_ctype_name);
         }
         if (!$ctype) {
             cmsCore::error404();
         } else {
             $this->cms_core->uri_controller_before_remap = $ctype_name;
         }
     }
     if (!$ctype['options']['list_on']) {
         cmsCore::error404();
     }
     $category = array('id' => false);
     $subcats = array();
     // Получаем SLUG категории
     $slug = $this->request->get('slug', '');
     if (!$ctype['is_cats'] && $slug != 'index') {
         cmsCore::error404();
     }
     if ($ctype['is_cats'] && $slug != 'index') {
         $category = $this->model->getCategoryBySLUG($ctype['name'], $slug);
         if (!$category) {
             cmsCore::error404();
         }
     }
     // Получаем список подкатегорий для текущей
     if ($ctype['is_cats']) {
         $current_cat_id = $category['id'] ? $category['id'] : 1;
         $subcats = $this->model->getSubCategories($ctype['name'], $current_cat_id);
     }
     // Получаем список наборов
     $datasets = $this->model->getContentDatasets($ctype['id'], true);
     // Текущий набор
     $dataset = $this->request->get('dataset', '');
     // Это вывод на главной?
     $is_frontpage = $this->request->get('is_frontpage', false);
     // Номер страницы
     $page = $this->request->get('page', 1);
     // Если это не главная, но данный контент выводится на главной и сейчас
     // открыта индексная страница контента - редиректим на главную
     if (!$is_frontpage && $this->cms_config->frontpage == "content:{$ctype['name']}" && $slug == 'index' && !$dataset && $page == 1) {
         $query = $this->cms_core->uri_query;
         if ($query) {
             $this->redirect(href_to_home() . '?' . http_build_query($query));
         } else {
             $this->redirectToHome();
         }
     }
     // Если есть наборы, применяем фильтры текущего
     // иначе будем сортировать по дате создания
     if ($datasets) {
         if ($dataset && empty($datasets[$dataset])) {
             cmsCore::error404();
         }
         $keys = array_keys($datasets);
         $current_dataset = $dataset ? $datasets[$dataset] : $datasets[$keys[0]];
         $this->model->applyDatasetFilters($current_dataset);
     }
     // Фильтр по категории
     if ($ctype['is_cats']) {
         if ($slug != 'index') {
             $this->model->filterCategory($ctype['name'], $category, $ctype['is_cats_recursive']);
         } elseif (!$ctype['is_cats_recursive']) {
             $this->model->filterCategory($ctype['name'], array('id' => 1));
         }
     }
     // Скрываем записи из скрытых родителей (приватных групп и т.п.)
     $this->model->filterHiddenParents();
     // Формируем базовые URL для страниц
     $page_url = array('base' => href_to($ctype['name'] . ($dataset ? '-' . $dataset : ''), isset($category['slug']) ? $category['slug'] : ''), 'first' => href_to($ctype['name'] . ($dataset ? '-' . $dataset : ''), isset($category['slug']) ? $category['slug'] : ''));
     // если не на главной
     if (!$is_frontpage) {
         // если название переопределено, то редиректим со старого на новый адрес
         $mapping = cmsConfig::getControllersMapping();
         if ($mapping) {
             foreach ($mapping as $name => $alias) {
                 if ($name == $ctype['name'] && !$this->cms_core->uri_controller_before_remap) {
                     $this->redirect(href_to($alias . ($dataset ? '-' . $dataset : ''), isset($category['slug']) ? $category['slug'] : ''), 301);
                 }
             }
         }
     }
     list($ctype, $category) = cmsEventsManager::hook("content_before_category", array($ctype, $category));
     list($ctype, $category) = cmsEventsManager::hook("content_{$ctype['name']}_before_category", array($ctype, $category));
     $items_list_html = '';
     $is_hide_items = !empty($ctype['options']['is_empty_root']) && $slug == 'index';
     // Получаем HTML списка записей
     if (!$is_hide_items) {
         $items_list_html = $this->renderItemsList($ctype, $page_url, false, $category['id'], array(), $dataset);
     }
     // кешируем
     cmsModel::cacheResult('current_ctype', $ctype);
     cmsModel::cacheResult('current_ctype_category', $category);
     return $this->cms_template->render('category_view', array('is_frontpage' => $is_frontpage, 'is_hide_items' => $is_hide_items, 'parent' => isset($parent) ? $parent : false, 'slug' => $slug, 'ctype' => $ctype, 'datasets' => $datasets, 'dataset' => $dataset, 'current_dataset' => isset($current_dataset) ? $current_dataset : array(), 'category' => $category, 'subcats' => $subcats, 'items_list_html' => $items_list_html, 'user' => $this->cms_user), $this->request);
 }
Beispiel #5
0
 public function run()
 {
     $props = $props_values = false;
     // Получаем название типа контента и сам тип
     $ctype = $this->model->getContentTypeByName($this->request->get('ctype_name', ''));
     // Получаем SLUG записи
     $slug = $this->request->get('slug', '');
     if (!$ctype) {
         if ($this->cms_config->ctype_default) {
             $ctype = $this->model->getContentTypeByName($this->cms_config->ctype_default);
             if (!$ctype) {
                 cmsCore::error404();
             }
             $slug = $ctype['name'] . '/' . $slug;
         } else {
             cmsCore::error404();
         }
     } else {
         if ($this->cms_config->ctype_default && $this->cms_config->ctype_default == $this->cms_core->uri_action) {
             $this->redirect(href_to($slug . '.html'), 301);
         }
         // если название переопределено, то редиректим со старого на новый
         $mapping = cmsConfig::getControllersMapping();
         if ($mapping) {
             foreach ($mapping as $name => $alias) {
                 if ($name == $ctype['name'] && !$this->cms_core->uri_controller_before_remap) {
                     $this->redirect(href_to($alias . '/' . $slug . '.html'), 301);
                 }
             }
         }
     }
     // чтобы привязки виджетов к записям работали
     if ($this->cms_config->ctype_default && $this->cms_config->ctype_default == $ctype['name']) {
         $this->cms_core->uri = $this->cms_config->ctype_default . '/' . $this->cms_core->uri;
     }
     if (!$ctype['options']['item_on']) {
         cmsCore::error404();
     }
     // Получаем запись
     $item = $this->model->getContentItemBySLUG($ctype['name'], $slug);
     if (!$item) {
         cmsCore::error404();
     }
     // Проверяем прохождение модерации
     $is_moderator = $this->cms_user->is_admin || $this->model->userIsContentTypeModerator($ctype['name'], $this->cms_user->id);
     if (!$item['is_approved']) {
         if (!$is_moderator && $this->cms_user->id != $item['user_id']) {
             cmsCore::error404();
         }
     }
     // Проверяем публикацию
     if (!$item['is_pub']) {
         if (!$is_moderator && $this->cms_user->id != $item['user_id']) {
             cmsCore::error404();
         }
     }
     // Проверяем приватность
     if ($item['is_private'] == 1) {
         // доступ только друзьям
         $is_friend = $this->cms_user->isFriend($item['user_id']);
         $is_can_view_private = cmsUser::isAllowed($ctype['name'], 'view_all');
         if (!$is_friend && !$is_can_view_private && !$is_moderator) {
             // если в настройках указано скрывать, 404
             if (empty($ctype['options']['privacy_type']) || $ctype['options']['privacy_type'] == 'hide') {
                 cmsCore::error404();
             }
             // иначе пишем, к кому в друзья нужно проситься
             cmsUser::addSessionMessage(sprintf(LANG_CONTENT_PRIVATE_FRIEND_INFO, !empty($ctype['labels']['one']) ? $ctype['labels']['one'] : LANG_PAGE, href_to('users', $item['user_id']), htmlspecialchars($item['user']['nickname'])), 'info');
             $this->redirect(href_to($ctype['name']));
         }
     }
     // Проверяем ограничения доступа из других контроллеров
     if ($item['is_parent_hidden']) {
         $is_parent_viewable_result = cmsEventsManager::hook('content_view_hidden', array('viewable' => true, 'item' => $item, 'is_moderator' => $is_moderator));
         if (!$is_parent_viewable_result['viewable']) {
             if (isset($is_parent_viewable_result['access_text'])) {
                 cmsUser::addSessionMessage($is_parent_viewable_result['access_text'], 'error');
                 if (isset($is_parent_viewable_result['access_redirect_url'])) {
                     $this->redirect($is_parent_viewable_result['access_redirect_url']);
                 } else {
                     $this->redirect(href_to($ctype['name']));
                 }
             }
             cmsUser::goLogin();
         }
     }
     $item['ctype_name'] = $ctype['name'];
     if ($ctype['is_cats'] && $item['category_id'] > 1) {
         $item['category'] = $this->model->getCategory($ctype['name'], $item['category_id']);
     }
     // Получаем поля для данного типа контента
     $fields = $this->model->getContentFields($ctype['name']);
     // Парсим значения полей
     foreach ($fields as $name => $field) {
         $fields[$name]['html'] = $field['handler']->setItem($item)->parse($item[$name]);
     }
     // Получаем поля-свойства
     if ($ctype['is_cats'] && $item['category_id'] > 1) {
         $props = $this->model->getContentProps($ctype['name'], $item['category_id']);
         $props_values = $this->model->getPropsValues($ctype['name'], $item['id']);
     }
     // Рейтинг
     if ($ctype['is_rating'] && $this->isControllerEnabled('rating')) {
         $rating_controller = cmsCore::getController('rating', new cmsRequest(array('target_controller' => $this->name, 'target_subject' => $ctype['name']), cmsRequest::CTX_INTERNAL));
         $is_rating_allowed = cmsUser::isAllowed($ctype['name'], 'rate') && $item['user_id'] != $this->cms_user->id;
         $item['rating_widget'] = $rating_controller->getWidget($item['id'], $item['rating'], $is_rating_allowed);
     }
     // Комментарии
     if ($ctype['is_comments'] && $item['is_approved'] && $item['is_comments_on'] && $this->isControllerEnabled('comments')) {
         $comments_controller = cmsCore::getController('comments', new cmsRequest(array('target_controller' => $this->name, 'target_subject' => $ctype['name'], 'target_user_id' => $item['user_id'], 'target_id' => $item['id']), cmsRequest::CTX_INTERNAL));
         $item['comments_widget'] = $comments_controller->getWidget();
     }
     // Получаем теги
     if ($ctype['is_tags']) {
         $tags_model = cmsCore::getModel('tags');
         $item['tags'] = $tags_model->getTagsForTarget($this->name, $ctype['name'], $item['id']);
     }
     // Информация о модераторе для админа и владельца записи
     if ($item['approved_by'] && ($this->cms_user->is_admin || $this->cms_user->id == $item['user_id'])) {
         $item['approved_by'] = cmsCore::getModel('users')->getUser($item['approved_by']);
     }
     list($ctype, $item, $fields) = cmsEventsManager::hook('content_before_item', array($ctype, $item, $fields));
     list($ctype, $item, $fields) = cmsEventsManager::hook("content_{$ctype['name']}_before_item", array($ctype, $item, $fields));
     if (!empty($ctype['options']['hits_on']) && $this->cms_user->id != $item['user_id'] && !$this->cms_user->is_admin) {
         $this->model->incrementHitsCounter($ctype['name'], $item['id']);
     }
     // кешируем запись для получения ее в виджетах
     cmsModel::cacheResult('current_ctype', $ctype);
     cmsModel::cacheResult('current_ctype_item', $item);
     cmsModel::cacheResult('current_ctype_fields', $fields);
     cmsModel::cacheResult('current_ctype_props', $props);
     return $this->cms_template->render('item_view', array('ctype' => $ctype, 'fields' => $fields, 'props' => $props, 'props_values' => $props_values, 'item' => $item, 'is_moderator' => $is_moderator, 'user' => $this->cms_user));
 }