Merge remote-tracking branch 'mike/master' into dev
This commit is contained in:
commit
214fa81ec6
121
Zotlabs/Lib/Img_filesize.php
Normal file
121
Zotlabs/Lib/Img_filesize.php
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zotlabs\Lib;
|
||||||
|
|
||||||
|
class Img_filesize {
|
||||||
|
|
||||||
|
private $url;
|
||||||
|
|
||||||
|
function __construct($url) {
|
||||||
|
$this->url = $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSize() {
|
||||||
|
$size = null;
|
||||||
|
|
||||||
|
if(stripos($this->url,z_root() . '/photo') !== false) {
|
||||||
|
$size = self::getLocalFileSize($this->url);
|
||||||
|
}
|
||||||
|
if(! $size) {
|
||||||
|
$size = getRemoteFileSize($this->url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static function getLocalFileSize($url) {
|
||||||
|
|
||||||
|
$fname = basename($url);
|
||||||
|
$resolution = 0;
|
||||||
|
|
||||||
|
if(strpos($fname,'.') !== false)
|
||||||
|
$fname = substr($fname,0,strpos($fname,'.'));
|
||||||
|
|
||||||
|
if(substr($fname,-2,1) == '-') {
|
||||||
|
$resolution = intval(substr($fname,-1,1));
|
||||||
|
$fname = substr($fname,0,-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = q("SELECT filesize FROM photo WHERE resource_id = '%s' AND imgscale = %d LIMIT 1",
|
||||||
|
dbesc($fname),
|
||||||
|
intval($resolution)
|
||||||
|
);
|
||||||
|
if($r) {
|
||||||
|
return $r[0]['filesize'];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to determine the size of a remote file by making an HTTP request for
|
||||||
|
* a byte range, or look for the content-length header in the response.
|
||||||
|
* The function aborts the transfer as soon as the size is found, or if no
|
||||||
|
* length headers are returned, it aborts the transfer.
|
||||||
|
*
|
||||||
|
* @return int|null null if size could not be determined, or length of content
|
||||||
|
*/
|
||||||
|
function getRemoteFileSize($url)
|
||||||
|
{
|
||||||
|
$ch = curl_init($url);
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
'Range: bytes=0-1',
|
||||||
|
'Connection: close',
|
||||||
|
);
|
||||||
|
|
||||||
|
$in_headers = true;
|
||||||
|
$size = null;
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2450.0 Iron/46.0.2450.0');
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_VERBOSE, 0); // set to 1 to debug
|
||||||
|
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'r'));
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $line) use (&$in_headers, &$size) {
|
||||||
|
$length = strlen($line);
|
||||||
|
|
||||||
|
if (trim($line) == '') {
|
||||||
|
$in_headers = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
list($header, $content) = explode(':', $line, 2);
|
||||||
|
$header = strtolower(trim($header));
|
||||||
|
|
||||||
|
if ($header == 'content-range') {
|
||||||
|
// found a content-range header
|
||||||
|
list($rng, $s) = explode('/', $content, 2);
|
||||||
|
$size = (int)$s;
|
||||||
|
return 0; // aborts transfer
|
||||||
|
} else if ($header == 'content-length' && 206 != curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
|
||||||
|
// found content-length header and this is not a 206 Partial Content response (range response)
|
||||||
|
$size = (int)$content;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
// continue
|
||||||
|
return $length;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) use ($in_headers) {
|
||||||
|
if (!$in_headers) {
|
||||||
|
// shouldn't be here unless we couldn't determine file size
|
||||||
|
// abort transfer
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write function is also called when reading headers
|
||||||
|
return strlen($data);
|
||||||
|
});
|
||||||
|
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
$info = curl_getinfo($ch);
|
||||||
|
|
||||||
|
return $size;
|
||||||
|
}
|
@ -16,12 +16,15 @@ class Feed extends \Zotlabs\Web\Controller {
|
|||||||
$params['type'] = ((stristr(argv(0),'json')) ? 'json' : 'xml');
|
$params['type'] = ((stristr(argv(0),'json')) ? 'json' : 'xml');
|
||||||
$params['pages'] = ((x($_REQUEST,'pages')) ? intval($_REQUEST['pages']) : 0);
|
$params['pages'] = ((x($_REQUEST,'pages')) ? intval($_REQUEST['pages']) : 0);
|
||||||
$params['top'] = ((x($_REQUEST,'top')) ? intval($_REQUEST['top']) : 0);
|
$params['top'] = ((x($_REQUEST,'top')) ? intval($_REQUEST['top']) : 0);
|
||||||
$params['start'] = ((x($params,'start')) ? intval($params['start']) : 0);
|
$params['start'] = ((x($_REQUEST,'start')) ? intval($_REQUEST['start']) : 0);
|
||||||
$params['records'] = ((x($params,'records')) ? intval($params['records']) : 40);
|
$params['records'] = ((x($_REQUEST,'records')) ? intval($_REQUEST['records']) : 40);
|
||||||
$params['direction'] = ((x($params,'direction')) ? dbesc($params['direction']) : 'desc');
|
$params['direction'] = ((x($_REQUEST,'direction')) ? dbesc($_REQUEST['direction']) : 'desc');
|
||||||
$params['cat'] = ((x($_REQUEST,'cat')) ? escape_tags($_REQUEST['cat']) : '');
|
$params['cat'] = ((x($_REQUEST,'cat')) ? escape_tags($_REQUEST['cat']) : '');
|
||||||
$params['compat'] = ((x($_REQUEST,'compat')) ? intval($_REQUEST['compat']) : 0);
|
$params['compat'] = ((x($_REQUEST,'compat')) ? intval($_REQUEST['compat']) : 0);
|
||||||
|
|
||||||
|
if(! in_array($params['direction'],['asc','desc'])) {
|
||||||
|
$params['direction'] = 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
if(argc() > 1) {
|
if(argc() > 1) {
|
||||||
|
|
||||||
|
@ -17,12 +17,15 @@ class Ofeed extends \Zotlabs\Web\Controller {
|
|||||||
$params['type'] = ((stristr(argv(0),'json')) ? 'json' : 'xml');
|
$params['type'] = ((stristr(argv(0),'json')) ? 'json' : 'xml');
|
||||||
$params['pages'] = ((x($_REQUEST,'pages')) ? intval($_REQUEST['pages']) : 0);
|
$params['pages'] = ((x($_REQUEST,'pages')) ? intval($_REQUEST['pages']) : 0);
|
||||||
$params['top'] = ((x($_REQUEST,'top')) ? intval($_REQUEST['top']) : 0);
|
$params['top'] = ((x($_REQUEST,'top')) ? intval($_REQUEST['top']) : 0);
|
||||||
$params['start'] = ((x($params,'start')) ? intval($params['start']) : 0);
|
$params['start'] = ((x($_REQUEST,'start')) ? intval($_REQUEST['start']) : 0);
|
||||||
$params['records'] = ((x($params,'records')) ? intval($params['records']) : 10);
|
$params['records'] = ((x($_REQUEST,'records')) ? intval($_REQUEST['records']) : 10);
|
||||||
$params['direction'] = ((x($params,'direction')) ? dbesc($params['direction']) : 'desc');
|
$params['direction'] = ((x($_REQUEST,'direction')) ? dbesc($_REQUEST['direction']) : 'desc');
|
||||||
$params['cat'] = ((x($_REQUEST,'cat')) ? escape_tags($_REQUEST['cat']) : '');
|
$params['cat'] = ((x($_REQUEST,'cat')) ? escape_tags($_REQUEST['cat']) : '');
|
||||||
$params['compat'] = ((x($_REQUEST,'compat')) ? intval($_REQUEST['compat']) : 1);
|
$params['compat'] = ((x($_REQUEST,'compat')) ? intval($_REQUEST['compat']) : 1);
|
||||||
|
|
||||||
|
if(! in_array($params['direction'],['asc','desc'])) {
|
||||||
|
$params['direction'] = 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
if(argc() > 1) {
|
if(argc() > 1) {
|
||||||
|
|
||||||
|
@ -1801,12 +1801,17 @@ function compat_photos_list($s) {
|
|||||||
|
|
||||||
if($found) {
|
if($found) {
|
||||||
foreach($matches as $match) {
|
foreach($matches as $match) {
|
||||||
$ret[] = [
|
$entry = [
|
||||||
'href' => $match[2],
|
'href' => $match[2],
|
||||||
'length' => 0,
|
|
||||||
'type' => guess_image_type($match[2])
|
'type' => guess_image_type($match[2])
|
||||||
];
|
];
|
||||||
|
$sizer = new \Zotlabs\Lib\Img_filesize($match[2]);
|
||||||
|
$size = $sizer->getSize();
|
||||||
|
if(intval($size)) {
|
||||||
|
$entry['length'] = intval($size);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret[] = $entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4063,8 +4063,9 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
|
|||||||
$item_uids = ' true ';
|
$item_uids = ' true ';
|
||||||
$item_normal = item_normal();
|
$item_normal = item_normal();
|
||||||
|
|
||||||
|
if($arr['uid']) {
|
||||||
if ($arr['uid']) $uid= $arr['uid'];
|
$uid = $arr['uid'];
|
||||||
|
}
|
||||||
|
|
||||||
if($channel) {
|
if($channel) {
|
||||||
$uid = $channel['channel_id'];
|
$uid = $channel['channel_id'];
|
||||||
@ -4226,7 +4227,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
|
|||||||
$items = q("SELECT item.*, item.id AS item_id FROM item
|
$items = q("SELECT item.*, item.id AS item_id FROM item
|
||||||
WHERE $item_uids $item_restrict
|
WHERE $item_uids $item_restrict
|
||||||
$simple_update
|
$simple_update
|
||||||
$sql_extra $sql_nets
|
$sql_extra $sql_nets $sql_extra3
|
||||||
ORDER BY item.received DESC $pager_sql"
|
ORDER BY item.received DESC $pager_sql"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -105,8 +105,8 @@ function strip_zats($s) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function clean_query_string() {
|
function clean_query_string($s = '') {
|
||||||
$x = strip_zids(\App::$query_string);
|
$x = strip_zids(($s) ? $s : \App::$query_string);
|
||||||
$x = strip_owt($x);
|
$x = strip_owt($x);
|
||||||
$x = strip_zats($x);
|
$x = strip_zats($x);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user