public function __construct() { parent::__construct(); //$this->output->enable_profiler(TRUE); //check if config file is empty or it's not empty but script is not installed if ((is_db_conf_empty() || !is_installed()) && !defined('CS_EXTERNAL')) { redirect("setup/index"); } //load database, datamapper and login manager $this->load->database(); $this->load->library('datamapper'); $this->load->library('translate'); $this->load->library('loginmanager'); //hack for datamapper prefix DataMapper::$config['prefix'] = $this->db->dbprefix; //set web site name in title $this->templatemanager->set_title(Setting::value('website_title', CS_PRODUCT_NAME)); //test if should save uri $should = true; if ($this instanceof Process) { $uri = $path = trim($this->uri->uri_string()); $file = new File(); $file->path = $path; $mime = $file->mime_type(); if ($mime !== 'text/html') { $should = false; } } //set current url for auth controller to know where to redirect if (!$this instanceof Auth && !$this instanceof JS && !$this->is_ajax_request() && $should) { $this->loginmanager->set_redirect(current_url()); } //set time zone date_default_timezone_set(Setting::value('default_time_zone', 'Europe/Belgrade')); //set language $sess_lang = $this->session->userdata('lang'); if (!empty($sess_lang)) { if (is_numeric($sess_lang)) { $lang = Language::factory()->get_by_id((int) $sess_lang)->name; } else { $lang = $sess_lang; } } else { $lang = Setting::value('default_language', 'English'); } $this->translate->set_language($lang); //fetch user from the database if logged in if ($this->loginmanager->is_logged_in()) { $this->user = User::factory($this->loginmanager->user->id); $this->templatemanager->assign('user', $this->user); } $this->templatemanager->set_template_name($this->in_admin() ? "administration" : ""); if ($this->in_admin() && isset($_GET['iu-popup'])) { $this->templatemanager->popup(); } }
private function _body_attachment() { if (!$this->_has_attachment) { return NULL; } foreach ($this->_attachment as $path => $file) { $attach_data[] = sprintf('--%s', $this->_boundary); $attach_data[] = sprintf('Content-Type: %s; name="%s"', File::mime_type($file) ?: 'application/octet-stream', $file); $attach_data[] = 'Content-Transfer-Encoding: base64'; $attach_data[] = 'Content-Disposition: attachment'; $attach_data[] = sprintf('filename="%s"', $file); $attach_data[] = NULL; //需要占位,这样mail发送才能正常进行解析附件 $attach_data[] = chunk_split(@base64_encode(@file_get_contents($path))); $attach_data[] = NULL; } return join("\n", $attach_data); }
public function test_mime_type() { $file = new File("/tmp/test.txt"); $mime = $file->mime_type(); FuzzyTest::assert_equal($mime, "text/plain", "Wrong mime type"); }