From 39c95c0b5878abbf2e4a27521ff02e0624a14094 Mon Sep 17 00:00:00 2001 From: Banana Date: Tue, 16 Jul 2019 17:28:23 +0200 Subject: [PATCH] code tabs --- webroot/lib/link.class.php | 468 ++++++++++++++++----------------- webroot/lib/summoner.class.php | 318 +++++++++++----------- webroot/view/editlink.inc.php | 78 +++--- webroot/view/editlink.php | 228 ++++++++-------- webroot/view/home.php | 274 +++++++++---------- webroot/view/linkinfo.php | 200 +++++++------- webroot/view/overview.php | 74 +++--- 7 files changed, 820 insertions(+), 820 deletions(-) diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index bd4867f..1017473 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -27,33 +27,33 @@ */ class Link { - /** - * the database object - * @var object - */ - private $DB; - - /** - * the current loaded link data - * @var array - */ - private $_data; - - public function __construct($databaseConnectionObject) { - $this->DB = $databaseConnectionObject; - } - - /** - * load all the info we have about a link by given hash - * @param string $hash - * @return mixed - */ - public function load($hash) { - - $this->_data = array(); - - if(!empty($hash)) { - $queryStr = "SELECT + /** + * the database object + * @var object + */ + private $DB; + + /** + * the current loaded link data + * @var array + */ + private $_data; + + public function __construct($databaseConnectionObject) { + $this->DB = $databaseConnectionObject; + } + + /** + * load all the info we have about a link by given hash + * @param string $hash + * @return mixed + */ + public function load($hash) { + + $this->_data = array(); + + if(!empty($hash)) { + $queryStr = "SELECT any_value(`id`) as id, any_value(`link`) as link, any_value(`created`) as created, @@ -64,248 +64,248 @@ class Link { any_value(`image`) as image, any_value(`hash`) as hash FROM `".DB_PREFIX."_link` - WHERE `hash` = '".$this->DB->real_escape_string($hash)."'"; - $query = $this->DB->query($queryStr); - if(!empty($query) && $query->num_rows == 1) { + WHERE `hash` = '".$this->DB->real_escape_string($hash)."'"; + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows == 1) { $this->_data = $query->fetch_assoc(); - # add stuff - $this->_tags(); - $this->_categories(); - $this->_image(); - } - } - - return $this->_data; - } - - public function getData($key=false) { - $ret = $this->_data; - - if(!empty($key) && isset($this->_data[$key])) { - $ret = $this->_data[$key]; - } - - return $ret; - } - - /** - * 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); - - # did the image url change? + # add stuff + $this->_tags(); + $this->_categories(); + $this->_image(); + } + } + + return $this->_data; + } + + public function getData($key=false) { + $ret = $this->_data; + + if(!empty($key) && isset($this->_data[$key])) { + $ret = $this->_data[$key]; + } + + return $ret; + } + + /** + * 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); + + # did the image url change? $_imageUrlChanged = false; if($this->_data['image'] != $data['image']) { $_imageUrlChanged = true; } - $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']); - } - } - - # decide to store or remove the image + $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']); + } + } + + # decide to store or remove the image if(isset($data['localImage'])) { - $image = ABSOLUTE_PATH.'/'.LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash']; - if($data['localImage'] === true) { + $image = ABSOLUTE_PATH.'/'.LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash']; + if($data['localImage'] === true) { if(!file_exists($image) || $_imageUrlChanged === true) { Summoner::downloadFile($data['image'],$image); } } elseif($data['localImage'] === false) { - if(file_exists($image)) { - unlink($image); + if(file_exists($image)) { + unlink($image); } } } - $ret = true; - } + $ret = true; + } - return $ret; - } + return $ret; + } - /** - * check if the given URL exists in the DB - * if so return the hash. If not, return false - * @param string $link - * @return string - */ - public function exists($link) { - $ret = false; + /** + * check if the given URL exists in the DB + * if so return the hash. If not, return false + * @param string $link + * @return string + */ + public function exists($link) { + $ret = false; - if(!empty($link)) { - $queryStr = "SELECT + if(!empty($link)) { + $queryStr = "SELECT any_value(`hash`) as hash - 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['hash']; - } - } - - return $ret; - } - - /** - * load all the tags we have to the already loaded link - * needs $this->load called first - */ - private function _tags() { - $ret = array(); - - if(!empty($this->_data['hash'])) { - $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['hash']; + } + } + + return $ret; + } + + /** + * load all the tags we have to the already loaded link + * needs $this->load called first + */ + private function _tags() { + $ret = array(); + + if(!empty($this->_data['hash'])) { + $queryStr = "SELECT DISTINCT(tag) as tag FROM `".DB_PREFIX."_combined` WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; - $query = $this->DB->query($queryStr); - if(!empty($query) && $query->num_rows > 0) { - while($result = $query->fetch_assoc()) { - if($result['tag'] !== NULL) { - $ret[$result['tag']] = $result['tag']; - } - } - - } - } - - $this->_data['tags'] = $ret; - } - - /** - * load all the categories we have to the already loaded link - * needs $this->load called first - */ - private function _categories() { - $ret = array(); - - if(!empty($this->_data['hash'])) { - $queryStr = "SELECT + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows > 0) { + while($result = $query->fetch_assoc()) { + if($result['tag'] !== NULL) { + $ret[$result['tag']] = $result['tag']; + } + } + + } + } + + $this->_data['tags'] = $ret; + } + + /** + * load all the categories we have to the already loaded link + * needs $this->load called first + */ + private function _categories() { + $ret = array(); + + if(!empty($this->_data['hash'])) { + $queryStr = "SELECT DISTINCT(category) FROM `".DB_PREFIX."_combined` - WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; - $query = $this->DB->query($queryStr); - if(!empty($query) && $query->num_rows > 0) { - while($result = $query->fetch_assoc()) { - if($result['category'] !== NULL) { - $ret[$result['category']] = $result['category']; - } - } - } - } - - $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 + WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows > 0) { + while($result = $query->fetch_assoc()) { + if($result['category'] !== NULL) { + $ret[$result['category']] = $result['category']; + } + } + } + } + + $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 + 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 + 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 + 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); - } - } - } + AND `categoryid` = '".$this->DB->real_escape_string($categoryid)."'"; + } + if(!empty($queryStr)) { + $this->DB->query($queryStr); + } + } + } /** * determine of we have a local stored image * if so populate the localImage attribute */ - private function _image() { + private function _image() { if(!empty($this->_data['hash'])) { $this->_data['imageToShow'] = $this->_data['image']; $image = ABSOLUTE_PATH.'/'.LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash']; diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index 7b5487f..6400cec 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -58,12 +58,12 @@ class Summoner { switch ($mode) { case 'mail': - if(filter_var($input,FILTER_VALIDATE_EMAIL) === $input) { - return true; - } - else { - return false; - } + if(filter_var($input,FILTER_VALIDATE_EMAIL) === $input) { + return true; + } + else { + return false; + } break; case 'url': @@ -137,14 +137,14 @@ class Summoner { 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 + [\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); } @@ -262,7 +262,7 @@ class Summoner { * @return bool */ static function ifset($array,$key) { - return isset($array[$key]) ? $array[$key] : false; + return isset($array[$key]) ? $array[$key] : false; } /** @@ -271,16 +271,16 @@ class Summoner { * @return array|bool */ static function gatherInfoFromURL($url) { - $ret = false; + $ret = false; - if(self::validate($url,'url')) { - $data = self::curlCall($url); - if(!empty($data)) { - $ret = self::socialMetaInfos($data); - } - } + if(self::validate($url,'url')) { + $data = self::curlCall($url); + if(!empty($data)) { + $ret = self::socialMetaInfos($data); + } + } - return $ret; + return $ret; } /** @@ -290,88 +290,88 @@ class Summoner { * @return array */ static function socialMetaInfos($string) { - #http://www.w3bees.com/2013/11/fetch-facebook-og-meta-tags-with-php.html - #http://www.9lessons.info/2014/01/social-meta-tags-for-google-twitter-and.html - #http://ogp.me/ - #https://moz.com/blog/meta-data-templates-123 - - $dom = new DomDocument; - # surpress invalid html warnings - @$dom->loadHTML($string); - - $xpath = new DOMXPath($dom); - $metas = $xpath->query('//*/meta'); - - $mediaInfos = array(); - - # meta tags - foreach($metas as $meta) { - if($meta->getAttribute('property')) { - $prop = $meta->getAttribute('property'); - $prop = mb_strtolower($prop); - - # minimum required information - # http://ogp.me/#metadata - if($prop == "og:title") { - - $mediaInfos['title'] = $meta->getAttribute('content'); - } - elseif($prop == "og:image") { - $mediaInfos['image'] = $meta->getAttribute('content'); - } - elseif($prop == "og:url") { - $mediaInfos['link'] = $meta->getAttribute('content'); - } - elseif($prop == "og:description") { - $mediaInfos['description'] = $meta->getAttribute('content'); - } - } - elseif($meta->getAttribute('name')) { - $name = $meta->getAttribute('name'); - $name = mb_strtolower($name); - - # twitter - # https://dev.twitter.com/cards/overview - - if($name == "twitter:title") { - $mediaInfos['title'] = $meta->getAttribute('content'); - } - elseif($name == "twitter:description") { - $mediaInfos['description'] = $meta->getAttribute('content'); - } - elseif($name == "twitter:image") { - $mediaInfos['image'] = $meta->getAttribute('content'); - } - elseif($name == "description") { - $mediaInfos['description'] = $meta->getAttribute('content'); - } - - } - elseif($meta->getAttribute('itemprop')) { - $itemprop = $meta->getAttribute('itemprop'); - $itemprop = mb_strtolower($itemprop); - - # google plus - if($itemprop == "name") { - $mediaInfos['title'] = $meta->getAttribute('content'); - } - elseif($itemprop == "description") { - $mediaInfos['description'] = $meta->getAttribute('content'); - } - elseif($itemprop == "image") { - $mediaInfos['image'] = $meta->getAttribute('content'); - } - - } - } - - - if(!isset($mediaInfos['title'])) { - $titleDom = $xpath->query('//html/head/title'); - $mediaInfos['title'] = $titleDom->item(0)->nodeValue; - } - - return $mediaInfos; + #http://www.w3bees.com/2013/11/fetch-facebook-og-meta-tags-with-php.html + #http://www.9lessons.info/2014/01/social-meta-tags-for-google-twitter-and.html + #http://ogp.me/ + #https://moz.com/blog/meta-data-templates-123 + + $dom = new DomDocument; + # surpress invalid html warnings + @$dom->loadHTML($string); + + $xpath = new DOMXPath($dom); + $metas = $xpath->query('//*/meta'); + + $mediaInfos = array(); + + # meta tags + foreach($metas as $meta) { + if($meta->getAttribute('property')) { + $prop = $meta->getAttribute('property'); + $prop = mb_strtolower($prop); + + # minimum required information + # http://ogp.me/#metadata + if($prop == "og:title") { + + $mediaInfos['title'] = $meta->getAttribute('content'); + } + elseif($prop == "og:image") { + $mediaInfos['image'] = $meta->getAttribute('content'); + } + elseif($prop == "og:url") { + $mediaInfos['link'] = $meta->getAttribute('content'); + } + elseif($prop == "og:description") { + $mediaInfos['description'] = $meta->getAttribute('content'); + } + } + elseif($meta->getAttribute('name')) { + $name = $meta->getAttribute('name'); + $name = mb_strtolower($name); + + # twitter + # https://dev.twitter.com/cards/overview + + if($name == "twitter:title") { + $mediaInfos['title'] = $meta->getAttribute('content'); + } + elseif($name == "twitter:description") { + $mediaInfos['description'] = $meta->getAttribute('content'); + } + elseif($name == "twitter:image") { + $mediaInfos['image'] = $meta->getAttribute('content'); + } + elseif($name == "description") { + $mediaInfos['description'] = $meta->getAttribute('content'); + } + + } + elseif($meta->getAttribute('itemprop')) { + $itemprop = $meta->getAttribute('itemprop'); + $itemprop = mb_strtolower($itemprop); + + # google plus + if($itemprop == "name") { + $mediaInfos['title'] = $meta->getAttribute('content'); + } + elseif($itemprop == "description") { + $mediaInfos['description'] = $meta->getAttribute('content'); + } + elseif($itemprop == "image") { + $mediaInfos['image'] = $meta->getAttribute('content'); + } + + } + } + + + if(!isset($mediaInfos['title'])) { + $titleDom = $xpath->query('//html/head/title'); + $mediaInfos['title'] = $titleDom->item(0)->nodeValue; + } + + return $mediaInfos; } /** @@ -383,56 +383,56 @@ class Summoner { * @return array */ static function prepareTagOrCategoryStr($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; + $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; } /** * a very simple HTTP_AUTH authentication. */ static function simpleAuth() { - if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) - || $_SERVER['PHP_AUTH_USER'] !== FRONTEND_USERNAME || $_SERVER['PHP_AUTH_PW'] !== FRONTEND_PASSWORD - ) { - header('WWW-Authenticate: Basic realm="Insipid edit area"'); - header('HTTP/1.0 401 Unauthorized'); - echo 'No Access.'; - exit; - } + if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) + || $_SERVER['PHP_AUTH_USER'] !== FRONTEND_USERNAME || $_SERVER['PHP_AUTH_PW'] !== FRONTEND_PASSWORD + ) { + header('WWW-Authenticate: Basic realm="Insipid edit area"'); + header('HTTP/1.0 401 Unauthorized'); + echo 'No Access.'; + exit; + } } /** @@ -444,20 +444,20 @@ class Summoner { * @return array $ret */ static function extractEmailLinks($string) { - $ret = array(); + $ret = array(); - #this matches a valid URL. An URL with | is still valid... - $urlpattern = '#(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#'; + #this matches a valid URL. An URL with | is still valid... + $urlpattern = '#(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#'; - preg_match_all($urlpattern, $string, $matches); - if(isset($matches[0]) && !empty($matches[0])) { - foreach($matches[0] as $match) { - $ret[md5($match)] = $match; - } - } + preg_match_all($urlpattern, $string, $matches); + if(isset($matches[0]) && !empty($matches[0])) { + foreach($matches[0] as $match) { + $ret[md5($match)] = $match; + } + } - return $ret; + return $ret; } } diff --git a/webroot/view/editlink.inc.php b/webroot/view/editlink.inc.php index 4aaa1ad..522106b 100644 --- a/webroot/view/editlink.inc.php +++ b/webroot/view/editlink.inc.php @@ -35,24 +35,24 @@ Summoner::simpleAuth(); $_id = false; if(isset($_GET['id']) && !empty($_GET['id'])) { - $_id = trim($_GET['id']); - $_id = Summoner::validate($_id,'nospace') ? $_id : false; + $_id = trim($_GET['id']); + $_id = Summoner::validate($_id,'nospace') ? $_id : false; } $linkObj = new Link($DB); $linkObj->load($_id); $linkData = $linkObj->getData(); if(empty($linkData)) { - header("HTTP/1.0 404 Not Found"); + header("HTTP/1.0 404 Not Found"); } if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink'])) { - $fData = $_POST['data']; + $fData = $_POST['data']; - $formData['private'] = 2; - if(isset($fData['private'])) { - $formData['private'] = 1; - } + $formData['private'] = 2; + if(isset($fData['private'])) { + $formData['private'] = 1; + } $formData['localImage'] = false; if(isset($fData['localImage'])) { @@ -60,31 +60,31 @@ if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink'])) } - $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']); + $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(!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'; - } + 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'; + } } elseif(isset($_POST['refreshlink'])) { $linkInfo = Summoner::gatherInfoFromURL($linkData['link']); @@ -105,19 +105,19 @@ $formData = $linkData; # prepare the tag string $formData['tag'] = ''; if(!empty($linkData['tags'])) { - foreach($linkData['tags'] as $k=>$v) { - $formData['tag'] .= $v.','; - } - $formData['tag'] = trim($formData['tag']," ,"); + foreach($linkData['tags'] as $k=>$v) { + $formData['tag'] .= $v.','; + } + $formData['tag'] = trim($formData['tag']," ,"); } # prepare the category string $formData['category'] = ''; if(!empty($linkData['categories'])) { - foreach($linkData['categories'] as $k=>$v) { - $formData['category'] .= $v.','; - } - $formData['category'] = trim($formData['category']," ,"); + foreach($linkData['categories'] as $k=>$v) { + $formData['category'] .= $v.','; + } + $formData['category'] = trim($formData['category']," ,"); } $existingCategories = $Management->categories(); diff --git a/webroot/view/editlink.php b/webroot/view/editlink.php index 8152f1a..f3676a2 100644 --- a/webroot/view/editlink.php +++ b/webroot/view/editlink.php @@ -29,45 +29,45 @@
-
-
-
-
Error
-

Something went wrong...

-
-
-
+
+
+
+
Error
+

Something went wrong...

+
+
+
-
-
Error
-

-
+
+
Error
+

+
-
-
Success
-

-
+
+
Success
+

+
-
-

- - - -

-
-
+
+

+ + + +

+
+
-
+

@@ -75,104 +75,104 @@
-
-
-
-

Date added:

-
-
-

+ +

+
+

Date added:

+
+
+

(Last update: )

-
-
-
-
-

Title:

-
-
- -
-
-
-
-

Description:

-
-
- -
-
-
-
-

URL:

-
-
-

-
-
-
-
-

- Image: (If provided) -

-
-
-

- Image if provided... -

-
+
+
+
+
+

Title:

+
+
+ +
+
+
+
+

Description:

+
+
+ +
+
+
+
+

URL:

+
+
+

+
+
+
+
+

+ Image: (If provided) +

+
+
+

+ Image if provided... +

+

/> Store image locally -
-
+
+
-
-
-

Tags:

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

Category:

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

Tags:

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

Category:

+
+
+ + + + + + +
+
+
+
+ + /> +
+
-
-
- +
+
+
diff --git a/webroot/view/home.php b/webroot/view/home.php index ed7b850..404a6e4 100644 --- a/webroot/view/home.php +++ b/webroot/view/home.php @@ -28,27 +28,27 @@ ?>
-
-
-
- - +
+
+ + +
-
-
- - - - -
-
-
- -
-
- -
-
+
+
+ + + + +
+
+
+ +
+
+ +
+
@@ -71,126 +71,126 @@
-
-
-
-

Something has been found...

-
+
+
+
+

Something has been found...

+
- - -
-
+ + +
+
-
-
-
-
+
+
+ +
- - -
-
-
-

This URL was not found. Want to add it?

-
-
-
-
- - - - -
-
-
-
-
+ + +
+
+
+

This URL was not found. Want to add it?

+
+
+
+
+ + + + +
+
+
+
+
-
-
-
- -
- -
-
-
-
-
- -
- -
-
-
-
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
-
-
- Image from provided link -
-
-
- -
- -
-
-
-
+
+
+ Image from provided link +
+
+
+ +
+ +
+
+
+
-
-
- -
- - - - - - -
-
-
- -
- - - - - - -
-
-
+
+
+ +
+ + + + + + +
+
+
+ +
+ + + + + + +
+
+
-
-
- -
-
-
- -
-
-
+
+
+ +
+
+
+ +
+
+
@@ -204,9 +204,9 @@
-
-
-

Last added

+
+
+

Last added

@@ -223,13 +223,13 @@
$v) { - $links = $Management->linksByCategory($v['id'],false); + if(!empty($orderedCategories)) { + foreach ($orderedCategories as $k=>$v) { + $links = $Management->linksByCategory($v['id'],false); ?> -
-
-

+
+
+

@@ -238,8 +238,8 @@
diff --git a/webroot/view/linkinfo.php b/webroot/view/linkinfo.php index 664286e..073bce1 100644 --- a/webroot/view/linkinfo.php +++ b/webroot/view/linkinfo.php @@ -29,30 +29,30 @@
-
-
-
-
Error
-

Something went wrong...

-
-
-
+
+
+
+
Error
+

Something went wrong...

+
+
+
-
-

- - - -

-
-
+
+

+ + + +

+
+
-
+

@@ -68,89 +68,89 @@
-
-

Description:

-
-
-

-
-
-
-
-

URL:

-
-
-

-
-
-
-
-

- Image: (If provided) -

-
-
-

- Image if provided... -

-
-
-
-
-

Date added:

-
-
-

-
-
-
-
-

Tags:

-
-
- $v) { - ?> - - - - - -
-
-
-
-

Category:

-
-
- $v) { - ?> - - - - - -
-
- +
+

Description:

+
+
+

+
+
+
+
+

URL:

+
+
+

+
+
+
+
+

+ Image: (If provided) +

+
+
+

+ Image if provided... +

+
+
+
+
+

Date added:

+
+
+

+
+
+
+
+

Tags:

+
+
+ $v) { + ?> + + + + + +
+
+
+
+

Category:

+
+
+ $v) { + ?> + + + + + +
+
+
diff --git a/webroot/view/overview.php b/webroot/view/overview.php index 540cf49..b52aeda 100644 --- a/webroot/view/overview.php +++ b/webroot/view/overview.php @@ -30,25 +30,25 @@
- -

- + +

+
@@ -60,27 +60,27 @@
-

-

+

+

-
-
+
+ -
+ @@ -104,18 +104,18 @@
- - - - - +
Name# of links
+ + + + $v) { ?> - - - + + + -
Name# of links
+
-- 2.39.5