本文整理汇总了PHP中JLanguage::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP JLanguage::exists方法的具体用法?PHP JLanguage::exists怎么用?PHP JLanguage::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JLanguage
的用法示例。
在下文中一共展示了JLanguage::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialise
/**
* Initialise the application.
*
* @param array An optional associative array of configuration settings.
*/
function initialise($options = array())
{
$config =& JFactory::getConfig();
// if a language was specified it has priority
// otherwise use user or default language settings
if (empty($options['language'])) {
$user =& JFactory::getUser();
$lang = $user->getParam('admin_language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$params = JComponentHelper::getParams('com_languages');
$client =& JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get($client->name, $config->getValue('config.language', 'en-GB'));
}
}
// One last check to make sure we have something
if (!JLanguage::exists($options['language'])) {
$lang = $config->getValue('config.language', 'en-GB');
if (JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$options['language'] = 'en-GB';
// as a last ditch fail to english
}
}
parent::initialise($options);
}
示例2: testExists
/**
* Test...
*
* @covers JLanguage::exists
* @todo Implement testExists().
*
* @return void
*/
public function testExists()
{
$this->assertFalse($this->object->exists(null));
$basePath = __DIR__ . '/data';
$this->assertTrue($this->object->exists('en-GB', $basePath));
$this->assertFalse($this->object->exists('es-ES', $basePath));
}
示例3: 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;
}
示例4: initialise
/**
* Initialise the application.
*
* @param array $options An optional associative array of configuration settings.
*
* @return void
* @since 1.5
*/
public function initialise($options = array())
{
$config = JFactory::getConfig();
// if a language was specified it has priority
// otherwise use user or default language settings
if (empty($options['language'])) {
$user = JFactory::getUser();
$lang = $user->getParam('admin_language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$params = JComponentHelper::getParams('com_languages');
$client = JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get($client->name, $config->get('language', 'es-LA'));
}
}
// One last check to make sure we have something
if (!JLanguage::exists($options['language'])) {
$lang = $config->get('language', 'es-LA');
if (JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$options['language'] = 'es-LA';
// as a last ditch fail to english
}
}
// Execute the parent initialise method.
parent::initialise($options);
// Load Library language
$lang = JFactory::getLanguage();
$lang->load('lib_joomla', JPATH_ADMINISTRATOR, null, false, true);
}
示例5: initialise
/**
* Initialise the application.
*
* @access public
*/
function initialise( $options = array())
{
// if a language was specified it has priority
// otherwise use user or default language settings
if (empty($options['language']))
{
$user = & JFactory::getUser();
$lang = $user->getParam( 'language' );
// Make sure that the user's language exists
if ( $lang && JLanguage::exists($lang) ) {
$options['language'] = $lang;
}
else
{
$params = JComponentHelper::getParams('com_extensions');
$client =& JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get('language_'.$client->name, 'en-GB');
}
}
// One last check to make sure we have something
if ( ! JLanguage::exists($options['language']) ) {
$options['language'] = 'en-GB';
}
parent::initialise($options);
}
示例6: 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;
}
示例7: initialise
/**
* Method to initialise the database
*
* @param array $options The options to use for configuration
*
* @return boolean
*
* @since 3.0
*/
public function initialise($options)
{
// Get the options as a object for easier handling.
$options = JArrayHelper::toObject($options);
// Load the back-end language files so that the DB error messages work
$lang = JFactory::getLanguage();
$currentLang = $lang->getTag();
// Load the selected language
if (JLanguage::exists($currentLang, JPATH_ADMINISTRATOR)) {
$lang->load('joomla', JPATH_ADMINISTRATOR, $currentLang, true);
} else {
$lang->load('joomla', JPATH_ADMINISTRATOR, 'en-GB', true);
}
// Ensure a database type was selected.
if (empty($options->db_type)) {
$this->setError(JText::_('INSTL_DATABASE_INVALID_TYPE'));
return false;
}
// Ensure that a hostname and user name were input.
if (empty($options->db_host) || empty($options->db_user)) {
$this->setError(JText::_('INSTL_DATABASE_INVALID_DB_DETAILS'));
return false;
}
// Ensure that a database name was input.
if (empty($options->db_name)) {
$this->setError(JText::_('INSTL_DATABASE_EMPTY_NAME'));
return false;
}
// Validate database table prefix.
if (!preg_match('#^[a-zA-Z]+[a-zA-Z0-9_]*$#', $options->db_prefix)) {
$this->setError(JText::_('INSTL_DATABASE_PREFIX_INVALID_CHARS'));
return false;
}
// Validate length of database table prefix.
if (strlen($options->db_prefix) > 15) {
$this->setError(JText::_('INSTL_DATABASE_FIX_TOO_LONG'));
return false;
}
// Validate length of database name.
if (strlen($options->db_name) > 64) {
$this->setError(JText::_('INSTL_DATABASE_NAME_TOO_LONG'));
return false;
}
// Get a database object.
try {
return InstallationHelperDatabase::getDbo($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix, $options->db_select);
} catch (RuntimeException $e) {
$this->setError(JText::sprintf('INSTL_DATABASE_COULD_NOT_CONNECT', $e->getMessage()));
return false;
}
}
示例8: parseRule
public function parseRule(&$router, &$uri)
{
$array = array();
$lang_code = JRequest::getString(JUtility::getHash('language'), null, 'cookie');
if (!$lang_code) {
$lang_code = JLanguageHelper::detectLanguage();
}
if (self::$mode_sef) {
$path = $uri->getPath();
$parts = explode('/', $path);
$sef = $parts[0];
if (!isset(self::$sefs[$sef])) {
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setPath($sef . '/' . $path);
$post = JRequest::get('POST');
if (JRequest::getMethod() != "POST" || count($post) == 0) {
$app = JFactory::getApplication();
if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
} else {
$app->redirect($uri->base() . 'index.php/' . $uri->toString(array('path', 'query', 'fragment')));
}
}
}
$lang_code = self::$sefs[$sef]->lang_code;
if ($lang_code && JLanguage::exists($lang_code)) {
array_shift($parts);
$uri->setPath(implode('/', $parts));
}
} else {
$sef = $uri->getVar('lang');
if (!isset(self::$sefs[$sef])) {
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setVar('lang', $sef);
$post = JRequest::get('POST');
if (JRequest::getMethod() != "POST" || count($post) == 0) {
$app = JFactory::getApplication();
$app->redirect(JURI::base(true) . '/index.php?' . $uri->getQuery());
}
}
}
$array = array('lang' => $sef);
return $array;
}
示例9: parseRule
public function parseRule(&$router, &$uri)
{
$array = array();
$lang_code = JRequest::getString(JUtility::getHash('language'), null, 'cookie');
// No cookie - let's try to detect browser language or use site default
if (!$lang_code) {
if ($this->params->get('detect_browser', 1)) {
$lang_code = JLanguageHelper::detectLanguage();
} else {
$lang_code = self::$default_sef;
}
}
if (self::$mode_sef) {
$path = $uri->getPath();
$parts = explode('/', $path);
$sef = $parts[0];
$app = JFactory::getApplication();
// Redirect only if not in post
$post = JRequest::get('POST');
if (JRequest::getMethod() != "POST" || count($post) == 0) {
if ($this->params->get('remove_default_prefix', 0) == 0) {
// redirect if sef does not exists
if (!isset(self::$sefs[$sef])) {
// Use the current language sef or the default one
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setPath($sef . '/' . $path);
if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
} else {
$path = $uri->toString(array('path', 'query', 'fragment'));
$app->redirect($uri->base() . 'index.php' . ($path ? '/' . $path : ''));
}
}
} else {
// redirect if sef does not exists and language is not the default one
if (!isset(self::$sefs[$sef]) && $lang_code != self::$default_lang) {
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setPath($sef . '/' . $path);
if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
} else {
$path = $uri->toString(array('path', 'query', 'fragment'));
$app->redirect($uri->base() . 'index.php' . ($path ? '/' . $path : ''));
}
} elseif ($sef == self::$default_sef) {
array_shift($parts);
$uri->setPath(implode('/', $parts));
if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
} else {
$path = $uri->toString(array('path', 'query', 'fragment'));
$app->redirect($uri->base() . 'index.php' . ($path ? '/' . $path : ''));
}
}
}
}
$lang_code = isset(self::$sefs[$sef]) ? self::$sefs[$sef]->lang_code : '';
if ($lang_code && JLanguage::exists($lang_code)) {
array_shift($parts);
$uri->setPath(implode('/', $parts));
}
} else {
$sef = $uri->getVar('lang');
if (!isset(self::$sefs[$sef])) {
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setVar('lang', $sef);
$post = JRequest::get('POST');
if (JRequest::getMethod() != "POST" || count($post) == 0) {
$app = JFactory::getApplication();
$app->redirect(JURI::base(true) . '/index.php?' . $uri->getQuery());
}
}
}
$array = array('lang' => $sef);
return $array;
}
示例10: initialiseApp
/**
* Initialise the application.
*
* @param array $options An optional associative array of configuration settings.
*
* @return void
*
* @since 3.2
*/
protected function initialiseApp($options = array())
{
$user = JFactory::getUser();
// If the user is a guest we populate it with the guest user group.
if ($user->guest) {
$guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
$user->groups = array($guestUsergroup);
}
/*
* If a language was specified it has priority, otherwise use user or default language settings
* Check this only if the languagefilter plugin is enabled
*
* @TODO - Remove the hardcoded dependency to the languagefilter plugin
*/
if (JPluginHelper::isEnabled('system', 'languagefilter')) {
$plugin = JPluginHelper::getPlugin('system', 'languagefilter');
$pluginParams = new Registry($plugin->params);
$this->setLanguageFilter(true);
$this->setDetectBrowser($pluginParams->get('detect_browser', '1') == '1');
}
if (empty($options['language'])) {
// Detect the specified language
$lang = $this->input->getString('language', null);
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if ($this->getLanguageFilter() && empty($options['language'])) {
// Detect cookie language
$lang = $this->input->cookie->get(md5($this->get('secret') . 'language'), null, 'string');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if (empty($options['language'])) {
// Detect user language
$lang = $user->getParam('language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if ($this->getDetectBrowser() && empty($options['language'])) {
// Detect browser language
$lang = JLanguageHelper::detectLanguage();
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if (empty($options['language'])) {
// Detect default language
$params = JComponentHelper::getParams('com_languages');
$options['language'] = $params->get('site', $this->get('language', 'en-GB'));
}
// One last check to make sure we have something
if (!JLanguage::exists($options['language'])) {
$lang = $this->config->get('language', 'en-GB');
if (JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
// As a last ditch fail to english
$options['language'] = 'en-GB';
}
}
// Finish initialisation
parent::initialiseApp($options);
}
示例11: onAfterDispatch
/**
* This method adds alternate meta tags for associated menu items
*
* @return nothing
* @since 1.7
*/
public function onAfterDispatch()
{
if (App::isSite() && $this->params->get('alternate_meta') && Document::getType() == 'html') {
// Get active menu item
$active = App::get('menu')->getActive();
if (!$active) {
return;
}
// Get menu item link
if (Config::get('sef')) {
$active_link = Route::url('index.php?Itemid=' . $active->id, false);
} else {
$active_link = Route::url($active->link . '&Itemid=' . $active->id, false);
}
if ($active_link == JUri::base(true) . '/') {
$active_link .= 'index.php';
}
// Get current link
$current_link = Request::getUri();
if ($current_link == Request::base(true) . '/') {
$current_link .= 'index.php';
}
// Check the exact menu item's URL
if ($active_link == $current_link) {
// Get menu item associations
JLoader::register('MenusHelper', PATH_CORE . '/components/com_menus/admin/helpers/menus.php');
$associations = MenusHelper::getAssociations($active->id);
// Remove current menu item
unset($associations[$active->language]);
// Associated menu items in other languages
if ($associations && $this->params->get('menu_associations')) {
$menu = App::get('menu');
$server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
foreach (JLanguageHelper::getLanguages() as $language) {
if (isset($associations[$language->lang_code])) {
$item = $menu->getItem($associations[$language->lang_code]);
if ($item && Lang::exists($language->lang_code)) {
if (Config::get('sef')) {
$link = Route::url('index.php?Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef);
} else {
$link = Route::url($item->link . '&Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef);
}
// Check if language is the default site language and remove url language code is on
if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') {
$relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1);
Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code));
} else {
Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
}
}
}
}
} elseif ($active->home) {
$menu = App::get('menu');
$server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
foreach (JLanguageHelper::getLanguages() as $language) {
$item = $menu->getDefault($language->lang_code);
if ($item && $item->language != $active->language && $item->language != '*' && JLanguage::exists($language->lang_code)) {
if (Config::get('sef')) {
$link = Route::url('index.php?Itemid=' . $item->id . '&lang=' . $language->sef);
} else {
$link = Route::url($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
}
// Check if language is the default site language and remove url language code is on
if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') {
$relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1);
Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code));
} else {
Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
}
}
}
}
}
}
}
示例12: onAfterDispatch
/**
* Method to add alternative meta tags for associated menu items.
*
* @return void
*
* @since 1.7
*/
public function onAfterDispatch()
{
$doc = JFactory::getDocument();
$menu = $this->app->getMenu();
$server = JUri::getInstance()->toString(array('scheme', 'host', 'port'));
$option = $this->app->input->get('option');
$eName = JString::ucfirst(JString::str_ireplace('com_', '', $option));
if ($this->app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') {
// Get active menu item.
$active = $menu->getActive();
$assocs = array();
$home = false;
// Load menu associations.
if ($active) {
$active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false);
// Get current link.
$current_link = JUri::getInstance()->toString(array('path', 'query'));
// Check the exact menu item's URL.
if ($active_link == $current_link) {
$associations = MenusHelper::getAssociations($active->id);
unset($associations[$active->language]);
$assocs = array_keys($associations);
// If the menu item is a home menu item and the URLs are identical, we are on the homepage
$home = true;
}
}
// Load component associations.
$cName = JString::ucfirst($eName . 'HelperAssociation');
JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php'));
if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) {
$cassociations = call_user_func(array($cName, 'getAssociations'));
$lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language'));
// No cookie - let's try to detect browser language or use site default.
if (!$lang_code) {
if ($this->params->get('detect_browser', 1)) {
$lang_code = JLanguageHelper::detectLanguage();
} else {
$lang_code = $this->default_lang;
}
}
unset($cassociations[$lang_code]);
$assocs = array_merge(array_keys($cassociations), $assocs);
}
// Handle the default associations.
if ($this->params->get('item_associations') || $active && $active->home && $home) {
$languages = JLanguageHelper::getLanguages('lang_code');
foreach ($assocs as $language) {
if (!JLanguage::exists($language)) {
continue;
}
$lang = $languages[$language];
if (isset($cassociations[$language])) {
$link = JRoute::_($cassociations[$language] . '&lang=' . $lang->sef);
// Check if language is the default site language and remove url language code is on
if ($lang->sef == $this->lang_codes[$this->default_lang]->sef && $this->params->get('remove_default_prefix') == '1') {
$link = preg_replace('|/' . $lang->sef . '/|', '/', $link, 1);
}
$doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language));
} elseif (isset($associations[$language])) {
$item = $menu->getItem($associations[$language]);
if ($item) {
$link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $lang->sef);
$doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language));
}
}
}
}
}
}
示例13: initialise
/**
* Initialise the application.
*
* @param array
*/
public function initialise($options = array())
{
$config = JFactory::getConfig();
jimport('joomla.language.helper');
if (empty($options['language'])) {
$lang = JRequest::getString('language', null);
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if ($this->_language_filter && empty($options['language'])) {
// Detect cookie language
jimport('joomla.utilities.utility');
$lang = JRequest::getString(JUtility::getHash('language'), null ,'cookie');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if (empty($options['language'])) {
// Detect user language
$lang = JFactory::getUser()->getParam('language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if ($this->_detect_browser && empty($options['language'])) {
// Detect browser language
$lang = JLanguageHelper::detectLanguage();
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if (empty($options['language'])) {
// Detect default language
$params = JComponentHelper::getParams('com_languages');
$client = JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get($client->name, $config->get('language', 'en-GB'));
}
// One last check to make sure we have something
if (!JLanguage::exists($options['language'])) {
$lang = $config->get('language','en-GB');
if (JLanguage::exists($lang)) {
$options['language'] = $lang;
}
else {
$options['language'] = 'en-GB'; // as a last ditch fail to english
}
}
// Execute the parent initialise method.
parent::initialise($options);
// Load Library language
$lang = JFactory::getLanguage();
$lang->load('lib_joomla', JPATH_SITE)
|| $lang->load('lib_joomla', JPATH_ADMINISTRATOR);
}
示例14: sendInvitations
/**
* Envía la invitación a calificar a los clientes
* @return void
*/
function sendInvitations()
{
$option = JRequest::getCmd('option');
$params =& JComponentHelper::getParams('com_catalogo_planes');
$max_attempts = (int) $params->get('cfg_comments_invitation');
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__cp_pending_comments WHERE end_date < CURDATE()';
// Si se ha definido un máximo de envío de correos, agregar a consulta.
if ($max_attempts) {
$max_attempts++;
$query .= ' AND total_attempts < ' . $max_attempts;
}
$db->setQuery($query);
$result = $db->loadObjectList();
if (count($result)) {
$msg = JText::_('CP.COMMENTS_EMAIL_SENT');
$type = 'message';
$link = JURI::root() . 'index.php?option=' . $option . '&view=comments&layout=display&id=';
$lang =& JFactory::getLanguage();
$languages = array();
$langparams = JComponentHelper::getParams('com_languages');
$langTag = $defaultLang = $langparams->get("site");
// Si el idioma actual no es el idioma por defecto, cargarlo
if ($langTag != $lang->getTag()) {
$lang =& JLanguage::getInstance($langTag);
$lang->load($option);
}
$languages[$langTag] = $lang;
// Preparar envío de correo
$mailer =& JFactory::getMailer();
$config =& JFactory::getConfig();
$sender = array($config->getValue('config.mailfrom'), $config->getValue('config.fromname'));
$mailer->setSender($sender);
$mailer->isHTML(true);
// Enviar correo por cada reserva pendiente
foreach ($result as $row) {
$langTag = $row->language;
// Carga el idioma de la reserva para enviar el correo
if (isset($languages[$langTag])) {
$lang =& $languages[$langTag];
} else {
if (JLanguage::exists($langTag)) {
$lang =& JLanguage::getInstance($langTag);
$lang->load($option);
} else {
$lang =& $languages[$defaultLang];
}
$languages[$langTag] =& $lang;
}
//print_r($languages[$langTag]->getTag() . ' ' . $languages[$langTag]->_strings['CP.CLONE']);
//echo '<br />';
//print_r(nl2br(sprintf($languages[$langTag]->_strings['CP.COMMENTS_EMAIL_BODY'], $row->contact_name, $row->product_name)));
$email_link = $link . $row->comment_id . '&lang=' . substr($langTag, 0, 2) . '&key=' . base64_encode($row->product_name);
$body = nl2br(sprintf($lang->_('CP.COMMENTS_EMAIL_BODY'), $row->contact_name, $row->product_name, JRoute::_($email_link)));
$subject = sprintf($lang->_('CP.COMMENTS_EMAIL_SUBJECT'), $row->product_name);
$mailer->setSubject($subject);
$mailer->ClearAllRecipients();
$mailer->addRecipient($row->contact_email);
$mailer->setBody($body);
$send =& $mailer->Send();
//echo 'aqui='.$send;die();
if ($send !== true) {
$type = 'error';
$msg = JText::_('CP.COMMENTS_EMAIL_ERROR') . '<div class="hiddenerrormessage">' . $send . '</div>';
break;
} else {
$query = 'UPDATE #__cp_pending_comments SET total_attempts = total_attempts + 1 WHERE comment_id = ' . $row->comment_id;
$db->setQuery($query);
$db->query();
}
}
} else {
$type = 'notice';
$msg = JText::_('CP.COMMENTS_NO_PENDING_INVITATIONS');
}
$this->setRedirect('index.php?option=' . $option . '&view=comments', $msg, $type);
}
示例15: onAfterDispatch
/**
* Method to add alternative meta tags for associated menu items.
*
* @return void
*
* @since 1.7
*/
public function onAfterDispatch()
{
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$menu = $app->getMenu();
$server = JUri::getInstance()->toString(array('scheme', 'host', 'port'));
$option = $app->input->get('option');
$eName = JString::ucfirst(JString::str_ireplace('com_', '', $option));
if ($app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') {
// Get active menu item.
$active = $menu->getActive();
// Load menu associations.
if ($active) {
// Get menu item link.
if ($app->get('sef')) {
$active_link = JRoute::_('index.php?Itemid=' . $active->id, false);
} else {
$active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false);
}
if ($active_link == JUri::base(true) . '/') {
$active_link .= 'index.php';
}
// Get current link.
$current_link = JUri::getInstance()->toString(array('path', 'query'));
if ($current_link == JUri::base(true) . '/') {
$current_link .= 'index.php';
}
// Check the exact menu item's URL.
if ($active_link == $current_link) {
$associations = MenusHelper::getAssociations($active->id);
unset($associations[$active->language]);
}
}
// Load component associations.
$cName = JString::ucfirst($eName . 'HelperAssociation');
JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php'));
if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) {
$cassociations = call_user_func(array($cName, 'getAssociations'));
$lang_code = $app->input->cookie->getString(JApplication::getHash('language'));
// No cookie - let's try to detect browser language or use site default.
if (!$lang_code) {
if ($this->params->get('detect_browser', 1)) {
$lang_code = JLanguageHelper::detectLanguage();
} else {
$lang_code = self::$default_lang;
}
}
unset($cassociations[$lang_code]);
}
// Handle the default associations.
if ((!empty($associations) || !empty($cassociations)) && $this->params->get('item_associations')) {
foreach (JLanguageHelper::getLanguages() as $language) {
if (!JLanguage::exists($language->lang_code)) {
continue;
}
if (isset($cassociations[$language->lang_code])) {
$link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef);
$doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
} elseif (isset($associations[$language->lang_code])) {
$item = $menu->getItem($associations[$language->lang_code]);
if ($item) {
if ($app->get('sef')) {
$link = JRoute::_('index.php?Itemid=' . $item->id . '&lang=' . $language->sef);
} else {
$link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
}
$doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
}
}
}
} elseif ($active && $active->home) {
foreach (JLanguageHelper::getLanguages() as $language) {
if (!JLanguage::exists($language->lang_code)) {
continue;
}
$item = $menu->getDefault($language->lang_code);
if ($item && $item->language != $active->language && $item->language != '*') {
if ($app->get('sef')) {
$link = JRoute::_('index.php?Itemid=' . $item->id . '&lang=' . $language->sef);
} else {
$link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
}
$doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
}
}
}
}
}