Exemple #1
0
function smarty_function_includeMiscFiles($params, &$smarty)
{
    include_once "libSmartyHelpers.php";
    $loc = $smarty->_tpl_vars['__loc'];
    $myModule = $loc->mod;
    $myView = $smarty->_tpl_vars['__view'];
    //CSS
    $myCSSOriginals = glob2keyedArray(glob(BASE . "modules/" . $myModule . "/css/" . $myView . "*.css"));
    $myCSSOverrides = glob2keyedArray(glob(THEME_ABSOLUTE . "modules/" . $myModule . "/css/" . $myView . "*.css"));
    $myCSS = array_merge($myCSSOriginals, $myCSSOverrides);
    foreach ($myCSS as $myCSSFile) {
        echo "<link rel='stylesheet' type='text/css' href='" . absolute2relative($myCSSFile) . "'></link>";
    }
    //JavaScript
    $myJSOriginals = glob2keyedArray(glob(BASE . "modules/" . $myModule . "/js/" . $myView . "*.js"));
    $myJSOverrides = glob2keyedArray(glob(THEME_ABSOLUTE . "modules/" . $myModule . "/js/" . $myView . "*.js"));
    $myJS = array_merge($myJSOriginals, $myJSOverrides);
    foreach ($myJS as $myJSFile) {
        echo "<script type='text/javascript' src='" . absolute2relative($myJSFile) . "'></script>";
    }
}
function exponent_core_resolveFilePaths($type, $name, $subtype, $subname)
{
    //TODO: implement caching
    //TODO: optimization - walk the tree backwards and stop on the first match
    // new style name processing
    //once baseclasses are in place, simply lookup the baseclass name of an object
    if ($type == "guess") {
        $type = array_pop(preg_split("*(?=[A-Z])*", $name));
    }
    // convert types into paths
    $relpath = '';
    if ($type == "modules") {
        $relpath .= "modules/";
    } elseif ($type == "forms") {
        $relpath .= "subsystems/forms/";
    } elseif ($type == "themes") {
        $relpath .= "themes/";
    } elseif ($type == "datatypes") {
        $relpath .= "datatypes/";
    } elseif ($type == "controls") {
        $relpath .= "subsystems/forms/controls/";
        // new style names
    } elseif ($type == "Control") {
        $relpath .= "subsystems/forms/controls/";
    } elseif ($type == "Form") {
        $relpath .= "subsystems/forms/";
    } elseif ($type == "Module") {
        $relpath .= "modules/";
    } elseif ($type == "Theme") {
        $relpath .= "themes/";
    }
    // for later use for searching in lib/common
    $typepath = $relpath;
    if ($name != "") {
        $relpath .= $name . "/";
    }
    // for later use for searching in lib/common
    $relpath2 = '';
    if ($subtype == "css") {
        $relpath2 .= "css/";
    } elseif ($subtype == "js") {
        $relpath2 .= "js/";
    } elseif ($subtype == "tpl") {
        $relpath2 .= "views/";
    } elseif ($subtype == "form") {
        $relpath2 .= "views/";
    } elseif ($subtype == "action") {
        $relpath2 .= "actions/";
        //HACK: workaround for now
        $subtype = "php";
    }
    $relpath2 .= $subname;
    if ($subtype != "") {
        $relpath2 .= "." . $subtype;
    }
    $relpath .= $relpath2;
    //TODO: handle subthemes
    //TODO: now that glob is used build a syntax for it instead of calling it repeatedly
    //latter override the precursors
    //BASE does not have a trailing slash ?!
    $locations = array(BASE . "/", THEME_ABSOLUTE);
    foreach ($locations as $location) {
        // legacy support
        $checkpaths[] = $location . $typepath . "common/" . $relpath2;
        //$checkpaths[] = $location . $typepath . "lib/" . $relpath2;
        $checkpaths[] = $location . $relpath;
    }
    //TODO: handle the - currently unused - case where there is
    //the same file in different $type categories
    $myFiles = array();
    foreach ($checkpaths as $checkpath) {
        $tempFiles = glob2keyedArray(glob($checkpath));
        if ($tempFiles != false) {
            $myFiles = array_merge($myFiles, $tempFiles);
        }
    }
    if (count($myFiles) != 0) {
        return array_values($myFiles);
    } else {
        //TODO: invent better error handling, maybe an error message channel ?
        //die("The file " . basename($filepath) . " could not be found in the filesystem");
        return false;
    }
}