]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
move js to js folder
[friendica.git] / include / text.php
index a568b7a948ad7861735e0db47cedbbea36c3f684..78eae145e2c90a8617450e27ea31030cf08a4042 100644 (file)
@@ -19,11 +19,18 @@ function replace_macros($s,$r) {
 }}
 
 
-// random hash, 64 chars
+// random string, there are 86 characters max in text mode, 128 for hex
+// output is urlsafe
+
+define('RANDOM_STRING_HEX',  0x00 );
+define('RANDOM_STRING_TEXT', 0x01 );
 
 if(! function_exists('random_string')) {
-function random_string() {
-       return(hash('sha256',uniqid(rand(),true)));
+function random_string($size = 64,$type = RANDOM_STRING_HEX) {
+       // generate a bit of entropy and run it through the whirlpool
+       $s = hash('whirlpool', (string) rand() . uniqid(rand(),true) . (string) rand(),(($type == RANDOM_STRING_TEXT) ? true : false));
+       $s = (($type == RANDOM_STRING_TEXT) ? str_replace("\n","",base64url_encode($s,true)) : $s);
+       return(substr($s,0,$size));
 }}
 
 /**
@@ -140,7 +147,7 @@ if(! function_exists('xmlify')) {
 function xmlify($str) {
        $buffer = '';
        
-       for($x = 0; $x < strlen($str); $x ++) {
+       for($x = 0; $x < mb_strlen($str); $x ++) {
                $char = $str[$x];
         
                switch( $char ) {
@@ -532,22 +539,30 @@ function contact_block() {
                $total = intval($r[0]['total']);
        }
        if(! $total) {
-               $o .= '<h4 class="contact-h4">' . t('No contacts') . '</h4>';
-               return $o;
-       }
-       $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT %d",
-                       intval($a->profile['uid']),
-                       intval($shown)
-       );
-       if(count($r)) {
-               $o .= '<h4 class="contact-h4">' .  sprintf( tt('%d Contact','%d Contacts', $total),$total) . '</h4><div id="contact-block">';
-               foreach($r as $rr) {
-                       $o .= micropro($rr,true,'mpfriend');
-               }
-               $o .= '</div><div id="contact-block-end"></div>';
-               $o .=  '<div id="viewcontacts"><a id="viewcontacts-link" href="viewcontacts/' . $a->profile['nickname'] . '">' . t('View Contacts') . '</a></div>';
+               $contacts = t('No contacts');
+               $micropro = Null;
                
+       } else {
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT %d",
+                               intval($a->profile['uid']),
+                               intval($shown)
+               );
+               if(count($r)) {
+                       $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
+                       $micropro = Array();
+                       foreach($r as $rr) {
+                               $micropro[] = micropro($rr,true,'mpfriend');
+                       }
+               }
        }
+       
+       $tpl = get_markup_template('contact_block.tpl');
+       $o = replace_macros($tpl, array(
+               '$contacts' => $contacts,
+               '$nickname' => $a->profile['nickname'],
+               '$viewcontacts' => t('View Contacts'),
+               '$micropro' => $micropro,
+       ));
 
        $arr = array('contacts' => $r, 'output' => $o);
 
@@ -595,12 +610,14 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
 
 
 if(! function_exists('search')) {
-function search($s,$id='search-box',$url='/search') {
+function search($s,$id='search-box',$url='/search',$save = false) {
        $a = get_app();
        $o  = '<div id="' . $id . '">';
        $o .= '<form action="' . $a->get_baseurl() . $url . '" method="get" >';
        $o .= '<input type="text" name="search" id="search-text" value="' . $s .'" />';
        $o .= '<input type="submit" name="submit" id="search-submit" value="' . t('Search') . '" />'; 
+       if($save)
+               $o .= '<input type="submit" name="save" id="search-save" value="' . t('Save') . '" />'; 
        $o .= '</form></div>';
        return $o;
 }}
@@ -613,32 +630,6 @@ function valid_email($x){
 }}
 
 
-if(! function_exists('aes_decrypt')) {
-function aes_decrypt($val,$ky)
-{
-    $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
-    for($a=0;$a<strlen($ky);$a++)
-      $key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
-    $mode = MCRYPT_MODE_ECB;
-    $enc = MCRYPT_RIJNDAEL_128;
-    $dec = @mcrypt_decrypt($enc, $key, $val, $mode, @mcrypt_create_iv( @mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM ) );
-    return rtrim($dec,(( ord(substr($dec,strlen($dec)-1,1))>=0 and ord(substr($dec, strlen($dec)-1,1))<=16)? chr(ord( substr($dec,strlen($dec)-1,1))):null));
-}}
-
-
-if(! function_exists('aes_encrypt')) {
-function aes_encrypt($val,$ky)
-{
-    $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
-    for($a=0;$a<strlen($ky);$a++)
-      $key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
-    $mode=MCRYPT_MODE_ECB;
-    $enc=MCRYPT_RIJNDAEL_128;
-    $val=str_pad($val, (16*(floor(strlen($val) / 16)+(strlen($val) % 16==0?2:1))), chr(16-(strlen($val) % 16)));
-    return mcrypt_encrypt($enc, $key, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM));
-}} 
-
-
 /**
  *
  * Function: linkify
@@ -671,7 +662,8 @@ function smilies($s) {
        $a = get_app();
 
        return str_replace(
-       array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O'),
+       array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', 
+               '~friendika', 'Diaspora*' ),
        array(
                '<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
@@ -688,7 +680,10 @@ function smilies($s) {
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />'
+               '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
+               '<a href="http://project.friendika.com">~friendika <img src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendika" /></a>',
+               '<a href="http://joindiaspora.com">Diaspora<img src="' . $a->get_baseurl() . '/images/diaspora.png" alt="Diaspora*" /></a>',
+
        ), $s);
 }}
 
@@ -732,6 +727,9 @@ function link_compare($a,$b) {
        return false;
 }}
 
+// Given an item array, convert the body element from bbcode to html and add smilie icons.
+// If attach is true, also add icons for item attachments
+
 
 if(! function_exists('prepare_body')) {
 function prepare_body($item,$attach = false) {
@@ -771,6 +769,9 @@ function prepare_body($item,$attach = false) {
        return $s;
 }}
 
+
+// Given a text string, convert from bbcode to html and add smilie icons.
+
 if(! function_exists('prepare_text')) {
 function prepare_text($text) {
 
@@ -872,10 +873,10 @@ function return_bytes ($size_str) {
     }
 }}
 
-function generate_guid() {
+function generate_user_guid() {
        $found = true;
        do {
-               $guid = substr(random_string(),0,16);
+               $guid = random_string(16);
                $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
                        dbesc($guid)
                );
@@ -886,20 +887,6 @@ function generate_guid() {
 }
 
 
-function pkcs5_pad ($text, $blocksize)
-{
-    $pad = $blocksize - (strlen($text) % $blocksize);
-    return $text . str_repeat(chr($pad), $pad);
-}
-
-function pkcs5_unpad($text)
-{
-    $pad = ord($text{strlen($text)-1});
-    if ($pad > strlen($text)) return false;
-    if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
-    return substr($text, 0, -1 * $pad);
-} 
-
 
 function base64url_encode($s, $strip_padding = false) {
 
@@ -931,3 +918,7 @@ function base64url_decode($s) {
 
        return base64_decode(strtr($s,'-_','+/'));
 }
+
+function cc_license() {
+return '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
+}