X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=3aec42b3239b1fbee986d15b60183f53f05fc9fa;hb=497fd34026fbaa83b11a64d3a0a6e20f1360e5d6;hp=956344d63d622f9f00b089b053bf49ecbcce3414;hpb=01b02dbcaa8532f965389375e961d9c47d74eeec;p=friendica.git diff --git a/include/text.php b/include/text.php index 956344d63d..3aec42b323 100644 --- a/include/text.php +++ b/include/text.php @@ -717,10 +717,15 @@ function logger($msg,$level = 0) { if((! $debugging) || (! $logfile) || ($level > $loglevel)) return; + $process_id = session_id(); + + if ($process_id == "") + $process_id = get_app()->process_id; + $callers = debug_backtrace(); $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n", datetime_convert(), - session_id(), + $process_id, $LOGGER_LEVELS[$level], basename($callers[0]['file']), $callers[0]['line'], @@ -867,7 +872,8 @@ function contact_block() { $micropro = Null; } else { - $r = q("SELECT `id`, `uid`, `addr`, `url`, `name`, `micro`, `network` FROM `contact` + // Splitting the query in two parts makes it much faster + $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `hidden` AND NOT `archive` AND `network` IN ('%s', '%s', '%s') ORDER BY RAND() LIMIT %d", @@ -877,11 +883,19 @@ function contact_block() { dbesc(NETWORK_DIASPORA), 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'); + if ($r) { + $contacts = ""; + foreach ($r AS $contact) + $contacts[] = $contact["id"]; + + $r = q("SELECT `id`, `uid`, `addr`, `url`, `name`, `thumb`, `network` FROM `contact` WHERE `id` IN (%s)", + dbesc(implode(",", $contacts))); + if(count($r)) { + $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total); + $micropro = Array(); + foreach($r as $rr) { + $micropro[] = micropro($rr,true,'mpfriend'); + } } } } @@ -901,20 +915,28 @@ function contact_block() { }} -if(! function_exists('micropro')) { /** + * @brief Format contacts as picture links or as texxt links * - * @param array $contact - * @param boolean $redirect - * @param string $class - * @param boolean $textmode - * @return string #FIXME: remove html + * @param array $contact Array with contacts which contains an array with + * int 'id' => The ID of the contact + * int 'uid' => The user ID of the user who owns this data + * string 'name' => The name of the contact + * string 'url' => The url to the profile page of the contact + * string 'addr' => The webbie of the contact (e.g.) username@friendica.com + * string 'network' => The network to which the contact belongs to + * string 'thumb' => The contact picture + * string 'click' => js code which is performed when clicking on the contact + * @param boolean $redirect If true try to use the redir url if it's possible + * @param string $class CSS class for the + * @param boolean $textmode If true display the contacts as text links + * if false display the contacts as picture links + + * @return string Formatted html */ function micropro($contact, $redirect = false, $class = '', $textmode = false) { - if($class) - $class = ' ' . $class; - + // Use the contact URL if no address is available if ($contact["addr"] == "") $contact["addr"] = $contact["url"]; @@ -933,26 +955,23 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { else $url = zrl($url); } - $click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : ''); - if($click) + + // If there is some js available we don't need the url + if(x($contact,'click')) $url = ''; - if($textmode) { - return '
'. $contact['name'] . '
' . "\r\n"; - } - else { - return '
' . $contact['name']
-			. '
' . "\r\n"; - } -}} + + return replace_macros(get_markup_template(($textmode)?'micropro_txt.tpl':'micropro_img.tpl'),array( + '$click' => (($contact['click']) ? $contact['click'] : ''), + '$class' => $class, + '$url' => $url, + '$photo' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB), + '$name' => $contact['name'], + 'title' => $contact['name'] . ' [' . $contact['addr'] . ']', + '$parkle' => $sparkle, + '$redir' => $redir, + + )); +} @@ -975,6 +994,7 @@ function search($s,$id='search-box',$url='search',$save = false, $aside = true) '$search_label' => t('Search'), '$save_label' => t('Save'), '$savedsearch' => feature_enabled(local_user(),'savedsearch'), + '$search_hint' => t('@name, !forum, #tags, content'), ); if (!$aside) { @@ -2086,3 +2106,54 @@ function format_network_name($network, $url = 0) { } } + +/** + * @brief Syntax based code highlighting for popular languages. + * @param string $s Code block + * @param string $lang Programming language + * @return string Formated html + */ +function text_highlight($s,$lang) { + if($lang === 'js') + $lang = 'javascript'; + + if(! strpos('Text_Highlighter',get_include_path())) { + set_include_path(get_include_path() . PATH_SEPARATOR . 'library/Text_Highlighter'); + } + + require_once('library/Text_Highlighter/Text/Highlighter.php'); + require_once('library/Text_Highlighter/Text/Highlighter/Renderer/Html.php'); + $options = array( + 'numbers' => HL_NUMBERS_LI, + 'tabsize' => 4, + ); + + $tag_added = false; + $s = trim(html_entity_decode($s,ENT_COMPAT)); + $s = str_replace(" ","\t",$s); + + // The highlighter library insists on an opening php tag for php code blocks. If + // it isn't present, nothing is highlighted. So we're going to see if it's present. + // If not, we'll add it, and then quietly remove it after we get the processed output back. + + if($lang === 'php') { + if(strpos('setRenderer($renderer); + $o = $hl->highlight($s); + $o = str_replace([" ","\n"],["    ",''],$o); + + if($tag_added) { + $b = substr($o,0,strpos($o,'
  • ')); + $e = substr($o,strpos($o,'
  • ')); + $o = $b . $e; + } + + return('' . $o . ''); +}