]> git.mxchange.org Git - friendica.git/commitdiff
New versions of Twidere crashed during posting.
authorMichael Vogel <icarus@dabo.de>
Mon, 17 Aug 2015 20:38:05 +0000 (22:38 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 17 Aug 2015 20:38:05 +0000 (22:38 +0200)
include/api.php
mod/api.php

index 1069835817bfa367810ed54df2ca3a669866a772..b6fd1d2de296e49db3839cce6833a5b66a1bcc9f 100644 (file)
@@ -9,6 +9,15 @@
        require_once("include/html2plain.php");
        require_once("mod/share.php");
        require_once("include/Photo.php");
+       require_once("mod/item.php");
+       require_once('include/security.php');
+       require_once('include/contact_selectors.php');
+       require_once('library/HTMLPurifier.auto.php');
+       require_once('include/html2bbcode.php');
+       require_once('mod/wall_upload.php');
+       require_once("mod/proxy.php");
+       require_once("include/message.php");
+
 
        /*
         * Twitter-Like API
                        die('This api requires login');
                }
 
-               require_once('include/security.php');
                authenticate_success($record); $_SESSION["allow_api"] = true;
 
                call_hooks('logged_in', $a->user);
                                if (strpos($a->query_string, ".atom")>0) $type="atom";
                                if (strpos($a->query_string, ".as")>0) $type="as";
 
+                               $stamp =  microtime(true);
                                $r = call_user_func($info['func'], $a, $type);
+                               $duration = (float)(microtime(true)-$stamp);
+                               logger("API call duration: ".round($duration, 2)."\t".$a->query_string, LOGGER_DEBUG);
+
                                if ($r===false) return;
 
                                switch($type){
                        $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
                }
 
-               require_once('include/contact_selectors.php');
                $network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']);
 
                $ret = Array(
                $txt = requestdata('status');
                //$txt = urldecode(requestdata('status'));
 
-               require_once('library/HTMLPurifier.auto.php');
-               require_once('include/html2bbcode.php');
-
                if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
                        $txt = html2bb_video($txt);
                        $config = HTMLPurifier_Config::createDefault();
                $a->argv[1]=$user_info['screen_name']; //should be set to username?
 
                $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
-               require_once('mod/wall_upload.php');
                $bebop = wall_upload_post($a);
 
                //now that we have the img url in bbcode we can add it to the status and insert the wall item.
                $_REQUEST['body']=$txt."\n\n".$bebop;
-               require_once('mod/item.php');
                item_post($a);
 
                // this should output the last post (the one we just posted).
                // logger('api_post: ' . print_r($_POST,true));
 
                if(requestdata('htmlstatus')) {
-                       require_once('library/HTMLPurifier.auto.php');
-                       require_once('include/html2bbcode.php');
-
                        $txt = requestdata('htmlstatus');
                        if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
 
                $_REQUEST['title'] = requestdata('title');
 
                $parent = requestdata('in_reply_to_status_id');
+
+               // Twidere sends "-1" if it is no reply ...
+               if ($parent == -1)
+                       $parent = "";
+
                if(ctype_digit($parent))
                        $_REQUEST['parent'] = $parent;
                else
                if(x($_FILES,'media')) {
                        // upload the image if we have one
                        $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
-                       require_once('mod/wall_upload.php');
                        $media = wall_upload_post($a);
                        if(strlen($media)>0)
                                $_REQUEST['body'] .= "\n\n".$media;
 
                // 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 false;
                }
 
-               require_once('mod/wall_upload.php');
                $media = wall_upload_post($a, false);
                if(!$media) {
                        // Output error
                        if (!x($_REQUEST, "source"))
                                $_REQUEST["source"] = api_source();
 
-                       require_once('mod/item.php');
                        item_post($a);
                }
 
 
                $ret = api_statuses_show($a, $type);
 
-               require_once('include/items.php');
                drop_item($id, false);
 
                return($ret);
                $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false");
 
                if ($include_entities != "true") {
-                       require_once("mod/proxy.php");
 
                        preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
 
                                        // If image cache is activated, then use the following sizes:
                                        // thumb  (150), small (340), medium (600) and large (1024)
                                        if (!get_config("system", "proxy_disabled")) {
-                                               require_once("mod/proxy.php");
                                                $media_url = proxy_url($url);
 
                                                $sizes = array();
 
                $sender = api_get_user($a);
 
-               require_once("include/message.php");
-
                if ($_POST['screen_name']) {
                        $r = q("SELECT `id`, `nurl`, `network` FROM `contact` WHERE `uid`=%d AND `nick`='%s'",
                                        intval(api_user()),
index 63f8a934c81ef5e18a488cb113f21ab0b73eba1f..e3b5ea3a929e76ff77a687adcad1fbb39a40b7b7 100644 (file)
@@ -4,19 +4,19 @@ require_once('include/api.php');
 
 function oauth_get_client($request){
 
-       
+
        $params = $request->get_parameters();
        $token = $params['oauth_token'];
-       
-       $r = q("SELECT `clients`.* 
-                       FROM `clients`, `tokens` 
-                       WHERE `clients`.`client_id`=`tokens`.`client_id` 
+
+       $r = q("SELECT `clients`.*
+                       FROM `clients`, `tokens`
+                       WHERE `clients`.`client_id`=`tokens`.`client_id`
                        AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'",
                        dbesc($token));
 
        if (!count($r))
                return null;
-       
+
        return $r[0];
 }
 
@@ -36,31 +36,31 @@ function api_post(&$a) {
 
 function api_content(&$a) {
        if ($a->cmd=='api/oauth/authorize'){
-               /* 
+               /*
                 * api/oauth/authorize interact with the user. return a standard page
                 */
-               
+
                $a->page['template'] = "minimal";
-               
-               
+
+
                // get consumer/client from request token
                try {
                        $request = OAuthRequest::from_request();
                } catch(Exception $e) {
                        echo "<pre>"; var_dump($e); killme();
                }
-               
-               
+
+
                if (x($_POST,'oauth_yes')){
-               
+
                        $app = oauth_get_client($request);
                        if (is_null($app)) return "Invalid request. Unknown token.";
                        $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
 
                        $verifier = md5($app['secret'].local_user());
                        set_config("oauth", $verifier, local_user());
-                       
-                       
+
+
                        if ($consumer->callback_url!=null) {
                                $params = $request->get_parameters();
                                $glue="?";
@@ -68,35 +68,35 @@ function api_content(&$a) {
                                goaway($consumer->callback_url.$glue."oauth_token=".OAuthUtil::urlencode_rfc3986($params['oauth_token'])."&oauth_verifier=".OAuthUtil::urlencode_rfc3986($verifier));
                                killme();
                        }
-                       
-                       
-                       
+
+
+
                        $tpl = get_markup_template("oauth_authorize_done.tpl");
                        $o = replace_macros($tpl, array(
                                '$title' => t('Authorize application connection'),
                                '$info' => t('Return to your app and insert this Securty Code:'),
                                '$code' => $verifier,
                        ));
-               
+
                        return $o;
-               
-               
+
+
                }
-               
-               
+
+
                if(! local_user()) {
                        //TODO: we need login form to redirect to this page
                        notice( t('Please login to continue.') . EOL );
                        return login(false,$request->get_parameters());
                }
                //FKOAuth1::loginUser(4);
-               
+
                $app = oauth_get_client($request);
                if (is_null($app)) return "Invalid request. Unknown token.";
-               
-               
 
-               
+
+
+
                $tpl = get_markup_template('oauth_authorize.tpl');
                $o = replace_macros($tpl, array(
                        '$title' => t('Authorize application connection'),
@@ -105,15 +105,12 @@ function api_content(&$a) {
                        '$yes'  => t('Yes'),
                        '$no'   => t('No'),
                ));
-               
+
                //echo "<pre>"; var_dump($app); killme();
-               
+
                return $o;
        }
 
        echo api_call($a);
        killme();
 }
-
-
-