本文整理汇总了PHP中JLanguageHelper::getLanguages方法的典型用法代码示例。如果您正苦于以下问题:PHP JLanguageHelper::getLanguages方法的具体用法?PHP JLanguageHelper::getLanguages怎么用?PHP JLanguageHelper::getLanguages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JLanguageHelper
的用法示例。
在下文中一共展示了JLanguageHelper::getLanguages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
/**
* Function for getting the list of languages
*
* @return array Language list
*/
public static function getList()
{
$app = JFactory::getApplication();
$languages = JLanguageHelper::getLanguages();
$db = JFactory::getDbo();
$Itemid = $app->input->getInt('Itemid', 0);
$uri = new JURI(Juri::current());
$uri->delVar('lang');
$uri->delVar('Itemid');
$location = htmlspecialchars($uri->getQuery());
if (!empty($location)) {
$location .= '&';
}
if (!$Itemid) {
$active = $app->getMenu()->getActive();
if ($active) {
$Itemid = $active->id;
}
}
// For every language we load menu items language specific alias and params
foreach ($languages as $i => $language) {
$db->forceLanguageTranslation = $language->lang_code;
RMenu::resetJoomlaMenuItems();
$db->forceLanguageTranslation = false;
$languages[$i]->active = $language->lang_code == JFactory::getLanguage()->getTag();
$languages[$i]->link = RRoute::_('index.php?' . $location . 'lang=' . $language->sef . ($Itemid > 0 ? '&Itemid=' . $Itemid : ''));
}
// After we are done we reset it the way it was
RMenu::resetJoomlaMenuItems();
return $languages;
}
示例2: getUri
/**
* Get Uri
*
* @param string $url URL
*
* @return JUri
*/
public function getUri($url = 'SERVER')
{
static $uriArray = array();
if (!array_key_exists($url, $uriArray)) {
// This will enable both SEF and non-SEF URI to be parsed properly
$router = clone JRouter::getInstance('site');
$uri = clone JUri::getInstance($url);
$langCode = JLanguageHelper::detectLanguage();
$lang = $uri->getVar('lang', $langCode);
$uri->setVar('lang', $lang);
$sefs = JLanguageHelper::getLanguages('lang_code');
if (isset($sefs[$lang])) {
$lang = $sefs[$lang]->sef;
$uri->setVar('lang', $lang);
}
$router->setVars(array(), false);
$query = $router->parse($uri);
$query = array_merge($query, $uri->getQuery(true));
$uri->setQuery($query);
// We are removing format because of default value is csv if present and if not set
// and we are never going to remember csv page in a browser history anyway
$uri->delVar('format');
$uriArray[$url] = $uri;
}
return $uriArray[$url];
}
示例3: parseLang
public function parseLang($vars)
{
if (Mijosef::getConfig()->multilang == 0) {
return;
}
if (empty($vars['lang'])) {
$lang = JRequest::getWord('lang', '');
if (empty($lang)) {
return;
}
$vars['lang'] = $lang;
}
$languages = JLanguageHelper::getLanguages('sef');
$lang_code = $languages[$vars['lang']]->lang_code;
// if current language, don't bother
if ($lang_code == JFactory::getLanguage()->getTag()) {
//self::checkHomepage($vars['lang']);
return;
}
// Create a cookie
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
setcookie(JUtility::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
// set the request var
JRequest::setVar('language', $lang_code);
// set current language
jimport('joomla.language.language');
$conf = JFactory::getConfig();
$debug = $conf->get('debug_lang');
$lang = JLanguage::getInstance($lang_code, $debug);
JFactory::$language = $lang;
self::$_lang = $vars['lang'];
}
示例4: _actionCopy
/**
* @param KCommandContext $context
*/
public function _actionCopy(KCommandContext $context)
{
foreach (KRequest::get('get.id', 'raw') as $item_id) {
$this->count = 1;
$items = array();
$languages = JLanguageHelper::getLanguages();
$model_identifier = clone $context->caller->getIdentifier();
$model_identifier->path = array('model');
$model_identifier->name = KInflector::pluralize($model_identifier->name);
$isTranslatable = KService::get($model_identifier)->getTable()->hasBehavior('translatable');
if ($isTranslatable) {
foreach ($languages as $language) {
JFactory::getLanguage()->setLanguage($language->lang_code);
$item = $this->getService($model_identifier)->id($item_id)->getItem();
if ($item->original) {
$this->original_language = $language->lang_code;
$original = $item;
} else {
$items[$language->lang_code] = $item;
}
}
}
JFactory::getLanguage()->setLanguage($this->original_language);
$id = $this->_copyOriginal($original);
if ($isTranslatable) {
$this->_updateLanguages($id, $items);
}
}
}
示例5: preprocessForm
/**
* Auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
* @since 3.0
*/
protected function preprocessForm(JForm $form, $data, $group = 'jevents')
{
// Association content items
$app = JFactory::getApplication();
$assoc = false && JLanguageAssociations::isEnabled() && JFactory::getApplication()->isAdmin();
if ($assoc) {
$languages = JLanguageHelper::getLanguages('lang_code');
$addform = new SimpleXMLElement('<form />');
$fields = $addform->addChild('fields');
$fields->addAttribute('name', 'associations');
$fieldset = $fields->addChild('fieldset');
$fieldset->addAttribute('name', 'item_associations');
$fieldset->addAttribute('description', 'COM_JEVENTS_ITEM_ASSOCIATIONS_FIELDSET_DESC');
$add = false;
foreach ($languages as $tag => $language) {
if (empty($data->language) || $tag != $data->language) {
$add = true;
$field = $fieldset->addChild('field');
$field->addAttribute('name', $tag);
$field->addAttribute('type', 'modal_article');
$field->addAttribute('language', $tag);
$field->addAttribute('label', $language->title);
$field->addAttribute('translate_label', 'false');
$field->addAttribute('edit', 'true');
$field->addAttribute('clear', 'true');
}
}
if ($add) {
$form->load($addform, false);
}
}
parent::preprocessForm($form, $data, $group);
}
示例6: getContacts
public static function getContacts()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select('u.name, count(cd.language) as counted, MAX(cd.language=' . $db->quote('*') . ') as all_languages')->from('#__users AS u')->join('LEFT', '#__contact_details AS cd ON cd.user_id=u.id')->join('LEFT', '#__languages as l on cd.language=l.lang_code')->where('EXISTS (SELECT * from #__content as c where c.created_by=u.id)')->where('(l.published=1 or cd.language=' . $db->quote('*') . ')')->where('cd.published=1')->group('u.id')->having('(counted !=' . count(JLanguageHelper::getLanguages()) . ' OR all_languages=1)')->having('(counted !=1 OR all_languages=0)');
$db->setQuery($query);
return $db->loadObjectList();
}
示例7: isHome
/**
* Detect is this page are frontpage?
*
* @return boolean Is frontpage?
*/
public static function isHome()
{
$langPath = null;
$tag = null;
$lang = \JFactory::getLanguage();
// For multi language
if (\JPluginHelper::isEnabled('system', 'languagefilter')) {
$tag = $lang->getTag();
$langCodes = \JLanguageHelper::getLanguages('lang_code');
$langPath = $langCodes[$tag]->sef;
}
$uri = \JUri::getInstance();
$root = $uri::root(true);
// Get site route
$route = StringHelper::substr($uri->getPath(), StringHelper::strlen($root));
// Remove index.php
$route = str_replace('index.php', '', $route);
// If Multiple language enabled, we check first part of URI is language code or not.
if ($langPath) {
$params = ExtensionHelper::getParams('plg_system_languagefilter');
if ($tag == $lang->getDefault() && $params->get('remove_default_prefix', 0)) {
$langPath = '';
}
// If route equals lang path, means it is home route.
if (trim($route, '/') == $langPath && !$uri->getVar('option')) {
return true;
}
} else {
if (!trim($route, '/') && !$uri->getVar('option')) {
return true;
}
}
return false;
}
示例8: loadMultilangData
function loadMultilangData($prepareElementCallback)
{
$languages = JLanguageHelper::getLanguages();
$app = JApplication::getInstance('site');
$menu = $app->getMenu();
$config = JFactory::getConfig();
$sef = $config->get('sef', 0);
$sefRewrite = $config->get('sef_rewrite', 0);
$defaultLangCode = JFactory::getLanguage()->getDefault();
$websites = array();
//$websites['*'] = $menu->getDefault('*'); // TODO add?
$languageFilterEnabled = JPluginHelper::isEnabled('system', 'languagefilter');
if (!$languageFilterEnabled || $sef != '1') {
// TODO check also if sef is enabled
return $websites;
}
$oldLanguageFilterValue = $app->setLanguageFilter(true);
// necessary that $menu->getDefault() works
foreach ($languages as $language) {
$langCode = $language->lang_code;
$default = $menu->getDefault($langCode);
if ($default && $default->language == $langCode) {
$websites[$langCode] = $prepareElementCallback($language, $langCode, $defaultLangCode, $sefRewrite);
}
}
$app->setLanguageFilter($oldLanguageFilterValue);
return $websites;
}
示例9: getList
public static function getList(&$params)
{
$lang = JFactory::getLanguage();
$languages = JLanguageHelper::getLanguages();
$db = JFactory::getDBO();
$app = JFactory::getApplication();
$query = $db->getQuery(true);
$query->select('id');
$query->select('language');
$query->from($db->nameQuote('#__menu'));
$query->where('home=1');
$db->setQuery($query);
$homes = $db->loadObjectList('language');
foreach ($languages as $i => &$language) {
// Do not display language without frontend UI
if (!JLanguage::exists($language->lang_code)) {
unset($languages[$i]);
} elseif (!isset($homes[$language->lang_code])) {
unset($languages[$i]);
} else {
if ($app->getLanguageFilter()) {
$language->active = $language->lang_code == $lang->getTag();
if ($app->getCfg('sef') == '1') {
$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
} else {
$language->link = 'index.php?lang=' . $language->sef;
}
} else {
$language->link = 'index.php';
}
}
}
return $languages;
}
示例10: loadHomepages
public function loadHomepages()
{
$app = JFactory::getApplication();
if ($app->isAdmin()) {
return;
}
// store default links in each language
$defaultLanguage = shGetDefaultLang();
jimport('joomla.language.helper');
$languages = JLanguageHelper::getLanguages();
$menu = JFactory::getApplication()->getMenu();
foreach ($languages as $language) {
$menuItem = $menu->getDefault($language->lang_code);
if (!empty($menuItem)) {
$this->homeLinks[$language->lang_code] = $this->_prepareLink($menuItem, $languages);
}
}
// save default link
$this->homeLink = $this->homeLinks[$defaultLanguage];
// find about the "All" languages home link
$menuItem = $menu->getDefault('*');
if (!empty($menuItem)) {
$this->allLangHomeLink = $this->_prepareLink($menuItem, $languages);
}
}
示例11: getInput
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$html = array();
$thisid = $this->id;
$values = $this->value;
$class = $this->class;
$languages = JLanguageHelper::getLanguages();
foreach ($languages as $lang) {
$language = new JLanguage($lang->lang_code);
$this->class = $class . ($language->isRTL() ? ' rtl' : ' ltr');
$this->element['label'] = $lang->title;
$this->name = 'jform[' . $this->fieldname . '][' . $lang->lang_code . ']';
$this->id = $thisid . '_' . $lang->lang_code;
$this->value = array_key_exists($lang->lang_code, $values) ? $values[$lang->lang_code] : '';
$html[] = '<div class="control-group">';
$html[] = '<div class="control-label">';
$html[] = parent::getLabel();
$html[] = '</div>';
$html[] = '<div class="controls">';
$html[] = parent::getInput();
$html[] = '</div>';
$html[] = '</div>';
}
return implode($html);
}
示例12: displayAssociations
/**
* Method to display in frontend the associations for a given article
*
* @param integer $id Id of the article
*
* @return array An array containing the association URL and the related language object
*
* @since __DEPLOY_VERSION__
*/
public static function displayAssociations($id)
{
$return = array();
if ($associations = self::getAssociations($id)) {
$levels = JFactory::getUser()->getAuthorisedViewLevels();
$languages = JLanguageHelper::getLanguages();
foreach ($languages as $language) {
// Do not display language when no association
if (empty($associations[$language->lang_code])) {
continue;
}
// Do not display language without frontend UI
if (!array_key_exists($language->lang_code, JLanguageMultilang::getSiteLangs())) {
continue;
}
// Do not display language without specific home menu
if (!array_key_exists($language->lang_code, JLanguageMultilang::getSiteHomePages())) {
continue;
}
// Do not display language without authorized access level
if (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
continue;
}
$return[$language->lang_code] = array('item' => $associations[$language->lang_code], 'language' => $language);
}
}
return $return;
}
示例13: getLanguageCode
/**
* there is currently no fu***ing other way to get the short language code in Joomla :(
*
* @return string
*/
public static function getLanguageCode()
{
if (is_null(self::$languageCode)) {
$languages = JLanguageHelper::getLanguages('lang_code');
self::$languageCode = $languages[JFactory::getLanguage()->getTag()]->sef;
}
return self::$languageCode;
}
示例14: getList
public static function getList(&$params)
{
$user = JFactory::getUser();
$lang = JFactory::getLanguage();
$app = JFactory::getApplication();
$menu = $app->getMenu();
// Get menu home items
$homes = array();
foreach ($menu->getMenu() as $item) {
if ($item->home) {
$homes[$item->language] = $item;
}
}
// Load associations
$assoc = isset($app->menu_associations) ? $app->menu_associations : 0;
if ($assoc) {
$active = $menu->getActive();
if ($active) {
$associations = MenusHelper::getAssociations($active->id);
}
}
$levels = $user->getAuthorisedViewLevels();
$languages = JLanguageHelper::getLanguages();
// Filter allowed languages
foreach ($languages as $i => &$language) {
// Do not display language without frontend UI
if (!JLanguage::exists($language->lang_code)) {
unset($languages[$i]);
} elseif (!isset($homes[$language->lang_code])) {
unset($languages[$i]);
} elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
unset($languages[$i]);
} else {
$language->active = $language->lang_code == $lang->getTag();
if ($app->getLanguageFilter()) {
if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
$itemid = $associations[$language->lang_code];
if ($app->getCfg('sef') == '1') {
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
} else {
$language->link = 'index.php?lang=' . $language->sef . '&Itemid=' . $itemid;
}
} else {
if ($app->getCfg('sef') == '1') {
$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
} else {
$language->link = 'index.php?lang=' . $language->sef;
}
}
} else {
$language->link = JRoute::_('&Itemid=' . $homes['*']->id);
}
}
}
return $languages;
}
示例15: getInput
/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
$languageSef = array();
$lang_codes = JLanguageHelper::getLanguages('lang_code');
$languageSef[] = JHTML::_('select.option', '', '-' . JText::_('PLG_EASYLANGUAGE_SELECT_LANG') . '-');
foreach ($lang_codes as $lang) {
$languageSef[] = JHTML::_('select.option', $lang->sef, $lang->title);
}
return JHTML::_('select.genericlist', $languageSef, $this->name, '', 'value', 'text', $this->value);
}