public function __construct(EE_Channel_preparser $pre, EE_Channel_parser $parser) { $this->_preparser = $pre; $this->_parser = $parser; $this->_prefix = $pre->prefix(); $this->_channel = $pre->channel(); }
/** * Find all date variables in the template. The return value * will be passed to process for the main parsing loop. * * @param String The tagdata to be parsed * @param Object The preparser object. * @return Array Found date tags. */ public function pre_process($tagdata, EE_Channel_preparser $pre) { $prefix = $pre->prefix(); $entry_date = array(); $gmt_date = array(); $gmt_entry_date = array(); $edit_date = array(); $gmt_edit_date = array(); $expiration_date = array(); $week_date = array(); $date_vars = array('entry_date', 'gmt_date', 'gmt_entry_date', 'edit_date', 'gmt_edit_date', 'expiration_date', 'recent_comment_date', 'week_date'); ee()->load->helper('date'); foreach ($date_vars as $val) { if (!$pre->has_tag($val)) { continue; } $full_val = $prefix . $val; if (preg_match_all("/" . LD . $full_val . "\\s+format=([\"'])([^\\1]*?)\\1" . RD . "/s", $tagdata, $matches)) { for ($j = 0; $j < count($matches[0]); $j++) { $matches[0][$j] = str_replace(array(LD, RD), '', $matches[0][$j]); switch ($val) { case 'entry_date': $entry_date[$matches[0][$j]] = $matches[2][$j]; break; case 'gmt_date': $gmt_date[$matches[0][$j]] = $matches[2][$j]; break; case 'gmt_entry_date': $gmt_entry_date[$matches[0][$j]] = $matches[2][$j]; break; case 'edit_date': $edit_date[$matches[0][$j]] = $matches[2][$j]; break; case 'gmt_edit_date': $gmt_edit_date[$matches[0][$j]] = $matches[2][$j]; break; case 'expiration_date': $expiration_date[$matches[0][$j]] = $matches[2][$j]; break; case 'recent_comment_date': $recent_comment_date[$matches[0][$j]] = $matches[2][$j]; break; case 'week_date': $week_date[$matches[0][$j]] = $matches[2][$j]; break; } } } } return call_user_func_array('compact', $date_vars); }
/** * Find any {field} {/field} tag pair chunks in the template and * extract them for easier parsing in the main loop. * * The returned chunks will be passed to replace() as a third parameter. * * @param String The tagdata to be parsed * @param Object The preparser object. * @return Array The found custom field pair chunks */ public function pre_process($tagdata, EE_Channel_preparser $pre) { $pfield_chunk = array(); $prefix = $pre->prefix(); $channel = $pre->channel(); foreach ($channel->pfields as $site_id => $pfields) { $pfield_names = array_intersect($channel->cfields[$site_id], array_keys($pfields)); $pfield_chunk[$site_id] = array(); foreach ($pfield_names as $field_name => $field_id) { if (!$pre->has_tag_pair($field_name)) { continue; } $pfield_chunk[$site_id][$field_name] = ee()->api_channel_fields->get_pair_field($tagdata, $field_name, $prefix); } } return $pfield_chunk; }
/** * Find all custom date variables in the template. The return value * will be passed to process for the main parsing loop. * * @param String The tagdata to be parsed * @param Object The preparser object. * @return Array Found custom date tags. */ public function pre_process($tagdata, EE_Channel_preparser $pre) { $prefix = $pre->prefix(); $channel = $pre->channel(); $custom_date_fields = array(); if (count($channel->dfields) == 0) { return $custom_date_fields; } foreach ($channel->dfields as $site_id => $dfields) { foreach ($dfields as $key => $value) { if (!$pre->has_tag($key)) { continue; } $key = $prefix . $key; if (preg_match_all("/" . LD . $key . "\\s+format=[\"'](.*?)[\"']" . RD . "/s", $tagdata, $matches)) { for ($j = 0; $j < count($matches[0]); $j++) { $matches[0][$j] = str_replace(array(LD, RD), '', $matches[0][$j]); $custom_date_fields[$matches[0][$j]] = $matches[1][$j]; } } } } return $custom_date_fields; }
/** * Parse out $search_link for the {member_search_path} variable * * @param String The tagdata to be parsed * @param Object The preparser object. * @return String The $search_link path */ public function pre_process($tagdata, EE_Channel_preparser $pre) { $result_path = preg_match("/" . LD . $pre->prefix() . "member_search_path\\s*=(.*?)" . RD . "/s", $tagdata, $match) ? $match[1] : 'search/results'; $result_path = str_replace(array('"', "'"), "", $result_path); return ee()->functions->fetch_site_index(0, 0) . QUERY_MARKER . 'ACT=' . ee()->functions->fetch_action_id('Search', 'do_search') . '&result_path=' . $result_path . '&mbr='; }
/** * Before the parser runs, this will gather all category tag pairs that * need processing. * * The returned chunks will be passed to replace() as a third parameter. * * @param String The tagdata to be parsed * @param Object The preparser object. * @return Array The found category chunks */ public function pre_process($tagdata, EE_Channel_preparser $pre) { return $this->_get_cat_chunks($tagdata, $pre->prefix()); }