Skip to content

Commit

Permalink
add lang_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno17 committed Apr 13, 2014
1 parent f6b5c3b commit 9a3e238
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="[[++cultureKey]]" dir="[[++lang_dir]]">
<head>
<meta charset="[[++modx_charset]]">
<title>[[++site_name]] - [[+mml_pagetitle]]</title>
Expand All @@ -16,7 +16,7 @@
<div id="container">
<header>
<a href="#" id="logo"><img src="/assets/images/logo.png" width="180" height="43" alt="logo"/></a>
[[!mml_LangLinks]]
[[!mmlLangLinks]]
<nav>
[[!pdoMenu?
&startId=`0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ function clientLangDetect()

$_SESSION['mml_settings'] = array();
if (!empty($_REQUEST['cultureKey'])) {
$language = $languages[$_REQUEST['cultureKey']];
$_SESSION['cultureKey'] = $_REQUEST['cultureKey'];
$_SESSION['mml_settings']['cultureKey'] = $_REQUEST['cultureKey'];
$_SESSION['mml_settings']['lang_dir'] = $language['lang_dir'];
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,3 @@
//[[!mml_LangLinks]]

$outputSeparator = $modx->getOption('outputSeparator', $scriptProperties, '');
$tpl = $modx->getOption('tpl', $scriptProperties, 'mml_LinkTpl');

$wrapper = '<ul class="mml_links">[[+output]]</ul>';
$wrapper = $modx->getOption('wrapper', $scriptProperties, $wrapper);

$cultureKey = $modx->getOption('cultureKey');
$site_url = $modx->getOption('site_url');
$furls = $modx->getOption('friendly_urls');

$packageName = 'migxmultilang';

$packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
$modelpath = $packagepath . 'model/';
if (is_dir($modelpath)) {
$modx->addPackage($packageName, $modelpath, $prefix);
}
$classname = 'mmlLang';

$c = $modx->newQuery($classname);
$output = array();

$c->sortby('pos');

if ($collection = $modx->getCollection($classname, $c)) {

if ($furls == '1') {
$url = $modx->makeUrl($modx->resource->get('id'));
$base_url = $modx->getOption('base_url');
$url = $modx->makeUrl($modx->resource->get('id'));
if ($url == $base_url) {
$url = '';
}
$site_url = str_replace('/' . $cultureKey . '/', '', $site_url);
}


foreach ($collection as $object) {
$lang_key = $object->get('lang_key');
$class = ($lang_key == $cultureKey) ? 'class="active"' : '';
$row = $object->toArray();

if ($furls == '1') {
$lang_key = !empty($lang_key) ? $lang_key . '/' : '';
$row['link'] = rtrim($site_url, '/') . '/' . $lang_key . $url;
} else {
$row['link'] = $modx->makeUrl($modx->resource->get('id'), null, 'cultureKey=' . $lang_key);
}


$row['class'] = $class;
$output[] = $modx->getChunk($tpl, $row);
}
}

$output = implode($outputSeparator, $output);
$output = str_replace('[[+output]]', $output, $wrapper);

return $output;
return $modx->runSnippet('mmlLangLinks',$scriptProperties);
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//[[!mmlLangLinks]]

$outputSeparator = $modx->getOption('outputSeparator', $scriptProperties, '');
$tpl = $modx->getOption('tpl', $scriptProperties, 'mml_LinkTpl');

$wrapper = '<ul class="mml_links">[[+output]]</ul>';
$wrapper = $modx->getOption('wrapper', $scriptProperties, $wrapper);

$cultureKey = $modx->getOption('cultureKey');
$site_url = $modx->getOption('site_url');
$furls = $modx->getOption('friendly_urls');

$packageName = 'migxmultilang';

$packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
$modelpath = $packagepath . 'model/';
if (is_dir($modelpath)) {
$modx->addPackage($packageName, $modelpath, $prefix);
}
$classname = 'mmlLang';

$c = $modx->newQuery($classname);
$output = array();

$c->sortby('pos');

if ($collection = $modx->getCollection($classname, $c)) {

$qs = $modx->request->getParameters();

if ($furls == '1') {
$url = $modx->makeUrl($modx->resource->get('id'), null, $qs);
$base_url = $modx->getOption('base_url');
if ($url == $base_url) {
$url = '';
}
$site_url = str_replace('/' . $cultureKey . '/', '', $site_url);
}


foreach ($collection as $object) {
$lang_key = $object->get('lang_key');
$class = ($lang_key == $cultureKey) ? 'class="active"' : '';
$row = $object->toArray();

if ($furls == '1') {
$lang_key = !empty($lang_key) ? $lang_key . '/' : '';
$row['link'] = rtrim($site_url, '/') . '/' . $lang_key . $url;
} else {
$qs['cultureKey'] = $lang_key;
$row['link'] = $modx->makeUrl($modx->resource->get('id'), null, $qs );
}


$row['class'] = $class;
$output[] = $modx->getChunk($tpl, $row);
}
}

$output = implode($outputSeparator, $output);
$output = str_replace('[[+output]]', $output, $wrapper);

return $output;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
&includeTVs=`[[mmlGetTemplateTVs]]`
&prepareTVs=`1`
&processTVs=`1`
&includeContent=`1`
&tvPrefix=``
&loadModels=`migxmultilang`
&prepareSnippet = `mmlTranslatePdoToolsRow`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
"sources":"[]",
"inputOptionValues":"",
"default":""
},
{
"MIGX_id":3,
"field":"lang_dir",
"caption":"Lang Direction",
"description":"",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"listbox",
"validation":"",
"configs":"",
"display":"",
"sourceFrom":"config",
"sources":"[]",
"inputOptionValues":"ltr||rtl",
"default":"ltr"
}
]
}
Expand All @@ -50,7 +66,10 @@
"maxRecords":"",
"addNewItemAt":"bottom",
"multiple_formtabs":"",
"actionbuttonsperrow":4,
"winbuttonslist":"",
"extrahandlers":"this.handlePositionSelector",
"filtersperrow":4,
"packageName":"migxmultilang",
"classname":"mmlLang",
"task":"",
Expand Down Expand Up @@ -131,7 +150,7 @@
"createdby":1,
"createdon":"2014-01-06 11:39:28",
"editedby":1,
"editedon":"2014-03-13 13:12:22",
"editedon":"2014-04-13 06:22:03",
"deleted":0,
"deletedon":"-1-11-30 00:00:00",
"deletedby":0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
array (
'language' => '',
'lang_key' => '',
'lang_dir' => 'ltr',
'createdon' => NULL,
'active' => 0,
'properties' => NULL,
Expand All @@ -33,6 +34,14 @@
'default' => '',
'index' => 'index',
),
'lang_dir' =>
array (
'dbtype' => 'varchar',
'precision' => '3',
'phptype' => 'string',
'null' => false,
'default' => 'ltr',
),
'createdon' =>
array (
'dbtype' => 'datetime',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<object class="mmlLang" table="mml_languages" extends="xPDOSimpleObject">
<field key="language" dbtype="varchar" precision="50" phptype="string" null="false" default="" index="index" />
<field key="lang_key" dbtype="varchar" precision="2" phptype="string" null="false" default="" index="index" />
<field key="lang_dir" dbtype="varchar" precision="3" phptype="string" null="false" default="ltr" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="active" dbtype="tinyint" precision="1" phptype="integer" attributes="unsigned" null="false" default="0" />
<field key="properties" dbtype="text" phptype="array" null="true" />
Expand Down

0 comments on commit 9a3e238

Please sign in to comment.