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; } } } }