aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-04-25 01:55:35 -0700
committerfriendica <info@friendica.com>2013-04-25 01:55:35 -0700
commitd3b5e678908864d889b916ad2f976c1af16ca360 (patch)
treea5992a78ff9d9683da25f8fbdf895ecd5fc0a20d
parent9d564913f6ea913a39fe2e4937dc4703452c769d (diff)
downloadvolse-hubzilla-d3b5e678908864d889b916ad2f976c1af16ca360.tar.gz
volse-hubzilla-d3b5e678908864d889b916ad2f976c1af16ca360.tar.bz2
volse-hubzilla-d3b5e678908864d889b916ad2f976c1af16ca360.zip
odds and ends in prepearation for photo abstraction, plus red-to-friendica addon
-rw-r--r--include/Photo.php107
-rw-r--r--include/network.php50
-rw-r--r--mod/display.php15
-rw-r--r--mod/oexchange.php9
-rw-r--r--mod/starred.php8
-rw-r--r--version.inc2
6 files changed, 154 insertions, 37 deletions
diff --git a/include/Photo.php b/include/Photo.php
index 8daac450e..5882f39f5 100644
--- a/include/Photo.php
+++ b/include/Photo.php
@@ -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();
diff --git a/include/network.php b/include/network.php
index d3e6480d6..a70207be2 100644
--- a/include/network.php
+++ b/include/network.php
@@ -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();
-
}
diff --git a/mod/display.php b/mod/display.php
index 170f800ac..b1ae54df3 100644
--- a/mod/display.php
+++ b/mod/display.php
@@ -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;
diff --git a/mod/oexchange.php b/mod/oexchange.php
index 791a493ff..63b48751c 100644
--- a/mod/oexchange.php
+++ b/mod/oexchange.php
@@ -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;
diff --git a/mod/starred.php b/mod/starred.php
index 530c5c7e0..ca7621b0f 100644
--- a/mod/starred.php
+++ b/mod/starred.php
@@ -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),
diff --git a/version.inc b/version.inc
index a8393c1d0..4e4308bdf 100644
--- a/version.inc
+++ b/version.inc
@@ -1 +1 @@
-2013-04-23.292
+2013-04-25.294