/** * 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; }
/** * 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; }
/** * 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; }
/** * Gets configuration data. * * @param string $type * @param array $post * @return Data\Data|null * @throws \RuntimeException */ public function data($type, $post = array()) { static $data = []; if (isset($data[$type])) { return $data[$type]; } if (!$post) { $post = isset($_POST) ? $_POST : []; } switch ($type) { case 'configuration': case 'system': $type = 'system'; $blueprints = $this->blueprints("config/{$type}"); $config = $this->grav['config']; $obj = new Data\Data($config->get('system'), $blueprints); $obj->merge($post); $file = CompiledYamlFile::instance($this->grav['locator']->findResource("config://{$type}.yaml")); $obj->file($file); $data[$type] = $obj; break; case 'settings': case 'site': $type = 'site'; $blueprints = $this->blueprints("config/{$type}"); $config = $this->grav['config']; $obj = new Data\Data($config->get('site'), $blueprints); $obj->merge($post); $file = CompiledYamlFile::instance($this->grav['locator']->findResource("config://{$type}.yaml")); $obj->file($file); $data[$type] = $obj; break; case 'login': $data[$type] = null; break; default: /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; $filename = $locator->findResource("config://{$type}.yaml", true, true); $file = CompiledYamlFile::instance($filename); if (preg_match('|plugins/|', $type)) { /** @var Plugins $plugins */ $plugins = $this->grav['plugins']; $obj = $plugins->get(preg_replace('|plugins/|', '', $type)); $obj->merge($post); $obj->file($file); $data[$type] = $obj; } elseif (preg_match('|themes/|', $type)) { /** @var Themes $themes */ $themes = $this->grav['themes']; $obj = $themes->get(preg_replace('|themes/|', '', $type)); $obj->merge($post); $obj->file($file); $data[$type] = $obj; } elseif (preg_match('|users/|', $type)) { $obj = User::load(preg_replace('|users/|', '', $type)); $obj->merge($post); $data[$type] = $obj; } else { throw new \RuntimeException("Data type '{$type}' doesn't exist!"); } } return $data[$type]; }
/** * Toggle the gpm.releases setting */ protected function taskGpmRelease() { if (!$this->authorizeTask('configuration', ['admin.configuration', 'admin.super'])) { return false; } // Default release state $release = 'stable'; $reload = false; // Get the testing release value if set if ($this->post['release'] == 'testing') { $release = 'testing'; } $config = $this->grav['config']; $current_release = $config->get('system.gpm.releases'); // If the releases setting is different, save it in the system config if ($current_release != $release) { $data = new Data\Data($config->get('system')); $data->set('gpm.releases', $release); // Get the file location $file = CompiledYamlFile::instance($this->grav['locator']->findResource("config://system.yaml")); $data->file($file); // Save the configuration $data->save(); $config->reload(); $reload = true; } $this->admin->json_response = ['status' => 'success', 'reload' => $reload]; return true; }
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; }
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; }
/** * Gets configuration data. * * @param string $type * @param array $post * * @return mixed * @throws \RuntimeException */ public function data($type, array $post = []) { static $data = []; if (isset($data[$type])) { return $data[$type]; } if (!$post) { $post = isset($_POST['data']) ? $_POST['data'] : []; } // Check to see if a data type is plugin-provided, before looking into core ones $event = $this->grav->fireEvent('onAdminData', new Event(['type' => &$type])); if ($event && isset($event['data_type'])) { return $event['data_type']; } /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; $filename = $locator->findResource("config://{$type}.yaml", true, true); $file = CompiledYamlFile::instance($filename); if (preg_match('|plugins/|', $type)) { /** @var Plugins $plugins */ $plugins = $this->grav['plugins']; $obj = $plugins->get(preg_replace('|plugins/|', '', $type)); if (!$obj) { return []; } $obj->merge($post); $obj->file($file); $data[$type] = $obj; } elseif (preg_match('|themes/|', $type)) { /** @var Themes $themes */ $themes = $this->grav['themes']; $obj = $themes->get(preg_replace('|themes/|', '', $type)); if (!$obj) { return []; } $obj->merge($post); $obj->file($file); $data[$type] = $obj; } elseif (preg_match('|users/|', $type)) { $obj = User::load(preg_replace('|users/|', '', $type)); $obj->merge($post); $data[$type] = $obj; } elseif (preg_match('|user/|', $type)) { $obj = User::load(preg_replace('|user/|', '', $type)); $obj->merge($post); $data[$type] = $obj; } elseif (preg_match('|config/|', $type)) { $type = preg_replace('|config/|', '', $type); $blueprints = $this->blueprints("config/{$type}"); $config = $this->grav['config']; $obj = new Data\Data($config->get($type, []), $blueprints); $obj->merge($post); // FIXME: We shouldn't allow user to change configuration files in system folder! $filename = $this->grav['locator']->findResource("config://{$type}.yaml") ?: $this->grav['locator']->findResource("config://{$type}.yaml", true, true); $file = CompiledYamlFile::instance($filename); $obj->file($file); $data[$type] = $obj; } else { throw new \RuntimeException("Data type '{$type}' doesn't exist!"); } return $data[$type]; }
/** * 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; // Load default configuration. $file = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT); // ensure this is a valid theme if (!$file->exists()) { return null; } // Find thumbnail. $thumb = "themes://{$name}/thumbnail.jpg"; $path = $this->grav['locator']->findResource($thumb, false); if ($path) { $blueprint->set('thumbnail', $this->grav['base_url'] . '/' . $path); } $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; }
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; }