Esempio n. 1
0
/**
 * Create the meta keywords based on the content
 *
 * @package News
 * @author Instant Zero (http://xoops.instant-zero.com)
 * @copyright (c) Instant Zero
 */
function nw_createmeta_keywords($content)
{
	include NW_MODULE_PATH . '/config.php';
	include_once NW_MODULE_PATH . '/class/blacklist.php';
	include_once NW_MODULE_PATH . '/class/registryfile.php';

	if(!$cfg['meta_keywords_auto_generate']) {
		return '';
	}
	$registry = new nw_registryfile('nw_metagen_options.txt');
	$tcontent = '';
	$tcontent = $registry->getfile();
	if(xoops_trim($tcontent) != '') {
		list($keywordscount, $keywordsorder) = explode(',',$tcontent);
	} else {
		$keywordscount = $cfg['meta_keywords_count'];
		$keywordsorder = $cfg['meta_keywords_order'];
	}

	$tmp = array();
	// Search for the "Minimum keyword length"
	if(isset($_SESSION['nw_keywords_limit'])) {
		$limit = $_SESSION['nw_keywords_limit'];
	} else {
		$config_handler =& xoops_gethandler('config');
		$xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);
		$limit = $xoopsConfigSearch['keyword_min'];
		$_SESSION['nw_keywords_limit'] = $limit;
	}
	$myts =& MyTextSanitizer::getInstance();
	$content = str_replace ("<br />", " ", $content);
	$content= $myts->undoHtmlSpecialChars($content);
	$content= strip_tags($content);
	$content=strtolower($content);
	$search_pattern=array("&nbsp;","\t","\r\n","\r","\n",",",".","'",";",":",")","(",'"','?','!','{','}','[',']','<','>','/','+','-','_','\\','*');
	$replace_pattern=array(' ',' ',' ',' ',' ',' ',' ',' ','','','','','','','','','','','','','','','','','','','');
	$content = str_replace($search_pattern, $replace_pattern, $content);
	$keywords = explode(' ',$content);
	switch($keywordsorder) {
		case 0:	// Ordre d'apparition dans le texte
			$keywords = array_unique($keywords);
			break;
		case 1:	// Ordre de fréquence des mots
			$keywords = array_count_values($keywords);
			asort($keywords);
			$keywords = array_keys($keywords);
			break;
		case 2:	// Ordre inverse de la fréquence des mots
			$keywords = array_count_values($keywords);
			arsort($keywords);
			$keywords = array_keys($keywords);
			break;
	}
	// Remove black listed words
	$metablack = new nw_blacklist();
	$words = $metablack->getAllKeywords();
	$keywords = $metablack->remove_blacklisted($keywords);

	foreach($keywords as $keyword) {
		if(strlen($keyword)>=$limit && !is_numeric($keyword)) {
			$tmp[] = $keyword;
		}
	}
	$tmp = array_slice($tmp, 0, $keywordscount);
	if(count($tmp) > 0) {
		return implode(',',$tmp);
	} else {
		if(!isset($config_handler) || !is_object($config_handler)) {
			$config_handler =& xoops_gethandler('config');
		}
		$xoopsConfigMetaFooter =& $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER);
		if(isset($xoopsConfigMetaFooter['meta_keywords'])) {
			return $xoopsConfigMetaFooter['meta_keywords'];
		} else {
			return '';
		}
	}
}
Esempio n. 2
0
/**
 * Save Metagen Options
 */
function MetagenSaveOptions()
{
	$registry = new nw_registryfile('nw_metagen_options.txt');
	$registry->savefile(intval($_POST['keywordscount']).','.intval($_POST['keywordsorder']));
	redirect_header('index.php?op=metagen', 0, _AM_NW_DBUPDATED);
}