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