|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Paweł Mikołajczuk <[email protected]> |
|
5
|
|
|
* @copyright 2012 Sourcefabric o.p.s. |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-3.0.txt |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Newscoop subscribe_form block plugin. |
|
11
|
|
|
* |
|
12
|
|
|
* Type: block |
|
13
|
|
|
* Name: subscribe_form |
|
14
|
|
|
* Purpose: Displays a subscribe form |
|
15
|
|
|
* |
|
16
|
|
|
* @param string |
|
17
|
|
|
* $p_params |
|
18
|
|
|
* @param string |
|
19
|
|
|
* $p_smarty |
|
20
|
|
|
* @param string |
|
21
|
|
|
* $p_content |
|
22
|
|
|
* |
|
23
|
|
|
* @return string |
|
24
|
|
|
*/ |
|
25
|
|
|
function smarty_block_subscribe_form($p_params, $p_content, &$smarty) |
|
26
|
|
|
{ |
|
27
|
|
|
if (!isset($p_content)) { |
|
28
|
|
|
return ''; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$smarty->smarty->loadPlugin('smarty_shared_escape_special_chars'); |
|
32
|
|
|
$context = $smarty->getTemplateVars('gimme'); |
|
33
|
|
|
$entityManager = \Zend_Registry::get('container')->getService('em'); |
|
34
|
|
|
$orderService = \Zend_Registry::get('container')->getService('newscoop_paywall.services.order'); |
|
35
|
|
|
$url = $context->url; |
|
36
|
|
|
|
|
37
|
|
|
if (!isset($p_params['submit_button'])) { |
|
38
|
|
|
$p_params['submit_button'] = 'Subscribe'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (!isset($p_params['html_code']) || empty($p_params['html_code'])) { |
|
42
|
|
|
$p_params['html_code'] = ''; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (!isset($p_params['button_html_code']) || empty($p_params['button_html_code'])) { |
|
46
|
|
|
$p_params['button_html_code'] = ''; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (!isset($p_params['choose_text']) || empty($p_params['choose_text'])) { |
|
50
|
|
|
$p_params['choose_text'] = 'Choose...'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (isset($p_params['payment']) && $p_params['payment'] === 'offline') { |
|
54
|
|
|
$p_params['payment'] = '/'.$p_params['payment']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$meta = array(); |
|
58
|
|
|
$meta['publication'] = $context->publication->identifier; |
|
59
|
|
|
$meta['issue'] = $context->issue->number; |
|
60
|
|
|
$meta['section'] = $context->section->number; |
|
61
|
|
|
$meta['article'] = $context->article->number; |
|
62
|
|
|
|
|
63
|
|
|
$subscriptions = $entityManager->getRepository('Newscoop\PaywallBundle\Entity\Subscription') |
|
64
|
|
|
->findActiveBy($context->language->code, $meta); |
|
65
|
|
|
|
|
66
|
|
|
$html = '<form name="subscribe_content" action="'.$url->base.'/paywall/purchase/methods'.$p_params['payment'].'" method="get" '.$p_params['html_code'].'>'."\n"; |
|
67
|
|
|
|
|
68
|
|
|
$options = ''; |
|
|
|
|
|
|
69
|
|
|
if (array_key_exists('option_text', $p_params)) { |
|
70
|
|
|
$optionText = smarty_function_escape_special_chars($p_params['option_text']); |
|
71
|
|
|
} else { |
|
72
|
|
|
$optionText = 'This %type% for %range% month(s) - %price% %currency%'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if (array_key_exists('type', $p_params) && $p_params['type'] === 'radio') { |
|
76
|
|
View Code Duplication |
foreach ($subscriptions as $subscription) { |
|
|
|
|
|
|
77
|
|
|
foreach ($subscription['ranges'] as $range) { |
|
78
|
|
|
$order = $orderService->processAndCalculateOrderItems(array($subscription['id'] => $range['id']), $subscription['currency']); |
|
79
|
|
|
$html .= '<p><input type="radio" name="batchorder['.$subscription['id'].']" value="'.$range['id'].'"><span>'.str_replace('%currency%', $subscription['currency'], |
|
80
|
|
|
str_replace('%price%', $order->getTotal(), |
|
81
|
|
|
str_replace('%name%', $subscription['name'], |
|
82
|
|
|
str_replace('%range%', $range['value'], |
|
83
|
|
|
str_replace('%type%', $subscription['type'], $optionText) |
|
84
|
|
|
)))).'</span></p>'; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} else { |
|
88
|
|
|
foreach ($subscriptions as $subscription) { |
|
89
|
|
|
$options = ''; |
|
90
|
|
View Code Duplication |
foreach ($subscription['ranges'] as $range) { |
|
|
|
|
|
|
91
|
|
|
$order = $orderService->processAndCalculateOrderItems(array($subscription['id'] => $range['id']), $subscription['currency']); |
|
92
|
|
|
$options .= '<option value="'.$range['id'].'">'.str_replace('%currency%', $subscription['currency'], |
|
93
|
|
|
str_replace('%price%', $order->getTotal(), |
|
94
|
|
|
str_replace('%name%', $subscription['name'], |
|
95
|
|
|
str_replace('%range%', $range['value'], |
|
96
|
|
|
str_replace('%type%', $subscription['type'], $optionText) |
|
97
|
|
|
)))).'</option>'."\n"; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if ($options !== '') { |
|
101
|
|
|
$html .= '<select name="batchorder['.$subscription['id'].']"><option value="">'.$p_params['choose_text'].'</option>'.$options.'</select><br>'; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
$html .= $p_content; |
|
107
|
|
|
|
|
108
|
|
|
$html .= '<input type="submit" ' |
|
109
|
|
|
.'id="subscribe_content_submit" value="' |
|
110
|
|
|
.smarty_function_escape_special_chars($p_params['submit_button']) |
|
111
|
|
|
.'" '.$p_params['button_html_code']." />\n"; |
|
112
|
|
|
$html .= "</form>\n"; |
|
113
|
|
|
|
|
114
|
|
|
return $html; |
|
115
|
|
|
} |
|
116
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.