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