# add stuff
$this->_image();
+ $this->_snapshot();
}
}
}
}
+ $this->DB->commit();
+
# decide to store or remove the image
if (isset($data['localImage'])) {
$image = ABSOLUTE_PATH . '/' . LOCAL_STORAGE . '/thumbnail-' . $this->_data['hash'];
}
}
- $this->DB->commit();
+ # decide if we want to make a local snapshot
+ if(isset($data['snapshot'])) {
+ $snapshot = ABSOLUTE_PATH . '/' . LOCAL_STORAGE . '/snapshot-' . $this->_data['hash'];
+ if ($data['snapshot'] === true) {
+ if (!file_exists($snapshot) || $_imageUrlChanged === true) {
+ require_once 'lib/snapshot.class.php';
+ $snap = new Snapshot();
+ $snap->doSnapshot($this->_data['link']);
+ }
+ } elseif ($data['snapshot'] === false) {
+ if (file_exists($snapshot)) {
+ unlink($snapshot);
+ }
+ }
+ }
+
+
$ret = true;
} else {
$this->DB->rollback();
$this->_removeTagRelation(false);
$this->_removeCategoryRelation(false);
$this->_deleteImage();
+ $this->_deleteSnapshot();
}
/**
}
}
+ /**
+ * determine of we have a local stored snapshot
+ * if so populate the snapshotLink attribute
+ */
+ private function _snapshot() {
+ if (!empty($this->_data['hash'])) {
+ $snapshot = ABSOLUTE_PATH.'/'.LOCAL_STORAGE.'/snapshot-'.$this->_data['hash'];
+ if (file_exists($snapshot)) {
+ $this->_data['snapshotLink'] = LOCAL_STORAGE.'/snapshot-'.$this->_data['hash'];
+ $this->_data['snapshot'] = true;
+ }
+ }
+ }
+
/**
* remove the local stored image
*/
}
}
+ /**
+ * remove the local stored image
+ */
+ private function _deleteSnapshot() {
+ if (!empty($this->_data['hash']) && !empty($this->_data['snapshotLink'])) {
+ $snapshot = LOCAL_STORAGE.'/snapshot-'.$this->_data['hash'];
+ if (file_exists($snapshot)) {
+ unlink($snapshot);
+ }
+ }
+ }
+
/**
* check if the status is private and set the info
*/
class Snapshot {
private $_googlePageSpeed = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed';
- public _constructor() {}
+ public function __constructor() {}
/**
* call given url with google PageSpeed API
* @param String $url URL to take a screenshot from
* @return
*/
- public function doScreenshot($url) {
+ public function doSnapshot($url) {
if(!empty($url)) {
$theCall = Summoner::curlCall($url);
var_dump($theCall);
*/
class Summoner {
+ private const BROWSER_AGENT_STRING = 'Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0';
+
/**
* validate the given string with the given type. Optional check the string
* length
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_USERAGENT,self::BROWSER_AGENT_STRING);
// curl_setopt($ch, CURLOPT_VERBOSE, true);
//curl_setopt($ch, CURLOPT_HEADER, 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_USERAGENT, self::BROWSER_AGENT_STRING);
if(!empty($port)) {
curl_setopt($ch, CURLOPT_PORT, $port);
$formData['localImage'] = true;
}
+ $formData['snapshot'] = false;
+ if(isset($fData['snapshot'])) {
+ $formData['snapshot'] = true;
+ }
+
$formData['description'] = trim($fData['description']);
$formData['title'] = trim($fData['title']);
$formData['image'] = trim($fData['image']);
</div>
<div class="columns">
<div class="column is-one-quarter">
- <label>Private</label>
- <input class="checkbox" type="checkbox" name="data[private]" value="1" <?php if(Summoner::ifset($formData, 'private')) echo "checked"; ?> />
+ <label>Options</label>
+ </div>
+ <div class="column">
+ <label class="checkbox">
+ <input type="checkbox" name="data[private]" value="1" <?php if(Summoner::ifset($formData, 'private')) echo "checked"; ?> />
+ Private
+ </label>
+ <label class="checkbox">
+ <input type="checkbox" name="data[snapshot]" value="1" <?php if(Summoner::ifset($formData, 'snapshot')) echo "checked"; ?> />
+ Save a snapshot
+ </label>
+ </div>
+ </div>
+ <div class="columns">
+ <div class="column is-one-quarter">
+
</div>
<div class="column">
<input type="submit" class="button is-info" name="refreshlink" value="Refresh from source">