diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Contact.php | 2 | ||||
-rw-r--r-- | include/bbcode.php | 1 | ||||
-rw-r--r-- | include/cli_startup.php | 4 | ||||
-rw-r--r-- | include/conversation.php | 43 | ||||
-rw-r--r-- | include/dba.php | 289 | ||||
-rw-r--r-- | include/dba/dba_driver.php | 164 | ||||
-rw-r--r-- | include/dba/dba_mysql.php | 63 | ||||
-rw-r--r-- | include/dba/dba_mysqli.php | 71 | ||||
-rw-r--r-- | include/dir_fns.php | 43 | ||||
-rwxr-xr-x | include/items.php | 39 | ||||
-rw-r--r-- | include/network.php | 55 | ||||
-rw-r--r-- | include/photo/photo_driver.php (renamed from include/Photo.php) | 457 | ||||
-rw-r--r-- | include/photo/photo_gd.php | 140 | ||||
-rw-r--r-- | include/photo/photo_imagick.php | 177 | ||||
-rw-r--r-- | include/photos.php | 4 | ||||
-rw-r--r-- | include/poller.php | 15 | ||||
-rw-r--r-- | include/zot.php | 17 |
17 files changed, 895 insertions, 689 deletions
diff --git a/include/Contact.php b/include/Contact.php index a49cc335f..b2d459ca4 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -247,7 +247,7 @@ function contact_remove($channel_id, $abook_id) { intval($channel_id) ); - q("delete from abook where abook_id = %d and channel_id = %d limit 1", + q("delete from abook where abook_id = %d and abook_channel = %d limit 1", intval($abook['abook_id']), intval($channel_id) ); diff --git a/include/bbcode.php b/include/bbcode.php index 44bde9acb..7a1e3a5e8 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -268,7 +268,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1<a href="$2" >$2</a>', $Text); -// $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)\{zid\}($urlchars*)/ism", '$1<a class="zrl" href="$2$3" >$2$3</a>', $Text); $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); diff --git a/include/cli_startup.php b/include/cli_startup.php index 863f97d7c..1be58d855 100644 --- a/include/cli_startup.php +++ b/include/cli_startup.php @@ -14,8 +14,8 @@ function cli_startup() { if(is_null($db)) { @include(".htconfig.php"); - require_once("dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); + require_once('include/dba/dba_driver.php'); + $db = dba_factory($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); }; diff --git a/include/conversation.php b/include/conversation.php index 882d108f5..a615dfcc5 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -375,6 +375,20 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { $ssl_state = ((local_user()) ? true : false); + + $arr_blocked = null; + + if(local_user()) { + $str_blocked = get_pconfig(local_user(),'system','blocked'); + if($str_blocked) { + $arr_blocked = explode(',',$str_blocked); + for($x = 0; $x < count($arr_blocked); $x ++) + $arr_blocked[$x] = trim($arr_blocked[$x]); + } + + } + + $profile_owner = 0; $page_writeable = false; $live_update_div = ''; @@ -497,10 +511,27 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display + + + + //$tpl = get_markup_template('search_item.tpl'); $tpl = 'search_item.tpl'; foreach($items as $item) { + + if($arr_blocked) { + $blocked = false; + foreach($arr_blocked as $b) { + if(($b) && ($item['author_xchan'] == $b)) { + $blocked = true; + break; + } + } + if($blocked) + continue; + } + $threadsid++; $comment = ''; @@ -672,6 +703,18 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { $threads = array(); foreach($items as $item) { + if($arr_blocked) { + $blocked = false; + foreach($arr_blocked as $b) { + if(($b) && ($item['author_xchan'] == $b)) { + $blocked = true; + break; + } + } + if($blocked) + continue; + } + // Can we put this after the visibility check? like_puller($a,$item,$alike,'like'); diff --git a/include/dba.php b/include/dba.php deleted file mode 100644 index 004bff423..000000000 --- a/include/dba.php +++ /dev/null @@ -1,289 +0,0 @@ -<?php /** @file */ - -require_once('include/datetime.php'); - -/** - * - * MySQL database class - * - * For debugging, insert 'dbg(1);' anywhere in the program flow. - * dbg(0); will turn it off. Logging is performed at LOGGER_DATA level. - * When logging, all binary info is converted to text and html entities are escaped so that - * the debugging stream is safe to view within both terminals and web pages. - * - */ - - -class dba { - - private $debug = 0; - private $db; - public $mysqli = true; - public $connected = false; - public $error = false; - - function __construct($server,$user,$pass,$db,$install = false) { - - $server = trim($server); - $user = trim($user); - $pass = trim($pass); - $db = trim($db); - - if (!(strlen($server) && strlen($user))){ - $this->connected = false; - $this->db = null; - return; - } - - if($install) { - if(strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) { - if(! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) { - $this->error = sprintf( t('Cannot locate DNS info for database server \'%s\''), $server); - $this->connected = false; - $this->db = null; - return; - } - } - } - - if(class_exists('mysqli')) { - $this->db = @new mysqli($server,$user,$pass,$db); - if(! mysqli_connect_errno()) { - $this->connected = true; - } - } - else { - $this->mysqli = false; - $this->db = mysql_connect($server,$user,$pass); - if($this->db && mysql_select_db($db,$this->db)) { - $this->connected = true; - } - } - if(! $this->connected) { - $this->db = null; - if(! $install) - system_unavailable(); - } - } - - public function getdb() { - return $this->db; - } - - public function q($sql) { - global $a; - - if((! $this->db) || (! $this->connected)) - return false; - - $this->error = ''; - - if(x($a->config,'system') && x($a->config['system'],'db_log')) - $stamp1 = microtime(true); - - if($this->mysqli) - $result = @$this->db->query($sql); - else - $result = @mysql_query($sql,$this->db); - - if(x($a->config,'system') && x($a->config['system'],'db_log')) { - $stamp2 = microtime(true); - $duration = round($stamp2-$stamp1, 3); - if ($duration > $a->config["system"]["db_loglimit"]) { - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - @file_put_contents($a->config["system"]["db_log"], $duration."\t". - basename($backtrace[1]["file"])."\t". - $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". - substr($sql, 0, 2000)."\n", FILE_APPEND); - } - } - - if($this->mysqli) { - if($this->db->errno) - $this->error = $this->db->error; - } - elseif(mysql_errno($this->db)) - $this->error = mysql_error($this->db); - - if(strlen($this->error)) { - logger('dba: ' . $this->error); - } - - if($this->debug) { - - $mesg = ''; - - if($result === false) - $mesg = 'false'; - elseif($result === true) - $mesg = 'true'; - else { - if($this->mysqli) - $mesg = $result->num_rows . ' results' . EOL; - else - $mesg = mysql_num_rows($result) . ' results' . EOL; - } - - $str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg - . (($this->error) ? ' error: ' . $this->error : '') - . EOL; - - logger('dba: ' . $str ); - } - - /** - * If dbfail.out exists, we will write any failed calls directly to it, - * regardless of any logging that may or may nor be in effect. - * These usually indicate SQL syntax errors that need to be resolved. - */ - - if($result === false) { - logger('dba: ' . printable($sql) . ' returned false.' . "\n" . $this->error); - if(file_exists('dbfail.out')) - file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); - } - - if(($result === true) || ($result === false)) - return $result; - - $r = array(); - if($this->mysqli) { - if($result->num_rows) { - while($x = $result->fetch_array(MYSQLI_ASSOC)) - $r[] = $x; - $result->free_result(); - } - } - else { - if(mysql_num_rows($result)) { - while($x = mysql_fetch_array($result, MYSQL_ASSOC)) - $r[] = $x; - mysql_free_result($result); - } - } - - - if($this->debug) - logger('dba: ' . printable(print_r($r, true))); - return($r); - } - - public function dbg($dbg) { - $this->debug = $dbg; - } - - public function escape($str) { - if($this->db && $this->connected) { - if($this->mysqli) - return @$this->db->real_escape_string($str); - else - return @mysql_real_escape_string($str,$this->db); - } - } - - function __destruct() { - if ($this->db) - if($this->mysqli) - $this->db->close(); - else - mysql_close($this->db); - } -} - - -function printable($s) { - $s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~",".", $s); - $s = str_replace("\x00",'.',$s); - if(x($_SERVER,'SERVER_NAME')) - $s = escape_tags($s); - return $s; -} - -// Procedural functions - -function dbg($state) { - global $db; - if($db) - $db->dbg($state); -} - - -function dbesc($str) { - global $db; - if($db && $db->connected) - return($db->escape($str)); - else - return(str_replace("'","\\'",$str)); -} - - - -// Function: q($sql,$args); -// Description: execute SQL query with printf style args. -// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", -// 'user', 1); - - -function q($sql) { - - global $db; - $args = func_get_args(); - unset($args[0]); - - if($db && $db->connected) { - $stmt = vsprintf($sql,$args); - if($stmt === false) - logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true)); - return $db->q($stmt); - } - - /** - * - * This will happen occasionally trying to store the - * session data after abnormal program termination - * - */ - logger('dba: no database: ' . print_r($args,true)); - return false; - -} - -/** - * - * Raw db query, no arguments - * - */ - - -function dbq($sql) { - - global $db; - if($db && $db->connected) - $ret = $db->q($sql); - else - $ret = false; - return $ret; -} - - -// Caller is responsible for ensuring that any integer arguments to -// dbesc_array are actually integers and not malformed strings containing -// SQL injection vectors. All integer array elements should be specifically -// cast to int to avoid trouble. - - - -function dbesc_array_cb(&$item, $key) { - if(is_string($item)) - $item = dbesc($item); -} - - - -function dbesc_array(&$arr) { - if(is_array($arr) && count($arr)) { - array_walk($arr,'dbesc_array_cb'); - } -} - - diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php new file mode 100644 index 000000000..1091b9632 --- /dev/null +++ b/include/dba/dba_driver.php @@ -0,0 +1,164 @@ +<?php /** @file */ + +function dba_factory($server,$user,$pass,$db,$install = false) { + $dba = null; + + if(class_exists('mysqli')) { + require_once('include/dba/dba_mysqli.php'); + $dba = new dba_mysqli($server,$user,$pass,$db,$install); + } + else { + require_once('include/dba/dba_mysql.php'); + $dba = new dba_mysql($server,$user,$pass,$db,$install); + } + + return $dba; +} + + +abstract class dba_driver { + + protected $debug = 0; + protected $db; + public $connected = false; + public $error = false; + + abstract function connect($server,$user,$pass,$db); + abstract function q($sql); + abstract function escape($str); + abstract function close(); + + function __construct($server,$user,$pass,$db,$install = false) { + if(($install) && (! $this->install($server,$user,$pass,$db))) { + return; + } + $this->connect($server,$user,$pass,$db); + } + + + function install($server,$user,$pass,$db) { + if (!(strlen($server) && strlen($user))){ + $this->connected = false; + $this->db = null; + return false; + } + + if(strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) { + if(! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) { + $this->error = sprintf( t('Cannot locate DNS info for database server \'%s\''), $server); + $this->connected = false; + $this->db = null; + return false; + } + } + } + + + function dbg($dbg) { + $this->debug = $dbg; + } + + function __destruct() { + if($this->db && $this->connected) { + $this->close(); + } + } + +} + + + +function printable($s) { + $s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~",".", $s); + $s = str_replace("\x00",'.',$s); + if(x($_SERVER,'SERVER_NAME')) + $s = escape_tags($s); + return $s; +} + +// Procedural functions + +function dbg($state) { + global $db; + if($db) + $db->dbg($state); +} + + +function dbesc($str) { + global $db; + if($db && $db->connected) + return($db->escape($str)); + else + return(str_replace("'","\\'",$str)); +} + + + +// Function: q($sql,$args); +// Description: execute SQL query with printf style args. +// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", +// 'user', 1); + + +function q($sql) { + + global $db; + $args = func_get_args(); + unset($args[0]); + + if($db && $db->connected) { + $stmt = vsprintf($sql,$args); + if($stmt === false) + logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true)); + return $db->q($stmt); + } + + /** + * + * This will happen occasionally trying to store the + * session data after abnormal program termination + * + */ + logger('dba: no database: ' . print_r($args,true)); + return false; + +} + +/** + * + * Raw db query, no arguments + * + */ + + +function dbq($sql) { + + global $db; + if($db && $db->connected) + $ret = $db->q($sql); + else + $ret = false; + return $ret; +} + + +// Caller is responsible for ensuring that any integer arguments to +// dbesc_array are actually integers and not malformed strings containing +// SQL injection vectors. All integer array elements should be specifically +// cast to int to avoid trouble. + + + +function dbesc_array_cb(&$item, $key) { + if(is_string($item)) + $item = dbesc($item); +} + + + +function dbesc_array(&$arr) { + if(is_array($arr) && count($arr)) { + array_walk($arr,'dbesc_array_cb'); + } +} diff --git a/include/dba/dba_mysql.php b/include/dba/dba_mysql.php new file mode 100644 index 000000000..05e19903d --- /dev/null +++ b/include/dba/dba_mysql.php @@ -0,0 +1,63 @@ +<?php + +require_once('include/dba/dba_driver.php'); + + +class dba_mysql extends dba_driver { + + function connect($server,$user,$pass,$db) { + $this->db = mysql_connect($server,$user,$pass); + if($this->db && mysql_select_db($db,$this->db)) { + $this->connected = true; + } + if($this->connected) { + return true; + } + return false; + } + + + function q($sql) { + if((! $this->db) || (! $this->connected)) + return false; + + $this->error = ''; + $result = @mysql_query($sql,$this->db); + + + if(mysql_errno($this->db)) + $this->error = mysql_error($this->db); + + if($result === false || $this->error) { + logger('dba_mysql: ' . printable($sql) . ' returned false.' . "\n" . $this->error); + if(file_exists('dbfail.out')) + file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); + } + + if(($result === true) || ($result === false)) + return $result; + + $r = array(); + if(mysql_num_rows($result)) { + while($x = mysql_fetch_array($result,MYSQL_ASSOC)) + $r[] = $x; + mysql_free_result($result); + if($this->debug) + logger('dba_mysql: ' . printable(print_r($r,true))); + } + return $r; + } + + function escape($str) { + if($this->db && $this->connected) { + return @mysql_real_escape_string($str,$this->db); + } + } + + function close() { + if($this->db) + mysql_close($this->db); + $this->connected = false; + } + +} diff --git a/include/dba/dba_mysqli.php b/include/dba/dba_mysqli.php new file mode 100644 index 000000000..af9a2434e --- /dev/null +++ b/include/dba/dba_mysqli.php @@ -0,0 +1,71 @@ +<?php /** @file */ + +require_once('include/dba/dba_driver.php'); + +class dba_mysqli extends dba_driver { + + function connect($server,$user,$pass,$db) { + $this->db = new mysqli($server,$user,$pass,$db); + if(! mysqli_connect_errno()) { + $this->connected = true; + } + if($this->connected) { + return true; + } + return false; + } + + function q($sql) { + if((! $this->db) || (! $this->connected)) + return false; + + $this->error = ''; + $result = $this->db->query($sql); + + if($this->db->errno) + $this->error = $this->db->error; + + + if($this->error) { + logger('dba_mysqli: ERROR: ' . printable($sql) . "\n" . $this->error); + if(file_exists('dbfail.out')) { + file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND); + } + } + + if(($result === true) || ($result === false)) { + if($this->debug) { + logger('dba_mysqli: DEBUG: returns ' . (($result) ? 'true' : 'false')); + } + return $result; + } + + if($this->debug) { + logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returned ' . $result->num_rows . ' results.'); + } + + $r = array(); + if($result->num_rows) { + while($x = $result->fetch_array(MYSQLI_ASSOC)) + $r[] = $x; + $result->free_result(); + if($this->debug) { + logger('dba_mysqli: ' . printable(print_r($r,true))); + } + } + return $r; + } + + function escape($str) { + if($this->db && $this->connected) { + return @$this->db->real_escape_string($str); + } + } + + function close() { + if($this->db) + $this->db->close(); + $this->connected = flase; + } + +}
\ No newline at end of file diff --git a/include/dir_fns.php b/include/dir_fns.php index 677420c54..5a1d671cb 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -6,6 +6,49 @@ function find_upstream_directory($dirmode) { return ''; } + +function sync_directories($dirmode) { + + if($dirmode == DIRECTORY_MODE_STANDALONE || $dirmode == DIRECTORY_MODE_NORMAL) + return; + + $r = q("select * from site where (site_flags & %d) and site_url != '%s'", + intval(DIRECTORY_MODE_PRIMARY), + dbesc(z_root()) + ); + + // If there are no directory servers, setup the fallback master + + if((! $r) && (z_root() != DIRECTORY_FALLBACK_MASTER)) { + $r = array( + 'site_url' => DIRECTORY_FALLBACK_MASTER, + 'site_flags' => DIRECTORY_MODE_PRIMARY, + 'site_update' => '0000-00-00 00:00:00', + 'site_directory' => DIRECTORY_FALLBACK_MASTER . '/dirsearch' + ); + $x = q("insert into site ( site_url, site_flags, site_update, site_directory ) + values ( '%s', %d', '%s', '%s' ) ", + dbesc($r[0]['site_url']), + intval($r[0]['site_flags']), + dbesc($r[0]['site_update']), + dbesc($r[0]['site_directory']) + ); + + } + + + + + + +} + + + + + + + function syncdirs($uid) { logger('syncdirs', LOGGER_DEBUG); diff --git a/include/items.php b/include/items.php index 034d27256..2a85556df 100755 --- a/include/items.php +++ b/include/items.php @@ -3,7 +3,7 @@ require_once('include/bbcode.php'); require_once('include/oembed.php'); require_once('include/crypto.php'); -require_once('include/Photo.php'); +require_once('include/photo/photo_driver.php'); require_once('include/permissions.php'); @@ -54,6 +54,31 @@ function collect_recipients($item,&$private) { } /** + * @function red_zrl_callback + * preg_match function when fixing 'naked' links in mod item.php + * Check if we've got a hubloc for the site and use a zrl if we do, a url if we don't. + * + */ + + +function red_zrl_callback($matches) { + $m = @parse_url($matches[2]); + $zrl = false; + if($m['host']) { + $r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1", + dbesc($m['host']) + ); + if($r) + $zrl = true; + } + if($zrl) + return $matches[1] . '[zrl=' . $matches[2] . ']' . $matches[2] . '[/zrl]'; + return $matches[0]; +} + + + +/** * @function post_activity_item($arr) * * post an activity @@ -92,7 +117,7 @@ function post_activity_item($arr) { $arr['parent_mid'] = ((x($arr,'parent_mid')) ? $arr['parent_mid'] : $arr['mid']); $arr['thr_parent'] = ((x($arr,'thr_parent')) ? $arr['thr_parent'] : $arr['mid']); - $arr['owner_xchan'] = ((x($arr,'owner_xchan')) ? $arr['owner_xchan'] : $channel['channel_hash']); + $arr['owner_xchan'] = ((x($arr,'owner_xchan')) ? $arr['owner_xchan'] : $channel['channel_hash']); $arr['author_xchan'] = ((x($arr,'author_xchan')) ? $arr['author_xchan'] : $observer['xchan_hash']); $arr['verb'] = ((x($arr,'verb')) ? $arr['verb'] : ACTIVITY_POST); @@ -2408,7 +2433,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar_date'])) { logger('consume_feed: Updating photo for ' . $contact['name']); - require_once("Photo.php"); + $photo_failure = false; $have_photo = false; @@ -2429,7 +2454,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $type = guess_image_type($photo_url,true); - $img = new Photo($img_str, $type); + $img = photo_factory($img_str, $type); if($img->is_valid()) { if($have_photo) { q("DELETE FROM `photo` WHERE `resource_id` = '%s' AND `contact-id` = %d AND `uid` = %d", @@ -2954,7 +2979,7 @@ function local_delivery($importer,$data) { if(($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $importer['avatar_date'])) { logger('local_delivery: Updating photo for ' . $importer['name']); - require_once("Photo.php"); + $photo_failure = false; $have_photo = false; @@ -2975,7 +3000,7 @@ function local_delivery($importer,$data) { $type = guess_image_type($photo_url,true); - $img = new Photo($img_str, $type); + $img = photo_factory($img_str, $type); if($img->is_valid()) { if($have_photo) { q("DELETE FROM `photo` WHERE `resource_id` = '%s' AND `contact-id` = %d AND `uid` = %d", @@ -4185,7 +4210,7 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) { $width = intval($match[1]); $height = intval($match[2]); - $ph = new Photo($data, $type); + $ph = photo_factory($data, $type); if($ph->is_valid()) { $ph->scaleImage(max($width, $height)); $data = $ph->imageString(); diff --git a/include/network.php b/include/network.php index d3e6480d6..f750fcfd8 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(); - } @@ -1051,7 +1051,8 @@ function scale_external_images($s, $include_link = true, $scale_replace = false) $matches = null; $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER); if($c) { - require_once('include/Photo.php'); + require_once('include/photo/photo_driver.php'); + foreach($matches as $mtch) { logger('scale_external_image: ' . $mtch[1]); @@ -1080,7 +1081,7 @@ function scale_external_images($s, $include_link = true, $scale_replace = false) $type = guess_image_type($mtch[1],true); if($i) { - $ph = new Photo($i, $type); + $ph = photo_factory($i, $type); if($ph->is_valid()) { $orig_width = $ph->getWidth(); $orig_height = $ph->getHeight(); diff --git a/include/Photo.php b/include/photo/photo_driver.php index 8daac450e..27237c530 100644 --- a/include/Photo.php +++ b/include/photo/photo_driver.php @@ -1,166 +1,92 @@ <?php /** @file */ +function photo_factory($data, $type = null) { + $ph = null; -class Photo { - - private $image; - - /** - * Put back gd stuff, not everybody have Imagick - */ - private $imagick; - private $width; - private $height; - private $valid; - private $type; - private $types; - - /** - * supported mimetypes and corresponding file extensions - */ - static function supportedTypes() { - if(class_exists('Imagick')) { - /** - * Imagick::queryFormats won't help us a lot there... - * At least, not yet, other parts of friendica uses this array - */ - $t = array( - 'image/jpeg' => 'jpg', - 'image/png' => 'png', - 'image/gif' => 'gif' - ); - } else { - $t = array(); - $t['image/jpeg'] ='jpg'; - if (imagetypes() & IMG_PNG) $t['image/png'] = 'png'; - } - - return $t; + if(class_exists('Imagick')) { + require_once('include/photo/photo_imagick.php'); + $ph = new photo_imagick($data,$type); + } + else { + require_once('include/photo/photo_gd.php'); + $ph = new photo_gd($data,$type); } - public function __construct($data, $type=null) { - $this->imagick = class_exists('Imagick'); - $this->types = $this->supportedTypes(); - if (!array_key_exists($type,$this->types)){ - $type='image/jpeg'; - } - $this->type = $type; + return $ph; +} - if($this->is_imagick()) { - $this->image = new Imagick(); - $this->image->readImageBlob($data); - /** - * Setup the image to the format it will be saved to - */ - $map = $this->get_FormatsMap(); - $format = $map[$type]; - $this->image->setFormat($format); - // Always coalesce, if it is not a multi-frame image it won't hurt anyway - $this->image = $this->image->coalesceImages(); - /** - * setup the compression here, so we'll do it only once - */ - switch($this->getType()){ - case "image/png": - $quality = get_config('system','png_quality'); - if((! $quality) || ($quality > 9)) - $quality = PNG_QUALITY; - /** - * From http://www.imagemagick.org/script/command-line-options.php#quality: - * - * 'For the MNG and PNG image formats, the quality value sets - * the zlib compression level (quality / 10) and filter-type (quality % 10). - * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering, - * unless the image has a color map, in which case it means compression level 7 with no PNG filtering' - */ - $quality = $quality * 10; - $this->image->setCompressionQuality($quality); - break; - case "image/jpeg": - $quality = get_config('system','jpeg_quality'); - if((! $quality) || ($quality > 100)) - $quality = JPEG_QUALITY; - $this->image->setCompressionQuality($quality); - } - } else { - $this->valid = false; - $this->image = @imagecreatefromstring($data); - if($this->image !== FALSE) { - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - $this->valid = true; - imagealphablending($this->image, false); - imagesavealpha($this->image, true); - } - } - } +abstract class photo_driver { - public function __destruct() { - if($this->image) { - if($this->is_imagick()) { - $this->image->clear(); - $this->image->destroy(); - return; - } - imagedestroy($this->image); - } - } + protected $image; + protected $width; + protected $height; + protected $valid; + protected $type; + protected $types; + + abstract function supportedTypes(); + + abstract function load($data,$type); + + abstract function destroy(); + + abstract function setDimensions(); + + abstract function getImage(); + + abstract function doScaleImage($new_width,$new_height); + + abstract function rotate($degrees); + + abstract function flip($horiz = true, $vert = false); + + abstract function cropImage($max,$x,$y,$w,$h); - public function is_imagick() { - return $this->imagick; + abstract function imageString(); + + + public function __construct($data, $type='') { + $this->types = $this->supportedTypes(); + if (! array_key_exists($type,$this->types)){ + $type='image/jpeg'; + } + $this->type = $type; + $this->valid = false; + $this->load($data,$type); } - /** - * Maps Mime types to Imagick formats - */ - public function get_FormatsMap() { - $m = array( - 'image/jpeg' => 'JPG', - 'image/png' => 'PNG', - 'image/gif' => 'GIF' - ); - return $m; + public function __destruct() { + if($this->is_valid()) + $this->destroy(); } public function is_valid() { - if($this->is_imagick()) - return ($this->image !== FALSE); return $this->valid; } public function getWidth() { if(!$this->is_valid()) return FALSE; - - if($this->is_imagick()) - return $this->image->getImageWidth(); return $this->width; } public function getHeight() { if(!$this->is_valid()) return FALSE; - - if($this->is_imagick()) - return $this->image->getImageHeight(); return $this->height; } - public function getImage() { + + public function saveImage($path) { if(!$this->is_valid()) return FALSE; - - if($this->is_imagick()) { - /* Clean it */ - $this->image = $this->image->deconstructImages(); - return $this->image; - } - return $this->image; + file_put_contents($path, $this->imageString()); } + public function getType() { if(!$this->is_valid()) return FALSE; @@ -234,95 +160,72 @@ class Photo { } } } + $this->doScaleImage($dest_width,$dest_height); + } + public function scaleImageUp($min) { + if(!$this->is_valid()) + return FALSE; - if($this->is_imagick()) { - /** - * If it is not animated, there will be only one iteration here, - * so don't bother checking - */ - // Don't forget to go back to the first frame - $this->image->setFirstIterator(); - do { - // FIXME - implement horizantal bias for scaling as in followin GD functions - // to allow very tall images to be constrained only horizontally. + $width = $this->width; + $height = $this->height; - $this->image->scaleImage($dest_width, $dest_height); - } while ($this->image->nextImage()); + $dest_width = $dest_height = 0; - // FIXME - also we need to copy the new dimensions to $this->height, $this->width as other functions - // may rely on it. + if((! $width)|| (! $height)) + return FALSE; - return; + if($width < $min && $height < $min) { + if($width > $height) { + $dest_width = $min; + $dest_height = intval(( $height * $min ) / $width); + } + else { + $dest_width = intval(( $width * $min ) / $height); + $dest_height = $min; + } } - - - $dest = imagecreatetruecolor( $dest_width, $dest_height ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); + else { + if( $width < $min ) { + $dest_width = $min; + $dest_height = intval(( $height * $min ) / $width); + } + else { + if( $height < $min ) { + $dest_width = intval(( $width * $min ) / $height); + $dest_height = $min; + } + else { + $dest_width = $width; + $dest_height = $height; + } + } + } + $this->doScaleImage($dest_width,$dest_height); } - public function rotate($degrees) { + public function scaleImageSquare($dim) { if(!$this->is_valid()) return FALSE; - - if($this->is_imagick()) { - $this->image->setFirstIterator(); - do { - $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate() - } while ($this->image->nextImage()); - return; - } - - $this->image = imagerotate($this->image,$degrees,0); - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); + $this->doScaleImage($dim,$dim); } - public function flip($horiz = true, $vert = false) { - if(!$this->is_valid()) - return FALSE; - if($this->is_imagick()) { - $this->image->setFirstIterator(); - do { - if($horiz) $this->image->flipImage(); - if($vert) $this->image->flopImage(); - } while ($this->image->nextImage()); - return; - } - $w = imagesx($this->image); - $h = imagesy($this->image); - $flipped = imagecreate($w, $h); - if($horiz) { - for ($x = 0; $x < $w; $x++) { - imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h); - } - } - if($vert) { - for ($y = 0; $y < $h; $y++) { - imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1); - } - } - $this->image = $flipped; - } public function orient($filename) { - // based off comment on http://php.net/manual/en/function.imagerotate.php - if(!$this->is_valid()) + /** + * 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') ) + if((! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) return; $exif = @exif_read_data($filename); @@ -368,163 +271,6 @@ class Photo { } - - public function scaleImageUp($min) { - if(!$this->is_valid()) - return FALSE; - - - $width = $this->width; - $height = $this->height; - - $dest_width = $dest_height = 0; - - if((! $width)|| (! $height)) - return FALSE; - - if($width < $min && $height < $min) { - if($width > $height) { - $dest_width = $min; - $dest_height = intval(( $height * $min ) / $width); - } - else { - $dest_width = intval(( $width * $min ) / $height); - $dest_height = $min; - } - } - else { - if( $width < $min ) { - $dest_width = $min; - $dest_height = intval(( $height * $min ) / $width); - } - else { - if( $height < $min ) { - $dest_width = intval(( $width * $min ) / $height); - $dest_height = $min; - } - else { - $dest_width = $width; - $dest_height = $height; - } - } - } - - if($this->is_imagick()) - return $this->scaleImage($dest_width,$dest_height); - - $dest = imagecreatetruecolor( $dest_width, $dest_height ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - } - - - - public function scaleImageSquare($dim) { - if(!$this->is_valid()) - return FALSE; - - if($this->is_imagick()) { - $this->image->setFirstIterator(); - do { - $this->image->scaleImage($dim, $dim); - } while ($this->image->nextImage()); - return; - } - - $dest = imagecreatetruecolor( $dim, $dim ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - } - - - public function cropImage($max,$x,$y,$w,$h) { - if(!$this->is_valid()) - return FALSE; - - if($this->is_imagick()) { - $this->image->setFirstIterator(); - do { - $this->image->cropImage($w, $h, $x, $y); - /** - * We need to remove the canva, - * or the image is not resized to the crop: - * http://php.net/manual/en/imagick.cropimage.php#97232 - */ - $this->image->setImagePage(0, 0, 0, 0); - } while ($this->image->nextImage()); - return $this->scaleImage($max); - } - - $dest = imagecreatetruecolor( $max, $max ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - } - - public function saveImage($path) { - if(!$this->is_valid()) - return FALSE; - - $string = $this->imageString(); - file_put_contents($path, $string); - } - - public function imageString() { - if(!$this->is_valid()) - return FALSE; - - if($this->is_imagick()) { - /* Clean it */ - $this->image = $this->image->deconstructImages(); - $string = $this->image->getImagesBlob(); - return $string; - } - - $quality = FALSE; - - ob_start(); - - switch($this->getType()){ - case "image/png": - $quality = get_config('system','png_quality'); - if((! $quality) || ($quality > 9)) - $quality = PNG_QUALITY; - imagepng($this->image,NULL, $quality); - break; - case "image/jpeg": - $quality = get_config('system','jpeg_quality'); - if((! $quality) || ($quality > 100)) - $quality = JPEG_QUALITY; - imagejpeg($this->image,NULL,$quality); - } - $string = ob_get_contents(); - ob_end_clean(); - - return $string; - } - - - public function store($aid, $uid, $xchan, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { $x = q("select id from photo where `resource_id` = '%s' and uid = %d and `xchan` = '%s' and `scale` = %d limit 1", @@ -605,15 +351,18 @@ class Photo { } return $r; } + } + /** * Guess image mimetype from filename or from Content-Type header * * @arg $filename string Image filename * @arg $fromcurl boolean Check Content-Type header from curl request */ + function guess_image_type($filename, $fromcurl=false) { logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG); $type = null; diff --git a/include/photo/photo_gd.php b/include/photo/photo_gd.php new file mode 100644 index 000000000..466f8c23a --- /dev/null +++ b/include/photo/photo_gd.php @@ -0,0 +1,140 @@ +<?php /** @file */ + + +require_once('include/photo/photo_driver.php'); + + +class photo_gd extends photo_driver { + + function supportedTypes() { + $t = array(); + $t['image/jpeg'] ='jpg'; + if (imagetypes() & IMG_PNG) $t['image/png'] = 'png'; + + return $t; + + } + + function load($data, $type) { + $this->valid = false; + if(! $data) + return; + + $this->image = @imagecreatefromstring($data); + if($this->image !== FALSE) { + $this->valid = true; + $this->setDimensions(); + imagealphablending($this->image, false); + imagesavealpha($this->image, true); + } + } + + function setDimensions() { + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } + + + public function destroy() { + if($this->is_valid()) { + imagedestroy($this->image); + } + } + + public function getImage() { + if(!$this->is_valid()) + return FALSE; + + return $this->image; + } + + public function doScaleImage($dest_width,$dest_height) { + + $dest = imagecreatetruecolor( $dest_width, $dest_height ); + $width = imagesx($this->image); + $height = imagesy($this->image); + + imagealphablending($dest, false); + imagesavealpha($dest, true); + if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha + imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->setDimensions(); + } + + public function rotate($degrees) { + if(!$this->is_valid()) + return FALSE; + + $this->image = imagerotate($this->image,$degrees,0); + $this->setDimensions(); + } + + public function flip($horiz = true, $vert = false) { + if(!$this->is_valid()) + return FALSE; + + $w = imagesx($this->image); + $h = imagesy($this->image); + $flipped = imagecreate($w, $h); + if($horiz) { + for ($x = 0; $x < $w; $x++) { + imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h); + } + } + if($vert) { + for ($y = 0; $y < $h; $y++) { + imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1); + } + } + $this->image = $flipped; + $this->setDimensions(); // Shouldn't really be necessary + } + + public function cropImage($max,$x,$y,$w,$h) { + if(!$this->is_valid()) + return FALSE; + + $dest = imagecreatetruecolor( $max, $max ); + imagealphablending($dest, false); + imagesavealpha($dest, true); + if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha + imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->setDimensions(); + } + + public function imageString() { + if(!$this->is_valid()) + return FALSE; + + $quality = FALSE; + + ob_start(); + + switch($this->getType()){ + case "image/png": + $quality = get_config('system','png_quality'); + if((! $quality) || ($quality > 9)) + $quality = PNG_QUALITY; + 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(); + + return $string; + } + +}
\ No newline at end of file diff --git a/include/photo/photo_imagick.php b/include/photo/photo_imagick.php new file mode 100644 index 000000000..2737c8f69 --- /dev/null +++ b/include/photo/photo_imagick.php @@ -0,0 +1,177 @@ +<?php /** @file */ + + +require_once('include/photo/photo_driver.php'); + + +class photo_imagick extends photo_driver { + + + function supportedTypes() { + return array( + 'image/jpeg' => 'jpg', + 'image/png' => 'png', + 'image/gif' => 'gif' + ); + } + + public function get_FormatsMap() { + return array( + 'image/jpeg' => 'JPG', + 'image/png' => 'PNG', + 'image/gif' => 'GIF' + ); + } + + + function load($data, $type) { + $this->valid = false; + $this->image = new Imagick(); + + if(! $data) + return; + + $this->image->readImageBlob($data); + + + /** + * Setup the image to the format it will be saved to + */ + + $map = $this->get_FormatsMap(); + $format = $map[$type]; + + if($this->image) { + $this->image->setFormat($format); + + // Always coalesce, if it is not a multi-frame image it won't hurt anyway + $this->image = $this->image->coalesceImages(); + + + $this->valid = true; + $this->setDimensions(); + + /** + * setup the compression here, so we'll do it only once + */ + switch($this->getType()) { + case "image/png": + $quality = get_config('system','png_quality'); + if((! $quality) || ($quality > 9)) + $quality = PNG_QUALITY; + /** + * From http://www.imagemagick.org/script/command-line-options.php#quality: + * + * 'For the MNG and PNG image formats, the quality value sets + * the zlib compression level (quality / 10) and filter-type (quality % 10). + * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering, + * unless the image has a color map, in which case it means compression level 7 with no PNG filtering' + */ + $quality = $quality * 10; + $this->image->setCompressionQuality($quality); + break; + case "image/jpeg": + $quality = get_config('system','jpeg_quality'); + if((! $quality) || ($quality > 100)) + $quality = JPEG_QUALITY; + $this->image->setCompressionQuality($quality); + default: + break; + + } + } + } + + public function destroy() { + if($this->is_valid()) { + $this->image->clear(); + $this->image->destroy(); + } + } + + + public function setDimensions() { + $this->width = $this->image->getImageWidth(); + $this->height = $this->image->getImageHeight(); + } + + + public function getImage() { + if(!$this->is_valid()) + return FALSE; + + $this->image = $this->image->deconstructImages(); + return $this->image; + } + + public function doScaleImage($dest_width,$dest_height) { + + /** + * If it is not animated, there will be only one iteration here, + * so don't bother checking + */ + // Don't forget to go back to the first frame + $this->image->setFirstIterator(); + do { + $this->image->scaleImage($dest_width, $dest_height); + } while ($this->image->nextImage()); + + $this->setDimensions(); + } + + public function rotate($degrees) { + if(!$this->is_valid()) + return FALSE; + + $this->image->setFirstIterator(); + do { + // ImageMagick rotates in the opposite direction of imagerotate() + $this->image->rotateImage(new ImagickPixel(), -$degrees); + } while ($this->image->nextImage()); + + $this->setDimensions(); + } + + public function flip($horiz = true, $vert = false) { + if(!$this->is_valid()) + return FALSE; + + $this->image->setFirstIterator(); + do { + if($horiz) $this->image->flipImage(); + if($vert) $this->image->flopImage(); + } while ($this->image->nextImage()); + + $this->setDimensions(); // Shouldn't really be necessary + } + + public function cropImage($max,$x,$y,$w,$h) { + if(!$this->is_valid()) + return FALSE; + + $this->image->setFirstIterator(); + do { + $this->image->cropImage($w, $h, $x, $y); + /** + * We need to remove the canva, + * or the image is not resized to the crop: + * http://php.net/manual/en/imagick.cropimage.php#97232 + */ + $this->image->setImagePage(0, 0, 0, 0); + } while ($this->image->nextImage()); + + $this->doScaleImage($max); + } + + public function imageString() { + if(!$this->is_valid()) + return FALSE; + + /* Clean it */ + $this->image = $this->image->deconstructImages(); + return $this->image->getImagesBlob(); + } + + + +}
\ No newline at end of file diff --git a/include/photos.php b/include/photos.php index 123cd0659..fae01ba80 100644 --- a/include/photos.php +++ b/include/photos.php @@ -2,6 +2,8 @@ require_once('include/permissions.php'); require_once('include/items.php'); +require_once('include/photo/photo_driver.php'); + function photo_upload($channel, $observer, $args) { @@ -116,7 +118,7 @@ function photo_upload($channel, $observer, $args) { } - $ph = new Photo($imagedata, $type); + $ph = photo_factory($imagedata, $type); if(! $ph->is_valid()) { $ret['message'] = t('Unable to process image'); diff --git a/include/poller.php b/include/poller.php index 1dd065196..33e882735 100644 --- a/include/poller.php +++ b/include/poller.php @@ -50,16 +50,23 @@ function poller_run($argv, $argc){ if($d2 != intval($d1)) { + // If this is a directory server, request a sync with an upstream + // directory at least once a day, up to once every poll interval. + // Pull remote changes and push local changes. + // potential issue: how do we keep from creating an endless update loop? + + $dirmode = get_config('system','directory_mode'); + if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { + require_once('include/dir_fns.php'); + sync_directories($dirmode); + } + // update_suggestions(); set_config('system','last_expire_day',$d2); proc_run('php','include/expire.php'); } - // If this is a directory server, request a sync with an upstream - // directory at least once a day, up to once every poll interval. - // Pull remote changes and push local changes. - // potential issue: how do we keep from creating an endless update loop? $manual_id = 0; $generation = 0; diff --git a/include/zot.php b/include/zot.php index a06ae352b..e450304bd 100644 --- a/include/zot.php +++ b/include/zot.php @@ -375,14 +375,16 @@ function zot_refresh($them,$channel = null) { else { logger('zot_refresh: importing profile if available'); + logger('zot_refresh: import profile: ' . print_r($x,true), LOGGER_DATA); // Are we a directory server of some kind? $dirmode = intval(get_config('system','directory_mode')); if($dirmode != DIRECTORY_MODE_NORMAL) { - if(array_key_exists('profile',$x) && is_array($x['profile'])) { - import_directory_profile($x['hash'],$x['profile']); + if(array_key_exists('profile',$j) && is_array($j['profile'])) { + import_directory_profile($x['hash'],$j['profile']); } else { + logger('zot_refresh: profile not available - hiding'); // they may have made it private $r = q("delete from xprof where xprof_hash = '%s' limit 1", dbesc($x['hash']) @@ -475,6 +477,9 @@ function import_xchan($arr) { return $ret; } + + logger('import_xchan: ' . $xchan_hash, LOGGER_DEBUG); + $r = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($xchan_hash) ); @@ -517,6 +522,10 @@ function import_xchan($arr) { dbesc($arr['url']), dbesc($xchan_hash) ); + + logger('import_xchan: existing: ' . print_r($r[0],true), LOGGER_DATA); + logger('import_xchan: new: ' . print_r($arr,true), LOGGER_DATA); + update_modtime($xchan_hash); $changed = true; } @@ -563,7 +572,7 @@ function import_xchan($arr) { if($import_photos) { - require_once("Photo.php"); + require_once('include/photo/photo_driver.php'); $photos = import_profile_photo($arr['photo'],$xchan_hash); $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' @@ -865,6 +874,8 @@ function zot_import($arr) { $result = process_profile_delivery($i['notify']['sender'],$arr,$deliveries); } + + } if($result) $return = array_merge($return,$result); |