commit 652332ea48f6e8160cd10c690755a0c38a0ae3ef
parent cce5ba991be08b4128a5e34c2b515390f77d30f7
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Fri, 19 Feb 2016 11:42:57 +0100
indenting php
Diffstat:
6 files changed, 276 insertions(+), 322 deletions(-)
diff --git a/src/frontend_blog/blog_lib.php b/src/frontend_blog/blog_lib.php
@@ -1,42 +1,37 @@
<?php
-
-/**
- * Take a (article's) filename and return its
- * teaser. It has the articles folder hardcoded
- */
-function get_title($name){
- $content = file_get_contents("articles/$name.html");
- $doc = new DOMDocument();
- $doc->loadHTML($content);
- $finder = new DOMXPath($doc);
- $query_set = $finder->query("//h1[@class='chapter' or @class='unnumbered']");
- if (1 != $query_set->length)
- return "No title for this item";
- // assuming all the articles are well-formed..
- return $query_set->item(0)->nodeValue;
-}
-
-/**
- * Take a (article's) filename and return its
- * DOM. It has the articles folder hardcoded
- */
-function get_article($name){
- $raw_content = file_get_contents("articles/$name.html");
- return $raw_content;
- /*$doc = new DOMDocument();
- $doc->loadHTML($content);
- return $doc;*/
-}
-
-/**
- * Fetch the page $page and return its
- * DOM.
- */
-function get_page($page){
- $content = file_get_contents($page);
- $doc = new DOMDocument();
- $doc->loadHTML($content);
- return $doc;
-}
-
+ /**
+ * Take a (article's) filename and return its
+ * teaser. It has the articles folder hardcoded
+ */
+ function get_title($name){
+ $content = file_get_contents("articles/$name.html");
+ $doc = new DOMDocument();
+ $doc->loadHTML($content);
+ $finder = new DOMXPath($doc);
+ $query_set = $finder->query("//h1[@class='chapter' or @class='unnumbered']");
+ if (1 != $query_set->length)
+ return "No title for this item";
+ // assuming all the articles are well-formed..
+ return $query_set->item(0)->nodeValue;
+ }
+
+ /**
+ * Take a (article's) filename and return its
+ * DOM. It has the articles folder hardcoded
+ */
+ function get_article($name){
+ $raw_content = file_get_contents("articles/$name.html");
+ return $raw_content;
+ }
+
+ /**
+ * Fetch the page $page and return its
+ * DOM.
+ */
+ function get_page($page){
+ $content = file_get_contents($page);
+ $doc = new DOMDocument();
+ $doc->loadHTML($content);
+ return $doc;
+ }
?>
diff --git a/src/frontend_blog/essay_cc-form.html b/src/frontend_blog/essay_cc-form.html
@@ -1,100 +1,93 @@
<html>
-<head>
-<link rel="stylesheet" type="text/css" href="../style.css">
-</head>
-<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
-
-<header><div id="logo"><img src="../gnu.svg" height="100" width="100"></div><h1>Credit card payment</h1></header>
- <section id="main">
-
+ <head>
+ <link rel="stylesheet" type="text/css" href="../style.css">
+ </head>
+ <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
+ <header>
+ <div id="logo"><img src="../gnu.svg" height="100" width="100"></div>
+ <h1>Credit card payment</h1>
+ </header>
+ <section id="main">
<h1>Enter your details</h1>
<p>We need a few details before proceeding with credit card payment</p>
- <form>
- First name<br> <input type="text"></input><br>
- Family name<br> <input type="text"></input><br>
- Age<br> <input type="text"></input><br>
- Nationality<br> <input type="text"></input><br>
- Gender<br> <input type="radio" name"gender">Male</input>
- <input type="radio" name="gender">Female</input><br>
- <input id='article-name' type="hidden" value="{article}"></input>
- </form>
- <form method="post" action="essay_cc-fulfillment.php?article={article}">
- <input type="submit"></input>
- </form>
-
- </section>
- <script type="application/javascript" src="taler-presence.js"></script>
- <script type="application/javascript">
- function handle_contract(json_contract) {
- var cEvent = new CustomEvent('taler-contract',
- {detail: json_contract});
- document.dispatchEvent(cEvent);
- };
-
- function get_contract(article) {
- var contract_request = new XMLHttpRequest();
+ <form>
+ First name<br> <input type="text"></input><br>
+ Family name<br> <input type="text"></input><br>
+ Age<br> <input type="text"></input><br>
+ Nationality<br> <input type="text"></input><br>
+ Gender<br> <input type="radio" name"gender">Male</input>
+ <input type="radio" name="gender">Female</input><br>
+ <input id='article-name' type="hidden" value="{article}"></input>
+ </form>
+ <form method="post" action="essay_cc-fulfillment.php?article={article}">
+ <input type="submit"></input>
+ </form>
+ </section>
+ <script type="application/javascript">
+ function handle_contract(json_contract) {
+ var cEvent = new CustomEvent('taler-contract',
+ {detail: json_contract});
+ document.dispatchEvent(cEvent);
+ };
- contract_request.open("GET",
- "essay_contract.php?article=" + article,
- true);
- contract_request.onload = function (e) {
- if (contract_request.readyState == 4) {
- if (contract_request.status == 200) {
- console.log("response text:",
- contract_request.responseText);
- handle_contract(contract_request.responseText);
- } else {
- alert("Failure to download contract from merchant " +
- "(" + contract_request.status + "):\n" +
- contract_request.responseText);
- }
+ function get_contract(article) {
+ var contract_request = new XMLHttpRequest();
+ contract_request.open("GET",
+ "essay_contract.php?article=" + article,
+ true);
+ contract_request.onload = function (e) {
+ if (contract_request.readyState == 4) {
+ if (contract_request.status == 200) {
+ console.log("response text:",
+ contract_request.responseText);
+ handle_contract(contract_request.responseText);
+ } else {
+ alert("Failure to download contract from merchant " +
+ "(" + contract_request.status + "):\n" +
+ contract_request.responseText);
+ }
+ }
+ };
+ contract_request.onerror = function (e) {
+ alert("Failure requesting the contract:\n"
+ + contract_request.statusText);
+ };
+ contract_request.send();
}
- };
- contract_request.onerror = function (e) {
- alert("Failure requesting the contract:\n"
- + contract_request.statusText);
- };
- contract_request.send();
- }
- function has_taler_wallet_cb(aEvent)
- {
- var article = document.getElementById('article-name');
- get_contract(article.value);
- };
+ function has_taler_wallet_cb(aEvent){
+ var article = document.getElementById('article-name');
+ get_contract(article.value);
+ };
- function signal_taler_wallet_onload()
- {
- var eve = new Event('taler-probe');
- document.dispatchEvent(eve);
- };
+ function signal_taler_wallet_onload(){
+ var eve = new Event('taler-probe');
+ document.dispatchEvent(eve);
+ };
- document.addEventListener("taler-wallet-present",
- has_taler_wallet_cb,
- false);
+ document.addEventListener("taler-wallet-present",
+ has_taler_wallet_cb,
+ false);
- // Register event to be triggered by the wallet when it gets enabled while
- // the user is on the payment page
- document.addEventListener("taler-load",
- signal_taler_wallet_onload,
- false);
+ // Register event to be triggered by the wallet when it gets enabled while
+ // the user is on the payment page
+ document.addEventListener("taler-load",
+ signal_taler_wallet_onload,
+ false);
-
-
-
- function executePayment(H_contract, pay_url, offering_url) {
- var detail = {
- H_contract: H_contract,
- pay_url: pay_url,
- offering_url: offering_url
- };
- var eve = new CustomEvent('taler-execute-payment', {detail: detail});
- document.dispatchEvent(eve);
- }
- </script>
-
- <script type="text/javascript">
- {jscode}
- </script>
-</body>
+ function executePayment(H_contract, pay_url, offering_url) {
+ var detail = {
+ H_contract: H_contract,
+ pay_url: pay_url,
+ offering_url: offering_url
+ };
+ var eve = new CustomEvent('taler-execute-payment', {detail: detail});
+ document.dispatchEvent(eve);
+ }
+ </script>
+ <script type="application/javascript" src="taler-presence.js"></script>
+ <script type="text/javascript">
+ {jscode}
+ </script>
+ </body>
</html>
diff --git a/src/frontend_blog/essay_cc-fulfillment.php b/src/frontend_blog/essay_cc-fulfillment.php
@@ -1,20 +1,18 @@
<?php
+ include '../frontend_lib/util.php';
+ include './blog_lib.php';
-include '../frontend_lib/util.php';
-include './blog_lib.php';
+ $article = get($_GET['article']);
+ if (null == $article){
+ http_response_code(400);
+ echo "Bad request (no article specified)";
+ return;
+ }
-$article = get($_GET['article']);
-if (null == $article)
-{
- http_response_code(400);
- echo "Bad request (no article specified)";
- return;
-}
-
-session_start();
-$payments = &pull($_SESSION, "payments", array());
-$payments[$article] = "payed";
-$fulfillment_url = url_rel("essay_fulfillment.php");
-header("Location: $fulfillment_url");
-die();
+ session_start();
+ $payments = &pull($_SESSION, "payments", array());
+ $payments[$article] = "payed";
+ $fulfillment_url = url_rel("essay_fulfillment.php");
+ header("Location: $fulfillment_url");
+ die();
?>
diff --git a/src/frontend_blog/essay_contract.php b/src/frontend_blog/essay_contract.php
@@ -15,67 +15,55 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-include("../frontend_lib/merchants.php");
-include("../frontend_lib/util.php");
-include("../frontend_lib/config.php");
-include("./blog_lib.php");
-
-$article = get($_GET['article']);
-if (null == $article){
- echo "Please land here just to buy articles";
- die();
- }
-
-// send contract
-$transaction_id = rand(0, 1001);
-//$p_id = hexdec(substr(sha1($article), -5));
-file_put_contents('/tmp/yyy', "bogus");
-file_put_contents('/tmp/yyy', $MERCHANT_CURRENCY);
-$now = new DateTime('now');
-$teaser = get_title($article);
-$amount_value = 0;
-$amount_fraction = 50000;
-$teatax = array ();
-$transaction_id = rand(0, 1001);
-
-$fulfillment_url = url_rel("essay_fulfillment.php")
- . '×tamp=' . $now->getTimestamp()
- . '&tid=' . $transaction_id;
+ include("../frontend_lib/merchants.php");
+ include("../frontend_lib/util.php");
+ include("../frontend_lib/config.php");
+ include("./blog_lib.php");
-$contract_json = generate_contract($amount_value,
- $amount_fraction,
- $MERCHANT_CURRENCY,
- $transaction_id,
- trim($teaser),
- $article,
- $article,
- $teatax,
- $now,
- $fulfillment_url);
-$resp = give_to_backend($_SERVER['HTTP_HOST'],
- "backend/contract",
- $contract_json);
-
-// Our response code is the same we got from the backend:
-$status_code = $resp->getResponseCode();
-http_response_code ($status_code);
-
-// Now generate our body
-if ($status_code != 200)
-{
- echo json_encode(array(
- 'error' => "internal error",
- 'hint' => "backend indicated error",
- 'detail' => $resp->body->toString()
- ), JSON_PRETTY_PRINT);
-}
-else
-{
- $got_json = json_decode($resp->body->toString(), true);
- $hc = $got_json["H_contract"];
- session_start();
- $payments = &pull($_SESSION, "payments", array());
- $payments[$article] = "inprogress";
- echo $resp->body->toString();
-}
+ $article = get($_GET['article']);
+ if (null == $article){
+ echo "Please land here just to buy articles";
+ die();
+ }
+ // send contract
+ $transaction_id = rand(0, 1001);
+ $now = new DateTime('now');
+ $teaser = get_title($article);
+ $amount_value = 0;
+ $amount_fraction = 50000;
+ $teatax = array ();
+ $transaction_id = rand(0, 1001);
+ $fulfillment_url = url_rel("essay_fulfillment.php")
+ . '×tamp=' . $now->getTimestamp()
+ . '&tid=' . $transaction_id;
+ $contract_json = generate_contract($amount_value,
+ $amount_fraction,
+ $MERCHANT_CURRENCY,
+ $transaction_id,
+ trim($teaser),
+ $article,
+ $article,
+ $teatax,
+ $now,
+ $fulfillment_url);
+ $resp = give_to_backend($_SERVER['HTTP_HOST'],
+ "backend/contract",
+ $contract_json);
+ $status_code = $resp->getResponseCode();
+ http_response_code ($status_code);
+ if ($status_code != 200){
+ echo json_encode(array(
+ 'error' => "internal error",
+ 'hint' => "backend indicated error",
+ 'detail' => $resp->body->toString()
+ ), JSON_PRETTY_PRINT);
+ }
+ else {
+ $got_json = json_decode($resp->body->toString(), true);
+ $hc = $got_json["H_contract"];
+ session_start();
+ $payments = &pull($_SESSION, "payments", array());
+ $payments[$article] = "inprogress";
+ echo $resp->body->toString();
+ }
?>
diff --git a/src/frontend_blog/essay_fulfillment.php b/src/frontend_blog/essay_fulfillment.php
@@ -1,5 +1,5 @@
-<!DOCTYPE html>
-<!--
+<?php
+/*
This file is part of GNU TALER.
Copyright (C) 2014, 2015 GNUnet e.V.
@@ -13,76 +13,66 @@
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/>
--->
-<?php
-include '../frontend_lib/util.php';
-include '../frontend_lib/merchants.php';
-include '../frontend_lib/config.php';
-include './blog_lib.php';
-
-$article = get($_GET['article']);
-if (null == $article){
- http_response_code(400);
- echo "<p>Bad request (article missing)</p>";
- return;
-}
-
-session_start();
-
-$payments = get($_SESSION['payments'], array());
-$my_payment = get($payments[$article]);
-
-$pay_url = url_rel("essay_pay.php");
-$offering_url = url_rel("essay_offer.php", true);
-$offering_url .= "?article=$article";
-if ("payed" != $my_payment || null === $my_payment)
-
-{
- $tid = get($_GET['tid']);
- $timestamp = get($_GET['timestamp']);
- // 1st time
- if (null == $tid || null == $timestamp){
- $js_code = "get_contract(\"$article\")";
+*/
+ include '../frontend_lib/util.php';
+ include '../frontend_lib/merchants.php';
+ include '../frontend_lib/config.php';
+ include './blog_lib.php';
+
+ $article = get($_GET['article']);
+ if (null == $article){
+ http_response_code(400);
+ echo "<p>Bad request (article missing)</p>";
+ return;
+ }
+ session_start();
+ $payments = get($_SESSION['payments'], array());
+ $my_payment = get($payments[$article]);
+ $pay_url = url_rel("essay_pay.php");
+ $offering_url = url_rel("essay_offer.php", true);
+ $offering_url .= "?article=$article";
+ if ("payed" != $my_payment || null === $my_payment){
+ $tid = get($_GET['tid']);
+ $timestamp = get($_GET['timestamp']);
+ // 1st time
+ if (null == $tid || null == $timestamp){
+ $js_code = "get_contract(\"$article\")";
+ $cc_page = template("./essay_cc-form.html", array('article' => $article, 'jscode' => $js_code));
+ echo $cc_page;
+ die();
+ }
+ // restore contract
+ $now = new DateTime();
+ $now->setTimestamp(intval($timestamp));
+ $contract_rec = generate_contract(0,
+ 50000,
+ $MERCHANT_CURRENCY,
+ intval($tid),
+ trim(get_title($article)),
+ $article,
+ $article,
+ array(),
+ $now,
+ get_full_uri());
+ $resp = give_to_backend($_SERVER['HTTP_HOST'],
+ "backend/contract",
+ $contract_rec);
+ if ($resp->getResponseCode() != 200){
+ echo json_encode(array(
+ 'error' => "internal error",
+ 'hint' => "non hashable contract",
+ 'detail' => $resp->body->toString()
+ ), JSON_PRETTY_PRINT);
+ die();
+ }
+ $hc = json_decode($resp->body->toString(), true)['H_contract'];
+ $js_code = "executePayment('$hc', '$pay_url', '$offering_url')";
$cc_page = template("./essay_cc-form.html", array('article' => $article, 'jscode' => $js_code));
echo $cc_page;
- die();
- }
- // restore
- $now = new DateTime();
- $now->setTimestamp(intval($timestamp));
- $contract_rec = generate_contract(0,
- 50000,
- $MERCHANT_CURRENCY,
- intval($tid),
- trim(get_title($article)),
- $article,
- $article,
- array(),
- $now,
- get_full_uri());
-
- $resp = give_to_backend($_SERVER['HTTP_HOST'],
- "backend/contract",
- $contract_rec);
- if ($resp->getResponseCode() != 200)
- {
- echo json_encode(array(
- 'error' => "internal error",
- 'hint' => "non hashable contract",
- 'detail' => $resp->body->toString()
- ), JSON_PRETTY_PRINT);
- die();
- }
- $hc = json_decode($resp->body->toString(), true)['H_contract'];
- file_put_contents("/tmp/hash2", $hc."\n");
- $js_code = "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
-
-$article = get_article($article);
-echo $article;
+ return;
+ }
+
+ // control here == article payed
+ $article = get_article($article);
+ echo $article;
?>
diff --git a/src/frontend_blog/essay_pay.php b/src/frontend_blog/essay_pay.php
@@ -15,47 +15,37 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-/**
- * TODO check the hashed contract in the state against the hashed contract
- * actually bundled in the deposit permission
- */
-include("../frontend_lib/merchants.php");
-include("../frontend_lib/util.php");
-include("./blog_lib.php");
-
-$article = get($_GET["article"]);
-if (empty($article))
-{
- http_response_code(400);
- echo json_encode(array(
- "error" => "missing parameter",
- "parameter" => "article"
- ));
- return;
-}
-
-$deposit_permission = file_get_contents('php://input');
-$resp = give_to_backend($_SERVER['HTTP_HOST'],
- "backend/pay",
- $deposit_permission);
-$status_code = $resp->getResponseCode();
-
-// Our response code is the same we got from the backend:
-http_response_code ($status_code);
-// Now generate our body
-if ($status_code != 200)
-{
- $json = json_encode(
- array(
- "error" => "backend error",
- "status" => $status_code,
- "detail" => $resp->body->toString()));
- echo $json;
- die();
-}
-
-session_start();
-
-$payments = &pull($_SESSION, "payments", array());
-$payments[$article] = "payed";
+ include("../frontend_lib/merchants.php");
+ include("../frontend_lib/util.php");
+ include("./blog_lib.php");
+ $article = get($_GET["article"]);
+ if (empty($article)){
+ http_response_code(400);
+ echo json_encode(array(
+ "error" => "missing parameter",
+ "parameter" => "article"
+ ));
+ return;
+ }
+ $deposit_permission = file_get_contents('php://input');
+ // FIXME check here if the deposit permission is associated
+ // with the article that's going to be payed
+ $resp = give_to_backend($_SERVER['HTTP_HOST'],
+ "backend/pay",
+ $deposit_permission);
+ $status_code = $resp->getResponseCode();
+ http_response_code ($status_code);
+ if ($status_code != 200)
+ {
+ $json = json_encode(
+ array(
+ "error" => "backend error",
+ "status" => $status_code,
+ "detail" => $resp->body->toString()));
+ echo $json;
+ die();
+ }
+ session_start();
+ $payments = &pull($_SESSION, "payments", array());
+ $payments[$article] = "payed";
?>