Commit 074e81bb authored by Nigel McNie's avatar Nigel McNie
Browse files

Unify content type handling in LEAP export, and switch to 'html' content type.

We're not exporting as xhtml any more - that work would unfortunately conflict with future work we have planned.

Now there's a new method, get_content_type, which elements should define to say what type they should be. The default implementation of get_content is now applicable in many more cases. All escaping and cleaning is done in the template, where it should be.

The system still supports exporting content with type=xhtml - we're just not going to use it.
parent 2fbf617d
......@@ -45,17 +45,8 @@ class LeapExportElementBlogpost extends LeapExportElement {
return $content;
}
public function assign_smarty_vars() {
parent::assign_smarty_vars();
$this->smarty->assign('contenttype', 'xhtml');
}
public function get_content() {
//$rendered = $this->artefact->render_base(array('icons' => false));
//$rendered = $rendered['html'];
//return $this->replace_content_placeholders(clean_html($rendered));
// Probably need replace content placeholders!
return clean_html($this->artefact->get('description'));
public function get_content_type() {
return 'html';
}
public function get_categories() {
......@@ -86,12 +77,7 @@ class LeapExportElementBlog extends LeapExportElement {
);
}
public function assign_smarty_vars() {
parent::assign_smarty_vars();
$this->smarty->assign('contenttype', 'xhtml');
}
public function get_content() {
return clean_html($this->artefact->get('description'));
public function get_content_type() {
return 'html';
}
}
......@@ -60,7 +60,6 @@ class LeapExportElementFile extends LeapExportElement {
public function assign_smarty_vars() {
parent::assign_smarty_vars();
$this->smarty->assign('summary', $this->artefact->get('description'));
$this->smarty->assign('contenttype', $this->artefact->get('filetype'));
$this->smarty->assign('contentsrc', $this->exporter->get('filedir') . $this->filename);
}
......@@ -68,6 +67,10 @@ class LeapExportElementFile extends LeapExportElement {
$this->filename = $this->exporter->add_attachment($this->artefact->get_path(), $this->artefact->get('title'));
}
public function get_content_type() {
return $this->artefact->get('filetype');
}
public function get_content() {
return '';
}
......
......@@ -55,7 +55,7 @@ class LeapExportElementInternal extends LeapExportElement {
foreach ($this->artefacts as $a) {
if (!$data = $this->data_mapping($a)) {
if ($a->get('artefacttype') == 'introduction') {
$this->smarty->assign('contenttype', 'xhtml');
$this->smarty->assign('contenttype', 'html');
$this->smarty->assign('content', clean_html($a->get('title')));
}
continue;
......@@ -161,6 +161,10 @@ class LeapExportElementInternalNonPerson extends LeapExportElement {
parent::assign_smarty_vars();
$this->smarty->assign('title', ucfirst($this->artefact->get('artefacttype')));
}
public function get_content() {
return $this->artefact->get('title');
}
}
class LeapExportElementIndustry extends LeapExportElementInternalNonPerson { }
......
......@@ -148,9 +148,8 @@ class LeapExportElementPersonalinformation extends LeapExportElement {
}
class LeapExportElementResumeWysiwygField extends LeapExportElement {
public function assign_smarty_vars() {
parent::assign_smarty_vars();
$this->smarty->assign('contenttype', 'xhtml');
public function get_content_type() {
return 'html';
}
}
......@@ -272,6 +271,7 @@ abstract class LeapExportElementResumeCompositeChild extends LeapExportElement {
$this->smarty->assign($field, $value);
}
$this->smarty->assign('type', $this->get_leap_type());
$this->smarty->assign('contenttype', 'text');
$this->add_links();
$this->smarty->assign('links', $this->links);
}
......@@ -315,7 +315,7 @@ class LeapExportElementResumeCompositeChildCertification extends LeapExportEleme
return array(
'end' => $record->date,
'title' => $record->title,
'content' => hsc($record->description),
'content' => $record->description,
);
}
......@@ -330,7 +330,7 @@ class LeapExportElementResumeCompositeChildMembership extends LeapExportElementR
'start' => $record->startdate,
'end' => $record->enddate,
'title' => $record->title,
'content' => hsc($record->description),
'content' => $record->description,
);
}
......@@ -371,7 +371,7 @@ class LeapExportElementResumeCompositeChildEducationhistory extends LeapExportEl
'start' => $record->startdate,
'end' => $record->enddate,
'title' => $record->qualname . ' (' . $record->qualtype . ')',
'content' => hsc($record->qualdescription),
'content' => $record->qualdescription,
);
}
......@@ -395,7 +395,7 @@ class LeapExportElementResumeCompositeChildEmploymenthistory extends LeapExportE
'start' => $record->startdate,
'end' => $record->enddate,
'title' => $record->jobtitle,
'content' => hsc($record->positiondescription),
'content' => $record->positiondescription,
);
}
......@@ -417,7 +417,7 @@ class LeapExportElementResumeCompositeChildBook extends LeapExportElementResumeC
return array(
'end' => $record->date,
'title' => $record->title,
'content' => hsc($record->description),
'content' => $record->description,
);
}
......
......@@ -208,7 +208,7 @@ class PluginExportLeap extends PluginExport {
$this->smarty->assign('created', self::format_rfc3339_date(strtotime($view->get('ctime'))));
// TODO this is wrong - view description is HTML, summary should be text
//$this->smarty->assign('summary', $view->get('description'));
$this->smarty->assign('contenttype', 'xhtml');
$this->smarty->assign('contenttype', 'html');
$this->smarty->assign('content', $view->build_columns());
$this->smarty->assign('type', 'selection');
$this->xml .= $this->smarty->fetch("export:leap:entry.tpl");
......@@ -368,6 +368,7 @@ class LeapExportElement {
// these are the ones we really need to override
$this->add_links();
$this->smarty->assign('content', $this->get_content());
$this->smarty->assign('contenttype', $this->get_content_type());
$this->smarty->assign('type', $this->get_leap_type());
if ($tags = $this->artefact->get('tags')) {
......@@ -480,19 +481,37 @@ class LeapExportElement {
}
/**
* The main content of the element.
* Goes between <content> tags.
* The default is the artefact description
* But this can be an XHTML representation
* The content type of whatever is going in the <content> element.
*
* Can only be one of 'text', 'html' or 'xhtml', and we're currently not
* using XHTML in Mahara.
*
* @return string
*/
public function get_content_type() {
return 'text';
}
/**
* The main content of the element, which goes between <content> tags.
*
* Escaping of this value happens in the template, depending on the content
* type, which can be set with {@link get_content_type()}.
*
* The default is to use the artefact description.
*
* @return XHTML string
* @return string
*/
public function get_content() {
//TODO replace this with non-js content
// can use $this->artefact->get('description'); in most cases to avoid this (for testing) (and the appropriate |escape in the entry template content tag)
$rendered = $this->artefact->render_self(array());
$rendered = $rendered['html'];
return $this->replace_content_placeholders(clean_html($rendered));
switch ($this->get_content_type()) {
case 'text':
case 'html':
case 'xhtml':
return $this->artefact->get('description');
default:
throw new SystemException("Unrecognised content type");
}
}
public function replace_content_placeholders($content, $placeholder='ARTEFACTVIEWLINK') {
......
......@@ -7,7 +7,7 @@
{/if}
{if $summary} <summary>{$summary}</summary>
{/if}
<content{if $contenttype} type="{$contenttype}"{/if}{if $contentsrc} src="{$contentsrc}"{/if}>{if $contenttype == 'xhtml'}<div xmlns="http://www.w3.org/1999/xhtml">{/if}{$content}{if $contenttype == 'xhtml'}</div>{/if}</content>
<content{if $contenttype != 'text'} type="{$contenttype}"{/if}{if $contentsrc} src="{$contentsrc}"{/if}>{if $contenttype == 'xhtml'}<div xmlns="http://www.w3.org/1999/xhtml">{/if}{if $contenttype == 'xhtml'}{$content|clean_html}{elseif $contenttype == 'html'}{$content|clean_html|escape}{else}{$content|escape}{/if}{if $contenttype == 'xhtml'}</div>{/if}</content>
<rdf:type rdf:resource="leaptype:{$type}"/>
<mahara:artefactplugin mahara:type="{$artefacttype}" mahara:plugin="{$artefactplugin}"/>
{include file="export:leap:links.tpl"}
......
Supports Markdown
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