Beispiel #1
0
 public function run()
 {
     $ctype = cmsModel::getCachedResult('current_ctype');
     $ctype_name = $this->getOption('ctype_name');
     $active_cat = false;
     if (!$ctype_name) {
         if (!$ctype) {
             return false;
         }
         $ctype_name = $ctype['name'];
     }
     if ($ctype && $ctype['name'] == $ctype_name) {
         if (strpos(cmsCore::getInstance()->uri, '.html') === false) {
             $current_ctype_category = cmsModel::getCachedResult('current_ctype_category');
             if (!empty($current_ctype_category['id'])) {
                 $active_cat = $current_ctype_category;
             }
         } else {
             $item = cmsModel::getCachedResult('current_ctype_item');
             if (!$item) {
                 return false;
             }
             if (!empty($item['category'])) {
                 $active_cat = $item['category'];
             }
         }
     }
     $model = cmsCore::getModel('content');
     $cats = $model->getCategoriesTree($ctype_name, $this->getOption('is_root'));
     if (!$cats) {
         return false;
     }
     if ($active_cat) {
         $path = array_filter($cats, function ($cat) use($active_cat) {
             return $cat['ns_left'] <= $active_cat['ns_left'] && $cat['ns_level'] <= $active_cat['ns_level'] && $cat['ns_right'] >= $active_cat['ns_right'] && $cat['ns_level'] > 0;
         });
     }
     return array('ctype_name' => $ctype_name, 'cats' => $cats, 'active_cat' => $active_cat, 'path' => !empty($path) ? $path : array());
 }
Beispiel #2
0
 public function run()
 {
     $user = cmsUser::getInstance();
     $photo = cmsCore::getController('photos');
     // мы в профиле?
     $current_profile = cmsModel::getCachedResult('current_profile');
     if ($this->getOption('auto_user') && $current_profile) {
         $this->disableCache();
         $current_profile['user_id'] = $current_profile['id'];
         $this->photo_params = $current_profile;
         $photo->model->filterEqual('user_id', $current_profile['id']);
     }
     // мы на странице записи типа контента?
     $current_ctype_item = cmsModel::getCachedResult('current_ctype_item');
     if ($this->getOption('auto_ctype_item') && $current_ctype_item) {
         $this->disableCache();
         $photo->model->filterRelated('title', $current_ctype_item['title']);
     }
     // мы на странице группы?
     $current_group = cmsModel::getCachedResult('current_group');
     if ($this->getOption('auto_group') && $current_group) {
         $this->disableCache();
         $group_albums = cmsCore::getModel('content')->limit(false)->filterEqual('parent_id', $current_group['id'])->filterEqual('parent_type', 'group')->getContentItemsForSitemap('albums', array('id'));
         if ($group_albums) {
             foreach ($group_albums as $group_album) {
                 $albums_ids[] = $group_album['id'];
             }
             $photo->model->filterIn('album_id', $albums_ids);
         }
     }
     // альбом
     if ($this->getOption('album_id')) {
         $this->photo_params['id'] = $this->getOption('album_id');
         $this->photo_params['user_id'] = 0;
         $photo->model->filterEqual('album_id', $this->getOption('album_id'));
     }
     // типы альбомов
     switch ($this->getOption('target')) {
         case 1:
             // общие
             $photo->model->joinInner('con_albums', 'a', 'a.id = i.album_id');
             $photo->model->filterEqual('a.is_public', 1);
             break;
         case 2:
             // личные
             $photo->model->joinInner('con_albums', 'a', 'a.id = i.album_id');
             $photo->model->filterEqual('a.is_public', null);
             break;
     }
     // остальные опции
     if ($this->getOption('ordering')) {
         $photo->model->orderBy($this->getOption('ordering'), 'desc');
     }
     if (cmsUser::isAllowed('albums', 'view_all')) {
         $photo->model->disablePrivacyFilter();
     }
     if ($this->getOption('type')) {
         $photo->model->filterEqual('type', $this->getOption('type'));
     }
     if ($this->getOption('orientation')) {
         $photo->model->filterEqual('orientation', $this->getOption('orientation'));
     }
     if ($this->getOption('width')) {
         $photo->model->filterGtEqual('width', $this->getOption('width'));
     }
     if ($this->getOption('height')) {
         $photo->model->filterGtEqual('height', $this->getOption('height'));
     }
     $photo->model->limit($this->getOption('limit', 10));
     $photos = $photo->getPhotosList();
     if (!$photos) {
         return false;
     }
     $is_owner = cmsUser::isAllowed('albums', 'delete', 'all') || cmsUser::isAllowed('albums', 'delete', 'own') && ($user->id && $this->photo_params['user_id'] == $user->id);
     return array('row_height' => $photo->getRowHeight(), 'user' => $user, 'item' => $this->photo_params, 'photos' => $photos, 'is_owner' => $is_owner, 'preset_small' => $photo->options['preset_small']);
 }
Beispiel #3
0
 public function run()
 {
     $ctype_id = $this->getOption('ctype_id');
     $dataset_id = $this->getOption('dataset');
     $cat_id = $this->getOption('category_id');
     $image_field = $this->getOption('image_field');
     $teaser_field = $this->getOption('teaser_field');
     $is_show_details = $this->getOption('show_details');
     $style = $this->getOption('style', 'basic');
     $limit = $this->getOption('limit', 10);
     $teaser_len = $this->getOption('teaser_len', 100);
     $model = cmsCore::getModel('content');
     $ctype = $model->getContentType($ctype_id);
     if (!$ctype) {
         return false;
     }
     if ($cat_id) {
         $category = $model->getCategory($ctype['name'], $cat_id);
     } else {
         $category = false;
     }
     if ($dataset_id) {
         $dataset = $model->getContentDataset($dataset_id);
         if ($dataset) {
             $model->applyDatasetFilters($dataset);
         } else {
             $dataset_id = false;
         }
     }
     if ($category) {
         $model->filterCategory($ctype['name'], $category, true);
     }
     // Приватность
     // флаг показа только названий
     $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)) {
         $model->disablePrivacyFilter();
         if ($ctype['options']['privacy_type'] != 'show_title') {
             $hide_except_title = false;
         }
     }
     // А потом, если разрешено правами доступа, отключаем фильтр приватности
     if (cmsUser::isAllowed($ctype['name'], 'view_all')) {
         $model->disablePrivacyFilter();
         $hide_except_title = false;
     }
     // Скрываем записи из скрытых родителей (приватных групп и т.п.)
     $model->filterHiddenParents();
     if ($this->getOption('widget_type') == 'related') {
         // мы на странице записи типа контента?
         $current_ctype_item = cmsModel::getCachedResult('current_ctype_item');
         if ($current_ctype_item) {
             $this->disableCache();
             $model->filterRelated('title', $current_ctype_item['title']);
             if ($current_ctype_item['ctype_name'] == $ctype['name']) {
                 $model->filterNotEqual('id', $current_ctype_item['id']);
             }
         } else {
             return false;
         }
     }
     list($ctype, $model) = cmsEventsManager::hook("content_list_filter", array($ctype, $model));
     list($ctype, $model) = cmsEventsManager::hook("content_{$ctype['name']}_list_filter", array($ctype, $model));
     $items = $model->limit($limit)->getContentItems($ctype['name']);
     if (!$items) {
         return false;
     }
     list($ctype, $items) = cmsEventsManager::hook("content_before_list", array($ctype, $items));
     list($ctype, $items) = cmsEventsManager::hook("content_{$ctype['name']}_before_list", array($ctype, $items));
     if ($style) {
         $this->setTemplate('list_' . $style);
     } else {
         $this->setTemplate($this->tpl_body);
     }
     return array('ctype' => $ctype, 'hide_except_title' => $hide_except_title, 'teaser_len' => $teaser_len, 'image_field' => $image_field, 'teaser_field' => $teaser_field, 'is_show_details' => $is_show_details, 'style' => $style, 'items' => $items);
 }
Beispiel #4
0
 public function run()
 {
     $ctype_name = $this->getOption('ctype_name');
     $core = cmsCore::getInstance();
     $user = cmsUser::getInstance();
     $category = array('id' => 1);
     if (!$ctype_name) {
         $ctype = cmsModel::getCachedResult('current_ctype');
         if (!$ctype) {
             return false;
         }
         $ctype_name = $ctype['name'];
         if (strpos($core->uri, '.html') === false) {
             $current_ctype_category = cmsModel::getCachedResult('current_ctype_category');
             if (!empty($current_ctype_category['id'])) {
                 $category = $current_ctype_category;
             }
         } else {
             $item = cmsModel::getCachedResult('current_ctype_item');
             if (!$item) {
                 return false;
             }
             if (!empty($item['category'])) {
                 $category = $item['category'];
             }
         }
         $fields = cmsModel::getCachedResult('current_ctype_fields');
         $props = cmsModel::getCachedResult('current_ctype_props');
         $props_fields = cmsModel::getCachedResult('current_ctype_props_fields');
         if ($props_fields === null) {
             $props_fields = cmsCore::getController('content')->getPropsFields($props);
         }
     } else {
         $content_controller = cmsCore::getController('content');
         $fields = $content_controller->model->getContentFields($ctype_name);
         $props = $content_controller->model->getContentProps($ctype_name, $category['id']);
         $props_fields = $content_controller->getPropsFields($props);
     }
     if (!$fields && !$props) {
         return false;
     }
     $fields_count = 0;
     foreach ($fields as $field) {
         if ($field['is_in_filter'] && (empty($field['filter_view']) || $user->isInGroups($field['filter_view']))) {
             $fields_count++;
             break;
         }
     }
     if (!$fields_count && !empty($props_fields)) {
         foreach ($props as $prop) {
             if ($prop['is_in_filter']) {
                 $fields_count++;
                 break;
             }
         }
     }
     if (!$fields_count) {
         return false;
     }
     $filters = array();
     foreach ($fields as $name => $field) {
         if (!$field['is_in_filter']) {
             continue;
         }
         if (!$core->request->has($name)) {
             continue;
         }
         $value = $core->request->get($name, false, $field['handler']->getDefaultVarType(true));
         if (!$value) {
             continue;
         }
         $filters[$name] = $value;
     }
     if (!empty($props)) {
         foreach ($props as $prop) {
             $name = "p{$prop['id']}";
             if (!$prop['is_in_filter']) {
                 continue;
             }
             if (!$core->request->has($name)) {
                 continue;
             }
             $prop['handler'] = $props_fields[$prop['id']];
             $value = $core->request->get($name, false, $prop['handler']->getDefaultVarType(true));
             if (!$value) {
                 continue;
             }
             $filters[$name] = $value;
         }
     }
     return array('ctype_name' => $ctype_name, 'page_url' => $core->uri_absolute, 'fields' => $fields, 'props_fields' => $props_fields, 'props' => $props, 'filters' => $filters);
 }