X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fproxy.php;h=0b84233e5f356088916aca39b59b0762438af06c;hb=a5550b470223f084c355e1acea173c913c63675d;hp=790309c62769d4cea2ff235a02299cc544d074c2;hpb=0091d318e52f621f1af15e268b578798b972a25d;p=friendica.git diff --git a/mod/proxy.php b/mod/proxy.php index 790309c627..0b84233e5f 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -8,7 +8,10 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Database\DBM; -use Friendica\Object\Photo; +use Friendica\Model\Photo; +use Friendica\Object\Image; +use Friendica\Util\DateTimeFormat; +use Friendica\Util\Network; define('PROXY_DEFAULT_TIME', 86400); // 1 Day @@ -103,7 +106,7 @@ function proxy_init(App $a) { $url = substr($url, 0, $pos + 1); } - $url = str_replace(array('.jpg', '.jpeg', '.gif', '.png'), array('','','',''), $url); + $url = str_replace(['.jpg', '.jpeg', '.gif', '.png'], ['','','',''], $url); $url = base64_decode(strtr($url, '-_', '+/'), true); @@ -130,9 +133,9 @@ function proxy_init(App $a) { // reduce quality - if it isn't a GIF if ($mime != 'image/gif') { - $img = new Photo($img_str, $mime); - if ($img->isValid()) { - $img_str = $img->imageString(); + $Image = new Image($img_str, $mime); + if ($Image->isValid()) { + $img_str = $Image->asString(); } } @@ -144,24 +147,23 @@ function proxy_init(App $a) { } $valid = true; - $r = array(); - + $photo = null; if (!$direct_cache && ($cachefile == '')) { - $r = dba::select('photo', array('data', 'desc'), array('resource-id' => $urlhash), array('limit' => 1)); - if (DBM::is_result($r)) { - $img_str = $r['data']; - $mime = $r['desc']; + $photo = dba::selectFirst('photo', ['data', 'desc'], ['resource-id' => $urlhash]); + if (DBM::is_result($photo)) { + $img_str = $photo['data']; + $mime = $photo['desc']; if ($mime == '') { $mime = 'image/jpeg'; } } } - if (!DBM::is_result($r)) { + if (!DBM::is_result($photo)) { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']); $redirects = 0; - $img_str = fetch_url($_REQUEST['url'], true, $redirects, 10); + $img_str = Network::fetchUrl($_REQUEST['url'], true, $redirects, 10); $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); @@ -174,10 +176,10 @@ function proxy_init(App $a) { $mime = 'image/png'; $cachefile = ''; // Clear the cachefile so that the dummy isn't stored $valid = false; - $img = new Photo($img_str, 'image/png'); - if ($img->isValid()) { - $img->scaleImage(10); - $img_str = $img->imageString(); + $Image = new Image($img_str, 'image/png'); + if ($Image->isValid()) { + $Image->scaleDown(10); + $img_str = $Image->asString(); } } elseif ($mime != 'image/jpeg' && !$direct_cache && $cachefile == '') { $image = @imagecreatefromstring($img_str); @@ -186,15 +188,15 @@ function proxy_init(App $a) { die(); } - $fields = array('uid' => 0, 'contact-id' => 0, 'guid' => get_guid(), 'resource-id' => $urlhash, 'created' => datetime_convert(), 'edited' => datetime_convert(), + $fields = ['uid' => 0, 'contact-id' => 0, 'guid' => get_guid(), 'resource-id' => $urlhash, 'created' => DateTimeFormat::utcNow(), 'edited' => DateTimeFormat::utcNow(), 'filename' => basename($_REQUEST['url']), 'type' => '', 'album' => '', 'height' => imagesy($image), 'width' => imagesx($image), 'datasize' => 0, 'data' => $img_str, 'scale' => 100, 'profile' => 0, - 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '', 'desc' => $mime); + 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '', 'desc' => $mime]; dba::insert('photo', $fields); } else { - $img = new Photo($img_str, $mime); - if ($img->isValid() && !$direct_cache && ($cachefile == '')) { - $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100); + $Image = new Image($img_str, $mime); + if ($Image->isValid() && !$direct_cache && ($cachefile == '')) { + Photo::store($Image, 0, 0, $urlhash, $_REQUEST['url'], '', 100); } } } @@ -203,10 +205,10 @@ function proxy_init(App $a) { // reduce quality - if it isn't a GIF if ($mime != 'image/gif') { - $img = new Photo($img_str, $mime); - if ($img->isValid()) { - $img->scaleImage($size); - $img_str = $img->imageString(); + $Image = new Image($img_str, $mime); + if ($Image->isValid()) { + $Image->scaleDown($size); + $img_str = $Image->asString(); } } @@ -286,7 +288,7 @@ function proxy_url($url, $writemode = false, $size = '') { // Extract the URL extension $extension = pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION); - $extensions = array('jpg', 'jpeg', 'gif', 'png'); + $extensions = ['jpg', 'jpeg', 'gif', 'png']; if (in_array($extension, $extensions)) { $shortpath .= '.' . $extension; $longpath .= '.' . $extension; @@ -340,7 +342,7 @@ function proxy_parse_query($url) { $query = parse_url($url, PHP_URL_QUERY); $query = html_entity_decode($query); $query_list = explode('&', $query); - $arr = array(); + $arr = []; foreach ($query_list as $key_value) { $key_value_list = explode('=', $key_value);