From: Banana Date: Sat, 3 Nov 2018 22:13:41 +0000 (+0100) Subject: editing and new frontend X-Git-Tag: 2.1-alpha-2019-0-29~23 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=01a5b23c5de46c318b473dd0614ab85b58555430;p=insipid.git editing and new frontend --- diff --git a/TODO b/TODO index 6a97293..e330346 100755 --- a/TODO +++ b/TODO @@ -8,4 +8,5 @@ TODO / Feature list + stats + private links + more "secure" user authentication -++ multiple user accounts and stuff \ No newline at end of file +++ multiple user accounts and stuff ++ sorting \ No newline at end of file diff --git a/source/foundation-6.3.0-custom.zip b/source/foundation-6.3.0-custom.zip deleted file mode 100644 index 14502ac..0000000 Binary files a/source/foundation-6.3.0-custom.zip and /dev/null differ diff --git a/source/foundation-icons.zip b/source/foundation-icons.zip deleted file mode 100644 index 898b2a0..0000000 Binary files a/source/foundation-icons.zip and /dev/null differ diff --git a/source/foundation.info b/source/foundation.info deleted file mode 100644 index 99ee314..0000000 --- a/source/foundation.info +++ /dev/null @@ -1 +0,0 @@ -Foundation with flex grid active diff --git a/webroot/.gitignore b/webroot/.gitignore index 4f4773f..77e477b 100644 --- a/webroot/.gitignore +++ b/webroot/.gitignore @@ -1 +1,2 @@ config.php +error.log diff --git a/webroot/lib/category.class.php b/webroot/lib/category.class.php index a8f44dd..be4b5ad 100644 --- a/webroot/lib/category.class.php +++ b/webroot/lib/category.class.php @@ -48,6 +48,7 @@ class Category { * @param string $string */ public function initbystring($string) { + $this->id = false; if(!empty($string)) { $queryStr = "SELECT id FROM `".DB_PREFIX."_category` WHERE `name` = '".$this->DB->real_escape_string($string)."'"; diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index 20b869c..7f1db08 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2017 Johannes Keßler + * Copyright 2016-2018 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -34,10 +34,10 @@ class Link { private $DB; /** - * the current loaded tag by DB id - * @var int + * the current loaded link data + * @var array */ - private $id; + private $_data; public function __construct($databaseConnectionObject) { $this->DB = $databaseConnectionObject; @@ -51,6 +51,8 @@ class Link { public function load($hash) { $ret = false; + $this->_data = array(); + if(!empty($hash)) { $queryStr = "SELECT * FROM `".DB_PREFIX."_link` WHERE `hash` = '".$this->DB->real_escape_string($hash)."'"; @@ -58,24 +60,101 @@ class Link { if(!empty($query) && $query->num_rows == 1) { $ret = $query->fetch_assoc(); - $this->id = $ret['hash']; + $this->_data = $ret; # add stuff - $ret['tags'] = $this->_tags(); - $ret['categories'] = $this->_categories(); + $this->_tags(); + $this->_categories(); } } + return $this->_data; + } + + public function getData($key=false) { + $ret = $this->_data; + + if(!empty($key) && isset($this->_data[$key])) { + $ret = $this->_data[$key]; + } + return $ret; } - public function create($data) {} + /** + * reload the current id from DB + */ + public function reload() { + $this->load($this->_data['hash']); + } + + /** + * create a new link with the given data + * @param array $data + */ + public function create($data) { + } + + /** + * update the current loaded link with the given data + * @param array $data + * @return boolean|int + */ + public function update($data) { + + $ret = false; + + if(isset($data['title']) && !empty($data['title'])) { + + # categories and tag stuff + $catArr = Summoner::prepareTagOrCategoryStr($data['category']); + $tagArr = Summoner::prepareTagOrCategoryStr($data['tag']); + + $search = $data['title']; + $search .= ' '.$data['description']; + $search .= ' '.implode(" ",$tagArr); + $search .= ' '.implode(" ",$catArr); + + $queryStr = "UPDATE `".DB_PREFIX."_link` SET + `status` = '".$this->DB->real_escape_string($data['private'])."', + `description` = '".$this->DB->real_escape_string($data['description'])."', + `title` = '".$this->DB->real_escape_string($data['title'])."', + `image` = '".$this->DB->real_escape_string($data['image'])."', + `search` = '".$this->DB->real_escape_string($search)."' + WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; + + $query = $this->DB->query($queryStr); + + $catObj = new Category($this->DB); + $tagObj = new Tag($this->DB); + // clean the relations first + $this->_removeTagRelation(false); + $this->_removeCategoryRelation(false); + + if(!empty($catArr)) { + foreach($catArr as $c) { + $catObj->initbystring($c); + $catObj->setRelation($this->_data['id']); + } + } + if(!empty($tagArr)) { + foreach($tagArr as $t) { + $tagObj->initbystring($t); + $tagObj->setRelation($this->_data['id']); + } + } + + $ret = true; + } + + return $ret; + } /** * check if the given URL exists in the DB - * if so return the id. If not, return false + * if so return the hash. If not, return false * @param string $link - * @return boolean|int + * @return string */ public function exists($link) { $ret = false; @@ -100,16 +179,21 @@ class Link { private function _tags() { $ret = array(); - if(!empty($this->id)) { + if(!empty($this->_data['hash'])) { $queryStr = "SELECT DISTINCT(tag) FROM `".DB_PREFIX."_combined` - WHERE `hash` = '".$this->DB->real_escape_string($this->id)."'"; + WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; $query = $this->DB->query($queryStr); if(!empty($query) && $query->num_rows > 0) { - $ret = $query->fetch_all(MYSQLI_ASSOC); + while($result = $query->fetch_assoc()) { + if($result['tag'] !== NULL) { + $ret[] = $result['tag']; + } + } + } } - return $ret; + $this->_data['tags'] = $ret; } /** @@ -119,16 +203,64 @@ class Link { private function _categories() { $ret = array(); - if(!empty($this->id)) { + if(!empty($this->_data['hash'])) { $queryStr = "SELECT DISTINCT(category) FROM `".DB_PREFIX."_combined` - WHERE `hash` = '".$this->DB->real_escape_string($this->id)."'"; + WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; $query = $this->DB->query($queryStr); if(!empty($query) && $query->num_rows > 0) { - $ret = $query->fetch_all(MYSQLI_ASSOC); + while($result = $query->fetch_assoc()) { + if($result['category'] !== NULL) { + $ret[] = $result['category']; + } + } } } - return $ret; + $this->_data['categories'] = $ret; + } + + /** + * remove all or given tag relation to the current loaded link + * @param mixed $tagid + */ + private function _removeTagRelation($tagid) { + if(!empty($this->_data['id'])) { + $queryStr = false; + if($tagid === false) { + $queryStr = "DELETE FROM `".DB_PREFIX."_tagrelation` + WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'"; + } + elseif(is_numeric($tagid)) { + $queryStr = "DELETE FROM `".DB_PREFIX."_tagrelation` + WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."' + AND `tagid` = '".$this->DB->real_escape_string($tagid)."'"; + } + if(!empty($queryStr)) { + $this->DB->query($queryStr); + } + } + } + + /** + * remove all or given category relation to the current loaded link + * @param mixed $categoryid + */ + private function _removeCategoryRelation($categoryid) { + if(!empty($this->_data['id'])) { + $queryStr = false; + if($categoryid === false) { + $queryStr = "DELETE FROM `".DB_PREFIX."_categoryrelation` + WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'"; + } + elseif(is_numeric($categoryid)) { + $queryStr = "DELETE FROM `".DB_PREFIX."_categoryrelation` + WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."' + AND `categoryid` = '".$this->DB->real_escape_string($categoryid)."'"; + } + if(!empty($queryStr)) { + $this->DB->query($queryStr); + } + } } } ?> \ No newline at end of file diff --git a/webroot/lib/tag.class.php b/webroot/lib/tag.class.php index 060b297..ccf4eae 100644 --- a/webroot/lib/tag.class.php +++ b/webroot/lib/tag.class.php @@ -48,6 +48,7 @@ class Tag { * @param string $string */ public function initbystring($string) { + $this->id = false; if(!empty($string)) { $queryStr = "SELECT id FROM `".DB_PREFIX."_tag` WHERE `name` = '".$this->DB->real_escape_string($string)."'"; diff --git a/webroot/view/editlink.inc.php b/webroot/view/editlink.inc.php index 3d1b422..6d58f13 100644 --- a/webroot/view/editlink.inc.php +++ b/webroot/view/editlink.inc.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2017 Johannes Keßler + * Copyright 2016-2018 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -40,26 +40,62 @@ if(isset($_GET['id']) && !empty($_GET['id'])) { } $linkObj = new Link($DB); -$link = $linkObj->load($_id); -if(empty($link)) { +$linkObj->load($_id); +$linkData = $linkObj->getData(); +if(empty($linkData)) { header("HTTP/1.0 404 Not Found"); } -$formData = $link; -# prepate the tag edit string +if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink'])) { + $fData = $_POST['data']; + + $formData['private'] = 2; + if(isset($fData['private'])) { + $formData['private'] = 1; + } + + $formData['description'] = trim($fData['description']); + $formData['title'] = trim($fData['title']); + $formData['image'] = trim($fData['image']); + $formData['category'] = trim($fData['category']); + $formData['tag'] = trim($fData['tag']); + + if(!empty($formData['title'])) { + $update = $linkObj->update($formData); + + if($update === true) { + $submitFeedback['message'] = 'Link updated successfully.'; + $submitFeedback['status'] = 'success'; + // update link info + $linkObj->reload(); + $linkData = $linkObj->getData(); + } + else { + $submitFeedback['message'] = 'Something went wrong...'; + $submitFeedback['status'] = 'error'; + } + } + else { + $submitFeedback['message'] = 'Please provide a title.'; + $submitFeedback['status'] = 'error'; + } +} + +$formData = $linkData; +# prepate the tag string $formData['tag'] = ''; -if(!empty($link['tags'])) { - foreach($link['tags'] as $entry) { - $formData['tag'] .= $entry['tag'].','; +if(!empty($linkData['tags'])) { + foreach($linkData['tags'] as $k=>$v) { + $formData['tag'] .= $v.','; } $formData['tag'] = trim($formData['tag']," ,"); } # prepate the category string $formData['category'] = ''; -if(!empty($link['categories'])) { - foreach($link['categories'] as $entry) { - $formData['category'] .= $entry['category'].','; +if(!empty($linkData['categories'])) { + foreach($linkData['categories'] as $k=>$v) { + $formData['category'] .= $v.','; } $formData['category'] = trim($formData['category']," ,"); } diff --git a/webroot/view/editlink.php b/webroot/view/editlink.php index 0d0c34c..dd69138 100644 --- a/webroot/view/editlink.php +++ b/webroot/view/editlink.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2017 Johannes Keßler + * Copyright 2016-2018 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -27,128 +27,147 @@ */ ?> - -
-
Error
-

Something went wrong...

-
+
+ +
+
+
+
Error
+

Something went wrong...

+
+
+
- -
-
+
+
-
-
Error
-

-
+
+
Error
+

+
-
-
Success
-

-
+
+
Success
+

+
+
-
-
-
-

-
-
-
-
-

-
-
- -
-
-
-

Date added:

-
-
-

-
-
-
-
-

Title:

-
-
- -
-
-
-
-

Description:

-
-
- -
-
-
-
-

URL:

-
-
-

-
-
-
-
-

- Image:
- If provided +

+
+

+ + +

-
-

- Image if provided -

- -
-
-
-

Tags:

-
-
- - - - -
-
-
-
-
-

Category:

-
-
- - - - -
-
-
-
-
- /> -
-
- -
-
- +
+
+

+
+
+
+ +
+ +
+
+
+

Date added:

+
+
+

+
+
+
+
+

Title:

+
+
+ +
+
+
+
+

Description:

+
+
+ +
+
+
+
+

URL:

+
+
+

+
+
+
+
+

+ Image: (If provided) +

+
+
+

+ Image if provided... +

+ +
+
+ +
+
+

Tags:

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

Category:

+
+
+ + + + + + +
+
+
+
+ + /> +
+
+ +
+
+
+
+ + + + diff --git a/webroot/view/home.php b/webroot/view/home.php index 23a90f2..3bf73b4 100644 --- a/webroot/view/home.php +++ b/webroot/view/home.php @@ -152,7 +152,8 @@
@@ -165,7 +166,8 @@
diff --git a/webroot/view/linkinfo.inc.php b/webroot/view/linkinfo.inc.php index cbb9637..ab36e2e 100644 --- a/webroot/view/linkinfo.inc.php +++ b/webroot/view/linkinfo.inc.php @@ -38,7 +38,7 @@ if(isset($_GET['id']) && !empty($_GET['id'])) { } $linkObj = new Link($DB); -$link = $linkObj->load($_id); -if(empty($link)) { +$linkData = $linkObj->load($_id); +if(empty($linkData)) { header("HTTP/1.0 404 Not Found"); } \ No newline at end of file diff --git a/webroot/view/linkinfo.php b/webroot/view/linkinfo.php index 3428e4c..364f90f 100644 --- a/webroot/view/linkinfo.php +++ b/webroot/view/linkinfo.php @@ -27,7 +27,7 @@ */ ?> - +
@@ -53,7 +53,7 @@
-

+

@@ -64,7 +64,7 @@

Title:

-

+

@@ -72,7 +72,7 @@

Description:

-

+

@@ -80,7 +80,7 @@

URL:

-

+

@@ -91,7 +91,7 @@

- Image if provided + Image if provided...

@@ -100,7 +100,7 @@

Date added:

-

+

@@ -109,12 +109,12 @@
$v) { ?> - +
$v) { ?> - +
-
-
-
-
-
+
+
+
- + +
-
-
-

-

-

- Visit link - More details -

-
+
+
+
+

+

+
+
+
-
-
+
+
  • @@ -133,8 +94,8 @@
-
-
+
+