Example #1
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';
 }
Example #2
0
 public function run()
 {
     $user = cmsUser::getInstance();
     // Получаем название типа контента и сам тип
     $ctype = $this->model->getContentTypeByName($this->request->get('ctype_name'));
     if (!$ctype || !$ctype['options']['list_on']) {
         cmsCore::error404();
     }
     if (!$user->is_logged) {
         cmsUser::goLogin(href_to($ctype['name'], 'from_friends'));
     }
     // Скрываем записи из скрытых родителей (приватных групп и т.п.)
     $this->model->filterHiddenParents();
     $this->model->filterFriendsPrivateOnly($user->id);
     // Получаем HTML списка записей
     $items_list_html = $this->renderItemsList($ctype, href_to($ctype['name'], 'from_friends'), true);
     return cmsTemplate::getInstance()->render('from_friends', array('ctype' => $ctype, 'items_list_html' => $items_list_html, 'user' => $user), $this->request);
 }
Example #3
0
 public function routeAction($action_name)
 {
     if (!is_numeric($action_name)) {
         return $action_name;
     }
     $core = cmsCore::getInstance();
     $user = cmsUser::getInstance();
     $user_id = $action_name;
     $profile = $this->model->getUser($user_id);
     if (!$profile) {
         cmsCore::error404();
     }
     if (!$user->is_logged && $this->options['is_auth_only']) {
         cmsUser::goLogin();
     }
     $template = cmsTemplate::getInstance();
     $template->applyProfileStyle($profile);
     $this->current_params = $core->uri_params;
     // Статус
     if ($this->options['is_status']) {
         $profile['status'] = $this->model->getUserStatus($profile['status_id']);
     }
     // Репутация
     $profile['is_can_vote_karma'] = $user->is_logged && cmsUser::isAllowed('users', 'vote_karma') && $user->id != $profile['id'] && $this->model->isUserCanVoteKarma($user->id, $profile['id'], $this->options['karma_time']);
     // Нет параметров после названия экшена (/users/id) - значит
     // это главная страница профиля, первым параметром добавляем
     // сам профиль
     if (!$core->uri_params) {
         array_unshift($this->current_params, $profile);
         return 'profile';
     }
     // Ищем экшен внутри профиля
     if ($this->isActionExists('profile_' . $core->uri_params[0])) {
         $this->current_params[0] = $profile;
         return 'profile_' . $core->uri_params[0];
     }
     // Если дошли сюда, значит это неизвестный экшен, возможно вкладка
     // от другого контроллера, тогда первым параметром добавляем
     // сам профиль
     array_unshift($this->current_params, $profile);
     return 'profile_tab';
 }
Example #4
0
 public function run($id = false)
 {
     // редиректим со старых адресов
     if ($id) {
         $photo = $this->model->getPhoto($id);
         if (!$photo || !$photo['slug']) {
             cmsCore::error404();
         }
         $this->redirect(href_to('photos', $photo['slug'] . '.html'), 301);
     }
     $slug = $this->request->get('slug', '');
     if (!$slug) {
         cmsCore::error404();
     }
     $photo = $this->model->getPhoto($slug);
     if (!$photo) {
         cmsCore::error404();
     }
     $album = $this->model->getAlbum($photo['album_id']);
     if (!$album) {
         cmsCore::error404();
     }
     $ctype = $album['ctype'];
     unset($album['ctype']);
     list($photo, $album, $ctype) = cmsEventsManager::hook('photos_before_item', array($photo, $album, $ctype));
     // Проверяем прохождение модерации
     $is_moderator = false;
     if (!$album['is_approved']) {
         $is_moderator = $this->cms_user->is_admin || cmsCore::getModel('content')->userIsContentTypeModerator($ctype['name'], $this->cms_user->id);
         if (!$is_moderator && $this->cms_user->id != $album['user_id']) {
             cmsCore::error404();
         }
     }
     // Проверяем приватность альбома
     if ($album['is_private'] == 1) {
         // доступ только друзьям
         $is_friend = $this->cms_user->isFriend($album['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', $album['user_id']), htmlspecialchars($album['user']['nickname'])), 'info');
             $this->redirect(href_to($ctype['name']));
         }
     }
     // Проверяем приватность фото
     if ($photo['is_private'] == 1) {
         // доступ только друзьям
         $is_friend = $this->cms_user->isFriend($photo['user_id']);
         $is_can_view_private = cmsUser::isAllowed($ctype['name'], 'view_all');
         if (!$is_friend && !$is_can_view_private && !$is_moderator) {
             // иначе пишем, к кому в друзья нужно проситься
             cmsUser::addSessionMessage(sprintf(LANG_CONTENT_PRIVATE_FRIEND_INFO, LANG_PHOTOS_WP_ITEM, href_to('users', $photo['user_id']), htmlspecialchars($photo['user']['nickname'])), 'info');
             $this->redirect(href_to($ctype['name'], $album['slug'] . '.html'));
         }
     }
     // Проверяем ограничения доступа из других контроллеров
     if ($album['is_parent_hidden']) {
         $is_parent_viewable_result = cmsEventsManager::hook('content_view_hidden', array('viewable' => true, 'item' => $album, '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();
         }
     }
     if ($this->cms_user->id != $photo['user_id']) {
         $this->model->incrementCounter($photo['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') && $photo['user_id'] != $this->cms_user->id;
         $photo['rating_widget'] = $rating_controller->getWidget($photo['id'], $photo['rating'], $is_rating_allowed);
     }
     // Комментарии
     if ($ctype['is_comments'] && $this->isControllerEnabled('comments')) {
         $comments_controller = cmsCore::getController('comments', new cmsRequest(array('target_controller' => $this->name, 'target_subject' => 'photo', 'target_id' => $photo['id']), cmsRequest::CTX_INTERNAL));
         $photo['comments_widget'] = $comments_controller->getWidget();
     }
     $is_can_edit = cmsUser::isAllowed($ctype['name'], 'edit', 'all') || cmsUser::isAllowed($ctype['name'], 'edit', 'own') && $album['user_id'] == $this->cms_user->id || $photo['user_id'] == $this->cms_user->id;
     $is_can_delete = cmsUser::isAllowed($ctype['name'], 'delete', 'all') || cmsUser::isAllowed($ctype['name'], 'delete', 'own') && $album['user_id'] == $this->cms_user->id || $photo['user_id'] == $this->cms_user->id;
     $downloads = $this->getDownloadImages($photo);
     $available_downloads = array_filter($downloads, function ($item) {
         return !empty($item['link']);
     });
     $full_size_img_preset = '';
     if ($available_downloads) {
         $download_photo_sizes = array();
         foreach ($available_downloads as $preset => $data) {
             $download_photo_sizes[$preset] = $photo['sizes'][$preset];
         }
         $full_size_img_preset = $this->getMaxSizePresetName($download_photo_sizes);
     }
     $next_photo = $this->model->filterEqual('album_id', $photo['album_id'])->getNextPhoto($photo, $this->options['ordering']);
     $prev_photo = $this->model->filterEqual('album_id', $photo['album_id'])->getPrevPhoto($photo, $this->options['ordering']);
     $tpl = 'view';
     $preset = $this->getBigPreset($photo['sizes']);
     if ($this->request->isAjax()) {
         $tpl = 'view_photo_container';
         if ($full_size_img_preset) {
             $preset = $full_size_img_preset;
         }
     }
     return $this->cms_template->render($tpl, array('next_photo' => $next_photo, 'prev_photo' => $prev_photo, 'downloads' => $downloads, 'is_can_edit' => $is_can_edit, 'is_can_delete' => $is_can_delete, 'user' => $this->cms_user, 'preset' => $preset, 'preset_small' => !empty($this->options['preset_related']) ? $this->options['preset_related'] : $this->options['preset_small'], 'photo' => $photo, 'photos' => $this->getRelatedPhoto($photo), 'related_title' => $this->related_title, 'album' => $album, 'ctype' => $ctype, 'photo_details' => $this->buildPhotoDetails($photo, $album, $ctype), 'hooks_html' => cmsEventsManager::hookAll('photos_item_html', $photo), 'full_size_img' => $full_size_img_preset ? $available_downloads[$full_size_img_preset]['image'] : ''));
 }
Example #5
0
 public function run()
 {
     $user = cmsUser::getInstance();
     $config = cmsConfig::getInstance();
     // Получаем название типа контента и сам тип
     $ctype = $this->model->getContentTypeByName($this->request->get('ctype_name'));
     // Получаем SLUG записи
     $slug = $this->request->get('slug');
     if (!$ctype) {
         if ($config->ctype_default) {
             $ctype = $this->model->getContentTypeByName($config->ctype_default);
             if (!$ctype) {
                 cmsCore::error404();
             }
             $slug = $ctype['name'] . '/' . $slug;
         } else {
             cmsCore::error404();
         }
     } else {
         $core = cmsCore::getInstance();
         if ($config->ctype_default && $config->ctype_default == $core->uri_action) {
             $this->redirect(href_to($slug . '.html'), 301);
         }
     }
     if (!$ctype['options']['item_on']) {
         cmsCore::error404();
     }
     // Получаем запись
     $item = $this->model->getContentItemBySLUG($ctype['name'], $slug);
     if (!$item) {
         cmsCore::error404();
     }
     // Проверяем прохождение модерации
     $is_moderator = $user->is_admin || $this->model->userIsContentTypeModerator($ctype['name'], $user->id);
     if (!$item['is_approved']) {
         if (!$is_moderator && $user->id != $item['user_id']) {
             cmsCore::error404();
         }
     }
     // Проверяем публикацию
     if (!$item['is_pub']) {
         if (!$is_moderator && $user->id != $item['user_id']) {
             cmsCore::error404();
         }
     }
     // Проверяем приватность
     if ($item['is_private'] == 1) {
         // доступ только друзьям
         $is_friend = $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']) {
             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'] != $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'] && ($user->is_admin || $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']) && $user->id != $item['user_id'] && !$user->is_admin) {
         $this->model->incrementHitsCounter($ctype['name'], $item['id']);
     }
     return cmsTemplate::getInstance()->render('item_view', array('ctype' => $ctype, 'fields' => $fields, 'props' => isset($props) ? $props : false, 'props_values' => isset($props_values) ? $props_values : false, 'item' => $item, 'is_moderator' => $is_moderator, 'user' => $user));
 }