]> 91.132.146.200 Git - insipid.git/commitdiff
searching and adding a new URL
authorBanana <banana@optimus.de>
Mon, 19 Dec 2016 11:04:27 +0000 (12:04 +0100)
committerBanana <banana@optimus.de>
Mon, 19 Dec 2016 11:04:27 +0000 (12:04 +0100)
webroot/index.php
webroot/lib/summoner.class.php [new file with mode: 0644]
webroot/view/_foot.html [deleted file]
webroot/view/_foot.php [new file with mode: 0644]
webroot/view/_head.html [deleted file]
webroot/view/_head.php [new file with mode: 0644]
webroot/view/home.html [deleted file]
webroot/view/home.inc.php [new file with mode: 0644]
webroot/view/home.php

index e487ef33d4917f0bff721b2d389956771c4d247d..c8bd963910a9fff12f6b058a5e8d073254630f07 100644 (file)
@@ -54,16 +54,18 @@ else {
 }
 
 require('config.php');
+require('lib/summoner.class.php');
 
 ## main vars
+$Summoner = new Summoner();
 # database object
 $DB = false;
 # the template data as an array
 $TemplateData = array();
 # the default view
-$View = 'home.html';
+$View = 'home.php';
 # the default script
-$ViewScript = 'home.php';
+$ViewScript = 'home.inc.php';
 
 ## DB connection
 mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); # throw exeptions
@@ -95,9 +97,9 @@ if(!empty($TemplateData['refresh'])) {
 # header information
 header('Content-type: text/html; charset=UTF-8');
 
-require 'view/_head.html';
+require 'view/_head.php';
 require 'view/'.$View;
-require 'view/_foot.html';
+require 'view/_foot.php';
 
 $DB->close();
 # END
\ No newline at end of file
diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php
new file mode 100644 (file)
index 0000000..ce66c6d
--- /dev/null
@@ -0,0 +1,225 @@
+<?php
+/**
+ * Insipid
+ * Personal web-bookmark-system
+ *
+ * Copyright 2016-2017 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.
+ *
+ */
+
+/**
+ * a static helper class
+ */
+
+class Summoner {
+
+       /**
+        * validate the given string with the given type. Optional check the string
+        * length
+        *
+        * @param string $input The string to check
+        * @param string $mode How the string should be checked
+        * @param mixed $limit If int given the string is checked for length
+        *
+        * @see http://de.php.net/manual/en/regexp.reference.unicode.php
+        * http://www.sql-und-xml.de/unicode-database/#pc
+        *
+        * the pattern replaces all that is allowed. the correct result after
+        * the replace should be empty, otherwise are there chars which are not
+        * allowed
+        *
+        */
+       static function validate($input,$mode='text',$limit=false) {
+               // check if we have input
+               $input = trim($input);
+
+               if($input == "") return false;
+
+               $ret = false;
+
+               switch ($mode) {
+                       case 'mail':
+                           if(filter_var($input,FILTER_VALIDATE_EMAIL) === $input) {
+                               return true;
+                           }
+                else {
+                    return false;
+                           }
+                       break;
+
+                       case 'rights':
+                               return self::isRightsString($input);
+                       break;
+
+                       case 'url':
+                               if(filter_var($input,FILTER_VALIDATE_URL) === $input) {
+                                       return true;
+                               }
+                               else {
+                                       return false;
+                               }
+                       break;
+
+                       case 'nospace':
+                               // text without any whitespace and special chars
+                               $pattern = '/[\p{L}\p{N}]/u';
+                       break;
+
+                       case 'nospaceP':
+                               // text without any whitespace and special chars
+                               // but with Punctuation other
+                               # http://www.sql-und-xml.de/unicode-database/po.html
+                               $pattern = '/[\p{L}\p{N}\p{Po}\-]/u';
+                       break;
+
+                       case 'digit':
+                               // only numbers and digit
+                               // warning with negative numbers...
+                               $pattern = '/[\p{N}\-]/';
+                       break;
+
+                       case 'pageTitle':
+                               // text with whitespace and without special chars
+                               // but with Punctuation
+                               $pattern = '/[\p{L}\p{N}\p{Po}\p{Z}\s-]/u';
+                       break;
+
+                       # strange. the \p{M} is needed.. don't know why..
+                       case 'filename':
+                               $pattern = '/[\p{L}\p{N}\p{M}\-_\.\p{Zs}]/u';
+                       break;
+
+                       case 'text':
+                       default:
+                               $pattern = '/[\p{L}\p{N}\p{P}\p{S}\p{Z}\p{M}\s]/u';
+               }
+
+               $value = preg_replace($pattern, '', $input);
+
+               #if($input === $value) {
+               if($value === "") {
+                       $ret = true;
+               }
+
+               if(!empty($limit)) {
+                       # isset starts with 0
+                       if(isset($input[$limit])) {
+                               # too long
+                               $ret = false;
+                       }
+               }
+
+               return $ret;
+       }
+
+       /**
+        * return if the given string is utf8
+        * http://php.net/manual/en/function.mb-detect-encoding.php
+        *
+        * @param string $string
+        * @return number
+        */
+       static function is_utf8 ( $string ) {
+          // From http://w3.org/International/questions/qa-forms-utf-8.html
+          return preg_match('%^(?:
+                [\x09\x0A\x0D\x20-\x7E]            # ASCII
+              | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
+              |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
+              | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
+              |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
+              |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
+              | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
+              |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
+          )*$%xs', $string);
+       }
+
+       /**
+        * execute a curl call to the fiven $url
+        * @param string $curl The request url
+        */
+       static function curlCall($url,$port=80) {
+               $ret = false;
+
+               $ch = curl_init();
+
+               curl_setopt($ch, CURLOPT_URL, $url);
+               curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+               curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
+               curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+               curl_setopt($ch, CURLOPT_PORT, $port);
+
+               $do = curl_exec($ch);
+               if(is_string($do) === true) {
+                       $ret = $do;
+               }
+               else {
+                       $ret = false;
+               }
+
+               curl_close($ch);
+
+               return $ret;
+       }
+
+       /**
+        * check if a string strts with a given string
+        *
+        * @param string $haystack
+        * @param string $needle
+        * @return boolean
+        */
+       static function startsWith($haystack, $needle) {
+               $length = strlen($needle);
+               return (substr($haystack, 0, $length) === $needle);
+       }
+
+       /**
+        * check if a string ends with a given string
+        *
+        * @param string $haystack
+        * @param string $needle
+        * @return boolean
+        */
+       static function endsWith($haystack, $needle) {
+               $length = strlen($needle);
+               if ($length == 0) {
+                       return true;
+               }
+
+               return (substr($haystack, -$length) === $needle);
+       }
+
+
+       /**
+        * simulate the Null coalescing operator in php5
+        *
+        * this only works with arrays and checking if the key is there and echo/return it.
+        *
+        * http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
+        */
+
+       static function ifset($array,$key) {
+           return isset($array[$key]) ? $array[$key] : false;
+       }
+}
+
+?>
diff --git a/webroot/view/_foot.html b/webroot/view/_foot.html
deleted file mode 100644 (file)
index 416c434..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-       <section>
-               <div class="row expanded">
-                       <div class="large-12 columns">
-                               <div class="callout">
-                                       &copy; <?php echo date('Y'); ?> <a href="https://www.bananas-playground.net/projekt/insipid/" target="_blank">Insipid</a>
-                               </div>
-                       </div>
-               </div>
-       </section>
-       
-       <script src="asset/js/jquery.js"></script>
-    <script src="asset/js/what-input.js"></script>
-    <script src="asset/js/foundation.min.js"></script>
-    <script src="asset/js/app.js"></script>
-  </body>
-</html>
diff --git a/webroot/view/_foot.php b/webroot/view/_foot.php
new file mode 100644 (file)
index 0000000..d429468
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Insipid
+ * Personal web-bookmark-system
+ *
+ * Copyright 2016-2017 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>
+               <div class="row expanded">
+                       <div class="large-12 columns">
+                               <div class="callout">
+                                       &copy; <?php echo date('Y'); ?> <a href="https://www.bananas-playground.net/projekt/insipid/" target="_blank">Insipid</a>
+                               </div>
+                       </div>
+               </div>
+       </section>
+
+       <script src="asset/js/jquery.js"></script>
+    <script src="asset/js/what-input.js"></script>
+    <script src="asset/js/foundation.min.js"></script>
+    <script src="asset/js/app.js"></script>
+  </body>
+</html>
diff --git a/webroot/view/_head.html b/webroot/view/_head.html
deleted file mode 100644 (file)
index 1421536..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<!doctype html>
-<html class="no-js" lang="en" dir="ltr">
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="x-ua-compatible" content="ie=edge">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Foundation for Sites</title>
-    <link rel="stylesheet" href="asset/css/foundation.min.css">
-    <link rel="stylesheet" href="asset/foundation-icons/foundation-icons.css">
-    <link rel="stylesheet" href="asset/css/app.css">
-  </head>
-  <body>
\ No newline at end of file
diff --git a/webroot/view/_head.php b/webroot/view/_head.php
new file mode 100644 (file)
index 0000000..3b67ef6
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Insipid
+ * Personal web-bookmark-system
+ *
+ * Copyright 2016-2017 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.
+ *
+ */
+?>
+<!doctype html>
+<html class="no-js" lang="en" dir="ltr">
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="x-ua-compatible" content="ie=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Insipid</title>
+    <link rel="stylesheet" href="asset/css/foundation.min.css">
+    <link rel="stylesheet" href="asset/foundation-icons/foundation-icons.css">
+    <link rel="stylesheet" href="asset/css/app.css">
+  </head>
+  <body>
\ No newline at end of file
diff --git a/webroot/view/home.html b/webroot/view/home.html
deleted file mode 100644 (file)
index 4deb75e..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<div class="row">
-       <div class="large-12 columns">
-               <h1>Welcome to your Inspid installation</h1>
-       </div>
-</div>
-
-<div class="row">
-       <div class="large-12 columns">
-               <form>
-               <div class="input-group">
-                       <span class="input-group-label"><i class="fi-link"></i></span>
-                       <input class="input-group-field" type="url">
-                       <div class="input-group-button">
-                               <input type="submit" class="button" value="Search">
-                       </div>
-               </div>
-       </form>
-    </div>
-</div>  
-    
\ No newline at end of file
diff --git a/webroot/view/home.inc.php b/webroot/view/home.inc.php
new file mode 100644 (file)
index 0000000..3f63929
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Insipid
+ * Personal web-bookmark-system
+ *
+ * Copyright 2016-2017 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.
+ *
+ */
+
+$searchValue = false;
+$isUrl = false;
+$submitFeedback = false;
+$queryStr = false;
+$searchResult = false;
+$showAddForm = false;
+$formData = false;
+
+if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['submitsearch'])) {
+    $searchValue = trim($_POST['data']['searchfield']);
+    $isUrl = Summoner::validate($searchValue,'url');
+    if($isUrl === true) {
+        # search for URL
+        $queryStr = "SELECT * FROM";
+    }
+    elseif(Summoner::validate($searchValue,'text')) {
+        # search for this in more then one field
+
+    }
+    else {
+        $submitFeedback['message'] = 'Invalid input';
+        $submitFeedback['status'] = 'error';
+    }
+
+    if(!empty($queryStr)) {
+    }
+
+    # new one?
+    if(empty($searchResult) && $isUrl === true) {
+        # show the add form
+        $showAddForm = true;
+        $formData['url'] = $searchValue;
+    }
+}
\ No newline at end of file
index 24374fc29e474aa70205926616408a99cea63fe2..be4fbd16d05eddf0e2ec6555b466e3b32a06eb66 100644 (file)
  * 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.
  *
- */
\ No newline at end of file
+ */
+ ?>
+<div class="row">
+       <div class="large-12 columns">
+               <h1 class="text-center">Welcome to your Inspid installation</h1>
+       </div>
+</div>
+
+<div class="row">
+       <div class="large-12 columns">
+               <form method="post">
+               <div class="input-group">
+                       <span class="input-group-label"><i class="fi-link"></i></span>
+                       <input class="input-group-field" type="url" name="data[searchfield]">
+                       <div class="input-group-button">
+                               <input type="submit" class="button" value="Search" name="submitsearch">
+                       </div>
+               </div>
+       </form>
+    </div>
+</div>
+
+<?php if(!empty($submitFeedback)) { ?>
+<div class="row">
+       <div class="large-12 columns">
+<?php if($submitFeedback['status'] == "error") { ?>
+               <div class="callout alert">
+                       <h5>Error</h5>
+                       <p><?php echo $submitFeedback['message']; ?></p>
+               </div>
+<?php } else { ?>
+               <div class="callout success">
+                       <h5>Success</h5>
+                       <p><?php echo $submitFeedback['message']; ?></p>
+               </div>
+<?php } ?>
+       </div>
+</div>
+<?php } ?>
+
+<?php if($showAddForm) { ?>
+<form method="post">
+       <div class="row">
+       <div class="large-12 columns">
+               <h3>This URL was not found. Want to add it?</h3>
+       </div>
+    </div>
+    <div class="row">
+       <div class="large-12 columns">
+               <label>
+                       New URL
+                       <input type="url" name="data[url]" value="<?php echo Summoner::ifset($formData, 'url'); ?>" />
+               </label>
+        </div>
+    </div>
+    <div class="row">
+       <div class="large-6 columns">
+               <label>
+                       Username
+                       <input type="text" name="data[username]" />
+               </label>
+       </div>
+       <div class="large-6 columns">
+               <label>
+                       Password
+                       <input type="password" name="data[password]" />
+               </label>
+       </div>
+    </div>
+
+    <div class="row">
+       <div class="large-6 columns">
+               <label>
+                       Category
+                       <select name="data[category]"></select>
+               </label>
+       </div>
+       <div class="large-6 columns">
+               <label>
+                       Tag
+                       <select name="data[tag]"></select>
+               </label>
+       </div>
+    </div>
+
+    <div class="row">
+       <div class="large-12 columns">
+               <input type="submit" class="button" value="Add new Link">
+       </div>
+    </div>
+</form>
+<?php } ?>
+
+<div class="row expanded small-up-3 medium-up-6">
+       <div class="column">
+               <div class="card">
+                       <div class="card-divider">
+                       <h4>Last added</h4>
+                       </div>
+                       <img src="assets/img/generic/rectangle-1.jpg">
+                       <div class="card-section">
+                               <p>It has an easy to override visual style, and is appropriately subdued.</p>
+                               <a class="button" href="#">I'm a button</a>
+                       </div>
+               </div>
+       </div>
+  <div class="column">
+    <div class="card">
+      <img src="assets/img/generic/rectangle-1.jpg">
+      <div class="card-section">
+        <h4>This is a card.</h4>
+        <p>It has an easy to override visual style, and is appropriately subdued.</p>
+      </div>
+    </div>
+  </div>
+  <div class="column">
+    <div class="card">
+      <img src="assets/img/generic/rectangle-1.jpg">
+      <div class="card-section">
+        <h4>This is a card.</h4>
+        <p>It has an easy to override visual style, and is appropriately subdued.</p>
+      </div>
+    </div>
+  </div>
+  <div class="column">
+    <div class="card">
+      <img src="assets/img/generic/rectangle-1.jpg">
+      <div class="card-section">
+        <h4>This is a card.</h4>
+        <p>It has an easy to override visual style, and is appropriately subdued.</p>
+      </div>
+    </div>
+  </div>
+  <div class="column">
+    <div class="card">
+      <img src="assets/img/generic/rectangle-1.jpg">
+      <div class="card-section">
+        <h4>This is a card.</h4>
+        <p>It has an easy to override visual style, and is appropriately subdued.</p>
+      </div>
+    </div>
+  </div>
+  <div class="column">
+    <div class="card">
+      <img src="assets/img/generic/rectangle-1.jpg">
+      <div class="card-section">
+        <h4>This is a card.</h4>
+        <p>It has an easy to override visual style, and is appropriately subdued.</p>
+      </div>
+    </div>
+  </div>
+</div>