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");
13 if(! function_exists('replace_macros')) {
14 function replace_macros($s,$r) {
17 return $t->replace($s,$r);
22 // random string, there are 86 characters max in text mode, 128 for hex
25 define('RANDOM_STRING_HEX', 0x00 );
26 define('RANDOM_STRING_TEXT', 0x01 );
28 if(! function_exists('random_string')) {
29 function random_string($size = 64,$type = RANDOM_STRING_HEX) {
30 // generate a bit of entropy and run it through the whirlpool
31 $s = hash('whirlpool', (string) rand() . uniqid(rand(),true) . (string) rand(),(($type == RANDOM_STRING_TEXT) ? true : false));
32 $s = (($type == RANDOM_STRING_TEXT) ? str_replace("\n","",base64url_encode($s,true)) : $s);
33 return(substr($s,0,$size));
37 * This is our primary input filter.
39 * The high bit hack only involved some old IE browser, forget which (IE5/Mac?)
40 * that had an XSS attack vector due to stripping the high-bit on an 8-bit character
41 * after cleansing, and angle chars with the high bit set could get through as markup.
43 * This is now disabled because it was interfering with some legitimate unicode sequences
44 * and hopefully there aren't a lot of those browsers left.
46 * Use this on any text input where angle chars are not valid or permitted
47 * They will be replaced with safer brackets. This may be filtered further
48 * if these are not allowed either.
52 if(! function_exists('notags')) {
53 function notags($string) {
55 return(str_replace(array("<",">"), array('[',']'), $string));
57 // High-bit filter no longer used
58 // return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
61 // use this on "body" or "content" input where angle chars shouldn't be removed,
62 // and allow them to be safely displayed.
64 if(! function_exists('escape_tags')) {
65 function escape_tags($string) {
67 return(htmlspecialchars($string));
71 // generate a string that's random, but usually pronounceable.
72 // used to generate initial passwords
74 if(! function_exists('autoname')) {
75 function autoname($len) {
77 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
96 's','sc','sh','sm','sp','st',
104 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
105 'nd','ng','nk','nt','rn','rp','rt');
107 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
108 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
110 $start = mt_rand(0,2);
118 for ($x = 0; $x < $len; $x ++) {
119 $r = mt_rand(0,count($table) - 1);
122 if($table == $vowels)
123 $table = array_merge($cons,$midcons);
129 $word = substr($word,0,$len);
131 foreach($noend as $noe) {
132 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
133 $word = substr($word,0,-1);
137 if(substr($word,-1) == 'q')
138 $word = substr($word,0,-1);
143 // escape text ($str) for XML transport
144 // returns escaped text.
146 if(! function_exists('xmlify')) {
147 function xmlify($str) {
150 for($x = 0; $x < mb_strlen($str); $x ++) {
180 $buffer = trim($buffer);
185 // pass xml escaped text ($s), returns unescaped text
187 if(! function_exists('unxmlify')) {
188 function unxmlify($s) {
189 $ret = str_replace('&','&', $s);
190 $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
194 // convenience wrapper, reverse the operation "bin2hex"
196 if(! function_exists('hex2bin')) {
197 function hex2bin($s) {
198 if(! ctype_xdigit($s)) {
199 logger('hex2bin: illegal input: ' . print_r(debug_backtrace(), true));
203 return(pack("H*",$s));
206 // Automatic pagination.
207 // To use, get the count of total items.
208 // Then call $a->set_pager_total($number_items);
209 // Optionally call $a->set_pager_itemspage($n) to the number of items to display on each page
210 // Then call paginate($a) after the end of the display loop to insert the pager block on the page
211 // (assuming there are enough items to paginate).
212 // When using with SQL, the setting LIMIT %d, %d => $a->pager['start'],$a->pager['itemspage']
213 // will limit the results to the correct items for the current page.
214 // The actual page handling is then accomplished at the application layer.
216 if(! function_exists('paginate')) {
217 function paginate(&$a) {
219 $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string);
220 $stripped = str_replace('q=','',$stripped);
221 $stripped = trim($stripped,'/');
222 $pagenum = $a->pager['page'];
223 $url = $a->get_baseurl() . '/' . $stripped;
226 if($a->pager['total'] > $a->pager['itemspage']) {
227 $o .= '<div class="pager">';
228 if($a->pager['page'] != 1)
229 $o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">' . t('prev') . '</a></span> ';
231 $o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">" . t('first') . "</a></span> ";
233 $numpages = $a->pager['total'] / $a->pager['itemspage'];
236 $numstop = $numpages;
239 $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
240 $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
243 for($i = $numstart; $i <= $numstop; $i++){
244 if($i == $a->pager['page'])
245 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
247 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
251 if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
252 if($i == $a->pager['page'])
253 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
255 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
259 $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
260 $o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">" . t('last') . "</a></span> ";
262 if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
263 $o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('next') . '</a></span>';
264 $o .= '</div>'."\r\n";
269 // Turn user/group ACLs stored as angle bracketed text into arrays
271 if(! function_exists('expand_acl')) {
272 function expand_acl($s) {
273 // turn string array of angle-bracketed elements into numeric array
274 // e.g. "<1><2><3>" => array(1,2,3);
278 $t = str_replace('<','',$s);
279 $a = explode('>',$t);
282 $ret[] = intval($aa);
288 // Used to wrap ACL elements in angle brackets for storage
290 if(! function_exists('sanitise_acl')) {
291 function sanitise_acl(&$item) {
293 $item = '<' . intval(notags(trim($item))) . '>';
299 // Convert an ACL array to a storable string
301 if(! function_exists('perms2str')) {
302 function perms2str($p) {
306 array_walk($tmp,'sanitise_acl');
307 $ret = implode('',$tmp);
312 // generate a guaranteed unique (for this domain) item ID for ATOM
313 // safe from birthday paradox
315 if(! function_exists('item_new_uri')) {
316 function item_new_uri($hostname,$uid) {
320 $hash = random_string();
322 $uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash;
324 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
328 } while($dups == true);
332 // Generate a guaranteed unique photo ID.
333 // safe from birthday paradox
335 if(! function_exists('photo_new_resource')) {
336 function photo_new_resource() {
340 $resource = hash('md5',uniqid(mt_rand(),true));
341 $r = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' LIMIT 1",
346 } while($found == true);
351 // wrapper to load a view template, checking for alternate
352 // languages before falling back to the default
354 // obsolete, deprecated.
356 if(! function_exists('load_view_file')) {
357 function load_view_file($s) {
363 if(file_exists("$d/$lang/$b"))
364 return file_get_contents("$d/$lang/$b");
366 $theme = current_theme();
368 if(file_exists("$d/theme/$theme/$b"))
369 return file_get_contents("$d/theme/$theme/$b");
371 return file_get_contents($s);
374 if(! function_exists('get_intltext_template')) {
375 function get_intltext_template($s) {
381 if(file_exists("view/$lang/$s"))
382 return file_get_contents("view/$lang/$s");
383 elseif(file_exists("view/en/$s"))
384 return file_get_contents("view/en/$s");
386 return file_get_contents("view/$s");
389 if(! function_exists('get_markup_template')) {
390 function get_markup_template($s) {
392 $theme = current_theme();
394 if(file_exists("view/theme/$theme/$s"))
395 return file_get_contents("view/theme/$theme/$s");
397 return file_get_contents("view/$s");
405 // for html,xml parsing - let's say you've got
406 // an attribute foobar="class1 class2 class3"
407 // and you want to find out if it contains 'class3'.
408 // you can't use a normal sub string search because you
409 // might match 'notclass3' and a regex to do the job is
410 // possible but a bit complicated.
411 // pass the attribute string as $attr and the attribute you
412 // are looking for as $s - returns true if found, otherwise false
414 if(! function_exists('attribute_contains')) {
415 function attribute_contains($attr,$s) {
416 $a = explode(' ', $attr);
417 if(count($a) && in_array($s,$a))
422 if(! function_exists('logger')) {
423 function logger($msg,$level = 0) {
424 $debugging = get_config('system','debugging');
425 $loglevel = intval(get_config('system','loglevel'));
426 $logfile = get_config('system','logfile');
428 if((! $debugging) || (! $logfile) || ($level > $loglevel))
431 @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND);
436 if(! function_exists('activity_match')) {
437 function activity_match($haystack,$needle) {
438 if(($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle,NAMESPACE_ACTIVITY_SCHEMA)))
444 // Pull out all #hashtags and @person tags from $s;
445 // We also get @person@domain.com - which would make
446 // the regex quite complicated as tags can also
447 // end a sentence. So we'll run through our results
448 // and strip the period from any tags which end with one.
449 // Returns array of tags found, or empty array.
452 if(! function_exists('get_tags')) {
453 function get_tags($s) {
456 // ignore anything in a code block
458 $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s);
460 // Match full names against @tags including the space between first and last
461 // We will look these up afterward to see if they are full names or not recognisable.
463 if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
464 foreach($match[1] as $mtch) {
465 if(strstr($mtch,"]")) {
466 // we might be inside a bbcode color tag - leave it alone
469 if(substr($mtch,-1,1) === '.')
470 $ret[] = substr($mtch,0,-1);
476 // Otherwise pull out single word tags. These can be @nickname, @first_last
479 if(preg_match_all('/([@#][^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
480 foreach($match[1] as $mtch) {
481 if(strstr($mtch,"]")) {
482 // we might be inside a bbcode color tag - leave it alone
485 // ignore strictly numeric tags like #1
486 if((strpos($mtch,'#') === 0) && ctype_digit(substr($mtch,1)))
488 if(substr($mtch,-1,1) === '.')
489 $ret[] = substr($mtch,0,-1);
498 // quick and dirty quoted_printable encoding
500 if(! function_exists('qp')) {
502 return str_replace ("%","=",rawurlencode($s));
507 if(! function_exists('get_mentions')) {
508 function get_mentions($item) {
510 if(! strlen($item['tag']))
513 $arr = explode(',',$item['tag']);
514 foreach($arr as $x) {
516 if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
517 $o .= "\t\t" . '<link rel="mentioned" href="' . $matches[1] . '" />' . "\r\n";
518 $o .= "\t\t" . '<link rel="ostatus:attention" href="' . $matches[1] . '" />' . "\r\n";
524 if(! function_exists('contact_block')) {
525 function contact_block() {
529 $shown = get_pconfig($a->profile['uid'],'system','display_friend_count');
533 if((! is_array($a->profile)) || ($a->profile['hide-friends']))
535 $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0",
536 intval($a->profile['uid'])
539 $total = intval($r[0]['total']);
542 $o .= '<h4 class="contact-h4">' . t('No contacts') . '</h4>';
545 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT %d",
546 intval($a->profile['uid']),
550 $o .= '<h4 class="contact-h4">' . sprintf( tt('%d Contact','%d Contacts', $total),$total) . '</h4><div id="contact-block">';
552 $o .= micropro($rr,true,'mpfriend');
554 $o .= '</div><div id="contact-block-end"></div>';
555 $o .= '<div id="viewcontacts"><a id="viewcontacts-link" href="viewcontacts/' . $a->profile['nickname'] . '">' . t('View Contacts') . '</a></div>';
559 $arr = array('contacts' => $r, 'output' => $o);
561 call_hooks('contact_block_end', $arr);
566 if(! function_exists('micropro')) {
567 function micropro($contact, $redirect = false, $class = '', $textmode = false) {
570 $class = ' ' . $class;
572 $url = $contact['url'];
577 $redirect_url = $a->get_baseurl() . '/redir/' . $contact['id'];
578 if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === 'dfrn')) {
579 $url = $redirect_url;
580 $sparkle = ' sparkle';
583 $click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : '');
587 return '<div class="contact-block-textdiv' . $class . '"><a class="contact-block-link' . $class . $sparkle
588 . (($click) ? ' fakelink' : '') . '" '
589 . (($url) ? ' href="' . $url . '"' : '') . $click
590 . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
591 . '" >'. $contact['name'] . '</a></div>' . "\r\n";
594 return '<div class="contact-block-div' . $class . '"><a class="contact-block-link' . $class . $sparkle
595 . (($click) ? ' fakelink' : '') . '" '
596 . (($url) ? ' href="' . $url . '"' : '') . $click . ' ><img class="contact-block-img' . $class . $sparkle . '" src="'
597 . $contact['micro'] . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
598 . '" /></a></div>' . "\r\n";
604 if(! function_exists('search')) {
605 function search($s,$id='search-box',$url='/search') {
607 $o = '<div id="' . $id . '">';
608 $o .= '<form action="' . $a->get_baseurl() . $url . '" method="get" >';
609 $o .= '<input type="text" name="search" id="search-text" value="' . $s .'" />';
610 $o .= '<input type="submit" name="submit" id="search-submit" value="' . t('Search') . '" />';
611 $o .= '</form></div>';
615 if(! function_exists('valid_email')) {
616 function valid_email($x){
617 if(preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
627 * Replace naked text hyperlink with HTML formatted hyperlink
631 if(! function_exists('linkify')) {
632 function linkify($s) {
633 $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="external-link">$1</a>', $s);
643 * Replaces text emoticons with graphical images
645 * @Parameter: string $s
650 if(! function_exists('smilies')) {
651 function smilies($s) {
655 array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O',
656 '~friendika', 'Diaspora*' ),
658 '<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
659 '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
660 '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
661 '<img src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
662 '<img src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":)" />',
663 '<img src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
664 '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
665 '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":(" />',
666 '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
667 '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":P" />',
668 '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
669 '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
670 '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
671 '<img src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
672 '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
673 '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
674 '<a href="http://project.friendika.com">~friendika <img src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendika" /></a>',
675 '<a href="http://joindiaspora.com">Diaspora<img src="' . $a->get_baseurl() . '/images/diaspora.png" alt="Diaspora*" /></a>',
682 if(! function_exists('day_translate')) {
683 function day_translate($s) {
684 $ret = str_replace(array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'),
685 array( t('Monday'), t('Tuesday'), t('Wednesday'), t('Thursday'), t('Friday'), t('Saturday'), t('Sunday')),
688 $ret = str_replace(array('January','February','March','April','May','June','July','August','September','October','November','December'),
689 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')),
696 if(! function_exists('normalise_link')) {
697 function normalise_link($url) {
698 $ret = str_replace(array('https:','//www.'), array('http:','//'), $url);
699 return(rtrim($ret,'/'));
704 * Compare two URLs to see if they are the same, but ignore
705 * slight but hopefully insignificant differences such as if one
706 * is https and the other isn't, or if one is www.something and
707 * the other isn't - and also ignore case differences.
709 * Return true if the URLs match, otherwise false.
713 if(! function_exists('link_compare')) {
714 function link_compare($a,$b) {
715 if(strcasecmp(normalise_link($a),normalise_link($b)) === 0)
720 // Given an item array, convert the body element from bbcode to html and add smilie icons.
721 // If attach is true, also add icons for item attachments
724 if(! function_exists('prepare_body')) {
725 function prepare_body($item,$attach = false) {
727 $s = prepare_text($item['body']);
731 $arr = explode(',',$item['attach']);
733 $s .= '<div class="body-attach">';
734 foreach($arr as $r) {
737 $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches);
739 $icontype = strtolower(substr($matches[3],0,strpos($matches[3],'/')));
745 $icon = '<div class="attachtype type-' . $icontype . '"></div>';
748 $icon = '<div class="attachtype type-unkn"></div>';
751 $title = ((strlen(trim($matches[4]))) ? escape_tags(trim($matches[4])) : escape_tags($matches[1]));
752 $title .= ' ' . $matches[2] . ' ' . t('bytes');
754 $s .= '<a href="' . strip_tags($matches[1]) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>';
757 $s .= '<div class="clear"></div></div>';
763 // Given a text string, convert from bbcode to html and add smilie icons.
765 if(! function_exists('prepare_text')) {
766 function prepare_text($text) {
768 require_once('include/bbcode.php');
770 $s = smilies(bbcode($text));
777 * return atom link elements for all of our hubs
780 if(! function_exists('feed_hublinks')) {
781 function feed_hublinks() {
783 $hub = get_config('system','huburl');
787 $hubs = explode(',', $hub);
789 foreach($hubs as $h) {
793 $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
800 /* return atom link elements for salmon endpoints */
802 if(! function_exists('feed_salmonlinks')) {
803 function feed_salmonlinks($nick) {
807 $salmon = '<link rel="salmon" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
809 // old style links that status.net still needed as of 12/2010
811 $salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
812 $salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
816 if(! function_exists('get_plink')) {
817 function get_plink($item) {
819 $plink = (((x($item,'plink')) && (! $item['private'])) ? '<div class="wall-item-links-wrapper"><a href="'
820 . $item['plink'] . '" title="' . t('link to source') . '" target="external-link" class="icon remote-link"></a></div>' : '');
824 if(! function_exists('unamp')) {
826 return str_replace('&', '&', $s);
832 if(! function_exists('lang_selector')) {
833 function lang_selector() {
835 $o = '<div id="lang-select-icon" class="icon language" title="' . t('Select an alternate language') . '" onclick="openClose(\'language-selector\');" ></div>';
836 $o .= '<div id="language-selector" style="display: none;" >';
837 $o .= '<form action="" method="post" ><select name="system_language" onchange="this.form.submit();" >';
838 $langs = glob('view/*/strings.php');
839 if(is_array($langs) && count($langs)) {
840 if(! in_array('view/en/strings.php',$langs))
841 $langs[] = 'view/en/';
843 foreach($langs as $l) {
845 $ll = substr($ll,0,strrpos($ll,'/'));
846 $selected = (($ll === $lang) ? ' selected="selected" ' : '');
847 $o .= '<option value="' . $ll . '"' . $selected . '>' . $ll . '</option>';
850 $o .= '</select></form></div>';
855 if(! function_exists('return_bytes')) {
856 function return_bytes ($size_str) {
857 switch (substr ($size_str, -1))
859 case 'M': case 'm': return (int)$size_str * 1048576;
860 case 'K': case 'k': return (int)$size_str * 1024;
861 case 'G': case 'g': return (int)$size_str * 1073741824;
862 default: return $size_str;
866 function generate_user_guid() {
869 $guid = random_string(16);
870 $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
875 } while ($found == true );
881 function base64url_encode($s, $strip_padding = false) {
883 $s = strtr(base64_encode($s),'+/','-_');
886 $s = str_replace('=','',$s);
891 function base64url_decode($s) {
894 * // Placeholder for new rev of salmon which strips base64 padding.
895 * // PHP base64_decode handles the un-padded input without requiring this step
896 * // Uncomment if you find you need it.
899 * if(! strpos($s,'=')) {
909 return base64_decode(strtr($s,'-_','+/'));
912 function cc_license() {
913 return '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';