Skip to content

Instantly share code, notes, and snippets.

@TheRealJAG
Last active December 9, 2016 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheRealJAG/b2fcbb2527ad4061e1f2193d220e6ceb to your computer and use it in GitHub Desktop.
Save TheRealJAG/b2fcbb2527ad4061e1f2193d220e6ceb to your computer and use it in GitHub Desktop.
// This gives us the opportunity to specify things like extra header
// information and page title and all that
$extra_head = 'heads'.$slash.$subdir.basename($safepage);
$js = 'js/'.$subdir.basename($safepage, '.php').'.js';
$css = 'css/'.$subdir.basename($safepage, '.php').'.css';
/*
* If we cannot find an individual controller files, search for controller files
* that will blanket the entire directory. Failing upwards.
* For example:
* heads/phpdoc.php would apply to both intranet/phpdoc/all
* and intranet/phpdoc/framework/index or any other file in intranet/phpdoc/
*
* If no directory files are found check for a prepend controller files.
* For example:
* heads/cpu.php will apply to both /pages/cpu.php and /pages/cup_trucks.php
*/
$extControl = array(
$extra_head => array('heads', '.php'),
$js => array('js', '.js'),
$css => array('css', '.css')
);
$prepend = explode('_', basename($safepage, '.php'));
$dirstack = array_reverse(explode('/', $subdir));
unset($dirstack[0]);
array_push($dirstack, $basedir);
foreach ($extControl as $k => $v) {
$file = $k;
$extDir = $v[0];
$fileExt = $v[1];
$controller = $basedir . $slash . $subdir;
foreach ($dirstack as $dir) {
$controller = substr($controller, 0, -1);
if (!file_exists($file) && file_exists($extDir . $slash . $controller . $fileExt)) {
switch ($extDir) {
case 'heads':
$extra_head = $extDir . $slash . $controller . $fileExt;
break;
case 'js':
$js = $extDir . $slash . $controller . $fileExt;
break;
case 'css':
$css = $extDir . $slash . $controller . $fileExt;
break;
}
}
$controller = substr($controller, 0, (strlen($controller) - (strlen($dir))));
}
if (!file_exists($file) && file_exists($extDir . $slash . $prepend[0] . $fileExt)) {
switch ($extDir) {
case 'heads':
$extra_head = $extDir . $slash . $prepend[0] . $fileExt;
break;
case 'js':
$js = $extDir . $slash . $prepend[0] . $fileExt;
break;
case 'css':
$css = $extDir . $slash . $prepend[0] . $fileExt;
break;
}
}
}
if (file_exists($extra_head)) {
include($extra_head);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment