]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge pull request #53 from fabrixxm/master
[friendica.git] / include / text.php
old mode 100644 (file)
new mode 100755 (executable)
index 2d65b68..1f5d4a3
@@ -195,6 +195,9 @@ function unxmlify($s) {
 
 if(! function_exists('hex2bin')) {
 function hex2bin($s) {
+       if(! (is_string($s) && strlen($s)))
+               return '';
+
        if(! ctype_xdigit($s)) {
                logger('hex2bin: illegal input: ' . print_r(debug_backtrace(), true));
                return($s);
@@ -388,11 +391,13 @@ function get_intltext_template($s) {
 
 if(! function_exists('get_markup_template')) {
 function get_markup_template($s) {
-
+       $a=get_app();
        $theme = current_theme();
        
        if(file_exists("view/theme/$theme/$s"))
                return file_get_contents("view/theme/$theme/$s");
+       elseif (x($a->theme_info,"extends") && file_exists("view/theme/".$a->theme_info["extends"]."/$s"))
+               return file_get_contents("view/theme/".$a->theme_info["extends"]."/$s");
        else
                return file_get_contents("view/$s");
 
@@ -421,6 +426,12 @@ function attribute_contains($attr,$s) {
 
 if(! function_exists('logger')) {
 function logger($msg,$level = 0) {
+       // turn off logger in install mode
+       global $a;
+       global $db;
+
+       if(($a->module == 'install') || (! ($db && $db->connected))) return;
+
        $debugging = get_config('system','debugging');
        $loglevel  = intval(get_config('system','loglevel'));
        $logfile   = get_config('system','logfile');
@@ -460,7 +471,7 @@ function get_tags($s) {
        // Match full names against @tags including the space between first and last
        // We will look these up afterward to see if they are full names or not recognisable.
 
-       if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
+       if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/',$s,$match)) {
                foreach($match[1] as $mtch) {
                        if(strstr($mtch,"]")) {
                                // we might be inside a bbcode color tag - leave it alone
@@ -476,7 +487,7 @@ function get_tags($s) {
        // Otherwise pull out single word tags. These can be @nickname, @first_last
        // and #hash tags.
 
-       if(preg_match_all('/([@#][^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
+       if(preg_match_all('/([@#][^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/',$s,$match)) {
                foreach($match[1] as $mtch) {
                        if(strstr($mtch,"]")) {
                                // we might be inside a bbcode color tag - leave it alone
@@ -487,6 +498,9 @@ function get_tags($s) {
                        // ignore strictly numeric tags like #1
                        if((strpos($mtch,'#') === 0) && ctype_digit(substr($mtch,1)))
                                continue;
+                       // try not to catch url fragments
+                       if(strpos($s,$mtch) && preg_match('/[a-zA-z0-9\/]/',substr($s,strpos($s,$mtch)-1,1)))
+                               continue;
                        $ret[] = $mtch;
                }
        }
@@ -526,34 +540,44 @@ function contact_block() {
        $a = get_app();
 
        $shown = get_pconfig($a->profile['uid'],'system','display_friend_count');
-       if(! $shown)
+       if($shown === false)
                $shown = 24;
+       if($shown == 0)
+               return;
 
        if((! is_array($a->profile)) || ($a->profile['hide-friends']))
                return $o;
-       $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0",
+       $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0",
                        intval($a->profile['uid'])
        );
        if(count($r)) {
                $total = intval($r[0]['total']);
        }
        if(! $total) {
-               $o .= '<h4 class="contact-h4">' . t('No contacts') . '</h4>';
-               return $o;
-       }
-       $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT %d",
-                       intval($a->profile['uid']),
-                       intval($shown)
-       );
-       if(count($r)) {
-               $o .= '<h4 class="contact-h4">' .  sprintf( tt('%d Contact','%d Contacts', $total),$total) . '</h4><div id="contact-block">';
-               foreach($r as $rr) {
-                       $o .= micropro($rr,true,'mpfriend');
-               }
-               $o .= '</div><div id="contact-block-end"></div>';
-               $o .=  '<div id="viewcontacts"><a id="viewcontacts-link" href="viewcontacts/' . $a->profile['nickname'] . '">' . t('View Contacts') . '</a></div>';
+               $contacts = t('No contacts');
+               $micropro = Null;
                
+       } else {
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 ORDER BY RAND() LIMIT %d",
+                               intval($a->profile['uid']),
+                               intval($shown)
+               );
+               if(count($r)) {
+                       $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
+                       $micropro = Array();
+                       foreach($r as $rr) {
+                               $micropro[] = micropro($rr,true,'mpfriend');
+                       }
+               }
        }
+       
+       $tpl = get_markup_template('contact_block.tpl');
+       $o = replace_macros($tpl, array(
+               '$contacts' => $contacts,
+               '$nickname' => $a->profile['nickname'],
+               '$viewcontacts' => t('View Contacts'),
+               '$micropro' => $micropro,
+       ));
 
        $arr = array('contacts' => $r, 'output' => $o);
 
@@ -619,7 +643,7 @@ function search($s,$id='search-box',$url='/search',$save = false) {
 
 if(! function_exists('valid_email')) {
 function valid_email($x){
-       if(preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
+       if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
                return true;
        return false;
 }}
@@ -635,7 +659,8 @@ function valid_email($x){
 
 if(! function_exists('linkify')) {
 function linkify($s) {
-       $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="external-link">$1</a>', $s);
+       $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="external-link">$1</a>', $s);
+       $s = preg_replace("/\<(.*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism",'<$1$2=$3&$4>',$s);
        return($s);
 }}
 
@@ -650,42 +675,136 @@ function linkify($s) {
  * @Parameter: string $s
  *
  * Returns string
+ *
+ * It is expected that this function will be called using HTML text.
+ * We will escape text between HTML pre and code blocks from being 
+ * processed. 
+ * 
+ * At a higher level, the bbcode [nosmile] tag can be used to prevent this 
+ * function from being executed by the prepare_text() routine when preparing
+ * bbcode source for HTML display
+ *
  */
 
 if(! function_exists('smilies')) {
-function smilies($s) {
+function smilies($s, $sample = false) {
        $a = get_app();
 
-       $s = str_replace(
-       array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', 
-               '~friendika', 'Diaspora*' ),
-       array(
+       $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_encode',$s);
+       $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_encode',$s);
+
+       $texts =  array( 
+               '&lt;3', 
+               '&lt;/3', 
+               '&lt;\\3', 
+               ':-)', 
+//             ':)', 
+               ';-)', 
+//             ';)', 
+               ':-(', 
+//             ':(', 
+               ':-P', 
+//             ':P', 
+               ':-"', 
+               ':-&quot;', 
+               ':-x', 
+               ':-X', 
+               ':-D', 
+//             ':D', 
+               '8-|', 
+               '8-O', 
+               ':-O', 
+               '\\o/', 
+               'o.O', 
+               'O.o', 
+               '\\.../', 
+               '\\ooo/', 
+               ":'(", 
+               ":-!", 
+               ":-/", 
+               ":-[", 
+               "8-)",
+               ':beer', 
+               ':homebrew', 
+               ':coffee', 
+               ':facepalm',
+               ':headdesk',
+               '~friendika', 
+               '~friendica', 
+               'Diaspora*' 
+       );
+
+       $icons = array(
                '<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":)" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":)" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";)"/>',                
                '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":(" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":(" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":P" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":P" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":D"/>',                
                '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" />',                
+               '<img src="' . $a->get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-shaka.gif" alt="\\.../" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-shaka.gif" alt="\\ooo/" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
+               '<img src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
+               '<img src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" />',
+               '<img src="' . $a->get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-bangheaddesk.gif" alt=":headdesk" />',
                '<a href="http://project.friendika.com">~friendika <img src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendika" /></a>',
-               '<a href="http://joindiaspora.com">Diaspora<img src="' . $a->get_baseurl() . '/images/diaspora.png" alt="Diaspora*" /></a>',
+               '<a href="http://friendica.com">~friendica <img src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>',
+               '<a href="http://diasporafoundation.org">Diaspora<img src="' . $a->get_baseurl() . '/images/diaspora.png" alt="Diaspora*" /></a>',
+
+       );
+
+       $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
+       call_hooks('smilie', $params);
+
+       if($sample) {
+               $s = '<div class="smiley-sample">';
+               for($x = 0; $x < count($params['texts']); $x ++) {
+                       $s .= '<dl><dt>' . $params['texts'][$x] . '</dt><dd>' . $params['icons'][$x] . '</dd></dl>';
+               }
+       }
+       else {
+               $s = str_replace($params['texts'],$params['icons'],$params['string']);
+       }
 
-       ), $s);
+       $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_decode',$s);
+       $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_decode',$s);
 
-       call_hooks('smilie', $s);
        return $s;
 
 }}
 
+function smile_encode($m) {
+       return(str_replace($m[1],base64url_encode($m[1]),$m[0]));
+}
+
+function smile_decode($m) {
+       return(str_replace($m[1],base64url_decode($m[1]),$m[0]));
+}
+
+
 
 
 if(! function_exists('day_translate')) {
@@ -733,7 +852,14 @@ function link_compare($a,$b) {
 if(! function_exists('prepare_body')) {
 function prepare_body($item,$attach = false) {
 
+       call_hooks('prepare_body_init', $item); 
+
        $s = prepare_text($item['body']);
+
+       $prep_arr = array('item' => $item, 'html' => $s);
+       call_hooks('prepare_body', $prep_arr);
+       $s = $prep_arr['html'];
+
        if(! $attach)
                return $s;
 
@@ -751,10 +877,10 @@ function prepare_body($item,$attach = false) {
                                        case 'audio':
                                        case 'image':
                                        case 'text':
-                                               $icon = '<div class="attachtype type-' . $icontype . '"></div>';
+                                               $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>';
                                                break;
                                        default:
-                                               $icon = '<div class="attachtype type-unkn"></div>';
+                                               $icon = '<div class="attachtype icon s22 type-unkn"></div>';
                                                break;
                                }
                                $title = ((strlen(trim($matches[4]))) ? escape_tags(trim($matches[4])) : escape_tags($matches[1]));
@@ -765,7 +891,11 @@ function prepare_body($item,$attach = false) {
                }
                $s .= '<div class="clear"></div></div>';
        }
-       return $s;
+
+
+       $prep_arr = array('item' => $item, 'html' => $s);
+       call_hooks('prepare_body_final', $prep_arr);
+       return $prep_arr['html'];
 }}
 
 
@@ -776,7 +906,10 @@ function prepare_text($text) {
 
        require_once('include/bbcode.php');
 
-       $s = smilies(bbcode($text));
+       if(stristr($text,'[nosmile]'))
+               $s = bbcode($text);
+       else
+               $s = smilies(bbcode($text));
 
        return $s;
 }}
@@ -825,9 +958,14 @@ function feed_salmonlinks($nick) {
 if(! function_exists('get_plink')) {
 function get_plink($item) {
        $a = get_app(); 
-       $plink = (((x($item,'plink')) && (! $item['private'])) ? '<div class="wall-item-links-wrapper"><a href="' 
-                       . $item['plink'] . '" title="' . t('link to source') . '" target="external-link" class="icon remote-link"></a></div>' : '');
-       return $plink;
+       if (x($item,'plink') && (! $item['private'])){
+               return array(
+                       'href' => $item['plink'],
+                       'title' => t('link to source'),
+               );
+       } else {
+               return false;
+       }
 }}
 
 if(! function_exists('unamp')) {
@@ -843,16 +981,22 @@ function lang_selector() {
        global $lang;
        $o = '<div id="lang-select-icon" class="icon language" title="' . t('Select an alternate language') . '" onclick="openClose(\'language-selector\');" ></div>';
        $o .= '<div id="language-selector" style="display: none;" >';
-       $o .= '<form action="" method="post" ><select name="system_language" onchange="this.form.submit();" >';
+       $o .= '<form action="#" method="post" ><select name="system_language" onchange="this.form.submit();" >';
        $langs = glob('view/*/strings.php');
        if(is_array($langs) && count($langs)) {
+               $langs[] = '';
                if(! in_array('view/en/strings.php',$langs))
                        $langs[] = 'view/en/';
                asort($langs);
                foreach($langs as $l) {
+                       if($l == '') {
+                               $default_selected = ((! x($_SESSION,'language')) ? ' selected="selected" ' : '');
+                               $o .= '<option value="" ' . $default_selected . '>' . t('default') . '</option>';
+                               continue;
+                       }
                        $ll = substr($l,5);
                        $ll = substr($ll,0,strrpos($ll,'/'));
-                       $selected = (($ll === $lang) ? ' selected="selected" ' : '');
+                       $selected = (($ll === $lang && (x($_SESSION, 'language'))) ? ' selected="selected" ' : '');
                        $o .= '<option value="' . $ll . '"' . $selected . '>' . $ll . '</option>';
                }
        }
@@ -899,6 +1043,11 @@ function base64url_encode($s, $strip_padding = false) {
 
 function base64url_decode($s) {
 
+       if(is_array($s)) {
+               logger('base64url_decode: illegal input: ' . print_r(debug_backtrace(), true));
+               return $s;
+       }
+
 /*
  *  // Placeholder for new rev of salmon which strips base64 padding.
  *  // PHP base64_decode handles the un-padded input without requiring this step
@@ -918,6 +1067,137 @@ function base64url_decode($s) {
        return base64_decode(strtr($s,'-_','+/'));
 }
 
-function cc_license() {
-return '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
+
+if (!function_exists('str_getcsv')) {
+    function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = '\\', $eol = '\n') {
+        if (is_string($input) && !empty($input)) {
+            $output = array();
+            $tmp    = preg_split("/".$eol."/",$input);
+            if (is_array($tmp) && !empty($tmp)) {
+                while (list($line_num, $line) = each($tmp)) {
+                    if (preg_match("/".$escape.$enclosure."/",$line)) {
+                        while ($strlen = strlen($line)) {
+                            $pos_delimiter       = strpos($line,$delimiter);
+                            $pos_enclosure_start = strpos($line,$enclosure);
+                            if (
+                                is_int($pos_delimiter) && is_int($pos_enclosure_start)
+                                && ($pos_enclosure_start < $pos_delimiter)
+                                ) {
+                                $enclosed_str = substr($line,1);
+                                $pos_enclosure_end = strpos($enclosed_str,$enclosure);
+                                $enclosed_str = substr($enclosed_str,0,$pos_enclosure_end);
+                                $output[$line_num][] = $enclosed_str;
+                                $offset = $pos_enclosure_end+3;
+                            } else {
+                                if (empty($pos_delimiter) && empty($pos_enclosure_start)) {
+                                    $output[$line_num][] = substr($line,0);
+                                    $offset = strlen($line);
+                                } else {
+                                    $output[$line_num][] = substr($line,0,$pos_delimiter);
+                                    $offset = (
+                                                !empty($pos_enclosure_start)
+                                                && ($pos_enclosure_start < $pos_delimiter)
+                                                )
+                                                ?$pos_enclosure_start
+                                                :$pos_delimiter+1;
+                                }
+                            }
+                            $line = substr($line,$offset);
+                        }
+                    } else {
+                        $line = preg_split("/".$delimiter."/",$line);
+   
+                        /*
+                         * Validating against pesky extra line breaks creating false rows.
+                         */
+                        if (is_array($line) && !empty($line[0])) {
+                            $output[$line_num] = $line;
+                        } 
+                    }
+                }
+                return $output;
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+} 
+
+function cleardiv() {
+       return '<div class="clear"></div>';
+}
+
+
+function bb_translate_video($s) {
+
+       $matches = null;
+       $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
+       if($r) {
+               foreach($matches as $mtch) {
+                       if((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
+                               $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
+                       elseif(stristr($mtch[1],'vimeo'))
+                               $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
+               }
+       }
+       return $s;      
+}
+
+function html2bb_video($s) {
+
+       $s = preg_replace('#<object[^>]+>(.*?)https+://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)</object>#ism',
+                       '[youtube]$2[/youtube]', $s);
+
+       $s = preg_replace('#<iframe[^>](.*?)https+://www.youtube.com/embed/([A-Za-z0-9\-_=]+)(.*?)</iframe>#ism',
+                       '[youtube]$2[/youtube]', $s);
+
+       $s = preg_replace('#<iframe[^>](.*?)https+://player.vimeo.com/video/([0-9]+)(.*?)</iframe>#ism',
+                       '[vimeo]$2[/vimeo]', $s);
+
+       return $s;
+}
+
+/**
+ * apply xmlify() to all values of array $val, recursively
+ */
+function array_xmlify($val){
+       if (is_bool($val)) return $val?"true":"false";
+       if (is_array($val)) return array_map('array_xmlify', $val);
+       return xmlify((string) $val);
+}
+
+
+function reltoabs($text, $base)
+{
+  if (empty($base))
+    return $text;
+
+  $base = rtrim($base,'/');
+
+  $base2 = $base . "/";
+       
+  // Replace links
+  $pattern = "/<a([^>]*) href=\"(?!http|https|\/)([^\"]*)\"/";
+  $replace = "<a\${1} href=\"" . $base2 . "\${2}\"";
+  $text = preg_replace($pattern, $replace, $text);
+
+  $pattern = "/<a([^>]*) href=\"(?!http|https)([^\"]*)\"/";
+  $replace = "<a\${1} href=\"" . $base . "\${2}\"";
+  $text = preg_replace($pattern, $replace, $text);
+
+  // Replace images
+  $pattern = "/<img([^>]*) src=\"(?!http|https|\/)([^\"]*)\"/";
+  $replace = "<img\${1} src=\"" . $base2 . "\${2}\"";
+  $text = preg_replace($pattern, $replace, $text); 
+
+  $pattern = "/<img([^>]*) src=\"(?!http|https)([^\"]*)\"/";
+  $replace = "<img\${1} src=\"" . $base . "\${2}\"";
+  $text = preg_replace($pattern, $replace, $text); 
+
+
+  // Done
+  return $text;
 }
+