Beispiel #1
0
 public function run($id)
 {
     if (!$id) {
         cmsCore::error404();
     }
     $content_model = cmsCore::getModel('content');
     $ctype = $content_model->getContentType($id);
     $ctype = cmsEventsManager::hook("ctype_before_delete", $ctype);
     $content_model->deleteContentType($id);
     cmsEventsManager::hook("ctype_after_delete", $ctype);
     cmsCore::getModel('widgets')->deletePagesByName('content', "{$ctype['name']}.*");
     $binded_widgets = $content_model->get('widgets_bind', function ($item, $model) {
         $item['options'] = cmsModel::yamlToArray($item['options']);
         return $item;
     });
     if ($binded_widgets) {
         foreach ($binded_widgets as $widget) {
             if (isset($widget['options']['ctype_id']) && $ctype['id'] == $widget['options']['ctype_id']) {
                 $content_model->delete('widgets_bind', $widget['id']);
             }
         }
     }
     cmsCore::getController('activity')->deleteType('content', "add.{$ctype['name']}");
     $this->redirectToAction('ctypes');
 }
Beispiel #2
0
 public function run()
 {
     $form = $this->getForm('options');
     if (!$form) {
         cmsCore::error404();
     }
     $is_submitted = $this->request->has('submit');
     $options = cmsController::loadOptions($this->name);
     $source_controllers = cmsEventsManager::hookAll('sitemap_sources');
     if (is_array($source_controllers)) {
         foreach ($source_controllers as $controller) {
             foreach ($controller['sources'] as $id => $title) {
                 $form->addField('sources', new fieldCheckbox("sources:{$controller['name']}|{$id}", array('title' => $title)));
             }
         }
     }
     if ($is_submitted) {
         $options = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $options);
         if (!$errors) {
             cmsUser::addSessionMessage(LANG_CP_SAVE_SUCCESS, 'success');
             cmsController::saveOptions($this->name, $options);
             $this->redirectToAction('options');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/options', array('options' => $options, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Beispiel #3
0
 public function getWidget($title, $target, $permissions = array())
 {
     $user = cmsUser::getInstance();
     extract($target);
     $page = $this->request->get('page', 1);
     $show_id = $this->request->get('wid');
     $go_reply = $this->request->get('reply', 0);
     $show_reply_id = 0;
     if ($show_id) {
         $entry = $this->model->getEntry($show_id);
         if ($entry) {
             if ($entry['parent_id'] > 0) {
                 $show_id = $entry['parent_id'];
                 $show_reply_id = $entry['id'];
             }
             $page = $this->model->getEntryPageNumber($show_id, $target, self::$perpage);
         }
     }
     $total = $this->model->getEntriesCount($profile_type, $profile_id);
     $entries = $this->model->getEntries($profile_type, $profile_id, $page);
     $entries = cmsEventsManager::hook('wall_before_list', $entries);
     $csrf_token_seed = implode('/', array($profile_type, $profile_id));
     $template = cmsTemplate::getInstance();
     return $template->renderInternal($this, 'list', array('title' => $title, 'user' => $user, 'controller' => $controller, 'profile_type' => $profile_type, 'profile_id' => $profile_id, 'user' => $user, 'entries' => $entries, 'permissions' => $permissions, 'page' => $page, 'perpage' => wall::$perpage, 'total' => $total, 'max_entries' => $show_id ? 0 : 5, 'csrf_token_seed' => $csrf_token_seed, 'show_id' => $show_id, 'show_reply_id' => $show_reply_id, 'go_reply' => $go_reply));
 }
Beispiel #4
0
 public function run()
 {
     $template = cmsTemplate::getInstance();
     $config = cmsConfig::getInstance();
     $user = cmsUser::getInstance();
     $contact_id = $this->request->get('contact_id') or cmsCore::error404();
     $content = $this->request->get('content') or cmsCore::error404();
     $csrf_token = $this->request->get('csrf_token');
     // Проверяем валидность
     $is_valid = is_numeric($contact_id) && cmsForm::validateCSRFToken($csrf_token, false);
     if (!$is_valid) {
         $result = array('error' => true, 'message' => '');
         $template->renderJSON($result);
     }
     $contact = $this->model->getContact($user->id, $contact_id);
     // Контакт существует?
     if (!$contact) {
         $result = array('error' => true, 'message' => '');
         $template->renderJSON($result);
     }
     // Контакт не в игноре у отправителя?
     if ($contact['is_ignored']) {
         $result = array('error' => true, 'message' => LANG_PM_CONTACT_IS_IGNORED);
         $template->renderJSON($result);
     }
     // Отправитель не в игноре у контакта?
     if ($this->model->isContactIgnored($contact_id, $user->id)) {
         $result = array('error' => true, 'message' => LANG_PM_YOU_ARE_IGNORED);
         $template->renderJSON($result);
     }
     // Контакт принимает сообщения от этого пользователя?
     if (!$user->isPrivacyAllowed($contact, 'messages_pm')) {
         $result = array('error' => true, 'message' => LANG_PM_CONTACT_IS_PRIVATE);
         $template->renderJSON($result);
     }
     //
     // Отправляем сообщение
     //
     $content_html = cmsEventsManager::hook('html_filter', $content);
     if (!$content_html) {
         $template->renderJSON(array('error' => false, 'date' => false, 'message' => false));
     }
     $this->setSender($user->id);
     $this->addRecipient($contact_id);
     $message_id = $this->sendMessage($content_html);
     //
     // Отправляем уведомление на почту
     //
     $user_to = cmsCore::getModel('users')->getUser($contact_id);
     if (!$user_to['is_online']) {
         $this->sendNoticeEmail('messages_new');
     }
     //
     // Получаем и рендерим добавленное сообщение
     //
     $message = $this->model->getMessage($message_id);
     $message_html = $template->render('message', array('messages' => array($message), 'user' => $user), new cmsRequest(array(), cmsRequest::CTX_INTERNAL));
     // Результат
     $template->renderJSON(array('error' => false, 'date' => date($config->date_format, time()), 'message' => $message_html));
 }
Beispiel #5
0
 public function run()
 {
     $camera = urldecode($this->request->get('name', ''));
     if (!$camera) {
         cmsCore::error404();
     }
     if (cmsUser::isAllowed('albums', 'view_all')) {
         $this->model->disablePrivacyFilter();
     }
     $this->model->filterEqual('camera', $camera);
     $page = $this->request->get('photo_page', 1);
     $perpage = empty($this->options['limit']) ? 16 : $this->options['limit'];
     $this->model->limitPagePlus($page, $perpage);
     $this->model->orderBy($this->options['ordering'], 'desc');
     $photos = $this->getPhotosList();
     if (!$photos) {
         cmsCore::error404();
     }
     if ($photos && count($photos) > $perpage) {
         $has_next = true;
         array_pop($photos);
     } else {
         $has_next = false;
     }
     $ctype = cmsCore::getModel('content')->getContentTypeByName('albums');
     $this->cms_template->render('camera', array('page_title' => sprintf(LANG_PHOTOS_CAMERA_TITLE, $camera), 'ctype' => $ctype, 'page' => $page, 'row_height' => $this->getRowHeight(), 'user' => $this->cms_user, 'item' => array('id' => 0, 'user_id' => 0, 'url_params' => array('camera' => $camera), 'base_url' => href_to('photos', 'camera-' . urlencode($camera))), 'item_type' => 'camera', 'photos' => $photos, 'is_owner' => cmsUser::isAllowed('albums', 'delete', 'all'), 'has_next' => $has_next, 'hooks_html' => cmsEventsManager::hookAll('photo_camera_html', $camera), 'preset_small' => $this->options['preset_small']));
 }
Beispiel #6
0
 public function actionOptions()
 {
     if (empty($this->useDefaultOptionsAction)) {
         cmsCore::error404();
     }
     $form = $this->getForm('options');
     if (!$form) {
         cmsCore::error404();
     }
     $form = cmsEventsManager::hook("form_options_{this->name}", $form);
     $is_submitted = $this->request->has('submit');
     $options = cmsController::loadOptions($this->name);
     if ($is_submitted) {
         $options = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $options);
         if (!$errors) {
             cmsUser::addSessionMessage(LANG_CP_SAVE_SUCCESS, 'success');
             cmsController::saveOptions($this->name, $options);
             $this->redirectToAction('options');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/options', array('options' => $options, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Beispiel #7
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $template = cmsTemplate::getInstance();
     $entry_id = $this->request->get('id');
     // Проверяем валидность
     $is_valid = is_numeric($entry_id);
     if (!$is_valid) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         $template->renderJSON($result);
     }
     $user = cmsUser::getInstance();
     $entry = $this->model->getEntry($entry_id);
     $replies = $this->model->getReplies($entry_id);
     if (!$replies) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         $template->renderJSON($result);
     }
     $replies = cmsEventsManager::hook('wall_before_list', $replies);
     $permissions = array('add' => $user->is_logged, 'delete' => $user->is_admin || $user->id == $entry['profile_id']);
     $html = $template->renderInternal($this, 'entry', array('entries' => $replies, 'user' => $user, 'permissions' => $permissions));
     // Формируем и возвращаем результат
     $result = array('error' => false, 'html' => $html);
     $template->renderJSON($result);
 }
Beispiel #8
0
 public function actionLogout()
 {
     cmsEventsManager::hook('auth_logout', cmsUser::getInstance()->id);
     cmsUser::logout();
     $this->redirectToHome();
     $this->halt();
 }
Beispiel #9
0
 public function run($group)
 {
     if (!cmsUser::isAllowed('groups', 'delete')) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed('groups', 'delete', 'all') && $group['owner_id'] != $this->cms_user->id) {
         cmsCore::error404();
     }
     if ($this->request->has('submit')) {
         // подтвержение получено
         $csrf_token = $this->request->get('csrf_token', '');
         $is_delete_content = $this->request->get('is_delete_content', 0);
         if (!cmsForm::validateCSRFToken($csrf_token)) {
             cmsCore::error404();
         }
         list($group, $is_delete_content) = cmsEventsManager::hook('group_before_delete', array($group, $is_delete_content));
         $this->model->removeContentFromGroup($group['id'], $is_delete_content);
         $this->model->deleteGroup($group);
         cmsUser::addSessionMessage(sprintf(LANG_GROUPS_DELETED, $group['title']));
         $this->redirectToAction('');
     } else {
         // спрашиваем подтверждение
         return $this->cms_template->render('group_delete', array('user' => $this->cms_user, 'group' => $group));
     }
 }
Beispiel #10
0
 public function run($ctype_name)
 {
     $values = $this->request->get('value');
     if (!$values || !$ctype_name) {
         cmsCore::error404();
     }
     $content_model = cmsCore::getModel('content');
     $ctype = $content_model->getContentTypeByName($ctype_name);
     if (!$ctype) {
         cmsCore::error404();
     }
     $rules = cmsPermissions::getRulesList('content');
     list($ctype, $rules, $values) = cmsEventsManager::hook('content_perms', array($ctype, $rules, $values));
     list($ctype, $rules, $values) = cmsEventsManager::hook("content_{$ctype['name']}_perms", array($ctype, $rules, $values));
     $users_model = cmsCore::getModel('users');
     $groups = $users_model->getGroups(false);
     // перебираем правила
     foreach ($rules as $rule) {
         // если для этого правила вообще ничего нет,
         // то присваиваем null
         if (empty($values[$rule['id']])) {
             $values[$rule['id']] = null;
             continue;
         }
         // перебираем группы, заменяем на нуллы
         // значения отсутствующих правил
         foreach ($groups as $group) {
             if (empty($values[$rule['id']][$group['id']])) {
                 $values[$rule['id']][$group['id']] = null;
             }
         }
     }
     cmsPermissions::savePermissions($ctype_name, $values);
     $this->redirectBack();
 }
Beispiel #11
0
 public function run($pass_token)
 {
     if (!$pass_token) {
         cmsCore::error404();
     }
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $users_model = cmsCore::getModel('users');
     $user = $users_model->getUserByPassToken($pass_token);
     if (!$user) {
         cmsCore::error404();
     }
     $users_model->unlockUser($user['id']);
     $users_model->clearUserPassToken($user['id']);
     cmsEventsManager::hook('user_registered', $user);
     cmsUser::addSessionMessage($this->options['reg_auto_auth'] ? LANG_REG_SUCCESS_VERIFIED_AND_AUTH : LANG_REG_SUCCESS_VERIFIED, 'success');
     // авторизуем пользователя автоматически
     if ($this->options['reg_auto_auth']) {
         $user = cmsEventsManager::hook('user_login', $user);
         cmsUser::sessionSet('user', array('id' => $user['id'], 'groups' => $user['groups'], 'time_zone' => $user['time_zone'], 'perms' => cmsUser::getPermissions($user['groups']), 'is_admin' => $user['is_admin']));
         $update_data = array('ip' => cmsUser::getIp());
         $this->model->update('{users}', $user['id'], $update_data, true);
         cmsEventsManager::hook('auth_login', $user['id']);
     }
     $this->redirect($this->getAuthRedirectUrl($this->options['first_auth_redirect']));
 }
Beispiel #12
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed('comments', 'is_moderator')) {
         return $this->cms_template->renderJSON(array('error' => true, 'message' => LANG_COMMENT_ERROR));
     }
     $comment_id = $this->request->get('id', 0);
     if (!$comment_id) {
         return $this->cms_template->renderJSON(array('error' => true, 'message' => LANG_COMMENT_ERROR));
     }
     $comment = $this->model->getComment($comment_id);
     if (!$comment) {
         return $this->cms_template->renderJSON(array('error' => true, 'message' => LANG_COMMENT_ERROR));
     }
     $this->model->approveComment($comment['id']);
     // Уведомляем модель целевого контента об изменении количества комментариев
     $comments_count = $this->model->filterCommentTarget($comment['target_controller'], $comment['target_subject'], $comment['target_id'])->getCommentsCount();
     $this->model->resetFilters();
     cmsCore::getModel($comment['target_controller'])->updateCommentsCount($comment['target_subject'], $comment['target_id'], $comments_count);
     $parent_comment = $comment['parent_id'] ? $this->model->getComment($comment['parent_id']) : false;
     // Уведомляем подписчиков
     $this->notifySubscribers($comment, $parent_comment);
     // Уведомляем об ответе на комментарий
     if ($parent_comment) {
         $this->notifyParent($comment, $parent_comment);
     }
     $comment = cmsEventsManager::hook('comment_after_add', $comment);
     return $this->cms_template->renderJSON(array('error' => false, 'message' => '', 'id' => $comment['id'], 'parent_id' => $comment['parent_id'], 'level' => $comment['level'], 'html' => cmsEventsManager::hook('parse_text', $comment['content_html'])));
 }
Beispiel #13
0
 public function parse($value)
 {
     if ($this->getOption('is_html_filter')) {
         $value = cmsEventsManager::hook('html_filter', array('text' => $value, 'is_auto_br' => false));
     }
     return $value;
 }
Beispiel #14
0
 public function run()
 {
     $cat_id = $this->getOption('category_id');
     $ctype_id = $this->getOption('ctype_id');
     $dataset_id = $this->getOption('dataset');
     $image_field = $this->getOption('image_field');
     $big_image_field = $this->getOption('big_image_field');
     $big_image_preset = $this->getOption('big_image_preset');
     $teaser_fields = $this->getOption('teaser_field');
     $limit = $this->getOption('limit', 10);
     $delay = $this->getOption('delay', 5);
     $teaser_len = $this->getOption('teaser_len', 100);
     $model = cmsCore::getModel('content');
     $ctype = $model->getContentType($ctype_id);
     if (!$ctype) {
         return false;
     }
     if ($cat_id) {
         $category = $model->getCategory($ctype['name'], $cat_id);
     } else {
         $category = false;
     }
     if ($dataset_id) {
         $dataset = $model->getContentDataset($dataset_id);
         if ($dataset) {
             $model->applyDatasetFilters($dataset);
         } else {
             $dataset_id = false;
         }
     }
     if ($category) {
         $model->filterCategory($ctype['name'], $category, true);
     }
     // Приватность
     // флаг показа только названий
     $hide_except_title = !empty($ctype['options']['privacy_type']) && $ctype['options']['privacy_type'] == 'show_title';
     // Сначала проверяем настройки типа контента
     if (!empty($ctype['options']['privacy_type']) && in_array($ctype['options']['privacy_type'], array('show_title', 'show_all'), true)) {
         $model->disablePrivacyFilter();
         if ($ctype['options']['privacy_type'] != 'show_title') {
             $hide_except_title = false;
         }
     }
     // А потом, если разрешено правами доступа, отключаем фильтр приватности
     if (cmsUser::isAllowed($ctype['name'], 'view_all')) {
         $model->disablePrivacyFilter();
         $hide_except_title = false;
     }
     // Скрываем записи из скрытых родителей (приватных групп и т.п.)
     $model->filterHiddenParents();
     list($ctype, $model) = cmsEventsManager::hook('content_list_filter', array($ctype, $model));
     list($ctype, $model) = cmsEventsManager::hook("content_{$ctype['name']}_list_filter", array($ctype, $model));
     $items = $model->limit($limit)->getContentItems($ctype['name']);
     if (!$items) {
         return false;
     }
     list($ctype, $items) = cmsEventsManager::hook("content_before_list", array($ctype, $items));
     list($ctype, $items) = cmsEventsManager::hook("content_{$ctype['name']}_before_list", array($ctype, $items));
     return array('ctype' => $ctype, 'teaser_len' => $teaser_len, 'hide_except_title' => $hide_except_title, 'delay' => $delay, 'image_field' => $image_field, 'big_image_field' => $big_image_field, 'big_image_preset' => $big_image_preset, 'teaser_field' => $teaser_fields, 'items' => $items);
 }
Beispiel #15
0
 public function run($feed_id)
 {
     $feed = $this->model->getFeed($feed_id);
     if (!$feed) {
         cmsCore::error404();
     }
     $form = $this->getForm('feed');
     // выясняем контроллер ленты
     $controller = $feed['ctype_name'];
     if ($this->model->isCtypeFeed($feed['ctype_name'])) {
         $controller = 'content';
     }
     list($form, $feed) = cmsEventsManager::hook('rss_' . $controller . '_controller_form', array($form, $feed));
     list($form, $feed) = cmsEventsManager::hook('rss_edit_form', array($form, $feed));
     list($form, $feed) = cmsEventsManager::hook('rss_' . $feed['ctype_name'] . '_edit_form', array($form, $feed));
     if ($this->request->has('submit')) {
         $feed = array_merge($feed, $form->parse($this->request, true));
         $errors = $form->validate($this, $feed);
         if (!$errors) {
             $this->model->updateFeed($feed_id, $feed);
             cmsEventsManager::hook('rss_' . $controller . '_controller_after_update', $feed);
             $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));
 }
Beispiel #16
0
 public function parse($value)
 {
     if ($this->getOption('is_html_filter')) {
         $value = cmsEventsManager::hook('html_filter', array('text' => $value, 'is_auto_br' => false, 'build_redirect_link' => (bool) $this->getOption('build_redirect_link')));
     }
     return $value;
 }
Beispiel #17
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed('comments', 'delete')) {
         cmsCore::error404();
     }
     $comment = $this->model->getComment((int) $this->request->get('id'));
     // Проверяем
     if (!$comment) {
         cmsTemplate::getInstance()->renderJSON($result = array('error' => true, 'message' => LANG_ERROR));
     }
     $user = cmsUser::getInstance();
     if (!cmsUser::isAllowed('comments', 'delete', 'all') && !cmsUser::isAllowed('comments', 'delete', 'full_delete')) {
         if (cmsUser::isAllowed('comments', 'delete', 'own') && $comment['user']['id'] != $user->id) {
             cmsTemplate::getInstance()->renderJSON(array('error' => true, 'message' => LANG_ERROR));
         }
     }
     // проверяем, есть ли дети комментария
     $is_comment_child = $this->model->getItemByField('comments', 'parent_id', $comment['id']);
     $this->model->deleteComment($comment['id'], !$is_comment_child && cmsUser::isAllowed('comments', 'delete', 'full_delete', true));
     if (cmsUser::isAllowed('comments', 'delete', 'full_delete')) {
         cmsEventsManager::hook('comments_after_delete', $comment['id']);
     } else {
         cmsEventsManager::hook('comments_after_hide', $comment['id']);
     }
     cmsTemplate::getInstance()->renderJSON(array('error' => false, 'message' => LANG_COMMENT_DELETED));
 }
Beispiel #18
0
 public function run($ctype_name = false)
 {
     if (!$ctype_name) {
         cmsCore::error404();
     }
     $feed = $this->model->getFeedByCtypeName($ctype_name);
     if (!$feed || !$feed['is_enabled']) {
         cmsCore::error404();
     }
     $category_id = $this->request->get('category', false);
     $user_id = $this->request->get('user', false);
     $content_model = cmsCore::getModel('content');
     if ($category_id) {
         $category = $content_model->getCategory($ctype_name, $category_id);
     }
     if ($user_id) {
         $author = cmsCore::getModel('users')->getUser($user_id);
     }
     if (!empty($category)) {
         $content_model->filterCategory($ctype_name, $category, true);
     }
     if (!empty($author)) {
         $content_model->filterEqual('user_id', $user_id);
     }
     $content_model->orderBy('id', 'desc')->limit($feed['limit']);
     $feed['items'] = $content_model->getContentItems($ctype_name);
     $feed = cmsEventsManager::hook('before_render_' . $ctype_name . '_feed_list', $feed);
     header('Content-type: application/rss+xml; charset=utf-8');
     return cmsTemplate::getInstance()->renderPlain('feed', array('feed' => $feed, 'category' => isset($category) ? $category : false, 'author' => isset($author) ? $author : false));
 }
Beispiel #19
0
 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']);
 }
Beispiel #20
0
 public function run()
 {
     $form = $this->getForm('ctypes_basic', array('add'));
     $form = cmsEventsManager::hook('ctype_basic_form', $form);
     $is_submitted = $this->request->has('submit');
     $ctype = $form->parse($this->request, $is_submitted);
     if ($is_submitted) {
         $errors = $form->validate($this, $ctype);
         if (!$errors) {
             if (cmsCore::isControllerExists($ctype['name'])) {
                 $errors['name'] = LANG_CP_CTYPE_ERROR_NAME;
             }
         }
         if (!$errors) {
             $content_model = cmsCore::getModel('content');
             $ctype = cmsEventsManager::hook('ctype_before_add', $ctype);
             $ctype = cmsEventsManager::hook("ctype_{$ctype['name']}_before_add", $ctype);
             $ctype_id = $content_model->addContentType($ctype);
             $ctype['id'] = $ctype_id;
             cmsEventsManager::hook('ctype_after_add', $ctype);
             cmsEventsManager::hook("ctype_{$ctype['name']}_after_add", $ctype);
             if ($ctype_id) {
                 cmsCore::getController('content')->addWidgetsPages($ctype);
                 cmsUser::addSessionMessage(sprintf(LANG_CP_CTYPE_CREATED, $ctype['title']), 'success');
             }
             $this->redirectToAction('ctypes', array('labels', $ctype_id), array('wizard_mode' => true));
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('ctypes_basic', array('do' => 'add', 'ctype' => $ctype, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Beispiel #21
0
 public function run()
 {
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $email = $this->request->get('login_email');
     $password = $this->request->get('login_password');
     $remember = (bool) $this->request->get('remember');
     $back_url = $this->request->has('back') ? $this->request->get('back') : false;
     $is_site_offline = !cmsConfig::get('is_site_on');
     if ($this->request->has('submit')) {
         $is_captcha_valid = true;
         if (cmsUser::sessionGet('is_auth_captcha') && $this->options['auth_captcha']) {
             $is_captcha_valid = cmsEventsManager::hook('captcha_validate', $this->request);
         }
         if ($is_captcha_valid) {
             cmsUser::sessionUnset('is_auth_captcha');
             $logged_id = cmsUser::login($email, $password, $remember);
             if ($logged_id) {
                 if ($is_site_offline) {
                     $userSession = cmsUser::sessionGet('user');
                     if (!$userSession['is_admin']) {
                         cmsUser::addSessionMessage(LANG_LOGIN_ADMIN_ONLY, 'error');
                         cmsUser::logout();
                         $this->redirectBack();
                     }
                 }
                 cmsEventsManager::hook('auth_login', $logged_id);
                 $is_back = $this->request->get('is_back');
                 if ($is_back) {
                     $this->redirectBack();
                 }
                 if ($back_url) {
                     $this->redirect($back_url);
                 } else {
                     $this->redirectToHome();
                 }
             }
         }
         if ($this->options['auth_captcha'] && !$is_site_offline) {
             cmsUser::sessionSet('is_auth_captcha', true);
         }
         if ($is_captcha_valid) {
             cmsUser::addSessionMessage(LANG_LOGIN_ERROR, 'error');
             if ($is_site_offline) {
                 $this->redirectBack();
             }
         } else {
             cmsUser::addSessionMessage(LANG_CAPTCHA_ERROR, 'error');
         }
     }
     if ($back_url) {
         cmsUser::addSessionMessage(LANG_LOGIN_REQUIRED, 'error');
     }
     if (cmsUser::sessionGet('is_auth_captcha')) {
         $captcha_html = cmsEventsManager::hook('captcha_html');
     }
     return cmsTemplate::getInstance()->render('login', array('back_url' => $back_url, 'captcha_html' => isset($captcha_html) ? $captcha_html : false));
 }
Beispiel #22
0
 public function parse($value)
 {
     if ($this->getOption('is_html_filter')) {
         return cmsEventsManager::hook('html_filter', $value);
     } else {
         return nl2br(htmlspecialchars($value));
     }
 }
Beispiel #23
0
 public function parse($value)
 {
     if ($this->getOption('is_html_filter')) {
         return cmsEventsManager::hook('html_filter', array('text' => $value, 'is_auto_br' => true, 'build_redirect_link' => (bool) $this->getOption('build_redirect_link')));
     } else {
         return nl2br(htmlspecialchars($value));
     }
 }
Beispiel #24
0
 public function getPhotosList($item_type_id = 0, $item_type = '')
 {
     cmsEventsManager::hook('photos_list_filter', $this->model);
     $photos = $this->model->getPhotos($item_type_id, $item_type);
     if (!$photos) {
         return false;
     }
     return cmsEventsManager::hook('photos_before_list', $photos);
 }
Beispiel #25
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     // включено ли голосование от гостей?
     if (empty($this->options['allow_guest_vote']) && !$this->cms_user->is_logged) {
         return $this->cms_template->renderJSON(array('success' => false, 'message' => LANG_ERROR));
     }
     // Получаем параметры
     $direction = $this->request->get('direction', '');
     $target_controller = $this->request->get('controller', '');
     $target_subject = $this->request->get('subject', '');
     $target_id = $this->request->get('id', 0);
     $is_valid = $this->validate_sysname($target_controller) === true && $this->validate_sysname($target_subject) === true && is_numeric($target_id) && in_array($direction, array('up', 'down'));
     if (!$is_valid) {
         return $this->cms_template->renderJSON(array('success' => false, 'message' => LANG_ERROR));
     }
     // Объединяем всю информацию о голосе
     $vote = array('user_id' => $this->cms_user->id ? $this->cms_user->id : null, 'target_controller' => $target_controller, 'target_subject' => $target_subject, 'target_id' => $target_id, 'score' => $direction == 'up' ? 1 : -1, 'ip' => sprintf('%u', ip2long(cmsUser::getIp())));
     $cookie_key = $target_subject . $target_id . $target_controller;
     // Этот голос уже учитывался?
     $is_voted = $this->model->isUserVoted($vote, $this->cms_user->is_logged);
     if ($is_voted) {
         // если куки нет, ставим
         if (!empty($this->options['is_hidden']) && !cmsUser::getCookie($cookie_key)) {
             cmsUser::setCookie($cookie_key, 1, 2628000);
             // год
         }
         return $this->cms_template->renderJSON(array('success' => false, 'message' => LANG_RATING_VOTED));
     }
     $target_model = cmsCore::getModel($target_controller);
     $target = $target_model->getRatingTarget($target_subject, $target_id);
     if (!empty($target['user_id'])) {
         if ($this->cms_user->is_logged) {
             if ($target['user_id'] == $this->cms_user->id || !cmsUser::isAllowed($target_subject, 'rate')) {
                 return $this->cms_template->renderJSON(array('success' => false, 'message' => LANG_RATING_DISABLED));
             }
         }
     }
     // Добавляем голос в лог
     $this->model->addVote($vote);
     // Обновляем суммарный рейтинг цели
     $rating = (int) $target['rating'] + $vote['score'];
     $target_model->updateRating($target_subject, $target_id, $rating);
     // Оповещаем всех об изменении рейтинга
     cmsEventsManager::hook('rating_vote', array('subject' => $target_subject, 'id' => $target_id, 'target' => $target, 'vote' => $vote, 'rating' => $rating));
     // Собираем результат
     $result = array('success' => true, 'rating' => html_signed_num($rating), 'css_class' => html_signed_class($rating) . ($this->options['is_show'] ? ' clickable' : ''), 'message' => LANG_RATING_VOTED);
     // запоминаем в куках
     if (!empty($this->options['is_hidden'])) {
         cmsUser::setCookie($cookie_key, 1, 2628000);
         // год
     }
     return $this->cms_template->renderJSON($result);
 }
Beispiel #26
0
 public function run($group_id)
 {
     $content_model = cmsCore::getModel('content')->setTablePrefix('');
     $ctype = $content_model->getContentTypeByName('users');
     $fields = $content_model->getContentFields('users');
     $fields[] = array('title' => LANG_RATING, 'name' => 'rating', 'handler' => new fieldNumber('rating'));
     $fields[] = array('title' => LANG_KARMA, 'name' => 'karma', 'handler' => new fieldNumber('karma'));
     $fields = cmsEventsManager::hook('admin_users_filter', $fields);
     return cmsTemplate::getInstance()->render('users_filter', array('ctype' => $ctype, 'fields' => $fields));
 }
Beispiel #27
0
 public function run()
 {
     //
     // формируем виджеты главной админки
     //
     // Виджет статистики
     $chart_nav = cmsEventsManager::hookAll('admin_dashboard_chart');
     $cookie = cmsUser::getCookie('dashboard_chart');
     $defaults = array('controller' => 'users', 'section' => 'reg', 'period' => 7);
     if ($cookie) {
         $cookie = json_decode($cookie, true);
         if (is_array($cookie)) {
             $defaults = array('controller' => $cookie['c'], 'section' => $cookie['s'], 'period' => $cookie['p']);
         }
     }
     $dashboard_blocks[] = array('title' => LANG_CP_DASHBOARD_STATS, 'class' => 'col3', 'html' => $this->cms_template->getRenderedChild('index_chart', array('chart_nav' => $chart_nav, 'defaults' => $defaults)));
     $uploader = new cmsUploader();
     $extensions = get_loaded_extensions();
     $sysinfo = array(LANG_CP_DASHBOARD_SI_PHP => phpversion(), LANG_CP_DASHBOARD_SI_ML => files_format_bytes(files_convert_bytes(@ini_get('memory_limit'))), LANG_CP_DASHBOARD_SI_MAX => $uploader->getMaxUploadSize(), LANG_CP_DASHBOARD_SI_IP => filter_input(INPUT_SERVER, 'SERVER_ADDR'), LANG_CP_DASHBOARD_SI_ROOT => ROOT, LANG_CP_DASHBOARD_SI_SESSION => session_save_path(), LANG_CP_DASHBOARD_SI_ION => in_array('ionCube Loader', $extensions), LANG_CP_DASHBOARD_SI_ZEND => in_array('Zend Optimizer', $extensions), LANG_CP_DASHBOARD_SI_ZENDG => in_array('Zend Guard Loader', $extensions));
     $dashboard_blocks[] = array('title' => LANG_CP_DASHBOARD_SYSINFO, 'html' => $this->cms_template->getRenderedChild('index_sysinfo', array('sysinfo' => $sysinfo)));
     $dashboard_blocks[] = array('title' => LANG_CP_DASHBOARD_RESOURCES, 'html' => $this->cms_template->getRenderedChild('index_resources', array()));
     $dashboard_blocks = array_merge($dashboard_blocks, cmsEventsManager::hookAll('admin_dashboard_block', false, array()));
     $_block_id = 0;
     foreach ($dashboard_blocks as $dashboard_block) {
         // в одном хуке можно создавать несколько виджетов админки
         // для этого хук должен вернуть массив виджетов
         if (!isset($dashboard_block['title'])) {
             foreach ($dashboard_block as $sub_dashboard_block) {
                 $sub_dashboard_block['id'] = $_block_id;
                 $result_dashboard_blocks[$_block_id] = $sub_dashboard_block;
                 $_block_id++;
             }
         } else {
             $dashboard_block['id'] = $_block_id;
             $result_dashboard_blocks[$_block_id] = $dashboard_block;
         }
         $_block_id++;
     }
     // формируем с учетом порядка
     if (!empty($this->options['dashboard_order'])) {
         $order_id = 1000;
         foreach ($result_dashboard_blocks as $block_id => $block) {
             if (isset($this->options['dashboard_order'][$block_id])) {
                 $order_id = $this->options['dashboard_order'][$block_id];
             } else {
                 $order_id += 1;
             }
             $_result_dashboard_blocks[$order_id] = $block;
         }
         ksort($_result_dashboard_blocks);
     } else {
         $_result_dashboard_blocks = $result_dashboard_blocks;
     }
     return $this->cms_template->render('index', array('dashboard_blocks' => $_result_dashboard_blocks));
 }
Beispiel #28
0
 /**
  * Возвращает список всех слушателей указанного события
  * @param string $event_name Название события
  * @return array Список слушателей
  */
 public static function getEventListeners($event_name)
 {
     $listeners = array();
     if (self::$structure === null) {
         self::$structure = self::getAllListeners();
     }
     if (isset(self::$structure[$event_name])) {
         $listeners = self::$structure[$event_name];
     }
     return $listeners;
 }
Beispiel #29
0
 public function run()
 {
     $ctype_id = $this->getOption('ctype_id');
     $dataset_id = $this->getOption('dataset');
     $cat_id = $this->getOption('category_id');
     $image_field = $this->getOption('image_field');
     $teaser_field = $this->getOption('teaser_field');
     $is_show_details = $this->getOption('show_details');
     $style = $this->getOption('style', 'basic');
     $limit = $this->getOption('limit', 10);
     $model = cmsCore::getModel('content');
     $ctype = $model->getContentType($ctype_id);
     if (!$ctype) {
         return false;
     }
     if ($cat_id) {
         $category = $model->getCategory($ctype['name'], $cat_id);
     } else {
         $category = false;
     }
     if ($dataset_id) {
         $dataset = $model->getContentDataset($dataset_id);
         if ($dataset) {
             $model->applyDatasetFilters($dataset);
         } else {
             $dataset_id = false;
         }
     }
     if ($category) {
         $model->filterCategory($ctype['name'], $category, true);
         $model->groupBy('i.id');
     }
     if (!$dataset_id) {
         $model->orderBy('date_pub', 'desc');
     }
     // Отключаем фильтр приватности для тех кому это разрешено
     if (cmsUser::isAllowed($ctype['name'], 'view_all')) {
         $model->disablePrivacyFilter();
     }
     // Скрываем записи из скрытых родителей (приватных групп и т.п.)
     $model->filterHiddenParents();
     list($ctype, $model) = cmsEventsManager::hook("content_list_filter", array($ctype, $model));
     list($ctype, $model) = cmsEventsManager::hook("content_{$ctype['name']}_list_filter", array($ctype, $model));
     $items = $model->limit($limit)->getContentItems($ctype['name']);
     if (!$items) {
         return false;
     }
     if ($style) {
         $this->setTemplate('list_' . $style);
     } else {
         $this->setTemplate($this->tpl_body);
     }
     return array('ctype' => $ctype, 'image_field' => $image_field, 'teaser_field' => $teaser_field, 'is_show_details' => $is_show_details, 'style' => $style, 'items' => $items);
 }
Beispiel #30
0
 public function init()
 {
     return array(array('type' => 'fieldset', 'title' => LANG_SEARCH_IN_CTYPES, 'childs' => array(new fieldList('types', array('is_multiple' => true, 'generator' => function () {
         $search_controllers = cmsEventsManager::hookAll('fulltext_search');
         $items = array();
         foreach ($search_controllers as $controller) {
             $items = array_merge($items, $controller['sources']);
         }
         return $items;
     })), new fieldCheckbox('is_hash_tag', array('title' => LANG_SEARCH_IS_HASH_TAG)))), array('type' => 'fieldset', 'title' => LANG_SEARCH_PERPAGE, 'childs' => array(new fieldNumber('perpage', array('default' => 15, 'rules' => array(array('required')))))));
 }