Overview

Packages

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

Functions

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