Created
January 31, 2012 18:12
-
-
Save andyvanee/1711959 to your computer and use it in GitHub Desktop.
File uploads with nterchange ckeditor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CKEDITOR.editorConfig = function( config ) { | |
| // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.toolbar | |
| config.toolbar = [ | |
| ['Source', '-', 'Cut', 'Copy', 'PasteText', 'Link', 'Unlink'], | |
| ['Bold', 'Italic', 'NumberedList', 'BulletedList'], | |
| ['HorizontalRule', 'Table', 'Outdent', 'Indent', 'RemoveFormat'], | |
| ['Format', 'FontSize'] | |
| ]; | |
| config.uiColor = '#CCC'; | |
| config.skin = 'kama'; | |
| config.forcePasteAsPlainText = true; | |
| config.filebrowserUploadUrl = '/nterchange/media_element/ck_uploader'; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once 'app/controllers/asset_controller.php'; | |
| class MediaElementController extends AssetController { | |
| function __construct() { | |
| $this->name = 'media_element'; | |
| $this->versioning = true; | |
| $this->base_view_dir = ROOT_DIR; | |
| $this->login_required[] = 'ck_uploader'; | |
| parent::__construct(); | |
| } | |
| function ckUploader(){ | |
| if (defined('IN_NTERCHANGE')){ | |
| $funcNum = $_GET['CKEditorFuncNum']; | |
| // Optional: instance name (might be used to load a specific configuration file or anything else). | |
| $CKEditor = $_GET['CKEditor']; | |
| // Optional: might be used to provide localized messages. | |
| $langCode = $_GET['langCode']; | |
| $timestamp = date("YmdHis"); | |
| $fname = $timestamp.'/'.$_FILES['upload']['name']; | |
| $rel_path = '/upload/media_element/'.$fname; | |
| // Create a datestamped folder in upload/media_elemnt | |
| // Shouldn't collide with existing setup | |
| $dir = DOCUMENT_ROOT.'/upload/media_element/'.$timestamp; | |
| mkdir($dir); | |
| // Copy the temp file to the new path | |
| $path = DOCUMENT_ROOT.$rel_path; | |
| link($_FILES['upload']['tmp_name'], $path); | |
| // Create the media_element asset | |
| $m = $this->getDefaultModel(); | |
| $m->cms_headline = $fname; | |
| $m->media_file = $url; | |
| $m->link_title = $fname; | |
| $m->save(); | |
| // Usually you will only assign something here if the file could not be uploaded. | |
| $message = ''; | |
| echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$rel_path', '$message');</script>"; | |
| } | |
| } | |
| } | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uploads the file as a media element and returns the relative path to the file. Seems to work peachy!
Will add to the repo once I'm sure there's no loose ends. File browsing might be another story..