]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
use atom_time on atom entries
[friendica.git] / include / api.php
index 0753962ab983621a0db8985afff378e50807dc03..43a77bcc7a7ecfeb321846e55289f53ae934da9e 100644 (file)
         * Simple HTTP Login
         */
        function api_login(&$a){
+               // workaround for HTTP-auth in CGI mode
+               if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
+                       $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
+                       if(strlen($userpass)) {
+                               list($name, $password) = explode(':', $userpass);
+                               $_SERVER['PHP_AUTH_USER'] = $name;
+                               $_SERVER['PHP_AUTH_PW'] = $password;
+                       }
+               }
+
                if (!isset($_SERVER['PHP_AUTH_USER'])) {
+                  logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
                    header('WWW-Authenticate: Basic realm="Friendika"');
                    header('HTTP/1.0 401 Unauthorized');
-                   die('This api require login');
+                   die('This api requires login');
                }
                
                $user = $_SERVER['PHP_AUTH_USER'];
                if(count($r)){
                        $record = $r[0];
                } else {
+                  logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
                    header('WWW-Authenticate: Basic realm="Friendika"');
                    header('HTTP/1.0 401 Unauthorized');
-                   die('This api require login');
+                   die('This api requires login');
                }
                $_SESSION['uid'] = $record['uid'];
                $_SESSION['theme'] = $record['theme'];
                        'lang' => 'en', #XXX: fix me
                        'description' => '',
                        'followers_count' => $countfriends, #XXX: fix me
-                       'lang' => 'en', #XXX: fix me
                        'favourites_count' => 0,
                        'contributors_enabled' => false,
                        'follow_request_sent' => false,
                        case "atom":
                        case "xml":
                                $data = api_xmlify($data);
-                               $tpl = file_get_contents("view/api_".$templatename."_".$type.".tpl");
+                               $tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
                                $ret = replace_macros($tpl, $data);
                                break;
                        case "json":
        }
        api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
                
+
+       // TODO - media uploads and alternate 'source'
        
+       function api_statuses_update(&$a, $type) {
+               if (local_user()===false) return false;
+               $user_info = api_get_user($a);
+
+               // convert $_POST array items to the form we use for web posts.
+
+               $_POST['body'] = urldecode($_POST['status']);
+               $_POST['parent'] = $_POST['in_reply_to_status_id'];
+               if($_POST['lat'] && $_POST['long'])
+                       $_POST['coord'] = sprintf("%s %s",$_POST['lat'],$_POST['long']);
+               $_POST['profile_uid'] = local_user();
+               if($_POST['parent'])
+                       $_POST['type'] = 'net-comment';
+               else
+                       $_POST['type'] = 'wall';
+
+               // set this so that the item_post() function is quiet and doesn't redirect or emit json
+
+               $_POST['api_source'] = true;
+
+               // call out normal post function
+
+               require_once('mod/item.php');
+               item_post($a);  
+
+               // this should output the last post (the one we just posted).
+               return api_status_show($a,$type);
+       }
+       api_register_func('api/statuses/update','api_statuses_update', true);
+
+
+       function api_status_show(&$a, $type){
+               $user_info = api_get_user($a);
+               // get last public wall message
+               $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
+                               FROM `item`, `contact`,
+                                       (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i` 
+                               WHERE `item`.`contact-id` = %d
+                                       AND `i`.`id` = `item`.`parent`
+                                       AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
+                                       AND `type`!='activity'
+                                       AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
+                               ORDER BY `created` DESC 
+                               LIMIT 1",
+                               intval($user_info['id'])
+               );
+
+               if (count($lastwall)>0){
+                       $lastwall = $lastwall[0];
+                       
+                       $in_reply_to_status_id = '';
+                       $in_reply_to_user_id = '';
+                       $in_reply_to_screen_name = '';
+                       if ($lastwall['parent']!=$lastwall['id']) {
+                               $in_reply_to_status_id=$lastwall['parent'];
+                               $in_reply_to_user_id = $lastwall['reply_uid'];
+                               $in_reply_to_screen_name = $lastwall['reply_author'];
+                       }  
+                       $status_info = array(
+                               'created_at' => api_date($lastwall['created']),
+                               'id' => $lastwall['contact-id'],
+                               'text' => strip_tags(bbcode($lastwall['body'])),
+                               'source' => 'web',
+                               'truncated' => false,
+                               'in_reply_to_status_id' => $in_reply_to_status_id,
+                               'in_reply_to_user_id' => $in_reply_to_user_id,
+                               'favorited' => false,
+                               'in_reply_to_screen_name' => $in_reply_to_screen_name,
+                               'geo' => '',
+                               'coordinates' => $lastwall['coord'],
+                               'place' => $lastwall['location'],
+                               'contributors' => ''                                    
+                       );
+                       $status_info['user'] = $user_info;
+               }
+               return  api_apply_template("status", $type, array('$status' => $status_info));
+               
+       }
+
+
+
+
                
        /**
         * Returns extended information of a given user, specified by ID or screen name as per the required id parameter.
                foreach($r as $item) {
                        $status = array(
                                'created_at'=> api_date($item['created']),
+                               'published' => datetime_convert('UTC','UTC',$item['created'],ATOM_TIME),
+                               'updated'   => datetime_convert('UTC','UTC',$item['edited'],ATOM_TIME),
                                'id'            => $item['id'],
                                'text'          => strip_tags(bbcode($item['body'])),
                                'html'          => bbcode($item['body']),
                                'source'        => 'web',
                                'url'           => ($item['plink']!=''?$item['plink']:$item['author-link']),
                                'truncated' => False,
-                               'in_reply_to_status_id' => ($item['parent']!=$item['id']?$item['id']:''),
+                               'in_reply_to_status_id' => ($item['parent']!=$item['id']?$item['parent']:''),
                                'in_reply_to_user_id' => '',
                                'favorited' => false,
                                'in_reply_to_screen_name' => '',