public function execute() { if ($target_blog = max(0, $this->getRequest()->post('blog', 0, waRequest::TYPE_INT))) { $blog_model = new blogBlogModel(); if ($blog = $blog_model->getById($target_blog)) { if ($ids = $this->getRequest()->post('id', null, waRequest::TYPE_ARRAY_INT)) { $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); $this->response['moved'] = array(); foreach ($ids as $id) { try { //rights will checked for each record separately $post_model->updateItem($id, array('blog_id' => $target_blog)); $comment_model->updateByField('post_id', $id, array('blog_id' => $target_blog)); $this->response['moved'][$id] = $id; } catch (Exception $ex) { if (!isset($this->response['error'])) { $this->response['error'] = array(); } $this->response['error'][$id] = $ex->getMessage(); } } $this->response['style'] = $blog['color']; $blog_model->recalculate(); } } else { } } }
public function defaultAction() { // When viewed from a public dashboard, pretend we're logged in $old_user = $user = $this->getUser(); if (wa()->getUser()->getId() != $user->getId()) { $old_user = wa()->getUser(); wa()->setUser($user); } $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable(wa()->getUser()); $blog_id = $this->getSettings('blog_id'); if ($blog_id && !empty($blogs[$blog_id])) { $blog_ids = array($blog_id); } else { $blog_ids = array_keys($blogs); } $post_model = new blogPostModel(); $posts = $post_model->search(array('blog_id' => $blog_ids), array('status' => 'view', 'author_link' => false, 'rights' => true, 'text' => 'cut'), array('blog' => $blogs))->fetchSearchPage(1, 1); wa()->setUser($old_user); $post = reset($posts); $blog = false; if ($post && !empty($blogs[$post['blog_id']])) { $blog = $blogs[$post['blog_id']]; } $this->display(array('blog' => $blog, 'post' => $post)); }
public function execute() { ob_start(); $app = $this->getApp(); $app_settings_model = new waAppSettingsModel(); $app_settings_model->set($app, 'cron_schedule', time()); waFiles::create($this->getConfig()->getPath('log') . '/' . $app . '/'); $log_file = "{$app}/cron.txt"; $post_model = new blogPostModel(); $params = array('datetime' => date("Y-m-d H:i:s"), 'status' => blogPostModel::STATUS_SCHEDULED); $posts_schedule = $post_model->select("id,blog_id,contact_id,status,datetime")->where('datetime <= s:datetime AND status=s:status', $params)->fetchAll(); if ($posts_schedule) { foreach ($posts_schedule as $post) { try { waLog::log("Attempt publishing post with id [{$post['id']}]", $log_file); $data = array("status" => blogPostModel::STATUS_PUBLISHED); waLog::log($post_model->updateItem($post['id'], $data, $post) ? "success" : "fail", $log_file); } catch (Exception $ex) { waLog::log($ex->getMessage(), $log_file); waLog::log($ex->getTraceAsString(), $log_file); } } } $action = __FUNCTION__; /** * @event cron_action * @param string $action * @return void */ wa()->event('cron_action', $action); if ($log = ob_get_clean()) { waLog::log($log, $log_file); } }
public function execute() { $data = waRequest::post(); // check required params $this->post('blog_id', true); $this->post('title', true); $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']]; if ($blog['rights'] < blogRightConfig::RIGHT_READ_WRITE) { throw new waAPIException('access_denied', 403); } $data = array_merge($data, array('blog_status' => $blog['status'], 'url' => '', 'text' => '', 'status' => blogPostModel::STATUS_PUBLISHED)); $post_model = new blogPostModel(); $options = array(); if (waRequest::post('transliterate', null)) { $options['transliterate'] = true; } $messages = $post_model->validate($data, array('transliterate' => true)); if ($messages) { throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404); } $id = $post_model->updateItem(null, $data); $_GET['id'] = $id; $method = new blogPostGetInfoMethod(); $this->response = $method->getResponse(true); }
public function execute() { $this->getResponse()->addHeader('Content-type', 'application/json'); if ($comment_id = $this->getRequest()->post('id', 0, waRequest::TYPE_INT)) { $comment_model = new blogCommentModel(); $comment = $comment_model->getById($comment_id); if (!$comment) { throw new waException(_w('Comment not found'), 404); } $post_model = new blogPostModel(); if (!($post = $post_model->getBlogPost(array('id' => $comment['post_id'], 'blog_id' => $comment['blog_id'])))) { throw new waException(_w('Post not found'), 404); } $user_id = $this->getUser()->getId(); $rights = blogHelper::checkRights($comment['blog_id'], $user_id, blogRightConfig::RIGHT_READ_WRITE); if ($rights == blogRightConfig::RIGHT_READ_WRITE && $user_id != $post['contact_id']) { throw new waRightsException(_w('Access denied'), 403); } $status = $this->getRequest()->post('status', blogCommentModel::STATUS_DELETED); if ($status != blogCommentModel::STATUS_DELETED) { $status = blogCommentModel::STATUS_PUBLISHED; } $changed = $comment_model->updateById($comment_id, array('status' => $status)); $count = $comment_model->getCount($comment['blog_id'], $comment['post_id']); if ($changed) { if ($status == blogCommentModel::STATUS_DELETED) { $this->log('comment_delete', 1); } else { $this->log('comment_restore', 1); } } $this->response = array('count_str' => $count . " " . _w('comment', 'comments', $count), 'status' => $status, 'changed' => $changed); } }
public function execute() { $routes = $this->getRoutes(); $app_id = wa()->getApp(); $blog_model = new blogBlogModel(); $post_model = new blogPostModel(); $blogs = $blog_model->getAvailable(false, array('id', 'name', 'url')); foreach ($routes as $route) { $lastmod = null; $this->routing->setRoute($route); $default_blog_id = isset($route['blog_url_type']) ? (int) $route['blog_url_type'] : 0; $default_blog_id = max(0, $default_blog_id); $extend_options = array('datetime' => true); $extend_data = array('blog' => $blogs); foreach ($blogs as $blog_id => $blog) { if (!$default_blog_id || $blog_id == $default_blog_id) { $search_options = array('blog_id' => $blog_id); $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll('id,title,url,datetime,blog_id'); foreach ($posts as $post) { $post['blog_url'] = $blog['url']; $post_lastmod = strtotime($post['datetime']); $lastmod = max($lastmod, $post_lastmod); if (!empty($post['comment_datetime'])) { $post_lastmod = max($post_lastmod, strtotime($post['comment_datetime'])); } $this->addUrl($post['link'], $post_lastmod); } } } $this->addUrl(wa()->getRouteUrl($app_id . "/frontend", array(), true), $lastmod); } }
public function execute() { $blog_id = wa()->getRequest()->param('blog_url_type'); if ($blog_id <= 0) { $blog_id = waRequest::request('blog_id', 0, 'int'); } $this->setLayout(new blogFrontendLayout()); // Get contact id and name as post author if (wa()->getUser()->get('is_user')) { $post_contact_id = wa()->getUser()->getId(); $post_contact_name = wa()->getUser()->getName(); } else { foreach (blogHelper::getAuthors($blog_id) as $post_contact_id => $post_contact_name) { break; } } // Prepare empty fake post data $post_model = new blogPostModel(); $post = $post_model->prepareView(array(array('id' => 0, 'blog_id' => $blog_id, 'contact_id' => $post_contact_id, 'contact_name' => $post_contact_name, 'datetime' => date('Y-m-d H:i:s'), 'title' => '%replace-with-real-post-title%', 'status' => 'published', 'text' => '<div class="replace-with-real-post-text"></div>' . $this->getScripts(), 'comments_allowed' => 0) + $post_model->getEmptyRow())); $post = array_merge($post[0], array('comments' => array(), 'comment_link' => '', 'link' => '')); $this->getResponse()->setTitle(_w('Preview')); $this->getResponse()->setMeta('keywords', ''); $this->getResponse()->setMeta('description', ''); $current_auth = wa()->getStorage()->read('auth_user_data'); $current_auth_source = $current_auth ? $current_auth['source'] : null; $this->view->assign(array('realtime_preview' => true, 'frontend_post' => array(), 'errors' => array(), 'form' => array(), 'show_comments' => false, 'request_captcha' => false, 'require_authorization' => false, 'theme' => waRequest::param('theme', 'default'), 'current_auth_source' => $current_auth_source, 'current_auth' => $current_auth, true, 'auth_adapters' => wa()->getAuthAdapters(), 'post' => $post)); }
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); }
public function isInUse($value) { if ($this->subject == self::SUBJECT_BLOG) { $model = new blogBlogModel(); } else { $model = new blogPostModel(); } $cond = $this->options['id'] ? 'url = :url AND id != i:id' : 'url = :url'; return $model->select('id')->where($cond, array('url' => $value, 'id' => $this->options['id']))->limit(1)->fetch(); }
public function updateMarkdownText($post) { $post_id = $post['id']; $text = null; if (isset($post['plugin']) && isset($post['plugin'][$this->id]) && $post['plugin'][$this->id]) { $text = trim($post['plugin'][$this->id]); } $post_model = new blogPostModel(); $post_model->updateById($post_id, array('text_markdown' => $text)); }
static function move($blog_id, $move_blog_id) { if ($blog_id != $move_blog_id) { $post_model = new blogPostModel(); $post_model->updateByField('blog_id', $blog_id, array('blog_id' => $move_blog_id)); $comment_model = new blogCommentModel(); $comment_model->updateByField('blog_id', $blog_id, array('blog_id' => $move_blog_id)); $blog_model = new blogBlogModel(); $blog_model->recalculate(array($blog_id, $move_blog_id)); } }
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'); }
public function execute() { $post_id = max(0, waRequest::get('id', 0, waRequest::TYPE_INT)); if (!$post_id) { throw new waException(_w('Post not found'), 404); } $post_model = new blogPostModel(); $search_options = array('id' => $post_id); $extend_options = array('comments' => array(20), 'user' => array('photo_url_50'), 'status' => 'view'); $post = $post_model->search($search_options, $extend_options)->fetchSearchItem(); if (!$post) { throw new waException(_w('Post not found'), 404); } $post['rights'] = $this->getRights("blog.{$post['blog_id']}"); $posts = array(&$post); blogHelper::extendRights($posts, array(), $this->getUser()->getId()); blogPhotosBridge::loadAlbums($posts); if (isset($post['comments']) && $post['comments']) { $post['comments'] = blogCommentModel::extendRights($post['comments'], array($post_id => $post)); } $blog_model = new blogBlogModel(); $blog = $blog_model->getById($post['blog_id']); if ($blog['status'] != blogBlogModel::STATUS_PUBLIC || $post['status'] != blogPostModel::STATUS_PUBLISHED) { blogHelper::checkRights($post['blog_id'], true, blogRightConfig::RIGHT_READ); } $items = $blog_model->prepareView(array($blog)); $blog = array_shift($items); $this->setLayout(new blogDefaultLayout()); $this->getResponse()->setTitle($post['title']); /** * Backend post view page * UI hook allow extends post view page * @event backend_post * @param array[string]mixed $post Current page post item data * @param array[string]int $post['id'] Post ID * @param array[string]int $post['blog_id'] Post blog ID * @return array[string][string]string $backend_post['%plugin_id%']['footer'] Plugin %plugin_id% footer html */ $this->view->assign('backend_post', wa()->event('backend_post', $post, array('footer'))); $user = $this->getUser(); $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto(20))); $this->view->assign('blog_id', $blog['id']); $this->view->assign('blog', $blog); $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend')); if ($this->getConfig()->getOption('can_use_smarty')) { try { $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id); } catch (SmartyException $ex) { $post['text'] = blogPost::handleTemplateException($ex, $post); } } $this->view->assign('post', $post); }
private function verify() { $post_slug = waRequest::param('post_url', false, waRequest::TYPE_STRING); $post_model = new blogPostModel(); $this->post = $post_model->getBySlug($post_slug); if (!$this->post || $this->post['status'] != blogPostModel::STATUS_PUBLISHED || !$this->post['comments_allowed']) { throw new waException(_w('Post not found'), 404); } if ($this->blog_id && !in_array($this->post['blog_id'], (array) $this->blog_id)) { throw new waException(_w('Post not found'), 404); } }
public function execute() { if ($ids = $this->getRequest()->post('id', null, waRequest::TYPE_ARRAY_INT)) { $post_model = new blogPostModel(); $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable($this->getUser(), 'id'); $options = array('id' => $ids, 'blog_id' => array_keys($blogs)); $this->response['deleted'] = $post_model->deleteByField($options); $this->logAction('post_delete', implode(',', $ids)); } else { $this->errors[] = 'empty request'; } }
/** * @param int[] $params Deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute($params) { $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $params, true); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); foreach ($contacts as $contact) { $data = array('contact_id' => 0, 'contact_name' => $contact['name']); $post_model->updateByField('contact_id', $contact['id'], $data); $data = array('contact_id' => 0, 'name' => $contact['name'], 'auth_provider' => null); $comment_model->updateByField('contact_id', $contact['id'], $data); } }
public function execute() { $rss_author_tag = null; if ($blog_id = $this->getRequest()->param('blog_id')) { $rss_posts_number = max(1, $this->appSettings('rss_posts_number', 10)); $rss_author_tag = $this->appSettings('rss_author_tag'); $options = array(); $data = array(); switch ($rss_author_tag) { case 'blog': $blog_model = new blogBlogModel(); $data['blog'] = $blog_model->getByField(array('id' => $blog_id), 'id'); break; default: $data['blog'] = blogHelper::getAvailable(); break; } $options['params'] = true; $options['user'] = '******'; $post_model = new blogPostModel(); $posts = $post_model->search(array('blog_id' => $blog_id), $options, $data)->fetchSearchPage(1, $rss_posts_number); blogPhotosBridge::loadAlbums($posts); } else { $posts = array(); } $link = wa()->getRouteUrl('blog/frontend', array(), true); $rss_link = wa()->getRouteUrl('blog/frontend/rss', array(), true); $title = waRequest::param('rss_title') ? waRequest::param('rss_title') : wa()->accountName(); $this->view->assign('info', array('title' => $title, 'link' => $link, 'description' => '', 'language' => 'ru', 'pubDate' => date(DATE_RSS), 'lastBuildDate' => date(DATE_RSS), 'self' => $rss_link)); $this->view->assign('blog_name', $this->getResponse()->getTitle()); $this->view->assign('rss_author_tag', $rss_author_tag); if ($this->getConfig()->getOption('can_use_smarty')) { foreach ($posts as &$post) { try { $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id); } catch (SmartyException $ex) { $post['text'] = blogPost::handleTemplateException($ex, $post); } } unset($post); } foreach ($posts as &$post) { if (is_array($post['user']['email'])) { $post['user']['email'] = reset($post['user']['email']); } } unset($post); $this->view->assign('posts', $posts); $this->getResponse()->addHeader('Content-Type', 'application/rss+xml; charset=utf-8'); }
public function execute() { $contact_photo_size = 20; $comments_per_page = max(1, intval($this->getConfig()->getOption('comments_per_page'))); $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT)); $blog_models = new blogBlogModel(); $user = $this->getUser(); $blogs = blogHelper::getAvailable(); $comment_model = new blogCommentModel(); $offset = $comments_per_page * ($page - 1); $prepare_options = array('datetime' => blogActivity::getUserActivity()); $fields = array("photo_url_{$contact_photo_size}"); $blog_ids = array_keys($blogs); $comments = $comment_model->getList($offset, $comments_per_page, $blog_ids, $fields, $prepare_options); $comments_all_count = $comment_model->getCount($blog_ids, null, null, null, null, null); $post_ids = array(); foreach ($comments as $comment) { $post_ids[$comment['post_id']] = true; } //get related posts info $post_model = new blogPostModel(); $search_options = array('id' => array_keys($post_ids)); $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false); $extend_data = array('blog' => $blogs); $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false); $comments = blogCommentModel::extendRights($comments, $posts); $comments_count = ($page - 1) * $comments_per_page + count($comments); if ($page == 1) { $this->setLayout(new blogDefaultLayout()); $this->getResponse()->setTitle(_w('Comments')); } /** * Backend comments view page * UI hook allow extends backend comments view page * @event backend_comments * @param array[int][string]mixed $comments * @param array[int][string]int $comments[%id%][id] comment id * @return array[string][string]string $return[%plugin_id%]['toolbar'] Comment's toolbar html */ $this->view->assign('backend_comments', wa()->event('backend_comments', $comments)); $this->view->assign('comments', $comments); $this->view->assign('comments_count', $comments_count); $this->view->assign('comments_total_count', $comments_all_count); $this->view->assign('comments_per_page', $comments_per_page); $this->view->assign('pages', ceil($comments_all_count / $comments_per_page)); $this->view->assign('page', $page); $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend')); $this->view->assign('current_contact_id', $user->getId()); $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto($contact_photo_size))); }
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); } }
public function execute() { $id = $this->post('id', true); if (!is_array($id)) { if (strpos($id, ',') !== false) { $id = array_map('intval', explode(',', $id)); } else { $id = array($id); } } $post_model = new blogPostModel(); $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable(wa()->getUser(), 'id'); $post_model->deleteByField(array('id' => $id, 'blog_id' => array_keys($blogs))); $this->response = true; }
public function execute() { $id = $this->get('id', true); $post_model = new blogPostModel(); $post = $post_model->search(array('id' => $id))->fetchSearchItem(); if ($post) { $blog_model = new blogBlogModel(); $blog = $blog_model->getById($post['blog_id']); if ($blog['status'] != blogBlogModel::STATUS_PUBLIC || $post['status'] != blogPostModel::STATUS_PUBLISHED) { blogHelper::checkRights($post['blog_id'], true, blogRightConfig::RIGHT_READ); } $this->response = $post; } else { throw new waAPIException('invalid_param', 'Post not found', 404); } }
/** * @param array $params deleted contact_id * @return array|void */ public function execute(&$params) { waLocale::loadByDomain('blog'); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); $links = array(); foreach ($params as $contact_id) { $links[$contact_id] = array(); if ($count = $post_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('blog', 'Posts author'), 'links_number' => $count); } if ($count = $comment_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('blog', 'Comments author'), 'links_number' => $count); } } return $links; }
public function execute() { $data = waRequest::post('data', null); if (!$data) { return; } foreach ($data as $name => $value) { if (in_array($name, $this->allowed_fields) === false) { throw new waException("Can't update post: editing of this field is denied"); } if ($name == 'status') { if (in_array($value, array(blogPostModel::STATUS_DRAFT, blogPostModel::STATUS_DEADLINE, blogPostModel::STATUS_SCHEDULED, blogPostModel::STATUS_PUBLISHED)) === false) { throw new waException("Can't change status: unknown value"); } } } $post_id = waRequest::post('post_id', null, waRequest::TYPE_INT); $post_model = new blogPostModel(); $post = null; if ($post_id) { $post = $post_model->getFieldsById($post_id, array('id', 'blog_id', 'contact_id', 'datetime')); } if (!$post) { throw new waException("Unknown post"); } $contact = wa()->getUser(); $contact_id = $contact->getId(); $allow = blogHelper::checkRights($post['blog_id'], $contact_id, $contact_id != $post['contact_id'] ? blogRightConfig::RIGHT_FULL : blogRightConfig::RIGHT_READ_WRITE); if (!$allow) { throw new waException("Access denied"); } if (!$post_model->updateById($post_id, $data)) { throw new waException("Error when updating data"); } $post = array_merge($post, $data); if ($post['status'] == blogPostModel::STATUS_DEADLINE) { $user = wa()->getUser(); $timezone = $user->getTimezone(); $current_datetime = waDateTime::date("Y-m-d", null, $timezone); $datetime = waDateTime::date("Y-m-d", $post['datetime'], $timezone); if ($datetime <= $current_datetime) { $post['overdue'] = true; } } $this->response['post'] = $post; }
public function execute() { $data = waRequest::post(); $exclude = array('left_key', 'right_key', 'type', 'full_url', 'parent_id'); foreach ($exclude as $k) { if (isset($data[$k])) { unset($data[$k]); } } // check required params $this->post('text', true); $post_id = $this->get('post_id', true); $post_model = new blogPostModel(); $post = $post_model->getBlogPost($post_id); if (!$post) { throw new waAPIException('invalid_param', 'Post not found', 404); } $parent_id = $this->post('parent_id'); $comment_model = new blogCommentModel(); if ($parent_id) { $parent = $comment_model->getById($parent_id); if (!$parent) { throw new waAPIException('invalid_param', 'Parent comment not found', 404); } } $contact_id = wa()->getUser()->getId(); // check rights try { blogHelper::checkRights($post['blog_id'], $contact_id, blogRightConfig::RIGHT_READ); } catch (waException $e) { throw new waAPIException('access_denied', 403); } // check comment mode if (!$post['comments_allowed']) { throw new waAPIException('invalid_param', "Isn't allowed comment to this post", 404); } $data = array_merge($data, array('blog_id' => $post['blog_id'], 'post_id' => $post_id, 'contact_id' => $contact_id, 'auth_provider' => blogCommentModel::AUTH_USER)); $messages = $comment_model->validate($data); if ($messages) { throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404); } $id = $comment_model->add($data, $parent_id); $_GET['id'] = $id; $method = new blogPostCommentsGetInfoMethod(); $this->response = $method->getResponse(true); }
public function run() { $app_settings_model = new waAppSettingsModel(); $contact_settings_model = new waContactSettingsModel(); $app_settings_model->set('blog', 'last_reminder_cron_time', time()); // remider settings for all users $reminders = $contact_settings_model->select('contact_id, value')->where("app_id='blog' AND name='reminder'")->fetchAll('contact_id', true); if (!$reminders) { return; } $time = time(); // do job no more one time in 24 hours $last_cron_times = $contact_settings_model->select('contact_id')->where("app_id='blog' AND name='last_reminder_cron_time' AND value <= " . ($time - 86400))->fetchAll('contact_id', true); $reminders_allowed = array_keys($last_cron_times); if (!$reminders_allowed) { return; } $post_model = new blogPostModel(); $backend_url = $app_settings_model->get('blog', 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl()); $message_count = 0; foreach ($reminders_allowed as $contact_id) { $days = $reminders[$contact_id]; // get all deadline posts for this contact $posts = $post_model->select("id, title, datetime")->where("status='" . blogPostModel::STATUS_DEADLINE . "' AND contact_id=" . $contact_id . " AND datetime < '" . date('Y-m-d H:i:s', $time + $days * 86400) . "'")->order('datetime')->fetchAll(); if ($posts) { $contact = new waContact($contact_id); $email = $contact->get('email', 'default'); $message = new waMailMessage(_w('Scheduled blog posts'), $this->getMessage($posts, $time, $backend_url)); try { $message->setTo($email); if ($message->send()) { $message_count++; } } catch (Exception $e) { } } $contact_settings_model->set($contact_id, 'blog', 'last_reminder_cron_time', $time); } /** * Notify plugins about sending reminder * @event followup_send * @return void */ wa()->event('reminder_send', $message_count); }
public function execute() { $hash = $this->get('hash'); $offset = waRequest::get('offset', 0, 'int'); if ($offset < 0) { throw new waAPIException('invalid_param', 'Param offset must be greater than or equal to zero'); } $limit = waRequest::get('limit', 100, 'int'); if ($limit < 0) { throw new waAPIException('invalid_param', 'Param limit must be greater than or equal to zero'); } if ($limit > 1000) { throw new waAPIException('invalid_param', 'Param limit must be less or equal 1000'); } $options = array(); $hash = explode('/', trim($hash, '/')); $hash[1] = isset($hash[1]) ? $hash[1] : ''; switch ($hash[0]) { case 'blog': $options['blog_id'] = (int) $hash[1]; break; case 'contact': case 'author': $options['contact_id'] = (int) $hash[1]; break; case 'search': $options['text'] = $hash[1]; break; case 'tag': // use plugin $options['plugin'] = array('tag' => $hash[1]); break; } if ($options) { $post_model = new blogPostModel(); $posts = $post_model->search($options)->fetchSearch($offset, $limit); } else { $posts = array(); } $this->response['count'] = count($posts); $this->response['offset'] = $offset; $this->response['limit'] = $limit; $this->response['posts'] = array_values($posts); }
/** * @param int[] $params Deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute(&$params) { $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $params, true); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); foreach ($contacts as $contact) { $data = array('contact_id' => 0, 'contact_name' => $contact['name']); $post_model->updateByField('contact_id', $contact['id'], $data); $data = array('contact_id' => 0, 'name' => $contact['name'], 'auth_provider' => null); $comment_model->updateByField('contact_id', $contact['id'], $data); } /** * @event contacts_delete * @param array[] int $contact_ids array of contact's ID * @return void */ wa()->event(array('blog', 'contacts_delete'), $params); }
public function execute() { $routes = $this->getRoutes(); $app_id = wa()->getApp(); $blog_model = new blogBlogModel(); $post_model = new blogPostModel(); $page_model = new blogPageModel(); $blogs = $blog_model->getAvailable(false, array('id', 'name', 'url')); $real_domain = $this->routing->getDomain(null, true, false); foreach ($routes as $route) { $lastmod = null; $this->routing->setRoute($route); $default_blog_id = isset($route['blog_url_type']) ? (int) $route['blog_url_type'] : 0; $default_blog_id = max(0, $default_blog_id); $extend_options = array('datetime' => true); $extend_data = array('blog' => $blogs); foreach ($blogs as $blog_id => $blog) { if (!$default_blog_id || $blog_id == $default_blog_id) { $search_options = array('blog_id' => $blog_id); $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll('id,title,url,datetime,blog_id'); foreach ($posts as $post) { $post['blog_url'] = $blog['url']; $post_lastmod = strtotime($post['datetime']); $lastmod = max($lastmod, $post_lastmod); if (!empty($post['comment_datetime'])) { $post_lastmod = max($post_lastmod, strtotime($post['comment_datetime'])); } $this->addUrl($post['link'], $post_lastmod); } } } // pages $main_url = wa()->getRouteUrl($app_id . "/frontend", array(), true, $real_domain); $domain = $this->routing->getDomain(null, true); $sql = "SELECT full_url, url, create_datetime, update_datetime FROM " . $page_model->getTableName() . ' WHERE status = 1 AND domain = s:domain AND route = s:route'; $pages = $page_model->query($sql, array('domain' => $domain, 'route' => $route['url']))->fetchAll(); foreach ($pages as $p) { $this->addUrl($main_url . $p['full_url'], $p['update_datetime'] ? $p['update_datetime'] : $p['create_datetime'], self::CHANGE_MONTHLY, 0.6); } $this->addUrl(wa()->getRouteUrl($app_id . "/frontend", array(), true, $real_domain), $lastmod, self::CHANGE_DAILY, 1.0); } }
public function execute() { $this->getResponse()->addHeader('Content-type', 'application/json'); $post_id = waRequest::post('post_id', null); $date = waRequest::post('date'); if (!is_null($post_id)) { $post_model = new blogPostModel(); $post = $post_model->getFieldsById($post_id, array('status')); $status = $post['status']; if ($status == blogPostModel::STATUS_DEADLINE || $status == blogPostModel::STATUS_DRAFT) { if (strlen($date) == 0) { $this->response['valid'] = true; return; } } } $this->response['valid'] = true; if (!waDateTime::parse('date', $date, wa()->getUser()->getTimezone())) { $this->response['valid'] = false; } }
public function defaultAction() { $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable(wa()->getUser()); $blog_id = $this->getSettings('blog_id'); if ($blog_id && !empty($blogs[$blog_id])) { $blog_ids = array($blog_id); } else { $blog_ids = array_keys($blogs); } $search_options = array('blog_id' => $blog_ids); $extend_options = array('status' => 'view', 'author_link' => false, 'rights' => true, 'text' => 'cut'); $post_model = new blogPostModel(); $posts = $post_model->search($search_options, $extend_options, array('blog' => $blogs))->fetchSearchPage(1, 1); $post = reset($posts); $blog = false; if ($post && !empty($blogs[$post['blog_id']])) { $blog = $blogs[$post['blog_id']]; } $this->display(array('blog' => $blog, 'post' => $post)); }