Show post when it is added - refs BT#12324

pull/2487/head
Angel Fernando Quiroz Campos 8 years ago
parent 28ef92043e
commit 40abbbc63a
  1. 32
      main/blog/blog.php
  2. 70
      main/inc/lib/blog.lib.php

@ -40,17 +40,6 @@ $safe_comment_title = isset($_POST['comment_title']) ? Security::remove_XSS($_PO
$safe_task_name = isset($_POST['task_name']) ? Security::remove_XSS($_POST['task_name']) : null;
$safe_task_description = isset($_POST['task_description']) ? Security::remove_XSS($_POST['task_description']) : null;
if (!empty($_POST['new_post_submit'])) {
Blog::createPost(
$_POST['title'],
$_POST['full_text'],
$_POST['post_file_comment'],
$blog_id
);
Display::addFlash(
Display::return_message(get_lang('BlogAdded'), 'success')
);
}
if (!empty($_POST['edit_post_submit'])) {
Blog::editPost(
$_POST['post_id'],
@ -350,27 +339,12 @@ switch ($action) {
case 'new_post':
$formAdd = '';
if (api_is_allowed('BLOG_'.$blog_id, 'article_add', $user_task ? $task_id : 0)) {
// we show the form if
// 1. no post data
// 2. there is post data and the required field is empty
if (!$_POST OR (!empty($_POST) AND empty($_POST['title']))) {
// if there is post data there is certainly an error in the form
if ($_POST) {
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'));
}
$formAdd = Blog::displayPostCreateForm($blog_id);
} else {
if (isset($_GET['filter']) && !empty($_GET['filter'])) {
Blog::getDailyResults($blog_id, Database::escape_string($_GET['filter']));
} else {
Blog::getPosts($blog_id);
}
}
$formAdd = Blog::displayPostCreateForm($blog_id);
$tpl->assign('content', $formAdd);
$blogLayout = $tpl->get_template('blog/layout.tpl');
} else {
api_not_allowed();
}
$tpl->assign('content', $formAdd);
$blogLayout = $tpl->get_template('blog/layout.tpl');
break;
case 'view_post' :
$postArticle = Blog::getSinglePost($blog_id, intval($_GET['post_id']));

@ -404,6 +404,8 @@ class Blog
}
}
}
return $last_post_id;
} else {
Display::display_error_message(get_lang('UplNoFileUploaded'));
}
@ -1518,33 +1520,53 @@ class Blog
public static function displayPostCreateForm($blog_id)
{
$blog_id = intval($blog_id);
if (api_is_allowed('BLOG_'.$blog_id, 'article_add')) {
$form = new FormValidator(
'add_post',
'post',
api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=".$blog_id."&".api_get_cidreq(),
null,
array('enctype' => 'multipart/form-data')
if (!api_is_allowed('BLOG_'.$blog_id, 'article_add')) {
api_not_allowed();
}
$form = new FormValidator(
'add_post',
'post',
api_get_path(WEB_CODE_PATH)."blog/blog.php?action=new_post&blog_id=".$blog_id."&".api_get_cidreq(),
null,
array('enctype' => 'multipart/form-data')
);
$form->addHidden('post_title_edited', 'false');
$form->addHeader(get_lang('NewPost'));
$form->addText('title', get_lang('Title'));
$config = array();
$config['ToolbarSet'] = !api_is_allowed_to_edit() ? 'ProjectStudent' : 'Project';
$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
$form->addFile('user_upload', get_lang('AddAnAttachment'));
$form->addTextarea('post_file_comment', get_lang('FileComment'));
$form->addHidden('new_post_submit', 'true');
$form->addButton('save', get_lang('Save'));
if ($form->validate()) {
$values = $form->exportValues();
$postId = Blog::createPost(
$values['title'],
$values['full_text'],
$values['post_file_comment'],
$blog_id
);
$form->addHidden('post_title_edited', 'false');
$form->addHeader(get_lang('NewPost'));
$form->addText('title', get_lang('Title'));
$config = array();
if (!api_is_allowed_to_edit()) {
$config['ToolbarSet'] = 'ProjectStudent';
} else {
$config['ToolbarSet'] = 'Project';
}
$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
$form->addFile('user_upload', get_lang('AddAnAttachment'));
$form->addTextarea('post_file_comment', get_lang('FileComment'));
$form->addHidden('new_post_submit', 'true');
$form->addButton('save', get_lang('Save'));
return $form->return_form();
} else {
api_not_allowed();
if ($postId) {
Display::addFlash(
Display::return_message(get_lang('BlogAdded'), 'success')
);
header('Location: '.api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
'action' => 'view_post',
'blog_id' => $blog_id,
'post_id' => $postId,
]));
exit;
}
}
return $form->returnForm();
}
/**

Loading…
Cancel
Save