summaryrefslogtreecommitdiff
path: root/app/Libraries/Helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Libraries/Helper.php')
-rw-r--r--app/Libraries/Helper.php31
1 files changed, 29 insertions, 2 deletions
diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php
index 311c466..026abef 100644
--- a/app/Libraries/Helper.php
+++ b/app/Libraries/Helper.php
@@ -73,11 +73,38 @@ class Helper {
if ( "mastodon" == $title ) {
$cat_len= 0;
+
if ( ! $post->getCategories()->get()->isEmpty() ) {
- $categories = "#MostDiscussed ";
+
+ $categories_ar = array("#MostDiscussed");
+
foreach( $post->getCategories()->get() as $cat ) {
- $categories .= "#". $cat->name . " ";
+
+ // uppercase for every word in a possible multi worded hashtag
+ $tmp_cat = ucwords($cat->name);
+
+ // strip everything after / for brevity
+ if ( false !== strpos($tmp_cat, "/") )
+ $tmp_cat = substr($tmp_cat, 0, strpos($tmp_cat, "/"));
+
+ // replace any non-alphanumeric character except underscore, because
+ // it's not allowed to be used in a hashtag
+ $tmp_cat = preg_replace("/[^A-Za-z0-9_]/", '', $tmp_cat);
+
+ // trim just in case
+ $tmp_cat = trim($tmp_cat);
+
+ // if it's not empty, add it to the hashtag array
+ if ( "" != $tmp_cat )
+ $categories_ar[] = "#". $tmp_cat;
}
+
+ // remove possible duplicates (because stripping after "/")
+ $categories_ar = array_unique($categories_ar);
+
+ // join to one string
+ $categories = implode(" ", $categories_ar);
+
$cat_counter = $post->getCategories()->get()->count();
$cat_len = mb_strlen($categories, "UTF-8");
}