]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Merge remote-tracking branch 'upstream/master'
[friendica.git] / include / api.php
index e94c689fb33bd2bc915b590d467d5cacde5195f9..ade783662bd5d15e08dea74bc80bbadf302c8cc4 100644 (file)
                if($parent)
                        $_REQUEST['type'] = 'net-comment';
                else {
+//                     logger("api_statuses_update: upload ".print_r($_FILES, true)." ".print_r($_POST, true)." ".print_r($_GET, true), LOGGER_DEBUG);
+//die("blubb");
                        $_REQUEST['type'] = 'wall';
                        if(x($_FILES,'media')) {
                                // upload the image if we have one
                        $in_reply_to_status_id_str = NULL;
                        $in_reply_to_user_id_str = NULL;
                        $in_reply_to_screen_name = NULL;
-                       if ($lastwall['parent']!=$lastwall['id']) {
+                       if (intval($lastwall['parent']) != intval($lastwall['id'])) {
                                $in_reply_to_status_id= intval($lastwall['parent']);
                                $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
 
                                }
                        }
 
+                       // There seems to be situation, where both fields are identical:
+                       // https://github.com/friendica/friendica/issues/1010
+                       // This is a bugfix for that.
+                       if (intval($in_reply_to_status_id) == intval($lastwall['id'])) {
+                               logger('api_status_show: this message should never appear: id: '.$lastwall['id'].' similar to reply-to: '.$in_reply_to_status_id, LOGGER_DEBUG);
+                               $in_reply_to_status_id = NULL;
+                               $in_reply_to_user_id = NULL;
+                               $in_reply_to_status_id_str = NULL;
+                               $in_reply_to_user_id_str = NULL;
+                               $in_reply_to_screen_name = NULL;
+                       }
+
                        $status_info = array(
                                'text' => trim(html2plain(bbcode(api_clean_plain_items($lastwall['body']), false, false, 2, true), 0)),
                                'truncated' => false,
                        `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
                        FROM `item`, `contact`
                        WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
-                       AND `contact`.`id` = `item`.`contact-id`
+                       AND `contact`.`id` = `item`.`contact-id` AND `item`.`uid` = %d AND `item`.`verb` = '%s'
                        AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                        $sql_extra",
+                       intval(api_user()),
+                       dbesc(ACTIVITY_POST),
                        intval($id)
                );
 
                return $ret;
        }
 
-       function api_get_entitities($text, $bbcode) {
+       function api_get_entitities(&$text, $bbcode) {
                /*
                To-Do:
                * Links at the first character of the post
-               * different sizes of pictures
-               * caching picture data (using the id for that?) (See privacy_image_cache)
                */
 
+               $a = get_app();
+
                $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false");
 
-               if ($include_entities != "true")
+               if ($include_entities != "true") {
+                       require_once("mod/proxy.php");
+
+                       preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
+
+                       foreach ($images[1] AS $image) {
+                               $replace = proxy_url($image);
+                               $text = str_replace($image, $replace, $text);
+                       }
                        return array();
+               }
 
                $bbcode = bb_CleanPictureLinks($bbcode);
 
                                        '[url=https://www.youtube.com/watch?v=$1]https://www.youtube.com/watch?v=$1[/url]', $bbcode);
                $bbcode = preg_replace("/\[youtube\](.*?)\[\/youtube\]/ism",'[url=$1]$1[/url]',$bbcode);
 
-               $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
+               $bbcode = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
                                        '[url=https://vimeo.com/$1]https://vimeo.com/$1[/url]', $bbcode);
                $bbcode = preg_replace("/\[vimeo\](.*?)\[\/vimeo\]/ism",'[url=$1]$1[/url]',$bbcode);
 
 
                        $start = iconv_strpos($text, $url, $offset, "UTF-8");
                        if (!($start === false)) {
-                               $redirects = 0;
-                               $img_str = fetch_url($url,true, $redirects, 10);
-                               $image = @imagecreatefromstring($img_str);
+                               require_once("include/Photo.php");
+                               $image = get_photo_info($url);
                                if ($image) {
+                                       // 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();
+                                               $scale = scale_image($image[0], $image[1], 150);
+                                               $sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
+
+                                               if (($image[0] > 150) OR ($image[1] > 150)) {
+                                                       $scale = scale_image($image[0], $image[1], 340);
+                                                       $sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
+                                               }
+
+                                               $scale = scale_image($image[0], $image[1], 600);
+                                               $sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
+
+                                               if (($image[0] > 600) OR ($image[1] > 600)) {
+                                                       $scale = scale_image($image[0], $image[1], 1024);
+                                                       $sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
+                                               }
+                                       } else {
+                                               $media_url = $url;
+                                               $sizes["medium"] = array("w" => $image[0], "h" => $image[1], "resize" => "fit");
+                                       }
+
                                        $entities["media"][] = array(
                                                                "id" => $start+1,
                                                                "id_str" => (string)$start+1,
                                                                "indices" => array($start, $start+strlen($url)),
-                                                               "media_url" => $url,
-                                                               "media_url_https" => $url,
+                                                               "media_url" => normalise_link($media_url),
+                                                               "media_url_https" => $media_url,
                                                                "url" => $url,
                                                                "display_url" => $display_url,
                                                                "expanded_url" => $url,
                                                                "type" => "photo",
-                                                               "sizes" => array("medium" => array(
-                                                                                               "w" => imagesx($image),
-                                                                                               "h" => imagesy($image),
-                                                                                               "resize" => "fit")));
+                                                               "sizes" => $sizes);
                                }
                                $offset = $start + 1;
                        }
                                'truncated' => False,
                                'created_at'=> api_date($item['created']),
                                'in_reply_to_status_id' => $in_reply_to_status_id,
-                               'in_reply_to_status_id_str' => $in_reply_to_status_id,
+                               'in_reply_to_status_id_str' => $in_reply_to_status_id_str,
                                'source'    => (($item['app']) ? $item['app'] : 'web'),
                                'id'            => intval($item['id']),
                                'id_str'        => (string) intval($item['id']),
                                'in_reply_to_user_id' => $in_reply_to_user_id,
-                               'in_reply_to_user_id_str' => $in_reply_to_user_id,
+                               'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
                                'in_reply_to_screen_name' => $in_reply_to_screen_name,
                                'geo' => NULL,
                                'favorited' => $item['starred'] ? true : false,
        api_register_func('api/oauth/request_token', 'api_oauth_request_token', false);
        api_register_func('api/oauth/access_token', 'api_oauth_access_token', false);
 
+
+       function api_fr_photos_list(&$a,$type) {
+               if (api_user()===false) return false;
+               $r = q("select distinct `resource-id` from photo where uid = %d and album != 'Contact Photos' ",
+                       intval(local_user())
+               );
+               if($r) {
+                       $ret = array();
+                       foreach($r as $rr)
+                               $ret[] = $rr['resource-id'];
+                       header("Content-type: application/json");
+                       echo json_encode($ret);
+               }
+               killme();
+       }
+
+       function api_fr_photo_detail(&$a,$type) {
+               if (api_user()===false) return false;
+               if(! $_REQUEST['photo_id']) return false;
+               $scale = ((array_key_exists('scale',$_REQUEST)) ? intval($_REQUEST['scale']) : 0);
+               $r = q("select * from photo where uid = %d and `resource-id` = '%s' and scale = %d limit 1",
+                       intval(local_user()),
+                       dbesc($_REQUEST['photo_id']),
+                       intval($scale)
+               );
+               if($r) {
+                       header("Content-type: application/json");
+                       $r[0]['data'] = base64_encode($r[0]['data']);
+                       echo json_encode($r[0]);
+               }
+
+               killme();       
+       }
+
+       api_register_func('api/friendica/photos/list', 'api_fr_photos_list', true);
+       api_register_func('api/friendica/photo', 'api_fr_photo_detail', true);
+
+
+
+
+
+
 function api_share_as_retweet($a, $uid, &$item) {
        $body = trim($item["body"]);