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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • 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:  * @return array
 26:  */
 27: function cecCreateMetatags($metatags) {
 28:     global $cfg, $lang, $idart, $client, $cfgClient, $idcat, $idartlang;
 29: 
 30:     // (Re)build metatags
 31:     $db = cRegistry::getDb();
 32: 
 33:     // Get encoding
 34:     $oLang = new cApiLanguage((int) $lang);
 35:     if ($oLang->get('encoding')) {
 36:         $sEncoding = strtoupper($oLang->get('encoding'));
 37:     } else {
 38:         $sEncoding = 'ISO-8859-1';
 39:     }
 40: 
 41:     // Get idcat of homepage
 42:     $sql = "SELECT a.idcat
 43:         FROM
 44:             " . $cfg['tab']['cat_tree'] . " AS a,
 45:             " . $cfg['tab']['cat_lang'] . " AS b
 46:         WHERE
 47:             (a.idcat = b.idcat) AND
 48:             (b.visible = 1) AND
 49:             (b.idlang = " . (int) $lang . ")
 50:         ORDER BY a.idtree LIMIT 1";
 51: 
 52:     $db->query($sql);
 53: 
 54:     if ($db->next_record()) {
 55:         $idcat_homepage = $db->f('idcat');
 56:     }
 57: 
 58:     $availableTags = conGetAvailableMetaTagTypes();
 59: 
 60:     // Get first headline and first text for current article
 61:     // @todo use this cApiArticleLanguage instance in code below, instead of
 62:     // creating it again and again!
 63:     $oArt = new cApiArticleLanguage();
 64:     $oArt->loadByArticleAndLanguageId($idart, $lang);
 65: 
 66:     // Set idartlang, if not set
 67:     if ($idartlang == '') {
 68:         $idartlang = $oArt->getField('idartlang');
 69:     }
 70: 
 71:     $arrHead1 = $oArt->getContent('htmlhead');
 72:     $arrHead2 = $oArt->getContent('head');
 73: 
 74:     if (!is_array($arrHead1)) {
 75:         $arrHead1 = array();
 76:     }
 77: 
 78:     if (!is_array($arrHead2)) {
 79:         $arrHead2 = array();
 80:     }
 81: 
 82:     $arrHeadlines = array_merge($arrHead1, $arrHead2);
 83: 
 84:     foreach ($arrHeadlines as $key => $value) {
 85:         if ($value != '') {
 86:             $sHeadline = $value;
 87:             break;
 88:         }
 89:     }
 90: 
 91:     $sHeadline = strip_tags($sHeadline);
 92:     $sHeadline = substr(str_replace(chr(13) . chr(10), ' ', $sHeadline), 0, 100);
 93: 
 94:     $arrText1 = $oArt->getContent('html');
 95:     $arrText2 = $oArt->getContent('text');
 96: 
 97:     if (!is_array($arrText1)) {
 98:         $arrText1 = array();
 99:     }
100: 
101:     if (!is_array($arrText2)) {
102:         $arrText2 = array();
103:     }
104: 
105:     $arrText = array_merge($arrText1, $arrText2);
106: 
107:     foreach ($arrText as $key => $value) {
108:         if ($value != '') {
109:             $sText = $value;
110:             break;
111:         }
112:     }
113: 
114:     $sText = strip_tags(urldecode($sText));
115:     $sText = keywordDensity('', $sText);
116: 
117:     // Get metatags for homeapge
118:     $arrHomepageMetaTags = array();
119: 
120:     $sql = "SELECT startidartlang FROM " . $cfg['tab']['cat_lang'] . " WHERE (idcat=" . (int) $idcat_homepage . ") AND(idlang=" . (int) $lang . ")";
121:     $db->query($sql);
122: 
123:     if ($db->next_record()) {
124:         $iIdArtLangHomepage = $db->f('startidartlang');
125: 
126:         // Get idart of homepage
127:         $sql = "SELECT idart FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang=" . (int) $iIdArtLangHomepage;
128:         $db->query($sql);
129:         if ($db->next_record()) {
130:             $iIdArtHomepage = $db->f('idart');
131:         }
132: 
133:         $t1 = $cfg['tab']['meta_tag'];
134:         $t2 = $cfg['tab']['meta_type'];
135: 
136:         $sql = "SELECT " . $t1 . ".metavalue," . $t2 . ".metatype FROM " . $t1 . " INNER JOIN " . $t2 . " ON " . $t1 . ".idmetatype = " . $t2 . ".idmetatype WHERE " . $t1 . ".idartlang =" . $iIdArtLangHomepage . " ORDER BY " . $t2 . ".metatype";
137: 
138:         $db->query($sql);
139: 
140:         while ($db->next_record()) {
141:             $arrHomepageMetaTags[$db->f('metatype')] = $db->f('metavalue');
142:         }
143: 
144:         $oArt = new cApiArticleLanguage();
145:         $oArt->loadByArticleAndLanguageId($iIdArtHomepage, $lang);
146: 
147:         $arrHomepageMetaTags['pagetitle'] = $oArt->getField('title');
148:     }
149: 
150:     // Cycle through all metatags
151:     foreach ($availableTags as $key => $value) {
152:         $metavalue = conGetMetaValue($idartlang, $key);
153: 
154:         if (strlen($metavalue) == 0) {
155:             // Add values for metatags that don't have a value in the current
156:             // article
157:             switch (strtolower($value['metatype'])) {
158:                 case 'author':
159:                     // Build author metatag from name of last modifier
160:                     $oArt = new cApiArticleLanguage();
161:                     $oArt->loadByArticleAndLanguageId($idart, $lang);
162: 
163:                     $lastmodifier = $oArt->getField('modifiedby');
164:                     $oUser = new cApiUser(md5($lastmodifier));
165:                     $lastmodifier_real = $oUser->getRealName();
166: 
167:                     $iCheck = CheckIfMetaTagExists($metatags, 'author');
168:                     $metatags[$iCheck]['name'] = 'author';
169:                     $metatags[$iCheck]['content'] = $lastmodifier_real;
170: 
171:                     break;
172:                 case 'description':
173:                     // Build description metatag from first headline on page
174:                     $iCheck = CheckIfMetaTagExists($metatags, 'description');
175:                     $metatags[$iCheck]['name'] = 'description';
176:                     $metatags[$iCheck]['content'] = $sHeadline;
177: 
178:                     break;
179:                 case 'keywords':
180:                     $iCheck = CheckIfMetaTagExists($metatags, 'keywords');
181:                     $metatags[$iCheck]['name'] = 'keywords';
182:                     $metatags[$iCheck]['content'] = $sText;
183: 
184:                     break;
185:                 case 'revisit-after':
186:                 case 'robots':
187:                 case 'expires':
188:                     // Build these 3 metatags from entries in homepage
189:                     $sCurrentTag = strtolower($value['name']);
190:                     $iCheck = CheckIfMetaTagExists($metatags, $sCurrentTag);
191:                     if($sCurrentTag != '' && $arrHomepageMetaTags[$sCurrentTag] != "") {
192:                         $metatags[$iCheck]['name'] = $sCurrentTag;
193:                         $metatags[$iCheck]['content'] = $arrHomepageMetaTags[$sCurrentTag];
194:                     }
195: 
196:                     break;
197:             }
198:         }
199:     }
200: 
201:     return $metatags;
202: }
203: 
204: /**
205:  * Checks if the metatag allready exists inside the metatag list.
206:  *
207:  * @param array|mixed $arrMetatags
208:  *         List of metatags or not a list
209:  * @param string $sCheckForMetaTag
210:  *         The metatag to check
211:  * @return int
212:  *         Position of metatag inside the metatag list or the next 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 && $item['name'] != '') {
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.11 API documentation generated by ApiGen 2.8.0