Source for file function.keywords.php
Documentation is available at function.keywords.php
* Zikula Application Framework
* @copyright (c) 2004, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: function.keywords.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package Zikula_Template_Plugins
* Smarty function to get the meta keywords
* This function will take the contents of the page and transfer it
* into a keyword list. If stopwords are defined, they are filtered out.
* The keywords are sorted by count.
* As a default, the whole page contents are taken as a base for keyword
* generation. If set, the contents of "contents" are taken.
* Beware that the function always returns the site keywords if "generate
* meta keywords" is turned off.
* PLEASE NOTE: This function adds additional overhead when dynamic keyword
* generation is turned on. You should use Xanthia page caching in this case.
* - contents if set, this wil be taken as a base for the keywords
* - dynamic if set, the keywords will be created from the content / mainconent
* oterwise we use the page vars. The rules are:
* 1) If dynamic keywords disabled in admin settings then use static keywords
* 2) if parameter "dynamic" not set or empty then always use main content (default),
* 3) if parameter "dynamic" set and not empty then use page vars if any set - otherwise use content.
* - assign if set, the keywords will be assigned to this variable
* <meta name="KEYWORDS" content="<!--[keywords]-->">
* @param array $params All attributes passed to this function from the template
* @param object $smarty Reference to the Smarty object
* @return string the keywords
// Check for empty keywords array
$emptyPageVar = (empty($keywordsarray));
if (!isset ($params['dynamic']) || empty($params['dynamic']) || $emptyPageVar) {
if (isset ($params['contents'])) {
$pagecontent = $params['contents'];
} else if (isset ($smarty->_tpl_vars['maincontent'])) {
$pagecontent = $smarty->_tpl_vars['maincontent'];
// get the contents of the page.
// strip the contents to an array at each non-letter
// this might be an issue for languages with other charsets.
// sort the array by the most used keys first
// Remove entry that counts the number of blanks
// get back the keywords from the indexes
// not correct here: The _user language_ is not relevant, only
// the language of the document. How to get this?
$stopwords = file($stopword_file);
// make it a comma-separated string
$keywords = implode(',', $keywords);
// use PageUtil vars instead, no need to take care about stopwords
$ak = array_keys($keywordsarray); // einmal AK, immer AK ;-)
$keywordsarray[$v] = trim($keywordsarray[$v]);
if (empty($keywordsarray[$v])) {
unset ($keywordsarray[$v]);
$keywords = implode(',', $keywordsarray);
if (isset ($params['assign'])) {
$smarty->assign($params['assign'], $keywords);
* Convert all HTML entities to their applicable characters
* This function is a fallback if html_entity_decode isn't defined
* in the PHP version used (i.e. PHP < 4.3.0).
* Please note that this function doesn't support all parameters
* of the original html_entity_decode function.
* @param string $string the this function converts all HTML entities to their applicable characters from string.
* @return the converted string
* @link http://php.net/html_entity_decode The documentation of html_entity_decode
return (strtr($string, $trans_tbl));
|