portfolio MDL-20896 added mimetype checking for portfolio plugins for single-file...
[moodle.git] / lib / portfolio / formats.php
CommitLineData
87fcac8d 1<?php
2/**
3 * Moodle - Modular Object-Oriented Dynamic Learning Environment
4 * http://moodle.org
5 * Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * @package moodle
21 * @subpackage portfolio
22 * @author Penny Leach <penny@catalyst.net.nz>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
24 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
25 *
26 * This file contains all the class definitions of the export formats.
27 * They are implemented in php classes rather than just a simpler hash
28 * Because it provides an easy way to do subtyping using php inheritance.
29 */
30
31/**
32* the most basic type - pretty much everything is a subtype
33*/
34class portfolio_format_file {
086831a6
PL
35
36 /**
37 * array of mimetypes this format supports
38 */
87fcac8d 39 public static function mimetypes() {
40 return array(null);
41 }
6be1dcae 42
086831a6
PL
43 /**
44 * for multipart formats, eg html with attachments,
45 * we need to have a directory to place associated files in
46 * inside the zip file. this is the name of that directory
47 */
6be1dcae 48 public static function get_file_directory() {
49 return null;
50 }
51
086831a6
PL
52 /**
53 * given a file, return a snippet of markup in whatever format
54 * to link to that file.
55 * usually involves the path given by {@link get_file_directory}
56 */
6be1dcae 57 public static function file_output($file) {
58 return '';
59 }
87fcac8d 60}
61
62/**
63* image format, subtype of file.
64*/
65class portfolio_format_image extends portfolio_format_file {
086831a6
PL
66 /**
67 * return all mimetypes that use image.gif (eg all images)
68 */
87fcac8d 69 public static function mimetypes() {
70 return mimeinfo_from_icon('type', 'image.gif', true);
71 }
72}
73
74/**
75* html format - could be used for an external cms or something
76*
77* in case we want to be really specific.
78*/
6be1dcae 79class portfolio_format_plainhtml extends portfolio_format_file {
87fcac8d 80 public static function mimetypes() {
81 return array('text/html');
82 }
83}
84
85/**
86* video format, subtype of file.
87*
086831a6 88* for portfolio plugins that support videos specifically
87fcac8d 89*/
90class portfolio_format_video extends portfolio_format_file {
91 public static function mimetypes() {
d02b207a 92 return array_merge(
086831a6
PL
93 mimeinfo_from_icon('type', 'video.gif', true),
94 mimeinfo_from_icon('type', 'avi.gif', true)
95 );
87fcac8d 96 }
97}
98
99/**
100* class for plain text format.. not sure why we would need this yet
101* but since resource module wants to export it... we can
102*/
103class portfolio_format_text extends portfolio_format_file {
104 public static function mimetypes() {
105 return array('text/plain');
106 }
107}
108
086831a6
PL
109/**
110 * base class for rich formats.
111 * these are multipart - eg things with attachments
112 */
6be1dcae 113class portfolio_format_rich {
114 public static function mimetypes() {
115 return array(null);
116 }
117}
118
086831a6
PL
119/**
120 * most commonly used rich format - richhtml - html with attachments
121 * eg inline images
122 */
6be1dcae 123class portfolio_format_richhtml extends portfolio_format_rich {
124 public static function get_file_directory() {
125 return 'site_files';
126 }
127 public static function file_output($file) {
128 $path = self::get_file_directory() . '/' . $file->get_filename();
129 if (in_array($file->get_mimetype(), portfolio_format_image::mimetypes())) {
130 return '<img src="' . $path . '" alt="' . $file->get_filename() . '" />';
131 }
132 return '<a href="' . $path . '">' . $file->get_filename() . '</a>';
133 }
134}
135
136class portfolio_format_leap extends portfolio_format_rich { }
137
138
87fcac8d 139/**
140* later.... a moodle plugin might support this.
141* it's commented out in portfolio_supported_formats so cannot currently be used.
142*/
6be1dcae 143class portfolio_format_mbkp extends portfolio_format_rich {}