вопрос
Есть модуль последних комментариев (код ниже) в котором выводятся последние комменты и заголовки статей, в которых эти коменты были оставленны. Проблема в том, что если в заголовке публикации присутствует символ ' и пользователь к ней оставляет комментарий, то в модуле возникает критическая ошибка:
Сама 125я строка, которая выводит заголовки:
Пробовал изменять эту строку, итога два - либо ошибка, либо вместо заголовка выводится {title=35 ...} - это всё равно, что удалить строку вовсе.
Подскажите, как решить эту проблему? Что можно сделать?
Сумасшедший код всего модуля:
Parse error: syntax error, unexpected '', '' (T_CONSTANT_ENCAPSED_STRING) in /public_html/engine/modules/last_comments.php(125) : regexp code on line 1 Fatal error: preg_replace(): Failed evaluating code: trimming( '???µN?N‚?????°N? ????????N?N‚N? - ??N???N€?°???»N??µ?? ??N????±??N? '', '35', ' ...' ) in /public_html/engine/modules/last_comments.php on line 125
Сама 125я строка, которая выводит заголовки:
if ( search( $tpl->copy_template, '{title=' ) !== false ) $tpl->copy_template = preg_replace ( "#\{title=([0-9]{0,3})\|?([^\}]+)?\}#ie", "trimming( '{$row['title']}', '\\1', '\\2' )", $tpl->copy_template );
Пробовал изменять эту строку, итога два - либо ошибка, либо вместо заголовка выводится {title=35 ...} - это всё равно, что удалить строку вовсе.
Подскажите, как решить эту проблему? Что можно сделать?
Сумасшедший код всего модуля:
<?php
if ( ! defined( 'DATALIFEENGINE' ) ) die( 'Hacking attempt!' );
$debag = ( isset( $debag ) ) ? intval( $debag ) : false;
$cache = ( isset( $cache ) ) ? intval( $cache ) : 0;
if ( $debag )
{
$Timer = new microTimer ( );
$Timer->start ( );
}
$is_change = false;
if ($config['allow_cache'] != "yes") {
$config['allow_cache'] = "yes";
$is_change = true;
} //$config['allow_cache'] != "yes"
$tpl->result['result'] = dle_cache( 'last_comments', $config['skin'], true );
if ( $tpl->result['result'] === false )
{
function trimming( $text, $limit, $postfix = '' )
{ global $config;
if ( strtolower( $config['charset'] ) == 'utf-8' )
{
if ( iconv_strlen( $text, 'utf-8' ) > $limit )
return iconv_substr( $text, 0, $limit, 'utf-8' ) . $postfix;
} else
{
if ( strlen( $text ) > $limit )
return substr( $text, 0, $limit ) . $postfix;
}
return $text;
}
function search( $str, $needle )
{ global $config;
if ( strtolower( $config['charset'] ) == 'utf-8' ) return iconv_strpos( $str, $needle, 0, 'utf-8' );
else return strpos( $str, $needle );
}
$replase = array( );
$comment = ( isset( $comment ) AND intval( $comment ) > 0 ) ? intval( $comment ) : 15;
$tpl->load_template ( 'last_comments.tpl' );
$allow_cats = explode ( ',', $user_group[$member_id['user_group']]['allow_cats'] );
if ( $allow_cats[0] != 'all' )
{
if ( $config['allow_multi_category'] ) $allow_news = " AND category regexp '[[:<:]](" . implode ( '|', $allow_cats ) . ")[[:>:]]'";
else $allow_news = " AND category IN ('" . implode ( "','", $allow_cats ) . "')";
} else $allow_news = '';
$result = $db->query( "SELECT " . PREFIX . "_comments.id, " . PREFIX . "_comments.date, " . PREFIX . "_comments.autor, " . PREFIX . "_comments.text, is_register, " . PREFIX . "_post.id AS pid, " . PREFIX . "_post.autor AS pautor, " . PREFIX . "_post.date AS pdate, title, category, alt_name, " . PREFIX . "_post.comm_num, " . PREFIX . "_users.news_num, " . PREFIX . "_users.comm_num as ucomm_num, user_group, lastdate, reg_date, info, foto, fullname, land FROM " . PREFIX . "_comments LEFT JOIN " . PREFIX . "_post ON " . PREFIX . "_comments.post_id = " . PREFIX . "_post.id LEFT JOIN " . PREFIX . "_users ON " . PREFIX . "_comments.user_id = " . PREFIX . "_users.user_id WHERE " . PREFIX . "_comments.approve = '1' AND " . PREFIX . "_post.approve = '1'{$allow_news} ORDER BY " . PREFIX . "_comments.id DESC LIMIT 0,{$comment}" );
while ( $row = $db->get_row( $result ) )
{
$row['pdate'] = strtotime( $row['pdate'] );
$row['category'] = intval( $row['category'] );
$on_page = FALSE;
if ($row['comm_num'] > $config['comm_nummers'])
$on_page = 'page,1,' . ceil($row['comm_num'] / $config['comm_nummers']) . ',';
if ($config['allow_alt_url'] ) {
if ($condition = $config['seo_type'] == 1 OR $config['seo_type'] == 2) {
if ($row['category'] and $config['seo_type'] == 2) {
$full_link = $config['http_home_url'] . get_url($row['category']) . "/" . $on_page . $row['pid'] . "-" . $row['alt_name'] . ".html";
} //$row['category'] and $config['seo_type'] == 2
else {
$full_link = $config['http_home_url'] . $on_page . $row['pid'] . "-" . $row['alt_name'] . ".html";
}
} //$condition = $config['seo_type'] == 1 OR $config['seo_type'] == 2
else {
$full_link = $config['http_home_url'] . date('Y/m/d/', $row['date']) . $on_page . $row['alt_name'] . ".html";
}
} //$config['allow_alt_url'] == "yes"
else {
$full_link = $config['http_home_url'] . "index.php?newsid=" . $row['id'];
}
if ( search( $tpl->result['content'], '{content-' . $row['pid'] . '}' ) === false )
{
$row['title'] = strip_tags( stripslashes( $row['title'] ) );
$tpl->copy_template = preg_replace ( "#\\[main\\](.*?)\\[/main\\]#is", '', $tpl->copy_template );
$tpl->copy_template = preg_replace ( "#\\[comment\\](.*?)\\[/comment\\]#is", '', $tpl->copy_template );
$tpl->set ( '[news]', '' );
$tpl->set ( '[/news]', '' );
$tpl->set( '[news-link]', '<a href="' . $full_link . '">' );
$tpl->set( '[/news-link]', '</a>' );
$tpl->set ( '{id}', $row['pid'] );
$tpl->set ( '{news-link}', $full_link );
$tpl->set ( '{title}', $row['title'] );
if ( search( $tpl->copy_template, '{title=' ) !== false ) $tpl->copy_template = preg_replace ( "#\{title=([0-9]{0,3})\|?([^\}]+)?\}#ie", "trimming( '{$row['title']}', '\\1', '\\2' )", $tpl->copy_template );
if ( date( Ymd, $row['pdate'] ) == date( Ymd, $_TIME ) ) $tpl->set( '{date}', $lang['time_heute'] . langdate( ', H:i', $row['pdate'] ) );
elseif ( date( Ymd, $row['pdate'] ) == date( Ymd, ( $_TIME - 86400 ) ) ) $tpl->set( '{date}', $lang['time_gestern'] . langdate( ", H:i", $row['pdate'] ) );
else $tpl->set( '{date}', langdate( $config['timestamp_active'], $row['pdate'] ) );
if ( search( $tpl->copy_template, '{date=' ) !== false ) $tpl->copy_template = preg_replace ( "#\{date=(.+?)\}#ie", "langdate('\\1', '{$row['pdate']}')", $tpl->copy_template );
$tpl->set ( '{author}', $row['pautor'] );
$tpl->set( '[/day-news]', '</a>' );
if ( $config['version_id'] >= '9.0' ) $go_page = "onclick=\"ShowProfile('" . urlencode( $row['pautor'] ) . "', '" . htmlspecialchars( $go_page ) . "'); return false;\"";
else $go_page = "onclick=\"return dropdownmenu(this, event, UserNewsMenu('" . htmlspecialchars( 'href="' . $go_page . '"' ) . "', '" . htmlspecialchars( 'href="' . $news_page . '"' ) . "','" . urlencode( $row['pautor'] ) . "', '" . $user_group[$member_id['user_group']]['admin_editusers'] . "'), '170px')\" onmouseout=\"delayhidemenu()\"";
if( $config['allow_alt_url'] == 'yes' ) $tpl->set( '[profile]', "<a {$go_page} href=\"" . $config['http_home_url'] . "user/" . urlencode( $row['pautor'] ) . '/">' );
else $tpl->set( '[profile]', "<a {$go_page} href=\"$PHP_SELF?subaction=userinfo&user=" . urlencode( $row['pautor'] ) . '">' );
$tpl->set ( '[/profile]', '</a>' );
$tpl->set ( '{comment-num}', $row['comm_num'] );
$tpl->set ( '{news-read}', $row['news_read'] );
if ( $row['allow_rate'] ) $tpl->set( '{rating}', ShortRating( $row['pid'], $row['rating'], $row['vote_num'], false ) );
else $tpl->set( '{rating}', '' );
$tpl->set ( '{comment}', '{content-' . $row['pid'] . '}' );
$tpl->compile ( 'content' );
}
$row['date'] = strtotime( $row['date'] );
$row['text'] = stripslashes( $row['text'] );
if ( $user_group[$member_id['user_group']]['allow_hide'] ) $row['text'] = preg_replace( "'\[hide\](.*?)\[/hide\]'si", "\\1", $row['text'] );
else $row['text'] = preg_replace ( "'\[hide\](.*?)\[/hide\]'si", ' ', $row['text'] );
$tpl->copy_template = preg_replace ( "#\\[main\\](.*?)\\[/main\\]#is", '', $tpl->copy_template );
$tpl->copy_template = preg_replace ( "#\\[news\\](.*?)\\[/news\\]#is", '', $tpl->copy_template );
$tpl->set ( '[comment]', '' );
$tpl->set ( '[/comment]', '' );
$tpl->set( '[comment-link]', '<a href="' . $full_link . '#comment-' . $row['id'] . '">' );
$tpl->set( '[/comment-link]', '</a>' );
$tpl->set ( '{id}', $row['id'] );
$tpl->set ( '{author}', $row['autor'] );
$tpl->set ( '{news-link}', $full_link );
$tpl->set ( '{comment-link}', $full_link . '#comment-id-' . $row['id'] );
$tpl->set ( '{full-comment}', $row['text'] );
if ( ! $row['is_register'] OR $row['autor'] == '' )
{
$tpl->set ( '[profile]', '' );
$tpl->set ( '[/profile]', '' );
$tpl->set ( '{news-num}', '--' );
$tpl->set ( '{comment-num}', '--' );
$tpl->set ( '{lastdate}', '--' );
$tpl->set ( '{registration}', '--' );
$tpl->set ( '{info}', '--' );
$tpl->set ( '{land}', '--' );
$tpl->set ( '{fullname}', '--' );
$tpl->set ( '{foto}', '{THEME}/dleimages/noavatar.png' );
$tpl->set ( '[not-register]', '' );
$tpl->set ( '[/not-register]', '' );
$tpl->set_block ( "'\\[register\\](.*?)\\[/register\\]'si", '' );
} else
{
if ( $config['allow_alt_url'] == 'yes' )
{
$go_page = $config['http_home_url'] . 'user/' . urlencode( $row['autor'] ) . '/';
$news_page = $config['http_home_url'] . 'user/' . urlencode( $row['autor'] ) . '/news/';
} else
{
$go_page = $PHP_SELF . '?subaction=userinfo&user=' . urlencode( $row['autor'] );
$news_page = $PHP_SELF . '?subaction=allnews&user=' . urlencode( $row['autor'] );
}
if ( $config['version_id'] >= '9.0' ) $go_page = "onclick=\"ShowProfile('" . urlencode( $row['autor'] ) . "', '" . htmlspecialchars( $go_page ) . "'); return false;\"";
else $go_page = "onclick=\"return dropdownmenu(this, event, UserNewsMenu('" . htmlspecialchars( 'href="' . $go_page . '"' ) . "', '" . htmlspecialchars( 'href="' . $news_page . '"' ) . "','" . urlencode( $row['autor'] ) . "', '" . $user_group[$member_id['user_group']]['admin_editusers'] . "'), '170px')\" onmouseout=\"delayhidemenu()\"";
if( $config['allow_alt_url'] == 'yes' ) $tpl->set( '[profile]', "<a {$go_page} href=\"" . $config['http_home_url'] . "user/" . urlencode( $row['autor'] ) . '/">' );
else $tpl->set( '[profile]', "<a {$go_page} href=\"$PHP_SELF?subaction=userinfo&user=" . urlencode( $row['autor'] ) . '">' );
$tpl->set ( '[/profile]', '</a>' );
$tpl->set ( '{news-num}', $row['news_num'] );
$tpl->set ( '{comment-num}', $row['ucomm_num'] );
$tpl->set ( '{lastdate}', langdate( "j F Y H:i", $row['lastdate'] ) );
$tpl->set ( '{registration}', langdate( "j F Y H:i", $row['reg_date'] ) );
$tpl->set ( '{info}', stripslashes( $row['info'] ) );
$tpl->set ( '{land}', stripslashes( $row['land'] ) );
$tpl->set ( '{fullname}', stripslashes( $row['fullname'] ) );
$tpl->set ( '[register]', '' );
$tpl->set ( '[/register]', '' );
$tpl->set_block ( "'\\[not-register\\](.*?)\\[/not-register\\]'si", '' );
if ( $row['foto'] and ( file_exists( ROOT_DIR . '/uploads/fotos/' . $row['foto'] ) ) ) $tpl->set ( '{foto}', $config['http_home_url'] . 'uploads/fotos/' . $row['foto'] );
else $tpl->set ( '{foto}', '{THEME}/dleimages/noavatar.png' );
}
$tpl->set ( '{user-group}', $user_group[$row['user_group']]['group_prefix'] . $user_group[$row['user_group']]['group_name'] . $user_group[$row['user_group']]['group_suffix'] );
if ( $user_group[$row['user_group']]['icon'] ) $tpl->set( '{group-icon}', '<img src="' . $user_group[$row['user_group']]['icon'] . '" border="0" />' );
else $tpl->set( '{group-icon}', '' );
$row['text'] = strip_tags( $row['text'] );
$tpl->set ( '{comment}', $row['text'] );
if ( search( $tpl->copy_template, '{comment=' ) !== false ) $tpl->copy_template = preg_replace ( "#\{comment=([0-9]{0,3})\|?([^\}]+)?\}#ie", "trimming( '{$row['text']}', '\\1', '\\2' )", $tpl->copy_template );
if ( date( Ymd, $row['date'] ) == date( Ymd, $_TIME ) ) $tpl->set( '{date}', $lang['time_heute'] . langdate( ', H:i', $row['date'] ) );
elseif ( date( Ymd, $row['date'] ) == date( Ymd, ( $_TIME - 86400 ) ) ) $tpl->set( '{date}', $lang['time_gestern'] . langdate( ", H:i", $row['date'] ) );
else $tpl->set( '{date}', langdate( $config['timestamp_active'], $row['date'] ) );
if ( search( $tpl->copy_template, '{date=' ) !== false ) $tpl->copy_template = preg_replace ( "#\{date=(.+?)\}#ie", "langdate('\\1', '{$row['date']}')", $tpl->copy_template );
$replase[$row['pid']] = true;
$tpl->compile ( 'comment_' . $row['pid'] );
}
$db->free( $result );
foreach( $replase as $key => $value ) $tpl->result['content'] = str_replace( '{content-' . $key . '}', $tpl->result['comment_' . $key], $tpl->result['content'] );
$tpl->copy_template = preg_replace ( "#\\[news\\](.*?)\\[/news\\]#is", '', $tpl->copy_template );
$tpl->copy_template = preg_replace ( "#\\[comment\\](.*?)\\[/comment\\]#is", '', $tpl->copy_template );
$tpl->set ( '[main]', '' );
$tpl->set ( '[/main]', '' );
$tpl->set ( '{content}', $tpl->result['content'] );
$tpl->compile ( 'result' );
create_cache( 'last_comments', $tpl->result['result'], $config['skin'], false );
}
if ( $allow_cache ) $config['allow_cache'] = 'no';
echo $tpl->result['result'];
$tpl->global_clear( );
if ( $debag ) echo '<!-- Время выполнения модуля ' . $Timer->stop( ) . '-->';
?>