diff --git a/libs/timeline.css b/libs/timeline.css index 9dd5a0d..668e585 100644 --- a/libs/timeline.css +++ b/libs/timeline.css @@ -144,7 +144,7 @@ a.author { .profile { padding: 0 1rem; - margin-bottom: 2rem; + margin-bottom: 1rem; } .profile-grid { diff --git a/libs/twtxt.php b/libs/twtxt.php index 78f8710..a45ef1c 100644 --- a/libs/twtxt.php +++ b/libs/twtxt.php @@ -334,6 +334,7 @@ function getTwtsFromTwtxtString($url) { } if (str_starts_with($currentLine, '#')) { + // Check if comments (starting with #) have some metadata if (!is_null(getSingleParameter('url', $currentLine))) { $currentURL = getSingleParameter('url', $currentLine); @@ -364,6 +365,18 @@ function getTwtsFromTwtxtString($url) { } } + // Fallback for nick and url if not set in twtxt.txt + if ($twtxtData->nick === "") { + $host_to_nick = parse_url($url, PHP_URL_HOST); + $host_to_nick = str_replace("www.", "", $host_to_nick); + $host_to_nick = explode(".", $host_to_nick)[0]; + $twtxtData->nick = $host_to_nick; + } + if ($twtxtData->mainURL === "") { + $twtxtData->mainURL = $url; + } + + if (!str_starts_with($currentLine, '#')) { $explodedLine = explode("\t", $currentLine); if (count($explodedLine) >= 2) { diff --git a/partials/profile.php b/partials/profile.php index 5332176..bb90ce3 100644 --- a/partials/profile.php +++ b/partials/profile.php @@ -23,11 +23,19 @@ $twt_posts = array_filter($twts, function ($twt) use ($pattern) { return !preg_match($pattern, $twt->originalTwtStr); }); +$twt_gallery = array_filter($twts, function ($twt) { + return preg_match('/!\[(.*?)\]\((.*?)\)/', $twt->originalTwtStr); + //return preg_match('/(]+>)/i', $twt->content); +}); + + + // Get active view/filter $is_gallery = str_contains(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), "gallery"); $is_replies = str_contains(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), "replies"); if ($is_gallery) { + //$twts = $twt_gallery; $posts_active = ""; $replies_active = ""; $gallery_artive = "class='active'"; diff --git a/partials/search.php b/partials/search.php index 7029d74..6346c3f 100644 --- a/partials/search.php +++ b/partials/search.php @@ -9,6 +9,7 @@ if (!empty($_GET['search'])) { $pattern = preg_quote($search, '/'); $pattern = "/^.*$pattern.*\$/mi"; + // TODO: Make into a genral function in twtxt.php since i use it so much in profile.php and potentialle other places $twts = array_filter($twts, function ($twt) use ($pattern) { return preg_match($pattern, $twt->content); }); diff --git a/partials/tag_cloud.php b/partials/tag_cloud.php index 78cf387..b48912f 100644 --- a/partials/tag_cloud.php +++ b/partials/tag_cloud.php @@ -4,6 +4,8 @@ // Base on code from: https://social.dfaria.eu/search // Add all tags to one array +$tags = []; + foreach ($twts as $twt) { $tag_array = getTagsFromTwt($twt->content); @@ -12,66 +14,69 @@ foreach ($twts as $twt) { } } -natcasesort($tags); -$tag_count = array_count_values($tags); -//arsort($tag_count, SORT_STRING); -//ksort($tag_count, SORT_STRING); -//strnatcasecmp($tag_count); - -$max_count = max($tag_count); - -$min_font_size = 10; -$max_font_size = 30; -$num_intermediate_levels = 1; -$font_size_interval = ($max_font_size - $min_font_size) / ($num_intermediate_levels + 1); - -// Get current URI to keep the `?profile=URL` as the base for links to tags -$uri = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; - -// Remove existing `(?|&)search=word` params from base URI -// https://stackoverflow.com/a/4937540 -$uri = preg_replace('/.search=\w+&?/', '$1', $uri); - - -// Get active tag, if any -$active_tag = ""; -if (!empty($_GET['search'])) { - $active_tag = $_GET['search']; -} - -foreach ($tag_count as $tag => $count) { - $font_size = $min_font_size + ($count / $max_count) * $font_size_interval; - $tag = str_replace('#', '', $tag); +if(!empty($tags)) { - if ($tag === $active_tag) { - echo '#'. $tag .' '; - } else { - echo '#'. $tag .' '; + natcasesort($tags); + $tag_count = array_count_values($tags); + //arsort($tag_count, SORT_STRING); + //ksort($tag_count, SORT_STRING); + //strnatcasecmp($tag_count); + + $max_count = max($tag_count); + + $min_font_size = 10; + $max_font_size = 30; + $num_intermediate_levels = 1; + $font_size_interval = ($max_font_size - $min_font_size) / ($num_intermediate_levels + 1); + + // Get current URI to keep the `?profile=URL` as the base for links to tags + $uri = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + + // Remove existing `(?|&)search=word` params from base URI + // https://stackoverflow.com/a/4937540 + $uri = preg_replace('/.search=\w+&?/', '$1', $uri); + + + // Get active tag, if any + $active_tag = ""; + if (!empty($_GET['search'])) { + $active_tag = $_GET['search']; } - //echo '#'. $tag .' ('.$count.') '; -} -// Detail/summary with top tags and solo tags + foreach ($tag_count as $tag => $count) { + $font_size = $min_font_size + ($count / $max_count) * $font_size_interval; + $tag = str_replace('#', '', $tag); + + if ($tag === $active_tag) { + echo '#'. $tag .' '; + } else { + echo '#'. $tag .' '; + } + //echo '#'. $tag .' ('.$count.') '; + } -/* -$top_tags = array_filter($tag_count, function($val){return ($val>1);}); -$solo_tags = array_diff($tag_count, $top_tags); -krsort($solo_tags, SORT_STRING); + // Detail/summary with top tags and solo tags -echo "
Tags: "; + /* + $top_tags = array_filter($tag_count, function($val){return ($val>1);}); + $solo_tags = array_diff($tag_count, $top_tags); + krsort($solo_tags, SORT_STRING); -foreach ($top_tags as $tag => $count) { - $tag = str_replace('#', '', $tag); - echo '#'.$tag.' '; -} + echo "
Tags: "; -echo ""; + foreach ($top_tags as $tag => $count) { + $tag = str_replace('#', '', $tag); + echo '#'.$tag.' '; + } -foreach ($solo_tags as $tag => $count) { - $tag = str_replace('#', '', $tag); - echo '#'.$tag.' '; -} + echo "
"; -echo "
"; -*/ + foreach ($solo_tags as $tag => $count) { + $tag = str_replace('#', '', $tag); + echo '#'.$tag.' '; + } + echo ""; + */ + +} \ No newline at end of file