TODO / Feature list
==========================================================================
++ SQL transactions.
\ No newline at end of file
define('DB_USERNAME','user');
define('DB_PASSWORD','test');
define('DB_NAME','insipid');
-define('DB_PREFIX','insipid'); # a _ is added automatically as seperation
\ No newline at end of file
+define('DB_PREFIX','insipid'); # a _ is added automatically as seperation
+
+# user config
+define('FRONTEND_USERNAME','luke');
+define('FRONTEND_PASSWORD','thefather');
\ No newline at end of file
require('config.php');
require('lib/summoner.class.php');
require('lib/management.class.php');
+require('lib/tag.class.php');
+require('lib/category.class.php');
+require('lib/link.class.php');
## main vars
$Summoner = new Summoner();
--- /dev/null
+<?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.
+ *
+ */
+
+class Category {
+ /**
+ * the database object
+ * @var object
+ */
+ private $DB;
+
+ /**
+ * the current loaded category by DB id
+ * @var int
+ */
+ private $id;
+
+ public function __construct($databaseConnectionObject) {
+ $this->DB = $databaseConnectionObject;
+ }
+
+ /**
+ * by given string load the info from the DB and even create if not existing
+ * @param string $string
+ */
+ public function initbystring($string) {
+ if(!empty($string)) {
+ $queryStr = "SELECT id FROM `".DB_PREFIX."_category`
+ WHERE `name` = '".$this->DB->real_escape_string($string)."'";
+ $query = $this->DB->query($queryStr);
+ if(!empty($query) && $query->num_rows > 0) {
+ $result = $query->fetch_assoc();
+ $this->id = $result['id'];
+ }
+ else {
+ $queryStr = "INSERT INTO `".DB_PREFIX."_category`
+ SET `name` = '".$this->DB->real_escape_string($string)."'";
+ $this->DB->query($queryStr);
+ if(!empty($this->DB->insert_id)) {
+ $this->id = $this->DB->insert_id;
+ }
+ }
+ }
+ }
+
+ /**
+ * by given DB table id load all the info we need
+ * @param int $id
+ */
+ public function initbyid($id) {
+ if(!empty($id)) {
+ $this->id = $id;
+ }
+ }
+
+ /**
+ * set the relation to the given link to the loaded category
+ * @param int $linkid
+ * @return boolean
+ */
+ public function setRelation($linkid) {
+ if(!empty($linkid) && !empty($this->id)) {
+ $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_categoryrelation`
+ SET `linkid` = '".$this->DB->real_escape_string($linkid)."',
+ `categoryid` = '".$this->DB->real_escape_string($this->id)."'";
+ $this->DB->query($queryStr);
+ }
+ }
+}
+ ?>
\ No newline at end of file
--- /dev/null
+<?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.
+ *
+ */
+
+class Link {
+ /**
+ * the database object
+ * @var object
+ */
+ private $DB;
+
+ /**
+ * the current loaded tag by DB id
+ * @var int
+ */
+ private $id;
+
+ public function __construct($databaseConnectionObject) {
+ $this->DB = $databaseConnectionObject;
+ }
+
+ public function create($data) {}
+
+ /**
+ * check if the given URL exists in the DB
+ * if so return the id. If not, return false
+ * @param string $link
+ * @return boolean|int
+ */
+ public function exists($link) {
+ $ret = false;
+
+ if(!empty($link)) {
+ $queryStr = "SELECT * FROM `".DB_PREFIX."_link`
+ WHERE `link` = '".$this->DB->real_escape_string($link)."'";
+ $query = $this->DB->query($queryStr);
+ if(!empty($query) && $query->num_rows > 0) {
+ $result = $query->fetch_assoc();
+ $ret = $result['id'];
+ }
+ }
+
+ return $ret;
+ }
+}
+ ?>
\ No newline at end of file
return $ret;
}
+
}
?>
\ No newline at end of file
return $mediaInfos;
}
+
+ /**
+ * at creation a category or tag can be a string with multiple values.
+ * seperated with space or ,
+ * category and tag is a single string without any seperators
+ *
+ * @param string $string
+ */
+ static function prepareTagOrCategorieStr($string) {
+ $ret = array();
+
+ $string = trim($string, ", ");
+ if(strstr($string, ",")) {
+ $_t = explode(",", $string);
+ foreach($_t as $new) {
+ $ret[$new] = $new;
+ }
+ unset($_t);
+ unset($new);
+
+ foreach($ret as $e) {
+ if(strstr($e, " ")) {
+ unset($ret[$e]);
+ $_t = explode(" ", $e);
+ foreach($_t as $new) {
+ $new = trim($new);
+ if(!empty($new)) {
+ $ret[$new] = $new;
+ }
+ }
+ }
+ }
+ }
+ else {
+ $_t = explode(" ", $string);
+ foreach($_t as $new) {
+ $new = trim($new);
+ if(!empty($new)) {
+ $ret[$new] = $new;
+ }
+ }
+ }
+
+
+ return $ret;
+ }
}
?>
* along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
*
*/
+
+class Tag {
+ /**
+ * the database object
+ * @var object
+ */
+ private $DB;
+
+ /**
+ * the current loaded tag by DB id
+ * @var int
+ */
+ private $id;
+
+ public function __construct($databaseConnectionObject) {
+ $this->DB = $databaseConnectionObject;
+ }
+
+ /**
+ * by given string load the info from the DB and even create if not existing
+ * @param string $string
+ */
+ public function initbystring($string) {
+ if(!empty($string)) {
+ $queryStr = "SELECT id FROM `".DB_PREFIX."_tag`
+ WHERE `name` = '".$this->DB->real_escape_string($string)."'";
+ $query = $this->DB->query($queryStr);
+ if(!empty($query) && $query->num_rows > 0) {
+ $result = $query->fetch_assoc();
+ $this->id = $result['id'];
+ }
+ else {
+ $queryStr = "INSERT INTO `".DB_PREFIX."_tag`
+ SET `name` = '".$this->DB->real_escape_string($string)."'";
+ $this->DB->query($queryStr);
+ if(!empty($this->DB->insert_id)) {
+ $this->id = $this->DB->insert_id;
+ }
+ }
+ }
+ }
+
+ /**
+ * by given DB table id load all the info we need
+ * @param int $id
+ */
+ public function initbyid($id) {
+ if(!empty($id)) {
+ $this->id = $id;
+ }
+ }
+
+ /**
+ * set the relation to the given link to the loaded tag
+ * @param int $linkid
+ * @return boolean
+ */
+ public function setRelation($linkid) {
+ if(!empty($linkid) && !empty($this->id)) {
+ $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_tagrelation`
+ SET `linkid` = '".$this->DB->real_escape_string($linkid)."',
+ `tagid` = '".$this->DB->real_escape_string($this->id)."'";
+ $this->DB->query($queryStr);
+ }
+ }
+}
?>
\ No newline at end of file
$honeypotCheck = true;
}
+# search or new one.
if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['submitsearch']) && $honeypotCheck === false) {
$searchValue = trim($_POST['data']['searchfield']);
$isUrl = Summoner::validate($searchValue,'url');
if($isUrl === true) {
# search for URL
- $queryStr = "SELECT * FROM";
+ $queryStr = "SELECT * FROM `".DB_PREFIX."_link`
+ WHERE `link` = '".$DB->real_escape_string($searchValue)."'";
}
elseif(Summoner::validate($searchValue,'text')) {
# search for this in more then one field
}
if(!empty($queryStr)) {
+ $query = $DB->query($queryStr);
+ if(!empty($query) && $query->num_rows > 0) {
+ $searchResult = $query->fetch_all(MYSQLI_ASSOC);
+ }
}
# new one?
$showAddForm = true;
$formData['url'] = $searchValue;
}
+ elseif(!empty($searchResult)) {
+ # something has been found
+ }
+ else {
+ # nothing found
+ $submitFeedback['message'] = 'Nothing found...';
+ $submitFeedback['status'] = 'error';
+ }
+}
+
+# add a new one
+if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['addnewone']) && $honeypotCheck === false) {
+ $fData = $_POST['data'];
+
+ $formData['private'] = 2;
+ if(isset($fData['private'])) {
+ $formData['private'] = 1;
+ }
+
+ $formData['url'] = trim($fData['url']);
+ $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']);
+ $username = trim($fData['username']);
+ $password = trim($fData['password']);
+
+ $isUrl = Summoner::validate($formData['url'],'url');
+
+ if($isUrl === true && !empty($formData['title']) && $username === FRONTEND_USERNAME && $password === FRONTEND_PASSWORD) {
+ $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_link` SET
+ `link` = '".$DB->real_escape_string($formData['url'])."',
+ `created` = NOW(),
+ `status` = '".$DB->real_escape_string($formData['private'])."',
+ `description` = '".$DB->real_escape_string($formData['description'])."',
+ `title` = '".$DB->real_escape_string($formData['title'])."',
+ `image` = '".$DB->real_escape_string($formData['image'])."',
+ `hash` = '".$DB->real_escape_string(md5($formData['url']))."'";
+ $DB->query($queryStr);
+ $linkID = $DB->insert_id;
+
+ var_dump($linkID);
+
+ if(!empty($linkID)) {
+
+ # categories and tag stuff
+ $catArr = Summoner::prepareTagOrCategorieStr($formData['category']);
+ $tagArr = Summoner::prepareTagOrCategorieStr($formData['tag']);
+
+ if(!empty($catArr)) {
+ foreach($catArr as $c) {
+ $catObj = new Category($DB);
+ $catObj->initbystring($c);
+ $catObj->setRelation($linkID);
+
+ unset($catObj);
+ }
+ }
+ if(!empty($tagArr)) {
+ foreach($tagArr as $t) {
+ $tagObj = new Tag($DB);
+ $tagObj->initbystring($t);
+ $tagObj->setRelation($linkID);
+
+ unset($tagObj);
+ }
+ }
+
+ $submitFeedback['message'] = 'Link added successfully.';
+ $submitFeedback['status'] = 'success';
+ $TemplateData['refresh'] = 'index.php?p=showlink&id='.$linkID;
+ }
+ else {
+ $submitFeedback['message'] = 'Something went wrong...';
+ $submitFeedback['status'] = 'error';
+ $showAddForm = true;
+ }
+ }
+ else {
+ $submitFeedback['message'] = 'Please provide a valid URL, title, username and password.';
+ $submitFeedback['status'] = 'error';
+ $showAddForm = true;
+ }
}
$existingCategories = $Management->categories();
<div class="large-6 columns">
<label>
Category
- <input type="text" name="data[category]" list="categorylist" />
+ <input type="text" name="data[category]" list="categorylist" value="<?php echo Summoner::ifset($formData, 'category'); ?>" />
<datalist id="categorylist">
<?php foreach($existingCategories as $c) { ?>
<option value="<?php echo $c; ?>">
<div class="large-6 columns">
<label>
Tag
- <input type="text" name="data[tag]" list="taglist" />
+ <input type="text" name="data[tag]" list="taglist" value="<?php echo Summoner::ifset($formData, 'tag'); ?>" />
<datalist id="taglist">
<?php foreach($existingTags as $t) { ?>
<option value="<?php echo $t; ?>">
<div class="row">
<div class="large-8 columns">
- <input type="checkbox" name="data[private]" value="1" /><label>Private</label>
+ <input type="checkbox" name="data[private]" value="1" <?php if(Summoner::ifset($formData, 'private')) echo "checked"; ?> /><label>Private</label>
</div>
<div class="large-4 columns text-right" >
- <input type="submit" class="button" value="Add new Link">
+ <input type="submit" class="button" name="addnewone" value="Add new Link">
</div>
</div>
</form>