Merge remote branch 'upstream/master'

This commit is contained in:
Michael Vogel 2012-10-19 07:12:15 +02:00
commit 28b085569a
235 changed files with 43249 additions and 13965 deletions

View file

@ -129,11 +129,12 @@ class Photo {
$this->image->setCompressionQuality($quality);
}
$this->width = $this->image->getImageWidth();
// The 'width' and 'height' properties are only used by non-Imagick routines.
$this->width = $this->image->getImageWidth();
$this->height = $this->image->getImageHeight();
$this->valid = true;
return true;
return true;
}
$this->valid = false;
@ -205,21 +206,8 @@ class Photo {
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 {
$this->image->resizeImage($max, $max, imagick::FILTER_LANCZOS, 1, true);
} while ($this->image->nextImage());
return;
}
$width = $this->width;
$height = $this->height;
$width = $this->getWidth();
$height = $this->getHeight();
$dest_width = $dest_height = 0;
@ -227,7 +215,18 @@ class Photo {
return FALSE;
if($width > $max && $height > $max) {
if($width > $height) {
// very tall image (greater than 16:9)
// constrain the width - let the height float.
if((($height * 9) / 16) > $width) {
$dest_width = $max;
$dest_height = intval(( $height * $max ) / $width);
}
// else constrain both dimensions
elseif($width > $height) {
$dest_width = $max;
$dest_height = intval(( $height * $max ) / $width);
}
@ -243,8 +242,18 @@ class Photo {
}
else {
if( $height > $max ) {
$dest_width = intval(( $width * $max ) / $height);
$dest_height = $max;
// very tall image (greater than 16:9)
// but width is OK - don't do anything
if((($height * 9) / 16) > $width) {
$dest_width = $width;
$dest_height = $height;
}
else {
$dest_width = intval(( $width * $max ) / $height);
$dest_height = $max;
}
}
else {
$dest_width = $width;
@ -254,6 +263,29 @@ class Photo {
}
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.
$this->image->scaleImage($dest_width, $dest_height);
} while ($this->image->nextImage());
// These may not be necessary any more
$this->width = $this->image->getImageWidth();
$this->height = $this->image->getImageHeight();
return;
}
$dest = imagecreatetruecolor( $dest_width, $dest_height );
imagealphablending($dest, false);
imagesavealpha($dest, true);
@ -371,11 +403,9 @@ class Photo {
if(!$this->is_valid())
return FALSE;
if($this->is_imagick())
return $this->scaleImage($min);
$width = $this->width;
$height = $this->height;
$width = $this->getWidth();
$height = $this->getHeight();
$dest_width = $dest_height = 0;
@ -409,6 +439,8 @@ class Photo {
}
}
if($this->is_imagick())
return $this->scaleImage($dest_width,$dest_height);
$dest = imagecreatetruecolor( $dest_width, $dest_height );
imagealphablending($dest, false);
@ -431,7 +463,7 @@ class Photo {
if($this->is_imagick()) {
$this->image->setFirstIterator();
do {
$this->image->resizeImage($dim, $dim, imagick::FILTER_LANCZOS, 1, false);
$this->image->scaleImage($dim, $dim);
} while ($this->image->nextImage());
return;
}
@ -453,19 +485,19 @@ class Photo {
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);
}
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);
@ -633,7 +665,7 @@ function guess_image_type($filename, $fromcurl=false) {
}
if (is_null($type)){
// Guessing from extension? Isn't that... dangerous?
if(class_exists('Imagick')) {
if(class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
/**
* Well, this not much better,
* but at least it comes from the data inside the image,

View file

@ -458,10 +458,10 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$poll = 'email ' . random_string();
$priority = 0;
$x = email_msg_meta($mbox,$msgs[0]);
if(stristr($x->from,$orig_url))
$adr = imap_rfc822_parse_adrlist($x->from,'');
elseif(stristr($x->to,$orig_url))
$adr = imap_rfc822_parse_adrlist($x->to,'');
if(stristr($x[0]->from,$orig_url))
$adr = imap_rfc822_parse_adrlist($x[0]->from,'');
elseif(stristr($x[0]->to,$orig_url))
$adr = imap_rfc822_parse_adrlist($x[0]->to,'');
if(isset($adr)) {
foreach($adr as $feadr) {
if((strcasecmp($feadr->mailbox,$name) == 0)
@ -554,6 +554,13 @@ function probe_url($url, $mode = PROBE_NORMAL) {
logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA);
}
if($diaspora && $addr) {
// Diaspora returns the name as the nick. As the nick will never be updated,
// let's use the Diaspora nickname (the first part of the handle) as the nick instead
$addr_parts = explode('@', $addr);
$vcard['nick'] = $addr_parts[0];
}
if($twitter) {
logger('twitter: setup');
$tid = basename($url);

View file

@ -374,33 +374,79 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$ssl_state = ((local_user()) ? true : false);
$profile_owner = 0;
$page_writeable = false;
$page_writeable = false;
$live_update_div = '';
$previewing = (($preview) ? ' preview ' : '');
if($mode === 'network') {
$profile_owner = local_user();
$page_writeable = true;
}
if(!$update) {
// The special div is needed for liveUpdate to kick in for this page.
// We only launch liveUpdate if you aren't filtering in some incompatible
// way and also you aren't writing a comment (discovered in javascript).
if($mode === 'profile') {
$live_update_div = '<div id="live-network"></div>' . "\r\n"
. "<script> var profile_uid = " . $_SESSION['uid']
. "; var netargs = '" . substr($a->cmd,8)
. '?f='
. ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
. ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
. ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
. ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
. ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
. ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
. ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
. ((x($_GET,'spam')) ? '&spam=' . $_GET['spam'] : '')
. ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
. ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
. ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
. ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '')
. "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
}
}
else if($mode === 'profile') {
$profile_owner = $a->profile['profile_uid'];
$page_writeable = can_write_wall($a,$profile_owner);
}
if($mode === 'notes') {
if(!$update) {
$tab = notags(trim($_GET['tab']));
if($tab === 'posts') {
// This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
// because browser prefetching might change it on us. We have to deliver it with the page.
$live_update_div = '<div id="live-profile"></div>' . "\r\n"
. "<script> var profile_uid = " . $a->profile['profile_uid']
. "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
}
}
}
else if($mode === 'notes') {
$profile_owner = local_user();
$page_writeable = true;
if(!$update) {
$live_update_div = '<div id="live-notes"></div>' . "\r\n"
. "<script> var profile_uid = " . local_user()
. "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
}
}
if($mode === 'display') {
else if($mode === 'display') {
$profile_owner = $a->profile['uid'];
$page_writeable = can_write_wall($a,$profile_owner);
$live_update_div = '<div id="live-display"></div>' . "\r\n";
}
if($mode === 'community') {
else if($mode === 'community') {
$profile_owner = 0;
$page_writeable = false;
if(!$update) {
$live_update_div = '<div id="live-community"></div>' . "\r\n"
. "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
}
}
else if($mode === 'search') {
$live_update_div = '<div id="live-search"></div>' . "\r\n";
}
$page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
@ -630,7 +676,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$o = replace_macros($page_template, array(
'$baseurl' => $a->get_baseurl($ssl_state),
'$remove' => t('remove'),
'$live_update' => $live_update_div,
'$remove' => t('remove'),
'$mode' => $mode,
'$user' => $a->user,
'$threads' => $threads,

View file

@ -141,6 +141,17 @@ function diaspora_get_contact_by_handle($uid,$handle) {
);
if($r && count($r))
return $r[0];
$handle_parts = explode("@", $handle);
$nurl_sql = '%%://' . $handle_parts[1] . '%%/profile/' . $handle_parts[0];
$r = q("SELECT * FROM contact WHERE network = '%s' AND uid = %d AND nurl LIKE '%s' LIMIT 1",
dbesc(NETWORK_DFRN),
intval($uid),
dbesc($nurl_sql)
);
if($r && count($r))
return $r[0];
return false;
}
@ -1949,7 +1960,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
$contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
if(! $contact) {
logger('diaspora_signed_retraction: no contact');
logger('diaspora_signed_retraction: no contact ' . $diaspora_handle . ' for ' . $importer['uid']);
return;
}

View file

@ -48,8 +48,8 @@ function construct_mailbox_name($mailacct) {
function email_msg_meta($mbox,$uid) {
$ret = (($mbox && $uid) ? @imap_fetch_overview($mbox,$uid,FT_UID) : array(array()));
return ((count($ret)) ? $ret[0] : array());
$ret = (($mbox && $uid) ? @imap_fetch_overview($mbox,$uid,FT_UID) : array(array())); // POSSIBLE CLEANUP --> array(array()) is probably redundant now
return ((count($ret)) ? $ret : array());
}
function email_msg_headers($mbox,$uid) {

View file

@ -40,7 +40,7 @@ function group_add($uid,$name) {
function group_rmv($uid,$name) {
$ret = false;
if(x($uid) && x($name)) {
$r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
$r = q("SELECT id FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
intval($uid),
dbesc($name)
);
@ -49,6 +49,37 @@ function group_rmv($uid,$name) {
if(! $group_id)
return false;
// remove group from default posting lists
$r = q("SELECT def_gid, allow_gid, deny_gid FROM user WHERE uid = %d LIMIT 1",
intval($uid)
);
if($r) {
$user_info = $r[0];
$change = false;
if($user_info['def_gid'] == $group_id) {
$user_info['def_gid'] = 0;
$change = true;
}
if(strpos($user_info['allow_gid'], '<' . $group_id . '>') !== false) {
$user_info['allow_gid'] = str_replace('<' . $group_id . '>', '', $user_info['allow_gid']);
$change = true;
}
if(strpos($user_info['deny_gid'], '<' . $group_id . '>') !== false) {
$user_info['deny_gid'] = str_replace('<' . $group_id . '>', '', $user_info['deny_gid']);
$change = true;
}
if($change) {
q("UPDATE user SET def_gid = %d, allow_gid = '%s', deny_gid = '%s' WHERE uid = %d",
intval($user_info['def_gid']),
dbesc($user_info['allow_gid']),
dbesc($user_info['deny_gid']),
intval($uid)
);
}
}
// remove all members
$r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d ",
intval($uid),
@ -103,7 +134,7 @@ function group_add_member($uid,$name,$member,$gid = 0) {
if((! $gid) || (! $uid) || (! $member))
return false;
$r = q("SELECT * FROM `group_member` WHERE `uid` = %d AND `id` = %d AND `contact-id` = %d LIMIT 1",
$r = q("SELECT * FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d LIMIT 1",
intval($uid),
intval($gid),
intval($member)

View file

@ -291,36 +291,17 @@ function onepoll_run($argv, $argc){
if(count($msgs)) {
logger("Mail: Parsing ".count($msgs)." mails for ".$mailconf[0]['user'], LOGGER_DEBUG);
foreach($msgs as $msg_uid) {
$metas = email_msg_meta($mbox,implode(',',$msgs));
$msgs = array_combine($msgs, $metas);
foreach($msgs as $msg_uid => $meta) {
logger("Mail: Parsing mail ".$msg_uid, LOGGER_DATA);
$datarray = array();
$meta = email_msg_meta($mbox,$msg_uid);
$headers = email_msg_headers($mbox,$msg_uid);
// $meta = email_msg_meta($mbox,$msg_uid);
// $headers = email_msg_headers($mbox,$msg_uid);
// look for a 'references' header and try and match with a parent item we have locally.
$raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
$datarray['uri'] = msgid2iri(trim($meta->message_id,'<>'));
if($raw_refs) {
$refs_arr = explode(' ', $raw_refs);
if(count($refs_arr)) {
for($x = 0; $x < count($refs_arr); $x ++)
$refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
}
$qstr = implode(',',$refs_arr);
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
intval($importer_uid)
);
if(count($r))
$datarray['parent-uri'] = $r[0]['uri'];
}
if(! x($datarray,'parent-uri'))
$datarray['parent-uri'] = $datarray['uri'];
// Have we seen it before?
$r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
intval($importer_uid),
@ -328,15 +309,16 @@ function onepoll_run($argv, $argc){
);
if(count($r)) {
// logger("Mail: Seen before ".$msg_uid);
logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user']);
if($meta->deleted && ! $r[0]['deleted']) {
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($r[0]['id'])
);
}
switch ($mailconf[0]['action']) {
/*switch ($mailconf[0]['action']) {
case 0:
logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user'].". Doing nothing.", LOGGER_DEBUG);
break;
case 1:
logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']);
@ -352,10 +334,38 @@ function onepoll_run($argv, $argc){
if ($mailconf[0]['movetofolder'] != "")
imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);
break;
}
}*/
continue;
}
// look for a 'references' or an 'in-reply-to' header and try to match with a parent item we have locally.
// $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
$raw_refs = ((property_exists($meta,'references')) ? str_replace("\t",'',$meta->references) : '');
if(! trim($raw_refs))
$raw_refs = ((property_exists($meta,'in_reply_to')) ? str_replace("\t",'',$meta->in_reply_to) : '');
$raw_refs = trim($raw_refs); // Don't allow a blank reference in $refs_arr
if($raw_refs) {
$refs_arr = explode(' ', $raw_refs);
if(count($refs_arr)) {
for($x = 0; $x < count($refs_arr); $x ++)
$refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
}
$qstr = implode(',',$refs_arr);
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
intval($importer_uid)
);
if(count($r))
$datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item
// $datarray['parent-uri'] = $r[0]['uri'];
}
if(! x($datarray,'parent-uri'))
$datarray['parent-uri'] = $datarray['uri'];
// Decoding the header
$subject = imap_mime_header_decode($meta->subject);
$datarray['title'] = "";
@ -421,6 +431,7 @@ function onepoll_run($argv, $argc){
);
switch ($mailconf[0]['action']) {
case 0:
logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user'].". Doing nothing.", LOGGER_DEBUG);
break;
case 1:
logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']);

64
include/redir.php Normal file
View file

@ -0,0 +1,64 @@
<?php
function auto_redir(&$a, $contact_nick) {
if((! $contact_nick) || ($contact_nick === $a->user['nickname']))
return;
if(local_user()) {
$r = q("SELECT id FROM contact WHERE uid = ( SELECT uid FROM user WHERE nickname = '%s' LIMIT 1 ) AND nick = '%s' AND network = '%s' and self = 0 LIMIT 1",
dbesc($contact_nick),
dbesc($a->user['nickname']),
dbesc(NETWORK_DFRN)
);
if((!$r) || (! count($r)) || $r[0]['id'] == remote_user())
return;
$r = q("SELECT * FROM contact WHERE nick = '%s' AND network = '%s' AND uid = %d LIMIT 1",
dbesc($contact_nick),
dbesc(NETWORK_DFRN),
intval(local_user())
);
if(! ($r && count($r)))
return;
$cid = $r[0]['id'];
$dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
if($r[0]['duplex'] && $r[0]['issued-id']) {
$orig_id = $r[0]['issued-id'];
$dfrn_id = '1:' . $orig_id;
}
if($r[0]['duplex'] && $r[0]['dfrn-id']) {
$orig_id = $r[0]['dfrn-id'];
$dfrn_id = '0:' . $orig_id;
}
$sec = random_string();
q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`)
VALUES( %d, %s, '%s', '%s', %d )",
intval(local_user()),
intval($cid),
dbesc($dfrn_id),
dbesc($sec),
intval(time() + 45)
);
$url = curPageURL();
logger('check_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG);
$dest = (($url) ? '&destination_url=' . $url : '');
goaway ($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest );
}
return;
}

View file

@ -214,7 +214,7 @@ function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
$gs .= '|<' . intval($g) . '>';
}
$sql = sprintf(
/*$sql = sprintf(
" AND ( allow_cid = '' OR allow_cid REGEXP '<%d>' )
AND ( deny_cid = '' OR NOT deny_cid REGEXP '<%d>' )
AND ( allow_gid = '' OR allow_gid REGEXP '%s' )
@ -224,6 +224,16 @@ function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
intval($remote_user),
dbesc($gs),
dbesc($gs)
);*/
$sql = sprintf(
" AND ( NOT (deny_cid REGEXP '<%d>' OR deny_gid REGEXP '%s')
AND ( allow_cid REGEXP '<%d>' OR allow_gid REGEXP '%s' OR ( allow_cid = '' AND allow_gid = '') )
)
",
intval($remote_user),
dbesc($gs),
intval($remote_user),
dbesc($gs)
);
}
}

View file

@ -826,7 +826,6 @@ function smilies($s, $sample = false) {
':facepalm',
':like',
':dislike',
'~friendika',
'~friendica'
);
@ -864,7 +863,6 @@ function smilies($s, $sample = false) {
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
'<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />',
'<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
'<a href="http://project.friendika.com">~friendika <img class="smiley" src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendika" /></a>',
'<a href="http://friendica.com">~friendica <img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>'
);