Commit f7ca17cc authored by Son Nguyen's avatar Son Nguyen
Browse files

Allow images in Text blocks accessible. Bug 1400140



- Append view id to image urls in Text block when viewing
- Update the table 'view_artefact' when adding/editting
  urls of a Text block
- Add missing referred artefacts for existing database

Change-Id: I6b1ed5ca46b2642b0624df9027964043b4dc39a8
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 555f20f2
......@@ -25,11 +25,30 @@ class PluginBlocktypeText extends SystemBlocktype {
return array('general');
}
/**
* Returns artefact ids referred in the block
* @param BlockInstance $instance
* @return array artefact ids
*/
public static function get_artefacts(BlockInstance $instance) {
safe_require('artefact', 'file');
$configdata = $instance->get('configdata');
// Add all artefacts found in the text
if (empty($configdata['text'])) {
$artefacts = array();
}
else {
$artefacts = array_unique(artefact_get_references_in_html($configdata['text']));
}
return $artefacts;
}
public static function render_instance(BlockInstance $instance, $editing=false) {
$configdata = $instance->get('configdata');
$smarty = smarty_core();
if (array_key_exists('text', $configdata)) {
$smarty->assign('text', $configdata['text']);
safe_require('artefact', 'file');
$smarty->assign('text', ArtefactTypeFolder::append_view_url($configdata['text'], $instance->get('view')));
}
else {
$smarty->assign('text', '');
......
......@@ -3851,5 +3851,34 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2014092315) {
log_debug("Update referred artefacts in 'Text' blocktype");
if ($blockids = get_column_sql('
SELECT bi.id
FROM {block_instance} bi
WHERE bi.blocktype = ?
AND NOT EXISTS (
SELECT 1
FROM {view_artefact} va
WHERE va.block = bi.id)',
array('text'))) {
$count = 0;
$limit = 200;
$total = count($blockids);
require_once(get_config('docroot') . 'blocktype/lib.php');
foreach ($blockids as $blockid) {
$bi = new BlockInstance($blockid);
$bi->set('dirty', true);
$bi->commit();
$count++;
if (($count % $limit) == 0) {
log_debug("Updating 'Text' blocks: $count/$total");
set_time_limit(30);
}
}
log_debug("Updating 'Text' blocks: $count/$total");
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014092314;
$config->version = 2014092315;
$config->release = '1.10.3testing';
$config->series = '1.10';
$config->minupgradefrom = 2009022600;
......
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