1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: $plugin_name = "linkchecker";
18: $cfg = cRegistry::getConfig();
19:
20: if (!$cronjob) {
21:
22:
23: if (!$perm->have_perm_area_action($plugin_name, "linkchecker") && $cronjob != true) {
24: cRegistry::addErrorMessage(i18n("No permissions"));
25: $page = new cGuiPage('generic_page');
26: $page->abortRendering();
27: $page->render();
28: exit();
29: }
30:
31: if (cRegistry::getClientId() == 0 && $cronjob != true) {
32: $notification->displayNotification("error", i18n("No Client selected"));
33: exit();
34: }
35: }
36:
37:
38: if (empty($_GET['mode'])) {
39: $_GET['mode'] = 3;
40: }
41:
42:
43: if (empty($_GET['action'])) {
44: $_GET['action'] = 'linkchecker';
45: $action = "linkchecker";
46: }
47:
48:
49: $aCats = [];
50: $aSearchIDInfosArt = [];
51: $aSearchIDInfosCat = [];
52: $aSearchIDInfosCatArt = [];
53: $aSearchIDInfosNonID = [];
54:
55:
56: $aUrl = array(
57: 'cms' => cRegistry::getFrontendUrl(),
58: 'contenido' => cRegistry::getBackendUrl()
59: );
60:
61:
62: if ($cronjob != true) {
63: $tpl->set('s', 'MODE', cSecurity::toInteger($_GET['mode']));
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: 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: 137: 138: 139:
140: function url_is_image($sUrl) {
141: if (cString::getPartOfString($sUrl, -3, 3) == "gif" || cString::getPartOfString($sUrl, -3, 3) == "jpg" || cString::getPartOfString($sUrl, -4, 4) == "jpeg" || cString::getPartOfString($sUrl, -3, 3) == "png" || cString::getPartOfString($sUrl, -3, 3) == "tif" || cString::getPartOfString($sUrl, -3, 3) == "psd" || cString::getPartOfString($sUrl, -3, 3) == "bmp") {
142: return true;
143: } else {
144: return false;
145: }
146: }
147:
148: 149: 150: 151: 152:
153: function url_is_uri($sUrl) {
154: if (cString::getPartOfString($sUrl, 0, 4) == "file" || cString::getPartOfString($sUrl, 0, 3) == "ftp" || cString::getPartOfString($sUrl, 0, 4) == "http" || cString::getPartOfString($sUrl, 0, 2) == "ww") {
155: return true;
156: } else {
157: return false;
158: }
159: }
160:
161:
162: if (!empty($_GET['idcontent']) && !empty($_GET['idartlang']) && !empty($_GET['oldlink']) && !empty($_GET['repairedlink'])) {
163:
164: if ($_GET['redirect'] == true) {
165: $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET redirect_url = '" . $db->escape(base64_decode($_GET['repairedlink'])) . "' WHERE idartlang = '" . cSecurity::toInteger($_GET['idartlang']) . "'";
166: $db->query($sql);
167: } else {
168:
169:
170: $sql = "SELECT value FROM " . $cfg['tab']['content'] . " WHERE idcontent = '" . cSecurity::toInteger($_GET['idcontent']) . "' AND idartlang = '" . cSecurity::toInteger($_GET['idartlang']) . "'";
171: $db->query($sql);
172: $db->next_record();
173:
174:
175: $newvalue = str_replace($db->escape(base64_decode($_GET['oldlink'])), $db->escape(base64_decode($_GET['repairedlink'])), $db->f("value"));
176:
177:
178: $sql = "UPDATE " . $cfg['tab']['content'] . " SET value = '" . $newvalue . "' WHERE idcontent = '" . cSecurity::toInteger($_GET['idcontent']) . "' AND idartlang = '" . cSecurity::toInteger($_GET['idartlang']) . "'";
179: $db->query($sql);
180: }
181:
182:
183: $oCache->remove($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
184: }
185:
186:
187: if (!empty($_GET['whitelist'])) {
188: $sql = "REPLACE INTO " . $cfg['tab']['whitelist'] . " VALUES ('" . $db->escape(base64_decode($_GET['whitelist'])) . "', '" . time() . "')";
189: $db->query($sql);
190:
191: $oCache->remove($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
192: }
193:
194:
195: $sql = "SELECT url FROM " . $cfg['tab']['whitelist'] . " WHERE lastview < " . (time() + $iWhitelistTimeout) . "
196: AND lastview > " . (time() - $iWhitelistTimeout);
197: $db->query($sql);
198:
199: $aWhitelist = array();
200: while ($db->nextRecord()) {
201: $aWhitelist[] = $db->f("url");
202: }
203:
204:
205:
206: $sCache_errors = $oCache->get($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
207:
208:
209: if ($sCache_errors && $_GET['live'] != 1) {
210: $aErrors = unserialize($sCache_errors);
211: } else {
212:
213:
214: $searchLinks = new cLinkcheckerSearchLinks();
215:
216:
217:
218: $db->query("SELECT idcat FROM " . $cfg['tab']['cat'] . " GROUP BY idcat");
219: while ($db->nextRecord()) {
220: if ($cronjob || cLinkcheckerCategoryHelper::checkPermission($db->f("idcat"), $db2)) {
221: $aCats[] = cSecurity::toInteger($db->f("idcat"));
222: }
223: }
224:
225:
226: if (count($aCats) == 0) {
227: $aCats_Sql = "";
228: } else {
229: $aCats_Sql = "AND cat.idcat IN (0, " . join(", ", $aCats) . ")";
230: }
231:
232:
233: $languageId = cRegistry::getLanguageId();
234:
235:
236: $sql = "SELECT art.title, art.idartlang, art.idlang, cat.idart, cat.idcat, catName.name AS namecat, con.idcontent, con.value FROM " . $cfg['tab']['cat_art'] . " cat
237: LEFT JOIN " . $cfg['tab']['art_lang'] . " art ON (art.idart = cat.idart)
238: LEFT JOIN " . $cfg['tab']['cat_lang'] . " catName ON (catName.idcat = cat.idcat)
239: LEFT JOIN " . $cfg['tab']['content'] . " con ON (con.idartlang = art.idartlang)
240: WHERE (
241: con.value LIKE '%action%'
242: OR con.value LIKE '%data%'
243: OR con.value LIKE '%href%'
244: OR con.value LIKE '%src%'
245: )
246: " . $aCats_Sql . "
247: AND cat.idcat != '0'
248: AND art.idlang = '" . cSecurity::toInteger($languageId) . "'
249: AND catName.idlang = '" . cSecurity::toInteger($languageId) . "'
250: AND art.online = '1'
251: AND art.redirect = '0'";
252: $db->query($sql);
253:
254: while ($db->nextRecord()) {
255:
256: $value = $db->f("value");
257:
258:
259: $aSearchIDInfosNonID = $searchLinks->search($value, $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"), $db->f("idlang"), $db->f("idartlang"), $db->f("idcontent"));
260:
261:
262: if ($_GET['mode'] != 2) {
263: cLinkcheckerTester::searchFrontContentLinks($value, $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"));
264: }
265: }
266:
267:
268: $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
269: LEFT JOIN " . $cfg['tab']['art_lang'] . " art ON (art.idart = cat.idart)
270: LEFT JOIN " . $cfg['tab']['cat_lang'] . " catName ON (catName.idcat = cat.idcat)
271: WHERE art.online = '1'
272: AND art.redirect = '1'
273: " . $aCats_Sql . "
274: AND art.idlang = '" . cSecurity::toInteger($languageId) . "'
275: AND catName.idlang = '" . cSecurity::toInteger($languageId) . "'
276: AND cat.idcat != '0'";
277: $db->query($sql);
278:
279:
280: $searchLinks->setMode("redirect");
281:
282: while ($db->nextRecord()) {
283:
284:
285: $aSearchIDInfosNonID = $searchLinks->search($db->f("redirect_url"), $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"), $db->f("idlang"), $db->f("idartlang"));
286:
287:
288: if ($_GET['mode'] != 2) {
289: cLinkcheckerTester::searchFrontContentLinks($db->f("redirect_url"), $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"));
290: }
291: }
292:
293:
294: cLinkcheckerTester::checkLinks();
295: }
296:
297:
298:
299: if ($cronjob != true) {
300: $tpl->set('s', 'TITLE', i18n('Link analysis from ', $plugin_name) . strftime(i18n('%Y-%m-%d', $plugin_name), time()));
301: }
302:
303:
304: if (empty($aErrors) && $cronjob != true) {
305:
306: $oCache->remove($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
307:
308: $tpl->set('s', 'NO_ERRORS', i18n("<strong>No errors</strong> were found.", $plugin_name));
309: $tpl->generate($cfg['templates']['linkchecker_noerrors']);
310: } elseif (!empty($aErrors) && $cronjob != true) {
311:
312: $tpl->set('s', 'ERRORS_HEADLINE', i18n("Total checked links", $plugin_name));
313: $tpl->set('s', 'ERRORS_HEADLINE_ARTID', i18n("idart", $plugin_name));
314: $tpl->set('s', 'ERRORS_HEADLINE_ARTICLE', i18n("Article", $plugin_name));
315: $tpl->set('s', 'ERRORS_HEADLINE_CATID', i18n("idcat", $plugin_name));
316: $tpl->set('s', 'ERRORS_HEADLINE_CATNAME', i18n("Category", $plugin_name));
317: $tpl->set('s', 'ERRORS_HEADLINE_DESCRIPTION', i18n("Description", $plugin_name));
318: $tpl->set('s', 'ERRORS_HEADLINE_REPAIRED', i18n("Repair", $plugin_name));
319: $tpl->set('s', 'ERRORS_HEADLINE_LINK', i18n("Linkerror", $plugin_name));
320: $tpl->set('s', 'ERRORS_HEADLINE_LINKS_ARTICLES', i18n("Links to articles", $plugin_name));
321: $tpl->set('s', 'ERRORS_HEADLINE_LINKS_CATEGORYS', i18n("Links to categories", $plugin_name));
322: $tpl->set('s', 'ERRORS_HEADLINE_LINKS_DOCIMAGES', i18n("Links to documents and images", $plugin_name));
323: $tpl->set('s', 'ERRORS_HEADLINE_OTHERS', i18n("Links to extern sites and not defined links", $plugin_name));
324: $tpl->set('s', 'ERRORS_HEADLINE_WHITELIST', "Whitelist");
325: $tpl->set('s', 'ERRORS_HELP_ERRORS', i18n("Wrong links", $plugin_name));
326:
327:
328: $aError_output = array(
329: 'art' => '',
330: 'cat' => '',
331: 'docimages' => '',
332: 'others' => ''
333: );
334:
335:
336: $repair = new cLinkcheckerRepair();
337:
338: foreach ($aErrors as $sKey => $aRow) {
339:
340: $aRow = linksort($aRow);
341:
342: for ($i = 0; $i < count($aRow); $i++) {
343:
344: $tpl2 = new cTemplate();
345: $tpl2->reset();
346:
347:
348: $aRow[$i]['nameart'] = conHtmlentities($aRow[$i]['nameart']);
349: $aRow[$i]['namecat'] = conHtmlentities($aRow[$i]['namecat']);
350:
351:
352: $tpl2->set('s', 'ERRORS_ARTID', cSecurity::toInteger($aRow[$i]['idart']));
353: $tpl2->set('s', 'ERRORS_ARTICLE', cSecurity::escapeString($aRow[$i]['nameart']));
354: $tpl2->set('s', 'ERRORS_ARTICLE_SHORT', cString::getPartOfString($aRow[$i]['nameart'], 0, 20) . ((cString::getStringLength($aRow[$i]['nameart']) > 20) ? ' ...' : ''));
355: $tpl2->set('s', 'ERRORS_CATID', cSecurity::toInteger($aRow[$i]['idcat']));
356: $tpl2->set('s', 'ERRORS_LANGARTID', cSecurity::toInteger($aRow[$i]['idartlang']));
357: $tpl2->set('s', 'ERRORS_LINK', cSecurity::escapeString($aRow[$i]['url']));
358: $tpl2->set('s', 'ERRORS_LINK_ENCODE', base64_encode($aRow[$i]['url']));
359: $tpl2->set('s', 'ERRORS_LINK_SHORT', cString::getPartOfString($aRow[$i]['url'], 0, 45) . ((cString::getStringLength($aRow[$i]['url']) > 45) ? ' ...' : ''));
360: $tpl2->set('s', 'ERRORS_CATNAME', cSecurity::escapeString($aRow[$i]['namecat']));
361: $tpl2->set('s', 'ERRORS_CATNAME_SHORT', cString::getPartOfString($aRow[$i]['namecat'], 0, 20) . ((cString::getStringLength($aRow[$i]['namecat']) > 20) ? ' ...' : ''));
362: $tpl2->set('s', 'MODE', cSecurity::toInteger($_GET['mode']));
363: $tpl2->set('s', 'URL_FRONTEND', $aUrl['cms']);
364:
365: if ($aRow[$i]['error_type'] == "unknown") {
366: $tpl2->set('s', 'ERRORS_ERROR_TYPE', i18n("Unknown", $plugin_name));
367: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("Unknown: articles, documents etc. do not exist.", $plugin_name));
368: } elseif ($aRow[$i]['error_type'] == "offline") {
369: $tpl2->set('s', 'ERRORS_ERROR_TYPE', i18n("Offline", $plugin_name));
370: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("Offline: article or category is offline.", $plugin_name));
371: } elseif ($aRow[$i]['error_type'] == "startart") {
372: $tpl2->set('s', 'ERRORS_ERROR_TYPE', i18n("Offline startarticle", $plugin_name));
373: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("Offline: article or category is offline.", $plugin_name));
374: } elseif ($aRow[$i]['error_type'] == "dbfs") {
375: $tpl2->set('s', 'ERRORS_ERROR_TYPE', i18n("Filemanager", $plugin_name));
376: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("dbfs: no matches found in the dbfs database.", $plugin_name));
377: } elseif ($aRow[$i]['error_type'] == "invalidurl") {
378: $tpl2->set('s', 'ERRORS_ERROR_TYPE', i18n("Invalid url", $plugin_name));
379: $tpl2->set('s', 'ERRORS_ERROR_TYPE_HELP', i18n("Invalid url, i. e. syntax error.", $plugin_name));
380:
381:
382: $repaired_link = $repair->checkLink($aRow[$i]['url']);
383: }
384:
385:
386: if ($aRow[$i]['error_type'] != "invalidurl") {
387:
388: $tpl2->set('s', 'ERRORS_REPAIRED_LINK', '-');
389: } elseif ($repaired_link == false) {
390:
391: $tpl2->set('s', 'ERRORS_REPAIRED_LINK', i18n("No repaired link", $plugin_name));
392: } else {
393:
394:
395:
396: $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);
397:
398: $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'] . '&idcontent=' . $aRow[$i]['idcontent'] . '&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>');
399: }
400:
401: if ($sKey != "cat") {
402: $aError_output[$sKey] .= $tpl2->generate($cfg['templates']['linkchecker_test_errors'], 1);
403: } else {
404:
405: $aError_output[$sKey] .= $tpl2->generate($cfg['templates']['linkchecker_test_errors_cat'], 1);
406: }
407: }
408: }
409:
410:
411: if ($iCounter = $oCache->get($aCacheName['errorscount'], cSecurity::toInteger($_GET['mode']))) {
412:
413: $iErrorsCountChecked = $iCounter;
414: } else {
415:
416: $iErrorsCountChecked = count($aSearchIDInfosArt) + count($aSearchIDInfosCat) + count($aSearchIDInfosCatArt) + count($aSearchIDInfosNonID);
417: }
418:
419:
420: foreach ($aErrors as $sKey => $aRow) {
421: $iErrorsCounted += count($aErrors[$sKey]);
422: }
423:
424: $tpl->set('s', 'ERRORS_COUNT_CHECKED', $iErrorsCountChecked);
425: $tpl->set('s', 'ERRORS_COUNT_ERRORS', $iErrorsCounted);
426: $tpl->set('s', 'ERRORS_COUNT_ERRORS_PERCENT', round(($iErrorsCounted * 100) / $iErrorsCountChecked, 2));
427:
428:
429: foreach ($aError_output as $sKey => $sValue) {
430:
431: if (empty($aError_output[$sKey])) {
432: $tpl2->set('s', 'ERRORS_NOTHING', i18n("No errors for this type.", $plugin_name));
433: $aError_output[$sKey] = $tpl2->generate($cfg['templates']['linkchecker_test_nothing'], 1);
434: }
435:
436: $tpl->set('s', 'ERRORS_SHOW_' . cString::toUpperCase($sKey), $aError_output[$sKey]);
437:
438: if (count($aErrors[$sKey]) > 0) {
439: $tpl->set('s', 'ERRORS_COUNT_ERRORS_' . cString::toUpperCase($sKey), '<span class="settingWrong">' . count($aErrors[$sKey]) . '</span>');
440: } else {
441: $tpl->set('s', 'ERRORS_COUNT_ERRORS_' . cString::toUpperCase($sKey), count($aErrors[$key]));
442: }
443: }
444:
445: $tpl->generate($cfg['templates']['linkchecker_test']);
446:
447:
448:
449: $oCache->remove($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
450:
451:
452: $oCache->save(serialize($aErrors), $aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
453: $oCache->save($iErrorsCountChecked, $aCacheName['errorscount'], cSecurity::toInteger($_GET['mode']));
454: }
455:
456:
457: if ($cronjob != true) {
458: $backend->log(0, 0, cRegistry::getClientId(), cRegistry::getLanguageId(), $action);
459: }
460:
461: ?>