Example #1
0
 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();
 }
Example #2
0
 /**
  * Gather the data needed to process all Grid field
  *
  * The returned object will be passed to replace() as a third parameter.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The preparser object.
  * @return Object	EE_Grid_field_parser object
  */
 public function pre_process($tagdata, EE_Channel_preparser $pre)
 {
     $grid_field_names = array();
     // Run the preprocessor for each site
     foreach ($pre->site_ids() as $site_id) {
         $gfields = $pre->channel()->gfields;
         // Skip a site if it has no Grid fields
         if (!isset($gfields[$site_id]) or empty($gfields[$site_id])) {
             continue;
         }
         $grid_field_names = array_merge($grid_field_names, array_values(array_flip($gfields[$site_id])));
         ee()->load->library('grid_parser');
         ee()->grid_parser->pre_process($tagdata, $pre, $gfields[$site_id]);
     }
     $grid_field_names = $pre->prefix() . implode('|' . $pre->prefix(), $grid_field_names);
     // Match all conditionals with these Grid field names so we can
     // make {if grid_field} work
     preg_match_all("/" . preg_quote(LD) . "((if:(else))*if)\\s+({$grid_field_names})(?!:)(\\s+|" . preg_quote(RD) . ")/s", $tagdata, $matches);
     // For each field found in a conditional, add it to the modified
     // conditionals array to make the conditional evaluate with the
     // :total_rows modifier, otherwise it will evaluate based on what's
     // in channel_data, and only data from searchable fields is there
     if (isset($matches[4]) && !empty($matches[4])) {
         foreach ($matches[4] as $value) {
             $pre->modified_conditionals[$value][] = 'total_rows';
         }
     }
     return NULL;
 }
Example #3
0
 /**
  * Set up the relationship parser's tree and data pre-caching.
  *
  * The returned object will be passed to replace() as a third parameter.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The preparser object.
  * @return Array	The relationship parser object
  */
 public function pre_process($tagdata, EE_Channel_preparser $pre)
 {
     if (empty($pre->channel()->rfields)) {
         return NULL;
     }
     ee()->load->library('relationships_parser');
     try {
         return ee()->relationships_parser->create($pre->channel()->rfields, $pre->entry_ids());
     } catch (EE_Relationship_exception $e) {
         ee()->TMPL->log_item($e->getMessage());
     }
     return NULL;
 }
Example #4
0
 /**
  * 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);
 }
Example #5
0
 /**
  * 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;
 }
 /**
  * Set up the relationship parser's tree and data pre-caching.
  *
  * The returned object will be passed to replace() as a third parameter.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The preparser object.
  * @return Array	The relationship parser object
  */
 public function pre_process($tagdata, EE_Channel_preparser $pre)
 {
     $rfields = $pre->channel()->rfields;
     $process_fields = array();
     foreach ($pre->site_ids() as $site_id) {
         if (!isset($rfields[$site_id]) or empty($rfields[$site_id])) {
             continue;
         }
         $process_fields[$site_id] = $rfields[$site_id];
     }
     if (empty($process_fields)) {
         return NULL;
     }
     ee()->load->library('relationships_parser');
     try {
         return ee()->relationships_parser->create($process_fields, $pre->entry_ids());
     } catch (EE_Relationship_exception $e) {
         ee()->TMPL->log_item($e->getMessage());
     }
     return NULL;
 }
 /**
  * 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;
 }
 /**
  * Check if header/footer is enabled.
  *
  * @param array		A list of "disabled" features
  * @return Boolean	Is disabled?
  */
 public function disabled(array $disabled, EE_Channel_preparser $pre)
 {
     return !($pre->has_tag_pair('date_heading') or $pre->has_tag_pair('date_footer'));
 }
 /**
  * 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') . '&amp;result_path=' . $result_path . '&amp;mbr=';
 }
Example #10
0
 /**
  * Quick check if they're using switch
  *
  * @param array		A list of "disabled" features
  * @return Boolean	Is disabled?
  */
 public function disabled(array $disabled, EE_Channel_preparser $pre)
 {
     return !$pre->has_tag('switch');
 }
Example #11
0
 /**
  * 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());
 }
 /**
  * Check if member fields are enabled.
  *
  * @param array		A list of "disabled" features
  * @return Boolean	Is disabled?
  */
 public function disabled(array $disabled, EE_Channel_preparser $pre)
 {
     return in_array('member_data', $disabled) or empty($pre->channel()->mfields);
 }