Overview

Packages

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