Additional changes to get ad script download working, a=chris
Additional changes to get ad script download working, a=chris
<?php
/**
* SeekQuarry/Yioop --
* Open Source Pure PHP Search Engine, Crawler, and Indexer
*
* Copyright (C) 2009 - 2014 Chris Pollett chris@pollett.org
*
* LICENSE:
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* END LICENSE
*
* @author Chris Pollett chris@pollett.org
* @package seek_quarry
* @subpackage view
* @license http://www.gnu.org/licenses/ GPL3
* @link http://www.seekquarry.com/
* @copyright 2009 - 2014
* @filesource
*/
namespace seekquarry\yioop\views;
use seekquarry\yioop as B;
use seekquarry\yioop\configs as C;
/**
* This View is responsible for drawing the download
* information request form for the Seek Quarry app
*
* @author Chris Pollett
* @package seek_quarry
* @subpackage view
*/
class StoreView extends View
{
/** This view is drawn on a web layout
* @var string
*/
var $layout = "web";
/**
* Draws the various download ad script forms.
*
* @param array $data contains the anti CSRF token YIOOP_TOKEN
* the view
*/
function renderView($data)
{
$method = "render" . ucfirst($data['FORM_TYPE']);
$this->$method($data);
}
function renderGetScript($data)
{
$logo = C\BASE_URL . C\LOGO;
?>
<div class="download">
<h1 class="logo"><a href="<?=C\BASE_URL ?>"><img src="<?=$logo ?>"
alt="SeekQuarry" /></a><span> - <?= tl('store_view_get_form')
?></span></h1>
<form method="post" onsubmit="return checkFields();">
<input type="hidden" name="YIOOP_TOKEN" value="<?=
$data['YIOOP_TOKEN'] ?>" />
<input type="hidden" name="c" value="main" />
<input type="hidden" name="a" value="store" />
<input type="hidden" name="arg" value="<?= $data['FORM_TYPE'] ?>" />
<table>
<tr><td colspan="2"><?=
tl('store_view_keyword_purchase') ?></td></tr>
<tr><th class="table-label" ><label for="e-mail"><?=
tl('download_view_email') ?></label>:</th>
<td class="table-input"><input id="e-mail" type="text"
class="narrowfield" maxlength="80" name="e_mail" /></td>
<tr>
<th class="table-label" ><label for="nameserver-id"><?=
tl('store_view_name_server') ?></label>:</th>
<td class="table-input"><input id="nameserver-id" type="text"
class="narrowfield" maxlength="80" name="name_server" /></td>
</tr>
<tr><td colspan="2" class="center">
<button type="submit" name="c" value="main"><?=
tl('store_view_get_script') ?></button>
</td></tr>
</table>
</form>
<div class="center"><a href="<?=
B\wikiUrl('Downloads', false, 'static') ?>"><?=
tl('store_view_return_main') ?></a></div>
</div>
<script type="text/javascript" />
function checkFields()
{
var email = elt('e-mail');
var email_regex =
/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var email_good = email_regex.test(email.value);
var good = true;
if (!email_good) {
email.style.backgroundColor = 'red';
good = false
} else {
email.style.backgroundColor = 'white';
}
var nameserver = elt('nameserver-id');
var url_regex = /^https?\:\/\/.*$/; //very crude
var nameserver_good = url_regex.test(nameserver.value);
if (!nameserver_good) {
nameserver.style.backgroundColor = 'red';
good = false;
} else {
nameserver.style.backgroundColor = 'white';
}
if(!good) {
doMessage('<h1 class="red"><?=
tl("store_view_invalid fields") ?></h1>');
return false;
}
return true;
}
</script>
<?php
}
function renderPurchaseScript($data)
{
$logo = C\BASE_URL . C\LOGO;
?>
<div class="download">
<h1 class="logo"><a href="<?=C\BASE_URL ?>"><img src="<?=$logo ?>"
alt="SeekQuarry" /></a><span> - <?= tl('store_view_purchase_form')
?></span></h1>
<form id="adScriptPurchaseForm" method="post"
onsubmit="return checkFields();">
<input type="hidden" name="YIOOP_TOKEN" value="<?=
$data['YIOOP_TOKEN'] ?>" />
<input type="hidden" name="c" value="main" />
<input type="hidden" name="a" value="store" />
<input type="hidden" name="arg" value="<?= $data['FORM_TYPE'] ?>" />
<input type="hidden" id="credit-token" name="CREDIT_TOKEN" value="" />
<table>
<tr><td colspan="2" class="center"><div><?=
tl('store_view_purchase_instructions');?></div></td></tr>
<tr><th class="table-label" ><label for="e-mail"><?=
tl('download_view_email') ?></label>:</th>
<td class="table-input"><input id="e-mail" type="text"
class="narrowfield" maxlength="80" name="e_mail"
value="<?=$data['E_MAIL'] ?>" /></td>
<tr>
<th class="table-label" ><label for="nameserver-id"><?=
tl('store_view_name_server') ?></label>:</th>
<td class="table-input"><input id="nameserver-id" type="text"
class="narrowfield" maxlength="80" name="name_server"
value="<?=$data['NAME_SERVER'] ?>" /></td>
</tr>
<tr><th class="table-label"><label for="cost"><?=
tl('store_view_cost') ?>:
</label></th>
<td>
<input class="narrow-field" type="text" readonly="readonly"
disabled="disabled" value="<?=
C\AD_SCRIPT_COST ?>" />
</td>
</tr>
<tr><th class="table-label"><label for="card-number"><?=
tl('store_view_card_number') ?>:
</label></th>
<td>
<input class="narrow-field" id="card-number"
type="text" size="20" <?=
C\CreditConfig::getAttribute('card-number','name')
?>="<?=
C\CreditConfig::getAttribute('card-number','value')
?>" />
</td></tr>
<tr><th class="table-label"><label for="cvc"><?=
tl('store_view_cvc') ?>:
</label></th>
<td>
<input class="narrow-field" id="cvc"
type="text" size="4" <?=
C\CreditConfig::getAttribute('cvc','name')?>="<?=
C\CreditConfig::getAttribute('cvc','value') ?>" />
</td></tr>
<tr><th class="table-label"><label for="expiration"><?=
tl('store_view_expiration') ?>:
</label></th>
<td>
<?php
$this->helper('options')->render('expiration', '',
$data['MONTHS'], 0, false, [
C\CreditConfig::getAttribute('exp-month','name') =>
C\CreditConfig::getAttribute('exp-month','value'),
"class" => "medium-font"]);
?> / <?php
$this->helper('options')->render('', '',
$data['YEARS'], 0, false, [
C\CreditConfig::getAttribute('exp-year','name') =>
C\CreditConfig::getAttribute('exp-year','value'),
"class" => "medium-font"]);
?>
</td></tr>
<tr><td colspan="2" class="center">
<button type="submit" id="purchase" name="c" value="main"><?=
tl('store_view_get_script') ?></button>
<script type="text/javascript">
document.getElementById('purchase').onclick =
function(event) {
var ad_form = elt('adScriptPurchaseForm');
elt('purchase').disabled = true;
Stripe.card.createToken(ad_form, tokenResponseHandler);
event.preventDefault();
}
function tokenResponseHandler(status, response) {
var ad_form = elt('adScriptPurchaseForm');
if (response.error) {
alert(response.error.message);
elt('purchase').disabled = false;
} else {
elt('credit-token').value = response.id;
ad_form.submit();
}
}
</script>
</td></tr>
</table>
</form>
<div class="center"><a href="<?=
B\wikiUrl('Downloads', false, 'static') ?>"><?=
tl('store_view_return_main') ?></a></div>
</div>
<script type="text/javascript" />
function checkFields()
{
var email = elt('e-mail');
var email_regex =
/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var email_good = email_regex.test(email.value);
if(!email_good) {
email.style.backgroundColor = 'red';
doMessage('<h1 class="red"><?=
tl("store_view_valid_email") ?></h1>');
return false;
}
return true;
}
</script>
<?php
}
function renderShowScript($data)
{
$logo = C\BASE_URL . C\LOGO;
?>
<div class="download">
<h1 class="logo"><a href="<?=C\BASE_URL ?>"><img src="<?=$logo ?>"
alt="SeekQuarry" /></a><span> - <?= tl('store_view_show_form')
?></span></h1>
<table>
<tr><td colspan="2">
<h2><?= tl('store_view_show_instructions') ?></h2>
<ol>
<li><?= tl('store_view_script_instructions1') ?></li>
<li><?= tl('store_view_script_instructions2') ?></li>
<li><?= tl('store_view_script_instructions3') ?><br />
<tt> WORK_DIRECTORY/app/configs/CreditConfig.php
</tt><br />
<?= tl('store_view_script_instructions4') ?></li>
</ol></td></tr>
<tr><td>
<?=
$this->element('creditconfig')->render($data);
?>
</td></tr>
</table>
</div>
<?php
}
}