3 // This is our template processor.
4 // $s is the string requiring macro substitution.
5 // $r is an array of key value pairs (search => replace)
6 // returns substituted string.
7 // WARNING: this is pretty basic, and doesn't properly handle search strings that are substrings of each other.
8 // For instance if 'test' => "foo" and 'testing' => "bar", testing could become either bar or fooing,
9 // depending on the order in which they were declared in the array.
11 require_once("include/template_processor.php");
12 require_once("include/friendica_smarty.php");
14 if(! function_exists('replace_macros')) {
15 function replace_macros($s,$r) {
18 $stamp1 = microtime(true);
22 if($a->theme['template_engine'] === 'smarty3') {
24 if(gettype($s) === 'string') {
26 $s = new FriendicaSmarty();
28 foreach($r as $key=>$value) {
30 $key = substr($key, 1);
32 $s->assign($key, $value);
34 $output = $s->parsed($template);
37 $r = $t->replace($s,$r);
39 $output = template_unescape($r);
42 $stamp2 = microtime(true);
43 $duration = (float)($stamp2-$stamp1);
44 $a->performance["rendering"] += (float)$duration;
50 // random string, there are 86 characters max in text mode, 128 for hex
53 define('RANDOM_STRING_HEX', 0x00 );
54 define('RANDOM_STRING_TEXT', 0x01 );
56 if(! function_exists('random_string')) {
57 function random_string($size = 64,$type = RANDOM_STRING_HEX) {
58 // generate a bit of entropy and run it through the whirlpool
59 $s = hash('whirlpool', (string) rand() . uniqid(rand(),true) . (string) rand(),(($type == RANDOM_STRING_TEXT) ? true : false));
60 $s = (($type == RANDOM_STRING_TEXT) ? str_replace("\n","",base64url_encode($s,true)) : $s);
61 return(substr($s,0,$size));
65 * This is our primary input filter.
67 * The high bit hack only involved some old IE browser, forget which (IE5/Mac?)
68 * that had an XSS attack vector due to stripping the high-bit on an 8-bit character
69 * after cleansing, and angle chars with the high bit set could get through as markup.
71 * This is now disabled because it was interfering with some legitimate unicode sequences
72 * and hopefully there aren't a lot of those browsers left.
74 * Use this on any text input where angle chars are not valid or permitted
75 * They will be replaced with safer brackets. This may be filtered further
76 * if these are not allowed either.
80 if(! function_exists('notags')) {
81 function notags($string) {
83 return(str_replace(array("<",">"), array('[',']'), $string));
85 // High-bit filter no longer used
86 // return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
89 // use this on "body" or "content" input where angle chars shouldn't be removed,
90 // and allow them to be safely displayed.
92 if(! function_exists('escape_tags')) {
93 function escape_tags($string) {
95 return(htmlspecialchars($string, ENT_COMPAT, 'UTF-8', false));
99 // generate a string that's random, but usually pronounceable.
100 // used to generate initial passwords
102 if(! function_exists('autoname')) {
103 function autoname($len) {
108 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
109 if(mt_rand(0,5) == 4)
127 's','sc','sh','sm','sp','st',
135 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
136 'nd','ng','nk','nt','rn','rp','rt');
138 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
139 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
141 $start = mt_rand(0,2);
149 for ($x = 0; $x < $len; $x ++) {
150 $r = mt_rand(0,count($table) - 1);
153 if($table == $vowels)
154 $table = array_merge($cons,$midcons);
160 $word = substr($word,0,$len);
162 foreach($noend as $noe) {
163 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
164 $word = substr($word,0,-1);
168 if(substr($word,-1) == 'q')
169 $word = substr($word,0,-1);
174 // escape text ($str) for XML transport
175 // returns escaped text.
177 if(! function_exists('xmlify')) {
178 function xmlify($str) {
181 for($x = 0; $x < mb_strlen($str); $x ++) {
211 $buffer = trim($buffer);
216 // pass xml escaped text ($s), returns unescaped text
218 if(! function_exists('unxmlify')) {
219 function unxmlify($s) {
220 $ret = str_replace('&','&', $s);
221 $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
225 // convenience wrapper, reverse the operation "bin2hex"
227 if(! function_exists('hex2bin')) {
228 function hex2bin($s) {
229 if(! (is_string($s) && strlen($s)))
232 if(! ctype_xdigit($s)) {
236 return(pack("H*",$s));
239 // Automatic pagination.
240 // To use, get the count of total items.
241 // Then call $a->set_pager_total($number_items);
242 // Optionally call $a->set_pager_itemspage($n) to the number of items to display on each page
243 // Then call paginate($a) after the end of the display loop to insert the pager block on the page
244 // (assuming there are enough items to paginate).
245 // When using with SQL, the setting LIMIT %d, %d => $a->pager['start'],$a->pager['itemspage']
246 // will limit the results to the correct items for the current page.
247 // The actual page handling is then accomplished at the application layer.
249 if(! function_exists('paginate')) {
250 function paginate(&$a) {
252 $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string);
254 // $stripped = preg_replace('/&zrl=(.*?)([\?&]|$)/ism','',$stripped);
256 $stripped = str_replace('q=','',$stripped);
257 $stripped = trim($stripped,'/');
258 $pagenum = $a->pager['page'];
259 $url = $a->get_baseurl() . '/' . $stripped;
262 if($a->pager['total'] > $a->pager['itemspage']) {
263 $o .= '<div class="pager">';
264 if($a->pager['page'] != 1)
265 $o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">' . t('prev') . '</a></span> ';
267 $o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">" . t('first') . "</a></span> ";
269 $numpages = $a->pager['total'] / $a->pager['itemspage'];
272 $numstop = $numpages;
275 $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
276 $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
279 for($i = $numstart; $i <= $numstop; $i++){
280 if($i == $a->pager['page'])
281 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
283 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
287 if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
288 if($i == $a->pager['page'])
289 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
291 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
295 $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
296 $o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">" . t('last') . "</a></span> ";
298 if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
299 $o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('next') . '</a></span>';
300 $o .= '</div>'."\r\n";
305 if(! function_exists('alt_pager')) {
306 function alt_pager(&$a, $i) {
308 $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string);
309 $stripped = str_replace('q=','',$stripped);
310 $stripped = trim($stripped,'/');
311 $pagenum = $a->pager['page'];
312 $url = $a->get_baseurl() . '/' . $stripped;
314 $o .= '<div class="pager">';
316 if($a->pager['page']>1)
317 $o .= "<a href=\"$url"."&page=".($a->pager['page'] - 1).'" class="pager_newer">' . t('newer') . '</a>';
319 if($a->pager['page']>1)
320 $o .= " - ";
321 $o .= "<a href=\"$url"."&page=".($a->pager['page'] + 1).'" class="pager_older">' . t('older') . '</a>';
325 $o .= '</div>'."\r\n";
330 // Turn user/group ACLs stored as angle bracketed text into arrays
332 if(! function_exists('expand_acl')) {
333 function expand_acl($s) {
334 // turn string array of angle-bracketed elements into numeric array
335 // e.g. "<1><2><3>" => array(1,2,3);
339 $t = str_replace('<','',$s);
340 $a = explode('>',$t);
343 $ret[] = intval($aa);
349 // Used to wrap ACL elements in angle brackets for storage
351 if(! function_exists('sanitise_acl')) {
352 function sanitise_acl(&$item) {
354 $item = '<' . intval(notags(trim($item))) . '>';
360 // Convert an ACL array to a storable string
361 // Normally ACL permissions will be an array.
362 // We'll also allow a comma-separated string.
364 if(! function_exists('perms2str')) {
365 function perms2str($p) {
371 $tmp = explode(',',$p);
374 array_walk($tmp,'sanitise_acl');
375 $ret = implode('',$tmp);
380 // generate a guaranteed unique (for this domain) item ID for ATOM
381 // safe from birthday paradox
383 if(! function_exists('item_new_uri')) {
384 function item_new_uri($hostname,$uid) {
388 $hash = random_string();
390 $uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash;
392 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
396 } while($dups == true);
400 // Generate a guaranteed unique photo ID.
401 // safe from birthday paradox
403 if(! function_exists('photo_new_resource')) {
404 function photo_new_resource() {
408 $resource = hash('md5',uniqid(mt_rand(),true));
409 $r = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' LIMIT 1",
414 } while($found == true);
419 // wrapper to load a view template, checking for alternate
420 // languages before falling back to the default
422 // obsolete, deprecated.
424 if(! function_exists('load_view_file')) {
425 function load_view_file($s) {
431 if(file_exists("$d/$lang/$b"))
432 return file_get_contents("$d/$lang/$b");
434 $theme = current_theme();
436 if(file_exists("$d/theme/$theme/$b"))
437 return file_get_contents("$d/theme/$theme/$b");
439 return file_get_contents($s);
442 if(! function_exists('get_intltext_template')) {
443 function get_intltext_template($s) {
448 if($a->theme['template_engine'] === 'smarty3')
449 $engine = "/smarty3";
454 if(file_exists("view/$lang$engine/$s"))
455 return file_get_contents("view/$lang$engine/$s");
456 elseif(file_exists("view/en$engine/$s"))
457 return file_get_contents("view/en$engine/$s");
459 return file_get_contents("view$engine/$s");
462 if(! function_exists('get_markup_template')) {
463 function get_markup_template($s, $root = '') {
464 $stamp1 = microtime(true);
468 if($a->theme['template_engine'] === 'smarty3') {
469 $template_file = get_template_file($a, 'smarty3/' . $s, $root);
471 $template = new FriendicaSmarty();
472 $template->filename = $template_file;
474 $stamp2 = microtime(true);
475 $duration = (float)($stamp2-$stamp1);
476 $a->performance["rendering"] += (float)$duration;
481 $template_file = get_template_file($a, $s, $root);
483 $stamp2 = microtime(true);
484 $duration = (float)($stamp2-$stamp1);
485 $a->performance["rendering"] += (float)$duration;
487 return file_get_contents($template_file);
491 if(! function_exists("get_template_file")) {
492 function get_template_file($a, $filename, $root = '') {
493 $theme = current_theme();
495 // Make sure $root ends with a slash /
496 if($root !== '' && $root[strlen($root)-1] !== '/')
499 if(file_exists("{$root}view/theme/$theme/$filename"))
500 $template_file = "{$root}view/theme/$theme/$filename";
501 elseif (x($a->theme_info,"extends") && file_exists("{$root}view/theme/{$a->theme_info["extends"]}/$filename"))
502 $template_file = "{$root}view/theme/{$a->theme_info["extends"]}/$filename";
504 $template_file = "{$root}view/$filename";
506 return $template_file;
513 // for html,xml parsing - let's say you've got
514 // an attribute foobar="class1 class2 class3"
515 // and you want to find out if it contains 'class3'.
516 // you can't use a normal sub string search because you
517 // might match 'notclass3' and a regex to do the job is
518 // possible but a bit complicated.
519 // pass the attribute string as $attr and the attribute you
520 // are looking for as $s - returns true if found, otherwise false
522 if(! function_exists('attribute_contains')) {
523 function attribute_contains($attr,$s) {
524 $a = explode(' ', $attr);
525 if(count($a) && in_array($s,$a))
530 if(! function_exists('logger')) {
531 function logger($msg,$level = 0) {
532 // turn off logger in install mode
536 if(($a->module == 'install') || (! ($db && $db->connected))) return;
538 $debugging = get_config('system','debugging');
539 $loglevel = intval(get_config('system','loglevel'));
540 $logfile = get_config('system','logfile');
542 if((! $debugging) || (! $logfile) || ($level > $loglevel))
545 @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND);
550 if(! function_exists('activity_match')) {
551 function activity_match($haystack,$needle) {
552 if(($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle,NAMESPACE_ACTIVITY_SCHEMA)))
558 // Pull out all #hashtags and @person tags from $s;
559 // We also get @person@domain.com - which would make
560 // the regex quite complicated as tags can also
561 // end a sentence. So we'll run through our results
562 // and strip the period from any tags which end with one.
563 // Returns array of tags found, or empty array.
566 if(! function_exists('get_tags')) {
567 function get_tags($s) {
570 // ignore anything in a code block
571 $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s);
573 // Force line feeds at bbtags
574 $s = str_replace(array("[", "]"), array("\n[", "]\n"), $s);
576 // ignore anything in a bbtag
577 $s = preg_replace('/\[(.*?)\]/sm','',$s);
579 // Match full names against @tags including the space between first and last
580 // We will look these up afterward to see if they are full names or not recognisable.
582 if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/',$s,$match)) {
583 foreach($match[1] as $mtch) {
584 if(strstr($mtch,"]")) {
585 // we might be inside a bbcode color tag - leave it alone
588 if(substr($mtch,-1,1) === '.')
589 $ret[] = substr($mtch,0,-1);
595 // Otherwise pull out single word tags. These can be @nickname, @first_last
598 if(preg_match_all('/([@#][^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/',$s,$match)) {
599 foreach($match[1] as $mtch) {
600 if(strstr($mtch,"]")) {
601 // we might be inside a bbcode color tag - leave it alone
604 if(substr($mtch,-1,1) === '.')
605 $mtch = substr($mtch,0,-1);
606 // ignore strictly numeric tags like #1
607 if((strpos($mtch,'#') === 0) && ctype_digit(substr($mtch,1)))
609 // try not to catch url fragments
610 if(strpos($s,$mtch) && preg_match('/[a-zA-z0-9\/]/',substr($s,strpos($s,$mtch)-1,1)))
619 // quick and dirty quoted_printable encoding
621 if(! function_exists('qp')) {
623 return str_replace ("%","=",rawurlencode($s));
628 if(! function_exists('get_mentions')) {
629 function get_mentions($item) {
631 if(! strlen($item['tag']))
634 $arr = explode(',',$item['tag']);
635 foreach($arr as $x) {
637 if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
638 $o .= "\t\t" . '<link rel="mentioned" href="' . $matches[1] . '" />' . "\r\n";
639 $o .= "\t\t" . '<link rel="ostatus:attention" href="' . $matches[1] . '" />' . "\r\n";
645 if(! function_exists('contact_block')) {
646 function contact_block() {
650 $shown = get_pconfig($a->profile['uid'],'system','display_friend_count');
656 if((! is_array($a->profile)) || ($a->profile['hide-friends']))
658 $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0",
659 intval($a->profile['uid'])
662 $total = intval($r[0]['total']);
665 $contacts = t('No contacts');
669 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY RAND() LIMIT %d",
670 intval($a->profile['uid']),
674 $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
677 $micropro[] = micropro($rr,true,'mpfriend');
682 $tpl = get_markup_template('contact_block.tpl');
683 $o = replace_macros($tpl, array(
684 '$contacts' => $contacts,
685 '$nickname' => $a->profile['nickname'],
686 '$viewcontacts' => t('View Contacts'),
687 '$micropro' => $micropro,
690 $arr = array('contacts' => $r, 'output' => $o);
692 call_hooks('contact_block_end', $arr);
697 if(! function_exists('micropro')) {
698 function micropro($contact, $redirect = false, $class = '', $textmode = false) {
701 $class = ' ' . $class;
703 $url = $contact['url'];
709 $redirect_url = $a->get_baseurl() . '/redir/' . $contact['id'];
710 if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === 'dfrn')) {
712 $url = $redirect_url;
713 $sparkle = ' sparkle';
718 $click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : '');
722 return '<div class="contact-block-textdiv' . $class . '"><a class="contact-block-link' . $class . $sparkle
723 . (($click) ? ' fakelink' : '') . '" '
724 . (($redir) ? ' target="redir" ' : '')
725 . (($url) ? ' href="' . $url . '"' : '') . $click
726 . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
727 . '" >'. $contact['name'] . '</a></div>' . "\r\n";
730 return '<div class="contact-block-div' . $class . '"><a class="contact-block-link' . $class . $sparkle
731 . (($click) ? ' fakelink' : '') . '" '
732 . (($redir) ? ' target="redir" ' : '')
733 . (($url) ? ' href="' . $url . '"' : '') . $click . ' ><img class="contact-block-img' . $class . $sparkle . '" src="'
734 . $contact['micro'] . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
735 . '" /></a></div>' . "\r\n";
741 if(! function_exists('search')) {
742 function search($s,$id='search-box',$url='/search',$save = false) {
744 $o = '<div id="' . $id . '">';
745 $o .= '<form action="' . $a->get_baseurl((stristr($url,'network')) ? true : false) . $url . '" method="get" >';
746 $o .= '<input type="text" name="search" id="search-text" placeholder="' . t('Search') . '" value="' . $s .'" />';
747 $o .= '<input type="submit" name="submit" id="search-submit" value="' . t('Search') . '" />';
749 $o .= '<input type="submit" name="save" id="search-save" value="' . t('Save') . '" />';
750 $o .= '</form></div>';
754 if(! function_exists('valid_email')) {
755 function valid_email($x){
757 if(get_config('system','disable_email_validation'))
760 if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
770 * Replace naked text hyperlink with HTML formatted hyperlink
774 if(! function_exists('linkify')) {
775 function linkify($s) {
776 $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="external-link">$1</a>', $s);
777 $s = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$s);
781 function get_poke_verbs() {
783 // index is present tense verb
784 // value is array containing past tense verb, translation of present, translation of past
787 'poke' => array( 'poked', t('poke'), t('poked')),
788 'ping' => array( 'pinged', t('ping'), t('pinged')),
789 'prod' => array( 'prodded', t('prod'), t('prodded')),
790 'slap' => array( 'slapped', t('slap'), t('slapped')),
791 'finger' => array( 'fingered', t('finger'), t('fingered')),
792 'rebuff' => array( 'rebuffed', t('rebuff'), t('rebuffed')),
794 call_hooks('poke_verbs', $arr);
798 function get_mood_verbs() {
800 // index is present tense verb
801 // value is array containing past tense verb, translation of present, translation of past
804 'happy' => t('happy'),
806 'mellow' => t('mellow'),
807 'tired' => t('tired'),
808 'perky' => t('perky'),
809 'angry' => t('angry'),
810 'stupefied' => t('stupified'),
811 'puzzled' => t('puzzled'),
812 'interested' => t('interested'),
813 'bitter' => t('bitter'),
814 'cheerful' => t('cheerful'),
815 'alive' => t('alive'),
816 'annoyed' => t('annoyed'),
817 'anxious' => t('anxious'),
818 'cranky' => t('cranky'),
819 'disturbed' => t('disturbed'),
820 'frustrated' => t('frustrated'),
821 'motivated' => t('motivated'),
822 'relaxed' => t('relaxed'),
823 'surprised' => t('surprised'),
826 call_hooks('mood_verbs', $arr);
836 * Replaces text emoticons with graphical images
838 * @Parameter: string $s
842 * It is expected that this function will be called using HTML text.
843 * We will escape text between HTML pre and code blocks from being
846 * At a higher level, the bbcode [nosmile] tag can be used to prevent this
847 * function from being executed by the prepare_text() routine when preparing
848 * bbcode source for HTML display
852 if(! function_exists('smilies')) {
853 function smilies($s, $sample = false) {
857 if(intval(get_config('system','no_smilies'))
858 || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
861 $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_encode',$s);
862 $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_encode',$s);
902 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
903 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
904 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
905 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
906 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
907 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
908 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
909 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-p" />',
910 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
911 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
912 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
913 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
914 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
915 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
916 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
917 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" />',
918 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
919 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" />',
920 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" />',
921 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="o_O" />',
922 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" />',
923 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" />',
924 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
925 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
926 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
927 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
928 '<img class="smiley" src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
929 '<img class="smiley" src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" />',
930 '<img class="smiley" src="' . $a->get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
931 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
932 '<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />',
933 '<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
934 '<a href="http://friendica.com">~friendica <img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>'
937 $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
938 call_hooks('smilie', $params);
941 $s = '<div class="smiley-sample">';
942 for($x = 0; $x < count($params['texts']); $x ++) {
943 $s .= '<dl><dt>' . $params['texts'][$x] . '</dt><dd>' . $params['icons'][$x] . '</dd></dl>';
947 $params['string'] = preg_replace_callback('/<(3+)/','preg_heart',$params['string']);
948 $s = str_replace($params['texts'],$params['icons'],$params['string']);
951 $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_decode',$s);
952 $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_decode',$s);
958 function smile_encode($m) {
959 return(str_replace($m[1],base64url_encode($m[1]),$m[0]));
962 function smile_decode($m) {
963 return(str_replace($m[1],base64url_decode($m[1]),$m[0]));
966 // expand <3333 to the correct number of hearts
968 function preg_heart($x) {
970 if(strlen($x[1]) == 1)
973 for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
974 $t .= '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />';
975 $r = str_replace($x[0],$t,$x[0]);
980 if(! function_exists('day_translate')) {
981 function day_translate($s) {
982 $ret = str_replace(array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'),
983 array( t('Monday'), t('Tuesday'), t('Wednesday'), t('Thursday'), t('Friday'), t('Saturday'), t('Sunday')),
986 $ret = str_replace(array('January','February','March','April','May','June','July','August','September','October','November','December'),
987 array( t('January'), t('February'), t('March'), t('April'), t('May'), t('June'), t('July'), t('August'), t('September'), t('October'), t('November'), t('December')),
994 if(! function_exists('normalise_link')) {
995 function normalise_link($url) {
996 $ret = str_replace(array('https:','//www.'), array('http:','//'), $url);
997 return(rtrim($ret,'/'));
1002 * Compare two URLs to see if they are the same, but ignore
1003 * slight but hopefully insignificant differences such as if one
1004 * is https and the other isn't, or if one is www.something and
1005 * the other isn't - and also ignore case differences.
1007 * Return true if the URLs match, otherwise false.
1011 if(! function_exists('link_compare')) {
1012 function link_compare($a,$b) {
1013 if(strcasecmp(normalise_link($a),normalise_link($b)) === 0)
1018 // Given an item array, convert the body element from bbcode to html and add smilie icons.
1019 // If attach is true, also add icons for item attachments
1022 if(! function_exists('prepare_body')) {
1023 function prepare_body($item,$attach = false) {
1026 call_hooks('prepare_body_init', $item);
1028 //$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']));
1029 $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body']));
1031 if (($cachefile != '')) {
1032 if (file_exists($cachefile))
1033 $s = file_get_contents($cachefile);
1035 $s = prepare_text($item['body']);
1036 file_put_contents($cachefile, $s);
1037 logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile);
1040 $s = prepare_text($item['body']);
1043 $prep_arr = array('item' => $item, 'html' => $s);
1044 call_hooks('prepare_body', $prep_arr);
1045 $s = $prep_arr['html'];
1048 // Replace the blockquotes with quotes that are used in mails
1049 $mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
1050 $s = str_replace(array('<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'), array($mailquote, $mailquote, $mailquote), $s);
1054 $arr = explode('[/attach],',$item['attach']);
1056 $s .= '<div class="body-attach">';
1057 foreach($arr as $r) {
1060 $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER);
1062 foreach($matches as $mtch) {
1063 $icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/')));
1069 $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>';
1072 $icon = '<div class="attachtype icon s22 type-unkn"></div>';
1075 $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]));
1076 $title .= ' ' . $mtch[2] . ' ' . t('bytes');
1077 if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN))
1078 $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
1080 $the_url = $mtch[1];
1082 $s .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>';
1086 $s .= '<div class="clear"></div></div>';
1091 $spoilersearch = '<blockquote class="spoiler">';
1093 // Remove line breaks before the spoiler
1094 while ((strpos($s, "\n".$spoilersearch) !== false))
1095 $s = str_replace("\n".$spoilersearch, $spoilersearch, $s);
1096 while ((strpos($s, "<br />".$spoilersearch) !== false))
1097 $s = str_replace("<br />".$spoilersearch, $spoilersearch, $s);
1099 while ((strpos($s, $spoilersearch) !== false)) {
1101 $pos = strpos($s, $spoilersearch);
1102 $rnd = random_string(8);
1103 $spoilerreplace = '<br /> <span id="spoiler-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
1104 '<blockquote class="spoiler" id="spoiler-'.$rnd.'" style="display: none;">';
1105 $s = substr($s, 0, $pos).$spoilerreplace.substr($s, $pos+strlen($spoilersearch));
1108 // Look for quote with author
1109 $authorsearch = '<blockquote class="author">';
1111 while ((strpos($s, $authorsearch) !== false)) {
1113 $pos = strpos($s, $authorsearch);
1114 $rnd = random_string(8);
1115 $authorreplace = '<br /> <span id="author-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
1116 '<blockquote class="author" id="author-'.$rnd.'" style="display: block;">';
1117 $s = substr($s, 0, $pos).$authorreplace.substr($s, $pos+strlen($authorsearch));
1120 $prep_arr = array('item' => $item, 'html' => $s);
1121 call_hooks('prepare_body_final', $prep_arr);
1123 return $prep_arr['html'];
1127 // Given a text string, convert from bbcode to html and add smilie icons.
1129 if(! function_exists('prepare_text')) {
1130 function prepare_text($text) {
1132 require_once('include/bbcode.php');
1134 if(stristr($text,'[nosmile]'))
1137 $s = smilies(bbcode($text));
1148 * 'name': 'category name',
1149 * 'removeurl': 'url to remove this category',
1150 * 'first': 'is the first in this array? true/false',
1151 * 'last': 'is the last in this array? true/false',
1156 * 'name': 'folder name',
1157 * 'removeurl': 'url to remove this folder',
1158 * 'first': 'is the first in this array? true/false',
1159 * 'last': 'is the last in this array? true/false',
1165 function get_cats_and_terms($item) {
1167 $categories = array();
1170 $matches = false; $first = true;
1171 $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER);
1173 foreach($matches as $mtch) {
1174 $categories[] = array(
1175 'name' => xmlify(file_tag_decode($mtch[1])),
1177 'removeurl' => ((local_user() == $item['uid'])?$a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""),
1184 if (count($categories)) $categories[count($categories)-1]['last'] = true;
1187 if(local_user() == $item['uid']) {
1188 $matches = false; $first = true;
1189 $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER);
1191 foreach($matches as $mtch) {
1193 'name' => xmlify(file_tag_decode($mtch[1])),
1195 'removeurl' => ((local_user() == $item['uid'])?$a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""),
1204 if (count($folders)) $folders[count($folders)-1]['last'] = true;
1206 return array($categories, $folders);
1211 * return atom link elements for all of our hubs
1214 if(! function_exists('feed_hublinks')) {
1215 function feed_hublinks() {
1217 $hub = get_config('system','huburl');
1221 $hubs = explode(',', $hub);
1223 foreach($hubs as $h) {
1227 $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
1234 /* return atom link elements for salmon endpoints */
1236 if(! function_exists('feed_salmonlinks')) {
1237 function feed_salmonlinks($nick) {
1241 $salmon = '<link rel="salmon" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
1243 // old style links that status.net still needed as of 12/2010
1245 $salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
1246 $salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
1250 if(! function_exists('get_plink')) {
1251 function get_plink($item) {
1253 if (x($item,'plink') && ($item['private'] != 1)) {
1255 'href' => $item['plink'],
1256 'title' => t('link to source'),
1264 if(! function_exists('unamp')) {
1265 function unamp($s) {
1266 return str_replace('&', '&', $s);
1272 if(! function_exists('lang_selector')) {
1273 function lang_selector() {
1276 $langs = glob('view/*/strings.php');
1278 $lang_options = array();
1281 if(is_array($langs) && count($langs)) {
1283 if(! in_array('view/en/strings.php',$langs))
1284 $langs[] = 'view/en/';
1286 foreach($langs as $l) {
1288 $lang_options[""] = t('default');
1292 $ll = substr($ll,0,strrpos($ll,'/'));
1293 $selected = (($ll === $lang && (x($_SESSION, 'language'))) ? $ll : $selected);
1294 $lang_options[$ll]=$ll;
1298 $tpl = get_markup_template("lang_selector.tpl");
1299 $o = replace_macros($tpl, array(
1300 '$title' => t('Select an alternate language'),
1301 '$langs' => array($lang_options, $selected),
1308 if(! function_exists('return_bytes')) {
1309 function return_bytes ($size_str) {
1310 switch (substr ($size_str, -1))
1312 case 'M': case 'm': return (int)$size_str * 1048576;
1313 case 'K': case 'k': return (int)$size_str * 1024;
1314 case 'G': case 'g': return (int)$size_str * 1073741824;
1315 default: return $size_str;
1319 function generate_user_guid() {
1322 $guid = random_string(16);
1323 $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
1328 } while ($found == true );
1334 function base64url_encode($s, $strip_padding = false) {
1336 $s = strtr(base64_encode($s),'+/','-_');
1339 $s = str_replace('=','',$s);
1344 function base64url_decode($s) {
1347 logger('base64url_decode: illegal input: ' . print_r(debug_backtrace(), true));
1352 * // Placeholder for new rev of salmon which strips base64 padding.
1353 * // PHP base64_decode handles the un-padded input without requiring this step
1354 * // Uncomment if you find you need it.
1357 * if(! strpos($s,'=')) {
1367 return base64_decode(strtr($s,'-_','+/'));
1371 if (!function_exists('str_getcsv')) {
1372 function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = '\\', $eol = '\n') {
1373 if (is_string($input) && !empty($input)) {
1375 $tmp = preg_split("/".$eol."/",$input);
1376 if (is_array($tmp) && !empty($tmp)) {
1377 while (list($line_num, $line) = each($tmp)) {
1378 if (preg_match("/".$escape.$enclosure."/",$line)) {
1379 while ($strlen = strlen($line)) {
1380 $pos_delimiter = strpos($line,$delimiter);
1381 $pos_enclosure_start = strpos($line,$enclosure);
1383 is_int($pos_delimiter) && is_int($pos_enclosure_start)
1384 && ($pos_enclosure_start < $pos_delimiter)
1386 $enclosed_str = substr($line,1);
1387 $pos_enclosure_end = strpos($enclosed_str,$enclosure);
1388 $enclosed_str = substr($enclosed_str,0,$pos_enclosure_end);
1389 $output[$line_num][] = $enclosed_str;
1390 $offset = $pos_enclosure_end+3;
1392 if (empty($pos_delimiter) && empty($pos_enclosure_start)) {
1393 $output[$line_num][] = substr($line,0);
1394 $offset = strlen($line);
1396 $output[$line_num][] = substr($line,0,$pos_delimiter);
1398 !empty($pos_enclosure_start)
1399 && ($pos_enclosure_start < $pos_delimiter)
1401 ?$pos_enclosure_start
1405 $line = substr($line,$offset);
1408 $line = preg_split("/".$delimiter."/",$line);
1411 * Validating against pesky extra line breaks creating false rows.
1413 if (is_array($line) && !empty($line[0])) {
1414 $output[$line_num] = $line;
1428 function cleardiv() {
1429 return '<div class="clear"></div>';
1433 function bb_translate_video($s) {
1436 $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
1438 foreach($matches as $mtch) {
1439 if((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
1440 $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
1441 elseif(stristr($mtch[1],'vimeo'))
1442 $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
1448 function html2bb_video($s) {
1450 $s = preg_replace('#<object[^>]+>(.*?)https?://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)</object>#ism',
1451 '[youtube]$2[/youtube]', $s);
1453 $s = preg_replace('#<iframe[^>](.*?)https?://www.youtube.com/embed/([A-Za-z0-9\-_=]+)(.*?)</iframe>#ism',
1454 '[youtube]$2[/youtube]', $s);
1456 $s = preg_replace('#<iframe[^>](.*?)https?://player.vimeo.com/video/([0-9]+)(.*?)</iframe>#ism',
1457 '[vimeo]$2[/vimeo]', $s);
1463 * apply xmlify() to all values of array $val, recursively
1465 function array_xmlify($val){
1466 if (is_bool($val)) return $val?"true":"false";
1467 if (is_array($val)) return array_map('array_xmlify', $val);
1468 return xmlify((string) $val);
1472 function reltoabs($text, $base)
1477 $base = rtrim($base,'/');
1479 $base2 = $base . "/";
1482 $pattern = "/<a([^>]*) href=\"(?!http|https|\/)([^\"]*)\"/";
1483 $replace = "<a\${1} href=\"" . $base2 . "\${2}\"";
1484 $text = preg_replace($pattern, $replace, $text);
1486 $pattern = "/<a([^>]*) href=\"(?!http|https)([^\"]*)\"/";
1487 $replace = "<a\${1} href=\"" . $base . "\${2}\"";
1488 $text = preg_replace($pattern, $replace, $text);
1491 $pattern = "/<img([^>]*) src=\"(?!http|https|\/)([^\"]*)\"/";
1492 $replace = "<img\${1} src=\"" . $base2 . "\${2}\"";
1493 $text = preg_replace($pattern, $replace, $text);
1495 $pattern = "/<img([^>]*) src=\"(?!http|https)([^\"]*)\"/";
1496 $replace = "<img\${1} src=\"" . $base . "\${2}\"";
1497 $text = preg_replace($pattern, $replace, $text);
1504 function item_post_type($item) {
1505 if(intval($item['event-id']))
1507 if(strlen($item['resource-id']))
1509 if(strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST)
1510 return t('activity');
1511 if($item['id'] != $item['parent'])
1512 return t('comment');
1516 // post categories and "save to file" use the same item.file table for storage.
1517 // We will differentiate the different uses by wrapping categories in angle brackets
1518 // and save to file categories in square brackets.
1519 // To do this we need to escape these characters if they appear in our tag.
1521 function file_tag_encode($s) {
1522 return str_replace(array('<','>','[',']'),array('%3c','%3e','%5b','%5d'),$s);
1525 function file_tag_decode($s) {
1526 return str_replace(array('%3c','%3e','%5b','%5d'),array('<','>','[',']'),$s);
1529 function file_tag_file_query($table,$s,$type = 'file') {
1532 $str = preg_quote( '[' . str_replace('%','%%',file_tag_encode($s)) . ']' );
1534 $str = preg_quote( '<' . str_replace('%','%%',file_tag_encode($s)) . '>' );
1535 return " AND " . (($table) ? dbesc($table) . '.' : '') . "file regexp '" . dbesc($str) . "' ";
1538 // ex. given music,video return <music><video> or [music][video]
1539 function file_tag_list_to_file($list,$type = 'file') {
1542 $list_array = explode(",",$list);
1543 if($type == 'file') {
1552 foreach($list_array as $item) {
1554 $tag_list .= $lbracket . file_tag_encode(trim($item)) . $rbracket;
1561 // ex. given <music><video>[friends], return music,video or friends
1562 function file_tag_file_to_list($file,$type = 'file') {
1565 if($type == 'file') {
1566 $cnt = preg_match_all('/\[(.*?)\]/',$file,$matches,PREG_SET_ORDER);
1569 $cnt = preg_match_all('/<(.*?)>/',$file,$matches,PREG_SET_ORDER);
1572 foreach($matches as $mtch) {
1575 $list .= file_tag_decode($mtch[1]);
1582 function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') {
1583 // $file_old - categories previously associated with an item
1584 // $file_new - new list of categories for an item
1589 if($file_old == $file_new)
1592 $saved = get_pconfig($uid,'system','filetags');
1593 if(strlen($saved)) {
1594 if($type == 'file') {
1603 $filetags_updated = $saved;
1605 // check for new tags to be added as filetags in pconfig
1606 $new_tags = array();
1607 $check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
1609 foreach($check_new_tags as $tag) {
1610 if(! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
1614 $filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
1616 // check for deleted tags to be removed from filetags in pconfig
1617 $deleted_tags = array();
1618 $check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
1620 foreach($check_deleted_tags as $tag) {
1621 if(! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
1622 $deleted_tags[] = $tag;
1625 foreach($deleted_tags as $key => $tag) {
1626 $r = q("select file from item where uid = %d " . file_tag_file_query('item',$tag,$type),
1631 unset($deleted_tags[$key]);
1634 $filetags_updated = str_replace($lbracket . file_tag_encode($tag) . $rbracket,'',$filetags_updated);
1638 if($saved != $filetags_updated) {
1639 set_pconfig($uid,'system','filetags', $filetags_updated);
1644 if(strlen($file_new)) {
1645 set_pconfig($uid,'system','filetags', $file_new);
1650 function file_tag_save_file($uid,$item,$file) {
1654 $r = q("select file from item where id = %d and uid = %d limit 1",
1659 if(! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']'))
1660 q("update item set file = '%s' where id = %d and uid = %d limit 1",
1661 dbesc($r[0]['file'] . '[' . file_tag_encode($file) . ']'),
1665 $saved = get_pconfig($uid,'system','filetags');
1666 if((! strlen($saved)) || (! stristr($saved,'[' . file_tag_encode($file) . ']')))
1667 set_pconfig($uid,'system','filetags',$saved . '[' . file_tag_encode($file) . ']');
1668 info( t('Item filed') );
1673 function file_tag_unsave_file($uid,$item,$file,$cat = false) {
1679 $pattern = '<' . file_tag_encode($file) . '>' ;
1681 $pattern = '[' . file_tag_encode($file) . ']' ;
1684 $r = q("select file from item where id = %d and uid = %d limit 1",
1691 q("update item set file = '%s' where id = %d and uid = %d limit 1",
1692 dbesc(str_replace($pattern,'',$r[0]['file'])),
1697 $r = q("select file from item where uid = %d and deleted = 0 " . file_tag_file_query('item',$file,(($cat) ? 'category' : 'file')),
1702 $saved = get_pconfig($uid,'system','filetags');
1703 set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved));
1709 function normalise_openid($s) {
1710 return trim(str_replace(array('http://','https://'),array('',''),$s),'/');
1714 function undo_post_tagging($s) {
1716 $cnt = preg_match_all('/([@#])\[url=(.*?)\](.*?)\[\/url\]/ism',$s,$matches,PREG_SET_ORDER);
1718 foreach($matches as $mtch) {
1719 $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);
1725 function fix_mce_lf($s) {
1726 $s = str_replace("\r\n","\n",$s);
1727 // $s = str_replace("\n\n","\n",$s);
1732 function protect_sprintf($s) {
1733 return(str_replace('%','%%',$s));
1737 function is_a_date_arg($s) {
1741 if($i <= $y+1 && strpos($s,'-') == 4) {
1742 $m = intval(substr($s,5));
1743 if($m > 0 && $m <= 12)