/** * 编辑器配置参数整理 * @return boolean */ private function _init_ueditor_config() { if (!$this->server_url) { $this->ueditor_error = L('_ERR_NOT_UEDITOR_SERVER_URL_'); return false; } if (!$this->ueditor_home_url) { $this->ueditor_error = L('_ERR_NOT_UEDITOR_HOME_URL_'); return false; } // 定义常用的默认配置 $defaults = array('serverUrl' => $this->server_url, 'toolbars' => '_normal', 'charset' => 'utf-8', 'lang' => 'zh-cn', 'initialContent' => '', 'autoClearinitialContent' => false, 'emotionLocalization' => true, 'pageBreakTag' => 'ueditor_page_break_tag', 'initialFrameHeight' => '300', 'textarea' => 'contents', 'elementPathEnabled' => false); // 载入默认的配置 foreach ($defaults as $var => $val) { if (!isset($this->ueditor_config[$var])) { $this->ueditor_config[$var] = $val; } } // 设置工具栏 if (is_scalar($this->ueditor_config['toolbars'])) { switch (rstrtolower($this->ueditor_config['toolbars'])) { case '_all': $this->ueditor_config['toolbars'] = array('fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|', 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|', 'directionalityltr', 'directionalityrtl', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|', 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|', 'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|', 'print', 'preview', 'searchreplace', 'help', 'drafts'); break; case '_min': $this->ueditor_config['toolbars'] = array('bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|', 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|'); break; case '_normal': $this->ueditor_config['toolbars'] = array('bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|', 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|'); break; case '_mobile': $this->ueditor_config['toolbars'] = array('source', '|', 'bold', 'italic', 'underline', 'removeformat', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'fontfamily', 'fontsize', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'link', 'unlink', 'insertimage', 'insertvideo'); break; case '_cyadmin': $this->ueditor_config['toolbars'] = array('source', '|', 'bold', 'italic', 'underline', 'removeformat', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'fontfamily', 'fontsize', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'link', 'unlink', 'insertimage', 'insertvideo'); break; case '_map': $this->ueditor_config['toolbars'] = array('source', 'map'); break; } } $this->ueditor_config['toolbars'] = array($this->ueditor_config['toolbars']); return true; }
/** * 获取文件 或 扩展名 的 mime 类型字符串 * @author Deepseath * @param string $filename 可以是文件名也可以是扩展名也可以使用文件绝对路径 * @return string */ function rmime_content_type($filename) { $mime_types = array('txt' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', 'php' => 'text/html', 'css' => 'text/css', 'js' => 'application/javascript', 'json' => 'application/json', 'xml' => 'application/xml', 'swf' => 'application/x-shockwave-flash', 'flv' => 'video/x-flv', 'png' => 'image/png', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'bmp' => 'image/bmp', 'ico' => 'image/vnd.microsoft.icon', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml', 'zip' => 'application/zip', 'rar' => 'application/x-rar-compressed', 'exe' => 'application/x-msdownload', 'msi' => 'application/x-msdownload', 'cab' => 'application/vnd.ms-cab-compressed', 'mp3' => 'audio/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'pdf' => 'application/pdf', 'psd' => 'image/vnd.adobe.photoshop', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'doc' => 'application/msword', 'rtf' => 'application/rtf', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'odt' => 'application/vnd.oasis.opendocument.text', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet'); if (strpos($filename, '.') !== false) { // 如果是文件名则取出其扩展名 $ext = rstrtolower(substr(strrchr($filename, '.'), 1, 10)); } else { // 如果是扩展名则直接使用 $ext = $filename; } // 待返回的 mime 字符串 $mime = ''; if (isset($mime_types[$ext])) { // 已定义的扩展名mime $mime = $mime_types[$ext]; } elseif (is_file($filename)) { // 给出的参数是一个文件路径 if (function_exists('finfo_open')) { // 如果是一个文件路径 且 内置函数 finfo_open 可用(fileinfo扩展可用) $finfo = finfo_open(FILEINFO_MIME); $mime = finfo_file($finfo, $filename); finfo_close($finfo); } // 如果上面未取到 $mime if (!$mime && function_exists('mime_content_type') && ($tmp = mime_content_type($filename))) { // 尝试使用内置函数 mime_content_type 来获取(fileinfo扩展可用) $mime = $tmp; unset($tmp); } if ($mime && stripos($mime, ';') !== false) { // 剔除字符集信息 $mime = trim(preg_replace('/;.+?$/', '', $mime)); } } if (!$mime) { // 如果以上操作均未获取到,则认为是普通未知文件 $mime = 'application/octet-stream'; } return $mime; }