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