本文整理汇总了PHP中cmsEventsManager::hook方法的典型用法代码示例。如果您正苦于以下问题:PHP cmsEventsManager::hook方法的具体用法?PHP cmsEventsManager::hook怎么用?PHP cmsEventsManager::hook使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cmsEventsManager
的用法示例。
在下文中一共展示了cmsEventsManager::hook方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getWidget
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));
}
示例2: run
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);
}
示例3: run
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));
}
示例4: actionOptions
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));
}
示例5: run
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']));
}
示例6: run
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'])));
}
示例7: run
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);
}
示例8: run
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));
}
}
示例9: parse
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;
}
示例10: run
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');
}
示例11: run
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));
}
示例12: run
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));
}
示例13: run
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();
}
示例14: actionLogout
public function actionLogout()
{
cmsEventsManager::hook('auth_logout', cmsUser::getInstance()->id);
cmsUser::logout();
$this->redirectToHome();
$this->halt();
}
示例15: run
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));
}