Новичок
Профиль
Группа: Участник
Сообщений: 24
Регистрация: 15.11.2008
Репутация: нет Всего: нет
|
Здравствуйте уважаемые. У меня возникла большая проблема при добавлении новостей. У меня есть 3 поля textarea Краткая новость, Полная новость и ссылки к новости. И при заполении всех полей и при добавлении новости бывает что не считывается какое-нибудь поле либо сразу нескольких. но всегда считывается первое поле Краткая новость. проблемы во вторых полях. Помогите мне. Как исправить эту ошибку. Вот код: Это код вывода страницы добавления новостей: Код | function add(){ global $db, $tpl, $logged, $conf, $addnews; if($logged == 1){ if($conf['antiflood'] == 1){ flood(); } include('engine/bbedit.php'); tiny(); $tpl->set_global('subtitle', 'Добавление новости'); $category .= '<select class="select" size="1" name="cid">'; $category .= '<option value="0">---------------</option>'; $sql = $db->query("SELECT id, title FROM news_cat"); while(list($id, $title) = $db->arrow($sql)){ $category .= '<option value="'.$id.'">'.$title.'</option>\n'; } $category .= '</select>'; $tpl->assign('category', $category); $tpl->load('addnews.tpl'); $tpl->compil('content'); } else { err('Вы должны авторизироватся для добавления новостей'); } }
|
Это addnews.tpl Код | <form action="index.php?mod=news" method="post"> <div class="in"> <b class="box"><b class="b1"></b><b class="b2" style="background:#ffffff"></b><b class="b3" style="background:#ffffff"></b></b> <div class="boxcontent" style="background:#ffffff"> <table cellspacing="3" cellpadding="0" width="100%" border="0"> <tr><td align="left" valign="middle" style="padding-left:7px;"><b>Публикация новости на сайте</b></td></tr> <tr><td align="left" valign="middle" style="padding-left:7px;"> <table cellspacing="5" cellpadding="0" width="100%" border="0"> <tr><td width="110">Заголовок:</td><td><input class="edit" type="text" name="title" maxlength="150"></td></tr> <tr><td width="110">Источник:</td><td><input class="edit" type="text" name="source" maxlength="150"></td></td></tr> <tr><td width="110">Категория:</td><td>{category}</td></tr> <tr><td width="110">Краткое содержание:</td><td><textarea class="memo" name="short" id="short" style="width:100%; height:160px;"></textarea></td></tr> <tr><td width="110">Полная новость:<br>(необязательно)</td><td><textarea class="memo" name="full" id="full" style="width:100%; height:200px;"></textarea></td></tr> <tr><td width="110">Ссылки:<br>(необязательно)</td><td><textarea class="memo" name="links" id="links" style="width:100%; height:100px;"></textarea></td></tr> <tr><td width="110">Перенос строк:</td><td><input name="nl2br" type="checkbox" value="1" checked="yes"></td></tr> <tr><td width="110">На главной:</td><td><input name="hide" type="checkbox" value="0" checked="yes" disabled="yes"></td></tr> <tr><td width="110">Прикрепить:</td><td><input name="keeped" type="checkbox" value="0" disabled="yes"></td></tr> <tr><td width="110">Без комментариев:</td><td><input name="nocomm" type="checkbox" value="0" disabled="yes"></td></tr> <tr><td width="110"></td><td><input name="go" type="hidden" value="save"> <input type="submit" class="knopka" name="add" value="Отправить"></td></tr> </table> </td></tr> </table> </div> <b class="box"><b class="b3" style="background:#ffffff"></b><b class="b2" style="background:#ffffff"></b><b class="b1"></b></b> </div> </form>
|
Это функция получения всех полей и сохранения её в базу: Код | function save(){ global $db, $conf, $addnews, $uinfo, $admin; if($conf['antiflood'] == 1){ flood(1); } if(intval($_POST['nl2br']) == 1){ $_POST['short'] = str_replace("\r\n", '<br>', $_POST['short']); $_POST['full'] = str_replace("\r\n", '<br>', $_POST['full']); $_POST['links'] = str_replace("\r\n", '<br>', $_POST['links']); } $shortnews = parser($_POST['short'], 1); $fullnews = parser($_POST['full'], 1); $linksnews = parser($_POST['links'], 1); $title = parser($_POST['title'], 1); $source = parser($_POST['source'], 1); if(empty($shortnews) or empty($title)){ err("Заголово новости и краткая новость обязательны к заполнению!"); } $cid = intval($_POST['cid']); if($cid == 0){ err("Вы должны выбрать категорию!"); } $hidenews = intval($_POST['hide']); $keepnews = intval($_POST['keeped']); $nocomm = intval($_POST['nocomm']); if($admin == 1){ $status = '1'; $posted = '1'; } else { $status = '0'; $posted = '0'; } $date = time(); $ok = $db->query("INSERT INTO news set title = '$title', short = '$shortnews', full = '$fullnews', links = '$linksnews', cid = '$cid', autor = '".$uinfo['uname']."', source = '$source', date = $date, status = '$status', posted = '$posted'"); $db->query("UPDATE users set points=points+0.0100 where uname = '".$uinfo['uname']."'"); if($ok){ msg('Добавление новости', "<b>Новость успешно добавлена!</b>"); }else{ err("Ошибка!"); } }
|
Это функция парсинга новостей: Код | function parser($sources = '', $bb = 0, $strip_tags = 0, $substr = 0){ global $db; require_once 'engine/class.parser.php'; $par = new Parser(); if (get_magic_quotes_gpc()) { $sources = stripslashes($sources); } if($strip_tags == 1){ $sources = strip_tags($sources); } if($bb == 1){ $sources = $par->bb2html($sources); } if($substr != 0){ $sources = substr($sources, 0, $substr); } $sources = $par->bbxss($sources); $sources = $db->shield($sources); return $sources; }
|
И к фунции парсинга дополнительный класс парсинга: Код | <?php class Parser { function bbxss($str, $charset = '1251'){ if (get_magic_quotes_gpc()) { $str = stripslashes($str); } $str = preg_replace('/\0+/', '', $str); $str = preg_replace('/(\\\\0)+/', '', $str); $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#',"\\1;",$str); $str = preg_replace('#(&\#x*)([0-9A-F]+);*#i',"\\1\\2;",$str); $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); $str = preg_replace("/\.\//i", '', $str); if (preg_match_all("/<(.+?)>/si", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { $str = str_replace($matches['1'][$i], $this->_html_entity_decode($matches['1'][$i], $charset), $str); } } $str = preg_replace("#\t+#", " ", $str); $str = str_replace(array('<?', '?>'), array('<?', '?>'), $str); $words = array('javascript', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); foreach ($words as $word) { $temp = ''; for ($i = 0; $i < strlen($word); $i++) { $temp .= substr($word, $i, 1)."\s*"; } $temp = substr($temp, 0, -3); $str = preg_replace('#'.$temp.'#s', $word, $str); $str = preg_replace('#'.ucfirst($temp).'#s', ucfirst($word), $str); } $str = preg_replace("#<a.+?href=.*?(alert\(|alert&\#40;|javascript\:|data\:|mocha\:|window\.|document\.|\.cookie|<script|<xss).*?\>.*?</a>#si", "", $str); $str = preg_replace("#<img.+?src=.*?(alert\(|alert&\#40;|javascript\:|data\:|mocha\:|window\.|document\.|\.cookie|<script|<xss).*?\>#si","", $str); $str = preg_replace("#<(script|xss).*?\>#si", "", $str); $str = preg_replace("#<(div|h1|h2|h3|h4|h5|h6|h7).*?\>#si", "", $str); $str = preg_replace('#<(.+?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)(.+?)>#i', "<\\1\\2\\3>", $str); $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|mocha|xss)([^>]*)>#is', "<\\1\\2\\3>", $str); $str = preg_replace('#(alert|cmd|passthru|eval|exec|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); $bad = array( 'document.cookie' => '', 'document.write' => '', 'window.location' => '', "javascript\s*:" => '', "Redirect\s+302" => '', '<!--' => '<!--', '-->' => '-->', "`" => '`', '<>' => '<>' ); foreach ($bad as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } return $str; } function _html_entity_decode($str, $charset='utf-8') { if (stristr($str, '&') === FALSE) return $str; if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) { $str = html_entity_decode($str, ENT_COMPAT, "ISO-8859-1"); $str = preg_replace('~&#x([0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); } $str = preg_replace('~&#x([0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); if (stristr($str, '&') === FALSE) { $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); } return $str; } function bb2html($bb){ $bb = preg_replace("#\[b\](.+?)\[/b\]#is", "<b>\\1</b>", $bb); $bb = preg_replace("#\[i\](.+?)\[/i\]#is", "<i>\\1</i>", $bb); $bb = preg_replace("#\[u\](.+?)\[/u\]#is", "<u>\\1</u>", $bb); $bb = preg_replace("#\[s\](.+?)\[/s\]#is", "<s>\\1</s>", $bb); $bb = preg_replace("#\[center\](.+?)\[/center\]#is", "<center>\\1</center>", $bb); $bb = preg_replace("#\[left\](.+?)\[/left\]#is", "<div align=\"left\">\\1</div>", $bb); $bb = preg_replace("#\[right\](.+?)\[/right\]#is", "<div align=\"right\">\\1</div>", $bb); $bb = preg_replace("#\[url\](http://|ftp://|https://)(.+?)\[/url\]#is", "<a target=\"_blank\" href=\"\\1\\2\">\\1\\2</a>", $bb); $bb = preg_replace("#\[url\](www|ftp)(.+?)\[/url\]#is", "<a target=\"_blank\" href=\"http://\\1\\2\">\\1\\2</a>", $bb); $bb = preg_replace("#\(.+?)\[/url\]#is", "<a target=\"_blank\" href=\"\\1\\2\">\\3</a>", $bb); $bb = preg_replace("#\[url=(www|ftp)(.+?)\](.+?)\[/url\]#is", "<a target=\"_blank\" href=\"http://\\1\\2\">\\3</a>", $bb); $bb = preg_replace("#\[mail\](.+?)\[/mail\]#is", "<a href=\"mailto:\\1\">\\1</a>", $bb); $bb = preg_replace("#\[mail=(.+?)\](.+?)\[/mail\]#is", "<a href=\"mailto:\\1\">\\2</a>", $bb); $bb = preg_replace("#\[color=(.+?)\](.+?)\[/color\]#is", "<font color=\"\\1\">\\2</font>", $bb); $bb = preg_replace("#\[img=(left|right|center)\](www|ftp)(.+?)\.(jpg|gif|png|jpeg|bmp)\[/img\]#ies", "\$this->img('\\2\\3', '\\4', '\\1')", $bb); $bb = preg_replace("#\[img=(left|right|center)\](http://|ftp://|https://)(.+?)\.(jpg|gif|png|jpeg|bmp)\[/img\]#ies", "\$this->img('\\2\\3', '\\4', '\\1')", $bb); $bb = preg_replace("#\[img](www|ftp)(.+?)\.(jpg|gif|png|jpeg|bmp)\[/img\]#ies", "\$this->img('\\1\\2', '\\3')", $bb); $bb = preg_replace("#\[img\](http://|ftp://|https://)(.+?)\.(jpg|gif|png|jpeg|bmp)\[/img\]#ies", "\$this->img('\\1\\2', '\\3')", $bb); return $bb; } function html2bb($source){ $source = str_replace("<br>", "\n", $source); $source = preg_replace("#<i>(.+?)</i>#is", "\\1", $source); $source = preg_replace("#<b>(.+?)</b>#is", "\\1", $source); $source = preg_replace("#<s>(.+?)</s>#is", "\\1", $source); $source = preg_replace("#<u>(.+?)</u>#is", "\\1", $source); $source = preg_replace("#<center>(.+?)</center>#is", " \\1 ", $source); $source = preg_replace("#<div align=\"left\">(.+?)</div>#is", "[left]\\1[/left]", $source); $source = preg_replace("#<div align=\"right\">(.+?)</div>#is", "[right]\\1[/right]", $source); $source = preg_replace("#<a href=[\"\'](http://|https://|ftp://)(.+?)[\"\']>(.+?)</a>#", "[url=\\1\\2]\\3", $source); $source = preg_replace("#<a target=[\"\']_blank[\"\'] href=[\"\'](http://|https://|ftp://)(.+?)[\"\']>(.+?)</a>#", "\\3", $source); $source = preg_replace("#<a href=[\"\'](mailto(.+?)[\"\']>(.+?)</a>#", "[mail=\\2]\\3[/mail]", $source); $source = preg_replace("#<img align=[\"\'](left|center|right)[\"\'] src=(\'|\"|)(.+?)(\'|\"|) />#", "[img=\\1]\\3[/img]", $source); $source = str_replace("<br />", "\n", $source); return $source; } function clear_url($str=''){ $clear = array('&' => '', '?' => '', '#' => ''); return strtr($str, $clear); } function img($url, $exp, $align=''){ $url = strtolower($this->clear_url($url.'.'.$exp)); $arr = explode('.', $url); if($arr[0] == 'www'){ $url = 'http://'.$url; } else if ($arr[0] == 'ftp'){ $url = 'ftp://'.$url; } if(!empty($align)){ $align = ' align="'.$align.'"'; } $img = '<img'.$align.' src="'.$url.'" alt="" border="0">'; return $img; } } ?>
|
|