artefact.php 7.59 KB
Newer Older
1 2 3 4 5
<?php
/**
 *
 * @package    mahara
 * @subpackage core
6
 * @author     Catalyst IT Ltd
7 8
 * @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.
9 10 11 12 13
 *
 */

define('INTERNAL', 1);
define('PUBLIC', 1);
14
define('SECTION_PLUGINTYPE', 'core');
15
define('SECTION_PLUGINNAME', 'core');
16 17
define('SECTION_PAGE', 'artefact');

18
require(dirname(dirname(__FILE__)) . '/init.php');
19
require_once(get_config('libroot') . 'view.php');
20
require_once(get_config('libroot') . 'objectionable.php');
21
safe_require('artefact', 'comment');
22

23 24
$artefactid = param_integer('artefact');
$viewid     = param_integer('view');
25
$blockid    = param_integer('block', null);
26

27
$view = new View($viewid);
28
if (!can_view_view($view)) {
29 30 31
    throw new AccessDeniedException();
}

32 33
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($artefactid);
34 35 36 37 38 39

if (!$artefact->in_view_list()) {
    throw new AccessDeniedException(get_string('artefactonlyviewableinview', 'error'));
}

// Build the path to the artefact through its parents.
40
$artefactpath = array();
41
// Reverse the order of ancestors so we can get $baseobject by working backwards through the ancestors
42
$ancestors = array_reverse($artefact->get_item_ancestors());
43
$artefactok = false;
44 45

if (artefact_in_view($artefact, $viewid)) {
46 47 48 49
    $artefactok = true;
    $baseobject = $artefact;
}

50 51
if (!empty($ancestors)) {
    foreach ($ancestors as $ancestor) {
52 53 54 55 56 57 58 59 60 61
        if ($ancestor != $artefactid) {
            $pathitem = artefact_instance_from_id($ancestor);
            if (artefact_in_view($pathitem, $viewid)) {
                $artefactpath[] = array(
                    'url'   => get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $pathitem->get('id') . '&view=' . $viewid,
                    'title' => $pathitem->display_title(),
                );
                $artefactok = true;
                $baseobject = $pathitem;
            }
62
        }
63 64
    }
}
65 66
// Reverse the order back again so $artefactpath can display the paths from highest ancestor first
$artefactpath = array_reverse($artefactpath);
67

68
if ($artefactok == false) {
69
    throw new AccessDeniedException(get_string('artefactnotinview', 'error', $artefactid, $viewid));
70 71
}

72
// Comment list pagination requires limit/offset params
73 74 75
$limit       = param_integer('limit', 10);
$offset      = param_integer('offset', 0);
$showcomment = param_integer('showcomment', null);
76

77
if ($artefact && $viewid && $blockid) {
78
    // use the block instance title rather than the artefact title if it exists
79
    $title = artefact_title_for_view_and_block($artefact, $viewid, $blockid);
80 81 82
}
else {
    $title = $artefact->display_title();
83
}
84

85
// Create the "make comment private form" now if it's been submitted
86
if (param_exists('make_public_submit')) {
87
    pieform(ArtefactTypeComment::make_public_form(param_integer('comment')));
88
}
89
else if (param_exists('delete_comment_submit')) {
90
    pieform(ArtefactTypeComment::delete_comment_form(param_integer('comment')));
91 92
}

93
define('TITLE', $title . ' ' . get_string('in', 'view') . ' ' . $view->get('title'));
Nigel McNie's avatar
Nigel McNie committed
94 95

// Render the artefact
96 97
$options = array(
    'viewid' => $viewid,
98
    'details' => true,
99
    'metadata' => 1,
100
);
101

102
if ($artefact->get('artefacttype') == 'folder') {
103 104
    // Get folder block sort order - returns the first instance of folder on view unless $blockid is set.
    // TODO: get the clicking on a subfolder to carry the block id as well - that way we can get exact configdata.
105
    if ($block = get_records_sql_array('SELECT block FROM {view_artefact} WHERE view = ? AND artefact = ?', array($viewid, $baseobject->get('id')))) {
106
        require_once(get_config('docroot') . 'blocktype/lib.php');
107
        $key = 0;
108
        // If we have a $blockid, then we will use block's configdata.
109 110 111 112 113 114 115 116 117
        if ($blockid) {
            foreach ($block as $k => $b) {
                if ($b->block == $blockid) {
                    $key = $k;
                    break;
                }
            }
        }
        $bi = new BlockInstance($block[$key]->block);
118 119 120 121
        $configdata = $bi->get('configdata');
        if (!empty($configdata['sortorder'])) {
            $options['sortorder'] = $configdata['sortorder'];
        }
122 123 124
        if (!empty($configdata['folderdownloadzip'])) {
            $options['folderdownloadzip'] = true;
        }
125 126
    }
}
127 128 129
$rendered = $artefact->render_self($options);
$content = '';
if (!empty($rendered['javascript'])) {
130
    $content = '<script type="application/javascript">' . $rendered['javascript'] . '</script>';
131 132 133
}
$content .= $rendered['html'];

134
// Comments
135 136 137 138 139 140 141
$commentoptions = ArtefactTypeComment::get_comment_options();
$commentoptions->limit = $limit;
$commentoptions->offset = $offset;
$commentoptions->showcomment = $showcomment;
$commentoptions->view = $view;
$commentoptions->artefact = $artefact;
$feedback = ArtefactTypeComment::get_comments($commentoptions);
142

143
$inlinejavascript = <<<EOF
144
var viewid = {$viewid};
145
var artefactid = {$artefactid};
146
jQuery(function () {
147 148
    paginator = {$feedback->pagination_js}
});
149 150
EOF;

Naomi Guyer's avatar
Naomi Guyer committed
151
$javascript = array('paginator', 'viewmenu');
152

153
if ($artefact->get('allowcomments') && ( $USER->is_logged_in() || (!$USER->is_logged_in() && get_config('anonymouscomments')))) {
154 155 156 157
    $commenttype = $view->user_comments_allowed($USER);
    $moderate = isset($commenttype) && $commenttype === 'private';

    $addfeedbackform = pieform(ArtefactTypeComment::add_comment_form(false, $moderate));
158
}
159
$objectionform = pieform(objection_form());
160
if ($notrudeform = notrude_form()) {
161 162
    $notrudeform = pieform($notrudeform);
}
163

164 165
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);

166 167 168
// Set up theme
$viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
169
    $THEME = new Theme($view);
170
}
171
$headers = array();
172

173 174 175 176 177 178 179 180 181 182 183
// Set up skin, if the page has one
$owner    = $view->get('owner');
$viewskin = $view->get('skin');
if ($viewskin && get_config('skins') && can_use_skins($owner) && (!isset($THEME->skins) || $THEME->skins !== false)) {
    $skin = array('skinid' => $viewskin, 'viewid' => $view->get('id'));
    $skindata = unserialize(get_field('skin', 'viewskin', 'id', $viewskin));
}
else {
    $skin = false;
}

184 185 186
$hasfeed = false;
$feedlink = '';
// add a link to the ATOM feed in the header if the view is public
187
if ($artefact->get('artefacttype') == 'blog' && $view->is_public()) {
188 189
    $hasfeed = true;
    $feedlink = get_config('wwwroot') . 'artefact/blog/atom.php?artefact=' .
190
                $artefactid . '&view=' . $viewid;
191
    $headers[] = '<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '">';
192 193
}

194
$smarty = smarty(
195
    $javascript,
196
    $headers,
197
    array(),
198
    array(
199
        'sidebars'    => false,
200
        'skin'        => $skin,
201 202
    )
);
203

204
$smarty->assign('artefacttitle', $title);
205
$smarty->assign('artefact', $content);
Nigel McNie's avatar
Nigel McNie committed
206
$smarty->assign('artefactpath', $artefactpath);
207
$smarty->assign('INLINEJAVASCRIPT', $inlinejavascript);
208
$smarty->assign('PAGEHEADING', null);
209
$smarty->assign('view', $view);
210
$smarty->assign('viewid', $viewid);
211
$smarty->assign('feedback', $feedback);
212

213 214 215
$smarty->assign('hasfeed', $hasfeed);
$smarty->assign('feedlink', $feedlink);

216 217 218 219
if (isset($addfeedbackform)) {
    $smarty->assign('enablecomments', 1);
    $smarty->assign('addfeedbackform', $addfeedbackform);
}
220
$smarty->assign('objectionform', $objectionform);
221
$smarty->assign('notrudeform', $notrudeform);
222
$smarty->assign('viewbeingwatched', $viewbeingwatched);
223 224
$smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('viewdisplaytitle', $view->display_title(true, true, $view->display_author()));
225

226
$smarty->display('artefact/artefact.tpl');