1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18:
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) {
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:
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) {
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:
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) {
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:
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) {
145:
146:
147:
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) {
152:
153:
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:
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:
228: function searchFrontContentLinks($sValue, $iArt, $sArt, $iCat, $sCat) {
229: global $aSearchIDInfosArt, $aSearchIDInfosCat, $aSearchIDInfosCatArt, $aWhitelist;
230:
231:
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:
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:
268: $matches = array();
269: if (preg_match_all('/(?!file|ftp|http|ww)front_content.php\?idcatart=([0-9]*)/i', $sValue, $matches)) {
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:
287: function searchLinks($sValue, $iArt, $sArt, $iCat, $sCat, $iLang, $sFromtype = "") {
288: global $aUrl, $aSearchIDInfosNonID, $aWhitelist;
289:
290:
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:
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:
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: ?>