Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Functions

  • cecCreateBaseHref
  • cecCreateMetatags
  • cecFrontendCategoryAccess
  • cecFrontendCategoryAccess_Backend
  • cecIndexArticle
  • CheckIfMetaTagExists
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * CONTENIDO Chain.
  4:  * Generate metatags for current article if they are not set in article
  5:  * properties
  6:  *
  7:  * @package          Core
  8:  * @subpackage       Chain
  9:  * @version          SVN Revision $Rev:$
 10:  *
 11:  * @author           Andreas Lindner, Unknown
 12:  * @copyright        four for business AG <www.4fb.de>
 13:  * @license          http://www.contenido.org/license/LIZENZ.txt
 14:  * @link             http://www.4fb.de
 15:  * @link             http://www.contenido.org
 16:  */
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: cInclude('plugins', 'repository/keyword_density.php');
 20: 
 21: function cecCreateMetatags($metatags) {
 22:     global $cfg, $lang, $idart, $client, $cfgClient, $idcat, $idartlang;
 23: 
 24:     // (Re)build metatags
 25:     $db = cRegistry::getDb();
 26: 
 27:     // Get encoding
 28:     $oLang = new cApiLanguage((int) $lang);
 29:     if ($oLang->get('encoding')) {
 30:         $sEncoding = strtoupper($oLang->get('encoding'));
 31:     } else {
 32:         $sEncoding = 'ISO-8859-1';
 33:     }
 34: 
 35:     // Get idcat of homepage
 36:     $sql = "SELECT a.idcat
 37:         FROM
 38:             " . $cfg['tab']['cat_tree'] . " AS a,
 39:             " . $cfg['tab']['cat_lang'] . " AS b
 40:         WHERE
 41:             (a.idcat = b.idcat) AND
 42:             (b.visible = 1) AND
 43:             (b.idlang = " . (int) $lang . ")
 44:         ORDER BY a.idtree LIMIT 1";
 45: 
 46:     $db->query($sql);
 47: 
 48:     if ($db->next_record()) {
 49:         $idcat_homepage = $db->f('idcat');
 50:     }
 51: 
 52:     $availableTags = conGetAvailableMetaTagTypes();
 53: 
 54:     // Get first headline and first text for current article
 55:     // @todo use this cApiArticleLanguage instance in code below, instead of
 56:     // creating it again and again!
 57:     $oArt = new cApiArticleLanguage();
 58:     $oArt->loadByArticleAndLanguageId($idart, $lang);
 59: 
 60:     // Set idartlang, if not set
 61:     if ($idartlang == '') {
 62:         $idartlang = $oArt->getField('idartlang');
 63:     }
 64: 
 65:     $arrHead1 = $oArt->getContent('htmlhead');
 66:     $arrHead2 = $oArt->getContent('head');
 67: 
 68:     if (!is_array($arrHead1)) {
 69:         $arrHead1 = array();
 70:     }
 71: 
 72:     if (!is_array($arrHead2)) {
 73:         $arrHead2 = array();
 74:     }
 75: 
 76:     $arrHeadlines = array_merge($arrHead1, $arrHead2);
 77: 
 78:     foreach ($arrHeadlines as $key => $value) {
 79:         if ($value != '') {
 80:             $sHeadline = $value;
 81:             break;
 82:         }
 83:     }
 84: 
 85:     $sHeadline = strip_tags($sHeadline);
 86:     $sHeadline = substr(str_replace(chr(13) . chr(10), ' ', $sHeadline), 0, 100);
 87: 
 88:     $arrText1 = $oArt->getContent('html');
 89:     $arrText2 = $oArt->getContent('text');
 90: 
 91:     if (!is_array($arrText1)) {
 92:         $arrText1 = array();
 93:     }
 94: 
 95:     if (!is_array($arrText2)) {
 96:         $arrText2 = array();
 97:     }
 98: 
 99:     $arrText = array_merge($arrText1, $arrText2);
100: 
101:     foreach ($arrText as $key => $value) {
102:         if ($value != '') {
103:             $sText = $value;
104:             break;
105:         }
106:     }
107: 
108:     $sText = strip_tags(urldecode($sText));
109:     $sText = keywordDensity('', $sText);
110: 
111:     // Get metatags for homeapge
112:     $arrHomepageMetaTags = array();
113: 
114:     $sql = "SELECT startidartlang FROM " . $cfg['tab']['cat_lang'] . " WHERE (idcat=" . (int) $idcat_homepage . ") AND(idlang=" . (int) $lang . ")";
115:     $db->query($sql);
116: 
117:     if ($db->next_record()) {
118:         $iIdArtLangHomepage = $db->f('startidartlang');
119: 
120:         // Get idart of homepage
121:         $sql = "SELECT idart FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang=" . (int) $iIdArtLangHomepage;
122:         $db->query($sql);
123:         if ($db->next_record()) {
124:             $iIdArtHomepage = $db->f('idart');
125:         }
126: 
127:         $t1 = $cfg['tab']['meta_tag'];
128:         $t2 = $cfg['tab']['meta_type'];
129: 
130:         $sql = "SELECT " . $t1 . ".metavalue," . $t2 . ".metatype FROM " . $t1 . " INNER JOIN " . $t2 . " ON " . $t1 . ".idmetatype = " . $t2 . ".idmetatype WHERE " . $t1 . ".idartlang =" . $iIdArtLangHomepage . " ORDER BY " . $t2 . ".metatype";
131: 
132:         $db->query($sql);
133: 
134:         while ($db->next_record()) {
135:             $arrHomepageMetaTags[$db->f('metatype')] = $db->f('metavalue');
136:         }
137: 
138:         $oArt = new cApiArticleLanguage();
139:         $oArt->loadByArticleAndLanguageId($iIdArtHomepage, $lang);
140: 
141:         $arrHomepageMetaTags['pagetitle'] = $oArt->getField('title');
142:     }
143: 
144:     // Cycle through all metatags
145:     foreach ($availableTags as $key => $value) {
146:         $metavalue = conGetMetaValue($idartlang, $key);
147: 
148:         if (strlen($metavalue) == 0) {
149:             // Add values for metatags that don't have a value in the current
150:             // article
151:             switch (strtolower($value['metatype'])) {
152:                 case 'author':
153:                     // Build author metatag from name of last modifier
154:                     $oArt = new cApiArticleLanguage();
155:                     $oArt->loadByArticleAndLanguageId($idart, $lang);
156: 
157:                     $lastmodifier = $oArt->getField('modifiedby');
158:                     $oUser = new cApiUser(md5($lastmodifier));
159:                     $lastmodifier_real = $oUser->getRealname();
160: 
161:                     $iCheck = CheckIfMetaTagExists($metatags, 'author');
162:                     $metatags[$iCheck]['name'] = 'author';
163:                     $metatags[$iCheck]['content'] = $lastmodifier_real;
164: 
165:                     break;
166:                 case 'date':
167:                     // Build date metatag from date of last modification
168:                     $oArt = new cApiArticleLanguage();
169:                     $oArt->loadByArticleAndLanguageId($idart, $lang);
170:                     $lastmodified = $oArt->getField('lastmodified');
171: 
172:                     $iCheck = CheckIfMetaTagExists($metatags, 'date');
173:                     $metatags[$iCheck]['name'] = 'date';
174:                     $metatags[$iCheck]['content'] = $lastmodified;
175: 
176:                     break;
177:                 case 'description':
178:                     // Build description metatag from first headline on page
179:                     $iCheck = CheckIfMetaTagExists($metatags, 'description');
180:                     $metatags[$iCheck]['name'] = 'description';
181:                     $metatags[$iCheck]['content'] = $sHeadline;
182: 
183:                     break;
184:                 case 'keywords':
185:                     $iCheck = CheckIfMetaTagExists($metatags, 'keywords');
186:                     $metatags[$iCheck]['name'] = 'keywords';
187:                     $metatags[$iCheck]['content'] = $sText;
188: 
189:                     break;
190:                 case 'revisit-after':
191:                 case 'robots':
192:                 case 'expires':
193:                     // Build these 3 metatags from entries in homepage
194:                     $sCurrentTag = strtolower($value['name']);
195:                     $iCheck = CheckIfMetaTagExists($metatags, $sCurrentTag);
196:                     $metatags[$iCheck]['name'] = $sCurrentTag;
197:                     $metatags[$iCheck]['content'] = $arrHomepageMetaTags[$sCurrentTag];
198: 
199:                     break;
200:             }
201:         }
202:     }
203:     return $metatags;
204: }
205: 
206: /**
207:  * Checks if the metatag allready exists inside the metatag list.
208:  *
209:  * @param array|mixed $arrMetatags List of metatags or not a list
210:  * @param string $sCheckForMetaTag The metatag to check
211:  * @return int Position of metatag inside the metatag list or the next
212:  *         available position
213:  */
214: function CheckIfMetaTagExists($arrMetatags, $sCheckForMetaTag) {
215:     if (!is_array($arrMetatags) || count($arrMetatags) == 0) {
216:         // metatag list ist not set or empty, return initial position
217:         return 0;
218:     }
219: 
220:     // loop thru existing metatags and check against the listitem name
221:     foreach ($arrMetatags as $pos => $item) {
222:         if ($item['name'] == $sCheckForMetaTag) {
223:             // metatag found -> return the position
224:             return $pos;
225:         }
226:     }
227: 
228:     // metatag doesn't exists, return next position
229:     return count($arrMetatags);
230: }
231: 
232: ?>
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0