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

Last change on this file since 25791 was 25791, checked in by mistic100, 10 years ago

fix security problem, fix sql fatal error, try to fix display on smartpocket

File size: 4.7 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    // inactive on ws.php to allow AJAX admin tasks
116    if ($this->is_admin && script_basename() != 'ws')
117    {
118      if ($this->data['view_as'] == 0)
119      {
120        $this->data['view_as'] = $user['id'];
121      }
122      if (empty($this->data['lang']))
123      {
124        $this->data['lang'] = $user['language'];
125      }
126      if (empty($this->data['theme']))
127      {
128        $this->data['theme'] = $user['theme'];
129      }
130
131      // view_as
132      if (isset($_GET['ato_view_as']))
133      {
134        $this->data['view_as'] = (int)$_GET['ato_view_as'];
135      }
136      if ($this->data['view_as'] != $user['id'])
137      {
138        $user = build_user($this->data['view_as'], true);
139        $this->data['theme'] = $user['theme'];
140        $this->data['lang'] = $user['language'];
141      }
142
143      // theme
144      if (isset($_GET['ato_theme']))
145      {
146        $this->data['theme'] = $_GET['ato_theme'];
147      }
148      $user['theme'] = $this->data['theme'];
149
150      // lang
151      if (isset($_GET['ato_lang']))
152      {
153        $this->data['lang'] = $_GET['ato_lang'];
154      }
155      $user['language'] = $this->data['lang'];
156
157      // show_queries
158      if (isset($_GET['ato_show_queries']))
159      {
160        $this->data['show_queries'] = (bool)$_GET['ato_show_queries'];
161      }
162      $conf['show_queries'] = $this->data['show_queries'];
163
164      // debug_l10n
165      if (isset($_GET['ato_debug_l10n']))
166      {
167        $this->data['debug_l10n'] = (bool)$_GET['ato_debug_l10n'];
168      }
169      $conf['debug_l10n'] = $this->data['debug_l10n'];
170
171      // debug_template
172      if (isset($_GET['ato_debug_template']))
173      {
174        $this->data['debug_template'] = (bool)$_GET['ato_debug_template'];
175      }
176      $conf['debug_template'] = $this->data['debug_template'];
177
178      // template_combine_files
179      if (isset($_GET['ato_template_combine_files']))
180      {
181        $this->data['template_combine_files'] = (bool)$_GET['ato_template_combine_files'];
182      }
183      $conf['template_combine_files'] = $this->data['template_combine_files'];
184
185      // no_history
186      if (isset($_GET['ato_no_history']))
187      {
188        $this->data['no_history'] = (bool)$_GET['ato_no_history'];
189      }
190      if ($this->data['no_history'])
191      {
192        add_event_handler('pwg_log_allowed', create_function('', 'return false;'));
193      }
194
195      $this->save();
196    }
197  }
198
199  /**
200   * Triggered on "init", in order to clean template files (not initialized on "user_init")
201   */
202  public function init()
203  {
204    if ($this->is_admin)
205    {
206      if (isset($_GET['ato_purge_template']))
207      {
208        global $template;
209        $template->delete_compiled_templates();
210        FileCombiner::clear_combined_files();
211      }
212    }
213  }
214}
Note: See TracBrowser for help on using the repository browser.