mirror of
https://github.com/sorenpeter/timeline.git
synced 2026-03-11 12:42:17 +00:00
fallback nick and url if not set in txt
This commit is contained in:
parent
ccf39b7c91
commit
2b553bceb9
5 changed files with 81 additions and 54 deletions
|
|
@ -144,7 +144,7 @@ a.author {
|
||||||
|
|
||||||
.profile {
|
.profile {
|
||||||
padding: 0 1rem;
|
padding: 0 1rem;
|
||||||
margin-bottom: 2rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-grid {
|
.profile-grid {
|
||||||
|
|
|
||||||
|
|
@ -334,6 +334,7 @@ function getTwtsFromTwtxtString($url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_starts_with($currentLine, '#')) {
|
if (str_starts_with($currentLine, '#')) {
|
||||||
|
|
||||||
// Check if comments (starting with #) have some metadata
|
// Check if comments (starting with #) have some metadata
|
||||||
if (!is_null(getSingleParameter('url', $currentLine))) {
|
if (!is_null(getSingleParameter('url', $currentLine))) {
|
||||||
$currentURL = 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, '#')) {
|
if (!str_starts_with($currentLine, '#')) {
|
||||||
$explodedLine = explode("\t", $currentLine);
|
$explodedLine = explode("\t", $currentLine);
|
||||||
if (count($explodedLine) >= 2) {
|
if (count($explodedLine) >= 2) {
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,19 @@ $twt_posts = array_filter($twts, function ($twt) use ($pattern) {
|
||||||
return !preg_match($pattern, $twt->originalTwtStr);
|
return !preg_match($pattern, $twt->originalTwtStr);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$twt_gallery = array_filter($twts, function ($twt) {
|
||||||
|
return preg_match('/!\[(.*?)\]\((.*?)\)/', $twt->originalTwtStr);
|
||||||
|
//return preg_match('/(<img[^>]+>)/i', $twt->content);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get active view/filter
|
// Get active view/filter
|
||||||
$is_gallery = str_contains(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), "gallery");
|
$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");
|
$is_replies = str_contains(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), "replies");
|
||||||
|
|
||||||
if ($is_gallery) {
|
if ($is_gallery) {
|
||||||
|
//$twts = $twt_gallery;
|
||||||
$posts_active = "";
|
$posts_active = "";
|
||||||
$replies_active = "";
|
$replies_active = "";
|
||||||
$gallery_artive = "class='active'";
|
$gallery_artive = "class='active'";
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ if (!empty($_GET['search'])) {
|
||||||
$pattern = preg_quote($search, '/');
|
$pattern = preg_quote($search, '/');
|
||||||
$pattern = "/^.*$pattern.*\$/mi";
|
$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) {
|
$twts = array_filter($twts, function ($twt) use ($pattern) {
|
||||||
return preg_match($pattern, $twt->content);
|
return preg_match($pattern, $twt->content);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
// Base on code from: https://social.dfaria.eu/search
|
// Base on code from: https://social.dfaria.eu/search
|
||||||
|
|
||||||
// Add all tags to one array
|
// Add all tags to one array
|
||||||
|
$tags = [];
|
||||||
|
|
||||||
foreach ($twts as $twt) {
|
foreach ($twts as $twt) {
|
||||||
$tag_array = getTagsFromTwt($twt->content);
|
$tag_array = getTagsFromTwt($twt->content);
|
||||||
|
|
||||||
|
|
@ -12,66 +14,69 @@ foreach ($twts as $twt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
natcasesort($tags);
|
if(!empty($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) {
|
natcasesort($tags);
|
||||||
echo '<a href="'.$uri.'&search='.$tag.'" style="font-size: '.$font_size.'px;" class="active">#'. $tag .'</a> ';
|
$tag_count = array_count_values($tags);
|
||||||
} else {
|
//arsort($tag_count, SORT_STRING);
|
||||||
echo '<a href="'.$uri.'&search='.$tag.'" style="font-size: '.$font_size.'px;">#'. $tag .'</a> ';
|
//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 '<a href="?search='.$tag.'">#'. $tag .' ('.$count.')</a> ';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 '<a href="'.$uri.'&search='.$tag.'" style="font-size: '.$font_size.'px;" class="active">#'. $tag .'</a> ';
|
||||||
|
} else {
|
||||||
|
echo '<a href="'.$uri.'&search='.$tag.'" style="font-size: '.$font_size.'px;">#'. $tag .'</a> ';
|
||||||
|
}
|
||||||
|
//echo '<a href="?search='.$tag.'">#'. $tag .' ('.$count.')</a> ';
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
// 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 "<details><summary> 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) {
|
echo "<details><summary> Tags: ";
|
||||||
$tag = str_replace('#', '', $tag);
|
|
||||||
echo '<a href="?search='.$tag.'">#'.$tag.'</a> ';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "</summary>";
|
foreach ($top_tags as $tag => $count) {
|
||||||
|
$tag = str_replace('#', '', $tag);
|
||||||
|
echo '<a href="?search='.$tag.'">#'.$tag.'</a> ';
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($solo_tags as $tag => $count) {
|
echo "</summary>";
|
||||||
$tag = str_replace('#', '', $tag);
|
|
||||||
echo '<a href="?search='.$tag.'">#'.$tag.'</a> ';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "</details>";
|
foreach ($solo_tags as $tag => $count) {
|
||||||
*/
|
$tag = str_replace('#', '', $tag);
|
||||||
|
echo '<a href="?search='.$tag.'">#'.$tag.'</a> ';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</details>";
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue