1
0

-proofsheet: updated to v7 (previously v4 on github)

-tag_cloud_html5: updated to v7 (previously v5 on github)
-short_search_fix: updated to v2 (previously v1 on github)
-register: updated to v2 (previously v1 on github)
-image_optimizer: v1
This commit is contained in:
shadlaws 2012-12-12 22:51:42 +01:00
parent fe359ce21e
commit ab0265b1c4
24 changed files with 1067 additions and 750 deletions

View File

@ -20,8 +20,12 @@
/** /**
* Generate a PDF proof sheet on-the-fly of the current album or tag. * Generate a PDF proof sheet on-the-fly of the current album or tag.
* By Shad Laws. Version 5, 2012/04/05 * By Shad Laws. Version 7, 2012/10/05
* *
* 2012/10/04, version 7
* Fixed bug related to the URL for proofsheets of tags (as opposed to albums)
* 2012/06/15, version 6
* Fixed bug that could cause a crash when trying to use GD or GIF files (a typo from version 5)
* 2012/04/05, version 5 * 2012/04/05, version 5
* Added ability to include GIF thumbnails if GD is installed (FPDF uses GD) * 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 * Changed behavior of unhandled file types - now provides missing image icon instead of throwing an exception
@ -84,7 +88,8 @@ class proofsheet_Controller extends Controller {
$pdfname = $container->name.'.pdf'; $pdfname = $container->name.'.pdf';
$headerText = $container->name; $headerText = $container->name;
$headerLink = $container->abs_url(); //$headerLink = $container->abs_url();
$headerLink = url::abs_site("tag/{$container->id}/" . urlencode($container->name));
break; break;
default: default:
@ -214,7 +219,7 @@ class proofsheet_Controller extends Controller {
$cfg['footerY'] = $cfg['pageH']-$cfg['marginB']+$cfg['footerSpace']; $cfg['footerY'] = $cfg['pageH']-$cfg['marginB']+$cfg['footerSpace'];
$cfg['imageNum'] = $cfg['imageNumW']*$cfg['imageNumH']; $cfg['imageNum'] = $cfg['imageNumW']*$cfg['imageNumH'];
$cfgImageMissing['iconInfo'] = getimagesize($cfgImageMissing['iconPath']); $cfgImageMissing['iconInfo'] = getimagesize($cfgImageMissing['iconPath']);
$cfgImageMissing['GDflag'] = graphics::detect_toolkits()->gd>installed; // FPDF uses GD to convert GIFs $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 * Initialize and build PDF... the main routine. Note that almost all of the

View File

@ -17,32 +17,6 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. * 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 { class proofsheet_event_Core {
/** /**

View File

@ -1,6 +1,6 @@
name = "ProofSheet" name = "ProofSheet"
description = "Displays links to generate a PDF proof sheet of the current album in A4 or LTR size." 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_name = "Shad Laws"
author_url = "" author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:proofsheet" info_url = "http://codex.gallery2.org/Gallery3:Modules:proofsheet"

View File

@ -35,11 +35,17 @@ class Admin_register_Controller extends Admin_Controller {
$post->add_rules("policy", "required"); $post->add_rules("policy", "required");
$post->add_rules("group", array($this, "passthru")); $post->add_rules("group", array($this, "passthru"));
$post->add_rules("email_verification", 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(); $group_list = array();
if ($post->validate()) { if ($post->validate()) {
module::set_var("registration", "policy", $post->policy); module::set_var("registration", "policy", $post->policy);
module::set_var("registration", "default_group", $post->group); module::set_var("registration", "default_group", $post->group);
module::set_var("registration", "email_verification", !empty($post->email_verification)); 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.")); message::success(t("Registration defaults have been updated."));
@ -108,6 +114,12 @@ class Admin_register_Controller extends Admin_Controller {
if (empty($admin->email)) { if (empty($admin->email)) {
module::set_var("registration", "email_verification", false); 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(); $v->content->group_list = array();
foreach (identity::groups() as $group) { foreach (identity::groups() as $group) {
@ -134,7 +146,10 @@ class Admin_register_Controller extends Admin_Controller {
private function _get_form() { private function _get_form() {
$form = array("policy" => module::get_var("registration", "policy"), $form = array("policy" => module::get_var("registration", "policy"),
"group" => module::get_var("registration", "default_group"), "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), ""); $errors = array_fill_keys(array_keys($form), "");
return array($form, $errors); return array($form, $errors);

View File

@ -51,9 +51,15 @@ class register_Controller extends Controller {
} else if ($pending_user->state == 1) { } else if ($pending_user->state == 1) {
site_status::warning( site_status::warning(
t("There are pending user registration. <a href=\"%url\">Review now!</a>", t("There are pending user registration. <a href=\"%url\">Review now!</a>",
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"); "pending_user_registrations");
message::success(t("Your registration request is awaiting administrator approval")); 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 { } else {
register::send_confirmation($pending_user); register::send_confirmation($pending_user);
message::success(t("A confirmation email has been sent to your email address.")); message::success(t("A confirmation email has been sent to your email address."));
@ -84,9 +90,15 @@ class register_Controller extends Controller {
} else { } else {
site_status::warning( site_status::warning(
t("There are pending user registration. <a href=\"%url\">Review now!</a>", t("There are pending user registration. <a href=\"%url\">Review now!</a>",
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"); "pending_user_registrations");
message::success(t("Your registration request is awaiting administrator approval")); 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 { } else {
message::error(t("Your registration request is no longer valid, Please re-register.")); 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]"); ->rules("required|valid_email|length[1,255]");
$group->input("email2")->label(t("Confirm email"))->id("g-email2") $group->input("email2")->label(t("Confirm email"))->id("g-email2")
->matches($group->email); ->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"); ->rules("valid_url");
module::event("register_add_form", $form); module::event("register_add_form", $form);

View File

@ -47,14 +47,35 @@ class register_Core {
$message->user = $user; $message->user = $user;
$message->site_url = $requires_first ? url::abs_site("register/first/{$user->hash}") : $message->site_url = $requires_first ? url::abs_site("register/first/{$user->hash}") :
url::abs_site(""); 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) { static function send_confirmation($user) {
$message = new View("confirm_registration.html"); $message = new View("confirm_registration.html");
$message->confirm_url = url::abs_site("register/confirm/{$user->hash}"); $message->confirm_url = url::abs_site("register/confirm/{$user->hash}");
$message->user = $user; $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) { static function create_pending_request($form) {
@ -66,6 +87,8 @@ class register_Core {
$user->email = $form->register_user->inputs["email"]->value; $user->email = $form->register_user->inputs["email"]->value;
$user->url = $form->register_user->inputs["url"]->value; $user->url = $form->register_user->inputs["url"]->value;
$user->request_date = time(); $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) { if (!$email_verification) {
$user->state = 1; $user->state = 1;
@ -98,7 +121,8 @@ class register_Core {
->to($email) ->to($email)
->subject($subject) ->subject($subject)
->header("Mime-Version", "1.0") ->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()) ->message($message->render())
->send(); ->send();
} }

View File

@ -37,11 +37,34 @@ class register_installer {
module::set_var("registration", "policy", "admin_only"); module::set_var("registration", "policy", "admin_only");
module::set_var("registration", "default_group", ""); module::set_var("registration", "default_group", "");
module::set_var("registration", "email_verification", false); 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() { static function uninstall() {
Database::instance()->query("DROP TABLE IF EXISTS {pending_users};"); Database::instance()->query("DROP TABLE IF EXISTS {pending_users};");
// added Shad Laws, v2
module::clear_all_vars("registration");
} }
} }

View File

@ -25,4 +25,9 @@ class register_theme_Core {
return new View("register_welcome_message_loader.html"); return new View("register_welcome_message_loader.html");
} }
} }
// added Shad Laws, v2
static function head($theme) {
return $theme->css("register.css");
}
} }

View File

@ -1,7 +1,7 @@
name = "User Registration" name = "User Registration"
description = "Allow guests to register as users." description = "Allow guests to register as users."
version = 1 version = 2
author_name = "" author_name = "revised to v2 by Shad Laws"
author_url = "" author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:register" info_url = "http://codex.gallery2.org/Gallery3:Modules:register"
discuss_url = "http://gallery.menalto.com/forum_module_register" discuss_url = "http://gallery.menalto.com/forum_module_register"

View File

@ -7,6 +7,12 @@
} else { } else {
$(":checkbox[name=email_verification]").removeAttr("disabled"); $(":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");
}
}); });
}); });
</script> </script>
@ -27,6 +33,14 @@
<?= form::checkbox("email_verification", "true", !empty($form["email_verification"]), $disable_email) ?> <?= form::checkbox("email_verification", "true", !empty($form["email_verification"]), $disable_email) ?>
<?= form::label("email_verification", t("Require e-mail verification when a visitor creates an account")) ?> <?= form::label("email_verification", t("Require e-mail verification when a visitor creates an account")) ?>
</li> </li>
<li>
<?= form::checkbox("admin_notify", "true", !empty($form["admin_notify"]), $disable_admin_notify) ?>
<?= form::label("admin_notify", t("Send a pending user registration notification email to the site 'reply to' email address")) ?>
</li>
<li>
<?= form::input("subject_prefix", $form["subject_prefix"]) ?>
<?= form::label("subject_prefix", t("Email subject line prefix, with trailing spaces as needed (e.g. '[Gallery3] ')")) ?>
</li>
<li> <li>
<? if (!empty($group_list)): ?> <? if (!empty($group_list)): ?>
<label for="group" class="g-left"> <?= t("Default group: ") ?></label> <label for="group" class="g-left"> <?= t("Default group: ") ?></label>

View File

@ -1,17 +1,18 @@
<?php defined("SYSPATH") or die("No direct script access.") ?> <?php defined("SYSPATH") or die("No direct script access.") ?>
<html> <html>
<head> <head>
<title><?= t("User registration confirmation") ?> </title> <title><?= ($subject_prefix.$subject) ?></title>
</head> </head>
<body> <body>
<h2><?= t("User registration confirmation") ?> </h2> <h2><?= $subject ?></h2>
<p> <p>
<?= t("Hello, %name,", array("name" => $user->full_name ? $user->full_name : $user->name)) ?> <?= t("Hello %name,", array("name" => $user->full_name ? $user->full_name : $user->name, "locale" => $locale)) ?>
</p> </p>
<p> <p>
<?= t("We received a request to to create a user with this email. If you made this request, you can confirm it by <a href=\"%confirm_url\">clicking this link</a>. If you didn't request this password reset, it's ok to ignore this mail.", <?= t("We received a request to to create a user with this email. If you made this request, you can confirm it by <a href=\"%confirm_url\">clicking this link</a>. 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")), array("site_url" => html::mark_clean(url::base(false, "http")),
"confirm_url" => $confirm_url)) ?> "confirm_url" => $confirm_url,
"locale" => $locale)) ?>
</p> </p>
</body> </body>
</html> </html>

View File

@ -1,16 +1,17 @@
<?php defined("SYSPATH") or die("No direct script access.") ?> <?php defined("SYSPATH") or die("No direct script access.") ?>
<html> <html>
<head> <head>
<title><?= t("Welcome to Gallery3") ?> </title> <title><?= ($subject_prefix.$subject) ?></title>
</head> </head>
<body> <body>
<h2><?= t("Welcome") ?> </h2> <h2><?= $subject ?></h2>
<p> <p>
<?= t("Hello, %name,", array("name" => $user->full_name ? $user->full_name : $user->name)) ?> <?= t("Hello %name,", array("name" => $user->full_name ? $user->full_name : $user->name, "locale" => $locale)) ?>
</p> </p>
<p> <p>
<?= t("The user account you requested as been created.<br/>You can access the site by <a href=\"%site_url\">clicking this link</a> and you will be prompted to set your password at this point.", <?= t("The user account you requested as been created.<br/>You can access the site by <a href=\"%site_url\">clicking this link</a> and you will be prompted to set your password at this point.",
array("site_url" => html::mark_clean($site_url))) ?> array("site_url" => html::mark_clean($site_url),
"locale" => $locale)) ?>
</p> </p>
</body> </body>
</html> </html>

View File

@ -23,36 +23,101 @@ class search extends search_Core {
* few terms in the query. * few terms in the query.
*/ */
static function add_query_terms($q) { 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 // strip leading, trailing, and extra whitespaces
$terms = preg_replace('/^\s+/', '', $q); $terms = preg_replace('/^\s+/', '', $q);
$terms = preg_replace('/\s+$/', '', $terms); $terms = preg_replace('/\s+$/', '', $terms);
$terms = preg_replace('/\s\s+/', ' ', $terms); $terms = preg_replace('/\s\s+/', ' ', $terms);
// explode terms, initialize the loop
$terms = explode(" ", $terms, $MAX_TERMS); $terms = explode(" ", $terms); // array
//$terms = explode(" ", $q, $MAX_TERMS); // commented out from original function $termsextra = ""; // string, not array
for ($i = 0; $i < min(count($terms), $MAX_TERMS - 1); $i++) { $numtermsextra = 0;
// Don't wildcard quoted or already wildcarded terms $flagwild = 1;
if ((substr($terms[$i], 0, 1) != '"') && (substr($terms[$i], -1, 1) != "*")) { $countquote = 0;
$terms[] = rtrim($terms[$i], "s") . "*"; $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 // implode terms, trim termsextra trailing space (if it exists)
/**
* Add the search prefix to the start of every word.
*/
$prefix = module::get_var("short_search_fix","search_prefix");
$terms = implode(" ", $terms); $terms = implode(" ", $terms);
$terms = preg_replace('/^\s+/', '', $terms); // the implode seems to add this back in $termsextra = preg_replace('/\s+$/', '', $termsextra);
// add the prefixes // add extra closing quotes and parentheses
if (preg_match('/\w/',$terms) > 0) { while ($countquote > 0) {
$terms = ' ' . $terms; $terms = $terms.'"';
$terms = str_replace(' ', ' '.$prefix, $terms); $termsextra = $termsextra.'"';
$terms = str_replace(' '.$prefix.'"', ' '.'"'.$prefix, $terms); $countquote--;
$terms = substr($terms,1);
} }
return $terms; while ($countparen > 0) {
$terms = $terms.")";
$termsextra = $termsextra.")";
$countparen--;
}
// all done!
return ($terms." ".$termsextra);
} }
} }

View File

@ -1,6 +1,6 @@
name = "Short Search Fix" name = "Short Search Fix"
description = "Allows 2-3 letter searches to be performed without requiring SQL system variable modification (useful for shared hosting)." 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_name = "Shad Laws"
author_url = "" author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:short_search_fix" info_url = "http://codex.gallery2.org/Gallery3:Modules:short_search_fix"

View File

@ -29,111 +29,88 @@ class Admin_Tag_Cloud_Html5_Controller extends Admin_Controller {
$cfg = $this->_get_config(); $cfg = $this->_get_config();
$form = $this->_get_admin_form(); $form = $this->_get_admin_form();
if ($form->validate()) { if ($form->validate()) {
if ($form->options_general->load_defaults->value) { if ($form->general->reset_defaults->value) {
// reset all to defaults, redirect with message // reset all to defaults, redirect with message
module::install("tag_cloud_html5"); module::install("tag_cloud_html5");
message::success(t("Tag cloud options reset successfully")); message::success(t("Tag cloud options reset successfully"));
url::redirect("admin/tag_cloud_html5"); 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;
} }
// 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) { foreach ($cfg['groups'] as $groupname => $grouptext) {
${"options".$groupname} = $form->{"options".$groupname}; module::set_var("tag_cloud_html5", "maxtags".$groupname, $form->{"size".$groupname}->{"maxtags".$groupname}->value);
if ($options_general->{"maxtags".$groupname}->value < 0) { module::set_var("tag_cloud_html5", "width".$groupname, $form->{"size".$groupname}->{"width".$groupname}->value);
$form->options_general->{"maxtags".$groupname}->add_error("not_valid", 1); module::set_var("tag_cloud_html5", "height".$groupname, $form->{"size".$groupname}->{"height".$groupname}->value);
$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 = array();
$optionsarray['maxSpeed'] = ${"options".$groupname}->{"maxSpeed".$groupname}->value; // group size
$optionsarray['deadZone'] = ${"options".$groupname}->{"deadZone".$groupname}->value; $optionsarray['shape'] = $form->{"size".$groupname}->{"shape".$groupname}->value;
$optionsarray['initial'] = array(${"options".$groupname}->{"initialX".$groupname}->value, ${"options".$groupname}->{"initialY".$groupname}->value); $optionsarray['zoom'] = $form->{"size".$groupname}->{"zoom".$groupname}->value;
$optionsarray['initialDecel'] = (${"options".$groupname}->{"initialDecel".$groupname}->value == 1); $optionsarray['stretchX'] = $form->{"size".$groupname}->{"stretchX".$groupname}->value;
$optionsarray['zoom'] = ${"options".$groupname}->{"zoom".$groupname}->value; $optionsarray['stretchY'] = $form->{"size".$groupname}->{"stretchY".$groupname}->value;
$optionsarray['depth'] = ${"options".$groupname}->{"depth".$groupname}->value; // group motion
$optionsarray['outlineMethod'] = ${"options".$groupname}->{"outlineMethod".$groupname}->value; $optionsarray['maxSpeed'] = $form->{"motion".$groupname}->{"maxSpeed".$groupname}->value;
$optionsarray['outlineOffset'] = ${"options".$groupname}->{"outlineOffset".$groupname}->value; $optionsarray['minSpeed'] = $form->{"motion".$groupname}->{"minSpeed".$groupname}->value;
$optionsarray['outlineColour'] = ${"options".$groupname}->{"outlineColour".$groupname}->value; $optionsarray['deadZone'] = $form->{"motion".$groupname}->{"deadZone".$groupname}->value;
$optionsarray['textColour'] = ${"options".$groupname}->{"textColour".$groupname}->value; $optionsarray['decel'] = $form->{"motion".$groupname}->{"decel".$groupname}->value;
$optionsarray['textFont'] = ${"options".$groupname}->{"textFont".$groupname}->value; $optionsarray['initial'] = array($form->{"motion".$groupname}->{"initialX".$groupname}->value, $form->{"motion".$groupname}->{"initialY".$groupname}->value);
$optionsarray['textHeight'] = ${"options".$groupname}->{"textHeight".$groupname}->value; $optionsarray['maxInputZone'] = $form->{"motion".$groupname}->{"maxInputZone".$groupname}->value;
$optionsarray['frontSelect'] = (${"options".$groupname}->{"frontSelect".$groupname}->value == 1); // group select
$optionsarray['wheelZoom'] = false; // note that this is locked - otherwise scrolling through the page screws everything up $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)); module::set_var("tag_cloud_html5", "options".$groupname, json_encode($optionsarray));
} }
// all done; redirect with message // all done; redirect with message
message::success(t("Tag cloud options updated successfully")); message::success(t("Tag cloud options updated successfully"));
url::redirect("admin/tag_cloud_html5"); url::redirect("admin/tag_cloud_html5");
} }
} // not valid - print screen from existing form
}
// print screen from existing form - you wind up here if something wasn't validated
$this->_print_screen($form); $this->_print_screen($form);
} }
private function _get_config() { private function _get_config() {
// these define the two variable name groups, along with their labels which are always shown with t() for i18n. // 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(). // 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; return $cfg;
} }
private function _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("/<fieldset>/","<fieldset class=\"g-tag-cloud-html5-admin-form-top\">",$form,1);
$form = preg_replace("/<fieldset>/","<fieldset class=\"g-tag-cloud-html5-admin-form-left\">",$form,4);
$form = preg_replace("/<fieldset>/","<fieldset class=\"g-tag-cloud-html5-admin-form-right\">",$form,4);
$view = new Admin_View("admin.html"); $view = new Admin_View("admin.html");
$view->content = new View("admin_tag_cloud_html5.html"); $view->content = new View("admin_tag_cloud_html5.html");
$view->content->form = $form; $view->content->form = $form;
@ -144,12 +121,12 @@ class Admin_Tag_Cloud_Html5_Controller extends Admin_Controller {
$cfg = $this->_get_config(); $cfg = $this->_get_config();
$sep = $cfg['sep']; $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")); $form = new Forge("admin/tag_cloud_html5/edit", "", "post", array("id" => "g-tag-cloud-html5-admin-form"));
// group_general // group general
$group_general = $form->group("options_general")->label(t("Tag cloud options").$sep.t("General")); $group_general = $form->group("general")->label(t("General"))->set_attr("id","g-tag-cloud-html5-admin-form-general");
$group_general->checkbox("load_defaults") $group_general->checkbox("reset_defaults")
->label(t("Reset all to default values")) ->label(t("Reset all to default values"))
->checked(false); ->checked(false);
$group_general->checkbox("show_wholecloud_link") $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") $group_general->checkbox("show_add_tag_form")
->label(t("Show 'Add tag to album' form in sidebar (when permitted and applicable)")) ->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)); ->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") $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)); ->checked(module::get_var("tag_cloud_html5", "show_wholecloud_list", null));
foreach ($cfg['groups'] as $groupname => $grouptext) { foreach ($cfg['groups'] as $groupname => $grouptext) {
// maxtags - note that this is displayed under group_general! $maxtags = strval(module::get_var("tag_cloud_html5", "maxtags".$groupname, null));
$maxtags = module::get_var("tag_cloud_html5", "maxtags".$groupname, null); $width = strval(module::get_var("tag_cloud_html5", "width".$groupname, null));
$group_general->input("maxtags".$groupname) $height = strval(module::get_var("tag_cloud_html5", "height".$groupname, null));
->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
$options = json_decode(module::get_var("tag_cloud_html5", "options".$groupname, null),true); $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) // group size/shape
->label(t($grouptext).$sep.t("max speed (typically 0.01-0.20)")) ${"group_size".$groupname} = $form->group("size".$groupname)->label(t("Size and shape").$sep.$grouptext);
->value($options['maxSpeed']) ${"group_size".$groupname}->input("maxtags".$groupname)
->error_message("not_valid", t("Max speed must be a 1-5 digit number")) ->label(t("maximum tags shown"))
->rules("required|valid_numeric|length[1,5]"); ->value($maxtags)
${"group".$groupname}->input("initialX".$groupname) ->rules("required|numrange[0]");
->label(t($grouptext).$sep.t("initial horizontal speed (between +/-1.0, as fraction of max speed)")) ${"group_size".$groupname}->input("width".$groupname)
->value($options['initial'][0]) ->label(t("width")." (".$cfg['size'][$groupname].")")
->error_message("not_valid", t("Initial horizontal speed must be a 1-4 digit number")) ->value($width)
->rules("required|valid_numeric|length[1,4]"); ->rules("required|numrange[0]");
${"group".$groupname}->input("initialY".$groupname) ${"group_size".$groupname}->input("height".$groupname)
->label(t($grouptext).$sep.t("initial vertical speed (between +/-1.0, as fraction of max speed)")) ->label(t("height")." (".$cfg['size'][$groupname].")")
->value($options['initial'][1]) ->value($height)
->error_message("not_valid", t("Initial vertical speed must be a 1-4 digit number")) ->rules("required|numrange[0]");
->rules("required|valid_numeric|length[1,4]"); ${"group_size".$groupname}->dropdown("shape".$groupname)
${"group".$groupname}->checkbox("initialDecel".$groupname) ->label(t("shape of cloud")." {shape,lock}")
->label(t($grouptext).$sep.t("initial deceleration (if false, the initial speed is held until a mouseover event)")) ->options(array("sphere"=>t("sphere"),"hcylinder"=>t("horizontal cylinder"),"vcylinder"=>t("vertical cylinder")))
->checked($options['initialDecel']); ->selected($options['shape']);
${"group".$groupname}->input("deadZone".$groupname) ${"group_size".$groupname}->input("zoom".$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)")) ->label(t("zoom (<1.0 is zoom out, >1.0 is zoom in)")." {zoom}")
->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)"))
->value($options['zoom']) ->value($options['zoom'])
->error_message("not_valid", t("Zoom must be a 1-4 digit number")) ->rules("required|numrange[0]");
->rules("required|valid_numeric|length[1,4]"); ${"group_size".$groupname}->input("stretchX".$groupname)
${"group".$groupname}->input("depth".$groupname) ->label(t("x-axis stretch factor (<1.0 squishes, >1.0 stretches)")." {stretchX}")
->label(t($grouptext).$sep.t("depth (0.0-1.0)")) ->value($options['stretchX'])
->value($options['depth']) ->rules("required|numrange[0]");
->error_message("not_valid", t("Depth must be a 1-4 digit number")) ${"group_size".$groupname}->input("stretchY".$groupname)
->rules("required|valid_numeric|length[1,4]"); ->label(t("y-axis stretch factor (<1.0 squishes, >1.0 stretches)")." {stretchY}")
${"group".$groupname}->dropdown("outlineMethod".$groupname) ->value($options['stretchY'])
->label(t($grouptext).$sep.t("outline method (mouseover event)")) ->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"))) ->options(array("colour"=>t("change text color"),"outline"=>t("add outline around text"),"block"=>t("add block behind text")))
->selected($options['outlineMethod']); ->selected($options['outlineMethod']);
${"group".$groupname}->input("outlineOffset".$groupname) ${"group_select".$groupname}->input("outlineOffset".$groupname)
->label(t($grouptext).$sep.t("outline offset (mouseover region size around text, in pixels)")) ->label(t("mouseover region around tag text (in pixels - 0 is tight around text)")." {outlineOffset}")
->value($options['outlineOffset']) ->value($options['outlineOffset'])
->error_message("not_valid", t("Outline offset must be a 1-2 digit number")) ->rules("required|numrange[0]");
->rules("required|valid_numeric|length[1,2]"); ${"group_select".$groupname}->input("outlineColour".$groupname)
${"group".$groupname}->input("outlineColour".$groupname) ->label(t("color used for change of display (as #hhhhhh)")." {outlineColour}")
->label(t($grouptext).$sep.t("outline color (mouseover color, as #hhhhhh)"))
->value($options['outlineColour']) ->value($options['outlineColour'])
->error_message("not_valid", t("Outline color must be specified as #hhhhhh")) ->rules('required|color');
->rules("required|length[7]"); ${"group_select".$groupname}->checkbox("frontSelect".$groupname)
${"group".$groupname}->input("textColour".$groupname) ->label(t("only allow tags in front to be selected")." {frontSelect}")
->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"))
->checked($options['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")); $form->submit("")->value(t("Save"));
return $form; return $form;

View File

@ -26,6 +26,8 @@ class Tag_Cloud_Controller extends Controller {
// Get settings // Get settings
$options = module::get_var("tag_cloud_html5", "options_wholecloud", null); $options = module::get_var("tag_cloud_html5", "options_wholecloud", null);
$maxtags = module::get_var("tag_cloud_html5", "maxtags_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 = json_decode($options, true);
$options['hideTags'] = !module::get_var("tag_cloud_html5", "show_wholecloud_list", true); $options['hideTags'] = !module::get_var("tag_cloud_html5", "show_wholecloud_list", true);
@ -37,6 +39,74 @@ class Tag_Cloud_Controller extends Controller {
$template->content->title = t("Tag cloud"); $template->content->title = t("Tag cloud");
$template->content->cloud = tag::cloud($maxtags); $template->content->cloud = tag::cloud($maxtags);
$template->content->options = $options; $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. // Display the page.
print $template; print $template;

View File

@ -1,30 +1,17 @@
#g-content fieldset li { #g-content fieldset {
display: block; display: block;
}
#g-content fieldset.g-tag-cloud-html5-admin-form-top {
width: 80%;
clear: both; clear: both;
height: 24px;
} }
#g-content fieldset input { #g-content fieldset.g-tag-cloud-html5-admin-form-left {
display: inline; width: 45%;
float: left; float: left;
height: 18px; clear: left;
margin-right: 0.8em; margin-right: 2%
width: 250px;
} }
#g-content fieldset select { #g-content fieldset.g-tag-cloud-html5-admin-form-right {
display: inline; width: 45%;
float: left; clear: right;
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;
} }

View File

@ -32,6 +32,7 @@ class tag_cloud_html5_block {
$maxtags = module::get_var("tag_cloud_html5", "maxtags_sidebar", null); $maxtags = module::get_var("tag_cloud_html5", "maxtags_sidebar", null);
$showlink = module::get_var("tag_cloud_html5", "show_wholecloud_link", null); $showlink = module::get_var("tag_cloud_html5", "show_wholecloud_link", null);
$showaddtag = module::get_var("tag_cloud_html5", "show_add_tag_form", 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); $height = module::get_var("tag_cloud_html5", "height_sidebar", null);
// make the block // make the block
@ -41,6 +42,7 @@ class tag_cloud_html5_block {
$block->content = new View("tag_cloud_html5_block.html"); $block->content = new View("tag_cloud_html5_block.html");
$block->content->cloud = tag::cloud($maxtags); $block->content->cloud = tag::cloud($maxtags);
$block->content->options = $options; $block->content->options = $options;
$block->content->width = $width;
$block->content->height = $height; $block->content->height = $height;
// add the 'View whole cloud' link if needed // add the 'View whole cloud' link if needed

View File

@ -22,12 +22,19 @@ class tag_cloud_html5_installer {
// clear and reset default values. this is also called in the admin menu for // 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. // 'reset all to default values' and if the upgrader sees variables missing.
module::clear_all_vars("tag_cloud_html5"); module::clear_all_vars("tag_cloud_html5");
module::set_var("tag_cloud_html5", "show_wholecloud_link", true); 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_add_tag_form", true);
module::set_var("tag_cloud_html5", "show_wholecloud_list", 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", "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", "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( module::set_var("tag_cloud_html5", "options_sidebar", json_encode(array(
"maxSpeed" => 0.05, "maxSpeed" => 0.05,
"deadZone" => 0.25, "deadZone" => 0.25,
@ -42,8 +49,17 @@ class tag_cloud_html5_installer {
"textFont" => "", "textFont" => "",
"textHeight" => 12, "textHeight" => 12,
"frontSelect" => true, "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( module::set_var("tag_cloud_html5", "options_wholecloud", json_encode(array(
"maxSpeed" => 0.05, "maxSpeed" => 0.05,
"deadZone" => 0.25, "deadZone" => 0.25,
@ -58,17 +74,100 @@ class tag_cloud_html5_installer {
"textFont" => "", "textFont" => "",
"textHeight" => 13, "textHeight" => 13,
"frontSelect" => true, "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() { static function upgrade() {
if (is_null(module::get_var("tag_cloud_html5", "options_sidebar")) || if (is_null(module::get_var("tag_cloud_html5", "options_sidebar")) ||
is_null(module::get_var("tag_cloud_html5", "options_wholecloud")) || 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"); 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() { static function uninstall() {

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
name = "Tag Cloud HTML5" 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." 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_name = "Shad Laws"
author_url = "" author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:tag_cloud_html5" info_url = "http://codex.gallery2.org/Gallery3:Modules:tag_cloud_html5"

View File

@ -7,10 +7,23 @@
<?= t("Tag cloud HTML5 settings") ?> <?= t("Tag cloud HTML5 settings") ?>
</h2> </h2>
<p> <p>
<?= t("This module uses TagCanvas, a non-flash, HTML5-compliant jQuery plugin. It also uses <a href=\"http://excanvas.sourceforge.net/\">excanvas</a> to maintain compatibility with pre-9.0 Internet Explorer.") ?> <b><?= t("Underlying JS libraries:") ?></b><br/>
<?= "1. <a href='http://www.goat1000.com/tagcanvas.php'>TagCanvas</a>: ".t("a non-flash, HTML5-compliant jQuery plugin.") ?><br/>
<?= "2. <a href='http://excanvas.sourceforge.net'>excanvas</a>: ".t("maintains canvas compatibility with pre-9.0 Internet Explorer, and does not load if not needed.") ?><br/>
<?= t("The module author, Shad Laws, has modified TagCanvas to add a physics-based model for motion and some extra parameters.") ?>
<?= t("Although this module loads a minified version of the JS library, the full-sized one is included in the JS directory for reference.") ?>
</p> </p>
<p> <p>
<?= t("More details on the options below are given at TagCanvas's homepage <a href='http://www.goat1000.com/tagcanvas.php'>here</a>.") ?> <b><?= t("How sizing works in TagCanvas:") ?></b><br/>
<?= "1. ".t("make a square the size of the minimum of width and height (as determined by width and height parameters)") ?><br/>
<?= "2. ".t("scale result by the stretch factors, possibility resulting in a non-square shape") ?><br/>
<?= "3. ".t("set text into result at defined text height") ?><br/>
<?= "4. ".t("scale result by the zoom, scaling both cloud and text height (e.g. text height 12 and zoom 1.25 results in 15pt font)") ?>
</p>
<p>
<b><?= t("Legend:") ?></b><br/>
<?= t("&nbsp;&nbsp;&nbsp;option name (more info on option) {related TagCanvas parameters}") ?><br/>
<?= t("More details on TagCanvas parameters given at TagCanvas's homepage or in the above-mentioned JS library.") ?>
</p> </p>
<?= $form ?> <?= $form ?>
</div> </div>

View File

@ -1,12 +1,14 @@
<?php defined("SYSPATH") or die("No direct script access.") ?> <?php defined("SYSPATH") or die("No direct script access.") ?>
<!--[if lt IE 9]><?= $theme->script("excanvas.compiled.js"); ?><![endif]--> <!--[if lt IE 9]>
<?= html::script(gallery::find_file("js", "excanvas.compiled.js", false)) ?>
<![endif]-->
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
// set g-tag-cloud-html5-canvas size // set g-tag-cloud-html5-canvas size
$("#g-tag-cloud-html5-canvas").attr({ $("#g-tag-cloud-html5-canvas").attr({
'width': $("#g-tag-cloud-html5").width(), 'width' : Math.floor($("#g-tag-cloud-html5").width()*<?= $width ?>),
'height': $("#g-tag-cloud-html5").width()*<?= $height ?> 'height': Math.floor($("#g-tag-cloud-html5").width()*<?= $height ?>)
}); });
// start g-tag-cloud-html5-canvas // start g-tag-cloud-html5-canvas

View File

@ -1,12 +1,14 @@
<?php defined("SYSPATH") or die("No direct script access.") ?> <?php defined("SYSPATH") or die("No direct script access.") ?>
<!--[if lt IE 9]><?= $theme->script("excanvas.compiled.js"); ?><![endif]--> <!--[if lt IE 9]>
<?= html::script(gallery::find_file("js", "excanvas.compiled.js", false)) ?>
<![endif]-->
<script type="text/javascript"> <script type="text/javascript">
function redraw() { function redraw() {
// set g-tag-cloud-html5-page-canvas size // set g-tag-cloud-html5-page-canvas size
$("#g-tag-cloud-html5-page-canvas").attr({ $("#g-tag-cloud-html5-page-canvas").attr({
'height': Math.min( $(window).height()*0.75, $("#g-tag-cloud-html5-page").width() ), 'width' : Math.floor(Math.min( $(window).height()*<?= $width ?>, $("#g-tag-cloud-html5-page").width() )),
'width': Math.min( $(window).height()*0.95, $("#g-tag-cloud-html5-page").width() ) 'height': Math.floor( $(window).height()*<?= $height ?> )
}); });
// start g-tag-cloud-html5-page-canvas // start g-tag-cloud-html5-page-canvas