Exemple #1
0
/**
 * Macro definition block for Smarty.
 */
function smarty_block_defmacro($params, $content, &$smarty, &$repeat)
{
    if (isset($content)) {
        ## create a file to store the macro
        if ($params['name'] == '') {
            $smarty->trigger_error("defmacro: unspecified attribute 'name' for the macro");
            return;
        }
        $fileName = $smarty->getCurrentTemplate();
        $templateNameString = str_replace(PathManager::templateDir(), '', $fileName);
        $templateNameString = str_replace('/', ',', $templateNameString);
        $templateNameString .= ',' . $params['name'] . '.tpl';
        # now copy $content to file $templateNameString
        $fullPath = PathManager::smartyMacroTemplateDir() . $templateNameString;
        if (!file_exists($fullPath)) {
            $handle = fopen($fullPath, "w");
            fwrite($handle, $content);
            fclose($handle);
        }
        ## ok, now register the macro
        $smarty->registerMacro($params['name'], $templateNameString);
        ##echo $templateNameString;
        return '';
    }
}
Exemple #2
0
 public static function init()
 {
     // create db connection
     // see if tmp directories exist - and create if not
     $dir = PathManager::smartyCompileDir();
     if (!file_exists($dir)) {
         mkdirfull($dir);
     }
     $dir = PathManager::smartyCacheDir();
     if (!file_exists($dir)) {
         mkdirfull($dir);
     }
     $dir = PathManager::smartyMacroTemplateDir();
     if (!file_exists($dir)) {
         mkdirfull($dir);
     }
     // connect to memcache server
     if (GlobalProperties::$USE_MEMCACHE == true) {
         self::$memcache = new Memcache();
         self::$memcache->connect(GlobalProperties::$MEMCACHE_HOST, GlobalProperties::$MEMCACHE_PORT);
         self::$memcache->setCompressThreshold(5000);
     } else {
         self::$memcache = new DummyMemcache();
     }
 }
Exemple #3
0
/**
 * Macro calling method for Smarty.
 */
function smarty_function_macro($params, &$smarty)
{
    if ($params['name'] == '') {
        $smarty->trigger_error("macro: missing attribute 'name' for the macro");
        return;
    }
    ## get macro file name
    $templateFilename = $smarty->getMacroTemplateFileName($params['name']);
    if ($templateFilename == null) {
        $smarty->trigger_error("macro: template file for the macro missing");
        return;
    }
    // get new smarty instance to process the template:
    $subSmarty = Ozone::getSmartyPlain();
    unset($params['name']);
    $subSmarty->assign('params', $params);
    foreach ($params as $key => $value) {
        $subSmarty->assign($key, $value);
    }
    ## copy the macro register
    $subSmarty->setMacroRegister($smarty->getMacroRegister());
    #render the content
    $out = $subSmarty->fetch(PathManager::smartyMacroTemplateDir() . "/" . $templateFilename);
    return $out;
}