}
.linkthumbnail {
- max-height: 200px;
+ height: 230px;
+ object-fit: cover;
+ width: 306px;
}
h4 a {
.card {
border-top: 1px solid #cccccc;
-}
\ 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
+define('DB_PREFIX','insipid'); # a _ is added automatically as separation
# user config
define('FRONTEND_USERNAME','luke');
define('FRONTEND_PASSWORD','father');
+# absolute path of webroot
+define('ABSOLUTE_PATH', '/home/banana/code/insipid/webroot');
+# relative to absolute path the name of the storage folder
+define('LOCAL_STORAGE', 'localdata');
+
# complete restricted access not only the private links or the edit functions
# username and password see above
define("USE_PAGE_AUTH",false);
define('EMAIL_SERVER_PASS','');
define('EMAIL_SERVER_PORT',993);
define('EMAIL_SERVER_MAILBOX','INBOX'); # default INBOX
-define('EMAIL_MARKER','to-insipid- ');
\ No newline at end of file
+define('EMAIL_MARKER','to-insipid- ');
* @return mixed
*/
public function load($hash) {
- $ret = false;
$this->_data = array();
WHERE `hash` = '".$this->DB->real_escape_string($hash)."'";
$query = $this->DB->query($queryStr);
if(!empty($query) && $query->num_rows == 1) {
- $ret = $query->fetch_assoc();
-
- $this->_data = $ret;
+ $this->_data = $query->fetch_assoc();
# add stuff
$this->_tags();
$this->_categories();
+ $this->_image();
}
}
$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'])."',
}
}
+ # decide to store or remove the image
+ if(isset($data['localImage'])) {
+ $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);
+ }
+ }
+ }
+
$ret = true;
}
}
}
}
+
+ /**
+ * determine of we have a local stored image
+ * if so populate the localImage attribute
+ */
+ private function _image() {
+ if(!empty($this->_data['hash'])) {
+ $this->_data['imageToShow'] = $this->_data['image'];
+ $image = ABSOLUTE_PATH.'/'.LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash'];
+ if(file_exists($image)) {
+ $this->_data['imageToShow'] = LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash'];
+ $this->_data['localImage'] = true;
+ }
+ }
+ }
}
- ?>
+
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
+ curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0');
+ // curl_setopt($ch, CURLOPT_VERBOSE, true);
//curl_setopt($ch, CURLOPT_HEADER, true);
if(!empty($port)) {
return $ret;
}
+ /**
+ * Download given url to given file
+ * @param $url
+ * @param $whereToStore
+ * @param bool $port
+ * @return bool
+ */
+ static function downloadFile($url, $whereToStore, $port=false) {
+ $fh = fopen($whereToStore, 'w+');
+
+ $ret = false;
+
+ if($fh !== false) {
+ $ch = curl_init($url);
+ curl_setopt($ch, CURLOPT_FILE, $fh);
+
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
+ curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0');
+
+ if(!empty($port)) {
+ curl_setopt($ch, CURLOPT_PORT, $port);
+ }
+ curl_exec($ch);
+ curl_close($ch);
+
+ $ret = true;
+ }
+
+ fclose($fh);
+
+ return $ret;
+ }
+
/**
* check if a string starts with a given string
*
--- /dev/null
+*
+!.gitignore
$formData['private'] = 1;
}
+ $formData['localImage'] = false;
+ if(isset($fData['localImage'])) {
+ $formData['localImage'] = true;
+ }
+
+
$formData['description'] = trim($fData['description']);
$formData['title'] = trim($fData['title']);
$formData['image'] = trim($fData['image']);
</div>
<div class="column">
<p>
- <img class="linkthumbnail" src="<?php echo $linkData['image']; ?>" alt="Image if provided...">
+ <img class="linkthumbnail" src="<?php echo $linkData['imageToShow']; ?>" alt="Image if provided...">
</p>
- <input class="input" type="text" name="data[image]" value="<?php echo Summoner::ifset($formData, 'image'); ?>" />
+ <input class="input" type="text" name="data[image]" value="<?php echo Summoner::ifset($formData, 'image'); ?>" /><br />
+ <br />
+ <input class="checkbox" type="checkbox" name="data[localImage]" value="1" <?php if(Summoner::ifset($formData, 'localImage')) echo "checked"; ?> />
+ Store image locally
</div>
</div>
<div class="columns">
<div class="column is-half">
- <img class="linkthumbnail" src="<?php echo Summoner::ifset($formData, 'image'); ?>" alt="Image from provided link" />
+ <img class="linkthumbnail" src="<?php echo Summoner::ifset($formData, 'imageToShow'); ?>" alt="Image from provided link" />
</div>
<div class="column is-half">
<div class="field">
</div>
<div class="column is-two-third">
<p>
- <img class="linkthumbnail" src="<?php echo $linkData['image']; ?>" alt="Image if provided...">
+ <img class="linkthumbnail" src="<?php echo $linkData['imageToShow']; ?>" alt="Image if provided...">
</p>
</div>
</div>
<figure class="image is-4by3">
<a href="<?php echo $link['link']; ?>" target="_blank">
<?php if(!empty($link['image'])) { ?>
- <img class="" src= "<?php echo $link['image']; ?>">
+ <img class="linkthumbnail" src= "<?php echo $link['image']; ?>">
<?php } else { ?>
<img class="" src= "asset/img/no-link-picture.png">
<?php } ?>