Skip to content

Commit d5a2ed2

Browse files
committed
Fixed 413 - Dev issue: our .htaccess file on the server is doing a 301 redirect which is causing css and image loading issues.
- Switch to using a combine.php library and index.php scripts within each directory for combining files. This works around the iOS webkit bug that prevents images from being displayed the next time the page is loaded.
1 parent d22b711 commit d5a2ed2

File tree

5 files changed

+93
-207
lines changed

5 files changed

+93
-207
lines changed

.htaccess

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
Options +FollowSymLinks
33

44
RewriteEngine On
5-
RewriteRule ^themes/([a-zA-Z\-\_\0-9]+)\/$ combine.php?type=css&theme=$1
6-
RewriteRule ^js/all combine.php?type=javascript
5+
RewriteRule ^js/all$ js
76

87
# Turn on Expires and set default to 0
98
ExpiresActive On

combine.php

Lines changed: 16 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -1,207 +1,18 @@
11
<?php
22

3-
/************************************************************************
4-
* CSS and Javascript Combinator 0.5
5-
* Copyright 2006 by Niels Leenheer
6-
*
7-
* Permission is hereby granted, free of charge, to any person obtaining
8-
* a copy of this software and associated documentation files (the
9-
* "Software"), to deal in the Software without restriction, including
10-
* without limitation the rights to use, copy, modify, merge, publish,
11-
* distribute, sublicense, and/or sell copies of the Software, and to
12-
* permit persons to whom the Software is furnished to do so, subject to
13-
* the following conditions:
14-
*
15-
* The above copyright notice and this permission notice shall be
16-
* included in all copies or substantial portions of the Software.
17-
*
18-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24-
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25-
*/
26-
27-
28-
$cache = true;
29-
$write_combined = true;
30-
$pullfromcache = false;
31-
$theme = $_GET['theme'];
32-
$cachedir = dirname(__FILE__) . '/cache';
33-
$combinedir = dirname(__FILE__) . '/combined';
34-
$cssdir = dirname(__FILE__) . '/themes/' . $theme;
35-
$jsdir = dirname(__FILE__) . '/js';
36-
37-
// Determine the directory and type we should use
38-
switch ($_GET['type']) {
39-
case 'css':
40-
$base = realpath($cssdir);
41-
break;
42-
case 'javascript':
43-
$base = realpath($jsdir);
44-
break;
45-
default:
46-
header ("HTTP/1.0 503 Not Implemented");
47-
exit;
48-
};
49-
50-
$type = $_GET['type'];
51-
//$elements = explode(',', $_GET['files']);
52-
53-
include($base . '/manifest.php');
54-
55-
// Determine last modification date of the files
56-
$lastmodified = 0;
57-
while (list(,$element) = each($elements)) {
58-
$thisbase = $base;
59-
$thiselement = $element;
60-
if( strpos($thiselement, "../") === 0 ){
61-
$thiselement = str_replace("../","",$thiselement);
62-
$thisbase = explode("/", $thisbase);
63-
array_pop($thisbase);
64-
$thisbase = implode("/", $thisbase);
65-
}
66-
$path = realpath($thisbase . '/' . $thiselement);
67-
//echo $path;
68-
69-
if (($type == 'javascript' && substr($path, -3) != '.js') ||
70-
($type == 'css' && substr($path, -4) != '.css')) {
71-
header ("HTTP/1.0 403 Forbidden");
72-
exit;
73-
}
74-
75-
if (substr($path, 0, strlen($thisbase)) != $thisbase || !file_exists($path)) {
76-
header ("HTTP/1.0 404 Not Found");
77-
exit;
78-
}
79-
80-
$lastmodified = max($lastmodified, filemtime($path));
81-
}
82-
83-
// Send Etag hash
84-
$hash = $lastmodified . '-' . md5(implode('', $elements));
85-
header ("Etag: \"" . $hash . "\"");
86-
87-
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
88-
stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $hash . '"')
89-
{
90-
// Return visit and no modifications, so do not send anything
91-
header ("HTTP/1.0 304 Not Modified");
92-
header ('Content-Length: 0');
93-
}
94-
else
95-
{
96-
// First time visit or files were modified
97-
if ($cache)
98-
{
99-
// Determine supported compression method
100-
$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
101-
$deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate');
102-
103-
// Determine used compression method
104-
$encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none');
105-
106-
// Check for buggy versions of Internet Explorer
107-
if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') &&
108-
preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
109-
$version = floatval($matches[1]);
110-
111-
if ($version < 6)
112-
$encoding = 'none';
113-
114-
if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1'))
115-
$encoding = 'none';
116-
}
117-
118-
// Try the cache first to see if the combined files were already generated
119-
$cachefile = 'cache-' . $hash . '.' . $type . ($encoding != 'none' ? '.' . $encoding : '');
120-
121-
122-
if (file_exists($cachedir . '/' . $cachefile) && $pullfromcache == true) {
123-
if ($fp = fopen($cachedir . '/' . $cachefile, 'rb')) {
124-
125-
if ($encoding != 'none') {
126-
header ("Content-Encoding: " . $encoding);
127-
}
128-
129-
header ("Content-Type: text/" . $type);
130-
header ("Content-Length: " . filesize($cachedir . '/' . $cachefile));
131-
132-
fpassthru($fp);
133-
fclose($fp);
134-
exit;
135-
}
136-
}
137-
138-
}
139-
140-
// Get contents of the files
141-
$contents = '';
142-
reset($elements);
143-
while (list(,$element) = each($elements)) {
144-
$path = realpath($base . '/' . $element);
145-
$contents .= "\n\n" . file_get_contents($path);
146-
}
147-
148-
// Write pre gzipped files to disk
149-
if ($write_combined) {
150-
151-
if(!file_exists($combinedir)) {
152-
mkdir($combinedir, 0700);
153-
}
154-
155-
$filename = '';
156-
157-
//Determine the filename to use
158-
switch ($_GET['type']) {
159-
case 'css':
160-
$filename = 'jquery.mobile.css';
161-
break;
162-
case 'javascript':
163-
$filename = 'jquery.mobile.js';
164-
break;
165-
default:
166-
header ("HTTP/1.0 503 Not Implemented");
167-
exit;
168-
};
169-
170-
if ($fp = fopen($combinedir . '/' . $filename, 'wb')) {
171-
fwrite($fp, $contents);
172-
fclose($fp);
173-
}
174-
}
175-
176-
// Send Content-Type
177-
header ("Content-Type: text/" . $type);
178-
179-
if (isset($encoding) && $encoding != 'none')
180-
{
181-
// Send compressed contents
182-
$contents = gzencode($contents, 9, $gzip ? FORCE_GZIP : FORCE_DEFLATE);
183-
header ("Content-Encoding: " . $encoding);
184-
header ('Content-Length: ' . strlen($contents));
185-
echo $contents;
186-
}
187-
else
188-
{
189-
// Send regular contents
190-
header ('Content-Length: ' . strlen($contents));
191-
echo $contents;
192-
}
193-
194-
// Store cache
195-
if ($cache) {
196-
197-
if(!file_exists($cachedir)) {
198-
mkdir($cachedir, 0700);
199-
}
200-
201-
if ($fp = fopen($cachedir . '/' . $cachefile, 'wb')) {
202-
fwrite($fp, $contents);
203-
fclose($fp);
204-
}
205-
}
206-
}
207-
3+
if (!isset($type) || !isset($elements))
4+
{
5+
echo "\$type and \$elements must be specified!";
6+
exit;
7+
}
8+
9+
$contents = '';
10+
reset($elements);
11+
while (list(,$element) = each($elements)) {
12+
$contents .= "\n\n" . file_get_contents($element);
13+
}
14+
15+
header("Content-Type: " . $type);
16+
header("Content-Length: " . strlen($contents));
17+
echo $contents;
18+
?>

js/index.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
$type = "text/javascript";
3+
$elements = array(
4+
'jquery.js',
5+
'jquery.ui.widget.js',
6+
'jquery.mobile.widget.js',
7+
'jquery.mobile.support.js',
8+
'jquery.mobile.event.js',
9+
'jquery.mobile.hashchange.js',
10+
'jquery.mobile.page.js',
11+
'jquery.mobile.fixHeaderFooter.js',
12+
'jquery.mobile.forms.checkboxradio.js',
13+
'jquery.mobile.forms.textinput.js',
14+
'jquery.mobile.forms.select.js',
15+
'jquery.mobile.buttonMarkup.js',
16+
'jquery.mobile.forms.button.js',
17+
'jquery.mobile.forms.slider.js',
18+
'jquery.mobile.collapsible.js',
19+
'jquery.mobile.controlGroup.js',
20+
'jquery.mobile.fieldContain.js',
21+
'jquery.mobile.listview.js',
22+
'jquery.mobile.listview.filter.js',
23+
'jquery.mobile.dialog.js',
24+
'jquery.mobile.navbar.js',
25+
'jquery.mobile.grid.js',
26+
'jquery.mobile.js'
27+
);
28+
29+
include('../combine2.php');
30+
?>

themes/default/index.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
$type = "text/css";
3+
$elements = array(
4+
'jquery.mobile.theme.css',
5+
'jquery.mobile.core.css',
6+
'jquery.mobile.transitions.css',
7+
'jquery.mobile.grids.css',
8+
'jquery.mobile.headerfooter.css',
9+
'jquery.mobile.navbar.css',
10+
'jquery.mobile.button.css',
11+
'jquery.mobile.collapsible.css',
12+
'jquery.mobile.controlgroup.css',
13+
'jquery.mobile.dialog.css',
14+
'jquery.mobile.forms.checkboxradio.css',
15+
'jquery.mobile.forms.fieldcontain.css',
16+
'jquery.mobile.forms.select.css',
17+
'jquery.mobile.forms.textinput.css',
18+
'jquery.mobile.listview.css',
19+
'jquery.mobile.forms.slider.css'
20+
);
21+
22+
include('../../combine2.php');
23+
?>

themes/valencia/index.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
$type = "text/css";
3+
$elements = array(
4+
'jquery.mobile.theme.css',
5+
'../default/jquery.mobile.core.css',
6+
'../default/jquery.mobile.transitions.css',
7+
'../default/jquery.mobile.grids.css',
8+
'../default/jquery.mobile.headerfooter.css',
9+
'../default/jquery.mobile.navbar.css',
10+
'../default/jquery.mobile.button.css',
11+
'../default/jquery.mobile.collapsible.css',
12+
'../default/jquery.mobile.controlgroup.css',
13+
'../default/jquery.mobile.dialog.css',
14+
'../default/jquery.mobile.forms.checkboxradio.css',
15+
'../default/jquery.mobile.forms.fieldcontain.css',
16+
'../default/jquery.mobile.forms.select.css',
17+
'../default/jquery.mobile.forms.textinput.css',
18+
'../default/jquery.mobile.listview.css',
19+
'../default/jquery.mobile.forms.slider.css'
20+
);
21+
22+
include('../../combine2.php');
23+
?>

0 commit comments

Comments
 (0)