Пример #1
0
 public function run($profile)
 {
     // проверяем наличие доступа
     if ($profile['id'] != $this->cms_user->id) {
         cmsCore::error404();
     }
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     if (!$is_submitted && !$profile['invites_count']) {
         cmsCore::error404();
     }
     $form = new cmsForm();
     $fieldset_id = $form->addFieldset();
     if ($profile['invites_count'] > 1) {
         $form->addField($fieldset_id, new fieldText('emails', array('title' => LANG_USERS_INVITES_EMAILS, 'hint' => LANG_USERS_INVITES_EMAILS_HINT, 'rules' => array(array('required')))));
     }
     if ($profile['invites_count'] == 1) {
         $form->addField($fieldset_id, new fieldString('emails', array('title' => LANG_USERS_INVITES_EMAIL, 'rules' => array(array('required'), array('email')))));
     }
     $input = array();
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $input = $form->parse($this->request, $is_submitted);
         // Проверям правильность заполнения
         $errors = $form->validate($this, $input);
         if (!$errors) {
             $results = $this->sendInvites($profile, $input['emails']);
             return $this->cms_template->render('profile_invites_results', array('id' => $profile['id'], 'profile' => $profile, 'results' => $results));
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('profile_invites', array('id' => $profile['id'], 'profile' => $profile, 'form' => $form, 'input' => $input, 'errors' => isset($errors) ? $errors : false));
 }
Пример #2
0
 public function run($ctype_id, $parent_id)
 {
     $items = $this->request->get('selected');
     $is_submitted = $this->request->has('items');
     $template = cmsTemplate::getInstance();
     $content_model = cmsCore::getModel('content');
     $ctype = $content_model->getContentType($ctype_id);
     $fields = $content_model->getContentFields($ctype['name']);
     $form = new cmsForm();
     $fieldset_id = $form->addFieldset(LANG_MOVE_TO_CATEGORY);
     $form->addField($fieldset_id, new fieldList('category_id', array('default' => $parent_id, 'generator' => function ($data) {
         $content_model = cmsCore::getModel('content');
         $tree = $content_model->getCategoriesTree($data['ctype_name']);
         foreach ($tree as $c) {
             $items[$c['id']] = str_repeat('- ', $c['ns_level']) . ' ' . $c['title'];
         }
         return $items;
     })));
     $form->addField($fieldset_id, new fieldHidden('items'));
     $data = $form->parse($this->request, $is_submitted);
     if ($is_submitted) {
         // Проверяем правильность заполнения
         $errors = $form->validate($this, $data);
         if (!$errors) {
             $data['items'] = explode(',', $data['items']);
             $content_model->moveContentItemsToCategory($ctype, $data['category_id'], $data['items'], $fields);
             $template->renderJSON(array('errors' => false, 'callback' => 'contentItemsMoved'));
         }
         if ($errors) {
             $template->renderJSON(array('errors' => true));
         }
         $this->halt();
     }
     return $template->render('content_item_move', array('ctype' => $ctype, 'parent_id' => $parent_id, 'items' => $items, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Пример #3
0
 public function run($profile)
 {
     $user = cmsUser::getInstance();
     $template = cmsTemplate::getInstance();
     // проверяем наличие доступа
     if ($profile['id'] != $user->id && !$user->is_admin) {
         cmsCore::error404();
     }
     $pricacy_types = cmsEventsManager::hookAll('user_privacy_types');
     $form = new cmsForm();
     $fieldset_id = $form->addFieldset();
     $default_options = array('', 'anyone', 'friends');
     foreach ($pricacy_types as $list) {
         foreach ($list as $name => $type) {
             $options = array();
             if (!isset($type['options'])) {
                 $type['options'] = $default_options;
             }
             foreach ($type['options'] as $option) {
                 if (!$option) {
                     $options[''] = LANG_USERS_PRIVACY_FOR_NOBODY;
                 } else {
                     $options[$option] = constant('LANG_USERS_PRIVACY_FOR_' . mb_strtoupper($option));
                 }
             }
             $form->addField($fieldset_id, new fieldList($name, array('title' => $type['title'], 'default' => 'anyone', 'items' => $options)));
         }
     }
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     $options = $this->model->getUserPrivacyOptions($profile['id']);
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $options = array_merge($options, $form->parse($this->request, $is_submitted, $options));
         // Проверям правильность заполнения
         $errors = $form->validate($this, $options);
         if (!$errors) {
             // Обновляем профиль и редиректим на его просмотр
             $this->model->updateUserPrivacyOptions($profile['id'], $options);
             $this->redirectTo('users', $profile['id']);
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $template->render('profile_edit_privacy', array('id' => $profile['id'], 'profile' => $profile, 'options' => $options, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Пример #4
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;
 }
Пример #5
0
 public static function getWidgetOptionsForm($widget_name, $controller_name = false, $options = false)
 {
     $widget_path = self::getWidgetPath($widget_name, $controller_name);
     $path = cmsConfig::get('system_path') . $widget_path;
     $form_file = $path . '/options.form.php';
     $form_name = 'widget' . ($controller_name ? "_{$controller_name}_" : '_') . "{$widget_name}_options";
     $form = cmsForm::getForm($form_file, $form_name, array($options));
     if (!$form) {
         $form = new cmsForm();
     }
     $form->is_tabbed = true;
     //
     // Опции внешнего вида
     //
     $design_fieldset_id = $form->addFieldset(LANG_DESIGN);
     $form->addField($design_fieldset_id, new fieldString('class_wrap', array('title' => LANG_CSS_CLASS_WRAP)));
     $form->addField($design_fieldset_id, new fieldString('class_title', array('title' => LANG_CSS_CLASS_TITLE)));
     $form->addField($design_fieldset_id, new fieldString('class', array('title' => LANG_CSS_CLASS_BODY)));
     $form->addField($design_fieldset_id, new fieldString('tpl_wrap', array('title' => LANG_WIDGET_WRAPPER_TPL, 'hint' => LANG_WIDGET_WRAPPER_TPL_HINT)));
     $form->addField($design_fieldset_id, new fieldString('tpl_body', array('title' => LANG_WIDGET_BODY_TPL, 'hint' => sprintf(LANG_WIDGET_BODY_TPL_HINT, $widget_path))));
     //
     // Опции доступа
     //
     $access_fieldset_id = $form->addFieldset(LANG_PERMISSIONS);
     // Показывать группам
     $form->addField($access_fieldset_id, new fieldListGroups('groups_view', array('title' => LANG_SHOW_TO_GROUPS, 'show_all' => true, 'show_guests' => true)));
     // Не показывать группам
     $form->addField($access_fieldset_id, new fieldListGroups('groups_hide', array('title' => LANG_HIDE_FOR_GROUPS, 'show_all' => false, 'show_guests' => true)));
     //
     // Опции заголовка
     //
     $title_fieldset_id = $form->addFieldsetToBeginning(LANG_BASIC_OPTIONS);
     // ID виджета
     $form->addField($title_fieldset_id, new fieldNumber('id', array('is_hidden' => true)));
     // Заголовок виджета
     $form->addField($title_fieldset_id, new fieldString('title', array('title' => LANG_TITLE, 'rules' => array(array('required'), array('min_length', 3), array('max_length', 128)))));
     // Флаг показа заголовка
     $form->addField($title_fieldset_id, new fieldCheckbox('is_title', array('title' => LANG_SHOW_TITLE, 'default' => true)));
     // Флаг объединения с предыдущим виджетом
     $form->addField($title_fieldset_id, new fieldCheckbox('is_tab_prev', array('title' => LANG_WIDGET_TAB_PREV)));
     // Ссылки в заголовке
     $form->addField($title_fieldset_id, new fieldText('links', array('title' => LANG_WIDGET_TITLE_LINKS, 'hint' => LANG_WIDGET_TITLE_LINKS_HINT)));
     return $form;
 }
Пример #6
0
 public function run($profile, $do = false)
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     // если нужно, передаем управление другому экшену
     if ($do) {
         $this->runAction('profile_edit_' . $do, array($profile) + array_slice($this->params, 2));
         return;
     }
     // проверяем наличие доступа
     if ($profile['id'] != $user->id && !$user->is_admin) {
         cmsCore::error404();
     }
     // Получаем поля
     $content_model = cmsCore::getModel('content');
     $content_model->setTablePrefix('');
     $content_model->orderBy('ordering');
     $fields = $content_model->getContentFields('{users}');
     // Строим форму
     $form = new cmsForm();
     // Разбиваем поля по группам
     $fieldsets = cmsForm::mapFieldsToFieldsets($fields, function ($field, $user) {
         // проверяем что группа пользователя имеет доступ к редактированию этого поля
         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']);
         }
     }
     // Добавляем поле выбора часового пояса
     $config = cmsConfig::getInstance();
     $fieldset_id = $form->addFieldset(LANG_TIME_ZONE);
     $form->addField($fieldset_id, new fieldList('time_zone', array('default' => $config->time_zone, 'generator' => function ($item) {
         return cmsCore::getTimeZones();
     })));
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $new = $form->parse($this->request, $is_submitted, $profile);
         $old = $profile;
         $profile = array_merge($profile, $new);
         // Проверям правильность заполнения
         $errors = $form->validate($this, $profile);
         if (!$errors) {
             $is_allowed = cmsEventsManager::hookAll('user_profile_update', $profile, true);
             if ($is_allowed !== true && in_array(false, $is_allowed)) {
                 $errors = true;
             }
         }
         if (!$errors) {
             // Обновляем профиль и редиректим на его просмотр
             $this->model->updateUser($profile['id'], $profile);
             // Отдельно обновляем часовой пояс в сессии
             cmsUser::sessionSet('user_data:time_zone', $profile['time_zone']);
             // Постим уведомление о смене аватара в ленту
             if (!$this->model->isAvatarsEqual($new['avatar'], $old['avatar'])) {
                 $activity_controller = cmsCore::getController('activity');
                 $activity_controller->deleteEntry($this->name, "avatar", $profile['id']);
                 if (!empty($new['avatar'])) {
                     $activity_controller->addEntry($this->name, "avatar", array('user_id' => $profile['id'], 'subject_title' => $profile['nickname'], 'subject_id' => $profile['id'], 'subject_url' => href_to('users', $profile['id']), 'is_private' => 0, 'group_id' => null, 'images' => array(array('url' => href_to('users', $profile['id']), 'src' => html_image_src($new['avatar'], 'normal'))), 'images_count' => 1));
                 }
             }
             $this->redirectTo('users', $profile['id']);
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('profile_edit', array('do' => 'edit', 'id' => $profile['id'], 'profile' => $profile, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }