public function replace_content_tags($namespace, $content_vars, $contents) { if (is_array($content_vars)) { // Find all matching tags $s = '#<perch:' . $namespace . '[^>]*/>#'; $count = preg_match_all($s, $contents, $matches, PREG_SET_ORDER); if ($count) { foreach ($matches as $match) { $match = $match[0]; $tag = new PerchXMLTag($match); if ($tag->suppress) { $contents = str_replace($match, '', $contents); } else { if (isset($content_vars[$tag->id])) { $value = $content_vars[$tag->id]; } else { $replacement = ''; if ($tag->else()) { $replacement = $tag->else(); } $contents = str_replace($match, $replacement, $contents); continue; } $field_is_markup = false; if ($tag->type) { $FieldType = PerchFieldTypes::get($tag->type, false, $tag); $modified_value = $FieldType->get_processed($value); $field_is_markup = $FieldType->processed_output_is_markup; } else { $modified_value = $value; } // check for 'rewrite' attribute if ($tag->rewrite) { $modified_value = $this->_rewrite($tag, $modified_value); } // check for 'format' attribute if ($tag->format) { $modified_value = $this->_format($tag, $modified_value); } // check for 'replace' strings if ($tag->replace) { $pairs = explode(',', $tag->replace); if (PerchUtil::count($pairs)) { foreach ($pairs as $pair) { $pairparts = explode('|', $pair); if (isset($pairparts[0]) && isset($pairparts[1])) { $modified_value = str_replace(trim($pairparts[0]), trim($pairparts[1]), $modified_value); } } } } // Urlify if ($tag->urlify) { $modified_value = PerchUtil::urlify($modified_value); } // Trim by chars if ($tag->chars) { if (strlen($modified_value) > (int) $tag->chars) { $modified_value = PerchUtil::excerpt_char($modified_value, (int) $tag->chars, false, true, $tag->append); } } // Trim by words if ($tag->words) { $modified_value = PerchUtil::excerpt($modified_value, (int) $tag->words, false, true, $tag->append); } // Hash if ($tag->hash == 'md5') { $modified_value = md5($modified_value); } // check that what we've got isn't an array. If it is, try your best to get a good string. if (is_array($modified_value)) { if (isset($modified_value['_default'])) { $modified_value = (string) $modified_value['_default']; } else { if (isset($modified_value['processed'])) { $modified_value = (string) $modified_value['processed']; } else { $modified_value = (string) array_shift($modified_value); } } } // Strip tags if ($tag->striptags) { $modified_value = strip_tags($modified_value); } // Append if (!$tag->words && !$tag->chars && $tag->append) { $modified_value .= $tag->append; } // URL Encode if ($tag->urlencode) { $modified_value = rawurlencode($modified_value); } // Escape quotes if ($tag->escape) { $modified_value = PerchUtil::html($modified_value, true, false); $field_is_markup = true; } // check encoding if ($this->autoencode && !$field_is_markup) { if (!$tag->textile && !$tag->markdown) { if ((!$tag->is_set('encode') || $tag->encode == true) && (!$tag->is_set('html') || $tag->html == false)) { $modified_value = PerchUtil::html($modified_value); } } } // JSON encoding if ($tag->jsonencode) { $modified_value = json_encode($modified_value); } $contents = str_replace($match, $modified_value, $contents); } } } } return $contents; }