Merge remote branch 'upstream/master'

This commit is contained in:
Michael Vogel 2012-09-20 08:32:33 +02:00
commit 4c389eb73b
118 changed files with 17769 additions and 7593 deletions

View file

@ -46,9 +46,52 @@ class Photo {
}
$this->type = $type;
if($this->is_imagick()) {
$this->image = new Imagick();
$this->image->readImageBlob($data);
if($this->is_imagick() && $this->load_data($data)) {
return true;
} else {
// Failed to load with Imagick, fallback
$this->imagick = false;
}
return $this->load_data($data);
}
public function __destruct() {
if($this->image) {
if($this->is_imagick()) {
$this->image->clear();
$this->image->destroy();
return;
}
imagedestroy($this->image);
}
}
public function is_imagick() {
return $this->imagick;
}
/**
* Maps Mime types to Imagick formats
*/
public function get_FormatsMap() {
$m = array(
'image/jpeg' => 'JPG',
'image/png' => 'PNG',
'image/gif' => 'GIF'
);
return $m;
}
private function load_data($data) {
if($this->is_imagick()) {
$this->image = new Imagick();
try {
$this->image->readImageBlob($data);
}
catch (Exception $e) {
// Imagick couldn't use the data
return false;
}
/**
* Setup the image to the format it will be saved to
@ -85,45 +128,28 @@ class Photo {
$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);
}
}
}
public function __destruct() {
if($this->image) {
if($this->is_imagick()) {
$this->image->clear();
$this->image->destroy();
return;
}
imagedestroy($this->image);
}
}
$this->width = $this->image->getImageWidth();
$this->height = $this->image->getImageHeight();
$this->valid = true;
public function is_imagick() {
return $this->imagick;
}
return true;
}
/**
* Maps Mime types to Imagick formats
*/
public function get_FormatsMap() {
$m = array(
'image/jpeg' => 'JPG',
'image/png' => 'PNG',
'image/gif' => 'GIF'
);
return $m;
}
$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);
return true;
}
return false;
}
public function is_valid() {
if($this->is_imagick())
@ -637,7 +663,7 @@ function import_profile_photo($photo,$uid,$cid) {
intval($uid),
intval($cid)
);
if(count($r)) {
if(count($r) && strlen($r[0]['resource-id'])) {
$hash = $r[0]['resource-id'];
}
else {

View file

@ -215,10 +215,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$a = get_app();
// Move all spaces out of the tags
$Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
$Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text);
// Hide all [noparse] contained bbtags by spacefying them
// POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image?
@ -227,6 +223,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
// Move all spaces out of the tags
$Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
$Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text);
// Extract the private images which use data url's since preg has issues with
// large data sizes. Stash them away while we do bbcode conversion, and then put them back
// in after we've done all the regex matching. We cannot use any preg functions to do this.

View file

@ -59,8 +59,8 @@ function item_redir_and_replace_images($body, $images, $cid) {
while($pos !== false && $cnt < 1000) {
$search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
$replace = '[url=' . z_path() . '/redir/' . $cid
. '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
$replace = '[url=' . z_path() . '/redir/' . $cid
. '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
$newbody .= substr($origbody, 0, $pos['start']['open']);
$subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
@ -99,17 +99,17 @@ function localize_item(&$item){
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
if (activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)){
$r = q("SELECT * from `item`,`contact` WHERE
$r = q("SELECT * from `item`,`contact` WHERE
`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
dbesc($item['parent-uri']));
if(count($r)==0) return;
$obj=$r[0];
$author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
$author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
$objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
switch($obj['verb']){
case ACTIVITY_POST:
switch ($obj['object-type']){
@ -123,38 +123,36 @@ function localize_item(&$item){
default:
if($obj['resource-id']){
$post_type = t('photo');
$m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
$m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
$rr['plink'] = $m[1];
} else {
$post_type = t('status');
}
}
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
switch($item['verb']){
case ACTIVITY_LIKE :
$bodyverb = t('%1$s likes %2$s\'s %3$s');
break;
case ACTIVITY_DISLIKE:
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
break;
if(activity_match($item['verb'],ACTIVITY_LIKE)) {
$bodyverb = t('%1$s likes %2$s\'s %3$s');
}
elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) {
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
}
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
}
if ($item['verb']=== ACTIVITY_FRIEND){
if (activity_match($item['verb'],ACTIVITY_FRIEND)) {
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
$Aname = $item['author-name'];
$Alink = $item['author-link'];
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
$obj = parse_xml_string($xmlhead.$item['object']);
$links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
$Bname = $obj->title;
$Blink = ""; $Bphoto = "";
foreach ($links->link as $l){
@ -163,9 +161,9 @@ function localize_item(&$item){
case "alternate": $Blink = $atts['href'];
case "photo": $Bphoto = $atts['href'];
}
}
$A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
@ -181,12 +179,12 @@ function localize_item(&$item){
$Aname = $item['author-name'];
$Alink = $item['author-link'];
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
$obj = parse_xml_string($xmlhead.$item['object']);
$links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
$Bname = $obj->title;
$Blink = ""; $Bphoto = "";
foreach ($links->link as $l){
@ -195,9 +193,9 @@ function localize_item(&$item){
case "alternate": $Blink = $atts['href'];
case "photo": $Bphoto = $atts['href'];
}
}
$A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
@ -224,22 +222,22 @@ function localize_item(&$item){
$Aname = $item['author-name'];
$Alink = $item['author-link'];
$A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
$txt = t('%1$s is currently %2$s');
$item['body'] = sprintf($txt, $A, t($verb));
}
if ($item['verb']===ACTIVITY_TAG){
$r = q("SELECT * from `item`,`contact` WHERE
if (activity_match($item['verb'],ACTIVITY_TAG)) {
$r = q("SELECT * from `item`,`contact` WHERE
`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
dbesc($item['parent-uri']));
if(count($r)==0) return;
$obj=$r[0];
$author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
$author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
$objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
switch($obj['verb']){
case ACTIVITY_POST:
switch ($obj['object-type']){
@ -253,30 +251,30 @@ function localize_item(&$item){
default:
if($obj['resource-id']){
$post_type = t('photo');
$m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
$m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
$rr['plink'] = $m[1];
} else {
$post_type = t('status');
}
}
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
$parsedobj = parse_xml_string($xmlhead.$item['object']);
$tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
$item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
}
if ($item['verb']=== ACTIVITY_FAVORITE){
if (activity_match($item['verb'],ACTIVITY_FAVORITE)){
if ($item['object-type']== "")
return;
$Aname = $item['author-name'];
$Alink = $item['author-link'];
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
$obj = parse_xml_string($xmlhead.$item['object']);
if(strlen($obj->id)) {
$r = q("select * from item where uri = '%s' and uid = %d limit 1",
@ -318,7 +316,7 @@ function localize_item(&$item){
$y = best_link_url($item,$sparkle,true);
if(strstr($y,'/redir/'))
$item['plink'] = $y . '?f=&url=' . $item['plink'];
}
}
@ -332,9 +330,8 @@ function count_descendants($item) {
if($total > 0) {
foreach($item['children'] as $child) {
if($child['verb'] === ACTIVITY_LIKE || $child['verb'] === ACTIVITY_DISLIKE) {
if(! visible_activity($child))
$total --;
}
$total += count_descendants($child);
}
}
@ -342,6 +339,17 @@ function count_descendants($item) {
return $total;
}
function visible_activity($item) {
if(activity_match($child['verb'],ACTIVITY_LIKE) || activity_match($child['verb'],ACTIVITY_DISLIKE))
return false;
if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && $item['uid'] != local_user())
return false;
return true;
}
/**
* Recursively prepare a thread for HTML
*/
@ -353,19 +361,18 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$wallwall_template = 'wallwall_thread.tpl';
$items_seen = 0;
$nb_items = count($items);
$total_children = $nb_items;
foreach($items as $item) {
if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
// Don't count it as a visible item
$nb_items--;
$total_children --;
}
if($item['verb'] === ACTIVITY_LIKE || $item['verb'] === ACTIVITY_DISLIKE) {
if(! visible_activity($item)) {
$nb_items --;
$total_children --;
}
}
@ -375,12 +382,12 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
continue;
}
if($item['verb'] === ACTIVITY_LIKE || $item['verb'] === ACTIVITY_DISLIKE) {
if(! visible_activity($item)) {
continue;
}
$items_seen++;
$comment = '';
$template = $wall_template;
$commentww = '';
@ -417,13 +424,13 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$item_writeable = (($item['writable'] || $item['self']) ? true : false);
// This will allow us to comment on wall-to-wall items owned by our friends
// and community forums even if somebody else wrote the post.
// and community forums even if somebody else wrote the post.
if($visiting && $mode == 'profile')
$item_writeable = true;
$show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
$lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
$lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
|| strlen($item['deny_cid']) || strlen($item['deny_gid']))))
? t('Private Message')
: false);
@ -436,10 +443,10 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$drop = array(
'dropping' => $dropping,
'select' => t('Select'),
'select' => t('Select'),
'delete' => t('Delete'),
);
$filer = (($profile_owner == local_user()) ? t("save to folder") : false);
$diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
@ -454,7 +461,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
if($sp)
$sparkle = ' sparkle';
else
$profile_link = zrl($profile_link);
$profile_link = zrl($profile_link);
$normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
@ -467,9 +474,19 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
$tags=array();
$hashtags = array();
$mentions = array();
foreach(explode(',',$item['tag']) as $tag){
$tag = trim($tag);
if ($tag!="") $tags[] = bbcode($tag);
if ($tag!="") {
$t = bbcode($tag);
$tags[] = $t;
if($t[0] == '#')
$hashtags[] = $t;
elseif($t[0] == '@')
$mentions[] = $t;
}
}
$like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
@ -487,7 +504,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$owner_photo = $a->page_contact['thumb'];
$owner_name = $a->page_contact['name'];
$template = $wallwall_template;
$commentww = 'ww';
$commentww = 'ww';
}
else if($item['owner-link']) {
@ -497,14 +514,14 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
// The author url doesn't match the owner (typically the contact)
// and also doesn't match the contact alias.
// The name match is a hack to catch several weird cases where URLs are
// and also doesn't match the contact alias.
// The name match is a hack to catch several weird cases where URLs are
// all over the park. It can be tricked, but this prevents you from
// seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
// well that it's the same Bob Smith.
// well that it's the same Bob Smith.
// But it could be somebody else with the same name. It just isn't highly likely.
// But it could be somebody else with the same name. It just isn't highly likely.
$owner_url = $item['owner-link'];
$owner_photo = $item['owner-avatar'];
@ -512,7 +529,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$template = $wallwall_template;
$commentww = 'ww';
// If it is our contact, use a friendly redirect link
if((link_compare($item['owner-link'],$item['url']))
if((link_compare($item['owner-link'],$item['url']))
&& ($item['network'] === NETWORK_DFRN)) {
$owner_url = $redirect_url;
$osparkle = ' sparkle';
@ -577,7 +594,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
}
$comment = replace_macros($cmnt_tpl,array(
'$return_path' => '',
'$threaded' => $comments_threaded,
'$threaded' => $comments_threaded,
'$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
'$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
'$id' => $item['item_id'],
@ -618,9 +635,11 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
'comment_lastcollapsed' => $lastcollapsed,
// template to use to render item (wall, walltowall, search)
'template' => $template,
'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
'tags' => $tags,
'tags' => template_escape($tags),
'hashtags' => template_escape($hashtags),
'mentions' => template_escape($mentions),
'body' => template_escape($body),
'text' => strip_tags(template_escape($body)),
'id' => $item['item_id'],
@ -666,6 +685,8 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$item_result = $arr['output'];
if($firstcollapsed) {
$item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children );
$item_result['hidden_comments_num'] = $total_children;
$item_result['hidden_comments_text'] = tt('comment', 'comments', $total_children);
$item_result['hide_text'] = t('show more');
}
@ -690,7 +711,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$item_result['comment'] = false;
}
}
$result[] = $item_result;
}
@ -703,7 +724,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
* - Sequential or unthreaded ("New Item View" or search results)
* - conversation view
* The $mode parameter decides between the various renderings and also
* figures out how to determine page owner and other contextual items
* figures out how to determine page owner and other contextual items
* that are based on unique features of the calling module.
*
*/
@ -768,19 +789,19 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$alike = array();
$dlike = array();
// array with html for each thread (parent+comments)
$threads = array();
$threadsid = -1;
$page_template = get_markup_template("conversation.tpl");
if($items && count($items)) {
if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
// "New Item View" on network page or search page results
// "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');
@ -796,24 +817,39 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$sparkle = '';
if($mode === 'search' || $mode === 'community') {
if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
&& ($item['id'] != $item['parent']))
continue;
$nickname = $item['nickname'];
}
else
$nickname = $a->user['nickname'];
// prevent private email from leaking.
if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
continue;
$profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
if($item['author-link'] && (! $item['author-name']))
$profile_name = $item['author-link'];
$tags=array();
$hashtags = array();
$mentions = array();
foreach(explode(',',$item['tag']) as $tag){
$tag = trim($tag);
if ($tag!="") {
$t = bbcode($tag);
$tags[] = $t;
if($t[0] == '#')
$hashtags[] = $t;
elseif($t[0] == '@')
$mentions[] = $t;
}
}
$sp = false;
$profile_link = best_link_url($item,$sp);
if($profile_link === 'mailbox')
@ -821,7 +857,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
if($sp)
$sparkle = ' sparkle';
else
$profile_link = zrl($profile_link);
$profile_link = zrl($profile_link);
$normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
@ -843,19 +879,19 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$drop = array(
'dropping' => $dropping,
'select' => t('Select'),
'select' => t('Select'),
'delete' => t('Delete'),
);
$star = false;
$isstarred = "unstarred";
$lock = false;
$likebuttons = false;
$shareable = false;
$body = prepare_body($item,true);
//$tmp_item = replace_macros($tpl,array(
$tmp_item = array(
'template' => $tpl,
@ -869,6 +905,9 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
'thumb' => $profile_avatar,
'title' => template_escape($item['title']),
'body' => template_escape($body),
'tags' => template_escape($tags),
'hashtags' => template_escape($hashtags),
'mentions' => template_escape($mentions),
'text' => strip_tags(template_escape($body)),
'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
@ -906,25 +945,44 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
// Normal View
$page_template = get_markup_template("threaded_conversation.tpl");
require_once('object/Conversation.php');
require_once('object/Item.php');
$conv = new Conversation($mode, $preview);
// get all the topmost parents
// this shouldn't be needed, as we should have only them in ou array
// this shouldn't be needed, as we should have only them in our array
// But for now, this array respects the old style, just in case
$threads = array();
foreach($items as $item) {
// Can we put this after the visibility check?
like_puller($a,$item,$alike,'like');
like_puller($a,$item,$dlike,'dislike');
// Only add what is visible
if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
continue;
}
if(! visible_activity($item)) {
continue;
}
if($item['id'] == $item['parent']) {
$threads[] = $item;
$item_object = new Item($item);
$conv->add_thread($item_object);
}
}
$threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $alike, $dlike, $previewing);
$threads = $conv->get_template_data($alike, $dlike);
if(!$threads) {
logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
$threads = array();
}
}
}
$o = replace_macros($page_template, array(
'$baseurl' => $a->get_baseurl($ssl_state),
'$mode' => $mode,
@ -985,7 +1043,7 @@ function item_photo_menu($item){
$posts_link="";
$sparkle = false;
$profile_link = best_link_url($item,$sparkle,$ssl_state);
$profile_link = best_link_url($item,$sparkle,$ssl_state);
if($profile_link === 'mailbox')
$profile_link = '';
@ -1001,7 +1059,7 @@ function item_photo_menu($item){
$profile_link = zrl($profile_link);
if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
$cid = $item['contact-id'];
}
}
else {
$cid = 0;
}
@ -1027,18 +1085,18 @@ function item_photo_menu($item){
t("View Status") => $status_link,
t("View Profile") => $profile_link,
t("View Photos") => $photos_link,
t("Network Posts") => $posts_link,
t("Network Posts") => $posts_link,
t("Edit Contact") => $contact_url,
t("Send PM") => $pm_url,
t("Poke") => $poke_link
);
$args = array('item' => $item, 'menu' => $menu);
call_hooks('item_photo_menu', $args);
$menu = $args['menu'];
$menu = $args['menu'];
$o = "";
foreach($menu as $k=>$v){
@ -1070,7 +1128,7 @@ function like_puller($a,$item,&$arr,$mode) {
$arr[$item['thr-parent'] . '-l'] = array();
if(! isset($arr[$item['thr-parent']]))
$arr[$item['thr-parent']] = 1;
else
else
$arr[$item['thr-parent']] ++;
$arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
}
@ -1091,10 +1149,10 @@ function format_like($cnt,$arr,$type,$id) {
$o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
else {
$spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
$o .= (($type === 'like') ?
$o .= (($type === 'like') ?
sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
:
sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
:
sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
$o .= EOL ;
$total = count($arr);
if($total >= MAX_LIKERS)
@ -1114,7 +1172,7 @@ function format_like($cnt,$arr,$type,$id) {
function status_editor($a,$x, $notes_cid = 0, $popup=false) {
$o = '';
$geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
$plaintext = false;
@ -1156,7 +1214,7 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
$tpl = get_markup_template("jot.tpl");
$jotplugins = '';
$jotnets = '';
@ -1187,7 +1245,7 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
if($notes_cid)
$jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
$o .= replace_macros($tpl,array(
'$return_path' => $a->query_string,
@ -1231,12 +1289,13 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
'$profile_uid' => $x['profile_uid'],
'$preview' => t('Preview'),
'$sourceapp' => t($a->sourcename),
'$cancel' => t('Cancel')
));
if ($popup==true){
$o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
}
return $o;
@ -1252,7 +1311,7 @@ function get_item_children($arr, $parent) {
$thr_parent = $item['thr-parent'];
if($thr_parent == '')
$thr_parent = $item['parent-uri'];
if($thr_parent == $parent['uri']) {
$item['children'] = get_item_children($arr, $item);
$children[] = $item;
@ -1303,7 +1362,7 @@ function conv_sort($arr,$order) {
usort($parents,'sort_thr_commented');
if(count($parents))
foreach($parents as $i=>$_x)
foreach($parents as $i=>$_x)
$parents[$i]['children'] = get_item_children($arr, $_x);
/*foreach($arr as $x) {
@ -1321,7 +1380,7 @@ function conv_sort($arr,$order) {
usort($y,'sort_thr_created_rev');
$parents[$k]['children'] = $y;*/
}
}
}
}
$ret = array();

View file

@ -2061,11 +2061,20 @@ function diaspora_profile($importer,$xml,$msg) {
$image_url = unxmlify($xml->image_url);
$birthday = unxmlify($xml->birthday);
$r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ",
$handle_parts = explode("@", $diaspora_handle);
if($name === '') {
$name = $handle_parts[0];
}
if(strpos($image_url, $handle_parts[1]) === false) {
$image_url = "http://" . $handle_parts[1] . $image_url;
}
/* $r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ",
intval($importer['uid']),
intval($contact['id'])
);
$oldphotos = ((count($r)) ? $r : null);
$oldphotos = ((count($r)) ? $r : null);*/
require_once('include/Photo.php');
@ -2098,7 +2107,7 @@ function diaspora_profile($importer,$xml,$msg) {
intval($importer['uid'])
);
if($r) {
/* if($r) {
if($oldphotos) {
foreach($oldphotos as $ph) {
q("DELETE FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' AND `resource-id` = '%s' ",
@ -2108,7 +2117,7 @@ function diaspora_profile($importer,$xml,$msg) {
);
}
}
}
} */
return;

View file

@ -1190,6 +1190,15 @@ function tag_deliver($uid,$item_id) {
// send a notification
// use a local photo if we have one
$r = q("select thumb from contact where uid = %d and nurl = '%s' limit 1",
intval($u[0]['uid']),
dbesc(normalise_link($item['author-link']))
);
$photo = (($r && count($r)) ? $r[0]['thumb'] : $item['author-avatar']);
require_once('include/enotify.php');
notification(array(
'type' => NOTIFY_TAGSELF,
@ -1202,7 +1211,7 @@ function tag_deliver($uid,$item_id) {
'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item['id'],
'source_name' => $item['author-name'],
'source_link' => $item['author-link'],
'source_photo' => $item['author-avatar'],
'source_photo' => $photo,
'verb' => ACTIVITY_TAG,
'otype' => 'item'
));
@ -1253,6 +1262,59 @@ function tag_deliver($uid,$item_id) {
function tgroup_check($uid,$item) {
$a = get_app();
$mention = false;
// check that the message originated elsewhere and is a top-level post
if(($item['wall']) || ($item['origin']) || ($item['uri'] != $item['parent-uri']))
return false;
$u = q("select * from user where uid = %d limit 1",
intval($uid)
);
if(! count($u))
return false;
$community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
$prvgroup = (($u[0]['page-flags'] == PAGE_PRVGROUP) ? true : false);
$link = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']);
// Diaspora uses their own hardwired link URL in @-tags
// instead of the one we supply with webfinger
$dlink = normalise_link($a->get_baseurl() . '/u/' . $u[0]['nickname']);
$cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {
if(link_compare($link,$mtch[1]) || link_compare($dlink,$mtch[1])) {
$mention = true;
logger('tgroup_check: mention found: ' . $mtch[2]);
}
}
}
if(! $mention)
return false;
if((! $community_page) && (! $prvgroup))
return false;
return true;
}
@ -1809,6 +1871,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
if($pass == 1)
continue;
// not allowed to post
if($contact['rel'] == CONTACT_IS_FOLLOWER)
continue;
// Have we seen it? If not, import it.
$item_id = $item->get_id();
@ -2083,6 +2151,14 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$datarray['owner-avatar'] = $contact['thumb'];
}
// We've allowed "followers" to reach this point so we can decide if they are
// posting an @-tag delivery, which followers are allowed to do for certain
// page types. Now that we've parsed the post, let's check if it is legit. Otherwise ignore it.
if(($contact['rel'] == CONTACT_IS_FOLLOWER) && (! tgroup_check($importer['uid'],$datarray)))
continue;
$r = item_store($datarray);
continue;
@ -2626,22 +2702,32 @@ function local_delivery($importer,$data) {
// Specifically, the recipient?
$is_a_remote_comment = false;
// POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used?
$r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,
`contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s')
AND `item`.`uid` = %d
$sql_extra
$top_uri = $parent_uri;
$r = q("select `item`.`parent-uri` from `item`
WHERE `item`.`uri` = '%s'
LIMIT 1",
dbesc($parent_uri),
dbesc($parent_uri),
dbesc($parent_uri),
intval($importer['importer_uid'])
dbesc($parent_uri)
);
if($r && count($r))
$is_a_remote_comment = true;
if($r && count($r)) {
$top_uri = $r[0]['parent-uri'];
// POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used?
$r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,
`contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s')
AND `item`.`uid` = %d
$sql_extra
LIMIT 1",
dbesc($top_uri),
dbesc($top_uri),
dbesc($top_uri),
intval($importer['importer_uid'])
);
if($r && count($r))
$is_a_remote_comment = true;
}
// Does this have the characteristics of a community or private group comment?
// If it's a reply to a wall post on a community/prvgroup page it's a
@ -2695,15 +2781,6 @@ function local_delivery($importer,$data) {
}
// TODO: make this next part work against both delivery threads of a community post
// if((! link_compare($datarray['author-link'],$importer['url'])) && (! $community)) {
// logger('local_delivery: received relay claiming to be from ' . $importer['url'] . ' however comment author url is ' . $datarray['author-link'] );
// they won't know what to do so don't report an error. Just quietly die.
// return 0;
// }
// our user with $importer['importer_uid'] is the owner
$own = q("select name,url,thumb from contact where uid = %d and self = 1 limit 1",
intval($importer['importer_uid'])
@ -2773,15 +2850,6 @@ function local_delivery($importer,$data) {
}
}
// if($community) {
// $newtag = '@[url=' . $a->get_baseurl() . '/profile/' . $importer['nickname'] . ']' . $importer['username'] . '[/url]';
// if(! stristr($datarray['tag'],$newtag)) {
// if(strlen($datarray['tag']))
// $datarray['tag'] .= ',';
// $datarray['tag'] .= $newtag;
// }
// }
$posted_id = item_store($datarray);
$parent = 0;
@ -2851,6 +2919,9 @@ function local_delivery($importer,$data) {
$item_id = $item->get_id();
$datarray = get_atom_elements($feed,$item);
if($importer['rel'] == CONTACT_IS_FOLLOWER)
continue;
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['importer_uid'])
@ -2945,7 +3016,7 @@ function local_delivery($importer,$data) {
if(!x($datarray['type']) || $datarray['type'] != 'activity') {
$myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0",
dbesc($parent_uri),
dbesc($top_uri),
intval($importer['importer_uid'])
);
@ -3085,6 +3156,9 @@ function local_delivery($importer,$data) {
$datarray['owner-avatar'] = $importer['thumb'];
}
if(($importer['rel'] == CONTACT_IS_FOLLOWER) && (! tgroup_check($importer['importer_uid'],$datarray)))
continue;
$posted_id = item_store($datarray);
if(stristr($datarray['verb'],ACTIVITY_POKE)) {

View file

@ -275,7 +275,7 @@ function onepoll_run($argv, $argc){
openssl_private_decrypt(hex2bin($mailconf[0]['pass']),$password,$x[0]['prvkey']);
$mbox = email_connect($mailbox,$mailconf[0]['user'],$password);
unset($password);
logger("Mail: Connect");
logger("Mail: Connect to " . $mailconf[0]['user']);
if($mbox) {
q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
dbesc(datetime_convert()),
@ -289,7 +289,7 @@ function onepoll_run($argv, $argc){
$msgs = email_poll($mbox,$contact['addr']);
if(count($msgs)) {
logger("Mail: Parsing ".count($msgs)." mails.", LOGGER_DEBUG);
logger("Mail: Parsing ".count($msgs)." mails for ".$mailconf[0]['user'], LOGGER_DEBUG);
foreach($msgs as $msg_uid) {
logger("Mail: Parsing mail ".$msg_uid, LOGGER_DATA);
@ -339,15 +339,15 @@ function onepoll_run($argv, $argc){
case 0:
break;
case 1:
logger("Mail: Deleting ".$msg_uid);
logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']);
imap_delete($mbox, $msg_uid, FT_UID);
break;
case 2:
logger("Mail: Mark as seen ".$msg_uid);
logger("Mail: Mark as seen ".$msg_uid." for ".$mailconf[0]['user']);
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
break;
case 3:
logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']);
logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']." for ".$mailconf[0]['user']);
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
if ($mailconf[0]['movetofolder'] != "")
imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);
@ -377,12 +377,12 @@ function onepoll_run($argv, $argc){
$r = email_get_msg($mbox,$msg_uid, $reply);
if(! $r) {
logger("Mail: can't fetch msg ".$msg_uid);
logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf[0]['user']);
continue;
}
$datarray['body'] = escape_tags($r['body']);
logger("Mail: Importing ".$msg_uid);
logger("Mail: Importing ".$msg_uid." for ".$mailconf[0]['user']);
// some mailing lists have the original author as 'from' - add this sender info to msg body.
// todo: adding a gravatar for the original author would be cool
@ -423,15 +423,15 @@ function onepoll_run($argv, $argc){
case 0:
break;
case 1:
logger("Mail: Deleting ".$msg_uid);
logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']);
imap_delete($mbox, $msg_uid, FT_UID);
break;
case 2:
logger("Mail: Mark as seen ".$msg_uid);
logger("Mail: Mark as seen ".$msg_uid." for ".$mailconf[0]['user']);
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
break;
case 3:
logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']);
logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']." for ".$mailconf[0]['user']);
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
if ($mailconf[0]['movetofolder'] != "")
imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);

View file

@ -277,18 +277,24 @@ function create_user($arr) {
require_once('include/group.php');
group_add($newuid, t('Friends'));
if(! get_config('system', 'newuser_public')) {
$r = q("SELECT id FROM `group` WHERE uid = %d AND name = '%s'",
intval($newuid),
dbesc(t('Friends'))
$r = q("SELECT id FROM `group` WHERE uid = %d AND name = '%s'",
intval($newuid),
dbesc(t('Friends'))
);
if($r && count($r)) {
$def_gid = $r[0]['id'];
q("UPDATE user SET def_gid = %d WHERE uid = %d",
intval($r[0]['id']),
intval($newuid)
);
}
if(get_config('system', 'newuser_private') && $def_gid) {
q("UPDATE user SET allow_gid = '%s' WHERE uid = %d",
dbesc("<" . $def_gid . ">"),
intval($newuid)
);
if($r) {
q("UPDATE user SET def_gid = %d, allow_gid = '%s' WHERE uid = %d",
intval($r[0]['id']),
dbesc("<" . $r[0]['id'] . ">"),
intval($newuid)
);
}
}
}