* 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/
/**
* a static helper class
*/
-
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
}
break;
- case 'rights':
- return self::isRightsString($input);
- break;
-
case 'url':
if(filter_var($input,FILTER_VALIDATE_URL) === $input) {
return true;
* @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
}
/**
- * 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;
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);
}
$ret = $do;
}
else {
- $ret = false;
error_log(var_export(curl_error($ch),true));
}
}
/**
- * check if a string strts with a given string
+ * check if a string starts with a given string
*
* @param string $haystack
* @param string $needle
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;
}
/**
* try to gather meta information from given URL
* @param string $url
+ * @return array|bool
*/
static function gatherInfoFromURL($url) {
$ret = false;
* 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
/**
* 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();
* 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
*/
* 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/
$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) {
$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) {
<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>