get_template_vars('autodescription'); } } if (!isset($content_id) || empty($content_id)) { $extra_attr = 'content'; $module_name = 'Search'; $content_obj = $gCms->GetContentOperations()->getContentObject(); if (is_object($content_obj)) { $content_id = $content_obj->Id(); $manager = $gCms->GetHierarchyManager(); $node = $manager->getNodeById($content_id); if( !isset($node) || $node === FALSE ) return; $content = $node->Getcontent(); preg_match_all("|]+name=\"([^\"]*)\"[^>]+content=\"([^\"]*)\"[^>]+>|i", $gCms->GetContentOperations()->getContentObject()->Metadata(), $preg_array, PREG_SET_ORDER); // find existing meta data $found_meta = array(); if (!empty($preg_array)) { foreach($preg_array as $meta) { $found_meta[$meta[1]] = $meta[2]; } } $desc = $content->GetPropertyValue('content_en'); } } $do_keywords = isset($found_meta['keywords'])?false:true; $do_description = isset($found_meta['description'])?false:true; if ($do_keywords && $keywords) { if (CmsModule::GetModuleInstance('Search')) { $db = $gCms->GetDb(); $query = 'SELECT b.word FROM '.cms_db_prefix().'module_search_items a, '.cms_db_prefix().'module_search_index b WHERE a.content_id = ? AND a.module_name = ? AND a.extra_attr = ? AND a.id = b.item_id AND length(b.word) >= ? AND b.count >= ? ORDER BY b.count DESC'; $dbr = $db->SelectLimit( $query, $wordcount, 0, array($content_id, $module_name, $extra_attr, $wordlength, $worddensity)); $wordlist = array(); while( $dbr && ($row = $dbr->FetchRow() ) ) { $wordlist[] = strip_tags(str_replace('"','',$row['word'])); } $addkeys = array_diff($addkeys,$wordlist); $wordlist = array_merge($addkeys, $wordlist); if (!empty($wordlist)) { printf (''."\n"); } } } if ($do_description && $description) { $desc = preg_replace('/[\n\r]/','',$desc); $desc = str_replace('><','> <',$desc); $desc = strip_tags(str_replace('"','',$desc)); $desc = preg_replace('/{.*}/','',$desc); if (mb_strlen($desc) > $desclength) { $break = '.'; if (false !== ($breakpoint = mb_strpos($desc, $break, $desclength))) { if ($breakpoint < mb_strlen($desc) - 1) { $desc = mb_substr($desc, 0, $breakpoint).'.'; } } } if (!empty($desc)) { printf (''."\n"); } } } function smarty_cms_help_function_autometa() { ?>

What does this do?

Creates meta tags "keywords" and "description" on-the-fly if these tags are not found in the page metadata field. Keywords are taken from Search module. Description includes first characters of the page content.

How do I use it?

Just insert the tag into your template/page like: {autometa}

Module News

Keywords meta for detail view of news is supported automatically. To add auto description from news article, open detail template of news and add {assign var="autodescription" value=$entry->summary} or {assign var="autodescription" value=$entry->content} at the top of the template. Tip: you would add the second example if you do not use summary field for your news articles.

What parameters does it take?

About

Author: iCMS.info

fixes by Fernando Morgado aka Jo Morg 17 July 2014

Version: 1.2.2

Change Log