diff --git a/index.php b/index.php index b1cff4e..405e999 100644 --- a/index.php +++ b/index.php @@ -35,6 +35,7 @@ $routes = [ '/login' => 'login.php', '/logout' => 'logout.php', '/profile' => 'profile.php', + '/replies' => 'replies.php', '/gallery' => 'gallery.php', //'/profile/([a-zA-Z0-9_-]+)' => 'profile.php', '/conv/([a-zA-Z0-9]{7})' => 'conv.php', // matches only twtHash of exactly 7 alphanumeric characters diff --git a/libs/timeline.css b/libs/timeline.css index a2226fa..9dcb814 100644 --- a/libs/timeline.css +++ b/libs/timeline.css @@ -174,6 +174,35 @@ a.author { color: var(--accent); } +.profile .filters a { + text-decoration: none; + font-weight: bold; + padding-right: 0.5rem; +} + +.profile a.active { + color: var(--accent); +} + +/* == Tag Cloud ===================== */ + +.tagcloud { + margin-top: 0.75rem; + border-top: thin solid var(--border); + padding: 0.2rem; +} + +.tagcloud a, +.tagcloud a:visited { + text-decoration: none; + padding-right: 0.2rem; + line-height: 1; + color: var(--text-light); +} + +.tagcloud a.active { + color: var(--accent); +} /* === TIMELINE === */ @@ -282,25 +311,6 @@ nav.pagnation { border-radius: 0.25rem; } -/* == Tag Cloud ===================== */ - -.tagcloud { - margin-top: 0.75rem; - border-top: thin solid var(--border); - padding: 0.2rem; -} - -.tagcloud a, -.tagcloud a:visited { - text-decoration: none; - padding-right: 0.2rem; - color: var(--text-light); -} - -.tagcloud a.active { - color: red; -} - /* === FOOTER === */ footer { diff --git a/libs/twtxt.php b/libs/twtxt.php index 0b52cb8..78f8710 100644 --- a/libs/twtxt.php +++ b/libs/twtxt.php @@ -122,6 +122,7 @@ function getImagesFromTwt(string $twtString) { function getTagsFromTwt(string $twtString) { //$pattern = '/(?content); - }); - - echo "
";
-    print_r($twts[1711985096]);
-    */
-
-
-    $twts_filtered = [];
-
-    //print_r($twts_filtered);
-
-    // 2. Repalce original $twts with new $twts_filtered
-    //$twts = $twts_filtered
-
-
-    foreach ($twts as $twt) {
-
-        if (preg_match_all($pattern, $twt->content, $matches)) {
-            
-            echo "
"; - print_r($twt); - - - - /* - $date = preg_filter('/^(?[^\t]+)\t(?.+)/', '\2', $matches[0]); - $entry = preg_filter('/^(?[^\t]+)\t(?.+)/', '\1', $matches[0]); - - foreach ($date as $i => $tw) { - $post[$tw] = $entry[$i]; - } - - $post = array_reverse($post); - $perpage = 10; - - if(isset($_GET['start'])) $start = $_GET['start']; else $start = 0; - - $numposts = count($post); - $post = array_slice($post, $start, $perpage); - - echo "
"; - foreach ($post as $tw => $data) { - echo $tw; - echo "
"; - } - */ - } - } -} \ No newline at end of file diff --git a/partials/profile.php b/partials/profile.php index d3fa7b0..aa3759b 100644 --- a/partials/profile.php +++ b/partials/profile.php @@ -8,37 +8,74 @@ if (!empty($_GET['profile'])) { $profile = getTwtsFromTwtxtString($url); $profileURL = $baseURL . '/?profile=' . $profile->mainURL; $textareaValue = "@<$profile->nick $profile->mainURL> "; + +// TODO: Move this to twtxt.php or base.php +// and make nav for general timeline to filter on posts vs. replies + all + +// Filter posts vs. replies +$pattern = "/\(#\w{7}\)/"; + +$twt_replies = array_filter($twts, function ($twt) use ($pattern) { + return preg_match($pattern, $twt->originalTwtStr); +}); + +$twt_posts = array_filter($twts, function ($twt) use ($pattern) { + return !preg_match($pattern, $twt->originalTwtStr); +}); + +// 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) { + $posts_active = ""; + $replies_active = ""; + $gallery_artive = "class='active'"; +} elseif ($is_replies) { + $twts = $twt_replies; + $posts_active = ""; + $replies_active = "class='active'"; + $gallery_artive = ""; +} else { + $twts = $twt_posts; + $posts_active = "class='active'"; + $replies_active = ""; + $gallery_artive = ""; +} + ?>
- + diff --git a/partials/search.php b/partials/search.php new file mode 100644 index 0000000..7029d74 --- /dev/null +++ b/partials/search.php @@ -0,0 +1,15 @@ +content); + }); +} diff --git a/partials/tag_cloud.php b/partials/tag_cloud.php index 1b2c0e2..78cf387 100644 --- a/partials/tag_cloud.php +++ b/partials/tag_cloud.php @@ -3,63 +3,75 @@ // Tagcloud for twtxt // Base on code from: https://social.dfaria.eu/search -// if(empty($_GET['search'])) { +// Add all tags to one array +foreach ($twts as $twt) { + $tag_array = getTagsFromTwt($twt->content); - // Add all tags to one array - foreach ($twts as $twt) { - $tag_array = getTagsFromTwt($twt->content); + foreach ($tag_array as $tag) { + $tags[] = $tag[0]; + } +} - foreach ($tag_array as $tag) { - $tags[] = $tag[0]; - } +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 ($tag === $active_tag) { + echo '#'. $tag .' '; + } else { + echo '#'. $tag .' '; } + //echo '#'. $tag .' ('.$count.') '; +} - natcasesort($tags); - $tag_count = array_count_values($tags); - //arsort($tag_count, SORT_STRING); - //ksort($tag_count, SORT_STRING); - //strnatcasecmp($tag_count); +// Detail/summary with top tags and solo tags - $max_count = max($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); - $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); +echo "
Tags: "; - $uri = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; +foreach ($top_tags as $tag => $count) { + $tag = str_replace('#', '', $tag); + echo '#'.$tag.' '; +} - foreach ($tag_count as $tag => $count) { - $font_size = $min_font_size + ($count / $max_count) * $font_size_interval; - $tag = str_replace('#', '', $tag); - echo '#'. $tag .' '; - //echo '#'. $tag .' ('.$count.') '; - } +echo ""; - // Detail/summary with top tags and solo tags +foreach ($solo_tags as $tag => $count) { + $tag = str_replace('#', '', $tag); + echo '#'.$tag.' '; +} - /* - $top_tags = array_filter($tag_count, function($val){return ($val>1);}); - $solo_tags = array_diff($tag_count, $top_tags); - krsort($solo_tags, SORT_STRING); +echo "
"; +*/ - echo "
Tags: "; - - foreach ($top_tags as $tag => $count) { - $tag = str_replace('#', '', $tag); - echo '#'.$tag.' '; - } - - echo ""; - - foreach ($solo_tags as $tag => $count) { - $tag = str_replace('#', '', $tag); - echo '#'.$tag.' '; - } - - echo "
"; - */ - -// } else { -// echo "Showing posts with ".$_GET['search'].""; -// } \ No newline at end of file diff --git a/partials/timeline.php b/partials/timeline.php index bdf5fa6..96242de 100644 --- a/partials/timeline.php +++ b/partials/timeline.php @@ -6,23 +6,7 @@ --> -content); - }); -} - -?> +
diff --git a/views/gallery.php b/views/gallery.php index 5c4130c..5393e60 100644 --- a/views/gallery.php +++ b/views/gallery.php @@ -36,6 +36,7 @@ if (!empty($_GET['profile'])) { // Show twts for some user ?> +