From 2956dd4d9a896abcbcdfdc8732e456c253f5e6d2 Mon Sep 17 00:00:00 2001 From: "mihai.sucan" Date: Mon, 10 Aug 2009 19:14:16 +0000 Subject: [PATCH] started Moodle 2.0 integration work. --HG-- extra : convert_revision : svn%3Afc1ba2b4-ac28-11dd-a772-7fcde58d38e6/trunk%40107 --- CHANGES | 17 +++ TODO | 96 ---------------- ext/moodle/gen_moodlelang.php | 19 +++- ext/moodle/gen_paintweblang.php | 4 +- ext/moodle/lang.json.php | 5 +- ext/moodle/update_tinymcelang.php | 175 ++++++++++++++++++++++++++++++ src/includes/lib.js | 16 ++- src/paintweb.js | 5 +- 8 files changed, 228 insertions(+), 109 deletions(-) delete mode 100644 TODO create mode 100644 ext/moodle/update_tinymcelang.php diff --git a/CHANGES b/CHANGES index 0c39958..2d4be34 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,20 @@ +2009-08-10: +=========== + +- Started work on Moodle 2.0 integration. Moodle 1.9 integration has been +postponed for a number of reasons. Further details in an upcoming blog post at +robodesign.ro/mihai. + +- New script for localization integration specific to Moodle 2.0 - see +update_tinymcelang.pnp. + +- Improved/fixed gen_moodlelang.php. + +- Moved the TODO file to the Google Code wiki: +http://code.google.com/p/paintweb/wiki/TODO + +The wiki page includes new items and some fixes. + 2009-08-03: =========== diff --git a/TODO b/TODO deleted file mode 100644 index 4ae7681..0000000 --- a/TODO +++ /dev/null @@ -1,96 +0,0 @@ -$Author: Mihai Şucan $ -$URL: http://code.google.com/p/paintweb $ -$Date: 2009-07-30 14:35:21 +0300 $ - -Until the end of GSOC: - -- Integrate into TinyMCE and Moodle. -- Color theme for the OLPC XO. - -As quick as possible, after GSOC 2009: - -- report browser bugs: - - when strokeText() is used shadows do not render (Webkit, needs recheck). - - elem.hasAttribute('data-whatever') fails to return true when it should do - so. The problem affects Webkit. - - outlines are drawn irrespective of z-index in Opera 9.6 and Opera 10. - - serious redraw issues with the color mixer when the colormixer_selector tab - panel has some width set. The problem affects Opera 9.6 and Opera 10. - - globalCompositeOperation + gradients renders mildly different in Google - Chrome 2 on Windows, compared to the other browsers. To see this, test the RGB - color space visualisation in the color mixer. I cannot reproduce the issue - with Google Chrome 3 on Linux. - - images cannot be selected in editable content, on Webkit - in some special - cases. - - images with data URL are considered external, and thus when drawn on Canvas - they cause security violations, in Webkit and Gecko 1.9.0 (fixed in 1.9.1). - -- implement the GUI improvements suggested by Olli Savolainen. -- new tools: bucket, pencil v2 (avec pression). -- toolRegister creates instances of tool objects automatically. - - cleanup interface script from having hard-coded stuff related to tools. -- investigate the use of an iframe to hold the whole PaintWeb interface because -I can have style sandboxing and other advantages. -- allow integration by specifying a form input to replace. -- provide API to load language strings on demand. -- provide API to load configurations on demand. -- viewport resize handle. -- double-click on the tab bar to hide its content and only show a minimal list -of tabs. -- allow canvas resize on the right and at the bottom - not just the south-east -resize handle. -- allow single click on the image size, in the status bar to bring-up a panel -which shows the image dimensions, where the user can crop and resize the image. -- implement a GUI option to allow live changing of background color. -- flip and rotate image. -- some issues when middle/right clicking instead of simple left click on the -canvas, with some drawing tools. -- maybe selection rotate. -- maybe use .scale() and .translate() for selection manipulation. -- more per-tool settings. For example, do not share the lineWidth option between -tools. -- css 3 animations for the GUI. -- make the color mixer resizable. -- attempt color mixer code organization / code quality improvements. -- look into performance improvement specific to the color mixer. -- allow mousewheel scrolling on the color mixer slider. -- allow the user to focus the color mixer slider, to press up/down keys. -- allow the user to press Enter in the color mixer in an input to simply accept -the current color. -- (maybe) allow the user to press Escape in an input from the color mixer to -close/cancel the color change. -- retest overall performance and see if more things can be improved. More -importantly, try initialization performance improvements. -- allow mousewheel scroll to increase/decrease the numeric value in an input of -type=number. -- allow permanent color save in the color mixer. -- add a checkbox into the color mixer which allows the user to enable realtime -color changes, such that, without clicking accept, the user can test the new -color using some drawing tool. -- tab reordering and grouping. - -Each and every item is doable pretty "easy", but it takes a lot of time to do -all of the above. Some of the items might get dropped. On request, I can -prioritize any item from the list during GSOC. - -Further down the road: - -* allow editing of multiple images in a single paintweb instance; -* hybrid undo system, not like now (storing ImageDatas); -* hybrid drawing: vectorial + bitmap drawing; -* layers; -* non-destructive filters; -* color gradients and fill patterns; -* macros: look into the possibility of implementing a scripting API compatible - with that of Photoshop. Photoshop can run JavaScript. PaintWeb can run - JavaScript: just provide the same API. Obviously, PaintWeb could implement - only a subset, but it would be very good if this kind of work would be - successful. - -That should be all for now. Huh, lots of work to do. - -Volunteers are needed! Please contact me if you want to help. Thank you! ;) - --- -vim:set spell spl=en fenc=utf-8 ff=unix: - diff --git a/ext/moodle/gen_moodlelang.php b/ext/moodle/gen_moodlelang.php index 8003180..3cf8baa 100644 --- a/ext/moodle/gen_moodlelang.php +++ b/ext/moodle/gen_moodlelang.php @@ -18,7 +18,7 @@ * along with PaintWeb. If not, see . * * $URL: http://code.google.com/p/paintweb $ - * $Date: 2009-08-03 19:46:27 +0300 $ + * $Date: 2009-08-10 20:41:45 +0300 $ */ // This script allows you to convert PaintWeb JSON language files into Moodle @@ -36,6 +36,8 @@ // Warning: running this script will overwrite "paintweb.php" in your Moodle // lang/*/ folders. +// This script works with Moodle 1.9 and Moodle 2.0. + $paintweblangdir = '../../build/lang'; $moodlelangdir = '../../../../lang'; $moodlelangfile = 'paintweb.php'; @@ -72,17 +74,19 @@ * Convert a PaintWeb JSON language file to a Moodle PHP language file. * * @param string $file The file you want to convert. + * @return boolean True if the operation executed successfully, or false + * otherwise. */ function paintweb_convert_json_file($file) { global $moodlelangdir, $moodlelangfile, $paintweblangdir; - $lang = str_replace('.json', '', $file); + $lang = basename($file, '.json'); $outputfolder = $moodlelangdir . '/' . ($lang === 'en' ? 'en_utf8' : $lang); if (!is_dir($outputfolder)) { echo "Skipping $file because $outputfolder was not found.\n"; - continue; + return false; } $langparsed = file_get_contents($paintweblangdir . '/' . $file); @@ -91,7 +95,7 @@ function paintweb_convert_json_file($file) { $langparsed = json_decode($langparsed, true); if (!$langparsed) { echo "Parsing $file failed. \n"; - continue; + return false; } $output = ". * * $URL: http://code.google.com/p/paintweb $ - * $Date: 2009-08-03 19:35:04 +0300 $ + * $Date: 2009-08-10 15:58:48 +0300 $ */ // This script allows you to convert a Moodle PHP language file into a PaintWeb @@ -32,6 +32,8 @@ // Warning: running this script will overwrite the JSON language file from the // PaintWeb language folder. +// This script works with Moodle 1.9 and Moodle 2.0. + $paintweblangdir = '../../build/lang'; $moodlelangdir = '../../../../lang'; $moodlelangfile = 'paintweb.php'; diff --git a/ext/moodle/lang.json.php b/ext/moodle/lang.json.php index bae740b..65d60f3 100644 --- a/ext/moodle/lang.json.php +++ b/ext/moodle/lang.json.php @@ -18,12 +18,15 @@ * along with PaintWeb. If not, see . * * $URL: http://code.google.com/p/paintweb $ - * $Date: 2009-08-03 21:17:30 +0300 $ + * $Date: 2009-08-10 21:55:57 +0300 $ */ // This script generates the PaintWeb JSON language file dynamically using the // Moodle language files. The language picked is the one configured in Moodle. + +// This script works with Moodle 1.9 and Moodle 2.0. + require_once('../../../../config.php'); $moodlelangdir = '../../../../lang'; diff --git a/ext/moodle/update_tinymcelang.php b/ext/moodle/update_tinymcelang.php new file mode 100644 index 0000000..5e6de2f --- /dev/null +++ b/ext/moodle/update_tinymcelang.php @@ -0,0 +1,175 @@ +. + * + * $URL: http://code.google.com/p/paintweb $ + * $Date: 2009-08-10 21:12:30 +0300 $ + */ + +// This script allows you to update the TinyMCE language files from Moodle to +// hold the new strings of the TinyMCE plugin provided by PaintWeb. + +// In a typical setup, Moodle holds PaintWeb in lib/paintweb. + +// If you execute this script without any arguments, all the language files +// found in the TinyMCE plugin folder will be converted to the Moodle PHP +// language file format. The new strings will be appended to the +// editor_tinymce.php file from the Moodle languages folder. +// +// Optionally, you can give this script one argument, to tell it which language +// you want to update. This allows you to update only one language file, instead +// of all at once. + +// This script works only with Moodle 2.0. + +$pluginlangdir = '../tinymce-plugin/paintweb/langs'; +$moodlelangdir = '../../../../lang'; +$tinymcelangfile = 'editor_tinymce.php'; + +if (!is_dir($pluginlangdir)) { + echo "The TinyMCE plugin folder could not be found: $paintweblangdir\n"; + return 1; +} + +if (!is_dir($moodlelangdir)) { + echo "The Moodle folder could not be found: $moodlelangdir\n"; + return 1; +} + +if (isset($_SERVER['argv'][1])) { + $file = $_SERVER['argv'][1] . '.js'; + + if (!file_exists($pluginlangdir . '/' . $file)) { + echo "The TinyMCE plugin language file was not found: $pluginlangdir/$file\n"; + return 1; + } + + if (!paintweb_update_tinymcelang($file)) { + return 0; + } else { + return 1; + } +} + +$files = glob($pluginlangdir . '/*.js'); +foreach ($files as $file) { + echo "Reading $file.\n"; + paintweb_update_tinymcelang($file); +} + +/** + * Update a TinyMCE language file from the Moodle language folder + * (editor_tinymce.php) to include the language strings from the TinyMCE plugin + * provided by PaintWeb (see ext/tinymce-plugin/paintweb/langs). + * + * @param string $file The TinyMCE plugin language file (for example en.js) you + * want to read in order to update the associated editor_tinymce.php file from + * the Moodle language folder. + * + * @return boolean True if the operation was successful or false otherwise. + */ +function paintweb_update_tinymcelang($file) { + global $moodlelangdir, $tinymcelangfile, $pluginlangdir; + + if (empty($file)) { + return false; + } + + $file = basename($file); + $lang = substr($file, 0, 2); + + $content = file_get_contents($pluginlangdir . '/' . $file); + if (empty($content)) { + echo "Failed to read $pluginlangdir/$file\n"; + return false; + } + + if ($lang === 'en') { + $filephp = "$moodlelangdir/en_utf8/$tinymcelangfile"; + } else { + $filephp = "$moodlelangdir/$lang/$tinymcelangfile"; + } + + if (!file_exists($filephp)) { + echo "Skipping $lang. File not found: $filephp\n"; + return false; + } + + $output = file_get_contents($filephp); + if (empty($output)) { + echo "Failed to read $filephp\n"; + return false; + } + include($filephp); + + $group = ''; + $content = explode("\n", $content); + $json = ''; + foreach ($content as $line) { + $matches = array(); + + if (empty($line)) { + continue; + } + + if (preg_match('/tinymce\.addi18n\s*\([\'"][a-z]+\.([^\']+)[\'"]\s*,\s*\{/i', $line, $matches)) { + $group = $matches[1]; + + } else if (!empty($group) && preg_match('/}\s*\)\s*;*/', $line)) { + $group = ''; + + } else if (!empty($group) && preg_match('/^\s*([\'"]*)(.+?)\1\s*:\s*([\'"])(.+?)\3\s*,?/', $line, $matches)) { + $json .= ',"' . $group . ':' . $matches[2] .'": "' . $matches[4] . "\""; + } + } + + if (empty($json)) { + echo "No string was found in the language file $pluginlangdir/$file\n"; + return false; + } + + $json = json_decode('{' . substr($json, 1) . '}'); + + if (empty($json)) { + echo "Failed to parse the language file $pluginlangdir/$file\n"; + return false; + } + + foreach ($json as $key => $val) { + $key2 = var_export($key, true); + $val = var_export($val, true); + $line = "\$string[$key2] = $val;\n"; + + if (isset($string[$key])) { + $output = preg_replace('/^\$string[' . $key2 . '].+$/', $line, $output); + } else { + $output .= $line; + } + } + + if (file_put_contents($filephp, $output)) { + echo "Updated $filephp.\n"; + return true; + } else { + echo "Failed to update $filephp.\n"; + return false; + } +} + +// vim:set spell spl=en fo=tanqrowcb tw=80 ts=4 sw=4 sts=4 sta et noai nocin fenc=utf-8 ff=unix: + diff --git a/src/includes/lib.js b/src/includes/lib.js index 39fe0de..7374073 100644 --- a/src/includes/lib.js +++ b/src/includes/lib.js @@ -2,7 +2,7 @@ * © 2009 ROBO Design * http://www.robodesign.ro * - * $Date: 2009-07-30 19:20:27 +0300 $ + * $Date: 2009-08-04 19:34:48 +0300 $ */ /** @@ -185,15 +185,18 @@ pwlib.jsonParse = function (str) { * * @param {String} [method="GET"] The HTTP method to use for loading the URL. * - * @param {String} [send] The string you want to send in an HTTP POST request. + * @param {String} [send=null] The string you want to send in an HTTP POST + * request. * * @param {Object} [headers] An object holding the header names and values you * want to set for the request. * * @returns {XMLHttpRequest} The XMLHttpRequest object created by this method. + * + * @throws {TypeError} If the url is not a string. */ pwlib.xhrLoad = function (url, handler, method, send, headers) { - if (!url) { + if (typeof url !== 'string') { throw new TypeError('The first argument must be a string!'); } @@ -209,7 +212,9 @@ pwlib.xhrLoad = function (url, handler, method, send, headers) { send = null; } + /** @ignore */ var xhr = new XMLHttpRequest(); + /** @ignore */ xhr.onreadystatechange = function () { handler(xhr); }; xhr.open(method, url); @@ -2144,12 +2149,15 @@ pwlib.dom.KeyboardEventListener = function (elem_, handlers_) { } else { // This happens when the keydown event tries to dispatch a keypress event. - // FIXME: I could use createEvent() ... food for thought for later + // FIXME: I could use createEvent() ... food for thought for later. + + /** @ignore */ var ev_new = {}; pwlib.extend(ev_new, ev); ev_new.type = type; // Make sure preventDefault() is not borked... + /** @ignore */ ev_new.preventDefault = function () { ev.preventDefault(); }; diff --git a/src/paintweb.js b/src/paintweb.js index 145a5c9..9ba2281 100644 --- a/src/paintweb.js +++ b/src/paintweb.js @@ -17,7 +17,7 @@ * along with PaintWeb. If not, see . * * $URL: http://code.google.com/p/paintweb $ - * $Date: 2009-07-30 20:50:13 +0300 $ + * $Date: 2009-08-04 19:46:19 +0300 $ */ /** @@ -2308,8 +2308,11 @@ function PaintWeb (win, doc) { // huh, use XHR then eval() the code. // browsers do not dispatch the 'load' event reliably for script elements. + + /** @ignore */ var xhr = new XMLHttpRequest(); + /** @ignore */ xhr.onreadystatechange = function () { if (!xhr || xhr.readyState !== 4) { return;