コード例 #1
0
/**
 * @author Matt Basta
 * @param string[]           $params   parameters
 * @param \Box\Brainy\Brainy $compiler template object
 * @return string
 */
function smarty_compiler_storeclose($params, $compiler)
{
    if (count($compiler->_tag_stack) === 0) {
        $compiler->trigger_template_error('unexpected closing tag', $compiler->lex->taglineno);
    }
    // get stacked info
    list($openTag, $to) = array_pop($compiler->_tag_stack);
    if ($openTag !== 'store') {
        $compiler->trigger_template_error('Got {/' . $openTag . '}, but expected {/store}', $compiler->lex->taglineno);
    }
    return "\$_smarty_tpl->tpl_vars['smarty']['ls_loadables'][{$to}] = ob_get_clean();\n";
}
コード例 #2
0
ファイル: PluginLoader.php プロジェクト: jeantimex/brainy
 /**
  * Loads a plugin
  * @param  string             $type   The type of the plugin
  * @param  string             $name   The plugin name
  * @param  \Box\Brainy\Brainy $brainy The instance of Brainy to load it for
  * @return bool Whether the plugin was loaded successfully
  */
 public static function loadPlugin($type, $name, $brainy)
 {
     $function = self::getPluginFunction($type, $name);
     if (is_callable($function)) {
         return true;
     }
     $filename = self::getPluginFilename($type, $name);
     $pluginDirs = $brainy->getPluginsDir();
     foreach ($pluginDirs as $dir) {
         $ffile = $dir . $filename;
         if (!file_exists($ffile)) {
             continue;
         }
         include $ffile;
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: BatchUtil.php プロジェクト: xiaobudongzhang/brainy
 /**
  * Delete compiled template file
  *
  * @param  string  $resource_name template name
  * @param  string  $compile_id    compile id
  * @param  integer $exp_time      expiration time
  * @param  \Box\Brainy\Brainy  $smarty        \Box\Brainy\Brainy instance
  * @return integer number of template files deleted
  */
 public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, \Box\Brainy\Brainy $smarty)
 {
     $_compile_dir = realpath($smarty->getCompileDir()) . '/';
     $_compile_id = isset($compile_id) ? preg_replace('![^\\w\\|]+!', '_', $compile_id) : null;
     $_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
     if (isset($resource_name)) {
         $tpl = new \Box\Brainy\Templates\Template($resource_name, $smarty);
         // remove from template cache
         $tpl->source;
         // have the template registered before unset()
         $_templateId = $tpl->source->unique_resource . $tpl->compile_id;
         if (isset($_templateId[150])) {
             $_templateId = sha1($_templateId);
         }
         unset($smarty->template_objects[$_templateId]);
         if ($tpl->source->exists) {
             $_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
             $_resource_part_1_length = strlen($_resource_part_1);
         } else {
             return 0;
         }
     }
     $_dir = $_compile_dir;
     if ($smarty->use_sub_dirs && isset($_compile_id)) {
         $_dir .= $_compile_id . $_dir_sep;
     }
     if (isset($_compile_id)) {
         $_compile_id_part = str_replace('\\', '/', $_compile_dir . $_compile_id . $_dir_sep);
         $_compile_id_part_length = strlen($_compile_id_part);
     }
     $_count = 0;
     try {
         $_compileDirs = new \RecursiveDirectoryIterator($_dir);
     } catch (\UnexpectedValueException $e) {
         // NOTE: UnexpectedValueException thrown for PHP >= 5.3
         return 0;
     }
     $_compile = new \RecursiveIteratorIterator($_compileDirs, \RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($_compile as $_file) {
         if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
             continue;
         }
         $_filepath = str_replace('\\', '/', (string) $_file);
         if ($_file->isDir()) {
             if (!$_compile->isDot()) {
                 // delete folder if empty
                 @rmdir($_file->getPathname());
             }
         } else {
             $unlink = false;
             if ((!isset($_compile_id) || isset($_filepath[$_compile_id_part_length]) && ($a = !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) && (!isset($resource_name) || isset($_filepath[$_resource_part_1_length]) && substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0)) {
                 if (isset($exp_time)) {
                     if (time() - @filemtime($_filepath) >= $exp_time) {
                         $unlink = true;
                     }
                 } else {
                     $unlink = true;
                 }
             }
             if ($unlink && @unlink($_filepath)) {
                 $_count++;
             }
         }
     }
     // clear compiled cache
     \Box\Brainy\Resources\Resource::$sources = array();
     \Box\Brainy\Resources\Resource::$compileds = array();
     return $_count;
 }