Commit 2d0a9158 authored by Penny Leach's avatar Penny Leach
Browse files

Merge commit 'origin/master' into groupforums

parents 5c536115 2f8b3825
......@@ -32,7 +32,7 @@ define('TITLE', get_string('pluginadmin', 'admin'));
require_once('pieforms/pieform.php');
$plugintype = param_alpha('plugintype');
$pluginname = param_alpha('pluginname');
$pluginname = param_variable('pluginname');
define('SECTION_PLUGINTYPE', $plugintype);
define('SECTION_PLUGINNAME', $pluginname);
......
<?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;
}
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' => 10,
'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';
?>
......@@ -71,15 +71,6 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
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'])) {
return array($configdata['artefactid']);
}
return false;
}
public static function has_instance_config() {
return true;
}
......@@ -101,7 +92,7 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
'required' => true,
),
'blocktype' => 'blogpost',
'limit' => 2,
'limit' => 10,
'selectone' => true,
'artefacttypes' => array('blogpost'),
'template' => 'artefact:blog:artefactchooser-element.tpl',
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-file
* @subpackage blocktype-blogpost
* @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
......
<?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-recentposts
* @author Penny Leach <penny@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'] = 'Recent Blog Posts';
$string['description'] = 'Display the 10 most recent blog posts';
$string['postedin'] = 'in';
$string['postedon'] = 'on';
?>
<?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-recentposts
* @author Penny Leach <penny@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 PluginBlocktypeRecentposts extends PluginBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.blog/recentposts');
}
public static function get_description() {
return get_string('description', 'blocktype.blog/recentposts');
}
public static function get_categories() {
return array('blog');
}
public static function render_instance(BlockInstance $instance) {
$configdata = $instance->get('configdata');
$result = '';
if (!empty($configdata['artefactids'])) {
$artefactids = implode(', ', array_map('db_quote', $configdata['artefactids']));
if (!$mostrecent = get_records_sql_array(
'SELECT a.title, a.ctime, p.title AS parenttitle, a.id, a.parent
FROM {artefact} a
JOIN {artefact} p ON a.parent = p.id
WHERE a.artefacttype = \'blogpost\'
AND a.parent IN ( ' . $artefactids . ' )
AND a.owner = (SELECT owner from {view} WHERE id = ?)
ORDER BY a.ctime DESC
LIMIT 10', array($instance->get('view')))) {
$mostrecent = array();
}
// format the dates
foreach ($mostrecent as &$data) {
$data->displaydate = format_date(time($data->ctime));
}
$smarty = smarty_core();
$smarty->assign('mostrecent', $mostrecent);
$smarty->assign('view', $instance->get('view'));
$result = $smarty->fetch('blocktype:recentposts:recentposts.tpl');
}
return $result;
}
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['artefactids'])) ? $configdata['artefactids'] : null),
);
}
public static function artefactchooser_element($default=null) {
return array(
'name' => 'artefactids',
'type' => 'artefactchooser',
'title' => get_string('blogs', 'artefact.blog'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'recentposts',
'limit' => 10,
'selectone' => false,
'artefacttypes' => array('blog'),
'template' => 'artefact:blog:artefactchooser-element.tpl',
);
}
/**
* 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 'title';
}
}
?>
<ul>
{foreach from=$mostrecent item=post}
<li>
<a href="{$WWWROOT}view/view.php?view={$view}&artefact={$post->id}">{$post->title|escape}</a>
{str tag='postedin' section='blocktype.blog/recentposts'}
<a href="{$WWWROOT}view/view.php?view={$view}&artefact={$post->parent}">{$post->parenttitle|escape}</a>
{str tag='postedon' section='blocktype.blog/recentposts'}
{$post->displaydate}
</li>
{/foreach}
</ul>
<?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-recentposts
* @author Penny Leach <penny@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 = 2007110500;
$config->release = '0.9';
?>
<?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 artefact-blog
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
//
// NOTE: this script is used for rendering a blog in the view interface.
// It is envisioned later that the blog blocktype will be modified to not use
// javascript to render a blog, and thus this script can be removed.
//
define('INTERNAL', 1);
define('JSON', 1);
define('PUBLIC', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'blog');
$id = param_integer('id');
$limit = param_integer('limit', ArtefactTypeBlog::pagination);
$offset = param_integer('offset', 0);
$options = json_decode(param_variable('options'));
$viewid = isset($options->viewid) ? $options->viewid : null;
if ($viewid) {
if (!can_view_view($viewid)) {
throw new AccessDeniedException();
}
}
else {
if (!$USER->is_logged_in()) {
throw new AccessDeniedException();
}
if (!$viewid && get_field('artefact', 'owner', 'id', $id) != $USER->get('id')) {
throw new AccessDeniedException();
}
}
($postids = get_records_sql_array("
SELECT a.id
FROM {artefact} a
LEFT OUTER JOIN {artefact_blog_blogpost} bp
ON a.id = bp.blogpost
WHERE a.parent = ?
AND bp.published = 1
ORDER BY a.ctime DESC
LIMIT ? OFFSET ?;", array($id, $limit, $offset)))
|| ($postids = array());
$data = array();
foreach($postids as $postid) {
$blogpost = new ArtefactTypeBlogPost($postid->id);
$data[] = array(
'id' => $postid->id,
'content' => $blogpost->render_self((array) $options)
);
}
$count = (int)get_field_sql("
SELECT COUNT(*)
FROM {artefact} a
LEFT OUTER JOIN {artefact_blog_blogpost} bp
ON a.id = bp.blogpost
WHERE a.parent = ?
AND bp.published = 1", array($id));
if (!$count) {
$count = 1;
$data = array(
array(
'content' => get_string('noresults', 'artefact.blog')
)
);
}
json_reply(false, array(
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'data' => $data
));
?>
......@@ -78,6 +78,8 @@ $string['errorsavingattachments'] = 'An error occurred while saving blog post at
$string['horizontalspace'] = 'Horizontal space';
$string['insert'] = 'Insert';
$string['insertimage'] = 'Insert image';
$string['mustspecifytitle'] = 'You must specify a title for your post';
$string['mustspecifycontent'] = 'You must specify some content for your post';
$string['myblogs'] = 'My Blogs';
$string['name'] = 'Name';
$string['newattachmentsexceedquota'] = 'The total size of the new files that you have uploaded to this post would exceed your quota. You may be able to save the post if you remove some of the attachments you have just added.';
......
......@@ -234,6 +234,48 @@ class ArtefactTypeBlog extends ArtefactType {
return $this->count_children() . ' ' . get_string('posts', 'artefact.blog');
}