1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace ICanBoogie\Modules\Thumbnailer;
13
14 use ICanBoogie\ActiveRecord;
15 use ICanBoogie\Event;
16 use ICanBoogie\Operation;
17
18 use Brickrouge\Element;
19 use Brickrouge\Form;
20 use Brickrouge\Widget;
21
22 use Icybee\Modules\Cache\Collection as CacheCollection;
23 use Icybee\Modules\Images\Image as ImageActiveRecord;
24
25 class Hooks
26 {
27 28 29 30 31 32 33
34 static public function on_configblock_alter_children(Event $event, \Icybee\ConfigBlock $block)
35 {
36 global $core;
37
38 $module_id = (string) $event->module->id;
39
40 $c = $core->configs->synthesize('thumbnailer', 'merge');
41
42 if (!$c)
43 {
44 return;
45 }
46
47 $configs = array();
48
49 foreach ($c as $version_name => $config)
50 {
51 if (empty($config['module']) || $config['module'] != $module_id)
52 {
53 continue;
54 }
55
56 $configs[$version_name] = $config;
57 }
58
59 if (!$configs)
60 {
61 return;
62 }
63
64 $core->document->css->add(DIR . 'public/admin.css');
65
66 $children = array();
67
68 foreach ($configs as $version_name => $config)
69 {
70 list($defaults) = $config;
71
72 $config += array
73 (
74 'description' => null
75 );
76
77 $children['global[thumbnailer.versions][' . $version_name . ']'] = new Widget\PopThumbnailVersion
78 (
79 array
80 (
81 Form::LABEL => new Element('span', array(Element::INNER_HTML => $config['title'] . '<br /><small>' . $version_name . '</small>')),
82 Element::DEFAULT_VALUE => $defaults,
83 Element::GROUP => 'thumbnailer',
84 Element::DESCRIPTION => $config['description'],
85
86 'value' => $core->registry["thumbnailer.verison.$version_name"]
87 )
88 );
89 }
90
91 $event->attributes[Element::GROUPS]['thumbnailer'] = array
92 (
93 'title' => 'Miniatures',
94 'description' => "Ce groupe permet de configurer les différentes
95 versions de miniatures qu'il est possible d'utiliser pour
96 les entrées de ce module."
97 );
98
99 $event->children = array_merge($event->children, $children);
100 }
101
102 103 104 105 106
107 static public function before_configoperation_properties(\Icybee\ConfigOperation\BeforePropertiesEvent $event)
108 {
109 global $core;
110
111 if (empty($event->request->params['global']['thumbnailer.versions']))
112 {
113 return;
114 }
115
116 unset($core->vars['cached_thumbnailer_versions']);
117 }
118
119 120 121 122 123 124
125 static public function on_cache_collection_collect(CacheCollection\CollectEvent $event, CacheCollection $collection)
126 {
127 global $core;
128
129 $event->collection['thumbnails'] = new CacheManager();
130 }
131 }