odds and ends in prepearation for photo abstraction, plus red-to-friendica addon
This commit is contained in:
parent
9d564913f6
commit
d3b5e67890
@ -1,6 +1,111 @@
|
|||||||
<?php /** @file */
|
<?php /** @file */
|
||||||
|
|
||||||
|
|
||||||
|
abstract class photo_driver {
|
||||||
|
|
||||||
|
private $image;
|
||||||
|
private $width;
|
||||||
|
private $height;
|
||||||
|
private $valid;
|
||||||
|
private $type;
|
||||||
|
private $types;
|
||||||
|
|
||||||
|
|
||||||
|
abstract function supportedTypes();
|
||||||
|
abstract function load();
|
||||||
|
abstract function destroy();
|
||||||
|
abstract function getWidth();
|
||||||
|
abstract function getHeight();
|
||||||
|
|
||||||
|
abstract function getImage();
|
||||||
|
|
||||||
|
abstract function getType();
|
||||||
|
|
||||||
|
abstract function getExt();
|
||||||
|
|
||||||
|
abstract function scaleImage($max);
|
||||||
|
|
||||||
|
abstract function rotate($degrees);
|
||||||
|
|
||||||
|
abstract function flip($horiz = true, $vert = false);
|
||||||
|
|
||||||
|
abstract function scaleImageUp($min);
|
||||||
|
|
||||||
|
abstract function scaleImageSquare($dim);
|
||||||
|
|
||||||
|
abstract function cropImage($max,$x,$y,$w,$h);
|
||||||
|
|
||||||
|
abstract function imageString();
|
||||||
|
|
||||||
|
public function saveImage($path) {
|
||||||
|
if(!$this->is_valid())
|
||||||
|
return FALSE;
|
||||||
|
file_put_contents($path, $this->imageString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function orient($filename) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is a bit unusual, because it is operating on a file, but you must
|
||||||
|
* first create an image from that file to initialise the type and check validity
|
||||||
|
* of the image.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(! $this->is_valid())
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if((! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg'))
|
||||||
|
return;
|
||||||
|
|
||||||
|
$exif = @exif_read_data($filename);
|
||||||
|
if($exif) {
|
||||||
|
$ort = $exif['Orientation'];
|
||||||
|
|
||||||
|
switch($ort)
|
||||||
|
{
|
||||||
|
case 1: // nothing
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: // horizontal flip
|
||||||
|
$this->flip();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: // 180 rotate left
|
||||||
|
$this->rotate(180);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4: // vertical flip
|
||||||
|
$this->flip(false, true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5: // vertical flip + 90 rotate right
|
||||||
|
$this->flip(false, true);
|
||||||
|
$this->rotate(-90);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6: // 90 rotate right
|
||||||
|
$this->rotate(-90);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7: // horizontal flip + 90 rotate right
|
||||||
|
$this->flip();
|
||||||
|
$this->rotate(-90);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8: // 90 rotate left
|
||||||
|
$this->rotate(90);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Photo {
|
class Photo {
|
||||||
|
|
||||||
private $image;
|
private $image;
|
||||||
@ -512,10 +617,12 @@ class Photo {
|
|||||||
imagepng($this->image,NULL, $quality);
|
imagepng($this->image,NULL, $quality);
|
||||||
break;
|
break;
|
||||||
case "image/jpeg":
|
case "image/jpeg":
|
||||||
|
default:
|
||||||
$quality = get_config('system','jpeg_quality');
|
$quality = get_config('system','jpeg_quality');
|
||||||
if((! $quality) || ($quality > 100))
|
if((! $quality) || ($quality > 100))
|
||||||
$quality = JPEG_QUALITY;
|
$quality = JPEG_QUALITY;
|
||||||
imagejpeg($this->image,NULL,$quality);
|
imagejpeg($this->image,NULL,$quality);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$string = ob_get_contents();
|
$string = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
@ -321,7 +321,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function z_post_url($url,$params, $headers = null, $redirects = 0, $timeout = 0) {
|
function z_post_url($url,$params, $redirects = 0, $opts = array()) {
|
||||||
|
|
||||||
$ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => "");
|
$ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => "");
|
||||||
|
|
||||||
@ -336,28 +336,28 @@ function z_post_url($url,$params, $headers = null, $redirects = 0, $timeout = 0)
|
|||||||
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
|
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, "Red");
|
curl_setopt($ch, CURLOPT_USERAGENT, "Red");
|
||||||
|
|
||||||
if(intval($timeout)) {
|
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
if (x($opts,'accept_content')){
|
||||||
|
curl_setopt($ch,CURLOPT_HTTPHEADER, array (
|
||||||
|
"Accept: " . $opts['accept_content']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(x($opts,'timeout') && intval($opts['timeout'])) {
|
||||||
|
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$curl_time = intval(get_config('system','curl_timeout'));
|
$curl_time = intval(get_config('system','curl_timeout'));
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
|
@curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(defined('LIGHTTPD')) {
|
if(x($opts,'http_auth')) {
|
||||||
if(!is_array($headers)) {
|
// "username" . ':' . "password"
|
||||||
$headers = array('Expect:');
|
@curl_setopt($ch, CURLOPT_USERPWD, $opts['http_auth']);
|
||||||
} else {
|
|
||||||
if(!in_array('Expect:', $headers)) {
|
|
||||||
array_push($headers, 'Expect:');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if($headers)
|
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
||||||
|
|
||||||
|
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
((x($opts,'novalidate') && intval($opts['novalidate'])) ? false : true));
|
||||||
|
|
||||||
$prx = get_config('system','proxy');
|
$prx = get_config('system','proxy');
|
||||||
if(strlen($prx)) {
|
if(strlen($prx)) {
|
||||||
@ -398,9 +398,9 @@ function z_post_url($url,$params, $headers = null, $redirects = 0, $timeout = 0)
|
|||||||
if (isset($url_parsed)) {
|
if (isset($url_parsed)) {
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
if($http_code == 303) {
|
if($http_code == 303) {
|
||||||
return z_fetch_url($newurl,false,$headers,$redirects++,$timeout);
|
return z_fetch_url($newurl,false,$redirects++,$opts);
|
||||||
} else {
|
} else {
|
||||||
return z_post_url($newurl,$params,$headers,$redirects++,$timeout);
|
return z_post_url($newurl,$params,$redirects++,$opts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -447,22 +447,22 @@ function xml_status($st, $message = '') {
|
|||||||
* Send HTTP status header and exit
|
* Send HTTP status header and exit
|
||||||
* @param int $val
|
* @param int $val
|
||||||
* integer HTTP status result value
|
* integer HTTP status result value
|
||||||
*
|
* @param string $msg
|
||||||
|
* optional message
|
||||||
* @returns (does not return, process is terminated)
|
* @returns (does not return, process is terminated)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function http_status_exit($val) {
|
function http_status_exit($val,$msg = '') {
|
||||||
|
|
||||||
$err = '';
|
$err = '';
|
||||||
if($val >= 400)
|
if($val >= 400)
|
||||||
$err = 'Error';
|
$msg = (($msg) ? $msg : 'Error');
|
||||||
if($val >= 200 && $val < 300)
|
if($val >= 200 && $val < 300)
|
||||||
$err = 'OK';
|
$msg = (($msg) ? $msg : 'OK');
|
||||||
|
|
||||||
logger('http_status_exit ' . $val);
|
logger('http_status_exit ' . $val . ' ' . $msg);
|
||||||
header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err);
|
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $val . ' ' . $msg);
|
||||||
killme();
|
killme();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ function display_content(&$a, $update = 0, $load = false) {
|
|||||||
|
|
||||||
if($update && $load) {
|
if($update && $load) {
|
||||||
|
|
||||||
|
$updateable = false;
|
||||||
|
|
||||||
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
|
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
|
||||||
|
|
||||||
if($load) {
|
if($load) {
|
||||||
@ -107,6 +109,8 @@ function display_content(&$a, $update = 0, $load = false) {
|
|||||||
intval(local_user()),
|
intval(local_user()),
|
||||||
dbesc($target_item['parent_mid'])
|
dbesc($target_item['parent_mid'])
|
||||||
);
|
);
|
||||||
|
if($r)
|
||||||
|
$updateable = true;
|
||||||
}
|
}
|
||||||
if($r === null) {
|
if($r === null) {
|
||||||
$r = q("SELECT * from item
|
$r = q("SELECT * from item
|
||||||
@ -149,6 +153,17 @@ function display_content(&$a, $update = 0, $load = false) {
|
|||||||
|
|
||||||
|
|
||||||
$o .= conversation($a,$items,'display', $update, 'client');
|
$o .= conversation($a,$items,'display', $update, 'client');
|
||||||
|
|
||||||
|
if($updateable) {
|
||||||
|
$x = q("UPDATE item SET item_flags = ( item_flags ^ %d )
|
||||||
|
WHERE (item_flags & %d) AND uid = %d and parent = %d ",
|
||||||
|
intval(ITEM_UNSEEN),
|
||||||
|
intval(ITEM_UNSEEN),
|
||||||
|
intval(local_user()),
|
||||||
|
intval($r[0]['parent'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,18 +32,19 @@ function oexchange_content(&$a) {
|
|||||||
$tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags']))
|
$tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags']))
|
||||||
? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : '');
|
? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : '');
|
||||||
|
|
||||||
$s = fetch_url($a->get_baseurl() . '/parse_url?f=&url=' . $url . $title . $description . $tags);
|
$ret = z_fetch_url($a->get_baseurl() . '/parse_url?f=&url=' . $url . $title . $description . $tags);
|
||||||
|
|
||||||
|
if($ret['success'])
|
||||||
|
$s = $ret['body'];
|
||||||
|
|
||||||
if(! strlen($s))
|
if(! strlen($s))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
require_once('include/html2bbcode.php');
|
|
||||||
|
|
||||||
$post = array();
|
$post = array();
|
||||||
|
|
||||||
$post['profile_uid'] = local_user();
|
$post['profile_uid'] = local_user();
|
||||||
$post['return'] = '/oexchange/done' ;
|
$post['return'] = '/oexchange/done' ;
|
||||||
$post['body'] = html2bbcode($s);
|
$post['body'] = $s;
|
||||||
$post['type'] = 'wall';
|
$post['type'] = 'wall';
|
||||||
|
|
||||||
$_REQUEST = $post;
|
$_REQUEST = $post;
|
||||||
|
@ -19,13 +19,7 @@ function starred_init(&$a) {
|
|||||||
if(! count($r))
|
if(! count($r))
|
||||||
killme();
|
killme();
|
||||||
|
|
||||||
$item_flags = $r[0]['item_flags'];
|
$item_flags = ( $r[0]['item_flags'] ^ ITEM_STARRED );
|
||||||
|
|
||||||
if($item_flags & ITEM_STARRED)
|
|
||||||
$item_flags -= ITEM_STARRED;
|
|
||||||
else
|
|
||||||
$item_flags += ITEM_STARRED;
|
|
||||||
|
|
||||||
|
|
||||||
$r = q("UPDATE item SET item_flags = %d WHERE uid = %d and id = %d LIMIT 1",
|
$r = q("UPDATE item SET item_flags = %d WHERE uid = %d and id = %d LIMIT 1",
|
||||||
intval($item_flags),
|
intval($item_flags),
|
||||||
|
@ -1 +1 @@
|
|||||||
2013-04-23.292
|
2013-04-25.294
|
||||||
|
Reference in New Issue
Block a user