Skip to content

Commit 9c37b14

Browse files
author
Francesco Abeni
committed
Reduce spammyness of mail notification
1 parent 0c5aa8d commit 9c37b14

File tree

2 files changed

+126
-46
lines changed

2 files changed

+126
-46
lines changed

component/frontend/helpers/pizzabox.php

+28-46
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<?php
2-
32
/**
4-
* @version frontend/helpers/pizzabox.php 2014-07-23 09:36:00 UTC zanardi
3+
* @version frontend/helpers/pizzabox.php 2015-06-22 16:39:00 UTC zanardi
54
* @package GiBi PizzaBox
65
* @author GiBiLogic <[email protected]>
76
* @authorUrl http://www.gibilogic.com
8-
* @copyright Copyright (C) 2011-2013 GiBiLogic. All rights reserved.
9-
* @license GNU/GPL v2 or later
7+
* @copyright Copyright (C) 2011-2015 GiBiLogic. All rights reserved.
8+
* @license GNU/GPL v3 or later
109
*/
1110
defined('_JEXEC') or die();
12-
require_once(JPATH_COMPONENT_ADMINISTRATOR . '/models/orders.php');
11+
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/orders.php';
1312

1413
/**
1514
* PizzaboxHelper
@@ -19,22 +18,18 @@ class PizzaboxHelper
1918

2019
public function __construct()
2120
{
22-
$this->params = & JComponentHelper::getParams('com_pizzabox');
21+
$this->params = JComponentHelper::getParams('com_pizzabox');
2322
}
2423

2524
public function formatPrice($price)
2625
{
27-
if (!is_numeric($price))
28-
{
26+
if (!is_numeric($price)) {
2927
return '';
3028
}
3129

32-
if ($this->params->get('currency_symbol_position', 'before') == 'before')
33-
{
30+
if ($this->params->get('currency_symbol_position', 'before') == 'before') {
3431
return $this->params->get('currency_symbol') . " " . sprintf("%.2f", $price);
35-
}
36-
else
37-
{
32+
} else {
3833
return sprintf("%.2f", $price) . " " . $this->params->get('currency_symbol');
3934
}
4035
}
@@ -55,16 +50,17 @@ public function emailNotification($order_id)
5550
$mailer->setSender($config->get('mailfrom', '[email protected]'));
5651

5752
// Recipient(s)
58-
foreach ($this->getAdminRecipients() as $email => $name)
59-
{
53+
foreach ($this->getAdminRecipients() as $email => $name) {
6054
$mailer->addRecipient($email, $name);
6155
}
6256
$user = JFactory::getUser();
6357
$mailer->addRecipient($user->email, $user->name);
6458

6559
// Subject and body
6660
$mailer->setSubject(JText::_('PIZZABOX_EMAIL_NOTIFICATION_SUBJECT'));
67-
$mailer->setBody('<html><body><p>' . JText::_('PIZZABOX_EMAIL_NOTIFICATION_BODY') . $this->buildOrderBody($order_id) . "</p></body></html>");
61+
$body = '<html><body><p>' . JText::_('PIZZABOX_EMAIL_NOTIFICATION_BODY') . $this->buildOrderBody($order_id) . "</p></body></html>";
62+
$mailer->setBody($body);
63+
$mailer->AltBody = JMailHelper::cleanText(strip_tags($body));
6864

6965
// Send message
7066
$mailer->IsHTML(true);
@@ -79,8 +75,7 @@ public function emailNotification($order_id)
7975
*/
8076
private function buildOrderBody($order_id)
8177
{
82-
if (!$this->params->get("email_includes_order", 0))
83-
{
78+
if (!$this->params->get("email_includes_order", 0)) {
8479
$link = JURI::root() . JRoute::_("index.php?option=com_pizzabox&controller=orders&task=edit&id=$order_id");
8580
return "<a href=\"$link\">" . JText::_('PIZZABOX_EMAIL_NOTIFICATION_BODY_ORDER_DETAIL') . "</a>";
8681
}
@@ -90,8 +85,7 @@ private function buildOrderBody($order_id)
9085
$this->order = $orderModel->getItem();
9186
$parts = $orderModel->getParts();
9287

93-
foreach ($parts as &$part)
94-
{
88+
foreach ($parts as &$part) {
9589
$part->container_image = JURI::root() . $this->getElementImage('containers', $part->container_id);
9690
$part->part_image = JURI::root() . $this->getElementImage('parts', $part->part_id);
9791
$part->flavour_image = JURI::root() . $this->getElementImage('flavours', $part->flavour_id);
@@ -104,29 +98,24 @@ private function buildOrderBody($order_id)
10498
$this->helper = new PizzaboxHelper();
10599

106100
ob_start();
107-
include JPATH_COMPONENT_SITE . '/layouts/_order_details.php';
108-
return "<div>".ob_get_clean()."</div>";
101+
include JPATH_COMPONENT_SITE . '/layouts/_mail_order_details.php';
102+
return "<div>" . ob_get_clean() . "</div>";
109103
}
110104

111105
/**
112106
* Get all admin recipients which should receive the notification
113107
*/
114108
private function getAdminRecipients()
115109
{
116-
if (!$this->params->get('email_notification', 0))
117-
{
110+
if (!$this->params->get('email_notification', 0)) {
118111
return array();
119112
}
120113

121114
$recipients = array();
122-
if ($this->params->get('email_address', ''))
123-
{
115+
if ($this->params->get('email_address', '')) {
124116
$recipients[$this->params->get('email_address')] = $this->params->get('email_address');
125-
}
126-
else
127-
{
128-
foreach ($this->_getSystemEmailAddresses() as $recipient)
129-
{
117+
} else {
118+
foreach ($this->_getSystemEmailAddresses() as $recipient) {
130119
$recipients[$recipient->email] = $recipient->name;
131120
}
132121
}
@@ -138,10 +127,8 @@ public function convertOrderRows($rows)
138127
{
139128
$results = array();
140129

141-
foreach ($rows as $row)
142-
{
143-
if (!array_key_exists($row->container_number, $results))
144-
{
130+
foreach ($rows as $row) {
131+
if (!array_key_exists($row->container_number, $results)) {
145132
$results[$row->container_number] = array(
146133
'id' => $row->container_id,
147134
'name' => $row->container_name,
@@ -151,8 +138,7 @@ public function convertOrderRows($rows)
151138
);
152139
}
153140

154-
if (!array_key_exists($row->part_id, $results[$row->container_number]['parts']))
155-
{
141+
if (!array_key_exists($row->part_id, $results[$row->container_number]['parts'])) {
156142
$results[$row->container_number]['parts'][$row->part_id] = array(
157143
'id' => $row->part_id,
158144
'name' => $row->part_name,
@@ -161,8 +147,7 @@ public function convertOrderRows($rows)
161147
);
162148
}
163149

164-
if (!array_key_exists($row->flavour_id, $results[$row->container_number]['parts'][$row->part_id]['flavours']))
165-
{
150+
if (!array_key_exists($row->flavour_id, $results[$row->container_number]['parts'][$row->part_id]['flavours'])) {
166151
$results[$row->container_number]['rowspan'] += 1;
167152
$results[$row->container_number]['parts'][$row->part_id]['flavours'][$row->flavour_id] = array(
168153
'id' => $row->flavour_id,
@@ -182,12 +167,11 @@ protected function _getSystemEmailAddresses()
182167
{
183168
$recipients = array();
184169
$query = "SELECT `name`, `email` " .
185-
"FROM `#__users` " .
186-
"WHERE `sendEmail` = '1'";
170+
"FROM `#__users` " .
171+
"WHERE `sendEmail` = '1'";
187172
$db = & JFactory::getDBO();
188173
$db->setQuery($query);
189-
if ($result = $db->loadObjectList())
190-
{
174+
if ($result = $db->loadObjectList()) {
191175
$recipients = $result;
192176
}
193177
}
@@ -202,8 +186,7 @@ protected function _getSystemEmailAddresses()
202186
private function getElementImage($elements_type, $id)
203187
{
204188
$class_name = "PizzaboxModel" . $elements_type;
205-
if (!class_exists($class_name))
206-
{
189+
if (!class_exists($class_name)) {
207190
require_once ( JPATH_COMPONENT_ADMINISTRATOR . '/models/' . $elements_type . '.php' );
208191
}
209192

@@ -212,5 +195,4 @@ private function getElementImage($elements_type, $id)
212195
$element = $model->getItem();
213196
return ( $element['row']->image );
214197
}
215-
216198
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* @version frontend/layouts/_mail_order_details.php 2015-06-22 16:20:00Z zanardi
4+
* @package GiBi PizzaBox
5+
* @author GiBiLogic <[email protected]>
6+
* @authorUrl http://www.gibilogic.com
7+
* @copyright Copyright (C) 2015 GiBiLogic. All rights reserved.
8+
* @license GNU/GPL v3 or later
9+
*/
10+
11+
defined('_JEXEC') or die('Restricted access');
12+
13+
?>
14+
<h3><?php echo JText::_('PIZZABOX_ORDER_DETAILS') ?></h3>
15+
<p><?php echo JText::_('PIZZABOX_ORDER_TOTAL') ?>: <strong><?php echo $this->helper->formatPrice($this->order_total) ?></strong></p>
16+
17+
<?php if ($this->tpl == 'confirmed') : ?>
18+
<?php
19+
if ($this->order['row']->delivery != '0000-00-00 00:00:00')
20+
{
21+
$delivery = new DateTime($this->order['row']->delivery);
22+
$date = $delivery->format('d/m/Y');
23+
$time = $delivery->format('H:i');
24+
}
25+
else
26+
{
27+
$date = '';
28+
$time = '';
29+
}
30+
?>
31+
<?php if ($date && $time): ?>
32+
<p><?php echo JText::sprintf('PIZZABOX_DELIVERY_DATETIME', $date, $time) ?></p>
33+
<?php endif ?>
34+
<p><?php echo JText::_('PIZZABOX_ORDER_NAME') ?>: <strong><?php echo $this->order['row']->name ?></strong></p>
35+
<?php else : ?>
36+
<p class="info"><?php echo JText::_('PIZZABOX_ORDER_NOT_CONFIRMED_YET') ?></p>
37+
<?php endif ?>
38+
39+
<table id="order_details" class="adminlist">
40+
<thead>
41+
<tr>
42+
<?php if ($this->tpl != 'confirmed'): ?>
43+
<th></th>
44+
<?php endif; ?>
45+
<th><?php echo JText::_('PIZZABOX_CONTAINER') ?></th>
46+
<th><?php echo JText::_('PIZZABOX_PART') ?></th>
47+
<th><?php echo JText::_('PIZZABOX_FLAVOUR') ?></th>
48+
</tr>
49+
</thead>
50+
<tbody>
51+
<?php foreach ($this->orderData as $containerNumber => $container): ?>
52+
<tr class="<?php echo ($containerNumber % 2 != 0 ? 'row1' : '') ?> row-container-<?php echo $containerNumber ?>">
53+
<?php if ($this->tpl != 'confirmed'): ?>
54+
<td rowspan="<?php echo $container['rowspan'] ?>" style="vertical-align:top;">
55+
<button class="btn btn-danger btn_delete_container" data-container="<?php echo $containerNumber ?>">
56+
<i class="icon-remove icon-white"></i>
57+
</button>
58+
</td>
59+
<?php endif; ?>
60+
<td rowspan="<?php echo $container['rowspan'] ?>" style="vertical-align:top;">
61+
<?php if (!empty($container['image'])): ?>
62+
<span class="image"><img src="<?php echo $container['image'] ?>" alt="<?php echo $container['name'] ?>" width="100" /></span>
63+
<?php endif; ?>
64+
<?php echo $container['name'] ?>
65+
</td>
66+
67+
<?php foreach($container['parts'] as $part): ?>
68+
<td rowspan="<?php echo count($part['flavours']) ?>" style="vertical-align:top;">
69+
<?php if (!empty($part['image'])): ?>
70+
<span class="image"><img src="<?php echo $part['image'] ?>" alt="<?php echo $part['name'] ?>" width="100" /></span>
71+
<?php endif; ?>
72+
<?php echo $part['name'] ?>
73+
</td>
74+
<?php foreach($part['flavours'] as $flavour): ?>
75+
<td>
76+
<?php if (!empty($flavour['image'])): ?>
77+
<span class="image"><img src="<?php echo $flavour['image'] ?>" alt="<?php echo $flavour['name'] ?>" width="100" /></span>
78+
<?php endif; ?>
79+
<?php echo $flavour['name'] ?>
80+
<?php if ($flavour['count'] > 1): ?>
81+
&nbsp;x<?php echo $flavour['count'] ?>
82+
<?php endif; ?>
83+
</td>
84+
</tr><tr class="<?php echo ($containerNumber % 2 != 0 ? 'row1' : '') ?> row-container-<?php echo $containerNumber ?>">
85+
<?php endforeach; ?>
86+
<?php endforeach; ?>
87+
</tr>
88+
<?php endforeach; ?>
89+
90+
<?php if (count($this->parts) == 0): ?>
91+
<tr>
92+
<td colspan="4" style="text-align:center;">
93+
<em><?php echo JText::_('PIZZABOX_EMPTY_ORDER') ?></em>
94+
</td>
95+
</tr>
96+
<?php endif; ?>
97+
</tbody>
98+
</table>

0 commit comments

Comments
 (0)