Пример #1
1
 /**
  * Display the view.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise an Error object.
  */
 public function display($tpl = null)
 {
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->state = $this->get('State');
     $section = $this->state->get('category.section') ? $this->state->get('category.section') . '.' : '';
     $this->canDo = JHelperContent::getActions($this->state->get('category.component'), $section . 'category', $this->item->id);
     $this->assoc = $this->get('Assoc');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     // Check for tag type
     $this->checkTags = JHelperTags::getTypes('objectList', array($this->state->get('category.extension') . '.category'), true);
     JFactory::getApplication()->input->set('hidemainmenu', true);
     if ($this->getLayout() == 'modal') {
         // If we are forcing a language in modal (used for associations).
         if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
             // Set the language field to the forcedLanguage and disable changing it.
             $this->form->setValue('language', null, $forcedLanguage);
             $this->form->setFieldAttribute('language', 'readonly', 'true');
             // Only allow to select categories with All language or with the forced language.
             $this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage);
             // Only allow to select tags with All language or with the forced language.
             $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
         }
     } elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
         $this->form->setFieldAttribute('language', 'readonly', 'true');
     }
     $this->addToolbar();
     return parent::display($tpl);
 }
Пример #2
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     $options = array();
     foreach ($this->element->children() as $option) {
         // Only add <option /> elements.
         if ($option->getName() != 'option') {
             continue;
         }
         // Filter requirements
         if ($requires = explode(',', (string) $option['requires'])) {
             // Requires multilanguage
             if (in_array('multilanguage', $requires) && !JLanguageMultilang::isEnabled()) {
                 continue;
             }
             // Requires associations
             if (in_array('associations', $requires) && !JLanguageAssociations::isEnabled()) {
                 continue;
             }
         }
         $value = (string) $option['value'];
         $disabled = (string) $option['disabled'];
         $disabled = $disabled == 'true' || $disabled == 'disabled' || $disabled == '1';
         $disabled = $disabled || $this->readonly && $value != $this->value;
         // Create a new option object based on the <option /> element.
         $tmp = JHtml::_('select.option', $value, JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', trim((string) $option))), 'value', 'text', $disabled);
         // Set some option attributes.
         $tmp->class = (string) $option['class'];
         // Set some JavaScript option attributes.
         $tmp->onclick = (string) $option['onclick'];
         // Add the option object to the result set.
         $options[] = $tmp;
     }
     reset($options);
     return $options;
 }
Пример #3
0
 /**
  * Display the view
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  void
  *
  * @since   1.6
  */
 public function display($tpl = null)
 {
     $user = JFactory::getUser();
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->modules = $this->get('Modules');
     $this->levels = $this->get('ViewLevels');
     $this->state = $this->get('State');
     $this->canDo = JHelperContent::getActions('com_menus', 'menu', (int) $this->state->get('item.menutypeid'));
     // Check if we're allowed to edit this item
     // No need to check for create, because then the moduletype select is empty
     if (!empty($this->item->id) && !$this->canDo->get('core.edit')) {
         throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403);
     }
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     if ($this->getLayout() == 'modal') {
         // If we are forcing a language in modal (used for associations).
         if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
             // Set the language field to the forcedLanguage and disable changing it.
             $this->form->setValue('language', null, $forcedLanguage);
             $this->form->setFieldAttribute('language', 'readonly', 'true');
             // Only allow to select categories with All language or with the forced language.
             $this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage);
         }
     } elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
         $this->form->setFieldAttribute('language', 'readonly', 'true');
     }
     parent::display($tpl);
     $this->addToolbar();
 }
Пример #4
0
 /**
  * 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);
 }
Пример #5
0
 /**
  * Display the view.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise an Error object.
  */
 public function display($tpl = null)
 {
     // Initialise variables.
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->state = $this->get('State');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     if ($this->getLayout() == 'modal') {
         // If we are forcing a language in modal (used for associations).
         if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
             // Set the language field to the forcedLanguage and disable changing it.
             $this->form->setValue('language', null, $forcedLanguage);
             $this->form->setFieldAttribute('language', 'readonly', 'true');
             // Only allow to select categories with All language or with the forced language.
             $this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
             // Only allow to select tags with All language or with the forced language.
             $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
         }
     } elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
         $this->form->setFieldAttribute('language', 'readonly', 'true');
     }
     $this->addToolbar();
     return parent::display($tpl);
 }
Пример #6
0
 /**
  * Method to get the field label markup.
  *
  * @return  string  The field label markup.
  *
  * @since   2.5.5
  */
 protected function getLabel()
 {
     $label = '';
     if ($this->hidden) {
         return $label;
     }
     // Get the label text from the XML element, defaulting to the element name.
     $text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
     $text = $this->translateLabel ? JText::_($text) : $text;
     // Set required to true as this field is not displayed at all if not required.
     $this->required = true;
     // Add CSS and JS for the TOS field
     $doc = JFactory::getDocument();
     $css = "#jform_profile_tos {width: 18em; margin: 0 !important; padding: 0 2px !important;}\n\t\t\t\t#jform_profile_tos input {margin:0 5px 0 0 !important; width:10px !important;}\n\t\t\t\t#jform_profile_tos label {margin:0 15px 0 0 !important; width:auto;}\n\t\t\t\t";
     $doc->addStyleDeclaration($css);
     JHtml::_('behavior.modal');
     // Build the class for the label.
     $class = !empty($this->description) ? 'hasTooltip' : '';
     $class = $class . ' required';
     $class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class;
     // Add the opening label tag and main attributes attributes.
     $label .= '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '"';
     // If a description is specified, use it to build a tooltip.
     if (!empty($this->description)) {
         $label .= ' title="' . htmlspecialchars(trim($text, ':') . '<br />' . ($this->translateDescription ? JText::_($this->description) : $this->description), ENT_COMPAT, 'UTF-8') . '"';
     }
     $tosarticle = $this->element['article'] > 0 ? (int) $this->element['article'] : 0;
     if ($tosarticle) {
         JLoader::register('ContentHelperRoute', JPATH_BASE . '/components/com_content/helpers/route.php');
         $attribs = array();
         $attribs['class'] = 'modal';
         $attribs['rel'] = '{handler: \'iframe\', size: {x:800, y:500}}';
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('id, alias, catid, language')->from('#__content')->where('id = ' . $tosarticle);
         $db->setQuery($query);
         $article = $db->loadObject();
         if (JLanguageAssociations::isEnabled()) {
             $tosassociated = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $tosarticle);
         }
         $current_lang = JFactory::getLanguage()->getTag();
         if (isset($tosassociated) && $current_lang != $article->language && array_key_exists($current_lang, $tosassociated)) {
             $url = ContentHelperRoute::getArticleRoute($tosassociated[$current_lang]->id, $tosassociated[$current_lang]->catid);
             $link = JHtml::_('link', JRoute::_($url . '&tmpl=component&lang=' . $tosassociated[$current_lang]->language), $text, $attribs);
         } else {
             $slug = $article->alias ? $article->id . ':' . $article->alias : $article->id;
             $url = ContentHelperRoute::getArticleRoute($slug, $article->catid);
             $link = JHtml::_('link', JRoute::_($url . '&tmpl=component&lang=' . $article->language), $text, $attribs);
         }
     } else {
         $link = $text;
     }
     // Add the label text and closing tag.
     $label .= '>' . $link . '<span class="star">&#160;*</span></label>';
     return $label;
 }
Пример #7
0
 /**
  * Constructor.
  *
  * @param   array  $config  An optional associative array of configuration settings.
  *
  * @see     JController
  * @since   1.6
  */
 public function __construct($config = array())
 {
     if (empty($config['filter_fields'])) {
         $config['filter_fields'] = array('id', 'a.id', 'name', 'a.name', 'groups', 'a.groups', 'site', 'a.site', 'work_start', 'a.work_start');
         if (JLanguageAssociations::isEnabled()) {
             $config['filter_fields'][] = 'association';
         }
     }
     parent::__construct($config);
 }
Пример #8
0
 /**
  * Constructor.
  *
  * @param   array  $config  An optional associative array of configuration settings.
  *
  * @see     JController
  * @since   1.6
  */
 public function __construct($config = array())
 {
     if (empty($config['filter_fields'])) {
         $config['filter_fields'] = array('id', 'a.id', 'num', 'a.num', 'model', 'a.model', 'position', 'a.position', 'use_time', 'a.use_time', 'weld_time', 'a.weld_time', 'times', 'welder_name');
         if (JLanguageAssociations::isEnabled()) {
             $config['filter_fields'][] = 'association';
         }
     }
     parent::__construct($config);
 }
Пример #9
0
 /**
  * Constructor.
  *
  * @param   array  $config  An optional associative array of configuration settings.
  *
  * @since   1.6
  * @see     JController
  */
 public function __construct($config = array())
 {
     if (empty($config['filter_fields'])) {
         $config['filter_fields'] = array('id', 'a.id', 'title', 'a.title', 'alias', 'a.alias', 'checked_out', 'a.checked_out', 'checked_out_time', 'a.checked_out_time', 'catid', 'a.catid', 'category_title', 'state', 'a.state', 'access', 'a.access', 'access_level', 'created', 'a.created', 'created_by', 'a.created_by', 'created_by_alias', 'a.created_by_alias', 'ordering', 'a.ordering', 'featured', 'a.featured', 'language', 'a.language', 'hits', 'a.hits', 'publish_up', 'a.publish_up', 'publish_down', 'a.publish_down', 'published', 'a.published', 'author_id', 'category_id', 'level', 'tag');
         if (JLanguageAssociations::isEnabled()) {
             $config['filter_fields'][] = 'association';
         }
     }
     parent::__construct($config);
 }
Пример #10
0
 /**
  * Constructor.
  *
  * @param   array  $config  An optional associative array of configuration settings.
  *
  * @see     JController
  * @since   1.6
  */
 public function __construct($config = array())
 {
     if (empty($config['filter_fields'])) {
         $config['filter_fields'] = array('id', 'a.id', 'num', 'a.num', 'brand', 'a.brand');
         if (JLanguageAssociations::isEnabled()) {
             $config['filter_fields'][] = 'association';
         }
     }
     parent::__construct($config);
 }
 /**
  * Constructor.
  *
  * @param   array  $config  An optional associative array of configuration settings.
  *
  * @see        JController
  * @since      1.7.0
  */
 public function __construct($config = [])
 {
     if (empty($config['filter_fields'])) {
         $config['filter_fields'] = ['id', 'a.id', 'name', 'a.name', 'alias', 'a.alias', 'checked_out', 'a.checked_out', 'checked_out_time', 'a.checked_out_time', 'user_id', 'a.user_id', 'published', 'a.published', 'access', 'a.access', 'access_level', 'created', 'a.created', 'created_by', 'a.created_by', 'ordering', 'a.ordering', 'language', 'a.language', 'publish_up', 'a.publish_up', 'publish_down', 'a.publish_down', 'ul.name', 'linked_user', 'tag', 'level', 'c.level'];
         $assoc = JLanguageAssociations::isEnabled();
         if ($assoc) {
             $config['filter_fields'][] = 'association';
         }
     }
     parent::__construct($config);
 }
 public function store($updateNulls = false)
 {
     if (is_array($this->params)) {
         $registry = new JRegistry();
         $registry->loadArray($this->params);
         $this->params = (string) $registry;
     }
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $db->setQuery('SELECT username FROM #__users WHERE id=' . $this->userid);
     $this->alias = $db->loadResult();
     $this->alias = JApplication::stringURLSafe($this->alias);
     $table = JTable::getInstance('Author', 'AuthorListTable');
     if (!$this->userid) {
         $this->setError(JText::_('COM_AUTHORLIST_STORE_ERROR_USER_REQUIRED'));
         return false;
     }
     if ($table->load(array('userid' => $this->userid)) && ($table->id != $this->id || $this->id == 0)) {
         $app = JFactory::getApplication();
         $assoc = JLanguageAssociations::isEnabled();
         if ($assoc) {
             if ($table->language == $this->language || $this->language == '*' || $table->language == '*') {
                 $this->setError(JText::_('COM_AUTHORLIST_STORE_ERROR_AUTHOR_EXISTS_LANGUAGE'));
                 return false;
             }
         } else {
             $this->setError(JText::_('COM_AUTHORLIST_STORE_ERROR_AUTHOR_EXISTS'));
             return false;
         }
     }
     if (!$this->id) {
         if (!intval($this->created)) {
             $this->created = $date->toSql();
         }
         if (empty($this->created_by)) {
             $this->created_by = $user->get('id');
         }
         // Include user into the Editor Group
         $db->setQuery('SELECT user_id FROM #__user_usergroup_map WHERE user_id = ' . $this->userid . ' AND group_id = 3');
         if (!$db->loadResult()) {
             $db->setQuery('INSERT INTO `#__user_usergroup_map` (`user_id`,`group_id`) VALUES (' . $this->userid . ',3)');
             $db->query();
         }
     }
     return parent::store($updateNulls);
 }
Пример #13
0
 /**
  * Execute and display a template script.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise an Error object.
  *
  * @since   1.6
  */
 public function display($tpl = null)
 {
     if ($this->getLayout() == 'pagebreak') {
         // TODO: This is really dogy - should change this one day.
         $eName = JFactory::getApplication()->input->getCmd('e_name');
         $eName = preg_replace('#[^A-Z0-9\\-\\_\\[\\]]#i', '', $eName);
         $this->document->setTitle(JText::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));
         $this->eName =& $eName;
         return parent::display($tpl);
     }
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->state = $this->get('State');
     $this->canDo = JHelperContent::getActions('com_content', 'article', $this->item->id);
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     if ($this->getLayout() == 'modal') {
         // If we are forcing a language in modal (used for associations).
         if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
             // Set the language field to the forcedLanguage and disable changing it.
             $this->form->setValue('language', null, $forcedLanguage);
             $this->form->setFieldAttribute('language', 'readonly', 'true');
             // Only allow to select categories with All language or with the forced language.
             $this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
             // Only allow to select tags with All language or with the forced language.
             $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
         }
     } elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
         $this->form->setFieldAttribute('language', 'readonly', 'true');
     }
     $this->addToolbar();
     return parent::display($tpl);
 }
 protected function preprocessForm(JForm $form, $data, $group = 'content')
 {
     // Association content items
     $app = JFactory::getApplication();
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         $languages = JLanguageHelper::getLanguages('lang_code');
         // force to array (perhaps move to $this->loadFormData())
         $data = (array) $data;
         $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_CONTACT_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_contact');
                 $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);
 }
Пример #15
0
 /**
  * Gets a list of available languages
  *
  * @param   JRegistry  &$params  module params
  *
  * @return  array
  */
 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 = JLanguageAssociations::isEnabled();
     if ($assoc) {
         $active = $menu->getActive();
         if ($active) {
             $associations = MenusHelper::getAssociations($active->id);
         }
         // Load component associations
         $option = $app->input->get('option');
         $eName = JString::ucfirst(JString::str_ireplace('com_', '', $option));
         $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'));
         }
     }
     $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 (JLanguageMultilang::isEnabled()) {
                 if (isset($cassociations[$language->lang_code])) {
                     $language->link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef);
                 } elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
                     $itemid = $associations[$language->lang_code];
                     if ($app->get('sef') == '1') {
                         $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
                     } else {
                         $language->link = 'index.php?lang=' . $language->sef . '&amp;Itemid=' . $itemid;
                     }
                 } else {
                     if ($app->get('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;
 }
Пример #16
0
 public function save($data)
 {
     $dispatcher = JEventDispatcher::getInstance();
     $table = $this->getTable();
     $context = $this->option . '.' . $this->name;
     if (!empty($data['tags']) && $data['tags'][0] != '') {
         $table->newTags = $data['tags'];
     }
     $key = $table->getKeyName();
     $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id');
     $isNew = true;
     // Include the plugins for the save events.
     JPluginHelper::importPlugin($this->events_map['save']);
     // Allow an exception to be thrown.
     try {
         // Load the row if saving an existing record.
         if ($pk > 0) {
             $table->load($pk);
             $isNew = false;
         }
         // Bind the data.
         if (!$table->bind($data)) {
             $this->setError($table->getError());
             return false;
         }
         // Prepare the row for saving
         $this->prepareTable($table);
         // Check the data.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Trigger the before save event.
         $result = $dispatcher->trigger($this->event_before_save, array($context, $table, $isNew));
         if (in_array(false, $result, true)) {
             $this->setError($table->getError());
             return false;
         }
         // Store the data.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
         // Clean the cache.
         $this->cleanCache();
         // Trigger the after save event.
         $dispatcher->trigger($this->event_after_save, array($context, $table, $isNew));
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     if (isset($table->{$key})) {
         $this->setState($this->getName() . '.id', $table->{$key});
     }
     $this->setState($this->getName() . '.new', $isNew);
     if ($this->associationsContext && JLanguageAssociations::isEnabled()) {
         $associations = $data['associations'];
         // Unset any invalid associations
         $associations = Joomla\Utilities\ArrayHelper::toInteger($associations);
         // Unset any invalid associations
         foreach ($associations as $tag => $id) {
             if (!$id) {
                 unset($associations[$tag]);
             }
         }
         // Show a notice if the item isn't assigned to a language but we have associations.
         if ($associations && $table->language == '*') {
             JFactory::getApplication()->enqueueMessage(JText::_(strtoupper($this->option) . '_ERROR_ALL_LANGUAGE_ASSOCIATED'), 'notice');
         }
         // Adding self to the association
         $associations[$table->language] = (int) $table->{$key};
         // Deleting old association for these items
         $db = $this->getDbo();
         $query = $db->getQuery(true)->delete($db->qn('#__associations'))->where($db->qn('context') . ' = ' . $db->quote($this->associationsContext))->where($db->qn('id') . ' IN (' . implode(',', $associations) . ')');
         $db->setQuery($query);
         $db->execute();
         if (count($associations) > 1 && $table->language != '*') {
             // Adding new association for these items
             $key = md5(json_encode($associations));
             $query = $db->getQuery(true)->insert('#__associations');
             foreach ($associations as $id) {
                 $query->values((int) $id . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key));
             }
             $db->setQuery($query);
             $db->execute();
         }
     }
     return true;
 }
Пример #17
0
 /**
  * Build an SQL query to load the list data.
  *
  * @return  JDatabaseQuery
  */
 protected function getListQuery()
 {
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     // Select the required fields from the table.
     $query->select($this->getState('list.select', 'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.catid,' . ' a.numarticles, a.cache_time,' . ' a.published, a.access, a.ordering, a.language, a.publish_up, a.publish_down'));
     $query->from($db->quoteName('#__newsfeeds') . ' AS a');
     // Join over the language
     $query->select('l.title AS language_title, l.image AS language_image')->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
     // Join over the users for the checked out user.
     $query->select('uc.name AS editor')->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
     // Join over the asset groups.
     $query->select('ag.title AS access_level')->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
     // Join over the categories.
     $query->select('c.title AS category_title')->join('LEFT', '#__categories AS c ON c.id = a.catid');
     // Join over the associations.
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         $query->select('COUNT(asso2.id)>1 as association')->join('LEFT', '#__associations AS asso ON asso.id = a.id AND asso.context=' . $db->quote('com_newsfeeds.item'))->join('LEFT', '#__associations AS asso2 ON asso2.key = asso.key')->group('a.id, l.title, l.image, uc.name, ag.title, c.title');
     }
     // Filter by access level.
     if ($access = $this->getState('filter.access')) {
         $query->where('a.access = ' . (int) $access);
     }
     // Implement View Level Access
     if (!$user->authorise('core.admin')) {
         $groups = implode(',', $user->getAuthorisedViewLevels());
         $query->where('a.access IN (' . $groups . ')');
     }
     // Filter by published state.
     $published = $this->getState('filter.published');
     if (is_numeric($published)) {
         $query->where('a.published = ' . (int) $published);
     } elseif ($published === '') {
         $query->where('(a.published IN (0, 1))');
     }
     // Filter by category.
     $categoryId = $this->getState('filter.category_id');
     if (is_numeric($categoryId)) {
         $query->where('a.catid = ' . (int) $categoryId);
     }
     // Filter by search in title
     $search = $this->getState('filter.search');
     if (!empty($search)) {
         if (stripos($search, 'id:') === 0) {
             $query->where('a.id = ' . (int) substr($search, 3));
         } else {
             $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
             $query->where('(a.name LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')');
         }
     }
     // Filter on the language.
     if ($language = $this->getState('filter.language')) {
         $query->where('a.language = ' . $db->quote($language));
     }
     // Filter by a single tag.
     $tagId = $this->getState('filter.tag');
     if (is_numeric($tagId)) {
         $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId)->join('LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_newsfeeds.newsfeed'));
     }
     // Add the list ordering clause.
     $orderCol = $this->state->get('list.ordering');
     $orderDirn = $this->state->get('list.direction');
     if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
         $orderCol = 'c.title ' . $orderDirn . ', a.ordering';
     }
     $query->order($db->escape($orderCol . ' ' . $orderDirn));
     return $query;
 }
Пример #18
0
 public static function hasLanguageAssociations()
 {
     if (class_exists('JLanguageAssociations')) {
         return JLanguageAssociations::isEnabled();
     } else {
         $app = JFactory::getApplication();
         return isset($app->item_associations) ? $app->item_associations : 0;
     }
 }
Пример #19
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data    The form data.
  *
  * @return  boolean  True on success.
  * @since   1.6
  */
 public function save($data)
 {
     $dispatcher = JEventDispatcher::getInstance();
     $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState('item.id');
     $isNew = true;
     $table = $this->getTable();
     $context = $this->option . '.' . $this->name;
     // Include the plugins for the on save events.
     JPluginHelper::importPlugin($this->events_map['save']);
     // Load the row if saving an existing item.
     if ($pk > 0) {
         $table->load($pk);
         $isNew = false;
     }
     if (!$isNew) {
         if ($table->parent_id == $data['parent_id']) {
             // If first is chosen make the item the first child of the selected parent.
             if ($data['menuordering'] == -1) {
                 $table->setLocation($data['parent_id'], 'first-child');
             } elseif ($data['menuordering'] == -2) {
                 $table->setLocation($data['parent_id'], 'last-child');
             } elseif ($data['menuordering'] && $table->id != $data['menuordering'] || empty($data['id'])) {
                 $table->setLocation($data['menuordering'], 'after');
             } elseif ($data['menuordering'] && $table->id == $data['menuordering']) {
                 unset($data['menuordering']);
             }
         } else {
             $table->setLocation($data['parent_id'], 'last-child');
         }
     } else {
         $table->setLocation($data['parent_id'], 'last-child');
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Alter the title & alias for save as copy.  Also, unset the home record.
     if (!$isNew && $data['id'] == 0) {
         list($title, $alias) = $this->generateNewTitle($table->parent_id, $table->alias, $table->title);
         $table->title = $title;
         $table->alias = $alias;
         $table->published = 0;
         $table->home = 0;
     }
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the before save event.
     $result = $dispatcher->trigger($this->event_before_save, array($context, &$table, $isNew));
     // Store the data.
     if (in_array(false, $result, true) || !$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the after save event.
     $dispatcher->trigger($this->event_after_save, array($context, &$table, $isNew));
     // Rebuild the tree path.
     if (!$table->rebuildPath($table->id)) {
         $this->setError($table->getError());
         return false;
     }
     $this->setState('item.id', $table->id);
     $this->setState('item.menutype', $table->menutype);
     // Load associated menu items
     $app = JFactory::getApplication();
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         // Adding self to the association
         $associations = $data['associations'];
         foreach ($associations as $tag => $id) {
             if (empty($id)) {
                 unset($associations[$tag]);
             }
         }
         // Detecting all item menus
         $all_language = $table->language == '*';
         if ($all_language && !empty($associations)) {
             JError::raiseNotice(403, JText::_('COM_MENUS_ERROR_ALL_LANGUAGE_ASSOCIATED'));
         }
         $associations[$table->language] = $table->id;
         // Deleting old association for these items
         $db = JFactory::getDbo();
         $query = $db->getQuery(true)->delete('#__languages_associations')->where('context=' . $db->quote('com_menus.item'))->where('id IN (' . implode(',', $associations) . ')');
         $db->setQuery($query);
         try {
             $db->execute();
         } catch (RuntimeException $e) {
             $this->setError($e->getMessage());
             return false;
         }
         if (!$all_language && count($associations) > 1) {
             // Adding new association for these items
             $key = md5(json_encode($associations));
             $query->clear()->insert('#__languages_associations');
             foreach ($associations as $id) {
                 $query->values($id . ',' . $db->quote('com_menus.item') . ',' . $db->quote($key));
             }
             $db->setQuery($query);
             try {
                 $db->execute();
             } catch (RuntimeException $e) {
                 $this->setError($e->getMessage());
                 return false;
             }
         }
     }
     // Clean the cache
     $this->cleanCache();
     if (isset($data['link'])) {
         $base = JUri::base();
         $juri = JUri::getInstance($base . $data['link']);
         $option = $juri->getVar('option');
         // Clean the cache
         parent::cleanCache($option);
     }
     return true;
 }
Пример #20
0
 /**
  * Method to delete one or more records.
  *
  * @param   array  &$pks  An array of record primary keys.
  *
  * @return  boolean  True if successful, false if an error occurs.
  *
  * @since   12.2
  */
 public function delete(&$pks)
 {
     $dispatcher = JEventDispatcher::getInstance();
     $pks = (array) $pks;
     $table = $this->getTable();
     // Include the plugins for the delete events.
     JPluginHelper::importPlugin($this->events_map['delete']);
     // Iterate the items to delete each one.
     foreach ($pks as $i => $pk) {
         if ($table->load($pk)) {
             if ($this->canDelete($table)) {
                 $context = $this->option . '.' . $this->name;
                 // Trigger the before delete event.
                 $result = $dispatcher->trigger($this->event_before_delete, array($context, $table));
                 if (in_array(false, $result, true)) {
                     $this->setError($table->getError());
                     return false;
                 }
                 // Multilanguage: if associated, delete the item in the _associations table
                 if ($this->associationsContext && JLanguageAssociations::isEnabled()) {
                     $db = JFactory::getDbo();
                     $query = $db->getQuery(true)->select('COUNT(*) as count, ' . $db->quoteName('as1.key'))->from($db->quoteName('#__associations') . ' AS as1')->join('LEFT', $db->quoteName('#__associations') . ' AS as2 ON ' . $db->quoteName('as1.key') . ' =  ' . $db->quoteName('as2.key'))->where($db->quoteName('as1.context') . ' = ' . $db->quote($this->associationsContext))->where($db->quoteName('as1.id') . ' = ' . (int) $pk);
                     $db->setQuery($query);
                     $row = $db->loadAssoc();
                     if (!empty($row['count'])) {
                         $query = $db->getQuery(true)->delete($db->quoteName('#__associations'))->where($db->quoteName('context') . ' = ' . $db->quote($this->associationsContext))->where($db->quoteName('key') . ' = ' . $db->quote($row['key']));
                         if ($row['count'] > 2) {
                             $query->where($db->quoteName('id') . ' = ' . (int) $pk);
                         }
                         $db->setQuery($query);
                         $db->execute();
                     }
                 }
                 if (!$table->delete($pk)) {
                     $this->setError($table->getError());
                     return false;
                 }
                 // Trigger the after event.
                 $dispatcher->trigger($this->event_after_delete, array($context, $table));
             } else {
                 // Prune items that you can't change.
                 unset($pks[$i]);
                 $error = $this->getError();
                 if ($error) {
                     JLog::add($error, JLog::WARNING, 'jerror');
                     return false;
                 } else {
                     JLog::add(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
                     return false;
                 }
             }
         } else {
             $this->setError($table->getError());
             return false;
         }
     }
     // Clear the component's cache
     $this->cleanCache();
     return true;
 }
Пример #21
0
 /**
  * Build an SQL query to load the list data.
  *
  * @return  JDatabaseQuery
  *
  * @since   1.6
  */
 protected function getListQuery()
 {
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     // Select the required fields from the table.
     $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' . ', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.ordering, a.featured, a.language, a.hits' . ', a.publish_up, a.publish_down'));
     $query->from('#__content AS a');
     // Join over the language
     $query->select('l.title AS language_title, l.image AS language_image')->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
     // Join over the users for the checked out user.
     $query->select('uc.name AS editor')->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
     // Join over the asset groups.
     $query->select('ag.title AS access_level')->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
     // Join over the categories.
     $query->select('c.title AS category_title')->join('LEFT', '#__categories AS c ON c.id = a.catid');
     // Join over the users for the author.
     $query->select('ua.name AS author_name')->join('LEFT', '#__users AS ua ON ua.id = a.created_by');
     // Join over the associations.
     if (JLanguageAssociations::isEnabled()) {
         $query->select('COUNT(asso2.id)>1 as association')->join('LEFT', '#__associations AS asso ON asso.id = a.id AND asso.context=' . $db->quote('com_content.item'))->join('LEFT', '#__associations AS asso2 ON asso2.key = asso.key')->group('a.id, l.title, l.image, uc.name, ag.title, c.title, ua.name');
     }
     // Filter by access level.
     if ($access = $this->getState('filter.access')) {
         $query->where('a.access = ' . (int) $access);
     }
     // Implement View Level Access
     if (!$user->authorise('core.admin')) {
         $groups = implode(',', $user->getAuthorisedViewLevels());
         $query->where('a.access IN (' . $groups . ')');
     }
     // Filter by published state
     $published = $this->getState('filter.published');
     if (is_numeric($published)) {
         $query->where('a.state = ' . (int) $published);
     } elseif ($published === '') {
         $query->where('(a.state = 0 OR a.state = 1)');
     }
     // Filter by a single or group of categories.
     $baselevel = 1;
     $categoryId = $this->getState('filter.category_id');
     if (is_numeric($categoryId)) {
         $cat_tbl = JTable::getInstance('Category', 'JTable');
         $cat_tbl->load($categoryId);
         $rgt = $cat_tbl->rgt;
         $lft = $cat_tbl->lft;
         $baselevel = (int) $cat_tbl->level;
         $query->where('c.lft >= ' . (int) $lft)->where('c.rgt <= ' . (int) $rgt);
     } elseif (is_array($categoryId)) {
         JArrayHelper::toInteger($categoryId);
         $categoryId = implode(',', $categoryId);
         $query->where('a.catid IN (' . $categoryId . ')');
     }
     // Filter on the level.
     if ($level = $this->getState('filter.level')) {
         $query->where('c.level <= ' . ((int) $level + (int) $baselevel - 1));
     }
     // Filter by author
     $authorId = $this->getState('filter.author_id');
     if (is_numeric($authorId)) {
         $type = $this->getState('filter.author_id.include', true) ? '= ' : '<>';
         $query->where('a.created_by ' . $type . (int) $authorId);
     }
     // Filter by search in title.
     $search = $this->getState('filter.search');
     if (!empty($search)) {
         if (stripos($search, 'id:') === 0) {
             $query->where('a.id = ' . (int) substr($search, 3));
         } elseif (stripos($search, 'author:') === 0) {
             $search = $db->quote('%' . $db->escape(substr($search, 7), true) . '%');
             $query->where('(ua.name LIKE ' . $search . ' OR ua.username LIKE ' . $search . ')');
         } else {
             $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
             $query->where('(a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')');
         }
     }
     // Filter on the language.
     if ($language = $this->getState('filter.language')) {
         $query->where('a.language = ' . $db->quote($language));
     }
     // Filter by a single tag.
     $tagId = $this->getState('filter.tag');
     if (is_numeric($tagId)) {
         $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId)->join('LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_content.article'));
     }
     // Add the list ordering clause.
     $orderCol = $this->state->get('list.ordering', 'a.id');
     $orderDirn = $this->state->get('list.direction', 'desc');
     if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
         $orderCol = 'c.title ' . $orderDirn . ', a.ordering';
     }
     // SQL server change
     if ($orderCol == 'language') {
         $orderCol = 'l.title';
     }
     if ($orderCol == 'access_level') {
         $orderCol = 'ag.title';
     }
     $query->order($db->escape($orderCol . ' ' . $orderDirn));
     return $query;
 }
Пример #22
0
/**
 * @package     Joomla.Administrator
 * @subpackage  com_contact
 *
 * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
defined('_JEXEC') or die;
// Include the component HTML helpers.
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JHtml::_('behavior.formvalidation');
JHtml::_('formbehavior.chosen', 'select');
$app = JFactory::getApplication();
$input = $app->input;
$assoc = JLanguageAssociations::isEnabled();
?>
<script type="text/javascript">
	Joomla.submitbutton = function(task)
	{
		if (task == 'contact.cancel' || document.formvalidator.isValid(document.id('contact-form')))
		{
			<?php 
echo $this->form->getField('misc')->save();
?>

			if (window.opener && (task == 'contact.save' || task == 'contact.cancel'))
			{
				window.opener.document.closeEditWindow = self;
				window.opener.setTimeout('window.document.closeEditWindow.close()', 1000);
			}
 /**
  * Method to handle any login logic and report back to the subject.
  *
  * @param   array  $user     Holds the user data.
  * @param   array  $options  Array holding options (remember, autoregister, group).
  *
  * @return  boolean  True on success.
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $app = JFactory::getApplication();
     $menu = $app->getMenu();
     if ($app->isSite() && $this->params->get('automatic_change', 1)) {
         // Load associations.
         $assoc = JLanguageAssociations::isEnabled();
         if ($assoc) {
             $active = $menu->getActive();
             if ($active) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
         }
         $lang_code = $user['language'];
         if (empty($lang_code)) {
             $lang_code = self::$default_lang;
         }
         if ($lang_code != self::$tag) {
             // Change language.
             self::$tag = $lang_code;
             // Create a cookie.
             $conf = JFactory::getConfig();
             $cookie_domain = $conf->get('cookie_domain', '');
             $cookie_path = $conf->get('cookie_path', '/');
             setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
             // Change the language code.
             JFactory::getLanguage()->setLanguage($lang_code);
             // Change the redirect (language has changed).
             if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
                 $itemid = $associations[$lang_code];
                 $app->setUserState('users.login.form.return', 'index.php?&Itemid=' . $itemid);
             } else {
                 $itemid = isset(self::$homes[$lang_code]) ? self::$homes[$lang_code]->id : self::$homes['*']->id;
                 $app->setUserState('users.login.form.return', 'index.php?&Itemid=' . $itemid);
             }
         }
     }
 }
Пример #24
0
 /**
  * Builds an SQL query to load the list data.
  *
  * @return  JDatabaseQuery    A query object.
  *
  * @since   1.6
  */
 protected function getListQuery()
 {
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     // Select all fields from the table.
     $query->select($this->getState('list.select', $db->quoteName(array('a.id', 'a.menutype', 'a.title', 'a.alias', 'a.note', 'a.path', 'a.link', 'a.type', 'a.parent_id', 'a.level', 'a.published', 'a.component_id', 'a.checked_out', 'a.checked_out_time', 'a.browserNav', 'a.access', 'a.img', 'a.template_style_id', 'a.params', 'a.lft', 'a.rgt', 'a.home', 'a.language', 'a.client_id'), array(null, null, null, null, null, null, null, null, null, null, 'apublished', null, null, null, null, null, null, null, null, null, null, null, null, null))));
     $query->select('CASE ' . ' WHEN a.type = ' . $db->quote('component') . ' THEN a.published+2*(e.enabled-1) ' . ' WHEN a.type = ' . $db->quote('url') . 'AND a.published != -2 THEN a.published+2 ' . ' WHEN a.type = ' . $db->quote('url') . 'AND a.published = -2 THEN a.published-1 ' . ' WHEN a.type = ' . $db->quote('alias') . 'AND a.published != -2 THEN a.published+4 ' . ' WHEN a.type = ' . $db->quote('alias') . 'AND a.published = -2 THEN a.published-1 ' . ' WHEN a.type = ' . $db->quote('separator') . 'AND a.published != -2 THEN a.published+6 ' . ' WHEN a.type = ' . $db->quote('separator') . 'AND a.published = -2 THEN a.published-1 ' . ' WHEN a.type = ' . $db->quote('heading') . 'AND a.published != -2 THEN a.published+8 ' . ' WHEN a.type = ' . $db->quote('heading') . 'AND a.published = -2 THEN a.published-1 ' . ' END AS published ');
     $query->from($db->quoteName('#__menu') . ' AS a');
     // Join over the language
     $query->select('l.title AS language_title, l.image AS language_image')->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
     // Join over the users.
     $query->select('u.name AS editor')->join('LEFT', $db->quoteName('#__users') . ' AS u ON u.id = a.checked_out');
     // Join over components
     $query->select('c.element AS componentname')->join('LEFT', $db->quoteName('#__extensions') . ' AS c ON c.extension_id = a.component_id');
     // Join over the asset groups.
     $query->select('ag.title AS access_level')->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
     // Join over the associations.
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         $query->select('COUNT(asso2.id)>1 as association')->join('LEFT', '#__associations AS asso ON asso.id = a.id AND asso.context=' . $db->quote('com_menus.item'))->join('LEFT', '#__associations AS asso2 ON asso2.key = asso.key')->group('a.id, e.enabled, l.title, l.image, u.name, c.element, ag.title, e.name');
     }
     // Join over the extensions
     $query->select('e.name AS name')->join('LEFT', '#__extensions AS e ON e.extension_id = a.component_id');
     // Exclude the root category.
     $query->where('a.id > 1')->where('a.client_id = 0');
     // Filter on the published state.
     $published = $this->getState('filter.published');
     if (is_numeric($published)) {
         $query->where('a.published = ' . (int) $published);
     } elseif ($published === '') {
         $query->where('(a.published IN (0, 1))');
     }
     // Filter by search in title, alias or id
     if ($search = trim($this->getState('filter.search'))) {
         if (stripos($search, 'id:') === 0) {
             $query->where('a.id = ' . (int) substr($search, 3));
         } elseif (stripos($search, 'link:') === 0) {
             if ($search = substr($search, 5)) {
                 $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
                 $query->where('a.link LIKE ' . $search);
             }
         } else {
             $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
             $query->where('(' . 'a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search . ' OR a.note LIKE ' . $search . ')');
         }
     }
     // Filter the items over the parent id if set.
     $parentId = $this->getState('filter.parent_id');
     if (!empty($parentId)) {
         $query->where('p.id = ' . (int) $parentId);
     }
     // Filter the items over the menu id if set.
     $menuType = $this->getState('filter.menutype');
     if (!empty($menuType)) {
         $query->where('a.menutype = ' . $db->quote($menuType));
     }
     // Filter on the access level.
     if ($access = $this->getState('filter.access')) {
         $query->where('a.access = ' . (int) $access);
     }
     // Implement View Level Access
     if (!$user->authorise('core.admin')) {
         $groups = implode(',', $user->getAuthorisedViewLevels());
         $query->where('a.access IN (' . $groups . ')');
     }
     // Filter on the level.
     if ($level = $this->getState('filter.level')) {
         $query->where('a.level <= ' . (int) $level);
     }
     // Filter on the language.
     if ($language = $this->getState('filter.language')) {
         $query->where('a.language = ' . $db->quote($language));
     }
     // Add the list ordering clause.
     $query->order($db->escape($this->getState('list.ordering', 'a.lft')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
     return $query;
 }
Пример #25
0
 /**
  * Method to handle any login logic and report back to the subject.
  *
  * @param   array  $user     Holds the user data.
  * @param   array  $options  Array holding options (remember, autoregister, group).
  *
  * @return  boolean  True on success.
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $menu = $this->app->getMenu();
     if ($this->app->isSite()) {
         if ($this->params->get('automatic_change', 1)) {
             $assoc = JLanguageAssociations::isEnabled();
             $lang_code = $user['language'];
             // If no language is specified for this user, we set it to the site default language
             if (empty($lang_code)) {
                 $lang_code = $this->default_lang;
             }
             jimport('joomla.filesystem.folder');
             // The language has been deleted/disabled or the related content language does not exist/has been unpublished
             // or the related home page does not exist/has been unpublished
             if (!array_key_exists($lang_code, $this->lang_codes) || !array_key_exists($lang_code, JLanguageMultilang::getSiteHomePages()) || !JFolder::exists(JPATH_SITE . '/language/' . $lang_code)) {
                 $lang_code = $this->current_lang;
             }
             // Try to get association from the current active menu item
             $active = $menu->getActive();
             $foundAssociation = false;
             if ($active) {
                 if ($assoc) {
                     $associations = MenusHelper::getAssociations($active->id);
                 }
                 // The login menu item contains a redirection.
                 // This will override the automatic change to the user preferred language
                 if ($active->params['login_redirect_url']) {
                     $this->app->setUserState('users.login.form.return', JRoute::_($this->app->getUserState('users.login.form.return'), false));
                 } elseif ($this->app->getUserState('users.login.form.return')) {
                     // The login module contains a menu item redirection. Try to get association from that menu item.
                     $itemid = preg_replace('/\\D+/', '', $this->app->getUserState('users.login.form.return'));
                     if ($assoc) {
                         $associations = MenusHelper::getAssociations($itemid);
                     }
                     if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
                         $associationItemid = $associations[$lang_code];
                         $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
                         $foundAssociation = true;
                     }
                 } elseif (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
                     $associationItemid = $associations[$lang_code];
                     $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
                     $foundAssociation = true;
                 } elseif ($active->home) {
                     // We are on a Home page, we redirect to the user site language home page
                     $item = $menu->getDefault($lang_code);
                     if ($item && $item->language != $active->language && $item->language != '*') {
                         $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $item->id);
                         $foundAssociation = true;
                     }
                 }
             }
             if ($foundAssociation && $lang_code != $this->current_lang) {
                 // Change language.
                 $this->current_lang = $lang_code;
                 // Create a cookie.
                 $this->setLanguageCookie($lang_code);
                 // Change the language code.
                 JFactory::getLanguage()->setLanguage($lang_code);
             }
         } else {
             if ($this->app->getUserState('users.login.form.return')) {
                 $this->app->setUserState('users.login.form.return', JRoute::_($this->app->getUserState('users.login.form.return'), false));
             }
         }
     }
 }
Пример #26
0
 /**
  * Method to handle any login logic and report back to the subject.
  *
  * @param   array  $user     Holds the user data.
  * @param   array  $options  Array holding options (remember, autoregister, group).
  *
  * @return  boolean  True on success.
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $menu = $this->app->getMenu();
     if ($this->app->isSite() && $this->params->get('automatic_change', 1)) {
         // Load associations.
         $assoc = JLanguageAssociations::isEnabled();
         if ($assoc) {
             $active = $menu->getActive();
             if ($active) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
         }
         $lang_code = $user['language'];
         if (empty($lang_code)) {
             $lang_code = $this->default_lang;
         }
         if ($lang_code != $this->default_lang) {
             // Change language.
             $this->default_lang = $lang_code;
             // Create a cookie.
             $cookie_domain = $this->app->get('cookie_domain', '');
             $cookie_path = $this->app->get('cookie_path', '/');
             setcookie(JApplicationHelper::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
             // Change the language code.
             JFactory::getLanguage()->setLanguage($lang_code);
             // Change the redirect (language has changed).
             if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
                 $itemid = $associations[$lang_code];
                 $this->app->setUserState('users.login.form.return', 'index.php?&Itemid=' . $itemid);
             } else {
                 JLoader::register('MultilangstatusHelper', JPATH_ADMINISTRATOR . '/components/com_languages/helpers/multilangstatus.php');
                 $homes = MultilangstatusHelper::getHomepages();
                 $itemid = isset($homes[$lang_code]) ? $homes[$lang_code]->id : $homes['*']->id;
                 $this->app->setUserState('users.login.form.return', 'index.php?&Itemid=' . $itemid);
             }
         }
     }
 }
Пример #27
0
 /**
  * Method to determine if a category association is available.
  *
  * @return  boolean True if a category association is available; false otherwise.
  */
 public function getAssoc()
 {
     static $assoc = null;
     if (!is_null($assoc)) {
         return $assoc;
     }
     $app = JFactory::getApplication();
     $extension = $this->getState('category.extension');
     $assoc = JLanguageAssociations::isEnabled();
     $extension = explode('.', $extension);
     $component = array_shift($extension);
     $cname = str_replace('com_', '', $component);
     if (!$assoc || !$component || !$cname) {
         $assoc = false;
     } else {
         $hname = $cname . 'HelperAssociation';
         JLoader::register($hname, JPATH_SITE . '/components/' . $component . '/helpers/association.php');
         $assoc = class_exists($hname) && !empty($hname::$category_association);
     }
     return $assoc;
 }
Пример #28
0
        echo $this->form->renderField($fieldname, null, null, array('group_id' => 'field_' . $fieldname));
        ?>
						<?php 
    }
    ?>
					<?php 
}
?>
				
				</fieldset>
			</div>
			<?php 
echo JHtml::_('bootstrap.endTab');
?>
			<?php 
if (isset($app->item_associations) and JLanguageAssociations::isEnabled()) {
    ?>
				<?php 
    echo JHtml::_('bootstrap.addTab', 'teamid-tabs', 'associations', JText::_('COM_KNVBAPI2_FIELDSET_ASSOCIATIONS_LABEL', true));
    ?>
					<?php 
    echo JLayoutHelper::render('joomla.edit.associations', $this);
    ?>
				<?php 
    echo JHtml::_('bootstrap.endTab');
    ?>
			<?php 
}
?>
			<?php 
if ($this->can_do->get('core.admin')) {
Пример #29
0
 /**
  * Build an SQL query to load the list data.
  *
  * @return  JDatabaseQuery
  *
  * @since   1.6
  */
 protected function getListQuery()
 {
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     // Select the required fields from the table.
     $query->select($db->quoteName(explode(', ', $this->getState('list.select', 'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.catid, a.user_id' . ', a.published, a.access, a.created, a.created_by, a.ordering, a.featured, a.language' . ', a.publish_up, a.publish_down'))));
     $query->from($db->quoteName('#__contact_details', 'a'));
     // Join over the users for the linked user.
     $query->select(array($db->quoteName('ul.name', 'linked_user'), $db->quoteName('ul.email')))->join('LEFT', $db->quoteName('#__users', 'ul') . ' ON ' . $db->quoteName('ul.id') . ' = ' . $db->quoteName('a.user_id'));
     // Join over the language
     $query->select($db->quoteName('l.title', 'language_title'))->join('LEFT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->quoteName('l.lang_code') . ' = ' . $db->quoteName('a.language'));
     // Join over the users for the checked out user.
     $query->select($db->quoteName('uc.name', 'editor'))->join('LEFT', $db->quoteName('#__users', 'uc') . ' ON ' . $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out'));
     // Join over the asset groups.
     $query->select($db->quoteName('ag.title', 'access_level'))->join('LEFT', $db->quoteName('#__viewlevels', 'ag') . ' ON ' . $db->quoteName('ag.id') . ' = ' . $db->quoteName('a.access'));
     // Join over the categories.
     $query->select($db->quoteName('c.title', 'category_title'))->join('LEFT', $db->quoteName('#__categories', 'c') . ' ON ' . $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid'));
     // Join over the associations.
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         $query->select('COUNT(' . $db->quoteName('asso2.id') . ') > 1 as ' . $db->quoteName('association'))->join('LEFT', $db->quoteName('#__associations', 'asso') . ' ON ' . $db->quoteName('asso.id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('asso.context') . ' = ' . $db->quote('com_contact.item'))->join('LEFT', $db->quoteName('#__associations', 'asso2') . ' ON ' . $db->quoteName('asso2.key') . ' = ' . $db->quoteName('asso.key'))->group($db->quoteName(array('a.id', 'ul.name', 'l.title', 'uc.name', 'ag.title', 'c.title')));
     }
     // Filter by access level.
     if ($access = $this->getState('filter.access')) {
         $query->where($db->quoteName('a.access') . ' = ' . (int) $access);
     }
     // Implement View Level Access
     if (!$user->authorise('core.admin')) {
         $groups = implode(',', $user->getAuthorisedViewLevels());
         $query->where($db->quoteName('a.access') . ' IN (' . $groups . ')');
     }
     // Filter by published state
     $published = $this->getState('filter.published');
     if (is_numeric($published)) {
         $query->where($db->quoteName('a.published') . ' = ' . (int) $published);
     } elseif ($published === '') {
         $query->where('(' . $db->quoteName('a.published') . ' = 0 OR ' . $db->quoteName('a.published') . ' = 1)');
     }
     // Filter by a single or group of categories.
     $categoryId = $this->getState('filter.category_id');
     if (is_numeric($categoryId)) {
         $query->where($db->quoteName('a.catid') . ' = ' . (int) $categoryId);
     } elseif (is_array($categoryId)) {
         $categoryId = Joomla\Utilities\ArrayHelper::toInteger($categoryId);
         $categoryId = implode(',', $categoryId);
         $query->where($db->quoteName('a.catid') . ' IN (' . $categoryId . ')');
     }
     // Filter by search in name.
     $search = $this->getState('filter.search');
     if (!empty($search)) {
         if (stripos($search, 'id:') === 0) {
             $query->where('a.id = ' . (int) substr($search, 3));
         } elseif (stripos($search, 'author:') === 0) {
             $search = $db->quote('%' . $db->escape(substr($search, 7), true) . '%');
             $query->where('(' . $db->quoteName('uc.name') . ' LIKE ' . $search . ' OR ' . $db->quoteName('uc.username') . ' LIKE ' . $search . ')');
         } else {
             $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
             $query->where('(' . $db->quoteName('a.name') . ' LIKE ' . $search . ' OR ' . $db->quoteName('a.alias') . ' LIKE ' . $search . ')');
         }
     }
     // Filter on the language.
     if ($language = $this->getState('filter.language')) {
         $query->where($db->quoteName('a.language') . ' = ' . $db->quote($language));
     }
     // Filter by a single tag.
     $tagId = $this->getState('filter.tag');
     if (is_numeric($tagId)) {
         $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId)->join('LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_contact.contact'));
     }
     // Add the list ordering clause.
     $orderCol = $this->state->get('list.ordering', 'a.name');
     $orderDirn = $this->state->get('list.direction', 'asc');
     if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
         $orderCol = $db->quoteName('c.title') . ' ' . $orderDirn . ', ' . $db->quoteName('a.ordering');
     }
     $query->order($db->escape($orderCol . ' ' . $orderDirn));
     return $query;
 }
Пример #30
0
 /**
  * Preprocess the form.
  *
  * @param   JForm   $form   Form object.
  * @param   object  $data   Data object.
  * @param   string  $group  Group name.
  *
  * @return  void
  *
  * @since   3.0.3
  */
 protected function preprocessForm(JForm $form, $data, $group = 'content')
 {
     // Determine correct permissions to check.
     if ($this->getState('contact.id')) {
         // Existing record. Can only edit in selected categories.
         $form->setFieldAttribute('catid', 'action', 'core.edit');
     } else {
         // New record. Can only create in selected categories.
         $form->setFieldAttribute('catid', 'action', 'core.create');
     }
     if ($this->canCreateCategory()) {
         $form->setFieldAttribute('catid', 'allowAdd', 'true');
     }
     // Association content items
     $assoc = JLanguageAssociations::isEnabled();
     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_CONTACT_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_contact');
                 $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);
 }