Bywalec
Postów: 332 Pomógł: 25 Ostrzeżeń: 1
Data rejestracji: 09.05.2005 00:08
|
Tak sobie pomyślałem, że w artykułach przydałaby się opcja uploadu obrazów, tak jak to jest w newsach.
I spróbowałem to zrobić na podstawie analogii do newsów.
Zmodyfikowałem plik articles.php i wstawiłem do niego wszystkie funkcje związane z dodawaniem obrazów jakie znalazłem w news.php (oczywiście wszystkie nazwy pozamieniałem z news na articles).
Do tabeli articles dodałem dodatkowe 3 pola tak jak to jest w newsach. W maincore.php dodałem IMAGES_A_T.
Ale efekt jest taki, że pojawia się biała strona w miejscu gdzie powinny być pola do edycji.
Nagłówek, panele boczne i stopka wyświetla się prawidłowo.
Czy ktoś może zerknąć fachowym okiem na mój plik articles.php i zobaczyć gdzie popełniłem błąd.
Albo może jakieś inne sugestie się komuś nasuną?
Z góry dziękuję za wszelką pomoc.
Zawartość pliku articles.php
<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2010 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: articles.php
| Author: Nick Jones (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at http://www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../maincore.php";
require_once THEMES."templates/admin_header_mce.php";
include LOCALE.LOCALESET."admin/articles.php";
if (!checkrights("A") || !defined("iAUTH") || $_GET['aid'] != iAUTH) { redirect("../index.php"); }
if ($settings['tinymce_enabled'] == 1) {
echo "<script language='javascript' type='text/javascript'>advanced();</script>\n";
} else {
require_once INCLUDES."html_buttons_include.php";
}
if (isset($_GET['status']) && !isset($message)) {
if ($_GET['status'] == "sn") {
$message = $locale['410'];
} elseif ($_GET['status'] == "su") {
$message = $locale['411'];
} elseif ($_GET['status'] == "del") {
$message = $locale['412'];
}
if ($message) { echo "<div id='close-message'><div class='admin-message'>".$message."</div></div>\n"; }
}
$result = dbcount("(article_cat_id)", DB_ARTICLE_CATS);
if (!empty($result)) {
if (isset($_POST['save'])) {
$subject = stripinput($_POST['subject']);
if (isset($_FILES['article_image']) && is_uploaded_file($_FILES['article_image']['tmp_name'])) {
require_once INCLUDES."photo_functions_include.php";
$image = $_FILES['article_image'];
$image_name = str_replace(" ", "_", strtolower(substr($image['name'], 0, strrpos($image['name'], "."))));
$image_ext = strtolower(strrchr($image['name'],"."));
if ($image_ext == ".gif") { $filetype = 1;
} elseif ($image_ext == ".jpg") { $filetype = 2;
} elseif ($image_ext == ".png") { $filetype = 3;
} else { $filetype = false; }
if (!preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $image_name)) {
$error = 1;
} elseif ($image['size'] > $settings['article_photo_max_b']){
$error = 2;
} elseif (!$filetype) {
$error = 3;
} else {
$image_t1 = image_exists(IMAGES_A_T, $image_name."_t1".$image_ext);
$image_t2 = image_exists(IMAGES_A_T, $image_name."_t2".$image_ext);
$image_full = image_exists(IMAGES_A, $image_name.$image_ext);
move_uploaded_file($_FILES['article_image']['tmp_name'], IMAGES_A.$image_full);
if (function_exists("chmod")) { chmod(IMAGES_A.$image_full, 0644); }
$imagefile = @getimagesize(IMAGES_A.$image_full);
if ($imagefile[0] > $settings['news_photo_max_w'] || $imagefile[1] > $settings['news_photo_max_h']) {
$error = 4;
unlink(IMAGES_A.$image_full);
} else {
createthumbnail($filetype, IMAGES_A.$image_full, IMAGES_A_T.$image_t1, $settings['news_photo_w'], $settings['news_photo_h']);
if ($settings['news_thumb_ratio'] == 0) {
createthumbnail($filetype, IMAGES_A.$image_full, IMAGES_A_T.$image_t2, $settings['news_thumb_w'], $settings['news_thumb_h']);
} else {
createsquarethumbnail($filetype, IMAGES_A.$image_full, IMAGES_A_T.$image_t2, $settings['news_thumb_w']);
}
}
}
if (!$error) {
$article_image = $image_full;
$article_image_t1 = $image_t1;
$article_image_t2 = $image_t2;
} else {
$article_image = "";
$article_image_t1 = "";
$article_image_t2 = "";
}
} else {
$article_image = (isset($_POST['article_image']) ? $_POST['article_image'] : "");
$article_image_t1 = (isset($_POST['article_image_t1']) ? $_POST['article_image_t1'] : "");
$article_image_t2 = (isset($_POST['article_image_t2']) ? $_POST['article_image_t2'] : "");
}
$body = addslash($_POST['body']);
$body2 = addslash($_POST['body2']);
$draft = isset($_POST['article_draft']) ? "1" : "0";
if ($settings['tinymce_enabled'] != 1) { $breaks = isset($_POST['line_breaks']) ? "y" : "n"; } else { $breaks = "n"; }
$comments = isset($_POST['article_comments']) ? "1" : "0";
$ratings = isset($_POST['article_ratings']) ? "1" : "0";
if (isset($_POST['article_id']) && isnum($_POST['article_id'])) {
$result = dbquery("SELECT news_image, news_image_t1, news_image_t2 FROM ".DB_NEWS." WHERE news_id='".$_POST['news_id']."' LIMIT 1");
if (dbrows($result)) {
$data = dbarray($result);
if (isset($_POST['del_image'])) {
if (!empty($data['article_image']) && file_exists(IMAGES_A.$data['article_image'])) { unlink(IMAGES_A.$data['article_image']); }
if (!empty($data['article_image_t1']) && file_exists(IMAGES_A_T.$data['article_image_t1'])) { unlink(IMAGES_A_T.$data['article_image_t1']); }
if (!empty($data['article_image_t2']) && file_exists(IMAGES_A_T.$data['article_image_t2'])) { unlink(IMAGES_A_T.$data['article_image_t2']); }
$news_image = "";
$news_image_t1 = "";
$news_image_t2 = "";
}
$result = dbquery("UPDATE ".DB_ARTICLES." SET article_cat='".intval($_POST['article_cat'])."', article_subject='$subject', article_image='$article_image', article_snippet='$body', article_article='$body2', article_image_t1='$article_image_t1', article_image_t2='$article_image_t2', article_draft='$draft', article_breaks='$breaks', article_allow_comments='$comments', article_allow_ratings='$ratings' WHERE article_id='".$_POST['article_id']."'");
redirect(FUSION_SELF.$aidlink."&status=su");
} else {
$result = dbquery("INSERT INTO ".DB_ARTICLES." (article_cat, article_subject, article_snippet, article_article, article_image, article_image_t1, article_image_t2, article_draft, article_breaks, article_name, article_datestamp, article_reads, article_allow_comments, article_allow_ratings) VALUES ('".intval($_POST['article_cat'])."', '$subject', '$body', '$body2', '$draft', '$breaks', '".$userdata['user_id']."', '".time()."', '0', '$comments', '$ratings')");
redirect(FUSION_SELF.$aidlink."&status=sn");
}
} else if (isset($_POST['delete']) && (isset($_POST['article_id']) && isnum($_POST['article_id']))) {
$result = dbquery("SELECT article_image, article_image_t1, article_image_t2 FROM ".DB_ARTICLES." WHERE article_id='".$_POST['article_id']."' LIMIT 1");
if (dbrows($result)) {
$data = dbarray($result);
if (!empty($data['article_image']) && file_exists(IMAGES_A.$data['article_image'])) { unlink(IMAGES_A.$data['article_image']); }
if (!empty($data['article_image_t1']) && file_exists(IMAGES_A_T.$data['article_image_t1'])) { unlink(IMAGES_A_T.$data['article_image_t1']); }
if (!empty($data['article_image_t2']) && file_exists(IMAGES_A_T.$data['article_image_t2'])) { unlink(IMAGES_A_T.$data['article_image_t2']); }
$result = dbquery("DELETE FROM ".DB_ARTICLES." WHERE article_id='".$_POST['article_id']."'");
$result = dbquery("DELETE FROM ".DB_COMMENTS." WHERE comment_item_id='".$_POST['article_id']."' and comment_type='A'");
$result = dbquery("DELETE FROM ".DB_RATINGS." WHERE rating_item_id='".$_POST['article_id']."' and rating_type='A'");
redirect(FUSION_SELF.$aidlink."&status=del");
}
} else {
if (isset($_POST['preview'])) {
$article_cat = $_POST['article_cat'];
$subject = stripinput($_POST['subject']);
$body = phpentities(stripslash($_POST['body']));
$body2 = phpentities(stripslash($_POST['body2']));
$bodypreview = str_replace("src='".str_replace("../", "", IMAGES_A), "src='".IMAGES_A, stripslash($_POST['body']));
$body2preview = str_replace("src='".str_replace("../", "", IMAGES_A), "src='".IMAGES_A, stripslash($_POST['body2']));
$article_image = (isset($_POST['article_image']) ? $_POST['article_image'] : "");
$article_image_t1 = (isset($_POST['article_image_t1']) ? $_POST['article_image_t1'] : "");
$article_image_t2 = (isset($_POST['article_image_t2']) ? $_POST['article_image_t2'] : "");
$draft = isset($_POST['article_draft']) ? " checked='checked'" : "";
if (isset($_POST['line_breaks'])) {
$breaks = " checked='checked'";
$bodypreview = nl2br($bodypreview);
$body2preview = nl2br($body2preview);
} else {
$breaks = "";
}
$comments = isset($_POST['article_comments']) ? " checked='checked'" : "";
$ratings = isset($_POST['article_ratings']) ? " checked='checked'" : "";
opentable($subject);
echo $bodypreview."\n";
closetable();
opentable($subject);
echo $body2preview."\n";
closetable();
}
}
$result = dbquery("SELECT article_id, article_subject, article_draft FROM ".DB_ARTICLES." ORDER BY article_draft DESC, article_datestamp DESC");
if (dbrows($result)) {
$editlist = ""; $sel = "";
while ($data = dbarray($result)) {
if ((isset($_POST['article_id']) && isnum($_POST['article_id'])) || (isset($_GET['article_id']) && isnum($_GET['article_id']))) {
$article_id = isset($_POST['article_id']) ? $_POST['article_id'] : $_GET['article_id'];
$sel = ($article_id == $data['article_id'] ? " selected='selected'" : "");
} else {
$sel = "";
}
$editlist .= "<option value='".$data['article_id']."'".$sel.">".($data['article_draft'] ? $locale['433']." " : "").$data['article_subject']."</option>\n";
}
opentable($locale['402']);
echo "<div style='text-align:center'>\n<form name='selectform' method='post' action='".FUSION_SELF.$aidlink."&action=edit'>\n";
echo "<select name='article_id' class='textbox' style='width:250px;'>\n".$editlist."</select>\n";
echo "<input type='submit' name='edit' value='".$locale['420']."' class='button' />\n";
echo "<input type='submit' name='delete' value='".$locale['421']."' onclick='return DeleteArticle();' class='button' />\n";
echo "</form>\n</div>\n";
closetable();
}
if ((isset($_GET['action']) && $_GET['action'] == "edit") && (isset($_POST['article_id']) && isnum($_POST['article_id'])) || (isset($_GET['article_id']) && isnum($_GET['article_id']))) {
$result = dbquery("SELECT article_cat, article_subject, article_snippet, article_article, article_image, article_image_t1, article_image_t2, article_draft, article_breaks, article_allow_comments, article_allow_ratings FROM ".DB_ARTICLES." WHERE article_id='".(isset($_POST['article_id']) ? $_POST['article_id'] : $_GET['article_id'])."'");
if (dbrows($result)) {
$data = dbarray($result);
$article_cat = $data['article_cat'];
$subject = $data['article_subject'];
$body = phpentities(stripslashes($data['article_snippet']));
$body2 = phpentities(stripslashes($data['article_article']));
$article_image = $data['article_image'];
$article_image_t1 = $data['article_image_t1'];
$article_image_t2 = $data['article_image_t2'];
$draft = $data['article_draft'] ? " checked='checked'" : "";
$breaks = $data['article_breaks'] == "y" ? " checked='checked'" : "";
$comments = $data['article_allow_comments'] ? " checked='checked'" : "";
$ratings = $data['article_allow_ratings'] ? " checked='checked'" : "";
} else {
redirect(FUSION_SELF.$aidlink);
}
}
if ((isset($_POST['article_id']) && isnum($_POST['article_id'])) || (isset($_GET['article_id']) && isnum($_GET['article_id']))) {
opentable($locale['401']);
} else {
if (!isset($_POST['preview'])) {
$subject = "";
$body = "";
$body2 = "";
$article_image = "";
$article_image_t1 = "";
$article_image_t2 = "";
$draft = "";
$breaks = " checked='checked'";
$comments = " checked='checked'";
$ratings = " checked='checked'";
}
opentable($locale['400']);
}
$result = dbquery("SELECT article_cat_id, article_cat_name FROM ".DB_ARTICLE_CATS." ORDER BY article_cat_name DESC");
$catlist = ""; $sel = "";
while ($data = dbarray($result)) {
if (isset($article_cat)) $sel = ($article_cat == $data['article_cat_id'] ? " selected='selected'" : "");
$catlist .= "<option value='".$data['article_cat_id']."'$sel>".$data['article_cat_name']."</option>\n";
}
echo "<form name='inputform' method='post' action='".FUSION_SELF.$aidlink."' onsubmit='return ValidateForm(this)'>\n";
echo "<table cellpadding='0' cellspacing='0' class='center'>\n<tr>\n";
echo "<td width='100' class='tbl'>".$locale['422']."</td>\n";
echo "<td class='tbl'><select name='article_cat' class='textbox' style='width:250px;'>".$catlist."</select></td>\n";
echo "</tr>\n<tr>\n";
echo "<td width='100' class='tbl'>".$locale['423']."</td>\n";
echo "<td class='tbl'><input type='text' name='subject' value='$subject' class='textbox' style='width:250px;' /></td>\n";
echo "</tr>\n<tr>\n";
echo "<td class='tbl' valign='top'>".$locale['439'].":</td>\n<td class='tbl' valign='top'>";
if ($article_image != "" && $article_image_t1 != "") {
echo "<label><img src='".IMAGES_A_T.$article_image_t2."' alt='".$locale['439']."' /><br />\n";
echo "<input type='checkbox' name='del_image' value='y' /> ".$locale['421']."</label>\n";
echo "<input type='hidden' name='article_image' value='".$article_image."' />\n";
echo "<input type='hidden' name='article_image_t1' value='".$article_image_t1."' />\n";
echo "<input type='hidden' name='article_image_t2' value='".$article_image_t2."' />\n";
} else {
echo "<input type='file' name='article_image' class='textbox' style='width:250px;' /><br />\n";
echo sprintf($locale['440'], parsebytesize($settings['news_photo_max_b']))."\n";
}
echo "</td>\n</tr>\n<tr>\n";
echo "<td valign='top' width='100' class='tbl'>".$locale['424']."</td>\n";
echo "<td class='tbl'><textarea name='body' cols='95' rows='5' class='textbox' style='width:98%'>".$body."</textarea></td>\n";
echo "</tr>\n";
if ($settings['tinymce_enabled'] != 1) {
echo "<tr>\n<td class='tbl'></td>\n<td class='tbl'>\n";
echo display_html("inputform", "body", true, true, true, IMAGES_A);
echo "</td>\n</tr>\n";
}
echo "<tr>\n<td valign='top' width='100' class='tbl'>".$locale['425']."</td>\n";
echo "<td class='tbl'><textarea name='body2' cols='95' rows='10' class='textbox' style='width:98%'>".$body2."</textarea></td>\n";
echo "</tr>\n";
if ($settings['tinymce_enabled'] != 1) {
echo "<tr>\n<td class='tbl'></td><td class='tbl'>\n";
echo "<input type='button' value='".$locale['432']."' class='button' style='width:80px;' onclick=\"insertText('body2', '<--PAGEBREAK-->');\" />\n";
echo display_html("inputform", "body2", true, true, true, IMAGES_A);
echo "</td>\n</tr>\n";
}
echo "<tr>\n";
echo "<td class='tbl'></td><td class='tbl'>\n";
echo "<label><input type='checkbox' name='article_draft' value='yes'".$draft." /> ".$locale['426']."</label><br />\n";
if ($settings['tinymce_enabled'] != 1) { echo "<label><input type='checkbox' name='line_breaks' value='yes'".$breaks." /> ".$locale['427']."</label><br />\n"; }
echo "<label><input type='checkbox' name='article_comments' value='yes'".$comments." /> ".$locale['428']."</label><br />\n";
echo "<label><input type='checkbox' name='article_ratings' value='yes'".$ratings." /> ".$locale['429']."</label></td>\n";
echo "</tr>\n<tr>\n";
echo "<td align='center' colspan='2' class='tbl'><br />\n";
if ((isset($_POST['article_id']) && isnum($_POST['article_id'])) || (isset($_GET['article_id']) && isnum($_GET['article_id']))) {
echo "<input type='hidden' name='article_id' value='".(isset($_POST['article_id']) ? $_POST['article_id'] : $_GET['article_id'])."' />\n";
}
echo "<input type='submit' name='preview' value='".$locale['430']."' class='button' />\n";
echo "<input type='submit' name='save' value='".$locale['431']."' class='button' /></td>\n";
echo "</tr>\n</table>\n</form>\n";
closetable();
echo "<script type='text/javascript'>"."\n"."function DeleteArticle() {\n";
echo "return confirm('".$locale['451']."');\n}\n";
echo "function ValidateForm(frm) {"."\n"."if(frm.subject.value=='') {\n";
echo "alert('".$locale['450']."');"."\n"."return false;\n}\n}\n</script>\n";
}
} else {
opentable($locale['403']);
echo "<div style='text-align:center'>".$locale['452']."<br />\n".$locale['453']."<br />\n";
echo "<a href='article_cats.php".$aidlink."'>".$locale['454']."</a>".$locale['455']."</div>\n";
closetable();
}
require_once THEMES."templates/footer.php";
?>
|