/**
 * Smarty {includemiscfiles} postfilter plugin
 *
 * Type:     postfilter<br>
 * Name:     includemiscfiles<br>
 * Purpose:   This function creates html loaders for - currently - JS and CSS Files
 *            Please note it will only work for newtype __names (SomeModule, SomeForm, SomeTheme, SomeControl...)
 *
 * @param         $compiledsource
 * @param \Smarty $smarty
 *
 * @return bool
 */
function smarty_postfilter_includemiscfiles($compiledsource, &$smarty)
{
    ob_start();
    //CSS
    $myCSS = expCore::resolveFilePaths("guess", $smarty->getTemplateVars('__name'), "css", $smarty->getTemplateVars('__view') . "*");
    if ($myCSS != false) {
        foreach ($myCSS as $myCSSFile) {
            echo "<link rel='stylesheet' type='text/css' href='" . expCore::abs2rel($myCSSFile) . "'></link>\n";
        }
    }
    //JavaScript
    $myJS = expCore::resolveFilePaths("guess", $smarty->getTemplateVars('__name'), "js", $smarty->getTemplateVars('__view') . "*");
    if ($myJS != false) {
        foreach ($myJS as $myJSFile) {
            echo "<script type='text/javascript' src='" . expCore::abs2rel($myJSFile) . "'></script>\n";
        }
    }
    $html = ob_get_contents();
    ob_end_clean();
    return $html . $compiledsource;
}