public function getArticles($tree_id) { // general input $app = JFactory::getApplication(); $languageFilter = $app->getLanguageFilter(); $db = JFactory::getDBO(); $query = $db->getQuery(true); // get user access info $levels = JoaktreeHelper::getUserAccessLevels(); // initialization $retArticles = array(); $nullDate = $db->getNullDate(); $date = JFactory::getDate(); $now = $date->toSql(); //remove single space after commas in keywords $attribs = array(); $attribs[] = '","'; $attribs[] = 'REPLACE( a.metakey, ", ", "," )'; $attribs[] = '","'; $concat = $query->concatenate($attribs, ','); // end concats // select from content $query->select(' a.id AS id '); $query->select(' a.title AS title '); $query->select(' a.introtext AS introtext '); $query->select(' a.fulltext AS \'fulltext\' '); $query->select(' DATE_FORMAT( a.modified, "%e %b %Y" ) AS modified '); $query->select(' a.attribs AS attribs '); $query->from(' #__content AS a '); $query->where(' a.state = 1 '); $query->where(' a.access IN ' . $levels . ' '); $query->where(' ( a.publish_up = ' . $db->Quote($nullDate) . ' ' . ' OR a.publish_up <= ' . $db->Quote($now) . ' ' . ' ) '); $query->where(' ( a.publish_down = ' . $db->Quote($nullDate) . ' ' . ' OR a.publish_down >= ' . $db->Quote($now) . ' ' . ' ) '); // Filter by language if ($languageFilter) { $query->where('a.language in (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ') '); } // select from categories // join with tree to find matching category $query->select(' cc.id AS cat_id '); $query->innerJoin(' #__categories AS cc ' . ' ON ( cc.id = a.catid ' . ' AND cc.access IN ' . $levels . ' ' . ' ) '); $query->innerJoin(' #__joaktree_trees AS jte ' . ' ON ( cc.id = jte.catid ' . ' AND jte.id = ' . (int) $tree_id . ' ' . ' ) '); $db->setQuery($query); $articles = $db->loadObjectList(); foreach ($articles as $article) { // Convert parameter fields to objects for article. if (isset($article->attribs)) { $registry = new JRegistry(); $registry->loadString($article->attribs); $indIntrotext = (int) $registry->get('show_intro', 1); $article->showTitle = (int) $registry->get('show_title', 1); } else { $indIntrotext = 0; $article->showTitle = 1; } // Are we showing introtext with the article if ($indIntrotext == 1) { $article->text = $article->introtext . chr(13) . chr(13) . $article->fulltext; } elseif (!empty($article->fulltext)) { $article->text = $article->fulltext; } else { $article->text = $article->introtext; } // formating last update date if (!empty($article->modified)) { $article->modified = JoaktreeHelper::lastUpdateDateTimePerson($article->modified); } // check content using the content plugin - if it is available $plug = JPATH_SITE . DS . 'plugins' . DS . 'content' . DS . 'joaktree' . DS . 'joaktree.php'; // check if plugin file exists - only then we will use it if (JFile::exists($plug)) { // load the plugin JLoader::register('plgContentJoaktree', $plug); $params = array(); plgContentJoaktree::onContentPrepare('com_content', $article, $params); } $retArticles[] = $article; } return $retArticles; }
public function getArticle($id, $app_id, $person_id, $type) { $articleId = (int) $id; $app_id = (int) $app_id; $person_id = $this->_db->escape(substr($person_id, 0, (int) JoaktreeHelper::getIdlength())); $query = $this->_db->getQuery(true); if ($type == 'article') { // select from content $query->select(' a.id AS id '); $query->select(' a.title AS title '); $query->select(' a.introtext AS introtext '); $query->select(' a.fulltext AS \'fulltext\' '); $query->select(' DATE_FORMAT( a.modified, "%e %b %Y" ) AS modified '); $query->select(' a.attribs AS attribs '); $query->from(' #__content AS a '); $query->where(' a.state = 1 '); $query->where(' a.access IN ' . $this->_levels . ' '); $query->where(' a.id = ' . $articleId . ' '); // Filter by language if ($this->languageFilter) { $query->where('a.language in (' . $this->_db->Quote(JFactory::getLanguage()->getTag()) . ',' . $this->_db->Quote('*') . ') '); } // select from categories $query->select(' cc.id AS cat_id '); $query->leftJoin(' #__categories AS cc ' . ' ON ( cc.id = a.catid ' . ' AND cc.published = 1 ' . ' AND cc.access IN ' . $this->_levels . ' ' . ' ) '); } else { if ($type == 'note') { $params = JoaktreeHelper::getJTParams(); $titleLength = (int) $params->get('notetitlelength', 0); // prepare title // 1. Trim the title to "titlelength" after first space and remove , (if present) $tmp = ' TRIM( TRAILING ' . $this->_db->Quote(',') . ' FROM ' . ' RTRIM( SUBSTRING( IFNULL( jne.value, jpn.value ) ' . ' , 1 ' . ' , LOCATE( ' . $this->_db->Quote(' ') . ' ' . ' , IFNULL( jne.value, jpn.value ) ' . ' , ' . $titleLength . ' ' . ' ) ' . ' ) ' . ' ) ' . ' ) '; // 2. Concatenat the trimmed text with .... $attribs = array(); $attribs[] = $tmp; $attribs[] = $this->_db->Quote(' ...'); $concat = $query->concatenate($attribs); // end prepare title $query->select(' jpn.orderNumber AS id '); $query->select(' IF( ' . $titleLength . ' = 0 ' . ' , ' . $this->_db->Quote(JText::_('JT_NOTE')) . ' ' . ' , ' . $concat . ' ' . ' ) AS title '); $query->select(' IFNULL( jne.value, jpn.value ) AS introtext '); $query->select(' NULL AS \'fulltext\' '); $query->select(' jpn.person_id AS cat_id '); $query->select(' NULL AS modified '); $query->from(' #__joaktree_person_notes AS jpn '); $query->leftJoin(' #__joaktree_notes AS jne ' . ' ON ( jne.app_id = jpn.app_id ' . ' AND jne.id = jpn.note_id ' . ' ) '); $query->where(' jpn.app_id = ' . $app_id . ' '); $query->where(' jpn.person_id = ' . $this->_db->Quote($person_id) . ' '); $query->where(' jpn.orderNumber = ' . $articleId . ' '); } } $this->_db->setQuery($query); $article = $this->_db->loadObject(); // Convert parameter fields to objects for article. if (isset($article->attribs)) { $registry = new JRegistry(); $registry->loadString($article->attribs); $indIntrotext = $registry->get('show_intro', '1'); } else { $indIntrotext = '0'; } // Are we showing introtext with the article if ($indIntrotext == '1') { $article->text = $article->introtext . chr(13) . chr(13) . $article->fulltext; } elseif (!empty($article->fulltext)) { $article->text = $article->fulltext; } else { $article->text = $article->introtext; } // formating last update date if (!empty($article->modified)) { $article->modified = JoaktreeHelper::lastUpdateDateTimePerson($article->modified); } if ($type == 'article') { // check content using the content plugin - if it is available $plug = JPATH_SITE . DS . 'plugins' . DS . 'content' . DS . 'joaktree' . DS . 'joaktree.php'; // check if plugin file exists - only then we will use it if (JFile::exists($plug)) { // load the plugin JLoader::register('plgContentJoaktree', $plug); $params = array(); plgContentJoaktree::onContentPrepare('com_content', $article, $params); } } return $article; }