merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 5eac4e76af3c5aea686213854e08c0753f92d523
parent 0776397028140e6441b22928cc5d7c5d73a54015
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Mon, 25 Jul 2016 18:30:04 +0200

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.

Diffstat:
Mexamples/blog/articles/article_images.php | 7++++---
Aexamples/blog/data/giraffe.jpg | 0
Mexamples/blog/essay_cc-form.html | 2--
Mexamples/blog/essay_fulfillment.php | 4++--
Mexamples/blog/essay_pay.php | 3++-
Aexamples/blog/images.php | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 66 insertions(+), 8 deletions(-)

diff --git 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 Binary files differ. diff --git 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 @@ -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 @@ -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 @@ -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; +?>