本文整理汇总了PHP中blogPostModel::getPreviewHash方法的典型用法代码示例。如果您正苦于以下问题:PHP blogPostModel::getPreviewHash方法的具体用法?PHP blogPostModel::getPreviewHash怎么用?PHP blogPostModel::getPreviewHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blogPostModel
的用法示例。
在下文中一共展示了blogPostModel::getPreviewHash方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$post_title = waRequest::post('post_title', '', waRequest::TYPE_STRING_TRIM);
$blog_id = waRequest::post('blog_id', 0, waRequest::TYPE_INT);
$slug = waRequest::post('slug', '', waRequest::TYPE_STRING_TRIM);
$blog_model = new blogBlogModel();
$blog = $blog_model->getById($blog_id);
if (!$blog) {
throw new waException(_w("Can't find corresponding blog"));
}
$this->response['is_private_blog'] = $blog['status'] == blogBlogModel::STATUS_PRIVATE;
$post_id = waRequest::post('post_id', 0, waRequest::TYPE_INT);
$post_model = new blogPostModel();
if ($post_id) {
$post = $post_model->getById($post_id, array('text', 'text_before_cut'));
if (!$post) {
throw new waException(_w("Can't find corresponding post"));
}
if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
$options = array('contact_id' => $post['contact_id'], 'blog_id' => $blog_id, 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId());
$this->response['preview_hash'] = blogPostModel::getPreviewHash($options);
$this->response['preview_hash'] = base64_encode($this->response['preview_hash'] . $options['user_id']);
}
$this->response['slug'] = $post['url'];
$this->response['is_published'] = $post['status'] == blogPostModel::STATUS_PUBLISHED;
$this->response['is_adding'] = false;
} else {
$post = array();
$this->response['slug'] = $slug ? $slug : blogHelper::transliterate($post_title);
$this->response['is_published'] = false;
$this->response['is_adding'] = true;
}
$post['blog_id'] = $blog_id;
$post['album_link_type'] = 'blog';
$other_links = blogPostModel::getPureUrls($post);
$this->response['link'] = array_shift($other_links);
if (!$this->response['link']) {
$this->response['is_private_blog'] = true;
}
$this->response['other_links'] = $other_links;
foreach ($this->response as $k => &$item) {
if (!$item || !is_string($item) && !is_array($item)) {
continue;
}
if (is_array($item)) {
$item = array_map('htmlspecialchars', $item, array_fill(0, count($item), ENT_QUOTES));
continue;
}
$item = htmlspecialchars($item, ENT_QUOTES);
}
unset($item);
$this->getResponse()->addHeader('Content-type', 'application/json');
}
示例2: frontendExecute
public function frontendExecute()
{
$post_slug = waRequest::param('post_url', false, waRequest::TYPE_STRING_TRIM);
$storage = wa()->getStorage();
$post_model = new blogPostModel();
$show_comments = $this->appSettings('show_comments', true);
$request_captcha = $show_comments && $this->appSettings('request_captcha', true);
$require_authorization = $show_comments && $this->appSettings('require_authorization', false);
$available = blogHelper::getAvailable();
// it's preview
$hash = waRequest::get('preview');
$post = $post_model->search(array('url' => $post_slug, 'status' => $hash ? false : blogPostModel::STATUS_PUBLISHED), array('comments' => $show_comments ? array(50, 20) : false, 'params' => true, 'escape' => true), array('blog' => $available))->fetchSearchItem();
if (!$post) {
throw new waException(_w('Post not found'), 404);
}
if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
$hash = base64_decode($hash);
list($hash, $user_id) = array(substr($hash, 0, 32), substr($hash, 32));
$options = array('contact_id' => $post['contact_id'], 'blog_id' => $post['blog_id'], 'post_id' => $post['id'], 'user_id' => $user_id);
$preview_cached_options = $storage->read('preview');
$preview_cached_post_options = isset($preview_cached_options['post_id']) ? $preview_cached_options['post_id'] : null;
if ($preview_cached_post_options && $preview_cached_post_options != $options) {
$preview_cached_post_options = null;
}
if (!$preview_cached_post_options) {
if ($hash == blogPostModel::getPreviewHash($options, false, false)) {
$preview_cached_options['post_id'] = $preview_cached_post_options = $options;
$storage->write('preview', $preview_cached_options);
}
}
if (!$preview_cached_post_options) {
throw new waException(_w('Post not found'), 404);
}
if (!$this->checkAuthorRightsToBlog($user_id, $post)) {
throw new waException(_w('Post not found'), 404);
}
}
$title = $this->getResponse()->getTitle();
if ($this->getRequest()->param('title_type', 'blog_post') == 'blog_post') {
if ($title) {
$this->getResponse()->setTitle($title . " » " . $post['title']);
} elseif (isset($available[$post['blog_id']]) && ($title = $available[$post['blog_id']]['title'])) {
$this->getResponse()->setTitle($title . " » " . $post['title']);
} else {
$this->getResponse()->setTitle($post['title']);
}
} else {
$this->getResponse()->setTitle($post['title']);
}
$blog_id = (array) $this->getRequest()->param('blog_id');
if (!in_array($post['blog_id'], $blog_id)) {
if ($this->getRequest()->param('blog_url_type') == 0) {
if (isset($available[$post['blog_id']])) {
$this->redirect($post['link'], 301);
}
}
throw new waException(_w('Post not found'), 404);
}
$this->getRequest()->setParam('blog_id', $post['blog_id']);
if (isset($post['comments']) && !empty($post['comments'])) {
$depth = 1000;
foreach ($post['comments'] as $key => $comment) {
if ($comment['status'] == blogCommentModel::STATUS_DELETED) {
if ($comment['depth'] < $depth) {
$depth = $comment['depth'];
}
unset($post['comments'][$key]);
continue;
}
if ($comment['depth'] > $depth) {
unset($post['comments'][$key]);
} else {
$depth = 1000;
}
}
}
$errors = array();
$form = array();
if ($storage->read('errors') !== null) {
$errors = $storage->read('errors');
$form = $storage->read('form');
$storage->remove('errors');
$storage->remove('form');
}
$post['comment_link'] = blogPost::getUrl($post, 'comment');
$post['link'] = blogPost::getUrl($post);
/**
* Frontend post view page
* UI hook allow extends frontend post view page
* @event frontend_post
* @param array[string]mixed $post
* @param array[string]int $post['id']
* @param array[string]int $post['blog_id']
* @return array[string][string]string $return[%plugin_id%]
* @return array[string][string]string $return[%plugin_id%]['footer']
*/
$this->view->assign('frontend_post', wa()->event('frontend_post', $post));
$this->view->assign('errors', $errors);
$this->view->assign('form', $form);
$this->view->assign('show_comments', $show_comments);
//.........这里部分代码省略.........
示例3: save
private function save($post)
{
$options = array();
if (waRequest::post('transliterate', null)) {
$options['transliterate'] = true;
}
$this->validate_messages = $this->post_model->validate($post, $options);
if ($this->validate_messages) {
$this->errors = $this->validate_messages;
} else {
$post['text_before_cut'] = null;
$post['cut_link_label'] = null;
$template = '<!--[\\s]*?more[\\s]*?(text[\\s]*?=[\\s]*?[\'"]([\\s\\S]*?)[\'"])*[\\s]*?-->';
$descriptor = preg_split("/{$template}/", $post['text'], 2, PREG_SPLIT_DELIM_CAPTURE);
if ($descriptor) {
if (count($descriptor) == 2) {
$post['text_before_cut'] = blogPost::closeTags($descriptor[0]);
} elseif (count($descriptor) > 2) {
$post['text_before_cut'] = blogPost::closeTags($descriptor[0]);
if (isset($descriptor[2])) {
$post['cut_link_label'] = $descriptor[2];
}
}
}
if ($post['id']) {
$prev_post = $this->post_model->getFieldsById($post['id'], 'status');
if ($prev_post['status'] != blogPostModel::STATUS_PUBLISHED && $post['status'] == blogPostModel::STATUS_PUBLISHED) {
$this->inline = false;
}
$this->post_model->updateItem($post['id'], $post);
if ($prev_post['status'] != blogPostModel::STATUS_PUBLISHED && $post['status'] == blogPostModel::STATUS_PUBLISHED) {
$this->log('post_publish', 1);
} else {
$this->log('post_edit', 1);
}
} else {
$post['id'] = $this->post_model->updateItem(null, $post);
$this->log('post_publish', 1);
}
$this->saveParams($post['id']);
$this->clearViewCache($post['id'], $post['url']);
if (!$this->inline) {
if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
$params = array('module' => 'post', 'action' => 'edit', 'id' => $post['id']);
} elseif ($post['blog_status'] == blogBlogModel::STATUS_PUBLIC) {
$params = array('blog' => $post['blog_id']);
} else {
$params = array('module' => 'post', 'id' => $post['id']);
}
$this->response['redirect'] = $this->getRedirectUrl($params);
} else {
$this->response['formatted_datetime'] = waDateTime::format('humandatetime', $post['datetime']);
$this->response['id'] = $post['id'];
$this->response['url'] = $post['url'];
if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
$options = array('contact_id' => $post['contact_id'], 'blog_id' => $post['blog_id'], 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId());
$preview_hash = blogPostModel::getPreviewHash($options);
$this->response['preview_hash'] = base64_encode($preview_hash . $options['user_id']);
$this->response['debug'] = $options;
}
}
}
}
示例4: execute
public function execute()
{
$post_id = waRequest::get('id', null, waRequest::TYPE_INT);
$blog_model = new blogBlogModel();
$blogs = $blog_model->getAvailable();
if (!$blogs) {
$this->setTemplate('BlogNotFound');
return;
}
$blogs = $blog_model->prepareView($blogs);
if ($post_id) {
// edit post
$post_model = new blogPostModel();
$post = $post_model->getById($post_id);
if (!$post) {
throw new waException(_w('Post not found'), 404);
}
//check rights
if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != $this->getUser()->getId()) {
throw new waRightsException(_w('Access denied'));
}
$post['datetime'] = $post['datetime'] >= 1971 ? $post['datetime'] : '';
$blog_id = $post['blog_id'];
$blog = $blogs[$blog_id];
$title = trim(sprintf(_w('Editing post %s'), $post['title']));
} else {
// add post
$date = waRequest::get('date', '');
$blog = $this->getAllowedBlog($blogs, wa()->getStorage()->read('blog_last_id'));
if (!$blog) {
throw new waRightsException(_w('Access denied'));
}
$blog_id = $blog['id'];
$post = array('title' => $this->getRequest()->post('title', '', waRequest::TYPE_STRING_TRIM), 'text' => $this->getRequest()->post('text', '', waRequest::TYPE_STRING_TRIM), 'continued_text' => null, 'categories' => array(), 'contact_id' => wa()->getUser()->getId(), 'url' => '', 'blog_id' => $blog_id, 'comments_allowed' => true);
$post['id'] = '';
$post['status'] = $date ? blogPostModel::STATUS_DEADLINE : blogPostModel::STATUS_DRAFT;
$post['datetime'] = '';
$post['meta_title'] = null;
$post['meta_keywords'] = null;
$post['meta_description'] = null;
$title = _w('Adding new post');
}
$all_links = blogPostModel::getPureUrls($post);
$post['other_links'] = $all_links;
$post['link'] = array_shift($post['other_links']);
$post['remaining_time'] = null;
if ($post['status'] == blogPostModel::STATUS_SCHEDULED && $post['datetime']) {
$post['remaining_time'] = $this->calculateRemainingTime($post['datetime']);
}
if ($blog['rights'] >= blogRightConfig::RIGHT_FULL) {
$users = blogHelper::getAuthors($post['blog_id']);
} else {
$user = $this->getUser();
$users = array($user->getId() => $user->getName());
}
// preview hash for all type of drafts
if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
$options = array('contact_id' => $post['contact_id'], 'blog_id' => $blog_id, 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId());
$preview_hash = blogPostModel::getPreviewHash($options);
$this->view->assign('preview_hash', base64_encode($preview_hash . $options['user_id']));
}
$this->view->assign('no_settlements', empty($all_links) ? true : false);
$this->view->assign('params', $this->getPostParams($post['id']));
$this->view->assign('blog', $blog);
$this->view->assign('users', $users);
$this->view->assign('blogs', $blogs);
$allow_change_blog = 0;
foreach ($blogs as $blog_item) {
if ($blog_item['rights'] >= blogRightConfig::RIGHT_READ_WRITE) {
++$allow_change_blog;
}
}
$this->view->assign('allow_change_blog', $allow_change_blog);
$this->view->assign('post_id', $post_id);
$this->view->assign('datetime_timezone', waDateTime::date("T", null, wa()->getUser()->getTimezone()));
/**
* Backend post edit page
* UI hook allow extends post edit page
* @event backend_post_edit
* @param array[string]mixed $post
* @param array[string]int $post['id']
* @param array[string]int $post['blog_id']
* @return array[string][string]string $return[%plugin_id%]['sidebar'] Plugin sidebar html output
* @return array[string][string]string $return[%plugin_id%]['toolbar'] Plugin toolbar html output
* @return array[string][string]string $return[%plugin_id%]['editor_tab'] Plugin editor tab html output
*/
$this->view->assign('backend_post_edit', wa()->event('backend_post_edit', $post, array('sidebar', 'toolbar', 'editor_tab')));
$app_settings = new waAppSettingsModel();
$show_comments = $app_settings->get($this->getApp(), 'show_comments', true);
$this->view->assign('show_comments', $show_comments);
$this->view->assign('post', $post);
/**
* @deprecated
* For backward compatibility reason
*/
$this->view->assign('cron_schedule_time', waSystem::getSetting('cron_schedule', 0, 'blog'));
$this->view->assign('last_schedule_cron_time', waSystem::getSetting('last_schedule_cron_time', 0, 'blog'));
$this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog schedule');
$this->setLayout(new blogDefaultLayout());
$this->getResponse()->setTitle($title);
//.........这里部分代码省略.........