Commit 9dc9df63 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes...

Merge changes I440ba232,I27b85297,I08f2769a,I173ff761,I027945b8,I599108e7,I2ce9b3d3,I6c90e97b,I27345803,I2809e104,Ib1f74406

* changes:
  Use default block titles on group homepage and dashboard (bug #677546)
  Fix block config popup template to deal with empty block titles
  Add default titles for dashboard & grouphomepage blocks
  Hide title in block config form for autogenerated block titles
  Move javascript to hide/expand forum post subjects into pieforms
  Automatically generate block titles when they are rendered
  Remove useless override_instance_title function from recentforumposts block This has been ineffective since 2010-09-09, commit 40733e1b
  Use instance data store in externalfeed, navigation blocks
  Allow blockinstances to keep persistent non-artefact data around Useful for blocks that need to get at the same db record multiple times
  Don't fetch artefact from db unnecessarily when generating a block title
  Don't fetch artefact from db unnecessarily when saving a block
parents 00198eae 51c41c13
......@@ -41,9 +41,7 @@ class PluginBlocktypeBlog extends PluginBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'artefact/lib.php');
$blog = artefact_instance_from_id($configdata['artefactid']);
return $blog->get('title');
return $bi->get_artefact_instance($configdata['artefactid'])->get('title');
}
return '';
}
......
......@@ -41,9 +41,7 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'artefact/lib.php');
$blogpost = artefact_instance_from_id($configdata['artefactid']);
return $blogpost->get('title');
return $bi->get_artefact_instance($configdata['artefactid'])->get('title');
}
return '';
}
......
......@@ -41,9 +41,7 @@ class PluginBlocktypeFolder extends PluginBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'artefact/lib.php');
$folder = artefact_instance_from_id($configdata['artefactid']);
return $folder->get('title');
return $bi->get_artefact_instance($configdata['artefactid'])->get('title');
}
return '';
}
......
......@@ -49,10 +49,7 @@ class PluginBlocktypePlans extends PluginBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
safe_require('artefact','plans');
$plan = new ArtefactTypePlan($configdata['artefactid']);
$title = $plan->get('title');
return $title;
return $bi->get_artefact_instance($configdata['artefactid'])->get('title');
}
return '';
}
......
......@@ -49,9 +49,7 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'artefact/lib.php');
$resumefield = artefact_instance_from_id($configdata['artefactid']);
return $resumefield->get('title');
return $bi->get_artefact_instance($configdata['artefactid'])->get('title');
}
return '';
}
......
......@@ -61,10 +61,8 @@ class PluginBlocktypeExternalfeed extends SystemBlocktype {
public static function render_instance(BlockInstance $instance, $editing=false) {
$configdata = $instance->get('configdata');
if (!empty($configdata['feedid'])) {
$data = get_record(
'blocktype_externalfeed_data', 'id', $configdata['feedid'], null, null, null, null,
'id,url,link,title,description,content,' . db_format_tsfield('lastupdate') . ',image'
);
$data = $instance->get_data('feed', $configdata['feedid']);
$data->content = unserialize($data->content);
$data->image = unserialize($data->image);
......@@ -104,6 +102,14 @@ class PluginBlocktypeExternalfeed extends SystemBlocktype {
return '';
}
// Called by $instance->get_data('feed', ...).
public static function get_instance_feed($id) {
return get_record(
'blocktype_externalfeed_data', 'id', $id, null, null, null, null,
'id,url,link,title,description,content,' . db_format_tsfield('lastupdate') . ',image'
);
}
public static function has_instance_config() {
return true;
}
......@@ -112,7 +118,7 @@ class PluginBlocktypeExternalfeed extends SystemBlocktype {
$configdata = $instance->get('configdata');
if (!empty($configdata['feedid'])) {
$url = get_field('blocktype_externalfeed_data', 'url', 'id', $configdata['feedid']);
$url = $instance->get_data('feed', $configdata['feedid'])->url;
}
else {
$url = '';
......@@ -163,7 +169,7 @@ class PluginBlocktypeExternalfeed extends SystemBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['feedid'])) {
if ($title = get_field('blocktype_externalfeed_data', 'title', 'id', $configdata['feedid'])) {
if ($title = $bi->get_data('feed', $configdata['feedid'])->title) {
return $title;
}
}
......
......@@ -42,3 +42,5 @@ $string['options_order_desc'] = 'You can choose to display the latest group memb
$string['Latest'] = 'Latest';
$string['Random'] = 'Random';
$string['defaulttitledescription'] = 'A default title will be generated if you leave the title field blank';
......@@ -121,4 +121,7 @@ class PluginBlocktypeGroupMembers extends SystemBlocktype {
);
}
public static function get_instance_title () {
return get_string('Members', 'group');
}
}
\ No newline at end of file
......@@ -33,3 +33,4 @@ $string['displaygroupviews'] = 'Display Group pages?';
$string['displaygroupviewsdesc'] = 'Group pages - pages created in the group';
$string['displaysharedviews'] = 'Display Shared pages?';
$string['displaysharedviewsdesc'] = 'Shared pages - pages shared by group members from their individual portfolio';
$string['defaulttitledescription'] = 'A default title will be generated if you leave the title field blank';
......@@ -169,6 +169,8 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
$data['group'] = $group;
return $data;
}
}
?>
public static function get_instance_title() {
return get_string('title', 'blocktype.groupviews');
}
}
......@@ -34,4 +34,4 @@ $string['maxitems'] = 'Maximum number of items to display';
$string['maxitemsdescription'] = 'Between 1 and 100';
$string['More'] = 'More';
$string['nomessages'] = 'No messages';
?>
$string['defaulttitledescription'] = 'A default title will be generated if you leave the title field blank';
......@@ -157,6 +157,27 @@ class PluginBlocktypeInbox extends SystemBlocktype {
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
}
}
?>
/**
* We need a default title for this block, so that the inbox blocks
* on the dashboard are translatable.
*
* To maintain existing behaviour, use the 'recentactivity' string unless
* the block has only got forum post notifications in it, in which case
* use 'topicsimfollowing'
*/
public static function get_instance_title(BlockInstance $instance) {
if ($configdata = $instance->get('configdata')) {
foreach ($configdata as $k => $v) {
if ($v && $k != 'newpost' && $k != 'maxitems') {
return get_string('recentactivity');
}
}
if ($configdata['newpost']) {
return get_string('topicsimfollowing');
}
}
return get_string('recentactivity');
}
}
......@@ -432,6 +432,8 @@ class BlockInstance {
private $canmoveup;
private $canmovedown;
private $maxorderincolumn;
private $artefacts = array();
private $temp = array();
public function __construct($id=0, $data=null) {
if (!empty($id)) {
......@@ -518,13 +520,6 @@ class BlockInstance {
$title = (isset($values['title'])) ? $values['title'] : '';
unset($values['title']);
$this->set('configdata', $values);
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
if (!$title && $title !== '0' && method_exists($blocktypeclass, 'get_instance_title')) {
// Get the default title for the block if one isn't set
$title = call_static_method($blocktypeclass, 'get_instance_title', $this);
}
$this->set('title', $title);
try {
......@@ -556,6 +551,20 @@ class BlockInstance {
$form->reply(PIEFORM_OK, $result);
}
public function get_title() {
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
if ($override = call_static_method($blocktypeclass, 'override_instance_title', $this)) {
return $override;
}
if ($title = $this->get('title') and $title != '') {
return $title;
}
if (method_exists($blocktypeclass, 'get_instance_title')) {
return call_static_method($blocktypeclass, 'get_instance_title', $this);
}
return '';
}
/**
* Builds the HTML for the block, inserting the blocktype content at the
* appropriate place
......@@ -570,6 +579,9 @@ class BlockInstance {
$js = '';
$movecontrols = array();
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
$title = $this->get_title();
if ($configure) {
list($content, $js) = array_values($this->build_configure_form($new));
}
......@@ -594,9 +606,7 @@ class BlockInstance {
$movecontrols[] = array(
'column' => $this->get('column') - 1,
'order' => $this->get('order'),
'title' => trim($this->get('title')) == '' ?
get_string('movethisblockleft', 'view') :
get_string('moveblockleft', 'view', "'".$this->get('title')."'"),
'title' => $title == '' ? get_string('movethisblockleft', 'view') : get_string('moveblockleft', 'view', "'$title'"),
'arrow' => '←',
'dir' => 'left',
);
......@@ -605,9 +615,7 @@ class BlockInstance {
$movecontrols[] = array(
'column' => $this->get('column'),
'order' => $this->get('order') + 1,
'title' => trim($this->get('title')) == '' ?
get_string('movethisblockdown', 'view') :
get_string('moveblockdown', 'view', "'".$this->get('title')."'"),
'title' => $title == '' ? get_string('movethisblockdown', 'view') : get_string('moveblockdown', 'view', "'$title'"),
'arrow' => '↓',
'dir' => 'down',
);
......@@ -616,9 +624,7 @@ class BlockInstance {
$movecontrols[] = array(
'column' => $this->get('column'),
'order' => $this->get('order') - 1,
'title' => trim($this->get('title')) == '' ?
get_string('movethisblockup', 'view') :
get_string('moveblockup', 'view', "'".$this->get('title')."'"),
'title' => $title == '' ? get_string('movethisblockup', 'view') : get_string('moveblockup', 'view', "'$title'"),
'arrow' => '↑',
'dir' => 'up',
);
......@@ -627,32 +633,33 @@ class BlockInstance {
$movecontrols[] = array(
'column' => $this->get('column') + 1,
'order' => $this->get('order'),
'title' => trim($this->get('title')) == '' ?
get_string('movethisblockright', 'view') :
get_string('moveblockright', 'view', "'".$this->get('title')."'"),
'title' => $title == '' ? get_string('movethisblockright', 'view') : get_string('moveblockright', 'view', "'$title'"),
'arrow' => '→',
'dir' => 'right',
);
}
}
}
$configtitle = $title == '' ? call_static_method($blocktypeclass, 'get_title') : $title;
$smarty = smarty_core();
$smarty->assign('id', $this->get('id'));
$smarty->assign('viewid', $this->get('view'));
$title = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'override_instance_title', $this);
$smarty->assign('title', $title ? $title : $this->get('title'));
$smarty->assign('title', $title);
$smarty->assign('column', $this->get('column'));
$smarty->assign('order', $this->get('order'));
$smarty->assign('movecontrols', $movecontrols);
$smarty->assign('configurable', call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'has_instance_config'));
$smarty->assign('configurable', call_static_method($blocktypeclass, 'has_instance_config'));
$smarty->assign('configure', $configure); // Used by the javascript to rewrite the block, wider.
$smarty->assign('configtitle', $configtitle);
$smarty->assign('content', $content);
$smarty->assign('javascript', defined('JSON'));
$smarty->assign('strnotitle', get_string('notitle', 'view'));
$smarty->assign('strconfigtitletext', trim($this->get('title')) == '' ? get_string('configurethisblock', 'view') : get_string('configureblock', 'view', "'".$this->get('title')."'"));
$smarty->assign('strremovetitletext', trim($this->get('title')) == '' ? get_string('removethisblock', 'view') : get_string('removeblock', 'view', "'".$this->get('title')."'"));
$smarty->assign('strconfigtitletext', $title == '' ? get_string('configurethisblock', 'view') : get_string('configureblock', 'view', "'$title'"));
$smarty->assign('strremovetitletext', $title == '' ? get_string('removethisblock', 'view') : get_string('removeblock', 'view', "'$title'"));
return array('html' => $smarty->fetch('view/blocktypecontainerediting.tpl'), 'javascript' => $js);
}
......@@ -679,13 +686,12 @@ class BlockInstance {
$smarty = smarty_core();
$smarty->assign('id', $this->get('id'));
$smarty->assign('blocktype', $this->get('blocktype'));
$title = call_static_method($classname, 'override_instance_title', $this);
// hide the title if required and no content is present
if (call_static_method($classname, 'hide_title_on_empty_content')
&& !trim($content)) {
return;
}
$smarty->assign('title', $title ? $title : $this->get('title'));
$smarty->assign('title', $this->get_title());
// If this block is for just one artefact, we set the title of the
// block to be a link to view more information about that artefact
......@@ -719,34 +725,30 @@ class BlockInstance {
}
safe_require('blocktype', $this->get('blocktype'));
$elements = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_form', $this, $this->get_view()->get('template'));
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
if ($this->get('title') != call_static_method($blocktypeclass, 'get_title')) {
// If the title for this block has been set to something other than
// the block title, use it unconditionally
$title = $this->get('title');
}
else if (method_exists($blocktypeclass, 'get_instance_title')) {
// Block types can specify a default title for a block
$title = call_static_method($blocktypeclass, 'get_instance_title', $this);
}
else {
// A block that doesn't have a method for setting an instance
// title, and hasn't had its title changed (e.g. a new textbox)
$title = $this->get('title');
}
$elements = call_static_method($blocktypeclass, 'instance_config_form', $this, $this->get_view()->get('template'));
// @todo: If we know the title is going to be overridden in override_instance_title(),
// hide or disable the title field in the form. Currently not a problem, because the
// blocktypes that override the instance title don't have configurable instances.
// Maybe just remove or simplify title in the elements list below and make all the
// blocktype classes pass the title element in their instance_config_form().
// Block types may specify a method to generate a default title for a block
$hasdefault = method_exists($blocktypeclass, 'get_instance_title');
$title = $this->get('title');
$elements = array_merge(
array(
'title' => array(
'type' => 'text',
'title' => get_string('blocktitle', 'view'),
'description' => (method_exists($blocktypeclass, 'get_instance_title'))
? get_string('defaulttitledescription', 'blocktype.' . blocktype_name_to_namespaced($this->get('blocktype'))) : null,
'description' => $hasdefault ? get_string('defaulttitledescription', 'blocktype.' . blocktype_name_to_namespaced($this->get('blocktype'))) : null,
'defaultvalue' => $title,
'rules' => array('maxlength' => 255),
'hidewhenempty' => $hasdefault,
'expandtext' => get_string('setblocktitle'),
),
'blockconfig' => array(
'type' => 'hidden',
......@@ -1074,6 +1076,10 @@ class BlockInstance {
* Get an artefact instance, checking republish permissions
*/
public function get_artefact_instance($id) {
if (isset($this->artefacts[$id])) {
return $this->artefacts[$id];
}
require_once(get_config('docroot') . 'artefact/lib.php');
$a = artefact_instance_from_id($id);
$viewowner = $this->get_view()->get('owner');
......@@ -1087,7 +1093,8 @@ class BlockInstance {
throw new ArtefactNotFoundException(get_string('artefactnotpublishable', 'mahara', $id, $this->get_view()->get('id')));
}
}
return $a;
return $this->artefacts[$id] = $a;
}
......@@ -1198,7 +1205,14 @@ class BlockInstance {
return true;
}
public function get_data($key, $id) {
if (!isset($this->temp[$key][$id])) {
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
if (!isset($this->temp[$key])) {
$this->temp[$key] = array();
}
$this->temp[$key][$id] = call_static_method($blocktypeclass, 'get_instance_' . $key, $id);
}
return $this->temp[$key][$id];
}
}
?>
......@@ -49,11 +49,7 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['collection'])) {
require_once('collection.php');
$data = get_record_select('collection', 'id = ?', array($configdata['collection']));
$collection = new Collection($configdata['collection'], (array)$data);
$title = $collection->get('name');
return $title;
return $bi->get_data('collection', $configdata['collection'])->get('name');
}
return '';
}
......@@ -63,21 +59,21 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
$smarty = smarty_core();
if (!empty($configdata['collection'])) {
$sql = "SELECT cv.*, v.title
FROM {collection_view} cv
LEFT JOIN {collection} c ON cv.collection = c.id
LEFT JOIN {view} v ON cv.view = v.id
WHERE c.id = ?
ORDER BY cv.displayorder, v.title, v.ctime ASC";
if ($views = get_records_sql_array($sql, array($configdata['collection']))) {
$smarty->assign('views',$views);
$views = $instance->get_data('collection', $configdata['collection'])->views();
if (!empty($views)) {
$smarty->assign('views', $views['views']);
}
}
$smarty->assign('currentview',$instance->get('view'));
return $smarty->fetch('blocktype:navigation:navigation.tpl');
}
// Called by $instance->get_data('collection', ...).
public static function get_instance_collection($id) {
require_once('collection.php');
return new Collection($id);
}
public static function has_instance_config() {
return true;
}
......
......@@ -31,5 +31,4 @@ $string['title'] = 'Latest Pages';
$string['description'] = 'List the most recently updated pages on the site';
$string['viewstoshow'] = 'Maximum number of pages to show';
$string['viewstoshowdescription'] = 'Between 1 and 100';
?>
$string['defaulttitledescription'] = 'A default title will be generated if you leave the title field blank';
\ No newline at end of file
......@@ -80,5 +80,8 @@ class PluginBlocktypeNewViews extends SystemBlocktype {
return 'shallow';
}
public static function get_instance_title(BlockInstance $instance) {
return get_string('title', 'blocktype.newviews');
}
}
......@@ -34,5 +34,5 @@ $string['nogroupstochoosefrom'] = 'Sorry, no groups to choose from';
$string['poststoshow'] = 'Maximum number of posts to show';
$string['poststoshowdescription'] = 'Between 1 and 100';
$string['recentforumpostsforgroup'] = "Recent Forum Posts for %s";
$string['defaulttitledescription'] = 'A default title will be generated if you leave the title field blank';
?>
......@@ -190,27 +190,6 @@ class PluginBlocktypeRecentForumPosts extends SystemBlocktype {
return 'shallow';
}
public static function override_instance_title(BlockInstance $instance) {
$groupid = $instance->get_view()->get('group');
if (!$groupid) {
$configdata = $instance->get('configdata');
if (isset($configdata['groupid'])) {
$groupid = intval($configdata['groupid']);
}
}
if (!empty($groupid)) {
return str_replace('<group>',
get_field('group', 'name', 'id', $groupid),
$instance->get('title')
);
}
else {
return $instance->get('title');
}
}
public static function feed_url(BlockInstance $instance) {
if ($group = self::get_group($instance)) {
if ($group->public) {
......@@ -219,6 +198,10 @@ class PluginBlocktypeRecentForumPosts extends SystemBlocktype {
}
}
public static function get_instance_title(BlockInstance $instance) {
if ($instance->get_view()->get('type') == 'grouphomepage') {
return get_string('latestforumposts', 'interaction.forum');
}
return get_string('title', 'blocktype.recentforumposts');
}
}
?>
......@@ -121,26 +121,6 @@ else { // edit post
$parent->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $parent->ctime);
// Javascript to hide the subject box if it has nothing in it, with a link you
// click to expand it.
$clicksetsubject = json_encode(get_string('clicksetsubject', 'interaction.forum'));
$inlinejs = <<<EOF
addLoadEvent(function() {
var subjectInput = $('editpost_subject');
if (subjectInput.value == '') {
hideElement(subjectInput);
var expandLink = A({'href': ''}, {$clicksetsubject});
connect(expandLink, 'onclick', function(e) {
showElement(subjectInput);
subjectInput.focus();
e.stop();
removeElement(expandLink);
});
insertSiblingNodesBefore(subjectInput, expandLink);
}
});
EOF;
$editform = pieform(array(
'name' => 'editpost',
'successcallback' => isset($post) ? 'editpost_submit' : 'addpost_submit',
......@@ -152,7 +132,9 @@ $editform = pieform(array(
'defaultvalue' => isset($post) ? $post->subject : null,
'rules' => array(
'maxlength' => 255
)
),
'hidewhenempty' => true,
'expandtext' => get_string('clicksetsubject', 'interaction.forum'),
),
'body' => array(
'type' => 'wysiwyg',
......
......@@ -929,4 +929,6 @@ $string['findfriendslinked'] = 'Find <a href="%s">Friends</a>';
$string['joingroups'] = 'Join <a href="%s">Groups</a>';
$string['sharenetworkdescription'] = '<br>Control your privacy.';
$string['howtodisable'] = 'You have hidden the information box. You can control its visibility in <a href="%s">Settings</a>.';
?>
// Blocktype
$string['setblocktitle'] = 'Set a block title';
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