aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrhatto <rhatto@riseup.net>2018-03-23 02:27:18 +0000
committerGitHub <noreply@github.com>2018-03-23 02:27:18 +0000
commit856e975127fff8f82b14f2886bb4ffb239541555 (patch)
tree72280f007b2552e605c1a3abd492325fb364f020
parent200aa3c79324ceb2b42ec6452bc11888e5fafa7d (diff)
parentf06e78a888f914788f0634feb93fcef071518e9d (diff)
downloadsemanticscuttle-856e975127fff8f82b14f2886bb4ffb239541555.tar.gz
semanticscuttle-856e975127fff8f82b14f2886bb4ffb239541555.tar.bz2
Merge pull request #1 from jasonmm/master
Update and bug fix
-rw-r--r--.gitignore1
-rw-r--r--data/config.default.php18
-rw-r--r--data/schema/2.sql2
-rw-r--r--data/templates/default/bookmarks.tpl.php81
-rw-r--r--www/.htaccess4
-rw-r--r--www/api/opensearch.php2
6 files changed, 106 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 7695176..725443e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ semanticscuttle-dump.sql
data/config.php
data/config.testing.php
data/config.testing-tmp.php
+cache
diff --git a/data/config.default.php b/data/config.default.php
index 5e560a7..95df176 100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@ -778,4 +778,22 @@ $unittestUrl = null;
*/
$allowUnittestMode = false;
+/***************************************************
+ * Caching support
+ *
+ * Use the following configuration if you want to provide a link
+ * to a cached copy of your bookmarks.
+ *
+ * Please note that these feature just provide the link if a cached
+ * copy exists.
+ *
+ * You should download SemanticScuttle bookmarks using a tool like
+ * https://git.fluxo.info/?p=httruta.git
+ */
+
+/**
+ * Set to the base public URL of you cache folder.
+ */
+$cacheUrl = null;
+
?>
diff --git a/data/schema/2.sql b/data/schema/2.sql
index 6c3bfaf..171e011 100644
--- a/data/schema/2.sql
+++ b/data/schema/2.sql
@@ -1,4 +1,4 @@
-ALTER TABLE `sc_bookmarks` CHANGE `bDescription` `bDescription` VARCHAR( 1500 )
+ALTER TABLE `sc_bookmarks` CHANGE `bDescription` `bDescription` VARCHAR( 1500 );
CREATE TABLE `sc_tagscache` (
`tcId` int(11) NOT NULL auto_increment,
`tag1` varchar(100) NOT NULL default '',
diff --git a/data/templates/default/bookmarks.tpl.php b/data/templates/default/bookmarks.tpl.php
index 2a3d169..818eea0 100644
--- a/data/templates/default/bookmarks.tpl.php
+++ b/data/templates/default/bookmarks.tpl.php
@@ -337,6 +337,86 @@ if ($currenttag!= '') {
}
}
+ // Local cache
+ $cacheInfo = $GLOBALS['dir_cache'] .'/urls';
+ $cacheLink = null;
+ if ($GLOBALS['cacheUrl'] != null) {
+ // Hashing discussion at http://linuxprocess.free.fr/MHonArc/Oct-2005/msg00016.html
+ $assetHash = sha1($row['bAddress'] . "\n");
+ $assetHash = substr($assetHash, 0, 2) . '/' . substr($assetHash, 2, 2) . '/' . $assetHash;
+ $assetBase = $GLOBALS['cacheUrl'] . '/' . $assetHash;
+ $assetLink = $assetBase;
+ $assetPdf = $assetBase.'/screenshot.pdf';
+ $assetPng = $assetBase .'/screenshot.png';
+
+ // Handle PDF links
+ $assetFile = basename(parse_url($row['bAddress'])['path']);
+ $assetExt = strtolower(pathinfo($assetFile, PATHINFO_EXTENSION));
+ if ($assetExt == 'pdf') {
+ $assetLink = $GLOBALS['cacheUrl'] . '/' . $assetHash . '/' . $assetFile;
+ }
+
+ // Check if the link exists
+ if (file_exists($cacheInfo .'/'. $assetHash .'/hascache')) {
+ $cacheLink = "| <a href=\"$assetLink\">Cache</a>";
+
+ if (file_exists($cacheInfo .'/'. $assetHash .'/haspdf')) {
+ $cacheLink .= " | <a href=\"$assetPdf\">PDF</a>";
+ }
+
+ if (file_exists($cacheInfo .'/'. $assetHash .'/haspng')) {
+ $cacheLink .= " | <a href=\"$assetPng\">PNG</a>";
+ }
+ }
+ else if ($fp = curl_init($assetBase)) {
+ curl_setopt($fp, CURLOPT_NOBODY, true);
+ curl_exec($fp);
+
+ $retcode = curl_getinfo($fp, CURLINFO_HTTP_CODE);
+
+ if ($retcode != 404) {
+ if (!file_exists($cacheInfo .'/'. $assetHash)) {
+ mkdir($cacheInfo .'/'. $assetHash, 0755, true);
+ }
+
+ touch($cacheInfo .'/'. $assetHash .'/hascache');
+ $cacheLink = "| <a href=\"$assetLink\">Cache</a>";
+
+ // Check if PDF is available
+ if ($fp = curl_init($assetPdf)) {
+ curl_setopt($fp, CURLOPT_NOBODY, true);
+ curl_exec($fp);
+
+ $retcode = curl_getinfo($fp, CURLINFO_HTTP_CODE);
+
+ if ($retcode != 404) {
+ touch($cacheInfo .'/'. $assetHash .'/haspdf');
+ $cacheLink .= " | <a href=\"$assetPdf\">PDF</a>";
+ }
+
+ curl_close($fp);
+ }
+
+ // Check if PNG is available
+ if ($fp = curl_init($assetPng)) {
+ curl_setopt($fp, CURLOPT_NOBODY, true);
+ curl_exec($fp);
+
+ $retcode = curl_getinfo($fp, CURLINFO_HTTP_CODE);
+
+ if ($retcode != 404) {
+ touch($cacheInfo .'/'. $assetHash .'/haspng');
+ $cacheLink .= " | <a href=\"$assetPng\">PNG</a>";
+ }
+
+ curl_close($fp);
+ }
+ }
+
+ curl_close($fp);
+ }
+ }
+
// Copy link
if ($userservice->isLoggedOn()
&& ($currentUser->getId() != $row['uId'])
@@ -425,6 +505,7 @@ if ($currenttag!= '') {
. $copy . "\n"
. $edit . "\n"
. $update . "\n"
+ . $cacheLink ."\n"
. " </div>\n";
echo $privateNoteField != ''
? ' <div class="privateNote" title="'. T_('Private Note on this bookmark') .'">'.$privateNoteField."</div>\n"
diff --git a/www/.htaccess b/www/.htaccess
index 563fe53..5799444 100644
--- a/www/.htaccess
+++ b/www/.htaccess
@@ -3,6 +3,10 @@
# (see $cleanurls in config.inc.php)
#####################################
+# See https://stackoverflow.com/questions/4558629/mod-rewrite-not-behaving-nicely
+# http://www.bennadel.com/blog/2218-Negotiation-Discovered-File-s-Matching-Request-None-Could-Be-Negotiated.htm
+# https://httpd.apache.org/docs/current/content-negotiation.html
+Options -MultiViews +FollowSymLinks
# Rewrite clean URLs onto real files
<IfModule mod_rewrite.c>
diff --git a/www/api/opensearch.php b/www/api/opensearch.php
index 3e7dbf7..9d3eae7 100644
--- a/www/api/opensearch.php
+++ b/www/api/opensearch.php
@@ -12,5 +12,5 @@ echo '<' . '?xml version="1.0" encoding="utf-8" ?' . ">\n";
<Developer>Jan Seifert "jan.seifert@uid.com"</Developer>
<Tags>semanticscuttle bookmark web</Tags>
<Image width="16" height="16">data:image/gif;base64,R0lGODlhEAAQAMZ9ANaPE9mREteTHtSXLdmXIdiXJtaYKdiYJ9iYKNeaLtKdP9CdRd2dLNWfQuWiFMqjX9+hNMykXt6jPOCkPM2oaM+paeCpQuGoR+OqOeKpR+GqS9+uWeSwU+ayS+uzOeWxVeWxWOSyWOu0POazXOS0YOm8Zee8cOy+WOm9a/jBLum+bPbCNurAbe7BYuvBc/LDV/LEV+zEdv/KKf/KLP/KLf/LLuzHe//MNP/NN/nMTv/OOf/OPP/OP/jNW//PPvnOVv/QQv7QRv/QRP/RR/HOhP/SSf/STPnRav/TT//TUPfScf/UUvzUXP/UVP/VV/bTfv/WWf/WW//WXP7XYf/XX//XYP/YZPPVmf/ZZv/ZZ/vYeP/aaf/aa//abP/abf/abvvaef/bb//bcfzbfP/ccv/cc//cdP/cdf/dd//deP/def3egP/ee//efP/efv/ffv/ggf/gg//ghP/ghfrfmv/hif/ii//ijP/jkfzjm//kkv7klv/lmP///////////yH5BAEKAH8ALAAAAAAQABAAAAergH+Cg38hhIeHIFcmiIgDLnt0Go2EE1pyd0QbjQMQDC9bZGprKBcjA4IfAQMrQUhOVFlhaGNPMRl/Aw4yMzc7QkZNUlZdZmASqAJKcW1WPDpARUtQUx0RgyR5fHpzUTU4PkMiqIMVNnh2c25lSTQpAIgqdXJvaWReXz0JiCxwbWhiuGCp8uMAohJszhw5AYMJlBwFEHFoYQHBAwUEMHgwgKjBA0QLKFAaKSgQADs=</Image>
- <Url type="text/html" template="http://<?php echo $_SERVER['HTTP_HOST'] . '/' . $GLOBALS['root']?>search.php/all/{searchTerms}"/>
+ <Url type="text/html" template="<?php if ($GLOBALS['root'] != null) { echo $GLOBALS['root']; } else { echo $_SERVER['SERVER_PROTOCOL'] .'://'. $_SERVER['HTTP_HOST'] . '/'; } ?>search.php/all/{searchTerms}"/>
</OpenSearchDescription>