From 633683de8b877f251819ebea6581bf6c0400fc0d Mon Sep 17 00:00:00 2001 From: Banana Date: Tue, 25 Feb 2020 20:35:25 +0100 Subject: [PATCH] init of the make snapshot function in edit view --- webroot/lib/link.class.php | 48 +++++++++++++++++++++++++++++++++- webroot/lib/snapshot.class.php | 4 +-- webroot/lib/summoner.class.php | 6 +++-- webroot/view/editlink.inc.php | 5 ++++ webroot/view/editlink.php | 18 +++++++++++-- 5 files changed, 74 insertions(+), 7 deletions(-) diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index e29c908..df5742a 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -107,6 +107,7 @@ class Link { # add stuff $this->_image(); + $this->_snapshot(); } } @@ -225,6 +226,8 @@ class Link { } } + $this->DB->commit(); + # decide to store or remove the image if (isset($data['localImage'])) { $image = ABSOLUTE_PATH . '/' . LOCAL_STORAGE . '/thumbnail-' . $this->_data['hash']; @@ -239,7 +242,23 @@ class Link { } } - $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(); @@ -258,6 +277,7 @@ class Link { $this->_removeTagRelation(false); $this->_removeCategoryRelation(false); $this->_deleteImage(); + $this->_deleteSnapshot(); } /** @@ -372,6 +392,20 @@ class Link { } } + /** + * 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 */ @@ -384,6 +418,18 @@ class Link { } } + /** + * 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 */ diff --git a/webroot/lib/snapshot.class.php b/webroot/lib/snapshot.class.php index 07c4c70..9c50877 100644 --- a/webroot/lib/snapshot.class.php +++ b/webroot/lib/snapshot.class.php @@ -34,7 +34,7 @@ class Snapshot { private $_googlePageSpeed = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed'; - public _constructor() {} + public function __constructor() {} /** * call given url with google PageSpeed API @@ -43,7 +43,7 @@ class Snapshot { * @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); diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index ece2021..a031a22 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -31,6 +31,8 @@ */ 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 @@ -164,7 +166,7 @@ class Summoner { 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); @@ -207,7 +209,7 @@ class Summoner { 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); diff --git a/webroot/view/editlink.inc.php b/webroot/view/editlink.inc.php index db8ca3e..f87099a 100644 --- a/webroot/view/editlink.inc.php +++ b/webroot/view/editlink.inc.php @@ -105,6 +105,11 @@ if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink'])) $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']); diff --git a/webroot/view/editlink.php b/webroot/view/editlink.php index 1b46a79..36f57e7 100644 --- a/webroot/view/editlink.php +++ b/webroot/view/editlink.php @@ -190,8 +190,22 @@
- - /> + +
+
+ + +
+
+
+
+  
-- 2.39.5