]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
I want HTML code!
[friendica.git] / include / api.php
index 5c17b35f56e7ae25b64631b653e966f3523dae75..32579fe7d387959bb7972f5a116bdab9373aee7a 100644 (file)
                        
                }
                
-               logger('api_user: ' . $extra_query . ' ' , $user);
+               logger('api_user: ' . $extra_query . ', user: ' . $user);
                // user info            
                $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `contact`
                                WHERE 1
                if ($page<0) $page=0;
                $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
                $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
+               $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
                //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
 
                $start = $page*$count;
 
                //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
 
+               $sql_extra = '';
                if ($max_id > 0)
-                       $sql_extra = 'AND `item`.`id` <= '.intval($max_id);
+                       $sql_extra .= ' AND `item`.`id` <= '.intval($max_id);
+               if ($exclude_replies > 0)
+                       $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
 
                $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
                        `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
                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";
 
                $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
                        `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
                        AND `contact`.`id` = `item`.`contact-id`
                        AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                        $sql_extra
-                       AND `item`.`id`=%d",
+                       ",
                        intval($id)
                );
-
+//var_dump($r);
                $ret = api_format_items($r,$user_info);
-
-               $data = array('$status' => $ret[0]);
-               /*switch($type){
-                       case "atom":
-                       case "rss":
-                               $data = api_rss_extra($a, $data, $user_info);
-               }*/
-               return  api_apply_template("status", $type, $data);
+//var_dump($ret);
+               if ($_GET["conversation"] == "true") {
+                       $data = array('$statuses' => $ret);
+                       return  api_apply_template("timeline", $type, $data);
+               } else {
+                       $data = array('$status' => $ret[0]);
+                       /*switch($type){
+                               case "atom":
+                               case "rss":
+                                       $data = api_rss_extra($a, $data, $user_info);
+                       }*/
+                       return  api_apply_template("status", $type, $data);
+               }
        }
        api_register_func('api/statuses/show','api_statuses_show', true);
 
                // params
                $id = intval($a->argv[3]);
 
-               logger('API: api_statuses_repeat: '.$id);               
+               logger('API: api_statuses_repeat: '.$id);
 
                //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
 
                        intval($id)
                );
 
-               $_REQUEST['body'] = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body'];
-               $_REQUEST['profile_uid'] = local_user();
-               $_REQUEST['type'] = 'wall';
-               $_REQUEST['api_source'] = true;
+               if ($r[0]['body'] != "") {
+                       $_REQUEST['body'] = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body'];
+                       $_REQUEST['profile_uid'] = local_user();
+                       $_REQUEST['type'] = 'wall';
+                       $_REQUEST['api_source'] = true;
 
-               require_once('mod/item.php');
-               item_post($a);
+                       require_once('mod/item.php');
+                       item_post($a);
+               }
 
                if ($type == 'xml')
                        $ok = "true";
                // params
                $id = intval($a->argv[3]);
 
-               logger('API: api_statuses_destroy: '.$id);      
+               logger('API: api_statuses_destroy: '.$id);
 
                require_once('include/items.php');
                drop_item($id, false);
                $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
                if ($page<0) $page=0;
                $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
+               $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
                //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
                
                $start = $page*$count;
 
-               if ($user_info['self']==1) $sql_extra = "AND `item`.`wall` = 1 ";
+               $sql_extra = '';
+               if ($user_info['self']==1) $sql_extra .= " AND `item`.`wall` = 1 ";
+               if ($exclude_replies > 0)  $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
 
                $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
                        `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
                
                $start = $page*$count;
                
-       
+    $profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
                if ($box=="sentbox") {
-                       $sql_extra = "`from-url`='%s'";
-               } else {
-                       $sql_extra = "`from-url`!='%s'";
+                       $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( $profile_url )."'";
                }
                
                $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){
-                       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(
+                       $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,
-                               
-                               '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"])) {
+        $d['title'] = $item['title'] ;
+        if ($_GET["getText"] == "true") {
+          $d['text'] = bbcode($item['body']);
+        }
+      } 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;
                }
                
 
        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);
 
@@ -1652,7 +1686,6 @@ account/update_profile_background_image
 account/update_profile_image
 blocks/create
 blocks/destroy
-oauth/authorize
 
 Not implemented in status.net:
 statuses/retweeted_to_me