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/proofsheet/controllers/proofsheet.php b/3.0/modules/proofsheet/controllers/proofsheet.php index 3dd91b87..c3713e42 100644 --- a/3.0/modules/proofsheet/controllers/proofsheet.php +++ b/3.0/modules/proofsheet/controllers/proofsheet.php @@ -1,441 +1,446 @@ -is_album()) { - throw new Kohana_Exception('container is not an album: '.$container->relative_path()); - } - - $pdfname = (empty($container->name)) - ? 'Gallery.pdf' // @todo purified_version_of($container->title).'.pdf' - : $container->name.'.pdf'; - $headerText = $container->title; - $headerLink = $container->abs_url(); - break; - - case "tag": - // @todo: if the module is not installed, it crash - $container = ORM::factory("tag", $id); - if (is_null($container->name)) { - throw new Kohana_Exception('container is not a tag: '.$id); - } - - $pdfname = $container->name.'.pdf'; - $headerText = $container->name; - $headerLink = $container->abs_url(); - break; - - default: - throw new Kohana_Exception('unhandled container type: '.$container_type); - } - $files = $this->getFilesList($container); - - /** - * Configure PDF file. These are all of the parameters that are used to - * format the proof sheet. If you'd like to tweak the formatting, here's - * where to do it. - */ - switch($page_type) { - case "ltr": - // Setup for LTR 8.5" x 11" paper (215.9mm x 279.4mm) - $cfg = array( - 'pageW' => 215.9, // mm - 'pageH' => 279.4, // mm - 'imageNumW' => 5, // integer number - 'imageNumH' => 5, // integer number - 'imageSizeW' => 36, // mm - 'imageSizeH' => 36, // mm - 'marginL' => 10, // mm - 'marginR' => 10, // mm - 'marginT' => 21, // mm (header goes in here) - 'marginB' => 20, // mm (footer goes in here) - 'headerSpace' => 2, // mm (header to top row of images and to link icon) - 'footerSpace' => 2, // mm (bottom row of captions to footer) - 'captionSpace' => 1, // mm (bottom of image to caption) - 'headerFont' => array( - 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats - 'size' => 14, // pt - 'style' => 'B', // combo of B, I, U - 'posn' => 'L', // combo of L, C, R - 'r' => 0, // Red 0-255 - 'g' => 0, // Green 0-255 - 'b' => 0),// Blue 0-255 - 'footerFont' => array( - 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats - 'size' => 12, // pt - 'style' => 'B', // combo of B, I, U - 'posn' => 'R', // combo of L, C, R - 'r' => 0, // Red 0-255 - 'g' => 0, // Green 0-255 - 'b' => 0),// Blue 0-255 - 'captionFont' => array( - 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats - 'size' => 8, // pt - 'style' => 'U', // combo of B, I, U - 'posn' => 'C', // combo of L, C, R - 'r' => 0, // Red 0-255 - 'g' => 0, // Green 0-255 - 'b' => 255),// Blue 0-255 - ); - break; - case "a4": - // Setup for A4 210mm x 297mm paper (8.27" x 11.69") - $cfg = array( - 'pageW' => 210, // mm - 'pageH' => 297, // mm - 'imageNumW' => 5, // integer number - 'imageNumH' => 6, // integer number - 'imageSizeW' => 36, // mm - 'imageSizeH' => 36, // mm - 'marginL' => 8, // mm - 'marginR' => 8, // mm - 'marginT' => 19, // mm (header goes in here) - 'marginB' => 18, // mm (footer goes in here) - 'headerSpace' => 2, // mm (header to top row of images and to link icon) - 'footerSpace' => 2, // mm (bottom row of captions to footer) - 'captionSpace' => 1, // mm (bottom of image to caption) - 'headerFont' => array( - 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats - 'size' => 14, // pt - 'style' => 'B', // combo of B, I, U - 'posn' => 'L', // combo of L, C, R - 'r' => 0, // Red 0-255 - 'g' => 0, // Green 0-255 - 'b' => 0),// Blue 0-255 - 'footerFont' => array( - 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats - 'size' => 12, // pt - 'style' => 'B', // combo of B, I, U - 'posn' => 'R', // combo of L, C, R - 'r' => 0, // Red 0-255 - 'g' => 0, // Green 0-255 - 'b' => 0),// Blue 0-255 - 'captionFont' => array( - 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats - 'size' => 8, // pt - 'style' => 'U', // combo of B, I, U - 'posn' => 'C', // combo of L, C, R - 'r' => 0, // Red 0-255 - 'g' => 0, // Green 0-255 - 'b' => 255),// Blue 0-255 - ); - break; - default: - throw new Kohana_Exception('unhandled page type: '.$page_type); - } - - // Here are some other parameters that need defining - $cfg['footerTextPage'] = 'Page '; // Note that this text isn't autofixed by translate module - $cfg['footerTextSlash'] = ' / '; - $cfg['headerLinkIconPath'] = MODPATH . 'proofsheet/images/ico-link.png'; - $cfgImageMissing['iconPath'] = MODPATH . 'proofsheet/images/image_missing.png'; - $cfgImageMissing['iconType'] = 'PNG'; // PNG or JPG is most robust, GIF okay only if GD is installed - $pt2mm = 25.4/72; // 25.4mm=1in=72pt - - // Derive a bunch more parameters. These are all dependent on the above stuff. - $cfg['headerH'] = $pt2mm * $cfg['headerFont']['size']; - $cfg['footerH'] = $pt2mm * $cfg['footerFont']['size']; - $cfg['captionH'] = $pt2mm * $cfg['captionFont']['size']; - $cfg['imageSpaceW'] = ($cfg['pageW']-$cfg['marginL']-$cfg['marginR']-$cfg['imageNumW']*$cfg['imageSizeW']) / ($cfg['imageNumW']-1); - $cfg['imageSpaceH'] = ($cfg['pageH']-$cfg['marginT']-$cfg['marginB']-$cfg['imageNumH']*$cfg['imageSizeH']-$cfg['captionH']-$cfg['captionSpace']) / ($cfg['imageNumH']-1); - $linkInfo = getimagesize($cfg['headerLinkIconPath']); - $cfg['headerLinkH'] = $cfg['headerH']; // I'm defining this to be the same as the text, but you can change it here. - $cfg['headerLinkW'] = $linkInfo[0] / $linkInfo[1] * $cfg['headerLinkH']; - $cfg['headerW'] = $cfg['pageW']-$cfg['marginL']-$cfg['marginR']-$cfg['headerLinkW']-$cfg['headerSpace']; - $cfg['footerW'] = $cfg['pageW']-$cfg['marginL']-$cfg['marginR']; - $cfg['captionW'] = $cfg['imageSizeW']; // I'm defining this to be the same as the image, but you can change it here. - $cfg['headerX'] = $cfg['marginL']; - $cfg['headerLinkX'] = $cfg['marginL']+$cfg['headerW']; - $cfg['footerX'] = $cfg['marginL']; - $cfg['headerY'] = $cfg['marginT']-$cfg['headerH']-$cfg['headerSpace']; - $cfg['headerLinkY'] = $cfg['marginT']-$cfg['headerLinkH']-$cfg['headerSpace']; - $cfg['footerY'] = $cfg['pageH']-$cfg['marginB']+$cfg['footerSpace']; - $cfg['imageNum'] = $cfg['imageNumW']*$cfg['imageNumH']; - $cfgImageMissing['iconInfo'] = getimagesize($cfgImageMissing['iconPath']); - $cfgImageMissing['GDflag'] = graphics::detect_toolkits()->gd>installed; // FPDF uses GD to convert GIFs - - /** - * Initialize and build PDF... the main routine. Note that almost all of the - * useful configuration parameters are already defined above. - */ - - // Initialize PDF, disable automatic margins and page breaks - $pdf = new proofsheet_PDF('P', 'mm', array($cfg['pageW'],$cfg['pageH']) ); - $pdf->SetMargins(0,0); - $pdf->SetAutoPageBreak(0); - - // Build the PDF - $numpages = floor(count($files)/$cfg['imageNum'])+1; - $i = 0; - foreach($files as $f_path => $f_info) { - // Initialize new pages, add header and footer - if (($i % $cfg['imageNum'])==0) { - $pdf->AddPage(); - $pdf->printText($headerText, $cfg['headerFont'], $cfg['headerX'], $cfg['headerY'], $cfg['headerW'], $cfg['headerH']); - $pdf->printImage($cfg['headerLinkIconPath'], $cfg['headerLinkX'], $cfg['headerLinkY'], $cfg['headerLinkW'], $cfg['headerLinkH'], $headerLink, $cfgImageMissing); - $footerText = $cfg['footerTextPage'] . strval(floor($i/$cfg['imageNum'])+1) . $cfg['footerTextSlash'] . strval($numpages); - $pdf->printText($footerText, $cfg['footerFont'], $cfg['footerX'], $cfg['footerY'], $cfg['footerW'], $cfg['footerH']); - } - // Add thumbnail and caption - $x = $cfg['marginL'] + ($cfg['imageSizeW']+$cfg['imageSpaceW']) * ( $i % $cfg['imageNumW']); - $y = $cfg['marginT'] + ($cfg['imageSizeH']+$cfg['imageSpaceH']) * (floor($i/$cfg['imageNumW']) % $cfg['imageNumH']); - $pdf->printImage($f_path, $x, $y, $cfg['imageSizeW'], $cfg['imageSizeH'], null, $cfgImageMissing); - $pdf->printText($f_info['name'], $cfg['captionFont'], $x, $y+$cfg['imageSizeH']+$cfg['captionSpace'], $cfg['captionW'], $cfg['captionH'], $f_info['url']); - // Increment index and loop - $i++; - } - - /** - * Output the PDF file. I wrote it in two versions (one should always be commented out). - */ - // Using a method similar to downloadalbum - $pdfstring = $pdf->Output('','S'); - $this->prepareOutput(); - $this->sendHeaders($pdfname, strlen($pdfstring)); - echo $pdfstring; - - // Using FPDF directly - //$pdf->Output($pdfname,'I'); - - } - - /** - * Return the files that must be included in the archive. - * This is largely borrowed from downloadalbum, but does have - * significant modifications. - */ - private function getFilesList($container) { - $files = array(); - - if( $container instanceof Item_Model && $container->is_album() ) { - $items = $container->viewable() - ->descendants(null, null, array(array("type", "<>", "album"))); - - foreach($items as $i) { - if (!access::can('view_full', $i)) { - continue; - } - - $thumb_realpath = realpath($i->thumb_path()); - if (!is_readable($thumb_realpath)) { - continue; - } - - $files[$thumb_realpath] = array('url' => $i->abs_url(), 'name' => $i->title); - } - - } else if( $container instanceof Tag_Model ) { - $items = $container->items(); - foreach($items as $i) { - if (!access::can('view_full', $i)) { - continue; - } - - if( $i->is_album() ) { - foreach($this->getFilesList($i) as $f_name => $f_info) { - $files[$f_name] = $f_info; - } - - } else { - $thumb_realpath = realpath($i->thumb_path()); - if (!is_readable($thumb_realpath)) { - continue; - } - - $files[$thumb_realpath] = array('url' => $i->abs_url(), 'name' => $i->title); - - } - } - } - - if (count($files) === 0) { - throw new Kohana_Exception('no thumb files in ['.$container->name.']'); - } - - return $files; - } - - - /** - * See system/helpers/download.php - * This is borrowed from downloadalbum without changes. - */ - private function prepareOutput() { - // Close output buffers - Kohana::close_buffers(FALSE); - // Clear any output - Event::add('system.display', create_function('', 'Kohana::$output = "";')); - } - - /** - * See system/helpers/download.php - * This is borrowed from downloadalbum without changes. - */ - private function sendHeaders($filename, $filesize = null) { - if (!is_null($filesize)) { - header('Content-Length: '.$filesize); - } - - // Retrieve MIME type by extension - $mime = Kohana::config('mimes.'.strtolower(substr(strrchr($filename, '.'), 1))); - $mime = empty($mime) ? 'application/octet-stream' : $mime[0]; - header("Content-Type: $mime"); - header('Content-Transfer-Encoding: binary'); - - // Send headers necessary to invoke a "Save As" dialog - header('Content-Disposition: attachment; filename="'.$filename.'"'); - - // Prevent caching - header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); - - $pragma = 'no-cache'; - $cachecontrol = 'no-cache, max-age=0'; - - // request::user_agent('browser') seems bugged - if (request::user_agent('browser') === 'Internet Explorer' - || stripos(request::user_agent(), 'msie') !== false - || stripos(request::user_agent(), 'internet explorer') !== false) - { - if (request::protocol() === 'https') { - // See http://support.microsoft.com/kb/323308/en-us - $pragma = 'cache'; - $cachecontrol = 'private'; - - } else if (request::user_agent('version') <= '6.0') { - $pragma = ''; - $cachecontrol = 'must-revalidate, post-check=0, pre-check=0'; - } - } - - header('Pragma: '.$pragma); - header('Cache-Control: '.$cachecontrol); - } -} - -class proofsheet_PDF extends FPDF { - - /** - * Print text (header, footer, or caption) with link, formatted as in cfg. - * It converts UTF-8 back to CP1252, which is used by FPDF. - * This will trim formatted text to fit and add ellipsis if needed. - */ - function printText($text, $font, $x, $y, $w, $h, $link = null) { - $ellipsis = '…'; // ASCII character 133 - // Convert from UTF-8 back to CP1252 - $text = iconv('utf-8','cp1252',$text); - // Set color, font, and position - $this->SetTextColor($font['r'],$font['g'],$font['b']); - $this->SetFont($font['name'],$font['style'],$font['size']); - $this->SetXY($x, $y); - // Trim text if needed - if (($this->GetStringWidth($text)) > $w) { - // Keep trimming until the size, with ellipsis, is small enough - while (($this->GetStringWidth($text.$ellipsis)) > $w) { - $text = substr($text,0,strlen($text)-1); - } - // Add the ellipsis to the shortened text - $text = $text.$ellipsis; - } - // Create text cell - $this->Cell($w,$h,$text,0,0,$font['posn'],false,$link); - } - - /** - * Print image. This is basically a wrapper around the FPDF image function, - * except that it determines the file type independent of the file extension - * and automatically resizes to main aspect ratio within the defined space. - * Note that this provides robustness for images with incorrect filenames, such - * as missing_movie.png being called a jpg when copied as a thumbnail in v3.0.2. - */ - function printImage($imagePath, $x, $y, $w, $h, $link = null, $cfgImageMissing) { - $imageInfo = getimagesize($imagePath); // [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG) - // Figure out the filetype - switch($imageInfo[2]) { - case 3: - $imageType = 'PNG'; - break; - case 2: - $imageType = 'JPG'; - break; - case 1: - if ($cfgImageMissing['GDflag']) { - $imageType = 'GIF'; - break; - } - default: - // use the missing image icon instead - $imagePath = $cfgImageMissing['iconPath']; - $imageType = $cfgImageMissing['iconType']; - $imageInfo = $cfgImageMissing['iconInfo']; - } - // Determine image orientation and create image - $ratioWH = ($imageInfo[0]/$w) / ($imageInfo[1]/$h); - if ($ratioWH>1) { - $this->image($imagePath, $x, $y+(1-1/$ratioWH)*$h/2, $w, 0, $imageType, $link); - } else { - $this->image($imagePath, $x+(1-$ratioWH)*$w/2, $y, 0, $h, $imageType, $link); - } - } -} +is_album()) { + throw new Kohana_Exception('container is not an album: '.$container->relative_path()); + } + + $pdfname = (empty($container->name)) + ? 'Gallery.pdf' // @todo purified_version_of($container->title).'.pdf' + : $container->name.'.pdf'; + $headerText = $container->title; + $headerLink = $container->abs_url(); + break; + + case "tag": + // @todo: if the module is not installed, it crash + $container = ORM::factory("tag", $id); + if (is_null($container->name)) { + throw new Kohana_Exception('container is not a tag: '.$id); + } + + $pdfname = $container->name.'.pdf'; + $headerText = $container->name; + //$headerLink = $container->abs_url(); + $headerLink = url::abs_site("tag/{$container->id}/" . urlencode($container->name)); + break; + + default: + throw new Kohana_Exception('unhandled container type: '.$container_type); + } + $files = $this->getFilesList($container); + + /** + * Configure PDF file. These are all of the parameters that are used to + * format the proof sheet. If you'd like to tweak the formatting, here's + * where to do it. + */ + switch($page_type) { + case "ltr": + // Setup for LTR 8.5" x 11" paper (215.9mm x 279.4mm) + $cfg = array( + 'pageW' => 215.9, // mm + 'pageH' => 279.4, // mm + 'imageNumW' => 5, // integer number + 'imageNumH' => 5, // integer number + 'imageSizeW' => 36, // mm + 'imageSizeH' => 36, // mm + 'marginL' => 10, // mm + 'marginR' => 10, // mm + 'marginT' => 21, // mm (header goes in here) + 'marginB' => 20, // mm (footer goes in here) + 'headerSpace' => 2, // mm (header to top row of images and to link icon) + 'footerSpace' => 2, // mm (bottom row of captions to footer) + 'captionSpace' => 1, // mm (bottom of image to caption) + 'headerFont' => array( + 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats + 'size' => 14, // pt + 'style' => 'B', // combo of B, I, U + 'posn' => 'L', // combo of L, C, R + 'r' => 0, // Red 0-255 + 'g' => 0, // Green 0-255 + 'b' => 0),// Blue 0-255 + 'footerFont' => array( + 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats + 'size' => 12, // pt + 'style' => 'B', // combo of B, I, U + 'posn' => 'R', // combo of L, C, R + 'r' => 0, // Red 0-255 + 'g' => 0, // Green 0-255 + 'b' => 0),// Blue 0-255 + 'captionFont' => array( + 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats + 'size' => 8, // pt + 'style' => 'U', // combo of B, I, U + 'posn' => 'C', // combo of L, C, R + 'r' => 0, // Red 0-255 + 'g' => 0, // Green 0-255 + 'b' => 255),// Blue 0-255 + ); + break; + case "a4": + // Setup for A4 210mm x 297mm paper (8.27" x 11.69") + $cfg = array( + 'pageW' => 210, // mm + 'pageH' => 297, // mm + 'imageNumW' => 5, // integer number + 'imageNumH' => 6, // integer number + 'imageSizeW' => 36, // mm + 'imageSizeH' => 36, // mm + 'marginL' => 8, // mm + 'marginR' => 8, // mm + 'marginT' => 19, // mm (header goes in here) + 'marginB' => 18, // mm (footer goes in here) + 'headerSpace' => 2, // mm (header to top row of images and to link icon) + 'footerSpace' => 2, // mm (bottom row of captions to footer) + 'captionSpace' => 1, // mm (bottom of image to caption) + 'headerFont' => array( + 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats + 'size' => 14, // pt + 'style' => 'B', // combo of B, I, U + 'posn' => 'L', // combo of L, C, R + 'r' => 0, // Red 0-255 + 'g' => 0, // Green 0-255 + 'b' => 0),// Blue 0-255 + 'footerFont' => array( + 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats + 'size' => 12, // pt + 'style' => 'B', // combo of B, I, U + 'posn' => 'R', // combo of L, C, R + 'r' => 0, // Red 0-255 + 'g' => 0, // Green 0-255 + 'b' => 0),// Blue 0-255 + 'captionFont' => array( + 'name' => 'Arial', // included are Arial/Helvetica, Courier, Times, Symbol, ZapfDingbats + 'size' => 8, // pt + 'style' => 'U', // combo of B, I, U + 'posn' => 'C', // combo of L, C, R + 'r' => 0, // Red 0-255 + 'g' => 0, // Green 0-255 + 'b' => 255),// Blue 0-255 + ); + break; + default: + throw new Kohana_Exception('unhandled page type: '.$page_type); + } + + // Here are some other parameters that need defining + $cfg['footerTextPage'] = 'Page '; // Note that this text isn't autofixed by translate module + $cfg['footerTextSlash'] = ' / '; + $cfg['headerLinkIconPath'] = MODPATH . 'proofsheet/images/ico-link.png'; + $cfgImageMissing['iconPath'] = MODPATH . 'proofsheet/images/image_missing.png'; + $cfgImageMissing['iconType'] = 'PNG'; // PNG or JPG is most robust, GIF okay only if GD is installed + $pt2mm = 25.4/72; // 25.4mm=1in=72pt + + // Derive a bunch more parameters. These are all dependent on the above stuff. + $cfg['headerH'] = $pt2mm * $cfg['headerFont']['size']; + $cfg['footerH'] = $pt2mm * $cfg['footerFont']['size']; + $cfg['captionH'] = $pt2mm * $cfg['captionFont']['size']; + $cfg['imageSpaceW'] = ($cfg['pageW']-$cfg['marginL']-$cfg['marginR']-$cfg['imageNumW']*$cfg['imageSizeW']) / ($cfg['imageNumW']-1); + $cfg['imageSpaceH'] = ($cfg['pageH']-$cfg['marginT']-$cfg['marginB']-$cfg['imageNumH']*$cfg['imageSizeH']-$cfg['captionH']-$cfg['captionSpace']) / ($cfg['imageNumH']-1); + $linkInfo = getimagesize($cfg['headerLinkIconPath']); + $cfg['headerLinkH'] = $cfg['headerH']; // I'm defining this to be the same as the text, but you can change it here. + $cfg['headerLinkW'] = $linkInfo[0] / $linkInfo[1] * $cfg['headerLinkH']; + $cfg['headerW'] = $cfg['pageW']-$cfg['marginL']-$cfg['marginR']-$cfg['headerLinkW']-$cfg['headerSpace']; + $cfg['footerW'] = $cfg['pageW']-$cfg['marginL']-$cfg['marginR']; + $cfg['captionW'] = $cfg['imageSizeW']; // I'm defining this to be the same as the image, but you can change it here. + $cfg['headerX'] = $cfg['marginL']; + $cfg['headerLinkX'] = $cfg['marginL']+$cfg['headerW']; + $cfg['footerX'] = $cfg['marginL']; + $cfg['headerY'] = $cfg['marginT']-$cfg['headerH']-$cfg['headerSpace']; + $cfg['headerLinkY'] = $cfg['marginT']-$cfg['headerLinkH']-$cfg['headerSpace']; + $cfg['footerY'] = $cfg['pageH']-$cfg['marginB']+$cfg['footerSpace']; + $cfg['imageNum'] = $cfg['imageNumW']*$cfg['imageNumH']; + $cfgImageMissing['iconInfo'] = getimagesize($cfgImageMissing['iconPath']); + $cfgImageMissing['GDflag'] = graphics::detect_toolkits()->gd->installed; // FPDF uses GD to convert GIFs + + /** + * Initialize and build PDF... the main routine. Note that almost all of the + * useful configuration parameters are already defined above. + */ + + // Initialize PDF, disable automatic margins and page breaks + $pdf = new proofsheet_PDF('P', 'mm', array($cfg['pageW'],$cfg['pageH']) ); + $pdf->SetMargins(0,0); + $pdf->SetAutoPageBreak(0); + + // Build the PDF + $numpages = floor(count($files)/$cfg['imageNum'])+1; + $i = 0; + foreach($files as $f_path => $f_info) { + // Initialize new pages, add header and footer + if (($i % $cfg['imageNum'])==0) { + $pdf->AddPage(); + $pdf->printText($headerText, $cfg['headerFont'], $cfg['headerX'], $cfg['headerY'], $cfg['headerW'], $cfg['headerH']); + $pdf->printImage($cfg['headerLinkIconPath'], $cfg['headerLinkX'], $cfg['headerLinkY'], $cfg['headerLinkW'], $cfg['headerLinkH'], $headerLink, $cfgImageMissing); + $footerText = $cfg['footerTextPage'] . strval(floor($i/$cfg['imageNum'])+1) . $cfg['footerTextSlash'] . strval($numpages); + $pdf->printText($footerText, $cfg['footerFont'], $cfg['footerX'], $cfg['footerY'], $cfg['footerW'], $cfg['footerH']); + } + // Add thumbnail and caption + $x = $cfg['marginL'] + ($cfg['imageSizeW']+$cfg['imageSpaceW']) * ( $i % $cfg['imageNumW']); + $y = $cfg['marginT'] + ($cfg['imageSizeH']+$cfg['imageSpaceH']) * (floor($i/$cfg['imageNumW']) % $cfg['imageNumH']); + $pdf->printImage($f_path, $x, $y, $cfg['imageSizeW'], $cfg['imageSizeH'], null, $cfgImageMissing); + $pdf->printText($f_info['name'], $cfg['captionFont'], $x, $y+$cfg['imageSizeH']+$cfg['captionSpace'], $cfg['captionW'], $cfg['captionH'], $f_info['url']); + // Increment index and loop + $i++; + } + + /** + * Output the PDF file. I wrote it in two versions (one should always be commented out). + */ + // Using a method similar to downloadalbum + $pdfstring = $pdf->Output('','S'); + $this->prepareOutput(); + $this->sendHeaders($pdfname, strlen($pdfstring)); + echo $pdfstring; + + // Using FPDF directly + //$pdf->Output($pdfname,'I'); + + } + + /** + * Return the files that must be included in the archive. + * This is largely borrowed from downloadalbum, but does have + * significant modifications. + */ + private function getFilesList($container) { + $files = array(); + + if( $container instanceof Item_Model && $container->is_album() ) { + $items = $container->viewable() + ->descendants(null, null, array(array("type", "<>", "album"))); + + foreach($items as $i) { + if (!access::can('view_full', $i)) { + continue; + } + + $thumb_realpath = realpath($i->thumb_path()); + if (!is_readable($thumb_realpath)) { + continue; + } + + $files[$thumb_realpath] = array('url' => $i->abs_url(), 'name' => $i->title); + } + + } else if( $container instanceof Tag_Model ) { + $items = $container->items(); + foreach($items as $i) { + if (!access::can('view_full', $i)) { + continue; + } + + if( $i->is_album() ) { + foreach($this->getFilesList($i) as $f_name => $f_info) { + $files[$f_name] = $f_info; + } + + } else { + $thumb_realpath = realpath($i->thumb_path()); + if (!is_readable($thumb_realpath)) { + continue; + } + + $files[$thumb_realpath] = array('url' => $i->abs_url(), 'name' => $i->title); + + } + } + } + + if (count($files) === 0) { + throw new Kohana_Exception('no thumb files in ['.$container->name.']'); + } + + return $files; + } + + + /** + * See system/helpers/download.php + * This is borrowed from downloadalbum without changes. + */ + private function prepareOutput() { + // Close output buffers + Kohana::close_buffers(FALSE); + // Clear any output + Event::add('system.display', create_function('', 'Kohana::$output = "";')); + } + + /** + * See system/helpers/download.php + * This is borrowed from downloadalbum without changes. + */ + private function sendHeaders($filename, $filesize = null) { + if (!is_null($filesize)) { + header('Content-Length: '.$filesize); + } + + // Retrieve MIME type by extension + $mime = Kohana::config('mimes.'.strtolower(substr(strrchr($filename, '.'), 1))); + $mime = empty($mime) ? 'application/octet-stream' : $mime[0]; + header("Content-Type: $mime"); + header('Content-Transfer-Encoding: binary'); + + // Send headers necessary to invoke a "Save As" dialog + header('Content-Disposition: attachment; filename="'.$filename.'"'); + + // Prevent caching + header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); + + $pragma = 'no-cache'; + $cachecontrol = 'no-cache, max-age=0'; + + // request::user_agent('browser') seems bugged + if (request::user_agent('browser') === 'Internet Explorer' + || stripos(request::user_agent(), 'msie') !== false + || stripos(request::user_agent(), 'internet explorer') !== false) + { + if (request::protocol() === 'https') { + // See http://support.microsoft.com/kb/323308/en-us + $pragma = 'cache'; + $cachecontrol = 'private'; + + } else if (request::user_agent('version') <= '6.0') { + $pragma = ''; + $cachecontrol = 'must-revalidate, post-check=0, pre-check=0'; + } + } + + header('Pragma: '.$pragma); + header('Cache-Control: '.$cachecontrol); + } +} + +class proofsheet_PDF extends FPDF { + + /** + * Print text (header, footer, or caption) with link, formatted as in cfg. + * It converts UTF-8 back to CP1252, which is used by FPDF. + * This will trim formatted text to fit and add ellipsis if needed. + */ + function printText($text, $font, $x, $y, $w, $h, $link = null) { + $ellipsis = '…'; // ASCII character 133 + // Convert from UTF-8 back to CP1252 + $text = iconv('utf-8','cp1252',$text); + // Set color, font, and position + $this->SetTextColor($font['r'],$font['g'],$font['b']); + $this->SetFont($font['name'],$font['style'],$font['size']); + $this->SetXY($x, $y); + // Trim text if needed + if (($this->GetStringWidth($text)) > $w) { + // Keep trimming until the size, with ellipsis, is small enough + while (($this->GetStringWidth($text.$ellipsis)) > $w) { + $text = substr($text,0,strlen($text)-1); + } + // Add the ellipsis to the shortened text + $text = $text.$ellipsis; + } + // Create text cell + $this->Cell($w,$h,$text,0,0,$font['posn'],false,$link); + } + + /** + * Print image. This is basically a wrapper around the FPDF image function, + * except that it determines the file type independent of the file extension + * and automatically resizes to main aspect ratio within the defined space. + * Note that this provides robustness for images with incorrect filenames, such + * as missing_movie.png being called a jpg when copied as a thumbnail in v3.0.2. + */ + function printImage($imagePath, $x, $y, $w, $h, $link = null, $cfgImageMissing) { + $imageInfo = getimagesize($imagePath); // [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG) + // Figure out the filetype + switch($imageInfo[2]) { + case 3: + $imageType = 'PNG'; + break; + case 2: + $imageType = 'JPG'; + break; + case 1: + if ($cfgImageMissing['GDflag']) { + $imageType = 'GIF'; + break; + } + default: + // use the missing image icon instead + $imagePath = $cfgImageMissing['iconPath']; + $imageType = $cfgImageMissing['iconType']; + $imageInfo = $cfgImageMissing['iconInfo']; + } + // Determine image orientation and create image + $ratioWH = ($imageInfo[0]/$w) / ($imageInfo[1]/$h); + if ($ratioWH>1) { + $this->image($imagePath, $x, $y+(1-1/$ratioWH)*$h/2, $w, 0, $imageType, $link); + } else { + $this->image($imagePath, $x+(1-$ratioWH)*$w/2, $y, 0, $h, $imageType, $link); + } + } +} diff --git a/3.0/modules/proofsheet/helpers/proofsheet_event.php b/3.0/modules/proofsheet/helpers/proofsheet_event.php index 3b772515..1f463c9b 100644 --- a/3.0/modules/proofsheet/helpers/proofsheet_event.php +++ b/3.0/modules/proofsheet/helpers/proofsheet_event.php @@ -17,32 +17,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ - -/** - * Generate a PDF proof sheet on-the-fly of the current album or tag. - * By Shad Laws. Version 5, 2012/04/05 - * - * 2012/04/05, version 5 - * Added ability to include GIF thumbnails if GD is installed (FPDF uses GD) - * Changed behavior of unhandled file types - now provides missing image icon instead of throwing an exception - * 2012/03/30, version 4 - * Major rewrite. Output is similar, but everything "under the hood" is much cleaner and (I hope) more easily understood and tweakable by other users. - * Header link is now an icon. - * Fixed encoding problems with diacritic marks and special characters. - * Now includes FPDF as a library instead of requiring a separate installtion. - * 2012/03/28, version 3 - * Made sizing configuration more flexible - * Prettified code so it's easier to understand and tweak as desired - * Added header link - * First version properly documented and linked to Gallery wiki - * 2012/03/27, version 2 - * Determines jpg/png type by file header, not extension, which makes it robust against misnamed extensions - * (N.B.: there's a bug in some movie modules that copy missing_movie.png as a jpg thumbnail!) - * Made caption size limits to prevent overrun - * 2012/03/27, version 1 - * Initial release - */ - class proofsheet_event_Core { /** diff --git a/3.0/modules/proofsheet/module.info b/3.0/modules/proofsheet/module.info index fec62944..e0debcf6 100644 --- a/3.0/modules/proofsheet/module.info +++ b/3.0/modules/proofsheet/module.info @@ -1,6 +1,6 @@ name = "ProofSheet" description = "Displays links to generate a PDF proof sheet of the current album in A4 or LTR size." -version = 5 +version = 7 author_name = "Shad Laws" author_url = "" info_url = "http://codex.gallery2.org/Gallery3:Modules:proofsheet" diff --git a/3.0/modules/register/controllers/admin_register.php b/3.0/modules/register/controllers/admin_register.php index f88bca30..1362a72b 100755 --- a/3.0/modules/register/controllers/admin_register.php +++ b/3.0/modules/register/controllers/admin_register.php @@ -35,11 +35,17 @@ class Admin_register_Controller extends Admin_Controller { $post->add_rules("policy", "required"); $post->add_rules("group", array($this, "passthru")); $post->add_rules("email_verification", array($this, "passthru")); + // added Shad Laws, v2 + $post->add_rules("admin_notify", array($this, "passthru")); + $post->add_rules("subject_prefix", array($this, "passthru")); $group_list = array(); if ($post->validate()) { module::set_var("registration", "policy", $post->policy); module::set_var("registration", "default_group", $post->group); module::set_var("registration", "email_verification", !empty($post->email_verification)); + // added Shad Laws, v2 + module::set_var("registration", "admin_notify", !empty($post->admin_notify)); + module::set_var("registration", "subject_prefix", $post->subject_prefix); message::success(t("Registration defaults have been updated.")); @@ -108,6 +114,12 @@ class Admin_register_Controller extends Admin_Controller { if (empty($admin->email)) { module::set_var("registration", "email_verification", false); } + // below lines added Shad Laws, v2 + $v->content->disable_admin_notify = + empty($admin->email) || $form["policy"] !== "admin_approval" ? "disabled" : ""; + if (empty($admin->email)) { + module::set_var("registration", "admin_notify", false); + } $v->content->group_list = array(); foreach (identity::groups() as $group) { @@ -134,7 +146,10 @@ class Admin_register_Controller extends Admin_Controller { private function _get_form() { $form = array("policy" => module::get_var("registration", "policy"), "group" => module::get_var("registration", "default_group"), - "email_verification" => module::get_var("registration", "email_verification")); + "email_verification" => module::get_var("registration", "email_verification"), + // added Shad Laws, v2 + "subject_prefix" => module::get_var("registration", "subject_prefix"), + "admin_notify" => module::get_var("registration", "admin_notify")); $errors = array_fill_keys(array_keys($form), ""); return array($form, $errors); diff --git a/3.0/modules/register/controllers/register.php b/3.0/modules/register/controllers/register.php index 35064b9a..ea8eaef5 100755 --- a/3.0/modules/register/controllers/register.php +++ b/3.0/modules/register/controllers/register.php @@ -51,9 +51,15 @@ class register_Controller extends Controller { } else if ($pending_user->state == 1) { site_status::warning( t("There are pending user registration. Review now!", - array("url" => html::mark_clean(url::site("admin/register")))), + // modified by Shad Laws, v2 + // array("url" => html::mark_clean(url::site("admin/register")))), + array("url" => html::mark_clean(url::site("admin/register")), "locale" => module::get_var("gallery", "default_locale"))), "pending_user_registrations"); message::success(t("Your registration request is awaiting administrator approval")); + // added by Shad Laws, v2 + if (module::get_var("registration", "admin_notify") == 1) { + register::send_admin_notify($pending_user); + } } else { register::send_confirmation($pending_user); message::success(t("A confirmation email has been sent to your email address.")); @@ -84,9 +90,15 @@ class register_Controller extends Controller { } else { site_status::warning( t("There are pending user registration. Review now!", - array("url" => html::mark_clean(url::site("admin/register")))), + // modified by Shad Laws, v2 + // array("url" => html::mark_clean(url::site("admin/register")))), + array("url" => html::mark_clean(url::site("admin/register")), "locale" => module::get_var("gallery", "default_locale"))), "pending_user_registrations"); message::success(t("Your registration request is awaiting administrator approval")); + // added by Shad Laws, v2 + if (module::get_var("registration", "admin_notify") == 1) { + register::send_admin_notify($pending_user); + } } } else { message::error(t("Your registration request is no longer valid, Please re-register.")); @@ -144,7 +156,9 @@ class register_Controller extends Controller { ->rules("required|valid_email|length[1,255]"); $group->input("email2")->label(t("Confirm email"))->id("g-email2") ->matches($group->email); - $group->input("url")->label(t("URL"))->id("g-url") + // modified by Shad Laws, v2 + // $group->input("url")->label(t("URL"))->id("g-url") + $group->input("url")->label(t("URL")." (".t("optional").")")->id("g-url") ->rules("valid_url"); module::event("register_add_form", $form); 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/helpers/register.php b/3.0/modules/register/helpers/register.php index 13781008..4a2b0128 100644 --- a/3.0/modules/register/helpers/register.php +++ b/3.0/modules/register/helpers/register.php @@ -47,14 +47,35 @@ class register_Core { $message->user = $user; $message->site_url = $requires_first ? url::abs_site("register/first/{$user->hash}") : url::abs_site(""); - self::_sendemail($user->email, t("Your userid has been created"), $message); + // added Shad Laws, v2 + $message->subject_prefix = module::get_var("registration", "subject_prefix"); + $message->locale = $user->locale; // as stored in pending_users table + $message->subject = t("Welcome", array("locale" => $message->locale)); + // modified Shad Laws, v2 + self::_sendemail($user->email, $message->subject_prefix.$message->subject, $message); } static function send_confirmation($user) { $message = new View("confirm_registration.html"); $message->confirm_url = url::abs_site("register/confirm/{$user->hash}"); $message->user = $user; - self::_sendemail($user->email, t("User registration confirmation"), $message); + // added Shad Laws, v2 + $message->subject_prefix = module::get_var("registration", "subject_prefix"); + $message->locale = $user->locale; // as stored in pending_users table + $message->subject = t("User registration confirmation", array("locale" => $message->locale)); + // modified Shad Laws, v2 + self::_sendemail($user->email, $message->subject_prefix.$message->subject, $message); + } + + // function added Shad Laws, v2 + static function send_admin_notify($user) { + $message = new View("register_admin_notify.html"); + $message->admin_register_url = url::abs_site("admin/register"); + $message->user = $user; + $message->subject_prefix = module::get_var("registration", "subject_prefix"); + $message->locale = module::get_var("gallery", "default_locale"); // as Gallery default + $message->subject = t("New pending user registration", array("locale" => $message->locale)); + self::_sendemail(module::get_var("gallery", "email_reply_to"), $message->subject_prefix.$message->subject, $message); } static function create_pending_request($form) { @@ -66,6 +87,8 @@ class register_Core { $user->email = $form->register_user->inputs["email"]->value; $user->url = $form->register_user->inputs["url"]->value; $user->request_date = time(); + // added by Shad Laws, v2 + $user->locale = locales::locale_from_http_request() ? locales::locale_from_http_request() : module::get_var("gallery", "default_locale"); // sets default locale based on browser if (!$email_verification) { $user->state = 1; @@ -98,7 +121,8 @@ class register_Core { ->to($email) ->subject($subject) ->header("Mime-Version", "1.0") - ->header("Content-type", "text/html; charset=iso-8859-1") + // modified by Shad Laws, v2 + ->header("Content-type", "text/html; charset=utf-8") ->message($message->render()) ->send(); } diff --git a/3.0/modules/register/helpers/register_installer.php b/3.0/modules/register/helpers/register_installer.php index fb7db4d3..58fd6389 100644 --- a/3.0/modules/register/helpers/register_installer.php +++ b/3.0/modules/register/helpers/register_installer.php @@ -37,11 +37,34 @@ class register_installer { module::set_var("registration", "policy", "admin_only"); module::set_var("registration", "default_group", ""); module::set_var("registration", "email_verification", false); + // added Shad Laws, v2 + module::set_var("registration", "admin_notify", false); + module::set_var("registration", "subject_prefix", ""); + $db->query("ALTER TABLE {pending_users} ADD `locale` varchar(32) default NULL;"); + // changed Shad Laws, v2 + module::set_version("register", 2); + } - module::set_version("register", 1); + // function added Shad Laws, v2 + static function upgrade() { + if (module::get_version("register") < 1) { + module::install("register"); + } + if (is_null(module::get_var("registration", "admin_notify")) || + is_null(module::get_var("registration", "subject_prefix")) || + (module::get_version("register") < 2) ) { + + module::set_var("registration", "admin_notify", false); + module::set_var("registration", "subject_prefix", ""); + $db = Database::instance(); + $db->query("ALTER TABLE {pending_users} ADD `locale` varchar(32) default NULL;"); + } + module::set_version("register", 2); } static function uninstall() { Database::instance()->query("DROP TABLE IF EXISTS {pending_users};"); + // added Shad Laws, v2 + module::clear_all_vars("registration"); } } \ No newline at end of file diff --git a/3.0/modules/register/helpers/register_theme.php b/3.0/modules/register/helpers/register_theme.php index 38833f86..468fb762 100644 --- a/3.0/modules/register/helpers/register_theme.php +++ b/3.0/modules/register/helpers/register_theme.php @@ -25,4 +25,9 @@ class register_theme_Core { return new View("register_welcome_message_loader.html"); } } + // added Shad Laws, v2 + static function head($theme) { + return $theme->css("register.css"); + } + } \ No newline at end of file diff --git a/3.0/modules/register/module.info b/3.0/modules/register/module.info index 36133cab..430cca8d 100755 --- a/3.0/modules/register/module.info +++ b/3.0/modules/register/module.info @@ -1,7 +1,7 @@ name = "User Registration" description = "Allow guests to register as users." -version = 1 -author_name = "" +version = 2 +author_name = "revised to v2 by Shad Laws" author_url = "" info_url = "http://codex.gallery2.org/Gallery3:Modules:register" discuss_url = "http://gallery.menalto.com/forum_module_register" diff --git a/3.0/modules/register/views/admin_register.html.php b/3.0/modules/register/views/admin_register.html.php index 6957ce76..54f74098 100644 --- a/3.0/modules/register/views/admin_register.html.php +++ b/3.0/modules/register/views/admin_register.html.php @@ -7,6 +7,12 @@ } else { $(":checkbox[name=email_verification]").removeAttr("disabled"); } + if ($(this).val() !== "admin_approval") { + $(":checkbox[name=admin_notify]").attr("disabled", "disabled"); + } else { + $(":checkbox[name=admin_notify]").removeAttr("disabled"); + } + }); }); @@ -27,6 +33,14 @@ +
  • + + +
  • +
  • + + +
  • diff --git a/3.0/modules/register/views/confirm_registration.html.php b/3.0/modules/register/views/confirm_registration.html.php index 51fed168..80c62937 100644 --- a/3.0/modules/register/views/confirm_registration.html.php +++ b/3.0/modules/register/views/confirm_registration.html.php @@ -1,17 +1,18 @@ - <?= t("User registration confirmation") ?> + <?= ($subject_prefix.$subject) ?> -

    +

    - $user->full_name ? $user->full_name : $user->name)) ?> + $user->full_name ? $user->full_name : $user->name, "locale" => $locale)) ?>

    - clicking this link. If you didn't request this password reset, it's ok to ignore this mail.", + clicking this link. If you didn't request this password reset, it's ok to ignore this mail.", array("site_url" => html::mark_clean(url::base(false, "http")), - "confirm_url" => $confirm_url)) ?> + "confirm_url" => $confirm_url, + "locale" => $locale)) ?>

    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/register/views/register_welcome.html.php b/3.0/modules/register/views/register_welcome.html.php index b2744641..2d18385b 100644 --- a/3.0/modules/register/views/register_welcome.html.php +++ b/3.0/modules/register/views/register_welcome.html.php @@ -1,16 +1,17 @@ - <?= t("Welcome to Gallery3") ?> + <?= ($subject_prefix.$subject) ?> -

    +

    - $user->full_name ? $user->full_name : $user->name)) ?> + $user->full_name ? $user->full_name : $user->name, "locale" => $locale)) ?>

    - You can access the site by clicking this link and you will be prompted to set your password at this point.", - array("site_url" => html::mark_clean($site_url))) ?> + You can access the site by clicking this link and you will be prompted to set your password at this point.", + array("site_url" => html::mark_clean($site_url), + "locale" => $locale)) ?>

    diff --git a/3.0/modules/short_search_fix/helpers/MY_search.php b/3.0/modules/short_search_fix/helpers/MY_search.php index 8e4b8830..aaf99645 100644 --- a/3.0/modules/short_search_fix/helpers/MY_search.php +++ b/3.0/modules/short_search_fix/helpers/MY_search.php @@ -23,36 +23,101 @@ class search extends search_Core { * few terms in the query. */ static function add_query_terms($q) { - $MAX_TERMS = 5; - + $MAX_TERMS = 5; // used to limit the max number of extra terms + $prefix = module::get_var("short_search_fix","search_prefix"); // short search fix prefix // strip leading, trailing, and extra whitespaces $terms = preg_replace('/^\s+/', '', $q); $terms = preg_replace('/\s+$/', '', $terms); $terms = preg_replace('/\s\s+/', ' ', $terms); - - $terms = explode(" ", $terms, $MAX_TERMS); - //$terms = explode(" ", $q, $MAX_TERMS); // commented out from original function - for ($i = 0; $i < min(count($terms), $MAX_TERMS - 1); $i++) { - // Don't wildcard quoted or already wildcarded terms - if ((substr($terms[$i], 0, 1) != '"') && (substr($terms[$i], -1, 1) != "*")) { - $terms[] = rtrim($terms[$i], "s") . "*"; + // explode terms, initialize the loop + $terms = explode(" ", $terms); // array + $termsextra = ""; // string, not array + $numtermsextra = 0; + $flagwild = 1; + $countquote = 0; + $countparen = 0; + // run the loop for each term + foreach ($terms as &$term) { + $countprefix = 0; + $countsuffix = 0; + $flagopenparen = 0; + $flagcloseparen = 0; + // set flagwild to 0 if we're over MAX_TERMS (only runs if we're not in the middle of parens/quotes) + if ($countparen == 0 && $countquote == 0 && ($numtermsextra >= ($MAX_TERMS - 1))) { + $flagwild = 0; + } + // find opening special characters + while ((substr($term, $countprefix, 1) == "(" || + substr($term, $countprefix, 1) == '"' || + substr($term, $countprefix, 1) == "+" || + substr($term, $countprefix, 1) == "-" || + substr($term, $countprefix, 1) == "~" || + substr($term, $countprefix, 1) == "<" || + substr($term, $countprefix, 1) == ">") && + ($countprefix+$countsuffix) < strlen($term)) { + if (substr($term, $countprefix, 1) == '"') { + $countquote++; + $flagwild = 0; + } + if (substr($term, $countprefix, 1) == "(") { + $countparen++; + $flagopenparen = 1; + } + $countprefix++; + } + // reset flagwild to 1 if we're under MAX_TERMS (only runs if we're not in the middle of quotes, and forced to run if we're still in paren) + if ($countquote == 0 && ($countparen > 0 || $numtermsextra < ($MAX_TERMS - 1))) { + $flagwild = 1; + } + // find closing special characters + while ((substr($term, -$countsuffix-1, 1) == ")" || + substr($term, -$countsuffix-1, 1) == '"') && + ($countprefix+$countsuffix) < strlen($term)) { + if (substr($term, -$countsuffix-1, 1) == '"') { + $countquote = max(0, $countquote-1); + } + if (substr($term, -$countsuffix-1, 1) == ")") { + $countparen = max(0, $countparen-1); + $flagcloseparen = 1; + } + $countsuffix++; + } + // split term + $termprefix = substr($term, 0, $countprefix); + $termterm = substr($term."A", $countprefix, -$countsuffix-1); // artificial padded A assures that the third argument is always negative + $termsuffix = substr($term, -$countsuffix, $countsuffix); + // add extra terms with wildcards + if ($flagwild == 1 && + substr($termterm, -1, 1) != "*" && + strlen($termterm) > 0) { + // @todo: make this i18n friendly with the plural character (only works here with s) + $termsextra = $termsextra . $termprefix . $prefix . rtrim($termterm, "s") . "*" . $termsuffix . " "; + $numtermsextra++; + } elseif ($flagopenparen == 1 && $flagcloseparen == 0) { + $termsextra = $termsextra . str_replace('"', '', $termprefix); + } elseif ($flagopenparen == 0 && $flagcloseparen == 1) { + $termsextra = preg_replace('/\s+$/', '', $termsextra) . ") "; + } + // add short search prefixes + if (strlen($termterm) > 0) { + $term = $termprefix . $prefix . $termterm . $termsuffix; } } - //return implode(" ", $terms); // commented out from original function - - /** - * Add the search prefix to the start of every word. - */ - $prefix = module::get_var("short_search_fix","search_prefix"); + // implode terms, trim termsextra trailing space (if it exists) $terms = implode(" ", $terms); - $terms = preg_replace('/^\s+/', '', $terms); // the implode seems to add this back in - // add the prefixes - if (preg_match('/\w/',$terms) > 0) { - $terms = ' ' . $terms; - $terms = str_replace(' ', ' '.$prefix, $terms); - $terms = str_replace(' '.$prefix.'"', ' '.'"'.$prefix, $terms); - $terms = substr($terms,1); + $termsextra = preg_replace('/\s+$/', '', $termsextra); + // add extra closing quotes and parentheses + while ($countquote > 0) { + $terms = $terms.'"'; + $termsextra = $termsextra.'"'; + $countquote--; } - return $terms; + while ($countparen > 0) { + $terms = $terms.")"; + $termsextra = $termsextra.")"; + $countparen--; + } + // all done! + return ($terms." ".$termsextra); } -} +} \ No newline at end of file diff --git a/3.0/modules/short_search_fix/module.info b/3.0/modules/short_search_fix/module.info index b24d10d2..e9d95782 100644 --- a/3.0/modules/short_search_fix/module.info +++ b/3.0/modules/short_search_fix/module.info @@ -1,6 +1,6 @@ name = "Short Search Fix" description = "Allows 2-3 letter searches to be performed without requiring SQL system variable modification (useful for shared hosting)." -version = 1 +version = 2 author_name = "Shad Laws" author_url = "" info_url = "http://codex.gallery2.org/Gallery3:Modules:short_search_fix" diff --git a/3.0/modules/tag_cloud_html5/controllers/admin_tag_cloud_html5.php b/3.0/modules/tag_cloud_html5/controllers/admin_tag_cloud_html5.php index e6a6a766..b724720c 100644 --- a/3.0/modules/tag_cloud_html5/controllers/admin_tag_cloud_html5.php +++ b/3.0/modules/tag_cloud_html5/controllers/admin_tag_cloud_html5.php @@ -29,111 +29,88 @@ class Admin_Tag_Cloud_Html5_Controller extends Admin_Controller { $cfg = $this->_get_config(); $form = $this->_get_admin_form(); if ($form->validate()) { - if ($form->options_general->load_defaults->value) { + if ($form->general->reset_defaults->value) { // reset all to defaults, redirect with message module::install("tag_cloud_html5"); message::success(t("Tag cloud options reset successfully")); url::redirect("admin/tag_cloud_html5"); - } else { - $valid = true; - // run checks on various inputs - $options_general = $form->options_general; - if ($options_general->height_sidebar->value < 0) { - $form->options_general->height_sidebar->add_error("not_valid", 1); - $valid = false; - } - foreach ($cfg['groups'] as $groupname => $grouptext) { - ${"options".$groupname} = $form->{"options".$groupname}; - if ($options_general->{"maxtags".$groupname}->value < 0) { - $form->options_general->{"maxtags".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if (${"options".$groupname}->{"maxSpeed".$groupname}->value < 0) { - $form->{"options".$groupname}->{"maxSpeed".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if ((${"options".$groupname}->{"initialX".$groupname}->value < -1) || (${"options".$groupname}->{"initialX".$groupname}->value > 1)) { - $form->{"options".$groupname}->{"initialX".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if ((${"options".$groupname}->{"initialY".$groupname}->value < -1) || (${"options".$groupname}->{"initialY".$groupname}->value > 1)) { - $form->{"options".$groupname}->{"initialY".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if ((${"options".$groupname}->{"deadZone".$groupname}->value < 0) || (${"options".$groupname}->{"deadZone".$groupname}->value > 1)) { - $form->{"options".$groupname}->{"deadZone".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if (${"options".$groupname}->{"zoom".$groupname}->value < 0) { - $form->{"options".$groupname}->{"zoom".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if ((${"options".$groupname}->{"depth".$groupname}->value < 0) || (${"options".$groupname}->{"depth".$groupname}->value > 1)) { - $form->{"options".$groupname}->{"depth".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if (${"options".$groupname}->{"outlineOffset".$groupname}->value < 0) { - $form->{"options".$groupname}->{"outlineOffset".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if (preg_match("/^#[0-9A-Fa-f]{6}$/", ${"options".$groupname}->{"outlineColour".$groupname}->value) == 0) { - $form->{"options".$groupname}->{"outlineColour".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if ((preg_match("/^#[0-9A-Fa-f]{6}$/", ${"options".$groupname}->{"textColour".$groupname}->value) == 0) && (strcmp(${"options".$groupname}->{"textColour".$groupname}->value, "") != 0) ) { - $form->{"options".$groupname}->{"textColour".$groupname}->add_error("not_valid", 1); - $valid = false; - } - if (${"options".$groupname}->{"textHeight".$groupname}->value < 0) { - $form->{"options".$groupname}->{"textHeight".$groupname}->add_error("not_valid", 1); - $valid = false; - } - } - if ($valid) { - // all inputs passed tests above; save them - module::set_var("tag_cloud_html5", "show_wholecloud_link", ($options_general->show_wholecloud_link->value == 1)); - module::set_var("tag_cloud_html5", "show_add_tag_form", ($options_general->show_add_tag_form->value == 1)); - module::set_var("tag_cloud_html5", "height_sidebar", $options_general->height_sidebar->value); - module::set_var("tag_cloud_html5", "show_wholecloud_list", ($options_general->show_wholecloud_list->value == 1)); - foreach ($cfg['groups'] as $groupname => $grouptext) { - module::set_var("tag_cloud_html5", "maxtags".$groupname, $options_general->{"maxtags".$groupname}->value); - - $optionsarray = array(); - $optionsarray['maxSpeed'] = ${"options".$groupname}->{"maxSpeed".$groupname}->value; - $optionsarray['deadZone'] = ${"options".$groupname}->{"deadZone".$groupname}->value; - $optionsarray['initial'] = array(${"options".$groupname}->{"initialX".$groupname}->value, ${"options".$groupname}->{"initialY".$groupname}->value); - $optionsarray['initialDecel'] = (${"options".$groupname}->{"initialDecel".$groupname}->value == 1); - $optionsarray['zoom'] = ${"options".$groupname}->{"zoom".$groupname}->value; - $optionsarray['depth'] = ${"options".$groupname}->{"depth".$groupname}->value; - $optionsarray['outlineMethod'] = ${"options".$groupname}->{"outlineMethod".$groupname}->value; - $optionsarray['outlineOffset'] = ${"options".$groupname}->{"outlineOffset".$groupname}->value; - $optionsarray['outlineColour'] = ${"options".$groupname}->{"outlineColour".$groupname}->value; - $optionsarray['textColour'] = ${"options".$groupname}->{"textColour".$groupname}->value; - $optionsarray['textFont'] = ${"options".$groupname}->{"textFont".$groupname}->value; - $optionsarray['textHeight'] = ${"options".$groupname}->{"textHeight".$groupname}->value; - $optionsarray['frontSelect'] = (${"options".$groupname}->{"frontSelect".$groupname}->value == 1); - $optionsarray['wheelZoom'] = false; // note that this is locked - otherwise scrolling through the page screws everything up - module::set_var("tag_cloud_html5", "options".$groupname, json_encode($optionsarray)); - } - // all done; redirect with message - message::success(t("Tag cloud options updated successfully")); - url::redirect("admin/tag_cloud_html5"); - } } + // save the new inputs + module::set_var("tag_cloud_html5", "show_wholecloud_link", ($form->general->show_wholecloud_link->value == 1)); + module::set_var("tag_cloud_html5", "show_add_tag_form", ($form->general->show_add_tag_form->value == 1)); + module::set_var("tag_cloud_html5", "show_wholecloud_list", ($form->general->show_wholecloud_list->value == 1)); + foreach ($cfg['groups'] as $groupname => $grouptext) { + module::set_var("tag_cloud_html5", "maxtags".$groupname, $form->{"size".$groupname}->{"maxtags".$groupname}->value); + module::set_var("tag_cloud_html5", "width".$groupname, $form->{"size".$groupname}->{"width".$groupname}->value); + module::set_var("tag_cloud_html5", "height".$groupname, $form->{"size".$groupname}->{"height".$groupname}->value); + + $optionsarray = array(); + // group size + $optionsarray['shape'] = $form->{"size".$groupname}->{"shape".$groupname}->value; + $optionsarray['zoom'] = $form->{"size".$groupname}->{"zoom".$groupname}->value; + $optionsarray['stretchX'] = $form->{"size".$groupname}->{"stretchX".$groupname}->value; + $optionsarray['stretchY'] = $form->{"size".$groupname}->{"stretchY".$groupname}->value; + // group motion + $optionsarray['maxSpeed'] = $form->{"motion".$groupname}->{"maxSpeed".$groupname}->value; + $optionsarray['minSpeed'] = $form->{"motion".$groupname}->{"minSpeed".$groupname}->value; + $optionsarray['deadZone'] = $form->{"motion".$groupname}->{"deadZone".$groupname}->value; + $optionsarray['decel'] = $form->{"motion".$groupname}->{"decel".$groupname}->value; + $optionsarray['initial'] = array($form->{"motion".$groupname}->{"initialX".$groupname}->value, $form->{"motion".$groupname}->{"initialY".$groupname}->value); + $optionsarray['maxInputZone'] = $form->{"motion".$groupname}->{"maxInputZone".$groupname}->value; + // group select + $optionsarray['outlineMethod'] = $form->{"select".$groupname}->{"outlineMethod".$groupname}->value; + $optionsarray['outlineOffset'] = $form->{"select".$groupname}->{"outlineOffset".$groupname}->value; + $optionsarray['outlineColour'] = $form->{"select".$groupname}->{"outlineColour".$groupname}->value; + $optionsarray['frontSelect'] = ($form->{"select".$groupname}->{"frontSelect".$groupname}->value == 1); + // group appearance + $optionsarray['textHeight'] = $form->{"appearance".$groupname}->{"textHeight".$groupname}->value; + $optionsarray['textColour'] = $form->{"appearance".$groupname}->{"textColour".$groupname}->value; + $optionsarray['textFont'] = $form->{"appearance".$groupname}->{"textFont".$groupname}->value; + $optionsarray['depth'] = $form->{"appearance".$groupname}->{"depth".$groupname}->value; + // options that are not explicitly defined in admin menu + $optionsarray['wheelZoom'] = false; // otherwise scrolling through the page screws everything up (was a problem in v1) + $optionsarray['initialDecel'] = true; // this was an option in v4, but it's sorta useless - use minSpeed for a related but better effect + $optionsarray['physModel'] = true; // this is the big enhancement for v5, and is a major modification that I did to TagCanvas + switch ($optionsarray['shape']) { + case "hcylinder": + // keep it horizontal - lock x-axis rotation + $optionsarray['lock'] = "x"; + break; + case "vcylinder": + // keep it vertical - lock y-axis rotation + $optionsarray['lock'] = "y"; + break; + default: + // do not lock either axis + $optionsarray['lock'] = ""; + } + module::set_var("tag_cloud_html5", "options".$groupname, json_encode($optionsarray)); + } + // all done; redirect with message + message::success(t("Tag cloud options updated successfully")); + url::redirect("admin/tag_cloud_html5"); } - // print screen from existing form - you wind up here if something wasn't validated + // not valid - print screen from existing form $this->_print_screen($form); } private function _get_config() { // these define the two variable name groups, along with their labels which are always shown with t() for i18n. - $cfg['groups'] = array("_sidebar"=>"Sidebar", "_wholecloud"=>"Whole cloud"); + $cfg['groups'] = array("_sidebar"=>t("Sidebar"), "_wholecloud"=>t("Whole cloud")); // this defines the separator that's used between the group name and the attribute, and is *not* put through t(). - $cfg['sep'] = ": "; + $cfg['sep'] = " : "; + // this is used in the labels of the width/height parameters + $cfg['size'] = array("_sidebar"=>t("as fraction of sidebar width, e.g. 'g-block-content' class"), "_wholecloud"=>t("as fraction of browser window height")); return $cfg; } 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,1); + $form = preg_replace("/
    /","
    ",$form,4); + $form = preg_replace("/
    /","
    ",$form,4); + $view = new Admin_View("admin.html"); $view->content = new View("admin_tag_cloud_html5.html"); $view->content->form = $form; @@ -144,12 +121,12 @@ class Admin_Tag_Cloud_Html5_Controller extends Admin_Controller { $cfg = $this->_get_config(); $sep = $cfg['sep']; - // Make the form. This form has three groups: group_general, group_sidebar, and group_wholecloud. + // Make the main form. This form has *nine* groups: general, then size, motion, select, and appearance for _sidebar and _wholecloud. $form = new Forge("admin/tag_cloud_html5/edit", "", "post", array("id" => "g-tag-cloud-html5-admin-form")); - // group_general - $group_general = $form->group("options_general")->label(t("Tag cloud options").$sep.t("General")); - $group_general->checkbox("load_defaults") + // group general + $group_general = $form->group("general")->label(t("General"))->set_attr("id","g-tag-cloud-html5-admin-form-general"); + $group_general->checkbox("reset_defaults") ->label(t("Reset all to default values")) ->checked(false); $group_general->checkbox("show_wholecloud_link") @@ -158,94 +135,115 @@ class Admin_Tag_Cloud_Html5_Controller extends Admin_Controller { $group_general->checkbox("show_add_tag_form") ->label(t("Show 'Add tag to album' form in sidebar (when permitted and applicable)")) ->checked(module::get_var("tag_cloud_html5", "show_add_tag_form", null)); - $group_general->input("height_sidebar") - ->label(t("Height of sidebar (as fraction of width)")) - ->value(round(module::get_var("tag_cloud_html5", "height_sidebar", null),3)) // round or else it gets 6 decimal places... - ->error_message("not_valid", t("Height of sidebar must be a 1-5 digit number")) - ->rules("required|valid_numeric|length[1,5]"); $group_general->checkbox("show_wholecloud_list") - ->label(t("Show tag list under cloud on 'View whole cloud' page")) + ->label(t("Show inline tag list under cloud on 'View whole cloud' page")." {hideTags}") ->checked(module::get_var("tag_cloud_html5", "show_wholecloud_list", null)); - + foreach ($cfg['groups'] as $groupname => $grouptext) { - // maxtags - note that this is displayed under group_general! - $maxtags = module::get_var("tag_cloud_html5", "maxtags".$groupname, null); - $group_general->input("maxtags".$groupname) - ->label(t($grouptext).$sep.t("max tags shown")) - ->value($maxtags) - ->error_message("not_valid", t("Max tags must be a 1-4 digit number")) - ->rules("required|valid_numeric|length[1,4]"); - // group_sidebar and group_wholecloud + $maxtags = strval(module::get_var("tag_cloud_html5", "maxtags".$groupname, null)); + $width = strval(module::get_var("tag_cloud_html5", "width".$groupname, null)); + $height = strval(module::get_var("tag_cloud_html5", "height".$groupname, null)); $options = json_decode(module::get_var("tag_cloud_html5", "options".$groupname, null),true); - ${"group".$groupname} = $form->group("options".$groupname)->label(t("Tag cloud options").$sep.t($grouptext)); - ${"group".$groupname}->input("maxSpeed".$groupname) - ->label(t($grouptext).$sep.t("max speed (typically 0.01-0.20)")) - ->value($options['maxSpeed']) - ->error_message("not_valid", t("Max speed must be a 1-5 digit number")) - ->rules("required|valid_numeric|length[1,5]"); - ${"group".$groupname}->input("initialX".$groupname) - ->label(t($grouptext).$sep.t("initial horizontal speed (between +/-1.0, as fraction of max speed)")) - ->value($options['initial'][0]) - ->error_message("not_valid", t("Initial horizontal speed must be a 1-4 digit number")) - ->rules("required|valid_numeric|length[1,4]"); - ${"group".$groupname}->input("initialY".$groupname) - ->label(t($grouptext).$sep.t("initial vertical speed (between +/-1.0, as fraction of max speed)")) - ->value($options['initial'][1]) - ->error_message("not_valid", t("Initial vertical speed must be a 1-4 digit number")) - ->rules("required|valid_numeric|length[1,4]"); - ${"group".$groupname}->checkbox("initialDecel".$groupname) - ->label(t($grouptext).$sep.t("initial deceleration (if false, the initial speed is held until a mouseover event)")) - ->checked($options['initialDecel']); - ${"group".$groupname}->input("deadZone".$groupname) - ->label(t($grouptext).$sep.t("dead zone (0.0-1.0, where 0.0 is no dead zone and 1.0 is no active zone)")) - ->value($options['deadZone']) - ->error_message("not_valid", t("Dead zone must be a 1-4 digit number")) - ->rules("required|valid_numeric|length[1,4]"); - ${"group".$groupname}->input("zoom".$groupname) - ->label(t($grouptext).$sep.t("zoom (<1.0 is zoom out, >1.0 is zoom in)")) + + // group size/shape + ${"group_size".$groupname} = $form->group("size".$groupname)->label(t("Size and shape").$sep.$grouptext); + ${"group_size".$groupname}->input("maxtags".$groupname) + ->label(t("maximum tags shown")) + ->value($maxtags) + ->rules("required|numrange[0]"); + ${"group_size".$groupname}->input("width".$groupname) + ->label(t("width")." (".$cfg['size'][$groupname].")") + ->value($width) + ->rules("required|numrange[0]"); + ${"group_size".$groupname}->input("height".$groupname) + ->label(t("height")." (".$cfg['size'][$groupname].")") + ->value($height) + ->rules("required|numrange[0]"); + ${"group_size".$groupname}->dropdown("shape".$groupname) + ->label(t("shape of cloud")." {shape,lock}") + ->options(array("sphere"=>t("sphere"),"hcylinder"=>t("horizontal cylinder"),"vcylinder"=>t("vertical cylinder"))) + ->selected($options['shape']); + ${"group_size".$groupname}->input("zoom".$groupname) + ->label(t("zoom (<1.0 is zoom out, >1.0 is zoom in)")." {zoom}") ->value($options['zoom']) - ->error_message("not_valid", t("Zoom must be a 1-4 digit number")) - ->rules("required|valid_numeric|length[1,4]"); - ${"group".$groupname}->input("depth".$groupname) - ->label(t($grouptext).$sep.t("depth (0.0-1.0)")) - ->value($options['depth']) - ->error_message("not_valid", t("Depth must be a 1-4 digit number")) - ->rules("required|valid_numeric|length[1,4]"); - ${"group".$groupname}->dropdown("outlineMethod".$groupname) - ->label(t($grouptext).$sep.t("outline method (mouseover event)")) + ->rules("required|numrange[0]"); + ${"group_size".$groupname}->input("stretchX".$groupname) + ->label(t("x-axis stretch factor (<1.0 squishes, >1.0 stretches)")." {stretchX}") + ->value($options['stretchX']) + ->rules("required|numrange[0]"); + ${"group_size".$groupname}->input("stretchY".$groupname) + ->label(t("y-axis stretch factor (<1.0 squishes, >1.0 stretches)")." {stretchY}") + ->value($options['stretchY']) + ->rules("required|numrange[0]"); + + // group motion + ${"group_motion".$groupname} = $form->group("motion".$groupname)->label(t("Motion").$sep.$grouptext); + ${"group_motion".$groupname}->input("maxSpeed".$groupname) + ->label(t("max speed (typically 0.01-0.20)")." {maxSpeed}") + ->value($options['maxSpeed']) + ->rules("required|numrange[0]"); + ${"group_motion".$groupname}->input("minSpeed".$groupname) + ->label(t("no mouseover speed (typically 0.00-0.01)")." {minSpeed}") + ->value($options['minSpeed']) + ->rules("required|numrange[0]"); + ${"group_motion".$groupname}->input("deadZone".$groupname) + ->label(t("dead zone size (0.0-1.0 - 0.0 is none and 1.0 is entire cloud)")." {deadZone}") + ->value($options['deadZone']) + ->rules("required|numrange[0,1]"); + ${"group_motion".$groupname}->input("decel".$groupname) + ->label(t("inertia (0.0-1.0 - 0.0 changes velocity instantly and 1.0 never changes)")." {decel}") + ->value($options['decel']) + ->rules("required|numrange[0,1]"); + ${"group_motion".$groupname}->input("initialX".$groupname) + ->label(t("initial horizontal speed (between +/-1.0, as fraction of max speed)")." {initial}") + ->value($options['initial'][0]) + ->rules("required|numrange[-1,1]"); + ${"group_motion".$groupname}->input("initialY".$groupname) + ->label(t("initial vertical speed (between +/-1.0, as fraction of max speed)")." {initial}") + ->value($options['initial'][1]) + ->rules("required|numrange[-1,1]"); + ${"group_motion".$groupname}->input("maxInputZone".$groupname) + ->label(t("mouseover region beyond cloud (as fraction of cloud - 0.0 is tight around cloud)")." {maxInputZone}") + ->value($options['maxInputZone']) + ->rules("required|numrange[0]"); + + // group select + ${"group_select".$groupname} = $form->group("select".$groupname)->label(t("Tag selection").$sep.$grouptext); + ${"group_select".$groupname}->dropdown("outlineMethod".$groupname) + ->label(t("change of display for selected tag")." {outlineMethod}") ->options(array("colour"=>t("change text color"),"outline"=>t("add outline around text"),"block"=>t("add block behind text"))) ->selected($options['outlineMethod']); - ${"group".$groupname}->input("outlineOffset".$groupname) - ->label(t($grouptext).$sep.t("outline offset (mouseover region size around text, in pixels)")) + ${"group_select".$groupname}->input("outlineOffset".$groupname) + ->label(t("mouseover region around tag text (in pixels - 0 is tight around text)")." {outlineOffset}") ->value($options['outlineOffset']) - ->error_message("not_valid", t("Outline offset must be a 1-2 digit number")) - ->rules("required|valid_numeric|length[1,2]"); - ${"group".$groupname}->input("outlineColour".$groupname) - ->label(t($grouptext).$sep.t("outline color (mouseover color, as #hhhhhh)")) + ->rules("required|numrange[0]"); + ${"group_select".$groupname}->input("outlineColour".$groupname) + ->label(t("color used for change of display (as #hhhhhh)")." {outlineColour}") ->value($options['outlineColour']) - ->error_message("not_valid", t("Outline color must be specified as #hhhhhh")) - ->rules("required|length[7]"); - ${"group".$groupname}->input("textColour".$groupname) - ->label(t($grouptext).$sep.t("text color (as #hhhhhh, or empty to use theme color)")) - ->value($options['textColour']) - ->error_message("not_valid", t("Text color must be specified as empty or #hhhhhh")) - ->rules("length[0,7]"); - ${"group".$groupname}->input("textFont".$groupname) - ->label(t($grouptext).$sep.t("text font family (empty to use theme font)")) - ->value($options['textFont']) - ->error_message("not_valid", t("Text font must be empty or a 0-40 character string")) - ->rules("length[0,40]"); - ${"group".$groupname}->input("textHeight".$groupname) - ->label(t($grouptext).$sep.t("text height (in pixels)")) - ->value($options['textHeight']) - ->error_message("not_valid", t("Text height must be a 1-2 digit number")) - ->rules("required|valid_numeric|length[1,2]"); - ${"group".$groupname}->checkbox("frontSelect".$groupname) - ->label(t($grouptext).$sep.t("only allow tags in front to be selected")) + ->rules('required|color'); + ${"group_select".$groupname}->checkbox("frontSelect".$groupname) + ->label(t("only allow tags in front to be selected")." {frontSelect}") ->checked($options['frontSelect']); - - } + // group appearance + ${"group_appearance".$groupname} = $form->group("appearance".$groupname)->label(t("Appearance").$sep.$grouptext); + ${"group_appearance".$groupname}->input("textHeight".$groupname) + ->label(t("text height (in pixels)")." {textHeight}") + ->value($options['textHeight']) + ->rules("required|numrange[0]"); + ${"group_appearance".$groupname}->input("textColour".$groupname) + ->label(t("text color (as #hhhhhh, or empty to use theme color)")." {textColour}") + ->value($options['textColour']) + ->rules('color'); + ${"group_appearance".$groupname}->input("textFont".$groupname) + ->label(t("text font family (empty to use theme font family)")." {textFont}") + ->value($options['textFont']) + ->rules("length[0,60]"); + ${"group_appearance".$groupname}->input("depth".$groupname) + ->label(t("depth/perspective of cloud (0.0-1.0 - 0.0 is none and >0.9 gets strange)")." {depth}") + ->value($options['depth']) + ->rules("required|numrange[0,1]"); + } $form->submit("")->value(t("Save")); return $form; diff --git a/3.0/modules/tag_cloud_html5/controllers/tag_cloud.php b/3.0/modules/tag_cloud_html5/controllers/tag_cloud.php index ce9e0147..05c2f5bb 100644 --- a/3.0/modules/tag_cloud_html5/controllers/tag_cloud.php +++ b/3.0/modules/tag_cloud_html5/controllers/tag_cloud.php @@ -26,6 +26,8 @@ class Tag_Cloud_Controller extends Controller { // Get settings $options = module::get_var("tag_cloud_html5", "options_wholecloud", null); $maxtags = module::get_var("tag_cloud_html5", "maxtags_wholecloud", null); + $width = module::get_var("tag_cloud_html5", "width_wholecloud", null); + $height = module::get_var("tag_cloud_html5", "height_wholecloud", null); $options = json_decode($options, true); $options['hideTags'] = !module::get_var("tag_cloud_html5", "show_wholecloud_list", true); @@ -37,8 +39,76 @@ class Tag_Cloud_Controller extends Controller { $template->content->title = t("Tag cloud"); $template->content->cloud = tag::cloud($maxtags); $template->content->options = $options; + $template->content->width = $width; + $template->content->height = $height; // Display the page. print $template; } -} + + public function embed() { + /** + * This is used to embed the tag cloud in other things. New in version 7. + * + * It expects the url to be in the form: + * tag_cloud/embed/optionsbase/option1/value1/option2/value2/.../optionN/valueN + * Where: + * optionsbase = "sidebar" or "wholecloud" (takes settings from this config) + * optionX = option name (either "maxtags" or any of the TagCanvas parameters - no name verification performed!) + * valueX = value of option (no value verification performed here!) + * Here's how the tag cloud is built: + * 1. Load "maxtags" and "options" variables for optionbase (as defined in admin menu or admin/advanced variables) + * Note: width and height are ignored, and the add tag form, wholecloud link, and inline tags are not shown. + * 2. Use option/value pairs to override and/or append those loaded above. + * 3. Build tag cloud, using 100% of the size from its parent. + * Correspondingly, the optionsbase is required, but the options and values are not. + */ + + // Require view permission for the root album for security purposes. + $album = ORM::factory("item", 1); + access::required("view", $album); + + // get the function arguments + $args = func_get_args(); + + // get/check the number of arguments - must be odd + $countargs = count($args); + if ($countargs % 2 == 0) { + return; + } + + // get/check the first argument - must be sidebar or wholecloud + $optionsbase = $args[0]; + if (!(in_array($optionsbase, array("sidebar", "wholecloud")))) { + return; + } + + // get and override/append options/values + $maxtags = module::get_var("tag_cloud_html5", "maxtags_".$optionsbase, null); + $options = module::get_var("tag_cloud_html5", "options_".$optionsbase, null); + $options = json_decode($options, true); + for ($i = 0; $i < ($countargs-1)/2; $i++) { + $option = $args[2*$i+1]; + $value = $args[2*$i+2]; + if ($option == "maxtags") { + // assign to maxtags + $maxtags = $value; + } elseif (substr($option,-6) == 'Colour') { + // assign to options with a hash in front + $options[$option] = '#'.$value; + } else { + // assign to options + $options[$option] = $value; + } + } + $options = json_encode($options); + + // Set up and display the actual page. + $template = new View("tag_cloud_html5_embed.html"); + $template->cloud = tag::cloud($maxtags); + $template->options = $options; + + // Display the page. + print $template; + } +} \ No newline at end of file diff --git a/3.0/modules/tag_cloud_html5/css/admin_tag_cloud_html5.css b/3.0/modules/tag_cloud_html5/css/admin_tag_cloud_html5.css index 28afb51f..e87717f1 100644 --- a/3.0/modules/tag_cloud_html5/css/admin_tag_cloud_html5.css +++ b/3.0/modules/tag_cloud_html5/css/admin_tag_cloud_html5.css @@ -1,30 +1,17 @@ -#g-content fieldset li { +#g-content fieldset { display: block; +} +#g-content fieldset.g-tag-cloud-html5-admin-form-top { + width: 80%; clear: both; - height: 24px; } -#g-content fieldset input { - display: inline; +#g-content fieldset.g-tag-cloud-html5-admin-form-left { + width: 45%; float: left; - height: 18px; - margin-right: 0.8em; - width: 250px; + clear: left; + margin-right: 2% } -#g-content fieldset select { - display: inline; - float: left; - height: 24px; - margin-right: 0.8em; - width: 256px; -} -#g-content fieldset label { - display: inline; - line-height: 24px; -} -#g-content fieldset label input.checkbox { - float: left; - height: 24px; - margin-right: 0.8em; - width: 20px; - margin-left: 236px; +#g-content fieldset.g-tag-cloud-html5-admin-form-right { + width: 45%; + clear: right; } \ No newline at end of file diff --git a/3.0/modules/tag_cloud_html5/helpers/tag_cloud_html5_block.php b/3.0/modules/tag_cloud_html5/helpers/tag_cloud_html5_block.php index e1df9264..27da5439 100644 --- a/3.0/modules/tag_cloud_html5/helpers/tag_cloud_html5_block.php +++ b/3.0/modules/tag_cloud_html5/helpers/tag_cloud_html5_block.php @@ -32,6 +32,7 @@ class tag_cloud_html5_block { $maxtags = module::get_var("tag_cloud_html5", "maxtags_sidebar", null); $showlink = module::get_var("tag_cloud_html5", "show_wholecloud_link", null); $showaddtag = module::get_var("tag_cloud_html5", "show_add_tag_form", null); + $width = module::get_var("tag_cloud_html5", "width_sidebar", null); $height = module::get_var("tag_cloud_html5", "height_sidebar", null); // make the block @@ -41,6 +42,7 @@ class tag_cloud_html5_block { $block->content = new View("tag_cloud_html5_block.html"); $block->content->cloud = tag::cloud($maxtags); $block->content->options = $options; + $block->content->width = $width; $block->content->height = $height; // add the 'View whole cloud' link if needed diff --git a/3.0/modules/tag_cloud_html5/helpers/tag_cloud_html5_installer.php b/3.0/modules/tag_cloud_html5/helpers/tag_cloud_html5_installer.php index 422a6f2c..fa2fc678 100644 --- a/3.0/modules/tag_cloud_html5/helpers/tag_cloud_html5_installer.php +++ b/3.0/modules/tag_cloud_html5/helpers/tag_cloud_html5_installer.php @@ -22,12 +22,19 @@ class tag_cloud_html5_installer { // clear and reset default values. this is also called in the admin menu for // 'reset all to default values' and if the upgrader sees variables missing. module::clear_all_vars("tag_cloud_html5"); + module::set_var("tag_cloud_html5", "show_wholecloud_link", true); module::set_var("tag_cloud_html5", "show_add_tag_form", true); module::set_var("tag_cloud_html5", "show_wholecloud_list", true); - module::set_var("tag_cloud_html5", "height_sidebar", 0.8); + module::set_var("tag_cloud_html5", "maxtags_sidebar", 30); + module::set_var("tag_cloud_html5", "width_sidebar", 1.00); + module::set_var("tag_cloud_html5", "height_sidebar", 0.8); + module::set_var("tag_cloud_html5", "maxtags_wholecloud", 500); + module::set_var("tag_cloud_html5", "width_wholecloud", 0.95); + module::set_var("tag_cloud_html5", "height_wholecloud", 0.75); + module::set_var("tag_cloud_html5", "options_sidebar", json_encode(array( "maxSpeed" => 0.05, "deadZone" => 0.25, @@ -42,8 +49,17 @@ class tag_cloud_html5_installer { "textFont" => "", "textHeight" => 12, "frontSelect" => true, - "wheelZoom" => false + "wheelZoom" => false, + "shape" => "sphere", + "lock" => "", + "stretchX" => 1.0, + "stretchY" => 1.0, + "decel" => 0.92, + "physModel" => true, + "maxInputZone" => 0.25, + "minSpeed" => 0.002 ))); + module::set_var("tag_cloud_html5", "options_wholecloud", json_encode(array( "maxSpeed" => 0.05, "deadZone" => 0.25, @@ -58,17 +74,100 @@ class tag_cloud_html5_installer { "textFont" => "", "textHeight" => 13, "frontSelect" => true, - "wheelZoom" => false + "wheelZoom" => false, + "shape" => "sphere", + "lock" => "", + "stretchX" => 1.0, + "stretchY" => 1.0, + "decel" => 0.92, + "physModel" => true, + "maxInputZone" => 0.15, + "minSpeed" => 0.002 ))); - module::set_version("tag_cloud_html5", 4); + + module::set_version("tag_cloud_html5", 7); } static function upgrade() { if (is_null(module::get_var("tag_cloud_html5", "options_sidebar")) || is_null(module::get_var("tag_cloud_html5", "options_wholecloud")) || - (module::get_version("tag_cloud_html5") < 4) ) { + (module::get_version("tag_cloud_html5") < 1) ) { + module::install("tag_cloud_html5"); } + if (module::get_version("tag_cloud_html5") < 2) { + // added wheelZoom, which is not accessible from admin menu + $options = json_decode(module::get_var("tag_cloud_html5", "options_sidebar"),true); + $options["wheelZoom"] = false; + module::set_var("tag_cloud_html5", "options_sidebar", json_encode($options)); + + $options = json_decode(module::get_var("tag_cloud_html5", "options_wholecloud"),true); + $options["wheelZoom"] = false; + module::set_var("tag_cloud_html5", "options_wholecloud", json_encode($options)); + } + if (module::get_version("tag_cloud_html5") < 3) { + // added deadZone, initial, and initialDecel + + module::set_var("tag_cloud_html5", "show_add_tag_form", true); + + $options = json_decode(module::get_var("tag_cloud_html5", "options_sidebar"),true); + $options["deadZone"] = 0.25; + $options["initial"] = array(0.8,-0.3); + $options["initialDecel"] = true; + module::set_var("tag_cloud_html5", "options_sidebar", json_encode($options)); + + $options = json_decode(module::get_var("tag_cloud_html5", "options_wholecloud"),true); + $options["deadZone"] = 0.25; + $options["initial"] = array(0.8,-0.3); + $options["initialDecel"] = true; + module::set_var("tag_cloud_html5", "options_wholecloud", json_encode($options)); + } + if (module::get_version("tag_cloud_html5") < 4) { + // added height_sidebar, then scaled back zoom and textHeight for consistency + module::set_var("tag_cloud_html5", "height_sidebar", 0.8); + + $options = json_decode(module::get_var("tag_cloud_html5", "options_sidebar"),true); + $options["zoom"] = $options["zoom"] / 0.8; + $options["textHeight"] = $options["textHeight"] * 0.8; + module::set_var("tag_cloud_html5", "options_sidebar", json_encode($options)); + } + if (module::get_version("tag_cloud_html5") < 5) { + // added lots of options that are on admin menu + // added physModel, lock, and initialDecel as options not on admin menu + // (previously initialDecel was on menu, so reset here) + + module::set_var("tag_cloud_html5", "width_sidebar", 1.00); + module::set_var("tag_cloud_html5", "width_wholecloud", 0.95); + module::set_var("tag_cloud_html5", "height_wholecloud", 0.75); + + $options = json_decode(module::get_var("tag_cloud_html5", "options_sidebar"),true); + $options["deadZone"] = $options["deadZone"]; + $options["shape"] = "sphere"; + $options["lock"] = ""; + $options["stretchX"] = 1.0; + $options["stretchY"] = 1.0; + $options["decel"] = 0.92; + $options["physModel"] = true; + $options["maxInputZone"] = 0.25; + $options["minSpeed"] = 0.002; + $options["initialDecel"] = true; + module::set_var("tag_cloud_html5", "options_sidebar", json_encode($options)); + + $options = json_decode(module::get_var("tag_cloud_html5", "options_wholecloud"),true); + $options["deadZone"] = $options["deadZone"]; + $options["shape"] = "sphere"; + $options["lock"] = ""; + $options["stretchX"] = 1.0; + $options["stretchY"] = 1.0; + $options["decel"] = 0.92; + $options["physModel"] = true; + $options["maxInputZone"] = 0.15; + $options["minSpeed"] = 0.002; + $options["initialDecel"] = true; + module::set_var("tag_cloud_html5", "options_wholecloud", json_encode($options)); + } + // note: there are no variable changes for v6 and v7 upgrades + module::set_version("tag_cloud_html5", 7); } static function uninstall() { 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/js/jquery.tagcanvas.mod.min.js b/3.0/modules/tag_cloud_html5/js/jquery.tagcanvas.mod.min.js index 44bf1876..b4f0191b 100644 --- a/3.0/modules/tag_cloud_html5/js/jquery.tagcanvas.mod.min.js +++ b/3.0/modules/tag_cloud_html5/js/jquery.tagcanvas.mod.min.js @@ -1,27 +1,30 @@ -/** - * 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/01 -- all modified lines have "mod Shad Laws" comments - * - included initialDecel and deadZone as options - * - set defaults of new options to mimic behavior without them (false and 0) - * - removed two unnecessary variable declarations caught by YUI Compressor - */ -(function(I){var R,Q,G=Math.abs,r=Math.sin,h=Math.cos,z=Math.max,V=Math.min,B={},C={},D={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,"},e,J,d,l=document,y,c={};for(R=0;R<256;++R){Q=R.toString(16);if(R<16){Q="0"+Q}C[Q]=C[Q.toUpperCase()]=R.toString()+","}function N(i){return typeof(i)!="undefined"}function H(j){var Y=j.length-1,X,Z;while(Y){Z=~~(Math.random()*Y);X=j[Y];j[Y]=j[Z];j[Z]=X;--Y}}function n(Y,aa,af,ac){var ab,ae,j,ad,ag=[],Z=Math.PI*(3-Math.sqrt(5)),X=2/Y;for(ab=0;ab0)}function W(ae,j){var X=1024,aa=ae.weightGradient,Z,ac,Y,ad,ab;if(ae.gCanvas){ac=ae.gCanvas.getContext("2d")}else{ae.gCanvas=Z=g(X,1);if(!Z){return null}ac=Z.getContext("2d");ad=ac.createLinearGradient(0,0,X,0);for(Y in aa){ad.addColorStop(1-Y,aa[Y])}ac.fillStyle=ad;ac.fillRect(0,0,X,1)}ab=ac.getImageData(~~((X-1)*j),0,1,1).data;return"rgba("+ab[0]+","+ab[1]+","+ab[2]+","+(ab[3]/255)+")"}function u(aa,Z,X,ad,ab,ac,j){var Y=(ac||0)+(j&&j[0]<0?G(j[0]):0),i=(ac||0)+(j&&j[1]<0?G(j[1]):0);aa.font=Z;aa.textBaseline="top";aa.fillStyle=X;ab&&(aa.shadowColor=ab);ac&&(aa.shadowBlur=ac);j&&(aa.shadowOffsetX=j[0],aa.shadowOffsetY=j[1]);aa.fillText(ad,Y,i)}function m(aj,ab,af,ah,aa,X,ad,ae,j,ai,ag){var Y=ah+G(j[0])+ae+ae,i=aa+G(j[1])+ae+ae,Z,ac;Z=g(Y+ai,i+ag);if(!Z){return null}ac=Z.getContext("2d");u(ac,ab,X,aj,ad,ae,j);return Z}function P(ab,ae,af,Y){var Z=ab.width+G(Y[0])+af+af,j=ab.height+G(Y[1])+af+af,ac,ad,aa=(af||0)+(Y&&Y[0]<0?G(Y[0]):0),X=(af||0)+(Y&&Y[1]<0?G(Y[1]):0);ac=g(Z,j);if(!ac){return null}ad=ac.getContext("2d");ae&&(ad.shadowColor=ae);af&&(ad.shadowBlur=af);Y&&(ad.shadowOffsetX=Y[0],ad.shadowOffsetY=Y[1]);ad.drawImage(ab,aa,X);return ac}function K(aj,ab,ah){var ai=parseInt(aj.length*ah),aa=parseInt(ah*2),Y=g(ai,aa),ae,j,Z,ad,ag,af,X,ac;if(!Y){return null}ae=Y.getContext("2d");ae.fillStyle="#000";ae.fillRect(0,0,ai,aa);u(ae,ah+"px "+ab,"#fff",aj);j=ae.getImageData(0,0,ai,aa);Z=j.width;ad=j.height;ac={min:{x:Z,y:ad},max:{x:-1,y:-1}};for(af=0;af0){if(agac.max.x){ac.max.x=ag}if(afac.max.y){ac.max.y=af}}}}if(Z!=ai){ac.min.x*=(ai/Z);ac.max.x*=(ai/Z)}if(ad!=aa){ac.min.y*=(ai/ad);ac.max.y*=(ai/ad)}Y=null;return ac}function t(i){return"'"+i.replace(/(\'|\")/g,"").replace(/\s*,\s*/g,"', '")+"'"}function A(i,j,X){X=X||l;if(X.addEventListener){X.addEventListener(i,j,false)}else{X.attachEvent("on"+i,j)}}function O(Z,ab,Y,j){var X=j.taglist,aa=j.imageScale;if(aa&&!(ab.width&&ab.height)){A("load",function(){O(Z,ab,Y,j)},window);return}if(!Z.complete){A("load",function(){O(Z,ab,Y,j)},Z);return}ab.width=ab.width;ab.height=ab.height;if(aa){Z.width=ab.width*aa;Z.height=ab.height*aa}Y.w=Z.width;Y.h=Z.height;X.push(Y)}function M(Y,X){var j=l.defaultView,i=X.replace(/\-([a-z])/g,function(Z){return Z.charAt(1).toUpperCase()});return(j&&j.getComputedStyle&&j.getComputedStyle(Y,null).getPropertyValue(X))||(Y.currentStyle&&Y.currentStyle[i])}function x(X,j){var i=1,Y;if(X.weightFrom){i=1*(j.getAttribute(X.weightFrom)||X.textHeight)}else{if(Y=M(j,"font-size")){i=(Y.indexOf("px")>-1&&Y.replace("px","")*1)||(Y.indexOf("pt")>-1&&Y.replace("pt","")*1.25)||Y*3.3}else{X.weight=false}}return i}function k(X){L(X);var j=X.target||X.fromElement.parentNode,i=s.tc[j.id];i&&(i.mx=i.my=-1)}function L(Z){var Y,X,j=l.documentElement,aa;for(Y in s.tc){X=s.tc[Y];if(X.tttimer){clearTimeout(X.tttimer);X.tttimer=null}aa=I(X.canvas).offset();if(Z.pageX){X.mx=Z.pageX-aa.left;X.my=Z.pageY-aa.top}else{X.mx=Z.clientX+(j.scrollLeft||l.body.scrollLeft)-aa.left;X.my=Z.clientY+(j.scrollTop||l.body.scrollTop)-aa.top}}}function q(Y){var j=s,i=l.addEventListener?0:1,X=Y.target&&N(Y.target.id)?Y.target.id:Y.srcElement.parentNode.id;if(X&&Y.button==i&&j.tc[X]){L(Y);j.tc[X].Clicked(Y)}}function T(X){var i=s,j=X.target&&N(X.target.id)?X.target.id:X.srcElement.parentNode.id;if(j&&i.tc[j]){X.cancelBubble=true;X.returnValue=false;X.preventDefault&&X.preventDefault();i.tc[j].Wheel((X.wheelDelta||X.detail)>0)}}function o(){var X=s.tc,j;for(j in X){X[j].Draw()}}function b(X,i){var j=r(i),Y=h(i);return{x:X.x,y:(X.y*Y)+(X.z*j),z:(X.y*-j)+(X.z*Y)}}function a(X,i){var j=r(i),Y=h(i);return{x:(X.x*Y)+(X.z*-j),y:X.y,z:(X.x*j)+(X.z*Y)}}function S(X,ae,ad,Z,ac,aa){var i,Y,ab,j=X.z1/(X.z1+X.z2+ae.z);i=ae.y*j*aa;Y=ae.x*j*ac;ab=X.z2+ae.z;return{x:Y,y:i,z:ab}}function f(i){this.ts=new Date().valueOf();this.tc=i;this.x=this.y=this.w=this.h=this.sc=1;this.z=0;this.Draw=i.pulsateTo<1&&i.outlineMethod!="colour"?this.DrawPulsate:this.DrawSimple;this.SetMethod(i.outlineMethod)}e=f.prototype;e.SetMethod=function(X){var j={block:["PreDraw","DrawBlock"],colour:["PreDraw","DrawColour"],outline:["PostDraw","DrawOutline"],classic:["LastDraw","DrawOutline"],none:["LastDraw"]},i=j[X]||j.outline;if(X=="none"){this.Draw=function(){return 1}}else{this.drawFunc=this[i[1]]}this[i[0]]=this.Draw};e.Update=function(ad,ac,ae,aa,ab,j,Z,i){var X=this.tc.outlineOffset,Y=2*X;this.x=ab*ad+Z-X;this.y=ab*ac+i-X;this.w=ab*ae+Y;this.h=ab*aa+Y;this.sc=ab;this.z=j.z};e.DrawOutline=function(aa,i,Z,j,X,Y){aa.strokeStyle=Y;aa.strokeRect(i,Z,j,X)};e.DrawColour=function(Y,ab,Z,ac,X,i,ad,j,aa){return this[ad.image?"DrawColourImage":"DrawColourText"](Y,ab,Z,ac,X,i,ad,j,aa)};e.DrawColourText=function(Z,ac,aa,ad,X,i,ae,j,ab){var Y=ae.colour;ae.colour=i;ae.Draw(Z,j,ab);ae.colour=Y;return 1};e.DrawColourImage=function(ac,af,ad,ag,ab,i,aj,j,ae){var ah=ac.canvas,Z=~~z(af,0),Y=~~z(ad,0),aa=V(ah.width-Z,ag)+0.5|0,ai=V(ah.height-Y,ab)+0.5|0,X;if(y){y.width=aa,y.height=ai}else{y=g(aa,ai)}if(!y){return this.SetMethod("outline")}X=y.getContext("2d");X.drawImage(ah,Z,Y,aa,ai,0,0,aa,ai);ac.clearRect(Z,Y,aa,ai);aj.Draw(ac,j,ae);ac.setTransform(1,0,0,1,0,0);ac.save();ac.beginPath();ac.rect(Z,Y,aa,ai);ac.clip();ac.globalCompositeOperation="source-in";ac.fillStyle=i;ac.fillRect(Z,Y,aa,ai);ac.restore();ac.globalCompositeOperation="destination-over";ac.drawImage(y,0,0,aa,ai,Z,Y,aa,ai);ac.globalCompositeOperation="source-over";return 1};e.DrawBlock=function(aa,i,Z,j,X,Y){aa.fillStyle=Y;aa.fillRect(i,Z,j,X)};e.DrawSimple=function(Z,i,j,Y){var X=this.tc;Z.setTransform(1,0,0,1,0,0);Z.strokeStyle=X.outlineColour;Z.lineWidth=X.outlineThickness;Z.shadowBlur=Z.shadowOffsetX=Z.shadowOffsetY=0;Z.globalAlpha=1;return this.drawFunc(Z,this.x,this.y,this.w,this.h,X.outlineColour,i,j,Y)};e.DrawPulsate=function(aa,i,j,Y){var Z=new Date().valueOf()-this.ts,X=this.tc;aa.setTransform(1,0,0,1,0,0);aa.strokeStyle=X.outlineColour;aa.lineWidth=X.outlineThickness;aa.shadowBlur=aa.shadowOffsetX=aa.shadowOffsetY=0;aa.globalAlpha=X.pulsateTo+((1-X.pulsateTo)*(0.5+(h(2*Math.PI*Z/(1000*X.pulsateTime))/2)));return this.drawFunc(aa,this.x,this.y,this.w,this.h,X.outlineColour,i,j,Y)};e.Active=function(X,i,j){return(i>=this.x&&j>=this.y&&i<=this.x+this.w&&j<=this.y+this.h)};e.PreDraw=e.PostDraw=e.LastDraw=function(){};function E(Z,j,ad,af,ae,ab,X,Y){var ac=Z.ctxt,aa;this.tc=Z;this.image=j.src?j:null;this.name=j.src?"":j;this.title=ad.title||null;this.a=ad;this.p3d={x:af[0]*Z.radius*1.1,y:af[1]*Z.radius*1.1,z:af[2]*Z.radius*1.1};this.x=this.y=0;this.w=ae;this.h=ab;this.colour=X||Z.textColour;this.textFont=Y||Z.textFont;this.weight=this.sc=this.alpha=1;this.weighted=!Z.weight;this.outline=new f(Z);if(this.image){if(Z.txtOpt&&Z.shadow){aa=P(this.image,Z.shadow,Z.shadowBlur,Z.shadowOffset);if(aa){this.image=aa;this.w=aa.width;this.h=aa.height}}}else{this.textHeight=Z.textHeight;this.extents=K(this.name,this.textFont,this.textHeight);this.Measure(ac,Z)}this.SetShadowColour=Z.shadowAlpha?this.SetShadowColourAlpha:this.SetShadowColourFixed;this.SetDraw(Z)}J=E.prototype;J.SetDraw=function(i){this.Draw=this.image?(i.ie>7?this.DrawImageIE:this.DrawImage):this.DrawText;i.noSelect&&(this.CheckActive=function(){})};J.Measure=function(ab,j){this.h=this.extents?this.extents.max.y+this.extents.min.y:this.textHeight;ab.font=this.font=this.textHeight+"px "+this.textFont;this.w=ab.measureText(this.name).width;if(j.txtOpt){var Y=j.txtScale,Z=Y*this.textHeight,aa=Z+"px "+this.textFont,X=[Y*j.shadowOffset[0],Y*j.shadowOffset[1]],i;ab.font=aa;i=ab.measureText(this.name).width;this.image=m(this.name,aa,Z,i,Y*this.h,this.colour,j.shadow,Y*j.shadowBlur,X,Y,Y);if(this.image){this.w=this.image.width/Y;this.h=this.image.height/Y}this.SetDraw(j);j.txtOpt=this.image}};J.SetWeight=function(i){if(!this.name.length){return}this.weight=i;this.Weight(this.tc.ctxt,this.tc);this.Measure(this.tc.ctxt,this.tc)};J.Weight=function(Y,X){var j=this.weight,i=X.weightMode;this.weighted=true;if(i=="colour"||i=="both"){this.colour=W(X,(j-X.min_weight)/(X.max_weight-X.min_weight))}if(i=="size"||i=="both"){this.textHeight=j*X.weightSize}this.extents=K(this.name,this.textFont,this.textHeight)};J.SetShadowColourFixed=function(X,j,i){X.shadowColor=j};J.SetShadowColourAlpha=function(X,j,i){X.shadowColor=p(j,i)};J.DrawText=function(X,ab,j){var ac=this.tc,Z=this.x,Y=this.y,aa,i,ad=this.sc;X.globalAlpha=this.alpha;X.setTransform(ad,0,0,ad,0,0);X.fillStyle=this.colour;ac.shadow&&this.SetShadowColour(X,ac.shadow,this.alpha);X.font=this.font;aa=this.w;i=this.h;Z+=(ab/ad)-(aa/2);Y+=(j/ad)-(i/2);X.fillText(this.name,Z,Y)};J.DrawImage=function(Z,af,Y){var ac=this.x,aa=this.y,ag=this.sc,j=this.image,ad=this.w,X=this.h,ab=this.alpha,ae=this.shadow;Z.globalAlpha=ab;Z.setTransform(ag,0,0,ag,0,0);Z.fillStyle=this.colour;ae&&this.SetShadowColour(Z,ae,ab);ac+=(af/ag)-(ad/2);aa+=(Y/ag)-(X/2);Z.drawImage(j,ac,aa,ad,X)};J.DrawImageIE=function(Z,ad,Y){var j=this.image,ae=this.sc,ac=j.width=this.w*ae,X=j.height=this.h*ae,ab=(this.x*ae)+ad-(ac/2),aa=(this.y*ae)+Y-(X/2);Z.setTransform(1,0,0,1,0,0);Z.globalAlpha=this.alpha;Z.drawImage(j,ab,aa)};J.Calc=function(Z,Y){var i=a(this.p3d,Z),j=this.tc,aa=j.minBrightness,X=j.radius;this.p3d=b(i,Y);i=S(j,this.p3d,this.w,this.h,j.stretchX,j.stretchY);this.x=i.x;this.y=i.y;this.sc=(j.z1+j.z2-i.z)/j.z2;this.alpha=z(aa,V(1,aa+1-((i.z-j.z2+X)/(2*X))))};J.CheckActive=function(Y,ac,X){var ad=this.tc,i=this.outline,ab=this.w,j=this.h,aa=this.x-ab/2,Z=this.y-j/2;i.Update(aa,Z,ab,j,this.sc,this.p3d,ac,X);return i.Active(Y,ad.mx,ad.my)?i:null};J.Clicked=function(aa){var j=this.a,X=j.target,Y=j.href,i;if(X!=""&&X!="_self"){if(self.frames[X]){self.frames[X]=Y}else{try{if(top.frames[X]){top.frames[X]=Y;return}}catch(Z){}window.open(Y,X)}return}if(l.createEvent){i=l.createEvent("MouseEvents");i.initMouseEvent("click",1,1,window,0,0,0,0,0,0,0,0,0,0,null);if(!j.dispatchEvent(i)){return}}else{if(j.fireEvent){if(!j.fireEvent("onclick")){return}}}l.location=Y};function s(){var j,X={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,deadZone:0,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(j in X){this[j]=X[j]}this.max_weight=0;this.min_weight=200}d=s.prototype;d.Draw=function(){var ag=this.canvas,ae=ag.width,X=ag.height,j=0,ad=this.yaw,Y=this.pitch,Z=ae/2,aj=X/2,ah=this.ctxt,ab,ai,af,ac=-1,al=this.taglist,aa=al.length,ak=this.frontSelect;if(ad==0&&Y==0&&this.drawn&&!this.deadZoneActive){return this.Animate(ae,X)}ah.setTransform(1,0,0,1,0,0);this.active=null;for(af=0;af=0&&this.my>=0&&al[af].CheckActive(ah,Z,aj);if(ai&&ai.sc>j&&(!ak||ai.z<=0)){ab=ai;ab.index=ac=af;j=ai.sc}}this.active=ab;if(!this.txtOpt&&this.shadow){ah.shadowBlur=this.shadowBlur;ah.shadowOffsetX=this.shadowOffset[0];ah.shadowOffsetY=this.shadowOffset[1]}ah.clearRect(0,0,ae,X);for(af=0;af=0&&aa>=0&&abae){this.yaw=ad>X.z0?X.yaw*X.decel:0}if(j!="y"&&Y>ae){this.pitch=Y>X.z0?X.pitch*X.decel:0}}}};d.Zoom=function(i){this.z2=this.z1*(1/i);this.drawn=0};d.Clicked=function(Y){var X=this.taglist,i=this.active;try{if(i&&X[i.index]){X[i.index].Clicked(Y)}}catch(j){}};d.Wheel=function(j){var X=this.zoom+this.zoomStep*(j?1:-1);this.zoom=V(this.zoomMax,z(this.zoomMin,X));this.Zoom(this.zoom)};s.tc={};jQuery.fn.tagcanvas=function(X,j){var i,Y=j?jQuery("#"+j):this;if(l.all&&!j){return false}i=Y.find("a");if(N(window.G_vmlCanvasManager)){this.each(function(){I(this)[0]=window.G_vmlCanvasManager.initElement(I(this)[0])});X.ie=parseFloat(navigator.appVersion.split("MSIE")[1])}if(!i.length||!this[0].getContext||!this[0].getContext("2d").fillText){return false}this.each(function(){var ab,Z,ad,ag,ah,ac,af,ae=[],aa={sphere:n,vcylinder:w,hcylinder:F};j||(i=I(this).find("a"));ac=new s;for(ab in X){ac[ab]=X[ab]}ac.z1=(19800/(Math.exp(ac.depth)*(1-1/Math.E)))+20000-19800/(1-(1/Math.E));ac.z2=ac.z1*(1/ac.zoom);ac.radius=(this.height>this.width?this.width:this.height)*0.33*(ac.z2+ac.z1)/(ac.z1);ac.yaw=ac.initial?ac.initial[0]*ac.maxSpeed:0;ac.pitch=ac.initial?ac.initial[1]*ac.maxSpeed:0;ac.canvas=I(this)[0];ac.ctxt=ac.canvas.getContext("2d");ac.textFont=ac.textFont&&t(ac.textFont);ac.deadZone*=1;ac.pulsateTo*=1;ac.textHeight*=1;ac.minBrightness*=1;ac.ctxt.textBaseline="top";if(ac.shadowBlur||ac.shadowOffset[0]||ac.shadowOffset[1]){ac.ctxt.shadowColor=ac.shadow;ac.shadow=ac.ctxt.shadowColor;ac.shadowAlpha=v()}else{delete ac.shadow}ac.taglist=[];ac.shape=aa[ac.shape]||aa.sphere;Z=ac.shape(i.length,ac.radiusX,ac.radiusY,ac.radiusZ);ac.shuffleTags&&H(Z);ac.listLength=i.length;for(ab=0;abac.max_weight){ac.max_weight=af}if(afac.min_weight)){for(ab=0;ab. + */ +/** + * 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(I){var S,R,G=Math.abs,r=Math.sin,h=Math.cos,z=Math.max,W=Math.min,M=Math.sqrt,B={},C={},D={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,"},e,J,d,l=document,y,c={};for(S=0;S<256;++S){R=S.toString(16);if(S<16){R="0"+R}C[R]=C[R.toUpperCase()]=S.toString()+","}function O(i){return typeof(i)!="undefined"}function H(j){var Z=j.length-1,Y,aa;while(Z){aa=~~(Math.random()*Z);Y=j[Z];j[Z]=j[aa];j[aa]=Y;--Z}}function n(Z,ab,ag,ad){var ac,af,j,ae,ah=[],aa=Math.PI*(3-Math.sqrt(5)),Y=2/Z;for(ac=0;ac0)}function X(af,j){var Y=1024,ab=af.weightGradient,aa,ad,Z,ae,ac;if(af.gCanvas){ad=af.gCanvas.getContext("2d")}else{af.gCanvas=aa=g(Y,1);if(!aa){return null}ad=aa.getContext("2d");ae=ad.createLinearGradient(0,0,Y,0);for(Z in ab){ae.addColorStop(1-Z,ab[Z])}ad.fillStyle=ae;ad.fillRect(0,0,Y,1)}ac=ad.getImageData(~~((Y-1)*j),0,1,1).data;return"rgba("+ac[0]+","+ac[1]+","+ac[2]+","+(ac[3]/255)+")"}function u(ab,aa,Y,ae,ac,ad,j){var Z=(ad||0)+(j&&j[0]<0?G(j[0]):0),i=(ad||0)+(j&&j[1]<0?G(j[1]):0);ab.font=aa;ab.textBaseline="top";ab.fillStyle=Y;ac&&(ab.shadowColor=ac);ad&&(ab.shadowBlur=ad);j&&(ab.shadowOffsetX=j[0],ab.shadowOffsetY=j[1]);ab.fillText(ae,Z,i)}function m(ak,ac,ag,ai,ab,Y,ae,af,j,aj,ah){var Z=ai+G(j[0])+af+af,i=ab+G(j[1])+af+af,aa,ad;aa=g(Z+aj,i+ah);if(!aa){return null}ad=aa.getContext("2d");u(ad,ac,Y,ak,ae,af,j);return aa}function Q(ac,af,ag,Z){var aa=ac.width+G(Z[0])+ag+ag,j=ac.height+G(Z[1])+ag+ag,ad,ae,ab=(ag||0)+(Z&&Z[0]<0?G(Z[0]):0),Y=(ag||0)+(Z&&Z[1]<0?G(Z[1]):0);ad=g(aa,j);if(!ad){return null}ae=ad.getContext("2d");af&&(ae.shadowColor=af);ag&&(ae.shadowBlur=ag);Z&&(ae.shadowOffsetX=Z[0],ae.shadowOffsetY=Z[1]);ae.drawImage(ac,ab,Y);return ad}function K(ak,ac,ai){var aj=parseInt(ak.length*ai),ab=parseInt(ai*2),Z=g(aj,ab),af,j,aa,ae,ah,ag,Y,ad;if(!Z){return null}af=Z.getContext("2d");af.fillStyle="#000";af.fillRect(0,0,aj,ab);u(af,ai+"px "+ac,"#fff",ak);j=af.getImageData(0,0,aj,ab);aa=j.width;ae=j.height;ad={min:{x:aa,y:ae},max:{x:-1,y:-1}};for(ag=0;ag0){if(ahad.max.x){ad.max.x=ah}if(agad.max.y){ad.max.y=ag}}}}if(aa!=aj){ad.min.x*=(aj/aa);ad.max.x*=(aj/aa)}if(ae!=ab){ad.min.y*=(aj/ae);ad.max.y*=(aj/ae)}Z=null;return ad}function t(i){return"'"+i.replace(/(\'|\")/g,"").replace(/\s*,\s*/g,"', '")+"'"}function A(i,j,Y){Y=Y||l;if(Y.addEventListener){Y.addEventListener(i,j,false)}else{Y.attachEvent("on"+i,j)}}function P(aa,ac,Z,j){var Y=j.taglist,ab=j.imageScale;if(ab&&!(ac.width&&ac.height)){A("load",function(){P(aa,ac,Z,j)},window);return}if(!aa.complete){A("load",function(){P(aa,ac,Z,j)},aa);return}ac.width=ac.width;ac.height=ac.height;if(ab){aa.width=ac.width*ab;aa.height=ac.height*ab}Z.w=aa.width;Z.h=aa.height;Y.push(Z)}function N(Z,Y){var j=l.defaultView,i=Y.replace(/\-([a-z])/g,function(aa){return aa.charAt(1).toUpperCase()});return(j&&j.getComputedStyle&&j.getComputedStyle(Z,null).getPropertyValue(Y))||(Z.currentStyle&&Z.currentStyle[i])}function x(Y,j){var i=1,Z;if(Y.weightFrom){i=1*(j.getAttribute(Y.weightFrom)||Y.textHeight)}else{if(Z=N(j,"font-size")){i=(Z.indexOf("px")>-1&&Z.replace("px","")*1)||(Z.indexOf("pt")>-1&&Z.replace("pt","")*1.25)||Z*3.3}else{Y.weight=false}}return i}function k(Y){L(Y);var j=Y.target||Y.fromElement.parentNode,i=s.tc[j.id];i&&(i.mx=i.my=-1)}function L(aa){var Z,Y,j=l.documentElement,ab;for(Z in s.tc){Y=s.tc[Z];if(Y.tttimer){clearTimeout(Y.tttimer);Y.tttimer=null}ab=I(Y.canvas).offset();if(aa.offsetX){Y.mx=aa.offsetX;Y.my=aa.offsetY}else{if(aa.pageX){Y.mx=aa.pageX-ab.left;Y.my=aa.pageY-ab.top}else{Y.mx=aa.clientX+(j.scrollLeft||l.body.scrollLeft)-ab.left;Y.my=aa.clientY+(j.scrollTop||l.body.scrollTop)-ab.top}}}}function q(Z){var j=s,i=l.addEventListener?0:1,Y=Z.target&&O(Z.target.id)?Z.target.id:Z.srcElement.parentNode.id;if(Y&&Z.button==i&&j.tc[Y]){L(Z);j.tc[Y].Clicked(Z)}}function U(Y){var i=s,j=Y.target&&O(Y.target.id)?Y.target.id:Y.srcElement.parentNode.id;if(j&&i.tc[j]){Y.cancelBubble=true;Y.returnValue=false;Y.preventDefault&&Y.preventDefault();i.tc[j].Wheel((Y.wheelDelta||Y.detail)>0)}}function o(){var Y=s.tc,j;for(j in Y){Y[j].Draw()}}function b(Y,i){var j=r(i),Z=h(i);return{x:Y.x,y:(Y.y*Z)+(Y.z*j),z:(Y.y*-j)+(Y.z*Z)}}function a(Y,i){var j=r(i),Z=h(i);return{x:(Y.x*Z)+(Y.z*-j),y:Y.y,z:(Y.x*j)+(Y.z*Z)}}function T(Y,af,ae,aa,ad,ab){var i,Z,ac,j=Y.z1/(Y.z1+Y.z2+af.z);i=af.y*j*ab;Z=af.x*j*ad;ac=Y.z2+af.z;return{x:Z,y:i,z:ac}}function f(i){this.ts=new Date().valueOf();this.tc=i;this.x=this.y=this.w=this.h=this.sc=1;this.z=0;this.Draw=i.pulsateTo<1&&i.outlineMethod!="colour"?this.DrawPulsate:this.DrawSimple;this.SetMethod(i.outlineMethod)}e=f.prototype;e.SetMethod=function(Y){var j={block:["PreDraw","DrawBlock"],colour:["PreDraw","DrawColour"],outline:["PostDraw","DrawOutline"],classic:["LastDraw","DrawOutline"],none:["LastDraw"]},i=j[Y]||j.outline;if(Y=="none"){this.Draw=function(){return 1}}else{this.drawFunc=this[i[1]]}this[i[0]]=this.Draw};e.Update=function(ae,ad,af,ab,ac,j,aa,i){var Y=this.tc.outlineOffset,Z=2*Y;this.x=ac*ae+aa-Y;this.y=ac*ad+i-Y;this.w=ac*af+Z;this.h=ac*ab+Z;this.sc=ac;this.z=j.z};e.DrawOutline=function(ab,i,aa,j,Y,Z){ab.strokeStyle=Z;ab.strokeRect(i,aa,j,Y)};e.DrawColour=function(Z,ac,aa,ad,Y,i,ae,j,ab){return this[ae.image?"DrawColourImage":"DrawColourText"](Z,ac,aa,ad,Y,i,ae,j,ab)};e.DrawColourText=function(aa,ad,ab,ae,Y,i,af,j,ac){var Z=af.colour;af.colour=i;af.Draw(aa,j,ac);af.colour=Z;return 1};e.DrawColourImage=function(ad,ag,ae,ah,ac,i,ak,j,af){var ai=ad.canvas,aa=~~z(ag,0),Z=~~z(ae,0),ab=W(ai.width-aa,ah)+0.5|0,aj=W(ai.height-Z,ac)+0.5|0,Y;if(y){y.width=ab,y.height=aj}else{y=g(ab,aj)}if(!y){return this.SetMethod("outline")}Y=y.getContext("2d");Y.drawImage(ai,aa,Z,ab,aj,0,0,ab,aj);ad.clearRect(aa,Z,ab,aj);ak.Draw(ad,j,af);ad.setTransform(1,0,0,1,0,0);ad.save();ad.beginPath();ad.rect(aa,Z,ab,aj);ad.clip();ad.globalCompositeOperation="source-in";ad.fillStyle=i;ad.fillRect(aa,Z,ab,aj);ad.restore();ad.globalCompositeOperation="destination-over";ad.drawImage(y,0,0,ab,aj,aa,Z,ab,aj);ad.globalCompositeOperation="source-over";return 1};e.DrawBlock=function(ab,i,aa,j,Y,Z){ab.fillStyle=Z;ab.fillRect(i,aa,j,Y)};e.DrawSimple=function(aa,i,j,Z){var Y=this.tc;aa.setTransform(1,0,0,1,0,0);aa.strokeStyle=Y.outlineColour;aa.lineWidth=Y.outlineThickness;aa.shadowBlur=aa.shadowOffsetX=aa.shadowOffsetY=0;aa.globalAlpha=1;return this.drawFunc(aa,this.x,this.y,this.w,this.h,Y.outlineColour,i,j,Z)};e.DrawPulsate=function(ab,i,j,Z){var aa=new Date().valueOf()-this.ts,Y=this.tc;ab.setTransform(1,0,0,1,0,0);ab.strokeStyle=Y.outlineColour;ab.lineWidth=Y.outlineThickness;ab.shadowBlur=ab.shadowOffsetX=ab.shadowOffsetY=0;ab.globalAlpha=Y.pulsateTo+((1-Y.pulsateTo)*(0.5+(h(2*Math.PI*aa/(1000*Y.pulsateTime))/2)));return this.drawFunc(ab,this.x,this.y,this.w,this.h,Y.outlineColour,i,j,Z)};e.Active=function(Y,i,j){return(i>=this.x&&j>=this.y&&i<=this.x+this.w&&j<=this.y+this.h)};e.PreDraw=e.PostDraw=e.LastDraw=function(){};function E(aa,j,ae,ag,af,ac,Y,Z){var ad=aa.ctxt,ab;this.tc=aa;this.image=j.src?j:null;this.name=j.src?"":j;this.title=ae.title||null;this.a=ae;this.p3d={x:ag[0]*aa.radius*1.1,y:ag[1]*aa.radius*1.1,z:ag[2]*aa.radius*1.1};this.x=this.y=0;this.w=af;this.h=ac;this.colour=Y||aa.textColour;this.textFont=Z||aa.textFont;this.weight=this.sc=this.alpha=1;this.weighted=!aa.weight;this.outline=new f(aa);if(this.image){if(aa.txtOpt&&aa.shadow){ab=Q(this.image,aa.shadow,aa.shadowBlur,aa.shadowOffset);if(ab){this.image=ab;this.w=ab.width;this.h=ab.height}}}else{this.textHeight=aa.textHeight;this.extents=K(this.name,this.textFont,this.textHeight);this.Measure(ad,aa)}this.SetShadowColour=aa.shadowAlpha?this.SetShadowColourAlpha:this.SetShadowColourFixed;this.SetDraw(aa)}J=E.prototype;J.SetDraw=function(i){this.Draw=this.image?(i.ie>7?this.DrawImageIE:this.DrawImage):this.DrawText;i.noSelect&&(this.CheckActive=function(){})};J.Measure=function(ac,j){this.h=this.extents?this.extents.max.y+this.extents.min.y:this.textHeight;ac.font=this.font=this.textHeight+"px "+this.textFont;this.w=ac.measureText(this.name).width;if(j.txtOpt){var Z=j.txtScale,aa=Z*this.textHeight,ab=aa+"px "+this.textFont,Y=[Z*j.shadowOffset[0],Z*j.shadowOffset[1]],i;ac.font=ab;i=ac.measureText(this.name).width;this.image=m(this.name,ab,aa,i,Z*this.h,this.colour,j.shadow,Z*j.shadowBlur,Y,Z,Z);if(this.image){this.w=this.image.width/Z;this.h=this.image.height/Z}this.SetDraw(j);j.txtOpt=this.image}};J.SetWeight=function(i){if(!this.name.length){return}this.weight=i;this.Weight(this.tc.ctxt,this.tc);this.Measure(this.tc.ctxt,this.tc)};J.Weight=function(Z,Y){var j=this.weight,i=Y.weightMode;this.weighted=true;if(i=="colour"||i=="both"){this.colour=X(Y,(j-Y.min_weight)/(Y.max_weight-Y.min_weight))}if(i=="size"||i=="both"){this.textHeight=j*Y.weightSize}this.extents=K(this.name,this.textFont,this.textHeight)};J.SetShadowColourFixed=function(Y,j,i){Y.shadowColor=j};J.SetShadowColourAlpha=function(Y,j,i){Y.shadowColor=p(j,i)};J.DrawText=function(Y,ac,j){var ad=this.tc,aa=this.x,Z=this.y,ab,i,ae=this.sc;Y.globalAlpha=this.alpha;Y.setTransform(ae,0,0,ae,0,0);Y.fillStyle=this.colour;ad.shadow&&this.SetShadowColour(Y,ad.shadow,this.alpha);Y.font=this.font;ab=this.w;i=this.h;aa+=(ac/ae)-(ab/2);Z+=(j/ae)-(i/2);Y.fillText(this.name,aa,Z)};J.DrawImage=function(aa,ag,Z){var ad=this.x,ab=this.y,ah=this.sc,j=this.image,ae=this.w,Y=this.h,ac=this.alpha,af=this.shadow;aa.globalAlpha=ac;aa.setTransform(ah,0,0,ah,0,0);aa.fillStyle=this.colour;af&&this.SetShadowColour(aa,af,ac);ad+=(ag/ah)-(ae/2);ab+=(Z/ah)-(Y/2);aa.drawImage(j,ad,ab,ae,Y)};J.DrawImageIE=function(aa,ae,Z){var j=this.image,af=this.sc,ad=j.width=this.w*af,Y=j.height=this.h*af,ac=(this.x*af)+ae-(ad/2),ab=(this.y*af)+Z-(Y/2);aa.setTransform(1,0,0,1,0,0);aa.globalAlpha=this.alpha;aa.drawImage(j,ac,ab)};J.Calc=function(aa,Z){var i=a(this.p3d,aa),j=this.tc,ab=j.minBrightness,Y=j.radius;this.p3d=b(i,Z);i=T(j,this.p3d,this.w,this.h,j.stretchX,j.stretchY);this.x=i.x;this.y=i.y;this.sc=(j.z1+j.z2-i.z)/j.z2;this.alpha=z(ab,W(1,ab+1-((i.z-j.z2+Y)/(2*Y))))};J.CheckActive=function(Z,ad,Y){var ae=this.tc,i=this.outline,ac=this.w,j=this.h,ab=this.x-ac/2,aa=this.y-j/2;i.Update(ab,aa,ac,j,this.sc,this.p3d,ad,Y);return i.Active(Z,ae.mx,ae.my)?i:null};J.Clicked=function(ab){var j=this.a,Y=j.target,Z=j.href,i;if(Y!=""&&Y!="_self"){if(self.frames[Y]){self.frames[Y]=Z}else{try{if(top.frames[Y]){top.frames[Y]=Z;return}}catch(aa){}window.open(Z,Y)}return}if(l.createEvent){i=l.createEvent("MouseEvents");i.initMouseEvent("click",1,1,window,0,0,0,0,0,0,0,0,0,0,null);if(!j.dispatchEvent(i)){return}}else{if(j.fireEvent){if(!j.fireEvent("onclick")){return}}}l.location=Z};function s(){var j,Y={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,deadZone:0,physModel:false,maxInputZone:0,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(j in Y){this[j]=Y[j]}this.max_weight=0;this.min_weight=200}d=s.prototype;d.Draw=function(){var ah=this.canvas,af=ah.width,Y=ah.height,j=0,ae=this.yaw,Z=this.pitch,aa=af/2,ak=Y/2,ai=this.ctxt,ac,aj,ag,ad=-1,am=this.taglist,ab=am.length,al=this.frontSelect;if(ae==0&&Z==0&&this.drawn&&!this.zoneActive){return this.Animate(af,Y)}ai.setTransform(1,0,0,1,0,0);this.active=null;for(ag=0;ag=0&&this.my>=0&&am[ag].CheckActive(ai,aa,ak);if(aj&&aj.sc>j&&(!al||aj.z<=0)){ac=aj;ac.index=ad=ag;j=aj.sc}}this.active=ac;if(!this.txtOpt&&this.shadow){ai.shadowBlur=this.shadowBlur;ai.shadowOffsetX=this.shadowOffset[0];ai.shadowOffsetY=this.shadowOffset[1]}ai.clearRect(0,0,af,Y);for(ag=0;ag=0&&aa>=0&&ac<=aq&&aa<=ax){Y=-aj*(2*aa/ax-1)*z(ax/aq,1)/av;j=aj*(2*ac/aq-1)*z(aq/ax,1)/ai;if(G(Y)<=1+al&&G(j)<=1+al){Y=(au!="y")?Y:0;j=(au!="x")?j:0;ag=M(Y*Y+j*j);if(ag<=az||az>=1-i){this.initial=null;this.zoneActive=true;Y=0,j=0,ag=0;am=0,ak=0,af=0}else{if(ag<=1){this.initial=null;this.zoneActive=true;Y=Y/ag*(ag-az)/(1-az),j=j/ag*(ag-az)/(1-az),ag=(ag-az)/(1-az);am=0,ak=0,af=0}else{if(ag<=1+al){this.initial=null;this.zoneActive=true;Y=Y/ag,j=j/ag,ag=1;am=0,ak=0,af=0}}}}}if(!this.zoneActive){Y=0,j=0,ag=0;if(ae>=i){am=aC/ae,ak=aB/ae,af=1}else{af=2*Math.PI*Math.random();if(au=="x"){am=0,ak=af=0&&aa>=0&&acah){this.yaw=ab>Z.z0?Z.yaw*Z.decel:0}if(au!="y"&&an>ah){this.pitch=an>Z.z0?Z.pitch*Z.decel:0}}}}};d.Zoom=function(i){this.z2=this.z1*(1/i);this.drawn=0};d.Clicked=function(Z){var Y=this.taglist,i=this.active;try{if(i&&Y[i.index]){Y[i.index].Clicked(Z)}}catch(j){}};d.Wheel=function(j){var Y=this.zoom+this.zoomStep*(j?1:-1);this.zoom=W(this.zoomMax,z(this.zoomMin,Y));this.Zoom(this.zoom)};s.tc={};jQuery.fn.tagcanvas=function(Y,j){var i,Z=j?jQuery("#"+j):this;if(l.all&&!j){return false}i=Z.find("a");if(O(window.G_vmlCanvasManager)){this.each(function(){I(this)[0]=window.G_vmlCanvasManager.initElement(I(this)[0])});Y.ie=parseFloat(navigator.appVersion.split("MSIE")[1])}if(!i.length||!this[0].getContext||!this[0].getContext("2d").fillText){return false}this.each(function(){var ac,aa,ae,ah,ai,ad,ag,af=[],ab={sphere:n,vcylinder:w,hcylinder:F};j||(i=I(this).find("a"));ad=new s;for(ac in Y){ad[ac]=Y[ac]}ad.z1=(19800/(Math.exp(ad.depth)*(1-1/Math.E)))+20000-19800/(1-(1/Math.E));ad.z2=ad.z1*(1/ad.zoom);ad.radius=(this.height>this.width?this.width:this.height)*0.33*(ad.z2+ad.z1)/(ad.z1);ad.yaw=ad.initial&&(ad.lock!="x")?ad.initial[0]*ad.maxSpeed:0;ad.pitch=ad.initial&&(ad.lock!="y")?ad.initial[1]*ad.maxSpeed:0;ad.canvas=I(this)[0];ad.ctxt=ad.canvas.getContext("2d");ad.textFont=ad.textFont&&t(ad.textFont);ad.deadZone*=1;ad.minSpeed*=1;ad.decel*=1;ad.maxInputZone*=1;ad.pulsateTo*=1;ad.textHeight*=1;ad.minBrightness*=1;ad.ctxt.textBaseline="top";if(ad.shadowBlur||ad.shadowOffset[0]||ad.shadowOffset[1]){ad.ctxt.shadowColor=ad.shadow;ad.shadow=ad.ctxt.shadowColor;ad.shadowAlpha=v()}else{delete ad.shadow}ad.taglist=[];ad.shape=ab[ad.shape]||ab.sphere;aa=ad.shape(i.length,ad.radiusX,ad.radiusY,ad.radiusZ);ad.shuffleTags&&H(aa);ad.listLength=i.length;for(ac=0;acad.max_weight){ad.max_weight=ag}if(agad.min_weight)){for(ac=0;acvalue)) { + 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/module.info b/3.0/modules/tag_cloud_html5/module.info index 7de09f86..e158d15a 100644 --- a/3.0/modules/tag_cloud_html5/module.info +++ b/3.0/modules/tag_cloud_html5/module.info @@ -1,6 +1,6 @@ name = "Tag Cloud HTML5" description = "HTML5-compliant tag cloud. Functions as non-Flash replacements for both 'tag_cloud' and 'tag_cloud_page' modules, with some extra features added." -version = 4 +version = 7 author_name = "Shad Laws" author_url = "" info_url = "http://codex.gallery2.org/Gallery3:Modules:tag_cloud_html5" diff --git a/3.0/modules/tag_cloud_html5/views/admin_tag_cloud_html5.html.php b/3.0/modules/tag_cloud_html5/views/admin_tag_cloud_html5.html.php index 6803f564..026624a5 100644 --- a/3.0/modules/tag_cloud_html5/views/admin_tag_cloud_html5.html.php +++ b/3.0/modules/tag_cloud_html5/views/admin_tag_cloud_html5.html.php @@ -7,10 +7,23 @@

    - excanvas to maintain compatibility with pre-9.0 Internet Explorer.") ?> +
    + TagCanvas: ".t("a non-flash, HTML5-compliant jQuery plugin.") ?>
    + excanvas: ".t("maintains canvas compatibility with pre-9.0 Internet Explorer, and does not load if not needed.") ?>
    + +

    - here.") ?> +
    +
    +
    +
    + +

    +

    +
    +
    +

    diff --git a/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_block.html.php b/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_block.html.php index 68d12e47..80360fe6 100644 --- a/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_block.html.php +++ b/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_block.html.php @@ -1,12 +1,14 @@ - + +
    + + + +
    + \ No newline at end of file diff --git a/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_page.html.php b/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_page.html.php index c8d58b97..2b6fa624 100644 --- a/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_page.html.php +++ b/3.0/modules/tag_cloud_html5/views/tag_cloud_html5_page.html.php @@ -1,12 +1,14 @@ - +