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