From fda929689c56fc0794dbce6a89f96172a6f65abf Mon Sep 17 00:00:00 2001 From: Banana Date: Wed, 26 Feb 2020 21:51:32 +0100 Subject: [PATCH] tried to get a full page snapshot. Getting only a thumbnail... --- ChangeLog | 4 ++++ documentation/thumbnail-of-link.txt | 6 ++++++ webroot/lib/link.class.php | 11 +++++++++-- webroot/lib/snapshot.class.php | 28 ++++++++++++++++------------ webroot/view/editlink.inc.php | 5 ++++- webroot/view/editlink.php | 26 ++++++++++++++++++++------ 6 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 documentation/thumbnail-of-link.txt diff --git a/ChangeLog b/ChangeLog index 58f1147..545680b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ version 2.5 - Winnowing Hall (tbd) + + Added a thumbnail by talking to Google page speed API + Planned was a full page snapshot, but only got the thumbnail. + Needs some more work with headless chrome. + version 2.4 - Seven Portals (2020-02-16) + Now including update instructions diff --git a/documentation/thumbnail-of-link.txt b/documentation/thumbnail-of-link.txt new file mode 100644 index 0000000..2758ef0 --- /dev/null +++ b/documentation/thumbnail-of-link.txt @@ -0,0 +1,6 @@ +While editing a link you can request thumbnail of the given link at the time. +It uses the Google page insights API to get a thumbnail. + +It will be created if the option is actived. To remove uncheck the option. +To refresh uncheck the option. Save. This will delete the data. +Check the option again and the thumbnail will be created again. \ No newline at end of file diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index df5742a..0229b4c 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -75,6 +75,7 @@ class Link { $this->_categories(); $this->_image(); $this->_private(); + $this->_snapshot(); } } @@ -107,7 +108,6 @@ class Link { # add stuff $this->_image(); - $this->_snapshot(); } } @@ -163,6 +163,9 @@ class Link { if ($returnId === true) { $ret = $this->DB->insert_id; } + else { + error_log('ERROR Failed to rcreate link: '.var_export($data,true)); + } return $ret; } @@ -249,7 +252,10 @@ class Link { if (!file_exists($snapshot) || $_imageUrlChanged === true) { require_once 'lib/snapshot.class.php'; $snap = new Snapshot(); - $snap->doSnapshot($this->_data['link']); + $do = $snap->doSnapshot($this->_data['link'], $snapshot); + if(empty($do)) { + error_log('ERROR Failed to create snapshot: '.var_export($data,true)); + } } } elseif ($data['snapshot'] === false) { if (file_exists($snapshot)) { @@ -262,6 +268,7 @@ class Link { $ret = true; } else { $this->DB->rollback(); + error_log('ERROR Failed to update link: '.var_export($data,true)); } } diff --git a/webroot/lib/snapshot.class.php b/webroot/lib/snapshot.class.php index 08af6ad..1274d11 100644 --- a/webroot/lib/snapshot.class.php +++ b/webroot/lib/snapshot.class.php @@ -40,21 +40,25 @@ class Snapshot { * call given url with google PageSpeed API * to recieve image data * - * @param String $url URL to take a screenshot from + * @param String $url URL to take a thumbnail from * @return */ - public function doSnapshot($url) { - if(!empty($url)) { + public function doSnapshot($url,$filename) { + $ret = false; + + if(!empty($url) && is_writable(dirname($filename))) { $theCall = Summoner::curlCall($this->_googlePageSpeed.urlencode($url).'&screenshot=true'); - var_dump($theCall); + if(!empty($theCall)) { + $jsonData = json_decode($theCall,true); + if(!empty($jsonData) && isset($jsonData['screenshot']['data'])) { + $imageData = $jsonData['screenshot']['data']; + $imageData = str_replace(['_', '-'], ['/', '+'], $imageData); + $imageData = base64_decode($imageData); + $ret = file_put_contents($filename, $imageData); + } + } } - } - /** - * save given screenshot data - * - * @param $data - * @return bool - */ - public function saveScreenshot($data) {} + return $ret; + } } \ No newline at end of file diff --git a/webroot/view/editlink.inc.php b/webroot/view/editlink.inc.php index f87099a..c9aeecc 100644 --- a/webroot/view/editlink.inc.php +++ b/webroot/view/editlink.inc.php @@ -59,7 +59,6 @@ if(empty($linkData)) { } $linkObj = new Link($DB); -$linkObj->load($_id); if($_isAwm === true) { $submitFeedback['message'] = 'To accept this link (link has moderation status), just save it. Otherwise just delete.'; @@ -67,6 +66,8 @@ if($_isAwm === true) { } if($_requestMode && $_requestMode == "export") { + $linkObj->load($_id); + $_i = $linkObj->getData('id'); if(!empty($_i)) { @@ -117,6 +118,8 @@ if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink'])) $formData['tag'] = trim($fData['tag']); if(!empty($formData['title'])) { + $linkObj->load($_id); + $update = $linkObj->update($formData); if($update === true) { diff --git a/webroot/view/editlink.php b/webroot/view/editlink.php index d928941..721b9ad 100644 --- a/webroot/view/editlink.php +++ b/webroot/view/editlink.php @@ -109,8 +109,26 @@



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

+ Thumbnail of the webpage. Not the image provided with html meta data. +

+
+
+ +

View Thumbnail

+ +
@@ -197,10 +215,6 @@ /> Private -
-- 2.39.5