]> 91.132.146.200 Git - insipid.git/commitdiff
added random page
authorBanana <mail@bananas-playground.net>
Sat, 8 Jan 2022 09:59:00 +0000 (10:59 +0100)
committerBanana <mail@bananas-playground.net>
Sat, 8 Jan 2022 09:59:00 +0000 (10:59 +0100)
ChangeLog
TODO
webroot/lib/lang/eng.lang.ini
webroot/lib/lang/ger.lang.ini
webroot/lib/management.class.php
webroot/view/_headNavIcons.inc.php
webroot/view/random.inc.php [new file with mode: 0644]
webroot/view/random.php [new file with mode: 0644]

index fbed0cda917f7c80316b3cda2a73d671f40a616e..848e26f2485a27dd95fbda6b33403f9729b86226 100644 (file)
--- 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 e242914cece491e60fd825f73289b3d6339268c0..a2360a00387a4228f993a5a97ef4697d8d1420b3 100644 (file)
--- 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
index 90723f5225b9cb1349c5d6cdbf107c79ebaeb9ee..ef295b0c1a90283cc54b88b0a66f58a03b9c2450 100644 (file)
@@ -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"
index 3c63e280920968bdbce00c67a5b860569c84c870..4547388f330b93cd7b6f75f8e00169e383cb7b5d 100644 (file)
@@ -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"
index d6189bba503feb2471be5546cb4ec56c18d5bcb9..56ad8ebc05a37a939a72fcbed976d99a21d2350e 100644 (file)
@@ -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
         *
index ad7b0157a1a7dc3648c10d70fde7c408953f824e..5c99b7945affec60e45fd66596c37caa84a3934c 100644 (file)
@@ -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 @@
                <a href="index.php" title="<?php echo $T->t('view.nav.back.home'); ?>" class="button">
                        <span class="icon"><i class="ion-md-home"></i></span>
                </a>
+               <a href="index.php?p=random" title="<?php echo $T->t('view.nav.random'); ?>" class="button">
+                       <span class="icon"><i class="ion-md-shuffle"></i><span>
+               </a>
        </p>
 </div>
diff --git a/webroot/view/random.inc.php b/webroot/view/random.inc.php
new file mode 100644 (file)
index 0000000..149f6c3
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Insipid
+ * Personal web-bookmark-system
+ *
+ * Copyright 2016-2022 Johannes Keßler
+ *
+ * Development starting from 2011: Johannes Keßler
+ * https://www.bananas-playground.net/projekt/insipid/
+ *
+ * creator:
+ * Luke Reeves <luke@neuro-tech.net>
+ *
+ * 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 (file)
index 0000000..3556118
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+/**
+ * Insipid
+ * Personal web-bookmark-system
+ *
+ * Copyright 2016-2022 Johannes Keßler
+ *
+ * Development starting from 2011: Johannes Keßler
+ * https://www.bananas-playground.net/projekt/insipid/
+ *
+ * creator:
+ * Luke Reeves <luke@neuro-tech.net>
+ *
+ * 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.
+ *
+ */
+?>
+<section class="section">
+       <div class="columns">
+               <?php require('_headNavIcons.inc.php'); ?>
+       </div>
+
+       <div class="columns">
+               <div class="column">
+                       <h2 class="is-size-2"><?php echo $T->t('view.random.headline'); ?></h2>
+               </div>
+       </div>
+</section>
+<section class="section">
+       <div class="columns">
+               <div class="column">
+
+                       <h3 class="is-size-3"><?php echo $T->t('view.random.link'); ?></h3>
+                       <div class="field is-grouped is-grouped-multiline">
+                               <?php foreach ($randomLink as $sr) { ?>
+                                       <div class="control">
+                                               <div class="tags has-addons">
+                                                       <a class="tag is-dark" href="<?php echo $sr['link']; ?>" target="_blank" ><?php echo $sr['title']; ?></a>
+                                                       <a class="tag is-info" title="<?php echo $T->t('view.more.details'); ?>" href="index.php?p=linkinfo&id=<?php echo $sr['hash']; ?>" ><i class="ion-md-information-circle-outline"></i></a>
+                                               </div>
+                                       </div>
+                               <?php } ?>
+                       </div>
+
+                       <h3 class="is-size-3"><?php echo $T->t('view.tag'); ?></h3>
+                       <div>
+                               <?php foreach ($randomTag as $sr) { ?>
+                                       <a href="index.php?p=overview&m=tag&id=<?php echo $sr['id']; ?>"" class="button is-small">
+                                               <span class="icon"><i class="ion-md-pricetag"></i></span>
+                                               <span><?php echo $sr['name']; ?></span>
+                                       </a>
+                               <?php } ?>
+                       </div>
+
+                       <h3 class="is-size-3"><?php echo $T->t('view.category'); ?></h3>
+                       <div>
+                               <?php foreach ($randomCategory as $sr) { ?>
+                                       <a href="index.php?p=overview&m=category&id=<?php echo $sr['id']; ?>"" class="button is-small">
+                                               <span class="icon"><i class="ion-md-filing"></i></span>
+                                               <span><?php echo $sr['name']; ?></span>
+                                       </a>
+                               <?php } ?>
+                       </div>
+
+               </div>
+       </div>
+</section>