public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $head = $data->parseVariables($this->getAttribute('head')); if (!$head) { throw new Exception("Recurse tag requires a head attribute"); } $loop = null; $parent = $this->parent(); while (!is_null($parent)) { if (is_a($parent, 'Pagemill_Tag_Loop')) { $loop = $parent; } if ($parent->name() == $head) { break; } $parent = $parent->parent(); } if (is_null($parent)) { throw new Exception("Recurse tag could not find '{$head}'"); } if (is_null($loop)) { throw new Exception("Recurse tag requires a loop to process"); } $parent = clone $parent; //$context = $loop->currentContext(); $context = clone $data; $parent->process($context, $stream); }
public function process(Pagemill_Tag $tag, Pagemill_Data $data, Pagemill_Stream $stream) { $result = $data->evaluate($this->_expression); if (!$result) { return false; } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $for = $data->parseVariables($this->getAttribute('for')); if (!$for) { throw new Exception("Socket tag requires 'for' attribute"); } $plugin = null; $detachable = true; if (count($this->children())) { $detachable = false; $found = $this->_findEmptyPluginTags(); if (count($found) == 0) { throw new Exception('Socket tag with content requires an empty plugin (no attributes)'); } else { if (count($found) > 1) { throw new Exception('Socket tag should not contain more than one empty plugin'); } } $plugin = $found[0]; } else { $plugin = new Typeframe_Tag_Plugin('plugin', array(), $this); $this->appendChild($plugin); } $plugins = self::_GetPluginsFor($for); foreach ($plugins as $p) { $signature = Typeframe::Registry()->getPluginSignature($p['plug']); $plugin->className = $signature->className(); $plugin->settings = $p['settings']; $plugin->attributes['plugid'] = $p['plugid']; parent::output($data, $stream); } if ($detachable) { $plugin->detach(); } }
protected function output(Pagemill_Data $data, Pagemill_Stream $stream, $encode = true) { if ($encode) { $stream->puts($data->parseVariables($this->_text, $this->doctype)); } else { $stream->puts($data->parseVariables($this->_text)); } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $db = Typeframe::Database(); if ($this->hasAttribute('rules') && !Typeframe_Tag_Socket::ProcessRules($this->getAttribute('rules'))) { return ''; } /* * Rules for loading the plugin: * 1. The plugid overrides other load settings. * 2. Load a plugin from the table if the name attribute matches an * an admin-specified name. * 3. Create a generic plugin from a signature. * 4. If the plugin was loaded from the database, attribute settings * override database settings. */ $p = null; if ($this->getAttribute('plugid')) { $plugin = Model_Plug::Get($data->parseVariables($this->getAttribute('plugid'))); if ($plugin->exists()) { $p = Typeframe::Registry()->getPluginSignature($plugin['plug']); } } else { if ($this->getAttribute('name')) { $plugins = new Model_Plug(); $plugins->where('name = ?', $data->parseVariables($this->getAttribute('name'))); $plugin = $plugins->getFirst(); if ($plugin->exists()) { $p = Typeframe::Registry()->getPluginSignature($plugin['plug']); } else { $p = Typeframe::Registry()->getPluginSignature($this->getAttribute('name')); } } } if ($p) { $cls = $p->className(); if (class_exists($cls)) { $settings = $this->settings; foreach ($this->attributes() as $k => $v) { $settings[$k] = $data->parseVariables($v); } //$obj = new $cls($settings); $obj = new $cls('plugin', $settings, null); foreach ($this->children() as $child) { $obj->appendChild($child); } $obj->process($data, $stream); foreach ($obj->children() as $child) { $this->appendChild($child); } $obj->detach(); } else { throw new Exception("Class '{$cls}' does not exist"); } } else { throw new Exception("Plugin does not have a signature"); } }
public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $src = $data->parseVariables($this->getAttribute('src')); if (!in_array($src, self::$_scripts)) { self::$_scripts[] = $src; $this->name = 'script'; parent::output($data, $stream); } }
public function process(Pagemill_Tag $tag, Pagemill_Data $data, Pagemill_Stream $stream) { $src = $data->parseVariables($tag->getAttribute('src')); $attr = 'src'; if (!$src) { $src = $data->parseVariables($tag->getAttribute('href')); $attr = 'href'; } $width = $data->parseVariables($tag->getAttribute('width')); $height = $data->parseVariables($tag->getAttribute('height')); // TODO: Is this good enough? $file = TYPEF_DIR . substr($src, strlen(TYPEF_WEB_DIR)); // TODO: Should this generate an error? if (!file_exists($file) || !is_file($file)) { return; } $ext = pathinfo($file, PATHINFO_EXTENSION); if (strtolower($ext) == 'bmp') { $ext = 'jpg'; } $md5 = md5("{$src}_{$width}_{$height}_{$this->_ratio}") . ".{$ext}"; if (file_exists(TYPEF_DIR . "/files/public/timg/{$md5}")) { if (filemtime($file) < filemtime(TYPEF_DIR . '/files/public/timg/' . $md5)) { $tag->setAttribute($attr, TYPEF_WEB_DIR . "/files/public/timg/{$md5}"); $size = getimagesize(TYPEF_DIR . "/files/public/timg/{$md5}"); $tag->setAttribute('width', $size[0]); $tag->setAttribute('height', $size[1]); return; } } // Resize image now if the file is below a particular // size. We'll try it with 900kb for now. if (filesize($file) < 900000) { Gdi::Thumbnail($file, TYPEF_DIR . '/files/public/timg/' . $md5, $width, $height, $this->_ratio); if (file_exists(TYPEF_DIR . '/files/public/timg/' . $md5)) { $tag->setAttribute($attr, TYPEF_WEB_DIR . "/files/public/timg/{$md5}"); } $tag->removeAttribute('width'); $tag->removeAttribute('height'); } else { // Schedule the resizing. $queue = new Model_TimgQueue(); $queue->where('src = ?', $file); $queue->where('dst = ?', TYPEF_DIR . "/files/public/timg/{$md5}"); if (!$queue->count()) { $timg = Model_TimgQueue::Create(); $timg['src'] = $file; $timg['dst'] = TYPEF_DIR . "/files/public/timg/{$md5}"; $timg['width'] = $width; $timg['height'] = $height; $timg['ratio'] = $this->_ratio; $timg->save(); } } }
public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $name = $data->parseVariables($this->getAttribute('name')); if ($name) { $this->name = $name; parent::output($data, $stream); } else { foreach ($this->children() as $child) { $child->process($data, $stream); } } }
public function process(Pagemill_Tag $tag, Pagemill_Data $data, Pagemill_Stream $stream) { if ($tag->hasAttribute('value')) { $checked = $data->parseVariables($this->_checkvalue); $value = $data->parseVariables($tag->getAttribute('value')); if ($checked == $value) { $tag->setAttribute('checked', 'checked'); } else { $tag->removeAttribute('checked'); } } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $select = $this->_getSelect(); if (get_class($select) == 'Pagemill_Tag_Select') { $selectedValue = $select->selectedValue(); $value = $data->parseVariables($this->getAttribute('value')); if ($selectedValue == $value) { $this->setAttribute('selected', 'selected'); } else { $this->removeAttribute('selected'); } } parent::output($data, $stream); }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $expr = $this->getAttribute('expr'); if (strpos($expr, '@{') === false) { $expr = "@{{$expr}}@"; } $result = $data->parseVariables($expr); if ($result) { foreach ($this->children() as $child) { $child->process($data, $stream); } } $this->_lastResult = $result; }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $file = $data->parseVariables($this->getAttribute('file')); if (!isset(self::$_includeCache[$file])) { $pm = new Pagemill($data); $tree = $pm->parseFile($file, $this->doctype()); self::$_includeCache[$file] = $tree; } else { $tree = self::$_includeCache[$file]; } // Unlike most tags, we don't want to use append/detach here // because the tree might be a fragment. //$this->appendChild($tree); $tree->parent = $this->parent; $tree->process($data, $stream); //$tree->detach(); $tree->parent = null; }
public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { if ($this->hasAttribute('template')) { $template = Typeframe_Skin::TemplatePath($data->parseVariables($this->getAttribute('template'))); $this->setAttribute('file', $template); } if ($this->getAttribute('select')) { $select = $this->getAttribute('select'); $temp = new Pagemill_Stream(true); parent::output($data, $temp); $xml = Pagemill_SimpleXmlElement::LoadString($temp->clean()); $parts = $xml->select($select); foreach ($parts as $part) { $stream->puts($part->asXml()); } } else { parent::output($data, $stream); } }
public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $plugid = $data->parseVariables($this->getAttribute('plugid')); $plug = Model_Plug::Get($plugid); if ($plug->exists()) { $name = $plug['plug']; $sig = Typeframe::Registry()->getPluginSignature($name); $cls = $sig->className(); if (is_subclass_of($cls, 'Plugin')) { $plug['settings']['plugid'] = $plugid; $plug = new $cls('', $plug['settings'], $this); $plug->admin($data, $stream); } else { throw new Exception("Invalid plugin type specified"); } } else { throw new Exception("Invalid plugin specified"); } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { // A list of attributes and settings to send to the template. $attribs = array(); $settings = array(); foreach ($this->attributes() as $k => $v) { switch ($k) { // The 'extra' attributes, these are settings that control something. case 'value': case 'name': case 'dir': case 'imgwidth': case 'imgheight': case 'id': $settings[$k] = $data->parseVariables($v); break; // Any additional attribute, will be passed to the div containing the elemnts. // Any additional attribute, will be passed to the div containing the elemnts. default: $attribs[] = array('name' => $k, 'value' => $data->parseVariables($v)); break; } } if (!isset($settings['name'])) { return ''; } // I need to ensure some exist. if (!(isset($settings['imgwidth']) && $settings['imgwidth'])) { $settings['imgwidth'] = 150; } if (!(isset($settings['imgheight']) && $settings['imgheight'])) { $settings['imgheight'] = 100; } if (!(isset($settings['id']) && $settings['id'])) { $settings['id'] = 'imageuploadtag-' . preg_replace('/[^a-zA-Z0-9]/', '_', $settings['name']) . '-' . rand(0, 9) . rand(0, 9) . rand(0, 9); } $data = $data->fork(); $data->setArray($settings); $data->set('attributes', $attribs); Typeframe_Tag_Include::Generate('/pagemill/tag/imageupload.html', $this)->process($data, $stream); }
public function process(Pagemill_Tag $tag, Pagemill_Data $data, Pagemill_Stream $stream) { $result = $data->evaluate($this->_expression); if ($result) { $tmp = new Pagemill_Tag($tag->name(), $tag->attributes(), $tag->parent()); $tmp->appendText($result); if ($this->_replace) { $tmp->processInner($data, $stream); } else { $tmp->process($data, $stream); } $tmp->detach(); return false; } else { if ($this->_replace) { $tag->processInner($data, $stream); return false; } } return true; }
public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $this->name = 'html'; $pm = new Pagemill($data); $skin = $data->parseVariables($this->getAttribute('skin')); $oldskin = null; if ($skin) { $oldskin = Typeframe_Skin::Current(); Typeframe_Skin::Set($skin); } else { $skin = Typeframe_Skin::Current(); } if (file_exists(TYPEF_DIR . '/skins/' . $skin . '/skin.html')) { $skinTree = $pm->parseFile(TYPEF_DIR . '/skins/' . $skin . '/skin.html'); } else { $skinTree = $pm->parseFile(TYPEF_DIR . '/skins/default/skin.html'); } $skinTree->process($data, $stream); if (!is_null($oldskin)) { Typeframe_Skin::Set($oldskin); } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $id = $data->parseVariables($this->getAttribute('id')); if (!$id) { $id = self::EditorId(); } $name = $data->parseVariables($this->getAttribute('name')); if ($this->getAttribute('config')) { $config = $this->getAttribute('config'); } else { $config = TYPEF_WEB_DIR . '/fckeditor/config.js'; } $data = $data->fork(); $data->set('id', $id); $data->set('name', $name); $data->set('config', $config); $data->set('toolbarset', $data->parseVariables($this->getAttribute('toolbarset'))); $data->set('stylesheets', $data->parseVariables($this->getAttribute('stylesheets'))); $data->set('bodyclass', $data->parseVariables($this->getAttribute('bodyclass'))); $data->set('bodyid', $data->parseVariables($this->getAttribute('bodyid'))); $data->set('editselector', $data->parseVariables($this->getAttribute('editselector'))); $include = new Typeframe_Tag_Include('', array('template' => '/ckeditor/ckeditor.inc.html'), $this, $this->doctype()); $include->process($data, $stream); }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { /* @var $child Pagemill_Tag */ foreach ($this->children() as $child) { if (is_a($child, 'Pagemill_tag')) { if ($child->name(false) == 'when') { $expr = $child->getAttribute('expr'); if (strpos($expr, '@{') === false) { $expr = "@{" . $expr . "}@"; } $value = $data->parseVariables($expr); if ($value) { $child->processInner($data, $stream); return; } } else { if ($child->name(false) == 'otherwise') { $child->processInner($data, $stream); return; } } } } }
<?php Pagemill_Data::RegisterExprFunc('breadcrumb', 'Plugin_Breadcrumbs::SavedState'); // Remember query strings for GET requests so the state of a page can be // included in its breadcrumb link // The query string can be recovered using Plugin_Breadcrumbs::SavedState($url) if (Typeframe::CurrentPage()->application()->name() == '403' || Typeframe::CurrentPage()->application()->name() == '404') { return; } if ($_SERVER['REQUEST_METHOD'] == 'GET') { if (!isset($_SESSION['breadcrumbs'])) { $_SESSION['breadcrumbs'] = array(); } if (Typeframe::CurrentPage()->uri() == Typeframe::CurrentPage()->applicationUri()) { $_SESSION['breadcrumbs'][Typeframe::CurrentPage()->uri()] = array('title' => Typeframe::CurrentPage()->page()->title(), 'query' => $_SERVER['QUERY_STRING']); } // Clear deeper URLs; i.e., if the user browsed to a page higher in the directory structure // (/foo) than a URL with a saved state (/foo/bar), unset the saved state foreach ($_SESSION['breadcrumbs'] as $k => $v) { if (strlen($k) > strlen(Typeframe::CurrentPage()->uri())) { unset($_SESSION['getcrumbs'][$k]); } } }
return TYPEF_ROOT_WEB_DIR . '/files/static' . $path; } else { // TODO: This might not be the best default. Should it trigger an error? return TYPEF_ROOT_WEB_DIR . $path; }*/ } else { if (Typeframe_Skin::Current() != TYPEF_SITE_SKIN && $uri != TYPEF_WEB_DIR . '/admin' && substr($uri, 0, strlen(TYPEF_WEB_DIR . '/admin/')) != TYPEF_WEB_DIR . '/admin/') { if (file_exists(TYPEF_DIR . '/skins/' . TYPEF_SITE_SKIN . $path)) { return TYPEF_ROOT_WEB_DIR . '/skins/' . TYPEF_SITE_SKIN . $path; } } else { return TYPEF_ROOT_WEB_DIR . '/skins/default' . $path; } } } Pagemill_Data::RegisterExprFunc('skin_path', 'skin_path'); //$skin = Pagemill_Tag_Html::Skin(); //Typeframe::SetTemplatePath(TYPEF_DIR . '/skins/' . $skin . '/templates;' . ($skin != 'default' ? TYPEF_DIR . '/skins/default/templates' . ';' : '') . TYPEF_SOURCE_DIR . '/templates'); if (!function_exists('http_response_code')) { function http_response_code($code = NULL) { static $status = 200; if ($code !== NULL) { switch ($code) { case 100: $text = 'Continue'; break; case 101: $text = 'Switching Protocols'; break; case 200:
function useFormHandler($form) { return array('fields' => $form->fields(), 'errors' => $form->errors()); } function useFormField($field) { return $field->data(); } Pagemill_Data::ClassHandler('Dbi_Model', 'useModel'); Pagemill_Data::ClassHandler('Form_Handler', 'useFormHandler'); Pagemill_Data::ClassHandler('Form_Field', 'useFormField'); Pagemill_Data::RegisterExprFunc('default_date', 'Typeframe_ExprFunc::default_date'); Pagemill_Data::RegisterExprFunc('default_date_time', 'Typeframe_ExprFunc::default_date_time'); Pagemill_Data::RegisterExprFunc('default_date_time_w_seconds', 'Typeframe_ExprFunc::default_date_time_w_seconds'); Pagemill_Data::RegisterExprFunc('skin_path', 'Typeframe_Skin::SkinPath'); Pagemill_Data::RegisterExprFunc('allow', 'Typeframe::Allow'); Pagemill_Data::RegisterExprFunc('shorten', 'Bam_Functions::GetIntro'); Pagemill_Data::RegisterExprFunc('count_plugins_for', 'Typeframe_Tag_Socket::CountPluginsFor'); Pagemill_Data::RegisterExprFunc('resize_image', 'Typeframe_ExprFunc::resize_image'); Pagemill_Data::RegisterExprFunc('strpos', 'strpos'); // TODO: Experimenting with session management in Typeframe_Response->execute(). if (isset($_SERVER['HTTP_HOST'])) { session_set_cookie_params(ini_get('session.cookie_lifetime'), TYPEF_WEB_DIR ? TYPEF_WEB_DIR . '/' : '/', defined('TYPEF_HOST') ? '.' . str_replace('www.', '', TYPEF_HOST) : ini_get('session.cookie_domain')); session_start(); } $dir = scandir(TYPEF_SOURCE_DIR . '/scripts/define.d'); foreach ($dir as $file) { if (substr($file, 0, 1) != '.' && is_file(TYPEF_SOURCE_DIR . '/scripts/define.d/' . $file)) { require_once TYPEF_SOURCE_DIR . '/scripts/define.d/' . $file; } }
public function process(Pagemill_Tag $tag, Pagemill_Data $data, Pagemill_Stream $stream) { $tag->selectedValue($data->parseVariables($this->_selectedValue)); }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $oldPointer = self::$_pointer; $cycle = $data->parseVariables($this->getAttribute('cycle')); if ($cycle) { $cycle = explode(',', $data->parseVariables($this->getAttribute('cycle'))); } $name = $data->parseVariables($this->getAttribute('name')); $times = $data->parseVariables($this->getAttribute('times')); $delimiter = $this->getAttribute('delimiter'); $loopTimes = 0; // get as attribute $as = $this->getAttribute('as'); $asKey = null; if (strpos($as, ' ') !== false) { list($asKey, $as) = explode(' ', $as); $as = trim($as); $asKey = trim($asKey); if (!$as) { $as = $asKey; $asKey = null; } } $this->_name = $name; $this->_originalData = $data->getArray(); $this->_data = $data; $this->_stream = $stream; $this->_as = $as; $this->_asKey = $asKey; $this->_cycle = $cycle; $this->_delimiter = $delimiter; // if name given... if ($name) { $children = $data->evaluate($name); if (is_null($children) || is_scalar($children)) { return; } if (!is_a($children, 'Pagemill_Data') && (is_array($children) || $children instanceof Countable)) { if (count($children) == 0) { return; } } self::$_pointer .= '[' . $name . ']'; $data->set('pointer', self::$_pointer); if (!is_array($children)) { if (is_a($children, 'Pagemill_Data')) { $children = $children->getArray(); } else { if ($children instanceof ArrayObject) { $children = $children->getArrayCopy(); } else { if (!$children instanceof Iterator) { // Unrecognized objects throw an exception so developers // can determine whether to modify the object or register // a handler. throw new Exception("Unable to loop over object '{$name}' of class '" . get_class($children) . "'"); } } } } if ($this->hasAttribute('sort')) { $sort = $data->parseVariables($this->getAttribute('sort')); if (!is_array($children)) { $array = array(); foreach ($children as $key => $value) { $array[$key] = $value; } $children = $array; // Replace the object with the array so we don't have to // convert it again later $data->set($name, $children); } $this->_sortKey = $sort; usort($children, array($this, '_cmp')); } $limit = $data->parseVariables($this->getAttribute('limit')); if ($limit) { // We have to do a numeric iteration. $start = null; $end = null; $parts = explode(',', $data->parseVariables($this->getAttribute('limit'))); if (count($parts) == 2) { $start = $parts[0]; $end = $parts[0] + $parts[1]; } else { $start = 0; $end = $parts[0]; } if (is_array($children) || $children instanceof Countable) { if (count($children) < $end - $start) { $end = count($children) - $start; } } if (is_array($children) && isset($children[$start])) { // for $start to $end $loopTimes = $this->_forLimit($children, $start, $end); } else { if ($children instanceof SeekableIterator) { // seek to $start and do foreach $loopTimes = $this->_forEachLimit($children, $start, $end); } else { if ($children instanceof ArrayAccess && isset($children[$start])) { // for $start to $end $loopTimes = $this->_forLimit($children, $start, $end); } else { // iterate to lower limit and proccess through upper limit $loopTimes = $this->_forEachLimit($children, $start, $end); } } } } else { $loopTimes = $this->_forEach($children); } self::$_pointer = $oldPointer; $data->set('pointer', self::$_pointer); } if ($times) { $start = $loopTimes; $this->_forTimes($start, $times); } }
public function parseVariables($text, Pagemill_Doctype $encoder = null) { $result = $text; preg_match_all('/@{([\\w\\W\\s\\S]*?)}@/i', $text, $matches); foreach ($matches[0] as $index => $container) { $expression = $matches[1][$index]; $evaluated = $this->evaluate($expression); if (!is_null($evaluated) && !is_scalar($evaluated)) { if (is_array($evaluated)) { $evaluated = self::IsAssoc($evaluated) ? '(Object)' : '(Array)'; } else { if (is_a($evaluated, 'Pagemill_Data')) { $evaluated = '(Object)'; } else { if (Pagemill_Data::LikeArray($evaluated)) { $evaluated = '(ArrayInterface)'; } else { if (Pagemill_Data::LikeAssoc($evaluated)) { $evaluated = '(Interface)'; } else { $evaluated = '(Unknown)'; } } } } } if ($encoder) { $evaluated = $encoder->encodeEntities($evaluated); } $result = str_replace($container, $evaluated, $result); } preg_match_all('/#{([\\w\\W\\s\\S]*?)}#/i', $result, $matches); foreach ($matches[0] as $index => $container) { $expression = $matches[1][$index]; $evaluated = $this->evaluate($expression); if (!is_null($evaluated) && !is_scalar($evaluated)) { if (is_array($evaluated)) { $evaluated = self::IsAssoc($evaluated) ? '(Object)' : '(Array)'; } else { if (is_a($evaluated, 'Pagemill_Data')) { $evaluated = '(Object)'; } else { if (Pagemill_Data::LikeArray($evaluated)) { $evaluated = '(ArrayInterface)'; } else { if (Pagemill_Data::LikeAssoc($evaluated)) { $evaluated = '(Interface)'; } else { $evaluated = '(Unknown)'; } } } } } if ($encoder) { $evaluated = $encoder->encodeEntities($evaluated); } $result = str_replace($container, '@{' . $evaluated . '}@', $result); } return $result; }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $members = array(); foreach ($this->children() as $child) { if (is_a($child, 'Pagemill_Tag') && $child->name() == 'pm:member') { $members[] = $child->attributes(); } } if ($this->insidePlugin()) { // We are inside a plugin. Content should have been passed into // the data node through the plugin's settings. $row = $data->get($this->getAttribute('name')); foreach ($members as $member) { if (@$member['type'] == 'html') { // Parse short URL attributes for ($i = 0; $i < count($row); $i++) { $urled = @$row[$i][$member['name']]; $urled = preg_replace('/(<[^>]*? href=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); $urled = preg_replace('/(<[^>]*? src=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); $row[$i][$member['name']] = $urled; } } } $data->set($this->getAttribute('name'), $row); } else { $content = self::Cache(); $rows = @$content[$this->getAttribute('name')]; $index = 0; if (is_array($rows)) { $data[$this->getAttribute('name')] = array(); foreach ($rows as $row) { foreach ($members as $member) { // Templates can leave the type attribute undefined and // assume a text field. Check here if it's set to avoid // error notices. if (isset($member['type'])) { if ($member['type'] == 'html') { // Parse short URL attributes $urled = @$row[$member['name']]; $urled = preg_replace('/(<[^>]*? href=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); $urled = preg_replace('/(<[^>]*? src=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); $row[$member['name']] = $urled; } if ($member['type'] == 'model') { $model = $row[$member['name']]; if ((string) $model != '') { $model = explode(':', $model); if (class_exists($model[0])) { $record = $model[0]::Get($model[1]); $row[$member['name']] = $record; } } } } } if ($this->getAttribute('subpage')) { $uri = makeFriendlyUrlText($row[$this->getAttribute('subpage')]); //if ('list' == $this->getAttribute('firstsubpage')) { if ($this->getAttribute('noindex')) { $row['uri'] = $uri; $pathinfo = Typeframe::CurrentPage()->pathInfo(); if ($pathinfo == $uri && !self::$_subPageSelected) { $row['content_selected'] = true; self::$_subPageSelected = true; } } else { //if (($index > 0) || self::$_mainPageSet) { $row['uri'] = $uri; //} else { // $row['uri'] = ''; // self::$_mainPageSet = true; //} $pathinfo = Typeframe::CurrentPage()->pathInfo(); //if ((($pathinfo == $uri) || (!$pathinfo && (0 == $index))) && !self::$_subPageSelected) { if ($pathinfo == $uri || $this->getAttribute('noindex') && $index == 0) { $row['content_selected'] = true; self::$_subPageSelected = true; } } } //$data->addChild(array($this->getAttribute('name'), $row)); //$data['name'][] = $row; $data[$this->getAttribute('name')][] = $row; $index++; } } } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream, $content = null) { if (!$this->insidePlugin()) { $content = self::Cache(); $name = $this->getAttribute('name'); $type = $this->getAttribute('type'); if ($type == 'html') { // Parse short URL attributes $urled = @$content[$name]; $urled = preg_replace('/(<[^>]*? href=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); $urled = preg_replace('/(<[^>]*? src=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); @($content[$name] = $urled); } if ($type == 'model') { if (!empty($content[$name])) { $model = $content[$name]; if ((string) $model != '') { $model = explode(':', $model); if (class_exists($model[0])) { $record = $model[0]::Get($model[1]); $content[$name] = $record; } } } else { $content[$name] = null; } } if ($this->getAttribute('scope') == 'global') { Typeframe::Pagemill()->set($name, @$content[$name]); } else { $data->set($name, @$content[$name]); } } //$inner = $this->inner($data); if (count($this->children()) > 0) { foreach ($this->children() as $child) { $child->process($data, $stream); } } else { $output = ''; if ($this->getAttribute('noop')) { $output = ''; } else { if ($type == 'html') { $pm = new Pagemill($data); $output = $pm->writeString('<pm:codeblock elements="*" attributes="*">@{' . $name . '}@</pm:codeblock>', true); } else { if ($type == 'image') { // Only display something if something is filled in, ie: no broken images. if (@$content[$name] && is_readable(TYPEF_DIR . '/files/public/content/' . @$content[$name])) { // Allow any other attribute to transparently pass to the image. $atts = ''; foreach ($this->attributes() as $k => $v) { switch ($k) { case 'name': case 'label': case 'type': case 'src': break; default: $atts .= " {$k}=\"{$v}\""; } } $output = '<img src="' . TYPEF_WEB_DIR . '/files/public/content/' . $content[$name] . '"' . $atts . '/>'; } else { $output = ''; } } else { if ($type == 'link') { if (!$content[$name] && @$this->getAttribute('ignoreblank') == true) { return ''; } $linktitle = @$this->getAttribute('linktitle') ? $this->getAttribute('linktitle') : 'Click Here'; $linkstyle = @$this->getAttribute('linkstyle') ? $this->getAttribute('linkstyle') : ''; $output = '<a href="' . $content[$name] . '" style="' . $linkstyle . '">' . $linktitle . '</a>'; } else { if ($type == 'checkbox' || $type == 'select') { // Checkbox and select types are primarily for configurable template logic and do not have default output. $output = ''; } else { $output = $content[$name]; } } } } } $stream->puts($output); } }
public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $result = $data->evaluate($this->getAttribute('expr')); $stream->puts($result); }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { // Create the element and attribute arrays if ($this->hasAttribute('elements')) { $elements = $data->parseVariables($this->getAttribute('elements')); } else { $elements = self::ELEMENTS; } if ($this->hasAttribute('attributes')) { $attributes = $data->parseVariables($this->getAttribute('attributes')); } else { $attributes = self::ATTRIBUTES; } if ($this->hasAttribute('xelements')) { $elements .= ($elements ? ',' : '') . $this->getAttribute('xelements'); } if ($this->hasAttribute('xattributes')) { $attributes .= ($attributes ? ',' : '') . $this->getAttribute('xattributes'); } $elementArray = array_unique(preg_split('/ *, */', $elements)); $attributeArray = array_unique(preg_split('/ *, */', $attributes)); if (in_array('*', $elementArray)) { $elementArray = array('*'); } if (in_array('*', $attributeArray) || in_array('*.*', $attributeArray)) { $attributeArray = array('*'); } $buffer = new Pagemill_Stream(true); foreach ($this->children() as $child) { $child->rawOutput($buffer, false); } $source = $buffer->clean(); $source = $data->parseVariables($source); if (!trim($source)) { return; } if ($this->getAttribute('use') == 'markdown') { require_once TYPEF_SOURCE_DIR . '/libraries/markdown.php'; $source = Markdown($source); } try { $parser = new Pagemill_Parser(); $doctype = new Pagemill_Doctype_Html(''); // Register the href and src attribute processors for URL shortcuts $doctype->registerAttribute('/href', 'Typeframe_Attribute_Url'); $doctype->registerAttribute('/src', 'Typeframe_Attribute_Url'); $tree = $parser->parse($source, $doctype); } catch (Exception $e) { $lastError = $e->getMessage(); //$stream->puts(htmlentities($source)); //$stream->puts($source); try { $xml = @Pagemill_SimpleXmlElement::LoadHtml("<div id=\"codeblock__\">{$source}</div>"); $select = $xml->select('#codeblock__'); $inner = $select[0]->innerXml(); $parser = new Pagemill_Parser(); $doctype = new Pagemill_Doctype_Html(''); $doctype->registerAttribute('/href', 'Typeframe_Attribute_Url'); $doctype->registerAttribute('/src', 'Typeframe_Attribute_Url'); $tree = $parser->parse('<pm:template>' . trim($inner) . '</pm:template>', $doctype); } catch (Exception $e) { trigger_error($lastError); trigger_error($e->getMessage()); $stream->puts(htmlentities($source)); return; } } $this->_recurseInput($tree, $stream, $elementArray, $attributeArray, $data); }
/** * Build an attribute string from the tag's attributes. This method will * evaluate expressions in attribute values. * @param Pagemill_Data $data * @return string */ protected function buildAttributeString(Pagemill_Data $data) { $string = ''; foreach ($this->attributes as $key => $value) { $string .= ' ' . $key . '="' . $this->doctype()->encodeEntities($data->parseVariables($value)) . '"'; } return $string; }