Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion installtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
include_once(LEGACY_ROOT . '/constants.php');
include_once(LEGACY_ROOT . '/lib/InstallationTests.php');

/* Version check before including TemplateUtility for asset URL versioning. */
$phpVersion = phpversion();
$phpVersionParts = explode('.', $phpVersion);
if ($phpVersionParts[0] >= 5)
{
include_once(LEGACY_ROOT . '/lib/TemplateUtility.php');
}
else
{
$php4 = true;
}

$mainCSSURL = 'main.css';
if (!isset($php4))
{
$mainCSSURL = call_user_func(array('TemplateUtility', 'getVersionedAssetURL'), $mainCSSURL);
}


define('REQUIRED_SCHEMA_VERSION', '1200');

Expand All @@ -45,7 +63,7 @@
<html>
<head>
<title>CATS - Installation Test Script</title>
<style type="text/css" media="all">@import "main.css";</style>
<style type="text/css" media="all">@import "<?php echo $mainCSSURL; ?>";</style>
<style type="text/css" media="all">
table.test_output
{
Expand Down
20 changes: 16 additions & 4 deletions installwizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@
{
$php4 = true;
}

$installLibURL = 'js/lib.js';
$installScriptURL = 'js/install.js';
$subModalScriptURL = 'js/submodal/subModal.js';
$installCSSURL = 'modules/install/install.css';
if (!isset($php4))
{
$installLibURL = call_user_func(array('TemplateUtility', 'getVersionedAssetURL'), $installLibURL);
$installScriptURL = call_user_func(array('TemplateUtility', 'getVersionedAssetURL'), $installScriptURL);
$subModalScriptURL = call_user_func(array('TemplateUtility', 'getVersionedAssetURL'), $subModalScriptURL);
$installCSSURL = call_user_func(array('TemplateUtility', 'getVersionedAssetURL'), $installCSSURL);
}
?>
<html>
<head>
<title>OpenCATS - Installation Wizard Script</title>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="js/install.js"></script>
<script type="text/javascript" src="js/submodal/subModal.js"></script>
<style type="text/css" media="all">@import "modules/install/install.css";</style>
<script type="text/javascript" src="<?php echo $installLibURL; ?>"></script>
<script type="text/javascript" src="<?php echo $installScriptURL; ?>"></script>
<script type="text/javascript" src="<?php echo $subModalScriptURL; ?>"></script>
<style type="text/css" media="all">@import "<?php echo $installCSSURL; ?>";</style>
</head>

<body>
Expand Down
1 change: 1 addition & 0 deletions js/submodal/loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<head>
<title>Loading...</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- This file is loaded as static HTML and does not go through the normal PHP template pipeline, so its stylesheet path is not versioned by the shared asset helper. -->
<style type="text/css" media="all">@import "../../main.css";</style>
</head>

Expand Down
5 changes: 4 additions & 1 deletion lib/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public function startTable()
$sheet = $this->_profileLib->getProfileStylesheet();
if ($profileStylesheet === false || strcmp($profileStylesheet, $sheet))
{
echo sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $sheet);
echo sprintf(
'<link rel="stylesheet" type="text/css" href="%s" />',
TemplateUtility::getVersionedAssetURL($sheet)
);
$profileStylesheet = $sheet;
}

Expand Down
118 changes: 97 additions & 21 deletions lib/TemplateUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,76 @@ public static function _printQuickActionMenuHolder()
echo '</div>';
}

/**
* Returns an asset URL with a file-based version query parameter.
*
* @param string Relative asset path
* @return string
*/
public static function getVersionedAssetURL($assetPath)
{
$assetPath = (string) $assetPath;
if ($assetPath == '')
{
return $assetPath;
}

$parsedURL = parse_url($assetPath);
if ($parsedURL === false || isset($parsedURL['scheme']) || isset($parsedURL['host']))
{
return $assetPath;
}

$path = isset($parsedURL['path']) ? $parsedURL['path'] : '';
if ($path == '')
{
return $assetPath;
}

$legacyRootPath = realpath(LEGACY_ROOT);
if ($legacyRootPath === false)
{
return $assetPath;
}

$normalizedPath = ltrim(str_replace('\\', '/', $path), '/');
if ($normalizedPath == '')
{
return $assetPath;
}

$assetFilePath = realpath(
$legacyRootPath . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $normalizedPath)
);
if ($assetFilePath === false)
{
return $assetPath;
}

$legacyRootPrefix = rtrim($legacyRootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if ($assetFilePath !== $legacyRootPath && strpos($assetFilePath, $legacyRootPrefix) !== 0)
{
return $assetPath;
}

$fileMTime = @filemtime($assetFilePath);
if ($fileMTime === false)
{
return $assetPath;
}

$queryString = isset($parsedURL['query']) ? $parsedURL['query'] . '&' : '';
$queryString .= 'v=' . (int) $fileMTime;

$versionedAssetURL = $path . '?' . $queryString;
if (isset($parsedURL['fragment']))
{
$versionedAssetURL .= '#' . $parsedURL['fragment'];
}

return $versionedAssetURL;
}

/**
* Prints template header HTML.
*
Expand All @@ -1186,16 +1256,6 @@ private static function _printCommonHeader($pageTitle, $headIncludes = array())

$siteID = $_SESSION['CATS']->getSiteID();

/* This prevents caching problems when SVN updates are preformed. */
if ($_SESSION['CATS']->getCachedBuild() > 0)
{
$javascriptAntiCache = '?b=' . $_SESSION['CATS']->getCachedBuild();
}
else
{
$javascriptAntiCache = '?v=' . CATSUtility::getVersionAsInteger();
}

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"', "\n";
echo '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">', "\n";
Expand All @@ -1208,11 +1268,18 @@ private static function _printCommonHeader($pageTitle, $headIncludes = array())
CATSUtility::getIndexName(), '?m=rss" />', "\n";

/* Core JS files */
echo '<script type="text/javascript" src="js/lib.js'.$javascriptAntiCache.'"></script>', "\n";
echo '<script type="text/javascript" src="js/quickAction.js'.$javascriptAntiCache.'"></script>', "\n";
echo '<script type="text/javascript" src="js/calendarDateInput.js'.$javascriptAntiCache.'"></script>', "\n";
echo '<script type="text/javascript" src="js/submodal/subModal.js'.$javascriptAntiCache.'"></script>', "\n";
echo '<script type="text/javascript" src="js/jquery-1.3.2.min.js'.$javascriptAntiCache.'"></script>', "\n";
$coreJavaScriptFiles = array(
'js/lib.js',
'js/quickAction.js',
'js/calendarDateInput.js',
'js/submodal/subModal.js',
'js/jquery-1.3.2.min.js'
);
foreach ($coreJavaScriptFiles as $coreJavaScriptFile)
{
$versionedFilename = self::getVersionedAssetURL($coreJavaScriptFile);
echo '<script type="text/javascript" src="', $versionedFilename, '"></script>', "\n";
}
echo '<script type="text/javascript">CATSIndexName = ', json_encode((string) CATSUtility::getIndexName(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT), ';</script>', "\n";
if (isset($_SESSION['CATS']) && $_SESSION['CATS']->isLoggedIn())
{
Expand Down Expand Up @@ -1284,22 +1351,31 @@ private static function _printCommonHeader($pageTitle, $headIncludes = array())

foreach ($headIncludes as $key => $filename)
{
$extension = substr($filename, strrpos($filename, '.') + 1);
$path = parse_url($filename, PHP_URL_PATH);
if ($path === false || $path === null)
{
$path = $filename;
}
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));

$filename .= $javascriptAntiCache;
$versionedFilename = self::getVersionedAssetURL($filename);

if ($extension == 'js')
{
echo '<script type="text/javascript" src="', $filename, '"></script>', "\n";
echo '<script type="text/javascript" src="', $versionedFilename, '"></script>', "\n";
}
else if ($extension == 'css')
{
echo '<style type="text/css" media="all">@import "', $filename, '";</style>', "\n";
echo '<style type="text/css" media="all">@import "', $versionedFilename, '";</style>', "\n";
}
}

echo '<!--[if IE]><link rel="stylesheet" type="text/css" href="ie.css" /><![endif]-->', "\n";
echo '<![if !IE]><link rel="stylesheet" type="text/css" href="not-ie.css" /><![endif]>', "\n";
echo '<!--[if IE]><link rel="stylesheet" type="text/css" href="',
self::getVersionedAssetURL('ie.css'),
'" /><![endif]-->', "\n";
echo '<![if !IE]><link rel="stylesheet" type="text/css" href="',
self::getVersionedAssetURL('not-ie.css'),
'" /><![endif]>', "\n";
echo '</head>', "\n\n";
}

Expand Down
16 changes: 8 additions & 8 deletions modules/careers/Blank.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo(HTML_ENCODING); ?>" />
<title><?php $this->_($this->siteName); ?> - Careers</title>
<script type="text/javascript" src="../js/careerPortalApply.js"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/careerPortalApply.js'); ?>"></script>
<?php global $careerPage; if (isset($careerPage) && $careerPage == true): ?>
<script type="text/javascript" src="../js/lib.js"></script>
<script type="text/javascript" src="../js/sorttable.js"></script>
<script type="text/javascript" src="../js/calendarDateInput.js"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/sorttable.js'); ?>"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/calendarDateInput.js'); ?>"></script>
<?php else: ?>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="js/sorttable.js"></script>
<script type="text/javascript" src="js/calendarDateInput.js"></script>
<script type="text/javascript" src="js/careersPage.js"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/sorttable.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/calendarDateInput.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/careersPage.js'); ?>"></script>
<?php endif; ?>
<style type="text/css" media="all">
<?php echo($this->template['CSS']); ?>
Expand Down
8 changes: 4 additions & 4 deletions modules/careers/Blank2.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo(HTML_ENCODING); ?>">
<title><?php $this->_($this->siteName); ?> - Careers</title>
<?php global $careerPage; if (isset($careerPage) && $careerPage == true): ?>
<script type="text/javascript" src="../js/lib.js"></script>
<script type="text/javascript" src="../js/sorttable.js"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/sorttable.js'); ?>"></script>
<?php else: ?>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="js/sorttable.js"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/sorttable.js'); ?>"></script>
<?php endif; ?>
<style type="text/css" media="all">
<?php echo($this->template['CSS']); ?>
Expand Down
12 changes: 6 additions & 6 deletions modules/careers/BlankNoMargin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo(HTML_ENCODING); ?>">
<title><?php $this->_($this->siteName); ?> - Careers</title>
<?php global $careerPage; if (isset($careerPage) && $careerPage == true): ?>
<script type="text/javascript" src="../js/lib.js"></script>
<script type="text/javascript" src="../js/sorttable.js"></script>
<script type="text/javascript" src="../js/calendarDateInput.js"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/sorttable.js'); ?>"></script>
<script type="text/javascript" src="<?php echo '../' . TemplateUtility::getVersionedAssetURL('js/calendarDateInput.js'); ?>"></script>
<?php else: ?>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="js/sorttable.js"></script>
<script type="text/javascript" src="js/calendarDateInput.js"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/sorttable.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/calendarDateInput.js'); ?>"></script>
<?php endif; ?>
<style type="text/css" media="all">
<?php echo($this->template['CSS']); ?>
Expand Down
2 changes: 1 addition & 1 deletion modules/import/MassImport.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php TemplateUtility::printHeader('Settings', array('js/massImport.js')); ?>
<?php TemplateUtility::printHeaderBlock(); ?>
<?php TemplateUtility::printTabs($this->active, '', 'settings'); ?>
<link rel="stylesheet" type="text/css" href="modules/import/MassImport.css" />
<link rel="stylesheet" type="text/css" href="<?php echo TemplateUtility::getVersionedAssetURL('modules/import/MassImport.css'); ?>" />
<div id="main">
<div id="contents">
<div style="width: 880px; padding: 15px;">
Expand Down
2 changes: 1 addition & 1 deletion modules/import/MassImportEdit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?php TemplateUtility::printHeaderBlock(); ?>
<?php TemplateUtility::printTabs($this->active); ?>
<script src='http://resfly.com/js/resumeParserValidation.js' type='text/javascript' language='javascript'></script>
<link rel="stylesheet" type="text/css" href="modules/import/MassImport.css" />
<link rel="stylesheet" type="text/css" href="<?php echo TemplateUtility::getVersionedAssetURL('modules/import/MassImport.css'); ?>" />
<div id="main">
<div id="contents">
<div style="width: 910px; padding: 20px 5px 0 5px;">
Expand Down
8 changes: 5 additions & 3 deletions modules/install/notinstalled.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/html4/transitional.dtd">
<?php include_once('config.php'); ?>
<?php include_once('constants.php'); ?>
<?php include_once(LEGACY_ROOT . '/lib/TemplateUtility.php'); ?>
<html>
<head>
<title>OpenCATS - Installation Wizard Script</title>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="js/install.js"></script>
<style type="text/css" media="all">@import "modules/install/install.css";</style>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/install.js'); ?>"></script>
<style type="text/css" media="all">@import "<?php echo TemplateUtility::getVersionedAssetURL('modules/install/install.css'); ?>";</style>
</head>

<body>
Expand Down
8 changes: 5 additions & 3 deletions modules/install/phpVersion.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/html4/transitional.dtd">
<?php include_once('config.php'); ?>
<?php include_once('constants.php'); ?>
<?php include_once(LEGACY_ROOT . '/lib/TemplateUtility.php'); ?>
<html>
<head>
<title>CATS - Installation Wizard Script</title>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="js/install.js"></script>
<style type="text/css" media="all">@import "modules/install/install.css";</style>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/install.js'); ?>"></script>
<style type="text/css" media="all">@import "<?php echo TemplateUtility::getVersionedAssetURL('modules/install/install.css'); ?>";</style>
</head>

<body>
Expand Down
6 changes: 3 additions & 3 deletions modules/login/ForgotPassword.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<head>
<title>OpenCATS - Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo(HTML_ENCODING); ?>">
<style type="text/css" media="all">@import "modules/login/login.css";</style>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="modules/login/validator.js"></script>
<style type="text/css" media="all">@import "<?php echo TemplateUtility::getVersionedAssetURL('modules/login/login.css'); ?>";</style>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('modules/login/validator.js'); ?>"></script>
</head>

<body>
Expand Down
8 changes: 4 additions & 4 deletions modules/login/Login.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<head>
<title>opencats - Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo(HTML_ENCODING); ?>" />
<style type="text/css" media="all">@import "modules/login/login.css";</style>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="modules/login/validator.js"></script>
<script type="text/javascript" src="js/submodal/subModal.js"></script>
<style type="text/css" media="all">@import "<?php echo TemplateUtility::getVersionedAssetURL('modules/login/login.css'); ?>";</style>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('modules/login/validator.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/submodal/subModal.js'); ?>"></script>
</head>

<body>
Expand Down
Loading
Loading