Skip to content

Commit

Permalink
Release 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Ghita committed Feb 8, 2012
1 parent 53f081b commit 0595d25
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 51 deletions.
5 changes: 3 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:

Expand Down
74 changes: 66 additions & 8 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -32,6 +32,14 @@ public function about() {
);
}


/**
* Supported operating modes.
*
* @var array
*/
private $op_modes;

/**
* PLH Datasource manager
*
Expand All @@ -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: <code>site.com/clients/_param1_/projects/_param2_/</b>. If you\'ll have <code>_param1_ = `projects`</code>, that will be a collision and Page LHandles will fail.')
)
);
}


Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
Expand All @@ -118,7 +150,7 @@ public function uninstall(){

return (boolean)Symphony::Database()->query($query);
}

return true;
}

Expand Down Expand Up @@ -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'));
Expand All @@ -322,7 +355,6 @@ public function dAddCustomPreferenceFieldsets($context) {

$div->appendChild($span);


$reference_language = FLang::instance()->referenceLanguage();
$all_languages = FLang::instance()->ld()->allLanguages();

Expand All @@ -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 .= "<br />";

$message .= "<b>".$op_mode_details['name']."</b>: ".$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);
}

Expand Down Expand Up @@ -365,7 +423,7 @@ public function dSavePreferences($context) {
}

$this->_insertTestTitlesAndHandles($saved_languages);

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@
</dependencies>

<releases>
<release version="2.4" date="2012-02-08"><![CDATA[
* Added compatibility for URL Router.
* Introduces $op_mode: `Strict` = Recommended & Default. `Relax` = URL Router compatibility.
]]></release>

<release version="2.3" date="2011-12-28"><![CDATA[
* Added more safety check to URL parsing.
* Improved `plh-utility.xsl` internals.
]]></release>

<release version="2.2" date="2011-12-22" min="2.2.x"><![CDATA[
* Compatibility release for Frontend Localisation 1.0
]]></release>
Expand Down
36 changes: 26 additions & 10 deletions lang/lang.ro.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,50 @@
'author' => array(
'name' => 'Vlad Ghita',
'email' => 'vlad.ghita@xandergroup.ro',
'website' => ''
),
'release-date' => '2011-09-17'
'release-date' => '2012-02-08'
);

/**
* Page LHandles
*/
$dictionary = array(

'<code>%1$s</code> depends on <code>%2$s</code>. Make sure you have this extension installed and enabled.' =>
'<code>%1$s</code> depends on <code>%2$s</code>. Make sure you have this extension installed and enabled.' =>
'<code>%1$s</code> depinde de <code>%2$s</code>. 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 <b>%1$s - %2$s</b> language, prefixed by language code.<br />E.g. <code>Romana : Acasa => English : ENAcasa</code>' =>
'Actualizează Titlul şi Handleul fiecărei Pagini cu valoarea pentru limba <b>%1$s - %2$s</b>, prefixată de codul de limbă.<br />Ex: <code>Romana : Acasa => English : ENAcasa</code>',
'Actualizează Titlul şi Handleul fiecărei Pagini cu valorile de la limba <b>%1$s - %2$s</b>, prefixate de codul de limbă.<br />Ex. <code>Romana : Acasa => English : ENAcasa</code>',

'Compatibility mode for URL Router. Enable this to use URLs like: <code>site.com/clients/_param1_/projects/_param2_/</b>. If you\'ll have <code>_param1_ = `projects`</code>, that will be a collision and Page LHandles will fail.' =>
'Mod de compatibilitate pentru URL Router. Activează pentru a folosi URLuri de genul: <code>site.com/clients/_param1_/projects/_param2_/</code>. Dacă vei avea <code>_param1_ = `projects`</code>, aceasta va fi o coliziune şi Page LHandles va da rezultate eronate.',

'Page LHandles' =>
false,

'Operating mode' =>
'Modul de operare',

);
108 changes: 81 additions & 27 deletions lib/class.PLHManagerURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ 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
INNER JOIN `tbl_pages_types` as pt ON pt.`page_id` = p.`id`
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 ){
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -209,4 +262,5 @@ private function _getPageHandle($query, &$last_parent, $target_handle) {

return false;
}

}
Loading

0 comments on commit 0595d25

Please sign in to comment.