protected function _script_tag(array $attrs, $content = '') { if (!isset($attrs['type'])) { $attrs['type'] = 'text/javascript'; } $out = PerchXMLTag::create('script', 'opening', $attrs); $out .= $content; $out .= PerchXMLTag::create('script', 'closing'); return $out; }
public static function thumbnail($Asset) { $w = $Asset->thumb_display_width(); $h = $Asset->thumb_display_height(); $mode = 'landscape'; if ($h > $w) { $mode = 'portrait'; } if ($h == $w) { $mode = 'square'; } return PerchXMLTag::create('img', 'single', array('src' => $Asset->thumb_url(), 'alt' => $Asset->resourceTitle(), 'class' => 'thumb ' . $mode)); }
/** * Return data from set field on address record * * @param string $field * * @return bool */ public function getField($field) { $data = $this->to_array(); if (isset($data[$field])) { $Template = $this->api->get('Template'); $Template->set('locator/address.html', 'locator'); $Tag = $Template->find_tag($field); if ($Tag) { if ($Tag->is_set('suppress')) { $Tag->set('suppress', false); } $Template->set_from_string(PerchXMLTag::create('perch:locator', 'single', $Tag->get_attributes()), 'locator'); return $Template->render($data); } return $data[$field]; } return false; }
public function get_field($field, $use_template = true) { $data = $this->to_array(array($field)); if (isset($data[$field])) { if ($use_template) { $Template = $this->api->get('Template'); $Template->set('blog/' . $this->postTemplate(), 'blog'); $Tag = $Template->find_tag($field); if ($Tag) { if ($Tag->is_set('suppress')) { $Tag->set('suppress', false); } $Template->set_from_string(PerchXMLTag::create('perch:blog', 'single', $Tag->get_attributes()), 'blog'); return $Template->render($data); } } return $data[$field]; } return false; }
public function get_processed($raw = false) { $json = $raw; if (is_array($json)) { $item = $json; $orig_item = $item; // item gets overriden by a variant. if ($this->Tag->width() || $this->Tag->height()) { $variant_key = 'w' . $this->Tag->width() . 'h' . $this->Tag->height() . 'c' . ($this->Tag->crop() ? '1' : '0') . ($this->Tag->density() ? '@' . $this->Tag->density() . 'x' : ''); if (isset($json['sizes'][$variant_key])) { $item = $json['sizes'][$variant_key]; } } if ($this->Tag->output() && $this->Tag->output() != 'path') { switch ($this->Tag->output()) { case 'size': return isset($item['size']) ? $item['size'] : 0; break; case 'h': case 'height': return isset($item['h']) ? $item['h'] : 0; break; case 'w': case 'width': return isset($item['w']) ? $item['w'] : 0; break; case 'filename': return $item['path']; break; case 'mime': return $item['mime']; break; case 'tag': // include inline? if ($this->Tag->include() == 'inline' && isset($item['mime'])) { if (strpos($item['mime'], 'svg')) { $this->processed_output_is_markup = true; return file_get_contents($this->_get_image_file($orig_item, $item)); break; } } $attrs = array('src' => $this->_get_image_src($orig_item, $item)); if (!PERCH_RWD) { $attrs['width'] = isset($item['w']) ? $item['w'] : ''; $attrs['height'] = isset($item['h']) ? $item['h'] : ''; } $tags = array('class', 'title', 'alt'); $dont_escape = array(); foreach ($tags as $tag) { if ($this->Tag->{$tag}()) { $val = $this->Tag->{$tag}(); if (substr($val, 0, 1) == '{' && substr($val, -1) == '}') { $attrs[$tag] = '<' . $this->Tag->tag_name() . ' id="' . str_replace(array('{', '}'), '', $val) . '" escape="true" />'; $dont_escape[] = $tag; } else { $attrs[$tag] = PerchUtil::html($val, true); } } } $this->processed_output_is_markup = true; return PerchXMLTag::create('img', 'single', $attrs, $dont_escape); break; } } return $this->_get_image_src($orig_item, $item); } if ($this->Tag->width() || $this->Tag->height()) { $PerchImage = new PerchImage(); return $PerchImage->get_resized_filename($raw, $this->Tag->width(), $this->Tag->height()); } return PERCH_RESPATH . '/' . str_replace(PERCH_RESPATH . '/', '', $raw); }
private function _get_hidden_cms_field() { if ($this->app) { $attrs = array(); $attrs['type'] = 'hidden'; $attrs['name'] = 'cms-form'; $attrs['value'] = $this->form_key; return PerchXMLTag::create('input', 'single', $attrs); } return false; }