source: extensions/AdminTools/include/MultiView.class.php @ 25693

Last change on this file since 25693 was 25655, checked in by mistic100, 11 years ago

quick edit for album
add language files
force default language for the toolbar
fix $_GET collision
orange save button
fix popup background color

File size: 4.6 KB
Line 
1<?php
2defined('ADMINTOOLS_PATH') or die('Hacking attempt!');
3
4/**
5 * Class managing multi views system
6 */
7class MultiView
8{
9  /** @var bool $is_admin */
10  private $is_admin = false;
11
12  /** @var array $data */
13  private $data = array();
14
15  /** @var array $user */
16  private $user = array();
17
18  /**
19   * Constructor, load $data from session
20   */
21  function __construct()
22  {
23    global $conf;
24
25    $this->data = array_merge(
26      array(
27        'view_as' => 0,
28        'theme' => '',
29        'lang' => '',
30        'show_queries' => $conf['show_queries'],
31        'debug_l10n' => $conf['debug_l10n'],
32        'debug_template' => $conf['debug_template'],
33        'template_combine_files' => $conf['template_combine_files'],
34        'no_history' => false,
35        ),
36      pwg_get_session_var('multiview', array())
37      );
38  }
39
40  /**
41   * @return bool
42   */
43  public function is_admin()
44  {
45    return $this->is_admin;
46  }
47
48  /**
49   * @return array
50   */
51  public function get_data()
52  {
53    return $this->data;
54  }
55
56  /**
57   * @return array
58   */
59  public function get_user()
60  {
61    return $this->user;
62  }
63
64  /**
65   * Save $data in session
66   */
67  private function save()
68  {
69    pwg_set_session_var('multiview', $this->data);
70  }
71
72  /**
73   * Returns the current url minus MultiView params
74   *
75   * @param bool $with_amp - adds ? or & at the end of the url
76   * @return string
77   */
78  public function get_clean_url($with_amp=false)
79  {
80    if (script_basename() == 'picture')
81    {
82      $url = duplicate_picture_url(array(), array_keys($this->data));
83    }
84    else if (script_basename() == 'index')
85    {
86      $url = duplicate_index_url(array(), array_keys($this->data));
87    }
88    else
89    {
90      $url = get_query_string_diff(array_keys($this->data));
91    }
92
93    if ($with_amp)
94    {
95      $url.= strpos($url, '?')!==false ? '&' : '?';
96    }
97
98    return $url;
99  }
100
101  /**
102   * Triggered on "user_init", change current view depending of URL params.
103   */
104  public function user_init()
105  {
106    global $user, $conf;
107
108    $this->is_admin = is_admin();
109
110    $this->user = array(
111      'id' => $user['id'],
112      'username' => $user['username'],
113      );
114
115    if ($this->is_admin)
116    {
117      if ($this->data['view_as'] == 0)
118      {
119        $this->data['view_as'] = $user['id'];
120      }
121      if (empty($this->data['lang']))
122      {
123        $this->data['lang'] = $user['language'];
124      }
125      if (empty($this->data['theme']))
126      {
127        $this->data['theme'] = $user['theme'];
128      }
129
130      // view_as
131      if (isset($_GET['ato_view_as']))
132      {
133        $this->data['view_as'] = (int)$_GET['ato_view_as'];
134      }
135      if ($this->data['view_as'] != $user['id'])
136      {
137        $user = build_user($this->data['view_as'], true);
138        $this->data['theme'] = $user['theme'];
139        $this->data['lang'] = $user['language'];
140      }
141
142      // theme
143      if (isset($_GET['ato_theme']))
144      {
145        $this->data['theme'] = $_GET['ato_theme'];
146      }
147      $user['theme'] = $this->data['theme'];
148
149      // lang
150      if (isset($_GET['ato_lang']))
151      {
152        $this->data['lang'] = $_GET['ato_lang'];
153      }
154      $user['language'] = $this->data['lang'];
155
156      // show_queries
157      if (isset($_GET['ato_show_queries']))
158      {
159        $this->data['show_queries'] = (bool)$_GET['ato_show_queries'];
160      }
161      $conf['show_queries'] = $this->data['show_queries'];
162
163      // debug_l10n
164      if (isset($_GET['ato_debug_l10n']))
165      {
166        $this->data['debug_l10n'] = (bool)$_GET['ato_debug_l10n'];
167      }
168      $conf['debug_l10n'] = $this->data['debug_l10n'];
169
170      // debug_template
171      if (isset($_GET['ato_debug_template']))
172      {
173        $this->data['debug_template'] = (bool)$_GET['ato_debug_template'];
174      }
175      $conf['debug_template'] = $this->data['debug_template'];
176
177      // template_combine_files
178      if (isset($_GET['ato_template_combine_files']))
179      {
180        $this->data['template_combine_files'] = (bool)$_GET['ato_template_combine_files'];
181      }
182      $conf['template_combine_files'] = $this->data['template_combine_files'];
183
184      // no_history
185      if (isset($_GET['ato_no_history']))
186      {
187        $this->data['no_history'] = (bool)$_GET['ato_no_history'];
188      }
189      if ($this->data['no_history'])
190      {
191        add_event_handler('pwg_log_allowed', create_function('', 'return false;'));
192      }
193
194      $this->save();
195    }
196  }
197
198  /**
199   * Triggered on "init", in order to clean template files (not initialized on "user_init")
200   */
201  public function init()
202  {
203    if (isset($_GET['ato_purge_template']))
204    {
205      global $template;
206      $template->delete_compiled_templates();
207      FileCombiner::clear_combined_files();
208    }
209  }
210}
Note: See TracBrowser for help on using the repository browser.