1 |
18092
|
thanos.pap
|
<?php
|
2 |
|
|
|
3 |
|
|
defined('_JEXEC') or die('Access denied');
|
4 |
|
|
|
5 |
|
|
jimport('joomla.application.component.view');
|
6 |
|
|
jimport('joomla.log.log');
|
7 |
|
|
jimport('joomla.utilities.utility');
|
8 |
|
|
|
9 |
|
|
class OpenAireViewEmailPublication extends JView {
|
10 |
25039
|
thanos.pap
|
const SEARCH = 'search';
|
11 |
|
|
const PIWIK = 'piwik';
|
12 |
18092
|
thanos.pap
|
const LOG = 'openaire';
|
13 |
18107
|
thanos.pap
|
const MAX_LINE = 900; // max allowable email line is 998 chars
|
14 |
18092
|
thanos.pap
|
|
15 |
|
|
function display($template = NULL) {
|
16 |
|
|
$application = JFactory :: getApplication();
|
17 |
|
|
$locale = JFactory :: getLanguage() -> getTag();
|
18 |
|
|
$itemId = JRequest :: getUInt('Itemid', 0);
|
19 |
|
|
$publicationId = JRequest :: getString('publicationId');
|
20 |
|
|
$recipient = JRequest :: getString('recipient');
|
21 |
25039
|
thanos.pap
|
$this -> getModel(self :: PIWIK) -> track('emailPublication', 'publicationId=' . urlencode($this -> publicationId) . '&locale=' . urlencode($locale) . '&recipient=' . urlencode($recipient));
|
22 |
|
|
$publication = $this -> getModel(self :: SEARCH) -> getPublication($publicationId, $locale);
|
23 |
18092
|
thanos.pap
|
$this -> loadHelper('PublicationHelper');
|
24 |
|
|
if (($publicationId == NULL) || ($publication == NULL) || ($publication -> title == NULL))
|
25 |
|
|
JLog :: add('Error sending publication ' . $publicationId . ' via email to ' . $recipient . ': error retrieving publication', JLog :: ERROR, self :: LOG);
|
26 |
25013
|
thanos.pap
|
else if (JUtility :: sendMail(JText :: _('EMAIL_ADDRESS'), JText :: _('OPENAIRE'), $recipient, JText :: _('OPENAIRE') . ' - ' . $publication -> title, $this -> splitLines(PublicationHelper :: formatPublication($publication, $itemId)), TRUE))
|
27 |
18092
|
thanos.pap
|
JLog :: add('Sent publication ' . $publicationId . ' via email to ' . $recipient, JLog :: INFO, self :: LOG);
|
28 |
|
|
else
|
29 |
|
|
JLog :: add('Error sending publication ' . $publicationId . ' via email to ' . $recipient . ': error delivering message', JLog :: ERROR, self :: LOG);
|
30 |
30864
|
yannis.str
|
$application -> redirect(JRoute :: _('index.php?option=com_openaire&view=article&Itemid=' . $itemId . '&articleId=' . $publicationId, FALSE));
|
31 |
18092
|
thanos.pap
|
return TRUE;
|
32 |
18107
|
thanos.pap
|
}
|
33 |
|
|
|
34 |
|
|
private function splitLines($body) {
|
35 |
|
|
$newBody = '';
|
36 |
|
|
while (strlen($body) >= self :: MAX_LINE) {
|
37 |
|
|
$line = substr($body, 0, self :: MAX_LINE);
|
38 |
|
|
$line = substr($line, 0, strrpos($line, ' '));
|
39 |
|
|
$body = substr($body, strlen($line));
|
40 |
|
|
$newBody .= $line . "\n";
|
41 |
|
|
}
|
42 |
|
|
$newBody .= $body;
|
43 |
|
|
return $newBody;
|
44 |
|
|
}
|
45 |
18092
|
thanos.pap
|
}
|