Example #1
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 #2
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 #3
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 #4
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 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);
 }