130520 User search and wetcat theme

This commit is contained in:
Daisuke
2020-05-13 15:26:38 -05:00
parent 1f2b2fd19c
commit 125b944385
21 changed files with 689 additions and 123 deletions

View File

@ -39,23 +39,6 @@ function get_urls($input) {
return false;
}
/* this function replaces the emoji codes in a text with the correspondent emojis
of the specified instance, returns the html code with the emojis in the specified size*/
/*
function emoji($text, $size = 30, $srv) {
$data = json_decode(file_get_contents("https://$srv/api/v1/custom_emojis") , true) [0]['url'];
$u = explode("/", $data);
array_pop($u);
$url = implode("/", $u);
$text = str_replace("http:", "http;", $text);
$text = str_replace("https:", "https;", $text);
$text = preg_replace('~:([a-z0-9_]+):~', "<img src='$url/$1.png' height=$size style='vertical-align: middle;'>", $text);
$text = str_replace("http;", "http:", $text);
$text = str_replace("https;", "https:", $text);
return $text;
}
*/
/* this is the same as above but is used on other places, like user bios and places where the
shortcodes and the emoji url is defined in the same place */
function emojify($string, $emojis, $size = 40) {
@ -89,6 +72,22 @@ function emoji_list($val){
return $return;
}
function contact_search($val){
global $user_settings;
$return = "";
$list = api_get("/accounts/search?q=".$val);
foreach ($list as $contact){
$return .= "<div class='contact' title='@".$contact['acct']."' style='width:100%; clear:both; height:40px; display:inline-block;'>
<div style='width:40px; height:40px; background-size:cover; background-image:url(".$contact['avatar']."); float:left;'></div>
<div>
<span style='font-weight:bold;'>".emojify($contact['display_name'], $contact['emojis'], 15)."</span><br>
<span style='font-size:12px;'>".$contact['acct']."</span>
</div>
</div>";
}
return $return;
}
/* general function to check if one strings starts with a given search */
function starts_with($string,$search){
@ -921,10 +920,13 @@ function processText($elem) {
global $user_settings;
require_once "vendor/simple_html_dom.php";
$content = trim(html_entity_decode($elem['content'],ENT_QUOTES));
$content = preg_replace("/<(?=[^>]*(?:<|$))/","&lt;",$content);
if (!empty($content)) {
$html = str_get_html($content);
foreach ($html->find('a') as $lnk) {
//remove text links to media attachments
foreach ($elem['media_attachments'] as $f) {
if (is_numeric(strpos($f['description'],explode("",$lnk->innertext)[0]))) {
$content = str_replace($lnk->outertext . "<br/>", null, $content);
@ -933,6 +935,7 @@ function processText($elem) {
}
}
//modify links for hashtags and external urls
if (is_numeric(strpos($lnk->href, $user_settings['instance'])) || in_array($lnk->class, array(
"u-url mention",
"hashtag"
@ -947,7 +950,7 @@ function processText($elem) {
}
}
}
$result = strip_tags($content, '<br><p><strong><a><em><strike>');
$result = str_replace('<br />', ' <br>', $result);
//$result = str_replace('&#39;', "'", $result);
@ -1038,4 +1041,22 @@ function time_elapsed_string($datetime, $full = false) {
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
function getHeaders($respHeaders) {
$headers = array();
$headerText = substr($respHeaders, 0, strpos($respHeaders, "\r\n\r\n"));
foreach (explode("\r\n", $headerText) as $i => $line) {
if ($i === 0) {
$headers['http_code'] = $line;
} else {
list ($key, $value) = explode(': ', $line);
$headers[$key] = $value;
}
}
return $headerText;
}