[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/phpbb/template/twig/node/ -> event.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\template\twig\node;
  15  
  16  class event extends \Twig\Node\Node
  17  {
  18      /**
  19      * The subdirectory in which all template listener files must be placed
  20      * @var string
  21      */
  22      protected $listener_directory = 'event/';
  23  
  24      /** @var \Twig\Environment */
  25      protected $environment;
  26  
  27  	public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null)
  28      {
  29          $this->environment = $environment;
  30  
  31          parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
  32      }
  33  
  34      /**
  35      * Compiles the node to PHP.
  36      *
  37      * @param \Twig\Compiler A Twig\Compiler instance
  38      */
  39  	public function compile(\Twig\Compiler $compiler)
  40      {
  41          $compiler->addDebugInfo($this);
  42  
  43          $location = $this->listener_directory . $this->getNode('expr')->getAttribute('name');
  44  
  45          foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path)
  46          {
  47              $ext_namespace = str_replace('/', '_', $ext_namespace);
  48  
  49              if ($this->environment->isDebug())
  50              {
  51                  // If debug mode is enabled, lets check for new/removed EVENT
  52                  //  templates on page load rather than at compile. This is
  53                  //  slower, but makes developing extensions easier (no need to
  54                  //  purge the cache when a new event template file is added)
  55                  $compiler
  56                      ->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n")
  57                      ->indent()
  58                  ;
  59              }
  60  
  61              if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html'))
  62              {
  63                  $compiler
  64                      ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
  65  
  66                      // We set the namespace lookup order to be this extension first, then the main path
  67                      ->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n")
  68                      ->write("\$this->env->loadTemplate('@{$ext_namespace}/{$location}.html')->display(\$context);\n")
  69                      ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")
  70                  ;
  71              }
  72  
  73              if ($this->environment->isDebug())
  74              {
  75                  $compiler
  76                      ->outdent()
  77                      ->write("}\n\n")
  78                  ;
  79              }
  80          }
  81      }
  82  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1