Ejemplo n.º 1
0
Archivo: Group.php Proyecto: ssrsfs/blg
 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++;
             }
         }
     }
 }
Ejemplo n.º 2
0
Archivo: Loop.php Proyecto: ssrsfs/blg
 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);
     }
 }
Ejemplo n.º 3
0
 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);
     }
 }