public function run($data) { $ctype_name = $data['ctype_name']; $item = $data['item']; $this->addEntry('content', "add.{$ctype_name}", array('user_id' => $item['user_id'], 'subject_title' => $item['title'], 'subject_id' => $item['id'], 'subject_url' => href_to_rel($ctype_name, $item['slug'] . '.html'), 'is_private' => isset($item['is_private']) ? $item['is_private'] : 0, 'group_id' => isset($item['parent_id']) ? $item['parent_id'] : null, 'is_parent_hidden' => $item['is_parent_hidden'], 'is_pub' => $item['is_pub'])); return $data; }
public function run($group) { if ($this->model->getMembership($group['id'], $this->cms_user->id)) { $this->redirectToAction($group['id']); } $invite = $this->model->getInvite($group['id'], $this->cms_user->id); if ($group['join_policy'] != groups::JOIN_POLICY_FREE && !$invite) { cmsCore::error404(); } $result = cmsEventsManager::hook('group_before_join', array('allow' => true, 'group' => $group, 'invite' => $invite)); if (!$result['allow']) { if (isset($result['access_text'])) { cmsUser::addSessionMessage($result['access_text'], 'error'); if (isset($result['redirect_url'])) { $this->redirect($result['redirect_url']); } else { $this->redirectToAction($group['id']); } } cmsCore::error404(); } $group = $result['group']; $invite = $result['invite']; $this->model->addMembership($group['id'], $this->cms_user->id); if ($invite) { $this->model->deleteInvite($invite['id']); } cmsCore::getController('activity')->addEntry($this->name, 'join', array('subject_title' => $group['title'], 'subject_id' => $group['id'], 'subject_url' => href_to_rel($this->name, $group['id']), 'group_id' => $group['id'])); cmsUser::addSessionMessage(LANG_GROUPS_JOIN_MESSAGE, 'success'); $this->redirectToAction($group['id']); }
public function run($data) { $ctype_name = $data['ctype_name']; $item = $data['item']; // обновляем запись в ленте активности $this->updateEntry('content', "add.{$ctype_name}", $item['id'], array('subject_title' => $item['title'], 'subject_id' => $item['id'], 'subject_url' => href_to_rel($ctype_name, $item['slug'] . '.html'), 'is_private' => isset($item['is_private']) ? $item['is_private'] : 0, 'is_pub' => $item['is_pub'])); return $data; }
public function run($data) { foreach ($data as $ctype_name => $items) { foreach ($items as $item) { $this->addEntry('content', "add.{$ctype_name}", array('user_id' => $item['user_id'], 'subject_title' => $item['title'], 'subject_id' => $item['id'], 'subject_url' => href_to_rel($ctype_name, $item['slug'] . '.html'), 'is_private' => isset($item['is_private']) ? $item['is_private'] : 0, 'group_id' => isset($item['parent_id']) ? $item['parent_id'] : null, 'is_parent_hidden' => $item['is_parent_hidden'], 'date_pub' => $item['date_pub'], 'is_pub' => true)); } } return $data; }
public function run($group) { $is_member = $this->model->getMembership($group['id'], $this->cms_user->id); $is_owner = $group['owner_id'] == $this->cms_user->id; if ($is_member && !$is_owner) { $group = cmsEventsManager::hook('group_before_leave', $group); $this->model->deleteMembership($group['id'], $this->cms_user->id); cmsCore::getController('activity')->addEntry($this->name, 'leave', array('subject_title' => $group['title'], 'subject_id' => $group['id'], 'subject_url' => href_to_rel($this->name, $group['id']), 'group_id' => $group['id'])); } cmsUser::addSessionMessage(LANG_GROUPS_LEAVE_MESSAGE, 'info'); $this->redirectToAction($group['id']); }
public function run($item) { $this->model->updateTracking('content', $item['ctype_data']['name'], $item['id']); // обновляем приватность комментариев if (isset($item['is_private'])) { $this->model->filterCommentTarget('content', $item['ctype_data']['name'], $item['id'])->updateCommentsPrivacy($item['is_private'] || $item['is_parent_hidden']); } // обновляем url if (!$item['ctype_data']['is_fixed_url']) { $this->model->filterCommentTarget('content', $item['ctype_data']['name'], $item['id'])->updateCommentsUrl(href_to_rel($item['ctype_data']['name'], $item['slug'] . '.html'), $item['title']); } return $item; }
public function run() { if (!cmsUser::isLogged()) { cmsCore::error404(); } if (!$this->request->isAjax()) { cmsCore::error404(); } $user_id = $this->request->get('user_id', 0); $content = $this->request->get('content', ''); // Проверяем валидность if (!is_numeric($user_id)) { return $this->cms_template->renderJSON(array('error' => true, 'message' => LANG_ERROR)); } if ($this->cms_user->id != $user_id) { return $this->cms_template->renderJSON(array('error' => true, 'message' => LANG_ERROR)); } // Вырезаем теги и форматируем $content = cmsEventsManager::hook('html_filter', strip_tags(trim($content))); if (!$content) { return $this->cms_template->renderJSON(array('error' => true, 'message' => ERR_VALIDATE_REQUIRED)); } $status_content = trim(strip_tags($content)); // проверяем длину статуса if (mb_strlen($status_content) > 140) { return $this->cms_template->renderJSON(array('error' => true, 'message' => sprintf(ERR_VALIDATE_MAX_LENGTH, 140))); } // Добавляем запись на стену $wall_model = cmsCore::getModel('wall'); $wall_entry_id = $wall_model->addEntry(array('controller' => 'users', 'profile_type' => 'user', 'profile_id' => $user_id, 'user_id' => $user_id, 'content' => $content, 'content_html' => $content)); // сохраняем статус $status_id = $this->model->addUserStatus(array('user_id' => $user_id, 'content' => $status_content, 'wall_entry_id' => $wall_entry_id)); if ($status_id) { $wall_model->updateEntryStatusId($wall_entry_id, $status_id); cmsCore::getController('activity')->addEntry($this->name, 'status', array('subject_title' => $status_content, 'reply_url' => href_to_rel($this->name, $user_id) . "?wid={$wall_entry_id}&reply=1")); } return $this->cms_template->renderJSON(array('error' => $status_id ? false : true, 'wall_entry_id' => $wall_entry_id, 'content' => $status_content)); }
public function addFriendship($user_id, $friend_id) { $is_mutual = false; if ($this->isFriendshipRequested($friend_id, $user_id)) { $this->filterEqual('user_id', $friend_id); $this->filterEqual('friend_id', $user_id); $this->updateFiltered('{users}_friends', array('is_mutual' => true)); $is_mutual = true; } if ($is_mutual) { $this->filterEqual('id', $user_id)->increment('{users}', 'friends_count'); $this->filterEqual('id', $friend_id)->increment('{users}', 'friends_count'); $friend = $this->getUser($friend_id); cmsCore::getController('activity')->addEntry('users', 'friendship', array('subject_title' => $friend['nickname'], 'subject_id' => $friend_id, 'subject_url' => href_to_rel('users', $friend_id))); } cmsCache::getInstance()->clean('users.friends'); return $this->insert('{users}_friends', array('user_id' => $user_id, 'friend_id' => $friend_id, 'is_mutual' => $is_mutual)); }
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)); }
public function getTargetItemInfo($ctype_name, $id) { $item = $this->getPhoto($id); if (!$item) { return false; } return array('url' => href_to_rel('photos', 'view', $id), 'title' => $item['title']); }
public function addModeratorTask($ctype_name, $user_id, $is_new_item, $item) { $this->filterEqual('user_id', $user_id)->filterEqual('ctype_name', $ctype_name)->increment('moderators', 'count_idle'); return $this->insert('moderators_tasks', array('moderator_id' => $user_id, 'author_id' => $item['user_id'], 'item_id' => $item['id'], 'ctype_name' => $ctype_name, 'title' => $item['title'], 'url' => href_to_rel($ctype_name, $item['slug'] . '.html'), 'date_pub' => '', 'is_new_item' => $is_new_item)); }
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)); }
public function run($profile, $do = false, $param = false) { if (!cmsUser::isLogged()) { cmsCore::error404(); } // если нужно, передаем управление другому экшену if ($do) { $this->runAction('profile_edit_' . $do, array($profile) + array_slice($this->params, 2, null, true)); return; } // проверяем наличие доступа if ($profile['id'] != $this->cms_user->id && !$this->cms_user->is_admin) { cmsCore::error404(); } // Получаем поля $content_model = cmsCore::getModel('content'); $content_model->setTablePrefix(''); $content_model->orderBy('ordering'); $fields = $content_model->getContentFields('{users}', $profile['id']); // Строим форму $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']); } } // Добавляем поле выбора часового пояса $fieldset_id = $form->addFieldset(LANG_TIME_ZONE); $form->addField($fieldset_id, new fieldList('time_zone', array('default' => $this->cms_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_array($is_allowed)) { $errors = array(); foreach ($is_allowed as $error_list) { if (is_array($error_list) && $error_list) { $errors = array_merge($error_list); } } } } 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_rel('users', $profile['id']), 'is_private' => 0, 'group_id' => null, 'images' => array(array('url' => href_to_rel('users', $profile['id']), 'src' => html_image_src($new['avatar'], 'normal'))), 'images_count' => 1)); } } cmsUser::addSessionMessage(LANG_SUCCESS_MSG, 'success'); $this->redirectTo('users', $profile['id']); } if ($errors) { cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error'); } } return $this->cms_template->render('profile_edit', array('do' => 'edit', 'id' => $profile['id'], 'profile' => $profile, 'form' => $form, 'errors' => isset($errors) ? $errors : false)); }
/** * Возвращает ссылку на указанное действие контроллера * с добавлением хоста сайта * @param string $controller * @param string $action * @param array|str|int $params Параметры, массив * @return string */ function href_to_abs($controller, $action = '', $params = false) { $lang_href = cmsCore::getLanguageHrefPrefix(); return cmsConfig::get('host') . '/' . ($lang_href ? $lang_href . '/' : '') . href_to_rel($controller, $action, $params); }
public function getTargetItemInfo($ctype_name, $id) { $item = $this->getContentItem($ctype_name, $id); if (!$item) { return false; } return array('url' => href_to_rel($ctype_name, $item['slug'] . '.html'), 'title' => $item['title'], 'is_private' => $item['is_private'] || $item['is_parent_hidden']); }
public function showUploadForm($album_id) { if (!cmsUser::isAllowed('albums', 'add')) { cmsCore::error404(); } $content_model = cmsCore::getModel('content'); $ctype = $content_model->getContentTypeByName('albums'); if ($album_id) { $album = $content_model->getContentItem('albums', $album_id); if ($album) { if ($this->cms_user->id == $album['id']) { $content_model->disablePrivacyFilter(); } } } if ($this->cms_user->is_admin) { $content_model->disablePrivacyFilter(); } $albums = $content_model->filterEqual('user_id', $this->cms_user->id)->filterOr()->filterEqual('is_public', 1)->orderByList(array(array('by' => 'is_public', 'to' => 'asc'), array('by' => 'date_pub', 'to' => 'desc')))->getContentItems('albums'); if (!$albums) { $this->redirect(href_to('albums', 'add')); } $album_id = $album_id ? (int) $album_id : $this->request->get('album_id', 0); if ($this->request->has('submit')) { if (!isset($albums[$album_id])) { $this->redirectBack(); } if (!$this->request->has('photos')) { $this->redirectBack(); } if (!$this->request->has('content')) { $this->redirectBack(); } $album = $albums[$album_id]; // данные $photo_titles = $this->request->get('photos', array()); $photo_contents = $this->request->get('content', array()); $photo_is_privates = $this->request->get('is_private', array()); $photo_types = array(); if (!empty($this->options['types'])) { $photo_types = $this->request->get('type', array()); } if (!$photo_titles) { $this->redirectBack(); } // по ключам названий определяем id фотографий $_photo_ids = array_keys($photo_titles); // ключи могут быть только числовые $photo_ids = array_filter($_photo_ids, function ($v) { return is_numeric($v); }); if (!$photo_ids) { $this->redirectBack(); } // формируем массив для каждой фотографии $photo_list = array(); $last_order = $this->model->filterEqual('album_id', $album['id'])->getNextOrdering('photos'); foreach ($photo_ids as $photo_id) { // эти данные должны существовать, пусть даже и пустые // если их нет, значит запрос подделанный if (!isset($photo_titles[$photo_id]) || !isset($photo_contents[$photo_id])) { $this->model->deletePhoto($photo_id); continue; } $_photo = array('date_pub' => null, 'album_id' => $album['id'], 'title' => strip_tags($photo_titles[$photo_id] ? $photo_titles[$photo_id] : sprintf(LANG_PHOTOS_PHOTO_UNTITLED, $photo_id)), 'content_source' => $photo_contents[$photo_id] ? $photo_contents[$photo_id] : null, 'content' => $photo_contents[$photo_id] ? cmsEventsManager::hook('html_filter', $photo_contents[$photo_id]) : null, 'is_private' => isset($photo_is_privates[$photo_id]) ? (int) $photo_is_privates[$photo_id] : 0, 'type' => isset($photo_types[$photo_id]) ? (int) $photo_types[$photo_id] : null, 'ordering' => $last_order); $photo_list[$photo_id] = $_photo; $last_order++; } $photos = $this->model->assignPhotoList($photo_list); $activity_thumb_images = array(); $photos_count = count($photos); if ($photos_count > 5) { $photos = array_slice($photos, 0, 4); } if ($photos_count) { foreach ($photos as $photo) { $_presets = array_keys($photo['image']); $small_preset = end($_presets); $activity_thumb_images[] = array('url' => href_to_rel('photos', $photo['slug'] . '.html'), 'src' => html_image_src($photo['image'], $small_preset)); } } cmsCore::getController('activity')->addEntry($this->name, 'add.photos', array('user_id' => $this->cms_user->id, 'subject_title' => $album['title'], 'subject_id' => $album['id'], 'subject_url' => href_to_rel('albums', $album['slug'] . '.html'), 'is_private' => isset($album['is_private']) ? $album['is_private'] : 0, 'group_id' => isset($album['parent_id']) ? $album['parent_id'] : null, 'images' => $activity_thumb_images, 'images_count' => $photos_count)); $this->redirect(href_to('albums', $albums[$album_id]['slug'] . '.html')); } $photos = $this->model->getOrphanPhotos($this->cms_user->id); if (!isset($albums[$album_id])) { $album_id = false; } $_albums_select = array(); $num = 0; foreach ($albums as $album) { if (!empty($album['parent_title'])) { if ($album['is_public']) { $album['title'] = '[' . LANG_PHOTOS_PUBLIC_ALBUM . '] ' . $album['title']; } $_albums_select[$album['parent_title']][] = $album; } elseif ($album['is_public']) { $_albums_select[LANG_PHOTOS_PUBLIC_ALBUMS][] = $album; } else { $_albums_select[LANG_PHOTOS_USER_ALBUMS][] = $album; } } $albums_select = array('' => ''); foreach ($_albums_select as $album_type => $_albums) { $albums_select['opt' . $num] = array($album_type); foreach ($_albums as $album) { $albums_select[$album['id']] = $album['title']; } $num++; } $this->cms_template->render('upload', array('title' => LANG_PHOTOS_UPLOAD, 'is_edit' => false, 'ctype' => $ctype, 'albums' => $albums, 'album' => isset($albums[$album_id]) ? $albums[$album_id] : array(), 'albums_select' => $albums_select, 'photos' => $photos, 'preset_big' => $this->options['preset'], 'types' => !empty($this->options['types']) ? array('' => LANG_PHOTOS_NO_TYPE) + $this->options['types'] : array(), 'album_id' => $album_id)); }
/** * Возвращает ссылку на указанное действие контроллера * с добавлением хоста сайта * @param string $controller * @param string $action * @param array|str|int $params Параметры, массив * @return string */ function href_to_abs($controller, $action = '', $params = false) { return cmsConfig::get('host') . '/' . href_to_rel($controller, $action, $params); }
<?php $list_header = empty($ctype['labels']['list']) ? $ctype['title'] : $ctype['labels']['list']; $page_header = isset($category['title']) ? $category['title'] : $list_header; $rss_query = isset($category['id']) ? "?category={$category['id']}" : ''; $base_url = $ctype['name']; $base_ds_url = href_to_rel($ctype['name']) . '-%s' . (isset($category['slug']) ? '/' . $category['slug'] : ''); if (!$is_frontpage) { $seo_title = false; if (!empty($ctype['seo_title'])) { $seo_title = $ctype['seo_title']; } if (!empty($category['seo_title'])) { $seo_title = $category['seo_title']; } if (!$seo_title) { $seo_title = $page_header; } if (!empty($current_dataset['title'])) { $seo_title .= ' · ' . $current_dataset['title']; } $this->setPageTitle($seo_title); } if (!empty($ctype['seo_keys'])) { $this->setPageKeywords($ctype['seo_keys']); } if (!empty($ctype['seo_desc'])) { $this->setPageDescription($ctype['seo_desc']); } if (!empty($category['seo_keys'])) { $this->setPageKeywords($category['seo_keys']);