1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: cInclude('plugins', 'repository/keyword_density.php');
20:
21: function cecCreateMetatags($metatags) {
22: global $cfg, $lang, $idart, $client, $cfgClient, $idcat, $idartlang;
23:
24:
25: $db = cRegistry::getDb();
26:
27:
28: $oLang = new cApiLanguage((int) $lang);
29: if ($oLang->get('encoding')) {
30: $sEncoding = strtoupper($oLang->get('encoding'));
31: } else {
32: $sEncoding = 'ISO-8859-1';
33: }
34:
35:
36: $sql = "SELECT a.idcat
37: FROM
38: " . $cfg['tab']['cat_tree'] . " AS a,
39: " . $cfg['tab']['cat_lang'] . " AS b
40: WHERE
41: (a.idcat = b.idcat) AND
42: (b.visible = 1) AND
43: (b.idlang = " . (int) $lang . ")
44: ORDER BY a.idtree LIMIT 1";
45:
46: $db->query($sql);
47:
48: if ($db->next_record()) {
49: $idcat_homepage = $db->f('idcat');
50: }
51:
52: $availableTags = conGetAvailableMetaTagTypes();
53:
54:
55:
56:
57: $oArt = new cApiArticleLanguage();
58: $oArt->loadByArticleAndLanguageId($idart, $lang);
59:
60:
61: if ($idartlang == '') {
62: $idartlang = $oArt->getField('idartlang');
63: }
64:
65: $arrHead1 = $oArt->getContent('htmlhead');
66: $arrHead2 = $oArt->getContent('head');
67:
68: if (!is_array($arrHead1)) {
69: $arrHead1 = array();
70: }
71:
72: if (!is_array($arrHead2)) {
73: $arrHead2 = array();
74: }
75:
76: $arrHeadlines = array_merge($arrHead1, $arrHead2);
77:
78: foreach ($arrHeadlines as $key => $value) {
79: if ($value != '') {
80: $sHeadline = $value;
81: break;
82: }
83: }
84:
85: $sHeadline = strip_tags($sHeadline);
86: $sHeadline = substr(str_replace(chr(13) . chr(10), ' ', $sHeadline), 0, 100);
87:
88: $arrText1 = $oArt->getContent('html');
89: $arrText2 = $oArt->getContent('text');
90:
91: if (!is_array($arrText1)) {
92: $arrText1 = array();
93: }
94:
95: if (!is_array($arrText2)) {
96: $arrText2 = array();
97: }
98:
99: $arrText = array_merge($arrText1, $arrText2);
100:
101: foreach ($arrText as $key => $value) {
102: if ($value != '') {
103: $sText = $value;
104: break;
105: }
106: }
107:
108: $sText = strip_tags(urldecode($sText));
109: $sText = keywordDensity('', $sText);
110:
111:
112: $arrHomepageMetaTags = array();
113:
114: $sql = "SELECT startidartlang FROM " . $cfg['tab']['cat_lang'] . " WHERE (idcat=" . (int) $idcat_homepage . ") AND(idlang=" . (int) $lang . ")";
115: $db->query($sql);
116:
117: if ($db->next_record()) {
118: $iIdArtLangHomepage = $db->f('startidartlang');
119:
120:
121: $sql = "SELECT idart FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang=" . (int) $iIdArtLangHomepage;
122: $db->query($sql);
123: if ($db->next_record()) {
124: $iIdArtHomepage = $db->f('idart');
125: }
126:
127: $t1 = $cfg['tab']['meta_tag'];
128: $t2 = $cfg['tab']['meta_type'];
129:
130: $sql = "SELECT " . $t1 . ".metavalue," . $t2 . ".metatype FROM " . $t1 . " INNER JOIN " . $t2 . " ON " . $t1 . ".idmetatype = " . $t2 . ".idmetatype WHERE " . $t1 . ".idartlang =" . $iIdArtLangHomepage . " ORDER BY " . $t2 . ".metatype";
131:
132: $db->query($sql);
133:
134: while ($db->next_record()) {
135: $arrHomepageMetaTags[$db->f('metatype')] = $db->f('metavalue');
136: }
137:
138: $oArt = new cApiArticleLanguage();
139: $oArt->loadByArticleAndLanguageId($iIdArtHomepage, $lang);
140:
141: $arrHomepageMetaTags['pagetitle'] = $oArt->getField('title');
142: }
143:
144:
145: foreach ($availableTags as $key => $value) {
146: $metavalue = conGetMetaValue($idartlang, $key);
147:
148: if (strlen($metavalue) == 0) {
149:
150:
151: switch (strtolower($value['metatype'])) {
152: case 'author':
153:
154: $oArt = new cApiArticleLanguage();
155: $oArt->loadByArticleAndLanguageId($idart, $lang);
156:
157: $lastmodifier = $oArt->getField('modifiedby');
158: $oUser = new cApiUser(md5($lastmodifier));
159: $lastmodifier_real = $oUser->getRealname();
160:
161: $iCheck = CheckIfMetaTagExists($metatags, 'author');
162: $metatags[$iCheck]['name'] = 'author';
163: $metatags[$iCheck]['content'] = $lastmodifier_real;
164:
165: break;
166: case 'date':
167:
168: $oArt = new cApiArticleLanguage();
169: $oArt->loadByArticleAndLanguageId($idart, $lang);
170: $lastmodified = $oArt->getField('lastmodified');
171:
172: $iCheck = CheckIfMetaTagExists($metatags, 'date');
173: $metatags[$iCheck]['name'] = 'date';
174: $metatags[$iCheck]['content'] = $lastmodified;
175:
176: break;
177: case 'description':
178:
179: $iCheck = CheckIfMetaTagExists($metatags, 'description');
180: $metatags[$iCheck]['name'] = 'description';
181: $metatags[$iCheck]['content'] = $sHeadline;
182:
183: break;
184: case 'keywords':
185: $iCheck = CheckIfMetaTagExists($metatags, 'keywords');
186: $metatags[$iCheck]['name'] = 'keywords';
187: $metatags[$iCheck]['content'] = $sText;
188:
189: break;
190: case 'revisit-after':
191: case 'robots':
192: case 'expires':
193:
194: $sCurrentTag = strtolower($value['name']);
195: $iCheck = CheckIfMetaTagExists($metatags, $sCurrentTag);
196: $metatags[$iCheck]['name'] = $sCurrentTag;
197: $metatags[$iCheck]['content'] = $arrHomepageMetaTags[$sCurrentTag];
198:
199: break;
200: }
201: }
202: }
203:
204: return $metatags;
205: }
206:
207: 208: 209: 210: 211: 212: 213: 214:
215: function CheckIfMetaTagExists($arrMetatags, $sCheckForMetaTag) {
216: if (!is_array($arrMetatags) || count($arrMetatags) == 0) {
217:
218: return 0;
219: }
220:
221:
222: foreach ($arrMetatags as $pos => $item) {
223: if ($item['name'] == $sCheckForMetaTag) {
224:
225: return $pos;
226: }
227: }
228:
229:
230: return count($arrMetatags);
231: }
232:
233: ?>