Данный код защищен авторскими правами
=====================================================
 Файл: show.custom.php
-----------------------------------------------------
 Назначение: вывод новостей
=====================================================
*/
if (!defined('DATALIFEENGINE')) {
    die("Hacking attempt!");
}
$i = 0;
if (isset($cstart)) {
    $i = $cstart;
}
$news_found = FALSE;
$xfields = xfieldsload();
$tpl->load_template($custom_template . '.tpl');
$sql_result = $db->query($sql_select);
while ($row = $db->get_row($sql_result)) {
    $news_found = TRUE;
    $attachments[] = $row['id'];
    $row['date'] = strtotime($row['date']);
    $i++;
    if (!$row['category']) {
        $my_cat = "---";
        $my_cat_link = "---";
    } else {
        $my_cat = array();
        $my_cat_link = array();
        $cat_list = explode(',', $row['category']);
        if (count($cat_list) == 1) {
Beispiel #2
0
 if ($row['user'] == $member_id['user_id'] and !$row['pm_read'] and $row['folder'] == "inbox") {
     $db->query("UPDATE " . USERPREFIX . "_users SET pm_unread=pm_unread-1  WHERE user_id='{$member_id['user_id']}'");
     if ($row['sendid']) {
         $addwhere = " OR id='{$row['sendid']}'";
     } else {
         $addwhere = "";
     }
     $db->query("UPDATE " . USERPREFIX . "_pm SET pm_read='1'  WHERE id='{$row['id']}'{$addwhere}");
 }
 if (strpos($tpl->copy_template, "[xfvalue_") !== false) {
     $xfound = true;
 } else {
     $xfound = false;
 }
 if ($xfound) {
     $xfields = xfieldsload(true);
     $xfieldsdata = xfieldsdataload($row['xfields']);
     foreach ($xfields as $value) {
         $preg_safe_name = preg_quote($value[0], "'");
         if ($value[5] != 1 or $member_id['user_group'] == 1 or $is_logged and $member_id['name'] == $row['user_from']) {
             if (empty($xfieldsdata[$value[0]])) {
                 $tpl->copy_template = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template);
             } else {
                 $tpl->copy_template = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template);
             }
             $tpl->copy_template = preg_replace("'\\[xfvalue_{$preg_safe_name}\\]'i", stripslashes($xfieldsdata[$value[0]]), $tpl->copy_template);
         } else {
             $tpl->copy_template = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template);
             $tpl->copy_template = preg_replace("'\\[xfvalue_{$preg_safe_name}\\]'i", "", $tpl->copy_template);
         }
     }
Beispiel #3
0
 function build_comments($template, $area, $allow_cache = false, $re_url = false)
 {
     global $config, $tpl, $is_logged, $member_id, $user_group, $lang, $ajax_adds, $dle_tree_comments, $dle_login_hash;
     $tpl->load_template($template);
     if ($area == "news" or $area == 'ajax' and !isset($ajax_adds)) {
         $build_full_news = true;
     } else {
         $build_full_news = false;
     }
     $tpl->copy_template = "<div id='comment-id-{id}'>" . $tpl->copy_template . "</div>";
     $tpl->template = "<div id='comment-id-{id}'>" . $tpl->template . "</div>";
     if (strpos($tpl->copy_template, "[xfvalue_") !== false) {
         $this->xfound = true;
     } else {
         $this->xfound = false;
     }
     if ($this->xfound) {
         $this->xfields = xfieldsload(true);
     }
     $rows = false;
     if ($allow_cache) {
         $rows = dle_cache("comm_" . $allow_cache, $this->query);
     }
     if ($rows) {
         $rows = unserialize($rows);
         if (!is_array($rows)) {
             die("Cache data not correct");
         }
         $full_cache = true;
     } else {
         $rows = array();
         if ($build_full_news) {
             $sql_result = $this->db->query($this->query);
         } else {
             $sql_result = $this->db->query($this->query . " LIMIT " . $this->cstart . "," . $this->comments_per_pages);
         }
         while ($row = $this->db->get_row($sql_result)) {
             $rows[$row['id']] = array();
             foreach ($row as $key => $value) {
                 if ($key == "parent" and $value == 0) {
                     $value = false;
                 }
                 $rows[$row['id']][$key] = $value;
             }
         }
         $this->db->free($sql_result);
         unset($row);
         if ($build_full_news and $config['tree_comments']) {
             $rows = $this->build_tree($rows);
             if ($config['comm_msort'] == "DESC") {
                 $rows = array_reverse($rows, true);
             }
         }
         if ($allow_cache) {
             create_cache("comm_" . $allow_cache, serialize($rows), $this->query);
         }
     }
     if ($build_full_news and count($rows)) {
         $this->total_comments = count($rows);
         if ($this->cstart < $this->total_comments) {
             $rows = array_slice($rows, $this->cstart, $this->comments_per_pages, true);
         } else {
             $rows = array();
         }
     }
     if (count($rows)) {
         if ($build_full_news and $config['tree_comments']) {
             $dle_tree_comments = 1;
             $tpl->result['comments'] = "<ol class=\"comments-tree-list\">" . $this->compile_tree($rows, $area) . "</ol>";
         } else {
             $tpl->result['comments'] = $this->compile_comments($rows, $area);
         }
     } else {
         if ($config['seo_control'] and $_GET['cstart'] and $re_url) {
             $re_url = str_replace($config['http_home_url'], "/", $re_url);
             header("HTTP/1.0 301 Moved Permanently");
             header("Location: {$re_url}");
             die("Redirect");
         }
         $tpl->result['comments'] = "";
     }
     $tpl->clear();
     if ($area != 'ajax') {
         $tpl->result['comments'] = "<a name=\"comment\"></a>" . $tpl->result['comments'];
     }
     if ($config['comments_lazyload'] and $area != 'ajax' and $this->total_comments > $this->comments_per_pages) {
         $tpl->result['comments'] .= "\n<div class=\"ajax_comments_area\"><div class=\"ajax_loaded_comments\"></div><div class=\"ajax_comments_next\"></div></div>\n";
     }
     if ($area == 'news' and $config['comm_msort'] == "DESC") {
         $tpl->result['comments'] = "\n<div id=\"dle-ajax-comments\"></div>\n" . $tpl->result['comments'];
     }
     if ($area == 'news' and $config['comm_msort'] == "ASC") {
         $tpl->result['comments'] .= "\n<div id=\"dle-ajax-comments\"></div>\n";
     }
     if ($area != 'ajax' and $user_group[$member_id['user_group']]['del_allc'] and !$user_group[$member_id['user_group']]['edit_limit']) {
         $tpl->result['comments'] .= "\n<div class=\"mass_comments_action\">{$lang['mass_comments']}&nbsp;<select name=\"mass_action\"><option value=\"\">{$lang['edit_selact']}</option><option value=\"mass_combine\">{$lang['edit_selcomb']}</option><option value=\"mass_delete\">{$lang['edit_seldel']}</option></select>&nbsp;&nbsp;<input type=\"submit\" class=\"bbcodes\" value=\"{$lang['b_start']}\" /></div>\n<input type=\"hidden\" name=\"do\" value=\"comments\" /><input type=\"hidden\" name=\"dle_allow_hash\" value=\"{$dle_login_hash}\" /><input type=\"hidden\" name=\"area\" value=\"{$area}\" />";
     }
     if ($area != 'ajax') {
         $tpl->result['comments'] = "<form method=\"post\" action=\"\" name=\"dlemasscomments\" id=\"dlemasscomments\"><div id=\"dle-comments-list\">\n" . $tpl->result['comments'] . "</div></form>\n";
     }
     if (strpos($tpl->result['content'], "<!--dlecomments-->") !== false) {
         $tpl->result['content'] = str_replace("<!--dlecomments-->", $tpl->result['comments'], $tpl->result['content']);
     } else {
         $tpl->result['content'] .= $tpl->result['comments'];
     }
 }
Beispiel #4
0
 function build_comments($template, $area, $allow_cache = false)
 {
     global $config, $tpl, $is_logged, $member_id, $user_group, $lang, $dle_login_hash, $_TIME, $allow_comments_ajax, $ajax_adds;
     $tpl->load_template($template);
     $tpl->copy_template = "<div id='comment-id-{id}'>" . $tpl->copy_template . "</div>";
     $tpl->template = "<div id='comment-id-{id}'>" . $tpl->template . "</div>";
     if (strpos($tpl->copy_template, "[xfvalue_") !== false) {
         $xfound = true;
     } else {
         $xfound = false;
     }
     if ($xfound) {
         $xfields = xfieldsload(true);
     }
     if ($area != 'ajax' and $config['comm_msort'] == "DESC") {
         $tpl->copy_template = "\n<div id=\"dle-ajax-comments\"></div>\n" . $tpl->copy_template;
     }
     if ($area != 'ajax') {
         $tpl->copy_template = "<form method=\"post\" action=\"\" name=\"dlemasscomments\" id=\"dlemasscomments\"><div id=\"dle-comments-list\">\n" . $tpl->copy_template;
     }
     if ($area != 'ajax') {
         $tpl->copy_template = "<a name=\"comment\"></a>" . $tpl->copy_template;
     }
     $rows = false;
     if ($allow_cache) {
         $rows = dle_cache("comm_" . $allow_cache, $this->query . " LIMIT " . $this->cstart . "," . $this->comments_per_pages);
     }
     if ($rows) {
         $rows = unserialize($rows);
         $full_cache = true;
     } else {
         $rows = $this->db->super_query($this->query . " LIMIT " . $this->cstart . "," . $this->comments_per_pages, true);
         if ($allow_cache) {
             create_cache("comm_" . $allow_cache, serialize($rows), $this->query . " LIMIT " . $this->cstart . "," . $this->comments_per_pages);
         }
     }
     if (count($rows)) {
         foreach ($rows as $row) {
             $this->intern_count++;
             $row['date'] = strtotime($row['date']);
             $row['gast_name'] = stripslashes($row['gast_name']);
             $row['gast_email'] = stripslashes($row['gast_email']);
             $row['name'] = stripslashes($row['name']);
             if (!$row['is_register'] or $row['name'] == '') {
                 if ($row['gast_email'] != "") {
                     $tpl->set('{author}', "<a href=\"mailto:" . htmlspecialchars($row['gast_email'], ENT_QUOTES) . "\">" . $row['gast_name'] . "</a>");
                 } else {
                     $tpl->set('{author}', $row['gast_name']);
                 }
                 $tpl->set('{login}', $row['gast_name']);
                 $tpl->set('[profile]', "");
                 $tpl->set('[/profile]', "");
             } else {
                 if ($config['allow_alt_url'] == "yes") {
                     $go_page = $config['http_home_url'] . "user/" . urlencode($row['name']) . "/";
                     $tpl->set('[profile]', "<a href=\"" . $config['http_home_url'] . "user/" . urlencode($row['name']) . "/\">");
                 } else {
                     $go_page = "{$PHP_SELF}?subaction=userinfo&user="******"<a href=\"{$PHP_SELF}?subaction=userinfo&amp;user="******"\">");
                 }
                 $go_page = "onclick=\"ShowProfile('" . urlencode($row['name']) . "', '" . htmlspecialchars($go_page) . "', '" . $user_group[$member_id['user_group']]['admin_editusers'] . "'); return false;\"";
                 if ($config['allow_alt_url'] == "yes") {
                     $tpl->set('{author}', "<a {$go_page} href=\"" . $config['http_home_url'] . "user/" . urlencode($row['name']) . "/\">" . $row['name'] . "</a>");
                 } else {
                     $tpl->set('{author}', "<a {$go_page} href=\"{$PHP_SELF}?subaction=userinfo&amp;user="******"\">" . $row['name'] . "</a>");
                 }
                 $tpl->set('{login}', $row['name']);
                 $tpl->set('[/profile]', "</a>");
             }
             if ($is_logged and $member_id['user_group'] == '1') {
                 $tpl->set('{ip}', "IP: <a onclick=\"return dropdownmenu(this, event, IPMenu('" . $row['ip'] . "', '" . $lang['ip_info'] . "', '" . $lang['ip_tools'] . "', '" . $lang['ip_ban'] . "'), '190px')\" href=\"https://www.nic.ru/whois/?ip={$row['ip']}\" target=\"_blank\">{$row['ip']}</a>");
             } else {
                 $tpl->set('{ip}', '');
             }
             $edit_limit = false;
             if (!$user_group[$member_id['user_group']]['edit_limit']) {
                 $edit_limit = true;
             } elseif ($row['date'] + $user_group[$member_id['user_group']]['edit_limit'] * 60 > $_TIME) {
                 $edit_limit = true;
             }
             if ($is_logged and $edit_limit and ($member_id['name'] == $row['name'] and $row['is_register'] and $user_group[$member_id['user_group']]['allow_editc'] or $user_group[$member_id['user_group']]['edit_allc'])) {
                 $tpl->set('[com-edit]', "<a onclick=\"ajax_comm_edit('" . $row['id'] . "', '" . $area . "'); return false;\" href=\"" . $config['http_home_url'] . "index.php?do=comments&amp;action=comm_edit&amp;id=" . $row['id'] . "&amp;area=" . $area . "\">");
                 $tpl->set('[/com-edit]', "</a>");
                 $allow_comments_ajax = true;
             } else {
                 $tpl->set_block("'\\[com-edit\\](.*?)\\[/com-edit\\]'si", "");
             }
             if ($is_logged and $edit_limit and ($member_id['name'] == $row['name'] and $row['is_register'] and $user_group[$member_id['user_group']]['allow_delc'] or $member_id['user_group'] == '1' or $user_group[$member_id['user_group']]['del_allc'])) {
                 $tpl->set('[com-del]', "<a href=\"javascript:DeleteComments('{$row['id']}', '{$dle_login_hash}')\">");
                 $tpl->set('[/com-del]', "</a>");
             } else {
                 $tpl->set_block("'\\[com-del\\](.*?)\\[/com-del\\]'si", "");
             }
             if ($user_group[$member_id['user_group']]['del_allc'] and !$user_group[$member_id['user_group']]['edit_limit']) {
                 $tpl->set('{mass-action}', "<input name=\"selected_comments[]\" value=\"{$row['id']}\" type=\"checkbox\" />");
             } else {
                 $tpl->set('{mass-action}', "");
             }
             if ($area == 'lastcomments') {
                 $tpl->set_block("'\\[fast\\](.*?)\\[/fast\\]'si", "");
             } else {
                 if ($user_group[$member_id['user_group']]['allow_addc'] and $config['allow_comments'] == "yes") {
                     if (!$row['is_register'] or $row['name'] == '') {
                         $row['name'] = $row['gast_name'];
                     } else {
                         $row['name'] = $row['name'];
                     }
                     $tpl->set('[fast]', "<a onmouseover=\"dle_copy_quote('" . str_replace(array(" ", "&#039;"), array("&nbsp;", "&amp;#039;"), $row['name']) . "');\" href=\"#\" onclick=\"dle_ins('" . str_replace(array(" ", "&#039;"), array("&nbsp;", "&amp;#039;"), $row['name']) . "'); return false;\">");
                     $tpl->set('[/fast]', "</a>");
                 } else {
                     $tpl->set_block("'\\[fast\\](.*?)\\[/fast\\]'si", "");
                 }
             }
             $tpl->set('{mail}', $row['email']);
             $tpl->set('{id}', $row['id']);
             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_comment'], $row['date']));
             }
             $tpl->copy_template = preg_replace("#\\{date=(.+?)\\}#ie", "langdate('\\1', '{$row['date']}')", $tpl->copy_template);
             if ($area == 'lastcomments') {
                 $row['category'] = intval($row['category']);
                 if ($config['allow_alt_url'] == "yes") {
                     if ($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']) . "/" . $row['post_id'] . "-" . $row['alt_name'] . ".html";
                         } else {
                             $full_link = $config['http_home_url'] . $row['post_id'] . "-" . $row['alt_name'] . ".html";
                         }
                     } else {
                         $full_link = $config['http_home_url'] . date('Y/m/d/', strtotime($row['newsdate'])) . $row['alt_name'] . ".html";
                     }
                 } else {
                     $full_link = $config['http_home_url'] . "index.php?newsid=" . $row['post_id'];
                 }
                 $tpl->set('{news_title}', "<a href=\"" . $full_link . "\">" . stripslashes($row['title']) . "</a>");
             } else {
                 $tpl->set('{news_title}', "");
             }
             if ($xfound) {
                 $xfieldsdata = xfieldsdataload($row['xfields']);
                 foreach ($xfields as $value) {
                     $preg_safe_name = preg_quote($value[0], "'");
                     if ($value[5] != 1 or $member_id['user_group'] == 1 or $is_logged and $row['is_register'] and $member_id['name'] == $row['name']) {
                         if (empty($xfieldsdata[$value[0]])) {
                             $tpl->copy_template = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template);
                             $tpl->copy_template = str_replace("[xfnotgiven_{$preg_safe_name}]", "", $tpl->copy_template);
                             $tpl->copy_template = str_replace("[/xfnotgiven_{$preg_safe_name}]", "", $tpl->copy_template);
                         } else {
                             $tpl->copy_template = preg_replace("'\\[xfnotgiven_{$preg_safe_name}\\](.*?)\\[/xfnotgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template);
                             $tpl->copy_template = str_replace("[xfgiven_{$preg_safe_name}]", "", $tpl->copy_template);
                             $tpl->copy_template = str_replace("[/xfgiven_{$preg_safe_name}]", "", $tpl->copy_template);
                         }
                         $tpl->copy_template = preg_replace("'\\[xfvalue_{$preg_safe_name}\\]'i", stripslashes($xfieldsdata[$value[0]]), $tpl->copy_template);
                     } else {
                         $tpl->copy_template = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template);
                         $tpl->copy_template = preg_replace("'\\[xfvalue_{$preg_safe_name}\\]'i", "", $tpl->copy_template);
                         $tpl->copy_template = preg_replace("'\\[xfnotgiven_{$preg_safe_name}\\](.*?)\\[/xfnotgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template);
                     }
                 }
             }
             if ($area == 'ajax' and isset($ajax_adds)) {
                 $tpl->set('{comment-id}', "--");
             } elseif ($area == 'lastcomments') {
                 $tpl->set('{comment-id}', $this->total_comments - $this->cstart - $this->intern_count + 1);
             } else {
                 if ($config['comm_msort'] == "ASC") {
                     $tpl->set('{comment-id}', $this->cstart + $this->intern_count);
                 } else {
                     $tpl->set('{comment-id}', $this->total_comments - $this->cstart - $this->intern_count + 1);
                 }
             }
             if ($row['foto']) {
                 $tpl->set('{foto}', $config['http_home_url'] . "uploads/fotos/" . $row['foto']);
             } else {
                 $tpl->set('{foto}', "{THEME}/images/noavatar.png");
             }
             if ($row['is_register'] and $row['fullname']) {
                 $tpl->set('[fullname]', "");
                 $tpl->set('[/fullname]', "");
                 $tpl->set('{fullname}', stripslashes($row['fullname']));
                 $tpl->set_block("'\\[not-fullname\\](.*?)\\[/not-fullname\\]'si", "");
             } else {
                 $tpl->set_block("'\\[fullname\\](.*?)\\[/fullname\\]'si", "");
                 $tpl->set('{fullname}', "");
                 $tpl->set('[not-fullname]', "");
                 $tpl->set('[/not-fullname]', "");
             }
             if ($row['is_register'] and $row['icq']) {
                 $tpl->set('[icq]', "");
                 $tpl->set('[/icq]', "");
                 $tpl->set('{icq}', stripslashes($row['icq']));
                 $tpl->set_block("'\\[not-icq\\](.*?)\\[/not-icq\\]'si", "");
             } else {
                 $tpl->set_block("'\\[icq\\](.*?)\\[/icq\\]'si", "");
                 $tpl->set('{icq}', "");
                 $tpl->set('[not-icq]', "");
                 $tpl->set('[/not-icq]', "");
             }
             if ($row['is_register'] and $row['land']) {
                 $tpl->set('[land]', "");
                 $tpl->set('[/land]', "");
                 $tpl->set('{land}', stripslashes($row['land']));
                 $tpl->set_block("'\\[not-land\\](.*?)\\[/not-land\\]'si", "");
             } else {
                 $tpl->set_block("'\\[land\\](.*?)\\[/land\\]'si", "");
                 $tpl->set('{land}', "");
                 $tpl->set('[not-land]', "");
                 $tpl->set('[/not-land]', "");
             }
             if ($row['comm_num']) {
                 $tpl->set('[comm-num]', "");
                 $tpl->set('[/comm-num]', "");
                 $tpl->set('{comm-num}', $row['comm_num']);
                 $tpl->set_block("'\\[not-comm-num\\](.*?)\\[/not-comm-num\\]'si", "");
             } else {
                 $tpl->set('{comm-num}', 0);
                 $tpl->set('[not-comm-num]', "");
                 $tpl->set('[/not-comm-num]', "");
                 $tpl->set_block("'\\[comm-num\\](.*?)\\[/comm-num\\]'si", "");
             }
             if ($row['news_num']) {
                 $tpl->set('[news-num]', "");
                 $tpl->set('[/news-num]', "");
                 $tpl->set('{news-num}', $row['news_num']);
                 $tpl->set_block("'\\[not-news-num\\](.*?)\\[/not-news-num\\]'si", "");
             } else {
                 $tpl->set('{news-num}', 0);
                 $tpl->set('[not-news-num]', "");
                 $tpl->set('[/not-news-num]', "");
                 $tpl->set_block("'\\[news-num\\](.*?)\\[/news-num\\]'si", "");
             }
             if ($row['is_register'] and $row['reg_date']) {
                 $tpl->set('{registration}', langdate("j.m.Y", $row['reg_date']));
             } else {
                 $tpl->set('{registration}', '--');
             }
             if ($row['is_register'] and $row['lastdate']) {
                 $tpl->set('{lastdate}', langdate("j.m.Y", $row['lastdate']));
                 if ($row['lastdate'] + 1200 > $_TIME or $row['user_id'] and $row['user_id'] == $member_id['user_id']) {
                     $tpl->set('[online]', "");
                     $tpl->set('[/online]', "");
                     $tpl->set_block("'\\[offline\\](.*?)\\[/offline\\]'si", "");
                 } else {
                     $tpl->set('[offline]', "");
                     $tpl->set('[/offline]', "");
                     $tpl->set_block("'\\[online\\](.*?)\\[/online\\]'si", "");
                 }
             } else {
                 $tpl->set('{lastdate}', '--');
                 $tpl->set_block("'\\[offline\\](.*?)\\[/offline\\]'si", "");
                 $tpl->set_block("'\\[online\\](.*?)\\[/online\\]'si", "");
             }
             if ($row['is_register'] and $row['signature'] and $user_group[$row['user_group']]['allow_signature']) {
                 $tpl->set_block("'\\[signature\\](.*?)\\[/signature\\]'si", "\\1");
                 $tpl->set('{signature}', stripslashes($row['signature']));
             } else {
                 $tpl->set_block("'\\[signature\\](.*?)\\[/signature\\]'si", "");
             }
             if ($is_logged) {
                 $tpl->set('[complaint]', "<a href=\"javascript:AddComplaint('" . $row['id'] . "', 'comments')\">");
                 $tpl->set('[/complaint]', "</a>");
             } else {
                 $tpl->set_block("'\\[complaint\\](.*?)\\[/complaint\\]'si", "");
             }
             if (!$row['user_group']) {
                 $row['user_group'] = 5;
             }
             if ($user_group[$row['user_group']]['icon']) {
                 $tpl->set('{group-icon}', "<img src=\"" . $user_group[$row['user_group']]['icon'] . "\" alt=\"\" />");
             } else {
                 $tpl->set('{group-icon}', "");
             }
             $tpl->set('{group-name}', $user_group[$row['user_group']]['group_prefix'] . $user_group[$row['user_group']]['group_name'] . $user_group[$row['user_group']]['group_suffix']);
             if (count($this->extras_rules)) {
                 foreach ($this->extras_rules as $rules) {
                     if ($rules[0] == 'set') {
                         $tpl->set($rules[1], $rules[2]);
                     } else {
                         $tpl->set_block($rules[1], $rules[2]);
                     }
                 }
             }
             if ($user_group[$member_id['user_group']]['allow_hide']) {
                 $row['text'] = str_ireplace("[hide]", "", str_ireplace("[/hide]", "", $row['text']));
             } else {
                 $row['text'] = preg_replace("#\\[hide\\](.+?)\\[/hide\\]#is", "<div class=\"quote\">" . $lang['news_regus'] . "</div>", $row['text']);
             }
             $tpl->set('{comment}', "<div id='comm-id-" . $row['id'] . "'>" . stripslashes($row['text']) . "</div>");
             $tpl->compile('comments');
         }
     } else {
         $tpl->result['comments'] = "";
         if ($area != 'ajax' and $config['comm_msort'] == "DESC") {
             $tpl->result['comments'] = "\n<div id=\"dle-ajax-comments\"></div>\n";
         }
         if ($area != 'ajax') {
             $tpl->result['comments'] = "<form method=\"post\" action=\"\" name=\"dlemasscomments\" id=\"dlemasscomments\"><div id=\"dle-comments-list\">\n" . $tpl->result['comments'];
         }
         if ($area != 'ajax') {
             $tpl->result['comments'] = "<a name=\"comment\"></a>" . $tpl->result['comments'];
         }
     }
     $tpl->clear();
     if ($area != 'ajax' and $config['comm_msort'] == "ASC") {
         $tpl->result['comments'] .= "\n<div id=\"dle-ajax-comments\"></div>\n";
     }
     if ($area != 'ajax' and $user_group[$member_id['user_group']]['del_allc'] and !$user_group[$member_id['user_group']]['edit_limit']) {
         $tpl->result['comments'] .= "\n<div class=\"mass_comments_action\">{$lang['mass_comments']}&nbsp;<select name=\"mass_action\"><option value=\"\">{$lang['edit_selact']}</option><option value=\"mass_combine\">{$lang['edit_selcomb']}</option><option value=\"mass_delete\">{$lang['edit_seldel']}</option></select>&nbsp;&nbsp;<input type=\"submit\" class=\"bbcodes\" value=\"{$lang['b_start']}\" /></div>\n<input type=\"hidden\" name=\"do\" value=\"comments\" /><input type=\"hidden\" name=\"dle_allow_hash\" value=\"{$dle_login_hash}\" /><input type=\"hidden\" name=\"area\" value=\"{$area}\" />";
     }
     if ($area != 'ajax') {
         $tpl->result['comments'] .= "</div></form>\n";
     }
     if (strpos($tpl->result['content'], "<!--dlecomments-->") !== false) {
         $tpl->result['content'] = str_replace("<!--dlecomments-->", $tpl->result['comments'], $tpl->result['content']);
     } else {
         $tpl->result['content'] .= $tpl->result['comments'];
     }
 }
		public function runBlockPro()
		{
			// Защита от фашистов )))) (НУЖНА ЛИ? )
			$this->config['post_id']     = @$this->db->safesql(strip_tags(str_replace('/', '', $this->config['post_id'])));
			$this->config['not_post_id'] = @$this->db->safesql(strip_tags(str_replace('/', '', $this->config['not_post_id'])));

			$this->config['author']      = @$this->db->safesql(strip_tags(str_replace('/', '', $this->config['author'])));
			$this->config['not_author']  = @$this->db->safesql(strip_tags(str_replace('/', '', $this->config['not_author'])));

			$this->config['xfilter']     = @$this->db->safesql(strip_tags(str_replace('/', '', $this->config['xfilter'])));
			$this->config['not_xfilter']     = @$this->db->safesql(strip_tags(str_replace('/', '', $this->config['not_xfilter'])));


			// Определяем сегодняшнюю дату
			$tooday = date( "Y-m-d H:i:s", (time() + $this->dle_config['date_adjust'] * 60) );
			// Проверка версии DLE
			if ($this->dle_config['version_id'] >= 9.6) $newVersion = true;
			
			
			// Пробуем подгрузить содержимое модуля из кэша
			$output = false;

			// Если установлено время жизи кеша - убираем префикс news_ чтобы кеш не чистился автоматом
			// и задаём настройки времени жизни кеша в секундах (надо доработать, где то косяк)
			if ($this->config['cache_live']) 
			{
				$this->config['prefix'] = ''; 

				$filedate = ENGINE_DIR.'/cache/'.$this->config['prefix'].'bp_'.md5(implode('_', $this->config)).'.tmp';

				if(@file_exists($filedate)) $cache_time=time()-@filemtime ($filedate);
				else $cache_time = $this->config['cache_live']*60;	
				if ($cache_time>=$this->config['cache_live']*60) $clear_time_cache = 1;
			}

			// Если nocache не установлен - добавляем префикс (по умолчанию news_) к файлу кеша. 
			if( !$this->config['nocache'])
			{
				$output = dle_cache($this->config['prefix'].'bp_'.md5(implode('_', $this->config)));
			}
			if ($clear_time_cache) {
				$output = false;
			}
			
			// Если значение кэша для данной конфигурации получено, выводим содержимое кэша
			if($output !== false)
			{
				$this->showOutput($output);
				return;
			}
			
			// Если в кэше ничего не найдено, генерируем модуль заново

			$wheres = array();


			// Условие для отображения только постов, прошедших модерацию
			$wheres[] = 'approve';

		
			// Разбираемся с временными рамками отбора новостей, если кол-во дней указано - ограничиваем выборку, если нет - выводим без ограничения даты
			// if ($this->config['day']) 
			// {
			// 	$interval = $this->config['day'];
			// 	$dateStart = 'AND date >= "'.$tooday.'" - INTERVAL "'.$interval.'" DAY'; 
			// }

			// if (!$this->config['day']) 
			// {
			// 	$dateStart = '';
			// }


			// Фильтрация КАТЕГОРИЙ по их ID
			if ($this->config['cat_id'] == 'this') $this->config['cat_id'] = $this->category_id;
			if ($this->config['not_cat_id'] == 'this') $this->config['not_cat_id'] = $this->category_id;
			
			if ($this->config['cat_id'] || $this->config['not_cat_id']) {
				$ignore = ($this->config['not_cat_id']) ? 'NOT ' : '';
				$catArr = ($this->config['not_cat_id']) ? $this->config['not_cat_id'] : $this->config['cat_id'];	
				
				$wheres[] = $ignore.'category regexp "[[:<:]]('.str_replace(',', '|', $catArr).')[[:>:]]"';				
			}

			// Фильтрация НОВОСТЕЙ по их ID
			if ($this->config['post_id'] == 'this') $this->config['post_id'] = $_REQUEST["newsid"];
			if ($this->config['not_post_id'] == 'this') $this->config['not_post_id'] = $_REQUEST["newsid"];

			if ($this->config['post_id'] || $this->config['not_post_id']) {
				$ignorePosts = ($this->config['not_post_id']) ? 'NOT ' : '';
				$postsArr = ($this->config['not_post_id']) ? $this->config['not_post_id'] : $this->config['post_id'];					
				$wheres[] = $ignorePosts.'id regexp "[[:<:]]('.str_replace(',', '|', $postsArr).')[[:>:]]"';				
			}

			// Фильтрация новостей по АВТОРАМ
			if ($this->config['author'] == 'this') $this->config['author'] = $_REQUEST["user"];
			if ($this->config['not_author'] == 'this') $this->config['not_author'] = $_REQUEST["user"];

			if ($this->config['author'] || $this->config['not_author']) {
				$ignoreAuthors = ($this->config['not_author']) ? 'NOT ' : '';
				$authorsArr = ($this->config['not_author']) ? $this->config['not_author'] : $this->config['author'];					
				$wheres[] = $ignoreAuthors.'autor regexp "[[:<:]]('.str_replace(',', '|', $authorsArr).')[[:>:]]"';				
			}

			// Фильтрация новостей по ДОПОЛНИТЕЛЬНЫМ ПОЛЯМ

			if ($this->config['xfilter'] || $this->config['not_xfilter']) {
				$ignoreXfilters = ($this->config['not_xfilter']) ? 'NOT ' : '';
				$xfiltersArr = ($this->config['not_xfilter']) ? $this->config['not_xfilter'] : $this->config['xfilter'];					
				$wheres[] = $ignoreXfilters.'xfields regexp "[[:<:]]('.str_replace(',', '|', $xfiltersArr).')[[:>:]]"';				
			}

			
			// Разбираемся с временными рамками отбора новостей, если кол-во дней указано - ограничиваем выборку, если нет - выводим без ограничения даты
			if(intval($this->config['day'])) $wheres[] =  'date >= "'.$tooday.'" - INTERVAL ' .  intval($this->config['day']) . ' DAY';

			// Условие для отображения только тех постов, дата публикации которых уже наступила
			$wheres[] = 'date < "'.$tooday.'"';
			
			// Условие для фильтрации текущего id
			// $wheres[] = 'id != '.$this->config['postId'];
			
			// Складываем условия
			$where = implode(' AND ', $wheres);
			
			// Направление сортировки по убыванию или возрастанию
			$ordering = $this->config['order'] == 'new'?'DESC':'ASC';

			// Сортировка новостей 
			switch ($this->config['sort']) 
			{
				case 'date':					// Дата
					$sort = 'date '; 			
					break;

				case 'rating':					// Рейтинг
					$sort = 'rating ';			
					break;

				case 'comms':					// Комментарии
					$sort = 'comm_num ';
					break;

				case 'views':					// Просмотры
					$sort = 'news_read ';
					break;

				case 'random':					// Случайные
					$sort = 'RAND() ';
					break;
				
				default:						// Топ как в DLE (сортировка по умолчанию)
					$sort = 'rating '.$ordering.', comm_num '.$ordering.', news_read ';
					break;
			}
			
			// Формирование запроса в зависимости от версии движка

			if ($newVersion) {
				// 9.6 и выше
				$selectRows = 'p.id, p.autor, p.date, p.short_story, p.full_story, p.xfields, p.title, p.category, p.alt_name, p.allow_comm, p.comm_num, e.news_read, e.allow_rate, e.rating, e.vote_num, e.votes';
			} else {
				// старые версии
				$selectRows = '*'; //пока старые версии курят в сторонке
			}

			
			/**
			 * Service function - take params from table
			 * @param $table string - название таблицы
			 * @param $fields string - необходимые поля через запятйю или * для всех
			 * @param $where string - условие выборки
			 * @param $multirow bool - забирать ли один ряд или несколько
			 * @param $start int - начальное значение выборки
			 * @param $limit int - количество записей для выборки, 0 - выбрать все
			 * @param $sort string - поле, по которому осуществляется сортировка
			 * @param $sort_order - направление сортировки
			 * @return array с данными или false если mysql вернуль 0 рядов
			 */
			//$news = $this->load_table (PREFIX."_post", $fields = "*", $where = '1', $multirow = false, $start = 0, $limit = 10, $sort = '', $sort_order = 'desc');

			$news = $this->load_table (PREFIX . '_post p LEFT JOIN ' . PREFIX . '_post_extras e ON (p.id=e.news_id)', $selectRows, $where, true, $this->config['start_from'], $this->config['limit'], $sort, $ordering);


			if(empty($news)) $news = array();

			// Задаём переменную, в котоую будем всё складывать
			$output = '';

			// Если в выборке нет новостей - сообщаем об этом
			if (empty($news)) {
				$output .= '<span style="color: #f00">По заданным критериям материалов нет, попробуйте изменить параметры строки подключения</span>';
				return;
			}
			// Пробегаем по массиву с новостями и формируем список
			foreach ($news as $newsItem) 
			{
				$xfields = xfieldsload();
				$newsItem['date'] = strtotime($newsItem['date']);

				// Формируем ссылки на категории и иконки категорий
				$my_cat = array();
				$my_cat_icon = array();
				$my_cat_link = array();
				$cat_list = explode(',', $newsItem['category']);
				foreach($cat_list as $element) {
					if(isset($this->cat_info[$element])) {
						$my_cat[] = $this->cat_info[$element]['name'];
						if ($this->cat_info[$element]['icon'])
							$my_cat_icon[] = '<img class="bp-cat-icon" src="'.$this->cat_info[$element]['icon'].'" alt="'.$this->cat_info[$element]['name'].'" />';
						else
							$my_cat_icon[] = '<img class="bp-cat-icon" src="{THEME}/blockpro/'.$this->config['noicon'].'" alt="'.$this->cat_info[$element]['name'].'" />';
						if( $this->dle_config['allow_alt_url'] == 'yes' ) 
							$my_cat_link[] = '<a href="'.$this->dle_config['http_home_url'].get_url($element).'/">'.$this->cat_info[$element]['name'].'</a>';
						else 
							$my_cat_link[] = '<a href="'.$PHP_SELF.'?do=cat&category='.$this->cat_info[$element]['alt_name'].'">'.$this->cat_info[$element]['name'].'</a>';
					}
				}
				$categoryUrl = ($newsItem['category']) ? $this->dle_config['http_home_url'] . get_url(intval($newsItem['category'])) . '/' : '/' ;

				// Ссылка на профиль  юзера
				if( $this->dle_config['allow_alt_url'] == 'yes' ) {
					$go_page = $config['http_home_url'].'user/'.urlencode($newsItem['autor']).'/';
				} else {
					$go_page = $PHP_SELF.'?subaction=userinfo&amp;user='******'autor']);
				}

				// Выводим картинку
				switch($this->config['image'])
				{
					// Изображение из дополнительного поля
					case 'short_story':
						$imgArray = $this->getImage($newsItem['short_story'], $newsItem['date']);
						break;
					
					// Первое изображение из полного описания
					case 'full_story':
						$imgArray = $this->getImage($newsItem['full_story'], $newsItem['date']);
						break;
					
					// По умолчанию - первое изображение из краткой новости
					default:
						$xfieldsdata = xfieldsdataload($newsItem['xfields'], $newsItem['date']);
						if(!empty($xfieldsdata) && !empty($xfieldsdata[$this->config['image']]))
						{
							$imgArray = getImage($xfieldsdata[$this->config['image']]);
						}
						break;
				}

				// Определяем переменные, выводящие картинку
				$image = ($imgArray['imgResized']) ? $imgArray['imgResized'] : '{THEME}/blockpro/'.$this->config['noimage'];
				if (!$imgArray['imgResized']) {
					$imageFull = '{THEME}/blockpro/'.$this->config['noimage_full'];
				} else {
					$imageFull = $imgArray['imgOriginal'];
				}

				// Формируем вид даты новости для вывода в шаблон
				if(date('Ymd', $newsItem['date']) == date('Ymd')) {
					$showDate = $this->dle_lang['time_heute'].langdate(', H:i', $newsItem['date']);		
				} elseif(date('Ymd', $newsItem['date'])  == date('Ymd') - 1) {			
					$showDate = $this->dle_lang['time_gestern'].langdate(', H:i', $newsItem['date']);		
				} else {			
					$showDate = langdate($this->dle_config['timestamp_active'], $newsItem['date']);		
				}

				/**
				 * Код, формирующий вывод шаблона новости
				 */
				$tpl->copy_template = preg_replace("#\{date=(.+?)\}#ie", "langdate('\\1', '{$newsItem['date']}')", $tpl->copy_template );

				$output .= $this->applyTemplate($this->config['template'],
					array(
						'{title}'          	=> $newsItem['title'],
						'{full-link}'		=> $this->getPostUrl($newsItem),
						'{image}'		=> $image,
						'{image_full}'		=> $imageFull,
						'{short-story}' 	=> $this->textLimit($newsItem['short_story'], $this->config['text_limit']),
                    				'{full-story}'  	=> $this->textLimit($newsItem['full_story'], $this->config['text_limit']),
                    				'{link-category}'	=> implode(', ', $my_cat_link),
						'{category}'		=> implode(', ', $my_cat),
						'{category-icon}'	=> implode('', $my_cat_icon),
						'{category-url}'	=> $categoryUrl,
						'{news-id}'		=> $newsItem['id'],
						'{author}'		=> "<a onclick=\"ShowProfile('" . urlencode( $newsItem['autor'] ) . "', '" . $go_page . "', '" . $user_group[$member_id['user_group']]['admin_editusers'] . "'); return false;\" href=\"" . $go_page . "\">" . $newsItem['autor'] . "</a>",
						'{login}'		=> $newsItem['autor'],
						'[profile]'		=> '<a href="'.$go_page.'">',
						'[/profile]'		=> '</a>',
						'[com-link]'		=> $newsItem['allow_comm']?'<a href="'.$this->getPostUrl($newsItem).'#comment">':'',
						'[/com-link]'		=> $newsItem['allow_comm']?'</a>':'',
						'{comments-num}'	=> $newsItem['allow_comm']?$newsItem['comm_num']:'',
						'{views}'		=> $newsItem['news_read'],
						'{date}'		=> $showDate,
						'{rating}'		=> $newsItem['allow_rate']?ShowRating( $newsItem['id'], $newsItem['rating'], $newsItem['vote_num'], 0 ):'', 
						'{vote-num}'		=> $newsItem['allow_rate']?$newsItem['vote_num']:'', 

					),
					array(
						// "'\[show_name\\](.*?)\[/show_name\]'si" => !empty($name)?"\\1":'',
						// "'\[show_description\\](.*?)\[/show_description\]'si" => !empty($description)?"\\1":'',
						"'\[comments\\](.*?)\[/comments\]'si"             => $newsItem['comm_num']!=='0'?'\\1':'',
						"'\[not-comments\\](.*?)\[/not-comments\]'si"     => $newsItem['comm_num']=='0'?'\\1':'',
						"'\[rating\\](.*?)\[/rating\]'si"                 => $newsItem['allow_rate']?'\\1':'',
						"'\[allow-comm\\](.*?)\[/allow-comm\]'si"         => $newsItem['allow_comm']?'\\1':'',
						"'\[not-allow-comm\\](.*?)\[/not-allow-comm\]'si" => !$newsItem['allow_comm']?'\\1':'',
						// не уверен, но можно попробовать
						//"'{title limit=\"(.*?)\"}'esi" => 'dle_substr(striptags($newsItem[\'title\']),0,\\1,$this->config[\'charset\'])',
					)

				);
			}

			// Cохраняем в кэш по данной конфигурации если nocache false
			if(!$this->config['nocache'])
			{
				create_cache($this->config['prefix'].'bp_'.md5(implode('_', $this->config)), $output);
			}
			
			// Выводим содержимое модуля
			$this->showOutput($output);

			
		}