1
|
<?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
|
const SEARCH = 'search';
|
11
|
const PIWIK = 'piwik';
|
12
|
const LOG = 'openaire';
|
13
|
const MAX_LINE = 900; // max allowable email line is 998 chars
|
14
|
|
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
|
$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
|
$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
|
else if (JUtility :: sendMail(JText :: _('EMAIL_ADDRESS'), JText :: _('OPENAIRE'), $recipient, JText :: _('OPENAIRE') . ' - ' . $publication -> title, $this -> splitLines(PublicationHelper :: formatPublication($publication, $itemId)), TRUE))
|
27
|
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
|
$application -> redirect(JRoute :: _('index.php?option=com_openaire&view=article&Itemid=' . $itemId . '&articleId=' . $publicationId, FALSE));
|
31
|
return TRUE;
|
32
|
}
|
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
|
}
|
46
|
|