diff --git a/README.markdown b/README.markdown index bc3e125..4cdabb3 100644 --- a/README.markdown +++ b/README.markdown @@ -3,8 +3,8 @@ Page LHandles Offers multilingual support for localised page handles in browser URL. -* Version: 2.3 -* Build Date: 2011-12-28 +* Version: 2.4 +* Build Date: 2012-02-08 * Authors: - [Vlad Ghita](http://www.xanderadvertising.com) * Requirements: @@ -23,6 +23,7 @@ Thank you all other Symphony Extensions developers for your inspirational work. * Offers a DS which outputs the current-page handle and title in all supported languages. * Provides a utility for easier URL manipulation. * Overrides the navigation template Datasources to output the extra information. +* URL Router compatible. URLs like `www.site.com/clients/_param1_/projects/_param2_/` are possible if `Operating mode` is set to `Relax`. See Preferences page. Old XML for a navigation Datasource: diff --git a/extension.driver.php b/extension.driver.php index 9ab75a7..a7c60cd 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -20,8 +20,8 @@ class Extension_page_lhandles extends Extension { public function about() { return array( 'name' => PLH_NAME, - 'version' => '2.3', - 'release-date' => '2011-12-28', + 'version' => '2.4', + 'release-date' => '2012-02-08', 'author' => array( array( 'name' => 'Vlad Ghita', @@ -32,6 +32,14 @@ public function about() { ); } + + /** + * Supported operating modes. + * + * @var array + */ + private $op_modes; + /** * PLH Datasource manager * @@ -53,6 +61,19 @@ public function __construct($args) { $this->plh_dsm = new PLHDatasourceManager(); $this->first_pass = true; + + $this->op_modes = array( + array( + 'handle' => 'strict', + 'name' => __('Strict'), + 'desc' => __('Default & Recommended mode.') + ), + array( + 'handle' => 'relax', + 'name' => __('Relax'), + 'desc' => __('Compatibility mode for URL Router. Enable this to use URLs like: site.com/clients/_param1_/projects/_param2_/. If you\'ll have _param1_ = `projects`, that will be a collision and Page LHandles will fail.') + ) + ); } @@ -63,7 +84,9 @@ public function __construct($args) { public function install(){ $this->plh_dsm->editAllNavDssTo('PLH'); - + + Symphony::Configuration()->set('op_mode', $this->op_modes[0]['handle'], PLH_GROUP); + return (boolean)$this->_addColumnsToPageTable(); } @@ -94,13 +117,22 @@ public function update($previous_version){ return Symphony::Database()->query($query); } } + + if( version_compare($previous_version, '2.4', '<') ){ + Symphony::Configuration()->set('op_mode', $this->op_modes[0]['handle'], PLH_GROUP); + } return true; } public function uninstall(){ + // Reset navigation datasources $this->plh_dsm->editAllNavDssTo('SYMPHONY'); - + + // remove config settings + Symphony::Configuration()->remove(PLH_GROUP); + + // remove columns from tbl_pages table $query_fields = ''; $fields = Symphony::Database()->fetch('DESCRIBE `tbl_pages`'); $fields_count = count($fields); @@ -118,7 +150,7 @@ public function uninstall(){ return (boolean)Symphony::Database()->query($query); } - + return true; } @@ -310,7 +342,8 @@ public function dAddCustomPreferenceFieldsets($context) { $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Page LHandles'))); - + + /* Fill test Names and Handles for Pages */ $div = new XMLElement('div', NULL, array('id' => 'file-actions', 'class' => 'label')); $span = new XMLElement('span', NULL, array('class' => 'frame')); @@ -322,7 +355,6 @@ public function dAddCustomPreferenceFieldsets($context) { $div->appendChild($span); - $reference_language = FLang::instance()->referenceLanguage(); $all_languages = FLang::instance()->ld()->allLanguages(); @@ -336,6 +368,32 @@ public function dAddCustomPreferenceFieldsets($context) { )); $group->appendChild($div); + + + /* Operating mode */ + $label = Widget::Label(__('Operating mode')); + + $op_mode = Symphony::Configuration()->get('op_mode', PLH_GROUP); + $options = array(); + $message = ''; + + foreach( $this->op_modes as $idx => $op_mode_details ){ + $options[] = array( + $op_mode_details['handle'], + ($op_mode_details['handle'] == $op_mode), + $op_mode_details['name'] + ); + + if( $idx > 0 ) $message .= "
"; + + $message .= "".$op_mode_details['name'].": ".$op_mode_details['desc']; + } + + $label->appendChild( Widget::Select('settings['.PLH_GROUP.'][op_mode]', $options) ); + $group->appendChild($label); + $group->appendChild(new XMLElement('p', $message, array('class' => 'help'))); + + $context['wrapper']->appendChild($group); } @@ -365,7 +423,7 @@ public function dSavePreferences($context) { } $this->_insertTestTitlesAndHandles($saved_languages); - + return true; } diff --git a/extension.meta.xml b/extension.meta.xml index a6d32c3..9a7b02b 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -29,10 +29,16 @@ + + + diff --git a/lang/lang.ro.php b/lang/lang.ro.php index 3694304..b26862e 100644 --- a/lang/lang.ro.php +++ b/lang/lang.ro.php @@ -5,8 +5,9 @@ 'author' => array( 'name' => 'Vlad Ghita', 'email' => 'vlad.ghita@xandergroup.ro', + 'website' => '' ), - 'release-date' => '2011-09-17' + 'release-date' => '2012-02-08' ); /** @@ -14,25 +15,40 @@ */ $dictionary = array( - '%1$s depends on %2$s. Make sure you have this extension installed and enabled.' => + '%1$s depends on %2$s. Make sure you have this extension installed and enabled.' => '%1$s depinde de %2$s. Asiguraţi-vă că această extensie există şi este activată.', - 'Localised Title' => + 'Fill test Names and Handles for Pages' => + 'Încarcă Nume de test pentru Pagini', + + 'Localised Title' => 'Titlu localizat', - 'Localised URL Handle' => + 'Localised URL Handle' => 'Handle URL localizat', - 'Unknown Lang : %s' => + 'Unknown Lang : %s' => 'Limbă necunoscută : %s', - 'Page LHandles' => - false, + 'Strict' => + 'Strict', - 'Fill test Names and Handles for Pages' => - 'Încarcă Nume de test pentru Pagini', + 'Default & Recommended mode.' => + 'Modul implicit & recomandat', + 'Relax' => + 'Relax', + 'Updates every Page\'s empty Titles and Handles with the value for %1$s - %2$s language, prefixed by language code.
E.g. Romana : Acasa => English : ENAcasa' => - 'Actualizează Titlul şi Handleul fiecărei Pagini cu valoarea pentru limba %1$s - %2$s, prefixată de codul de limbă.
Ex: Romana : Acasa => English : ENAcasa', + 'Actualizează Titlul şi Handleul fiecărei Pagini cu valorile de la limba %1$s - %2$s, prefixate de codul de limbă.
Ex. Romana : Acasa => English : ENAcasa', + 'Compatibility mode for URL Router. Enable this to use URLs like: site.com/clients/_param1_/projects/_param2_/. If you\'ll have _param1_ = `projects`, that will be a collision and Page LHandles will fail.' => + 'Mod de compatibilitate pentru URL Router. Activează pentru a folosi URLuri de genul: site.com/clients/_param1_/projects/_param2_/. Dacă vei avea _param1_ = `projects`, aceasta va fi o coliziune şi Page LHandles va da rezultate eronate.', + + 'Page LHandles' => + false, + + 'Operating mode' => + 'Modul de operare', + ); diff --git a/lib/class.PLHManagerURL.php b/lib/class.PLHManagerURL.php index 17acdac..9f700dc 100644 --- a/lib/class.PLHManagerURL.php +++ b/lib/class.PLHManagerURL.php @@ -121,7 +121,7 @@ private function _processURL($url, $ref_handle, $target_handle){ // resolve index if( $old_url == null || empty($old_url) || !is_array($old_url) ){ - // get the index page + // get the index page info $query = " SELECT p.`id`, p.`{$target_handle}`, p.`parent` FROM `tbl_pages` as p @@ -129,7 +129,7 @@ private function _processURL($url, $ref_handle, $target_handle){ WHERE pt.`type` = 'index' LIMIT 1"; - // try to get the index page + // try to resolve the index page $bit = $this->_getPageHandle($query, $last_parent, $target_handle); if( $bit === false ){ @@ -142,38 +142,91 @@ private function _processURL($url, $ref_handle, $target_handle){ // resolve other pages else{ - $page_mode = true; - - foreach( $old_url as $value ){ - if( !empty($value) ){ - - $query = sprintf(" - SELECT `id`, `%s`, `parent` FROM `tbl_pages` WHERE `%s` = '%s' AND `parent` %s LIMIT 1", - $target_handle, - $ref_handle, - $value, - ($last_parent != null ? sprintf("= %s", $last_parent) : "IS NULL") - ); - - if( $page_mode ){ - $bit = $this->_getPageHandle($query, $last_parent, $target_handle); - - if( $bit === false ){ - $path .= '/'.$value; - $page_mode = false; - } - else{ - $path .= '/'.$bit; - } + $op_mode = Symphony::Configuration()->get('op_mode', PLH_GROUP); + $method = '_process'.ucfirst($op_mode); + + if( method_exists($this, $method) ){ + $path = call_user_method($method, $this, $old_url, $ref_handle, $target_handle); + } + else{ + $path = trim($url, '/'); + } + } + + return (string) $path .'/'. $url_query . $url_hash; + } + + /** + * Processes the URL with relax settings. Used for URL Router compatibility + * Doesn't respect Symphony Page parents structure. + * + * @param array $old_url + * @param string $ref_handle + * @param string $target_handle + */ + private function _processRelax($old_url, $ref_handle, $target_handle){ + $path = ''; + + foreach( $old_url as $value ){ + if( !empty($value) ){ + $last_parent = null; + + $query = sprintf( + "SELECT `id`, `%s`, `parent` FROM `tbl_pages` WHERE `%s` = '%s' LIMIT 1", + $target_handle, $ref_handle, $value + ); + + $bit = $this->_getPageHandle($query, $last_parent, $target_handle); + + $path .= '/'.($bit === false ? $value : $bit ); + } + } + + return $path; + } + + /** + * Processes the URL with strict settings. + * Respects Symphony Page parents structure. + * + * @param array $old_url + * @param string $ref_handle + * @param string $target_handle + */ + private function _processStrict($old_url, $ref_handle, $target_handle){ + $path = ''; + $page_mode = true; + $last_parent = null; + + foreach( $old_url as $value ){ + if( !empty($value) ){ + + $query = sprintf(" + SELECT `id`, `%s`, `parent` FROM `tbl_pages` WHERE `%s` = '%s' AND `parent` %s LIMIT 1", + $target_handle, + $ref_handle, + $value, + ($last_parent != null ? sprintf("= %s", $last_parent) : "IS NULL") + ); + + if( $page_mode ){ + $bit = $this->_getPageHandle($query, $last_parent, $target_handle); + + if( $bit === false ){ + $path .= '/'.$value; + $page_mode = false; } else{ - $path .= '/'.$value; + $path .= '/'.$bit; } } + else{ + $path .= '/'.$value; + } } } - return (string) $path .'/'. $url_query . $url_hash; + return $path; } /** @@ -209,4 +262,5 @@ private function _getPageHandle($query, &$last_parent, $target_handle) { return false; } + } diff --git a/utilities/plh-toolkit.xsl b/utilities/plh-toolkit.xsl index 774f081..764fa32 100644 --- a/utilities/plh-toolkit.xsl +++ b/utilities/plh-toolkit.xsl @@ -1,8 +1,9 @@ - +