]> git.mxchange.org Git - friendica.git/commitdiff
scale external images
authorfriendica <info@friendica.com>
Sat, 25 Feb 2012 22:22:51 +0000 (14:22 -0800)
committerfriendica <info@friendica.com>
Sat, 25 Feb 2012 22:22:51 +0000 (14:22 -0800)
include/bb2diaspora.php
include/diaspora.php
include/network.php
mod/item.php

index bcef86616be4f73498fb6418ddb7577a3d0af86f..8487f845a62848a75750632f14b773047096dbde 100755 (executable)
@@ -55,42 +55,12 @@ function diaspora2bb($s) {
        $s = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/ism","[code]$2[/code]", $s);
 
        // Don't show link to full picture (until it is fixed)
-       $s = scale_diaspora_images($s, false);
+       $s = scale_external_images($s, false);
 
        return $s;
 }
 
 
-function scale_diaspora_images($s,$include_link = true) {
-
-       $matches = null;
-       $c = preg_match_all('/\[img\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
-       if($c) {
-               require_once('include/Photo.php');
-               foreach($matches as $mtch) {
-                       logger('scale_diaspora_image: ' . $mtch[1]);
-                       $i = fetch_url($mtch[1]);
-                       if($i) {
-                               $ph = new Photo($i);
-                               if($ph->is_valid()) {
-                                       if($ph->getWidth() > 600 || $ph->getHeight() > 600) {
-                                               $ph->scaleImage(600);
-                                               $new_width = $ph->getWidth();
-                                               $new_height = $ph->getHeight();
-                                               logger('scale_diaspora_image: ' . $new_width . 'w ' . $new_height . 'h' . 'match: ' . $mtch[0], LOGGER_DEBUG);
-                                               $s = str_replace($mtch[0],'[img=' . $new_width . 'x' . $new_height. ']' . $mtch[1] . '[/img]'
-                                                       . "\n" . (($include_link) 
-                                                               ? '[url=' . $mtch[1] . ']' . t('view full size') . '[/url]' . "\n"
-                                                               : ''),$s);
-                                               logger('scale_diaspora_image: new string: ' . $s, LOGGER_DEBUG);
-                                       }
-                               }
-                       }
-               }
-       }
-       return $s;
-}
-
 function stripdcode_br_cb($s) {
        return '[code]' . str_replace('<br />', "\n\t", $s[1]) . '[/code]';
 }
index 5896f1bfd476b4bafcbb503ac73f8112435b8eaa..dca857a19833369cf9f5d43eca1e41e8e5820b41 100755 (executable)
@@ -794,15 +794,15 @@ function diaspora_reshare($importer,$xml) {
 
        if(strlen($source_xml->post->asphoto->objectId) && ($source_xml->post->asphoto->objectId != 0) && ($source_xml->post->asphoto->image_url)) {
                $body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n";
-               $body = scale_diaspora_images($body,false);
+               $body = scale_external_images($body,false);
        }
        elseif($source_xml->post->asphoto->image_url) {
                $body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n";
-               $body = scale_diaspora_images($body);
+               $body = scale_external_images($body);
        }
        elseif($source_xml->post->status_message) {
                $body = diaspora2bb($source_xml->post->status_message->raw_message);
-               $body = scale_diaspora_images($body);
+               $body = scale_external_images($body);
 
        }
        else {
@@ -945,11 +945,11 @@ function diaspora_asphoto($importer,$xml) {
 
        if(strlen($xml->objectId) && ($xml->objectId != 0) && ($xml->image_url)) {
                $body = '[url=' . notags(unxmlify($xml->image_url)) . '][img]' . notags(unxmlify($xml->objectId)) . '[/img][/url]' . "\n";
-               $body = scale_diaspora_images($body,false);
+               $body = scale_external_images($body,false);
        }
        elseif($xml->image_url) {
                $body = '[img]' . notags(unxmlify($xml->image_url)) . '[/img]' . "\n";
-               $body = scale_diaspora_images($body);
+               $body = scale_external_images($body);
        }
        else {
                logger('diaspora_asphoto: no photo url found.');
@@ -1476,7 +1476,7 @@ function diaspora_photo($importer,$xml,$msg) {
 
        $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n";
 
-       $link_text = scale_diaspora_images($link_text);
+       $link_text = scale_external_images($link_text);
 
        if(strpos($parent_item['body'],$link_text) === false) {
                $r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d limit 1",
index 25db62d1611a0d4b78c8970981b03c5e1663abe5..531c3ea4c8714ba18c21a09517e11c28b927bfc2 100755 (executable)
@@ -776,3 +776,43 @@ function add_fcontact($arr,$update = false) {
 
        return $r;
 }
+
+
+function scale_external_images($s,$include_link = true) {
+
+       $a = get_app();
+
+       $matches = null;
+       $c = preg_match_all('/\[img\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
+       if($c) {
+               require_once('include/Photo.php');
+               foreach($matches as $mtch) {
+                       logger('scale_external_image: ' . $mtch[1]);
+                       $hostname = str_replace('www.','',substr($a->get_baseurl(),strpos($a->get_baseurl(),'://')+3));
+                       if(stristr($mtch[1],$hostname))
+                               continue;
+                       $i = fetch_url($mtch[1]);
+                       if($i) {
+                               $ph = new Photo($i);
+                               if($ph->is_valid()) {
+                                       $orig_width = $ph->getWidth();
+                                       $orig_height = $ph->getHeight();
+
+                                       if($orig_width > 640 || $orig_height > 640) {
+
+                                               $ph->scaleImage(640);
+                                               $new_width = $ph->getWidth();
+                                               $new_height = $ph->getHeight();
+                                               logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
+                                               $s = str_replace($mtch[0],'[img=' . $new_width . 'x' . $new_height. ']' . $mtch[1] . '[/img]'
+                                                       . "\n" . (($include_link) 
+                                                               ? '[url=' . $mtch[1] . ']' . t('view full size') . '[/url]' . "\n"
+                                                               : ''),$s);
+                                               logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG);
+                                       }
+                               }
+                       }
+               }
+       }
+       return $s;
+}
index 3035989f36ef8c36dc8ba1108c541ddd4af75085..9e0768a6582180815550fa40127f8ed00b8fbd7f 100755 (executable)
@@ -400,6 +400,8 @@ function item_post(&$a) {
 
        $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body); 
 
+       $body = scale_external_images($body,false);
+
        /**
         * Look for any tags and linkify them
         */