Пример #1
0
 /**
  * Get theme or throw exception if it cannot be found.
  *
  * @param string $name
  * @return Data
  * @throws \RuntimeException
  */
 public function get($name)
 {
     if (!$name) {
         throw new \RuntimeException('Theme name not provided.');
     }
     $blueprints = new Blueprints("theme:///{$name}");
     $blueprint = $blueprints->get('blueprints');
     $blueprint->name = $name;
     /** @var Config $config */
     $config = $this->grav['config'];
     // Find thumbnail.
     $thumb = "theme:///{$name}/thumbnail.jpg";
     if (file_exists($thumb)) {
         $blueprint->set('thumbnail', $config->get('system.base_url_relative') . "/user/themes/{$name}/thumbnail.jpg");
     }
     // Load default configuration.
     $file = Yaml::instance("theme:///{$name}/{$name}.yaml");
     $obj = new Data($file->content(), $blueprint);
     // Override with user configuration.
     $file = Yaml::instance("user://config/themes/{$name}.yaml");
     $obj->merge($file->content());
     // Save configuration always to user/config.
     $obj->file($file);
     return $obj;
 }
 /**
  * Extend page blueprints with textformatter configuration options.
  *
  * @param Event $event
  */
 public function onBlueprintCreated(Event $event)
 {
     /** @var Blueprints $blueprint */
     $blueprint = $event['blueprint'];
     if ($blueprint->get('form.fields.tabs')) {
         $blueprints = new Blueprints(__DIR__ . '/blueprints/');
         $extends = $blueprints->get($this->name);
         $blueprint->extend($extends, true);
     }
 }
Пример #3
0
 /**
  * Extend page blueprints with feed configuration options.
  *
  * @param Event $event
  */
 public function onBlueprintCreated(Event $event)
 {
     static $inEvent = false;
     /** @var Data\Blueprint $blueprint */
     $blueprint = $event['blueprint'];
     if (!$inEvent && $blueprint->get('form.fields.tabs')) {
         $inEvent = true;
         $blueprints = new Data\Blueprints(__DIR__ . '/blueprints/');
         $extends = $blueprints->get('smartypants');
         $blueprint->extend($extends, true);
         $inEvent = false;
     }
 }
Пример #4
0
 /**
  * @param Event $event
  */
 public function onBlueprintCreated(Event $event)
 {
     static $inEvent = false;
     /** @var \Grav\Common\Data\Blueprint $blueprint */
     $blueprint = $event['blueprint'];
     if (false === $inEvent and $blueprint->get('form.fields.tabs')) {
         $inEvent = true;
         $blueprints = new Blueprints(__DIR__ . '/blueprints/');
         $extends = $blueprints->get('simple_form');
         $blueprint->extend($extends, true);
         $inEvent = false;
     }
 }
Пример #5
0
 /**
  * Load user account.
  *
  * Always creates user object. To check if user exists, use $this->exists().
  *
  * @param string $username
  * @return User
  */
 public static function load($username)
 {
     // FIXME: validate directory name
     $blueprints = new Blueprints('blueprints://user');
     $blueprint = $blueprints->get('account');
     $file = CompiledYamlFile::instance(ACCOUNTS_DIR . $username . YAML_EXT);
     $content = $file->content();
     if (!isset($content['username'])) {
         $content['username'] = $username;
     }
     $user = new User($content, $blueprint);
     $user->file($file);
     return $user;
 }
Пример #6
0
 /**
  * Load user account.
  *
  * Always creates user object. To check if user exists, use $this->exists().
  *
  * @param string $username
  * @return User
  */
 public static function load($username)
 {
     $locator = self::getGrav()['locator'];
     $blueprints = new Blueprints('blueprints://');
     $blueprint = $blueprints->get('user/account');
     $file_path = $locator->findResource('account://' . $username . YAML_EXT);
     $file = CompiledYamlFile::instance($file_path);
     $content = $file->content();
     if (!isset($content['username'])) {
         $content['username'] = $username;
     }
     $user = new User($content, $blueprint);
     $user->file($file);
     return $user;
 }
Пример #7
0
 /**
  * Returns blueprints for the given type.
  *
  * @param string $type
  *
  * @return Data\Blueprint
  */
 public function blueprints($type)
 {
     if ($this->blueprints === null) {
         $this->blueprints = new Data\Blueprints('blueprints://');
     }
     return $this->blueprints->get($type);
 }
Пример #8
0
 /**
  * Returns blueprints for the given type.
  *
  * @param string $type
  * @return Data\Blueprint
  */
 public function blueprints($type)
 {
     if ($this->blueprints === null) {
         $this->blueprints = new Data\Blueprints($this->grav['locator']->findResource('blueprints://'));
     }
     return $this->blueprints->get($type);
 }
Пример #9
0
 /**
  * Get theme configuration or throw exception if it cannot be found.
  *
  * @param  string            $name
  * @return Data
  * @throws \RuntimeException
  */
 public function get($name)
 {
     if (!$name) {
         throw new \RuntimeException('Theme name not provided.');
     }
     $blueprints = new Blueprints("themes://{$name}");
     $blueprint = $blueprints->get('blueprints');
     $blueprint->name = $name;
     // Find thumbnail.
     $thumb = "themes://{$name}/thumbnail.jpg";
     if (file_exists($thumb)) {
         $blueprint->set('thumbnail', $this->grav['base_url'] . "/user/themes/{$name}/thumbnail.jpg");
     }
     // Load default configuration.
     $file = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT);
     $obj = new Data($file->content(), $blueprint);
     // Override with user configuration.
     $file = CompiledYamlFile::instance("user://config/themes/{$name}" . YAML_EXT);
     $obj->merge($file->content());
     // Save configuration always to user/config.
     $obj->file($file);
     return $obj;
 }
Пример #10
0
 /**
  * Get theme configuration or throw exception if it cannot be found.
  *
  * @param  string            $name
  * @return Data
  * @throws \RuntimeException
  */
 public function get($name)
 {
     if (!$name) {
         throw new \RuntimeException('Theme name not provided.');
     }
     $blueprints = new Blueprints('themes://');
     $blueprint = $blueprints->get("{$name}/blueprints");
     $blueprint->name = $name;
     // Find thumbnail.
     $thumb = "themes://{$name}/thumbnail.jpg";
     if ($path = $this->grav['locator']->findResource($thumb, false)) {
         $blueprint->set('thumbnail', $this->grav['base_url'] . '/' . $path);
     }
     // Load default configuration.
     $file = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT);
     $obj = new Data($file->content(), $blueprint);
     // Override with user configuration.
     $obj->merge($this->grav['config']->get('themes.' . $name) ?: []);
     // Save configuration always to user/config.
     $file = CompiledYamlFile::instance("config://themes/{$name}" . YAML_EXT);
     $obj->file($file);
     return $obj;
 }
Пример #11
0
 /**
  * Load user account.
  *
  * Always creates user object. To check if user exists, use $this->exists().
  *
  * @param string $username
  *
  * @return User
  */
 public static function load($username)
 {
     $grav = Grav::instance();
     $locator = $grav['locator'];
     $config = $grav['config'];
     // force lowercase of username
     $username = strtolower($username);
     $blueprints = new Blueprints();
     $blueprint = $blueprints->get('user/account');
     $file_path = $locator->findResource('account://' . $username . YAML_EXT);
     $file = CompiledYamlFile::instance($file_path);
     $content = $file->content();
     if (!isset($content['username'])) {
         $content['username'] = $username;
     }
     if (!isset($content['state'])) {
         $content['state'] = 'enabled';
     }
     $user = new User($content, $blueprint);
     $user->file($file);
     // add user to config
     $config->set("user", $user);
     return $user;
 }
Пример #12
0
 /**
  * Get a blueprint for a page type.
  *
  * @param  string  $type
  * @return Blueprint
  */
 public function blueprints($type)
 {
     if (!isset($this->blueprints)) {
         $this->blueprints = new Blueprints(self::getTypes());
     }
     try {
         $blueprint = $this->blueprints->get($type);
     } catch (\RuntimeException $e) {
         $blueprint = $this->blueprints->get('default');
     }
     if (!$blueprint->initialized) {
         $this->grav->fireEvent('onBlueprintCreated', new Event(['blueprint' => $blueprint]));
         $blueprint->initialized = true;
     }
     return $blueprint;
 }
Пример #13
0
 public static function get($name)
 {
     $blueprints = new Blueprints('plugins://');
     $blueprint = $blueprints->get("{$name}/blueprints");
     $blueprint->name = $name;
     // Load default configuration.
     $file = CompiledYamlFile::instance("plugins://{$name}/{$name}.yaml");
     // ensure the plugin exists physically
     if (!$file->exists()) {
         return null;
     }
     $obj = new Data($file->content(), $blueprint);
     // Override with user configuration.
     $obj->merge(self::getGrav()['config']->get('plugins.' . $name) ?: []);
     // Save configuration always to user/config.
     $file = CompiledYamlFile::instance("config://plugins/{$name}.yaml");
     $obj->file($file);
     return $obj;
 }
Пример #14
0
 /**
  * Extend page blueprints "with mathjax.process" configuration options.
  *
  * @param Event $event
  */
 public function onBlueprintCreated(Event $event)
 {
     $blueprint = $event['blueprint'];
     if ($blueprint->get('form.fields.tabs')) {
         $blueprints = new Data\Blueprints(__DIR__ . '/blueprints/');
         $extends = $blueprints->get('mathjax');
         $blueprint->extend($extends, true);
     }
 }
Пример #15
0
 /**
  * Remove a group
  *
  * @param string $groupname
  *
  * @return bool True if the action was performed
  */
 public static function remove($groupname)
 {
     $blueprints = new Blueprints('blueprints://');
     $blueprint = $blueprints->get('user/group');
     $groups = self::getGrav()['config']->get("groups");
     unset($groups[$groupname]);
     self::getGrav()['config']->set("groups", $groups);
     $type = 'groups';
     $obj = new Data(self::getGrav()['config']->get($type), $blueprint);
     $file = CompiledYamlFile::instance(self::getGrav()['locator']->findResource("config://{$type}.yaml"));
     $obj->file($file);
     $obj->save();
     return true;
 }
Пример #16
0
 /**
  * Get extra items which haven't been defined in blueprints.
  *
  * @return array
  */
 public function extra()
 {
     return $this->blueprints ? $this->blueprints->extra($this->items) : array();
 }
Пример #17
0
 /**
  * Get available page types.
  *
  * @return array
  */
 public static function types()
 {
     $grav = Grav::instance();
     /** @var Config $config */
     $config = $grav['config'];
     $blueprints = new Data\Blueprints(THEMES_DIR . $config->get('system.pages.theme') . '/blueprints/');
     return $blueprints->types();
 }
Пример #18
0
 /**
  * Extend page blueprints with feed configuration options.
  *
  * @param Event $event
  */
 public function onBlueprintCreated(Event $event)
 {
     static $inEvent = false;
     /** @var Data\Blueprint $blueprint */
     $blueprint = $event['blueprint'];
     if (!$inEvent && $blueprint->name == 'blog_list') {
         $inEvent = true;
         $blueprints = new Data\Blueprints(__DIR__ . '/blueprints/');
         $extends = $blueprints->get('feed');
         $blueprint->extend($extends, true);
         $inEvent = false;
     }
 }
Пример #19
0
 /**
  * Initialize object by loading all the configuration files.
  *
  * @param array $files
  */
 protected function init(array $files)
 {
     $this->updated = true;
     // Combine all configuration files into one larger lookup table (only keys matter).
     $allFiles = $files['user'] + $files['plugins'] + $files['system'];
     // Then sort the files to have all parent nodes first.
     // This is to make sure that child nodes override parents content.
     uksort($allFiles, function ($a, $b) {
         $diff = substr_count($a, '/') - substr_count($b, '/');
         return $diff ? $diff : strcmp($a, $b);
     });
     $systemBlueprints = new Blueprints(SYSTEM_DIR . 'blueprints');
     $pluginBlueprints = new Blueprints(USER_DIR);
     $items = array();
     foreach ($allFiles as $name => $dummy) {
         $lookup = array('system' => SYSTEM_DIR . 'config/' . $name . YAML_EXT, 'plugins' => USER_DIR . $name . '/' . basename($name) . YAML_EXT, 'user' => USER_DIR . 'config/' . $name . YAML_EXT);
         if (strpos($name, 'plugins/') === 0) {
             $blueprint = $pluginBlueprints->get("{$name}/blueprints");
         } else {
             $blueprint = $systemBlueprints->get($name);
         }
         $data = new Data(array(), $blueprint);
         foreach ($lookup as $key => $path) {
             if (is_file($path)) {
                 $data->merge(File\Yaml::instance($path)->content());
             }
         }
         //            $data->validate();
         //            $data->filter();
         // Find the current sub-tree location.
         $current =& $items;
         $parts = explode('/', $name);
         foreach ($parts as $part) {
             if (!isset($current[$part])) {
                 $current[$part] = array();
             }
             $current =& $current[$part];
         }
         // Handle both updated and deleted configuration files.
         $current = $data->toArray();
     }
     $this->items = $items;
     $this->files = $files;
 }
Пример #20
0
 public static function get($type)
 {
     $blueprints = new Data\Blueprints('plugin://' . $type);
     $blueprint = $blueprints->get('blueprints');
     $blueprint->name = $type;
     // Load default configuration.
     $file = File\Yaml::instance('plugin://' . "{$type}/{$type}" . YAML_EXT);
     $obj = new Data\Data($file->content(), $blueprint);
     // Override with user configuration.
     $file = File\Yaml::instance('plugin://' . "config/plugins/{$type}" . YAML_EXT);
     $obj->merge($file->content());
     // Save configuration always to user/config.
     $obj->file($file);
     return $obj;
 }
Пример #21
0
 public static function get($name)
 {
     $blueprints = new Blueprints("plugins://{$name}");
     $blueprint = $blueprints->get('blueprints');
     $blueprint->name = $name;
     // Load default configuration.
     $file = CompiledYamlFile::instance("plugins://{$name}/{$name}.yaml");
     $obj = new Data($file->content(), $blueprint);
     // Override with user configuration.
     $file = CompiledYamlFile::instance("user://config/plugins/{$name}.yaml");
     $obj->merge($file->content());
     // Save configuration always to user/config.
     $obj->file($file);
     return $obj;
 }