Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as PHP by tom ( 14 years ago )
public function checkUrlAction() {
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$posts = $this->registry->posts;
$url = urldecode($posts["adres"]);
$headers = get_headers($url, 1);
if (strpos($headers[0], '200')) {
$contentTypeArr = (isset($headers["Content-Type"])) ? explode(";", $headers["Content-Type"]) : explode(";", $headers["Content-type"]);
if (strtolower($contentTypeArr[0]) == "text/html") {
$content = file_get_contents($url);
if (preg_match_all("#\<img[^\>]+?\>#i", $content, $matches) > 0) {
$imgArr = array();
foreach ($matches[0] as $k => &$val) {
$src = preg_replace("#\<img\s+.*?src\=(\'|\")(.+?)\\1[^>]+?\>#i", "$2", $val);
$img = @getimagesize($src);
if (!empty($img) and in_array($img["mime"], array("image/jpg", "image/jpeg", "image/png", "image/gif"))) {
$o_width = $img[0];
$o_height = $img[1];
$c_width = 200;
$c_height = 200;
$ratio = round($o_width / $o_height);
if ($o_width > $o_height && $o_width >= $c_width) {
$c_height = round($c_width / $ratio);
if (preg_match("#width\=(\'|\").+?\\1#", $val)) {
$val = preg_replace("#width\=(\'|\").+?\\1#i", "width='" . $c_width . "'", $val);
} else {
$valArr = explode(" ", $val);
$count = count($valArr);
$arrSliced = array_slice($valArr, 0, $count - 1);
array_push($arrSliced, "width='$c_width'", end($valArr));
$val = implode(" ", array_values($arrSliced));
}
if (preg_match("#height\=(\'|\").+?\\1#", $val)) {
$val = preg_replace("#height\=(\'|\").+?\\1#i", "height='" . $c_height . "'", $val);
} else {
$valArr = explode(" ", $val);
$count = count($valArr);
$arrSliced = array_slice($valArr, 0, $count - 1);
array_push($arrSliced, "height='$c_height'", end($valArr));
$val = implode(" ", array_values($arrSliced));
}
$imgArr[] = $val;
} else if ($o_width < $o_height && $o_height >= $c_height) {
$c_width = round($c_height * $ratio);
if (preg_match("#width\=(\'|\").+?\\1#", $val)) {
$val = preg_replace("#width\=(\'|\").+?\\1#i", "width='" . $c_width . "'", $val);
} else {
$valArr = explode(" ", $val);
$count = count($valArr);
$arrSliced = array_slice($valArr, 0, $count - 1);
array_push($arrSliced, "width='$c_width'", end($valArr));
$val = implode(" ", array_values($arrSliced));
}
if (preg_match("#height\=(\'|\").+?\\1#", $val)) {
$val = preg_replace("#height\=(\'|\").+?\\1#i", "height='" . $c_height . "'", $val);
} else {
$valArr = explode(" ", $val);
$count = count($valArr);
$arrSliced = array_slice($valArr, 0, $count - 1);
array_push($arrSliced, "height='$c_height'", end($valArr));
$val = implode(" ", array_values($arrSliced));
}
$imgArr[] = $val;
} else {
continue;
}
} else {
continue;
}
}
$content = $imgArr;
} else {
$content = NULL;
}
print json_encode(array("error" => 0, "content" => $content, "typ" => "text/html"));
exit;
} else if (strtolower($contentTypeArr[0]) == "image/jpeg" || strtolower($contentTypeArr[0]) == "image/png") {
$content = $url;
print json_encode(array("error" => 0, "content" => $content, "typ" => strtolower($headers["Content-type"])));
exit;
}
} else {
print json_encode(array("error" => 1));
}
} else {
print json_encode(array("error" => 1));
exit;
}
}
Revise this Paste