1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Element;
13
14 use ICanBoogie\Route;
15
16 use Brickrouge\A;
17 use Brickrouge\DropdownMenu;
18 use Brickrouge\Element;
19
20 class extends Element
21 {
22 public function __construct(array $attributes=array())
23 {
24 parent::__construct('div', $attributes);
25 }
26
27 public function render_inner_html()
28 {
29 global $core;
30
31 $user = $core->user;
32 $site = $core->site;
33
34 $site_title = \ICanBoogie\escape($site->admin_title);
35
36 if (!$site_title)
37 {
38 $site_title = \ICanBoogie\escape($site->title) . '<span class="language">:' . $site->language . '</span>';
39 }
40
41 $options = array();
42
43 try
44 {
45 $query = $core->models['sites']->order('admin_title, title');
46
47 $restricted_sites = $user->restricted_sites_ids;
48
49 if ($restricted_sites)
50 {
51 $query->where(array('siteid' => $restricted_sites));
52 }
53
54 $sites = $query->all;
55
56 if (count($sites) > 1)
57 {
58 $path = $core->request->decontextualized_path;
59
60 foreach ($sites as $asite)
61 {
62 $title = $asite->admin_title;
63
64 if (!$title)
65 {
66 $title = new Element('span', array(Element::INNER_HTML => $asite->title . '<span class="language">:' . $asite->language . '</span>'));
67 }
68
69 $options[$asite->siteid] = new A($title, $asite->url . $path . '?ssc=1');
70 }
71 }
72 }
73 catch (\Exception $e) { }
74
75 $menu = null;
76 $menu_toggler = null;
77
78 if ($options)
79 {
80 $menu = new DropdownMenu(array
81 (
82 DropdownMenu::OPTIONS => $options,
83
84 'value' => $site->siteid
85 ));
86
87 $menu_toggler = <<<EOT
88 <span class="dropdown-toggle" data-toggle="dropdown"><i class="icon-home icon-white"></i> <span class="caret"></span></span>
89 EOT;
90 }
91 else
92 {
93 $menu_toggler = <<<EOT
94 <i class="icon-home icon-white"></i>
95 EOT;
96 }
97
98 return <<<EOT
99 <div class="btn-group">
100 <a href="$site->url">$site_title</a>
101 $menu_toggler
102 $menu
103 </div>
104 EOT;
105 }
106 }