version 2.7 - Sacred Grove
+ Fixed bug #12. Missing translation key
+ + Adapted some new PHP code formatting
version 2.6 - Hypostyle
https://github.com/PHPMailer/PHPMailer
https://ionicons.com/
https://github.com/ifsnop/mysqldump-php
+shellcommand by Michael Härtl <haertl.mike@gmail.com>
TODO / Feature list
-+ adapt new php 7
-++ http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
+ view table really still needed?
+ stats cleanup. Management functions should be standalone
+ theme support
+ more "secure" user authentication
++ multiple user accounts and stuff
-+ combine cat and tag class into one.
++ combine category and tag class into one.
* by given string load the info from the DB and even create if not existing
*
* @param string $string
- * @return int 0=fail, 1=existing, 2=new, 3=newNotCreated
- * @return bool|int
+ * @param bool $doNotCreate
+ * @return int 0=fail, 1=existing, 2=new, 3=newNotCreated
*/
- public function initbystring($string, $doNotCreate=false) {
+ public function initbystring(string $string, $doNotCreate=false): int {
$ret = 0;
$this->_id = false;
if(!empty($string)) {
/**
* by given DB table id load all the info we need
+ *
* @param int $id
- * @return mixed
+ * @return integer
*/
- public function initbyid($id) {
- $this->_id = false;
+ public function initbyid(int $id): int {
+ $this->_id = 0;
if(!empty($id)) {
$queryStr = "SELECT id,name
/**
* return all or data fpr given key on the current loaded tag
+ *
* @param bool $key
- * @return array|mixed
+ * @return array
*/
- public function getData($key=false) {
+ public function getData($key=false): array {
$ret = $this->_data;
if(!empty($key) && isset($this->_data[$key])) {
/**
* set the relation to the given link to the loaded category
- * @param int $linkid
+ *
+ * @param integer $linkid
* @return void
*/
- public function setRelation($linkid) {
+ public function setRelation(int $linkid) {
if(!empty($linkid) && !empty($this->_id)) {
$queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_categoryrelation`
SET `linkid` = '".$this->DB->real_escape_string($linkid)."',
/**
* Return an array of any linkid related to the current loaded category
+ *
* @return array
*/
- public function getReleations() {
+ public function getRelations(): array {
$ret = array();
$queryStr = "SELECT linkid
/**
* deletes the current loaded category from db
+ *
* @return boolean
*/
- public function delete() {
+ public function delete(): bool {
$ret = false;
if(!empty($this->_id)) {
return $ret;
}
- /**
- * Rename current loaded cat name
- * @param $newValue
- * @return void
- */
- public function rename($newValue) {
+ /**
+ * Rename current loaded cat name
+ *
+ * @param string $newValue
+ * @return void
+ */
+ public function rename(string $newValue) {
if(!empty($newValue)) {
$queryStr = "UPDATE `".DB_PREFIX."_category`
SET `name` = '".$this->DB->real_escape_string($newValue)."'
* Insipid
* Personal web-bookmark-system
*
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
*
* Development starting from 2011: Johannes Keßler
* https://www.bananas-playground.net/projekt/insipid/
* @param string $string
* @return array $ret
*/
- static function extractEmailLinks($string) {
+ static function extractEmailLinks(string $string): array {
$ret = array();
#this matches a valid URL. An URL with | is still valid...
/**
* Check if given from is in the valid EMAIL_REPLY_BACK_VALID
- * @param $replyto
+ *
+ * @param string $replyTo
* @return bool
*/
- static function canSendReplyTo($replyto) {
+ static function canSendReplyTo(string $replyTo): bool {
if(defined("EMAIL_REPORT_BACK") && EMAIL_REPORT_BACK === true
&& defined("EMAIL_REPLY_BACK_VALID") && !empty(EMAIL_REPLY_BACK_VALID)) {
- if(strstr($replyto,EMAIL_REPLY_BACK_VALID)) {
+ if(strstr($replyTo,EMAIL_REPLY_BACK_VALID)) {
return true;
}
}
*
* this does not really quality check the values. It just checks if some headers are set
*
- * @param $headers complete email headers as an array
+ * @param array $headers complete email headers as an array
* @return bool
*/
- static function isAutoReplyMessage($headers) {
+ static function isAutoReplyMessage(array $headers): bool {
if(empty($headers)) {
return true;
}
* Insipid
* Personal web-bookmark-system
*
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
*
* Development starting from 2011: Johannes Keßler
* https://www.bananas-playground.net/projekt/insipid/
class ImportExport {
/**
- * @var String The current memory xmlwriter
+ * @var XMLWriter The current memory xmlwriter
*/
private $_currentXW;
/**
* create a xml file for a given single link
* expects the array from Link->load
+ *
* @param array $data
* @return string XML string from xmlwriter
*/
- public function createSingleLinkExportXML($data) {
+ public function createSingleLinkExportXML(array $data): string {
$this->_currentXW = xmlwriter_open_memory();
xmlwriter_set_indent($this->_currentXW, 1);
}
/**
- * @param $file array $_FILES array. Just check if everything is there
- * and put it into _uploadedData
+ * Just check if everything is there and put it into _uploadedData
+ *
+ * @param array $file $_FILES array.
* @throws Exception
+ * @return void
*/
- public function loadImportFile($file) {
+ public function loadImportFile(array $file) {
if(!isset($file['name'])
|| !isset($file['type'])
/**
* parse the data from _uploadedData and create an array we can use
+ *
* @return array
* @throws Exception
*/
- public function parseImportFile() {
+ public function parseImportFile(): array {
$ret = array();
if(!empty($this->_uploadedData)) {
/**
* Create a single xml element for the current loaded xmlwriter
+ *
* @param String $name
* @param String $key
* @param String $value
+ * @return void
*/
- private function _elementFromKeyValue($name, $key, $value) {
+ private function _elementFromKeyValue(string $name, string $key, string $value) {
if(!empty($key) && !empty($value) && !empty($name)) {
xmlwriter_start_element($this->_currentXW, $name);
/**
* validate an import of a export xml with the
* saved xsd file _xmlImportXSD
+ *
* @return bool|string
*/
private function _validateXMLImport() {
/**
* Reads libxml_get_errors and creates a simple string with all
* the info we need.
+ *
* @return string
*/
- private function _xmlErrors() {
+ private function _xmlErrors(): string {
$errors = libxml_get_errors();
$result = array();
foreach ($errors as $error) {
*
*/
+/**
+ * Class Link
+ */
class Link {
/**
* the database object
- * @var object
+ *
+ * @var Object
*/
private $DB;
/**
* the current loaded link data
+ *
* @var array
*/
private $_data;
+ /**
+ * Link constructor.
+ *
+ * @param Object $databaseConnectionObject
+ * @return void
+ */
public function __construct($databaseConnectionObject) {
$this->DB = $databaseConnectionObject;
}
/**
* load all the info we have about a link by given hash
+ *
* @param string $hash
- * @return mixed
+ * @return array
*/
- public function load($hash) {
+ public function load(string $hash): array {
$this->_data = array();
* loads only the info needed to display the link
* for edit use $this->load
*
- * @param $hash
+ * @param string $hash
* @return array
*/
- public function loadShortInfo($hash) {
+ public function loadShortInfo(string $hash): array {
$this->_data = array();
if (!empty($hash)) {
return $this->_data;
}
- public function loadFromDataShortInfo($data) {
+ /**
+ * Get shortinfo from given data array
+ *
+ * @param array $data
+ * @return array
+ */
+ public function loadFromDataShortInfo(array $data): array {
$this->_data = array();
if(isset($data['id']) && isset($data['link']) && isset($data['created']) && isset($data['status'])
* @param bool $key
* @return array|mixed
*/
- public function getData($key = false) {
+ public function getData($key = false): array {
$ret = $this->_data;
if (!empty($key) && isset($this->_data[$key])) {
/**
* reload the current id from DB
+ *
+ * @return void
*/
public function reload() {
$this->load($this->_data['hash']);
}
- /**
- * create a new link with the given data
- * @param array $data
- * @param bool $returnId
- * @return boolean|int
- */
- public function create($data, $returnId = false) {
- $ret = false;
+ /**
+ * create a new link with the given data
+ *
+ * @param array $data
+ * @param bool $returnId
+ * @return int
+ */
+ public function create(array $data, $returnId = false): int {
+ $ret = 0;
- if (!isset($data['link']) || empty($data['link'])) return false;
- if (!isset($data['hash']) || empty($data['hash'])) return false;
- if (!isset($data['title']) || empty($data['title'])) return false;
+ if (!isset($data['link']) || empty($data['link'])) return $ret;
+ if (!isset($data['hash']) || empty($data['hash'])) return $ret;
+ if (!isset($data['title']) || empty($data['title'])) return $ret;
$_t = parse_url($data['link']);
$data['search'] = $data['title'];
$ret = $this->DB->insert_id;
}
else {
- error_log('ERROR Failed to rcreate link: '.var_export($data,true));
+ error_log('ERROR Failed to create link: '.var_export($data,true));
}
return $ret;
* update the current loaded link with the given data
*
* @param array $data
- * @return boolean|int
+ * @return boolean
*/
- public function update($data) {
+ public function update(array $data): bool {
$ret = false;
/**
* call this to delete all the relations to this link.
* To completely remove the link use Management->deleteLink()
+ *
+ * @return void
*/
public function deleteRelations() {
$this->_removeTagRelation(false);
/**
* load all the tags we have to the already loaded link
* needs $this->load called first
+ *
+ * @return void
*/
private function _tags() {
$ret = array();
/**
* load all the categories we have to the already loaded link
* needs $this->load called first
+ *
+ * @return void
*/
private function _categories() {
$ret = array();
/**
* remove all or given tag relation to the current loaded link
- * @param mixed $tagid
+ *
+ * @param boolean|integer $tagid
+ * @return void
*/
private function _removeTagRelation($tagid) {
if (!empty($this->_data['id'])) {
/**
* remove all or given category relation to the current loaded link
- * @param mixed $categoryid
+ *
+ * @param boolean|integer $categoryid
+ * @return void
*/
private function _removeCategoryRelation($categoryid) {
if (!empty($this->_data['id'])) {
/**
* determine of we have a local stored image
* if so populate the localImage attribute
+ *
+ * @return void
*/
private function _image() {
if (!empty($this->_data['hash'])) {
/**
* determine if we have a local stored snapshot
* if so populate the snapshotLink attribute
+ *
+ * @return void
*/
private function _snapshot() {
if (!empty($this->_data['hash'])) {
/**
* determine if we have a local full page screenshot
* if so populate the pagescreenshotLink attribute
+ *
+ * @return void
*/
private function _pageScreenshot() {
if (!empty($this->_data['hash'])) {
/**
* remove the local stored image
+ *
+ * @return void
*/
private function _deleteImage() {
if (!empty($this->_data['hash']) && !empty($this->_data['imageToShow'])) {
/**
* remove the local stored snapshot
+ *
+ * @return void
*/
private function _deleteSnapshot() {
if (!empty($this->_data['hash']) && !empty($this->_data['snapshotLink'])) {
/**
* remove the local stored pagescreenshot
+ *
+ * @return void
*/
private function _deletePageScreenshot() {
if (!empty($this->_data['hash']) && !empty($this->_data['pagescreenshotLink'])) {
/**
* check if the status is private and set the info
+ *
+ * @return void
*/
private function _private() {
if (!empty($this->_data['status']) && $this->_data['status'] == "1") {
*
*/
+/**
+ * Class Management
+ */
class Management {
const LINK_QUERY_STATUS = 2;
/**
* the database object
+ *
* @var object
*/
private $DB;
/**
* Type of links based on status to show
+ *
* @var bool
*/
private $_queryStatus = self::LINK_QUERY_STATUS;
-
+ /**
+ * Management constructor.
+ *
+ * @param Object $databaseConnectionObject
+ * @return void
+ */
public function __construct($databaseConnectionObject) {
$this->DB = $databaseConnectionObject;
}
/**
* Show private links or not
- * @param $bool
+ *
+ * @param boolean $bool
+ * @return void
*/
- public function setShowPrivate($bool) {
+ public function setShowPrivate(bool $bool) {
$this->_queryStatus = self::LINK_QUERY_STATUS;
if($bool === true) {
$this->_queryStatus = 1;
/**
* Show awaiting moderation links or not
- * @param $bool
+ *
+ * @param boolean $bool
+ * @return void
*/
- public function setShowAwm($bool) {
+ public function setShowAwm(bool $bool) {
$this->_queryStatus = self::LINK_QUERY_STATUS;
if($bool === true) {
$this->_queryStatus = 3;
* get all the available categories from the DB.
* optional limit
* optional stats
- * @param bool | int $limit
+ *
+ * @param bool|int $limit
* @param bool $stats
* @return array
*/
- public function categories($limit=false, $stats=false) {
+ public function categories($limit=false, $stats=false): array {
$ret = array();
$statsInfo = array();
* get all the available tags from the DB.
* optional limit
* optional stats
- * @param bool | int $limit
+ *
+ * @param bool|int $limit
* @param bool $stats
* @return array
*/
- public function tags($limit=false, $stats=false) {
+ public function tags($limit=false, $stats=false): array {
$ret = array();
$statsInfo = array();
/**
* return the latest added links
+ *
* @param int $limit
* @return array
*/
- public function latestLinks($limit=5) {
+ public function latestLinks($limit=5): array {
$ret = array();
$queryStr = "SELECT `title`, `link` FROM `".DB_PREFIX."_link` AS t";
/**
* get all the categories ordered by link added date
+ *
+ * @return array
*/
- public function categoriesByDateAdded() {
+ public function categoriesByDateAdded(): array {
$ret = array();
$categories = $this->categories();
return $ret;
}
- /**
- * find all links by given category string or id.
- * Return array sorted by creation date DESC
+ /**
+ * find all links by given category string or id.
+ * Return array sorted by creation date DESC
*
- * @param int $id Category ID
- * @param array $options Array with limit|offset|sort|sortDirection
- * @return array
- */
- public function linksByCategory($id, $options=array()) {
+ * @param int $id Category ID
+ * @param array $options Array with limit|offset|sort|sortDirection
+ * @return array
+ */
+ public function linksByCategory(int $id, $options=array()): array {
$ret = array();
if(!isset($options['limit'])) $options['limit'] = 5;
return $ret;
}
- /**
- * find all links by given tag string or id.
- * Return array sorted by creation date DESC
+ /**
+ * find all links by given tag string or id.
+ * Return array sorted by creation date DESC
*
- * @param int $id Tag id
- * @param array $options Array with limit|offset|sort|sortDirection
- * @return array
- */
- public function linksByTag($id, $options=array()) {
+ * @param int $id Tag id
+ * @param array $options Array with limit|offset|sort|sortDirection
+ * @return array
+ */
+ public function linksByTag(int $id, $options=array()): array {
$ret = array();
if(!isset($options['limit'])) $options['limit'] = 5;
/**
* return all links and Info we have from the combined view
- * @param bool | int $limit
+ *
+ * @param bool|int $limit
* @param bool $offset
* @return array
*/
- public function links($limit=10,$offset=false) {
+ public function links($limit=10,$offset=false): array {
$ret = array();
$querySelect = "SELECT `hash`";
* @param int $categoryid
* @return array
*/
- public function latestLinkForCategory($categoryid) {
+ public function latestLinkForCategory(int $categoryid): array {
$ret = array();
if(!empty($categoryid) && is_numeric($categoryid)) {
/**
* Search for the given url in the links table
- * @param $url
- * @return mixed
+ *
+ * @param string $url
+ * @return array
*/
- public function searchForLinkByURL($url) {
- $ret = false;
+ public function searchForLinkByURL(string $url): array {
+ $ret = array();
if(!empty($url)) {
$queryStr = "SELECT * FROM `".DB_PREFIX."_link` AS t";
/**
* search for given searchstring in the search data of the links
- * @param $searchStr
- * @return mixed
+ *
+ * @param string $searchStr
+ * @return array
*/
- public function searchForLinkBySearchData($searchStr) {
- $ret = false;
+ public function searchForLinkBySearchData(string $searchStr): array {
+ $ret = array();
if(!empty($searchStr)) {
$queryStr = "SELECT *,
/**
* amount of links in the DB. Status 1 and 2 only
+ *
* @return int
*/
- public function linkAmount() {
+ public function linkAmount(): int {
$ret = 0;
$queryStr = "SELECT COUNT(*) AS amount
/**
* amount of tags
+ *
* @return int
*/
- public function tagAmount() {
+ public function tagAmount(): int {
$ret = 0;
$queryStr = "SELECT COUNT(*) AS amount FROM `".DB_PREFIX."_tag`";
/**
* amount of categories
+ *
* @return int
*/
- public function categoryAmount() {
+ public function categoryAmount(): int {
$ret = 0;
$queryStr = "SELECT COUNT(*) AS amount FROM `".DB_PREFIX."_category`";
/**
* Amount of links need moderation
+ *
* @return int
*/
- public function moderationAmount() {
+ public function moderationAmount(): int {
$ret = 0;
$queryStr = "SELECT COUNT(*) AS amount FROM `".DB_PREFIX."_link`";
/**
* get the used disk space for local image storage
- * @return false|int
+ *
+ * @return int
*/
- public function storageAmount() {
+ public function storageAmount(): int {
$ret = 0;
$_storageFolder = ABSOLUTE_PATH.'/'.LOCAL_STORAGE;
/**
* empties the local storage directory
+ *
* @return bool
*/
- public function clearLocalStorage() {
+ public function clearLocalStorage(): bool {
$ret = false;
$_storageFolder = ABSOLUTE_PATH.'/'.LOCAL_STORAGE;
/**
* Load link by given hash. Do not use Link class directly.
* Otherwise the authentication will be ignored.
- * @param String $hash Link hash
+ *
+ * @param String $hash Link hash
* @param bool $fullInfo Load all the info we have
* @param bool $withObject An array with data and the link obj itself
- * @return array|mixed
+ * @return array
*/
- public function loadLink($hash,$fullInfo=true,$withObject=false) {
+ public function loadLink(string $hash, $fullInfo=true, $withObject=false): array {
$ret = array();
if (!empty($hash)) {
/**
* Delete link by given hash
- * @param $hash
+ *
+ * @param string $hash
* @return bool
*/
- public function deleteLink($hash) {
+ public function deleteLink(string $hash): bool {
$ret = false;
if (!empty($hash)) {
/**
* Export given link for download as a xml file
- * @param $hash
- * @param bool $linkObj Use already existing link obj
+ *
+ * @param string $hash
+ * @param bool|Link $linkObj Use already existing link obj
* @return bool
*/
- public function exportLinkData($hash,$linkObj=false) {
+ public function exportLinkData(string $hash, $linkObj=false): bool {
$ret = false;
if (!empty($hash)) {
/**
* for simpler management we have the search data in a separate column
* it is not fancy or even technical nice but it damn works
+ *
+ * @return boolean
*/
- public function updateSearchIndex() {
+ public function updateSearchIndex(): bool {
$ret = false;
$allLinks = array();
/**
* process the given xml file. Based on the export file
* options are overwrite => true|false
- * @param $file
- * @param $options
+ *
+ * @param string $file
+ * @param array $options
* @return array
*/
- public function processImportFile($file, $options) {
+ public function processImportFile(string $file, array $options): array {
$ret = array(
'status' => 'error',
'message' => 'Processing error'
/**
* Return the query string for the correct status type
+ *
* @return string
*/
- private function _decideLinkTypeForQuery() {
+ private function _decideLinkTypeForQuery(): string {
switch ($this->_queryStatus) {
case 1:
$ret = "t.status IN (2,1)";
/**
* Check if given id (not hash) exists in link database
- * @param $id
+ *
+ * @param integer $id
* @return bool
*/
- private function _linkExistsById($id) {
+ private function _linkExistsById($id): bool {
$ret = false;
if(!empty($id)) {
* Insipid
* Personal web-bookmark-system
*
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
*
* Development starting from 2011: Johannes Keßler
* https://www.bananas-playground.net/projekt/insipid/
private $_connectionstring = '';
+ /**
+ * SimpleImap constructor.
+ */
function __construct() {
# create the mailboxstring
$this->_connectionstring = '{'.$this->_server.':'.$this->_port.'/imap/ssl}';
}
+ /**
+ *
+ */
function __destruct() {
imap_close($this->_connection);
}
/**
* process the given mailbox and check for the special messages
* return the body and headers from the found message
+ *
* @param string $subjectmarker
* @return array emailId => array(body, header);
* @throws Exception
*/
- function messageWithValidSubject($subjectmarker) {
+ function messageWithValidSubject(string $subjectmarker): array {
$ret = array();
$messagecount = imap_num_msg($this->_connection);
/**
* This function causes a fetch of the complete, unfiltered RFC2822 format header of the specified message.
- * @param $messagenum Int
+ *
+ * @param integer $messagenum
* @return string
*/
- public function emailHeaders($messagenum) {
+ public function emailHeaders(int $messagenum): string {
return imap_fetchheader($this->_connection, $messagenum);
}
/**
* return the email headers by given emailid
- * @param $messagenum
+ *
+ * @param integer $messagenum
* @return object
*/
- public function emailHeaders_rfc822($messagenum) {
+ public function emailHeaders_rfc822(int $messagenum) {
return imap_rfc822_parse_headers($this->emailHeaders($messagenum));
}
/**
* Email headers parsed as an array
- * @param $messagenum
+ *
+ * @param integer $messagenum
* @return array
*/
- public function emailHeadersAsArray($messagenum) {
+ public function emailHeadersAsArray(int $messagenum): array {
preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $this->emailHeaders($messagenum), $matches );
return array_combine( $matches[1], $matches[2]);
}
- /**
- * Move given message to given folder
- * @param $messageUid This is the message Uid as an int
- * @param string $folder This is the target folder. Default is EMAIL_ARCHIVE_FOLDER
- */
- public function moveMessage($messageUid,$folder=EMAIL_ARCHIVE_FOLDER) {
+ /**
+ * Move given message to given folder
+ *
+ * @param integer $messageUid This is the message Uid as an int
+ * @param string $folder This is the target folder. Default is EMAIL_ARCHIVE_FOLDER
+ */
+ public function moveMessage(int $messageUid, $folder=EMAIL_ARCHIVE_FOLDER) {
if(!empty($messageUid) && !empty($folder)) {
$messageUid = (string)$messageUid;
imap_setflag_full($this->_connection,$messageUid,"\SEEN", ST_UID);
* @param int $messagenum
* @return string
*/
- private function _extractSubject($messagenum) {
+ private function _extractSubject(int $messagenum): string {
$ret = '';
$headerinfo = $this->emailHeaders_rfc822($messagenum);
/**
* extract the body of the given message
+ *
* @see http://php.net/manual/en/function.imap-fetchstructure.php
*
* @param int $messagenum
* @return string
*/
- private function _extractBody($messagenum) {
+ private function _extractBody(int $messagenum): string {
$ret = '';
$emailstructure = imap_fetchstructure($this->_connection, $messagenum);
* Insipid
* Personal web-bookmark-system
*
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
*
* Development starting from 2011: Johannes Keßler
* https://www.bananas-playground.net/projekt/insipid/
* right now it uses google pagespeedonline.
*/
class Snapshot {
+ /**
+ * @var string
+ */
private $_googlePageSpeed = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=';
+
+ /**
+ * @var string
+ */
private $_wkhtmltoimageOptions = '--load-error-handling ignore --quality 80 --quiet --width 1900';
+ /**
+ * Snapshot constructor
+ */
public function __constructor() {}
/**
* call given url with google PageSpeed API
- * to recieve image data
+ * to receive image data
*
* @param String $url URL to take a thumbnail from
- * @return
+ * @param string $filename
+ * @return boolean
*/
- public function doSnapshot($url,$filename) {
+ public function doSnapshot(string $url, string $filename): bool {
$ret = false;
if(!empty($url) && is_writable(dirname($filename))) {
}
/**
- * use configired WKHTMLTOPDF_COMMAND to create a whole page screenshot
+ * use configured WKHTMLTOPDF_COMMAND to create a whole page screenshot
* of the given link and store it locally
*
* @param String $url URL to take the screenshot from
- * @return
+ * @param string $filename
+ * @return boolean
*/
- public function wholePageSnpashot($url,$filename) {
+ public function wholePageSnpashot(string $url, string $filename): bool {
$ret = false;
require_once 'lib/shellcommand.class.php';
return $ret;
}
-}
\ No newline at end of file
+}
* Insipid
* Personal web-bookmark-system
*
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
*
* Development starting from 2011: Johannes Keßler
* https://www.bananas-playground.net/projekt/insipid/
*
* @return bool
*/
- static function validate($input,$mode='text',$limit=false) {
+ static function validate($input,$mode='text',$limit=false): bool {
// check if we have input
$input = trim($input);
/**
* execute a curl call to the given $url
+ *
* @param string $url The request url
* @param bool $port
- * @return bool|mixed
+ * @return string
*/
- static function curlCall($url,$port=false) {
- $ret = false;
+ static function curlCall(string $url, $port=false): string {
+ $ret = '';
$ch = curl_init();
/**
* Download given url to given file
- * @param $url
- * @param $whereToStore
+ *
+ * @param string $url
+ * @param string $whereToStore
* @param bool $port
* @return bool
*/
- static function downloadFile($url, $whereToStore, $port=false) {
+ static function downloadFile(string $url, string $whereToStore, $port=false): bool {
$fh = fopen($whereToStore, 'w+');
$ret = false;
* 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
*
- * @param $array
- * @param $key
+ * @param array $array
+ * @param string $key
* @return bool
*/
- static function ifset($array,$key) {
+ static function ifset(array $array, string $key): bool {
return isset($array[$key]) ? $array[$key] : false;
}
/**
* try to gather meta information from given URL
+ *
* @param string $url
- * @return array|bool
+ * @return array
*/
- static function gatherInfoFromURL($url) {
- $ret = false;
+ static function gatherInfoFromURL(string $url): array {
+ $ret = array();
if(self::validate($url,'url')) {
$data = self::curlCall($url);
/**
* get as much as possible social meta infos from given string
* the string is usually a HTML source
+ *
* @param string $string
* @return array
*/
- static function socialMetaInfos($string) {
+ static function socialMetaInfos(string $string): array {
#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/
* @param string $string
* @return array
*/
- static function prepareTagOrCategoryStr($string) {
+ static function prepareTagOrCategoryStr(string $string): array {
$ret = array();
$_ret = array();
/**
* check if we have a valid auth. Nothing more.
+ *
* @see Summoner::simpleAuth to trigger the auth
* @return bool
*/
- static function simpleAuthCheck() {
+ static function simpleAuthCheck(): bool {
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])
&& $_SERVER['PHP_AUTH_USER'] === FRONTEND_USERNAME && $_SERVER['PHP_AUTH_PW'] === FRONTEND_PASSWORD
) {
/**
* Checks if in the given urlstring a scheme is existent. If not add http:// to it
- * @param $urlString
+ *
+ * @param string $urlString
* @return string
*/
- static function addSchemeToURL($urlString) {
+ static function addSchemeToURL($urlString): string {
$ret = $urlString;
if(empty(parse_url($ret, PHP_URL_SCHEME))) {
return $ret;
}
- /**
- * retrieve the folder size with its children of given folder path
- * @param $folder
- * @return false|int
- */
- static function folderSize($folder) {
+ /**
+ * retrieve the folder size with its children of given folder path
+ *
+ * @param string $folder
+ * @return int
+ */
+ static function folderSize(string $folder): int {
$ret = 0;
if(file_exists($folder) && is_readable($folder)) {
return $ret;
}
- /**
- * Calculate the given byte size in more human readable format.
- * @param $size
- * @param string $unit
- * @return string
- */
- static function humanFileSize($size,$unit="") {
+ /**
+ * Calculate the given byte size in more human readable format.
+ *
+ * @param integer $size
+ * @param string $unit
+ * @return string
+ */
+ static function humanFileSize(int $size, $unit=""): string {
$ret = number_format($size)." bytes";
if((!$unit && $size >= 1<<30) || $unit == "GB") {
return $ret;
}
- /**
- * delete and/or empty a directory
- *
- * $empty = true => empty the directory but do not delete it
- *
- * @param string $directory
- * @param boolean $empty
- * @param int $fTime If not false remove files older then this value in sec.
- * @return boolean
- */
- static function recursive_remove_directory($directory,$empty=false,$fTime=0) {
+ /**
+ * delete and/or empty a directory
+ *
+ * $empty = true => empty the directory but do not delete it
+ *
+ * @param string $directory
+ * @param boolean $empty
+ * @param int $fTime If not false remove files older then this value in sec.
+ * @return boolean
+ */
+ static function recursive_remove_directory(string $directory, $empty=false, $fTime=0): bool {
if(substr($directory,-1) == '/') {
$directory = substr($directory,0,-1);
}
}
}
- /**
- * http_build_query with modify array
- * modify will add: key AND value not empty
- * modify will remove: only key with no value
- *
- * @param $array
- * @param bool $modify
- * @return string
- */
- static function createFromParameterLinkQuery($array,$modify=false) {
+ /**
+ * http_build_query with modify array
+ * modify will add: key AND value not empty
+ * modify will remove: only key with no value
+ *
+ * @param array $array
+ * @param bool $modify
+ * @return string
+ */
+ static function createFromParameterLinkQuery(array $array, $modify=false): string {
$ret = '';
if(!empty($modify)) {
* Insipid
* Personal web-bookmark-system
*
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
*
* Development starting from 2011: Johannes Keßler
* https://www.bananas-playground.net/projekt/insipid/
*
*/
+/**
+ * Class Tag
+ */
class Tag {
/**
* the database object
+ *
* @var object
*/
private $DB;
/**
* the current loaded tag by DB id
+ *
* @var int
*/
private $_id;
/**
* current loaded tag data
+ *
* @var array
*/
private $_data;
+ /**
+ * Tag constructor.
+ *
+ * @param Obnject $databaseConnectionObject
+ */
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 int 0=fail, 1=existing, 2=new, 3=newNotCreated
- */
- public function initbystring($string, $doNotCreate=false) {
+ /**
+ * by given string load the info from the DB and even create if not existing
+ *
+ * @param string $string
+ * @param bool $doNotCreate
+ * @return int 0=fail, 1=existing, 2=new, 3=newNotCreated
+ */
+ public function initbystring(string $string, $doNotCreate=false): int {
$ret = 0;
$this->_id = false;
if(!empty($string)) {
/**
* by given DB table id load all the info we need
+ *
* @param int $id
- * @return bool|int
+ * @return int
*/
- public function initbyid($id) {
- $this->_id = false;
+ public function initbyid(int $id): int {
+ $this->_id = 0;
if(!empty($id)) {
$queryStr = "SELECT `id`,`name` FROM `".DB_PREFIX."_tag`
/**
* return all or data fpr given key on the current loaded tag
+ *
* @param bool $key
- * @return array|mixed
+ * @return array|string
*/
public function getData($key=false) {
$ret = $this->_data;
return $ret;
}
- /**
- * set the relation to the given link to the loaded tag
- * @param int $linkid
- * @return void
- */
- public function setRelation($linkid) {
+ /**
+ * set the relation to the given link to the loaded tag
+ *
+ * @param int $linkid
+ * @return void
+ */
+ public function setRelation(int $linkid) {
if(!empty($linkid) && !empty($this->_id)) {
$queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_tagrelation`
SET `linkid` = '".$this->DB->real_escape_string($linkid)."',
/**
* Return an array of any linkid related to the current loaded tag
+ *
* @return array
*/
- public function getReleations() {
+ public function getReleations(): array {
$ret = array();
$queryStr = "SELECT linkid
/**
* deletes the current loaded tag from db
+ *
* @return boolean
*/
- public function delete() {
+ public function delete(): bool {
$ret = false;
if(!empty($this->_id)) {
return $ret;
}
- /**
- * Rename current loaded tag name
- * @param $newValue
- * @return void
- */
- public function rename($newValue) {
+ /**
+ * Rename current loaded tag name
+ *
+ * @param string $newValue
+ * @return void
+ */
+ public function rename(string $newValue) {
if(!empty($newValue)) {
$queryStr = "UPDATE `".DB_PREFIX."_tag`
SET `name` = '".$this->DB->real_escape_string($newValue)."'
*/
private $_langData = array();
+ /**
+ * Translation constructor.
+ */
public function __construct() {
$_langFile = ABSOLUTE_PATH.'/lib/lang/'.$this->_defaultLangToUse.'.lang.ini';
if(defined('FRONTEND_LANGUAGE')) {
/**
* Return text for given key for currently loaded lang
*
- * @param $key
+ * @param string $key
* @return string
*/
- public function t($key) {
+ public function t(string $key): string {
$ret = $key;
if(isset($this->_langData[$key])) {
$ret = $this->_langData[$key];
* Insipid
* Personal web-bookmark-system
*
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
*
* Development starting from 2011: Johannes Keßler
* https://www.bananas-playground.net/projekt/insipid/
$catDoNotDeleteFromUpdate[$catObjAlternative->getData('id')] = $catObjAlternative->getData('id');
$catObjOld = new Category($DB);
if(!empty($catObjOld->initbyid($k))) {
- $linksToUpdate = $catObjOld->getReleations();
+ $linksToUpdate = $catObjOld->getRelations();
if(!empty($linksToUpdate)) {
foreach($linksToUpdate as $linkId) {
$catObjAlternative->setRelation($linkId);
if($v == "delete" && !isset($catDoNotDeleteFromUpdate[$k])) {
$catObj = new Category($DB);
$load = $catObj->initbyid($k);
- if($load !== false) {
+ if(!empty($load)) {
$catObj->delete();
}
else {