function user_title($count, $title) { global $config; if ($count and dle_strlen($title, $config['charset']) > $count) { $title = dle_substr($title, 0, $count, $config['charset']); if ($temp_dmax = dle_strrpos($title, ' ', $config['charset'])) { $title = dle_substr($title, 0, $temp_dmax, $config['charset']); } } return $title; }
/** * @param $data - контент * @param $limit * @param string $etc - Окончание обрезанного текста * @param bool $wordcut - жесткое ограничение символов * * @param string $charset * * @return string $data - обрезанный результат */ public static function textLimit($data, $limit, $etc = '…', $wordcut = false, $charset = 'utf-8') { $data = strip_tags($data, '<br>'); $data = trim(str_replace(['<br>', '<br />'], ' ', $data)); if ($limit && dle_strlen($data, $charset) > $limit) { $data = dle_substr($data, 0, $limit, $charset) . $etc; if (!$wordcut && ($word_pos = dle_strrpos($data, ' ', $charset))) { $data = dle_substr($data, 0, $word_pos, $charset) . $etc; } } return $data; }
} if (count($images)) { $i = 0; foreach ($images as $url) { $i++; $tpl->copy_template = str_replace('{image-' . $i . '}', $url, $tpl->copy_template); $tpl->copy_template = str_replace('[image-' . $i . ']', "", $tpl->copy_template); $tpl->copy_template = str_replace('[/image-' . $i . ']', "", $tpl->copy_template); } } $tpl->copy_template = preg_replace("#\\[image-(.+?)\\](.+?)\\[/image-(.+?)\\]#is", "", $tpl->copy_template); $tpl->copy_template = preg_replace("#\\{image-(.+?)\\}#i", "{THEME}/dleimages/no_image.jpg", $tpl->copy_template); } $tpl->set('{short-story}', $row['short_story']); if (preg_match("#\\{short-story limit=['\"](.+?)['\"]\\}#i", $tpl->copy_template, $matches)) { $count = intval($matches[1]); $row['short_story'] = str_replace("</p><p>", " ", $row['short_story']); $row['short_story'] = strip_tags($row['short_story'], "<br>"); $row['short_story'] = trim(str_replace("<br>", " ", str_replace("<br />", " ", str_replace("\n", " ", str_replace("\r", "", $row['short_story']))))); if ($count and dle_strlen($row['short_story'], $config['charset']) > $count) { $row['short_story'] = dle_substr($row['short_story'], 0, $count, $config['charset']); if ($temp_dmax = dle_strrpos($row['short_story'], ' ', $config['charset'])) { $row['short_story'] = dle_substr($row['short_story'], 0, $temp_dmax, $config['charset']); } } $tpl->set($matches[0], $row['short_story']); } $tpl->compile('content'); } $tpl->clear(); $db->free($sql_result);
$title = dle_substr($title, 0, $t_count, $config['charset']) . "…"; } $tplb->set($t_matches[0], $title); } if ($user_group[$member_id['user_group']]['allow_hide']) { $rowb['short_story'] = str_ireplace(array("[hide]", "[/hide]"), "", $rowb['short_story']); } else { $rowb['short_story'] = preg_replace("#\\[hide\\](.+?)\\[/hide\\]#ims", "<div class=\"quote\">" . $lang['news_regus'] . "</div>", $rowb['short_story']); } if (preg_match("#\\{text limit=['\"](.+?)['\"]\\}#i", $tplb->copy_template, $matches)) { $count = intval($matches[1]); $rowb['short_story'] = strip_tags($rowb['short_story'], "<br>"); $rowb['short_story'] = trim(str_replace(array("<br>", '<br />'), " ", $rowb['short_story'])); if ($count > 0 and dle_strlen($rowb['short_story'], $config['charset']) > $count) { $rowb['short_story'] = dle_substr($rowb['short_story'], 0, $count, $config['charset']) . "…"; if (!$wordcut && ($word_pos = dle_strrpos($rowb['short_story'], ' ', $config['charset']))) { $rowb['short_story'] = dle_substr($rowb['short_story'], 0, $word_pos, $config['charset']) . "…"; } } $tplb->set($matches[0], $rowb['short_story']); } else { $tplb->set('{text}', $rowb['short_story']); } $tplb->set('{full-link}', $full_link); $tplb->set('{comments-num}', $rowb['comm_num']); $tplb->set('{views}', $rowb['news_read']); if ($allow_userinfo and !$rowb['approve'] and ($member_id['name'] == $rowb['autor'] and !$user_group[$member_id['user_group']]['allow_all_edit'])) { $tplb->set('[edit]', "<a href=\"" . $config['http_home_url'] . "index.php?do=addnews&id=" . $rowb['id'] . "\" >"); $tplb->set('[/edit]', "</a>"); } elseif ($is_logged and ($member_id['name'] == $rowb['autor'] and $user_group[$member_id['user_group']]['allow_edit'] or $user_group[$member_id['user_group']]['allow_all_edit'])) { $_SESSION['referrer'] = $_SERVER['REQUEST_URI'];
$tpl->copy_template = str_replace("[xfgiven_{$value[0]}]", "", $tpl->copy_template); $tpl->copy_template = str_replace("[/xfgiven_{$value[0]}]", "", $tpl->copy_template); } $xfieldsdata[$value[0]] = stripslashes($xfieldsdata[$value[0]]); if ($config['allow_links'] and $value[3] == "textarea" and function_exists('replace_links')) { $xfieldsdata[$value[0]] = replace_links($xfieldsdata[$value[0]], $replace_links['news']); } $tpl->copy_template = str_replace("[xfvalue_{$value[0]}]", $xfieldsdata[$value[0]], $tpl->copy_template); if (preg_match("#\\[xfvalue_{$preg_safe_name} limit=['\"](.+?)['\"]\\]#i", $tpl->copy_template, $matches)) { $count = intval($matches[1]); $xfieldsdata[$value[0]] = str_replace("</p><p>", " ", $xfieldsdata[$value[0]]); $xfieldsdata[$value[0]] = strip_tags($xfieldsdata[$value[0]], "<br>"); $xfieldsdata[$value[0]] = trim(str_replace("<br>", " ", str_replace("<br />", " ", str_replace("\n", " ", str_replace("\r", "", $xfieldsdata[$value[0]]))))); if ($count and dle_strlen($xfieldsdata[$value[0]], $config['charset']) > $count) { $xfieldsdata[$value[0]] = dle_substr($xfieldsdata[$value[0]], 0, $count, $config['charset']); if ($temp_dmax = dle_strrpos($xfieldsdata[$value[0]], ' ', $config['charset'])) { $xfieldsdata[$value[0]] = dle_substr($xfieldsdata[$value[0]], 0, $temp_dmax, $config['charset']); } } $tpl->set($matches[0], $xfieldsdata[$value[0]]); } } } $category_id = $row['category']; $tpl->compile('content'); if ($user_group[$member_id['user_group']]['allow_hide']) { $tpl->result['content'] = str_ireplace("[hide]", "", str_ireplace("[/hide]", "", $tpl->result['content'])); } else { $tpl->result['content'] = preg_replace("#\\[hide\\](.+?)\\[/hide\\]#ims", "<div class=\"quote\">" . $lang['news_regus'] . "</div>", $tpl->result['content']); } if ($config['allow_banner'] and count($banner_in_news) and !$view_template) {
$tpl->copy_template = $lang['news_err_39']; } $tpl->copy_template = str_replace('[full-preview]', "", $tpl->copy_template); $tpl->copy_template = str_replace('[/full-preview]', "", $tpl->copy_template); $tpl->copy_template = preg_replace("'\\[short-preview\\](.*?)\\[/short-preview\\]'si", "", $tpl->copy_template); $tpl->copy_template = preg_replace("'\\[static-preview\\](.*?)\\[/static-preview\\]'si", "", $tpl->copy_template); if (strlen($full_story) < 10 and strpos($tpl->copy_template, "{short-story}") === false) { $full_story = $short_story; } $tpl->set('{title}', $title); if (preg_match("#\\{title limit=['\"](.+?)['\"]\\}#i", $tpl->copy_template, $matches)) { $count = intval($matches[1]); $title = strip_tags($title); if ($count and dle_strlen($title, $config['charset']) > $count) { $title = dle_substr($title, 0, $count, $config['charset']); if ($temp_dmax = dle_strrpos($title, ' ', $config['charset'])) { $title = dle_substr($title, 0, $temp_dmax, $config['charset']); } } $tpl->set($matches[0], $title); } if (!count($_REQUEST['category'])) { $_REQUEST['category'] = array(); $_REQUEST['category'][] = '0'; } $c_list = array(); foreach ($_REQUEST['category'] as $value) { $c_list[] = intval($value); } $category_id = implode(',', $c_list); if (strpos($tpl->copy_template, "[catlist=") !== false) {
function create_metatags($story, $ajax = false) { global $config, $db; $keyword_count = 20; $newarr = array(); $headers = array(); $quotes = array("\"", "`", "\t", '\\n', '\\r', "\n", "\r", "\\", ",", ".", "/", "¬", "#", ";", ":", "@", "~", "[", "]", "{", "}", "=", "-", "+", ")", "(", "*", "^", "%", "\$", "<", ">", "?", "!", '"'); $fastquotes = array("\"", "`", "\t", "\n", "\r", '"', '\\r', '\\n', "\$", "{", "}", "[", "]", "<", ">", "\\"); $story = preg_replace("#\\[hide\\](.+?)\\[/hide\\]#is", "", $story); $story = preg_replace("'\\[attachment=(.*?)\\]'si", "", $story); $story = preg_replace("'\\[page=(.*?)\\](.*?)\\[/page\\]'si", "", $story); $story = str_replace("{PAGEBREAK}", "", $story); $story = str_replace(" ", " ", $story); $story = str_replace('<br />', ' ', $story); $story = strip_tags($story); $story = preg_replace("#&(.+?);#", "", $story); $story = trim(str_replace(" ,", "", $story)); if (trim($_REQUEST['meta_title']) != "") { $headers['title'] = trim(htmlspecialchars(strip_tags(stripslashes($_REQUEST['meta_title'])), ENT_COMPAT, $config['charset'])); $headers['title'] = $db->safesql(str_replace($fastquotes, '', $headers['title'])); } else { $headers['title'] = ""; } if (trim($_REQUEST['descr']) != "") { $headers['description'] = strip_tags(stripslashes($_REQUEST['descr'])); if (dle_strlen($headers['description'], $config['charset']) > 200) { $headers['description'] = dle_substr($headers['description'], 0, 200, $config['charset']); if ($temp_dmax = dle_strrpos($headers['description'], ' ', $config['charset'])) { $headers['description'] = dle_substr($headers['description'], 0, $temp_dmax, $config['charset']); } } $headers['description'] = $db->safesql(str_replace($fastquotes, '', $headers['description'])); } elseif ($config['create_metatags'] or $ajax) { $story = str_replace($fastquotes, '', $story); $headers['description'] = stripslashes($story); if (dle_strlen($headers['description'], $config['charset']) > 200) { $headers['description'] = dle_substr($headers['description'], 0, 200, $config['charset']); if ($temp_dmax = dle_strrpos($headers['description'], ' ', $config['charset'])) { $headers['description'] = dle_substr($headers['description'], 0, $temp_dmax, $config['charset']); } } $headers['description'] = $db->safesql($headers['description']); } else { $headers['description'] = ''; } if (trim($_REQUEST['keywords']) != "") { $arr = explode(",", $_REQUEST['keywords']); $newarr = array(); foreach ($arr as $word) { $newarr[] = trim($word); } $_REQUEST['keywords'] = implode(", ", $newarr); $headers['keywords'] = $db->safesql(str_replace($fastquotes, " ", strip_tags(stripslashes($_REQUEST['keywords'])))); } elseif ($config['create_metatags'] or $ajax) { $story = str_replace($quotes, ' ', $story); $arr = explode(" ", $story); foreach ($arr as $word) { if (dle_strlen($word, $config['charset']) > 4) { $newarr[] = $word; } } $arr = array_count_values($newarr); arsort($arr); $arr = array_keys($arr); $total = count($arr); $offset = 0; $arr = array_slice($arr, $offset, $keyword_count); $headers['keywords'] = $db->safesql(implode(", ", $arr)); } else { $headers['keywords'] = ''; } return $headers; }
foreach ($images as $url) { $i++; $tpl->copy_template = str_replace('{image-' . $i . '}', $url, $tpl->copy_template); $tpl->copy_template = str_replace('[image-' . $i . ']', "", $tpl->copy_template); $tpl->copy_template = str_replace('[/image-' . $i . ']', "", $tpl->copy_template); } } $tpl->copy_template = preg_replace("#\\[image-(.+?)\\](.+?)\\[/image-(.+?)\\]#is", "", $tpl->copy_template); $tpl->copy_template = preg_replace("#\\{image-(.+?)\\}#i", "{THEME}/dleimages/no_image.jpg", $tpl->copy_template); } $content['description'] = strip_tags($content['description'], "<br>"); $content['description'] = str_replace("<br>", " ", str_replace("<br />", " ", $content['description'])); $content['description'] = trim($content['description']); if ($value['dmax'] and dle_strlen($content['description'], $config['charset']) > $value['dmax']) { $content['description'] = dle_substr($content['description'], 0, $value['dmax'], $config['charset']); if ($temp_dmax = dle_strrpos($content['description'], ' ', $config['charset'])) { $content['description'] = dle_substr($content['description'], 0, $temp_dmax, $config['charset']); } $content['description'] .= " ..."; } $content['link'] = htmlspecialchars($content['link'], ENT_QUOTES, $config['charset']); $tpl->set('{title}', $content['title']); $tpl->set('{news}', $content['description']); $tpl->set('[link]', "<a href=\"{$content['link']}\" target=\"_blank\">"); $tpl->set('[/link]', "</a>"); $tpl->set('{link}', $content['link']); $tpl->set('{category}', $content['category']); $tpl->set('{author}', $content['author']); $tpl->set('{date}', langdate($value['rss_date_format'], $content['date'])); $news_date = $content['date']; $tpl->copy_template = preg_replace_callback("#\\{date=(.+?)\\}#i", "formdate", $tpl->copy_template);
} else { $tpl->set_block("'\\[yandex\\](.*?)\\[/yandex\\]'si", ""); $tpl->set('{yandex_url}', ''); } if (preg_match("#\\{text limit=['\"](.+?)['\"]\\}#i", $tpl->copy_template, $matches)) { $count = intval($matches[1]); $stext = preg_replace("#<!--TBegin(.+?)<!--TEnd-->#is", "", $template); $stext = preg_replace("#<!--MBegin(.+?)<!--MEnd-->#is", "", $stext); $stext = preg_replace("'\\[attachment=(.*?)\\]'si", "", $stext); $stext = preg_replace("#\\[hide\\](.+?)\\[/hide\\]#ims", "", $stext); $stext = str_replace("</p><p>", " ", $stext); $stext = strip_tags($stext, "<br>"); $stext = trim(str_replace("<br>", " ", str_replace("<br />", " ", str_replace("\n", " ", str_replace("\r", "", $stext))))); if ($count and dle_strlen($stext, $config['charset']) > $count) { $stext = dle_substr($stext, 0, $count, $config['charset']); if ($temp_dmax = dle_strrpos($stext, ' ', $config['charset'])) { $stext = dle_substr($stext, 0, $temp_dmax, $config['charset']); } } $tpl->set($matches[0], $stext); } if (stripos($tpl->copy_template, "{image-") !== false) { $images = array(); preg_match_all('/(img|src)=("|\')[^"\'>]+/i', $template, $media); $data = preg_replace('/(img|src)("|\'|="|=\')(.*)/i', "\$3", $media[0]); foreach ($data as $url) { $info = pathinfo($url); if (isset($info['extension'])) { if ($info['filename'] == "spoiler-plus" or $info['filename'] == "spoiler-plus") { continue; }
/** * @param $data - контент * @param $length - максимальный размер возвращаемого контента * * @return $data - обрезанный результат */ public function textLimit($data, $count) { if ($this->config['text_limit'] != '0') { $data = strip_tags($data, '<br>'); $data = trim(str_replace( array('<br>','<br />'), ' ', $data)); if($count && dle_strlen($data, $this->dle_config['charset'] ) > $count) { $data = dle_substr( $data, 0, $count, $this->dle_config['charset'] ). '…'; if( !$this->config['wordcut'] && ($word_pos = dle_strrpos( $data, ' ', $this->dle_config['charset'] )) ) $data = dle_substr( $data, 0, $word_pos, $this->dle_config['charset'] ). '…'; } } return $data; }
function create_keywords($story) { global $metatags, $config; $keyword_count = 20; $newarr = array(); $quotes = array("\"", "`", "\t", "\n", "\r", ",", ".", "/", "\\", "¬", "#", ";", ":", "@", "~", "[", "]", "{", "}", "=", "-", "+", ")", "(", "*", "^", "%", "\$", "<", ">", "?", "!", '"'); $fastquotes = array("\"", "`", "\t", "\n", "\r", '"', "\\", '\\r', '\\n', "/", "{", "}", "[", "]"); $story = preg_replace("#\\[hide\\](.+?)\\[/hide\\]#is", "", $story); $story = preg_replace("'\\[attachment=(.*?)\\]'si", "", $story); $story = preg_replace("'\\[page=(.*?)\\](.*?)\\[/page\\]'si", "", $story); $story = str_replace("{PAGEBREAK}", "", $story); $story = str_replace(" ", " ", $story); $story = str_replace('<br />', ' ', $story); $story = strip_tags($story); $story = preg_replace("#&(.+?);#", "", $story); $story = trim(str_replace(" ,", "", stripslashes($story))); $story = str_replace($fastquotes, '', $story); $metatags['description'] = dle_substr($story, 0, 200, $config['charset']); if ($temp_dmax = dle_strrpos($metatags['description'], ' ', $config['charset'])) { $metatags['description'] = dle_substr($metatags['description'], 0, $temp_dmax, $config['charset']); } $story = str_replace($quotes, ' ', $story); $arr = explode(" ", $story); foreach ($arr as $word) { if (dle_strlen($word, $config['charset']) > 4) { $newarr[] = $word; } } $arr = array_count_values($newarr); arsort($arr); $arr = array_keys($arr); $total = count($arr); $offset = 0; $arr = array_slice($arr, $offset, $keyword_count); $metatags['keywords'] = implode(", ", $arr); }