* Insipid
* Personal web-bookmark-system
*
- * Copyright 2016-2018 Johannes Keßler
+ * Copyright 2016-2019 Johannes Keßler
*
* Development starting from 2011: Johannes Keßler
* https://www.bananas-playground.net/projekt/insipid/
define("USE_PAGE_AUTH",false);
# results per page
-define("RESULTS_PER_PAGE",10);
+define("RESULTS_PER_PAGE",12);
# settings for importing from e-mail
# SSL/TLS only
* the current loaded category by DB id
* @var int
*/
- private $id;
+ private $_id;
+
+ /**
+ * current loaded tag data
+ * @var array
+ */
+ private $_data;
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
+ * @return bool|int
*/
public function initbystring($string) {
- $this->id = false;
+ $this->_id = false;
if(!empty($string)) {
- $queryStr = "SELECT id FROM `".DB_PREFIX."_category`
+ $queryStr = "SELECT `id`,`name` 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'];
+ $this->_id = $result['id'];
+ $this->_data = $result;
}
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;
+ $this->_id = $this->DB->insert_id;
+ $this->_data['id'] = $this->_id;
+ $this->_data['name'] = $string;
}
}
}
- return $this->id;
+ return $this->_id;
}
/**
* @return mixed
*/
public function initbyid($id) {
- $this->id = false;
+ $this->_id = false;
if(!empty($id)) {
$queryStr = "SELECT id,name
$query = $this->DB->query($queryStr);
if(!empty($query) && $query->num_rows > 0) {
$result = $query->fetch_assoc();
- $this->id = $id;
+ $this->_id = $id;
+ $this->_data = $result;
}
}
- return $this->id;
+ return $this->_id;
+ }
+
+ /**
+ * return all or data fpr given key on the current loaded tag
+ * @param bool $key
+ * @return array|mixed
+ */
+ public function getData($key=false) {
+ $ret = $this->_data;
+
+ if(!empty($key) && isset($this->_data[$key])) {
+ $ret = $this->_data[$key];
+ }
+
+ return $ret;
}
/**
* @return void
*/
public function setRelation($linkid) {
- if(!empty($linkid) && !empty($this->id)) {
+ 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)."'";
+ `categoryid` = '".$this->DB->real_escape_string($this->_id)."'";
$this->DB->query($queryStr);
}
}
public function delete() {
$ret = false;
- if(!empty($this->id)) {
+ if(!empty($this->_id)) {
$this->DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
try {
$queryStr = "DELETE
FROM `".DB_PREFIX."_categoryrelation`
- WHERE `categoryid` = '".$this->DB->real_escape_string($this->id)."'";
+ WHERE `categoryid` = '".$this->DB->real_escape_string($this->_id)."'";
$this->DB->query($queryStr);
$queryStr = "DELETE
FROM `".DB_PREFIX."_category`
- WHERE `id` = '".$this->DB->real_escape_string($this->id)."'";
+ WHERE `id` = '".$this->DB->real_escape_string($this->_id)."'";
$this->DB->query($queryStr);
$this->DB->commit();
public function latestLinks($limit=5) {
$ret = array();
- $queryStr = "SELECT * FROM `".DB_PREFIX."_link` WHERE `status` = 2 ORDER BY `created` DESC";
+ $queryStr = "SELECT `title` FROM `".DB_PREFIX."_link` WHERE `status` = 2 ORDER BY `created` DESC";
if(!empty($limit)) {
$queryStr .= " LIMIT $limit";
}
* @param int $id
* @param string $string
* @param int $limit
+ * @param bool $offset
* @return array
*/
- public function linksByCategory($id,$string,$limit=5) {
+ public function linksByCategory($id, $string, $limit=5, $offset=false) {
$ret = array();
- $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
- FROM `".DB_PREFIX."_combined`
- WHERE `status` = 2";
+ $querySelect = "SELECT ".$this->COMBINED_SELECT_VALUES;
+ $queryFrom = " FROM `".DB_PREFIX."_combined`";
+ $queryWhere = " WHERE `status` = 2";
+
if(!empty($id) && is_numeric($id)) {
- $queryStr .= " AND `categoryId` = '" . $this->DB->real_escape_string($id) . "'";
+ $queryWhere .= " AND `categoryId` = '" . $this->DB->real_escape_string($id) . "'";
}
elseif(!empty($string) && is_string($string)) {
- $queryStr .= " AND `category` = '" . $this->DB->real_escape_string($string) . "'";
+ $queryWhere .= " AND `category` = '" . $this->DB->real_escape_string($string) . "'";
}
else {
return $ret;
}
- $queryStr .= "GROUP BY `hash`
+ $queryOrder = "GROUP BY `hash`
ORDER BY `created` DESC";
+ $queryLimit = '';
if(!empty($limit)) {
- $queryStr .= " LIMIT $limit";
+ $queryLimit .= " LIMIT $limit";
+ if($offset !== false) {
+ $queryLimit .= " OFFSET $offset";
+ }
}
- $query = $this->DB->query($queryStr);
+ $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryOrder.$queryLimit);
if(!empty($query) && $query->num_rows > 0) {
- $ret = $query->fetch_all(MYSQLI_ASSOC);
+ while($result = $query->fetch_assoc()) {
+ $linkObj = new Link($this->DB);
+ $ret['results'][] = $linkObj->loadShortInfo($result['hash']);
+ unset($linkObj);
+ }
+
+ $query = $this->DB->query("SELECT COUNT(DISTINCT(hash)) AS amount ".$queryFrom.$queryWhere);
+ $result = $query->fetch_assoc();
+ $ret['amount'] = $result['amount'];
}
return $ret;
* @param int $id
* @param string $string
* @param int $limit
+ * @param bool $offset
* @return array
*/
- public function linksByTag($id,$string,$limit=5) {
+ public function linksByTag($id, $string, $limit=5, $offset=false) {
$ret = array();
- $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
- FROM `".DB_PREFIX."_combined`
- WHERE `status` = 2";
+ $querySelect = "SELECT ".$this->COMBINED_SELECT_VALUES;
+ $queryFrom = " FROM `".DB_PREFIX."_combined`";
+ $queryWhere = " WHERE `status` = 2";
+
if(!empty($id) && is_numeric($id)) {
- $queryStr .= " AND `tagId` = '" . $this->DB->real_escape_string($id) . "'";
+ $queryWhere .= " AND `tagId` = '" . $this->DB->real_escape_string($id) . "'";
}
elseif(!empty($string) && is_string($string)) {
- $queryStr .= " AND `tag` = '" . $this->DB->real_escape_string($string) . "'";
+ $queryWhere .= " AND `tag` = '" . $this->DB->real_escape_string($string) . "'";
}
else {
return $ret;
}
- $queryStr .= "GROUP BY `hash`
+ $queryOrder = "GROUP BY `hash`
ORDER BY `created` DESC";
+ $queryLimit = '';
if(!empty($limit)) {
- $queryStr .= " LIMIT $limit";
+ $queryLimit .= " LIMIT $limit";
+ if($offset !== false) {
+ $queryLimit .= " OFFSET $offset";
+ }
}
- $query = $this->DB->query($queryStr);
+ $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryOrder.$queryLimit);
if(!empty($query) && $query->num_rows > 0) {
- $ret = $query->fetch_all(MYSQLI_ASSOC);
+ while($result = $query->fetch_assoc()) {
+ $linkObj = new Link($this->DB);
+ $ret['results'][] = $linkObj->loadShortInfo($result['hash']);
+ unset($linkObj);
+ }
+
+ $query = $this->DB->query("SELECT COUNT(DISTINCT(hash)) AS amount ".$queryFrom.$queryWhere);
+ $result = $query->fetch_assoc();
+ $ret['amount'] = $result['amount'];
}
return $ret;
* @param bool $offset
* @return array
*/
- public function links($limit=false,$offset=false) {
+ public function links($limit=10,$offset=false) {
$ret = array();
- $queryStr = "SELECT `hash`
- FROM `".DB_PREFIX."_link`
- WHERE `status` = 2
- ORDER BY `created` DESC";
+ $querySelect = "SELECT `hash`";
+ $queryFrom = " FROM `".DB_PREFIX."_link`";
+ $queryWhere = " WHERE `status` = 2";
+ $queryOrder = " ORDER BY `created` DESC";
+ $queryLimit = "";
if(!empty($limit)) {
- $queryStr .= " LIMIT $limit";
+ $queryLimit = " LIMIT $limit";
if($offset !== false) {
- $queryStr .= " OFFSET $offset";
+ $queryLimit .= " OFFSET $offset";
}
}
- $query = $this->DB->query($queryStr);
+ $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryOrder.$queryLimit);
if(!empty($query) && $query->num_rows > 0) {
while($result = $query->fetch_assoc()) {
$linkObj = new Link($this->DB);
unset($linkObj);
}
- $query = $this->DB->query("SELECT COUNT(DISTINCT(hash)) AS `amount`
- FROM `".DB_PREFIX."_combined`
- WHERE `status` = 2");
+ $query = $this->DB->query("SELECT COUNT(hash) AS amount ".$queryFrom.$queryWhere);
$result = $query->fetch_assoc();
$ret['amount'] = $result['amount'];
}
* the current loaded tag by DB id
* @var int
*/
- private $id;
+ private $_id;
+
+ /**
+ * current loaded tag data
+ * @var array
+ */
+ private $_data;
public function __construct($databaseConnectionObject) {
$this->DB = $databaseConnectionObject;
* @param string $string
*/
public function initbystring($string) {
- $this->id = false;
+ $this->_id = false;
if(!empty($string)) {
- $queryStr = "SELECT id FROM `".DB_PREFIX."_tag`
+ $queryStr = "SELECT `id`,`name` 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'];
+ $this->_id = $result['id'];
+ $this->_data = $result;
}
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;
+ $this->_id = $this->DB->insert_id;
+ $this->_data['id'] = $this->_id;
+ $this->_data['name'] = $string;
}
}
}
/**
* by given DB table id load all the info we need
* @param int $id
+ * @return bool|int
*/
public function initbyid($id) {
+ $this->_id = false;
+
if(!empty($id)) {
- $this->id = $id;
+ $queryStr = "SELECT `id`,`name` FROM `".DB_PREFIX."_tag`
+ WHERE `id` = '".$this->DB->real_escape_string($id)."'";
+ $query = $this->DB->query($queryStr);
+ if(!empty($query) && $query->num_rows > 0) {
+ $result = $query->fetch_assoc();
+ $this->_id = $result['id'];
+ $this->_data = $result;
+ }
}
+
+ return $this->_id;
+ }
+
+ /**
+ * return all or data fpr given key on the current loaded tag
+ * @param bool $key
+ * @return array|mixed
+ */
+ public function getData($key=false) {
+ $ret = $this->_data;
+
+ if(!empty($key) && isset($this->_data[$key])) {
+ $ret = $this->_data[$key];
+ }
+
+ return $ret;
}
/**
* @return boolean
*/
public function setRelation($linkid) {
- if(!empty($linkid) && !empty($this->id)) {
+ 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)."'";
+ `tagid` = '".$this->DB->real_escape_string($this->_id)."'";
$this->DB->query($queryStr);
}
}
public function delete() {
$ret = false;
- if(!empty($this->id)) {
+ if(!empty($this->_id)) {
$this->DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
try {
$queryStr = "DELETE
FROM `".DB_PREFIX."_tagrelation`
- WHERE `tagid` = '".$this->DB->real_escape_string($this->id)."'";
+ WHERE `tagid` = '".$this->DB->real_escape_string($this->_id)."'";
$this->DB->query($queryStr);
$queryStr = "DELETE
FROM `".DB_PREFIX."_tag`
- WHERE `id` = '".$this->DB->real_escape_string($this->id)."'";
+ WHERE `id` = '".$this->DB->real_escape_string($this->_id)."'";
$this->DB->query($queryStr);
$this->DB->commit();
<div class="content">
<h4><a href="?p=overview&m=category&id=<?php echo urlencode($v['id']); ?>"><?php echo $v['name']; ?></a></h4>
<ul>
-<?php foreach ($links as $link) { ?>
+<?php foreach ($links['results'] as $link) { ?>
<li><a class="" href="<?php echo $link['link']; ?>" target="_blank"><?php echo $link['title']; ?></a></li>
<?php } ?>
</ul>
switch($_requestMode) {
case 'tag':
if(!empty($_id)) {
- $linkCollection = $Management->linksByTag($_id,false,false);
- if(!empty($linkCollection)) {
- $subHeadline = $linkCollection[0]['tag'].' <i class="ion-md-pricetag"></i>';
+ $linkCollection = $Management->linksByTag($_id,false,RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
+ if(!empty($linkCollection['results'])) {
+ $tagObj = new Tag($DB);
+ $tagObj->initbyid($_id);
+ $tagname = $tagObj->getData('name');
+ $subHeadline = $tagname.' <i class="ion-md-pricetag"></i>';
}
}
else {
break;
case 'category':
if(!empty($_id)) {
- $linkCollection = $Management->linksByCategory($_id,false,false);
- if(!empty($linkCollection)) {
- $subHeadline = $linkCollection[0]['category'].' <i class="ion-md-filing"></i>';
+ $linkCollection = $Management->linksByCategory($_id,false,RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
+ if(!empty($linkCollection['results'])) {
+ $catObj = new Category($DB);
+ $catObj->initbyid($_id);
+ $catname = $catObj->getData('name');
+ $subHeadline = $catname.' <i class="ion-md-filing"></i>';
}
}
else {
default:
# show all
$linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
- if(!empty($linkCollection['amount'])) {
- $pagination['pages'] = ceil($linkCollection['amount'] / RESULTS_PER_PAGE);
- $pagination['curPage'] = $_curPage;
- $pagination['m'] = $_requestMode;
- }
+}
+if(!empty($linkCollection['amount'])) {
+ $pagination['pages'] = ceil($linkCollection['amount'] / RESULTS_PER_PAGE);
+ $pagination['curPage'] = $_curPage;
+ $pagination['linkadd'] = '&m='.$_requestMode;
+ if(!empty($_id)) {
+ $pagination['linkadd'] .= '&id='.$_id;
+ }
}
if($pagination['pages'] > 11) {
</div>
</div>
- <?php if($pagination['pages'] > 0) { ?>
+ <?php if($pagination['pages'] > 1) { ?>
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
<?php if($pagination['curPage'] > 1) {
- echo '<a href="index.php?p=overview&m='.$pagination['m'].'&page='.($pagination['curPage']-1).'"
+ echo '<a href="index.php?p=overview'.$pagination['linkadd'].'&page='.($pagination['curPage']-1).'"
class="pagination-previous">Previous</a>';
}
if($pagination['curPage'] < $pagination['pages']) {
- echo '<a href="index.php?p=overview&m='.$pagination['m'].'&page='.($pagination['curPage']+1).'"
+ echo '<a href="index.php?p=overview'.$pagination['linkadd'].'&page='.($pagination['curPage']+1).'"
class="pagination-next">Next</a>';
}
?>
if($i == $pagination['curPage']) $active = 'is-current';
if(in_array($i,$pagination['visibleRange'])) {
- echo '<li><a href="index.php?p=overview&m=' . $pagination['m'] . '&page=' . $i . '"
+ echo '<li><a href="index.php?p=overview' . $pagination['linkadd'] . '&page=' . $i . '"
class="pagination-link ' . $active . '"
aria-label="Goto page ' . $i . '">' . $i . '</a></li>';
}