Beispiel #1
0
        ?>
                        <?php 
        echo html_button(LANG_SEND, 'submit', 'icms.comments.submit()');
        ?>
                    </div>
                    <div class="loading">
                        <?php 
        echo LANG_LOADING;
        ?>
                    </div>
                </form>
            <?php 
    } else {
        ?>
                <p><?php 
        printf(LANG_COMMENTS_LOW_KARMA, cmsUser::getPermissionValue('comments', 'karma'));
        ?>
</p>
            <?php 
    }
    ?>
        </div>
    <?php 
}
?>

    <script>
        <?php 
echo $this->getLangJS('LANG_SEND', 'LANG_SAVE', 'LANG_COMMENT_DELETED', 'LANG_COMMENT_DELETE_CONFIRM');
?>
        <?php 
Beispiel #2
0
 public function getItemForm($ctype, $fields, $action, $data = array(), $item_id = false, $item = false)
 {
     $user = cmsUser::getInstance();
     // Контейнер для передачи дополнительных списков:
     // $groups_list, $folders_list и т.д.
     extract($data);
     // Строим форму
     $form = new cmsForm();
     $fieldset_id = $form->addFieldset();
     // Если включены категории, добавляем в форму поле выбора категории
     if ($ctype['is_cats'] && ($action != 'edit' || $ctype['options']['is_cats_change'])) {
         $fieldset_id = $form->addFieldset(LANG_CATEGORY, 'category');
         $form->addField($fieldset_id, new fieldList('category_id', array('rules' => array(array('required')), 'generator' => function ($item) {
             $content_model = cmsCore::getModel('content');
             $ctype = $content_model->getContentTypeByName($item['ctype_name']);
             $tree = $content_model->getCategoriesTree($item['ctype_name']);
             $level_offset = 0;
             $last_header_id = false;
             $items = array('' => LANG_CONTENT_SELECT_CATEGORY);
             if ($tree) {
                 foreach ($tree as $c) {
                     if ($ctype['options']['is_cats_only_last']) {
                         $dash_pad = $c['ns_level'] - 1 >= 0 ? str_repeat('-', $c['ns_level'] - 1) . ' ' : '';
                         if ($c['ns_right'] - $c['ns_left'] == 1) {
                             if ($last_header_id !== false && $last_header_id != $c['parent_id']) {
                                 $items['opt' . $c['id']] = array(str_repeat('-', $c['ns_level'] - 1) . ' ' . $c['title']);
                             }
                             $items[$c['id']] = $dash_pad . $c['title'];
                         } else {
                             if ($c['parent_id'] > 0) {
                                 $items['opt' . $c['id']] = array($dash_pad . $c['title']);
                                 $last_header_id = $c['id'];
                             }
                         }
                         continue;
                     }
                     if (!$ctype['options']['is_cats_only_last']) {
                         if ($c['parent_id'] == 0 && !$ctype['options']['is_cats_open_root']) {
                             $level_offset = 1;
                             continue;
                         }
                         $items[$c['id']] = str_repeat('-- ', $c['ns_level'] - $level_offset) . ' ' . $c['title'];
                         continue;
                     }
                 }
             }
             return $items;
         })));
         if (cmsUser::isAllowed($ctype['name'], 'add_cat')) {
             $form->addField($fieldset_id, new fieldString('new_category', array('title' => LANG_ADD_CATEGORY_QUICK)));
         }
         if (!empty($ctype['options']['is_cats_multi'])) {
             $fieldset_id = $form->addFieldset(LANG_ADDITIONAL_CATEGORIES, 'multi_cats', array('is_empty' => true));
         }
     }
     // Если включены личные папки, добавляем в форму поле выбора личной папки
     if ($ctype['is_folders']) {
         $fieldset_id = $form->addFieldset(LANG_FOLDER, 'folder');
         $folders = array('0' => LANG_CONTENT_SELECT_FOLDER);
         if ($folders_list) {
             $folders = $folders + $folders_list;
         }
         $form->addField($fieldset_id, new fieldList('folder_id', array('items' => $folders)));
         $form->addField($fieldset_id, new fieldString('new_folder', array('title' => LANG_ADD_FOLDER_QUICK)));
     }
     // Если есть поля-свойства, то добавляем область для них
     if ($ctype['props']) {
         $form->addFieldset('', 'props', array('is_empty' => true, 'class' => 'highlight'));
     }
     // Если этот контент можно создавать в группах (сообществах) то добавляем
     // поле выбора группы
     if ($action == 'add' && $groups_list && $groups_list != array('0' => '')) {
         $fieldset_id = $form->addFieldset(LANG_GROUP);
         $form->addField($fieldset_id, new fieldList('parent_id', array('items' => $groups_list)));
     }
     // Разбиваем поля по группам
     $fieldsets = cmsForm::mapFieldsToFieldsets($fields, function ($field, $user) {
         // пропускаем системные поля
         if ($field['is_system']) {
             return false;
         }
         // проверяем что группа пользователя имеет доступ к редактированию этого поля
         if ($field['groups_edit'] && !$user->isInGroups($field['groups_edit'])) {
             return false;
         }
         return true;
     });
     // Добавляем поля в форму
     foreach ($fieldsets as $fieldset) {
         $fieldset_id = $form->addFieldset($fieldset['title']);
         foreach ($fieldset['fields'] as $field) {
             // добавляем поле в форму
             $form->addField($fieldset_id, $field['handler']);
         }
     }
     //
     // Если включены теги, то добавляем поле для них
     //
     if ($ctype['is_tags']) {
         $fieldset_id = $form->addFieldset(LANG_TAGS);
         $form->addField($fieldset_id, new fieldString('tags', array('hint' => LANG_TAGS_HINT, 'autocomplete' => array('multiple' => true, 'url' => href_to('tags', 'autocomplete')))));
     }
     // Если ручной ввод SLUG, то добавляем поле для этого
     if (!$ctype['is_auto_url']) {
         $slug_field_rules = array(array('required'), array('slug'));
         if ($action == 'add') {
             $slug_field_rules[] = array('unique', $this->model->table_prefix . $ctype['name'], 'slug');
         }
         if ($action == 'edit') {
             $slug_field_rules[] = array('unique_exclude', $this->model->table_prefix . $ctype['name'], 'slug', $item_id);
         }
         $fieldset_id = $form->addFieldset(LANG_SLUG);
         $form->addField($fieldset_id, new fieldString('slug', array('prefix' => '/' . $ctype['name'] . '/', 'suffix' => '.html', 'rules' => $slug_field_rules)));
     }
     // Если разрешено управление видимостью, то добавляем поле
     if (cmsUser::isAllowed($ctype['name'], 'privacy')) {
         $fieldset_id = $form->addFieldset(LANG_PRIVACY);
         $form->addField($fieldset_id, new fieldList('is_private', array('items' => array(0 => LANG_PRIVACY_PUBLIC, 1 => LANG_PRIVACY_PRIVATE), 'rules' => array(array('number')))));
     }
     // если разрешено отключать комментарии к записи
     if (cmsUser::isAllowed($ctype['name'], 'disable_comments') && $ctype['is_comments']) {
         $fieldset_id = $form->addFieldset(LANG_RULE_CONTENT_COMMENT, 'is_comment');
         $form->addField($fieldset_id, new fieldList('is_comments_on', array('default' => 1, 'items' => array(1 => LANG_YES, 0 => LANG_NO))));
     }
     //
     // Если ручной ввод ключевых слов или описания, то добавляем поля для этого
     //
     if (!empty($ctype['options']['is_manual_title']) || !$ctype['is_auto_keys'] || !$ctype['is_auto_desc']) {
         $fieldset_id = $form->addFieldset(LANG_SEO);
         if ($ctype['options']['is_manual_title']) {
             $form->addField($fieldset_id, new fieldString('seo_title', array('title' => LANG_SEO_TITLE, 'rules' => array(array('max_length', 256)))));
         }
         if (!$ctype['is_auto_keys']) {
             $form->addField($fieldset_id, new fieldString('seo_keys', array('title' => LANG_SEO_KEYS, 'hint' => LANG_SEO_KEYS_HINT, 'rules' => array(array('max_length', 256)))));
         }
         if (!$ctype['is_auto_desc']) {
             $form->addField($fieldset_id, new fieldText('seo_desc', array('title' => LANG_SEO_DESC, 'hint' => LANG_SEO_DESC_HINT, 'rules' => array(array('max_length', 256)))));
         }
     }
     //
     // Если включен выбор даты публикации, то добавляем поля
     //
     $pub_fieldset_id = false;
     $is_dates = $ctype['is_date_range'];
     $is_pub_start_date = cmsUser::isAllowed($ctype['name'], 'pub_late');
     $is_pub_end_date = cmsUser::isAllowed($ctype['name'], 'pub_long', 'any');
     $is_pub_end_days = cmsUser::isAllowed($ctype['name'], 'pub_long', 'days');
     $is_pub_control = cmsUser::isAllowed($ctype['name'], 'pub_on');
     $is_pub_ext = cmsUser::isAllowed($ctype['name'], 'pub_max_ext');
     $pub_max_days = intval(cmsUser::getPermissionValue($ctype['name'], 'pub_max_days'));
     if ($user->is_admin) {
         $is_pub_end_days = false;
     }
     if ($is_pub_control) {
         $pub_fieldset_id = $pub_fieldset_id ? $pub_fieldset_id : $form->addFieldset(LANG_CONTENT_PUB);
         $form->addField($pub_fieldset_id, new fieldList('is_pub', array('title' => sprintf(LANG_CONTENT_IS_PUB, $ctype['labels']['create']), 'default' => 1, 'items' => array(1 => LANG_YES, 0 => LANG_NO))));
     }
     if ($is_dates) {
         if ($is_pub_start_date) {
             $pub_fieldset_id = $pub_fieldset_id ? $pub_fieldset_id : $form->addFieldset(LANG_CONTENT_PUB);
             $m = date('i');
             $form->addField($pub_fieldset_id, new fieldDate('date_pub', array('title' => LANG_CONTENT_DATE_PUB, 'default' => date('Y-m-d H:') . ($m - $m % 5), 'options' => array('show_time' => true), 'rules' => array(array('required')))));
         }
         if ($is_pub_end_date) {
             $pub_fieldset_id = $pub_fieldset_id ? $pub_fieldset_id : $form->addFieldset(LANG_CONTENT_PUB);
             $form->addField($pub_fieldset_id, new fieldDate('date_pub_end', array('title' => LANG_CONTENT_DATE_PUB_END, 'hint' => LANG_CONTENT_DATE_PUB_END_HINT)));
         }
         if ($action == 'add' && $is_pub_end_days || $action == 'edit' && $is_pub_ext && $is_pub_end_days) {
             $pub_fieldset_id = $pub_fieldset_id ? $pub_fieldset_id : $form->addFieldset(LANG_CONTENT_PUB);
             $title = $action == 'add' ? LANG_CONTENT_PUB_LONG : LANG_CONTENT_PUB_LONG_EXT;
             $hint = $action == 'add' ? false : sprintf(LANG_CONTENT_PUB_LONG_NOW, html_date($item['date_pub_end']));
             if ($pub_max_days) {
                 $days = array();
                 $rules = array();
                 if ($action == 'add') {
                     $rules[] = array('required');
                     $min = 1;
                 }
                 if ($action == 'edit') {
                     $min = 0;
                 }
                 $rules[] = array('number');
                 $rules[] = array('min', $min);
                 $rules[] = array('max', $pub_max_days);
                 if ($action == 'add') {
                     $rules[] = array('required');
                     $min = 1;
                 }
                 if ($action == 'edit') {
                     $min = 0;
                 }
                 for ($d = $min; $d <= $pub_max_days; $d++) {
                     $days[$d] = $d;
                 }
                 $form->addField($pub_fieldset_id, new fieldList('pub_days', array('title' => $title, 'hint' => $hint, 'items' => $days, 'rules' => $rules)));
             } else {
                 $rules = array();
                 if ($action == 'add') {
                     $rules[] = array('required');
                     $min = 1;
                 }
                 if ($action == 'edit') {
                     $min = 0;
                 }
                 $rules[] = array('min', $min);
                 $rules[] = array('max', 65535);
                 $form->addField($pub_fieldset_id, new fieldNumber('pub_days', array('title' => $title, 'default' => 10, 'rules' => $rules)));
             }
         }
     }
     return $form;
 }
Beispiel #3
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));
 }