function editBlog() { $results = array(); // User has not posted the article edit form yet: display the form $results['blog'] = Blog::getBlogById((int) $_POST['blogId']); include 'templates/editBlog.php'; }
public static function actionUpdate($id) { $blog = Blog::getBlogById($id); if (!$blog) { $blog = array(); } $errors = array(); $title = ''; $description = ''; $content = ''; if (isset($_POST['submit'])) { $title = FunctionLibrary::clearStr($_POST['title']); $description = nl2br(FunctionLibrary::clearStr($_POST['description'])); $content = nl2br(FunctionLibrary::clearStr($_POST['content'])); if (!User::checkName($title)) { $errors[] = 'Заглавие не может быть пустым.'; } if (!User::checkName($description)) { $errors[] = 'Описание не может быть пустым.'; } if (!User::checkName($content)) { $errors[] = 'Содержание не может быть пустым.'; } if (empty($errors)) { $result = Blog::updateBlogById($id, $title, $description, $content); if (!$result) { $_SESSION['message'] = 'Произошла ошибка при редактировании.'; } else { if (!empty($_FILES['image']['tmp_name'])) { $tmpName = $_FILES['image']['tmp_name']; if (is_uploaded_file($tmpName)) { $imagePath = "/images/blog/blog{$id}.jpg"; $result = Blog::putImageToDataBase($id, $imagePath); if ($result) { $destination = ROOT . '/template' . $imagePath; $moveResult = move_uploaded_file($tmpName, $destination); if (!$moveResult) { $_SESSION['message'] = "Произошла ошибка при добавлении картинки."; } } } } } FunctionLibrary::redirectTo('/admin/blog'); } } require_once ROOT . '/views/admin-blog/update.php'; return true; }
public function actionView($id) { $categories = Category::getCategoriesList(); if (!$categories) { $categories = array(); } $blog = Blog::getBlogById($id); if (!$blog) { $blog = array(); } if ($blog['id'] != $id) { FunctionLibrary::redirectTo('/blog'); } require_once ROOT . '/views/blog/view.php'; return true; }
function viewBlog() { if (!isset($_GET["blogId"]) || !$_GET["blogId"]) { homepage(); return; } $data = Page::getPageByTitle($_GET['action']); //body content echo "<div id='output'>"; if ($data) { if ($data->page_protection == '1' && !isset($_SESSION['name'])) { echo "Please log-in to view this page."; } else { if ($data->page_status == 'draft') { echo "This page is not yet published. Contact the site admin."; } else { //show body and blog echo "<p>" . $data->page_body . "</p>"; $results = array(); $results['blog'] = Blog::getBlogById($_GET["blogId"]); $results['pageTitle'] = $results['blog']->title . " | Widget News"; $row = $results['blog']; echo "<input type='hidden' value='" . $row->id . "' id='hBlogId'/>"; echo '<h1 class="headSection">' . $row->title . '</h1><p class="smallText">' . $row->publicationDate . '</p><p>' . $row->content . '</p>'; echo '<p style="font-weight:bold;">Share this!</p><a href="#"><img src="include/images/fb.png"/></a><a href="#"><img src="include/images/twit.png"/></a><a href="#"><img src="include/images/rss2.png"/></a><a href="#"><img src="include/images/google.png"/></a><a href="#"><img src="include/images/delicious.png"/></a><a href="#"><img src="include/images/stumbleupon.png"/></a><a href="#"><img src="include/images/digg.png"/></a><hr/>'; echo '<div id="commentSection"><p class="smallText">Leave a comment...</p><textarea id="comment" placeholder="Put your comment here" required maxlength="1000" style="height: 3em; width:90%; display: block;margin-left: auto;margin-right: auto;"></textarea><input type="button" id="submitComment" value="Post!" title="' . $_GET["blogId"] . '"/></div>'; //existing comments getComment(); //end of comment } } } echo "</div>"; //end of body content //sidebar echo "<div id='sidebar'>"; if ($data) { echo "<p>" . $data->page_sidebar . "</p>"; } echo "</div>"; //end of sidebar }