├── .gitignore ├── .gitmodules ├── GruntFile.js ├── LICENSE ├── README.md ├── SirTrevorConverter.php ├── SirTrevorWidget.php ├── assets └── SirTrevorAsset.php ├── bower.json ├── composer.json ├── package.json └── web ├── dist ├── scripts │ ├── blocks-yii2-sirtrevorjs-0.0.5.js │ ├── lib │ │ └── vendor-yii2-sirtrevorjs-0.0.5.js │ ├── locales │ │ ├── cn.js │ │ ├── de.js │ │ ├── es.js │ │ ├── fi.js │ │ ├── fr.js │ │ └── pt.js │ └── yii2-sirtrevorjs-0.0.5.min.js └── styles │ ├── yii2-sirtrevorjs-0.0.5.css │ └── yii2-sirtrevorjs-0.0.5.min.css ├── scripts ├── blocks │ ├── CodeBlock.js │ ├── ColumnsBlock.js │ ├── Gallery.js │ ├── ImageCaption.js │ └── ImageExtended.js └── lib │ ├── Eventable │ └── eventable.js │ ├── sir-trevor-js │ └── sir-trevor.js │ └── underscore │ └── underscore.js ├── scss ├── _variables.scss └── main.scss └── styles ├── sir-trevor-icons.css └── sir-trevor.css /.gitignore: -------------------------------------------------------------------------------- 1 | # Include your project-specific ignores in this file 2 | # Read about how to use .gitignore: https://help.github.com/articles/ignoring-files 3 | # Compiled source # 4 | ################### 5 | *.com 6 | #*.class 7 | *.dll 8 | *.exe 9 | *.o 10 | *.so 11 | 12 | # Packages # 13 | ############ 14 | # it's better to unpack these files and commit the raw source 15 | # git has its own built in compression methods 16 | *.7z 17 | *.dmg 18 | *.gz 19 | *.iso 20 | *.jar 21 | *.rar 22 | *.tar 23 | *.zip 24 | 25 | # Logs and databases # 26 | ###################### 27 | *.log 28 | *.sql 29 | *.sqlite 30 | 31 | # OS generated files # 32 | ###################### 33 | .DS_Store 34 | .DS_Store? 35 | ._* 36 | .Spotlight-V100 37 | .Trashes 38 | ehthumbs.db 39 | Thumbs.db 40 | 41 | 42 | #Composer 43 | ######### 44 | composer.phar 45 | vendor 46 | composer.lock 47 | 48 | #Compass 49 | ######### 50 | .sass-cache 51 | 52 | # Node 53 | ######### 54 | lib-cov 55 | lcov.info 56 | *.seed 57 | *.log 58 | *.csv 59 | *.dat 60 | *.out 61 | *.pid 62 | *.gz 63 | 64 | pids 65 | logs 66 | results 67 | build 68 | .grunt 69 | 70 | node_modules 71 | bower_components 72 | 73 | # PHPSTORM 74 | ######### 75 | .idea 76 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sir-trevor"] 2 | path = sir-trevor 3 | url = git@github.com:DrMabuse23/sir-trevor-js.git 4 | -------------------------------------------------------------------------------- /GruntFile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | 3 | // Project configuration. 4 | grunt.initConfig({ 5 | bower: 'bower_components/', 6 | dist: 'web/dist', 7 | web: 'web', 8 | pkg: grunt.file.readJSON('package.json'), 9 | clean:{ 10 | dist:["<%= dist %>"] 11 | }, 12 | replace: { 13 | readme: { 14 | src: ['README.md'], 15 | overwrite: true, 16 | replacements: [ 17 | { 18 | from: /Version \d{1,1}\.\d{1,2}\.\d{1,2}/g, 19 | to: 'Version <%= pkg.version %>' 20 | } 21 | ] 22 | }, 23 | sirtrevorwidget_php: { 24 | src: ['SirTrevorWidget.php'], 25 | overwrite: true, 26 | replacements: [ 27 | { 28 | from: /\d{1,1}\.\d{1,2}\.\d{1,2}/g, 29 | to: '<%= pkg.version %>' 30 | } 31 | ] 32 | }, 33 | asset_php: { 34 | src: ['assets/SirTrevorAsset.php'], 35 | overwrite: true, 36 | replacements: [ 37 | { 38 | from: /dist\/styles\/yii2-sirtrevorjs-\d{1,1}\.\d{1,2}\.\d{1,2}/g, 39 | to: 'dist/styles/yii2-sirtrevorjs-<%= pkg.version %>' 40 | } 41 | ] 42 | }, 43 | asset_php_js: { 44 | src: ['assets/SirTrevorAsset.php'], 45 | overwrite: true, 46 | replacements: [ 47 | { 48 | from: /dist\/scripts\/yii2-sirtrevorjs-\d{1,1}\.\d{1,2}\.\d{1,2}/g, 49 | to: 'dist/scripts/yii2-sirtrevorjs-<%= pkg.version %>' 50 | } 51 | ] 52 | } 53 | }, 54 | uglify: { 55 | options: { 56 | banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n', 57 | report: 'min', 58 | beautify: { 59 | width: 80, 60 | beautify: true 61 | }, 62 | compress: { 63 | drop_console:true 64 | } 65 | }, 66 | vendor: { 67 | src: [ 68 | '<%= dist %>/scripts/lib/vendor-<%= pkg.name %>-<%= pkg.version %>.js', 69 | '<%= dist %>/scripts/blocks-<%= pkg.name %>-<%= pkg.version %>.js' 70 | ], 71 | dest: '<%= dist %>/scripts/<%= pkg.name %>-<%= pkg.version %>.min.js' 72 | } 73 | }, 74 | cssmin: { 75 | add_banner: { 76 | options: { 77 | banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' 78 | }, 79 | files: { 80 | '<%= dist %>/styles/<%= pkg.name %>-<%= pkg.version %>.min.css': [ 'web/styles/*.css'] 81 | } 82 | } 83 | }, 84 | bumpup: { 85 | options: { 86 | dateformat: 'YYYY-MM-DD HH:mm', 87 | normalize: false 88 | }, 89 | files: ['package.json', 'composer.json', 'bower.json'] 90 | }, 91 | copy: { 92 | locales: { 93 | files: [ 94 | { 95 | expand: true, 96 | cwd:'<%= bower %>/sir-trevor-js/locales', 97 | src: ['**'], 98 | dest: '<%= dist %>/scripts/locales', 99 | filter: 'isFile' 100 | } 101 | ] 102 | }, 103 | styles: { 104 | files: [ 105 | { 106 | expand: true, 107 | cwd:'<%= bower %>/sir-trevor-js', 108 | src: ['*.css'], 109 | dest: '<%= web %>/styles', 110 | filter: 'isFile' 111 | } 112 | ] 113 | }, 114 | vendor:{ 115 | files:[ 116 | { 117 | expand: true, 118 | cwd: '<%= bower %>', 119 | src: [ 120 | 'underscore/underscore.js', 121 | 'Eventable/eventable.js', 122 | 'sir-trevor-js/sir-trevor.js' 123 | ], 124 | dest: '<%= web %>/scripts/lib', 125 | filter: 'isFile' 126 | } 127 | ] 128 | } 129 | 130 | }, 131 | concat: { 132 | options: { 133 | }, 134 | vendor: { 135 | src: [ 136 | '<%= bower %>/underscore/underscore.js', 137 | '<%= bower %>/Eventable/eventable.js', 138 | '<%= bower %>/sir-trevor-js/sir-trevor.js' 139 | ], 140 | dest: '<%= dist %>/scripts/lib/vendor-<%= pkg.name %>-<%= pkg.version %>.js' 141 | }, 142 | blocks: { 143 | src: [ 144 | '<%= web %>/scripts/blocks/*', 145 | ], 146 | dest: '<%= dist %>/scripts/blocks-<%= pkg.name %>-<%= pkg.version %>.js' 147 | }, 148 | 149 | css: { 150 | src: [ 151 | '<%= bower %>sir-trevor-js/sir-trevor.css', 152 | '<%= bower %>sir-trevor-js/sir-trevor-icons.css' 153 | ], 154 | dest: '<%= dist %>/styles/<%= pkg.name %>-<%= pkg.version %>.css' 155 | } 156 | } 157 | }); 158 | 159 | grunt.loadNpmTasks('grunt-contrib-uglify'); 160 | grunt.loadNpmTasks('grunt-bumpup'); 161 | grunt.loadNpmTasks('grunt-contrib-concat'); 162 | grunt.loadNpmTasks('grunt-contrib-cssmin'); 163 | grunt.loadNpmTasks('grunt-contrib-copy'); 164 | grunt.loadNpmTasks('grunt-contrib-clean'); 165 | grunt.loadNpmTasks('grunt-text-replace'); 166 | 167 | grunt.event.on('watch', function (action, filepath) { 168 | grunt.log.writeln(filepath + ' has ' + action); 169 | }); 170 | 171 | grunt.registerTask('default', ['clean','copy', 'concat','uglify','cssmin']); 172 | grunt.registerTask('semantic', ['replace','default']); 173 | grunt.registerTask('min', ['uglify', 'cssmin']); 174 | 175 | }; 176 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, DrMabuse 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | * Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | yii2-sir-trevor-js 2 | ================== 3 | 4 | [![Latest Stable Version](https://poser.pugx.org/drmabuse/yii2-sir-trevor-js/v/stable.svg)](https://packagist.org/packages/drmabuse/yii2-sir-trevor-js) [![Total Downloads](https://poser.pugx.org/drmabuse/yii2-sir-trevor-js/downloads.svg)](https://packagist.org/packages/drmabuse/yii2-sir-trevor-js) [![Latest Unstable Version](https://poser.pugx.org/drmabuse/yii2-sir-trevor-js/v/unstable.svg)](https://packagist.org/packages/drmabuse/yii2-sir-trevor-js) [![License](https://poser.pugx.org/drmabuse/yii2-sir-trevor-js/license.svg)](https://packagist.org/packages/drmabuse/yii2-sir-trevor-js) 5 | 6 | #### Version 0.0.5 7 | a sir-trevor-js module 8 | 9 | ![Sir Trevor in action](https://raw.github.com/madebymany/sir-trevor-js/master/examples/sir-trevor.gif) 10 | ## Browser support 11 | 12 | Sir Trevor is only tested on the following modern browsers: 13 | 14 | - IE10+ 15 | - Chrome 25+ 16 | - Safari 5+ 17 | - Firefox 16+ 18 | 19 | ## Dependencies 20 | 21 | Sir Trevor requires [Underscore](http://underscorejs.org/) (or LoDash), [jQuery](http://jquery.com) (or Zepto) and [Eventable](https://github.com/madebymany/eventable). 22 | 23 | ## Contributing 24 | 25 | See the [roadmap](https://github.com/madebymany/sir-trevor-js/wiki/Roadmap) and read a little about [the philosophy](https://github.com/madebymany/sir-trevor-js/wiki/Philosophy) guiding development. 26 | 27 | 28 | #### Todo 29 | 1. create output from Input 30 | 31 | 32 | ## Get Started 33 | 34 | Installation using composer: 35 | 36 | composer install drmabuse/yii2-sir-trevor-js:"*" 37 | 38 | ## Basic Usage 39 | 40 | field( 42 | $model, 43 | 'attributeName')->widget(\drmabuse\sirtrevorjs\SirTrevorWidget::className(), 44 | [ 45 | 'imageUploadUrl' => \yii\helpers\Url::to(['file/sir-trevor-upload']), 46 | 'language' => 'de',//es,fi,pt,fr,de,cn, 47 | 'assetMode' => 'min'//dev, 48 | 'element' => '.sir-trevor'// wil add to the textarea, 49 | 'initJs' => 'SirTrevor....'//PLZ read before Sir Trevor Api 50 | 'options' => ['class' => 'mysexyTextarea'], 51 | 'blockOptions' => Json::encode( 52 | [ 53 | 'el' => new JsExpression("$('.sir-trevor')"), 54 | 'blockTypes' => [ 55 | "Heading", 56 | "Text", 57 | "List", 58 | "Quote", 59 | "Image", 60 | "Video", 61 | "Tweet", 62 | "Columns", 63 | "Code", 64 | "Gallery" 65 | ], 66 | 'defaultType' => false 67 | ] 68 | ) 69 | ] 70 | ) 71 | ?> 72 | //Output 73 | 77 | toHtml($json) ?> 78 | 79 | 80 | ## Advanced Usage 81 | 82 | ### Image Block - Example File Upload Handler 83 | 84 | /** 85 | * Action for file uploads via sir-trevor image block from SirTrevorWidget (input widget) 86 | * 87 | * @param $root relative base folder 88 | */ 89 | public function actionSirTrevorUpload($root) 90 | { 91 | $upload = UploadedFile::getInstanceByName('attachment[file]'); 92 | $model = new File(); 93 | $name_id = Inflector::slug(str_replace($upload->extension, '', $upload->name)); 94 | $model->path = 'images/' . $root . '/' . $model->name_id . '.' . $upload->extension; 95 | $savePath = \Yii::getAlias('@backend/web') . '/' . $model->path; 96 | 97 | $response = new Response(); 98 | $response->format = Response::FORMAT_JSON; 99 | $response->data['message'] = "File"; 100 | 101 | if (!is_file($savePath) && is_dir(dirname($savePath))) { 102 | if ($upload->saveAs($model->path)) { 103 | $model->mime_type = FileHelper::getMimeType($model->path); 104 | $model->file_size = $upload->size; 105 | if ($model->save()) { 106 | $items = $this->getItems($this->rootPath); 107 | list($width, $height, $type, $attr) = getimagesize($model->path); 108 | $response->setStatusCode(200); 109 | $response->content = Json::encode(['file' => ['url' => $model->path]]); 110 | \Yii::$app->end(0, $response); 111 | } else { 112 | $response->statusText = "Database record could not be saved."; 113 | } 114 | } else { 115 | $response->statusText = "File could not be saved."; 116 | } 117 | }else{ 118 | $response->statusText = "File exists or root folder '{$savePath}' not found."; 119 | } 120 | 121 | $response->setStatusCode(500); 122 | \Yii::$app->end(0, $response); 123 | 124 | } 125 | 126 | ### Developer Info 127 | 128 | If you want to compile/build from the latest javascript sources, use the following commands to get the JavaScript 129 | dependencies. 130 | 131 | npm update 132 | bower update 133 | 134 | To create the asset files run 135 | 136 | grunt default 137 | 138 | To create a new version 139 | 140 | grunt bumpup 141 | grunt semantic 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /SirTrevorConverter.php: -------------------------------------------------------------------------------- 1 | 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * Neither the name of the {organization} nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | namespace drmabuse\sirtrevorjs; 32 | 33 | use \Michelf\MarkdownExtra as Markdown; 34 | use yii\helpers\VarDumper; 35 | 36 | /** 37 | * Class SirTrevorConverter 38 | * @package drmabuse\sirtrevorjs 39 | * @author 40 | */ 41 | 42 | class SirTrevorConverter { 43 | /** 44 | * Code JS needed by elements 45 | * 46 | * @access protected 47 | * @var array 48 | */ 49 | protected $codejs = null; 50 | 51 | /** 52 | * Converts the outputted json from Sir Trevor to html 53 | * 54 | * @param string $json 55 | * @return string 56 | */ 57 | public function toHtml($json) 58 | { 59 | // convert the json to an associative array 60 | $input = json_decode($json, true); 61 | $html = null; 62 | 63 | if (!empty($input) && is_array($input)) { 64 | // loop trough the data blocks 65 | foreach ($input['data'] as $block) { 66 | 67 | // no data, problem 68 | if (!isset($block['data'])) { 69 | break; 70 | } 71 | 72 | // check if we have a converter for this type 73 | $converter = $block['type'] . 'ToHtml'; 74 | if (is_callable(array($this, $converter))) { 75 | // call the function and add the data as parameters 76 | $html .= call_user_func_array( 77 | array($this, $converter), 78 | $block['data'] 79 | ); 80 | } elseif ($block['type'] == "tweet") { 81 | // special twitter 82 | $html .= $this->twitterToHtml($block['data']); 83 | } elseif (array_key_exists('text', $block['data'])) { 84 | // we have a text block. Let's just try the default converter 85 | $html .= $this->defaultToHtml($block['data']['text']); 86 | } 87 | } 88 | 89 | // code js 90 | if ($this->codejs != null && is_array($this->codejs)) { 91 | foreach ($this->codejs as $arr) { 92 | $html .= $arr; 93 | } 94 | } 95 | } 96 | 97 | return $html; 98 | } 99 | 100 | /** 101 | * Converts default elements to html 102 | * 103 | * @param string $text 104 | * @return string 105 | */ 106 | public function defaultToHtml($text) 107 | { 108 | return Markdown::defaultTransform($text); 109 | } 110 | 111 | 112 | /** 113 | * Converts headers to html 114 | * 115 | * @param string $text 116 | * @return string 117 | */ 118 | public function headingToHtml($text) 119 | { 120 | return '

' . $text . '

'; 121 | } 122 | 123 | /** 124 | * Converts block quotes to html 125 | * 126 | * @param string $cite 127 | * @param string $text 128 | * @return string 129 | */ 130 | public function blockquoteToHtml($cite, $text) 131 | { 132 | // remove the indent thats added by Sir Trevor 133 | $text = ltrim($text, '>'); 134 | 135 | $html = '
'; 136 | 137 | $html .= Markdown::defaultTransform($text); 138 | 139 | // Add the cite if necessary 140 | if (!empty($cite)) { 141 | $html .= '' . $cite . ''; 142 | } 143 | 144 | $html .= '
'; 145 | return $html; 146 | } 147 | 148 | /** 149 | * Converts quote to html 150 | * 151 | * @param string $cite 152 | * @param string $text 153 | * @return string 154 | */ 155 | public function quoteToHtml($cite, $text) 156 | { 157 | return $this->blockquoteToHtml($cite, $text); 158 | } 159 | 160 | /** 161 | * Converts the image to html 162 | * 163 | * @param array $file 164 | * @param string $caption 165 | * @return string 166 | */ 167 | public function imageToHtml($file, $caption = '') 168 | { 169 | $url = (isset($file['url']))?$file['url']:''; 170 | 171 | $_return = '
'; 172 | 173 | if ($caption != null) { 174 | $_return .= '
'.$caption.'
'; 175 | } 176 | 177 | $_return .= '
'; 178 | 179 | return $_return; 180 | } 181 | 182 | 183 | /** 184 | * Converts the video to html 185 | * 186 | * @param string $provider 187 | * @param string $remote_id 188 | * @param string $caption 189 | * @return string 190 | */ 191 | public function videoToHtml($provider, $remote_id, $caption = null) 192 | { 193 | $html = null; 194 | 195 | switch ($provider) { 196 | /** 197 | * Youtube 198 | */ 199 | case "youtube": 200 | $html = ''; 201 | break; 202 | 203 | /** 204 | * Vimeo 205 | */ 206 | case "vimeo": 207 | $html = ''; 208 | break; 209 | 210 | /** 211 | * Dailymotion 212 | */ 213 | case "dailymotion": 214 | $html = ''; 215 | break; 216 | 217 | /** 218 | * Vine 219 | */ 220 | case "vine": 221 | $this->codejs['vine'] = ''; 222 | 223 | $html = ''; 224 | break; 225 | 226 | /** 227 | * Metacafe 228 | */ 229 | case "metacafe": 230 | $html = ''; 231 | break; 232 | 233 | /** 234 | * Yahoo video 235 | */ 236 | case "yahoo": 237 | $html = ''; 238 | break; 239 | 240 | /** 241 | * UStream Live 242 | */ 243 | case "ustream": 244 | $html = ''; 245 | break; 246 | 247 | /** 248 | * UStream Recorded 249 | */ 250 | case "ustreamrecord": 251 | $html = ''; 252 | break; 253 | 254 | /** 255 | * Veoh 256 | */ 257 | case "veoh": 258 | $html = ''; 259 | break; 260 | 261 | /** 262 | * Vevo 263 | */ 264 | case "vevo": 265 | $html = ''; 266 | break; 267 | 268 | /** 269 | * AOL 270 | */ 271 | case "aol": 272 | $html = ''; 273 | break; 274 | 275 | /** 276 | * Metatube 277 | */ 278 | case "metatube": 279 | $html = ''; 280 | break; 281 | 282 | /** 283 | * Wat.tv 284 | */ 285 | case "wat": 286 | $html = ''; 287 | break; 288 | 289 | /** 290 | * Daily Mail UK 291 | */ 292 | case "dailymailuk": 293 | $html = ''; 294 | break; 295 | 296 | /** 297 | * Canal Plus 298 | */ 299 | case "cplus": 300 | $html = ''; 301 | break; 302 | 303 | /** 304 | * France Television 305 | */ 306 | case "francetv": 307 | $html = ''; 308 | break; 309 | 310 | /** 311 | * Zoomin.tv 312 | */ 313 | case "zoomin": 314 | $html = ''; 315 | break; 316 | 317 | /** 318 | * Global News 319 | */ 320 | case "globalnews": 321 | $html = ''; 322 | break; 323 | } 324 | 325 | /** 326 | * Caption 327 | */ 328 | if ($html != null && $caption != null) { 329 | $html .= '
'.$caption.'
'; 330 | } 331 | 332 | if ($html != null) { 333 | return '
'.$html.'
'; 334 | } 335 | 336 | return null; 337 | } 338 | 339 | /** 340 | * set a single column html 341 | * @param $column 342 | */ 343 | private function _columns($column){ 344 | 345 | } 346 | 347 | 348 | } -------------------------------------------------------------------------------- /SirTrevorWidget.php: -------------------------------------------------------------------------------- 1 | 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * Neither the name of the {organization} nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | namespace drmabuse\sirtrevorjs; 31 | 32 | use drmabuse\sirtrevorjs\assets\SirTrevorAsset; 33 | use Yii; 34 | use yii\helpers\Html; 35 | use yii\helpers\Json; 36 | use yii\helpers\Url; 37 | use yii\web\JsExpression; 38 | use yii\web\View; 39 | use yii\widgets\InputWidget; 40 | 41 | /** 42 | * Class SirTrevorWidget 43 | * @package yii2-sirtrevorjs 44 | */ 45 | class SirTrevorWidget extends InputWidget 46 | { 47 | 48 | /** 49 | * @var string 50 | */ 51 | public $version = '0.0.5'; 52 | 53 | /** 54 | * @var string 55 | */ 56 | public $assetMode = 'min'; 57 | 58 | /** 59 | * debug mode on off 60 | * @var bool 61 | */ 62 | public $debug = 'false'; 63 | /** 64 | * default_language 65 | * @var string 66 | */ 67 | public $language = 'en'; 68 | /** 69 | * mus be an array of options 70 | * @var null 71 | */ 72 | public $blockOptions = null; 73 | 74 | /** 75 | * you can set full/standard or set your own 76 | * @var string 77 | */ 78 | public $block_type = 'full'; 79 | 80 | /** 81 | * blockTypes 82 | * @var array 83 | */ 84 | public $blockTypes = [ 85 | "Heading", 86 | "Text", 87 | "List", 88 | "Quote", 89 | "Image", 90 | "Video" 91 | ]; 92 | 93 | /** 94 | * @var array 95 | */ 96 | public $blockTypesFull = [ 97 | "Heading", 98 | "Text", 99 | "List", 100 | "Quote", 101 | "Image", 102 | "Video", 103 | "Tweet", 104 | "Columns", 105 | "Code", 106 | "Gallery" 107 | ]; 108 | /** 109 | * the area element 110 | * @var string 111 | */ 112 | public $element = '.sir-trevor'; 113 | 114 | /** 115 | * @var string 116 | */ 117 | public $imageUploadUrl = null; 118 | /** 119 | * @var null 120 | */ 121 | public $initJs = null; 122 | 123 | /** 124 | * textarea options 125 | * @var array 126 | */ 127 | public $options; 128 | 129 | /** 130 | * like __construct 131 | * @throws \yii\base\InvalidConfigException 132 | */ 133 | public function init() 134 | { 135 | parent::init(); 136 | } 137 | 138 | /** 139 | * set the element as class to the texteare 140 | * @return string|void 141 | */ 142 | public function run() 143 | { 144 | $this->options['class'] = str_replace('.', '', $this->element); 145 | $this->registerAsset(); 146 | echo $this->renderInput(); 147 | } 148 | 149 | /** 150 | * register the concated files 151 | */ 152 | private function registerAsset() 153 | { 154 | SirTrevorAsset::register($this->view)->options = [ 155 | 'language' => $this->language, 156 | 'assetMode' => $this->assetMode 157 | ]; 158 | $this->view->registerJs( 159 | '(function($){ 160 | "use strict";'.PHP_EOL.' 161 | $(function(){' . PHP_EOL . 162 | $this->getInitJs() . PHP_EOL . 163 | '}); 164 | })(jQuery);' . PHP_EOL, 165 | View::POS_END 166 | ); 167 | } 168 | 169 | /** 170 | * 171 | * Render the text area input 172 | */ 173 | protected function renderInput() 174 | { 175 | if ($this->hasModel()) { 176 | $input = Html::activeTextArea($this->model, $this->attribute, $this->options); 177 | } else { 178 | $input = Html::textArea($this->name, $this->value, $this->options); 179 | } 180 | 181 | return $input; 182 | } 183 | 184 | /** 185 | * @return array 186 | */ 187 | public function getBlockTypes() 188 | { 189 | if ($this->block_type === 'full') { 190 | return $this->blockTypesFull; 191 | } 192 | 193 | return $this->blockTypes; 194 | } 195 | 196 | /** 197 | * @param array $blockTypes 198 | */ 199 | public function setBlockTypes($blockTypes) 200 | { 201 | $this->blockTypes = $blockTypes; 202 | } 203 | 204 | /** 205 | * @return string 206 | */ 207 | public function getImageUploadUrl() 208 | { 209 | if ($this->imageUploadUrl === null) { 210 | $this->imageUploadUrl = Url::to(['/blog/crud/post-content/upload']); 211 | } 212 | return $this->imageUploadUrl; 213 | } 214 | 215 | /** 216 | * @param string $imageUploadUrl 217 | */ 218 | public function setImageUploadUrl($imageUploadUrl) 219 | { 220 | $this->imageUploadUrl = $imageUploadUrl; 221 | } 222 | 223 | /** 224 | * @return null 225 | */ 226 | public function getBlockOptions() 227 | { 228 | if (is_null($this->blockOptions)) { 229 | $this->blockOptions = Json::encode( 230 | [ 231 | 'el' => new JsExpression("$('{$this->element}')"), 232 | 'blockTypes' => $this->getBlockTypes(), 233 | 'defaultType' => false 234 | ] 235 | ); 236 | } 237 | 238 | return $this->blockOptions; 239 | } 240 | 241 | /** 242 | * setting a standard js 243 | * @return null 244 | */ 245 | public function getInitJs() 246 | { 247 | if (is_null($this->initJs)) { 248 | $this->initJs = 'SirTrevor.DEBUG = ' . $this->debug . ';' . PHP_EOL; 249 | $this->initJs .= 'SirTrevor.LANGUAGE = "' . $this->language . '";' . PHP_EOL; 250 | $this->initJs .= 'SirTrevor.setDefaults({ uploadUrl: "' . $this->getImageUploadUrl() . '" });' . PHP_EOL; 251 | $this->initJs .= "window.editor = new SirTrevor.Editor(" . $this->getBlockOptions() . ");" . PHP_EOL; 252 | } 253 | 254 | return $this->initJs; 255 | } 256 | 257 | /** 258 | * @param null $initJs 259 | */ 260 | public function setInitJs($initJs) 261 | { 262 | $this->initJs = $initJs; 263 | } 264 | 265 | } -------------------------------------------------------------------------------- /assets/SirTrevorAsset.php: -------------------------------------------------------------------------------- 1 | 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * Neither the name of the {organization} nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | namespace drmabuse\sirtrevorjs\assets; 31 | 32 | use Yii; 33 | use yii\helpers\ArrayHelper; 34 | use yii\helpers\VarDumper; 35 | use yii\web\AssetBundle; 36 | 37 | class SirTrevorAsset extends AssetBundle 38 | { 39 | /** 40 | * @var language file 41 | */ 42 | public $options = [ 43 | 'language' => 'en', 44 | 'assetMode' => 'min' 45 | ]; 46 | 47 | 48 | /** 49 | * @var string 50 | */ 51 | public $sourcePath = '@vendor/drmabuse/yii2-sir-trevor-js/web'; 52 | 53 | /** 54 | * @var array 55 | */ 56 | public $css = [ 57 | "dist/styles/yii2-sirtrevorjs-0.0.5.min.css", 58 | ]; 59 | public $dev_css = [ 60 | "styles/sir-trevor.css", 61 | "styles/sir-trevor-icons.css", 62 | ]; 63 | /** 64 | * @var array 65 | */ 66 | public $js = [ 67 | "dist/scripts/yii2-sirtrevorjs-0.0.5.min.js" 68 | ]; 69 | 70 | /** 71 | * @var array 72 | */ 73 | public $dev_js = [ 74 | 'scripts/lib/underscore/underscore.js', 75 | 'scripts/lib/Eventable/eventable.js', 76 | 'scripts/lib/sir-trevor-js/sir-trevor.js', 77 | "scripts/blocks/CodeBlock.js", 78 | "scripts/blocks/ColumnsBlock.js", 79 | "scripts/blocks/Gallery.js", 80 | "scripts/blocks/ImageCaption.js", 81 | 82 | ]; 83 | /** 84 | * @var array 85 | */ 86 | public $depends = [ 87 | 'yii\web\JqueryAsset', 88 | 'yii\web\YiiAsset' 89 | ]; 90 | 91 | /** 92 | * @var bool 93 | */ 94 | public $forceCopy = false; 95 | 96 | /** 97 | * 98 | */ 99 | public function registerAssetFiles($view) 100 | { 101 | 102 | $language = $this->options['language']; 103 | $mode = $this->options['assetMode']; 104 | $langFile = is_file($this->sourcePath . "/dist/scripts/locales/{$language}.js") ? 105 | "dist/scripts/locales/{$language}.js" : null; 106 | 107 | if ($mode === 'min' && $language !== 'en' && $langFile !== null) { 108 | $this->js = ArrayHelper::merge($this->js, [$langFile]); 109 | } else { 110 | $this->css = $this->dev_css; 111 | $this->js = $this->dev_js; 112 | if ($language !== 'en' && $langFile !== null) { 113 | $this->js = ArrayHelper::merge($this->js, [$langFile]); 114 | } 115 | } 116 | 117 | /** 118 | * @todo double code 119 | */ 120 | 121 | foreach ($this->js as $js) { 122 | if ($js[0] !== '/' && $js[0] !== '.' && strpos($js, '://') === false) { 123 | $view->registerJsFile($this->baseUrl . '/' . $js, [], $this->jsOptions); 124 | } else { 125 | $view->registerJsFile($js, [], $this->jsOptions); 126 | } 127 | } 128 | foreach ($this->css as $css) { 129 | if ($css[0] !== '/' && $css[0] !== '.' && strpos($css, '://') === false) { 130 | $view->registerCssFile($this->baseUrl . '/' . $css, [], $this->cssOptions); 131 | } else { 132 | $view->registerCssFile($css, [], $this->cssOptions); 133 | } 134 | } 135 | } 136 | } -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yii2-yii2-sirtrevorjs", 3 | "version": "0.0.5", 4 | "dependencies": { 5 | "sir-trevor-js": "https://github.com/schmunk42/sir-trevor-js.git#9c3060d96ae4e9bb30dd3e5ea15766679b5f8f24" 6 | } 7 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "drmabuse/yii2-sir-trevor-js", 3 | "description": "Yii 2 Sir Trevor JS widget", 4 | "homepage": "https://github.com/DrMabuse23/yii2-sir-trevor-js", 5 | "license": "BSD-3-Clause", 6 | "type": "yii2-extension", 7 | "version": "0.0.5", 8 | "keywords": [ 9 | "yii2", 10 | "sir trevor js" 11 | ], 12 | "authors": [ 13 | { 14 | "name": "Pascal Brewing", 15 | "email": "pascalbrewing@gmail.com" 16 | } 17 | ], 18 | "autoload": { 19 | "psr-4": { 20 | "drmabuse\\sirtrevorjs\\": "" 21 | } 22 | }, 23 | "require": { 24 | "yiisoft/yii2": "*", 25 | "michelf/php-markdown": "1.*" 26 | } 27 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yii2-sirtrevorjs", 3 | "version": "0.0.5", 4 | "description": "yii2-sirtrevorjs as yii2 module", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Pascal Brewing", 10 | "license": "BSD3", 11 | "devDependencies": { 12 | "grunt": "~0.4.2", 13 | "grunt-bumpup": "~0.5.0", 14 | "grunt-contrib-clean": "^0.5.0", 15 | "grunt-contrib-concat": "^0.5.0", 16 | "grunt-contrib-copy": "^0.5.0", 17 | "grunt-contrib-cssmin": "~0.7.0", 18 | "grunt-contrib-uglify": "~0.3.2", 19 | "grunt-release": "*", 20 | "grunt-text-replace": "^0.3.12" 21 | } 22 | } -------------------------------------------------------------------------------- /web/dist/scripts/blocks-yii2-sirtrevorjs-0.0.5.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by pascal on 20.07.14. 3 | */ 4 | 5 | /* 6 | An example of a SirTrevor.Block 7 | -- 8 | Author: C J Bell @ madebymany 9 | */ 10 | 11 | SirTrevor.Blocks.Code = (function(){ 12 | 13 | return SirTrevor.Block.extend({ 14 | 15 | // String; Names the block 16 | // Note – please use underscores when naming 17 | // Eg example_block should be ExampleBlock 18 | type: 'code', 19 | 20 | // Function; the title displayed in the toolbar 21 | // Can return a translated string (if required) 22 | title: function() { 23 | return i18n.t('blocks:code:title'); 24 | }, 25 | icon_name: 'code', 26 | 27 | // Boolean; show this blockType of the toolbar 28 | toolbarEnabled: true, 29 | 30 | // Block Mixins 31 | // Allow different UI components / methods to be mixed into the block 32 | 33 | // Enable drop functionality on the block 34 | droppable: false, 35 | 36 | // Enable paste functionality (to paste URLS etc) 37 | pastable: false, 38 | 39 | // Enable an upload button to be added 40 | // Mixins Ajaxable automatically 41 | // Exposes an uploader method 42 | // Usage: this.uploader(file, success, failure) 43 | uploadable: false, 44 | 45 | // Enable queued remote fetching 46 | // Exposes a small wrapper around the $.ajax method 47 | // Usage: this.fetch(ajaxOptions, success, failure) 48 | fetchable: false, 49 | 50 | // Add an ajax queue to the block 51 | // Added to uploadable & fetchable automatically 52 | ajaxable: false, 53 | 54 | // Overwritable mixin options: 55 | // -- 56 | drop_options: { 57 | // String; (can use underscore template tags) 58 | // Defines the HTML for the dropzone template 59 | html: "
", 60 | // Boolean; 61 | // On re-order, should we re-render this item. 62 | // Useful for when re-ordering iframes (like Twitter) 63 | re_render_on_reorder: false 64 | }, 65 | 66 | paste_options: { 67 | // String; (can use underscore template tags) 68 | // Defines the HTML for the paste template 69 | html: "
" 70 | }, 71 | 72 | upload_options: { 73 | // String; (can use underscore template tags) 74 | // Defines the HTML for the upload template 75 | html: "" 76 | }, 77 | 78 | formattable: true, 79 | 80 | // String or Function; The HTML for the inner portion of the editor block 81 | // In this example, the editorHTML is an editable input div (like we use for a TextBlock) 82 | 83 | // Classes: 84 | // st-required – indicates this input must be present to pass validation 85 | // st-text-block – gives the block the ability to use the formatting controls 86 | 87 | editorHTML: function() { 88 | return "
"; 89 | }, 90 | 91 | // Element shorthands 92 | // -- 93 | // this.$el 94 | // this.el 95 | // this.$inner (the inner container for the block) 96 | // this.$editor (contains all the UI inputs for the block) 97 | // this.$inputs (contains all the UI inputs for blocks that are uploadable / droppable / pastable) 98 | // this.getTextBlock() (shorthand for this.$el.find('.st-text-block')) 99 | // this.$(selector) (shorthand for this.$el.find(selector)) 100 | 101 | // Validations 102 | // -- 103 | // Required fields (with .st-required class) always get validted 104 | // Called using the validateField method 105 | // Set a data-st-name="Field Name" on your required inputs to use it in the validation fail message 106 | 107 | // Array; defines custom validator methods to call 108 | validations: ['myCustomValidator'], 109 | 110 | // Example custom validator 111 | myCustomValidator: function() { 112 | var field = this.$('.a-field'); 113 | 114 | if (field.val() === 'herp derp') { 115 | this.setError(field, "A validation fail message"); 116 | } 117 | }, 118 | 119 | // Function; Executed on render of the block if some data is provided. 120 | // LoadData gives us a means to convert JSON data into the editor dom 121 | // In this example we convert the text from markdown to HTML and show it inside the element 122 | loadData: function(data){ 123 | this.getTextBlock().html(SirTrevor.toHTML(data.text, this.type)); 124 | }, 125 | 126 | // Function; Executed on save of the block, once the block is validated 127 | // toData expects a way for the block to be transformed from inputs into structured data 128 | // The default toData function provides a pretty comprehensive way of turning data into JSON 129 | // In this example we take the text data and save it to the data object on the block 130 | toData: function(){ 131 | var dataObj = {}; 132 | 133 | var content = this.getTextBlock().html(); 134 | if (content.length > 0) { 135 | dataObj.text = SirTrevor.toMarkdown(content, this.type); 136 | } 137 | 138 | this.setData(dataObj); 139 | }, 140 | 141 | // Function; Returns true or false whether there is data in the block 142 | isEmpty: function() { 143 | return _.isEmpty(this.saveAndGetData()); // Default implementation 144 | }, 145 | 146 | // Other data functions 147 | // -- 148 | // getData – returns the data in the store 149 | // save - Invokes the toData method 150 | // saveAndReturnData - Saves and returns the entire store 151 | // saveAndGetData - Save and only return the data part of the store 152 | 153 | 154 | // Function; Hook executed at the end of the block rendering method. 155 | // Useful for initialising extra pieces of UI or binding extra events. 156 | // In this example we add an extra button, just because. 157 | onBlockRender: function() { 158 | 159 | // this.$editor.append($('