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