diff --git a/libs/timeline.css b/libs/timeline.css index 542afef..a2226fa 100644 --- a/libs/timeline.css +++ b/libs/timeline.css @@ -282,6 +282,24 @@ 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 === */ diff --git a/libs/twtxt.php b/libs/twtxt.php index ddd0e76..0b52cb8 100644 --- a/libs/twtxt.php +++ b/libs/twtxt.php @@ -34,7 +34,8 @@ class Twt { public $emoji; public $nick; public $mainURL; - public $images; + public $images = []; + public $tags = []; } # https://stackoverflow.com/a/39360281/13173382 @@ -118,6 +119,24 @@ function getImagesFromTwt(string $twtString) { return $result; } +function getTagsFromTwt(string $twtString) { + //$pattern = '/(?]+)\s([^>]+)>/'; // Matches "@" preg_match_all($pattern, $twtString, $matches, PREG_SET_ORDER); @@ -187,8 +206,8 @@ function replaceImagesFromTwt(string $twtString) { function replaceTagsFromTwt(string $twtString) { $pattern = '/#(\w+)?/'; - $replacement = '#\1'; // Dummy link - //$replacement = '#${1}'; + //$replacement = '#\1'; // Dummy link + $replacement = '#${1}'; $result = preg_replace($pattern, $replacement, $twtString); return $result; @@ -376,7 +395,7 @@ function getTwtsFromTwtxtString($url) { } // TODO: Make ?tag= filtering feature - //$twtContent = replaceTagsFromTwt($twtContent); + $twtContent = replaceTagsFromTwt($twtContent); // TODO: Get mentions $mentions = getMentionsFromTwt($twtContent); diff --git a/partials/__search.php b/partials/__search.php new file mode 100644 index 0000000..c91b01c --- /dev/null +++ b/partials/__search.php @@ -0,0 +1,67 @@ +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/base.php b/partials/base.php index 69ea709..2016de3 100644 --- a/partials/base.php +++ b/partials/base.php @@ -114,6 +114,23 @@ foreach ($parsedTwtxtFiles as $currentTwtFile) { } } +// Search / filter on tags (or anything within a twt actually) +// Base on hash filter below and on code from: https://social.dfaria.eu/search + +// TODO: Move to after rendering of tag-cloud to get all tags rendered +/* +if (!empty($_GET['search'])) { + $search = $_GET['search']; + + $pattern = preg_quote($search, '/'); + $pattern = "/^.*$pattern.*\$/mi"; + + $twts = array_filter($twts, function ($twt) use ($pattern) { + return preg_match($pattern, $twt->content); + }); +} +*/ + if (!empty($_GET['hash'])) { $hash = $_GET['hash']; $twts = array_filter($twts, function ($twt) use ($hash) { diff --git a/partials/profile.php b/partials/profile.php index e450929..d3fa7b0 100644 --- a/partials/profile.php +++ b/partials/profile.php @@ -30,12 +30,16 @@ $textareaValue = "@<$profile->nick $profile->mainURL> "; - mainURL?> + mainURL?> (How to follow) +
+ +
+ - + \ No newline at end of file diff --git a/partials/tag_cloud.php b/partials/tag_cloud.php new file mode 100644 index 0000000..1b2c0e2 --- /dev/null +++ b/partials/tag_cloud.php @@ -0,0 +1,65 @@ +content); + + 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); + + $uri = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + + 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.') '; + } + + // Detail/summary with top tags and solo 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); + + 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 58796dc..bdf5fa6 100644 --- a/partials/timeline.php +++ b/partials/timeline.php @@ -6,6 +6,24 @@ --> +content); + }); +} + +?> +