国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

YII視圖整合kindeditor擴展的方法

2020-03-22 19:08:54
字體:
供稿:網(wǎng)友
本文實例講述了YII視圖整合kindeditor擴展的方法。分享給大家供大家參考,具體如下:比較喜歡用kindeditor,YII上的版本比較舊,所以自己重新整了個擴展
先在protected/extensions下創(chuàng)建KEditor文件夾用來放文件,keSource里放kindeditor的源文件,然后建三個類KEditor、KEditorManage和KEditorUpload,KEditor是擴展的主文件,KEditorManage是用來瀏覽服務器文件的,KEditorUpload是用來示例接收上傳文件的,KEditor代碼html' target='_blank'>class KEditor extends CWidget{ * TEXTAREA輸入框的屬性,保證js調(diào)用KE失敗時,文本框的樣式。 public $textareaOptions=array(); * 編輯器屬性集。 public $properties=array(); * TEXTAREA輸入框的name,必須設(shè)置。 * 數(shù)據(jù)類型:String public $name; * TEXTAREA的id,可為空 public $id; public $model; public $baseUrl; public static function getUploadPath(){ $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'keSource'; if(isset(Yii::app()- params- uploadPath)){ return Yii::getPathOfAlias('webroot').str_replace( '/',DIRECTORY_SEPARATOR, Yii::app()- params- uploadPath); return Yii::app()- getAssetmanager() - getPublishedPath($dir).DIRECTORY_SEPARATOR.'upload'; public static function getUploadUrl(){ $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'keSource'; if(isset(Yii::app()- params- uploadPath)){ return Yii::app()- baseUrl.Yii::app()- params- uploadPath; return Yii::app()- getAssetManager()- publish($dir).'/upload'; public function init(){ if($this- name===null) throw new CException(Yii::t('zii','The id property cannot be empty.')); $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'keSource'; $this- baseUrl=Yii::app()- getAssetManager()- publish($dir); $cs=Yii::app()- getClientScript(); $cs- registerCssFile($this- baseUrl.'/themes/default/default.css'); if(YII_DEBUG) $cs- registerScriptFile($this- baseUrl.'/kindeditor.js'); else $cs- registerScriptFile($this- baseUrl.'/kindeditor-min.js'); public function run(){ $cs=Yii::app()- getClientScript(); $textAreaOptions=$this- gettextareaOptions(); $textAreaOptions['name']=CHtml::resolveName($this- model,$this- name); $this- id=$textAreaOptions['id']=CHtml::getIdByName($textAreaOptions['name']); echo CHtml::activeTextArea($this- model,$this- name,$textAreaOptions); $properties_string = CJavaScript::encode($this- getKeProperties()); $js= EOFKindEditor.ready(function(K) { var editor_$this- id = K.create('#$this- id',$properties_string $cs- registerScript('KE'.$this- name,$js,CClientScript::POS_HEAD); public function gettextareaOptions(){ //允許獲取的屬性 $allowParams=array('rows','cols','style'); //準備返回的屬性數(shù)組 $params=array(); foreach($allowParams as $key){ if(isset($this- textareaOptions[$key])) $params[$key]=$this- textareaOptions[$key]; $params['name']=$params['id']=$this- name; return $params; public function getKeProperties(){ $properties_key=array( 'width', 'height', 'minWidth', 'minHeight', 'items', 'noDisableItems', 'filterMode', 'htmlTags', 'wellFormatMode', 'resizeType', 'themeType', 'langType', 'designMode', 'fullscreenMode', 'basePath', 'themesPath', 'pluginsPath', 'langPath', 'minChangeSize', 'urlType', 'newlineTag', 'pasteType', 'dialogAlignType', 'shadowMode', 'useContextmenu', 'syncType', 'indentChar', 'cssPath', 'cssData', 'bodyClass', 'colorTable', 'afterCreate', 'afterChange', 'afterTab', 'afterFocus', 'afterBlur', 'afterUpload', 'uploadJson', 'fileManagerJson', 'allowPreviewEmoticons', 'allowImageUpload', 'allowFlashUpload', 'allowMediaUpload', 'allowFileUpload', 'allowFileManager', 'fontSizeTable', 'imageTabIndex', 'formatUploadUrl', 'fullscreenShortcut', 'extraFileUploadParams', //準備返回的屬性數(shù)組 $params=array(); foreach($properties_key as $key){ if(isset($this- properties[$key])) $params[$key]=$this- properties[$key]; return $params;KEditorManage代碼class KEditorManage extends CAction{ public function run(){ Yii::import('ext.KEditor.KEditor'); $root_path=KEditor::getUploadPath().'/'; $root_url=KEditor::getUploadUrl().'/'; //圖片擴展名 $ext_arr = array('gif', 'jpg', 'jpeg', 'png', 'bmp'); //目錄名 $dir_name = empty($_GET['dir']) '' : trim($_GET['dir']); if (!in_array($dir_name, array('', 'image', 'flash', 'media', 'file'))) { echo "Invalid Directory name."; exit; if ($dir_name !== '') { $root_path .= $dir_name . "/"; $root_url .= $dir_name . "/"; if (!file_exists($root_path)) { mkdir($root_path); //根據(jù)path參數(shù),設(shè)置各路徑和URL if (empty($_GET['path'])) { $current_path = realpath($root_path) . '/'; $current_url = $root_url; $current_dir_path = ''; $moveup_dir_path = ''; } else { $current_path = realpath($root_path) . '/' . $_GET['path']; $current_url = $root_url . $_GET['path']; $current_dir_path = $_GET['path']; $moveup_dir_path = preg_replace('/(.* )[^//]+//$/', '$1', $current_dir_path); echo realpath($root_path); //排序形式,name or size or type $order = empty($_GET['order']) 'name' : strtolower($_GET['order']); //不允許使用..移動到上一級目錄 if (preg_match('//././', $current_path)) { echo 'Access is not allowed.'; exit; //最后一個字符不是/ if (!preg_match('///$/', $current_path)) { echo 'Parameter is not valid.'; exit; //目錄不存在或不是目錄 if (!file_exists($current_path) || !is_dir($current_path)) { echo 'Directory does not exist.'; exit; //遍歷目錄取得文件信息 $file_list = array(); $handle = new DirectoryIterator($current_path); $i=0; foreach($handle as $file){ if($file- isDot()) continue; if($file- isDir()){ $file_list[$i]['is_dir'] = true; //是否文件夾 $file_list[$i]['has_file'] = (count(scandir($file- getPath())) //文件夾是否包含文件 $file_list[$i]['filesize'] = 0; //文件大小 $file_list[$i]['is_photo'] = false; //是否圖片 $file_list[$i]['filetype'] = ''; //文件類別,用擴展名判斷 }else{ $file_list[$i]['is_dir'] = false; $file_list[$i]['has_file'] = false; $file_list[$i]['filesize'] = $file- getSize(); $file_list[$i]['dir_path'] = ''; $file_ext = $file- getExtension(); $file_list[$i]['is_photo'] = in_array($file_ext, $ext_arr); $file_list[$i]['filetype'] = $file_ext; $file_list[$i]['filename'] = $file- getFilename(); //文件名,包含擴展名 $file_list[$i]['datetime'] = date('Y-m-d H:i:s', $file- getMTime()); $i++; usort($file_list, array($this,'cmp_func')); $result = array(); //相對于根目錄的上一級目錄 $result['moveup_dir_path'] = $moveup_dir_path; //相對于根目錄的當前目錄 $result['current_dir_path'] = $current_dir_path; //當前目錄的URL $result['current_url'] = $current_url; //文件數(shù) $result['total_count'] = count($file_list); //文件列表數(shù)組 $result['file_list'] = $file_list; //輸出JSON字符串 header('Content-type: application/json; charset=UTF-8'); echo CJSON::encode($result); exit; //排序 public function cmp_func($a, $b) { global $order; if ($a['is_dir'] && !$b['is_dir']) { return -1; } else if (!$a['is_dir'] && $b['is_dir']) { return 1; } else { if ($order == 'size') { if ($a['filesize'] $b['filesize']) { return 1; } else if ($a['filesize'] $b['filesize']) { return -1; } else { return 0; } else if ($order == 'type') { return strcmp($a['filetype'], $b['filetype']); } else { return strcmp($a['filename'], $b['filename']);

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 腾冲县| 苏州市| 合作市| 卢氏县| 铜梁县| 泽普县| 武宁县| 陇川县| 长宁区| 丹寨县| 文山县| 清苑县| 黎川县| 蒙山县| 清新县| 鹤壁市| 河东区| 台北县| 信宜市| 大同市| 屯昌县| 平顺县| 将乐县| 卓尼县| 丰宁| 玉田县| 沐川县| 玛纳斯县| 磐安县| 南通市| 湖州市| 穆棱市| 汉中市| 拜城县| 龙川县| 呼玛县| 桐柏县| 中牟县| 桂东县| 普兰县| 同仁县|