From: Banana Date: Sat, 8 Jan 2022 09:59:00 +0000 (+0100) Subject: added random page X-Git-Tag: 2.7_2022-06-12~9 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=57c846885292371796375df533c04a1468ea8c4a;p=insipid.git added random page --- diff --git a/ChangeLog b/ChangeLog index fbed0cd..848e26f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ version 2.7 - Sacred Grove + Adapted some new PHP code formatting + Fixed some translations + Updated bulma css + + Added random link page version 2.6 - Hypostyle (2021-03-21) diff --git a/TODO b/TODO index e242914..a2360a0 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ TODO / Feature list ++ random link or link of the day + view table really still needed? + stats cleanup. Management functions should be standalone + theme support diff --git a/webroot/lib/lang/eng.lang.ini b/webroot/lib/lang/eng.lang.ini index 90723f5..ef295b0 100644 --- a/webroot/lib/lang/eng.lang.ini +++ b/webroot/lib/lang/eng.lang.ini @@ -102,6 +102,8 @@ view.num.links = "# of links" view.edit.tags = "Edit tags" view.edit.categories = "Edit categories" view.links = "Links" +view.random.headline = "Surprise" +view.random.link = "Link" stats.view.all = "View all" stats.moderation = "Moderation" @@ -123,6 +125,7 @@ stats.import.xml.import = "Import" view.nav.all.tags = "Tags" view.nav.all.categories = "Categories" view.nav.back.home = "back home" +view.nav.random = "Random link" stats.storage.clean.fail = "Something went wrong while storage cleaning" stats.import.missing.file = "Please provide a import file" diff --git a/webroot/lib/lang/ger.lang.ini b/webroot/lib/lang/ger.lang.ini index 3c63e28..4547388 100644 --- a/webroot/lib/lang/ger.lang.ini +++ b/webroot/lib/lang/ger.lang.ini @@ -102,6 +102,8 @@ view.num.links = "# der Links" view.edit.tags = "Tags bearbeiten" view.edit.categories = "Kategorien bearbeiten" view.links = "Links" +view.random.headline = "Überraschung" +view.random.link = "Link" stats.view.all = "Alle" stats.moderation = "Moderation" @@ -123,6 +125,7 @@ stats.import.xml.import = "Import" view.nav.all.tags = "Tags" view.nav.all.categories = "Kategorien" view.nav.back.home = "zurück nach Hause" +view.nav.random = "Zufallslink" stats.storage.clean.fail = "Ein Fehler bei der Speicherplatzlöschung trat auf" stats.import.missing.file = "Bitte eine Importdatei angeben" diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index d6189bb..56ad8eb 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -33,19 +33,6 @@ class Management { const LINK_QUERY_STATUS = 2; - const COMBINED_SELECT_VALUES = "`id`, - `link`, - `created`, - `status`, - `description`, - `title`, - `image`, - `hash`, - `tag`, - `category`, - `categoryId`, - `tagId`"; - /** * the database object * @@ -221,6 +208,63 @@ class Management { return $ret; } + /** + * Return a random entry from link table. + * Slow but does the trick for now. If there is way more entries + * re-think this solution + * + * @param int $limit + * @return array + */ + public function randomLink($limit=1): array { + $ret = array(); + + $queryStr = "SELECT `title`, `link`, `hash` FROM `".DB_PREFIX."_link` AS t"; + $queryStr .= " WHERE ".$this->_decideLinkTypeForQuery(); + $queryStr .= " ORDER BY RAND()"; + if(!empty($limit)) { + $queryStr .= " LIMIT $limit"; + } + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows > 0) { + $ret = $query->fetch_all(MYSQLI_ASSOC); + } + + return $ret; + } + + public function randomCategory($limit=1): array { + $ret = array(); + + $queryStr = "SELECT `id`, `name` FROM `".DB_PREFIX."_category`"; + $queryStr .= " ORDER BY RAND()"; + if(!empty($limit)) { + $queryStr .= " LIMIT $limit"; + } + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows > 0) { + $ret = $query->fetch_all(MYSQLI_ASSOC); + } + + return $ret; + } + + public function randomTag($limit=1): array { + $ret = array(); + + $queryStr = "SELECT `id`, `name` FROM `".DB_PREFIX."_tag`"; + $queryStr .= " ORDER BY RAND()"; + if(!empty($limit)) { + $queryStr .= " LIMIT $limit"; + } + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows > 0) { + $ret = $query->fetch_all(MYSQLI_ASSOC); + } + + return $ret; + } + /** * get all the categories ordered by link added date * diff --git a/webroot/view/_headNavIcons.inc.php b/webroot/view/_headNavIcons.inc.php index ad7b015..5c99b79 100644 --- a/webroot/view/_headNavIcons.inc.php +++ b/webroot/view/_headNavIcons.inc.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2021 Johannes Keßler + * Copyright 2016-2022 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -37,5 +37,8 @@ + + +

diff --git a/webroot/view/random.inc.php b/webroot/view/random.inc.php new file mode 100644 index 0000000..149f6c3 --- /dev/null +++ b/webroot/view/random.inc.php @@ -0,0 +1,31 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0. + * + */ + +$randomLink = $Management->randomLink(10); +$randomCategory = $Management->randomCategory(10); +$randomTag = $Management->randomTag(10); diff --git a/webroot/view/random.php b/webroot/view/random.php new file mode 100644 index 0000000..3556118 --- /dev/null +++ b/webroot/view/random.php @@ -0,0 +1,78 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0. + * + */ +?> +
+
+ +
+ +
+
+

t('view.random.headline'); ?>

+
+
+
+
+
+
+ +

t('view.random.link'); ?>

+
+ +
+
+ + +
+
+ +
+ +

t('view.tag'); ?>

+
+ + + + + + +
+ +

t('view.category'); ?>

+
+ + + + + + +
+ +
+
+