]> 91.132.146.200 Git - aranea.git/commitdiff
adding individual views
authorBanana <mail@bananas-playground.net>
Sun, 13 Oct 2024 08:34:58 +0000 (10:34 +0200)
committerBanana <mail@bananas-playground.net>
Sun, 13 Oct 2024 08:34:58 +0000 (10:34 +0200)
Signed-off-by: Banana <mail@bananas-playground.net>
webroot/index.php
webroot/lib/base.class.php
webroot/lib/domains.class.php
webroot/lib/management.class.php [new file with mode: 0644]
webroot/view/domains/domains.inc.php [new file with mode: 0644]
webroot/view/domains/domains.php [new file with mode: 0644]
webroot/view/home/home.inc.php
webroot/view/home/home.php
webroot/view/system/menu.php

index 3ffa7ccc2fd600b288dd08efa7d57a532db76d6e..d556a99129a3da4473d129846dc8533476e3f129 100644 (file)
@@ -51,8 +51,8 @@ $ViewMessage = 'view/system/message.php';
 # the menu
 $ViewMenu = 'system/menu.php';
 # valid includes
-$_validPages["about"] = "about";
-
+$_validPages["domains"] = "domains";
+$_validPages["urls"] = "urls";
 
 $_requestMode = "home";
 if(isset($_GET['p']) && !empty($_GET['p'])) {
index aeb998f7ba881677b409a3ccd4d19d388aea6e95..f1fdcaec165796af1190cd3f28c7a7b7ff5ed4d3 100644 (file)
@@ -35,6 +35,14 @@ abstract class Base {
      */
     protected array $_queryOptions;
 
+    /**
+     * The available sort columns.
+     * Used in query and sort options in FE
+     *
+     * @var array|array[]
+     */
+    protected array $_sortOptions = array();
+
     /**
      * Set the following options which can be used in DB queries
      * array(
@@ -46,7 +54,7 @@ abstract class Base {
      *
      * @param array $options
      */
-    protected function setQueryOptions(array $options): void {
+    public function setQueryOptions(array $options): void {
 
         if(!isset($options['limit'])) $options['limit'] = 20;
         if(!isset($options['offset'])) $options['offset'] = false;
@@ -69,6 +77,15 @@ abstract class Base {
         $this->_queryOptions = $options;
     }
 
+    /**
+     * Return the available sort options and the active used one
+     *
+     * @return array|array[]
+     */
+    public function getSortOptions(): array {
+        return $this->_sortOptions;
+    }
+
     /**
      * set some defaults by init of the class
      *
index c551875c00d26bacab5b304c5975a6df2f2c9eb7..003cd9367188344dbcca5cb50989f156b868b719 100644 (file)
@@ -24,6 +24,17 @@ require_once 'lib/base.class.php';
 
 class Domains extends Base {
 
+    /**
+     * The available sort columns.
+     * Used in query and sort options in FE
+     *
+     * @var array|array[]
+     */
+    public array $_sortOptions = array(
+        'default' => array('col' => 'd.url', 'displayText' => 'URL (default)'),
+        'created' => array('col' => 'd.created', 'displayText' => 'Created')
+    );
+
     /**
      * Domains constructor.
      *
diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php
new file mode 100644 (file)
index 0000000..aef1cca
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * 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.
+ *
+ * 2022 - 2024 https://www.bananas-playground.net/projekt/aranea
+ */
+
+ /**
+  * Management class.
+  * Handles general stuff.
+  */
+
+class Management {
+    /**
+     * the database object
+     *
+     * @var mysqli
+     */
+    protected mysqli $_DB;
+
+    /**
+     * Management constructor.
+     *
+     * @param mysqli $databaseConnectionObject
+     */
+    public function __construct(mysqli $databaseConnectionObject) {
+        $this->_DB = $databaseConnectionObject;
+    }
+
+    /**
+     * Return the data from the stats table
+     *
+     * @return array
+     */
+    public function stats(): array {
+        $ret = array();
+
+        $queryStr = "SELECT `action`, `value`
+                        FROM `stats`
+                        ORDER BY `action` ASC";
+        if(QUERY_DEBUG) Helper::sysLog("[QUERY] ".__METHOD__." query: ".Helper::cleanForLog($queryStr));
+
+        try {
+            $query = $this->_DB->query($queryStr);
+
+            if($query !== false && $query->num_rows > 0) {
+                while(($result = $query->fetch_assoc()) != false) {
+                    $ret[] = $result;
+                }
+            }
+        }
+        catch (Exception $e) {
+            Helper::sysLog("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
+        }
+
+        return $ret;
+    }
+}
diff --git a/webroot/view/domains/domains.inc.php b/webroot/view/domains/domains.inc.php
new file mode 100644 (file)
index 0000000..9941539
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/**
+ * 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.
+ *
+ * 2022 - 2024 https://www.bananas-playground.net/projekt/aranea
+ */
+
+$TemplateData['pageTitle'] = 'Domains';
+
+require_once 'lib/domains.class.php';
+$Domains = new Domains($DB);
+
+# pagination
+$TemplateData['pagination'] = array('pages' => 0, 'currentGetParameters' => array('p' => 'domains'));
+
+$_curPage = 1;
+if(isset($_GET['page']) && !empty($_GET['page'])) {
+    $_curPage = trim($_GET['page']);
+    $_curPage = Helper::validate($_curPage,'digit') ? $_curPage : 1;
+}
+
+$_sort = 'default';
+if(isset($_GET['s']) && !empty($_GET['s'])) {
+    $_sort = trim($_GET['s']);
+    $_sort = Helper::validate($_sort,'nospace') ? $_sort : 'default';
+}
+
+$_sortDirection = '';
+if(isset($_GET['sd']) && !empty($_GET['sd'])) {
+    $_sortDirection = trim($_GET['sd']);
+    $_sortDirection = Helper::validate($_sortDirection,'nospace') ? $_sortDirection : '';
+}
+
+$_rpp = RESULTS_PER_PAGE;
+if(isset($_GET['rpp']) && !empty($_GET['rpp'])) {
+    $_rpp = trim($_GET['rpp']);
+    $_rpp = Helper::validate($_rpp,'digit') ? $_rpp : RESULTS_PER_PAGE;
+}
+
+$queryOptions = array(
+    'limit' => $_rpp,
+    'offset' => ($_rpp * ($_curPage-1)),
+    'sort' => $_sort,
+    'sortDirection' => $_sortDirection
+);
+## pagination end
+
+
+
+## pagination
+if(!empty($TemplateData['searchresults']['amount'])) {
+    $TemplateData['pagination']['pages'] = (int)ceil($TemplateData['searchresults']['amount'] / $_rpp);
+    $TemplateData['pagination']['curPage'] = $_curPage;
+
+    $TemplateData['pagination']['currentGetParameters']['page'] = $_curPage;
+    $TemplateData['pagination']['currentGetParameters']['s'] = $_sort;
+    $TemplateData['pagination']['currentGetParameters']['sd'] = $_sortDirection;
+    $TemplateData['pagination']['currentGetParameters']['rpp'] = $_rpp;
+    $TemplateData['pagination']['sortOptions'] = $Domains->getSortOptions();
+}
+
+if($TemplateData['pagination']['pages'] > 11) {
+    # first pages
+    $TemplateData['pagination']['visibleRange'] = range(1,3);
+    # last pages
+    foreach(range($TemplateData['pagination']['pages']-2, $TemplateData['pagination']['pages']) as $e) {
+        $TemplateData['pagination']['visibleRange'][] = $e;
+    }
+    # pages before and after current page
+    $cRange = range($TemplateData['pagination']['curPage']-1, $TemplateData['pagination']['curPage']+1);
+    foreach($cRange as $e) {
+        $TemplateData['pagination']['visibleRange'][] = $e;
+    }
+    $TemplateData['pagination']['currentRangeStart'] = array_shift($cRange);
+    $TemplateData['pagination']['currentRangeEnd'] = array_pop($cRange);
+}
+else {
+    $TemplateData['pagination']['visibleRange'] = range(1,$TemplateData['pagination']['pages']);
+}
+## pagination end
diff --git a/webroot/view/domains/domains.php b/webroot/view/domains/domains.php
new file mode 100644 (file)
index 0000000..d3af84a
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * 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.
+ *
+ * 2022 - 2024 https://www.bananas-playground.net/projekt/aranea
+ */
+?>
+<h1>Domains</h1>
index e82abee2e877e355a04784a1dab64b5b3e634a3d..aef0373937e4f1bdf7951f7c23b6d0f59def173d 100644 (file)
@@ -24,5 +24,9 @@ $Domains = new Domains($DB);
 require_once 'lib/urls.class.php';
 $Urls = new Urls($DB);
 
+require_once 'lib/management.class.php';
+$Management = new Management($DB);
+
 $TemplateData['latestDomains'] = $Domains->latest();
 $TemplateData['latestUrls'] = $Urls->latest();
+$TemplateData['stats'] = $Management->stats();
index ada549940ffd2df3fde9fce6477f3aabf8c63db3..b69e5cf4d8453b0208ecc8dadf8244c45c051545 100644 (file)
@@ -19,7 +19,7 @@
 <h1>Home</h1>
 
 <div class="uk-grid uk-child-width-1-1 uk-child-width-1-2@m uk-child-width-1-3@l">
-    <div>
+       <div class="uk-overflow-auto">
         <h3>Latest Domains</h3>
         <table class="uk-table uk-table-striped">
             <thead>
@@ -42,7 +42,7 @@
             </tbody>
         </table>
     </div>
-    <div>
+    <div class="uk-overflow-auto">
         <h3>Latest URLs</h3>
         <table class="uk-table uk-table-striped">
             <thead>
@@ -65,7 +65,7 @@
             </tbody>
         </table>
     </div>
-       <div>
+       <div class="uk-overflow-auto">
                <h3>Info</h3>
                <table class="uk-table uk-table-striped">
                        <thead>
                        </thead>
                        <tbody>
             <?php
-            if(!empty($TemplateData['latestUrls'])) {
-                foreach($TemplateData['latestUrls'] as $k=>$value) {
+            if(!empty($TemplateData['stats'])) {
+                foreach($TemplateData['stats'] as $k=>$value) {
                     ?>
                                        <tr>
-                                               <td><?php echo $value['url']; ?></a></td>
+                                               <td><?php echo $value['action']; ?></a></td>
+                                               <td><?php echo $value['value']; ?></a></td>
                                        </tr>
                     <?php
                 }
index e6ecffe8a4f92178b7560544fa57173e6e35c000..602dbda7ad80df58dfa112bcdf56972c360ef766 100644 (file)
  *
  * 2022 - 2024 https://www.bananas-playground.net/projekt/aranea
  */
+?>
+<nav class="uk-navbar-container">
+    <div class="uk-container">
+        <div class="uk-navbar">
+            <div class="uk-navbar-left">
+                <ul class="uk-navbar-nav">
+                    <li>
+                        <a class="uk-navbar-item uk-logo" href="index.php" aria-label="Back to Home">&#128375;</a>
+                    </li>
+                    <li class="<?php if($_requestMode == "domains") echo 'uk-active'; ?>">
+                        <a href="index.php?p=packages">Domains</a>
+                    </li>
+                    <li class="<?php if($_requestMode == "urls") echo 'uk-active'; ?>">
+                        <a href="index.php?p=categories">URLs</a>
+                    </li>
+                    <li class="<?php if($_requestMode == "stats") echo 'uk-active'; ?>">
+                        <a href="index.php?p=stats">Stats</a>
+                    </li>
+                </ul>
+            </div>
+        </div>
+    </div>
+</nav>