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 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='" . cSecurity::escapeDB($auth->auth['uid'], $db) . "' 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 (url_is_uri($aSearchIDInfosNonID[$i]['url'])) {
162:                 if (substr($aSearchIDInfosNonID[$i]['url'], 0, strlen($aSearchIDInfosNonID[$i]['url'])) == $frontendURL) {
163:                     $iPing = @cFileHandler::exists(str_replace($frontendURL, $frontendPath, $aSearchIDInfosNonID[$i]['url']));
164:                 } else {
165:                     $iPing = @fopen($aSearchIDInfosNonID[$i]['url'], 'r');
166:                 }
167: 
168:                 if (!$iPing) {
169: 
170:                     if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
171:                         $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array(
172:                                 "error_type" => "unknown"
173:                         ));
174:                     } else {
175:                         $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array(
176:                                 "error_type" => "unknown"
177:                         ));
178:                     }
179:                 }
180:             } elseif (substr($aSearchIDInfosNonID[$i]['url'], strlen($aSearchIDInfosNonID[$i]['url']) - 5, 5) == ".html") {
181: 
182:                 $iPing = @cFileHandler::exists($frontendURL . $aSearchIDInfosNonID[$i]['url']);
183: 
184:                 if (!$iPing) {
185:                     $aErrors['art'][] = array_merge($aSearchIDInfosNonID[$i], array(
186:                             "error_type" => "unknown"
187:                     ));
188:                 }
189:             } elseif (substr($aSearchIDInfosNonID[$i]['url'], 0, 20) == "dbfs.php?file=dbfs:/") {
190: 
191:                 $sDBurl = substr($aSearchIDInfosNonID[$i]['url'], 20, strlen($aSearchIDInfosNonID[$i]['url']));
192: 
193:                 $iPos = strrpos($sDBurl, '/');
194:                 $sDirname = substr($sDBurl, 0, $iPos);
195:                 $sFilename = substr($sDBurl, $iPos + 1);
196: 
197:                 // Check dbfs
198:                 $sql = "SELECT iddbfs FROM " . $cfg['tab']['dbfs'] . " WHERE dirname IN('" . $sDirname . "', '" . conHtmlEntityDecode($sDirname) . "', '" . $sDirname . "') AND filename = '" . $sFilename . "'";
199:                 $db->query($sql);
200: 
201:                 if ($db->numRows() == 0) {
202:                     $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array(
203:                             "error_type" => "dbfs"
204:                     ));
205:                 }
206:             } else {
207: 
208:                 if (!cFileHandler::exists($frontendPath . $aSearchIDInfosNonID[$i]['url'])) {
209: 
210:                     if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
211:                         $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array(
212:                                 "error_type" => "unknown"
213:                         ));
214:                     } else {
215:                         $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array(
216:                                 "error_type" => "unknown"
217:                         ));
218:                     }
219:                 }
220:             }
221:         }
222:     }
223: 
224:     return $aErrors;
225: }
226: 
227: // Searchs front_content.php-links
228: function searchFrontContentLinks($sValue, $iArt, $sArt, $iCat, $sCat) {
229:     global $aSearchIDInfosArt, $aSearchIDInfosCat, $aSearchIDInfosCatArt, $aWhitelist;
230: 
231:     // detect urls with parameter idart
232:     $matches = array();
233:     if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idart=([0-9]*)/i', $sValue, $matches)) {
234:         for ($i = 0; $i < count($matches[0]); $i++) {
235:             if (!in_array($matches[0][$i], $aWhitelist)) {
236:                 $aSearchIDInfosArt[] = array(
237:                         "id" => $matches[1][$i],
238:                         "url" => $matches[0][$i],
239:                         "idart" => $iArt,
240:                         "nameart" => $sArt,
241:                         "idcat" => $iCat,
242:                         "namecat" => $sCat,
243:                         "urltype" => "intern"
244:                 );
245:             }
246:         }
247:     }
248: 
249:     // detect urls with parameter idcat
250:     $matches = array();
251:     if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idcat=([0-9]*)/i', $sValue, $matches)) {
252:         for ($i = 0; $i < count($matches[0]); $i++) {
253:             if (!in_array($matches[0][$i], $aWhitelist)) {
254:                 $aSearchIDInfosCat[] = array(
255:                         "id" => $matches[1][$i],
256:                         "url" => $matches[0][$i],
257:                         "idart" => $iArt,
258:                         "nameart" => $sArt,
259:                         "idcat" => $iCat,
260:                         "namecat" => $sCat,
261:                         "urltype" => "intern"
262:                 );
263:             }
264:         }
265:     }
266: 
267:     // detect urls with parameter idcatart
268:     $matches = array();
269:     if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idcatart=([0-9]*)/i', $sValue, $matches)) { // idcatart
270:         for ($i = 0; $i < count($matches[0]); $i++) {
271:             if (!in_array($matches[0][$i], $aWhitelist)) {
272:                 $aSearchIDInfosCatArt[] = array(
273:                         "id" => $matches[1][$i],
274:                         "url" => $matches[0][$i],
275:                         "idart" => $iArt,
276:                         "nameart" => $sArt,
277:                         "idcat" => $iCat,
278:                         "namecat" => $sCat,
279:                         "urltype" => "intern"
280:                 );
281:             }
282:         }
283:     }
284: }
285: 
286: // Searchs extern and intern links
287: function searchLinks($sValue, $iArt, $sArt, $iCat, $sCat, $iLang, $sFromtype = "") {
288:     global $aUrl, $aSearchIDInfosNonID, $aWhitelist;
289: 
290:     // Extern URL
291:     if (preg_match_all('~(?:(?:action|data|href|src)=["\']((?:file|ftp|http|ww)[^\s]*)["\'])~i', $sValue, $aMatches) && $_GET['mode'] != 1) {
292: 
293:         for ($i = 0; $i < count($aMatches[1]); $i++) {
294: 
295:             if (!in_array($aMatches[1][$i], $aWhitelist)) {
296:                 $aSearchIDInfosNonID[] = array(
297:                         "url" => $aMatches[1][$i],
298:                         "idart" => $iArt,
299:                         "nameart" => $sArt,
300:                         "idcat" => $iCat,
301:                         "namecat" => $sCat,
302:                         "lang" => $iLang,
303:                         "urltype" => "extern"
304:                 );
305:             }
306:         }
307:     }
308: 
309:     // Redirect
310:     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)) {
311:         $aSearchIDInfosNonID[] = array(
312:                 "url" => $aMatches[0],
313:                 "idart" => $iArt,
314:                 "nameart" => $sArt,
315:                 "idcat" => $iCat,
316:                 "namecat" => $sCat,
317:                 "lang" => $iLang,
318:                 "urltype" => "unknown"
319:         );
320:     }
321: 
322:     // Intern URL
323:     if (preg_match_all('~(?:(?:action|data|href|src)=["\'])(?!file://)(?!ftp://)(?!http://)(?!https://)(?!ww)(?!mailto)(?!\#)(?!/\#)([^"\']+)(?:["\'])~i', $sValue, $aMatches) && $_GET['mode'] != 2) {
324: 
325:         for ($i = 0; $i < count($aMatches[1]); $i++) {
326: 
327:             if (strpos($aMatches[1][$i], "front_content.php") === false && !in_array($aMatches[1][$i], $aWhitelist)) {
328:                 $aSearchIDInfosNonID[] = array(
329:                         "url" => $aMatches[1][$i],
330:                         "idart" => $iArt,
331:                         "nameart" => $sArt,
332:                         "idcat" => $iCat,
333:                         "namecat" => $sCat,
334:                         "lang" => $iLang,
335:                         "urltype" => "intern"
336:                 );
337:             }
338:         }
339:     }
340: }
341: ?>
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0