X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=doc%2FExample-patch---add-new-via-field-for-links.md;h=883adf40e2cb6ba7f59c4153fd9d732df774da6e;hb=adcdac1dec45090e2fa1cd4a340e91a40c7a205f;hp=d84ef25a62f9fd324791ce04530d51d2d27f13f4;hpb=bc66d513a9aa6da9361dbfc2f0b4bf384e9597a6;p=github%2Fshaarli%2FShaarli.git diff --git a/doc/Example-patch---add-new-via-field-for-links.md b/doc/Example-patch---add-new-via-field-for-links.md index d84ef25a..883adf40 100644 --- a/doc/Example-patch---add-new-via-field-for-links.md +++ b/doc/Example-patch---add-new-via-field-for-links.md @@ -1,3 +1,4 @@ +#Example patch add new via field for links Example patch to add a new field ("via") for links, an input field to set the "via" property from the "edit link" dialog, and display the "via" field in the link list display. **Untested, use at your own risk** Thanks to @Knah-Tsaeb in https://github.com/sebsauvage/Shaarli/pull/158 @@ -6,7 +7,7 @@ Thanks to @Knah-Tsaeb in https://github.com/sebsauvage/Shaarli/pull/158 From e0f363c18e8fe67990ed2bb1a08652e24e70bbcb Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Fri, 11 Oct 2013 15:18:37 +0200 -Subject: [PATCH] Add a "via"/origin property for links, add new input in "edit link" dialog +Subject: [PATCH] Add a "via"/origin property for links, add new input in "edit link" dialog[](.html) Thanks to: * https://github.com/Knah-Tsaeb/Shaarli/commit/040eb18ec8cdabd5ea855e108f81f97fbf0478c4 * https://github.com/Knah-Tsaeb/Shaarli/commit/4123658eae44d7564d1128ce52ddd5689efee813 @@ -22,27 +23,27 @@ diff --git a/index.php b/index.php index 6fae2f8..53f798e 100644 --- a/index.php +++ b/index.php -@@ -436,6 +436,12 @@ if (isset($_POST['login'])) +@@ -436,6 +436,12 @@ if (isset($_POST['login']))[](.html) // ------------------------------------------------------------------------------------------ // Misc utility functions: +// Try to get just domain for @via +function getJustDomain($url){ + $parts = parse_url($url); -+ return trim($parts['host']); ++ return trim($parts['host']);[](.html) + } + // Returns the server URL (including port and http/https), without path. // e.g. "http://myserver.com:8080" - // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL. + // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL.[](.html) @@ -799,7 +805,8 @@ class linkdb implements Iterator, Countable, ArrayAccess - $found= (strpos(strtolower($l['title']),$s)!==false) - || (strpos(strtolower($l['description']),$s)!==false) - || (strpos(strtolower($l['url']),$s)!==false) -- || (strpos(strtolower($l['tags']),$s)!==false); -+ || (strpos(strtolower($l['tags']),$s)!==false) -+ || (!empty($l['via']) && (strpos(strtolower($l['via']),$s)!==false)); - if ($found) $filtered[$l['linkdate']] = $l; + $found= (strpos(strtolower($l['title']),$s)!==false)[](.html) + || (strpos(strtolower($l['description']),$s)!==false)[](.html) + || (strpos(strtolower($l['url']),$s)!==false)[](.html) +- || (strpos(strtolower($l['tags']),$s)!==false);[](.html) ++ || (strpos(strtolower($l['tags']),$s)!==false)[](.html) ++ || (!empty($l['via']) && (strpos(strtolower($l['via']),$s)!==false));[](.html) + if ($found) $filtered[$l['linkdate'[ = $l;](-=-$l;.html) } krsort($filtered); @@ -814,7 +821,7 @@ class linkdb implements Iterator, Countable, ArrayAccess @@ -52,74 +53,74 @@ index 6fae2f8..53f798e 100644 - foreach($this->links as $l) + foreach($this-> links as $l) { - $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags']))); + $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags'])));[](.html) if (count(array_intersect($linktags,$searchtags)) == count($searchtags)) @@ -905,7 +912,7 @@ function showRSS() else $linksToDisplay = $LINKSDB; $nblinksToDisplay = 50; // Number of links to display. - if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. + if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.[](.html) - { + { - $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; + $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;[](.html) } @@ -944,7 +951,12 @@ function showRSS() // If user wants permalinks first, put the final link in description if ($usepermalinks===true) $descriptionlink = '(Link)'; - if (strlen($link['description'])>0) $descriptionlink = '
'.$descriptionlink; -- echo ''."\n\n"; -+ if(!empty($link['via'])){ -+ $via = '
Origine => '.htmlspecialchars(getJustDomain($link['via'])).''; + if (strlen($link['description'])>0) $descriptionlink = '
'.$descriptionlink;[](.html) +- echo ''."\n\n";](>'."\n\n";.html) ++ if(!empty($link['via'])){[](.html) ++ $via = '
Origine => '.htmlspecialchars(getJustDomain($link['via'])).'';[](.html) + } else { + $via = ''; + } -+ echo ''."\n\n"; ++ echo ''."\n\n";](>'."\n\n";.html) $i++; } echo ''; @@ -980,7 +992,7 @@ function showATOM() else $linksToDisplay = $LINKSDB; $nblinksToDisplay = 50; // Number of links to display. - if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. + if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.[](.html) - { + { - $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; + $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;[](.html) } @@ -1006,11 +1018,16 @@ function showATOM() // Add permalink in description $descriptionlink = htmlspecialchars('(Permalink)'); -+ if(isset($link['via']) && !empty($link['via'])){ -+ $via = htmlspecialchars('
Origine => '.getJustDomain($link['via']).''); ++ if(isset($link['via']) && !empty($link['via'])){[](.html) ++ $via = htmlspecialchars('
Origine => '.getJustDomain($link['via']).'');[](.html) + } else { + $via = ''; + } // If user wants permalinks first, put the final link in description if ($usepermalinks===true) $descriptionlink = htmlspecialchars('(Link)'); - if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink; + if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink;[](.html) -- $entries.=''.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink."\n"; -+ $entries.=''.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink.$via."\n"; - if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification) +- $entries.=''.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink."\n";[](.html) ++ $entries.=''.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink.$via."\n";[](.html) + if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification)[](.html) { - foreach(explode(' ',$link['tags']) as $tag) + foreach(explode(' ',$link['tags']) as $tag)[](.html) @@ -1478,7 +1495,7 @@ function renderPage() if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?')) $url = 'http://'.$url; - $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), + $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0),[](.html) - 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); -+ 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags), 'via'=>trim($_POST['lf_via'])); - if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. - $LINKSDB[$linkdate] = $link; ++ 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags), 'via'=>trim($_POST['lf_via']));[](.html) + if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title.[](.html) + $LINKSDB[$linkdate] = $link;[](.html) $LINKSDB->savedb(); // Save to disk. @@ -1556,7 +1573,8 @@ function renderPage() - $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). - $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] - $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL -- $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL -+ $via = (empty($_GET['via']) ? '' : $_GET['via'] ); -+ $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL + $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet).[](.html) + $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that][](.html) + $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL[](.html) +- $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL [](.html) ++ $via = (empty($_GET['via']) ? '' : $_GET['via'] );[](.html) ++ $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL[](.html) if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; // If this is an HTTP link, we try go get the page to extract the title (otherwise we will to straight to the edit form.) if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') @@ -130,10 +131,10 @@ index 6fae2f8..53f798e 100644 - + // If found, extract encoding. - if (!empty($meta[0])) + if (!empty($meta[0]))[](.html) { @@ -1577,7 +1595,7 @@ function renderPage() - $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8'; + $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8';[](.html) } else { $html_charset = 'utf-8'; } - @@ -151,13 +152,13 @@ index 6fae2f8..53f798e 100644 $PAGE = new pageBuilder; @@ -1842,6 +1860,9 @@ function buildLinkList($PAGE,$LINKSDB) - $taglist = explode(' ',$link['tags']); + $taglist = explode(' ',$link['tags']);[](.html) uasort($taglist, 'strcasecmp'); - $link['taglist']=$taglist; -+ if(!empty($link['via'])){ -+ $link['via']=htmlspecialchars($link['via']); + $link['taglist']=$taglist;[](.html) ++ if(!empty($link['via'])){[](.html) ++ $link['via']=htmlspecialchars($link['via']);[](.html) + } - $linkDisp[$keys[$i]] = $link; + $linkDisp[$keys[$i[ = $link;](-=-$link;.html) $i++; } diff --git a/tpl/editlink.html b/tpl/editlink.html @@ -169,7 +170,7 @@ index 4a2c30c..14d4f9c 100644 Description

Tags

+ Origine

- {if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"} + {if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}[](.html)  
diff --git a/tpl/linklist.html b/tpl/linklist.html @@ -181,9 +182,9 @@ index ddc38cb..0a8475f 100644
{if="$value.description"}
{$value.description}
{/if} + {if condition="isset($value.via) && !empty($value.via)"}
Origine => {$value.via|getJustDomain}
{/if} - {if="!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()"} + {if="!$GLOBALS['config'['HIDE_TIMESTAMPS'] || isLoggedIn()"}]('HIDE_TIMESTAMPS']-||-isLoggedIn()"}.html) {$value.localdate|htmlspecialchars} - permalink - {else} -- 2.1.1 -``` \ No newline at end of file +```