Commit 80b8e009 authored by Nigel McNie's avatar Nigel McNie
Browse files

First shot at a blog blocktype. Uses the tablerenderer for pagination.

parent 439eaa69
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage blocktype-blockpost
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$string['title'] = 'Blog';
$string['description'] = 'Display an entire blog';
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage blocktype-blog
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
class PluginBlocktypeBlog extends PluginBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.blog/blog');
}
/**
* Optional method. If exists, allows this class to decide the title for
* all blockinstances of this type
*/
public static function get_instance_title(BlockInstance $bi) {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'lib/artefact.php');
$blog = artefact_instance_from_id($configdata['artefactid']);
return $blog->get('title');
}
return '';
}
public static function get_description() {
return get_string('description', 'blocktype.blog/blog');
}
public static function get_categories() {
return array('blog');
}
public static function render_instance(BlockInstance $instance) {
$configdata = $instance->get('configdata');
$result = '';
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'lib/artefact.php');
$blog = artefact_instance_from_id($configdata['artefactid']);
$configdata['hidetitle'] = true;
$configdata['viewid'] = $instance->get('view');
$result = $blog->render_self($configdata);
$result = $result['html'] . '<script type="text/javascript">'
. $result['javascript'];
$result .= '</script>';
}
return $result;
}
// TODO: Implement in parent class, saving us a lot of hassle
public static function get_artefacts(BlockInstance $instance) {
$configdata = $instance->get('configdata');
if (!empty($configdata['artefactid'])) {
//require_once(get_config('docroot') . 'lib/artefact.php');
//$blog = artefact_instance_from_id($configdata['artefactid']);
$list = array();
//foreach ($blog->get_children_instances() as $blogpost) {
// $list = array_merge($list, $blogpost->attachment_id_list());
//}
$list[] = $configdata['artefactid'];
return $list;
}
return false;
}
public static function has_instance_config() {
return true;
}
public static function instance_config_form($instance) {
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null),
);
}
public static function artefactchooser_element($default=null) {
return array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('blog', 'artefact.blog'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'blog',
'limit' => 2,
'selectone' => true,
'artefacttypes' => array('blog'),
'template' => 'artefact:blog:artefactchooser-element.tpl',
);
}
/**
* Optional method. If specified, allows the blocktype class to munge the
* artefactchooser element data before it's templated
*/
//public static function artefactchooser_get_element_data($artefact) {
// static $blognames = array();
// if (!isset($blognames[$artefact->parent])) {
// $blognames[$artefact->parent] = get_field('artefact', 'title', 'id', $artefact->parent);
// }
// $artefact->blog = $blognames[$artefact->parent];
// $ellipsis = '';
// $artefact->description = trim(strip_tags($artefact->description));
// if (strlen($artefact->description) > 100) {
// $ellipsis = '…';
// }
// $artefact->description = substr($artefact->description, 0, 100) . $ellipsis;
// return $artefact;
//}
/**
* Optional method. If specified, changes the order in which the artefacts are sorted in the artefact chooser.
*
* This is a valid SQL string for the ORDER BY clause. Fields you can sort on are as per the artefact table
*/
//public static function artefactchooser_get_sort_order() {
// return 'parent, ctime DESC';
//}
}
?>
{if !$options.hidetitle}<h2>{$artefacttitle}</h2>{/if}
<table id="blog_renderfull{$blockid}">
<thead></thead>
<tbody></tbody>
</table>
<script type="text/javascript">
var blog_renderfull{$blockid} = new TableRenderer(
'blog_renderfull{$blockid}',
config['wwwroot'] + 'artefact/blog/blog_render_self.json.php',
[
{literal}function(r) {
var td = TD();
td.innerHTML = r.content.html;
return td;
}{/literal}
]
);
blog_renderfull{$blockid}.statevars.push('id');
blog_renderfull{$blockid}.id = {$enc_id};
blog_renderfull{$blockid}.limit = {$limit};
blog_renderfull{$blockid}.statevars.push('options');
blog_renderfull{$blockid}.options = {$enc_options};
blog_renderfull{$blockid}.updateOnLoad();
</script>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage blocktype-blog
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2007082801;
$config->release = '0.9';
?>
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