예제 #1
0
 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);
 }
예제 #2
0
 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);
 }
 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;
             }
         }
     }
 }