Beispiel #1
0
 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();
         }
     }
 }
Beispiel #2
0
 public function output(\Pagemill_Data $data, \Pagemill_Stream $stream)
 {
     if ($this->getAttribute('name') == 'keywords') {
         $name = 'keywords';
     } else {
         if ($this->getAttribute('name') == 'description') {
             $name = 'description';
         } else {
             parent::output($data, $stream);
             return;
         }
     }
     $urlmeta = Model_UrlMeta::GetUrl(null, false);
     if (!$urlmeta->exists()) {
         parent::output($data, $stream);
         return;
     }
     $seo = Model_SeoHead::Get($urlmeta['id']);
     if (!$seo->exists()) {
         parent::output($data, $stream);
         return;
     }
     if (!$seo['meta' . $name]) {
         parent::output($data, $stream);
         return;
     }
     $meta = new Pagemill_Tag('meta', $this->attributes, null, $this->doctype());
     $meta->setAttribute('content', $seo['meta' . $name]);
     $meta->output($data, $stream);
 }
Beispiel #3
0
 public function process(\Pagemill_Tag $tag, \Pagemill_Data $data, \Pagemill_Stream $stream)
 {
     //if ($this->_method == 'post') {
     // TODO: Add the postlink stuff
     $tag->setAttribute('rel', $tag->getAttribute('rel') ? $tag->getAttribute('rel') . ' ' . $this->_method : $this->_method);
     //}
 }
Beispiel #4
0
 public function process(\Pagemill_Tag $tag, \Pagemill_Data $data, \Pagemill_Stream $stream)
 {
     $stream = new Pagemill_Stream(true);
     $this->_attributeTag->outputForAttribute($data, $stream);
     $value = $stream->peek();
     if ($value !== '') {
         $tag->setAttribute($this->_attributeTag->getAttribute('name'), $value);
     }
 }
Beispiel #5
0
 public function process(\Pagemill_Tag $tag, \Pagemill_Data $data, \Pagemill_Stream $stream)
 {
     $pmBody = Typeframe_TagPreprocessor_Export::Export('body');
     if ($pmBody) {
         foreach ($pmBody[0]->attributes() as $key => $value) {
             $tag->setAttribute($key, $value);
         }
     }
 }
Beispiel #6
0
 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');
         }
     }
 }