Beispiel #1
0
 public function run($ctype_name = false)
 {
     $user = cmsUser::getInstance();
     $template = cmsTemplate::getInstance();
     $counts = $this->model->getTasksCounts($user->id);
     $is_moderator = $this->model->isUserModerator($user->id);
     if (!$is_moderator) {
         cmsCore::error404();
     }
     if (!$counts) {
         return $template->render('empty');
     }
     $is_index = false;
     $ctypes_list = array_keys($counts);
     if (!$ctype_name) {
         $ctype_name = $ctypes_list[0];
         $is_index = true;
     }
     $content_controller = cmsCore::getController('content');
     $ctypes = $content_controller->model->filterIn('name', $ctypes_list)->getContentTypesFiltered();
     $ctypes = array_collection_to_list($ctypes, 'name', 'title');
     $ctype = $content_controller->model->getContentTypeByName($ctype_name);
     $content_controller->model->filterByModeratorTask($user->id, $ctype_name);
     $page_url = $is_index ? href_to($this->name) : href_to($this->name, $ctype_name);
     $content_controller->model->disableApprovedFilter();
     $list_html = $content_controller->renderItemsList($ctype, $page_url, true);
     return $template->render('index', array('is_index' => $is_index, 'counts' => $counts, 'ctype' => $ctype, 'ctypes' => $ctypes, 'ctype_name' => $ctype_name, 'list_html' => $list_html, 'user' => $user));
 }
 public function init()
 {
     return array(array('type' => 'fieldset', 'title' => LANG_ACTIVITY_OPT_TYPES, 'childs' => array(new fieldList('types', array('is_multiple' => true, 'generator' => function () {
         $types = cmsCore::getModel('activity')->getTypes();
         return array_collection_to_list($types, 'id', 'title');
     })))));
 }
Beispiel #3
0
 public function init()
 {
     return array(array('type' => 'fieldset', 'title' => LANG_ACTIVITY_OPT_TYPES, 'childs' => array(new fieldList('types', array('is_multiple' => true, 'generator' => function () {
         $types = cmsCore::getModel('activity')->getTypes();
         return array_collection_to_list($types, 'id', 'title');
     })))), array('type' => 'fieldset', 'title' => LANG_LIST_LIMIT, 'childs' => array(new fieldNumber('limit', array('default' => 15, 'rules' => array(array('required')))))));
 }
Beispiel #4
0
 public function run($feed_id)
 {
     if (!$feed_id) {
         cmsCore::error404();
     }
     $rss_model = cmsCore::getModel('rss');
     $feed = $rss_model->getFeed($feed_id);
     $ctype_id = $feed['ctype_id'];
     $content_model = cmsCore::getModel('content');
     $fields = $content_model->getContentFields($feed['ctype_name']);
     $fields = array('' => '') + array_collection_to_list($fields, 'name', 'title');
     $form = $this->getForm('feed', array($fields));
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         $feed = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $feed);
         if (!$errors) {
             $rss_model->updateFeed($feed_id, $feed);
             $ctype = $content_model->getContentType($ctype_id);
             $ctype['options']['is_rss'] = $feed['is_enabled'];
             $content_model->updateContentType($ctype_id, array('options' => $ctype['options']));
             $this->redirectToAction();
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/edit', array('feed' => $feed, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
 public function init($do)
 {
     return array('basic' => array('type' => 'fieldset', 'title' => '', 'childs' => array(new fieldList('vocabulary_id', array('title' => LANG_TAXONOMY_TERMS_VOCABULARY, 'generator' => function () {
         $model = cmsCore::getModel('taxonomy');
         $vocabularies = $model->getVocabularies();
         return array_collection_to_list($vocabularies, 'id', 'title');
     }, 'rules' => array(array('required')))), new fieldText('title', array('title' => LANG_TAXONOMY_TERMS_TITLES, 'hint' => LANG_TAXONOMY_TERMS_TITLES_HINT, 'rules' => array(array('required')))))));
 }
 public function init()
 {
     return array(array('type' => 'fieldset', 'title' => LANG_SEARCH_IN_CTYPES, 'childs' => array(new fieldList('ctypes', array('is_multiple' => true, 'generator' => function () {
         $ctypes = cmsCore::getModel('content')->getContentTypes();
         $items = array_collection_to_list($ctypes, 'name', 'title');
         return $items;
     })))), array('type' => 'fieldset', 'title' => LANG_SEARCH_PERPAGE, 'childs' => array(new fieldNumber('perpage', array('default' => 15, 'rules' => array(array('required')))))));
 }
 public function init($do)
 {
     $groups = cmsCore::getModel('users')->getGroups();
     return array('basic' => array('type' => 'fieldset', 'childs' => array(new fieldString('title', array('title' => LANG_USERS_MIG_TITLE, 'rules' => array(array('required'), array('max_length', 256)))), new fieldCheckbox('is_active', array('title' => LANG_USERS_MIG_IS_ACTIVE)))), array('type' => 'fieldset', 'childs' => array(new fieldList('is_keep_group', array('title' => LANG_USERS_MIG_ACTION, 'items' => array(0 => LANG_USERS_MIG_ACTION_CHANGE, 1 => LANG_USERS_MIG_ACTION_ADD))), new fieldList('group_from_id', array('title' => LANG_USERS_MIG_FROM, 'generator' => function () use($groups) {
         return array_collection_to_list($groups, 'id', 'title');
     })), new fieldList('group_to_id', array('title' => LANG_USERS_MIG_TO, 'generator' => function () use($groups) {
         return array_collection_to_list($groups, 'id', 'title');
     })))), array('type' => 'fieldset', 'childs' => array(new fieldCheckbox('is_passed', array('title' => LANG_USERS_MIG_COND_DATE)), new fieldList('passed_from', array('title' => LANG_USERS_MIG_PASSED_FROM, 'items' => array(0 => LANG_USERS_MIG_PASSED_REG, 1 => LANG_USERS_MIG_PASSED_MIG))), new fieldNumber('passed_days', array('title' => LANG_USERS_MIG_PASSED)))), array('type' => 'fieldset', 'childs' => array(new fieldCheckbox('is_rating', array('title' => LANG_USERS_MIG_COND_RATING)), new fieldNumber('rating', array('title' => LANG_USERS_MIG_RATING)))), array('type' => 'fieldset', 'childs' => array(new fieldCheckbox('is_karma', array('title' => LANG_USERS_MIG_COND_KARMA)), new fieldNumber('karma', array('title' => LANG_USERS_MIG_KARMA)))), array('type' => 'fieldset', 'childs' => array(new fieldCheckbox('is_notify', array('title' => LANG_USERS_MIG_NOTIFY)), new fieldHtml('notify_text', array('title' => LANG_USERS_MIG_NOTIFY_TEXT, 'options' => array('editor' => cmsConfig::get('default_editor')))))));
 }
 public function init($do)
 {
     return array('basic' => array('type' => 'fieldset', 'title' => '', 'childs' => array(new fieldString('title', array('title' => LANG_TAXONOMY_VOCABULARY_TITLE, 'rules' => array(array('max_length', 255), array('required')))), new fieldString('name', array('title' => LANG_TAXONOMY_VOCABULARY_NAME, 'hint' => LANG_TAXONOMY_VOCABULARY_NAME_HINT, 'rules' => array(array('max_length', 255), array('required'), array('sysname'), $do == 'add' ? array('unique', 'menu', 'name') : false))))), array('type' => 'fieldset', 'title' => LANG_TAXONOMY_VOCABULARY_IN_CTYPES, 'childs' => array(new fieldList('ctypes', array('is_multiple' => true, 'generator' => function () {
         $content_model = cmsCore::getModel('content');
         $ctypes = $content_model->getContentTypes();
         $items = array_collection_to_list($ctypes, 'name', 'title');
         return $items;
     })))));
 }
Beispiel #9
0
 public function run()
 {
     $ctypes = $this->model->getContentTypes();
     $sources = array_collection_to_list($ctypes, 'name', 'title');
     foreach ($sources as $name => $title) {
         $sources[$name] = LANG_CONTENT_CONTROLLER . ': ' . $title;
     }
     return array('name' => $this->name, 'sources' => $sources);
 }
 public function run($data)
 {
     list($form, $feed) = $data;
     $fields = $this->model->getContentFields($feed['ctype_name']);
     $fields = array('' => '') + array_collection_to_list($fields, 'name', 'title');
     $form->addFieldset(LANG_RSS_FEED_MAPPING, 'mapping', array('childs' => array(new fieldList('mapping:title', array('title' => LANG_RSS_FEED_MAP_TITLE, 'items' => $fields)), new fieldList('mapping:description', array('title' => LANG_RSS_FEED_MAP_DESC, 'items' => $fields)), new fieldList('mapping:pubDate', array('title' => LANG_RSS_FEED_MAP_DATE, 'items' => $fields)), new fieldList('mapping:image', array('title' => LANG_RSS_FEED_MAP_IMAGE, 'items' => $fields)), new fieldList('mapping:image_size', array('title' => LANG_RSS_FEED_MAP_IMAGE_SIZE, 'generator' => function ($item) {
         return array('original' => LANG_PARSER_IMAGE_SIZE_ORIGINAL) + cmsCore::getModel('images')->getPresetsList();
     })))));
     return array($form, $feed);
 }
Beispiel #11
0
 public function applyFilter($model, $value)
 {
     $users_model = cmsCore::getModel('users');
     $users = $users_model->filterLike('nickname', "%{$value}%")->getUsers();
     if (!$users) {
         return $model->filterIsNull($this->name . '_id');
     } else {
         $users_ids = array_collection_to_list($users, 'id', 'id');
         return $model->filterIn($this->name . '_id', $users_ids);
     }
 }
Beispiel #12
0
 public function run()
 {
     $ctypes = $this->model->getContentTypes();
     $sources = array_collection_to_list($ctypes, 'name', 'title');
     foreach ($sources as $name => $title) {
         $sources[$name] = $title;
     }
     // по каким полям поиск
     $match_fields = array();
     // какие поля получать
     $select_fields = array();
     // из каких таблиц выборка
     $table_names = array();
     // какие поля точно нужны
     $default_fields = array('id', 'slug', 'date_pub');
     foreach ($ctypes as $ctype) {
         $fields = $this->model->getContentFields($ctype['name']);
         $table_names[$ctype['name']] = $this->model->getContentTypeTableName($ctype['name']);
         $select_fields[$ctype['name']] = $default_fields;
         foreach ($fields as $field) {
             // индексы создаются только на поля типа caption, text, html
             // в настройках полей должно быть включено их участие в индексе
             $is_text = in_array($field['type'], array('caption', 'text', 'html')) && $field['handler']->getOption('in_fulltext_search');
             if ($is_text && !$field['is_private'] && (!$field['groups_read'] || $this->cms_user->isInGroups($field['groups_read']))) {
                 $match_fields[$ctype['name']][] = $field['name'];
                 $select_fields[$ctype['name']][] = $field['name'];
             }
             if ($field['type'] == 'image' && !$field['is_private'] && (!$field['groups_read'] || $this->cms_user->isInGroups($field['groups_read']))) {
                 $select_fields[$ctype['name']]['image'] = $field['name'];
             }
         }
         $filters[$ctype['name']] = array(array('condition' => '=', 'value' => 1, 'field' => 'is_pub'), array('condition' => '=', 'value' => 1, 'field' => 'is_approved'), array('condition' => 'IS', 'value' => NULL, 'field' => 'is_parent_hidden'));
         $_ctypes[$ctype['name']] = $ctype;
     }
     return array('name' => $this->name, 'sources' => $sources, 'table_names' => $table_names, 'match_fields' => $match_fields, 'select_fields' => $select_fields, 'filters' => $filters, 'item_callback' => function ($item, $model, $sources_name, $match_fields, $select_fields) use($_ctypes) {
         $fields = array();
         foreach ($match_fields as $match_field) {
             if ($match_field == 'title') {
                 continue;
             }
             $fields[$match_field] = $item[$match_field];
         }
         return array_merge($item, array('url' => href_to($sources_name, $item['slug'] . '.html'), 'ctype' => $_ctypes[$sources_name], 'title' => $item['title'], 'fields' => $fields, 'date_pub' => $item['date_pub'], 'image' => !empty($select_fields['image']) ? html_image($item[$select_fields['image']], 'small', strip_tags($item['title'])) : ''));
     });
 }
Beispiel #13
0
 private function createCategories($content_model, $ctype, $data)
 {
     $list = explode("\n", $data['title']);
     $levels_ids = array();
     $cats_ids = array();
     $parent_props = $content_model->getContentPropsBinds($ctype['name'], $data['parent_id']);
     $parent_props = array_collection_to_list($parent_props, 'id', 'prop_id');
     $is_first = true;
     $remove_level_offset = 0;
     foreach ($list as $category_title) {
         $category_title = trim($category_title);
         if (!$category_title) {
             continue;
         }
         $level = mb_strlen(str_replace(' ', '', $category_title)) - mb_strlen(ltrim(str_replace(' ', '', $category_title), '- '));
         //			dump($level.': '.ltrim($category_title, '- '), false);
         if ($is_first && $level > 0) {
             $remove_level_offset = $level;
         }
         $level = $level - $remove_level_offset;
         $is_sub = $level > 0;
         $is_first = false;
         $category_title = ltrim($category_title, '- ');
         if (!$is_sub) {
             $levels_ids = array();
             $result = $content_model->addCategory($ctype['name'], array('parent_id' => $data['parent_id'], 'title' => $category_title));
             $levels_ids[0] = $result['id'];
             $cats_ids[] = $result['id'];
             continue;
         }
         $parent_id = $levels_ids[$level - 1];
         if (!$category_title) {
             $category_title = 'untitled';
         }
         $result = $content_model->addCategory($ctype['name'], array('parent_id' => $parent_id, 'title' => ltrim($category_title, '- ')));
         $levels_ids[$level] = $result['id'];
         $cats_ids[] = $result['id'];
     }
     //		die();
     if ($data['is_inherit_binds'] && $parent_props && $cats_ids) {
         foreach ($parent_props as $prop_id) {
             $content_model->bindContentProp($ctype['name'], $prop_id, $cats_ids);
         }
     }
 }
Beispiel #14
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     if (!cmsUser::isAdmin()) {
         cmsCore::error404();
     }
     $ctype_id = $this->request->get('value', 0);
     if (!$ctype_id) {
         cmsCore::error404();
     }
     $datasets = $this->model->getContentDatasets($ctype_id);
     $list = array();
     if ($datasets) {
         $list = array('0' => '') + array_collection_to_list($datasets, 'id', 'title');
     }
     cmsTemplate::getInstance()->renderJSON($list);
 }
Beispiel #15
0
 public function init($options = false)
 {
     $cats_list = array();
     $datasets_list = array('0' => '');
     $fields_list = array('' => '');
     if (!empty($options['ctype_id'])) {
         $content_model = cmsCore::getModel('content');
         $ctype = $content_model->getContentType($options['ctype_id']);
         $cats = $content_model->getCategoriesTree($ctype['name']);
         if ($cats) {
             foreach ($cats as $cat) {
                 if ($cat['ns_level'] > 1) {
                     $cat['title'] = str_repeat('-', $cat['ns_level']) . ' ' . $cat['title'];
                 }
                 $cats_list[$cat['id']] = $cat['title'];
             }
         }
         $datasets = $content_model->getContentDatasets($options['ctype_id']);
         if ($datasets) {
             $datasets_list = array(0 => '') + array_collection_to_list($datasets, 'id', 'title');
         }
         $fields = $content_model->getContentFields($ctype['name']);
         if ($fields) {
             $fields_list = array('' => '') + array_collection_to_list($fields, 'name', 'title');
         }
     }
     return array(array('type' => 'fieldset', 'title' => LANG_OPTIONS, 'childs' => array(new fieldList('options:ctype_id', array('title' => LANG_CONTENT_TYPE, 'generator' => function ($item) {
         $model = cmsCore::getModel('content');
         $tree = $model->getContentTypes();
         $items = array();
         if ($tree) {
             foreach ($tree as $item) {
                 $items[$item['id']] = $item['title'];
             }
         }
         return $items;
     })), new fieldList('options:category_id', array('title' => LANG_CATEGORY, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_cats_ajax')), 'items' => $cats_list)), new fieldList('options:dataset', array('title' => LANG_WD_CONTENT_SLIDER_DATASET, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_datasets_ajax')), 'items' => $datasets_list)), new fieldList('options:image_field', array('title' => LANG_WD_CONTENT_SLIDER_IMAGE, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_fields_ajax')), 'items' => $fields_list)), new fieldList('options:big_image_field', array('title' => LANG_WD_CONTENT_SLIDER_BIG_IMAGE, 'hint' => LANG_WD_CONTENT_SLIDER_BIG_IMAGE_HINT, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_fields_ajax')), 'items' => $fields_list)), new fieldList('options:big_image_preset', array('title' => LANG_WD_CONTENT_SLIDER_BIG_IMAGE_PRESET, 'generator' => function ($item) {
         return cmsCore::getModel('images')->getPresetsList() + array('original' => LANG_PARSER_IMAGE_SIZE_ORIGINAL);
     })), new fieldList('options:teaser_field', array('title' => LANG_WD_CONTENT_SLIDER_TEASER, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_fields_ajax')), 'items' => $fields_list)), new fieldNumber('options:delay', array('title' => LANG_WD_CONTENT_SLIDER_DELAY, 'hint' => LANG_WD_CONTENT_SLIDER_DELAY_HINT, 'default' => 5, 'units' => LANG_SECOND10)), new fieldNumber('options:limit', array('title' => LANG_LIST_LIMIT, 'default' => 4, 'rules' => array(array('required')))))));
 }
Beispiel #16
0
 public function init($options = false)
 {
     $cats_list = array();
     $datasets_list = array('0' => '');
     $fields_list = array('' => '');
     if (!empty($options['ctype_id'])) {
         $content_model = cmsCore::getModel('content');
         $ctype = $content_model->getContentType($options['ctype_id']);
         $cats = $content_model->getCategoriesTree($ctype['name']);
         if ($cats) {
             foreach ($cats as $cat) {
                 if ($cat['ns_level'] > 1) {
                     $cat['title'] = str_repeat('-', $cat['ns_level']) . ' ' . $cat['title'];
                 }
                 $cats_list[$cat['id']] = $cat['title'];
             }
         }
         $datasets = $content_model->getContentDatasets($options['ctype_id']);
         if ($datasets) {
             $datasets_list = array('0' => '') + array_collection_to_list($datasets, 'id', 'title');
         }
         $fields = $content_model->getContentFields($ctype['name']);
         if ($fields) {
             $fields_list = array('' => '') + array_collection_to_list($fields, 'name', 'title');
         }
     }
     return array(array('type' => 'fieldset', 'title' => LANG_OPTIONS, 'childs' => array(new fieldList('options:ctype_id', array('title' => LANG_CONTENT_TYPE, 'generator' => function ($item) {
         $model = cmsCore::getModel('content');
         $tree = $model->getContentTypes();
         $items = array();
         if ($tree) {
             foreach ($tree as $item) {
                 $items[$item['id']] = $item['title'];
             }
         }
         return $items;
     })), new fieldList('options:category_id', array('title' => LANG_CATEGORY, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_cats_ajax')), 'items' => $cats_list)), new fieldList('options:dataset', array('title' => LANG_WD_CONTENT_LIST_DATASET, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_datasets_ajax')), 'items' => $datasets_list)), new fieldList('options:image_field', array('title' => LANG_WD_CONTENT_LIST_IMAGE, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_fields_ajax')), 'items' => $fields_list)), new fieldList('options:teaser_field', array('title' => LANG_WD_CONTENT_LIST_TEASER, 'parent' => array('list' => 'options:ctype_id', 'url' => href_to('content', 'widget_fields_ajax')), 'items' => $fields_list)), new fieldList('options:style', array('title' => LANG_WD_CONTENT_LIST_STYLE, 'default' => 'basic', 'items' => array('basic' => LANG_WD_CONTENT_LIST_STYLE_BASIC, 'featured' => LANG_WD_CONTENT_LIST_STYLE_FEATURED, 'tiles_big' => LANG_WD_CONTENT_LIST_STYLE_TILES_BIG, 'tiles_small' => LANG_WD_CONTENT_LIST_STYLE_TILES_SMALL, 'compact' => LANG_WD_CONTENT_LIST_STYLE_COMPACT))), new fieldCheckbox('options:show_details', array('title' => LANG_WD_CONTENT_LIST_DETAILS)), new fieldNumber('options:limit', array('title' => LANG_LIST_LIMIT, 'default' => 10, 'rules' => array(array('required')))))));
 }
Beispiel #17
0
 public function init($do, $ctype_name)
 {
     $model = cmsCore::getModel('content');
     return array('basic' => array('type' => 'fieldset', 'childs' => array(new fieldString('name', array('title' => LANG_SYSTEM_NAME, 'hint' => $do == 'edit' ? LANG_SYSTEM_EDIT_NOTICE : false, 'rules' => array(array('required'), array('sysname'), array('max_length', 20), $do == 'add' ? array('unique_ctype_field', $ctype_name) : false))), new fieldString('title', array('title' => LANG_CP_FIELD_TITLE, 'rules' => array(array('required'), array('max_length', 100)))), new fieldString('hint', array('title' => LANG_CP_FIELD_HINT, 'rules' => array(array('max_length', 255)))))), 'type' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_TYPE, 'childs' => array(new fieldList('type', array('default' => 'string', 'generator' => function () {
         $field_types = array();
         $field_types = cmsForm::getAvailableFormFields();
         asort($field_types, SORT_STRING);
         return $field_types;
     })))), 'group' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_FIELDSET, 'childs' => array(new fieldList('fieldset', array('title' => LANG_CP_FIELD_FIELDSET_SELECT, 'generator' => function ($field) use($model) {
         $fieldsets = $model->getContentFieldsets($field['ctype_id']);
         $items = array('');
         foreach ($fieldsets as $fieldset) {
             $items[$fieldset] = $fieldset;
         }
         return $items;
     })), new fieldString('new_fieldset', array('title' => LANG_CP_FIELD_FIELDSET_ADD, 'rules' => array(array('max_length', 100)))))), 'visibility' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_VISIBILITY, 'childs' => array(new fieldCheckbox('is_in_item', array('title' => LANG_CP_FIELD_IN_ITEM, 'default' => true)), new fieldCheckbox('is_in_list', array('title' => LANG_CP_FIELD_IN_LIST)), new fieldCheckbox('is_in_filter', array('title' => LANG_CP_FIELD_IN_FILTER)))), 'labels' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_LABELS, 'childs' => array(new fieldList('options:label_in_list', array('title' => LANG_CP_FIELD_LABELS_IN_LIST, 'default' => 'left', 'items' => array('left' => LANG_CP_FIELD_LABEL_LEFT, 'top' => LANG_CP_FIELD_LABEL_TOP, 'none' => LANG_CP_FIELD_LABEL_NONE))), new fieldList('options:label_in_item', array('title' => LANG_CP_FIELD_LABELS_IN_ITEM, 'default' => 'left', 'items' => array('left' => LANG_CP_FIELD_LABEL_LEFT, 'top' => LANG_CP_FIELD_LABEL_TOP, 'none' => LANG_CP_FIELD_LABEL_NONE))))), 'wrap' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_WRAP, 'childs' => array(new fieldList('options:wrap_type', array('title' => LANG_CP_FIELD_WRAP_TYPE, 'default' => 'auto', 'items' => array('left' => LANG_CP_FIELD_WRAP_LTYPE, 'right' => LANG_CP_FIELD_WRAP_RTYPE, 'none' => LANG_CP_FIELD_WRAP_NTYPE, 'auto' => LANG_CP_FIELD_WRAP_ATYPE))), new fieldString('options:wrap_width', array('title' => LANG_CP_FIELD_WRAP_WIDTH, 'hint' => LANG_CP_FIELD_WRAP_WIDTH_HINT, 'default' => '')))), 'format' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_FORMAT, 'childs' => array(new fieldCheckbox('options:is_required', array('title' => LANG_VALIDATE_REQUIRED)), new fieldCheckbox('options:is_digits', array('title' => LANG_VALIDATE_DIGITS)), new fieldCheckbox('options:is_alphanumeric', array('title' => LANG_VALIDATE_ALPHANUMERIC)), new fieldCheckbox('options:is_email', array('title' => LANG_VALIDATE_EMAIL)), new fieldCheckbox('options:is_unique', array('title' => LANG_VALIDATE_UNIQUE)))), 'values' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_VALUES, 'childs' => array(new fieldText('values', array('size' => 8)))), 'profile' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_PROFILE_VALUE, 'childs' => array(new fieldList('options:profile_value', array('hint' => LANG_CP_FIELD_PROFILE_VALUE_HINT, 'generator' => function ($field) use($model) {
         $model->setTablePrefix('');
         // Ниже модель не используется
         $fields = $model->filterIn('type', array('string', 'text', 'html', 'list', 'city'))->getContentFields('{users}');
         $items = array('' => LANG_NO) + array_collection_to_list($fields, 'name', 'title');
         return $items;
     })))), 'read_access' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_GROUPS_READ, 'childs' => array(new fieldListGroups('groups_read', array('show_all' => true)))), 'edit_access' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_GROUPS_EDIT, 'childs' => array(new fieldListGroups('groups_edit', array('show_all' => true)))), 'filter_access' => array('type' => 'fieldset', 'title' => LANG_CP_FIELD_IN_FILTER, 'childs' => array(new fieldListGroups('filter_view', array('show_all' => true)))));
 }
Beispiel #18
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     if (!cmsUser::isAdmin()) {
         cmsCore::error404();
     }
     $ctype_id = $this->request->get('value', 0);
     if (!$ctype_id) {
         cmsCore::error404();
     }
     $ctype = $this->model->getContentType($ctype_id);
     if (!$ctype) {
         cmsCore::error404();
     }
     $fields = $this->model->getContentFields($ctype['name']);
     $list = array();
     if ($fields) {
         $list = array('' => '') + array_collection_to_list($fields, 'name', 'title');
     }
     cmsTemplate::getInstance()->renderJSON($list);
 }
Beispiel #19
0
 public function deleteUserMemberships($user_id)
 {
     cmsCache::getInstance()->clean("groups.members");
     $groups_ids = array_collection_to_list($this->getUserGroups($user_id), 'id', 'id');
     if (!$groups_ids) {
         return false;
     }
     $this->filterIn('id', $groups_ids);
     $this->decrement('groups', 'members_count');
     return $this->delete('groups_members', $user_id, 'user_id');
 }
Beispiel #20
0
                        <?php 
        echo html_submit('+');
        ?>
                        <label id="is_childs">
                            <?php 
        echo html_checkbox('is_childs', true);
        ?>
                            <?php 
        echo LANG_CP_PROPS_BIND_RECURSIVE;
        ?>
                        </label>
                    </div>
                </form>
                <div style="display:none">
                    <?php 
        echo html_select('props_list', array_collection_to_list($props, 'id', 'title'));
        ?>
                </div>
            <?php 
    }
    ?>

            <div class="buttons">
                <?php 
    echo html_button(LANG_SAVE_ORDER, 'save_button', "icms.datagrid.submit('{$this->href_to('ctypes', array('props_reorder', $ctype['name']))}')");
    ?>
            </div>

        </td>
    </tr>
</table>
Beispiel #21
0
 public function run()
 {
     // Получаем название типа контента и сам тип
     $ctype = $this->model->getContentTypeByName($this->request->get('ctype_name', ''));
     if (!$ctype) {
         cmsCore::error404();
     }
     $id = $this->request->get('id', 0);
     if (!$id) {
         cmsCore::error404();
     }
     // Получаем нужную запись
     $item = $this->model->getContentItem($ctype['name'], $id);
     if (!$item) {
         cmsCore::error404();
     }
     // проверяем наличие доступа
     if (!cmsUser::isAllowed($ctype['name'], 'edit')) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed($ctype['name'], 'edit', 'all')) {
         if (cmsUser::isAllowed($ctype['name'], 'edit', 'own') && $item['user_id'] != $this->cms_user->id) {
             cmsCore::error404();
         }
     }
     $is_premoderation = $ctype['is_premod_edit'];
     $is_moderator = $this->cms_user->is_admin || $this->model->userIsContentTypeModerator($ctype['name'], $this->cms_user->id);
     if (!$item['is_approved'] && !$is_moderator) {
         cmsCore::error404();
     }
     // Получаем родительский тип, если он задан
     if ($this->request->has('parent_type')) {
         $parent['ctype'] = $this->model->getContentTypeByName($this->request->get('parent_type', ''));
         $parent['item'] = $this->model->getContentItemBySLUG($parent['ctype']['name'], $this->request->get('parent_slug', ''));
     }
     // Определяем наличие полей-свойств
     $props = $this->model->getContentProps($ctype['name']);
     $ctype['props'] = $props;
     // Если включены личные папки - получаем их список
     $folders_list = array();
     if ($ctype['is_folders']) {
         $folders_list = $this->model->getContentFolders($ctype['id'], $item['user_id']);
         $folders_list = array_collection_to_list($folders_list, 'id', 'title');
     }
     // Получаем поля для данного типа контента
     $fields = $this->model->orderBy('ordering')->getContentFields($ctype['name'], $id);
     // Если этот контент можно создавать в группах (сообществах) то получаем список групп
     $groups_list = array();
     if ($ctype['is_in_groups'] || $ctype['is_in_groups_only']) {
         $groups_model = cmsCore::getModel('groups');
         $groups = $groups_model->getUserGroups($this->cms_user->id);
         if ($groups) {
             $groups_list = $ctype['is_in_groups_only'] ? array() : array('0' => '');
             $groups_list = $groups_list + array_collection_to_list($groups, 'id', 'title');
         }
     }
     // Строим форму
     $form = $this->getItemForm($ctype, $fields, 'edit', array('groups_list' => $groups_list, 'folders_list' => $folders_list), $id, $item);
     // Получаем теги
     if ($ctype['is_tags']) {
         $tags_model = cmsCore::getModel('tags');
         $item['tags'] = $tags_model->getTagsStringForTarget($this->name, $ctype['name'], $id);
     }
     list($ctype, $item) = cmsEventsManager::hook('content_edit', array($ctype, $item));
     list($form, $item) = cmsEventsManager::hook("content_{$ctype['name']}_form", array($form, $item));
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     $item['ctype_name'] = $ctype['name'];
     $item['ctype_id'] = $ctype['id'];
     if ($ctype['props']) {
         $item_props = $this->model->getContentProps($ctype['name'], $item['category_id']);
         $item_props_fields = $this->getPropsFields($item_props);
         $item['props'] = $this->model->getPropsValues($ctype['name'], $id);
         foreach ($item_props_fields as $field) {
             $form->addField('props', $field);
         }
     }
     $is_pub_control = cmsUser::isAllowed($ctype['name'], 'pub_on');
     $is_date_pub_allowed = $ctype['is_date_range'] && cmsUser::isAllowed($ctype['name'], 'pub_late');
     $is_date_pub_end_allowed = $ctype['is_date_range'] && cmsUser::isAllowed($ctype['name'], 'pub_long', 'any');
     $is_date_pub_days_allowed = $ctype['is_date_range'] && cmsUser::isAllowed($ctype['name'], 'pub_long', 'days');
     $is_date_pub_ext_allowed = $is_date_pub_days_allowed && cmsUser::isAllowed($ctype['name'], 'pub_max_ext');
     if ($is_date_pub_ext_allowed) {
         $item['pub_days'] = 0;
     }
     $add_cats = $this->model->getContentItemCategories($ctype['name'], $id);
     if ($add_cats) {
         foreach ($add_cats as $index => $cat_id) {
             if ($cat_id == $item['category_id']) {
                 unset($add_cats[$index]);
                 break;
             }
         }
     }
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $item = array_merge($item, $form->parse($this->request, $is_submitted, $item));
         // Проверям правильность заполнения
         $errors = $form->validate($this, $item);
         if (!$errors) {
             list($item, $errors) = cmsEventsManager::hook('content_validate', array($item, $errors));
         }
         if (!$errors) {
             unset($item['ctype_name']);
             unset($item['ctype_id']);
             if (isset($item['parent_id']) && $groups_list) {
                 if (array_key_exists($item['parent_id'], $groups_list) && $item['parent_id'] > 0) {
                     $group = $groups_model->getGroup($item['parent_id']);
                     $item['parent_type'] = 'group';
                     $item['parent_title'] = $groups_list[$item['parent_id']];
                     $item['parent_url'] = href_to_rel('groups', $item['parent_id'], array('content', $ctype['name']));
                     $item['is_parent_hidden'] = $group['is_closed'] ? true : null;
                 } else {
                     $item['parent_id'] = null;
                     $item['parent_type'] = null;
                     $item['parent_title'] = null;
                     $item['parent_url'] = null;
                 }
             }
             $item['is_approved'] = $item['is_approved'] && (!$ctype['is_premod_edit'] || $is_moderator);
             $item['approved_by'] = null;
             if ($ctype['is_auto_keys']) {
                 $item['seo_keys'] = string_get_meta_keywords($item['content']);
             }
             if ($ctype['is_auto_desc']) {
                 $item['seo_desc'] = string_get_meta_description($item['content']);
             }
             if ($ctype['is_tags']) {
                 $tags_model->updateTags($item['tags'], $this->name, $ctype['name'], $id);
                 $item['tags'] = $tags_model->getTagsStringForTarget($this->name, $ctype['name'], $id);
             }
             $date_pub_time = strtotime($item['date_pub']);
             $date_pub_end_time = strtotime($item['date_pub_end']);
             $now_time = time();
             $now_date = strtotime(date('Y-m-d', $now_time));
             $is_pub = true;
             if ($is_date_pub_allowed) {
                 $time_to_pub = $date_pub_time - $now_time;
                 $is_pub = $is_pub && $time_to_pub < 0;
             }
             if ($is_date_pub_end_allowed && !empty($item['date_pub_end'])) {
                 $days_from_pub = floor(($now_date - $date_pub_end_time) / 60 / 60 / 24);
                 $is_pub = $is_pub && $days_from_pub < 1;
             } else {
                 if ($is_date_pub_ext_allowed && !$this->cms_user->is_admin) {
                     $days = $item['pub_days'];
                     $date_pub_end_time = $date_pub_end_time + 60 * 60 * 24 * $days;
                     $days_from_pub = floor(($now_date - $date_pub_end_time) / 60 / 60 / 24);
                     $is_pub = $is_pub && $days_from_pub < 1;
                     $item['date_pub_end'] = date('Y-m-d', $date_pub_end_time);
                 } else {
                     $item['date_pub_end'] = false;
                 }
             }
             unset($item['pub_days']);
             if (!$is_pub_control) {
                 unset($item['is_pub']);
             }
             if (!isset($item['is_pub']) || !empty($item['is_pub'])) {
                 $item['is_pub'] = $is_pub;
                 if (!$is_pub) {
                     cmsUser::addSessionMessage(LANG_CONTENT_IS_PUB_OFF);
                 }
             }
             if (!empty($ctype['options']['is_cats_multi'])) {
                 $add_cats = $this->request->get('add_cats', array());
                 if (is_array($add_cats)) {
                     foreach ($add_cats as $index => $cat_id) {
                         if (!is_numeric($cat_id) || !$cat_id) {
                             unset($add_cats[$index]);
                         }
                     }
                     if ($add_cats) {
                         $item['add_cats'] = $add_cats;
                     }
                 }
             }
             //
             // Сохраняем запись и редиректим на ее просмотр
             //
             $item = cmsEventsManager::hook('content_before_update', $item);
             $item = cmsEventsManager::hook("content_{$ctype['name']}_before_update", $item);
             $item = $this->model->updateContentItem($ctype, $id, $item, $fields);
             $item['ctype_data'] = $ctype;
             cmsEventsManager::hook('content_after_update', $item);
             cmsEventsManager::hook("content_{$ctype['name']}_after_update", $item);
             if ($item['is_approved'] || $is_moderator) {
                 cmsEventsManager::hook('content_after_update_approve', array('ctype_name' => $ctype['name'], 'item' => $item));
                 cmsEventsManager::hook("content_{$ctype['name']}_after_update_approve", $item);
             } else {
                 $this->requestModeration($ctype['name'], $item, false);
             }
             $back_url = $this->request->get('back', '');
             if ($back_url) {
                 $this->redirect($back_url);
             } else {
                 $this->redirectTo($ctype['name'], $item['slug'] . '.html');
             }
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('item_form', array('do' => 'edit', 'ctype' => $ctype, 'parent' => isset($parent) ? $parent : false, 'item' => $item, 'form' => $form, 'props' => $props, 'is_moderator' => $is_moderator, 'is_premoderation' => $is_premoderation, 'is_load_props' => false, 'add_cats' => $add_cats, 'errors' => isset($errors) ? $errors : false));
 }
Beispiel #22
0
 public function run()
 {
     $user = cmsUser::getInstance();
     // Получаем название типа контента
     $ctype_name = $this->request->get('ctype_name');
     // проверяем наличие доступа
     if (!cmsUser::isAllowed($ctype_name, 'add')) {
         cmsCore::error404();
     }
     // Получаем тип контента
     $ctype = $this->model->getContentTypeByName($ctype_name);
     if (!$ctype) {
         cmsCore::error404();
     }
     // проверяем что не превышен лимит на число записей
     $user_items_count = $this->model->getUserContentItemsCount($ctype_name, $user->id, false);
     if (cmsUser::isPermittedLimitReached($ctype_name, 'limit', $user_items_count)) {
         cmsUser::addSessionMessage(sprintf(LANG_CONTENT_COUNT_LIMIT, $ctype['labels']['many']), 'error');
         $this->redirectBack();
     }
     // Проверяем ограничение по карме
     if (cmsUser::isPermittedLimitHigher($ctype_name, 'karma', $user->karma)) {
         cmsUser::addSessionMessage(sprintf(LANG_CONTENT_KARMA_LIMIT, cmsUser::getPermissionValue($ctype_name, 'karma')), 'error');
         $this->redirectBack();
     }
     $item = array();
     if ($ctype['is_cats']) {
         $category_id = $this->request->get('to_id');
     }
     // Определяем наличие полей-свойств
     $props = $this->model->getContentProps($ctype['name']);
     $ctype['props'] = $props;
     // Если этот контент можно создавать в группах (сообществах) то получаем список групп
     $groups_list = array();
     if ($ctype['is_in_groups'] || $ctype['is_in_groups_only']) {
         $groups_model = cmsCore::getModel('groups');
         $groups = $groups_model->getUserGroups($user->id);
         if (!$groups && $ctype['is_in_groups_only']) {
             cmsUser::addSessionMessage(sprintf(LANG_CONTENT_IS_IN_GROUPS_ONLY, $ctype['labels']['many']), 'error');
             $this->redirectBack();
         }
         $groups_list = $ctype['is_in_groups_only'] ? array() : array('0' => '');
         $groups_list = $groups_list + array_collection_to_list($groups, 'id', 'title');
     }
     // Если включены личные папки - получаем их список
     $folders_list = array();
     if ($ctype['is_folders']) {
         $folders_list = $this->model->getContentFolders($ctype['id'], $user->id);
         $folders_list = array_collection_to_list($folders_list, 'id', 'title');
     }
     // Получаем поля для данного типа контента
     $this->model->orderBy('ordering');
     $fields = $this->model->getContentFields($ctype['name']);
     $form = $this->getItemForm($ctype, $fields, 'add', array('groups_list' => $groups_list, 'folders_list' => $folders_list));
     // Заполняем поля значениями по-умолчанию, взятыми из профиля пользователя
     // (для тех полей, в которых это включено)
     foreach ($fields as $field) {
         if (!empty($field['options']['profile_value'])) {
             $item[$field['name']] = $user->{$field['options']['profile_value']};
         }
     }
     $is_moderator = $user->is_admin || $this->model->userIsContentTypeModerator($ctype_name, $user->id);
     $is_premoderation = $ctype['is_premod_add'];
     cmsEventsManager::hook("content_add", $ctype);
     list($form, $item) = cmsEventsManager::hook("content_{$ctype['name']}_form", array($form, $item));
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     if (!$is_submitted && !empty($category_id)) {
         $item['category_id'] = $category_id;
     }
     if ($this->request->has('group_id') && $groups_list && !$is_submitted) {
         $item['parent_id'] = $this->request->get('group_id');
     }
     $item['ctype_name'] = $ctype['name'];
     $item['ctype_id'] = $ctype['id'];
     if ($is_submitted) {
         if ($ctype['props']) {
             $props_cat_id = $this->request->get('category_id');
             if ($props_cat_id) {
                 $item_props = $this->model->getContentProps($ctype['name'], $props_cat_id);
                 $item_props_fields = $this->getPropsFields($item_props);
                 foreach ($item_props_fields as $field) {
                     $form->addField('props', $field);
                 }
             }
         }
         // Парсим форму и получаем поля записи
         $item = array_merge($item, $form->parse($this->request, $is_submitted));
         // Проверям правильность заполнения
         $errors = $form->validate($this, $item);
         if (!$errors) {
             list($item, $errors) = cmsEventsManager::hook('content_validate', array($item, $errors));
         }
         if (!$errors) {
             unset($item['ctype_name']);
             unset($item['ctype_id']);
             $item['is_approved'] = !$ctype['is_premod_add'] || $is_moderator;
             $item['parent_type'] = null;
             $item['parent_title'] = null;
             $item['parent_url'] = null;
             $item['is_parent_hidden'] = null;
             if (isset($item['parent_id'])) {
                 if (array_key_exists($item['parent_id'], $groups_list) && $item['parent_id'] > 0) {
                     $group = $groups_model->getGroup($item['parent_id']);
                     $item['parent_type'] = 'group';
                     $item['parent_title'] = $groups_list[$item['parent_id']];
                     $item['parent_url'] = href_to_rel('groups', $item['parent_id'], array('content', $ctype_name));
                     $item['is_parent_hidden'] = $group['is_closed'] ? true : null;
                 } else {
                     $item['parent_id'] = null;
                 }
             }
             if ($ctype['is_auto_keys']) {
                 $item['seo_keys'] = string_get_meta_keywords($item['content']);
             }
             if ($ctype['is_auto_desc']) {
                 $item['seo_desc'] = string_get_meta_description($item['content']);
             }
             $is_pub_control = cmsUser::isAllowed($ctype['name'], 'pub_on');
             $is_date_pub_allowed = $ctype['is_date_range'] && cmsUser::isAllowed($ctype['name'], 'pub_late');
             $is_date_pub_end_allowed = $ctype['is_date_range'] && cmsUser::isAllowed($ctype['name'], 'pub_long', 'any');
             $is_date_pub_days_allowed = $ctype['is_date_range'] && cmsUser::isAllowed($ctype['name'], 'pub_long', 'days');
             $pub_max_days = intval(cmsUser::getPermissionValue($ctype['name'], 'pub_max_days'));
             $date_pub_time = isset($item['date_pub']) ? strtotime($item['date_pub']) : time();
             $now_time = strtotime(date('Y-m-d', time()));
             $is_pub = true;
             if ($is_date_pub_allowed) {
                 $days_to_pub = ceil(($date_pub_time - $now_time) / 60 / 60 / 24);
                 $is_pub = $is_pub && $days_to_pub < 1;
             }
             if ($is_date_pub_end_allowed && !empty($item['date_pub_end'])) {
                 $date_pub_end_time = strtotime($item['date_pub_end']);
                 $days_from_pub = floor(($now_time - $date_pub_end_time) / 60 / 60 / 24);
                 $is_pub = $is_pub && $days_from_pub < 1;
             } else {
                 if ($is_date_pub_days_allowed && !$user->is_admin) {
                     $days = $item['pub_days'];
                     $date_pub_end_time = $date_pub_time + 60 * 60 * 24 * $days;
                     $days_from_pub = floor(($now_time - $date_pub_end_time) / 60 / 60 / 24);
                     $is_pub = $is_pub && $days_from_pub < 1;
                     $item['date_pub_end'] = date('Y-m-d', $date_pub_end_time);
                 } else {
                     $item['date_pub_end'] = false;
                 }
             }
             unset($item['pub_days']);
             if (!$is_pub_control) {
                 unset($item['is_pub']);
             }
             if (!isset($item['is_pub'])) {
                 $item['is_pub'] = $is_pub;
             }
             if (!empty($item['is_pub'])) {
                 $item['is_pub'] = $is_pub;
             }
             if (!empty($ctype['options']['is_cats_multi'])) {
                 $add_cats = $this->request->get('add_cats');
                 if (is_array($add_cats)) {
                     foreach ($add_cats as $index => $cat_id) {
                         if (!is_numeric($cat_id) || !$cat_id) {
                             unset($add_cats[$index]);
                         }
                     }
                     if ($add_cats) {
                         $item['add_cats'] = $add_cats;
                     }
                 }
             }
             $item = cmsEventsManager::hook("content_before_add", $item);
             $item = cmsEventsManager::hook("content_{$ctype['name']}_before_add", $item);
             $item = $this->model->addContentItem($ctype, $item, $fields);
             if ($ctype['is_tags']) {
                 $tags_model = cmsCore::getModel('tags');
                 $tags_model->addTags($item['tags'], $this->name, $ctype['name'], $item['id']);
                 $item['tags'] = $tags_model->getTagsStringForTarget($this->name, $ctype['name'], $item['id']);
                 $this->model->updateContentItemTags($ctype['name'], $item['id'], $item['tags']);
             }
             cmsEventsManager::hook("content_after_add", $item);
             cmsEventsManager::hook("content_{$ctype['name']}_after_add", $item);
             if ($item['is_approved']) {
                 cmsEventsManager::hook("content_after_add_approve", array('ctype_name' => $ctype_name, 'item' => $item));
                 cmsEventsManager::hook("content_{$ctype['name']}_after_add_approve", $item);
             } else {
                 $this->requestModeration($ctype_name, $item);
             }
             $back_url = $this->request->get('back');
             if ($back_url) {
                 $this->redirect($back_url);
             } else {
                 if ($ctype['options']['item_on']) {
                     $this->redirectTo($ctype_name, $item['slug'] . '.html');
                 } else {
                     $this->redirectTo($ctype_name);
                 }
             }
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('item_form', array('do' => 'add', 'parent' => isset($parent) ? $parent : false, 'ctype' => $ctype, 'item' => $item, 'form' => $form, 'props' => $props, 'is_moderator' => $is_moderator, 'is_premoderation' => $is_premoderation, 'is_load_props' => !isset($errors), 'errors' => isset($errors) ? $errors : false));
 }