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