本文整理汇总了PHP中blogPostModel::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP blogPostModel::getById方法的具体用法?PHP blogPostModel::getById怎么用?PHP blogPostModel::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blogPostModel
的用法示例。
在下文中一共展示了blogPostModel::getById方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$id = $this->get('id', true);
$post_model = new blogPostModel();
$post = $post_model->getById($id);
if (!$post) {
throw new waAPIException('invalid_param', 'Post not found', 404);
}
//check rights
if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != wa()->getUser()->getId()) {
throw new waAPIException('access_denied', 403);
}
$data = array_merge($post, waRequest::post());
$blog_model = new blogBlogModel();
$blogs = $blog_model->getAvailable();
if (!isset($blogs[$data['blog_id']])) {
throw new waAPIException('invalid_param', 'Blog not found', 404);
}
$blog = $blogs[$data['blog_id']];
$data['blog_status'] = $blog['status'];
$data['datetime'] = $this->formateDatetime($data['datetime']);
$messages = $post_model->validate($data, array('transliterate' => true));
if ($messages) {
throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404);
}
$post_model->updateItem($data['id'], $data);
$_GET['id'] = $id;
$method = new blogPostGetInfoMethod();
$this->response = $method->getResponse(true);
}
示例2: 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');
}
示例3: run
public function run($params = NULL)
{
$app_settings_model = new waAppSettingsModel();
$app_settings_model->set(array('blog', 'emailsubscription'), 'last_emailsubscription_cron_time', time());
$model = new blogEmailsubscriptionLogModel();
$row = $model->getByField('status', 0);
if ($row) {
$post_id = $row['post_id'];
$post_model = new blogPostModel();
$post = $post_model->getById($post_id);
$blog_model = new blogBlogModel();
$blog = $blog_model->getById($post['blog_id']);
$subject = $blog['name'] . ': ' . $post['title'];
$post_title = htmlspecialchars($post['title']);
if ($blog['status'] == blogBlogModel::STATUS_PUBLIC) {
$post_url = blogPost::getUrl($post);
} else {
$app_settings_model = new waAppSettingsModel();
$post_url = $app_settings_model->get(array('blog', 'emailsubscription'), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
$post_url .= "/blog/?module=post&id=" . $post_id;
}
$blog_name = htmlspecialchars($blog['name']);
$body = '<html><body>' . sprintf(_wp("New post in the blog “%s”"), $blog_name) . ': <strong><a href="' . $post_url . '">' . $post_title . '</a></strong></body></html>';
$message = new waMailMessage();
$message->setEncoder(Swift_Encoding::getBase64Encoding());
$message->setSubject($subject);
$message->setBody($body);
$rows = $model->getByField(array('status' => 0, 'post_id' => $post_id), true);
$message_count = 0;
foreach ($rows as $row) {
try {
$message->setTo($row['email'], $row['name']);
$status = $message->send() ? 1 : -1;
$model->setStatus($row['id'], $status);
if ($status) {
$message_count++;
}
} catch (Exception $e) {
$model->setStatus($row['id'], -1, $e->getMessage());
}
}
/**
* Notify plugins about sending emailsubscripition
* @event followup_send
* @return void
*/
wa()->event('emailsubscription_send', $message_count);
}
}
示例4: execute
public function execute()
{
$post_id = $this->get('post_id', true);
$post_model = new blogPostModel();
$post = $post_model->getById($post_id);
if (!$post) {
throw new waAPIException('invalid_param', 'Post not found', 404);
}
$parent_id = waRequest::get('parent_comment_id');
$comment_model = new blogCommentModel();
$comments = $comment_model->getSubtree($post_id, $parent_id);
$stack = array();
$result = array();
foreach ($comments as $r) {
$r['comments'] = array();
// Number of stack items
$l = count($stack);
// Check if we're dealing with different levels
while ($l > 0 && $stack[$l - 1]['depth'] >= $r['depth']) {
array_pop($stack);
$l--;
}
// Stack is empty (we are inspecting the root)
if ($l == 0) {
// Assigning the root node
$i = count($result);
$result[$i] = $r;
$stack[] =& $result[$i];
} else {
// Add node to parent
$i = count($stack[$l - 1]['comments']);
$stack[$l - 1]['comments'][$i] = $r;
$stack[] =& $stack[$l - 1]['comments'][$i];
}
}
$this->response = $result;
$this->response['_element'] = 'comment';
}
示例5: explainLogs
public function explainLogs($logs)
{
$logs = parent::explainLogs($logs);
$app_url = wa()->getConfig()->getBackendUrl(true) . $this->application . '/';
$post_ids = array();
$comment_ids = array();
foreach ($logs as $l_id => $l) {
if (in_array($l['action'], array('page_add', 'page_edit', 'page_move')) && isset($l['params_html'])) {
$logs[$l_id]['params_html'] = str_replace('#/pages/', '?module=pages#/', $l['params_html']);
} else {
if ($l['action'] == 'post_edit' && version_compare(wa('webasyst')->getVersion(), '1.4.0.40888') >= 0) {
// Removal of log records in activity is only supported since 1.4.0.40888,
// but we don't want to raise requirements yet, so have to check for version here.
// !!! TODO: should probably remove the check later and update requirements.php
$logs[$l_id] = null;
} else {
if (in_array($l['action'], array('post_edit', 'post_publish', 'post_unpublish')) && $l['params']) {
$post_ids[$l['params']] = 1;
} else {
if (in_array($l['action'], array('comment_add', 'comment_delete', 'comment_restore')) && $l['params']) {
$comment_ids[$l['params']] = 1;
}
}
}
}
}
if ($comment_ids) {
$comment_model = new blogCommentModel();
$comments = $comment_model->getById(array_keys($comment_ids));
foreach ($comments as $c) {
$post_ids[$c['post_id']] = 1;
}
}
if ($post_ids) {
$post_model = new blogPostModel();
$posts = $post_model->getById(array_keys($post_ids));
}
foreach ($logs as $l_id => $l) {
if (!$l) {
continue;
}
// Link to blog post in question
$p = $c = null;
if (in_array($l['action'], array('post_edit', 'post_publish', 'post_unpublish')) && isset($posts[$l['params']])) {
$p = $posts[$l['params']];
} else {
if (in_array($l['action'], array('comment_add', 'comment_delete', 'comment_restore')) && isset($comments[$l['params']])) {
$c = $comments[$l['params']];
if (isset($posts[$c['post_id']])) {
$p = $posts[$c['post_id']];
}
}
}
if (!empty($p)) {
if ($p['status'] == blogPostModel::STATUS_PUBLISHED) {
$url = $app_url . '?module=post&id=' . $p['id'];
} else {
$url = $app_url . '?module=post&action=edit&id=' . $p['id'];
}
$logs[$l_id]['params_html'] = '<div class="activity-target"><a href="' . $url . '">' . htmlspecialchars($p['title']) . '</a></div>';
}
if (!empty($c)) {
$logs[$l_id]['params_html'] .= '<div class="activity-body"><p' . ($c['status'] == 'deleted' ? ' class="strike gray"' : '') . '>' . nl2br(htmlspecialchars(mb_substr($c['text'], 0, 512))) . '</p></div>';
}
}
return $logs;
}
示例6: 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);
//.........这里部分代码省略.........