]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
allow users to set categories on their posts
[friendica.git] / include / text.php
index d34fd7fbeec35bcacfb5a1bd2fa201a3e770d692..f204e3f9b97dda32ef1da0a67433d362957eae6e 100644 (file)
@@ -20,7 +20,7 @@ function replace_macros($s,$r) {
        
        //$a = get_app();
        //$a->page['debug'] .= "$tt <br>\n";
-       return $r;
+       return template_unescape($r);
 
 }}
 
@@ -205,7 +205,6 @@ function hex2bin($s) {
                return '';
 
        if(! ctype_xdigit($s)) {
-               logger('hex2bin: illegal input: ' . print_r(debug_backtrace(), true));
                return($s);
        }
 
@@ -610,6 +609,8 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
                        $url = $redirect_url;
                        $sparkle = ' sparkle';
                }
+               else
+                       $url = zrl($url);
        }
        $click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : '');
        if($click)
@@ -638,7 +639,7 @@ if(! function_exists('search')) {
 function search($s,$id='search-box',$url='/search',$save = false) {
        $a = get_app();
        $o  = '<div id="' . $id . '">';
-       $o .= '<form action="' . $a->get_baseurl() . $url . '" method="get" >';
+       $o .= '<form action="' . $a->get_baseurl((stristr($url,'network')) ? true : false) . $url . '" method="get" >';
        $o .= '<input type="text" name="search" id="search-text" value="' . $s .'" />';
        $o .= '<input type="submit" name="submit" id="search-submit" value="' . t('Search') . '" />'; 
        if($save)
@@ -694,8 +695,13 @@ function linkify($s) {
 
 if(! function_exists('smilies')) {
 function smilies($s, $sample = false) {
+
        $a = get_app();
 
+       if(intval(get_config('system','no_smilies')) 
+               || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
+               return $s;
+
        $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_encode',$s);
        $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_encode',$s);
 
@@ -704,27 +710,21 @@ function smilies($s, $sample = false) {
                '&lt;/3', 
                '&lt;\\3', 
                ':-)', 
-//             ':)', 
                ';-)', 
-//             ';)', 
                ':-(', 
-//             ':(', 
                ':-P', 
-//             ':P', 
+               ':-p', 
                ':-"', 
                ':-&quot;', 
                ':-x', 
                ':-X', 
                ':-D', 
-//             ':D', 
                '8-|', 
                '8-O', 
                ':-O', 
                '\\o/', 
                'o.O', 
                'O.o', 
-               '\\.../', 
-               '\\ooo/', 
                ":'(", 
                ":-!", 
                ":-/", 
@@ -734,12 +734,8 @@ function smilies($s, $sample = false) {
                ':homebrew', 
                ':coffee', 
                ':facepalm',
-               ':headdesk',
                '~friendika', 
-               '~friendica', 
-//             'Diaspora*' 
-               ':beard',
-               ':whitebeard'
+               '~friendica'
 
        );
 
@@ -748,27 +744,21 @@ function smilies($s, $sample = false) {
                '<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-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-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=":-/" />',
@@ -778,12 +768,8 @@ function smilies($s, $sample = false) {
                '<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://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>',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-beard.png" alt=":beard" />',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-whitebeard.png" alt=":whitebeard" />'
+               '<a href="http://friendica.com">~friendica <img src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>'
        );
 
        $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
@@ -934,7 +920,7 @@ function prepare_body($item,$attach = false) {
                foreach($matches as $mtch) {
                        if(strlen($x))
                                $x .= ',';
-                       $x .= file_tag_decode($mtch[1]);
+                       $x .= xmlify(file_tag_decode($mtch[1]));
                }
                if(strlen($x))
                        $s .= '<div class="categorytags"><span>' . t('Categories:') . ' </span>' . $x . '</div>'; 
@@ -949,12 +935,42 @@ function prepare_body($item,$attach = false) {
                foreach($matches as $mtch) {
                        if(strlen($x))
                                $x .= '&nbsp;&nbsp;&nbsp;';
-                       $x .= file_tag_decode($mtch[1]). ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . file_tag_decode($mtch[1]) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>';
+                       $x .= xmlify(file_tag_decode($mtch[1])) . ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>';
                }
                if(strlen($x) && (local_user() == $item['uid']))
                        $s .= '<div class="filesavetags"><span>' . t('Filed under:') . ' </span>' . $x . '</div>'; 
        }
 
+       // Look for spoiler
+       $spoilersearch = '<blockquote class="spoiler">';
+
+       // Remove line breaks before the spoiler
+       while ((strpos($s, "\n".$spoilersearch) !== false))
+               $s = str_replace("\n".$spoilersearch, $spoilersearch, $s);
+       while ((strpos($s, "<br />".$spoilersearch) !== false))
+               $s = str_replace("<br />".$spoilersearch, $spoilersearch, $s);
+
+       while ((strpos($s, $spoilersearch) !== false)) {
+
+               $pos = strpos($s, $spoilersearch);
+               $rnd = random_string(8);
+               $spoilerreplace = '<br /> <span id="spoiler-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
+                                       '<blockquote class="spoiler" id="spoiler-'.$rnd.'" style="display: none;">';
+               $s = substr($s, 0, $pos).$spoilerreplace.substr($s, $pos+strlen($spoilersearch));
+       }
+
+       // Look for quote with author
+       $authorsearch = '<blockquote class="author">';
+
+       while ((strpos($s, $authorsearch) !== false)) {
+
+               $pos = strpos($s, $authorsearch);
+               $rnd = random_string(8);
+               $authorreplace = '<br /> <span id="author-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
+                                       '<blockquote class="author" id="author-'.$rnd.'" style="display: block;">';
+               $s = substr($s, 0, $pos).$authorreplace.substr($s, $pos+strlen($authorsearch));
+       }
+
        $prep_arr = array('item' => $item, 'html' => $s);
        call_hooks('prepare_body_final', $prep_arr);
 
@@ -1290,13 +1306,126 @@ function file_tag_decode($s) {
 }
 
 function file_tag_file_query($table,$s,$type = 'file') {
+
        if($type == 'file')
-               $str = preg_quote( '[' . file_tag_encode($s) . ']' );
+               $str = preg_quote( '[' . str_replace('%','%%',file_tag_encode($s)) . ']' );
        else
-               $str = preg_quote( '<' . file_tag_encode($s) . '>' );
+               $str = preg_quote( '<' . str_replace('%','%%',file_tag_encode($s)) . '>' );
        return " AND " . (($table) ? dbesc($table) . '.' : '') . "file regexp '" . dbesc($str) . "' ";
 }
 
+// ex. given music,video return <music><video> or [music][video]
+function file_tag_list_to_file($list,$type = 'file') {
+        $tag_list = '';
+        if(strlen($list)) {
+                $list_array = explode(",",$list);
+                if($type == 'file') {
+                       $lbracket = '[';
+                       $rbracket = ']';
+               }
+                else {
+                       $lbracket = '<';
+                       $rbracket = '>';
+               }
+
+                foreach($list_array as $item) {
+                 if(strlen($item)) {
+                               $tag_list .= $lbracket . file_tag_encode(trim($item))  . $rbracket;
+                       }
+                }
+       }
+        return $tag_list;
+}
+
+// ex. given <music><video>[friends], return music,video or friends
+function file_tag_file_to_list($file,$type = 'file') {
+        $matches = false;
+        $list = '';
+        if($type == 'file') {
+                $cnt = preg_match_all('/\[(.*?)\]/',$file,$matches,PREG_SET_ORDER);
+       }
+        else {
+                $cnt = preg_match_all('/<(.*?)>/',$file,$matches,PREG_SET_ORDER);
+       }
+       if($cnt) {
+               foreach($matches as $mtch) {
+                       if(strlen($list))
+                               $list .= ',';
+                       $list .= file_tag_decode($mtch[1]);
+               }
+       }
+
+        return $list;
+}
+
+function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') {
+        // $file_old - categories previously associated with an item
+        // $file_new - new list of categories for an item
+
+       if(! intval($uid))
+               return false;
+
+        if($file_old == $file_new)
+               return true;
+
+       $saved = get_pconfig($uid,'system','filetags');
+        if(strlen($saved)) {
+                if($type == 'file') {
+                       $lbracket = '[';
+                       $rbracket = ']';
+               }
+                else {
+                       $lbracket = '<';
+                       $rbracket = '>';
+               }
+
+                $filetags_updated = $saved;
+
+               // check for new tags to be added as filetags in pconfig
+                $new_tags = array();
+                $check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
+
+               foreach($check_new_tags as $tag) {
+                       if(! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
+                               $new_tags[] = $tag;
+               }
+
+               $filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
+
+               // check for deleted tags to be removed from filetags in pconfig
+                $deleted_tags = array();
+                $check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
+
+               foreach($check_deleted_tags as $tag) {
+                       if(! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
+                               $deleted_tags[] = $tag;
+               }
+
+                foreach($deleted_tags as $key => $tag) {
+                       $r = q("select file from item where uid = %d " . file_tag_file_query('item',$tag,$type),
+                               intval($uid)
+                       );
+
+                       if(count($r)) {
+                               unset($deleted_tags[$key]);
+                       }
+                       else {
+                               $filetags_updated = str_replace($lbracket . file_tag_encode($tag) . $rbracket,'',$filetags_updated);
+                       }
+               }
+
+                if($saved != $filetags_updated) {
+                       set_pconfig($uid,'system','filetags', $filetags_updated);
+                }
+               return true;
+       }
+        else
+                if(strlen($file_new)) {
+                       set_pconfig($uid,'system','filetags', $file_new);
+                }
+               return true;
+}
+
 function file_tag_save_file($uid,$item,$file) {
        $result = false;
        if(! intval($uid))
@@ -1315,6 +1444,7 @@ function file_tag_save_file($uid,$item,$file) {
                $saved = get_pconfig($uid,'system','filetags');
                if((! strlen($saved)) || (! stristr($saved,'[' . file_tag_encode($file) . ']')))
                        set_pconfig($uid,'system','filetags',$saved . '[' . file_tag_encode($file) . ']');
+               info( t('Item filed') );
        }
        return true;
 }
@@ -1350,3 +1480,19 @@ function file_tag_unsave_file($uid,$item,$file) {
        return true;
 }
 
+function normalise_openid($s) {
+       return trim(str_replace(array('http://','https://'),array('',''),$s),'/');
+}
+
+
+function undo_post_tagging($s) {
+       $matches = null;
+       $cnt = preg_match_all('/([@#])\[url=(.*?)\](.*?)\[\/url\]/ism',$s,$matches,PREG_SET_ORDER);
+       if($cnt) {
+               foreach($matches as $mtch) {
+                       $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);
+               }
+       }
+       return $s;
+}
+