1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Images;
13
14 use ICanBoogie\Modules\Thumbnailer\AdjustThumbnailOptions;
15
16 use Brickrouge\Element;
17
18 class AdjustThumbnail extends \Brickrouge\Widget
19 {
20 protected $adjust_image;
21 protected $adjust_thumbnail_options;
22
23 static protected function add_assets(\Brickrouge\Document $document)
24 {
25 parent::add_assets($document);
26
27 $document->css->add(DIR . 'public/module.css');
28 $document->js->add(DIR . 'public/module.js');
29 }
30
31 public function __construct(array $attributes=array())
32 {
33 parent::__construct
34 (
35 'div', $attributes + array
36 (
37 Element::CHILDREN => array
38 (
39 $this->adjust_image = new AdjustImage,
40 $this->adjust_thumbnail_options = new AdjustThumbnailOptions
41 ),
42
43 'data-widget-constructor' => 'AdjustThumbnail'
44 )
45 );
46 }
47
48 public function render_inner_html()
49 {
50 return '<input type="hidden" value="' . \Brickrouge\escape($this['value']) . '" />'
51 . parent::render_inner_html()
52 . '<div class="more"><i class="icon-cog"></i></div>';
53 }
54
55 public function offsetSet($attribute, $value)
56 {
57 if ($attribute == 'value')
58 {
59 if (preg_match('/\/api\/images\/(\d+)(\/(\d*)x(\d*)(\/([a-z\-]+))?)?/', $value, $matches))
60 {
61 list($path, $nid, , $width, $height, , $method) = $matches + array(3 => null, 4 => null, 6 => null);
62
63 $options = array();
64
65 $qs = strpos($value, '?');
66
67 if ($qs)
68 {
69 parse_str(substr($value, $qs + 1), $options);
70 }
71
72 $options['width'] = $width;
73 $options['height'] = $height;
74
75 if ($method)
76 {
77 $options['method'] = $method;
78 }
79
80 $this->adjust_image['value'] = $nid;
81 $this->adjust_thumbnail_options['value'] = $options;
82 }
83 }
84
85 parent::offsetSet($attribute, $value);
86 }
87
88
89 }
90
91 namespace Brickrouge\Widget;
92
93 class AdjustThumbnail extends \Icybee\Modules\Images\AdjustThumbnail
94 {
95
96 }