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