diff --git a/system/config/system.yaml b/system/config/system.yaml index 365a669c8..29596616d 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -5,6 +5,10 @@ param_sep: ':' # Parameter separator, use ';' for Apache home: alias: '/home' # Default path for home, ie / +languages: + en: English + fr: French + pages: theme: antimatter # Default theme (defaults to "antimatter" theme) order: @@ -32,7 +36,7 @@ pages: '<': 'lt' types: 'txt|xml|html|json|rss|atom' # Pipe separated list of valid page types expires: 0 # Page expires time in seconds (604800 seconds = 7 days) - last_modified: false # Set the last modified date header based on file modification timestamp + last_modified: false # Set the last modified date header based on file modifcation timestamp etag: false # Set the etag header tag cache: @@ -79,7 +83,7 @@ images: debug: false # Show an overlay over images indicating the pixel depth of the image when working with retina for example media: - enable_media_timestamp: false # Enable media timestamps + enable_media_timestamp: false # Enable media timetsamps upload_limit: 0 # Set maximum upload size in bytes (0 is unlimited) security: diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php index 8309bebff..3ca03a041 100644 --- a/system/src/Grav/Common/Filesystem/Folder.php +++ b/system/src/Grav/Common/Filesystem/Folder.php @@ -38,12 +38,12 @@ abstract class Folder * Recursively find the last modified time under given path by file. * * @param string $path + * @param string $extensions + * * @return int */ - public static function lastModifiedFile($path) + public static function lastModifiedFile($path, $extensions = 'md|yaml') { - // pipe separated list of extensions to search for changes with - $extensions = 'md|yaml'; $last_modified = 0; $dirItr = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 97082402b..7714834bf 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -55,6 +55,8 @@ class Grav extends Container $container['grav'] = $container; + + $container['debugger'] = new Debugger(); $container['debugger']->startTimer('_init', 'Initialize'); @@ -88,12 +90,16 @@ class Grav extends Container $container['taxonomy'] = function ($c) { return new Taxonomy($c); }; + $container['language'] = function ($c) { + return new Language($c); + }; + $container['pages'] = function ($c) { return new Page\Pages($c); }; - $container['assets'] = function ($c) { - return new Assets(); - }; + + $container['assets'] = new Assets(); + $container['page'] = function ($c) { /** @var Pages $pages */ $pages = $c['pages']; diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php new file mode 100644 index 000000000..a8856be35 --- /dev/null +++ b/system/src/Grav/Common/Language.php @@ -0,0 +1,58 @@ +languages = $grav['config']->get('system.languages', []); + $this->default_key = key($this->languages); + $this->default_lang = reset($this->languages); + + } + + public function setLanguage($key) + { + if (array_key_exists($key, $this->languages)) { + $this->active_key = $key; + $this->active_lang = $this->languages[$key]; + return true; + } + return false; + } + + public function getAvailableKeys() + { + return implode('|', array_keys($this->languages)); + } + + public function getDefaultKey() + { + return $this->default_key; + } + + public function getDefaultLanguage() + { + return $this->default_lang; + } + + public function getActiveKey() + { + return $this->active_key; + } + + public function getActiveLanguage() + { + return $this->active_lang; + } + +} diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index dd70501f3..9b552bafa 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -6,6 +6,7 @@ use Grav\Common\Config\Config; use Grav\Common\Utils; use Grav\Common\Cache; use Grav\Common\Taxonomy; +use Grav\Common\Language; use Grav\Common\Data\Blueprint; use Grav\Common\Data\Blueprints; use Grav\Common\Filesystem\Folder; @@ -61,6 +62,10 @@ class Pages */ protected $last_modified; + + protected $default_lang; + protected $page_extension; + /** * @var Types */ @@ -75,6 +80,8 @@ class Pages { $this->grav = $c; $this->base = ''; + $this->default_lang = $c['language']->getDefaultKey(); + $this->page_extension = '.' . $this->default_lang ? $this->default_lang . CONTENT_EXT : CONTENT_EXT; } /** @@ -572,7 +579,7 @@ class Pages $last_modified = $modified; } - if (preg_match('/^[^.].*'.CONTENT_EXT.'$/', $name)) { + if (preg_match('/^[^.].*'.$this->page_extension.'$/', $name)) { $page->init($file); $content_exists = true; diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 55e1ad806..1bfd73f96 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -73,6 +73,7 @@ class Uri public function init() { $config = Grav::instance()['config']; + $language = Grav::instance()['language']; // resets $this->paths = []; @@ -86,6 +87,13 @@ class Uri // process params $uri = $this->processParams($uri, $config->get('system.param_sep')); + $regex = '/(\/(?:'.$language->getAvailablekeys().')\/).*/'; + + if (preg_match($regex, $uri, $matches)) { + $uri = preg_replace("/\\".$matches[1]."/", '', $matches[0], 1); + $lang = $matches[2]; + } + // split the URL and params $bits = parse_url($uri);