]> 91.132.146.200 Git - insipid.git/commitdiff
static class code updates. fixed tag and category selection in edit view. Added to...
authorBanana <banana@optimus.de>
Tue, 16 Jul 2019 13:58:10 +0000 (15:58 +0200)
committerBanana <banana@optimus.de>
Tue, 16 Jul 2019 13:58:10 +0000 (15:58 +0200)
webroot/lib/summoner.class.php
webroot/view/editlink.inc.php
webroot/view/editlink.php

index 2a13c9ef30e3322e8e32a9275eb0c00b2a0b96e7..d5845288f040581200de4c924e264d459b4a95ed 100644 (file)
@@ -3,7 +3,7 @@
  * Insipid
  * Personal web-bookmark-system
  *
- * Copyright 2016-2018 Johannes Keßler
+ * Copyright 2016-2019 Johannes Keßler
  *
  * Development starting from 2011: Johannes Keßler
  * https://www.bananas-playground.net/projekt/insipid/
@@ -29,7 +29,6 @@
 /**
  * a static helper class
  */
-
 class Summoner {
 
        /**
@@ -47,6 +46,7 @@ class Summoner {
         * the replace should be empty, otherwise are there chars which are not
         * allowed
         *
+        * @return bool
         */
        static function validate($input,$mode='text',$limit=false) {
                // check if we have input
@@ -66,10 +66,6 @@ class Summoner {
                            }
                        break;
 
-                       case 'rights':
-                               return self::isRightsString($input);
-                       break;
-
                        case 'url':
                                if(filter_var($input,FILTER_VALIDATE_URL) === $input) {
                                        return true;
@@ -138,7 +134,7 @@ class Summoner {
         * @param string $string
         * @return number
         */
-       static function is_utf8 ( $string ) {
+       static function is_utf8($string) {
           // From http://w3.org/International/questions/qa-forms-utf-8.html
           return preg_match('%^(?:
                 [\x09\x0A\x0D\x20-\x7E]            # ASCII
@@ -153,8 +149,10 @@ class Summoner {
        }
 
        /**
-        * execute a curl call to the fiven $url
-        * @param string $curl The request url
+        * execute a curl call to the given $url
+        * @param string $url The request url
+        * @param bool $port
+        * @return bool|mixed
         */
        static function curlCall($url,$port=false) {
                $ret = false;
@@ -165,6 +163,11 @@ class Summoner {
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+               curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+               curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
+
+               //curl_setopt($ch, CURLOPT_HEADER, true);
+
                if(!empty($port)) {
                  curl_setopt($ch, CURLOPT_PORT, $port);
                }
@@ -175,7 +178,6 @@ class Summoner {
                        $ret = $do;
                }
                else {
-                       $ret = false;
                        error_log(var_export(curl_error($ch),true));
                }
 
@@ -185,7 +187,7 @@ class Summoner {
        }
 
        /**
-        * check if a string strts with a given string
+        * check if a string starts with a given string
         *
         * @param string $haystack
         * @param string $needle
@@ -208,19 +210,19 @@ class Summoner {
                if ($length == 0) {
                        return true;
                }
-
                return (substr($haystack, -$length) === $needle);
        }
 
 
        /**
         * simulate the Null coalescing operator in php5
-        *
         * this only works with arrays and checking if the key is there and echo/return it.
-        *
         * http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
+        *
+        * @param $array
+        * @param $key
+        * @return bool
         */
-
        static function ifset($array,$key) {
            return isset($array[$key]) ? $array[$key] : false;
        }
@@ -228,6 +230,7 @@ class Summoner {
        /**
         * try to gather meta information from given URL
         * @param string $url
+        * @return array|bool
         */
        static function gatherInfoFromURL($url) {
            $ret = false;
@@ -246,6 +249,7 @@ class Summoner {
         * get as much as possible solcial meta infos from given string
         * the string is usually a HTML source
         * @param string $string
+        * @return array
         */
        static function socialMetaInfos($string) {
            #http://www.w3bees.com/2013/11/fetch-facebook-og-meta-tags-with-php.html
@@ -334,10 +338,11 @@ class Summoner {
 
        /**
         * at creation a category or tag can be a string with multiple values.
-        * seperated with space or ,
-        * category and tag is a single string without any seperators
+        * separated with space or ,
+        * category and tag is a single string without any separators
         *
         * @param string $string
+        * @return array
         */
        static function prepareTagOrCategoryStr($string) {
            $ret = array();
@@ -397,8 +402,6 @@ class Summoner {
         * should be in the right format
         * return an array with links and the infos about them
         *
-        * new-absolute-link|multiple,category,strings|multiple,tag,strings\n
-        *
         * @param string $string
         * @return array $ret
         */
index 6d58f139b2bd461624c1b4c3730f24b6b87754f4..e3d0b7f6ae4330289ae3d3015b39d4ab9c57d400 100644 (file)
@@ -3,7 +3,7 @@
  * Insipid
  * Personal web-bookmark-system
  *
- * Copyright 2016-2018 Johannes Keßler
+ * Copyright 2016-2019 Johannes Keßler
  *
  * Development starting from 2011: Johannes Keßler
  * https://www.bananas-playground.net/projekt/insipid/
@@ -80,9 +80,23 @@ if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink']))
         $submitFeedback['status'] = 'error';
     }
 }
+elseif(isset($_POST['refreshlink'])) {
+       $linkInfo = Summoner::gatherInfoFromURL($linkData['link']);
+       if(!empty($linkInfo)) {
+               if(isset($linkInfo['description'])) {
+                       $linkData['description'] = $linkInfo['description'];
+               }
+               if(isset($linkInfo['title'])) {
+                       $linkData['title'] = $linkInfo['title'];
+               }
+               if(isset($linkInfo['image'])) {
+                       $linkData['image'] = $linkInfo['image'];
+               }
+       }
+}
 
 $formData = $linkData;
-# prepate the tag string
+# prepare the tag string
 $formData['tag'] = '';
 if(!empty($linkData['tags'])) {
     foreach($linkData['tags'] as $k=>$v) {
@@ -91,7 +105,7 @@ if(!empty($linkData['tags'])) {
     $formData['tag'] = trim($formData['tag']," ,");
 }
 
-# prepate the category string
+# prepare the category string
 $formData['category'] = '';
 if(!empty($linkData['categories'])) {
     foreach($linkData['categories'] as $k=>$v) {
index dd691381ac7f5d2b9ee2090ad03762653dd1bf22..8a8a589c18f311cae807917fed821f32c7a38f02 100644 (file)
                <div class="column">
                    <input type="text" name="data[tag]" list="taglist"
                                class="flexdatalist input" multiple='multiple'
-                               data-min-length="0" data-cache="0" data-selection-required='true'
+                               data-min-length="0" data-cache="0"
                                data-toggle-selected="true"
                                value="<?php echo Summoner::ifset($formData, 'tag'); ?>" />
                        <datalist id="taglist">
                <div class="column">
                    <input type="text" name="data[category]" list="categorylist"
                                class="flexdatalist input" multiple='multiple'
-                               data-min-length="0" data-cache="0" data-selection-required='true'
+                               data-min-length="0" data-cache="0"
                                data-toggle-selected="true"
                                value="<?php echo Summoner::ifset($formData, 'category'); ?>" />
                        <datalist id="categorylist">
                        <input class="checkbox" type="checkbox" name="data[private]" value="1" <?php if(Summoner::ifset($formData, 'private')) echo "checked"; ?> />
                </div>
                <div class="column is-half">
-                       <input type="submit" class="button is-primary" name="editlink" value="Update">
+                               <input type="submit" class="button is-info" name="refreshlink" value="Refresh from source">
+                               <input type="submit" class="button is-primary" name="editlink" value="Save">
                </div>
         </div>
     </form>