1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 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: 25: 26: 27: 28: 29: 30:
31: function cecCreateMetatags($metatags) {
32: global $cfg, $lang, $idart, $client, $cfgClient, $idcat, $idartlang;
33:
34:
35: $db = cRegistry::getDb();
36:
37:
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:
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:
65:
66:
67: $oArt = new cApiArticleLanguage();
68: $oArt->loadByArticleAndLanguageId($idart, $lang);
69:
70:
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:
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:
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:
157: foreach ($availableTags as $key => $value) {
158: $metavalue = conGetMetaValue($idartlang, $key);
159:
160: if (cString::getStringLength($metavalue) == 0) {
161:
162:
163: switch (cString::toLowerCase($value['metatype'])) {
164: case 'author':
165:
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:
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:
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: 212: 213: 214: 215: 216: 217: 218: 219:
220: function CheckIfMetaTagExists($arrMetatags, $sCheckForMetaTag) {
221: if (!is_array($arrMetatags) || count($arrMetatags) == 0) {
222:
223: return 0;
224: }
225:
226:
227: foreach ($arrMetatags as $pos => $item) {
228: if (isset($item['name']) && $item['name'] == $sCheckForMetaTag && $item['name'] != '') {
229:
230: return $pos;
231: }
232: }
233:
234:
235: return count($arrMetatags);
236: }
237:
238: ?>