/system/modules/weblog/mod.weblog.php
PHP | 7538 lines | 5257 code | 1360 blank | 921 comment | 1104 complexity | 9e9dbfb8c6d68a5c7e56286895847a9a MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- =====================================================
- ExpressionEngine - by EllisLab
- -----------------------------------------------------
- http://expressionengine.com/
- -----------------------------------------------------
- Copyright (c) 2003 - 2010 EllisLab, Inc.
- =====================================================
- THIS IS COPYRIGHTED SOFTWARE
- PLEASE READ THE LICENSE AGREEMENT
- http://expressionengine.com/docs/license.html
- =====================================================
- File: mod.weblog.php
- -----------------------------------------------------
- Purpose: Weblog class
- =====================================================
- */
- if ( ! defined('EXT'))
- {
- exit('Invalid file request');
- }
- class Weblog {
- var $limit = '100'; // Default maximum query results if not specified.
- // These variable are all set dynamically
-
- var $query;
- var $TYPE;
- var $entry_id = '';
- var $uri = '';
- var $uristr = '';
- var $return_data = ''; // Final data
- var $tb_action_id = '';
- var $basepath = '';
- var $hit_tracking_id = FALSE;
- var $sql = FALSE;
- var $display_tb_rdf = FALSE;
- var $cfields = array();
- var $dfields = array();
- var $rfields = array();
- var $mfields = array();
- var $categories = array();
- var $catfields = array();
- var $weblog_name = array();
- var $weblogs_array = array();
- var $related_entries = array();
- var $reverse_related_entries= array();
- var $reserved_cat_segment = '';
- var $use_category_names = FALSE;
- var $dynamic_sql = FALSE;
- var $tb_captcha_hash = '';
- var $cat_request = FALSE;
- var $enable = array(); // modified by various tags with disable= parameter
- // These are used with the nested category trees
-
- var $category_list = array();
- var $cat_full_array = array();
- var $cat_array = array();
- var $temp_array = array();
- var $category_count = 0;
- // Pagination variables
-
- var $paginate = FALSE;
- var $field_pagination = FALSE;
- var $paginate_data = '';
- var $pagination_links = '';
- var $page_next = '';
- var $page_previous = '';
- var $current_page = 1;
- var $total_pages = 1;
- var $multi_fields = array();
- var $display_by = '';
- var $total_rows = 0;
- var $pager_sql = '';
- var $p_limit = '';
- var $p_page = '';
-
- // SQL Caching
-
- var $sql_cache_dir = 'sql_cache/';
-
- // Misc. - Class variable usable by extensions
- var $misc = FALSE;
- /** ----------------------------------------
- /** Constructor
- /** ----------------------------------------*/
- function Weblog()
- {
- global $PREFS, $IN, $TMPL;
-
- $this->p_limit = $this->limit;
-
- $this->QSTR = ($IN->Pages_QSTR != '') ? $IN->Pages_QSTR : $IN->QSTR;
-
- if ($PREFS->ini("use_category_name") == 'y' AND $PREFS->ini("reserved_category_word") != '')
- {
- $this->use_category_names = $PREFS->ini("use_category_name");
- $this->reserved_cat_segment = $PREFS->ini("reserved_category_word");
- }
-
- // a number tags utilize the disable= parameter, set it here
- if (is_object($TMPL))
- {
- $this->_fetch_disable_param();
- }
- }
- /* END */
- /** ----------------------------------------
- /** Initialize values
- /** ----------------------------------------*/
- function initialize()
- {
- $this->sql = '';
- $this->return_data = '';
- }
- /* END */
-
-
- /** ----------------------------------------
- /** Fetch Cache
- /** ----------------------------------------*/
- function fetch_cache($identifier = '')
- {
- global $IN, $TMPL;
-
- $tag = ($identifier == '') ? $TMPL->tagproper : $TMPL->tagproper.$identifier;
-
- if ($TMPL->fetch_param('dynamic_parameters') !== FALSE AND isset($_POST) AND count($_POST) > 0)
- {
- foreach (explode('|', $TMPL->fetch_param('dynamic_parameters')) as $var)
- {
- if (isset($_POST[$var]) AND in_array($var, array('weblog', 'entry_id', 'category', 'orderby', 'sort', 'sticky', 'show_future_entries', 'show_expired', 'entry_id_from', 'entry_id_to', 'not_entry_id', 'start_on', 'stop_before', 'year', 'month', 'day', 'display_by', 'limit', 'username', 'status', 'group_id', 'cat_limit', 'month_limit', 'offset', 'author_id')))
- {
- $tag .= $var.'="'.$_POST[$var].'"';
- }
-
- if (isset($_POST[$var]) && strncmp($var, 'search:', 7) == 0)
- {
- $tag .= $var.'="'.substr($_POST[$var], 7).'"';
- }
- }
- }
-
- $cache_file = PATH_CACHE.$this->sql_cache_dir.md5($tag.$this->uri);
-
- if ( ! $fp = @fopen($cache_file, 'rb'))
- {
- return FALSE;
- }
-
- flock($fp, LOCK_SH);
- $sql = @fread($fp, filesize($cache_file));
- flock($fp, LOCK_UN);
- fclose($fp);
-
- return $sql;
- }
- /* END */
-
- /** ----------------------------------------
- /** Save Cache
- /** ----------------------------------------*/
- function save_cache($sql, $identifier = '')
- {
- global $IN, $TMPL;
-
- $tag = ($identifier == '') ? $TMPL->tagproper : $TMPL->tagproper.$identifier;
-
- $cache_dir = PATH_CACHE.$this->sql_cache_dir;
- $cache_file = $cache_dir.md5($tag.$this->uri);
-
- if ( ! @is_dir($cache_dir))
- {
- if ( ! @mkdir($cache_dir, 0777))
- {
- return FALSE;
- }
-
- if ($fp = @fopen($cache_dir.'/index.html', 'wb'))
- {
- fclose($fp);
- }
-
- @chmod($cache_dir, 0777);
- }
-
- if ( ! $fp = @fopen($cache_file, 'wb'))
- {
- return FALSE;
- }
-
- flock($fp, LOCK_EX);
- fwrite($fp, $sql);
- flock($fp, LOCK_UN);
- fclose($fp);
- @chmod($cache_file, 0777);
-
- return TRUE;
- }
- /* END */
-
- /** ----------------------------------------
- /** Weblog entries
- /** ----------------------------------------*/
- function entries()
- {
- global $IN, $PREFS, $DB, $TMPL, $FNS;
-
- // If the "related_categories" mode is enabled
- // we'll call the "related_categories" function
- // and bail out.
-
- if ($TMPL->fetch_param('related_categories_mode') == 'on')
- {
- return $this->related_entries();
- }
- // Onward...
-
- $this->initialize();
-
- $this->uri = ($this->QSTR != '') ? $this->QSTR : 'index.php';
-
- if ($this->enable['custom_fields'] == TRUE)
- {
- $this->fetch_custom_weblog_fields();
- }
-
- if ($this->enable['member_data'] == TRUE)
- {
- $this->fetch_custom_member_fields();
- }
-
- if ($this->enable['pagination'] == TRUE)
- {
- $this->fetch_pagination_data();
- }
-
- $save_cache = FALSE;
-
- if ($PREFS->ini('enable_sql_caching') == 'y')
- {
- if (FALSE == ($this->sql = $this->fetch_cache()))
- {
- $save_cache = TRUE;
- }
- else
- {
- if ($TMPL->fetch_param('dynamic') != 'off')
- {
- if (preg_match("#(^|\/)C(\d+)#", $this->QSTR, $match) OR in_array($this->reserved_cat_segment, explode("/", $this->QSTR)))
- {
- $this->cat_request = TRUE;
- }
- }
- }
-
- if (FALSE !== ($cache = $this->fetch_cache('pagination_count')))
- {
- if (FALSE !== ($this->fetch_cache('field_pagination')))
- {
- if (FALSE !== ($pg_query = $this->fetch_cache('pagination_query')))
- {
- $this->paginate = TRUE;
- $this->field_pagination = TRUE;
- $this->create_pagination(trim($cache), $DB->query(trim($pg_query)));
- }
- }
- else
- {
- $this->create_pagination(trim($cache));
- }
- }
- }
-
- if ($this->sql == '')
- {
- $this->build_sql_query();
- }
- if ($this->sql == '')
- {
- return $TMPL->no_results();
- }
- if ($save_cache == TRUE)
- {
- $this->save_cache($this->sql);
- }
-
- $this->query = $DB->query($this->sql);
-
- if ($this->query->num_rows == 0)
- {
- return $TMPL->no_results();
- }
-
- /* -------------------------------------
- /* "Relaxed" View Tracking
- /*
- /* Some people have tags that are used to mimic a single-entry
- /* page without it being dynamic. This allows Entry View Tracking
- /* to work for ANY combination that results in only one entry
- /* being returned by the tag, including weblog query caching.
- /*
- /* Hidden Configuration Variable
- /* - relaxed_track_views => Allow view tracking on non-dynamic
- /* single entries (y/n)
- /* -------------------------------------*/
- if ($PREFS->ini('relaxed_track_views') === 'y' AND $this->query->num_rows == 1)
- {
- $this->hit_tracking_id = $this->query->row['entry_id'];
- }
- $this->track_views();
- if ( ! class_exists('Typography'))
- {
- require PATH_CORE.'core.typography'.EXT;
- }
-
- $this->TYPE = new Typography;
- $this->TYPE->convert_curly = FALSE;
-
- if ($this->enable['categories'] == TRUE)
- {
- $this->fetch_categories();
- }
-
- if ($this->enable['trackbacks'] == TRUE)
- {
- $this->tb_action_id = $FNS->fetch_action_id('Trackback_CP', 'receive_trackback');
- }
-
- $this->parse_weblog_entries();
-
- if ($this->enable['pagination'] == TRUE)
- {
- $this->add_pagination_data();
- }
-
- // Does the tag contain "related entries" that we need to parse out?
- if (count($TMPL->related_data) > 0 AND count($this->related_entries) > 0)
- {
- $this->parse_related_entries();
- }
-
- if (count($TMPL->reverse_related_data) > 0 AND count($this->reverse_related_entries) > 0)
- {
- $this->parse_reverse_related_entries();
- }
-
- return $this->return_data;
- }
- /* END */
- /** ----------------------------------------
- /** Process related entries
- /** ----------------------------------------*/
- function parse_related_entries()
- {
- global $TMPL, $DB, $REGX, $FNS;
-
- $sql = "SELECT rel_id, rel_parent_id, rel_child_id, rel_type, rel_data
- FROM exp_relationships
- WHERE rel_id IN (";
-
- $templates = array();
- foreach ($this->related_entries as $val)
- {
- $x = explode('_', $val);
- $sql .= "'".$x['0']."',";
- $templates[] = array($x['0'], $x['1'], $TMPL->related_data[$x['1']]);
- }
-
- $sql = substr($sql, 0, -1).')';
- $query = $DB->query($sql);
-
- if ($query->num_rows == 0)
- return;
-
- /* --------------------------------
- /* Without this the Related Entries were inheriting the parameters of
- /* the enclosing Weblog Entries tag. Sometime in the future we will
- /* likely allow Related Entries to have their own parameters
- /* --------------------------------*/
-
- $TMPL->tagparams = array('rdf'=> "off");
-
- $return_data = $this->return_data;
-
- foreach ($templates as $temp)
- {
- foreach ($query->result as $row)
- {
- if ($row['rel_id'] != $temp['0'])
- continue;
-
- /* --------------------------------------
- /* If the data is emptied (cache cleared), then we
- /* rebuild it with fresh data so processing can continue.
- /* --------------------------------------*/
-
- if (trim($row['rel_data']) == '')
- {
- $rewrite = array(
- 'type' => $row['rel_type'],
- 'parent_id' => $row['rel_parent_id'],
- 'child_id' => $row['rel_child_id'],
- 'related_id' => $row['rel_id']
- );
-
- $FNS->compile_relationship($rewrite, FALSE);
-
- $results = $DB->query("SELECT rel_data FROM exp_relationships WHERE rel_id = '".$row['rel_id']."'");
- $row['rel_data'] = $results->row['rel_data'];
- }
-
- /** --------------------------------------
- /** Begin Processing
- /** --------------------------------------*/
-
- $this->initialize();
-
- if ($reldata = @unserialize($row['rel_data']))
- {
- $TMPL->var_single = $temp['2']['var_single'];
- $TMPL->var_pair = $temp['2']['var_pair'];
- $TMPL->var_cond = $temp['2']['var_cond'];
- $TMPL->tagdata = $temp['2']['tagdata'];
-
- if ($row['rel_type'] == 'blog')
- {
- // Bug fix for when categories were not being inserted
- // correctly for related weblog entries. Bummer.
-
- if (sizeof($reldata['categories'] == 0) && ! isset($reldata['cats_fixed']))
- {
- $fixdata = array(
- 'type' => $row['rel_type'],
- 'parent_id' => $row['rel_parent_id'],
- 'child_id' => $row['rel_child_id'],
- 'related_id' => $row['rel_id']
- );
-
- $FNS->compile_relationship($fixdata, FALSE);
- $reldata['categories'] = $FNS->cat_array;
- }
-
- $this->query = $reldata['query'];
- $this->categories = array($this->query->row['entry_id'] => $reldata['categories']);
- $this->parse_weblog_entries();
-
- $marker = LD."REL[".$row['rel_id']."][".$temp['2']['field_name']."]".$temp['1']."REL".RD;
- $return_data = str_replace($marker, $this->return_data, $return_data);
- }
- elseif ($row['rel_type'] == 'gallery')
- {
- if ( ! class_exists('Gallery'))
- {
- include_once PATH_MOD.'gallery/mod.gallery'.EXT;
- }
-
- $GAL = new Gallery;
- $GAL->one_entry = TRUE;
- $GAL->query = $reldata['query'];
- $GAL->TYPE = $this->TYPE;
- $GAL->parse_gallery_tag();
- $GAL->parse_gallery_entries();
- $marker = LD."REL[".$row['rel_id']."][".$temp['2']['field_name']."]".$temp['1']."REL".RD;
- $return_data = str_replace($marker, $GAL->return_data, $return_data);
- }
- }
- }
- }
-
- $this->return_data = $return_data;
- }
- /* END */
-
-
- /** ----------------------------------------
- /** Process reverse related entries
- /** ----------------------------------------*/
- function parse_reverse_related_entries()
- {
- global $TMPL, $DB, $REGX, $FNS;
-
- $sql = "SELECT rel_id, rel_parent_id, rel_child_id, rel_type, reverse_rel_data
- FROM exp_relationships
- WHERE rel_child_id IN ('".implode("','", array_keys($this->reverse_related_entries))."')
- AND rel_type = 'blog'";
- $query = $DB->query($sql);
- if ($query->num_rows == 0)
- {
- // remove Reverse Related tags for these entries
-
- foreach ($this->reverse_related_entries as $entry_id => $templates)
- {
- foreach($templates as $tkey => $template)
- {
- $this->return_data = str_replace(LD."REV_REL[".$TMPL->reverse_related_data[$template]['marker']."][".$entry_id."]REV_REL".RD, $TMPL->reverse_related_data[$template]['no_rev_content'], $this->return_data);
- }
- }
- return;
- }
-
- /** --------------------------------
- /** Data Processing Time
- /** --------------------------------*/
-
- $entry_data = array();
-
- foreach($query->result as $row)
- {
- /* --------------------------------------
- /* If the data is emptied (cache cleared or first process), then we
- /* rebuild it with fresh data so processing can continue.
- /* --------------------------------------*/
-
- if (trim($row['reverse_rel_data']) == '')
- {
- $rewrite = array(
- 'type' => $row['rel_type'],
- 'parent_id' => $row['rel_parent_id'],
- 'child_id' => $row['rel_child_id'],
- 'related_id' => $row['rel_id']
- );
-
- $FNS->compile_relationship($rewrite, FALSE, TRUE);
-
- $results = $DB->query("SELECT reverse_rel_data FROM exp_relationships WHERE rel_parent_id = '".$row['rel_parent_id']."'");
- $row['reverse_rel_data'] = $results->row['reverse_rel_data'];
- }
-
- /** --------------------------------------
- /** Unserialize the entries data, please
- /** --------------------------------------*/
-
- if ($revreldata = @unserialize($row['reverse_rel_data']))
- {
- $entry_data[$row['rel_child_id']][$row['rel_parent_id']] = $revreldata;
- }
- }
-
- /* --------------------------------
- /* Without this the Reverse Related Entries were inheriting the parameters of
- /* the enclosing Weblog Entries tag, which is not appropriate.
- /* --------------------------------*/
-
- $TMPL->tagparams = array('rdf'=> "off");
-
- $return_data = $this->return_data;
-
- foreach ($this->reverse_related_entries as $entry_id => $templates)
- {
- /** --------------------------------------
- /** No Entries? Remove Reverse Related Tags and Continue to Next Entry
- /** --------------------------------------*/
-
- if ( ! isset($entry_data[$entry_id]))
- {
- foreach($templates as $tkey => $template)
- {
- $return_data = str_replace(LD."REV_REL[".$TMPL->reverse_related_data[$template]['marker']."][".$entry_id."]REV_REL".RD, $TMPL->reverse_related_data[$template]['no_rev_content'], $return_data);
- }
-
- continue;
- }
-
- /** --------------------------------------
- /** Process Our Reverse Related Templates
- /** --------------------------------------*/
-
- foreach($templates as $tkey => $template)
- {
- $i = 0;
- $cats = array();
-
- $params = $TMPL->reverse_related_data[$template]['params'];
-
- if ( ! is_array($params))
- {
- $params = array('open');
- }
- elseif( ! isset($params['status']))
- {
- $params['status'] = 'open';
- }
-
- /** --------------------------------------
- /** Entries have to be ordered, sorted and other stuff
- /** --------------------------------------*/
-
- $new = array();
- $order = ( ! isset($params['orderby'])) ? 'date' : $params['orderby'];
- $offset = ( ! isset($params['offset']) OR ! is_numeric($params['offset'])) ? 0 : $params['offset'];
- $limit = ( ! isset($params['limit']) OR ! is_numeric($params['limit'])) ? 100 : $params['limit'];
- $sort = ( ! isset($params['sort'])) ? 'asc' : $params['sort'];
- $random = ($order == 'random') ? TRUE : FALSE;
-
- $base_orders = array('random', 'date', 'title', 'url_title', 'edit_date', 'comment_total', 'username', 'screen_name', 'most_recent_comment', 'expiration_date',
- 'view_count_one', 'view_count_two', 'view_count_three', 'view_count_four');
-
- if ( ! in_array($order, $base_orders))
- {
- $set = 'n';
- foreach($this->cfields as $site_id => $cfields)
- {
- if ( isset($cfields[$order]))
- {
- $order = 'field_id_'.$cfields[$order];
- $set = 'y';
- break;
- }
- }
-
- if ( $set == 'n' )
- {
- $order = 'date';
- }
- }
-
- if ($order == 'date' OR $order == 'random')
- {
- $order = 'entry_date';
- }
-
- if (isset($params['weblog']) && trim($params['weblog']) != '')
- {
- if (sizeof($this->weblogs_array) == 0)
- {
- $results = $DB->query("SELECT weblog_id, blog_name FROM exp_weblogs WHERE site_id IN ('".implode("','", $TMPL->site_ids)."') AND is_user_blog = 'n'");
-
- foreach($results->result as $row)
- {
- $this->weblogs_array[$row['weblog_id']] = $row['blog_name'];
- }
- }
-
- $weblogs = explode('|', trim($params['weblog']));
- $allowed = array();
-
- if (strncmp($weblogs[0], 'not ', 4) == 0)
- {
- $weblogs['0'] = trim(substr($weblogs['0'], 3));
- $allowed = $this->weblogs_array;
- foreach($weblogs as $name)
- {
- if (in_array($name, $allowed))
- {
- foreach (array_keys($allowed, $name) AS $k)
- {
- unset($allowed[$k]);
- }
- }
- }
- }
- else
- {
- foreach($weblogs as $name)
- {
- if (in_array($name, $this->weblogs_array))
- {
- foreach (array_keys($this->weblogs_array, $name) AS $k)
- {
- $allowed[$k] = $name;
- }
- }
- }
- }
- }
-
- $stati = array();
-
- if (isset($params['status']) && trim($params['status']) != '')
- {
- $stati = explode('|', trim($params['status']));
- $status_state = 'positive';
-
- if (substr($stati['0'], 0, 4) == 'not ')
- {
- $stati['0'] = trim(substr($stati['0'], 3));
- $status_state = 'negative';
- $stati[] = 'closed';
- }
- }
-
- // lower case to match MySQL's case-insensitivity
- $stati = array_map('strtolower', $stati);
-
- $r = 1; // Fixes a problem when a sorting key occurs twice
- foreach($entry_data[$entry_id] as $relating_data)
- {
- if ( ! isset($params['weblog']) OR array_key_exists($relating_data['query']->row['weblog_id'], $allowed))
- {
- if (isset($stati) && ! empty($stati) && isset($relating_data['query']->row[$order]))
- {
- if ($status_state == 'negative' && ! in_array(strtolower($relating_data['query']->row['status']), $stati))
- {
- $new[$relating_data['query']->row[$order].'_'.$r] = $relating_data;
- }
- elseif($status_state == 'positive' && in_array(strtolower($relating_data['query']->row['status']), $stati))
- {
- $new[$relating_data['query']->row[$order].'_'.$r] = $relating_data;
- }
- }
- elseif (strtolower($relating_data['query']->row['status']) == 'open')
- {
- $new[$relating_data['query']->row[$order].'_'.$r] = $relating_data;
- }
-
- ++$r;
- }
- }
-
- if ($random === TRUE)
- {
- shuffle($new);
- }
- elseif ($sort == 'asc') // 1 to 10, A to Z
- {
- uksort($new, 'strnatcasecmp');
- }
- else
- {
- uksort($new, 'strnatcasecmp');
- $new = array_reverse($new, TRUE);
- }
-
- $output_data[$entry_id] = array_slice($new, $offset, $limit);
-
- if (sizeof($output_data[$entry_id]) == 0)
- {
- $return_data = str_replace(LD."REV_REL[".$TMPL->reverse_related_data[$template]['marker']."][".$entry_id."]REV_REL".RD, $TMPL->reverse_related_data[$template]['no_rev_content'], $return_data);
- continue;
- }
-
- /** --------------------------------------
- /** Finally! We get to process our parents
- /** --------------------------------------*/
-
- foreach($output_data[$entry_id] as $relating_data)
- {
- if ($i == 0)
- {
- $query = $FNS->clone_object($relating_data['query']);
- }
- else
- {
- $query->result[] = $relating_data['query']->row;
- }
-
- $cats[$relating_data['query']->row['entry_id']] = $relating_data['categories'];
-
- ++$i;
- }
-
- $query->num_rows = $i;
-
- $this->initialize();
-
- $TMPL->var_single = $TMPL->reverse_related_data[$template]['var_single'];
- $TMPL->var_pair = $TMPL->reverse_related_data[$template]['var_pair'];
- $TMPL->var_cond = $TMPL->reverse_related_data[$template]['var_cond'];
- $TMPL->tagdata = $TMPL->reverse_related_data[$template]['tagdata'];
-
- $this->query = $query;
- $this->categories = $cats;
- $this->parse_weblog_entries();
-
- $return_data = str_replace( LD."REV_REL[".$TMPL->reverse_related_data[$template]['marker']."][".$entry_id."]REV_REL".RD,
- $this->return_data,
- $return_data);
- }
- }
-
- $this->return_data = $return_data;
- }
- /* END */
- /** ----------------------------------------
- /** Track Views
- /** ----------------------------------------*/
- function track_views()
- {
- global $DB, $TMPL, $PREFS;
-
- if ($PREFS->ini('enable_entry_view_tracking') == 'n')
- {
- return;
- }
-
- if ( ! $TMPL->fetch_param('track_views') OR $this->hit_tracking_id === FALSE OR ! in_array($TMPL->fetch_param('track_views'), array("one", "two", "three", "four")))
- {
- return;
- }
-
- if ($this->field_pagination == TRUE AND $this->p_page > 0)
- {
- return;
- }
-
- $column = "view_count_".$TMPL->fetch_param('track_views');
-
- $sql = "UPDATE exp_weblog_titles SET {$column} = ({$column} + 1) WHERE ";
-
- $sql .= (is_numeric($this->hit_tracking_id)) ? "entry_id = {$this->hit_tracking_id}" : "url_title = '".$DB->escape_str($this->hit_tracking_id)."'";
-
- $DB->query($sql);
- }
- /* END */
- /** ----------------------------------------
- /** Fetch pagination data
- /** ----------------------------------------*/
- function fetch_pagination_data()
- {
- global $TMPL, $FNS, $EXT;
-
- if (preg_match("/".LD."paginate".RD."(.+?)".LD.SLASH."paginate".RD."/s", $TMPL->tagdata, $match))
- {
- if ($TMPL->fetch_param('paginate_type') == 'field')
- {
- if (preg_match("/".LD."multi_field\=[\"'](.+?)[\"']".RD."/s", $TMPL->tagdata, $mmatch))
- {
- $this->multi_fields = $FNS->fetch_simple_conditions($mmatch['1']);
- $this->field_pagination = TRUE;
- }
- }
-
- // -------------------------------------------
- // 'weblog_module_fetch_pagination_data' hook.
- // - Works with the 'weblog_module_create_pagination' hook
- // - Developers, if you want to modify the $this object remember
- // to use a reference on function call.
- //
- if ($EXT->active_hook('weblog_module_fetch_pagination_data') === TRUE)
- {
- $edata = $EXT->universal_call_extension('weblog_module_fetch_pagination_data', $this);
- if ($EXT->end_script === TRUE) return;
- }
- //
- // -------------------------------------------
-
- $this->paginate = TRUE;
- $this->paginate_data = $match['1'];
-
- $TMPL->tagdata = preg_replace("/".LD."paginate".RD.".+?".LD.SLASH."paginate".RD."/s", "", $TMPL->tagdata);
- }
- }
- /* END */
-
-
- /** ----------------------------------------
- /** Add pagination data to result
- /** ----------------------------------------*/
-
- function add_pagination_data()
- {
- global $TMPL;
- if ($this->pagination_links == '')
- {
- // return;
- }
-
- if ($this->paginate == TRUE)
- {
- $this->paginate_data = str_replace(LD.'current_page'.RD, $this->current_page, $this->paginate_data);
- $this->paginate_data = str_replace(LD.'total_pages'.RD, $this->total_pages, $this->paginate_data);
- $this->paginate_data = str_replace(LD.'pagination_links'.RD, $this->pagination_links, $this->paginate_data);
-
- if (preg_match("/".LD."if previous_page".RD."(.+?)".LD.SLASH."if".RD."/s", $this->paginate_data, $match))
- {
- if ($this->page_previous == '')
- {
- $this->paginate_data = preg_replace("/".LD."if previous_page".RD.".+?".LD.SLASH."if".RD."/s", '', $this->paginate_data);
- }
- else
- {
- $match['1'] = preg_replace("/".LD.'path.*?'.RD."/", $this->page_previous, $match['1']);
- $match['1'] = preg_replace("/".LD.'auto_path'.RD."/", $this->page_previous, $match['1']);
-
- $this->paginate_data = str_replace($match['0'], $match['1'], $this->paginate_data);
- }
- }
-
-
- if (preg_match("/".LD."if next_page".RD."(.+?)".LD.SLASH."if".RD."/s", $this->paginate_data, $match))
- {
- if ($this->page_next == '')
- {
- $this->paginate_data = preg_replace("/".LD."if next_page".RD.".+?".LD.SLASH."if".RD."/s", '', $this->paginate_data);
- }
- else
- {
- $match['1'] = preg_replace("/".LD.'path.*?'.RD."/", $this->page_next, $match['1']);
- $match['1'] = preg_replace("/".LD.'auto_path'.RD."/", $this->page_next, $match['1']);
-
- $this->paginate_data = str_replace($match['0'], $match['1'], $this->paginate_data);
- }
- }
-
- $position = ( ! $TMPL->fetch_param('paginate')) ? '' : $TMPL->fetch_param('paginate');
-
- switch ($position)
- {
- case "top" : $this->return_data = $this->paginate_data.$this->return_data;
- break;
- case "both" : $this->return_data = $this->paginate_data.$this->return_data.$this->paginate_data;
- break;
- default : $this->return_data .= $this->paginate_data;
- break;
- }
- }
- }
- /* END */
-
-
- /** ----------------------------------------
- /** Fetch custom weblog field IDs
- /** ----------------------------------------*/
- function fetch_custom_weblog_fields()
- {
- global $DB, $SESS, $TMPL;
-
- if (isset($SESS->cache['weblog']['custom_weblog_fields']) && isset($SESS->cache['weblog']['date_fields']) && isset($SESS->cache['weblog']['relationship_fields']))
- {
- $this->cfields = $SESS->cache['weblog']['custom_weblog_fields'];
- $this->dfields = $SESS->cache['weblog']['date_fields'];
- $this->rfields = $SESS->cache['weblog']['relationship_fields'];
- return;
- }
-
- // Gotta catch 'em all!
- $sql = "SELECT field_id, field_type, field_name, site_id
- FROM exp_weblog_fields";
-
- $query = $DB->query($sql);
-
- foreach ($query->result as $row)
- {
- // Assign date fields
- if ($row['field_type'] == 'date')
- {
- $this->dfields[$row['site_id']][$row['field_name']] = $row['field_id'];
- }
- // Assign relationship fields
- if ($row['field_type'] == 'rel')
- {
- $this->rfields[$row['site_id']][$row['field_name']] = $row['field_id'];
- }
-
- // Assign standard fields
- $this->cfields[$row['site_id']][$row['field_name']] = $row['field_id'];
- }
- $SESS->cache['weblog']['custom_weblog_fields'] = $this->cfields;
- $SESS->cache['weblog']['date_fields'] = $this->dfields;
- $SESS->cache['weblog']['relationship_fields'] = $this->rfields;
- }
- /* END */
- /** ----------------------------------------
- /** Fetch custom member field IDs
- /** ----------------------------------------*/
- function fetch_custom_member_fields()
- {
- global $DB;
-
- $query = $DB->query("SELECT m_field_id, m_field_name, m_field_fmt FROM exp_member_fields");
-
- foreach ($query->result as $row)
- {
- $this->mfields[$row['m_field_name']] = array($row['m_field_id'], $row['m_field_fmt']);
- }
- }
- /* END */
- /** ----------------------------------------
- /** Fetch categories
- /** ----------------------------------------*/
- function fetch_categories()
- {
- global $DB, $TMPL;
-
- if ($this->enable['category_fields'] === TRUE)
- {
- $query = $DB->query("SELECT field_id, field_name FROM exp_category_fields WHERE site_id IN ('".implode("','", $TMPL->site_ids)."')");
-
- if ($query->num_rows > 0)
- {
- foreach ($query->result as $row)
- {
- $this->catfields[] = array('field_name' => $row['field_name'], 'field_id' => $row['field_id']);
- }
- }
-
- $field_sqla = ", cg.field_html_formatting, fd.* ";
- $field_sqlb = " LEFT JOIN exp_category_field_data AS fd ON fd.cat_id = c.cat_id
- LEFT JOIN exp_category_groups AS cg ON cg.group_id = c.group_id";
- }
- else
- {
- $field_sqla = '';
- $field_sqlb = '';
- }
-
- $sql = "SELECT c.cat_name, c.cat_url_title, c.cat_id, c.cat_image, c.cat_description, c.parent_id,
- p.cat_id, p.entry_id, c.group_id {$field_sqla}
- FROM (exp_categories AS c, exp_category_posts AS p)
- {$field_sqlb}
- WHERE c.cat_id = p.cat_id
- AND p.entry_id IN (";
-
- $categories = array();
-
- foreach ($this->query->result as $row)
- {
- $sql .= "'".$row['entry_id']."',";
-
- $categories[] = $row['entry_id'];
- }
-
- $sql = substr($sql, 0, -1).')';
-
- $sql .= " ORDER BY c.group_id, c.parent_id, c.cat_order";
-
- $query = $DB->query($sql);
- if ($query->num_rows == 0)
- {
- return;
- }
-
- foreach ($categories as $val)
- {
- $this->temp_array = array();
- $this->cat_array = array();
- $parents = array();
-
- foreach ($query->result as $row)
- {
- if ($val == $row['entry_id'])
- {
- $this->temp_array[$row['cat_id']] = array($row['cat_id'], $row['parent_id'], $row['cat_name'], $row['cat_image'], $row['cat_description'], $row['group_id'], $row['cat_url_title']);
-
- foreach ($row as $k => $v)
- {
- if (strpos($k, 'field') !== FALSE)
- {
- $this->temp_array[$row['cat_id']][$k] = $v;
- }
- }
-
- if ($row['parent_id'] > 0 && ! isset($this->temp_array[$row['parent_id']])) $parents[$row['parent_id']] = '';
- unset($parents[$row['cat_id']]);
- }
- }
-
- if (count($this->temp_array) == 0)
- {
- $temp = FALSE;
- }
- else
- {
- foreach($this->temp_array as $k => $v)
- {
- if (isset($parents[$v['1']])) $v['1'] = 0;
-
- if (0 == $v['1'])
- {
- $this->cat_array[] = $v;
- $this->process_subcategories($k);
- }
- }
- }
-
- $this->categories[$val] = $this->cat_array;
- }
- unset($this->temp_array);
- unset($this->cat_array);
- }
- /* END */
-
-
- /** ----------------------------------------
- /** Build SQL query
- /** ----------------------------------------*/
- function build_sql_query($qstring = '')
- {
- global $IN, $DB, $TMPL, $SESS, $LOC, $FNS, $REGX, $PREFS;
-
- $entry_id = '';
- $year = '';
- $month = '';
- $day = '';
- $qtitle = '';
- $cat_id = '';
- $corder = array();
- $offset = 0;
- $page_marker = FALSE;
- $dynamic = TRUE;
-
- $this->dynamic_sql = TRUE;
-
- /** ----------------------------------------------
- /** Is dynamic='off' set?
- /** ----------------------------------------------*/
-
- // If so, we'll override all dynamically set variables
-
- if ($TMPL->fetch_param('dynamic') == 'off')
- {
- $dynamic = FALSE;
- }
-
- /** ----------------------------------------------
- /** Do we allow dynamic POST variables to set parameters?
- /** ----------------------------------------------*/
- if ($TMPL->fetch_param('dynamic_parameters') !== FALSE AND isset($_POST) AND count($_POST) > 0)
- {
- foreach (explode('|', $TMPL->fetch_param('dynamic_parameters')) as $var)
- {
- if (isset($_POST[$var]) AND in_array($var, array('weblog', 'entry_id', 'category', 'orderby', 'sort', 'sticky', 'show_future_entries', 'show_expired', 'entry_id_from', 'entry_id_to', 'not_entry_id', 'start_on', 'stop_before', 'year', 'month', 'day', 'display_by', 'limit', 'username', 'status', 'group_id', 'cat_limit', 'month_limit', 'offset', 'author_id')))
- {
- $TMPL->tagparams[$var] = $_POST[$var];
- }
-
- if (isset($_POST[$var]) && strncmp($var, 'search:', 7) == 0)
- {
- $TMPL->search_fields[substr($var, 7)] = $_POST[$var];
- }
- }
- }
-
- /** ----------------------------------------------
- /** Parse the URL query string
- /** ----------------------------------------------*/
-
- $this->uristr = $IN->URI;
- if ($qstring == '')
- $qstring = $this->QSTR;
-
- $this->basepath = $FNS->create_url($this->uristr, 1);
-
- if ($qstring == '')
- {
- if ($TMPL->fetch_param('require_entry') == 'yes')
- {
- return '';
- }
- }
- else
- {
- /** --------------------------------------
- /** Do we have a pure ID number?
- /** --------------------------------------*/
-
- if (is_numeric($qstring) AND $dynamic)
- {
- $entry_id = $qstring;
- }
- else
- {
- /** --------------------------------------
- /** Parse day
- /** --------------------------------------*/
-
- if (preg_match("#\d{4}/\d{2}/(\d{2})#", $qstring, $match) AND $dynamic)
- {
- $partial = substr($match['0'], 0, -3);
-
- if (preg_match("#(\d{4}/\d{2})#", $partial, $pmatch))
- {
- $ex = explode('/', $pmatch['1']);
-
- $year = $ex['0'];
- $month = $ex['1'];
- }
-
- $day = $match['1'];
-
- $qstring = $REGX->trim_slashes(str_replace($match['0'], $partial, $qstring));
- }
-
- /** --------------------------------------
- /** Parse /year/month/
- /** --------------------------------------*/
-
- // added (^|\/) to make sure this doesn't trigger with url titles like big_party_2006
- if (preg_match("#(^|\/)(\d{4}/\d{2})(\/|$)#", $qstring, $match) AND $dynamic)
- {
- $ex = explode('/', $match['2']);
-
- $year = $ex['0'];
- $month = $ex['1'];
- $qstring = $REGX->trim_slashes(str_replace($match['2'], '', $qstring));
- // Removed this in order to allow archive pagination
- // $this->paginate = FALSE;
- }
-
- /** --------------------------------------
- /** Parse ID indicator
- /** --------------------------------------*/
- if (preg_match("#^(\d+)(.*)#", $qstring, $match) AND $dynamic)
- {
- $seg = ( ! isset($match['2'])) ? '' : $match['2'];
-
- if (substr($seg, 0, 1) == "/" OR $seg == '')
- {
- $entry_id = $match['1'];
- $qstring = $REGX->trim_slashes(preg_replace("#^".$match['1']."#", '', $qstring));
- }
- }
-
- /** --------------------------------------
- /** Parse page number
- /** --------------------------------------*/
-
- if (preg_match("#^P(\d+)|/P(\d+)#", $qstring, $match) AND ($dynamic OR $TMPL->fetch_param('paginate')))
- {
- $this->p_page = (isset($match['2'])) ? $match['2'] : $match['1'];
-
- $this->basepath = $FNS->remove_double_slashes(str_replace($match['0'], '', $this->basepath));
-
- $this->uristr = $FNS->remove_double_slashes(str_replace($match['0'], '', $this->uristr));
-
- $qstring = $REGX->trim_slashes(str_replace($match['0'], '', $qstring));
-
- $page_marker = TRUE;
- }
- /** --------------------------------------
- /** Parse category indicator
- /** --------------------------------------*/
-
- // Text version of the category
- if ($qstring != '' AND $this->reserved_cat_segment != '' AND in_array($this->reserved_cat_segment, explode("/", $qstring)) AND $dynamic AND $TMPL->fetch_param('weblog'))
- {
- $qstring = preg_replace("/(.*?)".preg_quote($this->reserved_cat_segment)."\//i", '', $qstring);
-
- $sql = "SELECT DISTINCT cat_group FROM exp_weblogs WHERE site_id IN ('".implode("','", $TMPL->site_ids)."') AND ";
-
- if (USER_BLOG !== FALSE)
- {
- $sql .= " weblog_id='".UB_BLOG_ID."'";
- }
- else
- {
- $xsql = $FNS->sql_andor_string($TMPL->fetch_param('weblog'), 'blog_name');
-
- if (substr($xsql, 0, 3) == 'AND') $xsql = substr($xsql, 3);
-
- $sql .= ' '.$xsql;
- }
-
- $query = $DB->query($sql);
- if ($query->num_rows > 0)
- {
- $valid = 'y';
- $last = explode('|', $query->row['cat_group']);
- $valid_cats = array();
-
- foreach($query->result as $row)
- {
- if ($TMPL->fetch_param('relaxed_categories') == 'yes')
- {
- $valid_cats = array_merge($valid_cats, explode('|', $row['cat_group']));
- }
- else
- {
- $valid_cats = array_intersect($last, explode('|', $row['cat_group']));
- }
-
- $valid_cats = array_unique($valid_cats);
-
- if (sizeof($valid_cats) == 0)
- {
- $valid = 'n';
- break;
- }
- }
- }
- else
- {
- $valid = 'n';
- }
- if ($valid == 'y')
- {
- // the category URL title should be the first segment left at this point in $qstring,
- // but because prior to this feature being added, category names were used in URLs,
- // and '/' is a valid character for category names. If they have not updated their
- // category url titles since updating to 1.6, their category URL title could still
- // contain a '/'. So we'll try to get the category the correct way first, and if
- // it fails, we'll try the whole $qstring
-
- $cut_qstring = array_shift($temp = explode('/', $qstring));
-
- $result = $DB->query("SELECT cat_id FROM exp_categories
- WHERE cat_url_title='".$DB->escape_str($cut_qstring)."'
- AND group_id IN ('".implode("','", $valid_cats)."')");
- if ($result->num_rows == 1)
- {
- $qstring = str_replace($cut_qstring, 'C'.$result->row['cat_id'], $qstring);
- }
- else
- {
- // give it one more try using the whole $qstring
- $result = $DB->query("SELECT cat_id FROM exp_categories
- WHERE cat_url_title='".$DB->escape_str($qstring)."'
- AND group_id IN ('".implode("','", $valid_cats)."')");
- if ($result->num_rows == 1)
- {
- $qstring = 'C'.$result->row['cat_id'];
- }
- }
- }
- }
- // Numeric version of the category
- if (preg_match("#(^|\/)C(\d+)#", $qstring, $match) AND $dynamic)
- {
- $this->cat_request = TRUE;
-
- $cat_id = $match['2'];
-
- $qstring = $REGX->trim_slashes(str_replace($match['0'], '', $qstring));
- }
-
- /** --------------------------------------
- /** Remove "N"
- /** --------------------------------------*/
-
- // The recent comments feature uses "N" as the URL indicator
- // It needs to be removed if presenst
- if (preg_match("#^N(\d+)|/N(\d+)#", $qstring, $match))
- {
- $this->uristr = $FNS->remove_double_slashes(str_replace($match['0'], '', $this->uristr));
-
- $qstring = $REGX->trim_slashes(str_replace($match['0'], '', $qstring));
- }
-
- /** --------------------------------------
- /** Parse URL title
- /** --------------------------------------*/
- if (($cat_id == '' AND $year == '') OR $TMPL->fetch_param('require_entry') == 'yes')
- {
- if (strstr($qstring, '/'))
- {
- $xe = explode('/', $qstring);
- $qstring = current($xe);
- }
-
- if ($dynamic == TRUE)
- {
- $sql = "SELECT count(*) AS count
- FROM exp_weblog_titles, exp_weblogs
- WHERE exp_weblog_titles.weblog_id = exp_weblogs.weblog_id
- AND exp_weblog_titles.url_title = '".$DB->escape_str($qstring)."'";
-
- if (USER_BLOG !== FALSE)
- {
- $sql .= " AND exp_weblogs.weblog_id = '".UB_BLOG_ID."'";
- }
- else
- {
- $sql .= " AND exp_weblogs.is_user_blog = 'n' AND exp_weblogs.site_id IN ('".implode("','", $TMPL->site_ids)."') ";
- }
- $query = $DB->query($sql);
-
- if ($query->row['count'] == 0)
- {
- if ($TMPL->fetch_param('require_entry') == 'yes')
- {
- return '';
- }
-
- $qtitle = '';
- }
- else
- {
- $qtitle = $qstring;
- }
- }
- }
- }
- }
-
-
- /** ----------------------------------------------
- /** Entry ID number
- /** ----------------------------------------------*/
-
- // If the "entry ID" was hard-coded, use it instead of
- // using the dynamically set one above
-
- if ($TMPL->fetch_param('entry_id'))
- {
- $entry_id = $TMPL->fetch_param('entry_id');
- }
-
- /** ----------------------------------------------
- /** Only Entries with Pages
- /** ----------------------------------------------*/
-
- if ($TMPL->fetch_param('show_pages') !== FALSE && in_array($TMPL->fetch_param('show_pages'), array('only', 'no')) && ($pages = $PREFS->ini('site_pages')) !== FALSE)
- {
- // consider entry_id
- if ($TMPL->fetch_param('entry_id') !== FALSE)
- {
- $not = FALSE;
- if (strncmp($entry_id, 'not', 3) == 0)
- {
- $not = TRUE;
- $entry_id = trim(substr($entry_id, 3));
- }
- $ids = explode('|', $entry_id);
- if ($TMPL->fetch_param('show_pages') == 'only')
- {
- if ($not === TRUE)
- {
- $entry_id = implode('|', array_diff(array_flip($pages['uris']), explode('|', $ids)));
- }
- else
- {
- $entry_id = implode('|',array_diff($ids, array_diff($ids, array_flip($pages['uris']))));
- }
- }
- else
- {
- if ($not === TRUE)
- {
- $entry_id = "not {$entry_id}|".implode('|', array_flip($pages['uris']));
- }
- else
- {
- $entry_id = implode('|',array_diff($ids, array_flip($pages['uris'])));
- }
- }
- echo $entry_id;
- }
- else
- {
- $entry_id = (($TMPL->fetch_param('show_pages') == 'no') ? 'not ' : '').implode('|', array_flip($pages['uris']));
- }
- }
- /** ----------------------------------------------
- /** Assing the order variables
- /** ----------------------------------------------*/
-
- $order = $TMPL->fetch_param('orderby');
- $sort = $TMPL->fetch_param('sort');
- $sticky = $TMPL->fetch_param('sticky');
-
- /** -------------------------------------
- /** Multiple Orders and Sorts...
- /** -------------------------------------*/
-
- if ($order !== FALSE && stristr($order, '|'))
- {
- $order_array = explode('|', $order);
-
- if ($order_array['0'] == 'random')
- {
- $order_array = array('random');
- }
- }
- else
- {
- $order_array = array($order);
- }
-
- if ($sort !== FALSE && stristr($sort, '|'))
- {
- $sort_array = explode('|', $sort);
- }
- else
- {
- $sort_array = array($sort);
- }
-
- /** -------------------------------------
- /** Validate Results for Later Processing
- /** -------------------------------------*/
-
- $base_orders = array('random', 'entry_id', 'date', 'title', 'url_title', 'edit_date', 'comment_total', 'username', 'screen_name', 'most_recent_comment', 'expiration_date',
- 'view_count_one', 'view_count_two', 'view_count_three', 'view_count_four');
-
- foreach($order_array as $key => $order)
- {
- if ( ! in_array($order, $base_orders))
- {
- if (FALSE !== $order)
- {
- $set = 'n';
-
- /** -------------------------------------
- /** Site Namespace is Being Used, Parse Out
- /** -------------------------------------*/
-
- if (strpos($order, ':') !== FALSE)
- {
- $order_parts = explode(':', $order, 2);
-
- if (isset($TMPL->site_ids[$order_parts[0]]) && isset($this->cfields[$TMPL->site_ids[$order_parts[0]]][$order_parts[1]]))
- {
- $corder[$key] = $this->cfields[$TMPL->site_ids[$order_parts[0]]][$order_parts[1]];
- $order_array[$key] = 'custom_field';
- $set = 'y';
- }
- }
-
- /** -------------------------------------
- /** Find the Custom Field, Cycle Through All Sites for Tag
- /** - If multiple sites have the same short_name for a field, we do a CONCAT ORDERBY in query
- /** -------------------------------------*/
-
- if ($set == 'n')
- {
- foreach($this->cfields as $site_id => $cfields)
- {
- // Only those sites specified
- if ( ! in_array($site_id, $TMPL->site_ids))
- {
- continue;
- }
-
- if (isset($cfields[$order]))
- {
- if ($set == 'y')
- {
- $corder[$key] .= '|'.$cfields[$order];
- }
- else
- {
- $corder[$key] = $cfields[$order];
- $order_array[$key] = 'custom_field';
- $set = 'y';
- }
- }
- }
- }
-
- if ($set == 'n')
- {
- $order_array[$key] = FALSE;
- }
- }
- }
-
- if ( ! isset($sort_array[$key]))
- {
- $sort_array[$key] = 'desc';
- }
- }
-
- foreach($sort_array as $key => $sort)
- {
- if ($sort == FALSE || ($sort != 'asc' AND $sort != 'desc'))
- {
- $sort_array[$key] = "desc";
- }
- }
-
- // fixed entry id ordering
- if (($fixed_order = $TMPL->fetch_param('fixed_order')) === FALSE OR preg_match('/[^0-9\|]/', $fixed_order))
- {
- $fixed_order = FALSE;
- }
- else
- {
- // MySQL will not order the entries correctly unless the results are constrained
- // to matching rows only, so we force the entry_id as well
- $entry_id = $fixed_order;
- $fixed_order = preg_split('/\|/', $fixed_order, -1, PREG_SPLIT_NO_EMPTY);
-
- // some peeps might want to be able to 'flip' it
- // the default sort order is 'desc' but in this context 'desc' has a stronger "reversing"
- // connotation, so we look not at the sort array, but the tag parameter itself, to see the user's intent
- if ($sort == 'desc')
- {
- $fixed_order = array_reverse($fixed_order);
- }
- }
- /** ----------------------------------------------
- /** Build the master SQL query
- /** ----------------------------------------------*/
-
- $sql_a = "SELECT ";
-
- $sql_b = ($TMPL->fetch_param('category') || $TMPL->fetch_param('category_group') || $cat_id != '' || $order_array['0'] == 'random') ? "DISTINCT(t.entry_id) " : "t.entry_id ";
-
- if ($this->field_pagination == TRUE)
- {
- $sql_b .= ",wd.* ";
- }
- $sql_c = "COUNT(t.entry_id) AS count ";
-
- $sql = "FROM exp_weblog_titles AS t
- LEFT JOIN exp_weblogs ON t.weblog_id = exp_weblogs.weblog_id ";
-
- if ($this->field_pagination == TRUE)
- {
- $sql .= "LEFT JOIN exp_weblog_data AS wd ON t.entry_id = wd.entry_id ";
- }
- elseif (in_array('custom_field', $order_array))
- {
- $sql .= "LEFT JOIN exp_weblog_data AS wd ON t.entry_id = wd.entry_id ";
- }
-
- $sql .= "LEFT JOIN exp_members AS m ON m.member_id = t.author_id ";
-
-
- if ($TMPL->fetch_param('category') || $TMPL->fetch_param('category_group') || $cat_id != '')
- {
- /* --------------------------------
- /* We use LEFT JOIN when there is a 'not' so that we get
- /* entries that are not assigned to a category.
- /* --------------------------------*/
-
- if ((substr($TMPL->fetch_param('category_group'), 0, 3) == 'not' OR substr($TMPL->fetch_param('category'), 0, 3) == 'not') && $TMPL->fetch_param('uncategorized_entries') !== 'n')
- {
- $sql .= "LEFT JOIN exp_category_posts ON t.entry_id = exp_category_posts.entry_id
- LEFT JOIN exp_categories ON exp_category_posts.cat_id = exp_categories.cat_id ";
- }
- else
- {
- $sql .= "INNER JOIN exp_category_posts ON t.entry_id = exp_category_posts.entry_id
- INNER JOIN exp_categories ON exp_category_posts.cat_id = exp_categories.cat_id ";
- }
- }
-
- // join data table if we're searching fields
- if (! empty($TMPL->search_fields) && strpos($sql, 'exp_weblog_data AS wd') === FALSE)
- {
- $sql .= "LEFT JOIN exp_weblog_da…
Large files files are truncated, but you can click here to view the full file