From c07afab981a00b97469c999404e89a9214224a8f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 23 Jun 2015 18:57:54 -0600 Subject: [PATCH 01/57] support arrays in `startsWith()` and `endsWith()` --- system/src/Grav/Common/Utils.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index ac1a2dcec..22ba7b7d0 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -19,6 +19,16 @@ abstract class Utils */ public static function startsWith($haystack, $needle) { + if (is_array($needle)) { + $status = false; + foreach ($needle as $each_needle) { + $status = $status || ($each_needle === '' || strpos($haystack, $each_needle) === 0); + if ($status) { + return $status; + } + } + return $status; + } return $needle === '' || strpos($haystack, $needle) === 0; } @@ -29,6 +39,16 @@ abstract class Utils */ public static function endsWith($haystack, $needle) { + if (is_array($needle)) { + $status = false; + foreach ($needle as $each_needle) { + $status = $status || ($each_needle === '' || substr($haystack, -strlen($each_needle)) === $each_needle); + if ($status) { + return $status; + } + } + return $status; + } return $needle === '' || substr($haystack, -strlen($needle)) === $needle; } From 49941105dcddef20a07090c0277adf28641b8afe Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 23 Jun 2015 18:58:24 -0600 Subject: [PATCH 02/57] Fix issue where page-based css and js were being downloaded rather than processed --- system/src/Grav/Common/Grav.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 806cbaa62..97082402b 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -126,7 +126,12 @@ class Grav extends Container } Utils::download($medium->path(), false); } else { - Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), true); + $download = true; + // little work-around to ensure .css and .js files are always sent inline not downloaded + if (Utils::endsWith($uri->basename(), ['.css', '.js'])) { + $download = false; + } + Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download); } } From adf758a5697921c63f1e1919b124fb8e3f08b60b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 25 Jun 2015 16:25:31 -0600 Subject: [PATCH 03/57] updated some config files --- system/config/site.yaml | 15 +++++++++------ system/config/system.yaml | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/system/config/site.yaml b/system/config/site.yaml index 72bc8027a..177a4e7bf 100644 --- a/system/config/site.yaml +++ b/system/config/site.yaml @@ -6,22 +6,25 @@ author: taxonomies: [category,tag] # Arbitrary list of taxonomy types -blog: - route: '/blog' # Route to blog (deprecated) - metadata: description: 'My Grav Site' # Site description summary: enabled: true # enable or disable summary of page - format: short # long = summary delimiter will be ignored; short = use the first occurence of delimter or size + format: short # long = summary delimiter will be ignored; short = use the first occurrence of delimiter or size size: 300 # Maximum length of summary (characters) delimiter: === # The summary delimiter +redirects: + /redirect-test: / # Redirect test goes to home page + /old/(.*): /new/$1 # Would redirect /old/my-page to /new/my-page + routes: /something/else: '/blog/sample-3' # Alias for /blog/sample-3 - /another/one/here: '/blog/sample-3' # Another alias for /blog/sample-3 - /new/*: '/blog/*' # Wildcard any /new/my-page URL to /blog/my-page Route + /new/(.*): '/blog/$1' # Regex any /new/my-page URL to /blog/my-page Route + +blog: + route: '/blog' # Custom value added (accessible via system.blog.route) #menu: # Sample Menu Example # - text: Source diff --git a/system/config/system.yaml b/system/config/system.yaml index 54a40419d..4d59ee364 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -60,7 +60,7 @@ assets: # Configuration for Assets Manager (JS, C css_rewrite: true # Rewrite any CSS relative URLs during pipelining js_pipeline: false # The JS pipeline is the unification of multiple JS resources into one file js_minify: true # Minify the JS during pipelining - enable_asset_timestamp: false # Enable asset timetsamps + enable_asset_timestamp: false # Enable asset timestamps collections: jquery: system://assets/jquery/jquery-2.1.3.min.js From 7e2fa8295afa95609a7f488d1eafa0fda05e9f6d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 25 Jun 2015 16:25:45 -0600 Subject: [PATCH 04/57] fixed ordering on a couple of filters --- system/src/Grav/Common/TwigExtension.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/TwigExtension.php b/system/src/Grav/Common/TwigExtension.php index c9d5f2289..742dc242b 100644 --- a/system/src/Grav/Common/TwigExtension.php +++ b/system/src/Grav/Common/TwigExtension.php @@ -349,14 +349,14 @@ class TwigExtension extends \Twig_Extension return $string; } - public function startsWithFilter($needle, $haystack) + public function startsWithFilter($haystack, $needle) { - return Utils::startsWith($needle, $haystack); + return Utils::startsWith($haystack, $needle); } - public function endsWithFilter($needle, $haystack) + public function endsWithFilter($haystack, $needle) { - return Utils::endsWith($needle, $haystack); + return Utils::endsWith($haystack, $needle); } /** From a98d01ba65cb82d192b912d606305dbc99b255dd Mon Sep 17 00:00:00 2001 From: Barry Anders Date: Fri, 26 Jun 2015 10:20:49 -0500 Subject: [PATCH 05/57] Spelling corrections. --- CHANGELOG.md | 16 ++++++++-------- system/config/system.yaml | 4 ++-- system/src/Grav/Common/Assets.php | 8 ++++---- system/src/Grav/Common/Cache.php | 2 +- system/src/Grav/Common/Data/DataMutatorTrait.php | 2 +- system/src/Grav/Common/GPM/GPM.php | 2 +- system/src/Grav/Common/GPM/Installer.php | 2 +- system/src/Grav/Common/GPM/Upgrader.php | 2 +- .../Grav/Common/Markdown/ParsedownGravTrait.php | 2 +- .../src/Grav/Common/Page/Medium/ImageMedium.php | 2 +- system/src/Grav/Common/Page/Medium/Medium.php | 2 +- .../Common/Page/Medium/ThumbnailImageMedium.php | 2 +- system/src/Grav/Common/Taxonomy.php | 2 +- system/src/Grav/Common/TwigExtension.php | 2 +- system/src/Grav/Common/Uri.php | 2 +- system/src/Grav/Common/User/User.php | 2 +- system/src/Grav/Common/Utils.php | 4 ++-- system/src/Grav/Console/Cli/SandboxCommand.php | 2 +- .../src/Grav/Console/Gpm/SelfupgradeCommand.php | 2 +- system/src/Grav/Console/Gpm/UpdateCommand.php | 2 +- 20 files changed, 32 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2aacd83b..112ea26a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ * Fix for `+` in image filenames * Fix for dot files causing issues with page processing * Fix for Uri path detection on Windows platform - * Fix for atlernative media resolutions + * Fix for alternative media resolutions * Fix for modularTypes key properties # v0.9.27 @@ -49,7 +49,7 @@ * Added a new `parseLinks` method to Plugins class * Added `starts_with` and `ends_with` Twig filters 2. [](#improved) - * Opitmized install of vendor libraries for speed improvement + * Optimized install of vendor libraries for speed improvement * Improved configuration handling in preparation for admin plugin * Cache optimization: Don't cache Twig templates when you pass dynamic params * Moved `Utils::rcopy` to `Folder::rcopy` @@ -63,7 +63,7 @@ * Fix for URLs with trailing slashes * Handle condition where certain errors resulted in blank page * Fix for issue with theme name equal to base_url and asset pipeline - * Fix to properly nomralize font rewrite path + * Fix to properly normalize font rewrite path * Fix for absolute URLs below the current page * Fix for `..` page references @@ -81,7 +81,7 @@ 2. [](#improved) * Refactored media image handling to make it more flexible and support absolute paths * Refactored page modification check process to make it faster - * User account improvements in preparation for Admin plugin + * User account improvements in preparation for admin plugin * Protect against timing attacks * Reset default system expires time to 0 seconds (can override if you need to) 3. [](#bugfix) @@ -209,7 +209,7 @@ * Improved the markdown Lightbox functionality to better mimic Twig version * Fullsize Lightbox can now have filters applied * Added a new `mergeConfig()` method to Plugin class to merge system + page header configuration - * Added a new `disable()` method to Plugin class to programatically disable a plugin + * Added a new `disable()` method to Plugin class to programmatically disable a plugin * Updated Parsedown and Parsedown Extra to address bugs * Various PSR fixes 3. [](#bugfix) @@ -262,7 +262,7 @@ * Added `publish_date` in page headers to automatically publish page * Added `unpublish_date` in page headers to automatically unpublish page * Added `dateRange()` capability for collections - * Added ability to dynamically control Cache lifetime programatically + * Added ability to dynamically control Cache lifetime programmatically * Added ability to sort by anything in the page header. E.g. `sort: header.taxonomy.year` * Added various helper methods to collections: `copy, nonVisible, modular, nonModular, published, nonPublished, nonRoutable` 2. [](#improved) @@ -437,7 +437,7 @@ * Broke cache types out into multiple directories in the cache folder * Removed vendor libs from github repository * Various PSR cleanup of code - * Various Blueprint updates to support upcoming Admin plugin + * Various Blueprint updates to support upcoming admin plugin * Added ability to filter page children for normal/modular/all * Added `sort_by_key` twig filter * Added `visible()` and `routable()` filters to page collections @@ -510,7 +510,7 @@ * Addition of Dependency Injection Container * Refactored plugins to use Symfony Event Dispatcher * New Asset Manager to provide unified management of JavaScript and CSS - * Asset Pipelining to provide unification, minify, and optimazation of JavaScript and CSS + * Asset Pipelining to provide unification, minify, and optimization of JavaScript and CSS * Grav Media support directly in Markdown syntax * Additional Grav Generator meta tag in default themes * Added support for PHP Stream Wrapper for resource location diff --git a/system/config/system.yaml b/system/config/system.yaml index 4d59ee364..365a669c8 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -32,7 +32,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 modifcation timestamp + last_modified: false # Set the last modified date header based on file modification timestamp etag: false # Set the etag header tag cache: @@ -79,7 +79,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 timetsamps + enable_media_timestamp: false # Enable media timestamps upload_limit: 0 # Set maximum upload size in bytes (0 is unlimited) security: diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 3662f7d98..4028fa7db 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -47,7 +47,7 @@ class Assets * Closure used by the pipeline to fetch assets. * * Useful when file_get_contents() function is not available in your PHP - * instalation or when you want to apply any kind of preprocessing to + * installation or when you want to apply any kind of preprocessing to * your assets before they get pipelined. * * The closure will receive as the only parameter a string with the path/URL of the asset and @@ -509,7 +509,7 @@ class Assets /** - * Minifiy and concatenate CSS / JS files. + * Minify and concatenate CSS / JS files. * * @return string */ @@ -741,7 +741,7 @@ class Assets /** * Determine whether a link is local or remote. * - * Undestands both "http://" and "https://" as well as protocol agnostic links "//" + * Understands both "http://" and "https://" as well as protocol agnostic links "//" * * @param string $link * @@ -920,7 +920,7 @@ class Assets * * @param string $directory * @param string $pattern (regex) - * @param string $ltrim Will be trimed from the left of the file path + * @param string $ltrim Will be trimmed from the left of the file path * * @return array */ diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index 4cddca65a..0aefc0727 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -271,7 +271,7 @@ class Cache extends Getters /** - * Set the cache lifetime programatically + * Set the cache lifetime programmatically * * @param int $future timestamp */ diff --git a/system/src/Grav/Common/Data/DataMutatorTrait.php b/system/src/Grav/Common/Data/DataMutatorTrait.php index c2110fe50..707b5078a 100644 --- a/system/src/Grav/Common/Data/DataMutatorTrait.php +++ b/system/src/Grav/Common/Data/DataMutatorTrait.php @@ -32,7 +32,7 @@ trait DataMutatorTrait } /** - * Sey value by using dot notation for nested arrays/objects. + * Set value by using dot notation for nested arrays/objects. * * @example $value = $data->set('this.is.my.nested.variable', true); * diff --git a/system/src/Grav/Common/GPM/GPM.php b/system/src/Grav/Common/GPM/GPM.php index c33d8cbb5..a6eefce5a 100644 --- a/system/src/Grav/Common/GPM/GPM.php +++ b/system/src/Grav/Common/GPM/GPM.php @@ -361,7 +361,7 @@ class GPM extends Iterator } if ($found = $this->findPackage($search)) { - // set override respository if provided + // set override repository if provided if ($repository) { $found->override_repository = $repository; } diff --git a/system/src/Grav/Common/GPM/Installer.php b/system/src/Grav/Common/GPM/Installer.php index b153f9c82..e2ebd0ed2 100644 --- a/system/src/Grav/Common/GPM/Installer.php +++ b/system/src/Grav/Common/GPM/Installer.php @@ -158,7 +158,7 @@ class Installer /** - * Unnstalls one or more given package + * Uninstalls one or more given package * * @param string $path The slug of the package(s) * @param array $options Options to use for uninstalling diff --git a/system/src/Grav/Common/GPM/Upgrader.php b/system/src/Grav/Common/GPM/Upgrader.php index 413665144..f9e3c0e81 100644 --- a/system/src/Grav/Common/GPM/Upgrader.php +++ b/system/src/Grav/Common/GPM/Upgrader.php @@ -65,7 +65,7 @@ class Upgrader * Returns the changelog list for each version of Grav * @param string $diff the version number to start the diff from * - * @return array return the chagenlog list for each version + * @return array return the changelog list for each version */ public function getChangelog($diff = null) { diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index dcf571564..8b0c4d144 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -23,7 +23,7 @@ trait ParsedownGravTrait protected $twig_link_regex = '/\!*\[(?:.*)\]\((\{([\{%#])\s*(.*?)\s*(?:\2|\})\})\)/'; /** - * Initialiazation function to setup key variables needed by the MarkdownGravLinkTrait + * Initialization function to setup key variables needed by the MarkdownGravLinkTrait * * @param $page * @param $defaults diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index bea2b10d6..f7cc644d3 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -216,7 +216,7 @@ class ImageMedium extends Medium } /** - * Turn the current Medium inta a Link with lightbox enabled + * Turn the current Medium into a Link with lightbox enabled * * @param int $width * @param int $height diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index 0eb0666ce..48912f3eb 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -339,7 +339,7 @@ class Medium extends Data implements RenderableInterface } /** - * Turn the current Medium inta a Link with lightbox enabled + * Turn the current Medium into a Link with lightbox enabled * * @param int $width * @param int $height diff --git a/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php b/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php index 3f40200cb..da635223d 100644 --- a/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php @@ -90,7 +90,7 @@ class ThumbnailImageMedium extends ImageMedium } /** - * Turn the current Medium inta a Link with lightbox enabled + * Turn the current Medium into a Link with lightbox enabled * * @param int $width * @param int $height diff --git a/system/src/Grav/Common/Taxonomy.php b/system/src/Grav/Common/Taxonomy.php index ebd62f577..226b67d2c 100644 --- a/system/src/Grav/Common/Taxonomy.php +++ b/system/src/Grav/Common/Taxonomy.php @@ -76,7 +76,7 @@ class Taxonomy * * @param array $taxonomies taxonomies to search, eg ['tag'=>['animal','cat']] * @param string $operator can be 'or' or 'and' (defaults to 'or') - * @return Colleciton Collection object set to contain matches found in the taxonomy map + * @return Collection Collection object set to contain matches found in the taxonomy map */ public function findTaxonomy($taxonomies, $operator = 'and') { diff --git a/system/src/Grav/Common/TwigExtension.php b/system/src/Grav/Common/TwigExtension.php index 742dc242b..6645100f4 100644 --- a/system/src/Grav/Common/TwigExtension.php +++ b/system/src/Grav/Common/TwigExtension.php @@ -108,7 +108,7 @@ class TwigExtension extends \Twig_Extension * Truncate content by a limit. * * @param string $string - * @param int $limit Nax number of characters. + * @param int $limit Max number of characters. * @param string $break Break point. * @param string $pad Appended padding to the end of the string. * @return string diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 948c0fdfa..55e1ad806 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -384,7 +384,7 @@ class Uri } /** - * Retrun the IP address of the current user + * Return the IP address of the current user * * @return string ip address */ diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index 13dc5d8e8..b727fa19b 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -90,7 +90,7 @@ class User extends Data } /** - * Checks user authorisation to the action. + * Checks user authorization to the action. * * @param string $action * @return bool diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 22ba7b7d0..7262c498c 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -92,7 +92,7 @@ abstract class Utils if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { return $text; } - // splits all html-tags to scanable lines + // splits all html-tags to scannable lines preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); $total_length = strlen($ending); $truncate = ''; @@ -157,7 +157,7 @@ abstract class Utils } // if the words shouldn't be cut in the middle... if (!$exact) { - // ...search the last occurance of a space... + // ...search the last occurrence of a space... $spacepos = strrpos($truncate, ' '); if (isset($spacepos)) { // ...and cut the text in this position diff --git a/system/src/Grav/Console/Cli/SandboxCommand.php b/system/src/Grav/Console/Cli/SandboxCommand.php index 43cfc230c..a5a6ce126 100644 --- a/system/src/Grav/Console/Cli/SandboxCommand.php +++ b/system/src/Grav/Console/Cli/SandboxCommand.php @@ -281,7 +281,7 @@ class SandboxCommand extends Command private function perms() { $this->output->writeln(''); - $this->output->writeln('Permisions Initializing'); + $this->output->writeln('Permissions Initializing'); $dir_perms = 0755; diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php index 5e8f51a04..9647470f1 100644 --- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php +++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php @@ -96,7 +96,7 @@ class SelfupgradeCommand extends Command exit; } - // not used but pre-loaded just in case! + // not used but preloaded just in case! new ArrayInput([]); $questionHelper = $this->getHelper('question'); diff --git a/system/src/Grav/Console/Gpm/UpdateCommand.php b/system/src/Grav/Console/Gpm/UpdateCommand.php index bc987d52e..eef10039b 100644 --- a/system/src/Grav/Console/Gpm/UpdateCommand.php +++ b/system/src/Grav/Console/Gpm/UpdateCommand.php @@ -160,7 +160,7 @@ class UpdateCommand extends Command $commandExec = $installCommand->run($args, $this->output); if ($commandExec != 0) { - $this->output->writeln("Error: An error occured while trying to install the extensions"); + $this->output->writeln("Error: An error occurred while trying to install the extensions"); exit; } From 917a5c3082629fc4f2ce9be89ca1df4ec949aafc Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 26 Jun 2015 12:25:22 -0600 Subject: [PATCH 06/57] some initial lang work --- system/config/system.yaml | 8 ++- system/src/Grav/Common/Filesystem/Folder.php | 6 +- system/src/Grav/Common/Grav.php | 12 +++- system/src/Grav/Common/Language.php | 58 ++++++++++++++++++++ system/src/Grav/Common/Page/Pages.php | 9 ++- system/src/Grav/Common/Uri.php | 8 +++ 6 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 system/src/Grav/Common/Language.php 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); From eb421bc95ed8bfce9f4b8caa3f018673802c391b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 28 Jun 2015 09:23:48 -0600 Subject: [PATCH 07/57] more progress on matching lang keys --- system/src/Grav/Common/Uri.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 1bfd73f96..34fc4a372 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -87,13 +87,18 @@ class Uri // process params $uri = $this->processParams($uri, $config->get('system.param_sep')); - $regex = '/(\/(?:'.$language->getAvailablekeys().')\/).*/'; + $regex = '/(\/('.$language->getAvailablekeys().'\/)).*/'; - if (preg_match($regex, $uri, $matches)) { - $uri = preg_replace("/\\".$matches[1]."/", '', $matches[0], 1); - $lang = $matches[2]; + // if languages set + if ($language->defaultKey()) { + if (preg_match($regex, $uri, $matches)) { + $lang = $matches[2]; + } else { + $lang = $language->getDefaultKey(); + } } + // split the URL and params $bits = parse_url($uri); From 65285ad11e1638e0ed618e0232a4a166bffc3f2f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 28 Jun 2015 09:24:20 -0600 Subject: [PATCH 08/57] lost default page timeout in last release.. resetting --- system/config/system.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 365a669c8..5fa628583 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -31,7 +31,7 @@ pages: '>': 'gt' '<': '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) + expires: 604800 # Page expires time in seconds (604800 seconds = 7 days) last_modified: false # Set the last modified date header based on file modification timestamp etag: false # Set the etag header tag From f1a929624fa7c42bb2f2d5ab8680679fc4d4638e Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Sun, 28 Jun 2015 12:11:26 -0700 Subject: [PATCH 09/57] Potential fix for Insight (sensio labs) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d2cb6a8ef..c0b976c1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,7 +44,7 @@ before_install: - go get github.com/aktau/github-release - git clone --quiet --depth=50 --branch=master https://${BB_TOKEN}bitbucket.org/rockettheme/grav-devtools.git $RT_DEVTOOLS &>/dev/null; - if [ ! -z "$TRAVIS_TAG" ]; then - cd $RT_DEVTOOLS; + cd "${RT_DEVTOOLS}"; ./build-grav.sh skeletons.txt; fi script: From b529456745a36dfd691db846f21981ad083f5d8a Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 29 Jun 2015 12:51:05 -0600 Subject: [PATCH 10/57] initial default override support --- system/src/Grav/Common/Page/Page.php | 50 +++++++++++++++++++-------- system/src/Grav/Common/Page/Pages.php | 9 +++-- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 6bbaf1257..f60a867f9 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -54,6 +54,8 @@ class Page protected $unpublish_date; protected $slug; protected $route; + protected $url; + protected $routes; protected $routable; protected $modified; protected $id; @@ -121,6 +123,8 @@ class Page $this->date(); $this->metadata(); $this->slug(); + $this->route(); + $this->url(); $this->visible(); $this->modularTwig($this->slug[0] == '_'); @@ -226,6 +230,9 @@ class Page if (isset($this->header->slug)) { $this->slug = trim($this->header->slug); } + if (isset($this->header->routes)) { + $this->routes = (array)($this->header->routes); + } if (isset($this->header->title)) { $this->title = trim($this->header->title); } @@ -1050,16 +1057,13 @@ class Page { if ($var !== null) { $this->slug = $var; - $baseRoute = $this->parent ? (string) $this->parent()->route() : null; - $this->route = isset($baseRoute) ? $baseRoute . '/'. $this->slug : null; } if (empty($this->slug)) { $regex = '/^[0-9]+\./u'; $this->slug = preg_replace($regex, '', $this->folder); - $baseRoute = $this->parent ? (string) $this->parent()->route() : null; - $this->route = isset($baseRoute) ? $baseRoute . '/'. $this->slug : null; } + return $this->slug; } @@ -1109,21 +1113,26 @@ class Page */ public function url($include_host = false) { - /** @var Pages $pages */ - $pages = self::getGrav()['pages']; + if (empty($this->url)) { + /** @var Pages $pages */ + $pages = self::getGrav()['pages']; - /** @var Uri $uri */ - $uri = self::getGrav()['uri']; + /** @var Uri $uri */ + $uri = self::getGrav()['uri']; - $rootUrl = $uri->rootUrl($include_host) . $pages->base(); - $url = $rootUrl.'/'.trim($this->route(), '/'); + $rootUrl = $uri->rootUrl($include_host) . $pages->base(); + $url = $rootUrl.'/'.trim($this->route(), '/'); - // trim trailing / if not root - if ($url !== '/') { - $url = rtrim($url, '/'); + // trim trailing / if not root + if ($url !== '/') { + $url = rtrim($url, '/'); + } + + $this->url = $url; } - return $url; + + return $this->url; } /** @@ -1138,6 +1147,19 @@ class Page if ($var !== null) { $this->route = $var; } + + if (empty($this->route)) { + + if (!empty($this->routes) && isset($this->routes['default'])) { + $this->route = $this->routes['default']; + return $this->route; + } + + // calculate route based on parent slugs + $baseRoute = $this->parent ? (string) $this->parent()->route() : null; + $this->route = isset($baseRoute) ? $baseRoute . '/'. $this->slug() : null; + } + return $this->route; } diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index dd70501f3..5a9ebaf6c 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -627,11 +627,14 @@ class Pages /** @var $page Page */ foreach ($this->instances as $page) { $parent = $page->parent(); + $route = null; if ($parent) { - $route = rtrim($parent->route(), '/') . '/' . $page->slug(); - $this->routes[$route] = $page->path(); - $page->route($route); +// $route = rtrim($parent->route(), '/') . '/' . $page->slug(); + $route = $page->route(); + $this->routes[$page->route()] = $page->path(); + +// $page->route($route); } if (!empty($route)) { From 7b4f0a29ac162849cbbcb95db6ee86f4202362a8 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 29 Jun 2015 15:30:18 -0600 Subject: [PATCH 11/57] small optimization --- system/src/Grav/Common/Taxonomy.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Taxonomy.php b/system/src/Grav/Common/Taxonomy.php index 226b67d2c..791a43b7b 100644 --- a/system/src/Grav/Common/Taxonomy.php +++ b/system/src/Grav/Common/Taxonomy.php @@ -52,13 +52,13 @@ class Taxonomy $page_taxonomy = $page->taxonomy(); } - if (!$page->published()) { + if (!$page->published() || empty($page_taxonomy)) { return; } /** @var Config $config */ $config = $this->grav['config']; - if ($config->get('site.taxonomies') && count($page_taxonomy) > 0) { + if ($config->get('site.taxonomies')) { foreach ((array) $config->get('site.taxonomies') as $taxonomy) { if (isset($page_taxonomy[$taxonomy])) { foreach ((array) $page_taxonomy[$taxonomy] as $item) { From 0a42ace4bac0153dce67be3c35cd9360ca205185 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 29 Jun 2015 15:30:32 -0600 Subject: [PATCH 12/57] added accessor for routeAliases --- system/src/Grav/Common/Page/Page.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index f60a867f9..83a73a074 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1136,7 +1136,8 @@ class Page } /** - * Gets the route for the page based on the parents route and the current Page's slug. + * Gets the route for the page based on the route headers if available, else from + * the parents route and the current Page's slug. * * @param string $var Set new default route. * @@ -1163,6 +1164,26 @@ class Page return $this->route; } + /** + * Gets the route aliases for the page based on page headers. + * + * @param array $var list of route aliases + * + * @return array The route aliases for the Page. + */ + public function routeAliases($var = null) + { + if ($var != null) { + $this->routes['aliases'] = (array) $var; + } + + if (!empty($this->routes) && isset($this->routes['aliases'])) { + return $this->routes['aliases']; + } else { + return []; + } + } + /** * Gets and sets the identifier for this Page object. * From aeebc13d8379aec31cb9644244cecc2340129673 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 29 Jun 2015 15:30:53 -0600 Subject: [PATCH 13/57] get route() dynamically and add any route aliases --- system/src/Grav/Common/Page/Pages.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 5a9ebaf6c..7de8bda10 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -626,21 +626,20 @@ class Pages // Build routes and taxonomy map. /** @var $page Page */ foreach ($this->instances as $page) { - $parent = $page->parent(); - $route = null; + if (!$page->root()) { + // process taxonomy + $taxonomy->addTaxonomy($page); - if ($parent) { -// $route = rtrim($parent->route(), '/') . '/' . $page->slug(); - $route = $page->route(); + // add route $this->routes[$page->route()] = $page->path(); -// $page->route($route); - } - - if (!empty($route)) { - $taxonomy->addTaxonomy($page); - } else { - $page->routable(false); + // add aliases to routes list if they are provided + $route_aliases = $page->routeAliases(); + if ($route_aliases) { + foreach ($route_aliases as $alias) { + $this->routes[$alias] = $page->path(); + } + } } } From dfccfb3cf3dcf702ad58dfb757953d8886f87b05 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 29 Jun 2015 15:38:53 -0600 Subject: [PATCH 14/57] Fix for #212 - media timestamp typo --- system/src/Grav/Common/Page/Medium/Medium.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index 48912f3eb..cf15863cf 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -60,7 +60,7 @@ class Medium extends Data implements RenderableInterface { parent::__construct($items, $blueprint); - if (self::getGrav()['config']->get('media.enable_media_timestamp', true)) { + if (self::getGrav()['config']->get('system.media.enable_media_timestamp', true)) { $this->querystring('&' . self::getGrav()['cache']->getKey()); } From bedf1555af0a30bebf2a75a9ec210ed26ee463aa Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 29 Jun 2015 22:04:21 -0600 Subject: [PATCH 15/57] invalid method name --- system/src/Grav/Common/Uri.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 34fc4a372..7c2776302 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -90,7 +90,7 @@ class Uri $regex = '/(\/('.$language->getAvailablekeys().'\/)).*/'; // if languages set - if ($language->defaultKey()) { + if ($language->getDefaultKey()) { if (preg_match($regex, $uri, $matches)) { $lang = $matches[2]; } else { From 1e9418b87bad5b3f659b1135df021ec89b6e46c3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 30 Jun 2015 14:59:24 -0600 Subject: [PATCH 16/57] add canonical route support --- system/src/Grav/Common/Page/Page.php | 63 ++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 83a73a074..740e2ee06 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1108,31 +1108,37 @@ class Page /** * Gets the url for the Page. * - * @param bool $include_host Defaults false, but true would include http://yourhost.com - * @return string The url. + * @param bool $include_host Defaults false, but true would include http://yourhost.com + * @param bool $canonical true to return the canonical URL + * + * @return string The url. */ - public function url($include_host = false) + public function url($include_host = false, $canonical = false) { - if (empty($this->url)) { - /** @var Pages $pages */ - $pages = self::getGrav()['pages']; - /** @var Uri $uri */ - $uri = self::getGrav()['uri']; + /** @var Pages $pages */ + $pages = self::getGrav()['pages']; - $rootUrl = $uri->rootUrl($include_host) . $pages->base(); - $url = $rootUrl.'/'.trim($this->route(), '/'); - - // trim trailing / if not root - if ($url !== '/') { - $url = rtrim($url, '/'); - } - - $this->url = $url; + // get canonical route if requested + if ($canonical) { + $route = $this->routeCanonical(); + } else { + $route = $this->route(); } + /** @var Uri $uri */ + $uri = self::getGrav()['uri']; - return $this->url; + $rootUrl = $uri->rootUrl($include_host) . $pages->base(); + + $url = $rootUrl.'/'.trim($route, '/'); + + // trim trailing / if not root + if ($url !== '/') { + $url = rtrim($url, '/'); + } + + return $url; } /** @@ -1184,6 +1190,27 @@ class Page } } + /** + * Gets the canonical route for this page if its set. If provided it will use + * that value, else if it's `true` it will use the default route. + * + * @param null $var + * + * @return bool|string + */ + public function routeCanonical($var = null) + { + if ($var != null) { + $this->routes['canonical'] = (array)$var; + } + + if (!empty($this->routes) && isset($this->routes['canonical'])) { + return $this->routes['canonical']; + } + + return $this->route(); + } + /** * Gets and sets the identifier for this Page object. * From 1a91cf7033f16392963347712904dd780bb65edd Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 30 Jun 2015 14:59:48 -0600 Subject: [PATCH 17/57] add canonical routes like an alias --- system/src/Grav/Common/Page/Pages.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 7de8bda10..3f81dda5f 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -631,7 +631,14 @@ class Pages $taxonomy->addTaxonomy($page); // add route - $this->routes[$page->route()] = $page->path(); + $route = $page->route(); + $this->routes[$route] = $page->path(); + + // add canonical + $route_canonical = $page->routeCanonical(); + if ($route_canonical && ($route !== $route_canonical)) { + $this->routes[$route_canonical] = $page->path(); + } // add aliases to routes list if they are provided $route_aliases = $page->routeAliases(); From 2b6740dc7ba4d273b68dfa645f78b6d261084bc7 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 30 Jun 2015 16:14:06 -0600 Subject: [PATCH 18/57] fix for content mismatch error --- system/src/Grav/Common/Grav.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 97082402b..4379ee011 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -125,10 +125,13 @@ class Grav extends Container } } Utils::download($medium->path(), false); - } else { + } + + // has an extension, try to download it... + if (isset($path_parts['extension'])) { $download = true; // little work-around to ensure .css and .js files are always sent inline not downloaded - if (Utils::endsWith($uri->basename(), ['.css', '.js'])) { + if (in_array($path_parts['extension'], ['.css', '.js'])) { $download = false; } Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download); From 547f72919f96b7b9cd7a2b7feaf479b035becd44 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 30 Jun 2015 16:22:43 -0600 Subject: [PATCH 19/57] broke-out fallback into a protected method --- system/src/Grav/Common/Grav.php | 73 ++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 4379ee011..f495f9431 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -107,36 +107,9 @@ class Grav extends Container $page = $pages->dispatch($path); if (!$page || !$page->routable()) { - $path_parts = pathinfo($path); - $page = $c['pages']->dispatch($path_parts['dirname'], true); - if ($page) { - $media = $page->media()->all(); - $parsed_url = parse_url(urldecode($uri->basename())); - - $media_file = $parsed_url['path']; - - // if this is a media object, try actions first - if (isset($media[$media_file])) { - $medium = $media[$media_file]; - foreach ($uri->query(null, true) as $action => $params) { - if (in_array($action, ImageMedium::$magic_actions)) { - call_user_func_array(array(&$medium, $action), explode(',', $params)); - } - } - Utils::download($medium->path(), false); - } - - // has an extension, try to download it... - if (isset($path_parts['extension'])) { - $download = true; - // little work-around to ensure .css and .js files are always sent inline not downloaded - if (in_array($path_parts['extension'], ['.css', '.js'])) { - $download = false; - } - Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download); - } - } + // Try fallback URL stuff... + $c->fallbackUrl($page, $path); // If no page found, fire event $event = $c->fireEvent('onPageNotFound'); @@ -395,4 +368,46 @@ class Grav extends Container $this->fireEvent('onShutdown'); } + + /** + * This attempts to fine media, other files, and download them + * @param $page + * @param $path + */ + protected function fallbackUrl($page, $path) + { + /** @var Uri $uri */ + $uri = $this['uri']; + + $path_parts = pathinfo($path); + $page = $this['pages']->dispatch($path_parts['dirname'], true); + if ($page) { + $media = $page->media()->all(); + + $parsed_url = parse_url(urldecode($uri->basename())); + + $media_file = $parsed_url['path']; + + // if this is a media object, try actions first + if (isset($media[$media_file])) { + $medium = $media[$media_file]; + foreach ($uri->query(null, true) as $action => $params) { + if (in_array($action, ImageMedium::$magic_actions)) { + call_user_func_array(array(&$medium, $action), explode(',', $params)); + } + } + Utils::download($medium->path(), false); + } + + // has an extension, try to download it... + if (isset($path_parts['extension'])) { + $download = true; + // little work-around to ensure .css and .js files are always sent inline not downloaded + if (in_array($path_parts['extension'], ['.css', '.js'])) { + $download = false; + } + Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download); + } + } + } } From 1c9d41ad5840ed6ac682e88195b5751e50662c62 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 1 Jul 2015 10:59:08 -0600 Subject: [PATCH 20/57] some more multilane progress --- system/config/system.yaml | 6 +- system/src/Grav/Common/Language.php | 126 +++++++++++++++++++------- system/src/Grav/Common/Page/Page.php | 33 +++++-- system/src/Grav/Common/Page/Pages.php | 30 +++--- system/src/Grav/Common/Uri.php | 14 +-- 5 files changed, 139 insertions(+), 70 deletions(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 29596616d..4ea2df0f3 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -5,9 +5,9 @@ param_sep: ':' # Parameter separator, use ';' for Apache home: alias: '/home' # Default path for home, ie / -languages: - en: English - fr: French +languages: # Supported languages + - en + - fr pages: theme: antimatter # Default theme (defaults to "antimatter" theme) diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php index a8856be35..57c567152 100644 --- a/system/src/Grav/Common/Language.php +++ b/system/src/Grav/Common/Language.php @@ -7,52 +7,108 @@ namespace Grav\Common; class Language { protected $languages = []; - protected $default_key; - protected $default_lang; - protected $active_key; - protected $active_lang; + protected $default; + protected $active; + protected $page_extension; public function __construct(Grav $grav) { $this->languages = $grav['config']->get('system.languages', []); - $this->default_key = key($this->languages); - $this->default_lang = reset($this->languages); + $this->default = reset($this->languages); } - public function setLanguage($key) + public function enabled() { - if (array_key_exists($key, $this->languages)) { - $this->active_key = $key; - $this->active_lang = $this->languages[$key]; + if (empty($this->languages)) { + return false; + } + return true; + } + + public function getLanguages() + { + return $this->languages; + } + + public function setLanguages($langs) + { + $this->languages = $langs; + } + + public function getAvailable() + { + return implode('|', $this->languages); + } + + public function getDefault() + { + return $this->default; + } + + public function setDefault($lang) + { + if ($this->validate($lang)) { + $this->default = $lang; + return $lang; + } + return false; + } + + public function getActive() + { + return $this->active; + } + + public function setActive($lang) + { + if ($this->validate($lang)) { + $this->active = $lang; + return $lang; + } + return false; + } + + public function setActiveFromUri($uri) + { + $regex = '/(\/('.$this->getAvailable().'\/)).*/'; + // if languages set + + if ($this->enabled()) { + if (preg_match($regex, $uri, $matches)) { + $this->active = $matches[2]; + $uri = preg_replace("/\\".$matches[1]."/", '', $matches[0], 1); + } else { + $this->active = null; + } + } + return $uri; + } + + public function getPageExtension() + { + if (empty($this->page_extension)) { + + if ($this->enabled()) { + if ($this->active) { + $lang = '.' . $this->active; + } else { + $lang = '.' . $this->default; + } + } else { + $lang = ''; + } + $this->page_extension = $lang . CONTENT_EXT; + } + return $this->page_extension; + } + + public function validate($lang) + { + if (in_array($lang, $this->languages)) { 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/Page.php b/system/src/Grav/Common/Page/Page.php index 740e2ee06..683d65a30 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -34,16 +34,9 @@ class Page * @var string Filename. Leave as null if page is folder. */ protected $name; - - /** - * @var string Folder name. - */ protected $folder; - - /** - * @var string Path to the folder. Add $this->folder to get full path. - */ protected $path; + protected $extension; protected $parent; protected $template; @@ -146,6 +139,8 @@ class Page } } $this->published(); + +// $this->setupLanguage(); } /** @@ -1119,11 +1114,17 @@ class Page /** @var Pages $pages */ $pages = self::getGrav()['pages']; + /** @var Language $language */ + $language = self::getGrav()['language']; + + // get pre-route + $pre_route = $language->enabled() && $language->getActive() ? '/'.$language->getActive() : ''; + // get canonical route if requested if ($canonical) { - $route = $this->routeCanonical(); + $route = $pre_route . $this->routeCanonical(); } else { - $route = $this->route(); + $route = $pre_route . $this->route(); } /** @var Uri $uri */ @@ -1804,6 +1805,18 @@ class Page return $results; } + public function setupLanguage() + { + /** @var Language $language */ + $language = self::getGrav()['language']; + + // add the language pre route back to the route + if ($language->enabled() && $language->getActive()) { + $this->route = '/' . $language->getActive() . $this->route; + } + + } + /** * Returns whether or not this Page object has a .md file associated with it or if its just a directory. diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index d927b8a25..949cab08e 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -62,10 +62,6 @@ class Pages */ protected $last_modified; - - protected $default_lang; - protected $page_extension; - /** * @var Types */ @@ -80,8 +76,6 @@ 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; } /** @@ -470,6 +464,9 @@ class Pages /** @var Config $config */ $config = $this->grav['config']; + /** @var Language $language */ + $language = $this->grav['language']; + /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; $pagesDir = $locator->findResource('page://'); @@ -493,7 +490,9 @@ class Pages $last_modified = Folder::lastModifiedFile($pagesDir); } - $page_cache_id = md5(USER_DIR.$last_modified.$config->checksum()); + $lang_key = $this->active_language ?: ''; + + $page_cache_id = md5(USER_DIR.$last_modified.$lang_key.$config->checksum()); list($this->instances, $this->routes, $this->children, $taxonomy_map, $this->sort) = $cache->fetch($page_cache_id); if (!$this->instances) { @@ -536,9 +535,16 @@ class Pages /** @var Config $config */ $config = $this->grav['config']; - // Fire event for memory and time consuming plugins... - if ($parent === null && $config->get('system.pages.events.page')) { - $this->grav->fireEvent('onBuildPagesInitialized'); + /** @var Language $language */ + $language = $this->grav['language']; + + // stuff to do at root page + if ($parent === null) { + + // Fire event for memory and time consuming plugins... + if ($config->get('system.pages.events.page')) { + $this->grav->fireEvent('onBuildPagesInitialized'); + } } $page->path($directory); @@ -549,6 +555,8 @@ class Pages $page->orderDir($config->get('system.pages.order.dir')); $page->orderBy($config->get('system.pages.order.by')); + + // Add into instances if (!isset($this->instances[$page->path()])) { $this->instances[$page->path()] = $page; @@ -579,7 +587,7 @@ class Pages $last_modified = $modified; } - if (preg_match('/^[^.].*'.$this->page_extension.'$/', $name)) { + if (preg_match('/^[^.].*'.$language->getPageExtension().'$/', $name)) { $page->init($file); $content_exists = true; diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 7c2776302..31516789b 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -87,17 +87,8 @@ class Uri // process params $uri = $this->processParams($uri, $config->get('system.param_sep')); - $regex = '/(\/('.$language->getAvailablekeys().'\/)).*/'; - - // if languages set - if ($language->getDefaultKey()) { - if (preg_match($regex, $uri, $matches)) { - $lang = $matches[2]; - } else { - $lang = $language->getDefaultKey(); - } - } - + // set active language + $uri = $language->setActiveFromUri($uri); // split the URL and params $bits = parse_url($uri); @@ -420,6 +411,7 @@ class Uri return $ipaddress; } + /** * Is this an external URL? if it starts with `http` then yes, else false * From 8c695df9da2977e93918fc5ec6b832b7a9f89004 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 1 Jul 2015 11:07:09 -0600 Subject: [PATCH 21/57] fixed template name based on current lang --- system/src/Grav/Common/Page/Page.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 683d65a30..d844024a9 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -139,6 +139,7 @@ class Page } } $this->published(); + $this->extension(); // $this->setupLanguage(); } @@ -619,6 +620,15 @@ class Page return null; } + public function extension() + { + if (empty($this->extension)) { + $language = self::getGrav()['language']; + $this->extension = $language->getPageExtension(); + } + return $this->extension; + } + /** * Save page if there's a file assigned to it. * @param bool $reorder Internal use. @@ -822,7 +832,7 @@ class Page $this->template = $var; } if (empty($this->template)) { - $this->template = ($this->modular() ? 'modular/' : '') . str_replace(CONTENT_EXT, '', $this->name()); + $this->template = ($this->modular() ? 'modular/' : '') . str_replace($this->extension, '', $this->name()); } return $this->template; } From 63369247abd3da4c0f75c0d82d9a1a0150443afe Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 1 Jul 2015 15:56:56 -0600 Subject: [PATCH 22/57] fix for regex and last language --- system/src/Grav/Common/Language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php index 57c567152..5f42eecb8 100644 --- a/system/src/Grav/Common/Language.php +++ b/system/src/Grav/Common/Language.php @@ -71,7 +71,7 @@ class Language public function setActiveFromUri($uri) { - $regex = '/(\/('.$this->getAvailable().'\/)).*/'; + $regex = '/(\/('.$this->getAvailable().')).*/'; // if languages set if ($this->enabled()) { From e2db025aa0aada571de0996e018529bed94727f6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 1 Jul 2015 20:50:36 -0600 Subject: [PATCH 23/57] minor updates --- system/config/system.yaml | 4 ---- system/src/Grav/Common/Page/Pages.php | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 4ea2df0f3..4d59ee364 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -5,10 +5,6 @@ param_sep: ':' # Parameter separator, use ';' for Apache home: alias: '/home' # Default path for home, ie / -languages: # Supported languages - - en - - fr - pages: theme: antimatter # Default theme (defaults to "antimatter" theme) order: diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 949cab08e..c9c88a1a2 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -490,9 +490,7 @@ class Pages $last_modified = Folder::lastModifiedFile($pagesDir); } - $lang_key = $this->active_language ?: ''; - - $page_cache_id = md5(USER_DIR.$last_modified.$lang_key.$config->checksum()); + $page_cache_id = md5(USER_DIR.$last_modified.$language->getActive().$config->checksum()); list($this->instances, $this->routes, $this->children, $taxonomy_map, $this->sort) = $cache->fetch($page_cache_id); if (!$this->instances) { From ef40bb25fdf8eacb0fb2e9ff664274c5da3cec24 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 2 Jul 2015 09:46:57 -0600 Subject: [PATCH 24/57] added a timer around pageInitialized event --- system/src/Grav/Common/Grav.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 2d132f42b..7ac1c1c8e 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -209,7 +209,9 @@ class Grav extends Container $this->fireEvent('onPagesInitialized'); $debugger->stopTimer('pages'); + $debugger->startTimer('pageinit', 'Page Initialized'); $this->fireEvent('onPageInitialized'); + $debugger->stopTimer('pageinit'); $debugger->addAssets(); From 1f1df9afc7ef4c714bbb06f924a11499a7011082 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 2 Jul 2015 11:19:44 -0600 Subject: [PATCH 25/57] support lang specific homepage --- system/src/Grav/Common/Language.php | 2 +- system/src/Grav/Common/Page/Page.php | 2 +- system/src/Grav/Common/Page/Pages.php | 44 ++++++++++++++++++++++++++- system/src/Grav/Common/Uri.php | 14 +++++++-- 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php index 5f42eecb8..ea385c4dd 100644 --- a/system/src/Grav/Common/Language.php +++ b/system/src/Grav/Common/Language.php @@ -13,7 +13,7 @@ class Language public function __construct(Grav $grav) { - $this->languages = $grav['config']->get('system.languages', []); + $this->languages = $grav['config']->get('system.languages.supported', []); $this->default = reset($this->languages); } diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index d844024a9..f4b03984f 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1604,7 +1604,7 @@ class Page // Special check when item is home if ($this->home()) { $paths = $uri->paths(); - $home = ltrim($config->get('system.home.alias'), '/'); + $home = Pages::getHomeRoute(); if (isset($paths[0]) && $paths[0] == $home) { return true; } diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index c9c88a1a2..8a7ac45d4 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -67,6 +67,8 @@ class Pages */ static protected $types; + static protected $home_route; + /** * Constructor * @@ -452,6 +454,43 @@ class Pages return $pages->getList(); } + /** + * Get's the home route + * + * @return string + */ + public static function getHomeRoute() + { + if (empty(self::$home)) { + $grav = Grav::instance(); + + /** @var Config $config */ + $config = $grav['config']; + + /** @var Language $language */ + $language = $grav['language']; + + $home = $config->get('system.home.alias'); + + if ($language->enabled()) { + $home_aliases = $config->get('system.home.aliases'); + if ($home_aliases) { + $active = $language->getActive(); + $default = $language->getDefault(); + + if ($active) { + $home = $home_aliases[$active]; + } else { + $home = $home_aliases[$default]; + } + } + } + + self::$home_route = trim($home, '/'); + } + return self::$home_route; + } + /** * Builds pages. * @@ -636,6 +675,9 @@ class Pages /** @var $taxonomy Taxonomy */ $taxonomy = $this->grav['taxonomy']; + // Get the home route + $home = self::getHomeRoute(); + // Build routes and taxonomy map. /** @var $page Page */ foreach ($this->instances as $page) { @@ -667,7 +709,7 @@ class Pages $config = $this->grav['config']; // Alias and set default route to home page. - $home = trim($config->get('system.home.alias'), '/'); + if ($home && isset($this->routes['/' . $home])) { $this->routes['/'] = $this->routes['/' . $home]; $this->get($this->routes['/' . $home])->route('/'); diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 31516789b..32c7f1a35 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -1,6 +1,8 @@ paths = []; @@ -90,6 +94,12 @@ class Uri // set active language $uri = $language->setActiveFromUri($uri); + // redirect to language specific homepage if configured to do so + if ($uri == '/' && $language->enabled() && $config->get('system.languages.home.redirect') && !$language->getActive()) { + $prefix = $config->get('system.languages.home.include_lang') ? $language->getDefault() . '/' : ''; + $grav->redirect($prefix . Pages::getHomeRoute()); + } + // split the URL and params $bits = parse_url($uri); From 947cb795584fab5b4f8b849a9943b4792ca1991a Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 2 Jul 2015 15:50:05 -0600 Subject: [PATCH 26/57] optimized enabled test --- system/src/Grav/Common/Language.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php index ea385c4dd..b66696b48 100644 --- a/system/src/Grav/Common/Language.php +++ b/system/src/Grav/Common/Language.php @@ -10,20 +10,22 @@ class Language protected $default; protected $active; protected $page_extension; + protected $enabled = true; public function __construct(Grav $grav) { $this->languages = $grav['config']->get('system.languages.supported', []); $this->default = reset($this->languages); + if (empty($this->languages)) { + $this->enabled = false; + } + } public function enabled() { - if (empty($this->languages)) { - return false; - } - return true; + return $this->enabled; } public function getLanguages() From 08e239fcf4cda7a475b5bdfea0ce0cf24a315b56 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 2 Jul 2015 15:53:05 -0600 Subject: [PATCH 27/57] Added lang template paths for theme by default --- system/src/Grav/Common/Twig.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Twig.php b/system/src/Grav/Common/Twig.php index 6a92f86a0..1a31be124 100644 --- a/system/src/Grav/Common/Twig.php +++ b/system/src/Grav/Common/Twig.php @@ -57,6 +57,7 @@ class Twig public function __construct(Grav $grav) { $this->grav = $grav; + $this->twig_paths = []; } /** @@ -72,7 +73,19 @@ class Twig $locator = $this->grav['locator']; $debugger = $this->grav['debugger']; - $this->twig_paths = $locator->findResources('theme://templates'); + /** @var Language $language */ + $language = $this->grav['language']; + + // handle language templates if available + if ($language->enabled()) { + $lang_templates = $locator->findResource('theme://templates/'.$language->getActive()); + if ($lang_templates) { + $this->twig_paths[] = $lang_templates; + } + } + + $this->twig_paths = array_merge($this->twig_paths, $locator->findResources('theme://templates')); + $this->grav->fireEvent('onTwigTemplatePaths'); $this->loader = new \Twig_Loader_Filesystem($this->twig_paths); From be8d4244047f1fef7c52a6a31f38465b6306ce45 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 2 Jul 2015 22:06:07 -0600 Subject: [PATCH 28/57] added some fallback logic - still needs work! --- system/src/Grav/Common/Page/Page.php | 15 +++++-- system/src/Grav/Common/Page/Pages.php | 62 ++++++++++++++++++++------- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index f4b03984f..357c79601 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -620,12 +620,19 @@ class Page return null; } - public function extension() + /** + * Get page extension + * + * @param $var + * + * @return mixed + */ + public function extension($var = null) { - if (empty($this->extension)) { - $language = self::getGrav()['language']; - $this->extension = $language->getPageExtension(); + if ($var !== null) { + $this->extension = $var; } + return $this->extension; } diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 8a7ac45d4..8060f1cc6 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -566,7 +566,6 @@ class Pages protected function recurse($directory, Page &$parent = null) { $directory = rtrim($directory, DS); - $iterator = new \DirectoryIterator($directory); $page = new Page; /** @var Config $config */ @@ -604,17 +603,48 @@ class Pages throw new \RuntimeException('Fatal error when creating page instances.'); } + $content_exists = false; + // set current modified of page $last_modified = $page->modified(); - // flat for content availability - $content_exists = false; + $page_extension = $language->getPageExtension(); + + $page_found = glob($directory.'/*'.$page_extension); + + // fall back to default + if (empty($page_found)) { + $page_extension = '.'.$language->getDefault().CONTENT_EXT; + $page_found = glob($directory.'/*'.$page_extension); + + // still not found, fall back to any .md file + if (empty($page_found)) { + $page_extension = CONTENT_EXT; + $page_found = glob($directory.'/*'.$page_extension); + } + } + + + + if (!empty($page_found)) { + $file = new \SplFileInfo(array_shift($page_found)); + $page->init($file); + $page->extension($page_extension); + + $content_exists = true; + + if ($config->get('system.pages.events.page')) { + $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page])); + } + } + + + + // flag for content availability + /** @var \DirectoryIterator $file */ - foreach ($iterator as $file) { - if ($file->isDot()) { - continue; - } + foreach (new \FilesystemIterator($directory) as $file) { $name = $file->getFilename(); @@ -623,15 +653,15 @@ class Pages if ($file->getBasename() !== '.DS_Store' && ($modified = $file->getMTime()) > $last_modified) { $last_modified = $modified; } - - if (preg_match('/^[^.].*'.$language->getPageExtension().'$/', $name)) { - $page->init($file); - $content_exists = true; - - if ($config->get('system.pages.events.page')) { - $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page])); - } - } +// +// if (preg_match('/^[^.].*'.$language->getPageExtension().'$/', $name)) { +// $page->init($file); +// $content_exists = true; +// +// if ($config->get('system.pages.events.page')) { +// $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page])); +// } +// } } elseif ($file->isDir()) { if (!$page->path()) { $page->path($file->getPath()); From 0fa70b5b35926b9d14e4b3c91189883d76b08f97 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 3 Jul 2015 08:20:21 -0600 Subject: [PATCH 29/57] better fallback approach --- system/src/Grav/Common/Language.php | 28 ++++++++++++------- system/src/Grav/Common/Page/Pages.php | 40 ++++++++------------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php index b66696b48..b6c3d523b 100644 --- a/system/src/Grav/Common/Language.php +++ b/system/src/Grav/Common/Language.php @@ -9,7 +9,7 @@ class Language protected $languages = []; protected $default; protected $active; - protected $page_extension; + protected $page_extensions; protected $enabled = true; public function __construct(Grav $grav) @@ -87,22 +87,30 @@ class Language return $uri; } - public function getPageExtension() + public function getValidPageExtensions() { - if (empty($this->page_extension)) { + if (empty($this->page_extensions)) { if ($this->enabled()) { - if ($this->active) { - $lang = '.' . $this->active; - } else { - $lang = '.' . $this->default; + $valid_lang_extensions = []; + foreach ($this->languages as $lang) { + $valid_lang_extensions[] = '.'.$lang.CONTENT_EXT; } + + + if ($this->active) { + $active_extension = '.'.$this->active.CONTENT_EXT; + $key = array_search($active_extension, $valid_lang_extensions); + unset($valid_lang_extensions[$key]); + array_unshift($valid_lang_extensions, $active_extension); + } + + $this->page_extensions = array_merge($valid_lang_extensions, (array) CONTENT_EXT); } else { - $lang = ''; + $this->page_extensions = (array) CONTENT_EXT; } - $this->page_extension = $lang . CONTENT_EXT; } - return $this->page_extension; + return $this->page_extensions; } public function validate($lang) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 8060f1cc6..d80697a5e 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -608,26 +608,24 @@ class Pages // set current modified of page $last_modified = $page->modified(); - $page_extension = $language->getPageExtension(); + $pages_found = glob($directory.'/*'.CONTENT_EXT); + $page_extensions = $language->getValidPageExtensions(); - $page_found = glob($directory.'/*'.$page_extension); + if ($pages_found) { - // fall back to default - if (empty($page_found)) { - $page_extension = '.'.$language->getDefault().CONTENT_EXT; - $page_found = glob($directory.'/*'.$page_extension); - - // still not found, fall back to any .md file - if (empty($page_found)) { - $page_extension = CONTENT_EXT; - $page_found = glob($directory.'/*'.$page_extension); + foreach ($page_extensions as $extension) { + foreach ($pages_found as $found) { + if (Utils::endsWith($found, $extension)) { + $page_found = $found; + $page_extension = $extension; + break 2; + } + } } } - - if (!empty($page_found)) { - $file = new \SplFileInfo(array_shift($page_found)); + $file = new \SplFileInfo($page_found); $page->init($file); $page->extension($page_extension); @@ -638,11 +636,6 @@ class Pages } } - - - // flag for content availability - - /** @var \DirectoryIterator $file */ foreach (new \FilesystemIterator($directory) as $file) { @@ -653,15 +646,6 @@ class Pages if ($file->getBasename() !== '.DS_Store' && ($modified = $file->getMTime()) > $last_modified) { $last_modified = $modified; } -// -// if (preg_match('/^[^.].*'.$language->getPageExtension().'$/', $name)) { -// $page->init($file); -// $content_exists = true; -// -// if ($config->get('system.pages.events.page')) { -// $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page])); -// } -// } } elseif ($file->isDir()) { if (!$page->path()) { $page->path($file->getPath()); From 571f27d518bd73828a53d7e9ee75b036202cfd0c Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 3 Jul 2015 14:05:15 -0600 Subject: [PATCH 30/57] minor modifications --- system/src/Grav/Common/Language.php | 7 ++++++- system/src/Grav/Common/Page/Pages.php | 11 ++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php index b6c3d523b..89ad83a60 100644 --- a/system/src/Grav/Common/Language.php +++ b/system/src/Grav/Common/Language.php @@ -7,9 +7,9 @@ namespace Grav\Common; class Language { protected $languages = []; + protected $page_extensions = []; protected $default; protected $active; - protected $page_extensions; protected $enabled = true; public function __construct(Grav $grav) @@ -87,6 +87,11 @@ class Language return $uri; } + public function setValidPageExtensions($extensions) + { + $this->page_extensions = (array) $extensions; + } + public function getValidPageExtensions() { if (empty($this->page_extensions)) { diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index d80697a5e..47a96ef18 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -591,8 +591,6 @@ class Pages $page->orderDir($config->get('system.pages.order.dir')); $page->orderBy($config->get('system.pages.order.by')); - - // Add into instances if (!isset($this->instances[$page->path()])) { $this->instances[$page->path()] = $page; @@ -604,10 +602,6 @@ class Pages } $content_exists = false; - - // set current modified of page - $last_modified = $page->modified(); - $pages_found = glob($directory.'/*'.CONTENT_EXT); $page_extensions = $language->getValidPageExtensions(); @@ -615,7 +609,7 @@ class Pages foreach ($page_extensions as $extension) { foreach ($pages_found as $found) { - if (Utils::endsWith($found, $extension)) { + if (preg_match('/^.*\/[0-9A-Za-z\-\_]+('.$extension.')$/', $found)) { $page_found = $found; $page_extension = $extension; break 2; @@ -636,6 +630,9 @@ class Pages } } + // set current modified of page + $last_modified = $page->modified(); + /** @var \DirectoryIterator $file */ foreach (new \FilesystemIterator($directory) as $file) { From 6668a7b8ab0ab40af1d7b18804c1e566541d44d7 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 3 Jul 2015 15:41:39 -0600 Subject: [PATCH 31/57] save standard routing in aliases if default overrides --- system/src/Grav/Common/Page/Page.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 357c79601..d8a969478 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1175,14 +1175,15 @@ class Page if (empty($this->route)) { - if (!empty($this->routes) && isset($this->routes['default'])) { - $this->route = $this->routes['default']; - return $this->route; - } - // calculate route based on parent slugs $baseRoute = $this->parent ? (string) $this->parent()->route() : null; $this->route = isset($baseRoute) ? $baseRoute . '/'. $this->slug() : null; + + if (!empty($this->routes) && isset($this->routes['default'])) { + $this->routes['aliases'][] = $this->route; + $this->route = $this->routes['default']; + return $this->route; + } } return $this->route; From 364f95ec45760ec5fb82c5b2a548a6223d47d96d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 3 Jul 2015 16:16:36 -0600 Subject: [PATCH 32/57] add active lang to the base_url stuff --- system/src/Grav/Common/Twig.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Twig.php b/system/src/Grav/Common/Twig.php index 1a31be124..68d3c518e 100644 --- a/system/src/Grav/Common/Twig.php +++ b/system/src/Grav/Common/Twig.php @@ -76,9 +76,13 @@ class Twig /** @var Language $language */ $language = $this->grav['language']; + $active_language = $language->getActive(); + + $language_append = $active_language ? '/'.$active_language : ''; + // handle language templates if available if ($language->enabled()) { - $lang_templates = $locator->findResource('theme://templates/'.$language->getActive()); + $lang_templates = $locator->findResource('theme://templates/'.$active_language); if ($lang_templates) { $this->twig_paths[] = $lang_templates; } @@ -144,9 +148,9 @@ class Twig 'config' => $config, 'uri' => $this->grav['uri'], 'base_dir' => rtrim(ROOT_DIR, '/'), - 'base_url' => $this->grav['base_url'], - 'base_url_absolute' => $this->grav['base_url_absolute'], - 'base_url_relative' => $this->grav['base_url_relative'], + 'base_url' => $this->grav['base_url'] . $language_append, + 'base_url_absolute' => $this->grav['base_url_absolute'] . $language_append, + 'base_url_relative' => $this->grav['base_url_relative'] . $language_append, 'theme_dir' => $locator->findResource('theme://'), 'theme_url' => $this->grav['base_url'] .'/'. $locator->findResource('theme://', false), 'site' => $config->get('site'), From 740ea2e86de901434630940537f730600cc5e316 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 4 Jul 2015 09:40:41 -0600 Subject: [PATCH 33/57] removed unused method for now --- system/src/Grav/Common/Language.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php index 89ad83a60..36ee463c2 100644 --- a/system/src/Grav/Common/Language.php +++ b/system/src/Grav/Common/Language.php @@ -87,22 +87,15 @@ class Language return $uri; } - public function setValidPageExtensions($extensions) - { - $this->page_extensions = (array) $extensions; - } - public function getValidPageExtensions() { if (empty($this->page_extensions)) { - if ($this->enabled()) { $valid_lang_extensions = []; foreach ($this->languages as $lang) { $valid_lang_extensions[] = '.'.$lang.CONTENT_EXT; } - if ($this->active) { $active_extension = '.'.$this->active.CONTENT_EXT; $key = array_search($active_extension, $valid_lang_extensions); From 79f5aaa03239c0f55112a2093f0d5dac6009946e Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 4 Jul 2015 10:11:40 -0600 Subject: [PATCH 34/57] added a default route alias - particularly useful for multilane switching --- system/src/Grav/Common/Page/Page.php | 22 +++++++++++++++++++--- system/src/Grav/Common/Page/Pages.php | 18 +++++++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index d8a969478..af01425dd 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -47,6 +47,7 @@ class Page protected $unpublish_date; protected $slug; protected $route; + protected $raw_route; protected $url; protected $routes; protected $routable; @@ -115,8 +116,6 @@ class Page $this->header(); $this->date(); $this->metadata(); - $this->slug(); - $this->route(); $this->url(); $this->visible(); $this->modularTwig($this->slug[0] == '_'); @@ -1174,7 +1173,6 @@ class Page } if (empty($this->route)) { - // calculate route based on parent slugs $baseRoute = $this->parent ? (string) $this->parent()->route() : null; $this->route = isset($baseRoute) ? $baseRoute . '/'. $this->slug() : null; @@ -1189,6 +1187,24 @@ class Page return $this->route; } + public function rawRoute($var = null) + { + if ($var !== null) { + $this->raw_route = $var; + } + + if (empty($this->raw_route)) { + $baseRoute = $this->parent ? (string) $this->parent()->rawRoute() : null; + + $regex = '/^[0-9]+\./u'; + $slug = preg_replace($regex, '', $this->folder); + + $this->raw_route = isset($baseRoute) ? $baseRoute . '/'. $slug : null; + } + + return $this->raw_route; + } + /** * Gets the route aliases for the page based on page headers. * diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 47a96ef18..5b1cf143e 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -696,21 +696,29 @@ class Pages // process taxonomy $taxonomy->addTaxonomy($page); - // add route $route = $page->route(); - $this->routes[$route] = $page->path(); + $raw_route = $page->rawRoute(); + $page_path = $page->path(); - // add canonical + // add regular route + $this->routes[$route] = $page_path; + + // add raw route + if ($raw_route != $route) { + $this->routes[$raw_route] = $page_path; + } + + // add canonical route $route_canonical = $page->routeCanonical(); if ($route_canonical && ($route !== $route_canonical)) { - $this->routes[$route_canonical] = $page->path(); + $this->routes[$route_canonical] = $page_path; } // add aliases to routes list if they are provided $route_aliases = $page->routeAliases(); if ($route_aliases) { foreach ($route_aliases as $alias) { - $this->routes[$alias] = $page->path(); + $this->routes[$alias] = $page_path; } } } From a4d39ce4243be86dfe9533e54cc104fc4cd10413 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 5 Jul 2015 13:58:33 -0600 Subject: [PATCH 35/57] Added translation Twig function and filter --- system/src/Grav/Common/Language.php | 173 +++++++++++++++++++++-- system/src/Grav/Common/Page/Pages.php | 3 +- system/src/Grav/Common/TwigExtension.php | 18 ++- 3 files changed, 181 insertions(+), 13 deletions(-) diff --git a/system/src/Grav/Common/Language.php b/system/src/Grav/Common/Language.php index 36ee463c2..77c5c8892 100644 --- a/system/src/Grav/Common/Language.php +++ b/system/src/Grav/Common/Language.php @@ -2,52 +2,110 @@ namespace Grav\Common; /** - * Contain some useful language functions + * Language and translation functionality for Grav */ class Language { + protected $enabled = true; protected $languages = []; protected $page_extensions = []; + protected $fallback_languages = []; protected $default; protected $active; - protected $enabled = true; + protected $config; + /** + * Constructor + * + * @param \Grav\Common\Grav $grav + */ public function __construct(Grav $grav) { - $this->languages = $grav['config']->get('system.languages.supported', []); + $this->config = $grav['config']; + $this->languages = $this->config->get('system.languages.supported', []); + $this->init(); + } + + /** + * Initialize the default and enabled languages + */ + public function init() + { $this->default = reset($this->languages); if (empty($this->languages)) { $this->enabled = false; } - } + /** + * Ensure that languages are enabled + * + * @return bool + */ public function enabled() { return $this->enabled; } + /** + * Gets the array of supported languages + * + * @return array + */ public function getLanguages() { return $this->languages; } + /** + * Sets the current supported languages manually + * + * @param $langs + */ public function setLanguages($langs) { $this->languages = $langs; + $this->init(); } + /** + * Gets a pipe-separated string of available languages + * + * @return string + */ public function getAvailable() { return implode('|', $this->languages); } + /** + * Gets language, active if set, else default + * + * @return mixed + */ + public function getLanguage() + { + return $this->active ? $this->active : $this->default; + } + + /** + * Gets current default language + * + * @return mixed + */ public function getDefault() { return $this->default; } + /** + * Sets default language manually + * + * @param $lang + * + * @return bool + */ public function setDefault($lang) { if ($this->validate($lang)) { @@ -57,11 +115,23 @@ class Language return false; } + /** + * Gets current active language + * + * @return mixed + */ public function getActive() { return $this->active; } + /** + * Sets active language manually + * + * @param $lang + * + * @return bool + */ public function setActive($lang) { if ($this->validate($lang)) { @@ -71,6 +141,13 @@ class Language return false; } + /** + * Sets the active language based on the first part of the URL + * + * @param $uri + * + * @return mixed + */ public function setActiveFromUri($uri) { $regex = '/(\/('.$this->getAvailable().')).*/'; @@ -87,30 +164,70 @@ class Language return $uri; } - public function getValidPageExtensions() + + /** + * Gets an array of valid extensions with active first, then fallback extensions + * + * @return array + */ + public function getFallbackPageExtensions($file_ext = null) { if (empty($this->page_extensions)) { + if (empty($file_ext)) { + $file_ext = CONTENT_EXT; + } + if ($this->enabled()) { $valid_lang_extensions = []; foreach ($this->languages as $lang) { - $valid_lang_extensions[] = '.'.$lang.CONTENT_EXT; + $valid_lang_extensions[] = '.'.$lang.$file_ext; } if ($this->active) { - $active_extension = '.'.$this->active.CONTENT_EXT; + $active_extension = '.'.$this->active.$file_ext; $key = array_search($active_extension, $valid_lang_extensions); unset($valid_lang_extensions[$key]); array_unshift($valid_lang_extensions, $active_extension); } - $this->page_extensions = array_merge($valid_lang_extensions, (array) CONTENT_EXT); + $this->page_extensions = array_merge($valid_lang_extensions, (array) $file_ext); } else { - $this->page_extensions = (array) CONTENT_EXT; + $this->page_extensions = (array) $file_ext; } } return $this->page_extensions; } + /** + * Gets an array of languages with active first, then fallback languages + * + * @return array + */ + public function getFallbackLanguages() + { + if (empty($this->fallback_languages)) { + if ($this->enabled()) { + $fallback_languages = $this->languages; + + if ($this->active) { + $active_extension = $this->active; + $key = array_search($active_extension, $fallback_languages); + unset($fallback_languages[$key]); + array_unshift($fallback_languages, $active_extension); + } + $this->fallback_languages = $fallback_languages; + } + } + return $this->fallback_languages; + } + + /** + * Ensures the language is valid and supported + * + * @param $lang + * + * @return bool + */ public function validate($lang) { if (in_array($lang, $this->languages)) { @@ -119,4 +236,42 @@ class Language return false; } + /** + * Translate a key and possibly arguments into a string using current lang and fallbacks + * + * @param Array $args first argument is the lookup key value + * other arguments can be passed and replaced in the translation with sprintf syntax + * @return string + */ + public function translate(Array $args) + { + $lookup = array_shift($args); + + if ($this->enabled() && $lookup) { + foreach ($this->getFallbackLanguages() as $lang) { + $translation = $this->getTranslation($lang, $lookup); + + if ($translation) { + if (count($args) >= 1) { + return vsprintf($translation, $args); + } else { + return $translation; + } + } + } + } + return ''.$lookup.''; + } + + /** + * Lookup the translation text for a given lang and key + * + * @param $lang lang code + * @param $key key to lookup with + * + * @return string + */ + public function getTranslation($lang, $key) { + return $this->config->get('languages.'.$lang.'.'.$key, null); + } } diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 5b1cf143e..9a705c8fd 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -603,10 +603,9 @@ class Pages $content_exists = false; $pages_found = glob($directory.'/*'.CONTENT_EXT); - $page_extensions = $language->getValidPageExtensions(); + $page_extensions = $language->getFallbackPageExtensions(); if ($pages_found) { - foreach ($page_extensions as $extension) { foreach ($pages_found as $found) { if (preg_match('/^.*\/[0-9A-Za-z\-\_]+('.$extension.')$/', $found)) { diff --git a/system/src/Grav/Common/TwigExtension.php b/system/src/Grav/Common/TwigExtension.php index 6645100f4..77d06bcfe 100644 --- a/system/src/Grav/Common/TwigExtension.php +++ b/system/src/Grav/Common/TwigExtension.php @@ -16,11 +16,13 @@ class TwigExtension extends \Twig_Extension { protected $grav; protected $debugger; + protected $config; public function __construct() { $this->grav = Grav::instance(); $this->debugger = isset($this->grav['debugger']) ? $this->grav['debugger'] : null; + $this->config = $this->grav['config']; } /** @@ -54,7 +56,8 @@ class TwigExtension extends \Twig_Extension new \Twig_SimpleFilter('absolute_url', [$this, 'absoluteUrlFilter']), new \Twig_SimpleFilter('markdown', [$this, 'markdownFilter']), new \Twig_SimpleFilter('starts_with', [$this, 'startsWithFilter']), - new \Twig_SimpleFilter('ends_with', [$this, 'endsWithFilter']) + new \Twig_SimpleFilter('ends_with', [$this, 'endsWithFilter']), + new \Twig_SimpleFilter('t', [$this, 'translateFilter']) ]; } @@ -72,6 +75,7 @@ class TwigExtension extends \Twig_Extension new \Twig_SimpleFunction('debug', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]), new \Twig_SimpleFunction('gist', [$this, 'gistFunc']), new \Twig_simpleFunction('random_string', [$this, 'randomStringFunc']), + new \Twig_simpleFunction('t', [$this, 'translateFunc']) ]; } @@ -335,7 +339,7 @@ class TwigExtension extends \Twig_Extension public function markdownFilter($string) { $page = $this->grav['page']; - $defaults = $this->grav['config']->get('system.pages.markdown'); + $defaults = $this->$config->get('system.pages.markdown'); // Initialize the preferred variant of Parsedown if ($defaults['extra']) { @@ -359,6 +363,11 @@ class TwigExtension extends \Twig_Extension return Utils::endsWith($haystack, $needle); } + public function translateFilter() + { + return $this->grav['language']->translate(func_get_args()); + } + /** * Repeat given string x times. * @@ -459,4 +468,9 @@ class TwigExtension extends \Twig_Extension { return Utils::generateRandomString($count); } + + public function translateFunc() + { + return $this->grav['language']->translate(func_get_args()); + } } From b06e3b3281456467dc56e88929e3a1753aa5933b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 5 Jul 2015 14:50:54 -0600 Subject: [PATCH 36/57] updated jQuery reference to v2.1.4 --- system/config/system.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 5fa628583..baf92567d 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -62,7 +62,7 @@ assets: # Configuration for Assets Manager (JS, C js_minify: true # Minify the JS during pipelining enable_asset_timestamp: false # Enable asset timestamps collections: - jquery: system://assets/jquery/jquery-2.1.3.min.js + jquery: system://assets/jquery/jquery-2.1.4.min.js errors: display: true # Display full backtrace-style error page From 5bdce4fb28d3b0676d875345b20a93dddc906066 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 5 Jul 2015 14:52:48 -0600 Subject: [PATCH 37/57] And the actual jQuery file! --- system/assets/jquery/jquery-2.1.3.min.js | 4 ---- system/assets/jquery/jquery-2.1.4.min.js | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 system/assets/jquery/jquery-2.1.3.min.js create mode 100644 system/assets/jquery/jquery-2.1.4.min.js diff --git a/system/assets/jquery/jquery-2.1.3.min.js b/system/assets/jquery/jquery-2.1.3.min.js deleted file mode 100644 index 25714ed29..000000000 --- a/system/assets/jquery/jquery-2.1.3.min.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! jQuery v2.1.3 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ -!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.3",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)+1>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=hb(),z=hb(),A=hb(),B=function(a,b){return a===b&&(l=!0),0},C=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},eb=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fb){H={apply:E.length?function(a,b){G.apply(a,I.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function gb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(f=_.exec(a)))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+rb(o[l]);w=ab.test(a)&&pb(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function hb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ib(a){return a[u]=!0,a}function jb(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function kb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function lb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function nb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function ob(a){return ib(function(b){return b=+b,ib(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function pb(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=gb.support={},f=gb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=gb.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",eb,!1):e.attachEvent&&e.attachEvent("onunload",eb)),p=!f(g),c.attributes=jb(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=jb(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=jb(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(jb(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),jb(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&jb(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return lb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?lb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):n},gb.matches=function(a,b){return gb(a,null,null,b)},gb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return gb(b,n,null,[a]).length>0},gb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},gb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&D.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},gb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},gb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=gb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=gb.selectors={cacheLength:50,createPseudo:ib,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||gb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&gb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+L+")"+a+"("+L+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=gb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(Q," ")+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||gb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ib(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=J(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ib(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?ib(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ib(function(a){return function(b){return gb(a,b).length>0}}),contains:ib(function(a){return a=a.replace(cb,db),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ib(function(a){return W.test(a||"")||gb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:ob(function(){return[0]}),last:ob(function(a,b){return[b-1]}),eq:ob(function(a,b,c){return[0>c?c+b:c]}),even:ob(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:ob(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:ob(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:ob(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function sb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function tb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function ub(a,b,c){for(var d=0,e=b.length;e>d;d++)gb(a,b[d],c);return c}function vb(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function wb(a,b,c,d,e,f){return d&&!d[u]&&(d=wb(d)),e&&!e[u]&&(e=wb(e,f)),ib(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ub(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:vb(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=vb(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=vb(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sb(function(a){return a===b},h,!0),l=sb(function(a){return J(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[sb(tb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return wb(i>1&&tb(m),i>1&&rb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xb(a.slice(i,e)),f>e&&xb(a=a.slice(e)),f>e&&rb(a))}m.push(c)}return tb(m)}function yb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=F.call(i));s=vb(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&gb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?ib(f):f}return h=gb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=xb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,yb(e,d)),f.selector=a}return f},i=gb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&pb(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&rb(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&pb(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=jb(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),jb(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||kb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&jb(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||kb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),jb(function(a){return null==a.getAttribute("disabled")})||kb(K,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),gb}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+K.uid++}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c) -},removeData:function(a,b){M.remove(a,b)},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthx",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*\s*$/g,ib={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(ob(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(ob(c,"script"),kb),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(hb,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function tb(a){var b=l,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||n("