lib.php 4.24 KB
Newer Older
1
2
3
4
5
6
<?php
/**
 *
 * @package    mahara
 * @subpackage blocktype-html
 * @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
 *
 */

defined('INTERNAL') || die();

14
class PluginBlocktypeHtml extends MaharaCoreBlocktype {
15
16
17
18
19
20
21
22
23
24

    public static function get_title() {
        return get_string('title', 'blocktype.file/html');
    }

    public static function get_description() {
        return get_string('description', 'blocktype.file/html');
    }

    public static function get_categories() {
25
        return array('fileimagevideo' => 9000);
26
27
    }

28
    public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
29
30
31
32
        $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
        $configdata['viewid'] = $instance->get('view');

        $result = '';
33
34
35
        $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null;
        if ($artefactid) {
            $artefact = $instance->get_artefact_instance($artefactid);
36

37
            if (!file_exists($artefact->get_path())) {
38
39
40
                return;
            }

41
42
43
44
45
            $result = clean_html(file_get_contents($artefact->get_path()));

            require_once(get_config('docroot') . 'artefact/comment/lib.php');
            require_once(get_config('docroot') . 'lib/view.php');
            $view = new View($configdata['viewid']);
46
            list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
47
         }
48

49
50
51
52
53
54
55
        $smarty = smarty_core();
        if ($artefactid) {
            $smarty->assign('commentcount', $commentcount);
            $smarty->assign('comments', $comments);
        }
        $smarty->assign('html', $result);
        return $smarty->fetch('blocktype:html:html.tpl');
56
57
58
59
60
61
    }

    public static function has_instance_config() {
        return true;
    }

Son Nguyen's avatar
Son Nguyen committed
62
    public static function instance_config_form(BlockInstance $instance) {
63
        $configdata = $instance->get('configdata');
64
65
        safe_require('artefact', 'file');
        $instance->set('artefactplugin', 'file');
66
        return array(
67
68
69
70
71
            'artefactfieldset' => array(
                'type'         => 'fieldset',
                'collapsible'  => true,
                'collapsed'    => true,
                'legend'       => get_string('file', 'artefact.file'),
72
                'class'        => 'last select-file with-formgroup',
73
74
75
76
                'elements'     => array(
                    'artefactid' => self::filebrowser_element($instance, (isset($configdata['artefactid'])) ? array($configdata['artefactid']) : null),
                )
            ),
77
78
79
        );
    }

80
81
82
83
84
85
86
87
    private static function get_allowed_mimetypes() {
        static $mimetypes = array();
        if (!$mimetypes) {
            $mimetypes = get_column('artefact_file_mime_types', 'mimetype', 'description', 'html');
        }
        return $mimetypes;
    }

88
89
    public static function filebrowser_element(&$instance, $default=array()) {
        $element = ArtefactTypeFileBase::blockconfig_filebrowser_element($instance, $default);
90
        $element['title'] = get_string('file', 'artefact.file');
91
        $element['name'] = 'artefactid';
92
        $element['config']['selectone'] = true;
93
        $element['config']['selectmodal'] = true;
94
95
96
        $element['filters'] = array(
            'artefacttype'    => array('file'),
            'filetype'        => self::get_allowed_mimetypes(),
97
        );
98
        $element['accept'] = implode(',', self::get_allowed_mimetypes());
99
        return $element;
100
101
    }

102
    public static function artefactchooser_element($default=null) {
103
        return array(
104
105
106
107
108
109
110
111
112
113
114
            'name'  => 'artefactid',
            'type'  => 'artefactchooser',
            'title' => get_string('file', 'artefact.file'),
            'defaultvalue' => $default,
            'blocktype' => 'html',
            'limit' => 10,
            'artefacttypes' => array('file'),
            'template' => 'artefact:file:artefactchooser-element.tpl',
        );
    }

115
116
117
118
    public static function default_copy_type() {
        return 'full';
    }

119
}