1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: $plugin_name = "linkchecker";
19: $cfg = cRegistry::getConfig();
20:
21: if (!$cronjob) {
22: if (!$perm->have_perm_area_action($plugin_name, $plugin_name) && $cronjob != true) {
23: exit();
24: }
25:
26: if (cRegistry::getClientId() == 0 && $cronjob != true) {
27: $notification->displayNotification("error", i18n("No Client selected"));
28: exit();
29: }
30: }
31:
32:
33: if (empty($_GET['mode'])) {
34: $_GET['mode'] = 3;
35: }
36:
37:
38: if (empty($_GET['action'])) {
39: $_GET['action'] = 'linkchecker';
40: $action = "linkchecker";
41: }
42:
43: plugin_include('linkchecker', 'includes/config.plugin.php');
44: plugin_include('linkchecker', 'includes/include.checkperms.php');
45: plugin_include('linkchecker', 'includes/include.linkchecker_tests.php');
46:
47:
48: $aCats = array();
49: $aSearchIDInfosArt = array();
50: $aSearchIDInfosCatArt = array();
51: $aSearchIDInfosNonID = array();
52:
53:
54: $aUrl = array(
55: 'cms' => cRegistry::getFrontendUrl(),
56: 'contenido' => cRegistry::getBackendUrl()
57: );
58:
59:
60: if ($cronjob != true) {
61: $tpl->set('s', 'URL_BACKEND', $aUrl['contenido']);
62: $tpl->set('s', 'MODE', cSecurity::toInteger($_GET['mode']));
63: $tpl->set('s', 'SID', $sess->id);
64: }
65:
66:
67: if (!$cronjob) {
68: $sLink = $sess->url("main.php?area=linkchecker&frame=4&action=linkchecker") . '&mode=';
69:
70:
71: $tpl->set('s', 'INTERNS_HREF', $sLink . '1');
72: $tpl->set('s', 'INTERNS_LABEL', i18n("Interns", $plugin_name));
73: $tpl->set('s', 'EXTERNS_HREF', $sLink . '2');
74: $tpl->set('s', 'EXTERNS_LABEL', i18n("Externs", $plugin_name));
75: $tpl->set('s', 'INTERNS_EXTERNS_HREF', $sLink . '3');
76: $tpl->set('s', 'INTERNS_EXTERNS_LABEL', i18n("Intern/extern Links", $plugin_name));
77:
78:
79: $tpl->set('s', 'UPDATE_HREF', $sLink . cSecurity::toInteger($_GET['mode']) . '&live=1');
80: }
81:
82:
83: $aCacheName = array(
84: 'errors' => $sess->id,
85: 'errorscount' => $aCacheName['errors'] . "ErrorsCountChecked"
86: );
87: $oCache = new cFileCache(array(
88: 'cacheDir' => $cfgClient[$client]['cache']['path'],
89: 'lifeTime' => $iCacheLifeTime
90: ));
91:
92: 93: 94:
95:
96:
97: function linksort($sErrors) {
98: if ($_GET['sort'] == "nameart") {
99:
100: foreach ($sErrors as $key => $aRow) {
101: $aNameart[$key] = $aRow['nameart'];
102: }
103:
104: array_multisort($sErrors, SORT_ASC, SORT_STRING, $aNameart);
105: } elseif ($_GET['sort'] == "namecat") {
106:
107: foreach ($sErrors as $key => $aRow) {
108: $aNamecat[$key] = $aRow['namecat'];
109: }
110:
111: array_multisort($sErrors, SORT_ASC, SORT_STRING, $aNamecat);
112: } elseif ($_GET['sort'] == "wronglink") {
113:
114: foreach ($sErrors as $key => $aRow) {
115: $aWronglink[$key] = $aRow['url'];
116: }
117:
118: array_multisort($sErrors, SORT_ASC, SORT_STRING, $aWronglink);
119: } elseif ($_GET['sort'] == "error_type") {
120:
121: foreach ($sErrors as $key => $aRow) {
122: $aError_type[$key] = $aRow['error_type'];
123: }
124:
125: array_multisort($sErrors, SORT_ASC, SORT_STRING, $aError_type);
126: }
127:
128: return $sErrors;
129: }
130:
131:
132: function url_is_image($sUrl) {
133: if (substr($sUrl, -3, 3) == "gif" || substr($sUrl, -3, 3) == "jpg" || substr($sUrl, -4, 4) == "jpeg" || substr($sUrl, -3, 3) == "png" || substr($sUrl, -3, 3) == "tif" || substr($sUrl, -3, 3) == "psd" || substr($sUrl, -3, 3) == "bmp") {
134: return true;
135: } else {
136: return false;
137: }
138: }
139:
140:
141: function url_is_uri($sUrl) {
142: if (substr($sUrl, 0, 4) == "file" || substr($sUrl, 0, 3) == "ftp" || substr($sUrl, 0, 4) == "http" || substr($sUrl, 0, 2) == "ww") {
143: return true;
144: } else {
145: return false;
146: }
147: }
148:
149:
150: if (!empty($_GET['whitelist'])) {
151:
152: $sql = "REPLACE INTO " . $cfg['tab']['whitelist'] . " VALUES ('" . $db->escape(base64_decode($_GET['whitelist'])) . "', '" . time() . "')";
153: $db->query($sql);
154:
155: $oCache->remove($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
156: }
157:
158:
159: $sql = "SELECT url FROM " . $cfg['tab']['whitelist'] . " WHERE lastview < " . (time() + $iWhitelistTimeout) . "
160: AND lastview > " . (time() - $iWhitelistTimeout);
161: $db->query($sql);
162:
163: $aWhitelist = array();
164: while ($db->nextRecord()) {
165: $aWhitelist[] = $db->f("url");
166: }
167:
168:
169:
170: $sCache_errors = $oCache->get($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
171:
172:
173: if ($sCache_errors && $_GET['live'] != 1) {
174: $aErrors = unserialize($sCache_errors);
175: } else {
176:
177:
178: $sql = "SELECT idcat FROM " . $cfg['tab']['cat'] . " GROUP BY idcat";
179: $db->query($sql);
180:
181: while ($db->nextRecord()) {
182:
183: if ($cronjob != true) {
184: $iCheck = cCatPerm($db->f("idcat"), $db2);
185:
186: if ($iCheck == true) {
187: $aCats[] = cSecurity::toInteger($db->f("idcat"));
188: }
189: } else {
190: $aCats[] = cSecurity::toInteger($db->f("idcat"));
191: }
192: }
193:
194:
195: if (count($aCats) == 0) {
196: $aCats_Sql = "";
197: } else {
198: $aCats_Sql = "AND cat.idcat IN (0, " . join(", ", $aCats) . ")";
199: }
200:
201:
202: if ($langart != 0) {
203: $sLang_Sql = "AND art.idlang = '" . cSecurity::toInteger($langart) . "' AND catName.idlang = '" . cSecurity::toInteger($langart) . "'";
204: } elseif (!isset($langart)) {
205: $sLang_Sql = "AND art.idlang = '" . cSecurity::toInteger($lang) . "' AND catName.idlang = '" . cSecurity::toInteger($lang) . "'";
206: }
207:
208:
209: $sql = "SELECT art.title, art.idlang, cat.idart, cat.idcat, catName.name AS namecat, con.value FROM " . $cfg['tab']['cat_art'] . " cat
210: LEFT JOIN " . $cfg['tab']['art_lang'] . " art ON (art.idart = cat.idart)
211: LEFT JOIN " . $cfg['tab']['cat_lang'] . " catName ON (catName.idcat = cat.idcat)
212: LEFT JOIN " . $cfg['tab']['content'] . " con ON (con.idartlang = art.idartlang)
213: WHERE (con.value LIKE '%action%' OR con.value LIKE '%data%' OR con.value LIKE '%href%' OR con.value LIKE '%src%')
214: " . $aCats_Sql . " AND cat.idcat != '0' " . $sLang_where . "
215: AND art.online = '1' AND art.redirect = '0'";
216: $db->query($sql);
217:
218: while ($db->nextRecord()) {
219:
220:
221: $value = $db->f("value");
222:
223:
224: searchLinks($value, $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"), $db->f("idlang"));
225:
226:
227: if ($_GET['mode'] != 2) {
228: searchFrontContentLinks($value, $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"));
229: }
230: }
231:
232:
233: $sql = "SELECT art.title, art.redirect_url, art.idlang, cat.idart, cat.idcat, catName.name AS namecat FROM " . $cfg['tab']['cat_art'] . " cat
234: LEFT JOIN " . $cfg['tab']['art_lang'] . " art ON (art.idart = cat.idart)
235: LEFT JOIN " . $cfg['tab']['cat_lang'] . " catName ON (catName.idcat = cat.idcat)
236: WHERE art.online = '1' AND art.redirect = '1' " . $aCats_Sql . " AND cat.idcat != '0' " . $sLang_Sql;
237: $db->query($sql);
238:
239: while ($db->nextRecord()) {
240:
241:
242: searchLinks($db->f("redirect_url"), $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"), $db->f("idlang"), "Redirect");
243:
244:
245: if ($_GET['mode'] != 2) {
246: searchFrontContentLinks($db->f("redirect_url"), $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"));
247: }
248: }
249:
250:
251: checkLinks();
252: }
253:
254:
255:
256: if ($cronjob != true) {
257: $tpl->set('s', 'TITLE', i18n('Link analysis from ', $plugin_name) . strftime(i18n('%Y-%m-%d', $plugin_name), time()));
258: }
259:
260:
261: if (empty($aErrors) && $cronjob != true) {
262:
263:
264: $oCache->remove($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
265:
266: $tpl->set('s', 'NO_ERRORS', i18n("<strong>No errors</strong> were found.", $plugin_name));
267: $tpl->generate($cfg['templates']['linkchecker_noerrors']);
268: } elseif (!empty($aErrors) && $cronjob != true) {
269:
270: $tpl->set('s', 'ERRORS_HEADLINE', i18n("Total checked links", $plugin_name));
271: $tpl->set('s', 'ERRORS_HEADLINE_ARTID', i18n("idart", $plugin_name));
272: $tpl->set('s', 'ERRORS_HEADLINE_ARTICLE', i18n("Article", $plugin_name));
273: $tpl->set('s', 'ERRORS_HEADLINE_CATID', i18n("idcat", $plugin_name));
274: $tpl->set('s', 'ERRORS_HEADLINE_CATNAME', i18n("Category", $plugin_name));
275: $tpl->set('s', 'ERRORS_HEADLINE_DESCRIPTION', i18n("Description", $plugin_name));
276: $tpl->set('s', 'ERRORS_HEADLINE_LINK', i18n("Linkerror", $plugin_name));
277: $tpl->set('s', 'ERRORS_HEADLINE_LINKS_ARTICLES', i18n("Links to articles", $plugin_name));
278: $tpl->set('s', 'ERRORS_HEADLINE_LINKS_CATEGORYS', i18n("Links to categories", $plugin_name));
279: $tpl->set('s', 'ERRORS_HEADLINE_LINKS_DOCIMAGES', i18n("Links to documents and images", $plugin_name));
280: $tpl->set('s', 'ERRORS_HEADLINE_OTHERS', i18n("Links to extern sites and not defined links", $plugin_name));
281: $tpl->set('s', 'ERRORS_HEADLINE_WHITELIST', "Whitelist");
282: $tpl->set('s', 'ERRORS_HELP_ERRORS', i18n("Wrong links", $plugin_name));
283:
284:
285: $aError_output = array(
286: 'art' => '',
287: 'cat' => '',
288: 'docimages' => '',
289: 'others' => ''
290: );
291:
292: foreach ($aErrors as $sKey => $aRow) {
293:
294: $aRow = linksort($aRow);
295:
296: for ($i = 0; $i < count($aRow); $i++) {
297:
298: $tpl2 = new cTemplate();
299: $tpl2->reset();
300:
301:
302: $aRow[$i]['nameart'] = conHtmlentities($aRow[$i]['nameart']);
303: $aRow[$i]['namecat'] = conHtmlentities($aRow[$i]['namecat']);
304:
305:
306: $tpl2->set('s', 'ERRORS_ERROR_TYPE', $aRow[$i]['error_type']);
307: $tpl2->set('s', 'ERRORS_ARTID', $aRow[$i]['idart']);
308: $tpl2->set('s', 'ERRORS_ARTICLE', $aRow[$i]['nameart']);
309: $tpl2->set('s', 'ERRORS_ARTICLE_SHORT', substr($aRow[$i]['nameart'], 0, 20) . ((strlen($aRow[$i]['nameart']) > 20) ? ' ...' : ''));
310: $tpl2->set('s', 'ERRORS_CATID', $aRow[$i]['idcat']);
311: $tpl2->set('s', 'ERRORS_LINK', $aRow[$i]['url']);
312: $tpl2->set('s', 'ERRORS_LINK_ENCODE', base64_encode($aRow[$i]['url']));
313: $tpl2->set('s', 'ERRORS_LINK_SHORT', substr($aRow[$i]['url'], 0, 55) . ((strlen($aRow[$i]['url']) > 55) ? ' ...' : ''));
314: $tpl2->set('s', 'ERRORS_CATNAME', $aRow[$i]['namecat']);
315: $tpl2->set('s', 'ERRORS_CATNAME_SHORT', substr($aRow[$i]['namecat'], 0, 20) . ((strlen($aRow[$i]['namecat']) > 20) ? ' ...' : ''));
316: $tpl2->set('s', 'MODE', $_GET['mode']);
317: $tpl2->set('s', 'URL_BACKEND', $aUrl['contenido']);
318: $tpl2->set('s', 'URL_FRONTEND', $aUrl['cms']);
319: $tpl2->set('s', 'SID', $sess->id);
320:
321: if ($aRow[$i]['error_type'] == "unknown") {
322: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("Unknown: articles, documents etc. do not exist.", $plugin_name));
323: } elseif ($aRow[$i]['error_type'] == "offline") {
324: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("Offline: article or category is offline.", $plugin_name));
325: } elseif ($aRow[$i]['error_type'] == "startart") {
326: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("Offline: article or category is offline.", $plugin_name));
327: } elseif ($aRow[$i]['error_type'] == "dbfs") {
328: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("dbfs: no matches found in the dbfs database.", $plugin_name));
329: }
330:
331: if ($sKey != "cat") {
332: $aError_output[$sKey] .= $tpl2->generate($cfg['templates']['linkchecker_test_errors'], 1);
333: } else {
334: $aError_output[$sKey] .= $tpl2->generate($cfg['templates']['linkchecker_test_errors_cat'], 1);
335:
336:
337:
338: }
339: }
340: }
341:
342:
343: if ($iCounter = $oCache->get($aCacheName['errorscount'], cSecurity::toInteger($_GET['mode']))) {
344:
345: $iErrorsCountChecked = $iCounter;
346: } else {
347: $iErrorsCountChecked = count($aSearchIDInfosArt) + count($aSearchIDInfosCat) + count($aSearchIDInfosCatArt) + count($aSearchIDInfosNonID);
348: }
349:
350:
351: foreach ($aErrors as $sKey => $aRow) {
352: $iErrorsCounted += count($aErrors[$sKey]);
353: }
354:
355: $tpl->set('s', 'ERRORS_COUNT_CHECKED', $iErrorsCountChecked);
356: $tpl->set('s', 'ERRORS_COUNT_ERRORS', $iErrorsCounted);
357: $tpl->set('s', 'ERRORS_COUNT_ERRORS_PERCENT', round(($iErrorsCounted * 100) / $iErrorsCountChecked, 2));
358:
359:
360: foreach ($aError_output as $sKey => $sValue) {
361:
362: if (empty($aError_output[$sKey])) {
363: $tpl2->set('s', 'ERRORS_NOTHING', i18n("No errors for this type.", $plugin_name));
364: $aError_output[$sKey] = $tpl2->generate($cfg['templates']['linkchecker_test_nothing'], 1);
365: }
366:
367: $tpl->set('s', 'ERRORS_SHOW_' . strtoupper($sKey), $aError_output[$sKey]);
368:
369: if (count($aErrors[$sKey]) > 0) {
370: $tpl->set('s', 'ERRORS_COUNT_ERRORS_' . strtoupper($sKey), '<span class="settingWrong">' . count($aErrors[$sKey]) . '</span>');
371: } else {
372: $tpl->set('s', 'ERRORS_COUNT_ERRORS_' . strtoupper($sKey), count($aErrors[$key]));
373: }
374: }
375:
376: $tpl->generate($cfg['templates']['linkchecker_test']);
377:
378:
379:
380: $oCache->remove($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
381:
382:
383: $oCache->save(serialize($aErrors), $aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
384: $oCache->save($iErrorsCountChecked, $aCacheName['errorscount'], cSecurity::toInteger($_GET['mode']));
385: }
386:
387:
388: if ($cronjob != true) {
389: $backend->log(0, 0, cRegistry::getClientId(), cRegistry::getLanguageId(), $action);
390: }
391:
392: ?>