Commit a3eea7b1 authored by Robert Lyon's avatar Robert Lyon
Browse files

Exporting to html was creating pages with ajaxify blocks (Bug #1417319)



Discovered this problem when I fixed the HTML export - it was
exporting blocks with the loading spinner rather than actual block
content

Change-Id: Id9c790f7cc6058141fb98c6d984af188ae265d6c
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 29053d1b
......@@ -33,7 +33,7 @@ class HtmlExportInternal extends HtmlExportArtefactPlugin {
$smarty->assign('breadcrumbs', array(array('text' => 'Profile page', 'path' => 'profilepage.html')));
$view = $this->exporter->get('user')->get_profile_view();
$outputfilter = new HtmlExportOutputFilter('../../', $this->exporter);
$smarty->assign('view', $outputfilter->filter($view->build_rows()));
$smarty->assign('view', $outputfilter->filter($view->build_rows(false, true)));
$content = $smarty->fetch('export:html/internal:profilepage.tpl');
if (!file_put_contents($this->fileroot . 'profilepage.html', $content)) {
......
......@@ -889,7 +889,14 @@ class BlockInstance {
return array('html' => $smarty->fetch('view/blocktypecontainerediting.tpl'), 'javascript' => $js, 'pieformcss' => $css);
}
public function render_viewing() {
/**
* To render the html of a block for viewing
*
* @param boolean $exporting Indicate the rendering is for an export
* If we are doing an export we can't render the block to be loaded via ajax
* @return the rendered block
*/
public function render_viewing($exporting=false) {
if (!safe_require_plugin('blocktype', $this->get('blocktype'))) {
return;
......@@ -898,7 +905,7 @@ class BlockInstance {
$smarty = smarty_core();
$classname = generate_class_name('blocktype', $this->get('blocktype'));
if (get_config('ajaxifyblocks') && call_static_method($classname, 'should_ajaxify')) {
if (get_config('ajaxifyblocks') && call_static_method($classname, 'should_ajaxify') && $exporting === false) {
$content = '';
$smarty->assign('loadbyajax', true);
}
......
......@@ -395,7 +395,7 @@ class PluginExportHtml extends PluginExport {
$smarty->assign('feedback', $feedback);
}
$smarty->assign('view', $outputfilter->filter($view->build_rows()));
$smarty->assign('view', $outputfilter->filter($view->build_rows(false, true)));
$content = $smarty->fetch('export:html:view.tpl');
if (!file_put_contents("$directory/index.html", $content)) {
throw new SystemException("Could not write view page for view $viewid");
......
......@@ -282,7 +282,7 @@ class PluginExportLeap extends PluginExport {
$this->smarty->assign('summary', $content);
}
$this->smarty->assign('contenttype', 'xhtml');
if ($viewcontent = self::parse_xhtmlish_content($view->build_rows(), $view->get('id'))) {
if ($viewcontent = self::parse_xhtmlish_content($view->build_rows(false, true), $view->get('id'))) {
$this->smarty->assign('content', $viewcontent);
}
$this->smarty->assign('viewdata', $config['rows']);
......
......@@ -1996,13 +1996,15 @@ class View {
/**
* Build_rows - for each row build_columms
* @param boolean $editing whether we are in the edit more or not
* @param boolean $exporting whether we are in the process of an export
* Returns the HTML for the rows of this view
*/
public function build_rows($editing=false) {
public function build_rows($editing=false, $exporting=false) {
$numrows = $this->get('numrows');
$result = '';
for ($i = 1; $i <= $numrows; $i++) {
$result .= $this->build_columns($i, $editing);
$result .= $this->build_columns($i, $editing, $exporting);
}
return $result;
}
......@@ -2010,14 +2012,14 @@ class View {
/**
* Returns the HTML for the columns of this view
*/
public function build_columns($row, $editing=false) {
public function build_columns($row, $editing=false, $exporting=false) {
global $USER;
$columnsperrow = $this->get('columnsperrow');
$currentrownumcols = $columnsperrow[$row]->columns;
$result = '';
for ($i = 1; $i <= $currentrownumcols; $i++) {
$result .= $this->build_column($row, $i, $editing);
$result .= $this->build_column($row, $i, $editing, $exporting);
}
$smarty = smarty_core();
......@@ -2038,9 +2040,10 @@ class View {
* Returns the HTML for a particular column
*
* @param int $column The column to build
* @param int $editing Whether the view is being built in edit mode
* @param boolean $editing Whether the view is being built in edit mode
* @param boolean $exporting Whether the view is being built for export
*/
public function build_column($row, $column, $editing=false) {
public function build_column($row, $column, $editing=false, $exporting=false) {
global $USER;
$data = $this->get_column_datastructure($row, $column);
static $installed = array();
......@@ -2049,25 +2052,20 @@ class View {
$installed = array_map(create_function('$a', 'return $a->name;'), $installed);
}
if ($editing) {
$renderfunction = 'render_editing';
}
else {
$renderfunction = 'render_viewing';
}
$blockcontent = '';
foreach($data['blockinstances'] as $blockinstance) {
if (!in_array($blockinstance->get('blocktype'), $installed)) {
continue; // this plugin has been disabled
}
$result = $blockinstance->$renderfunction();
if ($editing) {
$result = $blockinstance->render_editing();
$blockcontent .= $result['html'];
// NOTE: build_column is always called in the context of column
// operations, so the javascript returned, which is currently
// for configuring block instances only, is not necessary
}
else {
$result = $blockinstance->render_viewing($exporting);
$blockcontent .= $result;
}
}
......
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