Пример #1
0
    /**
     * rank
     * 
     *	@access		public
     *	@return		string 	tagdata
     */
    public function rank()
    {
        $entry_id = '';
        $cat_id = '';
        $dynamic = !$this->check_no(ee()->TMPL->fetch_param('dynamic'));
        // -------------------------------------------
        //  Grab entries
        // -------------------------------------------
        $sql = "FROM  \t\t{$this->sc->db->channel_titles} AS t\r\n\t\t\t\t   LEFT JOIN \t{$this->sc->db->channels} as c \r\n\t\t\t\t   ON \t\t\tc.{$this->sc->db->channel_id} = t.{$this->sc->db->channel_id}";
        if (ee()->TMPL->fetch_param('category') or $cat_id != '' and $dynamic) {
            $sql .= " LEFT JOIN \texp_category_posts \r\n\t\t\t \t\t\t ON \t\tt.entry_id = exp_category_posts.entry_id\r\n\t\t\t\t\t\t LEFT JOIN \texp_categories \r\n\t\t\t\t\t\t ON \t\texp_category_posts.cat_id = exp_categories.cat_id";
        }
        $sql .= " WHERE \tt.site_id \r\n\t\t\t\t\t IN \t('" . implode("','", ee()->TMPL->site_ids) . "') ";
        // -------------------------------------------
        //	Yes, One Could Potentially Show Nothing...
        // -------------------------------------------
        if (!$this->check_yes(ee()->TMPL->fetch_param('show_unfavorited'))) {
            $sql .= " AND (t.favorites_count_public != 0 \r\n\t\t\t\t\t\t AND t.favorites_count_public != '') ";
        }
        if ($this->check_no(ee()->TMPL->fetch_param('show_favorites'))) {
            $sql .= " AND (t.favorites_count_public = 0 OR t.favorites_count_public = '') ";
        }
        if (ee()->TMPL->fetch_param('favorites_start_on') !== FALSE or ee()->TMPL->fetch_param('favorites_stop_before') !== FALSE) {
            $asql = "SELECT DISTINCT \tentry_id\r\n\t\t\t\t\t   FROM \t\t\texp_favorites\r\n\t\t\t\t\t   WHERE \t\t\tsite_id \r\n\t\t\t\t\t   IN \t\t\t\t('" . implode("','", ee()->TMPL->site_ids) . "')";
            if (ee()->TMPL->fetch_param('favorites_start_on')) {
                $asql .= " AND exp_favorites.entry_date >= '" . ee()->localize->convert_human_date_to_gmt(ee()->TMPL->fetch_param('favorites_start_on')) . "' ";
            }
            if (ee()->TMPL->fetch_param('favorites_stop_before')) {
                $asql .= " AND exp_favorites.entry_date < '" . ee()->localize->convert_human_date_to_gmt(ee()->TMPL->fetch_param('favorites_stop_before')) . "' ";
            }
            $aquery = ee()->db->query($asql);
            if ($aquery->num_rows() == 0) {
                return $this->no_results();
            }
            $entries = array();
            foreach ($aquery->result_array() as $row) {
                $entries[] = $row['entry_id'];
            }
            $sql .= " AND t.entry_id IN ('" . implode("','", $entries) . "')";
            unset($aquery);
            unset($entries);
        }
        // -------------------------------------------
        //	We only select un-expired entries
        // -------------------------------------------
        $timestamp = ee()->TMPL->cache_timestamp != '' ? ee()->TMPL->cache_timestamp : ee()->localize->now;
        if (!$this->check_yes(ee()->TMPL->fetch_param('show_future_entries'))) {
            $sql .= " AND t.entry_date < " . $timestamp . " ";
        }
        if (!$this->check_yes(ee()->TMPL->fetch_param('show_expired'))) {
            $sql .= " AND (t.expiration_date = 0 || t.expiration_date > " . $timestamp . ") ";
        }
        // -------------------------------------------
        // Limit to/exclude specific weblogs
        // -------------------------------------------
        if ($channel = ee()->TMPL->fetch_param($this->sc->channel)) {
            $xql = "SELECT \t{$this->sc->db->channel_id} \r\n\t\t\t\t    FROM \t{$this->sc->db->channels} \r\n\t\t\t\t\tWHERE \tsite_id \r\n\t\t\t\t\tIN \t\t('" . implode("','", ee()->db->escape_str(ee()->TMPL->site_ids)) . "') ";
            $xql .= ee()->functions->sql_andor_string($channel, $this->sc->db->channel_name);
            $query = ee()->db->query($xql);
            if ($query->num_rows() == 0) {
                return $this->no_results();
            } else {
                if ($query->num_rows() == 1) {
                    $sql .= "AND t.{$this->sc->db->channel_id} = '" . $query->row($this->sc->db->channel_id) . "' ";
                } else {
                    $sql .= "AND (";
                    foreach ($query->result_array() as $row) {
                        $sql .= "t.{$this->sc->db->channel_id} = '" . $row[$this->sc->db->channel_id] . "' OR ";
                    }
                    $sql = substr($sql, 0, -3);
                    $sql .= ") ";
                }
            }
        }
        // -------------------------------------------
        //  Limit query by category
        // -------------------------------------------
        if (ee()->TMPL->fetch_param('category')) {
            $sql .= ee()->functions->sql_andor_string(ee()->TMPL->fetch_param('category'), 'exp_categories.cat_id') . " ";
        } else {
            if ($cat_id != '' and $dynamic) {
                $sql .= " AND exp_categories.cat_id = '" . ee()->db->escape_str($cat_id) . "' ";
            }
        }
        // -------------------------------------------
        //	Add status declaration
        // -------------------------------------------
        if ($status = ee()->TMPL->fetch_param('status')) {
            $status = str_replace('Open', 'open', $status);
            $status = str_replace('Closed', 'closed', $status);
            $sstr = ee()->functions->sql_andor_string($status, 't.status');
            if (!stristr($sstr, "'closed'")) {
                $sstr .= " AND t.status != 'closed' ";
            }
            $sql .= $sstr;
        } else {
            $sql .= "AND t.status = 'open' ";
        }
        // -------------------------------------------
        //	Limit by number of hours
        // -------------------------------------------
        if ($days = ee()->TMPL->fetch_param('hours')) {
            $time = ee()->localize->now - $days * 60 * 60;
            $sql .= " AND t.entry_date > {$time}";
        }
        // -------------------------------------------
        //	Order by
        // -------------------------------------------
        if (ee()->TMPL->fetch_param('orderby') == 'random') {
            $sql .= " ORDER BY rand()";
        } else {
            $sql .= " ORDER BY count DESC";
        }
        // ----------------------------------------
        //  Pagination!
        // ----------------------------------------
        if (is_numeric(ee()->TMPL->fetch_param('limit'))) {
            $this->p_limit = ee()->TMPL->fetch_param('limit');
        }
        // ----------------------------------------
        //  Favorites Date Required for Ordering?
        // ----------------------------------------
        $sort = in_array(strtoupper(ee()->TMPL->fetch_param('sort')), array('DESC', 'ASC')) ? strtoupper(ee()->TMPL->fetch_param('sort')) : 'DESC';
        if (ee()->TMPL->fetch_param('orderby') == 'favorites_date') {
            $sql = preg_replace("/ORDER BY.+?(LIMIT|\$)/is", "ORDER BY favorites_date " . $sort . ' \\1', $sql);
            $ugh = !$this->check_yes(ee()->TMPL->fetch_param('show_unfavorited')) ? 'INNER' : 'LEFT';
            $sql = preg_replace("/LEFT JOIN\\s+{$this->sc->db->channels}/is", "{$ugh} JOIN \texp_favorites AS f \r\n\t\t\t\t ON \t\t\t(t.entry_id = f.entry_id\r\n        \t\t AND \t\t\tf.favorites_id \r\n\t\t\t\t IN\t\t\t\t(SELECT MAX(favorites_id) FROM exp_favorites GROUP BY entry_id))\r\n        \t\t LEFT JOIN \t\t{$this->sc->db->channels}", $sql);
        }
        // -------------------------------------------
        //	Run query
        // -------------------------------------------
        $orderby = ee()->TMPL->fetch_param('orderby') != '' ? ee()->TMPL->fetch_param('orderby') : 'count';
        if ($orderby == 'favorites_date') {
            $query = ee()->db->query('SELECT t.entry_id, 
						f.entry_date AS favorites_date, 
						t.favorites_count_public AS count ' . $sql);
        } else {
            $query = ee()->db->query('SELECT t.entry_id, 
						t.favorites_count_public AS count ' . $sql);
        }
        // -------------------------------------------
        //	Create entries array
        // -------------------------------------------
        $entries = array();
        if ($query->num_rows() == 0) {
            return $this->no_results();
        } else {
            foreach ($query->result_array() as $row) {
                $entries[] = $row['entry_id'];
            }
            // -------------------------------------------
            //  Pass params
            // -------------------------------------------
            ee()->TMPL->tagparams['entry_id'] = implode("|", $entries);
            if ($orderby == 'favorites_date' or $orderby == 'count') {
                if ($sort == 'ASC') {
                    $entries = array_reverse($entries);
                }
                ee()->TMPL->tagparams['fixed_order'] = implode("|", $entries);
            }
            ee()->TMPL->tagparams['sort'] = $sort;
        }
        // -------------------------------------------
        //  Invoke weblog class
        // -------------------------------------------
        if (APP_VER < 2.0) {
            if (!class_exists('Weblog')) {
                require PATH_MOD . '/weblog/mod.weblog' . EXT;
            }
            $channel = new Weblog();
        } else {
            if (!class_exists('Channel')) {
                require PATH_MOD . '/channel/mod.channel' . EXT;
            }
            $channel = new Channel();
        }
        // --------------------------------------------
        //  Invoke Pagination for EE 2.4 and Above
        // --------------------------------------------
        if (APP_VER >= '2.4.0') {
            ee()->load->library('pagination');
            $channel->pagination = new Pagination_object('Channel');
            // Used by pagination to determine whether we're coming from the cache
            $channel->pagination->dynamic_sql = FALSE;
        }
        // ----------------------------------------
        //  Pre-process related data
        // ----------------------------------------
        //	TMPL class is coded so that only
        //	one method in the weblog class and one
        //	method in the search class are allowed
        //	to parse related entries tags. This is
        //	no doubt for performance reasons.
        // ----------------------------------------
        ee()->TMPL->tagdata = ee()->TMPL->assign_relationship_data(ee()->TMPL->tagdata);
        ee()->TMPL->var_single = array_merge(ee()->TMPL->var_single, ee()->TMPL->related_markers);
        // ----------------------------------------
        //  Execute needed methods
        // ----------------------------------------
        if (APP_VER < 2.0) {
            $channel->fetch_custom_weblog_fields();
        } else {
            $channel->fetch_custom_channel_fields();
        }
        $channel->fetch_custom_member_fields();
        // --------------------------------------------
        //  Pagination Tags Parsed Out
        // --------------------------------------------
        if (APP_VER >= '2.4.0') {
            $channel->pagination->get_template();
        } else {
            $channel->fetch_pagination_data();
        }
        //	----------------------------------------
        //	 Build Weblog Data Query
        //	----------------------------------------
        $channel->build_sql_query();
        // --------------------------------------------
        //  Transfer Pagination Variables Over to Channel object
        //	- Has to go after the building of the query as EE 2.4 does its Pagination work in there
        // --------------------------------------------
        if (APP_VER >= '2.4.0') {
            $transfer = array('paginate' => 'paginate', 'total_pages' => 'total_pages', 'current_page' => 'current_page', 'offset' => 'offset', 'page_next' => 'page_next', 'page_previous' => 'page_previous', 'page_links' => 'pagination_links', 'total_rows' => 'total_rows', 'per_page' => 'per_page', 'per_page' => 'p_limit', 'offset' => 'p_page');
            foreach ($transfer as $from => $to) {
                $channel->{$to} = $channel->pagination->{$from};
            }
        }
        //	----------------------------------------
        //	Empty?
        //	----------------------------------------
        if (trim($channel->sql) == '') {
            if ($this->check_yes(ee()->TMPL->fetch_param('favorites_count'))) {
                return $this->return_data = str_replace(LD . 'favorites_count' . RD, '0', ee()->TMPL->tagdata);
            } else {
                return $this->no_results();
            }
        }
        // ----------------------------------------
        //  Pagination
        // ----------------------------------------
        $query = ee()->db->query(preg_replace("/SELECT(.*?)\\s+FROM\\s+/is", 'SELECT COUNT(*) AS count FROM ', $channel->sql));
        $this->total_rows = $query->row('count');
        //pagination request but no entries?
        if ($query->row('count') == 0 and strpos(ee()->TMPL->tagdata, 'paginate') !== FALSE) {
            return $this->no_results();
        }
        //$sql_remove = 'SELECT t.entry_id ';
        //get pagination info
        $pagination_data = $this->universal_pagination(array('sql' => $channel->sql, 'total_results' => $this->total_rows, 'tagdata' => ee()->TMPL->tagdata, 'limit' => $this->p_limit, 'uri_string' => ee()->uri->uri_string, 'current_page' => $this->current_page));
        //if we paginated, sort the data
        if ($pagination_data['paginate'] === TRUE) {
            $this->paginate = $pagination_data['paginate'];
            $this->page_next = $pagination_data['page_next'];
            $this->page_previous = $pagination_data['page_previous'];
            $this->p_page = $pagination_data['pagination_page'];
            $this->current_page = $pagination_data['current_page'];
            $channel->sql = str_replace($sql_remove, '', $pagination_data['sql']);
            $this->pagination_links = $pagination_data['pagination_links'];
            $this->basepath = $pagination_data['base_url'];
            $this->total_pages = $pagination_data['total_pages'];
            $this->paginate_data = $pagination_data['paginate_tagpair_data'];
            ee()->TMPL->tagdata = $pagination_data['tagdata'];
        } else {
            $channel->sql .= " LIMIT " . $this->p_limit;
        }
        //	----------------------------------------
        //	 Favorites Specific Rewrites!
        //	----------------------------------------
        if ($this->check_yes(ee()->TMPL->fetch_param('favorites_count'))) {
            /*$query = ee()->db->query(
            			preg_replace(
            				"/SELECT(.*?)\s+FROM\s+/is", 
            				'SELECT COUNT(*) AS count FROM ', 
            				$channel->sql
            			)
            		);*/
            return $this->return_data = str_replace(LD . 'favorites_count' . RD, $this->total_rows, ee()->TMPL->tagdata);
        }
        //	----------------------------------------
        //	 Favorites date
        //	----------------------------------------
        if (stristr(ee()->TMPL->tagdata, LD . 'favorites_date ') or ee()->TMPL->fetch_param('orderby') == 'favorites_date') {
            $channel->favorites_date = TRUE;
            $channel->sql = preg_replace("/\\s+FROM\\s+/s", ", f.entry_date AS favorites_date FROM ", ltrim($channel->sql));
            $channel->sql = preg_replace("/LEFT JOIN\\s+{$this->sc->db->channels}/is", "LEFT JOIN \texp_favorites AS f \r\n\t\t\t\t ON \t\t(t.entry_id = f.entry_id\r\n\t\t\t\t AND \t\tf.favorites_id \r\n\t\t\t\t IN \t\t(SELECT MAX(favorites_id) FROM exp_favorites GROUP BY entry_id))\r\n        \t\t LEFT JOIN \t{$this->sc->db->channels}", $channel->sql);
        }
        $channel->query = ee()->db->query($channel->sql);
        if (APP_VER < 2.0) {
            $channel->query->result = $channel->query->result_array();
        }
        //	----------------------------------------
        //	Empty?
        //	----------------------------------------
        if (!isset($channel->query) or $channel->query->num_rows() == 0) {
            return $this->no_results();
        }
        //	----------------------------------------
        //	typography
        //	----------------------------------------
        if (APP_VER < 2.0) {
            if (!class_exists('Typography')) {
                require PATH_CORE . 'core.typography' . EXT;
            }
            $channel->TYPE = new Typography();
            $channel->TYPE->convert_curly = FALSE;
        } else {
            ee()->load->library('typography');
            ee()->typography->initialize();
            ee()->typography->convert_curly = FALSE;
        }
        $channel->fetch_categories();
        // ----------------------------------------
        //  Parse and return entry data
        // ----------------------------------------
        if (APP_VER < 2.0) {
            $channel->parse_weblog_entries();
        } else {
            $channel->parse_channel_entries();
        }
        // --------------------------------------------
        //  Render the Pagination Data
        // --------------------------------------------
        if (APP_VER >= '2.4.0') {
            $channel->return_data = $channel->pagination->render($channel->return_data);
        } else {
            $channel->add_pagination_data();
        }
        // --------------------------------------------
        //  Reverse and Related Entries
        // --------------------------------------------
        if (count(ee()->TMPL->related_data) > 0 and count($channel->related_entries) > 0) {
            $channel->parse_related_entries();
        }
        if (count(ee()->TMPL->reverse_related_data) > 0 and count($channel->reverse_related_entries) > 0) {
            $channel->parse_reverse_related_entries();
        }
        // ----------------------------------------
        //  Handle problem with pagination segments
        //	in the url
        // ----------------------------------------
        if (preg_match("#(/P\\d+)#", ee()->uri->uri_string, $match)) {
            $channel->return_data = str_replace($match['1'], "", $channel->return_data);
        } elseif (preg_match("#(P\\d+)#", ee()->uri->uri_string, $match)) {
            $channel->return_data = str_replace($match['1'], "", $channel->return_data);
        }
        // ----------------------------------------
        //  Pagination Replace
        // ----------------------------------------
        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 . preg_quote(T_SLASH, '/') . "if" . RD . "/s", $this->paginate_data, $match)) {
                if ($this->page_previous == '') {
                    $this->paginate_data = preg_replace("/" . LD . "if previous_page" . RD . ".+?" . LD . preg_quote(T_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 . preg_quote(T_SLASH, '/') . "if" . RD . "/s", $this->paginate_data, $match)) {
                if ($this->page_next == '') {
                    $this->paginate_data = preg_replace("/" . LD . "if next_page" . RD . ".+?" . LD . preg_quote(T_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 = !ee()->TMPL->fetch_param('paginate') ? '' : ee()->TMPL->fetch_param('paginate');
            switch ($position) {
                case "top":
                    $channel->return_data = $this->paginate_data . $channel->return_data;
                    break;
                case "both":
                    $channel->return_data = $this->paginate_data . $channel->return_data . $this->paginate_data;
                    break;
                default:
                    $channel->return_data .= $this->paginate_data;
                    break;
            }
        }
        $tagdata = $channel->return_data;
        return $tagdata;
    }
Пример #2
0
 /**
  * Prepare occurrences output
  *
  * @param	string	$tagdata			Tagdata
  * @param	array	$data				Array of data
  * @param	bool	$include_default	Include the default entry_id when fetching weblog data?
  * @return	string
  */
 protected function prep_occurrences_output($tagdata, $data, $include_default = TRUE)
 {
     // -------------------------------------
     //  Ensure $this->CDT is ready
     // -------------------------------------
     $this->load_calendar_datetime();
     if (empty($data->dates)) {
         return $tagdata;
     }
     $output = '';
     // -------------------------------------
     //  Put the items in order
     // -------------------------------------
     foreach ($data->dates as $ymd => $times) {
         ksort($data->dates[$ymd]);
     }
     ksort($data->dates);
     //--------------------------------------------
     //	order arrays for later multi sorting
     //--------------------------------------------
     $calendar_orderby_params = array('event_start_date', 'occurrence_start_date');
     $orders = explode('|', $this->P->value('orderby'));
     $sorts = explode('|', $this->P->value('sort'));
     $calendar_orders = array();
     $calendar_order_data = array();
     foreach ($orders as $k => $order) {
         if (in_array($order, $calendar_orderby_params)) {
             $sort = isset($sorts[$k]) ? $sorts[$k] : 'desc';
             $calendar_orders[$order] = $sort;
             $calendar_order_data[$order] = array();
         }
     }
     // -------------------------------------
     //  Are prior_ or upcoming_ limits in effect?
     // -------------------------------------
     $prior_limit = $this->P->value('prior_occurrences_limit') !== FALSE ? $this->P->value('prior_occurrences_limit') : FALSE;
     $upcoming_limit = $this->P->value('upcoming_occurrences_limit') !== FALSE ? $this->P->value('upcoming_occurrences_limit') : FALSE;
     if ($prior_limit !== FALSE or $upcoming_limit !== FALSE) {
         $priors = array();
         $upcoming = array();
         //set date to current
         $this->CDT->set_date_to_now();
         foreach ($data->dates as $ymd => $info) {
             //yeterday or before
             if ($ymd < $this->CDT->ymd) {
                 $priors[$ymd] = $info;
             } elseif ($ymd == $this->CDT->ymd) {
                 //we need to check all hours and minutes :/
                 foreach ($info as $time => $time_data) {
                     $temp_end_hour = $time_data['end_date']['hour'] + ($time_data['end_date']['pm'] ? 12 : 0);
                     $temp_end_minute = $time_data['end_date']['minute'];
                     //if this is an all day item and we are still in this day, its current
                     if ($time_data['all_day'] == TRUE) {
                         $upcoming[$ymd][$time] = $time_data;
                     } else {
                         if ($temp_end_hour > $this->CDT->hour() or $temp_end_hour == $this->CDT->hour() and $temp_end_minute > $this->CDT->minute()) {
                             $upcoming[$ymd][$time] = $time_data;
                         } else {
                             $priors[$ymd][$time] = $time_data;
                         }
                     }
                 }
             } else {
                 $upcoming[$ymd] = $info;
             }
         }
         //slice out our limits
         if ($prior_limit !== FALSE) {
             $priors = $this->apply_occurrences_limit($priors, $prior_limit, 0, 'prior');
             //$priors = array_slice(array_reverse($priors, TRUE), 0, $prior_limit, TRUE);
         }
         if ($upcoming_limit !== FALSE) {
             $upcoming = $this->apply_occurrences_limit($upcoming, $upcoming_limit, 0, 'upcoming');
             //$upcoming = array_slice($upcoming, 0, $upcoming_limit, TRUE);
         }
         //this has to be recursive because we can have the same $YMD happening if its today's date
         $data->dates = array_merge_recursive($priors, $upcoming);
     }
     //--------------------------------------------
     //	get default data from parent entry_id
     //--------------------------------------------
     if (!isset($this->cache['entry_info'])) {
         $this->cache['entry_info'] = array();
     }
     //we need some extra data about this entry so we can parse occurrences items
     if (!isset($this->cache['entry_info'][$data->default_data['entry_id']])) {
         $entry_info_query = ee()->db->query("SELECT \tct.title, ct.url_title, ct.author_id, ct.status, m.screen_name, m.username\n\t\t\t\t FROM\t\t{$this->sc->db->channel_titles} as ct\n\t\t\t\t LEFT JOIN\texp_members as m\n\t\t\t\t ON\t\t\tct.author_id = m.member_id\n\t\t\t\t WHERE\t\tct.entry_id = " . ee()->db->escape_str($data->default_data['entry_id']));
         if ($entry_info_query->num_rows() > 0) {
             $this->cache['entry_info'][$data->default_data['entry_id']] = $entry_info_query->row_array();
         } else {
             $this->cache['entry_info'][$data->default_data['entry_id']] = array();
         }
     }
     $entry_info = $this->cache['entry_info'][$data->default_data['entry_id']];
     // -------------------------------------
     //  Grab entry IDs from the occurrences
     // -------------------------------------
     foreach ($data->occurrences as $ymd => $times) {
         foreach ($times as $time => $info) {
             if ($info['entry_id'] != $data->default_data['entry_id'] and !isset($ids[$info['entry_id']])) {
                 $ids[$ymd] = $info['entry_id'];
             }
         }
     }
     $tagdatas = array();
     $tagdatas[$data->default_data['entry_id']] = $tagdata;
     //this will probably only happen for edited occurrences
     if (!empty($ids)) {
         // -------------------------------------
         //  Add the "parent" entry id for default data
         // -------------------------------------
         $ids[0] = $data->default_data['entry_id'];
         //ee()->TMPL_orig = clone ee()->TMPL;
         $tagdata = LD . 'occurrences id="' . LD . 'entry_id' . RD . '"' . RD . $tagdata . LD . T_SLASH . 'occurrences' . RD;
         //	----------------------------------------
         //	Invoke Channel class
         //	----------------------------------------
         if (APP_VER < 2.0) {
             if (!class_exists('Weblog')) {
                 require PATH_MOD . '/weblog/mod.weblog' . EXT;
             }
             $channel = new Weblog();
         } else {
             if (!class_exists('Channel')) {
                 require PATH_MOD . '/channel/mod.channel' . EXT;
             }
             $channel = new Channel();
         }
         //default is 100 and that could limit events when there are very many to be shown
         $channel->limit = 500;
         // --------------------------------------------
         //  Invoke Pagination for EE 2.4 and Above
         // --------------------------------------------
         if (APP_VER >= '2.4.0') {
             ee()->load->library('pagination');
             $channel->pagination = new Pagination_object('Channel');
             // Used by pagination to determine whether we're coming from the cache
             $channel->pagination->dynamic_sql = FALSE;
         }
         // -------------------------------------
         //  Prepare parameters
         // -------------------------------------
         ee()->TMPL->tagparams['entry_id'] = implode('|', $ids);
         ee()->TMPL->tagparams['weblog'] = CALENDAR_EVENTS_CHANNEL_NAME;
         ee()->TMPL->tagparams['channel'] = CALENDAR_EVENTS_CHANNEL_NAME;
         // -------------------------------------
         //  Pre-process related data
         // -------------------------------------
         ee()->TMPL->tagdata = ee()->TMPL->assign_relationship_data($tagdata);
         ee()->TMPL->var_single = array_merge(ee()->TMPL->var_single, ee()->TMPL->related_markers);
         ee()->TMPL->var_single['entry_id'] = 'entry_id';
         // -------------------------------------
         //  Execute needed methods
         // -------------------------------------
         if (APP_VER < 2.0) {
             $channel->fetch_custom_weblog_fields();
         } else {
             $channel->fetch_custom_channel_fields();
         }
         $channel->fetch_custom_member_fields();
         // --------------------------------------------
         //  Pagination Tags Parsed Out
         // --------------------------------------------
         if (APP_VER >= '2.4.0') {
             $channel->pagination->get_template();
         } else {
             $channel->fetch_pagination_data();
         }
         // -------------------------------------
         //  Add occurrence_ prefix to custom fields
         // -------------------------------------
         foreach ($channel->cfields as $sid => $fields) {
             foreach ($fields as $name => $fid) {
                 $channel->cfields[$sid]['occurrence_' . $name] = $fid;
                 unset($channel->cfields[$sid][$name]);
             }
         }
         // -------------------------------------
         //  Querification
         // -------------------------------------
         $channel->build_sql_query();
         if ($channel->sql == '') {
             return $this->no_results();
         }
         $channel->query = ee()->db->query($channel->sql);
         if ($channel->query->num_rows() == 0) {
             //ee()->TMPL->log_item('Calendar: Channel module says no results, bailing');
             return $this->no_results();
         }
         $channel->query->result = $channel->query->result_array();
         // -------------------------------------
         //  Trim IDs and build events
         // -------------------------------------
         $new_ids = array();
         foreach ($channel->query->result as $k => $row) {
             $new_ids[$row['entry_id']] = $row['entry_id'];
         }
         if (empty($new_ids)) {
             return $this->no_results();
         }
         $occurrence_data = $this->data->fetch_event_occurrences($data->default_data['entry_id']);
         // -------------------------------------
         //  Turn these IDs into events
         // -------------------------------------
         $events = array();
         if (!class_exists('Calendar_event')) {
             require_once CALENDAR_PATH . 'calendar.event' . EXT;
         }
         $calendars = array();
         $start_ymd = $this->P->value('date_range_start') !== FALSE ? $this->P->value('date_range_start', 'ymd') : '';
         $end_ymd = $this->P->value('date_range_end') !== FALSE ? $this->P->value('date_range_end', 'ymd') : '';
         foreach ($occurrence_data[$data->default_data['entry_id']] as $times) {
             foreach ($times as $k => $odata) {
                 $temp = new Calendar_event($odata, $start_ymd, $end_ymd);
                 if (!empty($temp->dates)) {
                     $temp->prepare_for_output();
                     $events[$odata['entry_id']] = $temp;
                     $calendars[$events[$odata['entry_id']]->default_data['calendar_id']] = array();
                 }
             }
         }
         // -------------------------------------
         //  Fetch information about the calendars
         // -------------------------------------
         $calendars = $this->data->fetch_calendar_data_by_id(array_keys($calendars));
         // -------------------------------------
         //  Prep variable aliases
         // -------------------------------------
         $variables = array('title' => 'occurrence_title', 'url_title' => 'occurrence_url_title', 'entry_id' => 'occurrence_id', 'author_id' => 'occurrence_author_id', 'author' => 'occurrence_author', 'status' => 'occurrence_status');
         // -------------------------------------
         //  Add variables to the query result
         // -------------------------------------
         foreach ($channel->query->result as $k => $row) {
             $channel->query->result[$k]['author'] = $row['screen_name'] != '' ? $row['screen_name'] : $row['username'];
             $entry_id = $row['entry_id'];
             if (isset($ids[0]) and $entry_id == $ids[0]) {
                 $events[$entry_id] = $data;
             } elseif (!isset($events[$entry_id])) {
                 unset($channel->query->result[$k]);
                 continue;
             }
             // -------------------------------------
             //  Alias
             // -------------------------------------
             foreach ($variables as $old => $new) {
                 $channel->query->result[$k][$new] = $channel->query->result[$k][$old];
             }
             // -------------------------------------
             //  Occurrence variables
             // -------------------------------------
             foreach ($events[$entry_id]->default_data as $key => $val) {
                 if (!is_array($val)) {
                     if ($val == 'y' or $val == 'n') {
                         $channel->query->result[$k]['occurrence_' . $key] = $val == 'y' ? TRUE : FALSE;
                     } else {
                         $channel->query->result[$k]['occurrence_' . $key] = $val;
                     }
                 } else {
                     foreach ($val as $vkey => $vval) {
                         if ($vval === 'y' or $vval === 'n') {
                             $channel->query->result[$k]['occurrence_' . $key . '_' . $vkey] = $vval == 'y' ? TRUE : FALSE;
                         } else {
                             $channel->query->result[$k]['occurrence_' . $key . '_' . $vkey] = $vval;
                         }
                     }
                 }
             }
         }
         unset($CDT);
         //	----------------------------------------
         //	Redeclare
         //	----------------------------------------
         //	We will reassign the $channel->query->result with our
         //	reordered array of values. Thank you PHP for being so fast with array loops.
         //	----------------------------------------
         if (APP_VER < 2.0) {
             $channel->query->result = $channel->query->result;
         } else {
             $channel->query->result_array = $channel->query->result;
         }
         // --------------------------------------------
         //  Typography
         // --------------------------------------------
         if (APP_VER < 2.0) {
             if (!class_exists('Typography')) {
                 require PATH_CORE . 'core.typography' . EXT;
             }
             $channel->TYPE = new Typography();
             $channel->TYPE->convert_curly = FALSE;
         } else {
             ee()->load->library('typography');
             ee()->typography->initialize();
             ee()->typography->convert_curly = FALSE;
         }
         $channel->fetch_categories();
         // -------------------------------------
         //  Parse
         // -------------------------------------
         //ee()->TMPL->log_item('Calendar: Parsing, via channel module');
         if (APP_VER < 2.0) {
             $channel->parse_weblog_entries();
         } else {
             $channel->parse_channel_entries();
         }
         // -------------------------------------
         //  Paginate
         // -------------------------------------
         //$channel->add_pagination_data();
         // -------------------------------------
         //  Related entries
         // -------------------------------------
         if (count(ee()->TMPL->related_data) > 0 and count($channel->related_entries) > 0) {
             $channel->parse_related_entries();
         }
         if (count(ee()->TMPL->reverse_related_data) > 0 and count($channel->reverse_related_entries) > 0) {
             $channel->parse_reverse_related_entries();
         }
         // -------------------------------------
         //  Send 'em home
         // -------------------------------------
         $tagdata = $channel->return_data;
         // -------------------------------------
         //  Collect the tagdata
         // -------------------------------------
         preg_match_all("/" . LD . 'occurrences id="(\\d+)"' . RD . '(.*?)' . LD . preg_quote(T_SLASH, '/') . 'occurrences' . RD . '/s', $tagdata, $matches);
         foreach ($matches[1] as $k => $id) {
             $tagdatas[$id] = $matches[2][$k];
         }
         //ee()->TMPL = ee()->TMPL_orig;
     }
     // -------------------------------------
     //  Date and time variables
     // -------------------------------------
     $dt_vars = array('start_date', 'end_date', 'start_time', 'end_time');
     $count = 1;
     $total = 0;
     foreach ($data->dates as $date) {
         $total += count($date);
     }
     if (empty($data->dates)) {
         return $this->no_results();
     }
     //--------------------------------------------
     //	reverse sorting
     //--------------------------------------------
     if ($this->parent_method == 'occurrences' and ee()->TMPL->fetch_param('reverse') and strtolower(ee()->TMPL->fetch_param('reverse')) === 'true') {
         krsort($data->dates);
     }
     //--------------------------------------------
     //	orderby sorting
     //--------------------------------------------
     /*if ($this->parent_method == 'occurrences' AND
     			ee()->TMPL->fetch_param('orderby'))
     		{
     			$sort = (ee()->TMPL->fetch_param('sort') AND
     					 strtolower(ee()->TMPL->fetch_param('sort')) === 'DESC') ? 'DESC' : 'ASC';
     
     
     		}*/
     //--------------------------------------------
     //	pagination
     //--------------------------------------------
     if ($this->parent_method === 'occurrences') {
         $this->paginate = FALSE;
     }
     $limit = ee()->TMPL->fetch_param('occurrences_limit') ? ee()->TMPL->fetch_param('occurrences_limit') : $this->limit;
     if ($limit > 0 and $this->parent_method === 'occurrences' and $total > $limit) {
         //get pagination info
         $pagination_data = $this->universal_pagination(array('total_results' => $total, 'tagdata' => $tagdata . $this->paginate_tagpair_data, 'limit' => $limit, 'uri_string' => ee()->uri->uri_string, 'paginate_prefix' => 'calendar_'));
         //if we paginated, sort the data
         if ($pagination_data['paginate'] === TRUE) {
             $this->paginate = $pagination_data['paginate'];
             $this->page_next = $pagination_data['page_next'];
             $this->page_previous = $pagination_data['page_previous'];
             $this->p_page = $pagination_data['pagination_page'];
             $this->current_page = $pagination_data['current_page'];
             $this->pager = $pagination_data['pagination_links'];
             $this->basepath = $pagination_data['base_url'];
             $this->total_pages = $pagination_data['total_pages'];
             $this->paginate_data = $pagination_data['paginate_tagpair_data'];
             $this->page_count = $pagination_data['page_count'];
             //$tagdata				= $pagination_data['tagdata'];
         }
     }
     //--------------------------------------------
     //	event limiter
     //--------------------------------------------
     $offset = ee()->TMPL->fetch_param('occurrences_offset') ? ee()->TMPL->fetch_param('occurrences_offset') : 0;
     $page = ($this->current_page - 1) * $limit;
     if ($this->parent_method === 'occurrences' and $page > 0) {
         $offset += $page;
     }
     //--------------------------------------------
     //	Add final variables and swap out,
     //	then add tagdata to return variable
     //--------------------------------------------
     $offset_counter = 0;
     foreach ($data->dates as $ymd => $times) {
         foreach ($times as $time => $info) {
             //offset and limiting
             if ($this->parent_method === 'occurrences' and ++$offset_counter <= $offset) {
                 continue;
             }
             if ($this->parent_method === 'occurrences' and $offset_counter > $limit + $offset) {
                 break 2;
             }
             //--------------------------------------------
             //	output variables
             //--------------------------------------------
             $tdata = isset($data->occurrences[$ymd][$time]['entry_id']) ? $tagdatas[$data->occurrences[$ymd][$time]['entry_id']] : $tagdatas[$data->default_data['entry_id']];
             if ($info['all_day'] === TRUE or $info['all_day'] == 'y') {
                 $info['date']['time'] = '0000';
                 $info['date']['hour'] = '00';
                 $info['date']['minute'] = '00';
                 $info['end_date']['time'] = '2400';
                 $info['end_date']['hour'] = '24';
                 $info['end_date']['minute'] = '00';
                 $info['duration']['hours'] = '24';
             }
             $vars = array('single' => array('occurrence_duration_minutes' => $info['duration']['minutes'], 'occurrence_duration_hours' => $info['duration']['hours'], 'occurrence_duration_days' => $info['duration']['days'], 'occurrence_id' => isset($data->occurrences[$ymd][$time]['entry_id']) ? $data->occurrences[$ymd][$time]['entry_id'] : $data->default_data['entry_id'], 'occurrence_start_year' => $info['date']['year'], 'occurrence_start_month' => $info['date']['month'], 'occurrence_start_day' => $info['date']['day'], 'occurence_start_hour' => $info['date']['hour'], 'occurrence_start_minute' => $info['date']['minute'], 'occurrence_end_year' => $info['end_date']['year'], 'occurrence_end_month' => $info['end_date']['month'], 'occurrence_end_day' => $info['end_date']['day'], 'occurrence_end_hour' => $info['end_date']['hour'], 'occurrence_end_minute' => $info['end_date']['minute'], 'occurrence_count' => $count, 'occurrence_total' => $total, 'occurrence_author_id' => isset($entry_info['author_id']) ? $entry_info['author_id'] : '', 'occurrence_author' => isset($entry_info['screen_name']) ? $entry_info['screen_name'] : (isset($entry_info['username']) ? $entry_info['username'] : ''), 'occurrence_title' => isset($entry_info['title']) ? $entry_info['title'] : '', 'occurrence_url_title' => isset($entry_info['url_title']) ? $entry_info['url_title'] : '', 'occurrence_status' => isset($entry_info['status']) ? $entry_info['status'] : ''), 'conditional' => array('occurrence_all_day' => $info['all_day'], 'occurrence_multi_day' => $info['multi_day'], 'occurrence_status' => isset($entry_info['status']) ? $entry_info['status'] : '', 'occurrence_author_id' => isset($entry_info['author_id']) ? $entry_info['author_id'] : ''), 'date' => array('occurrence_start_date' => $info['date'], 'occurrence_start_time' => $info['date'], 'occurrence_end_date' => $info['end_date'], 'occurrence_end_time' => $info['end_date']));
             $output .= $this->swap_vars($vars, $tdata);
             $count++;
         }
     }
     //--------------------------------------------
     //	offset too much? buh bye
     //--------------------------------------------
     if (trim($output) === '') {
         return $this->no_results();
     }
     return $output;
 }
 function search()
 {
     $address = '';
     $tagdata = $this->EE->TMPL->tagdata;
     $prec = !$this->EE->TMPL->fetch_param('prec') ? '' : ',' . $this->EE->TMPL->fetch_param('prec');
     $prefix = !$this->EE->TMPL->fetch_param('prefix') ? '' : ',' . $this->EE->TMPL->fetch_param('prefix');
     $orderby = !$this->EE->TMPL->fetch_param('orderby') ? false : ($this->EE->TMPL->fetch_param('orderby') == 'distance' ? false : $this->EE->TMPL->fetch_param('orderby'));
     $sort = !$this->EE->TMPL->fetch_param('sort') ? 'asc' : $this->EE->TMPL->fetch_param('sort');
     $this->EE->TMPL->tagparams['limit'] = !$this->EE->TMPL->fetch_param('limit') ? 99999 : $this->EE->TMPL->fetch_param('limit');
     $address_fields = !$this->EE->TMPL->fetch_param('address_fields') ? false : $this->EE->TMPL->fetch_param('address_fields');
     $debug = !$this->EE->TMPL->fetch_param('debug') ? false : true;
     //@delete
     $reverse_geocoding = !$this->EE->TMPL->fetch_param('reverse_geocoding') ? '' : ',' . $this->EE->TMPL->fetch_param('reverse_geocoding');
     if (isset($_POST) and count($_POST) > 0 or isset($_GET) and count($_GET) > 0) {
         $zipLongitude = $this->EE->security->xss_clean($this->EE->input->get_post('long'));
         $zipLatitude = $this->EE->security->xss_clean($this->EE->input->get_post('lat'));
         $unit = $this->EE->security->xss_clean($this->EE->input->get_post('unit'));
         //@add to site description
         if ($address_fields) {
             foreach (explode('|', $address_fields) as $field_name) {
                 $address = $this->EE->input->get_post($field_name) ? $address . $this->EE->security->xss_clean($this->EE->input->get_post($field_name)) . ', ' : '';
             }
         } else {
             $address = $this->EE->security->xss_clean($this->EE->input->get_post('address'));
             if (is_array($address)) {
                 $address = implode(",", $address);
             }
         }
         $address = $prefix . $address;
         $radius = $this->EE->security->xss_clean($this->EE->input->get_post('radius'));
     } else {
         $zipLongitude = $this->EE->TMPL->fetch_param('long') != '' ? $this->EE->TMPL->fetch_param('long') : "";
         $zipLatitude = $this->EE->TMPL->fetch_param('lat') != '' ? $this->EE->TMPL->fetch_param('lat') : '';
         $unit = $this->EE->TMPL->fetch_param('unit') != '' ? $this->EE->TMPL->fetch_param('unit') : 'ml';
         $address = $this->EE->TMPL->fetch_param('address') != '' ? $this->EE->TMPL->fetch_param('address') : '';
         $radius = $this->EE->TMPL->fetch_param('radius') != '' ? $this->EE->TMPL->fetch_param('radius') : $this->default_radius;
     }
     $radius = $radius == '' ? $this->default_radius : $radius;
     $earth_radius = $unit == 'km' ? 6371 : 3959;
     //earth_radius
     if (($zipLongitude == "" or $zipLatitude == "") and $address == "") {
         $zipLongitude = $this->default_long;
         $zipLatitude = $this->default_lat;
         $address = $this->default_address;
     }
     $entry_id = '';
     $points = array();
     $entry_id = rtrim($entry_id, '|');
     $channel = new Channel();
     $LD = '\\{';
     $RD = '\\}';
     $SLASH = '\\/';
     $variable = "entries";
     $return_data = "";
     if (isset($_POST['categories'])) {
         $this->EE->TMPL->tagparams['category'] = (isset($this->EE->TMPL->tagparams['category']) ? $this->EE->TMPL->tagparams['category'] : '') . '|' . implode("|", $this->EE->security->xss_clean($_POST['categories']));
     }
     if (preg_match("/" . LD . $variable . ".*?" . RD . "(.*?)" . LD . '\\/' . $variable . RD . "/s", $tagdata, $entries)) {
         $channel->EE->TMPL->tagdata = $entries[1];
         if ($channel->EE->TMPL->fetch_param('related_categories_mode') == 'yes') {
             return $channel->related_entries();
         }
         $channel->initialize();
         $channel->uri = $channel->query_string != '' ? $channel->query_string : 'index.php';
         if ($channel->enable['custom_fields'] == TRUE) {
             $channel->fetch_custom_channel_fields();
         }
         if ($channel->enable['member_data'] == TRUE) {
             $channel->fetch_custom_member_fields();
         }
         if ($channel->enable['pagination'] == TRUE) {
             if (version_compare(APP_VER, '2.4', '>=')) {
                 $channel->add_pagination_data();
             } else {
                 $channel->fetch_pagination_data();
             }
         }
         $save_cache = FALSE;
         $channel->EE->TMPL->tagparams['dynamic'] = 'no';
         //$zipLongitude.$zipLatitude.$address
         if ($channel->EE->config->item('enable_sql_caching') == 'y') {
             if (FALSE == ($channel->sql = $channel->fetch_cache())) {
                 $save_cache = TRUE;
             } else {
                 if ($channel->EE->TMPL->fetch_param('dynamic') != 'no') {
                     if (preg_match("#(^|\\/)C(\\d+)#", $channel->query_string, $match) or in_array($channel->reserved_cat_segment, explode("/", $channel->query_string))) {
                         $channel->cat_request = TRUE;
                     }
                 }
             }
             if (FALSE !== ($cache = $channel->fetch_cache('pagination_count'))) {
                 if (FALSE !== $channel->fetch_cache('field_pagination')) {
                     if (FALSE !== ($pg_query = $channel->fetch_cache('pagination_query'))) {
                         $channel->paginate = TRUE;
                         $channel->field_pagination = TRUE;
                         $channel->create_pagination(trim($cache), $channel->EE->db->query(trim($pg_query)));
                     }
                 } else {
                     $channel->create_pagination(trim($cache));
                 }
             }
         }
         if ($channel->sql == '') {
             $channel->build_sql_query();
         }
         if ($channel->sql == '') {
             return $channel->EE->TMPL->no_results();
         }
         $sql = "";
         //@start geocoding
         //if don't have the Latitude and Longitude, do query to google.map; ($zipLongitude == "" OR $zipLatitude == "") AND
         if ($address != "" and ($zipLongitude == "" or $zipLatitude == "")) {
             $GetLatLong_result = $this->GetLatLong($address, 2);
             if ($GetLatLong_result != false) {
                 list($zipLongitude, $zipLatitude) = $GetLatLong_result;
             } else {
                 return $this->EE->TMPL->no_results();
             }
         }
         if ($reverse_geocoding and $address == "") {
             $GetLatLong_result = $this->GetLatLong($zipLatitude . ',' . $zipLongitude, $api_key, 1);
             if ($GetLatLong_result != false) {
                 $address = $GetLatLong_result;
             } else {
                 return $this->EE->TMPL->no_results();
             }
         }
         //@END geocoding
         $conds['radius'] = $radius;
         $tagdata = $this->EE->functions->prep_conditionals($tagdata, $conds);
         $tagdata = str_replace(array('{center:long}', '{center:lat}', '{radius}'), array($zipLongitude, $zipLatitude, $radius), $tagdata);
         $where_strpos = strpos($channel->sql, "WHERE");
         if ($where_strpos > 0) {
             $sql_entry_id = substr($channel->sql, $where_strpos + 5, strpos($channel->sql, "ORDER BY") - $where_strpos - 5);
             $limit_strpos = strpos($channel->sql, "LIMIT");
             $order_by = substr($channel->sql, strpos($channel->sql, "ORDER BY"), $limit_strpos);
             $limit = substr($channel->sql, strpos($channel->sql, "LIMIT"));
             $sql = str_replace('FROM', ", gm.*, ROUND( {$earth_radius} * acos( cos( radians({$zipLatitude}) ) * cos( radians( gm.latitude ) ) * cos( radians( gm.longitude ) - radians({$zipLongitude}) ) + sin( radians({$zipLatitude}) ) *  sin( radians( gm.latitude ) ) ) {$prec} ) AS distance   FROM ", $channel->sql);
             $sql = substr($sql, 0, strpos($sql, "WHERE")) . "RIGHT JOIN exp_mx_google_map AS gm ON t.entry_id = gm.entry_id HAVING distance < {$radius} AND " . $sql_entry_id;
             if ($orderby) {
                 $sql = $sql . $order_by;
             } else {
                 $sql = $sql . " ORDER BY distance " . $sort;
             }
             $channel->sql = $sql;
         }
         if ($save_cache == TRUE) {
             $channel->save_cache($channel->sql);
         }
         $channel->query = $channel->EE->db->query($channel->sql);
         if ($channel->query->num_rows() == 0) {
             return $channel->EE->TMPL->no_results();
         }
         foreach ($channel->query->result_array() as $row) {
             $points[$row['point_id']] = $row['distance'];
         }
         $channel->EE->TMPL->tagparams['points'] = $points;
         if ($channel->EE->config->item('relaxed_track_views') === 'y' && $channel->query->num_rows() == 1) {
             $channel->hit_tracking_id = $channel->query->row('entry_id');
         }
         $channel->track_views();
         $channel->EE->load->library('typography');
         $channel->EE->typography->initialize();
         $channel->EE->typography->convert_curly = FALSE;
         if ($channel->enable['categories'] == TRUE) {
             $channel->fetch_categories();
         }
         $channel->parse_channel_entries();
         if ($channel->enable['pagination'] == TRUE) {
             if (version_compare(APP_VER, '2.4', '>=')) {
                 $channel->add_pagination_data();
             } else {
                 $channel->fetch_pagination_data();
             }
         }
         if (count($channel->EE->TMPL->related_data) > 0 && count($channel->related_entries) > 0) {
             $channel->parse_related_entries();
         }
         if (count($channel->EE->TMPL->reverse_related_data) > 0 && count($channel->reverse_related_entries) > 0) {
             $channel->parse_reverse_related_entries();
         }
         $return_data = str_replace($entries[0], $channel->return_data, $tagdata);
     }
     return $return_data;
 }
 /**
  *	List of Entires for an Author, Sub-Processing for entries() method
  *
  *	@access		private
  *	@param		array
  *	@return		string
  */
 private function _entries($params = array())
 {
     /**	----------------------------------------
     		/**	Execute?
     		/**	----------------------------------------*/
     if ($this->entry_id == '') {
         return FALSE;
     }
     /**	----------------------------------------
     		/**	Invoke Channel/Weblog class
     		/**	----------------------------------------*/
     if (APP_VER < 2.0) {
         if (!class_exists('Weblog')) {
             require PATH_MOD . 'weblog/mod.weblog' . EXT;
         }
         $channel = new Weblog();
     } else {
         if (!class_exists('Channel')) {
             require PATH_MOD . 'channel/mod.channel.php';
         }
         $channel = new Channel();
     }
     // --------------------------------------------
     //  Invoke Pagination for EE 2.4 and Above
     // --------------------------------------------
     if (APP_VER >= '2.4.0') {
         ee()->load->library('pagination');
         $channel->pagination = new Pagination_object('Channel');
         // Used by pagination to determine whether we're coming from the cache
         $channel->pagination->dynamic_sql = FALSE;
     }
     /**	----------------------------------------
     		/**	Pass params
     		/**	----------------------------------------*/
     ee()->TMPL->tagparams['entry_id'] = $this->entry_id;
     ee()->TMPL->tagparams['inclusive'] = '';
     if (isset($params['dynamic']) and $params['dynamic'] == "off") {
         if (APP_VER < 2.0) {
             ee()->TMPL->tagparams['dynamic'] = 'off';
         } else {
             ee()->TMPL->tagparams['dynamic'] = 'no';
         }
     }
     /**	----------------------------------------
     		/**	Pre-process related data
     		/**	----------------------------------------*/
     ee()->TMPL->tagdata = ee()->TMPL->assign_relationship_data(ee()->TMPL->tagdata);
     ee()->TMPL->var_single = array_merge(ee()->TMPL->var_single, ee()->TMPL->related_markers);
     /**	----------------------------------------
     		/**	Execute needed methods
     		/**	----------------------------------------*/
     if (APP_VER < 2.0) {
         $channel->fetch_custom_weblog_fields();
     } else {
         $channel->fetch_custom_channel_fields();
     }
     $channel->fetch_custom_member_fields();
     // --------------------------------------------
     //  Pagination Tags Parsed Out
     // --------------------------------------------
     if (APP_VER >= '2.4.0') {
         $channel->pagination->get_template();
     } else {
         $channel->fetch_pagination_data();
     }
     if (APP_VER >= '2.4.0') {
         $channel->pagination->cfields = $channel->cfields;
         $channel->pagination->build();
     } else {
         $channel->create_pagination();
     }
     /**	----------------------------------------
     		/**	Grab entry data
     		/**	----------------------------------------*/
     //$channel->create_pagination();
     $channel->build_sql_query();
     if ($channel->sql == '') {
         return $this->no_results();
     }
     $channel->query = ee()->db->query($channel->sql);
     if (APP_VER < 2.0) {
         $channel->query->result = $channel->query->result_array();
     }
     if (!isset($channel->query) or $channel->query->num_rows() == 0) {
         return $this->no_results();
     }
     if (APP_VER < 2.0) {
         if (!class_exists('Typography')) {
             require PATH_CORE . 'core.typography' . EXT;
         }
         $channel->TYPE = new Typography();
         $channel->TYPE->convert_curly = FALSE;
     } else {
         ee()->load->library('typography');
         ee()->typography->initialize();
         ee()->typography->convert_curly = FALSE;
     }
     $channel->fetch_categories();
     /**	----------------------------------------
     		/**	Parse and return entry data
     		/**	----------------------------------------*/
     if (APP_VER < 2.0) {
         $channel->parse_weblog_entries();
     } else {
         $channel->parse_channel_entries();
     }
     if (APP_VER >= '2.4.0') {
         $channel->return_data = $channel->pagination->render($channel->return_data);
     } else {
         $channel->add_pagination_data();
     }
     /**	----------------------------------------
     		/**	Count tag
     		/**	----------------------------------------*/
     if (count(ee()->TMPL->related_data) > 0 and count($channel->related_entries) > 0) {
         $channel->parse_related_entries();
     }
     if (count(ee()->TMPL->reverse_related_data) > 0 and count($channel->reverse_related_entries) > 0) {
         $channel->parse_reverse_related_entries();
     }
     // ----------------------------------------
     //  Handle problem with pagination segments in the url
     // ----------------------------------------
     if (preg_match("#(/P\\d+)#", ee()->uri->uri_string, $match)) {
         $channel->return_data = str_replace($match['1'], "", $channel->return_data);
     } elseif (preg_match("#(P\\d+)#", ee()->uri->uri_string, $match)) {
         $channel->return_data = str_replace($match['1'], "", $channel->return_data);
     }
     $tagdata = $channel->return_data;
     return $tagdata;
 }