Początkujący
Postów: 179 Pomógł: 7
Data rejestracji: 05.11.2006 18:58
|
Hello, myślę, że ten mod wielu z Was sie przyda, zmienia on wygląd i funkcjonalność formularzy dodawania newsa przez użytkowników. Po jego zaaplikowaniu użytkownik ma możliwość edycji obszaru "Czytaj więcej", używany jest także edytor TinyMCE a podgląd newsa jest formatowany, zupełnie jak w Panelu Administratora. Jak zwykle, gotowca w działaniu można zobaczyć na mojej stronie(adres w sygnaturze/profilu) Enjoy!
Jeśli nie masz jeszcze wstawionego TINYMCE do artow/newsow to pobierz najpierw załącznik z posta napisanego przez wlodekp, znajduje się on na 1 stronie tego tematu!
1. Aplikujemy TinyMCE do edycji newsow/artów edytując subheader.php:
Jeśli już masz TinyMCE w newsach/artykułach to dodaj tylko to co jest na czerwono.
W sekcji BODY dodajemy ten kod:
if ($settings['tinymce_submit'] != 0) {
echo "<script language='javascript' type='text/javascript' src='".INCLUDES."jscripts/tiny_mce/tiny_mce.js'></script><script type='text/javascript'>";
if (FUSION_SELF=="submit.php" && $settings['tinymce_submit']==1) {
echo "
function simple() {
tinyMCE.init({
mode:'exact',
elements:'news_body,[color=red]news_body2[/color],article_snippet,article_body,message',
theme:'simple',
language:'".$locale['tinymce']."',
convert_newlines_to_brs:'true',
force_br_newlines:'true',
force_p_newlines:'false'
});
}";
} else if (FUSION_SELF=="submit.php" && $settings['tinymce_submit']==2) {
echo "
function advanced() {
tinyMCE.init({
mode:'exact',
elements:'news_body,[color=red]news_body2[/color],article_snippet,article_body,message',
theme:'advanced',
width:'90%',
height:'250',
language:'".$locale['tinymce']."',
entities:'60,lt,62,gt',
document_base_url:'".$settings['siteurl']."',
relative_urls:'false',
convert_newlines_to_brs:'true',
force_br_newlines:'true',
force_p_newlines:'false',
plugins : 'table,advhr,advimage,advlink,emotions,insertdatetime,flash,searchreplace,print,contextmenu,paste,noneditable".((!FORUM_TINYMCE_SIMPLE && !FORUM_TINYMCE_ADVANCED) && $stype=="a"?",pb":"")."',
theme_advanced_buttons1_add : 'separator,fontsizeselect',
theme_advanced_buttons2_add : 'insertdate,inserttime,separator,forecolor,backcolor',
theme_advanced_buttons3_add_before: 'tablecontrols,separator',
theme_advanced_buttons4: '".((!FORUM_TINYMCE_SIMPLE && !FORUM_TINYMCE_ADVANCED) && $stype=="a"?"pb,separator,":"")."cut,copy,paste,pastetext,pasteword,separator,search,replace,separator,emotions,flash,advhr,separator,print',
theme_advanced_toolbar_align:'left',
theme_advanced_path_location:'none',
theme_advanced_toolbar_location:'top',
content_css:'".THEME."styles.css',
invalid_elements:'script,object,applet,iframe',
extended_valid_elements:'a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]'
});
}";
}
echo "
function showtiny(EditorID) {
tinyMCE.removeMCEControl(tinyMCE.getEditorId(EditorID));
tinyMCE.addMCEControl(document.getElementById(EditorID),EditorID);
}
function hidetiny(EditorID) {
tinyMCE.removeMCEControl(tinyMCE.getEditorId(EditorID));
}
</script>\n";
}
2. Jeśli wcześniej tego nie robiłeś to zapytaj bazę czy wszystko w porządku ;)
Jeśli już wcześniej to robiłeś, zmień w bazie wartość tinymce_submit na 2, by mieć pełny edytor.
Poniższy kod wklejamy np w polu tekstowym dodatkowych stron i dajemy podgląd, bynajmniej chodzi o to by wprowadzić dodatkową kolumnę tinymce_submit w tabeli fusion_settings:
<?
$result = dbquery("ALTER TABLE ".$db_prefix."settings ADD tinymce_submit TINYINT( 1 ) NOT NULL DEFAULT '2'");
?>
3. Edytujemy plik plik submit.php z paczki, którą zamieścił wlodekp, zamieniając w nim całą sekcję 'news'(trzymajcie się znaczników, podmieniać tylko od punktu a do b!) na:
} elseif ($stype == "n") {
if (isset($_POST['submit_news'])) {
if ($_POST['news_subject'] != "" && $_POST['news_body'] != "") {
$submit_info['news_subject'] = stripinput($_POST['news_subject']);
$submit_info['news_cat'] = isNum($_POST['news_cat']) ? $_POST['news_cat'] : "0";
$submit_info['news_body'] = descript($_POST['news_body']);
$submit_info['news_body2'] = descript($_POST['news_body2']);
$submit_info['news_breaks'] = (isset($_POST['line_breaks']) ? "y" : "n");
$result = dbquery("INSERT INTO ".$db_prefix."submissions (submit_type, submit_user, submit_datestamp, submit_criteria) VALUES('n', '".$userdata['user_id']."', '".time()."', '".addslashes(serialize($submit_info))."')");
opentable($locale['400']);
echo "<center><br>\n".$locale['460']."<br><br>
<a href='submit.php?stype=n'>".$locale['461']."</a><br><br>
<a href='index.php'>".$locale['412']."</a><br><br>\n</center>\n";
closetable();
}
} else {
if (isset($_POST['preview_news'])) {
$news_subject = stripinput($_POST['news_subject']);
$news_cat = isNum($_POST['news_cat']) ? $_POST['news_cat'] : "0";
$news_body = phpentities(descript(stripslash($_POST['news_body'])));
$bodypreview = str_replace("src='".str_replace("../", "", IMAGES_N), "src='".IMAGES_N, stripslash($_POST['news_body']));
if ($_POST['news_body2']) {
$news_body2 = phpentities(stripslash($_POST['news_body2']));
$body2preview = str_replace("src='".str_replace("../", "", IMAGES_N), "src='".IMAGES_N, stripslash($_POST['news_body2']));
}
if (isset($_POST['line_breaks'])) {
$breaks = " checked";
$bodypreview = nl2br($bodypreview);
if ($news_body2) $body2preview = nl2br($body2preview);
} else {
$breaks = "";
}
opentable($news_subject);
echo "$bodypreview\n";
closetable();
tablebreak();
if (isset($body2preview)) {
opentable($news_subject);
echo "$body2preview\n";
closetable();
}
tablebreak();
}
$news_cat_opts = ""; $sel = "";
$result2 = dbquery("SELECT * FROM ".$db_prefix."news_cats ORDER BY news_cat_name");
if (dbrows($result2)) {
while ($data2 = dbarray($result2)) {
if (isset($news_cat)) $sel = ($news_cat == $data2['news_cat_id'] ? " selected" : "");
$news_cat_opts .= "<option value='".$data2['news_cat_id']."'$sel>".$data2['news_cat_name']."</option>\n";
}
}
opentable($locale['450']);
echo $locale['470']."<br><br>
<form name='submit_form' method='post' action='".FUSION_SELF."?stype=n' onSubmit='return validateNews(this);'>
<table align='center' cellpadding='0' cellspacing='0'>
<tr>
<td class='tbl'>".$locale['471']."</td>
<td class='tbl'><input type='text' name='news_subject' value='$news_subject' maxlength='64' class='textbox' style='width:300px;'></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['476']."</td>
<td width='80%' class='tbl'><select name='news_cat' class='textbox'>
<option value='0'>".$locale['477']."</option>
$news_cat_opts</select>
</td>
</tr>
<tr>
<td valign='top' class='tbl'>".$locale['472']."</td>
</tr>
<tr>
<td colspan='2' class='tbl'><center><textarea class='textbox' name='news_body' cols='95' rows='10' style='width:300px;'>$news_body</textarea></center>
</td>
</tr>
<tr>
<td valign='top' width='100' class='tbl'>".$locale['478']."</td>
</tr>
<tr>
<td colspan='2' class='tbl'><center><textarea class='textbox' name='news_body2' cols='95' rows='10' style='width:300px;'>$news_body2</textarea></center>
</td>
</tr>
<tr>
<td colspan='2' class='tbl'><br><center>";
if ($settings['tinymce_enabled'] != 1) {
echo "<input type='checkbox' name='line_breaks' value='yes'$breaks>".$locale['473']."<br><br>";
}
echo "<input type='submit' name='preview_news' value='".$locale['474']."' class='button'>
<input type='submit' name='submit_news' value='".$locale['475']."' class='button'></center>
</td>
</tr>
</table>
</form>\n";
closetable();
}
4. Edytujemy jeden plik językowy z locale/Polish/submit.php, dodając w nim:
$locale['478'] = "Uzupełnienie newsa";
5. Edytujemy plik submissions.php podmieniając w nim całą sekcję 'news' na:
if ($stage == "2" && $t == "n") {
if (isset($_POST['publish'])) {
$data = dbarray(dbquery(
"SELECT ts.*, user_id,user_name FROM ".$db_prefix."submissions ts
LEFT JOIN ".$db_prefix."users tu ON ts.submit_user=tu.user_id
WHERE submit_id='$submit_id'"
));
$news_subject = stripinput($_POST['news_subject']);
$news_cat = isNum($_POST['news_cat']) ? $_POST['news_cat'] : "0";
$news_body = addslash($_POST['news_body']);
$news_body2 = addslash($_POST['news_body2']);
$news_breaks = ($_POST['news_breaks'] == "y") ? "y" : "n";
$result = dbquery("INSERT INTO ".$db_prefix."news (news_subject, news_cat, news_news, news_extended, news_breaks, news_name, news_datestamp, news_start, news_end, news_visibility, news_reads, news_allow_comments, news_allow_ratings) VALUES ('$news_subject', '$news_cat', '$news_body', '$news_body2', '$news_breaks', '".$data['user_id']."', '".time()."', '0', '0', '0', '0', '1', '1')");
$result = dbquery("DELETE FROM ".$db_prefix."submissions WHERE submit_id='$submit_id'");
opentable($locale['490']);
echo "<br><div align='center'>".$locale['491']."<br><br>
<a href='".FUSION_SELF.$aidlink."'>".$locale['402']."</a><br><br>
<a href='index.php".$aidlink."'>".$locale['403']."</a></div><br>\n";
closetable();
} else if (isset($_POST['delete'])) {
opentable($locale['492']);
$result = dbquery("DELETE FROM ".$db_prefix."submissions WHERE submit_id='$submit_id'");
echo "<br><div align='center'>".$locale['493']."<br><br>
<a href='".FUSION_SELF.$aidlink."'>".$locale['402']."</a><br><br>
<a href='index.php".$aidlink."'>".$locale['403']."</a></div><br>\n";
closetable();
} else {
if ($settings['tinymce_enabled'] == 1) echo "<script type='text/javascript'>advanced();</script>\n";
$data = dbarray(dbquery(
"SELECT ts.*, user_id,user_name FROM ".$db_prefix."submissions ts
LEFT JOIN ".$db_prefix."users tu ON ts.submit_user=tu.user_id
WHERE submit_id='$submit_id'"
));
$submit_criteria = unserialize($data['submit_criteria']);
$news_subject = $submit_criteria['news_subject'];
$news_cat = $submit_criteria['news_cat'];
$news_body = phpentities(stripslashes($submit_criteria['news_body']));
$news_body2 = phpentities(stripslashes($submit_criteria['news_body2']));
$news_breaks = $submit_criteria['news_breaks'];
$news_cat_opts = ""; $sel = "";
$result2 = dbquery("SELECT * FROM ".$db_prefix."news_cats ORDER BY news_cat_name");
if (dbrows($result2)) {
while ($data2 = dbarray($result2)) {
if (isset($news_cat)) $sel = ($news_cat == $data2['news_cat_id'] ? " selected" : "");
$news_cat_opts .= "<option value='".$data2['news_cat_id']."'$sel>".$data2['news_cat_name']."</option>\n";
}
}
opentable($locale['500']);
echo "<form name='publish' method='post' action='".FUSION_SELF.$aidlink."&sub=submissions&stage=2&t=n&submit_id=$submit_id'>
<table align='center' cellpadding='0' cellspacing='0'>
<tr>
<td width='100' class='tbl'>".$locale['505']."</td>
<td width='80%' class='tbl'><input type='text' name='news_subject' value='$news_subject' class='textbox' style='width: 250px'></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['506']."</td>
<td width='80%' class='tbl'><select name='news_cat' class='textbox'>
<option value='0'>".$locale['507']."</option>
$news_cat_opts</select>
</td>
</tr>
<tr>
<td valign='top' width='100' class='tbl'>".$locale['508']."</td>
<td width='80%' class='tbl'><textarea name='news_body' cols='65' rows='10' class='textbox'>$news_body</textarea></td>
</tr>
<tr>
<td valign='top' width='100' class='tbl'>".$locale['508']."</td>
<td width='80%' class='tbl'><textarea name='news_body2' cols='65' rows='10' class='textbox'>$news_body2</textarea></td>
</tr>
<tr>
<td align='center' colspan='2' class='tbl1'><br>
".$locale['501']."<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."'>".$data['user_name']."</a><br><br>
".$locale['502']."<br>
<input type='hidden' name='news_breaks' value='$news_breaks'>
<input type='submit' name='publish' value='".$locale['503']."' class='button'>
<input type='submit' name='delete' value='".$locale['504']."' class='button'>
</td>
</tr>
</table>
</form>\n";
closetable();
}
}
Poprawka dla artykułów! Naprawia problem formatowanego podglądu.
1. Edytujemy plik submit.php wcześniej zmodyfikowany przez wlodekp(załącznik na 1 stronie), chyba, że wprowadziłeś już moją modyfikację newsów to kontynuuj pracę na tym pliku. Zamieniamy w nim całą sekcję artykułów:
} elseif ($stype == "a") {
if (isset($_POST['submit_article'])) {
if ($_POST['article_subject'] != "" && $_POST['article_body'] != "") {
$submit_info['article_cat'] = $_POST['article_cat'];
$submit_info['article_subject'] = stripinput($_POST['article_subject']);
$submit_info['article_snippet'] = descript($_POST['article_snippet']);
$submit_info['article_body'] = descript($_POST['article_body']);
$submit_info['article_breaks'] = (isset($_POST['line_breaks']) ? "y" : "n");
$result = dbquery("INSERT INTO ".$db_prefix."submissions (submit_type, submit_user, submit_datestamp, submit_criteria) VALUES ('a', '".$userdata['user_id']."', '".time()."', '".addslashes(serialize($submit_info))."')");
opentable($locale['400']);
echo "<center><br>\n".$locale['510']."<br><br>
<a href='submit.php?stype=a'>".$locale['511']."</a><br><br>
<a href='index.php'>".$locale['412']."</a><br><br>\n</center>\n";
closetable();
}
} else {
if (isset($_POST['preview_article'])) {
$article_cat = $_POST['article_cat'];
$article_subject = stripinput($_POST['article_subject']);
$article_snippet = phpentities(descript(stripslash($_POST['article_snippet'])));
$article_body = phpentities(descript(stripslash($_POST['article_body'])));
$article_snippet_prev = str_replace("src='".str_replace("../", "", IMAGES_A), "src='".IMAGES_A, stripslash($_POST['article_snippet']));
$article_body_prev = str_replace("src='".str_replace("../", "", IMAGES_A), "src='".IMAGES_A, stripslash($_POST['article_body']));
if (isset($_POST['line_breaks'])) {
$breaks = " checked";
$article_snippet_prev = nl2br($article_snippet_prev);
$article_body_prev = nl2br($article_body_prev);
}
opentable($article_subject);
echo "$article_snippet_prev\n";
closetable();
tablebreak();
opentable($article_subject);
echo "$article_body_prev\n";
closetable();
tablebreak();
}
if (!isset($_POST['preview_article'])) {
$article_category = "";
$article_subject = "";
$article_snippet = "";
$article_body = "";
$breaks = " checked";
}
$cat_list = ""; $sel = "";
opentable($locale['500']);
$result = dbquery("SELECT * FROM ".$db_prefix."article_cats ORDER BY article_cat_name DESC");
if (dbrows($result)) {
while ($data = dbarray($result)) {
if (isset($_POST['preview_article'])) $sel = ($article_cat == $data['article_cat_id'] ? " selected" : "");
$cat_list .= "<option value='".$data['article_cat_id']."'$sel>".$data['article_cat_name']."</option>\n";
}
2. To chyba wszystko :) Czekam na opinie.
Edytowane przez Lukiqq dnia 18.06.2007 11:31:20
itvortal.avx.pl - A taka sobie moja strona :]
Pomoc na GG wyłącznie dla nieco wtajemniczonych, podstawowe HowTo znajduje się na forum.
|