1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
14:
15: 16: 17:
18: class cLinkcheckerTester
19: {
20: 21: 22: 23: 24: 25:
26: public static function checkLinks()
27: {
28: global $auth, $cfg, $cronjob, $db, $aErrors, $lang;
29: global $aSearchIDInfosArt, $aSearchIDInfosCat, $aSearchIDInfosCatArt, $aSearchIDInfosNonID;
30:
31: $sSearch = '';
32:
33: if (count($aSearchIDInfosArt) > 0) {
34:
35: for ($i = 0; $i < count($aSearchIDInfosArt); $i++) {
36: if ($i == 0) {
37: $sSearch = cSecurity::toInteger($aSearchIDInfosArt[$i]['id']);
38: } else {
39: $sSearch .= ", " . cSecurity::toInteger($aSearchIDInfosArt[$i]['id']);
40: }
41: }
42:
43:
44: $sql = "SELECT idart, online FROM " . $cfg['tab']['art_lang'] . " WHERE idart IN (" . $sSearch . ")";
45: $db->query($sql);
46:
47:
48: $aFind = [];
49:
50: while ($db->nextRecord()) {
51: $aFind[$db->f("idart")] = [
52: "online" => $db->f("online"),
53: ];
54: }
55:
56: for ($i = 0; $i < count($aSearchIDInfosArt); $i++) {
57: if (isset($aFind[$aSearchIDInfosArt[$i]['id']])
58: && $aFind[$aSearchIDInfosArt[$i]['id']]['online'] == 0
59: ) {
60: $aErrors['art'][] = array_merge(
61: $aSearchIDInfosArt[$i],
62: [
63: "error_type" => "offline",
64: ]
65: );
66: } elseif (!isset($aFind[$aSearchIDInfosArt[$i]['id']])) {
67: $aErrors['art'][] = array_merge(
68: $aSearchIDInfosArt[$i],
69: [
70: "error_type" => "unknown",
71: ]
72: );
73: }
74: }
75: }
76:
77: if (count($aSearchIDInfosCat) > 0) {
78:
79: for ($i = 0; $i < count($aSearchIDInfosCat); $i++) {
80: if ($i == 0) {
81: $sSearch = cSecurity::toInteger($aSearchIDInfosCat[$i]['id']);
82: } else {
83: $sSearch .= ", " . cSecurity::toInteger($aSearchIDInfosCat[$i]['id']);
84: }
85: }
86:
87:
88: $sql =
89: "SELECT idcat, startidartlang, visible FROM " . $cfg['tab']['cat_lang'] . " WHERE idcat IN (" . $sSearch
90: . ") AND idlang = '" . cSecurity::toInteger($lang) . "'";
91: $db->query($sql);
92:
93:
94: $aFind = [];
95:
96: while ($db->nextRecord()) {
97: $aFind[$db->f("idcat")] = [
98: "online" => $db->f("visible"),
99: "startidart" => $db->f("startidartlang"),
100: ];
101: }
102:
103: for ($i = 0; $i < count($aSearchIDInfosCat); $i++) {
104: if (is_array($aFind[$aSearchIDInfosCat[$i]['id']])
105: && $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] == 0
106: ) {
107: $aErrors['cat'][] = array_merge(
108: $aSearchIDInfosCat[$i],
109: [
110: "error_type" => "startart",
111: ]
112: );
113: } elseif (is_array($aFind[$aSearchIDInfosCat[$i]['id']])
114: && $aFind[$aSearchIDInfosCat[$i]['id']]['online'] == 0
115: ) {
116: $aErrors['cat'][] = array_merge(
117: $aSearchIDInfosCat[$i],
118: [
119: "error_type" => "offline",
120: ]
121: );
122: } elseif (!is_array($aFind[$aSearchIDInfosCat[$i]['id']])) {
123: $aErrors['cat'][] = array_merge(
124: $aSearchIDInfosCat[$i],
125: [
126: "error_type" => "unknown",
127: ]
128: );
129: }
130:
131: if (is_array($aFind[$aSearchIDInfosCat[$i]['id']])
132: && $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] != 0
133: ) {
134: $sql =
135: "SELECT idart FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang = '" . cSecurity::toInteger(
136: $aFind[$aSearchIDInfosCat[$i]['id']]['startidart']
137: ) . "' AND online = '1'";
138: $db->query($sql);
139:
140: if ($db->numRows() == 0) {
141: $aErrors['cat'][] = array_merge(
142: $aSearchIDInfosCat[$i],
143: [
144: "error_type" => "startart",
145: ]
146: );
147: }
148: }
149: }
150: }
151:
152: if (count($aSearchIDInfosCatArt) > 0) {
153:
154: for ($i = 0; $i < count($aSearchIDInfosCatArt); $i++) {
155: if ($i == 0) {
156: $sSearch = cSecurity::toInteger($aSearchIDInfosCatArt[$i]['id']);
157: } else {
158: $sSearch .= ", " . cSecurity::toInteger($aSearchIDInfosCatArt[$i]['id']);
159: }
160: }
161:
162:
163: $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'] . " WHERE idcatart IN (" . $sSearch . ")";
164: $db->query($sql);
165:
166:
167: $aFind = [];
168:
169: while ($db->nextRecord()) {
170: $aFind[] = $db->f("idcatart");
171: }
172:
173: for ($i = 0; $i < count($aSearchIDInfosCatArt); $i++) {
174: if (!in_array($aSearchIDInfosCatArt[$i]['id'], $aFind)) {
175: $aErrors['art'][] = array_merge(
176: $aSearchIDInfosCatArt[$i],
177: [
178: "error_type" => "unknown",
179: ]
180: );
181: }
182: }
183: }
184:
185: if (count($aSearchIDInfosNonID) != 0) {
186:
187:
188:
189: $sql = "SELECT username FROM " . $cfg['tab']['user'] . " WHERE user_id='" . cSecurity::toInteger(
190: $auth->auth['uid']
191: ) . "' AND perms LIKE '%admin%'";
192: $db->query($sql);
193:
194: if ($db->numRows() > 0 || $cronjob == true) {
195:
196:
197: $iAdmin = true;
198: }
199:
200: $frontendPath = cRegistry::getFrontendPath();
201: $frontendURL = cRegistry::getFrontendUrl();
202:
203: for ($i = 0; $i < count($aSearchIDInfosNonID); $i++) {
204: if (!filter_var($aSearchIDInfosNonID[$i]['url'], FILTER_VALIDATE_URL)
205: && !url_is_image(
206: $aSearchIDInfosNonID[$i]['url']
207: )
208: ) {
209: $aErrors['others'][] = array_merge(
210: $aSearchIDInfosNonID[$i],
211: [
212: "error_type" => "invalidurl",
213: ]
214: );
215: } elseif (url_is_uri($aSearchIDInfosNonID[$i]['url'])) {
216: if (cString::getPartOfString(
217: $aSearchIDInfosNonID[$i]['url'],
218: 0,
219: cString::getStringLength($aSearchIDInfosNonID[$i]['url'])
220: ) == $frontendURL
221: ) {
222: $iPing = @cFileHandler::exists(
223: str_replace($frontendURL, $frontendPath, $aSearchIDInfosNonID[$i]['url'])
224: );
225: } else {
226: $iPing = @fopen($aSearchIDInfosNonID[$i]['url'], 'r');
227: }
228:
229: if (!$iPing) {
230: if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
231: $aErrors['docimages'][] = array_merge(
232: $aSearchIDInfosNonID[$i],
233: [
234: "error_type" => "unknown",
235: ]
236: );
237: } else {
238: $aErrors['others'][] = array_merge(
239: $aSearchIDInfosNonID[$i],
240: [
241: "error_type" => "unknown",
242: ]
243: );
244: }
245: }
246: } elseif (cString::getPartOfString(
247: $aSearchIDInfosNonID[$i]['url'],
248: cString::getStringLength($aSearchIDInfosNonID[$i]['url']) - 5,
249: 5
250: ) == ".html"
251: ) {
252: $iPing = @cFileHandler::exists($frontendURL . $aSearchIDInfosNonID[$i]['url']);
253:
254: if (!$iPing) {
255: $aErrors['art'][] = array_merge(
256: $aSearchIDInfosNonID[$i],
257: [
258: "error_type" => "unknown",
259: ]
260: );
261: }
262: } elseif (cString::getPartOfString($aSearchIDInfosNonID[$i]['url'], 0, 20) == "dbfs.php?file="
263: . cApiDbfs::PROTOCOL_DBFS . "/"
264: ) {
265: $sDBurl = cString::getPartOfString(
266: $aSearchIDInfosNonID[$i]['url'],
267: 20,
268: cString::getStringLength($aSearchIDInfosNonID[$i]['url'])
269: );
270:
271: $iPos = cString::findLastPos($sDBurl, '/');
272: $sDirname = cString::getPartOfString($sDBurl, 0, $iPos);
273: $sFilename = cString::getPartOfString($sDBurl, $iPos + 1);
274:
275:
276: $sql = "SELECT iddbfs FROM " . $cfg['tab']['dbfs'] . " WHERE dirname IN('" . cSecurity::escapeDB(
277: $sDirname,
278: $db
279: ) . "', '" . conHtmlEntityDecode($sDirname) . "', '" . cSecurity::escapeDB($sDirname, $db)
280: . "') AND filename = '" . cSecurity::escapeDB($sFilename, $db) . "'";
281: $db->query($sql);
282:
283: if ($db->numRows() == 0) {
284: $aErrors['docimages'][] = array_merge(
285: $aSearchIDInfosNonID[$i],
286: [
287: "error_type" => "dbfs",
288: ]
289: );
290: }
291: } else {
292: if (!cFileHandler::exists($frontendPath . $aSearchIDInfosNonID[$i]['url'])) {
293: if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
294: $aErrors['docimages'][] = array_merge(
295: $aSearchIDInfosNonID[$i],
296: [
297: "error_type" => "unknown",
298: ]
299: );
300: } else {
301: $aErrors['others'][] = array_merge(
302: $aSearchIDInfosNonID[$i],
303: [
304: "error_type" => "unknown",
305: ]
306: );
307: }
308: }
309: }
310: }
311: }
312:
313: return $aErrors;
314: }
315:
316: 317: 318: 319: 320: 321: 322: 323: 324:
325: public static function searchFrontContentLinks($sValue, $iArt, $sArt, $iCat, $sCat)
326: {
327: global $aSearchIDInfosArt, $aSearchIDInfosCat, $aSearchIDInfosCatArt, $aWhitelist;
328:
329:
330: $matches = [];
331: if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idart=([0-9]*)/i', $sValue, $matches)) {
332: for ($i = 0; $i < count($matches[0]); $i++) {
333: if (!in_array($matches[0][$i], $aWhitelist)) {
334: $aSearchIDInfosArt[] = [
335: "id" => $matches[1][$i],
336: "url" => $matches[0][$i],
337: "idart" => $iArt,
338: "nameart" => $sArt,
339: "idcat" => $iCat,
340: "namecat" => $sCat,
341: "urltype" => "intern",
342: ];
343: }
344: }
345: }
346:
347:
348: $matches = [];
349: if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idcat=([0-9]*)/i', $sValue, $matches)) {
350: for ($i = 0; $i < count($matches[0]); $i++) {
351: if (!in_array($matches[0][$i], $aWhitelist)) {
352: $aSearchIDInfosCat[] = [
353: "id" => $matches[1][$i],
354: "url" => $matches[0][$i],
355: "idart" => $iArt,
356: "nameart" => $sArt,
357: "idcat" => $iCat,
358: "namecat" => $sCat,
359: "urltype" => "intern",
360: ];
361: }
362: }
363: }
364:
365:
366: $matches = [];
367: if (preg_match_all(
368: '/(?!file|ftp|http|ww)front_content.php\?idcatart=([0-9]*)/i',
369: $sValue,
370: $matches
371: )
372: ) {
373: for ($i = 0; $i < count($matches[0]); $i++) {
374: if (!in_array($matches[0][$i], $aWhitelist)) {
375: $aSearchIDInfosCatArt[] = [
376: "id" => $matches[1][$i],
377: "url" => $matches[0][$i],
378: "idart" => $iArt,
379: "nameart" => $sArt,
380: "idcat" => $iCat,
381: "namecat" => $sCat,
382: "urltype" => "intern",
383: ];
384: }
385: }
386: }
387: }
388: }
389: