active_filename = $base_path.'/opac_css/temp/.maintenance'; $this->content_filename = $base_path.'/opac_css/temp/maintenance.html'; } public function fetch_data() { $this->active = false; if (file_exists($this->active_filename)) { $this->active = true; } $this->fetch_content(); } public function get_form() { global $maintenance_page_content_form; $content_form = $maintenance_page_content_form; $interface_form = new interface_form('admin_opac_maintenance_form'); $checked = ''; if ($this->active) { $checked = 'checked="checked"'; } $content_form = str_replace('!!maintenance_page_activate_checked!!', $checked, $content_form); $content_form = str_replace('!!maintenance_page_content_title!!', $this->content['title'], $content_form); $content_form = str_replace('!!maintenance_page_content_body!!', $this->content['body'], $content_form); $content_form = str_replace('!!maintenance_page_content_style!!', $this->content['style'], $content_form); $interface_form->set_content_form($content_form); return $interface_form->get_display(); } public function get_values_from_form() { global $maintenance_page_activate; global $maintenance_page_content_body; global $maintenance_page_content_title; global $maintenance_page_content_style; $this->active = ($maintenance_page_activate*1 ? true : false); $this->content['body'] = stripslashes($maintenance_page_content_body); $this->content['title'] = stripslashes($maintenance_page_content_title); $this->content['style'] = stripslashes($maintenance_page_content_style); } public function save() { if ($this->active && !file_exists($this->active_filename)) { touch($this->active_filename); } if (!$this->active && file_exists($this->active_filename)) { unlink($this->active_filename); } file_put_contents($this->content_filename, $this->build_page()); } protected function fetch_content() { $this->content = array(); if (file_exists($this->content_filename)) { $html = file_get_contents($this->content_filename); $matches = array(); preg_match('/(.*)<\/title>/s', $html, $matches); $this->content['title'] = $matches[1]; preg_match('/<style>(.*)<\/style>/s', $html, $matches); $this->content['style'] = trim($matches[1]); preg_match('/<body>(.*)<\/body>/s', $html, $matches); $this->content['body'] = trim($matches[1]); } else { // Le fichier n'existe pas encore ou a été effacé, on va chercher le contenu par défaut global $maintenance_page_default_content, $msg; $this->content['body'] = $maintenance_page_default_content; $this->content['title'] = $msg['admin_opac_maintenance']; $this->content['style'] = ''; } } protected function build_page() { global $charset; $html = '<!DOCTYPE html> <html> <head> <meta charset="'.$charset.'" /> <title>'.$this->content['title'].' '.$this->content['body'].' '; return $html; } public function activate() { $this->active = true; if (!file_exists($this->active_filename)) { touch($this->active_filename); } file_put_contents($this->content_filename, $this->build_page()); } public function disable() { $this->active = false; if (file_exists($this->active_filename)) { unlink($this->active_filename); } file_put_contents($this->content_filename, $this->build_page()); } public function set_content($content) { $this->content = $content; } }