diff --git a/3.0/modules/image_optimizer/controllers/admin_image_optimizer.php b/3.0/modules/image_optimizer/controllers/admin_image_optimizer.php new file mode 100644 index 00000000..aad840a3 --- /dev/null +++ b/3.0/modules/image_optimizer/controllers/admin_image_optimizer.php @@ -0,0 +1,163 @@ +_get_admin_form(); + $this->_print_screen($form); + } + + public function save() { + access::verify_csrf(); + $form = $this->_get_admin_form(); + if ($form->validate()) { + foreach (array('jpg', 'png', 'gif') as $type) { + module::set_var("image_optimizer", "path_".$type, $form->paths->{"path_".$type}->value); + module::set_var("image_optimizer", "optlevel_thumb_".$type, $form->thumb->{"optlevel_thumb_".$type}->value); + module::set_var("image_optimizer", "optlevel_resize_".$type, $form->resize->{"optlevel_resize_".$type}->value); + } + module::set_var("image_optimizer", "rotate_jpg", ($form->rotate->rotate_jpg->value == 1)); + foreach (array('thumb', 'resize') as $target) { + module::set_var("image_optimizer", "convert_".$target."_gif", $form->$target->{"convert_".$target."_gif"}->value); + module::set_var("image_optimizer", "convert_".$target."_png", $form->$target->{"convert_".$target."_png"}->value); + module::set_var("image_optimizer", "metastrip_".$target, ($form->$target->{"metastrip_".$target}->value == 1)); + module::set_var("image_optimizer", "progressive_".$target, ($form->$target->{"progressive_".$target}->value == 1)); + // deal with enable changes + $enable_old = module::get_var("image_optimizer", "enable_".$target); + $enable_new = ($form->$target->{"enable_".$target}->value == 1); + if ($enable_new && !$enable_old) { + image_optimizer::add_image_optimizer_rule($target); + module::set_var("image_optimizer", "enable_".$target, true); + } elseif (!$enable_new && $enable_old) { + image_optimizer::remove_image_optimizer_rule($target); + module::set_var("image_optimizer", "enable_".$target, false); + } + // deal with update mode changes + $update_mode_old = module::get_var("image_optimizer", "update_mode_".$target); + $update_mode_new = ($form->$target->{"update_mode_".$target}->value == 1); + if ($update_mode_new && !$update_mode_old) { + image_optimizer::activate_update_mode($target); + } elseif (!$update_mode_new && $update_mode_old) { + image_optimizer::deactivate_update_mode($target); + } + // dirty images if needed + if ($form->$target->{"rebuild_".$target}->value == 1) { + image_optimizer::dirty($target); + } + } + // all done; redirect with message + message::success(t("Image optimizer settings updated successfully")); + url::redirect("admin/image_optimizer"); + } + // not valid - print screen from existing form + $this->_print_screen($form); + } + + private function _print_screen($form) { + // this part is a bit of a hack, but Forge doesn't seem to allow set_attr() for groups. + $form = $form->render(); + $form = preg_replace("/
/","
",$form,2); + $form = preg_replace("/
/","
",$form,1); + $form = preg_replace("/
/","
",$form,1); + // make and print view + $view = new Admin_View("admin.html"); + $view->page_title = t("Image optimizer settings"); + $view->content = new View("admin_image_optimizer.html"); + $view->content->form = $form; + // get module parameters + foreach (array('jpg', 'png', 'gif') as $type) { + $view->content->{"installed_path_".$type} = image_optimizer::tool_installed_path($type); + $view->content->{"version_".$type} = image_optimizer::tool_version($type); + } + print $view; + } + + private function _get_admin_form() { + $form = new Forge("admin/image_optimizer/save", "", "post", array("id" => "g-image-optimizer-admin-form")); + + $group_paths = $form->group("paths")->label(t("Toolkit paths"))->set_attr("id","g-image-optimizer-admin-form-paths"); + foreach (array('jpg', 'png', 'gif') as $type) { + $path = strval(module::get_var("image_optimizer", "path_".$type, null)); + $group_paths->input("path_".$type) + ->label(t("Path for")." ".image_optimizer::tool_name($type)." (".t("no symlinks, default")." ".MODPATH."image_optimizer/lib/".image_optimizer::tool_name($type).")") + ->value($path); + } + + $group_rotate = $form->group("rotate")->label(t("Full-size image rotation"))->set_attr("id","g-image-optimizer-admin-form-rotate"); + $group_rotate->checkbox("rotate_jpg") + ->label(t("Override default toolkit and use")." ".image_optimizer::tool_name('jpg')." ".t("for rotation")) + ->checked(module::get_var("image_optimizer", "rotate_jpg", null)); + + foreach (array('thumb', 'resize') as $target) { + ${'group_'.$target} = $form->group($target)->label(ucfirst($target)." ".t("images optimization"))->set_attr("id","g-image-optimizer-admin-form-".$target); + ${'group_'.$target}->checkbox("enable_".$target) + ->label(t("Enable optimization")) + ->checked(module::get_var("image_optimizer", "enable_".$target, null)); + ${'group_'.$target}->checkbox("update_mode_".$target) + ->label(t("Enable update mode - deactivates all other graphics rules to allow fast optimization on existing images; MUST deactivate this after initial rebuild!")) + ->checked(module::get_var("image_optimizer", "update_mode_".$target, null)); + ${'group_'.$target}->checkbox("rebuild_".$target) + ->label(t("Mark all existing images for rebuild - afterward, go to Maintenace | Rebuild Images")) + ->checked(false); // always set as false + ${'group_'.$target}->dropdown("convert_".$target."_png") + ->label(t("PNG conversion")) + ->options(array(0=>t("none"), + "jpg"=>("JPG ".t("(not lossless)")))) + ->selected(module::get_var("image_optimizer", "convert_".$target."_png", null)); + ${'group_'.$target}->dropdown("convert_".$target."_gif") + ->label(t("GIF conversion")) + ->options(array(0=>t("none"), + "jpg"=>("JPG ".t("(not lossless)")), + "png"=>("PNG ".t("(lossless)")))) + ->selected(module::get_var("image_optimizer", "convert_".$target."_gif", null)); + ${'group_'.$target}->dropdown("optlevel_".$target."_jpg") + ->label(t("JPG compression optimization (default: enabled)")) + ->options(array(0=>t("disabled"), + 1=>t("enabled"))) + ->selected(module::get_var("image_optimizer", "optlevel_".$target."_jpg", null)); + ${'group_'.$target}->dropdown("optlevel_".$target."_png") + ->label(t("PNG compression optimization (default: level 2)")) + ->options(array(0=>t("disabled"), + 1=>t("level 1: 1 trial"), + 2=>t("level 2: 8 trials"), + 3=>t("level 3: 16 trials"), + 4=>t("level 4: 24 trials"), + 5=>t("level 5: 48 trials"), + 6=>t("level 6: 120 trials"), + 7=>t("level 7: 240 trials"))) + ->selected(module::get_var("image_optimizer", "optlevel_".$target."_png", null)); + ${'group_'.$target}->dropdown("optlevel_".$target."_gif") + ->label(t("GIF compression optimization (default: enabled)")) + ->options(array(0=>t("disabled"), + 1=>t("enabled"))) + ->selected(module::get_var("image_optimizer", "optlevel_".$target."_gif", null)); + ${'group_'.$target}->checkbox("metastrip_".$target) + ->label(t("Remove all meta data")) + ->checked(module::get_var("image_optimizer", "metastrip_".$target, null)); + ${'group_'.$target}->checkbox("progressive_".$target) + ->label(t("Make images progressive/interlaced")) + ->checked(module::get_var("image_optimizer", "progressive_".$target, null)); + } + + $form->submit("")->value(t("Save")); + return $form; + } +} \ No newline at end of file diff --git a/3.0/modules/image_optimizer/css/admin_image_optimizer.css b/3.0/modules/image_optimizer/css/admin_image_optimizer.css new file mode 100644 index 00000000..c03aa1f5 --- /dev/null +++ b/3.0/modules/image_optimizer/css/admin_image_optimizer.css @@ -0,0 +1,17 @@ +#g-content fieldset { + display: block; +} +#g-content fieldset.g-image-optimizer-admin-form-top { + width: 80%; + clear: both; +} +#g-content fieldset.g-image-optimizer-admin-form-left { + width: 45%; + float: left; + clear: left; + margin-right: 2% +} +#g-content fieldset.g-image-optimizer-admin-form-right { + width: 45%; + clear: right; +} \ No newline at end of file diff --git a/3.0/modules/image_optimizer/helpers/MY_gallery_graphics.php b/3.0/modules/image_optimizer/helpers/MY_gallery_graphics.php new file mode 100644 index 00000000..72a0a206 --- /dev/null +++ b/3.0/modules/image_optimizer/helpers/MY_gallery_graphics.php @@ -0,0 +1,72 @@ + 0 ? $options["degrees"] : $options["degrees"]+360; + $exec_args .= " -copy all -optimize -outfile "; + // run it - from input_file to tmp_file + $tmp_file = image_optimizer::make_temp_name($output_file); + exec(escapeshellcmd($path) . $exec_args . escapeshellarg($tmp_file) . " " . escapeshellarg($input_file), $exec_output, $exec_status); + if ($exec_status || !filesize($tmp_file)) { + // either a blank/nonexistant file or an error - log an error and pass to normal function + Kohana_Log::add("error", "image_optimizer rotation failed on ".$output_file); + unlink($tmp_file); + } else { + // worked - move temp to output + rename($tmp_file, $output_file); + $status = true; + } + } + if (!$status) { + // we got here if we weren't supposed to use jpegtran or if jpegtran failed + // END mod to original function + + Image::factory($input_file) + ->quality(module::get_var("gallery", "image_quality")) + ->rotate($options["degrees"]) + ->save($output_file); + + // BEGIN mod to original function + } + // END mod to original function + + module::event("graphics_rotate_completed", $input_file, $output_file, $options); + } +} \ No newline at end of file diff --git a/3.0/modules/image_optimizer/helpers/image_optimizer.php b/3.0/modules/image_optimizer/helpers/image_optimizer.php new file mode 100644 index 00000000..de8b964f --- /dev/null +++ b/3.0/modules/image_optimizer/helpers/image_optimizer.php @@ -0,0 +1,343 @@ +module_name = "image_optimizer"; + $rule->target = $target; + $rule->operation = 'image_optimizer::optimize'; + $rule->priority = 999999999; // this MUST be larger than all others to be last + $rule->args = serialize($target); // this isn't typical for other graphics rules + $rule->active = true; + $rule->save(); + } + + // remove image_optimizer rules without marking for dirty (based on remove_rule) + static function remove_image_optimizer_rule($target) { + db::build() + ->delete("graphics_rules") + ->where("target", "=", $target) + ->where("module_name", "=", "image_optimizer") + ->execute(); + } + + // activate update mode - disactivates all currently-active rules except those of image_optimizer without marking for dirty + // sets update_mode_thumb/resize variable with serialized list of deactivated rule ids + static function activate_update_mode($target) { + // find all currently active non-image-optimizer rules + $rules = db::build() + ->from("graphics_rules") + ->select("id") + ->where("active", "=", true) + ->where("target", "=", $target) + ->where("module_name", "!=", "image_optimizer") + ->execute(); + // use found rules to build ids array and deactivate rules + $ids = array(); + foreach ($rules as $rule) { + $ids[] = $rule->id; + db::build() + ->update("graphics_rules") + ->where("id", "=", $rule->id) + ->set("active", false) // deactivation! + ->execute(); + } + // set module variable as deactivated rule ids + module::set_var("image_optimizer", "update_mode_".$target, serialize($ids)); + // display a warning that we're in update mode + site_status::warning( + t("Image optimizer is in thumb/resize update mode - remember to exit here after rebuild!", + array("url" => html::mark_clean(url::site("admin/image_optimizer")))), + "image_optimizer_update_mode"); + } + + // deactivate update mode - re-activates rules marked in the update_mode_thumb/resize variable as previously deactivated + static function deactivate_update_mode($target) { + // get deactivated rule ids + $ids = unserialize(module::get_var("image_optimizer", "update_mode_".$target)); + // activate them + foreach ($ids as $id) { + db::build() + ->update("graphics_rules") + ->where("id", "=", $id) + ->set("active", true) // activation! + ->execute(); + } + // reset module variable + module::set_var("image_optimizer", "update_mode_".$target, false); + // clear update mode warning + if (!module::get_var("image_optimizer", "update_mode_thumb") && !module::get_var("image_optimizer", "update_mode_resize")) { + site_status::clear("image_optimizer_update_mode"); + } + } + + // mark all as dirty (in similar syntax to above) + static function dirty($target) { + graphics::mark_dirty($target == "thumb", $target == "resize"); + } + + /** + * the main optimize function + * + * the function arguments are the same format as other graphics rules. the only "option" is $target, hence why it's renamed in the function def. + * + * NOTE: unlike other graphics transformations, this only uses the output file! if it isn't already there, we don't do anything. + * among other things, this means that the original, full-size images are never touched. + */ + static function optimize($input_file, $output_file, $target, $item=null) { + + // see if output file exists and is writable + if (is_writable($output_file)) { + // see if input is a supported file type. if not, return without doing anything. + $image_info = getimagesize($input_file); // [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG) + switch ($image_info[2]) { + case 1: + $type_old = "gif"; + $convert = module::get_var("image_optimizer", "convert_".$target."_gif"); + break; + case 2: + $type_old = "jpg"; + $convert = 0; // no conversion possible here... + break; + case 3: + $type_old = "png"; + $convert = module::get_var("image_optimizer", "convert_".$target."_png"); + break; + default: + // not a supported file type + return; + } + } else { + // file doesn't exist or isn't writable + return; + } + // set new file type + $type = $convert ? $convert : $type_old; + + // convert image type (if applicable). this isn't necessarily lossless. + if ($convert) { + $output_file_new = legal_file::change_extension($output_file, $type); + // perform conversion using standard Gallery toolkit (GD/ImageMagick/GraphicsMagick) + // note: if input was a GIF, this will kill animation + $image = Image::factory($output_file) + ->quality(module::get_var("gallery", "image_quality")) + ->save($output_file_new); + // if filenames are different, move the new on top of the old + if ($output_file != $output_file_new) { + /** + * HACK ALERT! Gallery3 is still broken with regard to treating thumb/resizes with proper extensions. This doesn't try to fix that. + * Normal Gallery setup: + * photo thumb -> keep photo type, keep photo extension + * album thumb -> keep source photo thumb type, change extension to jpg (i.e. ".album.jpg" even for png/gif) + * Also, missing_photo.png is similarly altered... + * + * Anyway, to avoid many rewrites of core functions (and not-easily-reversible database changes), this module also forces the extension to stay the same. + * With image optimizer conversion: + * photo thumb -> change type, keep photo extension (i.e. "photo.png" photo becomes "photo.png" thumb even if type has changed) + * album thumb -> keep source photo thumb type, change extension to jpg (i.e. ".album.jpg" even for png/gif) + */ + rename($output_file_new, $output_file); + } + } + + // get module variables + $configstatus = module::get_var("image_optimizer", "configstatus_".$type); + $path = module::get_var("image_optimizer", "path_".$type); + $opt = module::get_var("image_optimizer", "optlevel_".$target."_".$type); + $meta = module::get_var("image_optimizer", "metastrip_".$target); + $prog = module::get_var("image_optimizer", "progressive_".$target); + + // make sure the toolkit is configured correctly and we want to use it - if not, return without doing anything. + if ($configstatus) { + if (!$prog && !$meta && !$opt) { + // nothing to do! + return; + } + } else { + // not configured correctly + return; + } + + /** + * do the actual optimization + */ + + // set parameters + switch ($type) { + case "jpg": + $exec_args = $opt ? " -optimize" : ""; + $exec_args .= $meta ? " -copy none" : " -copy all"; + $exec_args .= $prog ? " -progressive" : ""; + $exec_args .= " -outfile "; + break; + case "png": + $exec_args = $opt ? " -o".$opt : ""; + $exec_args .= $meta ? " -strip all" : ""; + $exec_args .= $prog ? " -i 1" : ""; + $exec_args .= " -quiet -out "; + break; + case "gif": + $exec_args = $opt ? " --optimize=3" : ""; // levels 1 and 2 don't really help us + $exec_args .= $meta ? " --no-comments --no-extensions --no-names" : " --same-comments --same-extensions --same-names"; + $exec_args .= $prog ? " --interlace" : " --same-interlace"; + $exec_args .= " --careful --output "; + break; + } + + // run it - from output_file to tmp_file. + $tmp_file = image_optimizer::make_temp_name($output_file); + exec(escapeshellcmd($path) . $exec_args . escapeshellarg($tmp_file) . " " . escapeshellarg($output_file), $exec_output, $exec_status); + if ($exec_status || !filesize($tmp_file)) { + // either a blank/nonexistant file or an error - do nothing to the output, but log an error and delete the temp (if any) + Kohana_Log::add("error", "image_optimizer optimization failed on ".$output_file); + unlink($tmp_file); + } else { + // worked - move temp to output + rename($tmp_file, $output_file); + } + } + + /** + * make a unique temporary filename. this bit is inspired/copied from + * the system/libraries/Image.php save function and the system/libraries/drivers/Image/ImageMagick.php process function + */ + static function make_temp_name($file) { + // Separate the directory and filename + $dir = pathinfo($file, PATHINFO_DIRNAME); + $file = pathinfo($file, PATHINFO_BASENAME); + + // Normalize the path + $dir = str_replace('\\', '/', realpath($dir)).'/'; + + // Unique temporary filename + $tmp_file = $dir.'k2img--'.sha1(time().$dir.$file).substr($file, strrpos($file, '.')); + + return $tmp_file; + } + + /** + * get stdin, stdout, or stderr from shell command. php commands like exec() don't do this. + * this is only used to get jpegtran's version info in the admin screen. + * + * see http://stackoverflow.com/questions/2320608/php-stderr-after-exec + */ + static function get_pipe($cmd, $pipe) { + $descriptorspec = array( + 0 => array("pipe", "r"), // stdin + 1 => array("pipe", "w"), // stdout + 2 => array("pipe", "w"), // stderr + ); + $process = proc_open($cmd, $descriptorspec, $pipes); + $output = stream_get_contents($pipes[$pipe]); + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + proc_close($process); + return $output; + } +} \ No newline at end of file diff --git a/3.0/modules/image_optimizer/helpers/image_optimizer_event.php b/3.0/modules/image_optimizer/helpers/image_optimizer_event.php new file mode 100644 index 00000000..41bdd503 --- /dev/null +++ b/3.0/modules/image_optimizer/helpers/image_optimizer_event.php @@ -0,0 +1,29 @@ +get("settings_menu") + ->append( + Menu::factory("link") + ->id("image_optimizer") + ->label(t("Image optimizer")) + ->url(url::site("admin/image_optimizer"))); + } +} diff --git a/3.0/modules/image_optimizer/helpers/image_optimizer_installer.php b/3.0/modules/image_optimizer/helpers/image_optimizer_installer.php new file mode 100644 index 00000000..73dd6404 --- /dev/null +++ b/3.0/modules/image_optimizer/helpers/image_optimizer_installer.php @@ -0,0 +1,75 @@ + '1', 'png' => '2', 'gif' => '1'); + foreach ($defaults as $type => $optlevel) { + // set default path as the pre-compiled versions in the lib + module::set_var("image_optimizer", "path_".$type, MODPATH."image_optimizer/lib/".image_optimizer::tool_name($type)); + // check config status (also sets configstatus_ variables and ensures that the permissions are set correctly) + image_optimizer::tool_status($type); + // set default optimization levels + module::set_var("image_optimizer", "optlevel_thumb_".$type, $optlevel); + module::set_var("image_optimizer", "optlevel_resize_".$type, $optlevel); + } + module::set_var("image_optimizer", "rotate_jpg", true); + module::set_var("image_optimizer", "enable_thumb", true); + module::set_var("image_optimizer", "enable_resize", true); + module::set_var("image_optimizer", "update_mode_thumb", false); + module::set_var("image_optimizer", "update_mode_resize", false); + module::set_var("image_optimizer", "metastrip_thumb", true); + module::set_var("image_optimizer", "convert_thumb_png", "jpg"); + module::set_var("image_optimizer", "convert_resize_png", false); + module::set_var("image_optimizer", "convert_thumb_gif", "jpg"); + module::set_var("image_optimizer", "convert_resize_gif", false); + module::set_var("image_optimizer", "metastrip_resize", false); + module::set_var("image_optimizer", "progressive_thumb", false); + module::set_var("image_optimizer", "progressive_resize", true); + module::set_version("image_optimizer", 1); + image_optimizer::add_image_optimizer_rule("thumb"); + image_optimizer::add_image_optimizer_rule("resize"); + } + + static function activate() { + // add graphics rules if enabled + if (module::get_var("image_optimizer", "enable_thumb")) { + image_optimizer::add_image_optimizer_rule("thumb"); + } + if (module::get_var("image_optimizer", "enable_resize")) { + image_optimizer::add_image_optimizer_rule("resize"); + } + } + + static function deactivate() { + // ensure that update modes are disabled + image_optimizer::deactivate_update_mode("thumb"); + image_optimizer::deactivate_update_mode("resize"); + // remove graphics rules + image_optimizer::remove_image_optimizer_rule("thumb"); + image_optimizer::remove_image_optimizer_rule("resize"); + } + + static function uninstall() { + // deactivate + module::deactivate("image_optimizer"); + // delete vars from database + module::clear_all_vars("image_optimizer"); + } +} \ No newline at end of file diff --git a/3.0/modules/image_optimizer/lib/gifsicle b/3.0/modules/image_optimizer/lib/gifsicle new file mode 100644 index 00000000..0af29c73 Binary files /dev/null and b/3.0/modules/image_optimizer/lib/gifsicle differ diff --git a/3.0/modules/image_optimizer/lib/gifsicle.exe b/3.0/modules/image_optimizer/lib/gifsicle.exe new file mode 100644 index 00000000..79280a01 Binary files /dev/null and b/3.0/modules/image_optimizer/lib/gifsicle.exe differ diff --git a/3.0/modules/image_optimizer/lib/jpegtran b/3.0/modules/image_optimizer/lib/jpegtran new file mode 100644 index 00000000..ebdb0e3c Binary files /dev/null and b/3.0/modules/image_optimizer/lib/jpegtran differ diff --git a/3.0/modules/image_optimizer/lib/jpegtran.exe b/3.0/modules/image_optimizer/lib/jpegtran.exe new file mode 100644 index 00000000..e1f21973 Binary files /dev/null and b/3.0/modules/image_optimizer/lib/jpegtran.exe differ diff --git a/3.0/modules/image_optimizer/lib/optipng b/3.0/modules/image_optimizer/lib/optipng new file mode 100644 index 00000000..a7706595 Binary files /dev/null and b/3.0/modules/image_optimizer/lib/optipng differ diff --git a/3.0/modules/image_optimizer/lib/optipng.exe b/3.0/modules/image_optimizer/lib/optipng.exe new file mode 100644 index 00000000..9b0c9e05 Binary files /dev/null and b/3.0/modules/image_optimizer/lib/optipng.exe differ diff --git a/3.0/modules/image_optimizer/module.info b/3.0/modules/image_optimizer/module.info new file mode 100644 index 00000000..e91084e9 --- /dev/null +++ b/3.0/modules/image_optimizer/module.info @@ -0,0 +1,7 @@ +name = Image Optimizer +description = "Use jpegtran, optipng, and gifsicle for lossless optimization and rotation." +version = 1 +author_name = "Shad Laws" +author_url = "" +info_url = "http://codex.gallery2.org/Gallery3:Modules:image_optimizer" +discuss_url = "http://gallery.menalto.com/node/110262" diff --git a/3.0/modules/image_optimizer/views/admin_image_optimizer.html.php b/3.0/modules/image_optimizer/views/admin_image_optimizer.html.php new file mode 100644 index 00000000..700fbf68 --- /dev/null +++ b/3.0/modules/image_optimizer/views/admin_image_optimizer.html.php @@ -0,0 +1,51 @@ + + +
+

+ +

+

+ lossless transformations.")." ". + t("You can set the paths to each of the three toolkits below.")." ". + t("By default, this module uses it's own pre-compiled versions, included as libraries.")." ". + t("Additionally, your server may have copies installed elsewhere (see table below).") ?>
+ + + + + + + + + + + + + + + + + + + + + + + + + +
JPGJpegtran Jpegclub
PNGOptiPNG Cosmin Truta et al.
GIFGIFsicle LCDF
+ EWWW Image Optimizer ".t("and the Gallery3 module")." Jpegtran." ?> +

+

+
+ 1. :
+ 2. :
+ 3. :
+ 4. :
+ 5. :
+

+ +
\ No newline at end of file diff --git a/3.0/modules/register/css/register.css b/3.0/modules/register/css/register.css new file mode 100644 index 00000000..adbac655 --- /dev/null +++ b/3.0/modules/register/css/register.css @@ -0,0 +1 @@ +#g-register-form { width: 350px; } \ No newline at end of file diff --git a/3.0/modules/register/views/register_admin_notify.html.php b/3.0/modules/register/views/register_admin_notify.html.php new file mode 100644 index 00000000..39cd04d8 --- /dev/null +++ b/3.0/modules/register/views/register_admin_notify.html.php @@ -0,0 +1,15 @@ + + + + <?= ($subject_prefix.$subject) ?> + + +

+

+ You can access the site by clicking this link, after which you can review and approve this request.", + array("name" => $user->full_name ? $user->full_name : $user->name, + "locale" => $locale, + "site_url" => html::mark_clean($admin_register_url))) ?> +

+ + diff --git a/3.0/modules/tag_cloud_html5/js/jquery.tagcanvas.mod.js b/3.0/modules/tag_cloud_html5/js/jquery.tagcanvas.mod.js new file mode 100644 index 00000000..016a2917 --- /dev/null +++ b/3.0/modules/tag_cloud_html5/js/jquery.tagcanvas.mod.js @@ -0,0 +1,1014 @@ +/** + * Copyright (C) 2010-2012 Graham Breach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +/** + * jQuery.tagcanvas 1.17.1 + * For more information, please contact + */ +/** + * Modified by Shad Laws 2012/06/08 -- all modified lines have "mod Shad Laws" comments + * - built a physics-based model for motion, which is activated with the physModel flag + * - included initialDecel, deadZone, maxInputZone, and physModel as options + * - set defaults of new options to mimic behavior without them (false, 0, 0, and false) + * - removed two unnecessary variable declarations caught by YUI Compressor + * - fixed initialization of a few variables (minSpeed, decel, yaw/pitch) + * - fixed problem with html margin-top changing coordinates in IE (but not Chrome or Firefox) + */ +(function($) { +// var i, j, abs = Math.abs, sin = Math.sin, cos = Math.cos, max = Math.max, min = Math.min, // mod Shad Laws +var i, j, abs = Math.abs, sin = Math.sin, cos = Math.cos, max = Math.max, min = Math.min, sqrt = Math.sqrt, // mod Shad Laws + hexlookup3 = {}, hexlookup2 = {}, hexlookup1 = { + 0:"0,", 1:"17,", 2:"34,", 3:"51,", 4:"68,", 5:"85,", + 6:"102,", 7:"119,", 8:"136,", 9:"153,", a:"170,", A:"170,", + b:"187,", B:"187,", c:"204,", C:"204,", d:"221,", D:"221,", + e:"238,", E:"238,", f:"255,", F:"255," +}, Oproto, Tproto, TCproto, doc = document, ocanvas, handlers = {}; +for(i = 0; i < 256; ++i) { + j = i.toString(16); + if(i < 16) + j = '0' + j; + hexlookup2[j] = hexlookup2[j.toUpperCase()] = i.toString() + ','; +} +function Defined(d) { + return typeof(d) != 'undefined'; +} +function Shuffle(a) { + var i = a.length-1, t, p; + while(i) { + p = ~~(Math.random()*i); + t = a[i]; + a[i] = a[p]; + a[p] = t; + --i; + } +} +function PointsOnSphere(n,xr,yr,zr) { + var i, y, r, phi, pts = [], inc = Math.PI * (3-Math.sqrt(5)), off = 2/n; + for(i = 0; i < n; ++i) { + y = i * off - 1 + (off / 2); + r = Math.sqrt(1 - y*y); + phi = i * inc; + pts.push([cos(phi) * r * xr, y * yr, sin(phi) * r * zr]); + } + return pts; +} +function Cylinder(n,o,xr,yr,zr,i,j,k,l) { + var phi, pts = [], inc = Math.PI * (3-Math.sqrt(5)), off = 2/n; + for(i = 0; i < n; ++i) { + j = i * off - 1 + (off / 2); + phi = i * inc; + k = cos(phi); + l = sin(phi); + pts.push(o ? [j * xr, k * yr, l * zr] : [k * xr, j * yr, l * zr]); + } + return pts; +} +function PointsOnCylinderV(n,xr,yr,zr) { return Cylinder(n, 0, xr, yr, zr) } +function PointsOnCylinderH(n,xr,yr,zr) { return Cylinder(n, 1, xr, yr, zr) } +function SetAlpha(c,a) { + var d = c, p1, p2, ae = (a*1).toPrecision(3) + ')'; + if(c[0] === '#') { + if(!hexlookup3[c]) + if(c.length === 4) + hexlookup3[c] = 'rgba(' + hexlookup1[c[1]] + hexlookup1[c[2]] + hexlookup1[c[3]]; + else + hexlookup3[c] = 'rgba(' + hexlookup2[c.substr(1,2)] + hexlookup2[c.substr(3,2)] + hexlookup2[c.substr(5,2)]; + d = hexlookup3[c] + ae; + } else if(c.substr(0,4) === 'rgb(' || c.substr(0,4) === 'hsl(') { + d = (c.replace('(','a(').replace(')', ',' + ae)); + } else if(c.substr(0,5) === 'rgba(' || c.substr(0,5) === 'hsla(') { + p1 = c.lastIndexOf(',') + 1, p2 = c.indexOf(')'); + a *= parseFloat(c.substring(p1,p2)); + d = c.substr(0,p1) + a.toPrecision(3) + ')'; + } + return d; +} +function NewCanvas(w,h) { + // if using excanvas, give up now + if(window.G_vmlCanvasManager) + return null; + var c = doc.createElement('canvas'); + c.width = w; + c.height = h; + return c; +} +// I think all browsers pass this test now... +function ShadowAlphaBroken() { + var cv = NewCanvas(3,3), c, i; + if(!cv) + return false; + c = cv.getContext('2d'); + c.strokeStyle = '#000'; + c.shadowColor = '#fff'; + c.shadowBlur = 3; + c.globalAlpha = 0; + c.strokeRect(2,2,2,2); + c.globalAlpha = 1; + i = c.getImageData(2,2,1,1); + cv = null; + return (i.data[0] > 0); +} +function FindGradientColour(t,p) { + var l = 1024, g = t.weightGradient, cv, c, i, gd, d; + if(t.gCanvas) { + c = t.gCanvas.getContext('2d'); + } else { + t.gCanvas = cv = NewCanvas(l,1); + if(!cv) + return null; + c = cv.getContext('2d'); + gd = c.createLinearGradient(0,0,l,0); + for(i in g) + gd.addColorStop(1-i, g[i]); + c.fillStyle = gd; + c.fillRect(0,0,l,1); + } + d = c.getImageData(~~((l-1)*p),0,1,1).data; + return 'rgba(' + d[0] + ',' + d[1] + ',' + d[2] + ',' + (d[3]/255) + ')'; +} +function TextSet(c,f,l,s,sc,sb,so) { + var xo = (sb || 0) + (so && so[0] < 0 ? abs(so[0]) : 0), + yo = (sb || 0) + (so && so[1] < 0 ? abs(so[1]) : 0); + c.font = f; + c.textBaseline = 'top'; + c.fillStyle = l; + sc && (c.shadowColor = sc); + sb && (c.shadowBlur = sb); + so && (c.shadowOffsetX = so[0], c.shadowOffsetY = so[1]); + c.fillText(s, xo, yo); +} +function TextToCanvas(s,f,ht,w,h,l,sc,sb,so,padx,pady) { + var cw = w + abs(so[0]) + sb + sb, ch = h + abs(so[1]) + sb + sb, cv, c; + cv = NewCanvas(cw+padx,ch+pady); + if(!cv) + return null; + c = cv.getContext('2d'); + TextSet(c,f,l,s,sc,sb,so); + return cv; +} +function AddShadowToImage(i,sc,sb,so) { + var cw = i.width + abs(so[0]) + sb + sb, ch = i.height + abs(so[1]) + sb + sb, cv, c, + xo = (sb || 0) + (so && so[0] < 0 ? abs(so[0]) : 0), + yo = (sb || 0) + (so && so[1] < 0 ? abs(so[1]) : 0); + cv = NewCanvas(cw,ch); + if(!cv) + return null; + c = cv.getContext('2d'); + sc && (c.shadowColor = sc); + sb && (c.shadowBlur = sb); + so && (c.shadowOffsetX = so[0], c.shadowOffsetY = so[1]); + c.drawImage(i, xo, yo); + return cv; +} +function FindTextBoundingBox(s,f,ht) { + var w = parseInt(s.length * ht), h = parseInt(ht * 2), cv = NewCanvas(w,h), c, idata, w1, h1, x, y, i, ex; + if(!cv) + return null; + c = cv.getContext('2d'); + c.fillStyle = '#000'; + c.fillRect(0,0,w,h); + TextSet(c,ht + 'px ' + f,'#fff',s) + + idata = c.getImageData(0,0,w,h); + w1 = idata.width; h1 = idata.height; + ex = { + min: { x: w1, y: h1 }, + max: { x: -1, y: -1 } + }; + for(y = 0; y < h1; ++y) { + for(x = 0; x < w1; ++x) { + i = (y * w1 + x) * 4; + if(idata.data[i+1] > 0) { + if(x < ex.min.x) ex.min.x = x; + if(x > ex.max.x) ex.max.x = x; + if(y < ex.min.y) ex.min.y = y; + if(y > ex.max.y) ex.max.y = y; + } + } + } + // device pixels might not be css pixels + if(w1 != w) { + ex.min.x *= (w / w1); + ex.max.x *= (w / w1); + } + if(h1 != h) { + ex.min.y *= (w / h1); + ex.max.y *= (w / h1); + } + + cv = null; + return ex; +} +function FixFont(f) { + return "'" + f.replace(/(\'|\")/g,'').replace(/\s*,\s*/g, "', '") + "'"; +} +function AddHandler(h,f,e) { + e = e || doc; + if(e.addEventListener) + e.addEventListener(h,f,false); + else + e.attachEvent('on' + h, f); +} +function AddImage(i,o,t,tc) { + var tl = tc.taglist, s = tc.imageScale; + if(s && !(o.width && o.height)) { + // images are not yet rendered, wait for window onload + AddHandler('load', function() { AddImage(i,o,t,tc); }, window); + return; + } + if(!i.complete) { + // image not loaded, wait for image onload + AddHandler('load',function() { AddImage(i,o,t,tc); }, i); + return; + } + + // Yes, this does look like nonsense, but it makes sure that both the + // width and height are actually set and not just calculated. This is + // required to keep proportional sizes when the images are hidden, so + // the images can be used again for another cloud. + o.width = o.width; + o.height = o.height; + + if(s) { + i.width = o.width * s; + i.height = o.height * s; + } + t.w = i.width; + t.h = i.height; + tl.push(t); +} +function GetProperty(e,p) { + var dv = doc.defaultView, pc = p.replace(/\-([a-z])/g,function(a){return a.charAt(1).toUpperCase()}); + return (dv && dv.getComputedStyle && dv.getComputedStyle(e,null).getPropertyValue(p)) || + (e.currentStyle && e.currentStyle[pc]); +} +function FindWeight(t,a) { + var w = 1, p; + if(t.weightFrom) { + w = 1 * (a.getAttribute(t.weightFrom) || t.textHeight); + } else if(p = GetProperty(a,'font-size')) { + w = (p.indexOf('px') > -1 && p.replace('px','') * 1) || + (p.indexOf('pt') > -1 && p.replace('pt','') * 1.25) || + p * 3.3; + } else { + t.weight = false; + } + return w; +} +function MouseOut(e) { + MouseMove(e); + var cv = e.target || e.fromElement.parentNode, tc = TagCanvas.tc[cv.id]; + tc && (tc.mx = tc.my = -1); +} +function MouseMove(e) { + var i, tc, dd = doc.documentElement, o; + for(i in TagCanvas.tc) { + tc = TagCanvas.tc[i]; + if(tc.tttimer) { + clearTimeout(tc.tttimer); + tc.tttimer = null; + } + o = $(tc.canvas).offset(); + // if(e.pageX) { // mod Shad Laws + if(e.offsetX) { // mod Shad Laws + // this works for IE + tc.mx = e.offsetX; // mod Shad Laws + tc.my = e.offsetY; // mod Shad Laws + } else if(e.pageX) { // mod Shad Laws + // this doesn't work for IE --> e.pageY = -parseInt($("html").css("margin-left"), 10) for the top row! + tc.mx = e.pageX - o.left; + tc.my = e.pageY - o.top; + } else { + tc.mx = e.clientX + (dd.scrollLeft || doc.body.scrollLeft) - o.left; + tc.my = e.clientY + (dd.scrollTop || doc.body.scrollTop) - o.top; + } + } +} +function MouseClick(e) { + var t = TagCanvas, cb = doc.addEventListener ? 0 : 1, + tg = e.target && Defined(e.target.id) ? e.target.id : e.srcElement.parentNode.id; + if(tg && e.button == cb && t.tc[tg]) { + MouseMove(e); + t.tc[tg].Clicked(e); + } +} +function MouseWheel(e) { + var t = TagCanvas, + tg = e.target && Defined(e.target.id) ? e.target.id : e.srcElement.parentNode.id; + if(tg && t.tc[tg]) { + e.cancelBubble = true; + e.returnValue = false; + e.preventDefault && e.preventDefault(); + t.tc[tg].Wheel((e.wheelDelta || e.detail) > 0); + } +} +function DrawCanvas() { + var t = TagCanvas.tc, i; + for(i in t) + t[i].Draw(); +} +function RotX(p1,t) { + var s = sin(t), c = cos(t); + return {x:p1.x, y:(p1.y * c) + (p1.z * s), z:(p1.y * -s) + (p1.z * c)}; +} +function RotY(p1,t) { + var s = sin(t), c = cos(t); + return {x:(p1.x * c) + (p1.z * -s), y:p1.y, z:(p1.x * s) + (p1.z * c)}; +} +function Project(tc,p1,w,h,sx,sy) { + var yn, xn, zn, m = tc.z1 / (tc.z1 + tc.z2 + p1.z); + yn = p1.y * m * sy; + xn = p1.x * m * sx; + zn = tc.z2 + p1.z; + return {x:xn, y:yn, z:zn}; +} +/** + * @constructor + */ +function Outline(tc) { + this.ts = new Date().valueOf(); + this.tc = tc; + this.x = this.y = this.w = this.h = this.sc = 1; + this.z = 0; + this.Draw = tc.pulsateTo < 1 && tc.outlineMethod != 'colour' ? this.DrawPulsate : this.DrawSimple; + this.SetMethod(tc.outlineMethod); +} +Oproto = Outline.prototype; +Oproto.SetMethod = function(om) { + var methods = { + block: ['PreDraw','DrawBlock'], + colour: ['PreDraw','DrawColour'], + outline: ['PostDraw','DrawOutline'], + classic: ['LastDraw','DrawOutline'], + none: ['LastDraw'] + }, funcs = methods[om] || methods.outline; + if(om == 'none') { + this.Draw = function() { return 1; } + } else { + this.drawFunc = this[funcs[1]]; + } + this[funcs[0]] = this.Draw; +}; +Oproto.Update = function(x,y,w,h,sc,p,xo,yo) { + var o = this.tc.outlineOffset, o2 = 2 * o; + this.x = sc * x + xo - o; + this.y = sc * y + yo - o; + this.w = sc * w + o2; + this.h = sc * h + o2; + this.sc = sc; // used to determine frontmost + this.z = p.z; +}; +Oproto.DrawOutline = function(c,x,y,w,h,colour) { + c.strokeStyle = colour; + c.strokeRect(x,y,w,h); +}; +Oproto.DrawColour = function(c,x,y,w,h,colour,tag,x1,y1) { + return this[tag.image ? 'DrawColourImage' : 'DrawColourText'](c,x,y,w,h,colour,tag,x1,y1); +}; +Oproto.DrawColourText = function(c,x,y,w,h,colour,tag,x1,y1) { + var normal = tag.colour; + tag.colour = colour; + tag.Draw(c,x1,y1); + tag.colour = normal; + return 1; +}; +Oproto.DrawColourImage = function(c,x,y,w,h,colour,tag,x1,y1) { + var ccanvas = c.canvas, fx = ~~max(x,0), fy = ~~max(y,0), + fw = min(ccanvas.width - fx, w) + .5|0, fh = min(ccanvas.height - fy,h) + .5|0, cc; + if(ocanvas) + ocanvas.width = fw, ocanvas.height = fh; + else + ocanvas = NewCanvas(fw, fh); + if(!ocanvas) + return this.SetMethod('outline'); // if using IE and images, give up! + cc = ocanvas.getContext('2d'); + + cc.drawImage(ccanvas,fx,fy,fw,fh,0,0,fw,fh); + c.clearRect(fx,fy,fw,fh); + tag.Draw(c,x1,y1); + c.setTransform(1,0,0,1,0,0); + c.save(); + c.beginPath(); + c.rect(fx,fy,fw,fh); + c.clip(); + c.globalCompositeOperation = 'source-in'; + c.fillStyle = colour; + c.fillRect(fx,fy,fw,fh); + c.restore(); + c.globalCompositeOperation = 'destination-over'; + c.drawImage(ocanvas,0,0,fw,fh,fx,fy,fw,fh); + c.globalCompositeOperation = 'source-over'; + return 1; +}; +Oproto.DrawBlock = function(c,x,y,w,h,colour) { + c.fillStyle = colour; + c.fillRect(x,y,w,h); +}; +Oproto.DrawSimple = function(c, tag, x1, y1) { + var t = this.tc; + c.setTransform(1,0,0,1,0,0); + c.strokeStyle = t.outlineColour; + c.lineWidth = t.outlineThickness; + c.shadowBlur = c.shadowOffsetX = c.shadowOffsetY = 0; + c.globalAlpha = 1; + return this.drawFunc(c,this.x,this.y,this.w,this.h,t.outlineColour,tag,x1,y1); +}; +Oproto.DrawPulsate = function(c, tag, x1, y1) { + var diff = new Date().valueOf() - this.ts, t = this.tc; + c.setTransform(1,0,0,1,0,0); + c.strokeStyle = t.outlineColour; + c.lineWidth = t.outlineThickness; + c.shadowBlur = c.shadowOffsetX = c.shadowOffsetY = 0; + c.globalAlpha = t.pulsateTo + ((1 - t.pulsateTo) * + (0.5 + (cos(2 * Math.PI * diff / (1000 * t.pulsateTime)) / 2))); + return this.drawFunc(c,this.x,this.y,this.w,this.h,t.outlineColour,tag,x1,y1); +}; +Oproto.Active = function(c,x,y) { + return (x >= this.x && y >= this.y && + x <= this.x + this.w && y <= this.y + this.h); +}; +Oproto.PreDraw = Oproto.PostDraw = Oproto.LastDraw = function() {}; +/** + * @constructor + */ +function Tag(tc,name,a,v,w,h,col,font) { + var c = tc.ctxt, i; + this.tc = tc; + this.image = name.src ? name : null; + this.name = name.src ? '' : name; + this.title = a.title || null; + this.a = a; + this.p3d = { x: v[0] * tc.radius * 1.1, y: v[1] * tc.radius * 1.1, z: v[2] * tc.radius * 1.1}; + this.x = this.y = 0; + this.w = w; + this.h = h; + this.colour = col || tc.textColour; + this.textFont = font || tc.textFont; + this.weight = this.sc = this.alpha = 1; + this.weighted = !tc.weight; + this.outline = new Outline(tc); + if(this.image) { + if(tc.txtOpt && tc.shadow) { + i = AddShadowToImage(this.image,tc.shadow,tc.shadowBlur,tc.shadowOffset); + if(i) { + this.image = i; + this.w = i.width; + this.h = i.height; + } + } + } else { + this.textHeight = tc.textHeight; + this.extents = FindTextBoundingBox(this.name, this.textFont, this.textHeight); + this.Measure(c,tc); + } + this.SetShadowColour = tc.shadowAlpha ? this.SetShadowColourAlpha : this.SetShadowColourFixed; + this.SetDraw(tc); +} +Tproto = Tag.prototype; +Tproto.SetDraw = function(t) { + this.Draw = this.image ? (t.ie > 7 ? this.DrawImageIE : this.DrawImage) : this.DrawText; + t.noSelect && (this.CheckActive = function() {}); +}; +Tproto.Measure = function(c,t) { + this.h = this.extents ? this.extents.max.y + this.extents.min.y : this.textHeight; + c.font = this.font = this.textHeight + 'px ' + this.textFont; + this.w = c.measureText(this.name).width; + if(t.txtOpt) { + var s = t.txtScale, th = s * this.textHeight, f = th + 'px ' + this.textFont, + soff = [s*t.shadowOffset[0],s*t.shadowOffset[1]], cw; + c.font = f; + cw = c.measureText(this.name).width; + this.image = TextToCanvas(this.name, f, th, cw, s * this.h, this.colour, + t.shadow, s * t.shadowBlur, soff, s, s); + if(this.image) { + this.w = this.image.width / s; + this.h = this.image.height / s; + } + this.SetDraw(t); + t.txtOpt = this.image; + } +}; +Tproto.SetWeight = function(w) { + if(!this.name.length) + return; + this.weight = w; + this.Weight(this.tc.ctxt, this.tc); + this.Measure(this.tc.ctxt, this.tc); +}; +Tproto.Weight = function(c,t) { + var w = this.weight, m = t.weightMode; + this.weighted = true; + if(m == 'colour' || m == 'both') + this.colour = FindGradientColour(t, (w - t.min_weight) / (t.max_weight-t.min_weight)); + if(m == 'size' || m == 'both') + this.textHeight = w * t.weightSize; + this.extents = FindTextBoundingBox(this.name, this.textFont, this.textHeight); +}; +Tproto.SetShadowColourFixed = function(c,s,a) { + c.shadowColor = s; +}; +Tproto.SetShadowColourAlpha = function(c,s,a) { + c.shadowColor = SetAlpha(s, a); +}; +Tproto.DrawText = function(c,xoff,yoff) { + var t = this.tc, x = this.x, y = this.y, w, h, s = this.sc; + c.globalAlpha = this.alpha; + c.setTransform(s,0,0,s,0,0); + c.fillStyle = this.colour; + t.shadow && this.SetShadowColour(c,t.shadow,this.alpha); + c.font = this.font; + w = this.w; + h = this.h; + x += (xoff / s) - (w / 2); + y += (yoff / s) - (h / 2); + c.fillText(this.name, x, y); +}; +Tproto.DrawImage = function(c,xoff,yoff) { + //var t = this.tc, x = this.x, y = this.y, s = this.sc, // mod Shad Laws + var x = this.x, y = this.y, s = this.sc, // mod Shad Laws + i = this.image, w = this.w, h = this.h, a = this.alpha, + shadow = this.shadow; + c.globalAlpha = a; + c.setTransform(s,0,0,s,0,0); + c.fillStyle = this.colour; + shadow && this.SetShadowColour(c,shadow,a); + x += (xoff / s) - (w / 2); + y += (yoff / s) - (h / 2); + c.drawImage(i, x, y, w, h); +}; +Tproto.DrawImageIE = function(c,xoff,yoff) { + var i = this.image, s = this.sc, + w = i.width = this.w*s, h = i.height = this.h * s, + x = (this.x*s) + xoff - (w/2), y = (this.y*s) + yoff - (h/2); + c.setTransform(1,0,0,1,0,0); + c.globalAlpha = this.alpha; + c.drawImage(i, x, y); +}; +Tproto.Calc = function(yaw,pitch) { + var pp = RotY(this.p3d,yaw), t = this.tc, mb = t.minBrightness, r = t.radius; + this.p3d = RotX(pp,pitch); + pp = Project(t, this.p3d, this.w, this.h, t.stretchX, t.stretchY); + this.x = pp.x; + this.y = pp.y; + this.sc = (t.z1 + t.z2 - pp.z) / t.z2; + this.alpha = max(mb,min(1,mb + 1 - ((pp.z - t.z2 + r) / (2 * r)))); +}; +Tproto.CheckActive = function(c,xoff,yoff) { + var t = this.tc, o = this.outline, + w = this.w, h = this.h, + x = this.x - w/2, y = this.y - h/2; + o.Update(x, y, w, h, this.sc, this.p3d, xoff, yoff); + return o.Active(c, t.mx, t.my) ? o : null; +}; +Tproto.Clicked = function(e) { + var a = this.a, t = a.target, h = a.href, evt; + if(t != '' && t != '_self') { + if(self.frames[t]) { + self.frames[t] = h; + } else{ + try { + if(top.frames[t]) { + top.frames[t] = h; + return; + } + } catch(err) { + // different domain/port/protocol? + } + window.open(h, t); + } + return; + } + if(doc.createEvent) { + evt = doc.createEvent('MouseEvents'); + evt.initMouseEvent('click', 1, 1, window, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null); + if(!a.dispatchEvent(evt)) + return; + } else if(a.fireEvent) { + if(!a.fireEvent('onclick')) + return; + } + doc.location = h; +}; +/** + * @constructor + */ +function TagCanvas() { + var i, opts = { + mx: -1, my: -1, + z1: 20000, z2: 20000, z0: 0.0002, + freezeActive: false, + activeCursor: 'pointer', + pulsateTo: 1, + pulsateTime: 3, + reverse: false, + depth: 0.5, + maxSpeed: 0.05, + minSpeed: 0, + decel: 0.95, + interval: 20, + initial: null, + initialDecel: false, // mod Shad Laws + deadZone: 0, // mod Shad Laws + physModel: false, // mod Shad Laws + maxInputZone: 0, // mod Shad Laws + hideTags: true, + minBrightness: 0.1, + outlineColour: '#ffff99', + outlineThickness: 2, + outlineOffset: 5, + outlineMethod: 'outline', + textColour: '#ff99ff', + textHeight: 15, + textFont: 'Helvetica, Arial, sans-serif', + shadow: '#000', + shadowBlur: 0, + shadowOffset: [0,0], + zoom: 1, + weight: false, + weightMode: 'size', + weightFrom: null, + weightSize: 1, + weightGradient: {0:'#f00', 0.33:'#ff0', 0.66:'#0f0', 1:'#00f'}, + txtOpt: true, + txtScale: 2, + frontSelect: false, + wheelZoom: true, + zoomMin: 0.3, + zoomMax: 3, + zoomStep: 0.05, + shape: 'sphere', + lock: null, + tooltip: null, + tooltipDelay: 300, + tooltipClass: 'tctooltip', + radiusX: 1, + radiusY: 1, + radiusZ: 1, + stretchX: 1, + stretchY: 1, + shuffleTags: false, + noSelect: false, + noMouse: false, + imageScale: 1 + }; + for(i in opts) + this[i] = opts[i]; + this.max_weight = 0; + this.min_weight = 200; +} +TCproto = TagCanvas.prototype; +TCproto.Draw = function() { + var cv = this.canvas, cw = cv.width, ch = cv.height, max_sc = 0, yaw = this.yaw, pitch = this.pitch, + x1 = cw / 2, y1 = ch / 2, c = this.ctxt, active, a, i, aindex = -1, tl = this.taglist, l = tl.length, + frontsel = this.frontSelect; + //if(yaw == 0 && pitch == 0 && this.drawn) // mod Shad Laws + if(yaw == 0 && pitch == 0 && this.drawn && !this.zoneActive) // mod Shad Laws + return this.Animate(cw,ch); + c.setTransform(1,0,0,1,0,0); + this.active = null; + for(i = 0; i < l; ++i) + tl[i].Calc(yaw, pitch); + tl = tl.sort(function(a,b) {return a.sc-b.sc}); + + for(i = 0; i < l; ++i) { + a = tl[i].CheckActive(c, x1, y1); + a = this.mx >= 0 && this.my >= 0 && tl[i].CheckActive(c, x1, y1); + if(a && a.sc > max_sc && (!frontsel || a.z <= 0)) { + active = a; + active.index = aindex = i; + max_sc = a.sc; + } + } + this.active = active; + + if(!this.txtOpt && this.shadow) { + c.shadowBlur = this.shadowBlur; + c.shadowOffsetX = this.shadowOffset[0]; + c.shadowOffsetY = this.shadowOffset[1]; + } + c.clearRect(0,0,cw,ch); + for(i = 0; i < l; ++i) { + if(!(aindex == i && active.PreDraw(c, tl[i], x1, y1))) + tl[i].Draw(c, x1, y1); + aindex == i && active.PostDraw(c); + } + if(this.freezeActive && active) { + this.yaw = this.pitch = this.drawn = 0; + } else { + this.Animate(cw, ch); + this.drawn = (l == this.listLength); + } + active && active.LastDraw(c); + cv.style.cursor = active ? this.activeCursor : ''; + this.Tooltip(active,tl[aindex]); +}; +TCproto.TooltipNone = function() { }; +TCproto.TooltipNative = function(active,tag) { + this.canvas.title = active && tag.title ? tag.title : ''; +}; +TCproto.TooltipDiv = function(active,tag) { + //var tc = this, s = tc.ttdiv.style, cid = tc.canvas.id; // mod Shad Laws + var tc = this, s = tc.ttdiv.style; // mod Shad Laws + if(active && tag.title) { + tc.ttdiv.innerHTML = tag.title; + if(s.display == 'none' && ! tc.tttimer) { + tc.tttimer = setTimeout(function() { + var p = $(tc.canvas).offset(); + s.display = 'block'; + s.left = p.left + tc.mx + 'px'; + s.top = p.top + tc.my + 24 + 'px'; + tc.tttimer = null; + }, tc.tooltipDelay); + } + } else { + s.display = 'none'; + } +}; +TCproto.Animate = function(w,h) { // mod Shad Laws - original function afterward + var tc = this; // mod Shad Laws + if(tc.physModel) + /** + * Physics-based model -- mod Shad Laws + * State update equation + * (normalized inertia J=1 and time-step dt=1, forward Euler discretization) + * w1 = w - b*w + m*(u-f) + n*v + * where w1,w,u,f,v are vectors, b,m,n are scalars: + * w = rotational speed at t=k + * components wx, wy, magnitude w + * w1 = rotational speed at t=k+1 + * components wx1, wy1, magnitude w1 + * u-f = actual input from mouse position (-1 <= u-f <= 1) + * components ux, uy, magnitude u + * coulomb friction f (models "deadZone" effect) + * reversed/locked/saturated as defined (models "reverse", "lock", and "maxInputZone" effects) + * v = fictitious input (-1 <= v <= 1) + * components vx, vy, magnitude v + * directed as needed (models "minSpeed" effect) + * b = damping (models "decel" effect) + * m = maximum actual input (models "maxSpeed" effect) + * n = maximum fictitious input (models "minSpeed" effect) + */ + { + var x = tc.mx, y = tc.my, xmax = w-1, ymax = h-1, xstr = tc.stretchX, ystr = tc.stretchY; + var r = tc.reverse ? -1 : 1, l = tc.lock, usat = tc.maxInputZone, zt = tc.z0; + // calculate physical parameters (b,f,m,n) + var b = 1-tc.decel, f = tc.deadZone, m = tc.maxSpeed*b, n = tc.minSpeed*b; + // set rotational velocities, following previous convention where x-rotation is "pitch" and y-rotation is "yaw" + var wx = tc.pitch, wy = tc.yaw, w = sqrt(wx*wx + wy*wy), wx1, wy1, w1; + // calculate inputs + var ux, uy, u, vx, vy, v; + this.zoneActive = false; + if(x >= 0 && y >= 0 && x <= xmax && y <= ymax) + { + // the "max(xmax/ymax,1)" parts are needed to deal with non-square tag clouds correctly + ux = -r * (2 * y/ymax - 1) * max(ymax/xmax,1) / ystr; + uy = r * (2 * x/xmax - 1) * max(xmax/ymax,1) / xstr; + if(abs(ux) <= 1+usat && abs(uy) <= 1+usat) + { + ux = (l != 'y') ? ux : 0; + uy = (l != 'x') ? uy : 0; + u = sqrt(ux*ux + uy*uy); + if(u <= f || f >= 1-zt) // dead zone, zero input + { + this.initial = null; + this.zoneActive = true; + ux = 0, uy = 0, u = 0; + vx = 0, vy = 0, v = 0; + } + else if(u <= 1) // inside cloud, normal input + { + this.initial = null; + this.zoneActive = true; + ux = ux/u*(u-f)/(1-f), uy = uy/u*(u-f)/(1-f), u = (u-f)/(1-f); + vx = 0, vy = 0, v = 0; + } + else if(u <= 1+usat) // just outside cloud, saturated input + { + this.initial = null; + this.zoneActive = true; + ux = ux/u, uy = uy/u, u = 1; + vx = 0, vy = 0, v = 0; + } + } + } + if(!this.zoneActive) // outside cloud, fictitious input + { + ux = 0, uy = 0, u = 0; + if(w >= zt) + vx = wx/w, vy = wy/w, v = 1; + else + { + v = 2*Math.PI*Math.random(); + if(l == 'x') + vx = 0, vy = v= 0 && y >= 0 && x < w && y < h) + { + tc.zoneActive = true; // mod Shad Laws + //s = tc.maxSpeed, r = tc.reverse ? -1 : 1; // mod Shad Laws + s = tc.maxSpeed, r = tc.reverse ? -1 : 1, dz = tc.deadZone; // mod Shad Laws + if(l != 'x') + //this.yaw = r * ((s * 2 * x / w) - s); // mod Shad Laws + this.yaw = r * s / max(1-dz,0.000001) * ( max(2*x/w-1-dz,0) + min(2*x/w-1+dz,0) ); // mod Shad Laws + if(l != 'y') + //this.pitch = r * -((s * 2 * y / h) - s); // mod Shad Laws + this.pitch = -r * s / max(1-dz,0.000001) * ( max(2*y/h-1-dz,0) + min(2*y/h-1+dz,0) ); // mod Shad Laws + this.initial = null; + } + //else if(!tc.initial) // mod Shad Laws + else if(!tc.initial || tc.initialDecel) // mod Shad Laws + { + s = tc.minSpeed, ay = abs(tc.yaw), ap = abs(tc.pitch); + if(l != 'x' && ay > s) + this.yaw = ay > tc.z0 ? tc.yaw * tc.decel : 0; + if(l != 'y' && ap > s) + this.pitch = ap > tc.z0 ? tc.pitch * tc.decel : 0; + } + } +}; +TCproto.Zoom = function(r) { + this.z2 = this.z1 * (1/r); + this.drawn = 0; +}; +TCproto.Clicked = function(e) { + var t = this.taglist, a = this.active; + try { + if(a && t[a.index]) + t[a.index].Clicked(e); + } catch(ex) { + } +}; +TCproto.Wheel = function(i) { + var z = this.zoom + this.zoomStep * (i ? 1 : -1); + this.zoom = min(this.zoomMax,max(this.zoomMin,z)); + this.Zoom(this.zoom); +}; + +TagCanvas.tc = {}; + +jQuery.fn.tagcanvas = function(options,lctr) { + var links, ctr = lctr ? jQuery('#'+lctr) : this; + if(doc.all && !lctr) return false; // IE must have external list + links = ctr.find('a'); + if(Defined(window.G_vmlCanvasManager)) { + this.each(function() { $(this)[0] = window.G_vmlCanvasManager.initElement($(this)[0]); }); + options.ie = parseFloat(navigator.appVersion.split('MSIE')[1]); + } + + if(!links.length || !this[0].getContext || !this[0].getContext('2d').fillText) + return false; + + this.each(function() { + var i, vl, im, ii, tag, jqt, w, weights = [], + pfuncs = { + sphere:PointsOnSphere, + vcylinder:PointsOnCylinderV, + hcylinder:PointsOnCylinderH + }; + + // if using internal links, get only the links for this canvas + lctr || (links = $(this).find('a')); + + jqt = new TagCanvas; + for(i in options) + jqt[i] = options[i]; + + jqt.z1 = (19800 / (Math.exp(jqt.depth) * (1-1/Math.E))) + + 20000 - 19800 / (1-(1/Math.E)); + jqt.z2 = jqt.z1 * (1/jqt.zoom); + + jqt.radius = (this.height > this.width ? this.width : this.height) + * 0.33 * (jqt.z2 + jqt.z1) / (jqt.z1); + //jqt.yaw = jqt.initial ? jqt.initial[0] * jqt.maxSpeed : 0; // mod Shad Laws + //jqt.pitch = jqt.initial ? jqt.initial[1] * jqt.maxSpeed : 0; // mod Shad Laws + jqt.yaw = jqt.initial && (jqt.lock != 'x') ? jqt.initial[0] * jqt.maxSpeed : 0; + jqt.pitch = jqt.initial && (jqt.lock != 'y') ? jqt.initial[1] * jqt.maxSpeed : 0; + jqt.canvas = $(this)[0]; + jqt.ctxt = jqt.canvas.getContext('2d'); + jqt.textFont = jqt.textFont && FixFont(jqt.textFont); + jqt.deadZone *= 1; // mod Shad Laws + jqt.minSpeed *= 1; // mod Shad Laws + jqt.decel *= 1; // mod Shad Laws + jqt.maxInputZone *= 1; // mod Shad Laws + jqt.pulsateTo *= 1; + jqt.textHeight *= 1; + jqt.minBrightness *= 1; + jqt.ctxt.textBaseline = 'top'; + if(jqt.shadowBlur || jqt.shadowOffset[0] || jqt.shadowOffset[1]) { + // let the browser translate "red" into "#ff0000" + jqt.ctxt.shadowColor = jqt.shadow; + jqt.shadow = jqt.ctxt.shadowColor; + jqt.shadowAlpha = ShadowAlphaBroken(); + } else { + delete jqt.shadow; + } + jqt.taglist = []; + + jqt.shape = pfuncs[jqt.shape] || pfuncs.sphere; + vl = jqt.shape(links.length, jqt.radiusX, jqt.radiusY, jqt.radiusZ); + jqt.shuffleTags && Shuffle(vl); + jqt.listLength = links.length; + for(i = 0; i < links.length; ++i) { + im = links[i].getElementsByTagName('img'); + if(im.length) { + ii = new Image; + ii.src = im[0].src; + tag = new Tag(jqt,ii, links[i], vl[i], 1, 1); + AddImage(ii,im[0],tag,jqt); + } else { + jqt.taglist.push(new Tag(jqt,links[i].innerText || links[i].textContent, links[i], + vl[i], 2, jqt.textHeight + 2, jqt.textColour || GetProperty(links[i],'color'), + jqt.textFont || FixFont(GetProperty(links[i],'font-family')))); + } + if(jqt.weight) { + w = FindWeight(jqt,links[i]); + if(w > jqt.max_weight) jqt.max_weight = w; + if(w < jqt.min_weight) jqt.min_weight = w; + weights.push(w); + } + } + if(jqt.weight = (jqt.max_weight > jqt.min_weight)) { + for(i = 0; i < jqt.taglist.length; ++i) { + jqt.taglist[i].SetWeight(weights[i]); + } + } + + TagCanvas.tc[$(this)[0].id] = jqt; + jqt.Tooltip = (jqt.tooltip == 'native' ? jqt.TooltipNative : (jqt.tooltip ? jqt.TooltipDiv : jqt.TooltipNone)); + if(jqt.tooltip) { + if(jqt.tooltip == 'native') { + jqt.Tooltip = jqt.TooltipNative; + } else { + jqt.Tooltip = jqt.TooltipDiv; + if(!jqt.ttdiv) { + jqt.ttdiv = doc.createElement('div'); + jqt.ttdiv.className = jqt.tooltipClass; + jqt.ttdiv.style.position = 'absolute'; + jqt.ttdiv.style.zIndex = jqt.canvas.style.zIndex + 1; + AddHandler('mouseover',function(e){e.target.style.display='none';},jqt.ttdiv); + doc.body.appendChild(jqt.ttdiv); + } + } + } else { + jqt.Tooltip = jqt.TooltipNone; + } + if(!jqt.noMouse && !handlers[$(this)[0].id]) { + // for some reason, using bind with mouseup isn't working in IE + AddHandler('mousemove', MouseMove, this); + AddHandler('mouseout', MouseOut, this); + AddHandler('mouseup', MouseClick, this); + if(jqt.wheelZoom) { + AddHandler('mousewheel', MouseWheel, this); + AddHandler('DOMMouseScroll', MouseWheel, this); + } + handlers[$(this)[0].id] = 1; + } + if(lctr && jqt.hideTags) { + if(TagCanvas.loaded) + $(ctr).hide(); + else + AddHandler('load', function() { $(ctr).hide() }, window); + } + options.interval = options.interval || jqt.interval; + }); + return !!(TagCanvas.started || (TagCanvas.started = setInterval(DrawCanvas, options.interval))); +}; +// set a flag for when the window has loaded +AddHandler('load',function(){TagCanvas.loaded=1;},window); +})(jQuery); diff --git a/3.0/modules/tag_cloud_html5/libraries/MY_Form_Input.php b/3.0/modules/tag_cloud_html5/libraries/MY_Form_Input.php new file mode 100644 index 00000000..e7b926de --- /dev/null +++ b/3.0/modules/tag_cloud_html5/libraries/MY_Form_Input.php @@ -0,0 +1,58 @@ +value)) { + if (!is_null($min) && ($this->value < $min)) { + // below min + $this->errors['numrange'] = true; + $this->error_messages['numrange'] = t('Value is below minimum of').' '.$min; + } elseif (!is_null($max) && ($this->value > $max)) { + // above max + $this->errors['numrange'] = true; + $this->error_messages['numrange'] = t('Value is above maximum of').' '.$max;; + } + } else { + // not numeric + $this->errors['numrange'] = true; + $this->error_messages['numrange'] = t('Value is not numeric'); + } + } + + /** + * Custom validation rule: color + * returns no error if string is formatted as #hhhhhh OR if string is empty + * to exclude the empty case, add "required" as another rule + */ + protected function rule_color() { + if (preg_match("/^#[0-9A-Fa-f]{6}$|^$/", $this->value) == 0) { + $this->errors['color'] = true; + $this->error_messages['color'] = t('Color is not in #hhhhhh format'); + } + } +} \ No newline at end of file diff --git a/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_embed.html.php b/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_embed.html.php new file mode 100644 index 00000000..99e5af4b --- /dev/null +++ b/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_embed.html.php @@ -0,0 +1,59 @@ + + + +
+ + + +
+ \ No newline at end of file