1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Sites;
13
14 15 16
17 class ManageBlock extends \Icybee\ManageBlock
18 {
19 static public function add_assets(\Brickrouge\Document $document)
20 {
21 parent::add_assets($document);
22
23 $document->css->add(DIR . 'public/admin.css');
24 $document->js->add(DIR . 'public/admin.js');
25 }
26
27 public function __construct($module, array $attributes=array())
28 {
29 global $core;
30
31 parent::__construct
32 (
33 $module, $attributes + array
34 (
35 self::T_ORDER_BY => array('updated_at', 'desc'),
36 self::T_COLUMNS_ORDER => array('title', 'url', 'language', 'timezone', 'updated_at', 'status')
37 )
38 );
39 }
40
41 42 43 44 45 46 47 48 49 50
51 protected function get_available_columns()
52 {
53 return array_merge(parent::get_available_columns(), array
54 (
55 'title' => __CLASS__ . '\TitleColumn',
56 'url' => __CLASS__ . '\URLColumn',
57 'language' => __CLASS__ . '\LanguageColumn',
58 'status' => __CLASS__ . '\StatusColumn',
59 'timezone' => __CLASS__ . '\TimezoneColumn',
60 'updated_at' => 'Icybee\ManageBlock\DateTimeColumn'
61 ));
62 }
63 }
64
65 namespace Icybee\Modules\Sites\ManageBlock;
66
67 use Brickrouge\DropdownMenu;
68
69 use Icybee\ManageBlock\Column;
70 use Icybee\Modules\Sites\Site;
71 use Icybee\ManageBlock\FilterDecorator;
72 use Icybee\ManageBlock\EditDecorator;
73
74
75
76 class TitleColumn extends Column
77 {
78 public function render_cell($record)
79 {
80 return new EditDecorator($record->title, $record);
81 }
82 }
83
84 85 86
87 class StatusColumn extends Column
88 {
89 public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
90 {
91 parent::__construct
92 (
93 $manager, $id, $options + array
94 (
95 'title' => 'Status'
96 )
97 );
98 }
99
100 public function render_cell($record)
101 {
102 static $labels = array
103 (
104 Site::STATUS_OK => 'Ok (online)',
105 Site::STATUS_UNAUTHORIZED => 'Unauthorized',
106 Site::STATUS_NOT_FOUND => 'Not found (offline)',
107 Site::STATUS_UNAVAILABLE => 'Unavailable'
108 );
109
110 static $classes = array
111 (
112 Site::STATUS_OK => 'btn-success',
113 Site::STATUS_UNAUTHORIZED => 'btn-warning',
114 Site::STATUS_NOT_FOUND => 'btn-danger',
115 Site::STATUS_UNAVAILABLE => 'btn-warning'
116 );
117
118 $status = $record->status;
119 $status_label = isset($labels[$status]) ? $labels[$status] : "<em>Invalid status code: $status</em>";
120 $status_class = isset($classes[$status]) ? $classes[$status] : 'btn-danger';
121 $site_id = $record->siteid;
122
123 $menu = new DropdownMenu
124 (
125 array
126 (
127 DropdownMenu::OPTIONS => $labels,
128
129 'value' => $status
130 )
131 );
132
133 $classes_json = \Brickrouge\escape(json_encode($classes));
134
135 return <<<EOT
136 <div class="btn-group" data-property="status" data-site-id="$site_id" data-classes="$classes_json">
137 <span class="btn $status_class dropdown-toggle" data-toggle="dropdown"><span class="text">$status_label</span> <span class="caret"></span></span>
138 $menu
139 </div>
140 EOT;
141 }
142 }
143
144 145 146
147 class URLColumn extends Column
148 {
149 public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
150 {
151 parent::__construct
152 (
153 $manager, $id, $options + array
154 (
155 'orderable' => false
156 )
157 );
158 }
159
160 public function render_cell($record)
161 {
162 $parts = explode('.', $_SERVER['SERVER_NAME']);
163 $parts = array_reverse($parts);
164
165 if ($record->tld)
166 {
167 $parts[0] = '<strong>' . $record->tld . '</strong>';
168 }
169
170 if ($record->domain)
171 {
172 $parts[1] = '<strong>' . $record->domain . '</strong>';
173 }
174
175 if ($record->subdomain)
176 {
177 $parts[2] = '<strong>' . $record->subdomain . '</strong>';
178 }
179 else if (empty($parts[2]))
180 {
181 unset($parts[2]);
182 }
183
184 $label = 'http://' . implode('.', array_reverse($parts)) . ($record->path ? '<strong>' . $record->path . '</strong>' : '');
185
186 return '<a href="' . $record->url . '">' . $label . '</a>';
187 }
188 }
189
190 191 192
193 class TimezoneColumn extends Column
194 {
195 public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
196 {
197 parent::__construct
198 (
199 $manager, $id, $options + array
200 (
201 'discreet' => true
202 )
203 );
204 }
205
206 public function render_cell($record)
207 {
208 $timezone = $record->timezone;
209
210 if (!$timezone)
211 {
212 return '<em title="Inherited from the server\'s configuration" class="light">' . date_default_timezone_get() . '</em>';
213 }
214
215 return new FilterDecorator($record, $this->id, $this->manager->is_filtering($this->id));
216 }
217 }
218
219 220 221
222 class LanguageColumn extends Column
223 {
224 public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
225 {
226 parent::__construct
227 (
228 $manager, $id, $options + array
229 (
230 'discreet' => true
231 )
232 );
233 }
234
235 public function render_cell($record)
236 {
237 global $core;
238
239 $property = $this->id;
240
241 return new FilterDecorator
242 (
243 $record,
244 $property,
245 $this->manager->is_filtering($property),
246 \ICanBoogie\capitalize($core->locale['languages'][$record->$property])
247 );
248 }
249 }