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) {
21 if($a->theme['template_engine'] === 'smarty3') {
23 if(gettype($s) === 'string') {
25 $s = new FriendicaSmarty();
27 foreach($r as $key=>$value) {
29 $key = substr($key, 1);
31 $s->assign($key, $value);
33 $output = $s->parsed($template);
36 $r = $t->replace($s,$r);
38 $output = template_unescape($r);
40 // $tt = microtime() - $ts;
42 // $a->page['debug'] .= "$tt <br>\n";
47 // random string, there are 86 characters max in text mode, 128 for hex
50 define('RANDOM_STRING_HEX', 0x00 );
51 define('RANDOM_STRING_TEXT', 0x01 );
53 if(! function_exists('random_string')) {
54 function random_string($size = 64,$type = RANDOM_STRING_HEX) {
55 // generate a bit of entropy and run it through the whirlpool
56 $s = hash('whirlpool', (string) rand() . uniqid(rand(),true) . (string) rand(),(($type == RANDOM_STRING_TEXT) ? true : false));
57 $s = (($type == RANDOM_STRING_TEXT) ? str_replace("\n","",base64url_encode($s,true)) : $s);
58 return(substr($s,0,$size));
62 * This is our primary input filter.
64 * The high bit hack only involved some old IE browser, forget which (IE5/Mac?)
65 * that had an XSS attack vector due to stripping the high-bit on an 8-bit character
66 * after cleansing, and angle chars with the high bit set could get through as markup.
68 * This is now disabled because it was interfering with some legitimate unicode sequences
69 * and hopefully there aren't a lot of those browsers left.
71 * Use this on any text input where angle chars are not valid or permitted
72 * They will be replaced with safer brackets. This may be filtered further
73 * if these are not allowed either.
77 if(! function_exists('notags')) {
78 function notags($string) {
80 return(str_replace(array("<",">"), array('[',']'), $string));
82 // High-bit filter no longer used
83 // return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
86 // use this on "body" or "content" input where angle chars shouldn't be removed,
87 // and allow them to be safely displayed.
89 if(! function_exists('escape_tags')) {
90 function escape_tags($string) {
92 return(htmlspecialchars($string, ENT_COMPAT, 'UTF-8', false));
96 // generate a string that's random, but usually pronounceable.
97 // used to generate initial passwords
99 if(! function_exists('autoname')) {
100 function autoname($len) {
105 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
106 if(mt_rand(0,5) == 4)
124 's','sc','sh','sm','sp','st',
132 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
133 'nd','ng','nk','nt','rn','rp','rt');
135 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
136 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
138 $start = mt_rand(0,2);
146 for ($x = 0; $x < $len; $x ++) {
147 $r = mt_rand(0,count($table) - 1);
150 if($table == $vowels)
151 $table = array_merge($cons,$midcons);
157 $word = substr($word,0,$len);
159 foreach($noend as $noe) {
160 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
161 $word = substr($word,0,-1);
165 if(substr($word,-1) == 'q')
166 $word = substr($word,0,-1);
171 // escape text ($str) for XML transport
172 // returns escaped text.
174 if(! function_exists('xmlify')) {
175 function xmlify($str) {
178 for($x = 0; $x < mb_strlen($str); $x ++) {
208 $buffer = trim($buffer);
213 // pass xml escaped text ($s), returns unescaped text
215 if(! function_exists('unxmlify')) {
216 function unxmlify($s) {
217 $ret = str_replace('&','&', $s);
218 $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
222 // convenience wrapper, reverse the operation "bin2hex"
224 if(! function_exists('hex2bin')) {
225 function hex2bin($s) {
226 if(! (is_string($s) && strlen($s)))
229 if(! ctype_xdigit($s)) {
233 return(pack("H*",$s));
236 // Automatic pagination.
237 // To use, get the count of total items.
238 // Then call $a->set_pager_total($number_items);
239 // Optionally call $a->set_pager_itemspage($n) to the number of items to display on each page
240 // Then call paginate($a) after the end of the display loop to insert the pager block on the page
241 // (assuming there are enough items to paginate).
242 // When using with SQL, the setting LIMIT %d, %d => $a->pager['start'],$a->pager['itemspage']
243 // will limit the results to the correct items for the current page.
244 // The actual page handling is then accomplished at the application layer.
246 if(! function_exists('paginate')) {
247 function paginate(&$a) {
249 $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string);
251 // $stripped = preg_replace('/&zrl=(.*?)([\?&]|$)/ism','',$stripped);
253 $stripped = str_replace('q=','',$stripped);
254 $stripped = trim($stripped,'/');
255 $pagenum = $a->pager['page'];
256 $url = $a->get_baseurl() . '/' . $stripped;
259 if($a->pager['total'] > $a->pager['itemspage']) {
260 $o .= '<div class="pager">';
261 if($a->pager['page'] != 1)
262 $o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">' . t('prev') . '</a></span> ';
264 $o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">" . t('first') . "</a></span> ";
266 $numpages = $a->pager['total'] / $a->pager['itemspage'];
269 $numstop = $numpages;
272 $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
273 $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
276 for($i = $numstart; $i <= $numstop; $i++){
277 if($i == $a->pager['page'])
278 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
280 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
284 if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
285 if($i == $a->pager['page'])
286 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
288 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
292 $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
293 $o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">" . t('last') . "</a></span> ";
295 if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
296 $o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('next') . '</a></span>';
297 $o .= '</div>'."\r\n";
302 if(! function_exists('alt_pager')) {
303 function alt_pager(&$a, $i) {
305 $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string);
306 $stripped = str_replace('q=','',$stripped);
307 $stripped = trim($stripped,'/');
308 $pagenum = $a->pager['page'];
309 $url = $a->get_baseurl() . '/' . $stripped;
311 $o .= '<div class="pager">';
313 if($a->pager['page']>1)
314 $o .= "<a href=\"$url"."&page=".($a->pager['page'] - 1).'" class="pager_newer">' . t('newer') . '</a>';
316 if($a->pager['page']>1)
317 $o .= " - ";
318 $o .= "<a href=\"$url"."&page=".($a->pager['page'] + 1).'" class="pager_older">' . t('older') . '</a>';
322 $o .= '</div>'."\r\n";
327 // Turn user/group ACLs stored as angle bracketed text into arrays
329 if(! function_exists('expand_acl')) {
330 function expand_acl($s) {
331 // turn string array of angle-bracketed elements into numeric array
332 // e.g. "<1><2><3>" => array(1,2,3);
336 $t = str_replace('<','',$s);
337 $a = explode('>',$t);
340 $ret[] = intval($aa);
346 // Used to wrap ACL elements in angle brackets for storage
348 if(! function_exists('sanitise_acl')) {
349 function sanitise_acl(&$item) {
351 $item = '<' . intval(notags(trim($item))) . '>';
357 // Convert an ACL array to a storable string
358 // Normally ACL permissions will be an array.
359 // We'll also allow a comma-separated string.
361 if(! function_exists('perms2str')) {
362 function perms2str($p) {
368 $tmp = explode(',',$p);
371 array_walk($tmp,'sanitise_acl');
372 $ret = implode('',$tmp);
377 // generate a guaranteed unique (for this domain) item ID for ATOM
378 // safe from birthday paradox
380 if(! function_exists('item_new_uri')) {
381 function item_new_uri($hostname,$uid) {
385 $hash = random_string();
387 $uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash;
389 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
393 } while($dups == true);
397 // Generate a guaranteed unique photo ID.
398 // safe from birthday paradox
400 if(! function_exists('photo_new_resource')) {
401 function photo_new_resource() {
405 $resource = hash('md5',uniqid(mt_rand(),true));
406 $r = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' LIMIT 1",
411 } while($found == true);
416 // wrapper to load a view template, checking for alternate
417 // languages before falling back to the default
419 // obsolete, deprecated.
421 if(! function_exists('load_view_file')) {
422 function load_view_file($s) {
428 if(file_exists("$d/$lang/$b"))
429 return file_get_contents("$d/$lang/$b");
431 $theme = current_theme();
433 if(file_exists("$d/theme/$theme/$b"))
434 return file_get_contents("$d/theme/$theme/$b");
436 return file_get_contents($s);
439 if(! function_exists('get_intltext_template')) {
440 function get_intltext_template($s) {
445 if($a->theme['template_engine'] === 'smarty3')
446 $engine = "/smarty3";
451 if(file_exists("view/$lang$engine/$s"))
452 return file_get_contents("view/$lang$engine/$s");
453 elseif(file_exists("view/en$engine/$s"))
454 return file_get_contents("view/en$engine/$s");
456 return file_get_contents("view$engine/$s");
459 if(! function_exists('get_markup_template')) {
460 function get_markup_template($s, $root = '') {
461 // $ts = microtime();
464 if($a->theme['template_engine'] === 'smarty3') {
465 $template_file = get_template_file($a, 'smarty3/' . $s, $root);
467 $template = new FriendicaSmarty();
468 $template->filename = $template_file;
470 // $tt = microtime() - $ts;
471 // $a->page['debug'] .= "$tt <br>\n";
475 $template_file = get_template_file($a, $s, $root);
476 // $file_contents = file_get_contents($template_file);
477 // $tt = microtime() - $ts;
478 // $a->page['debug'] .= "$tt <br>\n";
479 // return $file_contents;
480 return file_get_contents($template_file);
484 if(! function_exists("get_template_file")) {
485 function get_template_file($a, $filename, $root = '') {
486 $theme = current_theme();
488 // Make sure $root ends with a slash /
489 if($root !== '' && $root[strlen($root)-1] !== '/')
492 if(file_exists($root . "view/theme/$theme/$filename"))
493 $template_file = $root . "view/theme/$theme/$filename";
494 elseif (x($a->theme_info,"extends") && file_exists($root . "view/theme/".$a->theme_info["extends"]."/$filename"))
495 $template_file = $root . "view/theme/".$a->theme_info["extends"]."/$filename";
497 $template_file = $root . "view/$filename";
499 return $template_file;
502 if(! function_exists("set_template_includes")) {
503 function set_template_includes($engine, $includes) {
504 if($engine === 'smarty3') {
506 foreach($includes as $name=>$path) {
507 // $sm_includes[$name] = $_SERVER['DOCUMENT_ROOT'] . '/' . get_template_file($a, 'smarty3/' . $path);
508 $sm_includes[$name] = get_template_file($a, 'smarty3/' . $path);
521 // for html,xml parsing - let's say you've got
522 // an attribute foobar="class1 class2 class3"
523 // and you want to find out if it contains 'class3'.
524 // you can't use a normal sub string search because you
525 // might match 'notclass3' and a regex to do the job is
526 // possible but a bit complicated.
527 // pass the attribute string as $attr and the attribute you
528 // are looking for as $s - returns true if found, otherwise false
530 if(! function_exists('attribute_contains')) {
531 function attribute_contains($attr,$s) {
532 $a = explode(' ', $attr);
533 if(count($a) && in_array($s,$a))
538 if(! function_exists('logger')) {
539 function logger($msg,$level = 0) {
540 // turn off logger in install mode
544 if(($a->module == 'install') || (! ($db && $db->connected))) return;
546 $debugging = get_config('system','debugging');
547 $loglevel = intval(get_config('system','loglevel'));
548 $logfile = get_config('system','logfile');
550 if((! $debugging) || (! $logfile) || ($level > $loglevel))
553 @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND);
558 if(! function_exists('activity_match')) {
559 function activity_match($haystack,$needle) {
560 if(($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle,NAMESPACE_ACTIVITY_SCHEMA)))
566 // Pull out all #hashtags and @person tags from $s;
567 // We also get @person@domain.com - which would make
568 // the regex quite complicated as tags can also
569 // end a sentence. So we'll run through our results
570 // and strip the period from any tags which end with one.
571 // Returns array of tags found, or empty array.
574 if(! function_exists('get_tags')) {
575 function get_tags($s) {
578 // ignore anything in a code block
580 $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s);
582 // ignore anything in a bbtag
584 $s = preg_replace('/\[(.*?)\]/sm','',$s);
586 // Match full names against @tags including the space between first and last
587 // We will look these up afterward to see if they are full names or not recognisable.
589 if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/',$s,$match)) {
590 foreach($match[1] as $mtch) {
591 if(strstr($mtch,"]")) {
592 // we might be inside a bbcode color tag - leave it alone
595 if(substr($mtch,-1,1) === '.')
596 $ret[] = substr($mtch,0,-1);
602 // Otherwise pull out single word tags. These can be @nickname, @first_last
605 if(preg_match_all('/([@#][^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/',$s,$match)) {
606 foreach($match[1] as $mtch) {
607 if(strstr($mtch,"]")) {
608 // we might be inside a bbcode color tag - leave it alone
611 if(substr($mtch,-1,1) === '.')
612 $mtch = substr($mtch,0,-1);
613 // ignore strictly numeric tags like #1
614 if((strpos($mtch,'#') === 0) && ctype_digit(substr($mtch,1)))
616 // try not to catch url fragments
617 if(strpos($s,$mtch) && preg_match('/[a-zA-z0-9\/]/',substr($s,strpos($s,$mtch)-1,1)))
626 // quick and dirty quoted_printable encoding
628 if(! function_exists('qp')) {
630 return str_replace ("%","=",rawurlencode($s));
635 if(! function_exists('get_mentions')) {
636 function get_mentions($item) {
638 if(! strlen($item['tag']))
641 $arr = explode(',',$item['tag']);
642 foreach($arr as $x) {
644 if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
645 $o .= "\t\t" . '<link rel="mentioned" href="' . $matches[1] . '" />' . "\r\n";
646 $o .= "\t\t" . '<link rel="ostatus:attention" href="' . $matches[1] . '" />' . "\r\n";
652 if(! function_exists('contact_block')) {
653 function contact_block() {
657 $shown = get_pconfig($a->profile['uid'],'system','display_friend_count');
663 if((! is_array($a->profile)) || ($a->profile['hide-friends']))
665 $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",
666 intval($a->profile['uid'])
669 $total = intval($r[0]['total']);
672 $contacts = t('No contacts');
676 $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",
677 intval($a->profile['uid']),
681 $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
684 $micropro[] = micropro($rr,true,'mpfriend');
689 $tpl = get_markup_template('contact_block.tpl');
690 $o = replace_macros($tpl, array(
691 '$contacts' => $contacts,
692 '$nickname' => $a->profile['nickname'],
693 '$viewcontacts' => t('View Contacts'),
694 '$micropro' => $micropro,
697 $arr = array('contacts' => $r, 'output' => $o);
699 call_hooks('contact_block_end', $arr);
704 if(! function_exists('micropro')) {
705 function micropro($contact, $redirect = false, $class = '', $textmode = false) {
708 $class = ' ' . $class;
710 $url = $contact['url'];
716 $redirect_url = $a->get_baseurl() . '/redir/' . $contact['id'];
717 if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === 'dfrn')) {
719 $url = $redirect_url;
720 $sparkle = ' sparkle';
725 $click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : '');
729 return '<div class="contact-block-textdiv' . $class . '"><a class="contact-block-link' . $class . $sparkle
730 . (($click) ? ' fakelink' : '') . '" '
731 . (($redir) ? ' target="redir" ' : '')
732 . (($url) ? ' href="' . $url . '"' : '') . $click
733 . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
734 . '" >'. $contact['name'] . '</a></div>' . "\r\n";
737 return '<div class="contact-block-div' . $class . '"><a class="contact-block-link' . $class . $sparkle
738 . (($click) ? ' fakelink' : '') . '" '
739 . (($redir) ? ' target="redir" ' : '')
740 . (($url) ? ' href="' . $url . '"' : '') . $click . ' ><img class="contact-block-img' . $class . $sparkle . '" src="'
741 . $contact['micro'] . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
742 . '" /></a></div>' . "\r\n";
748 if(! function_exists('search')) {
749 function search($s,$id='search-box',$url='/search',$save = false) {
751 $o = '<div id="' . $id . '">';
752 $o .= '<form action="' . $a->get_baseurl((stristr($url,'network')) ? true : false) . $url . '" method="get" >';
753 $o .= '<input type="text" name="search" id="search-text" placeholder="' . t('Search') . '" value="' . $s .'" />';
754 $o .= '<input type="submit" name="submit" id="search-submit" value="' . t('Search') . '" />';
756 $o .= '<input type="submit" name="save" id="search-save" value="' . t('Save') . '" />';
757 $o .= '</form></div>';
761 if(! function_exists('valid_email')) {
762 function valid_email($x){
764 if(get_config('system','disable_email_validation'))
767 if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
777 * Replace naked text hyperlink with HTML formatted hyperlink
781 if(! function_exists('linkify')) {
782 function linkify($s) {
783 $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="external-link">$1</a>', $s);
784 $s = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$s);
788 function get_poke_verbs() {
790 // index is present tense verb
791 // value is array containing past tense verb, translation of present, translation of past
794 'poke' => array( 'poked', t('poke'), t('poked')),
795 'ping' => array( 'pinged', t('ping'), t('pinged')),
796 'prod' => array( 'prodded', t('prod'), t('prodded')),
797 'slap' => array( 'slapped', t('slap'), t('slapped')),
798 'finger' => array( 'fingered', t('finger'), t('fingered')),
799 'rebuff' => array( 'rebuffed', t('rebuff'), t('rebuffed')),
801 call_hooks('poke_verbs', $arr);
805 function get_mood_verbs() {
807 // index is present tense verb
808 // value is array containing past tense verb, translation of present, translation of past
811 'happy' => t('happy'),
813 'mellow' => t('mellow'),
814 'tired' => t('tired'),
815 'perky' => t('perky'),
816 'angry' => t('angry'),
817 'stupefied' => t('stupified'),
818 'puzzled' => t('puzzled'),
819 'interested' => t('interested'),
820 'bitter' => t('bitter'),
821 'cheerful' => t('cheerful'),
822 'alive' => t('alive'),
823 'annoyed' => t('annoyed'),
824 'anxious' => t('anxious'),
825 'cranky' => t('cranky'),
826 'disturbed' => t('disturbed'),
827 'frustrated' => t('frustrated'),
828 'motivated' => t('motivated'),
829 'relaxed' => t('relaxed'),
830 'surprised' => t('surprised'),
833 call_hooks('mood_verbs', $arr);
843 * Replaces text emoticons with graphical images
845 * @Parameter: string $s
849 * It is expected that this function will be called using HTML text.
850 * We will escape text between HTML pre and code blocks from being
853 * At a higher level, the bbcode [nosmile] tag can be used to prevent this
854 * function from being executed by the prepare_text() routine when preparing
855 * bbcode source for HTML display
859 if(! function_exists('smilies')) {
860 function smilies($s, $sample = false) {
864 if(intval(get_config('system','no_smilies'))
865 || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
868 $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_encode',$s);
869 $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_encode',$s);
909 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
910 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
911 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
912 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
913 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
914 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
915 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
916 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-p" />',
917 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
918 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
919 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
920 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
921 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
922 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
923 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
924 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" />',
925 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
926 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" />',
927 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" />',
928 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="o_O" />',
929 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" />',
930 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" />',
931 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
932 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
933 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
934 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
935 '<img class="smiley" src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
936 '<img class="smiley" src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" />',
937 '<img class="smiley" src="' . $a->get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
938 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
939 '<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />',
940 '<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
941 '<a href="http://friendica.com">~friendica <img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>'
944 $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
945 call_hooks('smilie', $params);
948 $s = '<div class="smiley-sample">';
949 for($x = 0; $x < count($params['texts']); $x ++) {
950 $s .= '<dl><dt>' . $params['texts'][$x] . '</dt><dd>' . $params['icons'][$x] . '</dd></dl>';
954 $params['string'] = preg_replace_callback('/<(3+)/','preg_heart',$params['string']);
955 $s = str_replace($params['texts'],$params['icons'],$params['string']);
958 $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_decode',$s);
959 $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_decode',$s);
965 function smile_encode($m) {
966 return(str_replace($m[1],base64url_encode($m[1]),$m[0]));
969 function smile_decode($m) {
970 return(str_replace($m[1],base64url_decode($m[1]),$m[0]));
973 // expand <3333 to the correct number of hearts
975 function preg_heart($x) {
977 if(strlen($x[1]) == 1)
980 for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
981 $t .= '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />';
982 $r = str_replace($x[0],$t,$x[0]);
987 if(! function_exists('day_translate')) {
988 function day_translate($s) {
989 $ret = str_replace(array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'),
990 array( t('Monday'), t('Tuesday'), t('Wednesday'), t('Thursday'), t('Friday'), t('Saturday'), t('Sunday')),
993 $ret = str_replace(array('January','February','March','April','May','June','July','August','September','October','November','December'),
994 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')),
1001 if(! function_exists('normalise_link')) {
1002 function normalise_link($url) {
1003 $ret = str_replace(array('https:','//www.'), array('http:','//'), $url);
1004 return(rtrim($ret,'/'));
1009 * Compare two URLs to see if they are the same, but ignore
1010 * slight but hopefully insignificant differences such as if one
1011 * is https and the other isn't, or if one is www.something and
1012 * the other isn't - and also ignore case differences.
1014 * Return true if the URLs match, otherwise false.
1018 if(! function_exists('link_compare')) {
1019 function link_compare($a,$b) {
1020 if(strcasecmp(normalise_link($a),normalise_link($b)) === 0)
1025 // Given an item array, convert the body element from bbcode to html and add smilie icons.
1026 // If attach is true, also add icons for item attachments
1029 if(! function_exists('prepare_body')) {
1030 function prepare_body($item,$attach = false) {
1033 call_hooks('prepare_body_init', $item);
1035 $cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']));
1037 if (($cachefile != '')) {
1038 if (file_exists($cachefile))
1039 $s = file_get_contents($cachefile);
1041 $s = prepare_text($item['body']);
1042 file_put_contents($cachefile, $s);
1045 $s = prepare_text($item['body']);
1048 $prep_arr = array('item' => $item, 'html' => $s);
1049 call_hooks('prepare_body', $prep_arr);
1050 $s = $prep_arr['html'];
1053 // Replace the blockquotes with quotes that are used in mails
1054 $mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
1055 $s = str_replace(array('<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'), array($mailquote, $mailquote, $mailquote), $s);
1059 $arr = explode(',',$item['attach']);
1061 $s .= '<div class="body-attach">';
1062 foreach($arr as $r) {
1065 $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches, PREG_SET_ORDER);
1067 foreach($matches as $mtch) {
1068 $icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/')));
1074 $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>';
1077 $icon = '<div class="attachtype icon s22 type-unkn"></div>';
1080 $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]));
1081 $title .= ' ' . $mtch[2] . ' ' . t('bytes');
1082 if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN))
1083 $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
1085 $the_url = $mtch[1];
1087 $s .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>';
1091 $s .= '<div class="clear"></div></div>';
1096 $spoilersearch = '<blockquote class="spoiler">';
1098 // Remove line breaks before the spoiler
1099 while ((strpos($s, "\n".$spoilersearch) !== false))
1100 $s = str_replace("\n".$spoilersearch, $spoilersearch, $s);
1101 while ((strpos($s, "<br />".$spoilersearch) !== false))
1102 $s = str_replace("<br />".$spoilersearch, $spoilersearch, $s);
1104 while ((strpos($s, $spoilersearch) !== false)) {
1106 $pos = strpos($s, $spoilersearch);
1107 $rnd = random_string(8);
1108 $spoilerreplace = '<br /> <span id="spoiler-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
1109 '<blockquote class="spoiler" id="spoiler-'.$rnd.'" style="display: none;">';
1110 $s = substr($s, 0, $pos).$spoilerreplace.substr($s, $pos+strlen($spoilersearch));
1113 // Look for quote with author
1114 $authorsearch = '<blockquote class="author">';
1116 while ((strpos($s, $authorsearch) !== false)) {
1118 $pos = strpos($s, $authorsearch);
1119 $rnd = random_string(8);
1120 $authorreplace = '<br /> <span id="author-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
1121 '<blockquote class="author" id="author-'.$rnd.'" style="display: block;">';
1122 $s = substr($s, 0, $pos).$authorreplace.substr($s, $pos+strlen($authorsearch));
1125 $prep_arr = array('item' => $item, 'html' => $s);
1126 call_hooks('prepare_body_final', $prep_arr);
1128 return $prep_arr['html'];
1132 // Given a text string, convert from bbcode to html and add smilie icons.
1134 if(! function_exists('prepare_text')) {
1135 function prepare_text($text) {
1137 require_once('include/bbcode.php');
1139 if(stristr($text,'[nosmile]'))
1142 $s = smilies(bbcode($text));
1153 * 'name': 'category name',
1154 * 'removeurl': 'url to remove this category',
1155 * 'first': 'is the first in this array? true/false',
1156 * 'last': 'is the last in this array? true/false',
1161 * 'name': 'folder name',
1162 * 'removeurl': 'url to remove this folder',
1163 * 'first': 'is the first in this array? true/false',
1164 * 'last': 'is the last in this array? true/false',
1170 function get_cats_and_terms($item) {
1172 $categories = array();
1175 $matches = false; $first = true;
1176 $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER);
1178 foreach($matches as $mtch) {
1179 $categories[] = array(
1180 'name' => xmlify(file_tag_decode($mtch[1])),
1182 'removeurl' => ((local_user() == $item['uid'])?$a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""),
1189 if (count($categories)) $categories[count($categories)-1]['last'] = true;
1192 if(local_user() == $item['uid']) {
1193 $matches = false; $first = true;
1194 $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER);
1196 foreach($matches as $mtch) {
1198 'name' => xmlify(file_tag_decode($mtch[1])),
1200 'removeurl' => ((local_user() == $item['uid'])?$a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""),
1209 if (count($folders)) $folders[count($folders)-1]['last'] = true;
1211 return array($categories, $folders);
1216 * return atom link elements for all of our hubs
1219 if(! function_exists('feed_hublinks')) {
1220 function feed_hublinks() {
1222 $hub = get_config('system','huburl');
1226 $hubs = explode(',', $hub);
1228 foreach($hubs as $h) {
1232 $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
1239 /* return atom link elements for salmon endpoints */
1241 if(! function_exists('feed_salmonlinks')) {
1242 function feed_salmonlinks($nick) {
1246 $salmon = '<link rel="salmon" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
1248 // old style links that status.net still needed as of 12/2010
1250 $salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
1251 $salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
1255 if(! function_exists('get_plink')) {
1256 function get_plink($item) {
1258 if (x($item,'plink') && ($item['private'] != 1)) {
1260 'href' => $item['plink'],
1261 'title' => t('link to source'),
1269 if(! function_exists('unamp')) {
1270 function unamp($s) {
1271 return str_replace('&', '&', $s);
1277 if(! function_exists('lang_selector')) {
1278 function lang_selector() {
1281 $langs = glob('view/*/strings.php');
1283 $lang_options = array();
1286 if(is_array($langs) && count($langs)) {
1288 if(! in_array('view/en/strings.php',$langs))
1289 $langs[] = 'view/en/';
1291 foreach($langs as $l) {
1293 $lang_options[""] = t('default');
1297 $ll = substr($ll,0,strrpos($ll,'/'));
1298 $selected = (($ll === $lang && (x($_SESSION, 'language'))) ? $ll : $selected);
1299 $lang_options[$ll]=$ll;
1303 $tpl = get_markup_template("lang_selector.tpl");
1304 $o = replace_macros($tpl, array(
1305 '$title' => t('Select an alternate language'),
1306 '$langs' => array($lang_options, $selected),
1313 if(! function_exists('return_bytes')) {
1314 function return_bytes ($size_str) {
1315 switch (substr ($size_str, -1))
1317 case 'M': case 'm': return (int)$size_str * 1048576;
1318 case 'K': case 'k': return (int)$size_str * 1024;
1319 case 'G': case 'g': return (int)$size_str * 1073741824;
1320 default: return $size_str;
1324 function generate_user_guid() {
1327 $guid = random_string(16);
1328 $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
1333 } while ($found == true );
1339 function base64url_encode($s, $strip_padding = false) {
1341 $s = strtr(base64_encode($s),'+/','-_');
1344 $s = str_replace('=','',$s);
1349 function base64url_decode($s) {
1352 logger('base64url_decode: illegal input: ' . print_r(debug_backtrace(), true));
1357 * // Placeholder for new rev of salmon which strips base64 padding.
1358 * // PHP base64_decode handles the un-padded input without requiring this step
1359 * // Uncomment if you find you need it.
1362 * if(! strpos($s,'=')) {
1372 return base64_decode(strtr($s,'-_','+/'));
1376 if (!function_exists('str_getcsv')) {
1377 function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = '\\', $eol = '\n') {
1378 if (is_string($input) && !empty($input)) {
1380 $tmp = preg_split("/".$eol."/",$input);
1381 if (is_array($tmp) && !empty($tmp)) {
1382 while (list($line_num, $line) = each($tmp)) {
1383 if (preg_match("/".$escape.$enclosure."/",$line)) {
1384 while ($strlen = strlen($line)) {
1385 $pos_delimiter = strpos($line,$delimiter);
1386 $pos_enclosure_start = strpos($line,$enclosure);
1388 is_int($pos_delimiter) && is_int($pos_enclosure_start)
1389 && ($pos_enclosure_start < $pos_delimiter)
1391 $enclosed_str = substr($line,1);
1392 $pos_enclosure_end = strpos($enclosed_str,$enclosure);
1393 $enclosed_str = substr($enclosed_str,0,$pos_enclosure_end);
1394 $output[$line_num][] = $enclosed_str;
1395 $offset = $pos_enclosure_end+3;
1397 if (empty($pos_delimiter) && empty($pos_enclosure_start)) {
1398 $output[$line_num][] = substr($line,0);
1399 $offset = strlen($line);
1401 $output[$line_num][] = substr($line,0,$pos_delimiter);
1403 !empty($pos_enclosure_start)
1404 && ($pos_enclosure_start < $pos_delimiter)
1406 ?$pos_enclosure_start
1410 $line = substr($line,$offset);
1413 $line = preg_split("/".$delimiter."/",$line);
1416 * Validating against pesky extra line breaks creating false rows.
1418 if (is_array($line) && !empty($line[0])) {
1419 $output[$line_num] = $line;
1433 function cleardiv() {
1434 return '<div class="clear"></div>';
1438 function bb_translate_video($s) {
1441 $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
1443 foreach($matches as $mtch) {
1444 if((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
1445 $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
1446 elseif(stristr($mtch[1],'vimeo'))
1447 $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
1453 function html2bb_video($s) {
1455 $s = preg_replace('#<object[^>]+>(.*?)https?://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)</object>#ism',
1456 '[youtube]$2[/youtube]', $s);
1458 $s = preg_replace('#<iframe[^>](.*?)https?://www.youtube.com/embed/([A-Za-z0-9\-_=]+)(.*?)</iframe>#ism',
1459 '[youtube]$2[/youtube]', $s);
1461 $s = preg_replace('#<iframe[^>](.*?)https?://player.vimeo.com/video/([0-9]+)(.*?)</iframe>#ism',
1462 '[vimeo]$2[/vimeo]', $s);
1468 * apply xmlify() to all values of array $val, recursively
1470 function array_xmlify($val){
1471 if (is_bool($val)) return $val?"true":"false";
1472 if (is_array($val)) return array_map('array_xmlify', $val);
1473 return xmlify((string) $val);
1477 function reltoabs($text, $base)
1482 $base = rtrim($base,'/');
1484 $base2 = $base . "/";
1487 $pattern = "/<a([^>]*) href=\"(?!http|https|\/)([^\"]*)\"/";
1488 $replace = "<a\${1} href=\"" . $base2 . "\${2}\"";
1489 $text = preg_replace($pattern, $replace, $text);
1491 $pattern = "/<a([^>]*) href=\"(?!http|https)([^\"]*)\"/";
1492 $replace = "<a\${1} href=\"" . $base . "\${2}\"";
1493 $text = preg_replace($pattern, $replace, $text);
1496 $pattern = "/<img([^>]*) src=\"(?!http|https|\/)([^\"]*)\"/";
1497 $replace = "<img\${1} src=\"" . $base2 . "\${2}\"";
1498 $text = preg_replace($pattern, $replace, $text);
1500 $pattern = "/<img([^>]*) src=\"(?!http|https)([^\"]*)\"/";
1501 $replace = "<img\${1} src=\"" . $base . "\${2}\"";
1502 $text = preg_replace($pattern, $replace, $text);
1509 function item_post_type($item) {
1510 if(intval($item['event-id']))
1512 if(strlen($item['resource-id']))
1514 if(strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST)
1515 return t('activity');
1516 if($item['id'] != $item['parent'])
1517 return t('comment');
1521 // post categories and "save to file" use the same item.file table for storage.
1522 // We will differentiate the different uses by wrapping categories in angle brackets
1523 // and save to file categories in square brackets.
1524 // To do this we need to escape these characters if they appear in our tag.
1526 function file_tag_encode($s) {
1527 return str_replace(array('<','>','[',']'),array('%3c','%3e','%5b','%5d'),$s);
1530 function file_tag_decode($s) {
1531 return str_replace(array('%3c','%3e','%5b','%5d'),array('<','>','[',']'),$s);
1534 function file_tag_file_query($table,$s,$type = 'file') {
1537 $str = preg_quote( '[' . str_replace('%','%%',file_tag_encode($s)) . ']' );
1539 $str = preg_quote( '<' . str_replace('%','%%',file_tag_encode($s)) . '>' );
1540 return " AND " . (($table) ? dbesc($table) . '.' : '') . "file regexp '" . dbesc($str) . "' ";
1543 // ex. given music,video return <music><video> or [music][video]
1544 function file_tag_list_to_file($list,$type = 'file') {
1547 $list_array = explode(",",$list);
1548 if($type == 'file') {
1557 foreach($list_array as $item) {
1559 $tag_list .= $lbracket . file_tag_encode(trim($item)) . $rbracket;
1566 // ex. given <music><video>[friends], return music,video or friends
1567 function file_tag_file_to_list($file,$type = 'file') {
1570 if($type == 'file') {
1571 $cnt = preg_match_all('/\[(.*?)\]/',$file,$matches,PREG_SET_ORDER);
1574 $cnt = preg_match_all('/<(.*?)>/',$file,$matches,PREG_SET_ORDER);
1577 foreach($matches as $mtch) {
1580 $list .= file_tag_decode($mtch[1]);
1587 function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') {
1588 // $file_old - categories previously associated with an item
1589 // $file_new - new list of categories for an item
1594 if($file_old == $file_new)
1597 $saved = get_pconfig($uid,'system','filetags');
1598 if(strlen($saved)) {
1599 if($type == 'file') {
1608 $filetags_updated = $saved;
1610 // check for new tags to be added as filetags in pconfig
1611 $new_tags = array();
1612 $check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
1614 foreach($check_new_tags as $tag) {
1615 if(! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
1619 $filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
1621 // check for deleted tags to be removed from filetags in pconfig
1622 $deleted_tags = array();
1623 $check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
1625 foreach($check_deleted_tags as $tag) {
1626 if(! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
1627 $deleted_tags[] = $tag;
1630 foreach($deleted_tags as $key => $tag) {
1631 $r = q("select file from item where uid = %d " . file_tag_file_query('item',$tag,$type),
1636 unset($deleted_tags[$key]);
1639 $filetags_updated = str_replace($lbracket . file_tag_encode($tag) . $rbracket,'',$filetags_updated);
1643 if($saved != $filetags_updated) {
1644 set_pconfig($uid,'system','filetags', $filetags_updated);
1649 if(strlen($file_new)) {
1650 set_pconfig($uid,'system','filetags', $file_new);
1655 function file_tag_save_file($uid,$item,$file) {
1659 $r = q("select file from item where id = %d and uid = %d limit 1",
1664 if(! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']'))
1665 q("update item set file = '%s' where id = %d and uid = %d limit 1",
1666 dbesc($r[0]['file'] . '[' . file_tag_encode($file) . ']'),
1670 $saved = get_pconfig($uid,'system','filetags');
1671 if((! strlen($saved)) || (! stristr($saved,'[' . file_tag_encode($file) . ']')))
1672 set_pconfig($uid,'system','filetags',$saved . '[' . file_tag_encode($file) . ']');
1673 info( t('Item filed') );
1678 function file_tag_unsave_file($uid,$item,$file,$cat = false) {
1684 $pattern = '<' . file_tag_encode($file) . '>' ;
1686 $pattern = '[' . file_tag_encode($file) . ']' ;
1689 $r = q("select file from item where id = %d and uid = %d limit 1",
1696 q("update item set file = '%s' where id = %d and uid = %d limit 1",
1697 dbesc(str_replace($pattern,'',$r[0]['file'])),
1702 $r = q("select file from item where uid = %d and deleted = 0 " . file_tag_file_query('item',$file,(($cat) ? 'category' : 'file')),
1707 $saved = get_pconfig($uid,'system','filetags');
1708 set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved));
1714 function normalise_openid($s) {
1715 return trim(str_replace(array('http://','https://'),array('',''),$s),'/');
1719 function undo_post_tagging($s) {
1721 $cnt = preg_match_all('/([@#])\[url=(.*?)\](.*?)\[\/url\]/ism',$s,$matches,PREG_SET_ORDER);
1723 foreach($matches as $mtch) {
1724 $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);
1730 function fix_mce_lf($s) {
1731 $s = str_replace("\r\n","\n",$s);
1732 // $s = str_replace("\n\n","\n",$s);
1737 function protect_sprintf($s) {
1738 return(str_replace('%','%%',$s));
1742 function is_a_date_arg($s) {
1746 if($i <= $y+1 && strpos($s,'-') == 4) {
1747 $m = intval(substr($s,5));
1748 if($m > 0 && $m <= 12)