public function __construct(PerchForm $Form = null, PerchXMLTag $Tag = null, $app_id) { $this->Form = $Form; $this->Tag = $Tag; $this->app_id = $app_id; $this->required_id = $Tag->input_id(); $this->add_class_dependancies(); }
/** * Parses placeholder attributes from tag * * @param string $value_string * @param PerchXMLTag $Tag * @return string */ private function parse_placeholders($value_string, PerchXMLTag $Tag) { $s = '/:\\w+/'; $count = preg_match_all($s, $value_string, $matches, PREG_SET_ORDER); if ($count > 0) { foreach ($matches as $match) { $replacement = $match[0]; $placeholder = str_replace('-', '_', trim($match[0], ':')); if ($Tag->is_set("placeholder_{$placeholder}")) { $value_string = str_replace($replacement, $Tag->{"placeholder_{$placeholder}"}, $value_string); } } } return $value_string; }
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)); }
protected function parse_conditional($type, $opening_tag, $condition_contents, $exact_match, $template_contents, $content_vars, $index_in_group = false) { $Tag = new PerchXMLTag($opening_tag); //PerchUtil::debug($Tag); //PerchUtil::debug(PerchUtil::html($condition_contents)); $type = false; if ($Tag->logged_in() || $Tag->logged_out()) { $type = 'auth'; } elseif ($Tag->has_tag()) { $type = 'tag'; } else { $type = 'data'; } //PerchUtil::debug('Condition: '.$type, 'error'); $Session = $this->Session; $positive = $condition_contents; $negative = ''; // else condition if (strpos($condition_contents, 'perch:else:member') > 0) { $parts = preg_split('/<perch:else:member\\s*\\/>/', $condition_contents); if (is_array($parts) && count($parts) > 1) { $positive = $parts[0]; $negative = $parts[1]; } } switch ($type) { case 'auth': if ($Session->logged_in && $Tag->logged_in() || !$Session->logged_in && $Tag->logged_out()) { $template_contents = str_replace($exact_match, $positive, $template_contents); } else { $template_contents = str_replace($exact_match, $negative, $template_contents); } break; case 'tag': if ($Session->has_tag($Tag->has_tag())) { $template_contents = str_replace($exact_match, $positive, $template_contents); } else { $template_contents = str_replace($exact_match, $negative, $template_contents); } break; default: if (strpos($condition_contents, 'perch:else:member') > 0) { $condition_contents = preg_replace('/<perch:else:member\\s*\\/>/', '', $condition_contents); } $template_contents = str_replace($exact_match, $condition_contents, $template_contents); break; } return $template_contents; }
/** * 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; }
<?php require '../../../../../core/inc/api.php'; if (!class_exists('PerchAssets_Assets', false)) { include_once PERCH_CORE . '/apps/assets/PerchAssets_Assets.class.php'; include_once PERCH_CORE . '/apps/assets/PerchAssets_Asset.class.php'; } if (PerchUtil::count($_FILES)) { $Tag = new PerchXMLTag('<perch:content id="miu_image_upload_image" disable-asset-panel="true" detect-type="true" />'); $Tag->set('input_id', 'miu_image_upload_image'); $API = new PerchAPI(1.0, 'miu_image_upload'); if ($_POST['image'] == 'false') { $is_image = false; $Tag->set('type', 'file'); } else { $is_image = true; $Tag->set('type', 'image'); } /* -------- GET THE RESOURCE BUCKET TO USE ---------- */ $bucket_name = 'default'; if (isset($_POST['bucket']) && $_POST['bucket'] != '') { $bucket_name = $_POST['bucket']; } $Tag->set('bucket', $bucket_name); if ($is_image) { $width = false; if (isset($_POST['width'])) { $width = (int) $_POST['width']; } $Tag->set('width', $width); $height = false;
<?php header('Content-Type: application/json'); $FieldTag = new PerchXMLTag('<perch:content id="file" type="image" disable-asset-panel="true" detect-type="true" accept="all" />'); $FieldTag->set('input_id', 'file'); if (isset($_POST['bucket']) && !empty($_POST['bucket'])) { $FieldTag->set('bucket', $_POST['bucket']); } if (!$CurrentUser->has_priv('assets.create')) { die; } $Assets = new PerchAssets_Assets(); $message = false; $assetID = false; $Asset = false; $Form = new PerchForm('edit'); if (PerchUtil::count($_FILES)) { //PerchUtil::debug($_FILES); $Resources = new PerchResources(); $data = array(); $FieldType = PerchFieldTypes::get($FieldTag->type(), $Form, $FieldTag, null, 'assets'); $var = $FieldType->get_raw(); if (PerchUtil::count($var)) { $ids = $Resources->get_logged_ids(); $assetID = $ids[0]; $Asset = $Assets->find($assetID); $Asset->reindex(); //PerchUtil::debug($ids); if (PerchUtil::count($ids)) { if (!PerchSession::is_set('resourceIDs')) { $logged_ids = array();
public function get_attribute_map($attribute, $reverse_output = false) { $template = $this->_get_template_content(); $s = '/(<perch:input[^>]* ' . $attribute . '="[^>]*>)/s'; preg_match_all($s, $template, $matches, PREG_SET_ORDER); $out = array(); if ($matches) { $attribute = str_replace('-', '_', $attribute); foreach ($matches as $match) { $Tag = new PerchXMLTag($match[0]); if ($reverse_output) { $out[$Tag->{$attribute}()] = $Tag->id(); } else { $out[$Tag->id()] = $Tag->{$attribute}(); } } } return $out; }
private function _cache_block_template_variation($type, $opening_tag, $condition_contents, $exact_match, $template_contents, $content_vars, $index_in_group = false) { $OpeningTag = new PerchXMLTag($opening_tag); $block_index = count($this->blocks); $this->blocks[$OpeningTag->type()] = $condition_contents; $replacement = ''; if ($block_index == 0) { $replacement = '<BLOCKS />'; } return str_replace($exact_match, $replacement, $template_contents); }
public function index($Template = null) { if (!$this->index_table) { return; } $table = PERCH_DB_PREFIX . $this->index_table; // clear out old items $sql = 'DELETE FROM ' . $table . ' WHERE itemKey=' . $this->db->pdb($this->pk) . ' AND itemID=' . $this->db->pdb($this->id()); $this->db->execute($sql); $tags = $Template->find_all_tags_and_repeaters($Template->namespace); $tag_index = array(); if (PerchUtil::count($tags)) { foreach ($tags as $Tag) { if (!isset($tag_index[$Tag->id()])) { $tag_index[$Tag->id()] = $Tag; } } } $fields = $this->to_array(array_keys($tag_index)); $sql = 'INSERT INTO ' . $table . ' (itemKey, itemID, indexKey, indexValue) VALUES '; $values = array(); $id_set = false; if (PerchUtil::count($fields)) { foreach ($fields as $key => $value) { if (strpos($key, 'DynamicFields') !== false || substr($key, 0, 6) == 'perch_' || strpos($key, 'JSON') !== false) { continue; } if (isset($tag_index[$key])) { $tag = $tag_index[$key]; } else { $tag = new PerchXMLTag('<perch:x type="text" id="' . $key . '" />'); } if ($tag->type() == 'PerchRepeater') { $index_value = $tag->get_index($value); } else { $FieldType = PerchFieldTypes::get($tag->type(), false, $tag); $index_value = $FieldType->get_index($value); } if (is_array($index_value)) { foreach ($index_value as $index_item) { $data = array(); $data['itemKey'] = $this->db->pdb($this->pk); $data['itemID'] = $this->pk_is_int ? (int) $this->id() : $this->db->pdb($this->id()); $data['indexKey'] = $this->db->pdb(substr($index_item['key'], 0, 64)); $data['indexValue'] = $this->db->pdb(substr($index_item['value'], 0, 255)); $values[] = '(' . implode(',', $data) . ')'; if ($index_item['key'] == '_id') { $id_set = true; } } } } } // _id if (!$id_set) { $data = array(); $data['itemKey'] = $this->db->pdb($this->pk); $data['itemID'] = $this->pk_is_int ? (int) $this->id() : $this->db->pdb($this->id()); $data['indexKey'] = $this->db->pdb('_id'); $data['indexValue'] = $this->pk_is_int ? (int) $this->id() : $this->db->pdb($this->id()); $values[] = '(' . implode(',', $data) . ')'; } $sql .= implode(',', $values); $this->db->execute($sql); // optimize index $sql = 'OPTIMIZE TABLE ' . $table; $this->db->get_row($sql); if ($this->event_prefix && !$this->suppress_events) { $Perch = Perch::fetch(); $Perch->event($this->event_prefix . '.index', $this); } return true; }
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; }
public function posterous_process_images($post, $Template) { $html = $post['postDescHTML']; // find posterous URLs // <img alt="Img_8371" height="333" src="http://getfile0.posterous.com/getfile/files.posterous.com/temp-2012-02-04/ybzoAslvztsefCumHsmxEuFjiEutyFpnhGanxcfyunylvDaoAhgpAxChyrnp/IMG_8371.jpg.scaled500.jpg" width="500"/> // <a href="http://getfile0.posterous.com/getfile/files.posterous.com/temp-2012-02-04/ybzoAslvztsefCumHsmxEuFjiEutyFpnhGanxcfyunylvDaoAhgpAxChyrnp/IMG_8371.jpg.scaled1000.jpg"> $s = '/<img[^>]*src="[^"]*posterous\\.com[^"]*"[^>]*>/'; $count = preg_match_all($s, $html, $matches); $PerchImage = $this->api->get('Image'); $image_folder = $this->import_folder . '/image/'; $Perch = Perch::fetch(); $bucket = $Perch->get_resource_bucket($this->resource_bucket); if ($count) { foreach ($matches as $match) { $Tag = new PerchXMLTag($match[0]); // Find the file name $parts = explode('/', $Tag->src()); $filename = array_pop($parts); $linkpath = str_replace($filename, '', $Tag->src()); $fileparts = explode('.scaled', $filename); $filename = array_shift($fileparts); $linkpath .= $filename; // Find the temp-YYYY-MM-DD part of the path to find the image folder $s = '/\\/temp-([0-9]{4})-([0-9]{2})-[0-9]{2}\\//'; $count = preg_match($s, $Tag->src(), $path_matches); if ($count) { $folder = PerchUtil::file_path($image_folder . $path_matches[1] . '/' . $path_matches[2] . '/'); $files = PerchUtil::get_dir_contents($folder, false); if (PerchUtil::count($files)) { $l = strlen($filename); $image_file = false; foreach ($files as $file) { PerchUtil::debug(substr($file, -$l)); if (substr($file, -$l) == $filename) { $image_file = PerchUtil::file_path($folder . $file); break; } } if ($image_file) { $new_image_file = PerchUtil::file_path($bucket['file_path'] . '/' . $file); copy($image_file, $new_image_file); $new_image = $PerchImage->resize_image($new_image_file, (int) $Tag->width(), (int) $Tag->height()); $img_html = '<img src="' . $new_image['web_path'] . '" width="' . $new_image['w'] . '" height="' . $new_image['h'] . '" alt="' . PerchUtil::html($Tag->alt()) . '" />'; if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) { $img_html = str_replace(' />', '>', $img_html); } $html = str_replace($match[0], $img_html, $html); // find links to the bigger version $s = '/<a[^>]*href="' . preg_quote($linkpath, '/') . '[^"]*"[^>]*>/'; $s = preg_replace('#getfile[0-9]{1,2}#', 'getfile[0-9]{1,2}', $s); $count = preg_match_all($s, $html, $link_matches); if ($count) { $big_image = $PerchImage->resize_image($new_image_file, (int) $Tag->width() * 2, (int) $Tag->height() * 2); $link_html = '<a href="' . $big_image['web_path'] . '">'; foreach ($link_matches as $link_match) { $html = str_replace($link_match[0], $link_html, $html); } } else { PerchUtil::debug('FAIL', 'error'); PerchUtil::debug($new_image); PerchUtil::debug($s); PerchUtil::debug($link_matches); } } } } } } $post['postDescHTML'] = $html; $post['postDescRaw'] = $html; return $post; }
<?php # include the API include '../../../../../core/inc/api.php'; # include Assets if (!class_exists('PerchAssets_Assets', false)) { include_once PERCH_CORE . '/apps/assets/PerchAssets_Assets.class.php'; include_once PERCH_CORE . '/apps/assets/PerchAssets_Asset.class.php'; } /* -------- SET UP TEMPLATE TAG ---------- */ $Tag = new PerchXMLTag('<perch:content id="file" disable-asset-panel="true" detect-type="true" />'); $Tag->set('input_id', 'file'); $API = new PerchAPI(1.0, 'redactorjs'); if (isset($_GET['filetype']) && $_GET['filetype'] == 'image') { $is_image = true; $Tag->set('type', 'image'); } else { $is_image = false; $Tag->set('type', 'file'); } /* -------- GET THE RESOURCE BUCKET TO USE ---------- */ $bucket_name = 'default'; if (isset($_POST['bucket']) && $_POST['bucket'] != '') { $bucket_name = $_POST['bucket']; } if ($is_image) { $width = 800; if (isset($_POST['width']) && $_POST['width'] != '') { $width = (int) $_POST['width']; } $Tag->set('width', $width);
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; }
<?php $FieldTag = new PerchXMLTag('<perch:content id="image" type="image" disable-asset-panel="true" app-mode="true" detect-type="true" />'); $FieldTag->set('input_id', 'image'); $Assets = new PerchAssets_Assets(); $Tags = new PerchAssets_Tags(); $Form = new PerchForm('edit'); $message = false; if (isset($_GET['id']) && is_numeric($_GET['id'])) { $assetID = (int) $_GET['id']; $Asset = $Assets->find($assetID); if ($Asset) { if (!$Asset->is_image()) { $FieldTag->set('type', 'file'); } } } else { if (!$CurrentUser->has_priv('assets.create')) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/assets/'); } $assetID = false; $Asset = false; } $Form = new PerchForm('edit'); $req = array(); $req['resourceTitle'] = "Required"; $Form->set_required($req); if ($Form->posted() && $Form->validate()) { /* if (isset($_POST['image_remove']) && $_POST['image_remove']=='1') { $Asset->delete();
$data[$checkbox] = '0'; } } if (isset($_POST['logo_remove']) && $_POST['logo_remove'] == '1') { $data['logoPath'] = ''; } foreach ($data as $key => $value) { $Settings->set($key, $value); } $Lang = PerchLang::fetch(); $Lang->reload(); $Alert->set('success', PerchLang::get("Your settings have been updated.")); // image upload if (isset($_FILES['customlogo']) && (int) $_FILES['customlogo']['size'] > 0) { // new $FieldTag = new PerchXMLTag('<perch:content id="customlogo" type="image" disable-asset-panel="true" detect-type="true" accept="webimage" />'); $FieldTag->set('input_id', 'customlogo'); $Assets = new PerchAssets_Assets(); $Resources = new PerchResources(); $FieldType = PerchFieldTypes::get($FieldTag->type(), $Form, $FieldTag, false, 'system'); $var = $FieldType->get_raw(); if (PerchUtil::count($var)) { $ids = $Resources->get_logged_ids(); $assetID = $ids[0]; $Asset = $Assets->find($assetID); $Asset->reindex(); $Asset->mark_as_library(); $Settings->set('logoPath', $Asset->web_path()); } } $Settings->reload();