Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The dropdown should follow userewrite URLs + Hreflang Support #248

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions action.php
Expand Up @@ -67,6 +67,33 @@ function register(Doku_Event_Handler $controller) {

$controller->register_hook('SEARCH_QUERY_PAGELOOKUP', 'AFTER', $this, 'translation_search');
$controller->register_hook('COMMON_PAGETPL_LOAD', 'AFTER', $this, 'page_template_replacement');
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'inject_hreflangs');
}

/**
* Tell search engines about all localized version of the current page
* @see https://en.wikipedia.org/wiki/Hreflang
*
* @param Doku_Event $event
* @param $args
*/
public function inject_hreflangs(Doku_Event $event, $args)
{
global $ID;

list($lc, $idpart) = $this->helper->getTransParts($ID);
foreach ($this->helper->translations as $iso) {
$trans_id = $this->helper->buildTransID($iso, $idpart);

$translated_id = cleanID($trans_id[0]);
if (page_exists($translated_id)) {
$event->data['link'][] = array(
'rel' => 'alternate',
'hreflang' => $iso,
'href' => wl($translated_id, '', true),
);
}
}
}

/**
Expand Down
4 changes: 1 addition & 3 deletions helper.php
Expand Up @@ -357,9 +357,7 @@ function getTransItem($lc, $idpart) {
// prepare output
$out = '';
if($this->getConf('dropdown')) {
if($conf['useslash']) $link = str_replace(':', '/', $link);

$out .= '<option class="' . $class . '" title="' . hsc($localname) . '" value="' . $link . '"' . $sel . $style . '>';
$out .= '<option class="' . $class . '" title="' . hsc($localname) . '" value="' . wl($link) . '"' . $sel . $style . '>';
$out .= $display;
$out .= '</option>';
} else {
Expand Down
11 changes: 1 addition & 10 deletions script.js
Expand Up @@ -6,15 +6,6 @@ jQuery(function(){
if(!$frm.length) return;
$frm.find('input[name=go]').hide();
$frm.find('select[name=id]').change(function(){
var id = jQuery(this).val();
// this should hopefully detect rewriting good enough:
var action = $frm.attr('action');
if(action.substr(action.length-1) == '/'){
var link = action + id;
}else{
var link = action + '?id=' + id;
}

window.location.href= link;
location.href = this.value;
});
});