forked from MaharaProject/mahara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
120 lines (109 loc) · 4.07 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
*
* @package mahara
* @subpackage artefact-blog
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'blog');
define('SECTION_PAGE', 'index');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'blog');
if ($delete = param_integer('delete', 0)) {
ArtefactTypeBlog::delete_form($delete);
}
$blogs = (object) array(
'offset' => param_integer('offset', 0),
'limit' => param_integer('limit', 10),
'institution' => null,
'group' => null,
'data' => false,
'pagination_js' => false,
);
$subsectionheading = false;
$institutionname = $groupid = null;
if ($institution = param_alphanum('institution', null)) {
define('TITLE', get_string('blogs','artefact.blog'));
if ($institution == 'mahara') {
$institutionname = $institution;
if (!($USER->get('admin'))) {
throw new AccessDeniedException();
}
$institutiontitle = get_string('siteblogs', 'artefact.blog');
}
else {
$s = institution_selector_for_page($institution, get_config('wwwroot') . 'artefact/blog/index.php');
$institutionname = $s['institution'];
if (!($USER->get('admin') || $USER->is_institutional_admin())) {
throw new AccessDeniedException();
}
$institutiontitle = get_string('institutionblogs', 'artefact.blog');
}
$blogs->institution = $institutionname;
}
else if ($groupid = param_alphanum('group', null)) {
$blogs->group = $groupid;
$group = get_record('group', 'id', $groupid, 'deleted', 0);
$subsectionheading = get_string('blogs','artefact.blog');
define('TITLE', $group->name);
}
else {
define('TITLE', get_string('blogs','artefact.blog'));
}
PluginArtefactBlog::set_blog_nav($institution, $institutionname, $groupid);
list($blogs->count, $blogs->data) = ArtefactTypeBlog::get_blog_list($blogs->limit, $blogs->offset, $blogs->institution, $blogs->group);
if (empty($blogs->institution) && empty($blogs->group)) {
if (!$USER->get_account_preference('multipleblogs')) {
$extra = !empty($institution) ? '?institution=' . $institution : '';
$extra = !empty($group) ? '?group=' . $group : '';
redirect(get_config('wwwroot') . 'artefact/blog/view/index.php' . $extra);
}
}
ArtefactTypeBlog::build_blog_list_html($blogs);
$smarty = smarty(array('paginator'));
$smarty->assign_by_ref('blogs', $blogs);
$smarty->assign('institutionname', $institutionname);
$smarty->assign('group', $groupid);
if ($subsectionheading) {
$smarty->assign('subsectionheading', $subsectionheading);
}
$smarty->assign('PAGEHEADING', TITLE);
$js = '';
if ($blogs->pagination_js) {
$js .= 'addLoadEvent(function() {' . $blogs->pagination_js . '});';
}
if (!empty($institutionname) && ($institutionname != 'mahara')) {
$smarty->assign('institution', $institutionname);
$smarty->assign('institutionselector', $s['institutionselector']);
$js .= $s['institutionselectorjs'];
}
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->display('artefact:blog:index.tpl');
function delete_blog_submit(Pieform $form, $values) {
global $SESSION;
require_once('embeddedimage.php');
$blog = new ArtefactTypeBlog($values['delete']);
$blog->check_permission();
$institution = $blog->get('institution');
$group = $blog->get('group');
if ($blog->get('locked')) {
$SESSION->add_error_msg(get_string('submittedforassessment', 'view'));
}
else {
$blog->delete();
EmbeddedImage::delete_embedded_images('blog', $blog->get('id'));
$SESSION->add_ok_msg(get_string('blogdeleted', 'artefact.blog'));
}
if ($institution) {
redirect('/artefact/blog/index.php?institution=' . $institution);
}
else if ($group) {
redirect('/artefact/blog/index.php?group=' . $group);
}
redirect('/artefact/blog/index.php');
}