/** * Method to get an object. * * @param integer $id The id of the object to get. * * @return mixed Object on success, false on failure. */ public function getItem($id = null) { if (!$id) { $id = $this->getState($this->getName() . '.id'); } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.title, a.description, a.votes, a.record_date, a.catid, a.user_id, a.status_id, a.hits, a.params, ' . $query->concatenate(array('a.id', 'a.alias'), '-') . ' AS slug, ' . 'b.name, b.username, ' . 'c.title AS category, ' . $query->concatenate(array('c.id', 'c.alias'), '-') . ' AS catslug, ' . 'd.name AS status_name, d.params AS status_params, d.default AS status_default'); $query->from($db->quoteName('#__uideas_items', 'a')); $query->leftJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id'); $query->leftJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id'); $query->leftJoin($db->quoteName('#__uideas_statuses', 'd') . ' ON a.status_id = d.id'); $query->where('a.id = ' . (int) $id); $db->setQuery($query); $this->item = $db->loadObject(); // Prepare status object if ($this->item !== null and (int) $this->item->id > 0) { $this->prepareStatus($this->item); $tags = new JHelperTags(); $this->item->tags = $tags->getItemTags('com_userideas.item', $this->item->id); $registry = new Joomla\Registry\Registry(); $registry->loadString($this->item->params); $this->item->params = $registry; } return $this->item; }
public static function getIndexAjax() { jimport('joomla.application.module.helper'); $module = JModuleHelper::getModule('jsolrconnectionmonitor'); $params = new \Joomla\Registry\Registry(); $params->loadString($module->params); $index = self::getIndex($params); $language = JFactory::getLanguage(); $loaded = $language->load('mod_jsolrconnectionmonitor', JPATH_ADMINISTRATOR, null, true); if (JArrayHelper::getValue($index, 'status')) { $index['statusText'] = JText::_("MOD_JSOLRCONNECTIONMONITOR_CONNECTED"); } else { $index['statusText'] = JText::_("MOD_JSOLRCONNECTIONMONITOR_NOT_CONNECTED"); } if ($statistics = JArrayHelper::getValue($index, 'statistics')) { if (isset($statistics->lastModified)) { $index['statistics']->lastModifiedFormatted = JHtml::_('date', $statistics->lastModified, JText::_('DATE_FORMAT_LC2')); } } return $index ? $index : false; }
public static function prepareContent($text, $params = null) { static $loaded; // Get the dispatcher. $dispatcher = JDispatcher::getInstance(); // Load the content plugins if necessary. if (empty($loaded)) { JPluginHelper::getPlugin('content'); $loaded = true; } // Instantiate the parameter object if necessary. if (!$params instanceof \Joomla\Registry\Registry) { $registry = new \Joomla\Registry\Registry(); $registry->loadString($params); $params = $registry; } // Create a mock content object. $content = JTable::getInstance('Content'); $content->text = $text; // Fire the onContentPrepare event with the com_finder context to avoid // errors with loadmodule/loadposition plugins. $dispatcher->trigger('onContentPrepare', array('com_finder.indexer', &$content, &$params, 0)); return $content->text; }
/** * Method to get a single record. * * @param integer $pk The id of the primary key. * @param integer $userId The id of the user. * * @return CrowdfundingTableProject Object on success, false on failure. * * @throws Exception * * @since 11.1 */ public function getItem($pk, $userId) { if ($this->item) { return $this->item; } // Initialise variables. $table = $this->getTable(); if ($pk > 0 and $userId > 0) { $keys = array("id" => $pk, "user_id" => $userId); // Attempt to load the row. $return = $table->load($keys); // Check for a table object error. if ($return === false) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); } } // Convert to the JObject before adding other data. $properties = $table->getProperties(); $this->item = Joomla\Utilities\ArrayHelper::toObject($properties, 'JObject'); if (property_exists($this->item, 'params')) { $registry = new Joomla\Registry\Registry(); /** @var $registry Joomla\Registry\Registry */ $registry->loadString($this->item->params); $this->item->params = $registry->toArray(); } return $this->item; }
/** * @return array */ private function getStyles() { $cache = JFactory::getCache('com_templates', ''); $list = $cache->get('gantry-templates'); if ($list === false) { // Load styles $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('s.id, s.template, s.params')->from('#__template_styles as s')->where('s.client_id = 0')->where('e.enabled = 1')->leftJoin('#__extensions as e ON e.element=s.template AND e.type=' . $db->quote('template') . ' AND e.client_id=s.client_id'); $db->setQuery($query); $templates = (array) $db->loadObjectList(); $list = array(); foreach ($templates as $template) { if (file_exists(JPATH_SITE . "/templates/{$template->template}/gantry/theme.yaml")) { $params = new \Joomla\Registry\Registry(); $params->loadString($template->params); $list[$template->id] = true; } } $cache->store($list, 'gantry-templates'); } return $list; }
/** * Caches a harvested record. * * @param JObject $harvest The harvest configuration. * @param SimpleXmlElement $data An OAI record as an instance of the SimpleXmlElement class. */ protected function cache($harvest, $data) { $params = new \Joomla\Registry\Registry(); $params->loadString($harvest->params); if (isset($data->header->identifier)) { $context = 'joai.' . $params->get('discovery.plugin.metadata'); $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin("joai"); $array = $dispatcher->trigger('onJOaiHarvestMetadata', array($context, $data->metadata)); $cache = array("metadata" => JArrayHelper::getValue($array, 0)); if ($params->get('harvest_type') !== self::METADATA) { $metadataPrefix = $params->get('discovery.plugin.assets'); $queries = array('verb' => 'GetRecord', 'identifier' => (string) $data->header->identifier, 'metadataPrefix' => $metadataPrefix); $url = new JUri($params->get('discovery.url')); $url->setQuery($queries); $http = JHttpFactory::getHttp(); $response = $http->get($url); if ((int) $response->code == 200) { $context = 'joai.' . $metadataPrefix; $node = simplexml_load_string($response->body); $array = $dispatcher->trigger('onJOaiHarvestAssets', array($context, $node)); $cache["assets"] = JArrayHelper::getValue($array, 0, array()); } else { throw new Exception((string) $response, (int) $response->code); } } $table = JTable::getInstance('Cache', 'JHarvestTable'); $table->set('id', (string) $data->header->identifier); $table->set('data', json_encode($cache)); $table->set('harvest_id', (int) $harvest->id); $table->store(); } }
/** * Method to get a single record. * * @param integer $pk The id of the primary key. * * @return mixed Object on success, false on failure. * * @since 12.2 */ public function getItem($pk = null) { $pk = $pk !== null ? (int) $pk : (int) $this->getState($this->getName() . '.id'); $table = $this->getTable(); if ($pk > 0) { // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false) { throw new RuntimeException(JText::_('COM_USERIDEAS_ERROR_INVALID_ITEM')); } } // Convert to the JObject before adding other data. $properties = $table->getProperties(1); $item = Joomla\Utilities\ArrayHelper::toObject($properties, 'JObject'); if (property_exists($item, 'params')) { $registry = new Joomla\Registry\Registry(); $registry->loadString($item->params); $item->params = $registry->toArray(); } $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_userideas.item'); return $item; }
?> " class="btn btn-default"> <span class="fa fa-plus"></span> <?php echo JText::_('COM_USERIDEAS_POST_ITEM'); ?> </a> <?php } ?> <?php foreach ($this->items as $item) { // Load parameters. $registry = new Joomla\Registry\Registry(); $registry->loadString($item->params); $item->params = $registry; $commentsNumber = 0; if (array_key_exists($item->id, $this->comments)) { $commentsNumber = (int) $this->comments[$item->id]; } ?> <div class="media ui-item"> <div class="ui-vote pull-left"> <div class="ui-vote-counter" id="js-ui-vote-counter-<?php echo $item->id; ?> "><?php echo $item->votes; ?> </div>
/** * Prepare the item for indexing. * * @param stdClass $item * @return \JSolr\Apache\Solr\Document */ protected function prepare($item) { // Initialize the item's parameters. if (isset($item->params)) { $registry = new \Joomla\Registry\Registry(); $registry->loadString($item->params); } if (isset($item->metadata)) { $registry = new \Joomla\Registry\Registry(); $registry->loadString($item->metadata); $item->metadata = $registry; } $document = $this->getDocument($item); $document->addField('id', $item->id); $document->addField('context', $this->get('context')); $document->addField('lang', $item->language); $key = $this->buildKey($document); $document->addField('key', $key); return $document; }
/** * 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 a Error object. * * @since 1.7.2 */ public function display($tpl = null) { $app = JFactory::getApplication(); $params = JComponentHelper::getParams('com_churchdirectory'); // Get some data from the models $state = $this->get('State'); $items = $this->get('Items'); $category = $this->get('Category'); // Check whether category access level allows access. $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); if (!in_array($category->access, $groups)) { $app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error'); return false; } if ($items == false) { $app->enqueueMessage(JText::_('COM_CHURCHDIRECTOY_ERROR_DIRECTORY_NOT_FOUND'), 'error'); return false; } $this->count = count($items); $this->subcount = count($items); $children = $this->get('Children'); $pagination = $this->get('Pagination'); $this->loadHelper('render'); $renderHelper = new ChurchDirectoryRenderHelper; $this->span = $renderHelper->rowWidth($params->get('rows_per_page')); JLoader::register('DirectoryHeaderHelper', JPATH_SITE . '/components/com_churchdirectory/helpers/directoryheader.php'); $this->header = new DirectoryHeaderHelper; $this->header->setPages($params); // Prepare the data. // Compute the contact slug. for ($i = 0, $n = $this->count; $i < $n; $i++) { $item = & $items[$i]; $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; $temp = new Joomla\Registry\Registry; $temp->loadString($item->params); $item->params = clone $params; $item->params->merge($temp); if ($item->params->get('show_email', 0) == 1) { $item->email_to = trim($item->email_to); if (!empty($item->email_to) && JMailHelper::isEmailAddress($item->email_to)) { $item->email_to = '<a href="mailto::' . $item->email_to . '">' . $item->email_to . '</a>'; } else { $item->email_to = ''; } } if ($item->params->get('dr_show_street_address') || $item->params->get('dr_show_suburb') || $item->params->get('dr_show_state') || $item->params->get('dr_show_postcode') || $item->params->get('dr_show_country')) { $params->set('address_check', 1); } else { $params->set('address_check', 0); } if ($item->params->get('dr_show_email') || $item->params->get('dr_show_telephone') || $item->params->get('dr_show_fax') || $item->params->get('dr_show_mobile') || $item->params->get('dr_show_webpage') || $item->params->get('dr_show_spouse') || $item->params->get('dr_show_children')) { $params->set('other_check', 1); } else { $params->set('other_check', 0); } switch ($params->get('dr_churchdirectory_icons')) { case 1 : // Text $params->set('marker_address', JText::_('COM_CHURCHDIRECTORY_ADDRESS') . ": "); $params->set('marker_email', JText::_('JGLOBAL_EMAIL') . ": "); $params->set('marker_telephone', JText::_('COM_CHURCHDIRECTORY_TELEPHONE') . ": "); $params->set('marker_fax', JText::_('COM_CHURCHDIRECTORY_FAX') . ": "); $params->set('marker_mobile', JText::_('COM_CHURCHDIRECTORY_MOBILE') . ": "); $params->set('marker_misc', JText::_('COM_CHURCHDIRECTORY_OTHER_INFORMATION') . ": "); $params->set('marker_class', 'jicons-text'); break; case 2 : // None $params->set('marker_address', ''); $params->set('marker_email', ''); $params->set('marker_telephone', ''); $params->set('marker_mobile', ''); $params->set('marker_fax', ''); $params->set('marker_misc', ''); $params->set('marker_class', 'jicons-none'); break; default : // Icons $image1 = JHtml::_('image', 'contacts/' . $params->get('icon_address', 'con_address.png'), JText::_('COM_CHURCHDIRECTORY_ADDRESS') . ": ", null, true ); $image2 = JHtml::_('image', 'contacts/' . $params->get('icon_email', 'emailButton.png'), JText::_('JGLOBAL_EMAIL') . ": ", null, true); $image3 = JHtml::_('image', 'contacts/' . $params->get('icon_telephone', 'con_tel.png'), JText::_('COM_CHURCHDIRECTORY_TELEPHONE') . ": ", null, true ); $image4 = JHtml::_('image', 'contacts/' . $params->get('icon_fax', 'con_fax.png'), JText::_('COM_CHURCHDIRECTORY_FAX') . ": ", null, true); $image5 = JHtml::_('image', 'contacts/' . $params->get('icon_misc', 'con_info.png'), JText::_('COM_CHURCHDIRECTORY_OTHER_INFORMATION') . ": ", null, true ); $image6 = JHtml::_('image', 'contacts/' . $params->get('icon_mobile', 'con_mobile.png'), JText::_('COM_CHURCHDIRECTORY_MOBILE') . ": ", null, true ); $params->set('marker_address', $image1); $params->set('marker_email', $image2); $params->set('marker_telephone', $image3); $params->set('marker_fax', $image4); $params->set('marker_misc', $image5); $params->set('marker_mobile', $image6); $params->set('marker_class', 'jicons-icons'); break; } } $params->set('prepare_content', '0'); // Setup the category parameters. $cparams = $category->getParams(); $category->params = clone $params; $category->params->merge($cparams); $children = [$category->id => $children]; $maxLevel = $params->get('maxLevel', -1); $items = $renderHelper->groupit(['items' => & $items, 'field' => 'lname']); if (0) { foreach ($items as $s1) { $items[$s1] = $renderHelper->groupit(['items' => $items[$s1], 'field' => 'suburb']); } } $this->renderHelper = $renderHelper; $this->maxLevel = & $maxLevel; $this->state = & $state; $this->items = $items; $this->category = & $category; $this->children = & $children; $this->params = & $params; $this->pagination = & $pagination; // Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $menus = $app->getMenu(); $title = 'directory_prent_out'; // Because the application sets a default page title, // we need to get it from the menu item itself $menu = $menus->getActive(); // Clean the output buffer @ob_end_clean(); // Create new PDF document $this->pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // Set document information $this->pdf->SetCreator(PDF_CREATOR); $this->pdf->SetAuthor('NFSDA Church'); $this->pdf->SetTitle($this->params->get('page_title', '')); $this->pdf->SetSubject('Church Directory'); $this->pdf->SetKeywords('Directory, PDF, Members'); // Set default header data $this->pdf->setHeaderData( $params->get('pdf_logo'), $params->get('pdf_logo_width'), $this->params->get('page_heading'), $params->get('pdf_header_string') ); // Remove default header/footer $this->pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $this->pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // Set default monospaced font $this->pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // Set margins $this->pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $this->pdf->setHeaderMargin(PDF_MARGIN_HEADER); $this->pdf->setFooterMargin(PDF_MARGIN_FOOTER); // Set auto page breaks $this->pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM); $this->pdf->setCellHeightRatio(1.25); // Set image scale factor $this->pdf->setImageScale(2.5); // --------------------------------------------------------- // Set font $this->pdf->SetFont('times', 'BI', 8, '', 'false'); // Set some text to print $html = $this->loadTemplate($tpl); $jweb = new JApplicationWeb; $jweb->clearHeaders(); // Close and output PDF document $this->pdf->Output($title . '.pdf', 'I'); return null; }
/** * CVS Dump * * @param object $items Items to pass through * @param string $report Name of report to return. * * @return bool * * @since 1.7.0 */ public function getCsv($items, $report) { $date = new JDate('now'); $jWeb = new JApplicationWeb(); $csv = fopen('php://output', 'w'); $jWeb->clearHeaders(); // Clean the output buffer, @ob_end_clean(); @ob_start(); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=report." . $report . '.' . $date->format('Y-m-d-His') . ".csv"); header("Pragma: no-cache"); header("Expires: 0"); $count = 0; foreach ($items as $line) { foreach ($line as $c => $item) { if ($c == 'params') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); unset($line->params); $line = (object) array_merge((array) $line, (array) $params); } elseif ($c == 'attribs') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); $params_att = new stdClass(); foreach ($params as $p => $item_p) { $p = 'att_' . $p; if ($p == 'sex') { switch ($item_p) { case 0: $params_att->{$p} = 'M'; break; case 1: $params_att->{$p} = 'F'; break; } } else { $params_att->{$p} = $item_p; } } unset($line->attribs); $line = (object) array_merge((array) $line, (array) $params_att); } elseif ($c == 'kml_params') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); unset($line->kml_params); $line = (object) array_merge((array) $line, (array) $params); } elseif ($c == 'category_params') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); unset($line->category_params); $line = (object) array_merge((array) $line, (array) $params); } elseif ($c == 'metadata') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); unset($line->metadata); $line = (object) array_merge((array) $line, (array) $params); } elseif ($c == 'con_position') { $pos = []; if ($item != 0) { $positions = explode(',', $item); foreach ($positions as $p => $position) { $query = $this->db->getQuery(true); // Join on Position. $query->select('name'); $query->from('#__churchdirectory_position'); $query->where('id =' . $position); $this->db->setQuery($query); $pos[] = $this->db->loadResult(); } } else { $pos[] = null; } unset($line->con_position); $line = (object) array_merge((array) $line, ['con_position' => implode(",", $pos)]); } elseif ($c == 'image') { $line->{$c} = JUri::root() . $item; } } if ($count == 0) { $array = get_object_vars($line); fputcsv($csv, array_keys($array)); } $count = 1; fputcsv($csv, (array) $line); } @ob_flush(); @flush(); fclose($csv); exit; }
public static function getArticleContentNumber($jatype = '', $jawhere = array()) { $mainframe = JFactory::getApplication(); $app = JFactory::getApplication('site'); $mergedParams = $app->getParams(); $menuParams = new \Joomla\Registry\Registry(); if ($menu = $app->getMenu()->getActive()) { $menuParams->loadString($menu->params); } $mergedParams = clone $menuParams; $mergedParams->merge($mergedParams); // Get the current user for authorisation checks $user = JFactory::getUser(); // Create a new query object. $db = JFactory::getDbo(); $query = $db->getQuery(true); $model = JModelLegacy::getInstance('Articles', 'ContentModel'); $modelcat = JModelLegacy::getInstance('Category', 'ContentModel'); $category = $modelcat->getCategory(); $model->setState('params', $mergedParams); $model->setState('filter.category_id', $category->id); $model->setState('filter.subcategories', $mergedParams->get('show_subcategory_content')); $model->setState('filter.max_category_levels', $mergedParams->get('maxLevel', 4)); // Select the required fields from the table. $query->select($model->getState('list.select', 'a.id, a.title, a.alias, a.introtext, a.fulltext, ' . 'a.checked_out, a.checked_out_time, ' . 'a.catid, a.created, a.created_by, a.created_by_alias, ' . 'CASE WHEN a.modified = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.modified END as modified, ' . 'a.modified_by, uam.name as modified_by_name,' . 'CASE WHEN a.publish_up = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END as publish_up,' . 'a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, ' . 'a.hits, a.xreference, a.featured, a.language, ' . ' ' . $query->length('a.fulltext') . ' AS readmore')); // Process an Archived Article layout if ($model->getState('filter.published') == 2) { // If badcats is not null, this means that the article is inside an archived category // In this case, the state is set to 2 to indicate Archived (even if the article state is Published) $query->select($model->getState('list.select', 'CASE WHEN badcats.id is null THEN a.state ELSE 2 END AS state')); } else { /* Process non-archived layout If badcats is not null, this means that the article is inside an unpublished category In this case, the state is set to 0 to indicate Unpublished (even if the article state is Published) */ $query->select($model->getState('list.select', 'CASE WHEN badcats.id is not null THEN 0 ELSE a.state END AS state')); } $query->from('#__content AS a'); // Join over the categories. $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias')->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the users for the author and modified_by names. $query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author")->select("ua.email AS author_email")->join('LEFT', '#__users AS ua ON ua.id = a.created_by')->join('LEFT', '#__users AS uam ON uam.id = a.modified_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')->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); // Join on voting table $query->select('ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count')->join('LEFT', '#__content_rating AS v ON a.id = v.content_id'); // Join to check for category published state in parent categories up the tree $query->select('c.published, CASE WHEN badcats.id is null THEN c.published ELSE 0 END AS parents_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'); if ($model->getState('filter.published') == 2) { // Find any up-path categories that are archived // If any up-path categories are archived, include all children in archived layout $subquery .= ' AND parent.published = 2 GROUP BY cat.id '; // Set effective state to archived if up-path category is archived $publishedWhere = 'CASE WHEN badcats.id is null THEN a.state ELSE 2 END'; } else { // Find any up-path categories that are not published // If all categories are published, badcats.id will be null, and we just use the article state $subquery .= ' AND parent.published != 1 GROUP BY cat.id '; // Select state to unpublished if up-path category is unpublished $publishedWhere = 'CASE WHEN badcats.id is null THEN a.state ELSE 0 END'; } $query->join('LEFT OUTER', '(' . $subquery . ') AS badcats ON badcats.id = c.id'); // Filter by access level. if ($access = $model->getState('filter.access')) { $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN (' . $groups . ')')->where('c.access IN (' . $groups . ')'); } // Filter by published state $published = $model->getState('filter.published'); if (is_numeric($published)) { // Use article state if badcats.id is null, otherwise, force 0 for unpublished $query->where($publishedWhere . ' = ' . (int) $published); } elseif (is_array($published)) { JArrayHelper::toInteger($published); $published = implode(',', $published); // Use article state if badcats.id is null, otherwise, force 0 for unpublished $query->where($publishedWhere . ' IN (' . $published . ')'); } // Filter by featured state $featured = $model->getState('filter.featured'); switch ($featured) { case 'hide': $query->where('a.featured = 0'); break; case 'only': $query->where('a.featured = 1'); break; case 'show': default: // Normally we do not discriminate // between featured/unfeatured items. break; } // Filter by a single or group of articles. $articleId = $model->getState('filter.article_id'); if (is_numeric($articleId)) { $type = $model->getState('filter.article_id.include', true) ? '= ' : '<> '; $query->where('a.id ' . $type . (int) $articleId); } elseif (is_array($articleId)) { JArrayHelper::toInteger($articleId); $articleId = implode(',', $articleId); $type = $model->getState('filter.article_id.include', true) ? 'IN' : 'NOT IN'; $query->where('a.id ' . $type . ' (' . $articleId . ')'); } // Filter by a single or group of categories $categoryId = $model->getState('filter.category_id'); if (is_numeric($categoryId)) { $type = $model->getState('filter.category_id.include', true) ? '= ' : '<> '; // Add subcategory check $includeSubcategories = $model->getState('filter.subcategories', false); $categoryEquals = 'a.catid ' . $type . (int) $categoryId; if ($includeSubcategories) { $levels = (int) $model->getState('filter.max_category_levels', '1'); // Create a subquery for the subcategory list $subQuery = $db->getQuery(true)->select('sub.id')->from('#__categories as sub')->join('INNER', '#__categories as this ON sub.lft > this.lft AND sub.rgt < this.rgt')->where('this.id = ' . (int) $categoryId); if ($levels >= 0) { $subQuery->where('sub.level <= this.level + ' . $levels); } // Add the subquery to the main query $query->where('(' . $categoryEquals . ' OR a.catid IN (' . $subQuery->__toString() . '))'); } else { $query->where($categoryEquals); } } elseif (is_array($categoryId) && count($categoryId) > 0) { JArrayHelper::toInteger($categoryId); $categoryId = implode(',', $categoryId); if (!empty($categoryId)) { $type = $model->getState('filter.category_id.include', true) ? 'IN' : 'NOT IN'; $query->where('a.catid ' . $type . ' (' . $categoryId . ')'); } } // Filter by author $authorId = $model->getState('filter.author_id'); $authorWhere = ''; if (is_numeric($authorId)) { $type = $model->getState('filter.author_id.include', true) ? '= ' : '<> '; $authorWhere = 'a.created_by ' . $type . (int) $authorId; } elseif (is_array($authorId)) { JArrayHelper::toInteger($authorId); $authorId = implode(',', $authorId); if ($authorId) { $type = $model->getState('filter.author_id.include', true) ? 'IN' : 'NOT IN'; $authorWhere = 'a.created_by ' . $type . ' (' . $authorId . ')'; } } // Filter by author alias $authorAlias = $model->getState('filter.author_alias'); $authorAliasWhere = ''; if (is_string($authorAlias)) { $type = $model->getState('filter.author_alias.include', true) ? '= ' : '<> '; $authorAliasWhere = 'a.created_by_alias ' . $type . $db->quote($authorAlias); } elseif (is_array($authorAlias)) { $first = current($authorAlias); if (!empty($first)) { JArrayHelper::toString($authorAlias); foreach ($authorAlias as $key => $alias) { $authorAlias[$key] = $db->quote($alias); } $authorAlias = implode(',', $authorAlias); if ($authorAlias) { $type = $model->getState('filter.author_alias.include', true) ? 'IN' : 'NOT IN'; $authorAliasWhere = 'a.created_by_alias ' . $type . ' (' . $authorAlias . ')'; } } } if (!empty($authorWhere) && !empty($authorAliasWhere)) { $query->where('(' . $authorWhere . ' OR ' . $authorAliasWhere . ')'); } elseif (empty($authorWhere) && empty($authorAliasWhere)) { // If both are empty we don't want to add to the query } else { // One of these is empty, the other is not so we just add both $query->where($authorWhere . $authorAliasWhere); } // Define null and now dates $nullDate = $db->quote($db->getNullDate()); $nowDate = $db->quote(JFactory::getDate()->toSql()); // Filter by start and end dates. if (!$user->authorise('core.edit.state', 'com_content') && !$user->authorise('core.edit', 'com_content')) { $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')')->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); } // Filter by Date Range or Relative Date $dateFiltering = $model->getState('filter.date_filtering', 'off'); $dateField = $model->getState('filter.date_field', 'a.created'); switch ($dateFiltering) { case 'range': $startDateRange = $db->quote($model->getState('filter.start_date_range', $nullDate)); $endDateRange = $db->quote($model->getState('filter.end_date_range', $nullDate)); $query->where('(' . $dateField . ' >= ' . $startDateRange . ' AND ' . $dateField . ' <= ' . $endDateRange . ')'); break; case 'relative': $relativeDate = (int) $model->getState('filter.relative_date', 0); $query->where($dateField . ' >= DATE_SUB(' . $nowDate . ', INTERVAL ' . $relativeDate . ' DAY)'); break; case 'off': default: break; } if (is_object($mergedParams) && $mergedParams->get('filter_field') != 'hide' && ($filter = $model->getState('list.filter'))) { // Clean filter variable $filter = JString::strtolower($filter); $hitsFilter = (int) $filter; $filter = $db->quote('%' . $db->escape($filter, true) . '%', false); switch ($mergedParams->get('filter_field')) { case 'author': $query->where('LOWER( CASE WHEN a.created_by_alias > ' . $db->quote(' ') . ' THEN a.created_by_alias ELSE ua.name END ) LIKE ' . $filter . ' '); break; case 'hits': $query->where('a.hits >= ' . $hitsFilter . ' '); break; case 'title': default: // Default to 'title' if parameter is not valid $query->where('LOWER( a.title ) LIKE ' . $filter); break; } } // Filter by language if ($model->getState('filter.language')) { $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } if ($jatype != '') { $query->where('a.attribs REGEXP \'"ctm_content_type":"' . $jatype . '"\''); } if ($jawhere != false) { foreach ($jawhere as $jw) { $query->where($jw); } } // Add the list ordering clause. $query->order($model->getState('list.ordering', 'a.ordering') . ' ' . $model->getState('list.direction', 'ASC')); $db->setQuery($query); $result = $db->loadObjectList(); return count($result); }