X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=d61cc3d4aacd6a4dfcb50f328dcb3ae852c0008e;hb=660bd39efad52b1c69bd8dd0ca27141b81f84ca5;hp=e94c689fb33bd2bc915b590d467d5cacde5195f9;hpb=22772876a9db871db484c4008a934ce1d0fd86be;p=friendica.git diff --git a/include/api.php b/include/api.php index e94c689fb3..d61cc3d4aa 100644 --- a/include/api.php +++ b/include/api.php @@ -710,6 +710,8 @@ 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 @@ -1617,18 +1619,32 @@ 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(); + + $result = q("SELECT `installed` FROM `addon` WHERE `name` = 'privacy_image_cache' AND `installed`"); + $image_cache = (count($result) > 0); + $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false"); - if ($include_entities != "true") + if ($include_entities != "true") { + if ($image_cache) { + require_once("addon/privacy_image_cache/privacy_image_cache.php"); + + preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images); + + foreach ($images[1] AS $image) { + $replace = $a->get_baseurl()."/privacy_image_cache/".privacy_image_cache_cachename($image); + $text = str_replace($image, $replace, $text); + } + } return array(); + } $bbcode = bb_CleanPictureLinks($bbcode); @@ -1653,7 +1669,7 @@ '[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); @@ -1717,24 +1733,47 @@ $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 privacy_image_cache is activated, then use the following sizes: + // thumb (150), small (340), medium (600) and large (1024) + if ($image_cache) { + require_once("addon/privacy_image_cache/privacy_image_cache.php"); + $media_url = $a->get_baseurl()."/privacy_image_cache/".privacy_image_cache_cachename($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; } @@ -1816,12 +1855,12 @@ '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,