Commit 76e5d0c7 authored by Richard Mansfield's avatar Richard Mansfield

Use template for output from filedownload block

Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 1a07d3b2
...@@ -45,7 +45,10 @@ class PluginBlocktypeFiledownload extends PluginBlocktype { ...@@ -45,7 +45,10 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
require_once(get_config('docroot') . 'artefact/lib.php'); require_once(get_config('docroot') . 'artefact/lib.php');
$configdata = $instance->get('configdata'); $configdata = $instance->get('configdata');
$result = ''; $viewid = $instance->get('view');
$wwwroot = get_config('wwwroot');
$files = array();
if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) { if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) {
foreach ($configdata['artefactids'] as $artefactid) { foreach ($configdata['artefactids'] as $artefactid) {
try { try {
...@@ -55,44 +58,35 @@ class PluginBlocktypeFiledownload extends PluginBlocktype { ...@@ -55,44 +58,35 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
continue; continue;
} }
$icondata = array( $file = array(
'id' => $artefactid, 'id' => $artefactid,
'viewid' => $instance->get('view'), 'title' => $artefact->get('title'),
'description' => $artefact->get('description'),
'size' => $artefact->get('size'),
'ctime' => $artefact->get('ctime'),
'iconsrc' => call_static_method(
generate_artefact_class_name($artefact->get('artefacttype')),
'get_icon',
array('id' => $artefactid, 'viewid' => $viewid)
),
'downloadurl' => $wwwroot,
); );
$detailsurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view');
if ($artefact instanceof ArtefactTypeProfileIcon) { if ($artefact instanceof ArtefactTypeProfileIcon) {
require_once('file.php'); $file['downloadurl'] .= 'thumb.php?type=profileiconbyid&id=' . $artefactid;
$downloadurl = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid;
$size = filesize(get_dataroot_image_path('artefact/file/profileicons/', $artefactid));
} }
else if ($artefact instanceof ArtefactTypeFile) { else if ($artefact instanceof ArtefactTypeFile) {
$downloadurl = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid . '&view=' . $icondata['viewid']; $file['downloadurl'] .= 'artefact/file/download.php?file=' . $artefactid . '&view=' . $viewid;
$size = $artefact->get('size');
}
$result .= '<div title="' . hsc($artefact->get('title')) . '">';
$result .= '<div class="fl"><a href="' . hsc($downloadurl) . '" target="_blank">';
$result .= '<img src="' . hsc(call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', $icondata))
. '" alt=""></a></div>';
$result .= '<div style="margin-left: 30px;">';
$result .= '<h4><a href="' . hsc($downloadurl) . '" target="_blank">' . str_shorten_text($artefact->get('title'), 20) . '</a></h4>';
$description = $artefact->get('description');
if ($description) {
$result .= '<p style="margin: 0;"><strong>' . hsc($description) . '</strong></p>';
} }
$result .= '' . display_size($size) . ' | ' . strftime(get_string('strftimedaydate'),$artefact->get('ctime'));
$result .= ' | <a href="' . hsc($detailsurl) . '">' . get_string('Details', 'artefact.file') . '</a>';
$result .= '</div>';
$result .= '</div>'; $files[] = $file;
} }
} }
return $result; $smarty = smarty_core();
$smarty->assign('viewid', $instance->get('view'));
$smarty->assign('files', $files);
return $smarty->fetch('blocktype:filedownload:filedownload.tpl');
} }
public static function has_instance_config() { public static function has_instance_config() {
......
{foreach $files file}
<div title="{$file.title}">
<div class="fl"><a href="{$WWWROOT}{$file.downloadurl}" target="_blank"><img src="{$file.iconsrc}" alt=""></a></div>
<div style="margin-left: 30px;">
<h4><a href="{$file.downloadurl}" target="_blank">{$file.title|str_shorten_text:20|safe}</a></h4>
{if $file.description}<p style="margin: 0;"><strong>{$file.description}</strong></p>{/if}
{$file.size|display_size} | {$file.ctime|format_date:'strftimedaydate'}
| <a href="{$WWWROOT}view/artefact.php?artefact={$file.id}&view={$viewid}">{str tag=Details section=artefact.file}</a>
</div>
</div>
{/foreach}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment