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

Classes

  • LinkcheckerRepair

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 tests 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: // Checks all links without front_content.php
 19: function checkLinks() {
 20:     global $auth, $cfgClient, $client, $cfg, $cronjob, $db, $aErrors, $lang, $langart, $whitelist;
 21:     global $aSearchIDInfosArt, $aSearchIDInfosCat, $aSearchIDInfosCatArt, $aSearchIDInfosNonID;
 22: 
 23:     $sSearch = '';
 24: 
 25:     if (count($aSearchIDInfosArt) > 0) { // Checks idarts
 26: 
 27:         for ($i = 0; $i < count($aSearchIDInfosArt); $i++) {
 28: 
 29:             if ($i == 0) {
 30:                 $sSearch = cSecurity::toInteger($aSearchIDInfosArt[$i]['id']);
 31:             } else {
 32:                 $sSearch .= ", " . cSecurity::toInteger($aSearchIDInfosArt[$i]['id']);
 33:             }
 34:         }
 35: 
 36:         // Check articles
 37:         $aFind = array();
 38:         $sql = "SELECT idart, online FROM " . $cfg['tab']['art_lang'] . " WHERE idart IN (" . $sSearch . ")";
 39:         $db->query($sql);
 40: 
 41:         while ($db->nextRecord()) {
 42:             $aFind[$db->f("idart")] = array(
 43:                 "online" => $db->f("online")
 44:             );
 45:         }
 46: 
 47:         for ($i = 0; $i < count($aSearchIDInfosArt); $i++) {
 48: 
 49:             if (isset($aFind[$aSearchIDInfosArt[$i]['id']]) && $aFind[$aSearchIDInfosArt[$i]['id']]['online'] == 0) {
 50:                 $aErrors['art'][] = array_merge($aSearchIDInfosArt[$i], array(
 51:                     "error_type" => "offline"
 52:                 ));
 53:             } elseif (!isset($aFind[$aSearchIDInfosArt[$i]['id']])) {
 54:                 $aErrors['art'][] = array_merge($aSearchIDInfosArt[$i], array(
 55:                     "error_type" => "unknown"
 56:                 ));
 57:             }
 58:         }
 59:     }
 60: 
 61:     if (count($aSearchIDInfosCat) > 0) { // Checks idcats
 62: 
 63:         for ($i = 0; $i < count($aSearchIDInfosCat); $i++) {
 64: 
 65:             if ($i == 0) {
 66:                 $sSearch = $aSearchIDInfosCat[$i]['id'];
 67:             } else {
 68:                 $sSearch .= ", " . $aSearchIDInfosCat[$i]['id'];
 69:             }
 70:         }
 71: 
 72:         // Check categorys
 73:         $aFind = array();
 74:         $sql = "SELECT idcat, startidartlang, visible FROM " . $cfg['tab']['cat_lang'] . " WHERE idcat IN (" . $sSearch . ") AND idlang = '" . cSecurity::toInteger($lang) . "'";
 75:         $db->query($sql);
 76: 
 77:         while ($db->nextRecord()) {
 78:             $aFind[$db->f("idcat")] = array(
 79:                 "online" => $db->f("visible"),
 80:                 "startidart" => $db->f("startidartlang")
 81:             );
 82:         }
 83: 
 84:         for ($i = 0; $i < count($aSearchIDInfosCat); $i++) {
 85: 
 86:             if (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] == 0) {
 87:                 $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array(
 88:                     "error_type" => "startart"
 89:                 ));
 90:             } elseif (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['online'] == 0) {
 91:                 $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array(
 92:                     "error_type" => "offline"
 93:                 ));
 94:             } elseif (!is_array($aFind[$aSearchIDInfosCat[$i]['id']])) {
 95:                 $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array(
 96:                     "error_type" => "unknown"
 97:                 ));
 98:             }
 99: 
100:             if (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] != 0) {
101: 
102:                 $sql = "SELECT idart FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang = '" . $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] . "' AND online = '1'";
103:                 $db->query($sql);
104: 
105:                 if ($db->numRows() == 0) {
106:                     $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array(
107:                         "error_type" => "startart"
108:                     ));
109:                 }
110:             }
111:         }
112:     }
113: 
114:     if (count($aSearchIDInfosCatArt) > 0) { // Checks idcatarts
115: 
116:         for ($i = 0; $i < count($aSearchIDInfosCatArt); $i++) {
117: 
118:             if ($i == 0) {
119:                 $sSearch = cSecurity::toInteger($aSearchIDInfosCatArt[$i]['id']);
120:             } else {
121:                 $sSearch .= ", " . cSecurity::toInteger($aSearchIDInfosCatArt[$i]['id']);
122:             }
123:         }
124: 
125:         // Check articles
126:         $aFind = array();
127:         $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'] . " WHERE idcatart IN (" . $sSearch . ")";
128:         $db->query($sql);
129: 
130:         while ($db->nextRecord()) {
131:             $aFind[] = $db->f("idcatart");
132:         }
133: 
134:         for ($i = 0; $i < count($aSearchIDInfosCatArt); $i++) {
135: 
136:             if (!in_array($aSearchIDInfosCatArt[$i]['id'], $aFind)) {
137:                 $aErrors['art'][] = array_merge($aSearchIDInfosCatArt[$i], array(
138:                     "error_type" => "unknown"
139:                 ));
140:             }
141:         }
142:     }
143: 
144:     if (count($aSearchIDInfosNonID) != 0) { // Checks other links (e. g. http,
145:                                             // www, dfbs)
146: 
147:         // Select userrights (is the user admin or sysadmin?)
148:         $sql = "SELECT username FROM " . $cfg['tab']['user'] . " WHERE user_id='" . $db->escape($auth->auth['uid']) . "' AND perms LIKE '%admin%'";
149:         $db->query($sql);
150: 
151:         if ($db->numRows() > 0 || $cronjob == true) { // User is admin when he
152:                                                       // is or when he run the
153:                                                       // cronjob
154:             $iAdmin = true;
155:         }
156: 
157:         $frontendPath = cRegistry::getFrontendPath();
158:         $frontendURL = cRegistry::getFrontendUrl();
159: 
160:         for ($i = 0; $i < count($aSearchIDInfosNonID); $i++) {
161:             if (!filter_var($aSearchIDInfosNonID[$i]['url'], FILTER_VALIDATE_URL) && !url_is_image($aSearchIDInfosNonID[$i]['url'])) {
162:                 $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array(
163:                     "error_type" => "invalidurl"
164:                 ));
165:             } elseif (url_is_uri($aSearchIDInfosNonID[$i]['url'])) {
166:                 if (substr($aSearchIDInfosNonID[$i]['url'], 0, strlen($aSearchIDInfosNonID[$i]['url'])) == $frontendURL) {
167:                     $iPing = @cFileHandler::exists(str_replace($frontendURL, $frontendPath, $aSearchIDInfosNonID[$i]['url']));
168:                 } else {
169:                     $iPing = @fopen($aSearchIDInfosNonID[$i]['url'], 'r');
170:                 }
171: 
172:                 if (!$iPing) {
173: 
174:                     if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
175:                         $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array(
176:                             "error_type" => "unknown"
177:                         ));
178:                     } else {
179:                         $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array(
180:                             "error_type" => "unknown"
181:                         ));
182:                     }
183:                 }
184:             } elseif (substr($aSearchIDInfosNonID[$i]['url'], strlen($aSearchIDInfosNonID[$i]['url']) - 5, 5) == ".html") {
185: 
186:                 $iPing = @cFileHandler::exists($frontendURL . $aSearchIDInfosNonID[$i]['url']);
187: 
188:                 if (!$iPing) {
189:                     $aErrors['art'][] = array_merge($aSearchIDInfosNonID[$i], array(
190:                         "error_type" => "unknown"
191:                     ));
192:                 }
193:             } elseif (substr($aSearchIDInfosNonID[$i]['url'], 0, 20) == "dbfs.php?file=" . cApiDbfs::PROTOCOL_DBFS . "/") {
194: 
195:                 $sDBurl = substr($aSearchIDInfosNonID[$i]['url'], 20, strlen($aSearchIDInfosNonID[$i]['url']));
196: 
197:                 $iPos = strrpos($sDBurl, '/');
198:                 $sDirname = substr($sDBurl, 0, $iPos);
199:                 $sFilename = substr($sDBurl, $iPos + 1);
200: 
201:                 // Check dbfs
202:                 $sql = "SELECT iddbfs FROM " . $cfg['tab']['dbfs'] . " WHERE dirname IN('" . $sDirname . "', '" . conHtmlEntityDecode($sDirname) . "', '" . $sDirname . "') AND filename = '" . $sFilename . "'";
203:                 $db->query($sql);
204: 
205:                 if ($db->numRows() == 0) {
206:                     $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array(
207:                         "error_type" => "dbfs"
208:                     ));
209:                 }
210:             } else {
211: 
212:                 if (!cFileHandler::exists($frontendPath . $aSearchIDInfosNonID[$i]['url'])) {
213: 
214:                     if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
215:                         $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array(
216:                             "error_type" => "unknown"
217:                         ));
218:                     } else {
219:                         $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array(
220:                             "error_type" => "unknown"
221:                         ));
222:                     }
223:                 }
224:             }
225:         }
226:     }
227: 
228:     return $aErrors;
229: }
230: 
231: // Searchs front_content.php-links
232: function searchFrontContentLinks($sValue, $iArt, $sArt, $iCat, $sCat) {
233:     global $aSearchIDInfosArt, $aSearchIDInfosCat, $aSearchIDInfosCatArt, $aWhitelist;
234: 
235:     // detect urls with parameter idart
236:     $matches = array();
237:     if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idart=([0-9]*)/i', $sValue, $matches)) {
238:         for ($i = 0; $i < count($matches[0]); $i++) {
239:             if (!in_array($matches[0][$i], $aWhitelist)) {
240:                 $aSearchIDInfosArt[] = array(
241:                     "id" => $matches[1][$i],
242:                     "url" => $matches[0][$i],
243:                     "idart" => $iArt,
244:                     "nameart" => $sArt,
245:                     "idcat" => $iCat,
246:                     "namecat" => $sCat,
247:                     "urltype" => "intern"
248:                 );
249:             }
250:         }
251:     }
252: 
253:     // detect urls with parameter idcat
254:     $matches = array();
255:     if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idcat=([0-9]*)/i', $sValue, $matches)) {
256:         for ($i = 0; $i < count($matches[0]); $i++) {
257:             if (!in_array($matches[0][$i], $aWhitelist)) {
258:                 $aSearchIDInfosCat[] = array(
259:                     "id" => $matches[1][$i],
260:                     "url" => $matches[0][$i],
261:                     "idart" => $iArt,
262:                     "nameart" => $sArt,
263:                     "idcat" => $iCat,
264:                     "namecat" => $sCat,
265:                     "urltype" => "intern"
266:                 );
267:             }
268:         }
269:     }
270: 
271:     // detect urls with parameter idcatart
272:     $matches = array();
273:     if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idcatart=([0-9]*)/i', $sValue, $matches)) { // idcatart
274:         for ($i = 0; $i < count($matches[0]); $i++) {
275:             if (!in_array($matches[0][$i], $aWhitelist)) {
276:                 $aSearchIDInfosCatArt[] = array(
277:                     "id" => $matches[1][$i],
278:                     "url" => $matches[0][$i],
279:                     "idart" => $iArt,
280:                     "nameart" => $sArt,
281:                     "idcat" => $iCat,
282:                     "namecat" => $sCat,
283:                     "urltype" => "intern"
284:                 );
285:             }
286:         }
287:     }
288: }
289: 
290: // Searchs extern and intern links
291: function searchLinks($sValue, $iArt, $sArt, $iCat, $sCat, $iArtLang, $iLang, $sFromtype = "") {
292:     global $aUrl, $aSearchIDInfosNonID, $aWhitelist;
293: 
294:     // Extern URL
295:     if (preg_match_all('~(?:(?:action|data|href|src)=["\']((?:file|ftp|http|ww)[^\s]*)["\'])~i', $sValue, $aMatches) && $_GET['mode'] != 1) {
296: 
297:         for ($i = 0; $i < count($aMatches[1]); $i++) {
298: 
299:             if (!in_array($aMatches[1][$i], $aWhitelist)) {
300:                 $aSearchIDInfosNonID[] = array(
301:                     "url" => $aMatches[1][$i],
302:                     "idart" => $iArt,
303:                     "nameart" => $sArt,
304:                     "idcat" => $iCat,
305:                     "namecat" => $sCat,
306:                     "idartlang" => $iArtLang,
307:                     "lang" => $iLang,
308:                     "urltype" => "extern"
309:                 );
310:             }
311:         }
312:     }
313: 
314:     // Redirect
315:     if ($sFromtype == "Redirect" && (preg_match('!(' . preg_quote($aUrl['cms']) . '[^\s]*)!i', $sValue, $aMatches) || (preg_match('~(?:file|ftp|http|ww)[^\s]*~i', $sValue, $aMatches) && $_GET['mode'] != 1)) && (stripos($sValue, 'front_content.php') === false) && !in_array($aMatches[0], $aWhitelist)) {
316:         $aSearchIDInfosNonID[] = array(
317:             "url" => $aMatches[0],
318:             "idart" => $iArt,
319:             "nameart" => $sArt,
320:             "idcat" => $iCat,
321:             "namecat" => $sCat,
322:             "idartlang" => $iArtLang,
323:             "lang" => $iLang,
324:             "urltype" => "unknown",
325:             "redirect" => true
326:         );
327:     }
328: 
329:     // Intern URL
330:     if (preg_match_all('~(?:(?:action|data|href|src)=["\'])(?!file://)(?!ftp://)(?!http://)(?!https://)(?!ww)(?!mailto)(?!\#)(?!/\#)([^"\']+)(?:["\'])~i', $sValue, $aMatches) && $_GET['mode'] != 2) {
331: 
332:         for ($i = 0; $i < count($aMatches[1]); $i++) {
333: 
334:             if (strpos($aMatches[1][$i], "front_content.php") === false && !in_array($aMatches[1][$i], $aWhitelist)) {
335:                 $aSearchIDInfosNonID[] = array(
336:                     "url" => $aMatches[1][$i],
337:                     "idart" => $iArt,
338:                     "nameart" => $sArt,
339:                     "idcat" => $iCat,
340:                     "namecat" => $sCat,
341:                     "idartlang" => $iArtLang,
342:                     "lang" => $iLang,
343:                     "urltype" => "intern"
344:                 );
345:             }
346:         }
347:     }
348: }
349: ?>
CMS CONTENIDO 4.9.3 API documentation generated by ApiGen 2.8.0