/** * 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 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 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 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; }
/** * 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; }
/** * 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; }