1 | <?php |
---|
2 | defined('ADMINTOOLS_ID') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | class MultiView |
---|
5 | { |
---|
6 | private $is_admin; |
---|
7 | |
---|
8 | private $data = array(); |
---|
9 | |
---|
10 | function __construct() |
---|
11 | { |
---|
12 | global $conf; |
---|
13 | |
---|
14 | $this->data = array_merge( |
---|
15 | array( |
---|
16 | 'view_as' => 0, |
---|
17 | 'theme' => '', |
---|
18 | 'lang' => '', |
---|
19 | 'show_queries' => $conf['show_queries'], |
---|
20 | 'debug_l10n' => $conf['debug_l10n'], |
---|
21 | 'debug_template' => $conf['debug_template'], |
---|
22 | 'template_combine_files' => $conf['template_combine_files'], |
---|
23 | 'no_history' => false, |
---|
24 | 'purge_template' => false, |
---|
25 | ), |
---|
26 | pwg_get_session_var('multiview', array()) |
---|
27 | ); |
---|
28 | } |
---|
29 | |
---|
30 | public function is_admin() |
---|
31 | { |
---|
32 | return $this->is_admin; |
---|
33 | } |
---|
34 | |
---|
35 | public function get_data() |
---|
36 | { |
---|
37 | return $this->data; |
---|
38 | } |
---|
39 | |
---|
40 | private function save() |
---|
41 | { |
---|
42 | pwg_set_session_var('multiview', $this->data); |
---|
43 | } |
---|
44 | |
---|
45 | public function get_clean_url($with_amp=false) |
---|
46 | { |
---|
47 | if (script_basename() == 'picture') |
---|
48 | { |
---|
49 | $url = duplicate_picture_url(array(), array_keys($this->data)); |
---|
50 | } |
---|
51 | else if (script_basename() == 'index') |
---|
52 | { |
---|
53 | $url = duplicate_index_url(array(), array_keys($this->data)); |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | $url = get_query_string_diff(array_keys($this->data)); |
---|
58 | } |
---|
59 | |
---|
60 | if ($with_amp) |
---|
61 | { |
---|
62 | $url.= strpos($url, '?')!==false ? '&' : '?'; |
---|
63 | } |
---|
64 | |
---|
65 | return $url; |
---|
66 | } |
---|
67 | |
---|
68 | public function user_init() |
---|
69 | { |
---|
70 | $this->is_admin = is_admin(); |
---|
71 | |
---|
72 | if ($this->is_admin) |
---|
73 | { |
---|
74 | global $user, $conf; |
---|
75 | |
---|
76 | $this->data['view_as'] = $user['id']; |
---|
77 | $this->data['theme'] = $user['theme']; |
---|
78 | $this->data['lang'] = $user['language']; |
---|
79 | |
---|
80 | $refresh = false; |
---|
81 | |
---|
82 | // view_as |
---|
83 | if (isset($_GET['view_as'])) |
---|
84 | { |
---|
85 | $this->data['view_as'] = (int)$_GET['view_as']; |
---|
86 | } |
---|
87 | if ($this->data['view_as'] != $user['id']) |
---|
88 | { |
---|
89 | $user = build_user($this->data['view_as'], true); |
---|
90 | $this->data['theme'] = $user['theme']; |
---|
91 | $this->data['lang'] = $user['language']; |
---|
92 | } |
---|
93 | |
---|
94 | // theme |
---|
95 | if (isset($_GET['theme'])) |
---|
96 | { |
---|
97 | $this->data['theme'] = $_GET['theme']; |
---|
98 | } |
---|
99 | $user['theme'] = $this->data['theme']; |
---|
100 | |
---|
101 | // lang |
---|
102 | if (isset($_GET['lang'])) |
---|
103 | { |
---|
104 | $this->data['lang'] = $_GET['lang']; |
---|
105 | } |
---|
106 | $user['language'] = $this->data['lang']; |
---|
107 | |
---|
108 | // show_queries |
---|
109 | if (isset($_GET['show_queries'])) |
---|
110 | { |
---|
111 | $this->data['show_queries'] = (bool)$_GET['show_queries']; |
---|
112 | } |
---|
113 | $conf['show_queries'] = $this->data['show_queries']; |
---|
114 | |
---|
115 | // debug_l10n |
---|
116 | if (isset($_GET['debug_l10n'])) |
---|
117 | { |
---|
118 | $this->data['debug_l10n'] = (bool)$_GET['debug_l10n']; |
---|
119 | } |
---|
120 | $conf['debug_l10n'] = $this->data['debug_l10n']; |
---|
121 | |
---|
122 | // debug_template |
---|
123 | if (isset($_GET['debug_template'])) |
---|
124 | { |
---|
125 | $this->data['debug_template'] = (bool)$_GET['debug_template']; |
---|
126 | } |
---|
127 | $conf['debug_template'] = $this->data['debug_template']; |
---|
128 | |
---|
129 | // template_combine_files |
---|
130 | if (isset($_GET['template_combine_files'])) |
---|
131 | { |
---|
132 | $this->data['template_combine_files'] = (bool)$_GET['template_combine_files']; |
---|
133 | } |
---|
134 | $conf['template_combine_files'] = $this->data['template_combine_files']; |
---|
135 | |
---|
136 | // no_history |
---|
137 | if (isset($_GET['no_history'])) |
---|
138 | { |
---|
139 | $this->data['no_history'] = (bool)$_GET['no_history']; |
---|
140 | } |
---|
141 | if ($this->data['no_history']) |
---|
142 | { |
---|
143 | add_event_handler('pwg_log_allowed', create_function('', 'return false;')); |
---|
144 | } |
---|
145 | |
---|
146 | // purge_template |
---|
147 | if (isset($_GET['purge_template'])) |
---|
148 | { |
---|
149 | $this->data['purge_template'] = true; |
---|
150 | $refresh = true; |
---|
151 | } |
---|
152 | |
---|
153 | $this->save(); |
---|
154 | |
---|
155 | if ($refresh) |
---|
156 | { |
---|
157 | redirect($this->get_clean_url()); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | public function init() |
---|
163 | { |
---|
164 | // can't know if user is admin, not build yet |
---|
165 | // so only do non-critical tasks only |
---|
166 | |
---|
167 | if ($this->data['purge_template']) |
---|
168 | { |
---|
169 | global $template; |
---|
170 | $template->delete_compiled_templates(); |
---|
171 | FileCombiner::clear_combined_files(); |
---|
172 | |
---|
173 | $this->data['purge_template'] = false; |
---|
174 | $this->save(); |
---|
175 | } |
---|
176 | } |
---|
177 | } |
---|