Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Functions

  • cCatPerm
  • checkLinks
  • getGroupIDs
  • linksort
  • searchFrontContentLinks
  • searchLinks
  • url_is_image
  • url_is_uri
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This is the main backend page for the linkchecker plugin.
  4:  *
  5:  * @package Plugin
  6:  * @subpackage Linkchecker
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Frederic Schneider
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 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: // If no mode defined, use mode three
 33: if (empty($_GET['mode'])) {
 34:     $_GET['mode'] = 3;
 35: }
 36: 
 37: // If no action definied
 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: // Initialization
 48: $aCats = array();
 49: $aSearchIDInfosArt = array();
 50: $aSearchIDInfosCatArt = array();
 51: $aSearchIDInfosNonID = array();
 52: 
 53: // Var initialization
 54: $aUrl = array(
 55:     'cms' => cRegistry::getFrontendUrl(),
 56:     'contenido' => cRegistry::getBackendUrl()
 57: );
 58: 
 59: // Template- and languagevars
 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: // Fill Subnav I
 67: if (!$cronjob) {
 68:     $sLink = $sess->url("main.php?area=linkchecker&frame=4&action=linkchecker") . '&mode=';
 69: 
 70:     // Fill Subnav II
 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:     // Fill Subnav III
 79:     $tpl->set('s', 'UPDATE_HREF', $sLink . cSecurity::toInteger($_GET['mode']) . '&live=1');
 80: }
 81: 
 82: // Cache options
 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:  * ******** Program code ********
 94:  */
 95: 
 96: // function linksort
 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: // function url_is_image
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: // function url_is_uri
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: /* Whitelist: Add */
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: /* Whitelist: Get */
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: /* Get all links */
169: // Cache errors
170: $sCache_errors = $oCache->get($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
171: 
172: // Search if cache doesn't exist or we're in live mode
173: if ($sCache_errors && $_GET['live'] != 1) {
174:     $aErrors = unserialize($sCache_errors);
175: } else { // If no cache exists
176: 
177:     // Select all categorys
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) { // Check userrights, if no cronjob
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:     // Build $aCats-Statement
195:     if (count($aCats) == 0) {
196:         $aCats_Sql = "";
197:     } else {
198:         $aCats_Sql = "AND cat.idcat IN (0, " . join(", ", $aCats) . ")";
199:     }
200: 
201:     // Use Sql-WHERE if lang is not zero
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:     // How many articles exist? [Text]
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:         // Text decode
221:         $value = $db->f("value");
222: 
223:         // Search the text
224:         searchLinks($value, $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"), $db->f("idlang"));
225: 
226:         // Search front_content.php-links
227:         if ($_GET['mode'] != 2) {
228:             searchFrontContentLinks($value, $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"));
229:         }
230:     }
231: 
232:     // How many articles exist? [Redirects]
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:         // Search links
242:         searchLinks($db->f("redirect_url"), $db->f("idart"), $db->f("title"), $db->f("idcat"), $db->f("namecat"), $db->f("idlang"), "Redirect");
243: 
244:         // Search front_content.php-links
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:     // Check the links
251:     checkLinks();
252: }
253: 
254: /* Analysis of the errors */
255: // Templateset
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: // If no errors found, say that
261: if (empty($aErrors) && $cronjob != true) {
262: 
263:     // Remove older cache
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:     // error_output initialization
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:             // html entities for artname and catname
302:             $aRow[$i]['nameart'] = conHtmlentities($aRow[$i]['nameart']);
303:             $aRow[$i]['namecat'] = conHtmlentities($aRow[$i]['namecat']);
304: 
305:             // set template variables
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); // special
335:                                                                                                                    // template
336:                                                                                                                    // for
337:                                                                                                                    // idcats
338:             }
339:         }
340:     }
341: 
342:     /* Counter */
343:     if ($iCounter = $oCache->get($aCacheName['errorscount'], cSecurity::toInteger($_GET['mode']))) { // Cache
344:                                                                                                      // exists?
345:         $iErrorsCountChecked = $iCounter;
346:     } else { // Count searched links: idarts + idcats + idcatarts + others
347:         $iErrorsCountChecked = count($aSearchIDInfosArt) + count($aSearchIDInfosCat) + count($aSearchIDInfosCatArt) + count($aSearchIDInfosNonID);
348:     }
349: 
350:     // Count errors
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:     /* Template output */
360:     foreach ($aError_output as $sKey => $sValue) {
361: 
362:         if (empty($aError_output[$sKey])) { // Errors for this type?
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:     /* Cache */
379:     // Remove older cache
380:     $oCache->remove($aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
381: 
382:     // Build new cache
383:     $oCache->save(serialize($aErrors), $aCacheName['errors'], cSecurity::toInteger($_GET['mode']));
384:     $oCache->save($iErrorsCountChecked, $aCacheName['errorscount'], cSecurity::toInteger($_GET['mode']));
385: }
386: 
387: // Log
388: if ($cronjob != true) {
389:     $backend->log(0, 0, cRegistry::getClientId(), cRegistry::getLanguageId(), $action);
390: }
391: 
392: ?>
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0