Beispiel #1
0
 /**
  * Replace all of the default date fields.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $date_vars)
 {
     $prefix = $obj->prefix();
     $tag = $obj->tag();
     $data = $obj->row();
     $dates = array($prefix . 'entry_date' => $data['entry_date'], $prefix . 'edit_date' => $data['edit_date'], $prefix . 'recent_comment_date' => $data['recent_comment_date'] != 0 ? $data['recent_comment_date'] : '', $prefix . 'expiration_date' => $data['expiration_date'] != 0 ? $data['expiration_date'] : '', $prefix . 'comment_expiration_date' => $data['comment_expiration_date'] != 0 ? $data['comment_expiration_date'] : '');
     // "week_date"
     // Subtract the number of days the entry is "into" the week to get zero (Sunday)
     // If the entry date is for Sunday, and Monday is being used as the week's start day,
     // then we must back things up by six days
     $offset = 0;
     if (strtolower(ee()->TMPL->fetch_param('start_day')) == 'monday') {
         $day_of_week = ee()->localize->format_date('%w', $data['entry_date']);
         if ($day_of_week == '0') {
             $offset = -518400;
             // back six days
         } else {
             $offset = 86400;
             // plus one day
         }
     }
     $dates['week_date'] = $data['entry_date'] - ee()->localize->format_date('%w', $data['entry_date'], TRUE) * 60 * 60 * 24 + $offset;
     $tagdata = ee()->TMPL->parse_date_variables($tagdata, $dates);
     $dates = array($prefix . 'gmt_date' => $data['entry_date'], $prefix . 'gmt_entry_date' => $data['entry_date'], $prefix . 'gmt_edit_date' => $data['edit_date']);
     $tagdata = ee()->TMPL->parse_date_variables($tagdata, $dates, FALSE);
     return $tagdata;
 }
 /**
  * Replace all of the relationship fields in one fell swoop.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $relationship_parser)
 {
     if (!isset($relationship_parser)) {
         return $tagdata;
     }
     $row = $obj->row();
     $channel = $obj->channel();
     try {
         return $relationship_parser->parse($row['entry_id'], $tagdata, $channel);
     } catch (EE_Relationship_exception $e) {
         return $tagdata;
     }
 }
 /**
  * Replace all of the custom date fields.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $custom_date_fields)
 {
     if (!count($custom_date_fields)) {
         return $tagdata;
     }
     $tag = $obj->tag();
     $data = $obj->row();
     $prefix = $obj->prefix();
     $dfields = $obj->channel()->dfields;
     if (isset($custom_date_fields[$tag]) && isset($dfields[$data['site_id']])) {
         foreach ($dfields[$data['site_id']] as $dtag => $dval) {
             if (strncmp($tag . ' ', $prefix . $dtag . ' ', strlen($prefix . $dtag . ' ')) !== 0) {
                 continue;
             }
             if ($data['field_id_' . $dval] == 0 or $data['field_id_' . $dval] == '') {
                 $tagdata = str_replace(LD . $tag . RD, '', $tagdata);
                 continue;
             }
             // If date is fixed, get timezone to convert timestamp to,
             // otherwise localize it normally
             $localize = TRUE;
             if (isset($data['field_dt_' . $dval]) and $data['field_dt_' . $dval] != '') {
                 $localize = $data['field_dt_' . $dval];
             }
             $tagdata = str_replace(LD . $tag . RD, ee()->localize->format_date($custom_date_fields[$tag], $data['field_id_' . $dval], $localize), $tagdata);
         }
     }
     return $tagdata;
 }
 /**
  * Replace all variables.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $search_link)
 {
     $tag = $obj->tag();
     $tag_options = $obj->tag_options();
     $data = $obj->row();
     $prefix = $obj->prefix();
     // I decided to split the huge if statement into educated guesses
     // so we spend less time doing silly comparisons
     if (strpos($tag, '_path') !== FALSE or strpos($tag, 'permalink') !== FALSE) {
         return $this->_paths($data, $tagdata, $tag, $tag_options, $prefix);
     }
     if (strpos($tag, 'url') !== FALSE) {
         return $this->_urls($data, $tagdata, $tag, $tag_options, $prefix);
     }
     // @todo remove
     $key = $tag;
     $val = $tag_options;
     //  parse {title}
     if ($key == $prefix . 'title') {
         $data['title'] = str_replace(array('{', '}'), array('{', '}'), $data['title']);
         $tagdata = str_replace(LD . $key . RD, ee()->typography->format_characters($data['title']), $tagdata);
     } elseif ($key == $prefix . "author") {
         $tagdata = str_replace(LD . $val . RD, $data['screen_name'] != '' ? $data['screen_name'] : $data['username'], $tagdata);
     } elseif ($key == $prefix . "channel") {
         $tagdata = str_replace(LD . $val . RD, $data['channel_title'], $tagdata);
     } elseif ($key == $prefix . "channel_short_name") {
         $tagdata = str_replace(LD . $val . RD, $data['channel_name'], $tagdata);
     } elseif ($key == $prefix . "relative_date") {
         $tagdata = str_replace(LD . $val . RD, timespan($data['entry_date']), $tagdata);
     } elseif ($key == $prefix . "signature") {
         if (ee()->session->userdata('display_signatures') == 'n' or $data['signature'] == '') {
             $tagdata = str_replace(LD . $key . RD, '', $tagdata);
         } else {
             $tagdata = str_replace(LD . $key . RD, ee()->typography->parse_type($data['signature'], array('text_format' => 'xhtml', 'html_format' => 'safe', 'auto_links' => 'y', 'allow_img_url' => ee()->config->item('sig_allow_img_hotlink'))), $tagdata);
         }
     } else {
         return $this->_basic($data, $tagdata, $tag, $tag_options, $prefix);
     }
     return $tagdata;
 }
 /**
  * Replace all of the simple conditionals
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $pre)
 {
     $tag = $obj->tag();
     $tag_options = $obj->tag_options();
     $data = $obj->row();
     $prefix = $obj->prefix();
     // @todo
     $key = $tag;
     $val = $tag_options;
     $cfields = $obj->channel()->cfields;
     if (strpos($key, '|') !== FALSE && is_array($val)) {
         foreach ($val as $item) {
             // Basic fields
             if (isset($data[$item]) and $data[$item] != "") {
                 $tagdata = str_replace(LD . $prefix . $key . RD, $data[$item], $tagdata);
                 continue;
             }
             // Custom channel fields
             if (isset($this->cfields[$data['site_id']][$item]) and isset($data['field_id_' . $cfields[$data['site_id']][$item]]) and $data['field_id_' . $cfields[$data['site_id']][$item]] != "") {
                 $entry = ee()->typography->parse_type($data['field_id_' . $cfields[$data['site_id']][$item]], array('text_format' => $data['field_ft_' . $cfields[$data['site_id']][$item]], 'html_format' => $data['channel_html_formatting'], 'auto_links' => $data['channel_auto_link_urls'], 'allow_img_url' => $data['channel_allow_img_urls']));
                 $tagdata = str_replace(LD . $prefix . $key . RD, $entry, $tagdata);
                 continue;
             }
         }
         // Garbage collection
         $val = '';
         $tagdata = str_replace(LD . $prefix . $key . RD, "", $tagdata);
     }
     return $tagdata;
 }
 /**
  * Replace all of the custom channel fields.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $ft_api)
 {
     $tag = $obj->tag();
     $data = $obj->row();
     $prefix = $obj->prefix();
     $site_id = $data['site_id'];
     $cfields = $obj->channel()->cfields;
     $rfields = $obj->channel()->rfields;
     $rfields = isset($rfields[$site_id]) ? $rfields[$site_id] : array();
     $cfields = isset($cfields[$site_id]) ? $cfields[$site_id] : array();
     $cfields = array_diff_key($cfields, $rfields);
     if (empty($cfields)) {
         return $tagdata;
     }
     $field = ee()->api_channel_fields->get_single_field($tag, $prefix);
     if (isset($cfields[$field['field_name']])) {
         $entry = '';
         $field_id = $cfields[$field['field_name']];
         if (isset($data['field_id_' . $field_id]) && $data['field_id_' . $field_id] !== '') {
             $modifier = $field['modifier'];
             $parse_fnc = $modifier ? 'replace_' . $modifier : 'replace_tag';
             $obj = $ft_api->setup_handler($field_id, TRUE);
             if ($obj) {
                 $_ft_path = $ft_api->ft_paths[$ft_api->field_type];
                 ee()->load->add_package_path($_ft_path, FALSE);
                 $obj->_init(array('row' => $data, 'content_id' => $data['entry_id'], 'content_type' => 'channel'));
                 $data = $ft_api->apply('pre_process', array($data['field_id_' . $field_id]));
                 if (method_exists($obj, $parse_fnc)) {
                     $entry = $ft_api->apply($parse_fnc, array($data, $field['params'], FALSE));
                 } elseif (method_exists($obj, 'replace_tag_catchall')) {
                     $entry = $ft_api->apply('replace_tag_catchall', array($data, $field['params'], FALSE, $modifier));
                 }
                 ee()->load->remove_package_path($_ft_path);
             } else {
                 // Couldn't find a fieldtype
                 $entry = ee()->typography->parse_type(ee()->functions->encode_ee_tags($data['field_id_' . $field_id]), array('text_format' => $data['field_ft_' . $field_id], 'html_format' => $data['channel_html_formatting'], 'auto_links' => $data['channel_auto_link_urls'], 'allow_img_url' => $data['channel_allow_img_urls']));
             }
             // prevent accidental parsing of other channel variables in custom field data
             if (strpos($entry, '{') !== FALSE) {
                 $entry = str_replace(array('{', '}'), array(unique_marker('channel_bracket_open'), unique_marker('channel_bracket_close')), $entry);
             }
             $tagdata = str_replace(LD . $tag . RD, $entry, $tagdata);
         }
         $tagdata = str_replace(LD . $tag . RD, '', $tagdata);
     }
     return $tagdata;
 }
 /**
  * Replace all of the custom member data fields.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $pre)
 {
     $mfields = $obj->channel()->mfields;
     $key = $obj->tag();
     $val = $obj->tag_options();
     $data = $obj->row();
     $prefix = $obj->prefix();
     $key = preg_replace('/^' . $prefix . '/', '', $key);
     //  parse custom member fields
     if (isset($mfields[$key]) && array_key_exists('m_field_id_' . $mfields[$key][0], $data)) {
         if (!isset($this->processed_member_fields[$data['member_id']]['m_field_id_' . $mfields[$key][0]])) {
             $this->processed_member_fields[$data['member_id']]['m_field_id_' . $mfields[$key][0]] = ee()->typography->parse_type($data['m_field_id_' . $mfields[$key][0]], array('text_format' => $mfields[$key][1], 'html_format' => 'safe', 'auto_links' => 'y', 'allow_img_url' => 'n'));
         }
         $tagdata = str_replace(LD . $val . RD, $this->processed_member_fields[$data['member_id']]['m_field_id_' . $mfields[$key][0]], $tagdata);
     }
     return $tagdata;
 }
 /**
  * Replace all of the header/footer chunks.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $flag_obj)
 {
     $tag = $obj->tag();
     $tag_options = $obj->tag_options();
     $data = $obj->row();
     $prefix = $obj->prefix();
     // @todo
     $val = $tag_options;
     //  parse date heading
     if (strncmp($tag, 'date_heading', 12) == 0) {
         // Set the display preference
         $display = (is_array($val) and isset($val['display'])) ? $val['display'] : 'daily';
         //  Hourly header
         if ($display == 'hourly') {
             $flag_obj->heading_date_hourly = ee()->localize->format_date('%Y%m%d%H', $data['entry_date']);
             if ($flag_obj->heading_date_hourly == $flag_obj->heading_flag_hourly) {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_heading', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_heading', $tagdata);
                 $flag_obj->heading_flag_hourly = $flag_obj->heading_date_hourly;
             }
         } elseif ($display == 'weekly') {
             $temp_date = $data['entry_date'];
             // date()'s week variable 'W' starts weeks on Monday per ISO-8601.
             // By default we start weeks on Sunday, so we need to do a little dance for
             // entries made on Sundays to make sure they get placed in the right week heading
             if (strtolower(ee()->TMPL->fetch_param('start_day')) != 'monday' && ee()->localize->format_date('%w', $data['entry_date']) == 0) {
                 // add 7 days to toss us into the next ISO-8601 week
                 $temp_date = strtotime('+1 week', $temp_date);
             }
             $flag_obj->heading_date_weekly = ee()->localize->format_date('%Y%W', $temp_date);
             if ($flag_obj->heading_date_weekly == $flag_obj->heading_flag_weekly) {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_heading', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_heading', $tagdata);
                 $flag_obj->heading_flag_weekly = $flag_obj->heading_date_weekly;
             }
         } elseif ($display == 'monthly') {
             $flag_obj->heading_date_monthly = ee()->localize->format_date('%Y%m', $data['entry_date']);
             if ($flag_obj->heading_date_monthly == $flag_obj->heading_flag_monthly) {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_heading', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_heading', $tagdata);
                 $flag_obj->heading_flag_monthly = $flag_obj->heading_date_monthly;
             }
         } elseif ($display == 'yearly') {
             $flag_obj->heading_date_yearly = ee()->localize->format_date('%Y', $data['entry_date']);
             if ($flag_obj->heading_date_yearly == $flag_obj->heading_flag_yearly) {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_heading', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_heading', $tagdata);
                 $flag_obj->heading_flag_yearly = $flag_obj->heading_date_yearly;
             }
         } else {
             $flag_obj->heading_date_daily = ee()->localize->format_date('%Y%m%d', $data['entry_date']);
             if ($flag_obj->heading_date_daily == $flag_obj->heading_flag_daily) {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_heading', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_heading', $tagdata);
                 $flag_obj->heading_flag_daily = $flag_obj->heading_date_daily;
             }
         }
     }
     // END DATE HEADING
     //  parse date footer
     if (strncmp($tag, 'date_footer', 11) == 0) {
         // Set the display preference
         $display = (is_array($val) and isset($val['display'])) ? $val['display'] : 'daily';
         $query_result = array_values($obj->data('entries', array()));
         //  Hourly footer
         if ($display == 'hourly') {
             if (!isset($query_result[$data['count']]) or ee()->localize->format_date('%Y%m%d%H', $data['entry_date']) != ee()->localize->format_date('%Y%m%d%H', $query_result[$data['count']]['entry_date'])) {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_footer', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_footer', $tagdata);
             }
         } elseif ($display == 'weekly') {
             $temp_date = $data['entry_date'];
             $temp_date_compare = isset($query_result[$data['count']]['entry_date']) ? $query_result[$data['count']]['entry_date'] : '';
             // We adjust for date()'s week variable 'W' Monday start
             if (strtolower(ee()->TMPL->fetch_param('start_day')) != 'monday') {
                 if (ee()->localize->format_date('%w', $temp_date) == 0) {
                     // add 7 days to toss us into the next ISO-8601 week
                     $temp_date = strtotime('+1 week', $temp_date);
                 }
                 if (ee()->localize->format_date('%w', $temp_date_compare) == 0) {
                     // add 7 days to toss us into the next ISO-8601 week
                     $temp_date_compare = strtotime('+1 week', $temp_date_compare);
                 }
             }
             if (!isset($query_result[$data['count']]) or ee()->localize->format_date('%Y%W', $temp_date) != ee()->localize->format_date('%Y%W', $temp_date_compare)) {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_footer', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_footer', $tagdata);
             }
         } elseif ($display == 'monthly') {
             if (!isset($query_result[$data['count']]) or ee()->localize->format_date('%Y%m', $data['entry_date']) != ee()->localize->format_date('%Y%m', $query_result[$data['count']]['entry_date'])) {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_footer', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_footer', $tagdata);
             }
         } elseif ($display == 'yearly') {
             if (!isset($query_result[$data['count']]) or ee()->localize->format_date('%Y', $data['entry_date']) != ee()->localize->format_date('%Y', $query_result[$data['count']]['entry_date'])) {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_footer', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_footer', $tagdata);
             }
         } else {
             if (!isset($query_result[$data['count']]) or ee()->localize->format_date('%Y%m%d', $data['entry_date']) != ee()->localize->format_date('%Y%m%d', $query_result[$data['count']]['entry_date'])) {
                 $tagdata = ee()->TMPL->swap_var_pairs($tag, 'date_footer', $tagdata);
             } else {
                 $tagdata = ee()->TMPL->delete_var_pairs($tag, 'date_footer', $tagdata);
             }
         }
     }
     // END DATE FOOTER
     return $tagdata;
 }
Beispiel #9
0
 /**
  * Replace the switch tag based on what step of the loop we're in.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $pre)
 {
     return ee()->TMPL->parse_switch($tagdata, $obj->count(), $obj->prefix());
 }
Beispiel #10
0
 /**
  * Replace all of the category pairs with the correct data.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $cat_chunk)
 {
     $data = $obj->row();
     $prefix = $obj->prefix();
     $categories = $obj->data('categories', array());
     $tagname = $prefix . 'categories';
     // Check to see if the category chunks still exist; if not, check
     // the tagdata in case they've been modified since pre-processing
     foreach ($cat_chunk as $chunk) {
         if (strpos($tagdata, $chunk[2]) === FALSE) {
             $cat_chunk = $this->_get_cat_chunks($tagdata, $prefix);
             $obj->preparsed()->set_once_data($this, $cat_chunk);
             break;
         }
     }
     if (isset($categories[$data['entry_id']]) and is_array($categories[$data['entry_id']]) and count($cat_chunk) > 0) {
         // Get category ID from URL for {if active} conditional
         ee()->load->helper('segment');
         $active_cat = $obj->channel()->pagination->dynamic_sql && $obj->channel()->cat_request ? parse_category($obj->channel()->query_string) : FALSE;
         foreach ($cat_chunk as $catkey => $catval) {
             $cats = '';
             $i = 0;
             $not_these = array();
             $these = array();
             $not_these_groups = array();
             $these_groups = array();
             if (isset($catval[1]['show'])) {
                 if (strncmp($catval[1]['show'], 'not ', 4) == 0) {
                     $not_these = explode('|', trim(substr($catval[1]['show'], 3)));
                 } else {
                     $these = explode('|', trim($catval[1]['show']));
                 }
             }
             if (isset($catval[1]['show_group'])) {
                 if (strncmp($catval[1]['show_group'], 'not ', 4) == 0) {
                     $not_these_groups = explode('|', trim(substr($catval[1]['show_group'], 3)));
                 } else {
                     $these_groups = explode('|', trim($catval[1]['show_group']));
                 }
             }
             foreach ($categories[$data['entry_id']] as $k => $v) {
                 if (in_array($v[0], $not_these) or isset($v[5]) && in_array($v[5], $not_these_groups)) {
                     continue;
                 } elseif (count($these) > 0 && !in_array($v[0], $these) or count($these_groups) > 0 && isset($v[5]) && !in_array($v[5], $these_groups)) {
                     continue;
                 }
                 $temp = $catval[0];
                 if (preg_match_all("#" . LD . "path=(.+?)" . RD . "#", $temp, $matches)) {
                     foreach ($matches[1] as $match) {
                         if ($obj->channel()->use_category_names == TRUE) {
                             $temp = preg_replace("#" . LD . "path=.+?" . RD . "#", reduce_double_slashes(ee()->functions->create_url($match) . '/' . $obj->channel()->reserved_cat_segment . '/' . $v[6]), $temp, 1);
                         } else {
                             $temp = preg_replace("#" . LD . "path=.+?" . RD . "#", reduce_double_slashes(ee()->functions->create_url($match) . '/C' . $v[0]), $temp, 1);
                         }
                     }
                 } else {
                     $temp = preg_replace("#" . LD . "path=.+?" . RD . "#", ee()->functions->create_url("SITE_INDEX"), $temp);
                 }
                 ee()->load->library('file_field');
                 $cat_image = ee()->file_field->parse_field($v[3]);
                 $cat_vars = array('category_name' => $v[2], 'category_url_title' => $v[6], 'category_description' => isset($v[4]) ? $v[4] : '', 'category_group' => isset($v[5]) ? $v[5] : '', 'category_image' => $cat_image['url'], 'category_id' => $v[0], 'parent_id' => $v[1], 'active' => $active_cat == $v[0] || $active_cat == $v[6]);
                 // add custom fields for conditionals prep
                 foreach ($obj->channel()->catfields as $cv) {
                     $cat_vars[$cv['field_name']] = !isset($v['field_id_' . $cv['field_id']]) ? '' : $v['field_id_' . $cv['field_id']];
                 }
                 $temp = ee()->functions->prep_conditionals($temp, $cat_vars);
                 $temp = str_replace(array(LD . "category_id" . RD, LD . "category_name" . RD, LD . "category_url_title" . RD, LD . "category_image" . RD, LD . "category_group" . RD, LD . 'category_description' . RD, LD . 'parent_id' . RD), array($v[0], ee()->functions->encode_ee_tags($v[2]), $v[6], $cat_image['url'], isset($v[5]) ? $v[5] : '', isset($v[4]) ? ee()->functions->encode_ee_tags($v[4]) : '', $v[1]), $temp);
                 foreach ($obj->channel()->catfields as $cv2) {
                     if (isset($v['field_id_' . $cv2['field_id']]) and $v['field_id_' . $cv2['field_id']] != '') {
                         $field_content = ee()->typography->parse_type($v['field_id_' . $cv2['field_id']], array('text_format' => $v['field_ft_' . $cv2['field_id']], 'html_format' => $v['field_html_formatting'], 'auto_links' => 'n', 'allow_img_url' => 'y'));
                         $temp = str_replace(LD . $cv2['field_name'] . RD, $field_content, $temp);
                     } else {
                         // garbage collection
                         $temp = str_replace(LD . $cv2['field_name'] . RD, '', $temp);
                     }
                     $temp = reduce_double_slashes($temp);
                 }
                 $cats .= $temp;
                 if (is_array($catval[1]) && isset($catval[1]['limit']) && $catval[1]['limit'] == ++$i) {
                     break;
                 }
             }
             if (is_array($catval[1]) and isset($catval[1]['backspace'])) {
                 $cats = substr($cats, 0, -$catval[1]['backspace']);
             }
             // Check to see if we need to parse {filedir_n}
             if (strpos($cats, '{filedir_') !== FALSE) {
                 ee()->load->library('file_field');
                 $cats = ee()->file_field->parse_string($cats);
             }
             $tagdata = str_replace($catval[2], $cats, $tagdata);
         }
     } else {
         $tagdata = preg_replace('/{' . $tagname . '[^}]*}(.+?){\\/' . $tagname . '[^}]*}/is', '', $tagdata);
     }
     return $tagdata;
 }
Beispiel #11
0
 /**
  * Replace all of the custom channel pair fields.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $pfield_chunks)
 {
     $data = $obj->row();
     $prefix = $obj->prefix();
     $site_id = $data['site_id'];
     $cfields = $obj->channel()->cfields;
     $cfields = isset($cfields[$site_id]) ? $cfields[$site_id] : array();
     if (empty($cfields) or !isset($pfield_chunks[$site_id])) {
         return $tagdata;
     }
     $ft_api = ee()->api_channel_fields;
     // Check to see if the pair field chunks still exist; if not, check
     // the tagdata in case they've been modified since pre-processing.
     // This check appears before the main loop below in case any custom
     // fields were removed from the tagdata.
     foreach ($pfield_chunks[$site_id] as $tag_name => $chunks) {
         foreach ($chunks as $chk_data) {
             if (strpos($tagdata, $chk_data[3]) === FALSE) {
                 $pfield_chunks[$site_id][$tag_name] = ee()->api_channel_fields->get_pair_field($tagdata, $tag_name, $prefix);
                 $obj->preparsed()->set_once_data($this, $pfield_chunks);
                 break;
             }
         }
     }
     $pfield_chunk = $pfield_chunks[$site_id];
     foreach ($pfield_chunk as $tag_name => $chunks) {
         $field_name = preg_replace('/^' . $prefix . '/', '', $tag_name);
         $field_name = substr($field_name, strpos($field_name, ' '));
         $field_id = $cfields[$field_name];
         $ft = $ft_api->setup_handler($field_id, TRUE);
         $ft_name = $ft_api->field_type;
         if ($ft) {
             $_ft_path = $ft_api->ft_paths[$ft_api->field_type];
             ee()->load->add_package_path($_ft_path, FALSE);
             $ft->_init(array('row' => $data, 'content_id' => $data['entry_id'], 'content_type' => 'channel'));
             $pre_processed = $ft_api->apply('pre_process', array($data['field_id_' . $field_id]));
             foreach ($chunks as $chk_data) {
                 // If some how the fieldtype that the channel fields
                 // API is referencing changed to another fieldtype
                 // (Grid may cause this), get it back on track to
                 // parse the next chunk
                 if ($ft_name != $ft_api->field_type) {
                     $ft_api->setup_handler($field_id);
                 }
                 list($modifier, $content, $params, $chunk) = $chk_data;
                 $tpl_chunk = '';
                 // Set up parse function name based on whether or not
                 // we have a modifier
                 $parse_fnc = $modifier ? 'replace_' . $modifier : 'replace_tag';
                 // -------------------------------------------
                 // 'custom_field_modify_parameter' hook.
                 // - Allow developers to modify the parameters array
                 //
                 // 	There are 3 ways to use this hook:
                 // 	 	1) Add to the existing Active Record call, e.g. ee()->db->where('foo', 'bar');
                 // 	 	2) Call ee()->db->_reset_select(); to terminate this AR call and start a new one
                 // 	 	3) Call ee()->db->_reset_select(); and modify the currently compiled SQL string
                 //
                 //   All 3 require a returned query result array.
                 //
                 if (ee()->extensions->active_hook('custom_field_modify_parameter') === TRUE) {
                     $related = ee()->extensions->call('custom_field_modify_parameter', $entry_id, $this->field_id, ee()->db->_compile_select(FALSE, FALSE));
                 }
                 if (method_exists($ft, $parse_fnc)) {
                     $tpl_chunk = $ft_api->apply($parse_fnc, array($pre_processed, $params, $content));
                 } elseif (method_exists($ft, 'replace_tag_catchall') and $modifier !== '') {
                     $tpl_chunk = $ft_api->apply('replace_tag_catchall', array($pre_processed, $params, $content, $modifier));
                 }
                 $tagdata = str_replace($chunk, $tpl_chunk, $tagdata);
             }
             ee()->load->remove_package_path($_ft_path);
         }
     }
     return $tagdata;
 }
Beispiel #12
0
 /**
  * Replace all of the default date fields.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $date_vars)
 {
     $tag = $obj->tag();
     $tag_options = $obj->tag_options();
     $data = $obj->row();
     $prefix = $obj->prefix();
     // @todo
     $key = $tag;
     $val = $tag_options;
     extract($date_vars);
     //  parse entry date
     if (isset($entry_date[$key])) {
         $val = str_replace($entry_date[$key], ee()->localize->format_date($entry_date[$key], $data['entry_date']), $val);
         $tagdata = str_replace(LD . $key . RD, $val, $tagdata);
     } elseif (isset($recent_comment_date[$key])) {
         if ($data['recent_comment_date'] != 0) {
             $val = str_replace($recent_comment_date[$key], ee()->localize->format_date($recent_comment_date[$key], $data['recent_comment_date']), $val);
             $tagdata = str_replace(LD . $key . RD, $val, $tagdata);
         } else {
             $tagdata = str_replace(LD . $key . RD, '', $tagdata);
         }
     } elseif (isset($gmt_entry_date[$key])) {
         $val = str_replace($gmt_entry_date[$key], ee()->localize->format_date($gmt_entry_date[$key], $data['entry_date'], FALSE), $val);
         $tagdata = str_replace(LD . $key . RD, $val, $tagdata);
     } elseif (isset($gmt_date[$key])) {
         $val = str_replace($gmt_date[$key], ee()->localize->format_date($gmt_date[$key], $data['entry_date'], FALSE), $val);
         $tagdata = str_replace(LD . $key . RD, $val, $tagdata);
     } elseif (isset($edit_date[$key])) {
         $val = str_replace($edit_date[$key], ee()->localize->format_date($edit_date[$key], mysql_to_unix($data['edit_date'])), $val);
         $tagdata = str_replace(LD . $key . RD, $val, $tagdata);
     } elseif (isset($gmt_edit_date[$key])) {
         $val = str_replace($gmt_edit_date[$key], ee()->localize->format_date($gmt_edit_date[$key], mysql_to_unix($data['edit_date']), FALSE), $val);
         $tagdata = str_replace(LD . $key . RD, $val, $tagdata);
     } elseif (isset($expiration_date[$key])) {
         if ($data['expiration_date'] != 0) {
             $val = str_replace($expiration_date[$key], ee()->localize->format_date($expiration_date[$key], $data['expiration_date']), $val);
             $tagdata = str_replace(LD . $key . RD, $val, $tagdata);
         } else {
             $tagdata = str_replace(LD . $key . RD, "", $tagdata);
         }
     } elseif (isset($week_date[$key])) {
         // Subtract the number of days the entry is "into" the week to get zero (Sunday)
         // If the entry date is for Sunday, and Monday is being used as the week's start day,
         // then we must back things up by six days
         $offset = 0;
         if (strtolower(ee()->TMPL->fetch_param('start_day')) == 'monday') {
             $day_of_week = ee()->localize->format_date('%w', $data['entry_date']);
             if ($day_of_week == '0') {
                 $offset = -518400;
                 // back six days
             } else {
                 $offset = 86400;
                 // plus one day
             }
         }
         $week_start_date = $data['entry_date'] - ee()->localize->format_date('%w', $data['entry_date'], TRUE) * 60 * 60 * 24 + $offset;
         $val = str_replace($week_date[$key], ee()->localize->format_date($week_date[$key], $week_start_date), $val);
         $tagdata = str_replace(LD . $key . RD, $val, $tagdata);
     }
     return $tagdata;
 }