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 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 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) { $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 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(); } }
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 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 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 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) { $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) { $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) { $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) { $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) { 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) { $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) { /* @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; } } } } }
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); }
public function process(Pagemill_Tag $tag, Pagemill_Data $data, Pagemill_Stream $stream) { $tag->selectedValue($data->parseVariables($this->_selectedValue)); }
/** * 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; }
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); } }