/** * Get the associated language flags * * @param integer $contactid The item id to search associations * * @return string The language HTML * * @throws Exception */ public static function association($contactid) { // Defaults $html = ''; // Get the associations if ($associations = JLanguageAssociations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $contactid)) { foreach ($associations as $tag => $associated) { $associations[$tag] = (int) $associated->id; } // Get the associated contact items $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('c.id, c.name as title')->select('l.sef as lang_sef, lang_code')->from('#__contact_details as c')->select('cat.title as category_title')->join('LEFT', '#__categories as cat ON cat.id=c.catid')->where('c.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON c.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (RuntimeException $e) { throw new Exception($e->getMessage(), 500, $e); } if ($items) { foreach ($items as &$item) { $text = strtoupper($item->lang_sef); $url = JRoute::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); $tooltip = $item->title . '<br />' . JText::sprintf('JCATEGORY_SPRINTF', $item->category_title); $classes = 'hasPopover label label-association label-' . $item->lang_sef; $item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes . '" data-content="' . $tooltip . '" data-placement="top">' . $text . '</a>'; } } JHtml::_('bootstrap.popover'); $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * Get the associated language flags * * @param int $newsfeedid The item id to search associations * * @return string The language HTML */ public static function association($newsfeedid) { // Defaults $html = ''; // Get the associations if ($associations = JLanguageAssociations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $newsfeedid)) { foreach ($associations as $tag => $associated) { $associations[$tag] = (int) $associated->id; } // Get the associated newsfeed items $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('c.id, c.name as title')->select('l.sef as lang_sef')->from('#__newsfeeds as c')->select('cat.title as category_title')->join('LEFT', '#__categories as cat ON cat.id=c.catid')->where('c.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON c.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (RuntimeException $e) { throw new Exception($e->getMessage(), 500); } if ($items) { foreach ($items as &$item) { $text = strtoupper($item->lang_sef); $url = JRoute::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); $tooltipParts = array(JHtml::_('image', 'mod_languages/' . $item->image . '.gif', $item->language_title, array('title' => $item->language_title), true), $item->title, '(' . $item->category_title . ')'); $item->link = JHtml::_('tooltip', implode(' ', $tooltipParts), null, null, $text, $url, null, 'hasTooltip label label-association label-' . $item->lang_sef); } } $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * Get the associated language flags * * @param int $contactid The item id to search associations * * @return string The language HTML */ public static function association($contactid) { // Defaults $html = ''; // Get the associations if ($associations = JLanguageAssociations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $contactid)) { foreach ($associations as $tag => $associated) { $associations[$tag] = (int) $associated->id; } // Get the associated contact items $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('c.*')->from('#__contact_details as c')->select('cat.title as category_title')->join('LEFT', '#__categories as cat ON cat.id=c.catid')->where('c.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON c.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (runtimeException $e) { throw new Exception($e->getMessage(), 500); return false; } $flags = array(); // Construct html foreach ($associations as $tag => $associated) { if ($associated != $contactid) { $flags[] = JText::sprintf('COM_CONTACT_TIP_ASSOCIATED_LANGUAGE', JHtml::_('image', 'mod_languages/' . $items[$associated]->image . '.gif', $items[$associated]->language_title, array('title' => $items[$associated]->language_title), true), $items[$associated]->name, $items[$associated]->category_title); } } $html = JHtml::_('tooltip', implode('<br />', $flags), JText::_('COM_CONTACT_TIP_ASSOCIATION'), 'admin/icon-16-links.png'); } return $html; }
/** * Method to get the associations for a given item * * @param integer $id Id of the item * @param string $view Name of the view * * @return array Array of associations for the item * * @since 3.0 */ public static function getAssociations($id = 0, $view = null) { jimport('helper.route', JPATH_COMPONENT_SITE); $app = JFactory::getApplication(); $jinput = $app->input; $view = is_null($view) ? $jinput->get('view') : $view; $id = empty($id) ? $jinput->getInt('id') : $id; if ($view == 'article') { if ($id) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id); $return = array(); foreach ($associations as $tag => $item) { $return[$tag] = TZ_PortfolioHelperRoute::getArticleRoute($item->id, $item->catid, $item->language); } return $return; } } elseif ($view == 'p_article') { if ($id) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id); $return = array(); foreach ($associations as $tag => $item) { $return[$tag] = TZ_PortfolioHelperRoute::getPortfolioArticleRoute($item->id, $item->catid, $item->language); } return $return; } } if ($view == 'category' || $view == 'categories') { return self::getCategoryAssociations($id, 'com_content'); } return array(); }
public function getItem($pk = null) { if ($item = parent::getItem($pk)) { $registry = new JRegistry(); $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); } // Load associated contact items $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_authorlist', '#__authorlist', 'com_authorlist.author', $item->id, 'id', '', ''); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } } } // Load item tags if (!empty($item->id)) { $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_authorlist.author'); } return $item; }
/** * Gets a list of associations for a given item. * * @param integer $pk Content item key. * @param string $extension Optional extension name. * * @return array of associations. */ public static function getAssociations($pk, $extension = 'com_content') { $langAssociations = JLanguageAssociations::getAssociations($extension, '#__categories', 'com_categories.item', $pk, 'id', 'alias', ''); $associations = array(); foreach ($langAssociations as $langAssociation) { $associations[$langAssociation->language] = $langAssociation->id; } return $associations; }
/** * 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"> *</span></label>'; return $label; }
public static function getAssociationsForm($id, $name, $config = array()) { $addform = new SimpleXMLElement('<form />'); $fields = $addform->addChild('fields'); $fields->addAttribute('name', $name); $fieldset = $fields->addChild('fieldset'); $fieldset->addAttribute('name', 'item_associations'); $fieldset->addAttribute('description', 'COM_CONTENT_ITEM_ASSOCIATIONS_FIELDSET_DESC'); $fieldset->addAttribute('addfieldpath', '/administrator/components/com_content/models/fields'); $hasForm = false; $languages = JLanguageHelper::getLanguages('lang_code'); foreach ($languages as $tag => $language) { if (empty($config['language']) || $tag != $config['language']) { $hasForm = true; $f = $fieldset->addChild('field'); $f->addAttribute('name', $tag); $f->addAttribute('type', 'modal_article'); $f->addAttribute('language', $tag); $f->addAttribute('label', $language->title); $f->addAttribute('translate_label', 'false'); } } $form = JForm::getInstance($id, $addform->asXML()); if ($hasForm) { $form->load($addform, false); $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $config['pk']); if (count($associations)) { foreach ($associations as $tag => $association) { $form->setValue($tag, $name, $association->id); } } if ($config['translate_id'] && isset($config['translate'])) { $form->setValue($config['translate'], $name, $config['translate_id']); } } // Render Form $fields = $form->getFieldset('item_associations'); $form = ''; foreach ($fields as $f) { $form .= '<div class="control-group"><div class="control-label">' . $f->label . '</div><div class="controls">' . $f->input . '</div></div>'; } return $form; }
public static function getAssociations($id = 0, $view = null) { jimport('helper.route', JPATH_COMPONENT_SITE); $app = JFactory::getApplication(); $jinput = $app->input; $view = is_null($view) ? $jinput->get('view') : $view; $id = empty($id) ? $jinput->getInt('id') : $id; if ($view == 'author') { if ($id) { $associations = JLanguageAssociations::getAssociations('com_authorlist', '#__authorlist', 'com_authorlist.author', $id, 'id', '', ''); $return = array(); foreach ($associations as $tag => $item) { $author_slug = AuthorListHelperRoute::getAuthorSlug($item->id); $return[$tag] = AuthorListHelperRoute::getAuthorRoute($author_slug, $item->language); } return $return; } } return array(); }
/** * Method to get the associations for a given item * * @param integer $id Id of the item * @param string $view Name of the view * * @return array Array of associations for the item * * @since 3.0 */ public static function getAssociations($id = 0, $view = null) { $jinput = JFactory::getApplication()->input; $view = $view === null ? $jinput->get('view') : $view; $id = empty($id) ? $jinput->getInt('id') : $id; if ($view === 'contact') { if ($id) { $associations = JLanguageAssociations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $id); $return = array(); foreach ($associations as $tag => $item) { $return[$tag] = ContactHelperRoute::getContactRoute($item->id, (int) $item->catid, $item->language); } return $return; } } if ($view === 'category' || $view === 'categories') { return self::getCategoryAssociations($id, 'com_contact'); } return array(); }
/** * Render the list of associated items * * @param integer $competitie_id The competitie item id * * @return string The language HTML */ public static function association($competitie_id) { // Get the associations // Defaults $html = ''; // Get the associations if ($associations = JLanguageAssociations::getAssociations('com_knvbapi', '#__knvbapi_competities', 'com_knvbapi.competitie.item', $competitie_id, 'id', 'alias', 'catid')) { foreach ($associations as $tag => $associated) { $associations[$tag] = (int) $associated->id; } // Get the associated menu items $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.*'); $query->from($db->quoteName('#__knvbapi_competities') . ' as a'); $query->select($db->quoteName('c.title') . ' as category_title'); $query->join('LEFT', $db->quoteName('#__categories') . ' as c ON ' . $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid')); $query->where($db->quoteName('a.id') . ' IN (' . implode(',', array_values($associations)) . ')'); $query->join('LEFT', $db->quoteName('#__languages') . ' as l ON ' . $db->quoteName('a.language') . ' = ' . $db->quoteName('l.lang_code')); $query->select($db->quoteName('l.image')); $query->select($db->quoteName('l.title') . ' as language_title'); $query->select($db->quoteName('l.sef') . ' as lang_sef'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (runtimeException $e) { throw new Exception($e->getMessage(), 500); } if ($items) { foreach ($items as &$item) { $text = strtoupper($item->lang_sef); $url = JRoute::_('index.php?option=com_knvbapi&task=competitie.edit&id=' . (int) $item->id); $tooltip_parts = array(JHtml::_('image', 'mod_languages/' . $item->image . '.gif', $item->language_title, array('title' => $item->language_title), true), $item->name, '(' . $item->category_title . ')'); $item->link = JHtml::_('tooltip', implode(' ', $tooltip_parts), null, null, $text, $url, null, 'hasTooltip label label-association label-' . $item->lang_sef); } } $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * Method to get the associations for a given item * * @param integer $id Id of the item * @param string $view Name of the view * * @return array Array of associations for the item * * @since 3.0 */ public static function getAssociations($id = 0, $view = null) { jimport('helper.route', JPATH_COMPONENT_SITE); $app = JFactory::getApplication(); $jinput = $app->input; $view = is_null($view) ? $jinput->get('view') : $view; $id = empty($id) ? $jinput->getInt('id') : $id; if ($view == 'newsfeed') { if ($id) { $associations = JLanguageAssociations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $id); $return = array(); foreach ($associations as $tag => $item) { $return[$tag] = NewsfeedsHelperRoute::getNewsfeedRoute($item->id, (int) $item->catid, $item->language); } return $return; } } if ($view == 'category' || $view == 'categories') { return self::getCategoryAssociations($id, 'com_newsfeeds'); } return array(); }
/** * Method to get the associations for a given item * * @param integer $id Id of the item * @param string $view Name of the view * * @return array Array of associations for the item * * @since 3.0 */ public static function getAssociations($id = 0, $view = null) { jimport('helper.route', JPATH_COMPONENT_SITE); $app = JFactory::getApplication(); $jinput = $app->input; $view = is_null($view) ? $jinput->get('view') : $view; $id = empty($id) ? $jinput->getInt('id') : $id; if ($view == 'article') { if ($id) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id); $return = array(); JLoader::register('ContentHelper', JPATH_ADMINISTRATOR . '/components/com_content/helpers/content.php'); foreach ($associations as $tag => $item) { $return[$tag] = ContentHelperRoute::getArticleRoute($item->id, $item->catid, $item->language); } return $return; } } if ($view == 'category' || $view == 'categories') { return self::getCategoryAssociations($id, 'com_jevents'); } return array(); }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 3.2 */ public function save($data) { // Associations are not edited in frontend ATM so we have to inherit them if (JLanguageAssociations::isEnabled() && !empty($data['id'])) { if ($associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $data['id'])) { foreach ($associations as $tag => $associated) { $associations[$tag] = (int) $associated->id; } $data['associations'] = $associations; } } return parent::save($data); }
/** * Method to get a single record. * * @param integer The id of the primary key. * * @return mixed Object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { if ($item = parent::getItem($pk)) { // Convert the params field to an array. $registry = new JRegistry(); $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); // Convert the images field to an array. $registry = new JRegistry(); $registry->loadString($item->images); $item->images = $registry->toArray(); } // Load associated newsfeeds items $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $item->id); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } } } if (!empty($item->id)) { $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_newsfeeds.newsfeed'); $item->metadata['tags'] = $item->tags; } return $item; }
/** * Method to get the record form. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return mixed A JForm object on success, false on failure * * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_content.article', 'article', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } $jinput = JFactory::getApplication()->input; // The front end calls this model and uses a_id to avoid id clashes so we need to check for that first. if ($jinput->get('a_id')) { $id = $jinput->get('a_id', 0); } else { $id = $jinput->get('id', 0); } // Determine correct permissions to check. if ($this->getState('article.id')) { $id = $this->getState('article.id'); // Existing record. Can only edit in selected categories. $form->setFieldAttribute('catid', 'action', 'core.edit'); // Existing record. Can only edit own articles in selected categories. $form->setFieldAttribute('catid', 'action', 'core.edit.own'); } else { // New record. Can only create in selected categories. $form->setFieldAttribute('catid', 'action', 'core.create'); } $user = JFactory::getUser(); // Check for existing article. // Modify the form based on Edit State access controls. if ($id != 0 && !$user->authorise('core.edit.state', 'com_content.article.' . (int) $id) || $id == 0 && !$user->authorise('core.edit.state', 'com_content')) { // Disable fields for display. $form->setFieldAttribute('featured', 'disabled', 'true'); $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('publish_up', 'disabled', 'true'); $form->setFieldAttribute('publish_down', 'disabled', 'true'); $form->setFieldAttribute('state', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is an article you can edit. $form->setFieldAttribute('featured', 'filter', 'unset'); $form->setFieldAttribute('ordering', 'filter', 'unset'); $form->setFieldAttribute('publish_up', 'filter', 'unset'); $form->setFieldAttribute('publish_down', 'filter', 'unset'); $form->setFieldAttribute('state', 'filter', 'unset'); } // Prevent messing with article language and category when editing existing article with associations $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); // Check if article is associated if ($this->getState('article.id') && $app->isSite() && $assoc) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id); // Make fields read only if (!empty($associations)) { $form->setFieldAttribute('language', 'readonly', 'true'); $form->setFieldAttribute('catid', 'readonly', 'true'); $form->setFieldAttribute('language', 'filter', 'unset'); $form->setFieldAttribute('catid', 'filter', 'unset'); } } return $form; }
/** * Get the items associations * * @param integer $pk Menu item id * * @return array * * @since 3.0 */ public static function getAssociations($pk) { $langAssociations = JLanguageAssociations::getAssociations('com_menus', '#__menu', 'com_menus.item', $pk, 'id', '', ''); $associations = array(); foreach ($langAssociations as $langAssociation) { $associations[$langAssociation->language] = $langAssociation->id; } return $associations; }
/** * Method to get a single record. * * @param integer The id of the primary key. * * @return mixed Object on success, false on failure. */ public function getItem($pk = null) { if ($item = parent::getItem($pk)) { // Convert the params field to an array. $registry = new JRegistry(); $registry->loadString($item->attribs); $item->attribs = $registry->toArray(); // Convert the metadata field to an array. $registry = new JRegistry(); $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); // Convert the images field to an array. $registry = new JRegistry(); $registry->loadString($item->images); $item->images = $registry->toArray(); // Convert the urls field to an array. $registry = new JRegistry(); $registry->loadString($item->urls); $item->urls = $registry->toArray(); $item->articletext = trim($item->fulltext) != '' ? $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext : $item->introtext; if (!empty($item->id)) { $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_content.article'); } } // Load associated content items $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $item->id); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } } } return $item; }
/** * Method to get a single record. * * @param integer $pk The id of the primary key. * * @return mixed Object on success, false on failure. * * @since 1.6 */ public function getItem($pk = null) { if ($item = parent::getItem($pk)) { // Convert the metadata field to an array. $registry = new Registry(); $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); } // Load associated contact items $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $item->id); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } } } // Load item tags if (!empty($item->id)) { $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_contact.contact'); } return $item; }
<div class="<?php echo $controlsClass; ?> "> <?php echo $this->captcha; ?> </div> </div> <?php } if ($this->config->accept_term == 1) { $articleId = $this->config->article_id; if (version_compare(JVERSION, '3.1', 'ge') && JLanguageMultilang::isEnabled()) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $articleId); $langCode = JFactory::getLanguage()->getTag(); if (isset($associations[$langCode])) { $article = $associations[$langCode]; } } if (!isset($article)) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id, catid')->from('#__content')->where('id = ' . (int) $articleId); $db->setQuery($query); $article = $db->loadObject(); } require_once JPATH_ROOT . '/components/com_content/helpers/route.php'; EventbookingHelperJquery::colorbox('eb-colorbox-term'); $termLink = ContentHelperRoute::getArticleRoute($article->id, $article->catid) . '&tmpl=component&format=html';
/** * Method to get a single record. * * @param integer The id of the primary key. * * @return mixed Object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { /* if ($item = parent::getItem($pk)) { // Convert the params field to an array. $registry = new JRegistry; $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); // Convert the images field to an array. $registry = new JRegistry; $registry->loadString($item->images); $item->images = $registry->toArray(); } */ $item = parent::getItem($pk); // Load associated categories items $app = JFactory::getApplication(); $assoc = isset($app->item_associations) ? $app->item_associations : 0; if ($assoc) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_wcatalog', '#__wcatalog_categories', 'com_wcatalog.item', $item->id); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } } } if (!empty($item->id)) { $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_wcatalog.category'); $item->metadata['tags'] = $item->tags; } return $item; }
/** * Method to load item data * * @access private * @return boolean True on success * @since 1.0 */ function _loadItem($no_cache = false, $force_version = 0) { if (!$this->_id) { return false; } // Only try to load existing item //echo 'force_version: '.$force_version ."<br/>"; //echo "<pre>"; debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); echo "</pre>"; // -- To load a different item: // a. use member function function setId($id, $currcatid=0) to change primary key and then call getItem() // b. call getItem($pk, $check_view_access=true) passing the item id and maybe also disabling read access checkings, to avoid unwanted messages/errors // This is ITEM cache. NOTE: only unversioned items are cached static $items = array(); // Clear item to make sure it is reloaded if ($no_cache) { $this->_item = null; } else { if (isset($this->_item) && (!$force_version || $force_version == $this->_version)) { //echo "********************************<br/>\n RETURNING ALREADY loaded item: {$this->_id}<br/> ********************************<br/><br/><br/>"; return (bool) $this->_item; } } static $unapproved_version_notice; $db = $this->_db; $app = JFactory::getApplication(); $user = JFactory::getUser(); $cparams = $this->_cparams; $task = JRequest::getVar('task', false); $layout = JRequest::getVar('layout', false); $view = JRequest::getVar('view', false); $option = JRequest::getVar('option', false); $use_versioning = $cparams->get('use_versioning', 1); $editjf_translations = $cparams->get('editjf_translations', 0); // *********************************************************************** // Check if loading specific VERSION and generate version related messages // *********************************************************************** $current_version = (int) FLEXIUtilities::getCurrentVersions($this->_id, true, $force = true); // Get current item version $last_version = (int) FLEXIUtilities::getLastVersions($this->_id, true, $force = true); // Get last version (=latest one saved, highest version id) // -- Decide the version to load: (a) the one specified or (b) UNversioned data (these should be same as current version data) or (c) the latest one if (!$use_versioning) { // Force version to zero (load current version), when not using versioning mode $version = 0; } else { if ($force_version) { $version = (int) $force_version; if ($version == -1) { // Load latest, but catch cases when we enable versioning mode after an item has been saved in unversioning mode // in these case we will load CURRENT version instead of the default for the item edit form which is the LATEST (for backend/fontend) //echo "LOADING LATEST: current_version >= last_version : $current_version >= $last_version <br/>"; $version = $current_version >= $last_version ? 0 : $last_version; } } else { $version = 0; // Load unversioned data } } // Check if item is alredy loaded and is of correct version if ($this->_version == $version && isset($this->_item)) { return (bool) $this->_item; } $this->_version = $version; // Set number of loaded version //echo 'version: '.$version ."<br/>"; // Current version number given, the data from the versioning table should be the same as the data from normal tables // we do not force $version to ZERO to allow testing the field data of current version from the versioning table //if ($version == $current_version) $version = 0; // Force zero to retrieve unversioned data // Check if not loading the current version while we are in edit form, and raise a notice to inform the user if ($version && $version != $current_version && $task == 'edit' && $option == 'com_flexicontent' && !$unapproved_version_notice) { $unapproved_version_notice = 1; if (!$app->isAdmin()) { JError::raiseNotice(10, JText::_('FLEXI_LOADING_UNAPPROVED_VERSION_NOTICE')); } else { JError::raiseNotice(10, JText::_('FLEXI_LOADING_UNAPPROVED_VERSION_NOTICE') . ' :: ' . JText::sprintf('FLEXI_LOADED_VERSION_INFO_NOTICE', $version, $current_version)); } } // Only unversioned items are cached, use cache if no specific version was requested if (!$version && isset($items[$this->_id])) { //echo "********************************<br/>\n RETURNING CAHCED item: {$this->_id}<br/> ********************************<br/><br/><br/>"; $this->_item =& $items[$this->_id]; return (bool) $this->_item; } //echo "**************************<br/>\n LOADING item id: {$this->_id} version:{$this->_version}<br/> **************************<br/><br/><br/>"; // ********************* // TRY TO LOAD ITEM DATA // ********************* try { if ($app->isAdmin()) { // ********************** // Item Retrieval BACKEND // ********************** $item = $this->getTable('flexicontent_items', ''); $result = $item->load($this->_id); // try loading existing item data if ($result === false) { $this->_item = false; if (!$version) { $items[$this->_id] =& $this->_item; } return false; // item not found, return } } else { // *********************** // Item Retrieval FRONTEND // *********************** // Extra access columns for main category and content type (item access will be added as 'access') $select_access = 'mc.access as category_access, ty.access as type_access'; // Access Flags for: content type, main category, item $aid_arr = JAccess::getAuthorisedViewLevels($user->id); $aid_list = implode(",", $aid_arr); $select_access .= ', CASE WHEN ty.access IN (0,' . $aid_list . ') THEN 1 ELSE 0 END AS has_type_access'; $select_access .= ', CASE WHEN mc.access IN (0,' . $aid_list . ') THEN 1 ELSE 0 END AS has_mcat_access'; $select_access .= ', CASE WHEN i.access IN (0,' . $aid_list . ') THEN 1 ELSE 0 END AS has_item_access'; // SQL date strings, current date and null date $nowDate = $db->Quote(JFactory::getDate()->toSql()); $nullDate = $db->Quote($db->getNullDate()); // Decide to limit to CURRENT CATEGORY $limit_to_cid = $this->_cid ? ' AND rel.catid = ' . (int) $this->_cid : ' AND rel.catid = i.catid'; // ******************************* // Initialize and create the query // ******************************* $query = $db->getQuery(true); $query->select('i.*, ie.*'); // Item basic and extended data $query->select($select_access); // Access Columns and Access Flags for: content type, main category, item if ($version) { $query->select('ver.version_id'); } // Versioned item viewing $query->select('c.id AS catid, i.catid as maincatid'); // Current category id and Main category id $query->select('c.title AS category_title, c.alias AS category_alias, c.lft,c.rgt'); // Current category data $query->select('ty.name AS typename, ty.alias as typealias'); // Content Type data, and author data $query->select('u.name AS author'); // Author data // Rating count, Rating & Score $query->select('v.rating_count as rating_count, ROUND( v.rating_sum / v.rating_count ) AS rating, ((v.rating_sum / v.rating_count)*20) as score'); // Item and Current Category slugs (for URL) $query->select('CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as slug'); $query->select('CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as categoryslug'); // Publication Scheduled / Expired Flags $query->select('CASE WHEN i.publish_up = ' . $nullDate . ' OR i.publish_up <= ' . $nowDate . ' THEN 0 ELSE 1 END as publication_scheduled'); $query->select('CASE WHEN i.publish_down = ' . $nullDate . ' OR i.publish_down >= ' . $nowDate . ' THEN 0 ELSE 1 END as publication_expired'); // From content table, and extended item table, content type table, user table, rating table, categories relation table $query->from('#__content AS i'); $query->join('LEFT', '#__flexicontent_items_ext AS ie ON ie.item_id = i.id'); $query->join('LEFT', '#__flexicontent_types AS ty ON ie.type_id = ty.id'); $query->join('LEFT', '#__users AS u on u.id = i.created_by'); $query->join('LEFT', '#__content_rating AS v ON i.id = v.content_id'); $query->join('LEFT', '#__flexicontent_cats_item_relations AS rel ON rel.itemid = i.id' . $limit_to_cid); // Join twice on category table, once for current category and once for item's main category $query->join('LEFT', '#__categories AS c on c.id = rel.catid'); // All item's categories $query->join('LEFT', '#__categories AS mc on mc.id = i.catid'); // Item's main category // HANDLE J1.6+ ancestor category being unpublished, when badcats.id is not null, // then the item is inside in an unpublished ancestor category, thus inaccessible /*$query->select('CASE WHEN badcats.id is null THEN 1 ELSE 0 END AS ancestor_cats_published'); $subquery = ' (SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent '; $subquery .= 'ON cat.lft BETWEEN parent.lft AND parent.rgt '; $subquery .= 'WHERE parent.extension = ' . $db->Quote('com_content'); $subquery .= ' AND parent.published <= 0 GROUP BY cat.id)'; $query->join('LEFT', $subquery . ' AS badcats ON badcats.id = c.id');*/ if ($version) { // NOTE: version_id is used by field helper file to load the specified version, the reason for left join here is to verify that the version exists $query->join('LEFT', '#__flexicontent_versions AS ver ON ver.item_id = i.id AND ver.version_id = ' . $db->Quote($version)); } // Join on contact table, to get contact data of author //$query = 'SHOW TABLES LIKE "' . JFactory::getApplication()->getCfg('dbprefix') . 'contact_details"'; //$db->setQuery($query); //$contact_details_tbl_exists = (boolean) count($db->loadObjectList()); //if ( $contact_details_tbl_exists) { // $query->select('contact.id as contactid' ) ; // $query->join('LEFT','#__contact_details AS contact on contact.user_id = i.created_by'); //} // Join over the categories to get parent category titles //$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias'); //$query->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); $query->where('i.id = ' . (int) $this->_id); //echo $db->replacePrefix($query); $db->setQuery($query); // Try to execute query directly and load the data as an object if (FLEXI_FISH && $task == 'edit' && $option == 'com_flexicontent' && in_array($app->getCfg('dbtype'), array('mysqli', 'mysql'))) { $data = flexicontent_db::directQuery($query); $data = @$data[0]; //$data = $db->loadObject(null, false); // do not, translate, this is the JoomFish overridden method of Database extended Class } else { $data = $db->loadObject(); } // Check for SQL error if ($db->getErrorNum()) { throw new Exception($db->getErrorMsg(), 500); } //print_r($data); exit; if (!$data) { $this->_item = false; $this->_typeid = 0; if (!$version) { $items[$this->_id] =& $this->_item; } return false; // item not found, return } if ($version && !$data->version_id) { JError::raiseNotice(10, JText::sprintf('NOTICE: Requested item version %d was not found, loaded currently active version', $version)); } $item =& $data; } $this->_typeid = $item->type_id; // -- Create the description field called 'text' by appending introtext + readmore + fulltext $item->text = $item->introtext; $item->text .= JString::strlen(trim($item->fulltext)) ? '<hr id="system-readmore" />' . $item->fulltext : ""; //echo "<br/>Current version (Frontend Active): " . $item->version; //echo "<br/>Version to load: ".$version; //echo "<br/><b> *** db title:</b> ".$item->title; //echo "<br/><b> *** db text:</b> ".$item->text; //echo "<pre>*** item data: "; print_r($item); echo "</pre>"; exit; // Load associated content items $useAssocs = $this->useAssociations(); if ($useAssocs) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $item->id); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } JArrayHelper::toInteger($item->associations); } } // ************************************************************************************************* // -- Retrieve all active site languages, and create empty item translation objects for each of them // ************************************************************************************************* $nn_content_tbl = 'falang_content'; if (FLEXI_FISH) { $site_languages = FLEXIUtilities::getlanguageslist(); $item_translations = new stdClass(); foreach ($site_languages as $lang_id => $lang_data) { if (!$lang_id && $item->language != '*') { continue; } $lang_data->fields = new stdClass(); $item_translations->{$lang_id} = $lang_data; } } // ********************************** // Retrieve and prepare JoomFish data // ********************************** if (FLEXI_FISH && $task == 'edit' && $option == 'com_flexicontent') { // -- Try to retrieve all joomfish data for the current item $query = "SELECT jfc.language_id, jfc.reference_field, jfc.value, jfc.published " . " FROM #__" . $nn_content_tbl . " as jfc " . " WHERE jfc.reference_table='content' AND jfc.reference_id = {$this->_id} "; $db->setQuery($query); $translated_fields = $db->loadObjectList(); if ($editjf_translations == 0 && $translated_fields) { // 1:disable without warning about found translations $app->enqueueMessage("3rd party Joom!Fish/Falang translations detected for current item." . " You can either enable editing them or disable this message in FLEXIcontent component configuration", 'message'); } else { if ($editjf_translations == 2) { if ($db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($db->getErrorMsg()), 'error'); } // -- Parse translation data according to their language if ($translated_fields) { // Add retrieved translated item properties foreach ($translated_fields as $field_data) { $item_translations->{$field_data->language_id}->fields->{$field_data->reference_field} = new stdClass(); $item_translations->{$field_data->language_id}->fields->{$field_data->reference_field}->value = $field_data->value; $found_languages[$field_data->language_id] = $item_translations->{$field_data->language_id}->name; } //echo "<br/>Joom!Fish translations found for: " . implode(",", $found_languages); } foreach ($item_translations as $lang_id => $translation_data) { // Default title can be somewhat long, trim it to first word, so that it is more suitable for tabs list($translation_data->name) = explode(' ', trim($translation_data->name)); // Create text field value for all languages $translation_data->fields->text = new stdClass(); $translation_data->fields->text->value = @$translation_data->fields->introtext->value; if (JString::strlen(trim(@$translation_data->fields->fulltext->value))) { $translation_data->fields->text->value .= '<hr id="system-readmore" />' . @$translation_data->fields->fulltext->value; } } $item->item_translations =& $item_translations; } } } //echo "<pre>"; print_r($item->item_translations); exit; // ***************************************************** // Overwrite item fields with the requested VERSION data // ***************************************************** $item->current_version = $current_version; $item->last_version = $last_version; if ($use_versioning && $version) { // Overcome possible group concat limitation $query = "SET SESSION group_concat_max_len = 9999999"; $db->setQuery($query); $db->query(); $query = "SELECT f.id, f.name, f.field_type, GROUP_CONCAT(iv.value SEPARATOR ',') as value, count(f.id) as valuecount, iv.field_id" . " FROM #__flexicontent_items_versions as iv " . " LEFT JOIN #__flexicontent_fields as f on f.id=iv.field_id" . " WHERE iv.version='" . $version . "' AND (f.iscore=1 OR iv.field_id=-1 OR iv.field_id=-2) AND iv.item_id='" . $this->_id . "'" . " GROUP BY f.id"; $db->setQuery($query); $fields = $db->loadObjectList(); $fields = $fields ? $fields : array(); //echo "<br/>Overwritting fields with version: $version"; foreach ($fields as $f) { //echo "<br/><b>{$f->field_id} : ". $f->name."</b> : "; print_r($f->value); // Use versioned data, by overwriting the item data $fieldname = $f->name; if ($f->field_type == 'hits' || $f->field_type == 'state' || $f->field_type == 'voting') { // skip fields that should not have been versioned: hits, state, voting continue; } else { if ($f->field_type == 'version') { // set version variable to indicate the loaded version $item->version = $version; } else { if ($fieldname == 'categories' || $fieldname == 'tags') { // categories and tags must have been serialized but some earlier versions did not do it, // we will check before unserializing them, otherwise they were concatenated to a single string and use explode ... $item->{$fieldname} = ($array = @unserialize($f->value)) ? $array : explode(",", $f->value); } else { if ($f->field_id == -1) { if (FLEXI_FISH) { $jfdata = unserialize($f->value); $item_lang = substr($item->language, 0, 2); foreach ($item_translations as $lang_id => $translation_data) { //echo "<br/>Adding values for: ".$translation_data->shortcode; if (empty($jfdata[$translation_data->shortcode])) { continue; } foreach ($jfdata[$translation_data->shortcode] as $fieldname => $fieldvalue) { //echo "<br/>".$translation_data->shortcode.": $fieldname => $fieldvalue"; if ($translation_data->shortcode != $item_lang) { $translation_data->fields->{$fieldname} = new stdClass(); $translation_data->fields->{$fieldname}->value = $fieldvalue; } else { $item->{$fieldname} = $fieldvalue; } } } } } else { if ($f->field_id == -2) { // Other item properties that were versioned, such as alias, catid, meta params, attribs $item_data = unserialize($f->value); //$item->bind($item_data); foreach ($item_data as $k => $v) { $item->{$k} = $v; } } else { if ($fieldname) { // Other fields (maybe serialized or not but we do not unserialized them, this is responsibility of the field itself) $item->{$fieldname} = $f->value; } } } } } } } // The text field is stored in the db as to seperate fields: introtext & fulltext // So we search for the {readmore} tag and split up the text field accordingly. $this->splitText($item); } // -- Retrieve tags field value (if not using versioning) if ($use_versioning && $version) { // Check version value was found if (!isset($item->tags) || !is_array($item->tags)) { $item->tags = array(); } } else { // Retrieve unversioned value $query = 'SELECT DISTINCT tid FROM #__flexicontent_tags_item_relations WHERE itemid = ' . (int) $this->_id; $db->setQuery($query); $item->tags = $db->loadColumn(); } // -- Retrieve categories field value (if not using versioning) if ($use_versioning && $version) { // Check version value was found, and is valid (above code should have produced an array) if (!isset($item->categories) || !is_array($item->categories)) { $item->categories = array(); } } else { // Retrieve unversioned value $query = 'SELECT DISTINCT catid FROM #__flexicontent_cats_item_relations WHERE itemid = ' . (int) $this->_id; $db->setQuery($query); $item->categories = $db->loadColumn(); } // Make sure catid is in categories array if (!in_array($item->catid, $item->categories)) { $item->categories[] = $item->catid; } // 'cats' is an alias of categories $item->cats =& $item->categories; // Set original content item id, e.g. maybe used by some fields that are marked as untranslatable $enable_translation_groups = flexicontent_db::useAssociations(); //$cparams->get('enable_translation_groups'); if ($enable_translation_groups) { $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2); $is_content_default_lang = $site_default == substr($item->language, 0, 2); if ($is_content_default_lang) { $item->lang_parent_id = $item->id; } else { $item->lang_parent_id = 0; $langAssocs = $this->getLangAssocs($item->id); foreach ($langAssocs as $content_id => $_assoc) { if ($site_default == substr($_assoc->language, 0, 2)) { $item->lang_parent_id = $content_id; break; } } } } // ********************************************************* // Retrieve item properties not defined in the model's CLASS // ********************************************************* $query = 'SELECT title FROM #__viewlevels WHERE id = ' . (int) $item->access; $db->setQuery($query); $item->access_level = $db->loadResult(); // Category access is retrieved here for J1.6+, for J1.5 we use FLEXIaccess // Get category access for the item's main category, used later to determine viewing of the item $query = 'SELECT access FROM #__categories WHERE id = ' . (int) $item->catid; $db->setQuery($query); $item->category_access = $db->loadResult(); // Typecast some properties in case LEFT JOIN produced nulls if (!isset($item->type_access)) { $public_acclevel = 1; $item->type_access = $public_acclevel; } if (!isset($item->rating_count)) { // Get category access for the item's main category, used later to determine viewing of the item $query = 'SELECT ' . ' v.rating_count as rating_count, ROUND( v.rating_sum / v.rating_count ) AS rating, ((v.rating_sum / v.rating_count)*20) as score' . ' FROM #__content_rating AS v WHERE v.content_id = ' . (int) $item->id; $db->setQuery($query); $rating_data = $db->loadObject(); $item->rating_count = !$rating_data ? 0 : $rating_data->rating_count; $item->rating = !$rating_data ? 0 : $rating_data->rating_count; $item->score = !$rating_data ? 0 : $rating_data->score; } $item->typename = (string) @$item->typename; $item->typealias = (string) @$item->typealias; // Retrieve Creator NAME and email (used to display the gravatar) $query = 'SELECT name, email FROM #__users WHERE id = ' . (int) $item->created_by; $db->setQuery($query); $creator_data = $db->loadObject(); $item->creator = $creator_data ? $creator_data->name : ''; $item->creatoremail = $creator_data ? $creator_data->email : ''; // Retrieve Modifier NAME if ($item->created_by == $item->modified_by) { $item->modifier = $item->creator; } else { $query = 'SELECT name, email FROM #__users WHERE id = ' . (int) $item->modified_by; $db->setQuery($query); $modifier_data = $db->loadObject(); $item->modifier = $modifier_data ? $modifier_data->name : ''; $item->modifieremail = $modifier_data ? $modifier_data->email : ''; } // Clear modified Date, if it is an invalid "null" date if ($item->modified == $db->getNulldate()) { $item->modified = null; } // *************************************************************************************** // Assign to the item data member variable and cache it if loaded an unversioned item data // *************************************************************************************** $this->_item =& $item; if (!$version) { $items[$this->_id] =& $this->_item; } // ****************************************************************************************************** // Detect if current version doesnot exist in version table and add it !!! e.g. after enabling versioning // ****************************************************************************************************** if ($use_versioning && $current_version > $last_version) { require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'flexicontent.php'; $fleximodel = new FlexicontentModelFlexicontent(); $fleximodel->addCurrentVersionData($item->id); $item->last_version = $last_version = $current_version; } } catch (JException $e) { $this->_item = false; if ($e->getCode() == 404) { // Need to go thru the error handler to allow Redirect to work. $msg = $e->getMessage(); throw new Exception($msg, 404); } else { $this->setError($e); $this->_item = false; } } /*$session = JFactory::getSession(); $postdata = $session->get('item_edit_postdata', array(), 'flexicontent'); if (count($postdata)) { $session->set('item_edit_postdata', null, 'flexicontent'); // ... }*/ // Add to cache if it is non-version data if (!$version) { $items[$this->_id] =& $this->_item; } // return true if item was loaded successfully return (bool) $this->_item; }
/** * Method to get a single record. * * @param * integer The id of the primary key. * * @return mixed Object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { if ($item = parent::getItem($pk)) { // vardie($item); // Convert the params field to an array. $registry = new JRegistry(); $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); /* * / Convert the images field to an array. $registry = new JRegistry; $registry->loadString($item->images); $item->images = $registry->toArray(); */ } $db = JFactory::getDBO(); if (!empty($item->id)) { // Load user (author) $item->author = JUser::getInstance($item->created_by)->name; // Load category $db->setQuery("SELECT title FROM #__categories WHERE id = " . $item->catid . " LIMIT 1;"); $item->category_title = $db->loadResult(); } else { // Get latest number $db->setQuery("SELECT COUNT(id) FROM #__edashboard"); if ($db->loadResult() > 0) { // If numerical ordering: // Autoincrement? jimport('joomla.application.component.helper'); if (JComponentHelper::getParams('com_edashboard')->get('autoincrement_sort_numerically') != '0') { $db->setQuery("SELECT official_number FROM #__edashboard ORDER BY CAST(official_number as SIGNED INTEGER) DESC LIMIT 1;"); } else { $db->setQuery("SELECT official_number FROM #__edashboard ORDER BY official_number DESC LIMIT 1;"); } $item->official_number = (int) $db->loadResult() + 1; } else { $item->official_number = 1; } } if ($item->id) { $db->setQuery("SELECT * FROM #__edashboard_attachments WHERE edashboard_id = " . $item->id . " order by ordering ASC"); $item->filenames = $db->loadAssocList(); } // Load associated edashboard items $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_edashboard', '#__edashboard', 'com_edashboard.item', $item->id); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } } } if (!empty($item->id)) { $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_edashboard.post'); $item->metadata['tags'] = $item->tags; } return $item; }
public static function getRouteByStorage(&$storage, $sef, $itemId, $config = array(), $lang_tag = '') { if (isset($storage[self::$table]->_route) && !$lang_tag) { return JRoute::_($storage[self::$table]->_route); } if ($sef) { if ($sef == '0' || $sef == '1') { $path = '&catid=' . $storage[self::$table]->catid; } elseif ($sef[0] == '4') { $path = '&catid=' . (isset($storage[self::$table]->category_alias) ? $storage[self::$table]->category_alias : $storage[self::$table]->catid); } elseif ($sef[0] == '3') { $path = '&typeid=' . $config['type']; } else { $path = ''; } if (is_object($storage[self::$table])) { $storage[self::$table]->_route = self::_getRoute($sef, $itemId, $storage[self::$table]->slug, $path); } // Multilanguage Associations if (JCckDevHelper::hasLanguageAssociations()) { $app = JFactory::getApplication(); $pk = $storage[self::$table]->id; if ($app->input->get('view') == 'article' && $app->input->get('id') == $storage[self::$table]->id && !count(self::$routes)) { JLoader::register('MenusHelper', JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php'); $assoc_c = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $pk); $assoc_m = MenusHelper::getAssociations($itemId); $languages = JLanguageHelper::getLanguages(); $lang_code = JFactory::getLanguage()->getTag(); foreach ($languages as $l) { if ($lang_code == $l->lang_code) { self::$routes[$l->lang_code] = $storage[self::$table]->_route; } else { $itemId2 = isset($assoc_m[$l->lang_code]) ? $assoc_m[$l->lang_code] : 0; $pk2 = isset($assoc_c[$l->lang_code]) ? (int) $assoc_c[$l->lang_code]->id : 0; self::$routes[$l->lang_code] = ''; if ($pk2 && $itemId2) { self::$routes[$l->lang_code] = self::getRoute($pk2, $sef, $itemId2, $config, $l->sef); } } } } } } else { require_once JPATH_SITE . '/components/com_content/helpers/route.php'; $storage[self::$table]->_route = ContentHelperRoute::getArticleRoute($storage[self::$table]->slug, $storage[self::$table]->catid, $storage[self::$table]->language); } return JRoute::_($storage[self::$table]->_route); }
/** * Method to get a single record. * * @param integer The id of the primary key. * * @return mixed Object on success, false on failure. */ public function getItem($pk = null) { if ($item = parent::getItem($pk)) { // Convert the params field to an array. $registry = new JRegistry(); $registry->loadString($item->attribs); $item->attribs = $registry->toArray(); // Convert the metadata field to an array. $registry = new JRegistry(); $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); // Convert the images field to an array. $registry = new JRegistry(); $registry->loadString($item->images); $item->images = $registry->toArray(); // Convert the urls field to an array. $registry = new JRegistry(); $registry->loadString($item->urls); $item->urls = $registry->toArray(); $item->articletext = trim($item->fulltext) != '' ? $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext : $item->introtext; if ($pContent = $this->getFieldsContent()) { if (isset($pContent->audio)) { $item->audio_soundcloud_id = $pContent->audio->audio_id; $item->audio_soundcloud_hidden_image = $pContent->audio->audiothumb; $item->audio_soundcloud_title = $pContent->audio->audiotitle; } $item->quote_author = $pContent->quote_author; $item->quote_text = $pContent->quote_text; $item->link_title = $pContent->link_title; $item->link_url = $pContent->link_url; $item->link_follow = $pContent->link_follow; $item->link_target = $pContent->link_target; } } if (COM_TZ_PORTFOLIO_JVERSION_COMPARE) { // Load associated content items $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $item->id); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } } } } return $item; }
/** * Method to copy items * * @access public * @return boolean True on success * @since 1.5 */ function copyitems($cid, $keeptags = 1, $prefix, $suffix, $copynr = 1, $lang = null, $state = null, $method = 1, $maincat = null, $seccats = null, $type_id = null, $access = null) { $app = JFactory::getApplication(); $jinput = $app->input; $dbprefix = $app->getCfg('dbprefix'); $use_versioning = $this->cparams->get('use_versioning', 1); require_once "components/com_flexicontent/models/item.php"; // ************************************************************************ // Try to find Falang/Joomfish, to import translation data, if so requested // ************************************************************************ $_FALANG = false; $this->_db->setQuery('SHOW TABLES LIKE "' . $dbprefix . 'falang_content"'); $_FALANG = (bool) count($this->_db->loadObjectList()); // Try to find old joomfish tables (with current DB prefix) $this->_db->setQuery('SHOW TABLES LIKE "' . $dbprefix . 'jf_content"'); $_FISH = (bool) count($this->_db->loadObjectList()); // Try to find old joomfish tables (with J1.5 jos prefix) if (!$_FISH) { $this->_db->setQuery('SHOW TABLES LIKE "jos_jf_content"'); if (count($this->_db->loadObjectList())) { $_FISH = true; $dbprefix = 'jos_'; } } // Detect version of joomfish tables $_FISH22GE = false; if ($_FISH) { $this->_db->setQuery('SHOW TABLES LIKE "' . $dbprefix . 'jf_languages_ext"'); $_FISH22GE = (bool) count($this->_db->loadObjectList()); } $_NEW_LANG_TBL = FLEXI_J16GE || $_FISH22GE; // Get if translation is to be performed, 1: FLEXI_DUPLICATEORIGINAL, 2: FLEXI_USE_JF_DATA, 3: FLEXI_AUTO_TRANSLATION, 4: FLEXI_FIRST_JF_THEN_AUTO if ($method == 99) { $translate_method = $jinput->get('translate_method', 1, 'int'); } else { $translate_method = 0; } // If translation method import the translator class if ($translate_method == 3 || $translate_method == 4) { require_once JPATH_COMPONENT_SITE . DS . 'helpers' . DS . 'translator.php'; } // If translation method load description field to allow some parsing according to parameters if ($translate_method == 3 || $translate_method == 4) { $this->_db->setQuery('SELECT id FROM #__flexicontent_fields WHERE name = "text" '); $desc_field_id = $this->_db->loadResult(); $desc_field = JTable::getInstance('flexicontent_fields', ''); $desc_field->load($desc_field_id); } // ************************************************************ // Loop through the items, copying, moving, or translating them // ************************************************************ foreach ($cid as $itemid) { for ($nr = 0; $nr < $copynr; $nr++) { // (a) Get existing item $item = JTable::getInstance('flexicontent_items', ''); $item->load($itemid); // Some shortcuts $sourceid = (int) $item->id; $curversion = (int) $item->version; // (b) We create copy so that the original data are always available $row = clone $item; // (c) Force creation & assigning of new records by cleaning the primary keys $row->id = null; // force creation of new record in _content DB table $row->item_id = null; // force creation of new record in _flexicontent_ext DB table $row->asset_id = null; // force creation of new record in _assets DB table // (d) Start altering the properties of the cloned item $row->title = ($prefix ? $prefix . ' ' : '') . $item->title . ($suffix ? ' ' . $suffix : ''); $row->hits = 0; if (!$translate_method) { // cleared featured flag if not translating $row->featured = 0; } $row->version = 1; $datenow = JFactory::getDate(); $row->created = $datenow->toSql(); $row->publish_up = $datenow->toSql(); $row->modified = $nullDate = $this->_db->getNullDate(); $lang_from = substr($row->language, 0, 2); $row->language = $lang ? $lang : $row->language; $lang_to = substr($row->language, 0, 2); $row->state = strlen($state) ? $state : $row->state; // keep original if: null, '' $row->type_id = $type_id ? $type_id : $row->type_id; // keep original if: null, zero, '' $row->access = $access ? $access : $row->access; // keep original if: null, zero, '' $doauto['title'] = $doauto['introtext'] = $doauto['fulltext'] = $doauto['metakey'] = $doauto['metadesc'] = true; // In case JF data is missing if ($translate_method == 2 || $translate_method == 4) { // a. Try to get joomfish/falang translation from the item $jfitemfields = false; if ($_FALANG) { $query = "SELECT c.* FROM `#__falang_content` AS c " . " LEFT JOIN #__languages AS lg ON c.language_id=lg.lang_id" . " WHERE c.reference_table = 'content' AND lg.lang_code='" . $row->language . "' AND c.reference_id = " . $sourceid; $this->_db->setQuery($query); $jfitemfields = $this->_db->loadObjectList(); } if (!$jfitemfields && $_FISH) { $query = "SELECT c.* FROM `" . $dbprefix . "jf_content` AS c " . " LEFT JOIN #__languages AS lg ON c.language_id=" . ($_NEW_LANG_TBL ? "lg.lang_id" : "lg.id") . " WHERE c.reference_table = 'content' AND " . ($_NEW_LANG_TBL ? "lg.lang_code" : "lg.code") . "='" . $row->language . "' AND c.reference_id = " . $sourceid; $this->_db->setQuery($query); $jfitemfields = $this->_db->loadObjectList(); } // b. if joomfish translation found set for the new item if ($jfitemfields) { $jfitemdata = new stdClass(); foreach ($jfitemfields as $jfitemfield) { $jfitemdata->{$jfitemfield->reference_field} = $jfitemfield->value; } if (isset($jfitemdata->title) && mb_strlen($jfitemdata->title) > 0) { $row->title = $jfitemdata->title; $doauto['title'] = false; } if (isset($jfitemdata->alias) && mb_strlen($jfitemdata->alias) > 0) { $row->alias = $jfitemdata->alias; } if (isset($jfitemdata->introtext) && mb_strlen(strip_tags($jfitemdata->introtext)) > 0) { $row->introtext = $jfitemdata->introtext; $doauto['introtext'] = false; } if (isset($jfitemdata->fulltext) && mb_strlen(strip_tags($jfitemdata->fulltext)) > 0) { $row->fulltext = $jfitemdata->fulltext; $doauto['fulltext'] = false; } if (isset($jfitemdata->metakey) && mb_strlen($jfitemdata->metakey) > 0) { $row->metakey = $jfitemdata->metakey; $doauto['metakey'] = false; } if (isset($jfitemdata->metadesc) && mb_strlen($jfitemdata->metadesc) > 0) { $row->metadesc = $jfitemdata->metadesc; $doauto['metadesc'] = false; } } } // Try to do automatic translation from the item, if autotranslate is SET and --NOT found-- or --NOT using-- JoomFish Data if ($translate_method == 3 || $translate_method == 4) { // Translate fulltext item property, using the function for which handles custom fields TYPES: text, textarea, ETC if ($doauto['fulltext']) { $desc_field->value = $row->fulltext; $fields = array(&$desc_field); $this->translateFieldValues($fields, $row, $lang_from, $lang_to); $row->fulltext = $desc_field->value; } // TRANSLATE basic item properties (if not already imported via Joomfish) $translatables = array('title', 'introtext', 'metakey', 'metadesc'); $fieldnames_arr = array(); $fieldvalues_arr = array(); foreach ($translatables as $translatable) { if (!$doauto[$translatable]) { continue; } $fieldnames_arr[] = $translatable; $translatable_obj = new stdClass(); $translatable_obj->originalValue = $row->{$translatable}; $translatable_obj->noTranslate = false; $fieldvalues_arr[] = $translatable_obj; } if (count($fieldvalues_arr)) { $result = autoTranslator::translateItem($fieldnames_arr, $fieldvalues_arr, $lang_from, $lang_to); if (intval($result)) { $n = 0; foreach ($fieldnames_arr as $fieldname) { $row->{$fieldname} = $fieldvalues_arr[$n]->translationValue; $n++; } } } } //print_r($row->fulltext); exit; // Create a new item in the content fc_items_ext table $row->store(); // Not doing a translation, we start a new language group for the new item if ($translate_method == 0) { $row->lang_parent_id = 0; //$row->id; $row->store(); } // *********************************************************** // Copy custom fields, translating the fields if so configured // *********************************************************** $doTranslation = $translate_method == 3 || $translate_method == 4; $query = 'SELECT fir.*, f.* ' . ' FROM #__flexicontent_fields_item_relations as fir' . ' LEFT JOIN #__flexicontent_fields as f ON f.id=fir.field_id' . ' WHERE item_id = ' . $sourceid; $this->_db->setQuery($query); $fields = $this->_db->loadObjectList(); //echo "<pre>"; print_r($fields); exit; if ($doTranslation) { $this->translateFieldValues($fields, $row, $lang_from, $lang_to); } //foreach ($fields as $field) if ($field->field_type!='text' && $field->field_type!='textarea') { print_r($field->value); echo "<br><br>"; } foreach ($fields as $field) { if (strlen($field->value)) { $query = 'INSERT INTO #__flexicontent_fields_item_relations (`field_id`, `item_id`, `valueorder`, `suborder`, `value`)' . ' VALUES(' . $field->field_id . ', ' . $row->id . ', ' . $field->valueorder . ', ' . $field->suborder . ', ' . $this->_db->Quote($field->value) . ')'; $this->_db->setQuery($query); $this->_db->execute(); } } if ($use_versioning) { $v = new stdClass(); $v->item_id = (int) $item->id; $v->version_id = 1; $v->created = $item->created; $v->created_by = $item->created_by; //$v->comment = 'copy version.'; $this->_db->insertObject('#__flexicontent_versions', $v); } // get the items versions $query = 'SELECT *' . ' FROM #__flexicontent_items_versions' . ' WHERE item_id = ' . $sourceid . ' AND version = ' . $curversion; $this->_db->setQuery($query); $curversions = $this->_db->loadObjectList(); foreach ($curversions as $cv) { $query = 'INSERT INTO #__flexicontent_items_versions (`version`, `field_id`, `item_id`, `valueorder`, `suborder`, `value`)' . ' VALUES(1 ,' . $cv->field_id . ', ' . $row->id . ', ' . $cv->valueorder . ', ' . $cv->suborder . ', ' . $this->_db->Quote($cv->value) . ')'; $this->_db->setQuery($query); $this->_db->execute(); } // get the item categories $query = 'SELECT catid' . ' FROM #__flexicontent_cats_item_relations' . ' WHERE itemid = ' . $sourceid; $this->_db->setQuery($query); $cats = $this->_db->loadColumn(); foreach ($cats as $cat) { $query = 'INSERT INTO #__flexicontent_cats_item_relations (`catid`, `itemid`)' . ' VALUES(' . $cat . ',' . $row->id . ')'; $this->_db->setQuery($query); $this->_db->execute(); } if ($keeptags) { // get the item tags $query = 'SELECT tid' . ' FROM #__flexicontent_tags_item_relations' . ' WHERE itemid = ' . $sourceid; $this->_db->setQuery($query); $tags = $this->_db->loadColumn(); foreach ($tags as $tag) { $query = 'INSERT INTO #__flexicontent_tags_item_relations (`tid`, `itemid`)' . ' VALUES(' . $tag . ',' . $row->id . ')'; $this->_db->setQuery($query); $this->_db->execute(); } } if ($method == 3) { $this->moveitem($row->id, $maincat, $seccats); } else { if ($method == 99 && ($maincat || $seccats)) { $row->catid = $maincat ? $maincat : $row->catid; $this->moveitem($row->id, $row->catid, $seccats); } } // Load item model and save it once, e.g. updating Joomla featured FLAG data //$itemmodel = new FlexicontentModelItem(); //$itemmodel->getItem($row->id); //$itemmodel->store((array)$row); // If new item is a tranlation, load the language associations of item // that was copied, and save the associations, adding the new item to them if ($method == 99 && $item->language != '*' && $row->language != '*' && flexicontent_db::useAssociations()) { $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $item->id); // associations of item that was copied $_data = array(); foreach ($associations as $tag => $association) { $_data['associations'][$tag] = (int) $association->id; } $_data['associations'][$row->language] = $row->id; // Add new item itself $_data['associations'][$item->language] = $item->id; // unneeded, done by saving ... $context = 'com_content'; flexicontent_db::saveAssociations($row, $_data, $context); // Save associations, adding the new item //$app->enqueueMessage( print_r($_data, true), 'message' ); } } } return true; }
/** * Method to get a single record. * * @param integer The id of the primary key. * * @return mixed Object on success, false on failure. */ public function getItem($pk = null) { if ($item = parent::getItem($pk)) { // Include any manipulation of the data on the record e.g. expand out Registry fields // NB The params registry field - if used - is done automatically in the JAdminModel parent class // Convert the images field to an array. $registry = new Registry(); $registry->loadString($item->images); $item->images = $registry->toArray(); $registry = null; //release memory // Convert the urls field to an array. $registry = new Registry(); $registry->loadString($item->urls); $item->urls = $registry->toArray(); $registry = null; //release memory $item->introdescription = trim($item->intro) != '' ? $item->intro . "<hr id=\"system-readmore\" />" . $item->description : $item->description; if (!empty($item->id)) { $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_knvbapi2.teamnaam'); } } // Load associated content items $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $item->associations = array(); if ($item->id != null) { $associations = JLanguageAssociations::getAssociations('com_knvbapi2', '#__knvbapi2_teamnaams', 'com_knvbapi2.teamnaam.item', $item->id, 'id', 'alias', 'catid'); foreach ($associations as $tag => $association) { $item->associations[$tag] = $association->id; } } } return $item; }
public function onCCK_FieldPrepareForm(&$field, $value = '', &$config = array(), $inherit = array(), $return = false) { if (self::$type != $field->type) { return; } self::$path = parent::g_getPath(self::$type . '/'); parent::g_onCCK_FieldPrepareForm($field, $config); // Init if (count($inherit)) { $id = isset($inherit['id']) && $inherit['id'] != '' ? $inherit['id'] : $field->name; $name = isset($inherit['name']) && $inherit['name'] != '' ? $inherit['name'] : $field->name; } else { $id = $field->name; $name = $field->name; } $value = $value != '' ? $value : $field->defaultvalue; $value = $value != ' ' ? $value : ''; // Validate $validate = ''; if ($config['doValidation'] > 1) { plgCCK_Field_ValidationRequired::onCCK_Field_ValidationPrepareForm($field, $id, $config); $validate = count($field->validate) ? ' validate[' . implode(',', $field->validate) . ']' : ''; } // Prepare $app = JFactory::getApplication(); $assoc = isset($app->item_associations) ? $app->item_associations : 0; $form = ''; if ($assoc && $config['pk']) { $languages = JLanguageHelper::getLanguages('lang_code'); // Create Form $addform = new SimpleXMLElement('<form />'); $fields = $addform->addChild('fields'); $fields->addAttribute('name', $name); $fieldset = $fields->addChild('fieldset'); $fieldset->addAttribute('name', 'item_associations'); $fieldset->addAttribute('description', 'COM_CONTENT_ITEM_ASSOCIATIONS_FIELDSET_DESC'); $fieldset->addAttribute('addfieldpath', '/administrator/components/com_content/models/fields'); $hasForm = false; foreach ($languages as $tag => $language) { if (empty($config['language']) || $tag != $config['language']) { $hasForm = true; $f = $fieldset->addChild('field'); $f->addAttribute('name', $tag); $f->addAttribute('type', 'modal_article'); $f->addAttribute('language', $tag); $f->addAttribute('label', $language->title); $f->addAttribute('translate_label', 'false'); } } $form = JForm::getInstance($id, $addform->asXML()); if ($hasForm) { $form->load($addform, false); $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $config['pk']); if (count($associations)) { foreach ($associations as $tag => $association) { $form->setValue($tag, $name, $association->id); } } if ($config['translate_id'] && isset($config['translate'])) { $form->setValue($config['translate'], $name, $config['translate_id']); } } // Render Form $fields = $form->getFieldset('item_associations'); $form = ''; foreach ($fields as $f) { $form .= '<div class="control-group"><div class="control-label">' . $f->label . '</div><div class="controls">' . $f->input . '</div></div>'; } } // Set if (!$field->variation) { $field->form = $form; if ($field->script) { parent::g_addScriptDeclaration($field->script); } } else { // } $field->value = $value; // Return if ($return === true) { return $field; } }