]> 91.132.146.200 Git - insipid.git/commitdiff
init of the make snapshot function in edit view
authorBanana <mail@bananas-playground.net>
Tue, 25 Feb 2020 19:35:25 +0000 (20:35 +0100)
committerBanana <mail@bananas-playground.net>
Tue, 25 Feb 2020 19:35:25 +0000 (20:35 +0100)
webroot/lib/link.class.php
webroot/lib/snapshot.class.php
webroot/lib/summoner.class.php
webroot/view/editlink.inc.php
webroot/view/editlink.php

index e29c9089aeb7439289744f99e3c716d888bce52e..df5742aebb9beb05c2d8cf890c37708465b515b1 100644 (file)
@@ -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
         */
index 07c4c70fcc4a59b30dc918a26011f65c444dff7a..9c5087753148ab5b53cc847b08bd51724d18ca6d 100644 (file)
@@ -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);
index ece2021c605d6c8ffde9e0057ff4e5facb65136b..a031a22a6bef30fd4b890376b498683bc0ec89fa 100644 (file)
@@ -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);
index db8ca3eb4b1d6396aacff0d7113fe2eef9616cb7..f87099ab300df0d11f80d42384efc0bef4149c48 100644 (file)
@@ -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']);
index 1b46a79feb006482b8825d5aa5c31da69e4337a9..36f57e7e34e28640a4e9ee3f2c48646644665caa 100644 (file)
                </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">
+                               &nbsp;
                        </div>
                        <div class="column">
                                <input type="submit" class="button is-info" name="refreshlink" value="Refresh from source">