data = array_merge( array( 'view_as' => 0, 'theme' => '', 'lang' => '', 'show_queries' => $conf['show_queries'], 'debug_l10n' => $conf['debug_l10n'], 'debug_template' => $conf['debug_template'], 'template_combine_files' => $conf['template_combine_files'], 'no_history' => false, ), pwg_get_session_var('multiview', array()) ); } /** * @return bool */ public function is_admin() { return $this->is_admin; } /** * @return array */ public function get_data() { return $this->data; } /** * @return array */ public function get_user() { return $this->user; } /** * Save $data in session */ private function save() { pwg_set_session_var('multiview', $this->data); } /** * Returns the current url minus MultiView params * * @param bool $with_amp - adds ? or & at the end of the url * @return string */ public function get_clean_url($with_amp=false) { if (script_basename() == 'picture') { $url = duplicate_picture_url(array(), array_keys($this->data)); } else if (script_basename() == 'index') { $url = duplicate_index_url(array(), array_keys($this->data)); } else { $url = get_query_string_diff(array_keys($this->data)); } if ($with_amp) { $url.= strpos($url, '?')!==false ? '&' : '?'; } return $url; } /** * Triggered on "user_init", change current view depending of URL params. */ public function user_init() { global $user, $conf; $this->is_admin = is_admin(); $this->user = array( 'id' => $user['id'], 'username' => $user['username'], ); if ($this->is_admin) { if ($this->data['view_as'] == 0) { $this->data['view_as'] = $user['id']; } if (empty($this->data['lang'])) { $this->data['lang'] = $user['language']; } if (empty($this->data['theme'])) { $this->data['theme'] = $user['theme']; } // view_as if (isset($_GET['ato_view_as'])) { $this->data['view_as'] = (int)$_GET['ato_view_as']; } if ($this->data['view_as'] != $user['id']) { $user = build_user($this->data['view_as'], true); $this->data['theme'] = $user['theme']; $this->data['lang'] = $user['language']; } // theme if (isset($_GET['ato_theme'])) { $this->data['theme'] = $_GET['ato_theme']; } $user['theme'] = $this->data['theme']; // lang if (isset($_GET['ato_lang'])) { $this->data['lang'] = $_GET['ato_lang']; } $user['language'] = $this->data['lang']; // show_queries if (isset($_GET['ato_show_queries'])) { $this->data['show_queries'] = (bool)$_GET['ato_show_queries']; } $conf['show_queries'] = $this->data['show_queries']; // debug_l10n if (isset($_GET['ato_debug_l10n'])) { $this->data['debug_l10n'] = (bool)$_GET['ato_debug_l10n']; } $conf['debug_l10n'] = $this->data['debug_l10n']; // debug_template if (isset($_GET['ato_debug_template'])) { $this->data['debug_template'] = (bool)$_GET['ato_debug_template']; } $conf['debug_template'] = $this->data['debug_template']; // template_combine_files if (isset($_GET['ato_template_combine_files'])) { $this->data['template_combine_files'] = (bool)$_GET['ato_template_combine_files']; } $conf['template_combine_files'] = $this->data['template_combine_files']; // no_history if (isset($_GET['ato_no_history'])) { $this->data['no_history'] = (bool)$_GET['ato_no_history']; } if ($this->data['no_history']) { add_event_handler('pwg_log_allowed', create_function('', 'return false;')); } $this->save(); } } /** * Triggered on "init", in order to clean template files (not initialized on "user_init") */ public function init() { if (isset($_GET['ato_purge_template'])) { global $template; $template->delete_compiled_templates(); FileCombiner::clear_combined_files(); } } }