]> git.mxchange.org Git - friendica.git/commitdiff
api profiles
authorFriendika <info@friendika.com>
Mon, 1 Aug 2011 03:01:00 +0000 (20:01 -0700)
committerFriendika <info@friendika.com>
Mon, 1 Aug 2011 03:01:00 +0000 (20:01 -0700)
include/api.php
mod/item.php

index 0d446d1a77959e9dc2c2a93dc6b04a508b1b2762..45ca6f1a820a98f88abe0777d8d23fd00df23a43 100644 (file)
                                //echo "<pre>"; var_dump($r); die();
                        }
                }
-               return false;
+               $r = '<status><error>not implemented</error></status>';
+               switch($type){
+                       case "xml":
+                               header ("Content-Type: text/xml");
+                               return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
+                               break;
+                       case "json": 
+                               header ("Content-Type: application/json");  
+                           return json_encode(array('error' => 'not implemented'));
+                               break;
+                       case "rss":
+                               header ("Content-Type: application/rss+xml");
+                               return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
+                               break;
+                       case "atom":
+                               header ("Content-Type: application/atom+xml");
+                               return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
+                               break;
+                               
+               }
        }
 
        /**
                        return False;
                }
                
-               // count public wall messages
-               $r = q("SELECT COUNT(`id`) as `count` FROM `item`
-                               WHERE  `uid` = %d
-                               AND `type`='wall' 
-                               AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
-                               intval($uinfo[0]['uid'])
-               );
-               $countitms = $r[0]['count'];
-               
+               if($uinfo[0]['self']) {
+                       // count public wall messages
+                       $r = q("SELECT COUNT(`id`) as `count` FROM `item`
+                                       WHERE  `uid` = %d
+                                       AND `type`='wall' 
+                                       AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
+                                       intval($uinfo[0]['uid'])
+                       );
+                       $countitms = $r[0]['count'];
+               }
+               else {
+                       $r = q("SELECT COUNT(`id`) as `count` FROM `item`
+                                       WHERE  `contact-id` = %d
+                                       AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
+                                       intval($uinfo[0]['id'])
+                       );
+                       $countitms = $r[0]['count'];
+               }
+
                // count friends
                $r = q("SELECT COUNT(`id`) as `count` FROM `contact`
                                WHERE  `uid` = %d
                                intval($uinfo[0]['uid'])
                );
                $countfriends = $r[0]['count'];
-                               
+
+               if(! $uinfo[0]['self']) {
+                       $countfriends = 0;
+               }
 
                $ret = Array(
                        'uid' => $uinfo[0]['uid'],
 
        
        function api_format_items($r,$user_info) {
+
+               //logger('api_format_items: ' . print_r($r,true));
+
+               //logger('api_format_items: ' . print_r($user_info,true));
+
                $a = get_app();
                $ret = Array();
 
index c4b4351c1801279477d974e782dcf86f3234715e..4b9f3d091f83f1dd82e666a6d8de732dad7bbbe9 100644 (file)
@@ -33,11 +33,18 @@ function item_post(&$a) {
 
        call_hooks('post_local_start', $_POST);
 
+
+       /**
+        * Is this a reply to something?
+        */
+
        $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
        $parent_uri = ((x($_POST,'parent_uri')) ? trim($_POST['parent_uri']) : '');
 
        $parent_item = null;
        $parent_contact = null;
+       $thr_parent = '';
+       $parid = 0;
        $r = false;
 
        if($parent || $parent_uri) {
@@ -47,11 +54,20 @@ function item_post(&$a) {
                        );
                }
                elseif($parent_uri && local_user()) {
+                       $_POST['type'] = 'net-comment';
                        // This is coming from an API source, we are logged in
+                       // This query will find the immediate parent
                        $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                                dbesc($parent_uri),
                                intval(local_user())
                        );
+                       // now find the real parent of the conversation
+                       if(count($r)) {
+                               $parid = $r[0]['parent'];
+                               $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
+                                       intval($parid)
+                               );
+                       }
                }
 
                if(($r === false) || (! count($r))) {
@@ -62,6 +78,11 @@ function item_post(&$a) {
                }
                $parent_item = $r[0];
                $parent = $r[0]['id'];
+
+               // multi-level threading - preserve the info but re-parent to our single level threading
+               if(($parid) && ($parid != $parent))
+                       $thr_parent = $parent_uri;
+
                if($parent_item['contact-id'] && $uid) {
                        $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                                intval($parent_item['contact-id']),
@@ -195,6 +216,8 @@ function item_post(&$a) {
                        $contact_record = $r[0];
        }
 
+
+
        $post_type = notags(trim($_POST['type']));
 
        if($post_type === 'net-comment') {
@@ -458,6 +481,7 @@ function item_post(&$a) {
        $datarray['private']       = $private;
        $datarray['pubmail']       = $pubmail_enable;
        $datarray['attach']        = $attachments;
+       $datarray['thr-parent']    = $thr_parent;
 
        /**
         * These fields are for the convenience of plugins...
@@ -495,9 +519,9 @@ function item_post(&$a) {
 
 
        $r = q("INSERT INTO `item` (`uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, 
-               `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `received`, `changed`, `uri`, `title`, `body`, `app`, `location`, `coord`, 
+               `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, 
                `tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach` )
-               VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s' )",
+               VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s' )",
                intval($datarray['uid']),
                dbesc($datarray['type']),
                intval($datarray['wall']),
@@ -514,6 +538,7 @@ function item_post(&$a) {
                dbesc($datarray['received']),
                dbesc($datarray['changed']),
                dbesc($datarray['uri']),
+               dbesc($datarray['thr-parent']),
                dbesc($datarray['title']),
                dbesc($datarray['body']),
                dbesc($datarray['app']),