From c14270ac648391660c989d9b5d28fd2d1070c4db Mon Sep 17 00:00:00 2001 From: Sebastian Egbers Date: Fri, 22 Jun 2012 13:35:36 +0200 Subject: [PATCH 01/12] modified conversion to use x function for parameter checking. --- include/api.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/api.php b/include/api.php index b77156dfae..730e1fa2ff 100644 --- a/include/api.php +++ b/include/api.php @@ -864,8 +864,13 @@ logger('API: api_statuses_show: '.$id); //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false); - //$sql_extra = ""; - if ($_GET["conversation"] == "true") $sql_extra .= " AND `item`.`parent` = %d ORDER BY `received` ASC "; else $sql_extra .= " AND `item`.`id` = %d"; + $conversation = (x($_REQUEST,'conversation')?1:0); + + $sql_extra = ''; + if ($conversation) + $sql_extra .= " AND `item`.`parent` = %d ORDER BY `received` ASC "; + else + $sql_extra .= " AND `item`.`id` = %d"; $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, @@ -875,16 +880,15 @@ WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 AND `contact`.`id` = `item`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - $sql_extra - ", + $sql_extra", intval($id) ); -//var_dump($r); + $ret = api_format_items($r,$user_info); -//var_dump($ret); - if ($_GET["conversation"] == "true") { + + if ($conversation) { $data = array('$statuses' => $ret); - return api_apply_template("timeline", $type, $data); + return api_apply_template("timeline", $type, $data); } else { $data = array('$status' => $ret[0]); /*switch($type){ From cd25c3b5dd61755791dcde8dfd09e0032bcfb197 Mon Sep 17 00:00:00 2001 From: Sebastian Egbers Date: Fri, 22 Jun 2012 14:54:31 +0200 Subject: [PATCH 02/12] added replyto and subject to direct messages. --- include/api.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/include/api.php b/include/api.php index 730e1fa2ff..ac9c2cc849 100644 --- a/include/api.php +++ b/include/api.php @@ -1507,21 +1507,32 @@ if (local_user()===false) return false; if (!x($_POST, "text") || !x($_POST,"screen_name")) return; - + $sender = api_get_user($a); $r = q("SELECT `id` FROM `contact` WHERE `uid`=%d AND `nick`='%s'", intval(local_user()), dbesc($_POST['screen_name'])); - $recipient = api_get_user($a, $r[0]['id']); - - require_once("include/message.php"); - $sub = ( (strlen($_POST['text'])>10)?substr($_POST['text'],0,10)."...":$_POST['text']); - $id = send_message($recipient['id'], $_POST['text'], $sub); - - + + $recipient = api_get_user($a, $r[0]['id']); + $replyto = ''; + if (x($_REQUEST,'replyto')) { + $r = q('SELECT `uri` FROM `mail` WHERE `uid`=%d AND `id`=%d', + intval(local_user()), + intval($_REQUEST['replyto'])); + $replyto = $r[0]['uri']; + } + + if (x($_REQUEST,'title')) { + $sub = $_REQUEST['title']; + } + else { + $sub = ((strlen($_POST['text'])>10)?substr($_POST['text'],0,10)."...":$_POST['text']); + } + $id = send_message($recipient['id'], $_POST['text'], $sub, $replyto); + if ($id>-1) { $r = q("SELECT * FROM `mail` WHERE id=%d", intval($id)); $item = $r[0]; From d8a376666c0f56baf96f88b74fdcb9575df9ec73 Mon Sep 17 00:00:00 2001 From: Max Weller Date: Sat, 23 Jun 2012 19:21:48 +0200 Subject: [PATCH 03/12] modified direct_messages --- include/api.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/include/api.php b/include/api.php index b77156dfae..e0e759b618 100644 --- a/include/api.php +++ b/include/api.php @@ -1566,16 +1566,19 @@ if ($box=="sentbox") { - $sql_extra = "`from-url`='%s'"; - } else { - $sql_extra = "`from-url`!='%s'"; + $sql_extra = "`from-url`='".dbesc( $a->get_baseurl() . '/profile/' . $a->user['nickname'] )."'"; + } elseif ($box=="conversation") { + $sql_extra = "`parent-uri`='".dbesc( $_GET["uri"] ) ."'"; + } elseif ($box=="all") { + $sql_extra = "true"; + } elseif ($box=="inbox") { + $sql_extra = "`from-url`!='".dbesc( $a->get_baseurl() . '/profile/' . $a->user['nickname'] )."'"; } $r = q("SELECT * FROM `mail` WHERE uid=%d AND $sql_extra ORDER BY created DESC LIMIT %d,%d", intval(local_user()), - dbesc( $a->get_baseurl() . '/profile/' . $a->user['nickname'] ), intval($start), intval($count) - ); + ); $ret = Array(); foreach($r as $item){ @@ -1595,15 +1598,26 @@ 'created_at'=> api_date($item['created']), 'sender_id'=> $sender['id'] , 'sender_screen_name'=> $sender['screen_name'], + 'sender_profile_img'=> $item['from-photo'], 'sender'=> $sender, 'recipient_id'=> $recipient['id'], 'recipient_screen_name'=> $recipient['screen_name'], 'recipient'=> $recipient, - 'text'=> $item['title']."\n".html2plain(bbcode($item['body']), 0) , ); - + //don't send title to regular StatusNET requests to avoid confusing these apps + if (isset($_GET["getText"])) { + $ret['title'] = $item['title'] ; + if ($_GET["getText"] == "true") { + $ret['text'] = html2plain(bbcode($item['body']), 0); + } + } else { + $ret['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); + } + + + } @@ -1624,6 +1638,14 @@ function api_direct_messages_inbox(&$a, $type){ return api_direct_messages_box($a, $type, "inbox"); } + function api_direct_messages_all(&$a, $type){ + return api_direct_messages_box($a, $type, "all"); + } + function api_direct_messages_conversation(&$a, $type){ + return api_direct_messages_box($a, $type, "conversation"); + } + api_register_func('api/direct_messages/conversation','api_direct_messages_conversation',true); + api_register_func('api/direct_messages/all','api_direct_messages_all',true); api_register_func('api/direct_messages/sent','api_direct_messages_sentbox',true); api_register_func('api/direct_messages','api_direct_messages_inbox',true); From f45c881815d1e3ab2cc494f47a836f18044aae5b Mon Sep 17 00:00:00 2001 From: Max Weller Date: Sat, 23 Jun 2012 19:29:58 +0200 Subject: [PATCH 04/12] changes on api_direct_messages_box to allow to retrieve conversations and all messages --- include/api.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/include/api.php b/include/api.php index e0e759b618..e22bcc9e9a 100644 --- a/include/api.php +++ b/include/api.php @@ -1564,15 +1564,15 @@ $start = $page*$count; - + $profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname']; if ($box=="sentbox") { - $sql_extra = "`from-url`='".dbesc( $a->get_baseurl() . '/profile/' . $a->user['nickname'] )."'"; + $sql_extra = "`from-url`='".dbesc( $profile_url )."'"; } elseif ($box=="conversation") { $sql_extra = "`parent-uri`='".dbesc( $_GET["uri"] ) ."'"; } elseif ($box=="all") { $sql_extra = "true"; } elseif ($box=="inbox") { - $sql_extra = "`from-url`!='".dbesc( $a->get_baseurl() . '/profile/' . $a->user['nickname'] )."'"; + $sql_extra = "`from-url`!='".dbesc( $profile_url )."'"; } $r = q("SELECT * FROM `mail` WHERE uid=%d AND $sql_extra ORDER BY created DESC LIMIT %d,%d", @@ -1582,15 +1582,12 @@ $ret = Array(); foreach($r as $item){ - switch ($box){ - case "inbox": + if ($box == "inbox" || $item['from-url'] != $profile_url){ $recipient = $user_info; $sender = api_get_user($a,$item['contact-id']); - break; - case "sentbox": + } elseif ($box == "sentbox" || $item['from-url'] != $profile_url){ $recipient = api_get_user($a,$item['contact-id']); $sender = $user_info; - break; } $ret[]=Array( @@ -1603,8 +1600,6 @@ 'recipient_id'=> $recipient['id'], 'recipient_screen_name'=> $recipient['screen_name'], 'recipient'=> $recipient, - - ); //don't send title to regular StatusNET requests to avoid confusing these apps if (isset($_GET["getText"])) { @@ -1615,9 +1610,6 @@ } else { $ret['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); } - - - } From 2c992c5969b44dce24c638af32879eac9e55f719 Mon Sep 17 00:00:00 2001 From: Max Weller Date: Sat, 23 Jun 2012 19:35:01 +0200 Subject: [PATCH 05/12] bugfix --- include/api.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/api.php b/include/api.php index e22bcc9e9a..78e628386c 100644 --- a/include/api.php +++ b/include/api.php @@ -1590,7 +1590,7 @@ $sender = $user_info; } - $ret[]=Array( + $d=Array( 'id' => $item['id'], 'created_at'=> api_date($item['created']), 'sender_id'=> $sender['id'] , @@ -1603,13 +1603,14 @@ ); //don't send title to regular StatusNET requests to avoid confusing these apps if (isset($_GET["getText"])) { - $ret['title'] = $item['title'] ; + $d['title'] = $item['title'] ; if ($_GET["getText"] == "true") { - $ret['text'] = html2plain(bbcode($item['body']), 0); + $d['text'] = html2plain(bbcode($item['body']), 0); } } else { - $ret['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); + $d['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); } + $ret[]=$d; } From 9d462c6b6a2d0b2eb859781d5de26f6a2275536b Mon Sep 17 00:00:00 2001 From: Max Weller Date: Sat, 23 Jun 2012 19:38:15 +0200 Subject: [PATCH 06/12] new param getUserObjects to avoid retransmitting the whole user info objects --- include/api.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/api.php b/include/api.php index 78e628386c..7466c199ae 100644 --- a/include/api.php +++ b/include/api.php @@ -1610,6 +1610,9 @@ } else { $d['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); } + if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") { + unset($d['sender']); unset($d['recipient']); + } $ret[]=$d; } From 111ace5abd855a0c4f248b34d468285b825abbd0 Mon Sep 17 00:00:00 2001 From: Max Weller Date: Sat, 23 Jun 2012 22:35:43 +0200 Subject: [PATCH 07/12] I want HTML code! --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index 7466c199ae..32579fe7d3 100644 --- a/include/api.php +++ b/include/api.php @@ -1605,7 +1605,7 @@ if (isset($_GET["getText"])) { $d['title'] = $item['title'] ; if ($_GET["getText"] == "true") { - $d['text'] = html2plain(bbcode($item['body']), 0); + $d['text'] = bbcode($item['body']); } } else { $d['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); From 11b6beae061d0536ea70c01c28a19b16826bfb8e Mon Sep 17 00:00:00 2001 From: Max Weller Date: Sat, 23 Jun 2012 22:39:11 +0200 Subject: [PATCH 08/12] make it selectable --- include/api.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index 32579fe7d3..52ae2fd695 100644 --- a/include/api.php +++ b/include/api.php @@ -1604,8 +1604,10 @@ //don't send title to regular StatusNET requests to avoid confusing these apps if (isset($_GET["getText"])) { $d['title'] = $item['title'] ; - if ($_GET["getText"] == "true") { + if ($_GET["getText"] == "html") { $d['text'] = bbcode($item['body']); + } elseif ($_GET["getText"] == "plain") { + $d['text'] = html2plain(bbcode($item['body']), 0); } } else { $d['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); From e3c36dfd1d1fea0b6d3ba6d6b58fcc8ed0c2dd36 Mon Sep 17 00:00:00 2001 From: Max Weller Date: Sat, 23 Jun 2012 22:52:50 +0200 Subject: [PATCH 09/12] add reliable way to get server version --- include/api.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index 52ae2fd695..49286d262c 100644 --- a/include/api.php +++ b/include/api.php @@ -1429,7 +1429,13 @@ 'logo' => $logo, 'fancy' => 'true', 'language' => 'en', 'email' => $email, 'broughtby' => '', 'broughtbyurl' => '', 'timezone' => 'UTC', 'closed' => $closed, 'inviteonly' => 'false', 'private' => $private, 'textlimit' => $textlimit, 'sslserver' => $sslserver, 'ssl' => $ssl, - 'shorturllength' => '30' + 'shorturllength' => '30', + 'friendica' => array( + 'FRIENDICA_PLATFORM' => FRIENDICA_PLATFORM, + 'FRIENDICA_VERSION' => FRIENDICA_VERSION, + 'DFRN_PROTOCOL_VERSION' => DFRN_PROTOCOL_VERSION, + 'DB_UPDATE_VERSION' => DB_UPDATE_VERSION + ) ), ); From af1d4bb632aa1f6c9fb9f756f1d8606f9fe947e1 Mon Sep 17 00:00:00 2001 From: Sebastian Egbers Date: Mon, 25 Jun 2012 15:53:56 +0200 Subject: [PATCH 10/12] modified api message reply to set title to conversion title, when replying. --- include/api.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/api.php b/include/api.php index 1db9d020be..2da183f019 100644 --- a/include/api.php +++ b/include/api.php @@ -1516,27 +1516,31 @@ $sender = api_get_user($a); + require_once("include/message.php"); + $r = q("SELECT `id` FROM `contact` WHERE `uid`=%d AND `nick`='%s'", intval(local_user()), dbesc($_POST['screen_name'])); - - require_once("include/message.php"); $recipient = api_get_user($a, $r[0]['id']); $replyto = ''; + $sub = ''; if (x($_REQUEST,'replyto')) { - $r = q('SELECT `uri` FROM `mail` WHERE `uid`=%d AND `id`=%d', + $r = q('SELECT `uri`, `title` FROM `mail` WHERE `uid`=%d AND `id`=%d', intval(local_user()), intval($_REQUEST['replyto'])); $replyto = $r[0]['uri']; - } - - if (x($_REQUEST,'title')) { - $sub = $_REQUEST['title']; + $sub = $r[0]['title']; } else { - $sub = ((strlen($_POST['text'])>10)?substr($_POST['text'],0,10)."...":$_POST['text']); + if (x($_REQUEST,'title')) { + $sub = $_REQUEST['title']; + } + else { + $sub = ((strlen($_POST['text'])>10)?substr($_POST['text'],0,10)."...":$_POST['text']); + } } + $id = send_message($recipient['id'], $_POST['text'], $sub, $replyto); if ($id>-1) { From 8c251aebc77a6daacfe20598fc861df4c243a726 Mon Sep 17 00:00:00 2001 From: Sebastian Egbers Date: Mon, 25 Jun 2012 16:25:34 +0200 Subject: [PATCH 11/12] fixed direct message reply in api call. --- include/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/api.php b/include/api.php index 2da183f019..191ed6fcd8 100644 --- a/include/api.php +++ b/include/api.php @@ -1526,10 +1526,10 @@ $replyto = ''; $sub = ''; if (x($_REQUEST,'replyto')) { - $r = q('SELECT `uri`, `title` FROM `mail` WHERE `uid`=%d AND `id`=%d', + $r = q('SELECT `parent-uri`, `title` FROM `mail` WHERE `uid`=%d AND `id`=%d', intval(local_user()), intval($_REQUEST['replyto'])); - $replyto = $r[0]['uri']; + $replyto = $r[0]['parent-uri']; $sub = $r[0]['title']; } else { From 587b081a38f3d6f983c15e8b7c3528eb93e0277e Mon Sep 17 00:00:00 2001 From: Sebastian Egbers Date: Tue, 26 Jun 2012 08:54:01 +0200 Subject: [PATCH 12/12] moved api direct message formating to own function. added same formating to direct reply message, when posting a new message. --- include/api.php | 108 ++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/include/api.php b/include/api.php index 0a038b0381..d790b4b875 100644 --- a/include/api.php +++ b/include/api.php @@ -1238,6 +1238,40 @@ return($as); } + function api_format_messages($item, $recipient, $sender) { + // standard meta information + $ret=Array( + 'id' => $item['id'], + 'created_at' => api_date($item['created']), + 'sender_id' => $sender['id'] , + 'sender_screen_name' => $sender['screen_name'], + 'sender' => $sender, + 'recipient_id' => $recipient['id'], + 'recipient_screen_name' => $recipient['screen_name'], + 'recipient' => $recipient, + ); + + //don't send title to regular StatusNET requests to avoid confusing these apps + if (x($_GET, 'getText')) { + $ret['title'] = $item['title'] ; + if ($_GET["getText"] == "html") { + $ret['text'] = bbcode($item['body']); + } + elseif ($_GET["getText"] == "plain") { + $ret['text'] = html2plain(bbcode($item['body']), 0); + } + } + else { + $ret['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); + } + if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") { + unset($ret['sender']); + unset($ret['recipient']); + } + + return $ret; + } + function api_format_items($r,$user_info) { //logger('api_format_items: ' . print_r($r,true)); @@ -1546,20 +1580,7 @@ if ($id>-1) { $r = q("SELECT * FROM `mail` WHERE id=%d", intval($id)); - $item = $r[0]; - $ret=Array( - 'id' => $item['id'], - 'created_at'=> api_date($item['created']), - 'sender_id'=> $sender['id'] , - 'sender_screen_name'=> $sender['screen_name'], - 'sender'=> $sender, - 'recipient_id'=> $recipient['id'], - 'recipient_screen_name'=> $recipient['screen_name'], - 'recipient'=> $recipient, - - 'text'=> $item['title']."\n".html2plain(bbcode($item['body']), 0) , - - ); + $ret = api_format_messages($r[0], $recipient, $sender); } else { $ret = array("error"=>$id); @@ -1578,7 +1599,7 @@ } api_register_func('api/direct_messages/new','api_direct_messages_new',true); - function api_direct_messages_box(&$a, $type, $box) { + function api_direct_messages_box(&$a, $type, $box) { if (local_user()===false) return false; $user_info = api_get_user($a); @@ -1590,14 +1611,17 @@ $start = $page*$count; - $profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname']; + $profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname']; if ($box=="sentbox") { $sql_extra = "`from-url`='".dbesc( $profile_url )."'"; - } elseif ($box=="conversation") { - $sql_extra = "`parent-uri`='".dbesc( $_GET["uri"] ) ."'"; - } elseif ($box=="all") { - $sql_extra = "true"; - } elseif ($box=="inbox") { + } + elseif ($box=="conversation") { + $sql_extra = "`parent-uri`='".dbesc( $_GET["uri"] ) ."'"; + } + elseif ($box=="all") { + $sql_extra = "true"; + } + elseif ($box=="inbox") { $sql_extra = "`from-url`!='".dbesc( $profile_url )."'"; } @@ -1607,41 +1631,17 @@ ); $ret = Array(); - foreach($r as $item){ + foreach($r as $item) { if ($box == "inbox" || $item['from-url'] != $profile_url){ - $recipient = $user_info; - $sender = api_get_user($a,$item['contact-id']); - } elseif ($box == "sentbox" || $item['from-url'] != $profile_url){ - $recipient = api_get_user($a,$item['contact-id']); - $sender = $user_info; + $recipient = $user_info; + $sender = api_get_user($a,$item['contact-id']); } - - $d=Array( - 'id' => $item['id'], - 'created_at'=> api_date($item['created']), - 'sender_id'=> $sender['id'] , - 'sender_screen_name'=> $sender['screen_name'], - 'sender_profile_img'=> $item['from-photo'], - 'sender'=> $sender, - 'recipient_id'=> $recipient['id'], - 'recipient_screen_name'=> $recipient['screen_name'], - 'recipient'=> $recipient, - ); - //don't send title to regular StatusNET requests to avoid confusing these apps - if (isset($_GET["getText"])) { - $d['title'] = $item['title'] ; - if ($_GET["getText"] == "html") { - $d['text'] = bbcode($item['body']); - } elseif ($_GET["getText"] == "plain") { - $d['text'] = html2plain(bbcode($item['body']), 0); - } - } else { - $d['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); - } - if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") { - unset($d['sender']); unset($d['recipient']); - } - $ret[]=$d; + elseif ($box == "sentbox" || $item['from-url'] != $profile_url){ + $recipient = api_get_user($a,$item['contact-id']); + $sender = $user_info; + } + + $ret[]=api_format_messages($item, $recipient, $sender); }