From f1348373cbdf0ce426541e26f20c818e218f8a0e Mon Sep 17 00:00:00 2001 From: onli Date: Mon, 12 May 2014 21:40:05 +0200 Subject: [PATCH] Include the full ckeditor, using composer (#148) This shall make it easier for users to customize the editor --- htmlarea/autoload.php | 7 + htmlarea/ckeditor/ckeditor | 1 + htmlarea/ckeditor/ckeditor_custom_config.js | 87 +++++++ htmlarea/ckeditor/ckeditor_custom_plugin.js | 0 htmlarea/ckeditor/wysiwyg-style.css | 86 +++++++ htmlarea/composer.json | 14 ++ htmlarea/composer.lock | 66 ++++++ htmlarea/composer/ClassLoader.php | 246 ++++++++++++++++++++ htmlarea/composer/autoload_classmap.php | 9 + htmlarea/composer/autoload_namespaces.php | 9 + htmlarea/composer/autoload_real.php | 43 ++++ htmlarea/composer/installed.json | 45 ++++ 12 files changed, 613 insertions(+) create mode 100644 htmlarea/autoload.php create mode 160000 htmlarea/ckeditor/ckeditor create mode 100644 htmlarea/ckeditor/ckeditor_custom_config.js create mode 100644 htmlarea/ckeditor/ckeditor_custom_plugin.js create mode 100644 htmlarea/ckeditor/wysiwyg-style.css create mode 100644 htmlarea/composer.json create mode 100644 htmlarea/composer.lock create mode 100644 htmlarea/composer/ClassLoader.php create mode 100644 htmlarea/composer/autoload_classmap.php create mode 100644 htmlarea/composer/autoload_namespaces.php create mode 100644 htmlarea/composer/autoload_real.php create mode 100644 htmlarea/composer/installed.json diff --git a/htmlarea/autoload.php b/htmlarea/autoload.php new file mode 100644 index 00000000..2c884944 --- /dev/null +++ b/htmlarea/autoload.php @@ -0,0 +1,7 @@ + tags + config.protectedSource.push( /<(script)[^>]*>.*<\/script>/ig ); // set default in ckeditor.js [//gi,//gi] + // allow imageselectorplus mediainsert tag code + config.protectedSource.push( /<(mediainsert)[^>]*>[\s\S]*?<\/mediainsert>/img ); + // allow a Smarty like {} tag syntax without starting whitespace, which would be some other code part. + config.protectedSource.push( /\{[a-zA-Z\$].*?\}/gi ); + + // Set placeholder tag cases - elements [attributes]{styles}(classes) + // Allowed mediainsert, gallery, media tags (imageselectorplus galleries) - which tells ACF to not touch the code! + // Allowed div is a need for Media Library inserts - which tells ACF to not touch the code! + // img[height] is even needed to avoid ACF OFF removement of height attributes + config.extraAllowedContent = 'mediainsert[*]{*}(*);gallery[*]{*}(*);media[*]{*}(*);script[*]{*}(*);audio[*]{*}(*);div[*]{*}(*);img[height,width];'; + + // CKEDITOR.protectedSource patterns used regex Escape sequences + // \s any whitespace character; + // \S any character that is not a whitespace character + // \t tab (hex 09); + // \r carriage return (hex 0D); + // \n newline (hex 0A); + // Pattern Modifiers + // /i caseless, match both upper and lower case letters + // /m treat as multiline + // /g be greedy + + // Prevent filler nodes in all empty blocks. - case switching source and wysiwyg mode multiple times + //config.fillEmptyBlocks = false; // default (true) - switches

 

to

+ //config.ignoreEmptyParagraph = false; // default(true) - Whether the editor must output an empty value ('') if it's contents is made by an empty paragraph only. (extends to config.fillEmptyBlocks) + // It will still generate an empty

though. + config.autoParagraph = false; // but this one definitely prevents adding multiple empty paragraphs when switching source mode!!! + + // add custom Serendipity styles to ckeditor wysiwyg-mode, to repect css image floats + config.contentsCss = 'htmlarea/ckeditor/wysiwyg-style.css'; + + // The configuration setting that controls the ENTER mode is "config.enterMode" and it offers three options: + // (1) The default creates a paragraph element each time the "enter" key is pressed: + //config.enterMode = CKEDITOR.ENTER_P; // inserts

+ // (2) You can choose to create a "div" element instead of a paragraph: + //config.enterMode = CKEDITOR.ENTER_DIV; // inserts
+ // (3) If you prefer to not wrap the text in anything, you can choose to insert a line break tag: + //config.enterMode = CKEDITOR.ENTER_BR; // inserts
+ // You can always use SHIFT+ENTER to set a br in the P-mode default option or change the SHIFT-mode to something else + //config.shiftEnterMode = CKEDITOR.ENTER_BR; + + //config.entities = false; + //config.htmlEncodeOutput = false; + + // ui configurations - just some examples + //config.uiColor = 'transparent'; // standard, but better disable config.uiColor all + //config.uiColor = '#CFD1CF'; // standard grey + //config.uiColor = '#f5f5f5'; // standard light grey + //config.uiColor = '#E6EDF3'; // extreme light blue + //config.uiColor = '#DFE8F6'; // very light blue + //config.uiColor = '#9AB8F3'; // light blue/violet + //config.uiColor = '#AADC6E'; // light green + //config.uiColor = '#FFDC6E'; // light gold + //config.uiColor = '#FF8040'; // mango + //config.uiColor = '#FF2400'; // scarlet red + //config.uiColor = '#14B8C4'; // light turquoise + config['skin'] = 'moono'; + config['height'] = 400; +}; diff --git a/htmlarea/ckeditor/ckeditor_custom_plugin.js b/htmlarea/ckeditor/ckeditor_custom_plugin.js new file mode 100644 index 00000000..e69de29b diff --git a/htmlarea/ckeditor/wysiwyg-style.css b/htmlarea/ckeditor/wysiwyg-style.css new file mode 100644 index 00000000..acb2ba20 --- /dev/null +++ b/htmlarea/ckeditor/wysiwyg-style.css @@ -0,0 +1,86 @@ +/** + * Adds custom Serendipity image float styles to CKEDITOR wysiwyg-mode + */ + +.serendipity_image_left, +.serendipity_image_right, +.serendipity_image_center, +.serendipity_imageComment_center, +.serendipity_imageComment_left, +.serendipity_imageComment_right { + background: transparent; + border: 0 none; + padding: 0!important; +} + +.serendipity_image_left, +.serendipity_image_right, +.serendipity_imageComment_left, +.serendipity_imageComment_right { + display: block; + float: none; + margin: 0 0 1em; +} + +.serendipity_image_center { + display: block; + margin: 0 auto 1em auto; +} + +.plain-images .serendipity_image_left, +.plain-images .serendipity_image_right, +.plain-images .serendipity_image_center, +.plain-images .serendipity_imageComment_center, +.plain-images .serendipity_imageComment_left, +.plain-images .serendipity_imageComment_right { + border: 1px solid #aaa; +} + +.plain-images .serendipity_imageComment_txt { + background: #ddd; +} + +.fancy-images .serendipity_image_left, +.fancy-images .serendipity_image_right, +.fancy-images .serendipity_image_center, +.fancy-images .serendipity_imageComment_img { + -webkit-box-shadow: 0 0 2px 1px rgba(0,0,0,.5); + -moz-box-shadow: 0 0 2px 1px rgba(0,0,0,.5); + box-shadow: 0 0 2px 1px rgba(0,0,0,.5); +} + +.no-boxshadow .fancy-images .serendipity_image_left, +.no-boxshadow .fancy-images .serendipity_image_right, +.no-boxshadow .fancy-images .serendipity_image_center, +.no-boxshadow .fancy-images .serendipity_imageComment_img { + border: 1px solid #aaa; +} + +.serendipity_imageComment_center, +.serendipity_imageComment_left, +.serendipity_imageComment_right { + height: auto; + max-width: 100%; +} + +.serendipity_image_left { + float: left; + margin: 0 2em 1em 0; +} + +.serendipity_image_right { + float: right; + margin: 0 0 1em 2em; +} + +.serendipity_imageComment_left { + display: inline; + float: left; + margin: 0 2em 1em 0; +} + +.serendipity_imageComment_right { + display: inline; + float: right; + margin: 0 0 1em 2em; +} diff --git a/htmlarea/composer.json b/htmlarea/composer.json new file mode 100644 index 00000000..013b49f9 --- /dev/null +++ b/htmlarea/composer.json @@ -0,0 +1,14 @@ +{ + "repositories": [ + { + "type": "composer", + "url": "http://packages.zendframework.com/" + } + ], + "require": { + "ckeditor": "dev-full/latest" + }, + "config": { + "vendor-dir": "." + } +} \ No newline at end of file diff --git a/htmlarea/composer.lock b/htmlarea/composer.lock new file mode 100644 index 00000000..db5f7474 --- /dev/null +++ b/htmlarea/composer.lock @@ -0,0 +1,66 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + ], + "hash": "a52359b4196b7fcf0071bef5cafda970", + "packages": [ + { + "name": "ckeditor/ckeditor", + "version": "dev-full/latest", + "source": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor-releases.git", + "reference": "5a3526cc90e3291d0193cffe02e3eceaef1318d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ckeditor/ckeditor-releases/zipball/5a3526cc90e3291d0193cffe02e3eceaef1318d3", + "reference": "5a3526cc90e3291d0193cffe02e3eceaef1318d3", + "shasum": "" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0+", + "LGPL-2.1+", + "MPL-1.1+" + ], + "authors": [ + { + "name": "CKSource - Frederico Knabben", + "homepage": "http://cksource.com" + } + ], + "description": "JavaScript WYSIWYG web text editor.", + "homepage": "http://ckeditor.com", + "keywords": [ + "CKEditor", + "editor", + "fckeditor", + "html", + "javascript", + "richtext", + "text", + "wysiwyg" + ], + "time": "2014-04-24 14:03:41" + } + ], + "packages-dev": [ + + ], + "aliases": [ + + ], + "minimum-stability": "stable", + "stability-flags": { + "ckeditor/ckeditor": 20 + }, + "platform": [ + + ], + "platform-dev": [ + + ] +} diff --git a/htmlarea/composer/ClassLoader.php b/htmlarea/composer/ClassLoader.php new file mode 100644 index 00000000..1db8d9a0 --- /dev/null +++ b/htmlarea/composer/ClassLoader.php @@ -0,0 +1,246 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0 class loader + * + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + */ +class ClassLoader +{ + private $prefixes = array(); + private $fallbackDirs = array(); + private $useIncludePath = false; + private $classMap = array(); + + public function getPrefixes() + { + return call_user_func_array('array_merge', $this->prefixes); + } + + public function getFallbackDirs() + { + return $this->fallbackDirs; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of classes, merging with any others previously set. + * + * @param string $prefix The classes prefix + * @param array|string $paths The location(s) of the classes + * @param bool $prepend Prepend the location(s) + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirs = array_merge( + (array) $paths, + $this->fallbackDirs + ); + } else { + $this->fallbackDirs = array_merge( + $this->fallbackDirs, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixes[$first][$prefix])) { + $this->prefixes[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixes[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixes[$first][$prefix] + ); + } else { + $this->prefixes[$first][$prefix] = array_merge( + $this->prefixes[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of classes, replacing any others previously set. + * + * @param string $prefix The classes prefix + * @param array|string $paths The location(s) of the classes + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirs = (array) $paths; + + return; + } + $this->prefixes[substr($prefix, 0, 1)][$prefix] = (array) $paths; + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + include $file; + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $classPath = strtr(substr($class, 0, $pos), '\\', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + $className = substr($class, $pos + 1); + } else { + // PEAR-like class name + $classPath = null; + $className = $class; + } + + $classPath .= strtr($className, '_', DIRECTORY_SEPARATOR) . '.php'; + + $first = $class[0]; + if (isset($this->prefixes[$first])) { + foreach ($this->prefixes[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) { + return $dir . DIRECTORY_SEPARATOR . $classPath; + } + } + } + } + } + + foreach ($this->fallbackDirs as $dir) { + if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) { + return $dir . DIRECTORY_SEPARATOR . $classPath; + } + } + + if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) { + return $file; + } + + return $this->classMap[$class] = false; + } +} diff --git a/htmlarea/composer/autoload_classmap.php b/htmlarea/composer/autoload_classmap.php new file mode 100644 index 00000000..a764508f --- /dev/null +++ b/htmlarea/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + $path) { + $loader->set($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + + $loader->register(true); + + return $loader; + } +} diff --git a/htmlarea/composer/installed.json b/htmlarea/composer/installed.json new file mode 100644 index 00000000..d5caea90 --- /dev/null +++ b/htmlarea/composer/installed.json @@ -0,0 +1,45 @@ +[ + { + "name": "ckeditor/ckeditor", + "version": "dev-full/latest", + "version_normalized": "dev-full/latest", + "source": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor-releases.git", + "reference": "5a3526cc90e3291d0193cffe02e3eceaef1318d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ckeditor/ckeditor-releases/zipball/5a3526cc90e3291d0193cffe02e3eceaef1318d3", + "reference": "5a3526cc90e3291d0193cffe02e3eceaef1318d3", + "shasum": "" + }, + "time": "2014-04-24 14:03:41", + "type": "library", + "installation-source": "source", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0+", + "LGPL-2.1+", + "MPL-1.1+" + ], + "authors": [ + { + "name": "CKSource - Frederico Knabben", + "homepage": "http://cksource.com" + } + ], + "description": "JavaScript WYSIWYG web text editor.", + "homepage": "http://ckeditor.com", + "keywords": [ + "CKEditor", + "editor", + "fckeditor", + "html", + "javascript", + "richtext", + "text", + "wysiwyg" + ] + } +]