1
0

Merge commit 'upstream/master'

This commit is contained in:
Romain LE DISEZ 2009-08-04 16:57:04 +02:00
commit 774712c428
13 changed files with 416 additions and 428 deletions

View File

@ -37,6 +37,7 @@ class Admin_EmbedLinks_Controller extends Admin_Controller {
$HTMLButton = false;
$BBCodeButton = false;
$FullURLButton = false;
$InPageLinks = false;
$DialogLinks = false;
@ -47,6 +48,9 @@ class Admin_EmbedLinks_Controller extends Admin_Controller {
if ($linkOpts_array[$i] == "BBCode") {
$BBCodeButton = true;
}
if ($linkOpts_array[$i] == "FullURL") {
$FullURLButton = true;
}
}
for ($i = 0; $i < count($displayType_array); $i++) {
if ($displayType_array[$i] == "InPageLinks") {
@ -60,6 +64,7 @@ class Admin_EmbedLinks_Controller extends Admin_Controller {
// Save Settings.
module::set_var("embedlinks", "HTMLCode", $HTMLButton);
module::set_var("embedlinks", "BBCode", $BBCodeButton);
module::set_var("embedlinks", "FullURL", $FullURLButton);
module::set_var("embedlinks", "InPageLinks", $InPageLinks);
module::set_var("embedlinks", "DialogLinks", $DialogLinks);
message::success(t("Your Selection Has Been Saved."));
@ -79,6 +84,7 @@ class Admin_EmbedLinks_Controller extends Admin_Controller {
// Make an array for the different types of link codes.
$linkCodes["HTMLCode"] = array("Show HTML Links", module::get_var("embedlinks", "HTMLCode"));
$linkCodes["BBCode"] = array("Show BBCode Links", module::get_var("embedlinks", "BBCode"));
$linkCodes["FullURL"] = array("Show the full URL", module::get_var("embedlinks", "FullURL"));
// Make an array for the different methods of displaying the links.
$linkDisplays["InPageLinks"] = array("Show Links In The Actual Page", module::get_var("embedlinks", "InPageLinks"));

View File

@ -100,4 +100,38 @@ class EmbedLinks_Controller extends Controller {
$view->details = $linkArray;
print $view;
}
public function showfullurl($item_id) {
// Generate the Dialog Box for the URLs to the items thumb, resize and fullsize image.
$item = ORM::factory("item", $item_id);
access::required("view", $item);
// If the current page is an album, only display a URL field,
// or else display a couple of fields.
if ($item->is_album()) {
$linkArray[0] = array("Album URL:", url::abs_site("{$item->type}s/{$item->id}"));
$linkArray[1] = array("Thumbnail:", $item->thumb_url(true));
$linkTitles[0] = array("URLs:", 2);
} else {
// Link to the current page.
$linkArray[0] = array("This Page:", url::abs_site("{$item->type}s/{$item->id}"));
$linkArray[1] = array("Thumbnail:", $item->thumb_url(true));
$linkArray[2] = array("Resized:", $item->resize_url(true));
// If the visitor has suficient privlidges to see the fullsized
// version of the current image, then display its URL.
if (access::can("view_full", $item)) {
$linkArray[3] = array("Fullsize:", $item->file_url(true));
$linkTitles[0] = array("URLs:", 4);
} else {
$linkTitles[0] = array("URLs:", 3);
}
}
$view = new View("embedlinks_fullurldialog.html");
$view->titles = $linkTitles;
$view->details = $linkArray;
print $view;
}
}

View File

@ -5,7 +5,7 @@ input[type="text"] {
}
</style>
<? if (module::get_var("embedlinks", "HTMLCode")) { ?>
<table class="gMetadata">
<table class="gEmbedLinks">
<tbody>
<tr>
<th colspan="2"><?= t("HTML Links:") ?></th>
@ -25,7 +25,7 @@ input[type="text"] {
<? } ?>
<? if (module::get_var("embedlinks", "BBCode")) { ?>
<table class="gMetadata">
<table class="gEmbedLinks">
<tbody>
<tr>
<th colspan="2"><?= t("BBCode Links:") ?></th>
@ -43,3 +43,24 @@ input[type="text"] {
</tbody>
</table>
<? } ?>
<? if (module::get_var("embedlinks", "FullURL")) { ?>
<table class="gEmbedLinks">
<tbody>
<tr>
<th colspan="2"><?= t("URLs:") ?></th>
</tr>
<tr>
<th><?= t("Album URL:") ?></th>
<td><input onclick="this.focus(); this.select();" name="forum" type="text" readonly="true" value="<?= url::abs_site("{$item->type}s/{$item->id}") ?>" /></td>
</tr>
<tr>
<th><?= t("Thumbnail:") ?></th>
<td><input onclick="this.focus(); this.select();" name="forum" type="text" readonly="true" size="85" value="<?= $item->thumb_url(true) ?>" /></td>
</tr>
</tbody>
</table>
<? } ?>

View File

@ -0,0 +1,24 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<style>
input[type="text"] {
width: 95%;
}
</style>
<h1 style="display: none;"><?= t("URLs") ?></h1>
<div id="gEmbedLinksFullURLData">
<? $counter = 0; ?>
<? for ($i = 0; $i < count($titles); $i++): ?>
<table class="gLinksFullURL" >
<thead><tr><th colspan="2"><?= t($titles[$i][0]) ?></th></thead>
<tbody>
<? for ($j = $counter; $j < $titles[$i][1]+$counter; $j++): ?>
<tr>
<td width="100"><?= t($details[$j][0]) ?></td>
<td><input type="text" onclick="this.focus(); this.select();" value="<?= $details[$j][1] ?>" readonly></td>
</tr>
<? endfor ?>
<? $counter+= $titles[$i][1]; ?>
</tbody>
</table>
<? endfor ?>
</div>

View File

@ -7,7 +7,7 @@ input[type="text"] {
<? if (module::get_var("embedlinks", "HTMLCode")) { ?>
<h3 align="center"><?= t("HTML Links")?></h3>
<table class="gMetadata">
<table class="gEmbedLink">
<tbody>
<tr>
<th colspan="2"><?= t("Link To This Page:") ?></th>
@ -74,7 +74,7 @@ input[type="text"] {
<? if (module::get_var("embedlinks", "BBCode")) { ?>
<h3 align="center"><?= t("BBCode Links")?></h3>
<table class="gMetadata">
<table class="gEmbedLinks">
<tbody>
<tr>
<th colspan="2"><?= t("Link To This Page:") ?></th>
@ -137,4 +137,44 @@ input[type="text"] {
</tbody>
</table>
<? } ?>
<? if (module::get_var("embedlinks", "FullURL")) { ?>
<h3 align="center"><?= t("URLs")?></h3>
<table class="gEmbedLinks">
<tbody>
<tr>
<th><?= t("This Page:") ?></th>
<td><input type="text" value="<?= url::abs_site("{$item->type}s/{$item->id}") ?>" onclick="this.focus(); this.select();" readonly></td>
</tr>
<tr>
<th><?= t("Thumbnail:") ?></th>
<td><input type="text" value="<?= $item->thumb_url(true) ?>" onclick="this.focus(); this.select();" readonly></td>
</tr>
<tr>
<th><?= t("Resized:") ?></th>
<td><input type="text" value="<?= $item->resize_url(true) ?>" onclick="this.focus(); this.select();" readonly></td>
</tr>
<? if (access::can("view_full", $item)) { ?>
<tr>
<th><?= t("Fullsize:") ?></th>
<td><input type="text" value="<?= $item->file_url(true) ?>" onclick="this.focus(); this.select();" readonly></td>
</tr>
<? } ?>
</tbody>
</table>
<? } ?>

View File

@ -13,4 +13,12 @@
<span class="ui-icon ui-icon-info"></span>
<?= t("Show BBCode") ?>
</a>
<? } ?>
<? if (module::get_var("embedlinks", "FullURL")) { ?>
<a href="<?= url::site("embedlinks/showfullurl/{$item->id}") ?>" title="<?= t("URLs") ?>"
class="gDialogLink gButtonLink ui-icon-left ui-state-default ui-corner-all">
<span class="ui-icon ui-icon-info"></span>
<?= t("Show URLs") ?>
</a>
<? } ?>

View File

@ -1,423 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class graphics_Core {
private static $init;
/**
* Add a new graphics rule.
*
* Rules are applied to targets (thumbnails and resizes) in priority order. Rules are functions
* in the graphics class. So for example, the following rule:
*
* graphics::add_rule("gallery", "thumb", "resize",
* array("width" => 200, "height" => 200, "master" => Image::AUTO), 100);
*
* Specifies that "gallery" is adding a rule to resize thumbnails down to a max of 200px on
* the longest side. The gallery module adds default rules at a priority of 100. You can set
* higher and lower priorities to perform operations before or after this fires.
*
* @param string $module_name the module that added the rule
* @param string $target the target for this operation ("thumb" or "resize")
* @param string $operation the name of the operation
* @param array $args arguments to the operation
* @param integer $priority the priority for this rule (lower priorities are run first)
*/
static function add_rule($module_name, $target, $operation, $args, $priority) {
$rule = ORM::factory("graphics_rule");
$rule->module_name = $module_name;
$rule->target = $target;
$rule->operation = $operation;
$rule->priority = $priority;
$rule->args = serialize($args);
$rule->active = true;
$rule->save();
self::mark_dirty($target == "thumb", $target == "resize");
}
/**
* Remove any matching graphics rules
* @param string $module_name the module that added the rule
* @param string $target the target for this operation ("thumb" or "resize")
* @param string $operation the name of the operation
*/
static function remove_rule($module_name, $target, $operation) {
ORM::factory("graphics_rule")
->where("module_name", $module_name)
->where("target", $target)
->where("operation", $operation)
->delete_all();
self::mark_dirty($target == "thumb", $target == "resize");
}
/**
* Remove all rules for this module
* @param string $module_name
*/
static function remove_rules($module_name) {
$status = Database::instance()->delete("graphics_rules", array("module_name" => $module_name));
if (count($status)) {
self::mark_dirty(true, true);
}
}
/**
* Activate the rules for this module, typically done when the module itself is deactivated.
* Note that this does not mark images as dirty so that if you deactivate and reactivate a
* module it won't cause all of your images to suddenly require a rebuild.
*/
static function activate_rules($module_name) {
Database::instance()
->update("graphics_rules",array("active" => true), array("module_name" => $module_name));
}
/**
* Deactivate the rules for this module, typically done when the module itself is deactivated.
* Note that this does not mark images as dirty so that if you deactivate and reactivate a
* module it won't cause all of your images to suddenly require a rebuild.
*/
static function deactivate_rules($module_name) {
Database::instance()
->update("graphics_rules",array("active" => false), array("module_name" => $module_name));
}
/**
* Rebuild the thumb and resize for the given item.
* @param Item_Model $item
* @return true on successful generation
*/
static function generate($item) {
if ($item->is_album()) {
if (!$cover = $item->album_cover()) {
return false;
}
$input_file = $cover->file_path();
$input_item = $cover;
} else {
$input_file = $item->file_path();
$input_item = $item;
}
if ($item->thumb_dirty) {
$ops["thumb"] = $item->thumb_path();
}
if ($item->resize_dirty && !$item->is_album() && !$item->is_movie()) {
$ops["resize"] = $item->resize_path();
}
if (empty($ops)) {
$item->thumb_dirty = 0;
$item->resize_dirty = 0;
$item->save();
return true;
}
try {
foreach ($ops as $target => $output_file) {
if ($input_item->is_movie()) {
// Convert the movie to a JPG first
$output_file = preg_replace("/...$/", "jpg", $output_file);
try {
movie::extract_frame($input_file, $output_file);
} catch (Exception $e) {
// Assuming this is MISSING_FFMPEG for now
copy(MODPATH . "gallery/images/missing_movie.png", $output_file);
}
$working_file = $output_file;
} else {
$working_file = $input_file;
}
foreach (ORM::factory("graphics_rule")
->where("target", $target)
->where("active", true)
->orderby("priority", "asc")
->find_all() as $rule) {
$args = array($working_file, $output_file, unserialize($rule->args));
call_user_func_array(array("graphics", $rule->operation), $args);
$working_file = $output_file;
}
}
if (!empty($ops["thumb"])) {
$dims = getimagesize($item->thumb_path());
$item->thumb_width = $dims[0];
$item->thumb_height = $dims[1];
$item->thumb_dirty = 0;
}
if (!empty($ops["resize"])) {
$dims = getimagesize($item->resize_path());
$item->resize_width = $dims[0];
$item->resize_height = $dims[1];
$item->resize_dirty = 0;
}
$item->save();
} catch (Exception $e) {
// Something went wrong rebuilding the image. Leave it dirty and move on.
// @todo we should handle this better.
Kohana::log("error", "Caught exception rebuilding image: {$item->title}\n" .
$e->getMessage() . "\n" . $e->getTraceAsString());
return false;
}
return true;
}
/**
* Resize an image. Valid options are width, height and master. Master is one of the Image
* master dimension constants.
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function resize($input_file, $output_file, $options) {
if (!self::$init) {
self::init_toolkit();
}
if (@filesize($input_file) == 0) {
throw new Exception("@todo EMPTY_INPUT_FILE");
}
$dims = getimagesize($input_file);
if (max($dims[0], $dims[1]) < min($options["width"], $options["height"])) {
// Image would get upscaled; do nothing
copy($input_file, $output_file);
} else {
Image::factory($input_file)
->resize($options["width"], $options["height"], $options["master"])
->quality(module::get_var("gallery", "image_quality"))
->save($output_file);
}
}
/**
* Rotate an image. Valid options are degrees
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function rotate($input_file, $output_file, $options) {
if (!self::$init) {
self::init_toolkit();
}
// BEGIN rWatcher MOD:
// If $input_file is located in VARPATH/albums/ then assume its a fullsize photo.
if (strncmp($input_file, VARPATH . "albums/", strlen(VARPATH . "albums/")) == 0) {
// Figure out where the original copy should be stashed at.
$temp_path = str_replace(VARPATH . "albums/", "", $input_file);
$original_image = VARPATH . "original/" . $temp_path;
$individual_dirs = split("[/\]", $temp_path);
// If any original file does not already exist, then create a folder structure
// similar to that found in VARPATH/albums/ and copy the photo over before
// rotating it.
if (!file_exists($original_image)) {
$new_img_path = VARPATH . "original/";
for($i = 0; $i < count($individual_dirs)-1; $i++) {
$new_img_path = $new_img_path . "/" . $individual_dirs[$i];
if(!file_exists($new_img_path)) {
@mkdir($new_img_path);
}
}
copy($input_file, $original_image);
}
}
// END rWatcher MOD.
Image::factory($input_file)
->quality(module::get_var("gallery", "image_quality"))
->rotate($options["degrees"])
->save($output_file);
}
/**
* Overlay an image on top of the input file.
*
* Valid options are: file, mime_type, position, transparency_percent, padding
*
* Valid positions: northwest, north, northeast,
* west, center, east,
* southwest, south, southeast
*
* padding is in pixels
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function composite($input_file, $output_file, $options) {
if (!self::$init) {
self::init_toolkit();
}
list ($width, $height) = getimagesize($input_file);
list ($w_width, $w_height) = getimagesize($options["file"]);
$pad = isset($options["padding"]) ? $options["padding"] : 10;
$top = $pad;
$left = $pad;
$y_center = max($height / 2 - $w_height / 2, $pad);
$x_center = max($width / 2 - $w_width / 2, $pad);
$bottom = max($height - $w_height - $pad, $pad);
$right = max($width - $w_width - $pad, $pad);
switch ($options["position"]) {
case "northwest": $x = $left; $y = $top; break;
case "north": $x = $x_center; $y = $top; break;
case "northeast": $x = $right; $y = $top; break;
case "west": $x = $left; $y = $y_center; break;
case "center": $x = $x_center; $y = $y_center; break;
case "east": $x = $right; $y = $y_center; break;
case "southwest": $x = $left; $y = $bottom; break;
case "south": $x = $x_center; $y = $bottom; break;
case "southeast": $x = $right; $y = $bottom; break;
}
Image::factory($input_file)
->composite($options["file"], $x, $y, $options["transparency"])
->quality(module::get_var("gallery", "image_quality"))
->save($output_file);
}
/**
* Return a query result that locates all items with dirty images.
* @return Database_Result Query result
*/
static function find_dirty_images_query() {
return Database::instance()->query(
"SELECT `id` FROM {items} " .
"WHERE ((`thumb_dirty` = 1 AND (`type` <> 'album' OR `album_cover_item_id` IS NOT NULL))" .
" OR (`resize_dirty` = 1 AND `type` = 'photo')) " .
" AND `id` != 1");
}
/**
* Mark thumbnails and resizes as dirty. They will have to be rebuilt.
*/
static function mark_dirty($thumbs, $resizes) {
if ($thumbs || $resizes) {
$db = Database::instance();
$fields = array();
if ($thumbs) {
$fields["thumb_dirty"] = 1;
}
if ($resizes) {
$fields["resize_dirty"] = 1;
}
$db->update("items", $fields, true);
}
$count = self::find_dirty_images_query()->count();
if ($count) {
site_status::warning(
t2("One of your photos is out of date. <a %attrs>Click here to fix it</a>",
"%count of your photos are out of date. <a %attrs>Click here to fix them</a>",
$count,
array("attrs" => sprintf(
'href="%s" class="gDialogLink"',
url::site("admin/maintenance/start/gallery_task::rebuild_dirty_images?csrf=__CSRF__")))),
"graphics_dirty");
}
}
/**
* Detect which graphics toolkits are available on this system. Return an array of key value
* pairs where the key is one of gd, imagemagick, graphicsmagick and the value is information
* about that toolkit. For GD we return the version string, and for ImageMagick and
* GraphicsMagick we return the path to the directory containing the appropriate binaries.
*/
static function detect_toolkits() {
$gd = function_exists("gd_info") ? gd_info() : array();
$exec = function_exists("exec");
if (!isset($gd["GD Version"])) {
$gd["GD Version"] = false;
}
putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin:/opt/bin");
return array("gd" => $gd,
"imagemagick" => $exec ? dirname(exec("which convert")) : false,
"graphicsmagick" => $exec ? dirname(exec("which gm")) : false);
}
/**
* This needs to be run once, after the initial install, to choose a graphics toolkit.
*/
static function choose_default_toolkit() {
// Detect a graphics toolkit
$toolkits = graphics::detect_toolkits();
foreach (array("imagemagick", "graphicsmagick", "gd") as $tk) {
if ($toolkits[$tk]) {
module::set_var("gallery", "graphics_toolkit", $tk);
module::set_var("gallery", "graphics_toolkit_path", $tk == "gd" ? "" : $toolkits[$tk]);
break;
}
}
if (!module::get_var("gallery", "graphics_toolkit")) {
site_status::warning(
t("Graphics toolkit missing! Please <a href=\"%url\">choose a toolkit</a>",
array("url" => url::site("admin/graphics"))),
"missing_graphics_toolkit");
}
}
/**
* Choose which driver the Kohana Image library uses.
*/
static function init_toolkit() {
switch(module::get_var("gallery", "graphics_toolkit")) {
case "gd":
Kohana::config_set("image.driver", "GD");
break;
case "imagemagick":
Kohana::config_set("image.driver", "ImageMagick");
Kohana::config_set(
"image.params.directory", module::get_var("gallery", "graphics_toolkit_path"));
break;
case "graphicsmagick":
Kohana::config_set("image.driver", "GraphicsMagick");
Kohana::config_set(
"image.params.directory", module::get_var("gallery", "graphics_toolkit_path"));
break;
}
self::$init = 1;
}
/**
* Verify that a specific graphics function is available with the active toolkit.
* @param string $func (eg rotate, resize)
* @return boolean
*/
static function can($func) {
if (module::get_var("gallery", "graphics_toolkit") == "gd" &&
$func == "rotate" &&
!function_exists("imagerotate")) {
return false;
}
return true;
}
}

View File

@ -18,6 +18,31 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class keeporiginal_event_Core {
static function graphics_rotate($input_file, $output_file, $options) {
// Make a copy of the original fullsized image before rotating it.
// If $input_file is located in VARPATH/albums/ then assume its a fullsize photo.
if (strncmp($input_file, VARPATH . "albums/", strlen(VARPATH . "albums/")) == 0) {
// Figure out where the original copy should be stashed at.
$temp_path = str_replace(VARPATH . "albums/", "", $input_file);
$original_image = VARPATH . "original/" . $temp_path;
$individual_dirs = split("[/\]", $temp_path);
// If any original file does not already exist, then create a folder structure
// similar to that found in VARPATH/albums/ and copy the photo over before
// rotating it.
if (!file_exists($original_image)) {
$new_img_path = VARPATH . "original/";
for($i = 0; $i < count($individual_dirs)-1; $i++) {
$new_img_path = $new_img_path . "/" . $individual_dirs[$i];
if(!file_exists($new_img_path)) {
@mkdir($new_img_path);
}
}
copy($input_file, $original_image);
}
}
}
static function item_before_delete($item) {
// If deleting a photo, make sure the original is deleted as well, if it exists.
if ($item->is_photo()) {

View File

@ -11,6 +11,24 @@
}
}
}
// If $metaTags is empty, use the item's title instead.
if ($metaTags == "") {
$metaTags = p::clean($item->title);
}
$metaDescription = "";
$metaDescription = trim(nl2br(p::purify($item->description)));
// If description is empty, use title instead.
if ($metaDescription == "") {
$metaDescription = p::clean($item->title);
}
// Strip HTML
$metaDescription = strip_tags($metaDescription);
// Strip Line Breaks
$metaDescription = str_replace("\n", " ", $metaDescription);
// Limit Description to 150 characters.
$metaDescription = substr($metaDescription, 0,150);
?>
<META NAME="KEYWORDS" CONTENT="<?= $metaTags ?>">
<META NAME="DESCRIPTION" CONTENT="<?= nl2br(p::purify($item->description)) ?>">
<META NAME="DESCRIPTION" CONTENT="<?= $metaDescription ?>">

View File

@ -0,0 +1,163 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_homes_event_Core {
/**
* Called when a user logs in. This will setup the session with the
* user home if it exists on the database. This means when the page
* is refreshed after logging in the direction can occur.
*/
static function user_login($user) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
if ($home->loaded && $home->home != 0) {
Session::instance()->set("redirect_home", $home->home);
}
}
/**
* called after a log in occurs and when the first gallery is loaded.
* if the home variable exists on the session then a redirect will
* occur to that home and the variable removed from the session to
*/
static function gallery_ready() {
$session = Session::instance();
$home = $session->get("redirect_home");
if ($home) {
// Remove from session to ensure redirect does not occur again
$session->set("redirect_home",null);
url::redirect("albums/$home");
}
}
/**
* Called just before a user is deleted. This will remove the user from
* the user_homes directory.
*/
static function user_before_delete($user) {
ORM::factory("user_home")
->where("id", $user->id)
->delete_all();
}
/**
* Called when admin is adding a user
*/
static function user_add_form_admin($user, $form) {
$form->add_user->dropdown("user_home")
->label(t("Home Gallery"))
->options(self::createGalleryArray())
->selected(0);
}
/**
* Called after a user has been added
*/
static function user_add_form_admin_completed($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
$home->id = $user->id;
$home->home = $form->add_user->user_home->value;
$home->save();
}
/**
* Called when admin is editing a user
*/
static function user_edit_form_admin($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
if ($home->loaded) {
$selected = $home->home;
} else {
$selected = 0;
}
$form->edit_user->dropdown("user_home")
->label(t("Home Gallery"))
->options(self::createGalleryArray())
->selected($selected);
}
/**
* Called after a user had been edited by the admin
*/
static function user_edit_form_admin_completed($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
$home->id = $user->id;
$home->home = $form->edit_user->user_home->value;
$home->save();
}
/**
* Called when user is editing their own form
*/
static function user_edit_form($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
if ($home->loaded) {
$selected = $home->home;
} else {
$selected = 0;
}
$form->edit_user->dropdown("user_home")
->label(t("Home Gallery"))
->options(self::createGalleryArray())
->selected($selected);
}
/**
* Called after a user had been edited by the user
*/
static function user_edit_form_completed($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
$home->id = $user->id;
$home->home = $form->edit_user->user_home->value;
$home->save();
}
/**
* Creates an array of galleries
*/
static function createGalleryArray() {
$array[0] = "none";
$root = ORM::factory("item", 1);
self::tree($root, "", $array);
return $array;
}
/**
* recursive function to build array for drop down list
*/
static function tree($parent, $dashes, &$array) {
if ($parent->id == "1") {
$array[$parent->id] = ORM::factory("item", 1)->title;
} else {
$array[$parent->id] = "$dashes $parent->name";
}
$albums = ORM::factory("item")
->where(array("parent_id" => $parent->id, "type" => "album"))
->orderby(array("title" => "ASC"))
->find_all();
foreach ($albums as $album) {
self::tree($album, "-$dashes", $array);
}
return;
}
}

View File

@ -0,0 +1,47 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_homes_installer {
static function install() {
module::set_version("user_homes", 1);
}
/**
* Installs the table of user homes when the module is installed.
*/
static function activate() {
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {user_homes} (
`id` int(9) NOT NULL,
`home` int(9) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_version("user_homes", 1);
}
/**
* Drops the table of user homes when the module is uninstalled.
*/
static function deactivate() {
$db = Database::instance();
$db->query("DROP TABLE IF EXISTS {user_homes};");
}
}

View File

@ -0,0 +1,22 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class User_home_Model extends ORM {
}

View File

@ -0,0 +1,3 @@
name = "User Homes"
description = "Allows users to have home galleries that they are redirected to when logged in."
version = 1