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