Skip to content

Commit

Permalink
Merge branch 'kohana_3' of github.com:gallery/gallery3 into kohana_3
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed May 31, 2013
2 parents a2f41e5 + 53dde68 commit 2fd03bd
Show file tree
Hide file tree
Showing 55 changed files with 648 additions and 437 deletions.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

case "upgrade":
case "package":
$_SERVER["argv"] = array("index.php", "{$arg_1}r/$arg_1");
$_SERVER["PATH_INFO"] = "/{$arg_1}r/$arg_1";
define("TEST_MODE", 0);
define("VARPATH", realpath("var") . "/");
break;
Expand Down
1 change: 1 addition & 0 deletions installer/init_var.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<?php
!file_exists(VARPATH . "albums") && mkdir(VARPATH . "albums");
!file_exists(VARPATH . "cache") && mkdir(VARPATH . "cache");
!file_exists(VARPATH . "logs") && mkdir(VARPATH . "logs");
!file_exists(VARPATH . "modules") && mkdir(VARPATH . "modules");
!file_exists(VARPATH . "resizes") && mkdir(VARPATH . "resizes");
Expand Down
11 changes: 6 additions & 5 deletions installer/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ CREATE TABLE {graphics_rules} (
PRIMARY KEY (`id`)
) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}','gallery','gallery_graphics::resize',100,'thumb');
INSERT INTO {graphics_rules} VALUES (2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:640;s:6:\"master\";i:2;}','gallery','gallery_graphics::resize',100,'resize');
INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:4;}','gallery','GalleryGraphics::resize',100,'thumb');
INSERT INTO {graphics_rules} VALUES (2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:640;s:6:\"master\";i:4;}','gallery','GalleryGraphics::resize',100,'resize');
DROP TABLE IF EXISTS {groups};
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
Expand Down Expand Up @@ -245,7 +245,7 @@ CREATE TABLE {modules} (
KEY `weight` (`weight`)
) AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO {modules} VALUES (1,1,'gallery',59,1);
INSERT INTO {modules} VALUES (1,1,'gallery',60,1);
INSERT INTO {modules} VALUES (2,1,'purifier',3,2);
INSERT INTO {modules} VALUES (3,1,'user',4,3);
INSERT INTO {modules} VALUES (4,1,'comment',8,4);
Expand All @@ -254,7 +254,7 @@ INSERT INTO {modules} VALUES (6,1,'info',2,6);
INSERT INTO {modules} VALUES (7,1,'rss',1,7);
INSERT INTO {modules} VALUES (8,1,'search',1,8);
INSERT INTO {modules} VALUES (9,1,'slideshow',2,9);
INSERT INTO {modules} VALUES (10,1,'tag',3,10);
INSERT INTO {modules} VALUES (10,1,'tag',4,10);
DROP TABLE IF EXISTS {outgoing_translations};
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
Expand Down Expand Up @@ -314,8 +314,9 @@ DROP TABLE IF EXISTS {tags};
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE {tags} (
`id` int(9) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`count` int(10) unsigned NOT NULL DEFAULT '0',
`name` varchar(128) NOT NULL,
`slug` varchar(128) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) DEFAULT CHARSET=utf8;
Expand Down
2 changes: 1 addition & 1 deletion modules/akismet/tests/Akismet_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function test_validate_key_request() {
public function test_comment_check_request() {
// First, we need a test comment.
$comment = ORM::factory("Comment");
$comment->item_id = Item::root()->id;
$comment->item_id = Item::ROOT_ID;
$comment->author_id = Identity::guest()->id;
$comment->text = "This is a comment";
$comment->guest_name = static::$test_author;
Expand Down
2 changes: 1 addition & 1 deletion modules/comment/classes/Comment/Hook/CommentRss.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static function feed($feed_id, $offset, $limit, $id) {
"thumb_width" => $item->thumb_width,
"item_uri" => URL::abs_site("{$item->type}s/$item->id"),
"title" => (
($item->id == Item::root()->id) ?
($item->is_root()) ?
HTML::purify($item->title) :
t("%site_title - %item_title",
array("site_title" => Item::root()->title,
Expand Down
4 changes: 2 additions & 2 deletions modules/comment/tests/Comment_Model_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function teardown() {
public function test_guest_name_and_email_is_required() {
try {
$comment = ORM::factory("Comment");
$comment->item_id = Item::root()->id;
$comment->item_id = Item::ROOT_ID;
$comment->author_id = Identity::guest()->id;
$comment->text = "text";
$comment->server_name = "server_name";
Expand All @@ -42,7 +42,7 @@ public function test_guest_name_and_email_is_required() {
public function test_guest_email_must_be_well_formed() {
try {
$comment = ORM::factory("Comment");
$comment->item_id = Item::root()->id;
$comment->item_id = Item::ROOT_ID;
$comment->author_id = Identity::guest()->id;
$comment->guest_name = "guest";
$comment->guest_email = "bogus";
Expand Down
4 changes: 2 additions & 2 deletions modules/comment/tests/Comment_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function teardown() {

public function test_create_comment_for_guest() {
$comment = ORM::factory("Comment");
$comment->item_id = Item::root()->id;
$comment->item_id = Item::ROOT_ID;
$comment->text = "text";
$comment->author_id = Identity::guest()->id;
$comment->guest_name = "name";
Expand Down Expand Up @@ -91,7 +91,7 @@ public function test_create_comment_for_user() {
$admin = Identity::admin_user();

$comment = ORM::factory("Comment");
$comment->item_id = Item::root()->id;
$comment->item_id = Item::ROOT_ID;
$comment->text = "text";
$comment->author_id = $admin->id;
$comment->save();
Expand Down
23 changes: 23 additions & 0 deletions modules/formo/classes/Formo/Core/Formo.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,29 @@ public function add_rules( array $array)
return $this;
}

/**
* Add a single rule accross a group of fields
*
* @access public
* @param array $rule
* @param array $fields
* @return void
*/
public function add_rule_fields( array $rule, array $fields)
{
foreach ($fields as $alias)
{
$field = $this->find($alias);

if ($field)
{
$field->add_rule($rule);
}
}

return $this;
}

/**
* Add rules for multiple fields
*
Expand Down
2 changes: 1 addition & 1 deletion modules/g2_import/classes/G2Import/Controller/G2.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function action_map() {

$tag = ORM::factory("Tag")->where("name", "=", $tag_name)->find();
if ($tag->loaded()) {
Item::set_display_context_callback("Controller_Tag::get_display_context", $tag->id);
Item::set_display_context_callback("Controller_Tags::get_display_context", $tag->id);
// We want to show the item as part of the tag virtual album. Most of this code is below; we'll
// change $path and $view to let it fall through
$view = "";
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/classes/Gallery/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static function deny($group, $perm_name, $item) {
* @param Model_Item $item
*/
static function reset($group, $perm_name, $item) {
if ($item->id == 1) {
if ($item->is_root()) {
throw new Access_Exception("Cant reset permissions on root album");
}
static::_set($group, $perm_name, $item, static::INHERIT);
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/classes/Gallery/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($title, $url) {
* @return array Breadcrumb instances
*/
static function array_from_item_parents($item) {
if ($item->id == Item::root()->id) {
if ($item->is_root()) {
return array();
}

Expand Down
27 changes: 8 additions & 19 deletions modules/gallery/classes/Gallery/Controller/FileProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,30 @@ public function action_index() {
// to this controller (e.g. "/gallery3/index.php/file_proxy/index/foo.jpg"), in which case
// type would be empty.
if ($type != "resizes" && $type != "albums" && $type != "thumbs") {
$e = HTTP_Exception::factory(404);
$e->test_fail_code = 2;
throw $e;
$code = $type ? 2 : 1; // 1 is no type at all, 2 is invalid type
throw HTTP_Exception::factory(404, TEST_MODE ? $code : null);
}

// Get the item model using the path and type (which corresponds to a var subdir)
$item = Item::find_by_path($path, $type);

if (!$item->loaded()) {
$e = HTTP_Exception::factory(404);
$e->test_fail_code = 3;
throw $e;
throw HTTP_Exception::factory(404, TEST_MODE ? 3 : null);
}

// Make sure we have access to the item
if (!Access::can("view", $item)) {
$e = HTTP_Exception::factory(404);
$e->test_fail_code = 4;
throw $e;
throw HTTP_Exception::factory(404, TEST_MODE ? 4 : null);
}

// Make sure we have view_full access to the original
if ($type == "albums" && !Access::can("view_full", $item)) {
$e = HTTP_Exception::factory(404);
$e->test_fail_code = 5;
throw $e;
throw HTTP_Exception::factory(404, TEST_MODE ? 5 : null);
}

// Don't try to load a directory
if ($type == "albums" && $item->is_album()) {
$e = HTTP_Exception::factory(404);
$e->test_fail_code = 6;
throw $e;
throw HTTP_Exception::factory(404, TEST_MODE ? 6 : null);
}

// Note: this code is roughly duplicated in Hook_Rest_Data, so if you modify this, please look to
Expand All @@ -92,9 +83,7 @@ public function action_index() {
}

if (!file_exists($file)) {
$e = HTTP_Exception::factory(404);
$e->test_fail_code = 7;
throw $e;
throw HTTP_Exception::factory(404, TEST_MODE ? 7 : null);
}

if (Gallery::show_profiler()) {
Expand All @@ -118,7 +107,7 @@ public function action_index() {
}

if (TEST_MODE) {
return $file;
$this->response->body($file);
} else {
// Send the file as the response. The filename will be set automatically from the path.
// Note: send_file() will automatically halt script execution after sending the file.
Expand Down
6 changes: 4 additions & 2 deletions modules/gallery/classes/Gallery/Controller/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function action_edit() {
Module::event("item_edit_form", $item, $form);

// We can't edit the root item's name or slug.
if ($item->id == 1) {
if ($item->is_root()) {
$form->item->name
->attr("type", "hidden")
->add_rule("equals", array(":value", $item->name));
Expand Down Expand Up @@ -455,7 +455,7 @@ public function action_dimensions() {
* @see Item::get_display_context_callback()
* @see Item::clear_display_context_callback()
* @see Controller_Search::get_display_context()
* @see Controller_Tag::get_display_context()
* @see Controller_Tags::get_display_context()
*/
public static function get_display_context($item) {
$where = array(array("type", "!=", "album"));
Expand Down Expand Up @@ -526,6 +526,7 @@ public static function item_add_callback($item_group) {

/**
* Get form error messages for the item group. This is a helper function for the edit/add forms.
* @see Controller_Admin_Tags::action_edit_slug(), which uses some of the same messages.
*/
public static function get_form_error_messages($type) {
// Define all of the error messages.
Expand Down Expand Up @@ -587,6 +588,7 @@ public static function get_form_error_messages($type) {

/**
* Get form labels for the item group. This is a helper function for the edit/add forms.
* @see Controller_Admin_Tags::action_edit_slug(), which uses some of the same labels.
*/
public static function get_form_labels($type) {
// Define all of the labels.
Expand Down
11 changes: 7 additions & 4 deletions modules/gallery/classes/Gallery/Controller/Packager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function _reset() {
foreach (Database::instance()->list_tables() as $table) {
Database::instance()->query(Database::DROP, "DROP TABLE IF EXISTS {{$table}}");
}
ORM::reinitialize();

// Clean out data
System::unlink_dir(VARPATH . "uploads");
Expand Down Expand Up @@ -94,9 +95,9 @@ protected function _dump_database() {
}
$command = sprintf(
"mysqldump --compact --skip-extended-insert --add-drop-table %s %s %s %s > $sql_file",
escapeshellarg("-h{$conn['host']}"),
escapeshellarg("-u{$conn['user']}"),
$conn['pass'] ? escapeshellarg("-p{$conn['pass']}") : "",
escapeshellarg("-h{$conn['hostname']}"),
escapeshellarg("-u{$conn['username']}"),
$conn['password'] ? escapeshellarg("-p{$conn['password']}") : "",
escapeshellarg($conn['database']));
exec($command, $output, $status);
if ($status) {
Expand All @@ -109,7 +110,7 @@ protected function _dump_database() {

// Post-process the sql file
$buf = "";
$root = ORM::factory("Item", 1);
$root = Item::root();
$root_created_timestamp = $root->created;
$root_updated_timestamp = $root->updated;
$table_name = "";
Expand Down Expand Up @@ -162,6 +163,8 @@ protected function _dump_var() {
continue;
} else if (basename($path) == "logs" && $basename != ".htaccess") {
continue;
} else if (strpos($name, Kohana::$cache_dir . "/HTML") === 0) { // HTMLPurifier cache
continue;
}

if ($file->isDir()) {
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/classes/Gallery/Hook/GalleryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static function site_menu($menu, $theme, $item_css_selector) {
->url(URL::site("items/rotate/$item->id/cw?csrf=$csrf")));
}

if ($item->id != Item::root()->id) {
if (!$item->is_root()) {
$parent = $item->parent;
if (Access::can("edit", $parent)) {
// We can't make this item the highlight if it's an album with no album cover, or if it's
Expand Down
37 changes: 31 additions & 6 deletions modules/gallery/classes/Gallery/Hook/GalleryInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ static function install() {
"sort_column", "sort_order", "thumb_dirty", "title", "type", "updated", "weight"))
->values(array($now, "", 1, 1, 0, 1, 2, "weight", "ASC", 1, "Gallery", "album", $now, 1))
->execute();
$root = ORM::factory("Item", 1);
Access::add_item($root);
Access::add_item(Item::root());

Module::set_var("gallery", "active_site_theme", "wind");
Module::set_var("gallery", "active_admin_theme", "admin_wind");
Expand Down Expand Up @@ -842,10 +841,36 @@ static function upgrade($version) {
Module::set_version("gallery", $version = 59);
}

// @TODO for the next upgrade - Image::AUTO in K2 was "2" and now in K3 it's "4" so we have to
// upgrade all graphics rules accordingly; "gallery_graphics" should be removed/renamed in the
// graphics rules definitions; "purifier" should be activated (3.1.x requires v2, 3.0.x could
// have had v1).
if ($version == 59) {
// In v60 we updated the graphics rules for Kohana 3. In particular, the class name has
// changed from "gallery_graphics" to "GalleryGraphics" and the image master constants
// have changed.

// Define how Kohana 2 image master constants (1-4) are mapped to Kohana 3 constants.
$image_master_translation = array(
1 => Image::NONE,
2 => Image::AUTO,
3 => Image::HEIGHT,
4 => Image::WIDTH
);

// Update all graphics rules that still have the old class name from Kohana 2.
foreach (ORM::factory("GraphicsRule")
->where("operation", "LIKE", "gallery_graphics::%")
->find_all() as $rule) {
$args = unserialize($rule->args);
if (isset($args["master"])) {
$args["master"] = $image_master_translation[$args["master"]];
$rule->args = serialize($args);
}
$rule->operation = str_replace("gallery_graphics::", "GalleryGraphics::", $rule->operation);
$rule->save();
}
Module::set_version("gallery", $version = 60);
}

// @todo: still need special upgrade to fix "database.php" config file and activate "purifier"
// module (3.1.x requires v2, 3.0.x could have had v1).
}

static function uninstall() {
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/classes/Gallery/Hook/GalleryRss.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static function feed($feed_id, $offset, $limit, $id) {
->find_all();
$feed->max_pages = ceil(
$item->descendants->viewable()->where("type", "=", "photo")->count_all() / $limit);
if ($item->id == Item::root()->id) {
if ($item->is_root()) {
$feed->title = HTML::purify($item->title);
} else {
$feed->title = t("%site_title - %item_title",
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/classes/Gallery/Hook/GalleryTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static function fix($task) {
switch ($state) {
case static::FIX_STATE_START_MPTT:
$task->set_data("ptr", $ptr = 1);
$task->set_data("stack", Item::root()->id . "L1");
$task->set_data("stack", Item::ROOT_ID . "L1");
$state = static::FIX_STATE_RUN_MPTT;
break;

Expand Down
Loading

0 comments on commit 2fd03bd

Please sign in to comment.