Example #1
0
 /**
  * Constructor
  *
  * @param string $id   The ID of the initializer
  * @param array  $data The configuration key/value pairs
  */
 public function __construct($id, $data)
 {
     parent::__construct($id, $data);
     $this->objectRegistry = Baobab::objectRegistry();
     $this->loadPsr4();
     Hooks::action('after_setup_theme', $this, 'instantiateClasses');
 }
Example #2
0
 /**
  * Hidden constructor. Use Configuration::setup
  *
  * @param array $mapping The mapping between configuration files and classes.
  *
  * @throws ConfigurationNotFoundException
  */
 protected function __construct($mapping)
 {
     // Supported parsers for configuration files
     $parsers = array('config.php' => new PhpParser());
     // Parse each file
     $configRoot = Paths::configuration();
     $env = Baobab::environment();
     foreach ($mapping as $file => $className) {
         $fileLoaded = false;
         $data = array();
         $pathStack = array($configRoot . '/' . $env . '/' . $file, $configRoot . '/' . $file);
         foreach ($pathStack as $fullPath) {
             $tempData = null;
             /** @var \Baobab\Configuration\Parser\Parser $parser */
             foreach ($parsers as $ext => $parser) {
                 if (file_exists($fullPath . '.' . $ext)) {
                     $fileLoaded = true;
                     $tempData = $parser->parse($fullPath);
                     break;
                 }
             }
             if ($tempData != null) {
                 $data = array_merge($tempData, $data);
             }
         }
         if ($fileLoaded) {
             $this->initializers[$file] = new $className($file, $data);
             // Provide some hooks
             do_action('baobab/configuration/file-loaded?file=' . $file);
         }
     }
 }
Example #3
0
 /**
  * Gather some variables from the child class
  */
 protected function loadStaticChildClassMembers()
 {
     if (is_null(static::$classLoader)) {
         throw new ThemeDeclarationException('You must specify a class loader in your child theme class');
     }
     Baobab::setObjectRegistry(new ObjectRegistry(static::$classLoader));
 }
Example #4
0
 private function setupAjax()
 {
     $data = $this->getData();
     $namespace = isset($data['ajax_namespace']) ? $data['ajax_namespace'] : Strings::sanitizeJsVarName($data['text_domain']);
     $ajax = new Ajax($namespace);
     Baobab::setAjax($ajax);
 }
Example #5
0
 /**
  * For themes properly structured, we can find the search form template at
  * app/views/parts/misc/search-form.php. We'll also try a blade template if possible. In order, the templates which
  * will be tried will be:
  *
  * /my-theme/app/views/parts/misc/search-form.blade.php
  * /my-theme/app/views/parts/search-form.blade.php
  * /my-theme/app/views/parts/misc/search-form.php
  * /my-theme/app/views/parts/search-form.php
  * /my-theme/searchform.php
  *
  * @param $form The search form
  *
  * @return string
  */
 public function suggestMoreSearchFormTemplates($form)
 {
     ob_start();
     // Try a blade template first and if not found, try standard PHP templates
     $template = Views::pickView(array('parts.misc.search-form', 'parts.search-form'));
     if ($template != null) {
         Views::render(Baobab::blade()->view()->make($template));
     } else {
         locate_template(array('/app/views/parts/misc/search-form.php', '/app/views/parts/search-form.php', 'searchform.php'), true, false);
     }
     $form = ob_get_clean();
     return $form;
 }
Example #6
0
 /**
  * Check that we have proper nonce value in our form data
  */
 public static function checkAjaxReferrer()
 {
     Baobab::ajax()->checkAjaxReferrer(static::$ACTION);
 }
Example #7
0
 /**
  * Display the 404 page
  *
  * @return View The view to be shown to the user
  */
 public function error404()
 {
     return Baobab::blade()->view()->make('templates.404');
 }