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: function cecCreateMetatags($metatags) {
28: global $cfg, $lang, $idart, $client, $cfgClient, $idcat, $idartlang;
29:
30:
31: $db = cRegistry::getDb();
32:
33:
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:
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:
61:
62:
63: $oArt = new cApiArticleLanguage();
64: $oArt->loadByArticleAndLanguageId($idart, $lang);
65:
66:
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:
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:
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:
151: foreach ($availableTags as $key => $value) {
152: $metavalue = conGetMetaValue($idartlang, $key);
153:
154: if (strlen($metavalue) == 0) {
155:
156:
157: switch (strtolower($value['metatype'])) {
158: case 'author':
159:
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:
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:
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: 206: 207: 208: 209: 210: 211: 212: 213:
214: function CheckIfMetaTagExists($arrMetatags, $sCheckForMetaTag) {
215: if (!is_array($arrMetatags) || count($arrMetatags) == 0) {
216:
217: return 0;
218: }
219:
220:
221: foreach ($arrMetatags as $pos => $item) {
222: if ($item['name'] == $sCheckForMetaTag && $item['name'] != '') {
223:
224: return $pos;
225: }
226: }
227:
228:
229: return count($arrMetatags);
230: }
231:
232: ?>