Example #1
0
 function l10n_lang_list($atts)
 {
     global $thisarticle, $l10n_language, $is_article_list, $pretext, $prefs;
     extract(lAtts(array('title' => '', 'on404' => '', 'current_class' => 'l10n_current', 'language_class' => 'long', 'list_class' => 'l10n_lang_list', 'show_empty' => '', 'link_current' => '', 'display' => 'native', 'article_list' => $is_article_list), $atts));
     $on404 = !empty($on404);
     # User marked this list as a 404 special lookup list.
     $show_empty = !empty($show_empty);
     $link_current = !empty($link_current);
     $processing404 = $pretext['status'] === '404';
     $list = array();
     static $alangs;
     $slangs = LanguageHandler::get_site_langs();
     $section = empty($pretext['s']) ? '' : $pretext['s'];
     $id = $pretext['id'];
     $url = trim($_SERVER['REQUEST_URI'], '/');
     $parts = chopUrl($url);
     //echo br , "l10n_lang_list(" , var_dump($atts) , ") Section($section) ID($id)" ;
     //echo br , "url = " , $_SERVER['REQUEST_URI'];
     //echo br , "parts = " , var_dump( $parts );
     if ($on404) {
         #
         #	Find the section and id of the faulting article (if possible)...
         #
         if (empty($id)) {
             $id = gps('id');
         }
         # Try out a messy match first
         if (empty($id)) {
             extract($parts);
             //echo br , 'permlink_mode = ' , $prefs['permlink_mode'];
             switch ($prefs['permlink_mode']) {
                 case 'section_id_title':
                     $id = $u1;
                     break;
                 case 'year_month_day_title':
                     $when = "{$u0}-{$u1}-{$u2}";
                     $rs = safe_row("ID,Section", "l10n_master_textpattern", "posted like '" . doSlash($when) . "%' and url_title like '" . doSlash($u3) . "' and Status >= 4 limit 1");
                     $id = !empty($rs['ID']) ? $rs['ID'] : '';
                     break;
                 case 'section_title':
                     $rs = safe_row("ID,Section", 'l10n_master_textpattern', "url_title like '" . doSlash($u1) . "' AND Section='" . doSlash($u0) . "' and Status >= 4 limit 1");
                     $id = @$rs['ID'];
                     break;
                 case 'title_only':
                     $rs = safe_row("ID", 'l10n_master_textpattern', "url_title like '" . doSlash($u0) . "' and Status >= 4 limit 1");
                     $id = @$rs['ID'];
                     break;
                 case 'id_title':
                     $id = $u0;
                     break;
             }
         }
         if (!empty($id) and is_numeric($id)) {
             $article_list = false;
         } else {
             return '';
         }
         #
         #	Make sure we show all alternatives, even if they are in the current language...
         #
         $link_current = true;
     }
     $show_title = !empty($title);
     if (!$article_list) {
         if (!isset($alangs) or !is_array($alangs)) {
             $alangs = ArticleManager::get_alternate_mappings($id, 'nothing', true);
         }
         //echo br , 'alangs = ' , var_dump( $alangs );
         if ($show_title) {
             $show_title = !empty($alangs);
         }
     }
     if ($show_title) {
         $title = tag($title, 'p') . n;
     } else {
         $title = '';
     }
     foreach ($slangs as $lang) {
         $codes = LanguageHandler::compact_code($lang);
         $short = $codes['short'];
         $long = $codes['long'];
         $dir = LanguageHandler::get_lang_direction_markup($lang);
         switch ($display) {
             case 'short':
                 $lname = $short;
                 break;
             case 'long':
                 $lname = $long;
                 break;
             case 'native+':
                 $lname = LanguageHandler::get_native_name_of_lang($lang) . " [{$short}]";
                 break;
             case 'native++':
                 $lname = LanguageHandler::get_native_name_of_lang($lang) . " [{$long}]";
                 break;
             default:
                 $lname = LanguageHandler::get_native_name_of_lang($lang);
                 break;
         }
         if ($article_list) {
             #
             #	No individual ID but we should be able to serve all the languages
             # so use the current url and inject the language component into each one...
             #
             $current = $l10n_language['long'] === $lang;
             $text = tag($lname, 'span', $dir);
             #
             #	Prep the line class...
             #
             $class = 'short' === $language_class ? $short : $lang;
             if ($current) {
                 $class .= ' ' . $current_class;
             }
             $class = ' class="' . $class . '"';
             if (!$current or $link_current) {
                 $uri = rtrim($_SERVER['REQUEST_URI'], '/');
                 if ($processing404) {
                     $uri = '';
                 }
                 $line = '<a href="' . hu . $short . $uri . '">' . $text . '</a>';
             } else {
                 $line = $text;
             }
             $list[] = tag($line, 'li', $class);
         } else {
             #
             #	If a translation exists for that language then we
             # build a valid url to it and make it active in the list, otherwise include it in the
             # list but wihtout the hyper-link.
             #
             #	The active page is marked up with a css class.
             #
             if (array_key_exists($lang, $alangs)) {
                 $record = $alangs[$lang];
                 $lang_rendition_title = $record['title'];
                 $lang_rendition_id = $record['id'];
                 $current = $l10n_language['long'] === $lang;
                 $text = $lname;
                 if ($processing404) {
                     $text = strong($text) . sp . ':' . sp . $lang_rendition_title;
                 }
                 $text = tag($text, 'span', $dir);
                 #
                 #	Prep the line class...
                 #
                 $class = 'short' === $language_class ? $short : $lang;
                 if ($current) {
                     $class .= ' ' . $current_class;
                 }
                 $class = ' class="' . $class . '"';
                 if (!$current or $link_current) {
                     //$line = '<a href="'.hu.$short.$section.'/'.$alangs[$lang].'">'.$text.'</a>';
                     #
                     #	Use messy urls to avoid permlink pattern processing...
                     #
                     $line = '<a href="' . hu . $short . '/?id=' . $lang_rendition_id . '">' . $text . '</a>';
                 } else {
                     $line = $text;
                 }
                 $list[] = tag($line, 'li', $class);
             } else {
                 if ($show_empty) {
                     $list[] = tag($lname, 'li');
                 }
             }
         }
     }
     $list = tag(join("\n\t", $list), 'ul', " class=\"{$list_class}\"");
     return $title . $list;
 }