1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 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: 26: 27:
28: function cecCreateMetatags($metatags) {
29: global $cfg, $lang, $idart, $client, $cfgClient, $idcat, $idartlang;
30:
31:
32: $db = cRegistry::getDb();
33:
34:
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:
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:
62:
63:
64: $oArt = new cApiArticleLanguage();
65: $oArt->loadByArticleAndLanguageId($idart, $lang);
66:
67:
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:
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:
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:
152: foreach ($availableTags as $key => $value) {
153: $metavalue = conGetMetaValue($idartlang, $key);
154:
155: if (strlen($metavalue) == 0) {
156:
157:
158: switch (strtolower($value['metatype'])) {
159: case 'author':
160:
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:
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:
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: 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 && $item['name'] != '') {
224:
225: return $pos;
226: }
227: }
228:
229:
230: return count($arrMetatags);
231: }
232:
233: ?>