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 */
|
||||
|
||||
|
||||
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 {
|
||||
|
||||
private $image;
|
||||
@ -512,10 +617,12 @@ class Photo {
|
||||
imagepng($this->image,NULL, $quality);
|
||||
break;
|
||||
case "image/jpeg":
|
||||
default:
|
||||
$quality = get_config('system','jpeg_quality');
|
||||
if((! $quality) || ($quality > 100))
|
||||
$quality = JPEG_QUALITY;
|
||||
imagejpeg($this->image,NULL,$quality);
|
||||
break;
|
||||
}
|
||||
$string = ob_get_contents();
|
||||
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' => "");
|
||||
|
||||
@ -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_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 {
|
||||
$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(!is_array($headers)) {
|
||||
$headers = array('Expect:');
|
||||
} else {
|
||||
if(!in_array('Expect:', $headers)) {
|
||||
array_push($headers, 'Expect:');
|
||||
}
|
||||
}
|
||||
if(x($opts,'http_auth')) {
|
||||
// "username" . ':' . "password"
|
||||
@curl_setopt($ch, CURLOPT_USERPWD, $opts['http_auth']);
|
||||
}
|
||||
if($headers)
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
|
||||
((x($opts,'novalidate') && intval($opts['novalidate'])) ? false : true));
|
||||
|
||||
$prx = get_config('system','proxy');
|
||||
if(strlen($prx)) {
|
||||
@ -398,9 +398,9 @@ function z_post_url($url,$params, $headers = null, $redirects = 0, $timeout = 0)
|
||||
if (isset($url_parsed)) {
|
||||
curl_close($ch);
|
||||
if($http_code == 303) {
|
||||
return z_fetch_url($newurl,false,$headers,$redirects++,$timeout);
|
||||
return z_fetch_url($newurl,false,$redirects++,$opts);
|
||||
} 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
|
||||
* @param int $val
|
||||
* integer HTTP status result value
|
||||
*
|
||||
* @param string $msg
|
||||
* optional message
|
||||
* @returns (does not return, process is terminated)
|
||||
*/
|
||||
|
||||
function http_status_exit($val) {
|
||||
function http_status_exit($val,$msg = '') {
|
||||
|
||||
$err = '';
|
||||
if($val >= 400)
|
||||
$err = 'Error';
|
||||
$msg = (($msg) ? $msg : 'Error');
|
||||
if($val >= 200 && $val < 300)
|
||||
$err = 'OK';
|
||||
$msg = (($msg) ? $msg : 'OK');
|
||||
|
||||
logger('http_status_exit ' . $val);
|
||||
header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err);
|
||||
logger('http_status_exit ' . $val . ' ' . $msg);
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $val . ' ' . $msg);
|
||||
killme();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,6 +94,8 @@ function display_content(&$a, $update = 0, $load = false) {
|
||||
|
||||
if($update && $load) {
|
||||
|
||||
$updateable = false;
|
||||
|
||||
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
|
||||
|
||||
if($load) {
|
||||
@ -107,6 +109,8 @@ function display_content(&$a, $update = 0, $load = false) {
|
||||
intval(local_user()),
|
||||
dbesc($target_item['parent_mid'])
|
||||
);
|
||||
if($r)
|
||||
$updateable = true;
|
||||
}
|
||||
if($r === null) {
|
||||
$r = q("SELECT * from item
|
||||
@ -149,6 +153,17 @@ function display_content(&$a, $update = 0, $load = false) {
|
||||
|
||||
|
||||
$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;
|
||||
|
||||
|
||||
|
@ -32,18 +32,19 @@ function oexchange_content(&$a) {
|
||||
$tags = (((x($_REQUEST,'tags')) && strlen($_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))
|
||||
return;
|
||||
|
||||
require_once('include/html2bbcode.php');
|
||||
|
||||
$post = array();
|
||||
|
||||
$post['profile_uid'] = local_user();
|
||||
$post['return'] = '/oexchange/done' ;
|
||||
$post['body'] = html2bbcode($s);
|
||||
$post['body'] = $s;
|
||||
$post['type'] = 'wall';
|
||||
|
||||
$_REQUEST = $post;
|
||||
|
@ -19,13 +19,7 @@ function starred_init(&$a) {
|
||||
if(! count($r))
|
||||
killme();
|
||||
|
||||
$item_flags = $r[0]['item_flags'];
|
||||
|
||||
if($item_flags & ITEM_STARRED)
|
||||
$item_flags -= ITEM_STARRED;
|
||||
else
|
||||
$item_flags += ITEM_STARRED;
|
||||
|
||||
$item_flags = ( $r[0]['item_flags'] ^ ITEM_STARRED );
|
||||
|
||||
$r = q("UPDATE item SET item_flags = %d WHERE uid = %d and id = %d LIMIT 1",
|
||||
intval($item_flags),
|
||||
|
@ -1 +1 @@
|
||||
2013-04-23.292
|
||||
2013-04-25.294
|
||||
|
Reference in New Issue
Block a user