Skip to content
Snippets Groups Projects
Unverified Commit 91d2dfc4 authored by Peter Rotich's avatar Peter Rotich Committed by GitHub
Browse files

Merge pull request #4613 from JediKev/feature/complete-thread-variable

feature: Complete Thread Variable
parents ef915213 ffcd4b5e
No related branches found
No related tags found
No related merge requests found
...@@ -197,6 +197,18 @@ class AttachmentFile extends VerySimpleModel { ...@@ -197,6 +197,18 @@ class AttachmentFile extends VerySimpleModel {
$options); $options);
} }
// Generates full download URL for external sources.
// e.g. https://domain.tld/file.php?args=123
function getExternalDownloadUrl($options=array()) {
global $cfg;
$download = self::getDownloadUrl($options);
// Separate URL handle and args
list($handle, $args) = explode('file.php?', $download);
return (string) rtrim($cfg->getBaseUrl(), '/').'/file.php?'.$args;
}
static function generateDownloadUrl($id, $key, $hash, $options = array()) { static function generateDownloadUrl($id, $key, $hash, $options = array()) {
// Expire at the nearest midnight, allow at least12 hrs access // Expire at the nearest midnight, allow at least12 hrs access
......
...@@ -2964,6 +2964,14 @@ implements TemplateVariable { ...@@ -2964,6 +2964,14 @@ implements TemplateVariable {
return $resp; return $resp;
} }
function __toString() {
return $this->asVar();
}
function asVar() {
return $this->getVar('complete');
}
function getVar($name) { function getVar($name) {
switch ($name) { switch ($name) {
case 'original': case 'original':
...@@ -2983,12 +2991,23 @@ implements TemplateVariable { ...@@ -2983,12 +2991,23 @@ implements TemplateVariable {
if ($entry) if ($entry)
return $entry->getBody(); return $entry->getBody();
break;
case 'complete':
$content = '';
$thread = $this;
ob_start();
include INCLUDE_DIR.'client/templates/thread-export.tmpl.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
break; break;
} }
} }
static function getVarScope() { static function getVarScope() {
return array( return array(
'complete' => __('Thread Correspondence'),
'original' => array('class' => 'MessageThreadEntry', 'desc' => __('Original Message')), 'original' => array('class' => 'MessageThreadEntry', 'desc' => __('Original Message')),
'lastmessage' => array('class' => 'MessageThreadEntry', 'desc' => __('Last Message')), 'lastmessage' => array('class' => 'MessageThreadEntry', 'desc' => __('Last Message')),
); );
......
<?php
global $cfg;
$entryTypes = array(
'M' => array('color' => '#0088cc'),
'R' => array('color' => '#e65524'),
);
AttachmentFile::objects()->filter(array(
'attachments__thread_entry__thread__id' => $thread->getId(),
'attachments__thread_entry__type__in' => array_keys($entryTypes)
))->all();
$entries = $thread->getEntries();
$entries->filter(array('type__in' => array_keys($entryTypes)));
?>
<style type="text/css">
div {font-family: sans-serif;}
</style>
<div style="width: 100%; margin: 0; padding: 0;">
<div style="padding:10px;">
<p style="font-family: sans-serif; font-size:12px; color:#999;">&nbsp;</p>
</div>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td></td>
</tr>
<?php
foreach ($entries as $entry) {
$user = $entry->getUser() ?: $entry->getStaff();
$name = $user ? $user->getName() : $entry->poster;
$color = $entryTypes[$entry->type]['color'];
?>
<tr>
<td style=" border-top: 1px dashed #999;">
<div style="background-color:#f7f7f7; padding:10px 20px;">
<p style="font-family: sans-serif; padding:0; margin:0; color:<?php echo $color; ?>;">
<strong><?php echo $name; ?></strong>
<span style="color:#888; font-size:12px; padding-left: 20px;"><?php
echo $entry->title;
?>
</span>
</p>
<p style="font-family: sans-serif; padding:0; margin:0; color:#888; font-size:12px;">
<?php
echo Format::daydatetime($entry->created);
?>
</p>
</div>
<div style="padding:2px 20px;">
<p style="font-family: sans-serif; font-size:14px; color:#555;">
<?php
echo $entry->getBody()->display('email');
?>
</p>
<?php
if ($entry->has_attachments) { ?>
<p style="font-family: sans-serif; font-size:12px; line-height:20px; color:#888;">
<?php echo __('Attachments'); ?>
<br />
<?php
foreach ($entry->attachments as $a) {
if ($a->inline) continue;
$size = '';
if ($a->file->size)
$size = sprintf('<small style="color:#ccc;">&nbsp;(%s)</small>',
Format::file_size($a->file->size));
$filename = Format::htmlchars($a->getFilename());
echo sprintf('<a href="%s" download="%s"
style="font-size:11px; color:#0088cc;"
target="_blank">%s</a>&nbsp;&nbsp;&nbsp;%s<br/>',
$a->file->getExternalDownloadUrl(),
$filename,
$filename,
$size);
}
?>
</p>
<?php
} ?>
</div>
</td>
</tr>
<?php
} ?>
</tbody>
</table>
<div style="font-family: sans-serif; margin: 2px 0 14px 0; padding: 10px ; border-top: 1px solid #999; font-size:12px; color:#888;">
&nbsp;
</div>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment