AVE.CMS v3.28
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.9 KiB

8 years ago
<?php
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru
*
*/
class Meta
{
private $_keyword_count = 10;
6 years ago
public function __construct($keyword_count = false)
8 years ago
{
6 years ago
if ((int)$keyword_count)
$this->_keyword_count = $keyword_count;
8 years ago
}
6 years ago
public function setKeywordCount($keyword_count)
8 years ago
{
6 years ago
if ((int)$keyword_count)
$this->_keyword_count = $keyword_count;
8 years ago
}
6 years ago
public function generateMeta($text)
8 years ago
{
$newarr = array ();
$quotes = array ("\x22", "\x60", "\t", "\n", "\r", ",", "/", "¬", "#", ";", ":", "@", "~", "[", "]", "{", "}", "=", "+", ")", "(", "*", "^", "%", "$", "<", ">", "?", "!", '"');
$fastquotes = array ("\x22", "\x60", "\t", "\n", "\r", '"', "\\", '\r', '\n', "/", "{", "}", "[", "]" );
$text = str_replace( chr(9), ' ', $text );
$text = str_replace( chr(10), ' ', $text );
$text = str_replace( chr(13), ' ', $text );
$text = str_replace( "&nbsp;", " ", $text );
$text = str_replace( '<br />', ' ', $text );
$text = strip_tags( $text );
$text = preg_replace('/ {2,}/',' ',$text);
$text = preg_replace( "#&(.+?);#", "", $text );
//$text = trim(str_replace( " ,", "", stripslashes( $text )));
$text = preg_replace('/\[tag:(.+?)\]/', '', $text);
$text = preg_replace('/\[mod_(.+?)\]/', '', $text);
$text = str_replace( $fastquotes, '', $text );
$text = str_replace( $quotes, ' ', $text );
$arr = explode( " ", $text );
6 years ago
foreach ($arr as $word)
{
if (mb_strlen(($word)) > 4 OR (mb_strtoupper($word) == $word) and mb_strlen(($word)) > 1)
$newarr[] = $word;
8 years ago
}
6 years ago
$arr = array_count_values($newarr);
8 years ago
6 years ago
arsort($arr);
8 years ago
6 years ago
$arr = array_keys($arr);
// Не используется
// $total = count($arr);
8 years ago
$offset = 0;
6 years ago
$arr = array_slice($arr, $offset, $this->_keyword_count);
8 years ago
$return['keywords'] = implode( ", ", $arr );
$return['description'] = trim(mb_substr( trim($text), 0, 220 ),'.').'.';
return $return;
}
}