]> 91.132.146.200 Git - insipid.git/commitdiff
tried to get a full page snapshot. Getting only a thumbnail...
authorBanana <mail@bananas-playground.net>
Wed, 26 Feb 2020 20:51:32 +0000 (21:51 +0100)
committerBanana <mail@bananas-playground.net>
Wed, 26 Feb 2020 20:51:32 +0000 (21:51 +0100)
ChangeLog
documentation/thumbnail-of-link.txt [new file with mode: 0644]
webroot/lib/link.class.php
webroot/lib/snapshot.class.php
webroot/view/editlink.inc.php
webroot/view/editlink.php

index 58f114717c998a598d870fd67a8e4aeb8176774f..545680b5cb9de1b9b05c4546ea961a4086b4098d 100644 (file)
--- 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 (file)
index 0000000..2758ef0
--- /dev/null
@@ -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
index df5742aebb9beb05c2d8cf890c37708465b515b1..0229b4ca8a43f55c4d35f743da685a93df04f362 100644 (file)
@@ -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));
                        }
 
                }
index 08af6ad7f34dc04e96b1d194e8c91082b458c8fa..1274d11732309136efb2a750b5c64174304c7b0c 100644 (file)
@@ -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
index f87099ab300df0d11f80d42384efc0bef4149c48..c9aeecc566e4e48f682ba6062f2eaa2bb8208020 100644 (file)
@@ -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) {
index d928941a3db33492bdac571e3c13003f758ca7be..721b9ad2f75e22b04af11a528de27befce396b89 100644 (file)
                                </p>
                                <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
+                               <label class="checkbox">
+                                       <input type="checkbox" name="data[localImage]" value="1" <?php if(Summoner::ifset($formData, 'localImage')) echo "checked"; ?> />
+                                       Store image locally
+                               </label>
+                       </div>
+               </div>
+               <div class="columns">
+                       <div class="column is-one-quarter">
+                               <p>
+                                       Thumbnail of the webpage. Not the image provided with html meta data.
+                               </p>
+                       </div>
+                       <div class="column">
+                               <?php if(isset($linkData['snapshotLink'])) { ?>
+                               <p><a href="<?php echo $linkData['snapshotLink']; ?>" target="_blank">View Thumbnail</a></p>
+                               <?php } ?>
+                               <label class="checkbox">
+                                       <input type="checkbox" name="data[snapshot]" value="1" <?php if(Summoner::ifset($formData, 'snapshot')) echo "checked"; ?>  />
+                                       Save a thumbnail (This can take some time)
+                               </label>
                        </div>
                </div>
         <div class="columns">
                                        <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 (This can take some time)
-                               </label>
                        </div>
                </div>
                <div class="columns">