rating MDL-24558 new string for when no ratings have been submitted
[moodle.git] / theme / yui_combo.php
CommitLineData
60f2c866 1<?php
aa42314d
PS
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * This file is responsible for serving of yui images
20 *
21 * @package moodlecore
22 * @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26
27// we need just the values from config.php and minlib.php
28define('ABORT_AFTER_CONFIG', true);
29require('../config.php'); // this stops immediately at the beginning of lib/setup.php
30
31// get special url parameters
32if (!$parts = combo_params()) {
33 combo_not_found();
34}
35
945f19f7
PS
36$parts = trim($parts, '&');
37
aa42314d
PS
38// find out what we are serving - only one type per request
39$content = '';
40if (substr($parts, -3) === '.js') {
a6338a13 41 $mimetype = 'application/javascript';
aa42314d
PS
42} else if (substr($parts, -4) === '.css') {
43 $mimetype = 'text/css';
44} else {
45 combo_not_found();
46}
47
48$parts = explode('&', $parts);
77387297 49$cache = true;
aa42314d
PS
50
51foreach ($parts as $part) {
945f19f7
PS
52 if (empty($part)) {
53 continue;
54 }
aa42314d
PS
55 $part = min_clean_param($part, 'SAFEPATH');
56 $bits = explode('/', $part);
57 if (count($bits) < 2) {
a4738eb3
PS
58 $content .= "\n// Wrong combo resource $part!\n";
59 continue;
aa42314d 60 }
2b722f87
SH
61 //debug($bits);
62 $version = array_shift($bits);
63 if ($version == 'moodle') {
78bfb562
PS
64 //TODO: this is a ugly hack because we should not load any libs here!
65 define('MOODLE_INTERNAL', true);
3b17690c 66 require_once($CFG->libdir.'/moodlelib.php');
77387297
SH
67 $revision = (int)array_shift($bits);
68 if ($revision === -1) {
69 // Revision -1 says please don't cache the JS
70 $cache = false;
71 }
2b722f87 72 $frankenstyle = array_shift($bits);
3b17690c 73 $filename = array_pop($bits);
2b722f87 74 $dir = get_component_directory($frankenstyle);
3b17690c
SH
75 if ($mimetype == 'text/css') {
76 $bits[] = 'assets';
77 $bits[] = 'skins';
78 $bits[] = 'sam';
79 }
80 $contentfile = $dir.'/yui/'.join('/', $bits).'/'.$filename;
2b722f87
SH
81 } else {
82 if ($version != $CFG->yui3version and $version != $CFG->yui2version and $version != 'gallery') {
83 $content .= "\n// Wrong yui version $part!\n";
84 continue;
85 }
86 $contentfile = "$CFG->libdir/yui/$part";
aa42314d 87 }
aa42314d 88 if (!file_exists($contentfile) or !is_file($contentfile)) {
a4738eb3
PS
89 $content .= "\n// Combo resource $part not found!\n";
90 continue;
aa42314d
PS
91 }
92 $filecontent = file_get_contents($contentfile);
93
94 if ($mimetype === 'text/css') {
3b17690c
SH
95 if ($version == 'moodle') {
96 $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/'.$frankenstyle.'/'.array_shift($bits).'/$1.$2', $filecontent);
97 } else if ($version == 'gallery') {
2a102b90 98 // search for all images in gallery module CSS and serve them through the yui_image.php script
2b722f87 99 $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/'.$bits[0].'/'.$bits[1].'/$1.$2', $filecontent);
2a102b90
SH
100 } else {
101 // search for all images in yui2 CSS and serve them through the yui_image.php script
102 $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/$1.$2', $filecontent);
103 }
aa42314d
PS
104 }
105
106 $content .= $filecontent;
107}
108
77387297
SH
109if ($cache) {
110 combo_send_cached($content, $mimetype);
111} else {
112 combo_send_uncached($content, $mimetype);
113}
aa42314d
PS
114
115
77387297
SH
116/**
117 * Send the JavaScript cached
118 * @param string $content
119 * @param string $mimetype
120 */
aa42314d
PS
121function combo_send_cached($content, $mimetype) {
122 $lifetime = 60*60*24*300; // 300 days === forever
123
124 header('Content-Disposition: inline; filename="combo"');
125 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
126 header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
127 header('Pragma: ');
945f19f7 128 header('Cache-Control: max-age=315360000');
aa42314d
PS
129 header('Accept-Ranges: none');
130 header('Content-Type: '.$mimetype);
7c986f04
PS
131 if (!min_enable_zlib_compression()) {
132 header('Content-Length: '.strlen($content));
133 }
aa42314d 134
aa42314d
PS
135 echo $content;
136 die;
137}
138
77387297
SH
139/**
140 * Send the JavaScript uncached
141 * @param string $content
142 * @param string $mimetype
143 */
144function combo_send_uncached($content, $mimetype) {
145 header('Content-Disposition: inline; filename="combo"');
146 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
147 header('Expires: '. gmdate('D, d M Y H:i:s', time() + 2) .' GMT');
148 header('Pragma: ');
149 header('Accept-Ranges: none');
150 header('Content-Type: '.$mimetype);
151 if (!min_enable_zlib_compression()) {
152 header('Content-Length: '.strlen($content));
153 }
154
155 echo $content;
156 die;
157}
158
aa42314d
PS
159function combo_not_found() {
160 header('HTTP/1.0 404 not found');
161 die('Combo resource not found, sorry.');
162}
163
164function combo_params() {
165 if (!empty($_SERVER['REQUEST_URI'])) {
166 $parts = explode('?', $_SERVER['REQUEST_URI']);
167 if (count($parts) != 2) {
168 return '';
169 }
170 return $parts[1];
171
172 } else if (!empty($_SERVER['QUERY_STRING'])) {
173 return $_SERVER['QUERY_STRING'];
174
175 } else {
176 return '';
177 }
178}