aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2016-07-25 18:30:04 +0200
committerMarcello Stanisci <marcello.stanisci@inria.fr>2016-07-25 18:30:04 +0200
commit5eac4e76af3c5aea686213854e08c0753f92d523 (patch)
tree95fa0de1ca3da5bc306bb3e029704f116cf07ce3
parent0776397028140e6441b22928cc5d7c5d73a54015 (diff)
Closing #4456 (PHP side). In order to fulfill #4456, the article
that has image x.jpg in it must contain the tag <img src='/data/article_x/x.jpg'></img>. Furthermore, before running the blog, the webmaster must run $ php articles/article_images.php in order to generate the JSON database file which accounts for each article which images are associated to it. Finally, any image must be placed under data/. See next commit for how to configure nginx in order to make PHP scripts handle images requests.
-rw-r--r--examples/blog/articles/article_images.php7
-rw-r--r--examples/blog/data/giraffe.jpgbin0 -> 12464 bytes
-rw-r--r--examples/blog/essay_cc-form.html2
-rw-r--r--examples/blog/essay_fulfillment.php4
-rw-r--r--examples/blog/essay_pay.php3
-rw-r--r--examples/blog/images.php58
m---------examples/blog/web-common0
m---------examples/shop/web-common0
8 files changed, 66 insertions, 8 deletions
diff --git a/examples/blog/articles/article_images.php b/examples/blog/articles/article_images.php
index b9087e10..af730079 100644
--- a/examples/blog/articles/article_images.php
+++ b/examples/blog/articles/article_images.php
@@ -3,8 +3,9 @@
* Parse $html_filename and add an entry of the type
* "$html_filename" => ("img1.png", "img2.png") for each
* encountered 'img' tag having the 'src' attribute formatted
- * as "/essay/<article_slug>/data/img1.png", to the JSON which
- * associates any article with its images
+ * as "/essay/<article_filename>/data/img1.png", to the JSON which
+ * associates any article with its images.
+ * Note that <article_filename> has the final '.html' removed
*/
function add_article($html_filename){
$doc = new DOMDocument();
@@ -12,7 +13,7 @@
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('php', 'http://php.net/xpath');
$xpath->registerPhpFunctions('preg_match');
- $elements = $xpath->query('//img[php:functionString("preg_match", "@^/essay/[^/]+/data/[^/]+@", @src) > 0]');
+ $elements = $xpath->query('//img[php:functionString("preg_match", "@^/data/[^/]+/[^/]+@", @src) > 0]');
$db_filename = "articles_images.json";
$json_str;
if (file_exists($db_filename))
diff --git a/examples/blog/data/giraffe.jpg b/examples/blog/data/giraffe.jpg
new file mode 100644
index 00000000..521510fd
--- /dev/null
+++ b/examples/blog/data/giraffe.jpg
Binary files differ
diff --git a/examples/blog/essay_cc-form.html b/examples/blog/essay_cc-form.html
index 8c48ec35..d9b07e1d 100644
--- a/examples/blog/essay_cc-form.html
+++ b/examples/blog/essay_cc-form.html
@@ -99,7 +99,6 @@
if (walletNotPresent) {
return;
}
- // FIXME: this is a template, but very ugly ...
{jscode}
};
@@ -117,6 +116,5 @@
timer = window.setTimeout(handleTimeout, 250);
</script>
- <script type="application/javascript" src="web-common/taler-presence.js"></script>
</body>
</html>
diff --git a/examples/blog/essay_fulfillment.php b/examples/blog/essay_fulfillment.php
index 2e33c018..abe5c329 100644
--- a/examples/blog/essay_fulfillment.php
+++ b/examples/blog/essay_fulfillment.php
@@ -76,14 +76,14 @@
}
$hc = json_decode($resp->body->toString(), true)['H_contract'];
$my_payment['hc'] = $hc;
- syslog($LOG_INFO, "sending payment event");
+ //syslog($LOG_INFO, "sending payment event");
$js_code = "taler.executePayment(\"$hc\", \"$pay_url\", \"$offering_url\");";
$cc_page = template("./essay_cc-form.html", array('article' => $article, 'jscode' => $js_code));
echo $cc_page;
return;
}
// control here == article payed
- syslog($LOG_INFO, "showing article");
+ //syslog($LOG_INFO, "showing article");
$article = get_article($article);
echo $article;
?>
diff --git a/examples/blog/essay_pay.php b/examples/blog/essay_pay.php
index 8370ff3b..5ad3ccf8 100644
--- a/examples/blog/essay_pay.php
+++ b/examples/blog/essay_pay.php
@@ -19,7 +19,8 @@
include("../../copylib/util.php");
include("./blog_lib.php");
- syslog($LOG_INFO, "paying");
+ /*FIXME: the following log gets annoyingly sent to _any_ open terminal */
+ /*syslog($LOG_INFO, "paying");*/
$article = get($_GET["article"]);
if (empty($article)){
diff --git a/examples/blog/images.php b/examples/blog/images.php
new file mode 100644
index 00000000..d16b1d76
--- /dev/null
+++ b/examples/blog/images.php
@@ -0,0 +1,58 @@
+<?php
+/*
+ This file is part of GNU TALER.
+ Copyright (C) 2014, 2015, 2016 INRIA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Lesser General Public License as published by the Free Software
+ Foundation; either version 2.1, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along with
+ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+
+ include '../../copylib/util.php';
+
+ $article = get($_GET['article']);
+ $image = get($_GET['image']);
+ session_start();
+ $payments = &pull($_SESSION, 'payments', false);
+ if (!$payments) {
+ echo "No session active";
+ return 400;
+ }
+ if (null == get($payments[$article]['ispayed'])) {
+ echo "Article not payed";
+ return 400;
+ }
+
+ $db_filename = "articles/articles_images.json";
+ $json_str;
+ if (file_exists($db_filename))
+ $json_str = file_get_contents($db_filename);
+ else {
+ echo "Internal server error: data registry not found";
+ return 500;
+ }
+ $db = json_decode($json_str, true);
+ $article_images = get($db[$article . ".html"]);
+ if (null == $article_images) {
+ echo "This article has no images to sell";
+ return 400;
+ }
+ if (false === array_search($image, $article_images)) {
+ echo "Requested image does not belong to article '$article'";
+ return 400;
+ }
+
+ $image_path = "data/" . $image;
+ $fp = fopen($image_path, 'rb');
+ header("Content-Type: image/png"); // fix image extension
+ header("Content-Length: " . filesize($image_path));
+ fpassthru($fp);
+ exit;
+?>
diff --git a/examples/blog/web-common b/examples/blog/web-common
-Subproject 80f1e2708dbe4b19349244b611a6167b4b7a98c
+Subproject e2931f26c84cd577bba367a3e13cb5c0515c333
diff --git a/examples/shop/web-common b/examples/shop/web-common
-Subproject 80f1e2708dbe4b19349244b611a6167b4b7a98c
+Subproject e2931f26c84cd577bba367a3e13cb5c0515c333