From 341e062c53c60eab03f36e8e00d3b57829d30b66 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Mon, 30 Apr 2012 18:58:52 -0400 Subject: [PATCH 1/5] Virtual album support for CalendarView. --- .../calendarview/controllers/calendarview.php | 177 ++++++++++-------- .../calendarview/helpers/calendarview.php | 48 +++++ 2 files changed, 142 insertions(+), 83 deletions(-) create mode 100644 3.0/modules/calendarview/helpers/calendarview.php diff --git a/3.0/modules/calendarview/controllers/calendarview.php b/3.0/modules/calendarview/controllers/calendarview.php index d9dfb7d5..d3a52f53 100644 --- a/3.0/modules/calendarview/controllers/calendarview.php +++ b/3.0/modules/calendarview/controllers/calendarview.php @@ -18,17 +18,13 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class CalendarView_Controller extends Controller { - public function calendar($display_year="", $display_user="") { + public function calendar($display_year="", $display_user="-1") { // Draw a calendar for the year specified by $display_year. - // Make sure the function parameters aren't null, - // give them default values if they are. + // Display the current year by default if a year wasn't provided. if ($display_year == "") { $display_year = date('Y'); } - if ($display_user == "") { - $display_user = "-1"; - } // Draw the page. $root = item::root(); @@ -50,26 +46,16 @@ class CalendarView_Controller extends Controller { public function day($display_year, $display_user, $display_month, $display_day) { // Display all images for the specified day. - // Figure out the total number of photos to display. - $day_count = 0; - if ($display_user == "-1") { - $day_count = ORM::factory("item") - ->viewable() - ->where("type", "!=", "album") - ->where("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year)) - ->where("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year)) - ->find_all() - ->count(); - } else { - $day_count = ORM::factory("item") - ->viewable() - ->where("owner_id", "=", $display_user) - ->where("type", "!=", "album") - ->where("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year)) - ->where("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year)) - ->find_all() - ->count(); + // Set up default search conditions for retrieving all photos from the specified day. + $where = array(array("type", "!=", "album")); + if ($display_user != "-1") { + $where[] = array("owner_id", "=", $display_user); } + $where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year)); + $where[] = array("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year)); + + // Figure out the total number of photos to display. + $day_count = calendarview::get_items_count($where); // Figure out paging stuff. $page_size = module::get_var("gallery", "page_size", 9); @@ -83,25 +69,7 @@ class CalendarView_Controller extends Controller { } // Figure out which photos go on this page. - $children = ""; - if ($display_user == "-1") { - $children = ORM::factory("item") - ->viewable() - ->where("type", "!=", "album") - ->where("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year)) - ->where("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year)) - ->order_by("captured", "ASC") - ->find_all($page_size, $offset); - } else { - $children = ORM::factory("item") - ->viewable() - ->where("owner_id", "=", $display_user) - ->where("type", "!=", "album") - ->where("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year)) - ->where("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year)) - ->order_by("captured", "ASC") - ->find_all($page_size, $offset); - } + $children = calendarview::get_items($page_size, $offset, $where); // Create and display the page. $root = item::root(); @@ -121,31 +89,46 @@ class CalendarView_Controller extends Controller { $template->content = new View("dynamic.html"); $template->content->title = t("Photos From ") . date("d", mktime(0, 0, 0, $display_month, $display_day, $display_year)) . " " . t(date("F", mktime(0, 0, 0, $display_month, $display_day, $display_year))) . " " . date("Y", mktime(0, 0, 0, $display_month, $display_day, $display_year)); print $template; + + // Set breadcrumbs on the photo pages to point back to the calendar day view. + item::set_display_context_callback("CalendarView_Controller::get_display_day_context", $display_user, $display_year, $display_month, $display_day); + } + + static function get_display_day_context($item, $display_user, $display_year, $display_month, $display_day) { + // Set up default search conditions for retrieving all photos from the specified day. + $where = array(array("type", "!=", "album")); + if ($display_user != "-1") { + $where[] = array("owner_id", "=", $display_user); + } + $where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year)); + $where[] = array("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year)); + + // Generate breadcrumbs for the photo page. + $root = item::root(); + $breadcrumbs = array( + Breadcrumb::instance($root->title, $root->url())->set_first(), + Breadcrumb::instance($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user)), + Breadcrumb::instance(t(date("F", mktime(0, 0, 0, $display_month, $display_day, $display_year))), url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month)), + Breadcrumb::instance($display_day, url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month . "/" . $display_day)), + Breadcrumb::instance($item->title, $item->url())->set_last() + ); + + return CalendarView_Controller::get_display_context($item, $where, $breadcrumbs); } public function month($display_year, $display_user, $display_month) { // Display all images for the specified month. - // Figure out the total number of photos to display. - $day_count = 0; - if ($display_user == "-1") { - $day_count = ORM::factory("item") - ->viewable() - ->where("type", "!=", "album") - ->where("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year)) - ->where("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year)) - ->find_all() - ->count(); - } else { - $day_count = ORM::factory("item") - ->viewable() - ->where("owner_id", "=", $display_user) - ->where("type", "!=", "album") - ->where("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year)) - ->where("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year)) - ->find_all() - ->count(); + // Set up default search conditions for retrieving all photos from the specified month. + $where = array(array("type", "!=", "album")); + if ($display_user != "-1") { + $where[] = array("owner_id", "=", $display_user); } + $where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year)); + $where[] = array("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year)); + + // Figure out the total number of photos to display. + $day_count = calendarview::get_items_count($where); // Figure out paging stuff. $page_size = module::get_var("gallery", "page_size", 9); @@ -159,25 +142,7 @@ class CalendarView_Controller extends Controller { } // Figure out which photos go on this page. - $children = ""; - if ($display_user == "-1") { - $children = ORM::factory("item") - ->viewable() - ->where("type", "!=", "album") - ->where("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year)) - ->where("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year)) - ->order_by("captured", "ASC") - ->find_all($page_size, $offset); - } else { - $children = ORM::factory("item") - ->viewable() - ->where("owner_id", "=", $display_user) - ->where("type", "!=", "album") - ->where("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year)) - ->where("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year)) - ->order_by("captured", "ASC") - ->find_all($page_size, $offset); - } + $children = calendarview::get_items($page_size, $offset, $where); // Create and display the page. $root = item::root(); @@ -196,6 +161,53 @@ class CalendarView_Controller extends Controller { $template->content = new View("dynamic.html"); $template->content->title = t("Photos From ") . t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))) . " " . date("Y", mktime(0, 0, 0, $display_month, 1, $display_year)); print $template; + + // Set up breadcrumbs for the photo pages to point back to the calendar month view. + item::set_display_context_callback("CalendarView_Controller::get_display_month_context", $display_user, $display_year, $display_month); + } + + static function get_display_month_context($item, $display_user, $display_year, $display_month) { + // Set up default search conditions for retrieving all photos from the specified month. + $where = array(array("type", "!=", "album")); + if ($display_user != "-1") { + $where[] = array("owner_id", "=", $display_user); + } + $where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year)); + $where[] = array("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year)); + + // Generate breadcrumbs for the photo page. + $root = item::root(); + $breadcrumbs = array( + Breadcrumb::instance($root->title, $root->url())->set_first(), + Breadcrumb::instance($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user)), + Breadcrumb::instance(t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))), url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month)), + Breadcrumb::instance($item->title, $item->url())->set_last() + ); + + return CalendarView_Controller::get_display_context($item, $where, $breadcrumbs); + } + + private function get_display_context($item, $where=array(), $breadcrumbs=array()) { + // Set up previous / next / breadcrumbs / etc to point to CalendarView instead of the album. + + // Figure out the photo's position. + $position = calendarview::get_position($item, $where); + + // Figure out the previous and next items. + if ($position > 1) { + list ($previous_item, $ignore, $next_item) = calendarview::get_items(3, $position - 2, $where); + } else { + list ($next_item) = calendarview::get_items(1, $position, $where); + } + + // Figure out the total number of photos. + $sibling_count = calendarview::get_items_count($where); + + return array("position" => $position, + "previous_item" => $previous_item, + "next_item" => $next_item, + "sibling_count" => $sibling_count, + "breadcrumbs" => $breadcrumbs); } private function _get_calenderprefs_form($display_year, $display_user) { @@ -224,7 +236,6 @@ class CalendarView_Controller extends Controller { $valid_years = Array(); $all_photos = ORM::factory("item") ->viewable() - //->where("owner_id", "=", $one_user->id) ->where("type", "!=", "album") ->where("captured", "!=", "") ->order_by("captured", "DESC") diff --git a/3.0/modules/calendarview/helpers/calendarview.php b/3.0/modules/calendarview/helpers/calendarview.php new file mode 100644 index 00000000..4406ed7f --- /dev/null +++ b/3.0/modules/calendarview/helpers/calendarview.php @@ -0,0 +1,48 @@ +viewable() + ->merge_where($where) + ->order_by("captured", "ASC") + ->count_all(); + } + + static function get_items($limit=null, $offset=null, $where=array()) { + // Returns the items identified by $where, up to $limit, and starting at $offset. + return ORM::factory("item") + ->viewable() + ->merge_where($where) + ->order_by("captured", "ASC") + ->find_all($limit, $offset); + } + + static function get_position($item, $where=array()) { + // Get's $item's position within $where. + return ORM::factory("item") + ->viewable() + ->merge_where($where) + ->where("items.id", "<=", $item->id) + ->order_by("captured", "ASC") + ->count_all(); + } +} From c72024db1d527185b40dc76a869f446d621d72dc Mon Sep 17 00:00:00 2001 From: rWatcher Date: Wed, 16 May 2012 21:11:06 -0400 Subject: [PATCH 2/5] Swith views to page.html and dynamic.html and use Gallery's breadcrumb object. --- .../tag_albums/controllers/tag_albums.php | 143 ++++++++------- .../libraries/Tag_Albums_Breadcrumb.php | 31 ---- 3.0/modules/tag_albums/views/calpage.html.php | 167 ------------------ .../views/tag_albums_album.html.php | 50 ------ 4 files changed, 71 insertions(+), 320 deletions(-) delete mode 100644 3.0/modules/tag_albums/libraries/Tag_Albums_Breadcrumb.php delete mode 100644 3.0/modules/tag_albums/views/calpage.html.php delete mode 100644 3.0/modules/tag_albums/views/tag_albums_album.html.php diff --git a/3.0/modules/tag_albums/controllers/tag_albums.php b/3.0/modules/tag_albums/controllers/tag_albums.php index a36f0555..f77fa893 100644 --- a/3.0/modules/tag_albums/controllers/tag_albums.php +++ b/3.0/modules/tag_albums/controllers/tag_albums.php @@ -144,19 +144,7 @@ class tag_albums_Controller extends Controller { // Figure out which items to display on this page and store their details in $children. $tag_children = $this->_get_records($tag_ids, $page_size, $offset, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, true); - $children_array = Array(); - foreach ($tag_children as $one_child) { - $child_tag = new Tag_Albums_Item($one_child->title, url::site("tag_albums/show/" . $one_child->id . "/0/" . $id . "/" . urlencode($one_child->name)), $one_child->type, $one_child->id); - $child_tag->id = $one_child->id; - $child_tag->view_count = $one_child->view_count; - $child_tag->owner = identity::lookup_user($one_child->owner_id); - if ($one_child->has_thumb()) { - $child_tag->set_thumb($one_child->thumb_url(), $one_child->thumb_width, $one_child->thumb_height); - } - $children_array[] = $child_tag; - } - $children = new Tag_Albums_Children($children_array); - + // Set up the previous and next page buttons. if ($page > 1) { $previous_page = $page - 1; @@ -168,34 +156,41 @@ class tag_albums_Controller extends Controller { } // Set up breadcrumbs. - $tag_album_breadcrumbs = Array(); + $tag_album_breadcrumbs = array(); $counter = 0; - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($album->title, ""); + $tag_album_breadcrumbs[] = Breadcrumb::instance($album->title, $album->url())->set_last(); $parent_item = ORM::factory("item", $album->parent_id); while ($parent_item->id != 1) { - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url()); $parent_item = ORM::factory("item", $parent_item->parent_id); } - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url())->set_first(); $tag_album_breadcrumbs[1]->url .= "?show=" . $album->id; + $tag_album_breadcrumbs = array_reverse($tag_album_breadcrumbs, true); // Set up and display the actual page. $parent_album = ORM::factory("item", $album->parent_id); - $template = new Theme_View("calpage.html", "collection", "Tag Albums"); + //$template = new Theme_View("calpage.html", "collection", "Tag Albums"); + $template = new Theme_View("page.html", "collection", "Tag Albums"); + $template->set_global( + array("page" => $page, + "max_pages" => $max_pages, + "page_size" => $page_size, + "children" => $tag_children, + "breadcrumbs" => $tag_album_breadcrumbs, + "children_count" => $count)); $template->page_title = $page_title; - $template->set_global("page", $page); - $template->set_global("page_size", $page_size); - $template->set_global("max_pages", $max_pages); - $template->set_global("children", $children); - $template->set_global("all_siblings", $this->_get_records($tag_ids, $count, 0, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false)); - $template->set_global("children_count", $count); - $template->set_global("parent_url", $parent_album->url()); // Used by Grey Dragon. - $template->content = new View("tag_albums_album.html"); + $template->content = new View("dynamic.html"); $template->content->title = $page_title; $template->content->description = $page_description; - $template->set_global("breadcrumbs", $tag_album_breadcrumbs); + + $template->set_global("all_siblings", $this->_get_records($tag_ids, $count, 0, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false)); + $template->set_global("parent_url", $parent_album->url()); // Used by Grey Dragon. print $template; + + // Set breadcrumbs on the photo pages to point back to the calendar day view. + //item::set_display_context_callback("CalendarView_Controller::get_display_day_context", $display_user, $display_year, $display_month, $display_day); } } @@ -411,36 +406,38 @@ class tag_albums_Controller extends Controller { $parent_url = ""; if ($id > 0) { $counter = 0; - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($album->title, ""); + $tag_album_breadcrumbs[] = Breadcrumb::instance($album->title, $album->url())->set_last(); $parent_item = ORM::factory("item", $album->parent_id); $parent_url = $parent_item->url(); while ($parent_item->id != 1) { - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url()); $parent_item = ORM::factory("item", $parent_item->parent_id); } - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url())->set_first(); $tag_album_breadcrumbs[1]->url .= "?show=" . $album->id; $tag_album_breadcrumbs = array_reverse($tag_album_breadcrumbs, true); } else { $parent_url = item::root()->url(); - $tag_album_breadcrumbs[0] = new Tag_Albums_Breadcrumb(item::root()->title, item::root()->url()); - $tag_album_breadcrumbs[1] = new Tag_Albums_Breadcrumb($page_title, ""); + $tag_album_breadcrumbs[] = Breadcrumb::instance(item::root()->title, item::root()->url())->set_first(); + $tag_album_breadcrumbs[] = Breadcrumb::instance($page_title, $str_page_url)->set_first(); } // Set up and display the actual page. - $template = new Theme_View("calpage.html", "collection", "Tag Albums"); + $template = new Theme_View("page.html", "collection", "Tag Albums"); + $template->set_global( + array("page" => $page, + "max_pages" => $max_pages, + "page_size" => $page_size, + "children" => $children, + "breadcrumbs" => $tag_album_breadcrumbs, + "children_count" => $all_tags_count)); $template->page_title = $page_title; - $template->set_global("page", $page); - $template->set_global("page_size", $page_size); - $template->set_global("max_pages", $max_pages); - $template->set_global("children", $children); - $template->set_global("children_count", $all_tags_count); - $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. - $template->content = new View("tag_albums_album.html"); + $template->content = new View("dynamic.html"); $template->content->title = $page_title; $template->content->description = $page_description; + + $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. $template->content->filter_text = $this->_get_filter_html($id, $filter); - $template->set_global("breadcrumbs", $tag_album_breadcrumbs); print $template; } @@ -510,20 +507,6 @@ class tag_albums_Controller extends Controller { // Figure out which items to display on this page. $tag_children = $this->_get_records(Array($id), $page_size, $offset, "items." . $sort_page_field, $sort_page_direction, "OR", true); - - // Create an array of "fake" items to display on the page. - $children_array = Array(); - foreach ($tag_children as $one_child) { - $child_tag = new Tag_Albums_Item($one_child->title, url::site("tag_albums/show/" . $one_child->id . "/" . $id . "/" . $album_id . "/" . urlencode($one_child->name)), $one_child->type, $one_child->id); - $child_tag->id = $one_child->id; - $child_tag->view_count = $one_child->view_count; - $child_tag->owner = identity::lookup_user($one_child->owner_id); - if ($one_child->has_thumb()) { - $child_tag->set_thumb($one_child->thumb_url(), $one_child->thumb_width, $one_child->thumb_height); - } - $children_array[] = $child_tag; - } - $children = new Tag_Albums_Children($children_array); // Set up the previous and next page buttons. if ($page > 1) { @@ -540,52 +523,68 @@ class tag_albums_Controller extends Controller { $parent_url = ""; if ($album_id > 0) { $counter = 0; - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($display_tag->name, ""); + //$tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($display_tag->name, ""); + $tag_album_breadcrumbs[] = Breadcrumb::instance($display_tag->name, $str_page_url)->set_last(); $parent_item = ORM::factory("item", $album_tags[0]->album_id); if ($album_tags[0]->tags != "*") { $parent_item = ORM::factory("item", $parent_item->parent_id); } $parent_url = $parent_item->url(); // Used by Grey Dragon. while ($parent_item->id != 1) { - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); + //$tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url()); $parent_item = ORM::factory("item", $parent_item->parent_id); } - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); + //$tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url())->set_first(); $parent_item = ORM::factory("item", $album_tags[0]->album_id); + /* if ((module::get_var("tag_albums", "tag_index_scope", "false")) && (module::get_var("tag_albums", "tag_index", "default") != "default")) { $tag_album_breadcrumbs[1]->url = url::site("tag_albums/album/" . $album_id . "/" . urlencode($parent_item->name)); } else { $tag_album_breadcrumbs[1]->url = url::site("tag_albums/album/" . $album_id . "/" . urlencode($parent_item->name)) . "?show=" . $id; } + */ + $tag_album_breadcrumbs[1]->url .= "?show=" . $id; + $tag_album_breadcrumbs = array_reverse($tag_album_breadcrumbs, true); } else { $parent_url = url::site("tag_albums/"); - $tag_album_breadcrumbs[0] = new Tag_Albums_Breadcrumb(item::root()->title, item::root()->url()); + //$tag_album_breadcrumbs[0] = new Tag_Albums_Breadcrumb(item::root()->title, item::root()->url()); + $tag_album_breadcrumbs[] = Breadcrumb::instance(item::root()->title, item::root()->url())->set_first(); if (module::get_var("tag_albums", "tag_index", "default") == "default") { - $tag_album_breadcrumbs[1] = new Tag_Albums_Breadcrumb(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/") . "?show=" . $id); + //$tag_album_breadcrumbs[1] = new Tag_Albums_Breadcrumb(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/") . "?show=" . $id); + $tag_album_breadcrumbs[] = Breadcrumb::instance(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/") . "?show=" . $id); } else { - $tag_album_breadcrumbs[1] = new Tag_Albums_Breadcrumb(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/")); + //$tag_album_breadcrumbs[1] = new Tag_Albums_Breadcrumb(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/")); + $tag_album_breadcrumbs[] = Breadcrumb::instance(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/")); } - $tag_album_breadcrumbs[2] = new Tag_Albums_Breadcrumb($display_tag->name, ""); + //$tag_album_breadcrumbs[2] = new Tag_Albums_Breadcrumb($display_tag->name, ""); + $tag_album_breadcrumbs[] = Breadcrumb::instance($display_tag->name, $str_page_url)->set_last(); } // Set up and display the actual page. - $template = new Theme_View("calpage.html", "collection", "Tag Albums"); + $template = new Theme_View("page.html", "collection", "Tag Albums"); + $template->set_global( + array("page" => $page, + "max_pages" => $max_pages, + "page_size" => $page_size, + "children" => $tag_children, + "breadcrumbs" => $tag_album_breadcrumbs, + "children_count" => $count)); $template->page_title = $display_tag->name; - $template->set_global("page", $page); - $template->set_global("page_size", $page_size); - $template->set_global("max_pages", $max_pages); - $template->set_global("children", $children); - $template->set_global("all_siblings", $this->_get_records(Array($id), $count, 0, "items." . $sort_page_field, $sort_page_direction, "OR", false)); - $template->set_global("children_count", $count); - $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. - $template->content = new View("tag_albums_album.html"); + $template->content = new View("dynamic.html"); $template->content->title = $display_tag->name; - $template->set_global("breadcrumbs", $tag_album_breadcrumbs); + //$template->content->description = $page_description; + + $template->set_global("all_siblings", $this->_get_records(Array($id), $count, 0, "items." . $sort_page_field, $sort_page_direction, "OR", false)); + $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. print $template; } public function show($item_id, $tag_id, $album_id) { + $item = ORM::factory("item", $item_id); + url::redirect(url::abs_site("{$item->type}s/{$item->id}")); // Display the specified photo or video ($item_id) with breadcrumbs // that point back to a virtual album ($tag_id / $album_id). diff --git a/3.0/modules/tag_albums/libraries/Tag_Albums_Breadcrumb.php b/3.0/modules/tag_albums/libraries/Tag_Albums_Breadcrumb.php deleted file mode 100644 index 64a755ee..00000000 --- a/3.0/modules/tag_albums/libraries/Tag_Albums_Breadcrumb.php +++ /dev/null @@ -1,31 +0,0 @@ -title = $new_title; - $this->url = $new_url; - } -} diff --git a/3.0/modules/tag_albums/views/calpage.html.php b/3.0/modules/tag_albums/views/calpage.html.php deleted file mode 100644 index c7fdbef0..00000000 --- a/3.0/modules/tag_albums/views/calpage.html.php +++ /dev/null @@ -1,167 +0,0 @@ - - -html_attributes() ?> xml:lang="en" lang="en"> - - - start_combining("script,css") ?> - - <? if ($page_title): ?> - <?= $page_title ?> - <? else: ?> - <? if ($theme->item()): ?> - <?= $theme->item()->title ?> - <? elseif ($theme->tag()): ?> - <?= t("Photos tagged with %tag_title", array("tag_title" => $theme->tag()->name)) ?> - <? else: /* Not an item, not a tag, no page_title specified. Help! */ ?> - <?= item::root()->title ?> - <? endif ?> - <? endif ?> - - " - type="image/x-icon" /> - " /> - page_type == "collection"): ?> - thumb_proportion($theme->item())) != 1): ?> - - - - - - - script("json2-min.js") ?> - script("jquery.js") ?> - script("jquery.form.js") ?> - script("jquery-ui.js") ?> - script("gallery.common.js") ?> - - - script("gallery.ajax.js") ?> - script("gallery.dialog.js") ?> - script("superfish/js/superfish.js") ?> - script("jquery.localscroll.js") ?> - - - page_subtype == "photo"): ?> - script("jquery.scrollTo.js") ?> - script("gallery.show_full_size.js") ?> - page_subtype == "movie"): ?> - script("flowplayer.js") ?> - - - head() ?> - - - script("ui.init.js") ?> - css("yui/reset-fonts-grids.css") ?> - css("superfish/css/superfish.css") ?> - css("themeroller/ui.base.css") ?> - css("screen.css") ?> - - css("screen-rtl.css") ?> - - - - - get_combined("css") ?> - - - get_combined("script") ?> - - - body_attributes() ?>> - page_top() ?> -
- site_status() ?> -
-
- - - - - - user_menu() ?> - header_top() ?> - - - - - - header_bottom() ?> -
- - - - - - - -
-
-
-
-
- messages() ?> - -
-
-
-
- page_subtype != "login"): ?> - - -
-
- -
- page_bottom() ?> - - \ No newline at end of file diff --git a/3.0/modules/tag_albums/views/tag_albums_album.html.php b/3.0/modules/tag_albums/views/tag_albums_album.html.php deleted file mode 100644 index 620d3c81..00000000 --- a/3.0/modules/tag_albums/views/tag_albums_album.html.php +++ /dev/null @@ -1,50 +0,0 @@ - -album_top() was changed to $theme->dynamic_top(). - // $item->title and $item->description have been changed to $title and $description. - // - // The g-album-grid block was also taken from album.html.php. The section for uploading new photos to an empty album - // has been removed. Also, $theme->context_menu has been removed as well (it was crashing the page). -?> -
- dynamic_top() ?> -

-
-
- - -
-
-
-
- - - -dynamic_bottom() ?> - -paginator() ?> From 7724e8a2bdc1742e0ed1b579bb7117762025e725 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Wed, 16 May 2012 23:15:09 -0400 Subject: [PATCH 3/5] Support navigating within virtual albums. --- .../tag_albums/controllers/tag_albums.php | 256 +++++++----------- 1 file changed, 104 insertions(+), 152 deletions(-) diff --git a/3.0/modules/tag_albums/controllers/tag_albums.php b/3.0/modules/tag_albums/controllers/tag_albums.php index f77fa893..5ece12e8 100644 --- a/3.0/modules/tag_albums/controllers/tag_albums.php +++ b/3.0/modules/tag_albums/controllers/tag_albums.php @@ -190,10 +190,109 @@ class tag_albums_Controller extends Controller { print $template; // Set breadcrumbs on the photo pages to point back to the calendar day view. - //item::set_display_context_callback("CalendarView_Controller::get_display_day_context", $display_user, $display_year, $display_month, $display_day); + item::set_display_context_callback("tag_albums_Controller::get_display_context", 0, $id); } } + static function get_display_context($item, $tag_id, $album_id) { + // Make sure #album_id is valid, clear it out if it isn't. + $album_tags = ORM::factory("tags_album_id") + ->where("id", "=", $album_id) + ->find_all(); + if (count($album_tags) == 0) { + $album_id = 0; + } + + // Load the tag and item, make sure the user has access to the item. + $display_tag = ORM::factory("tag", $tag_id); + + // Figure out sort order from module preferences. + $sort_page_field = ""; + $sort_page_direction = ""; + if (($tag_id > 0) || (count($album_tags) == 0)) { + $sort_page_field = module::get_var("tag_albums", "subalbum_sort_by", "title"); + $sort_page_direction = module::get_var("tag_albums", "subalbum_sort_direction", "ASC"); + } else { + $parent_album = ORM::factory("item", $album_tags[0]->album_id); + $sort_page_field = $parent_album->sort_column; + $sort_page_direction = $parent_album->sort_order; + } + + // Load the number of items in the parent album, and determine previous and next items. + $sibling_count = ""; + $tag_children = ""; + $previous_item = ""; + $next_item = ""; + $position = 0; + if ($tag_id > 0) { + $sibling_count = tag_albums_Controller::_count_records(Array($tag_id), "OR", false); + $position = tag_albums_Controller::_get_position($item->$sort_page_field, $item->id, Array($tag_id), "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if ($position > 1) { + $previous_item_object = tag_albums_Controller::_get_records(Array($tag_id), 1, $position-2, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if (count($previous_item_object) > 0) { + $previous_item = $previous_item_object[0]; + } + } + $next_item_object = tag_albums_Controller::_get_records(Array($tag_id), 1, $position, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if (count($next_item_object) > 0) { + $next_item = $next_item_object[0]; + } + } else { + $tag_ids = Array(); + foreach (explode(",", $album_tags[0]->tags) as $tag_name) { + $tag = ORM::factory("tag")->where("name", "=", trim($tag_name))->find(); + if ($tag->loaded()) { + $tag_ids[] = $tag->id; + } + } + $album_tags_search_type = $album_tags[0]->search_type; + $sibling_count = tag_albums_Controller::_count_records($tag_ids, $album_tags_search_type, false); + $position = tag_albums_Controller::_get_position($item->$sort_page_field, $item->id, $tag_ids, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if ($position > 1) { + $previous_item_object = tag_albums_Controller::_get_records($tag_ids, 1, $position-2, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if (count($previous_item_object) > 0) { + $previous_item = $previous_item_object[0]; + } + } + $next_item_object = tag_albums_Controller::_get_records($tag_ids, 1, $position, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if (count($next_item_object) > 0) { + $next_item = $next_item_object[0]; + } + + } + + // Set up breadcrumbs + $tag_album_breadcrumbs = Array(); + if ($album_id > 0) { + $counter = 0; + $tag_album_breadcrumbs[] = Breadcrumb::instance($item->title, $item->url())->set_last(); + if ($album_tags[0]->tags == "*") { + $tag_album_breadcrumbs[] = Breadcrumb::instance($display_tag->name, url::site("tag_albums/tag/" . $display_tag->id . "/" . $album_id . "/" . urlencode($display_tag->name))); + } + $parent_item = ORM::factory("item", $album_tags[0]->album_id); + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, url::site("tag_albums/album/" . $album_id . "/" . urlencode($parent_item->name))); + $parent_item = ORM::factory("item", $parent_item->parent_id); + while ($parent_item->id != 1) { + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url()); + $parent_item = ORM::factory("item", $parent_item->parent_id); + } + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url())->set_first(); + $tag_album_breadcrumbs[1]->url .= "?show=" . $item->id; + $tag_album_breadcrumbs = array_reverse($tag_album_breadcrumbs, true); + } else { + $tag_album_breadcrumbs[] = Breadcrumb::instance(item::root()->title, item::root()->url())->set_first(); + $tag_album_breadcrumbs[] = Breadcrumb::instance(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/")); + $tag_album_breadcrumbs[] = Breadcrumb::instance($display_tag->name, url::site("tag_albums/tag/" . $display_tag->id . "/" . urlencode($display_tag->name)) . "?show=" . $item->id); + $tag_album_breadcrumbs[] = Breadcrumb::instance($item->title, $item->url())->set_last(); + } + + return array("position" => $position, + "previous_item" => $previous_item, + "next_item" => $next_item, + "sibling_count" => $sibling_count, + "breadcrumbs" => $tag_album_breadcrumbs); + } + public function filter($id, $filter) { // Display the index page, but only show albums for // tags whose name begins with $filter. @@ -580,162 +679,15 @@ class tag_albums_Controller extends Controller { $template->set_global("all_siblings", $this->_get_records(Array($id), $count, 0, "items." . $sort_page_field, $sort_page_direction, "OR", false)); $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. print $template; + + // Set breadcrumbs on the photo pages to point back to the calendar day view. + item::set_display_context_callback("tag_albums_Controller::get_display_context", $id, $album_id); } public function show($item_id, $tag_id, $album_id) { + item::set_display_context_callback("tag_albums_Controller::get_display_context", $tag_id, $album_id); $item = ORM::factory("item", $item_id); url::redirect(url::abs_site("{$item->type}s/{$item->id}")); - // Display the specified photo or video ($item_id) with breadcrumbs - // that point back to a virtual album ($tag_id / $album_id). - - // Make sure #album_id is valid, clear it out if it isn't. - $album_tags = ORM::factory("tags_album_id") - ->where("id", "=", $album_id) - ->find_all(); - if (count($album_tags) == 0) { - $album_id = 0; - } - - // Load the tag and item, make sure the user has access to the item. - $display_tag = ORM::factory("tag", $tag_id); - $item = ORM::factory("item", $item_id); - access::required("view", $item); - $parent_url = ""; - - // Figure out sort order from module preferences. - $sort_page_field = ""; - $sort_page_direction = ""; - if (($tag_id > 0) || (count($album_tags) == 0)) { - $sort_page_field = module::get_var("tag_albums", "subalbum_sort_by", "title"); - $sort_page_direction = module::get_var("tag_albums", "subalbum_sort_direction", "ASC"); - } else { - $parent_album = ORM::factory("item", $album_tags[0]->album_id); - $sort_page_field = $parent_album->sort_column; - $sort_page_direction = $parent_album->sort_order; - } - - // Load the number of items in the parent album, and determine previous and next items. - $sibling_count = ""; - $tag_children = ""; - $previous_item = ""; - $next_item = ""; - $position = 0; - $dynamic_siblings = ""; - if ($tag_id > 0) { - $sibling_count = $this->_count_records(Array($tag_id), "OR", false); - $position = $this->_get_position($item->$sort_page_field, $item->id, Array($tag_id), "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if ($position > 1) { - $previous_item_object = $this->_get_records(Array($tag_id), 1, $position-2, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if (count($previous_item_object) > 0) { - $previous_item = new Tag_Albums_Item($previous_item_object[0]->title, url::site("tag_albums/show/" . $previous_item_object[0]->id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($previous_item_object[0]->name)), $previous_item_object[0]->type, $previous_item_object[0]->id); - } - } - $next_item_object = $this->_get_records(Array($tag_id), 1, $position, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if (count($next_item_object) > 0) { - $next_item = new Tag_Albums_Item($next_item_object[0]->title, url::site("tag_albums/show/" . $next_item_object[0]->id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($next_item_object[0]->name)), $next_item_object[0]->type, $next_item_object[0]->id); - } - $dynamic_siblings = $this->_get_records(Array($tag_id), null, null, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - } else { - $tag_ids = Array(); - foreach (explode(",", $album_tags[0]->tags) as $tag_name) { - $tag = ORM::factory("tag")->where("name", "=", trim($tag_name))->find(); - if ($tag->loaded()) { - $tag_ids[] = $tag->id; - } - } - $album_tags_search_type = $album_tags[0]->search_type; - $sibling_count = $this->_count_records($tag_ids, $album_tags_search_type, false); - $position = $this->_get_position($item->$sort_page_field, $item->id, $tag_ids, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if ($position > 1) { - $previous_item_object = $this->_get_records($tag_ids, 1, $position-2, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if (count($previous_item_object) > 0) { - $previous_item = new Tag_Albums_Item($previous_item_object[0]->title, url::site("tag_albums/show/" . $previous_item_object[0]->id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($previous_item_object[0]->name)), $previous_item_object[0]->type); - } - } - $next_item_object = $this->_get_records($tag_ids, 1, $position, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if (count($next_item_object) > 0) { - $next_item = new Tag_Albums_Item($next_item_object[0]->title, url::site("tag_albums/show/" . $next_item_object[0]->id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($next_item_object[0]->name)), $next_item_object[0]->type); - } - $dynamic_siblings = $this->_get_records($tag_ids, null, null, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - } - - // Set up breadcrumbs - $tag_album_breadcrumbs = Array(); - if ($album_id > 0) { - $counter = 0; - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($item->title, ""); - if ($album_tags[0]->tags == "*") { - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($display_tag->name, url::site("tag_albums/tag/" . $display_tag->id . "/" . $album_id . "/" . urlencode($display_tag->name))); - } - $parent_item = ORM::factory("item", $album_tags[0]->album_id); - if ($album_tags[0]->tags == "*") { - $parent_url = url::site("tag_albums/tag/" . $display_tag->id . "/" . $album_id . "/" . urlencode($display_tag->name)); - } else { - $parent_url = $parent_item->url(); - } - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, url::site("tag_albums/album/" . $album_id . "/" . urlencode($parent_item->name))); - $parent_item = ORM::factory("item", $parent_item->parent_id); - while ($parent_item->id != 1) { - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); - $parent_item = ORM::factory("item", $parent_item->parent_id); - } - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); - $tag_album_breadcrumbs[1]->url .= "?show=" . $item->id; - $tag_album_breadcrumbs = array_reverse($tag_album_breadcrumbs, true); - } else { - $tag_album_breadcrumbs[0] = new Tag_Albums_Breadcrumb(item::root()->title, item::root()->url()); - $tag_album_breadcrumbs[1] = new Tag_Albums_Breadcrumb(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/")); - $tag_album_breadcrumbs[2] = new Tag_Albums_Breadcrumb($display_tag->name, url::site("tag_albums/tag/" . $display_tag->id . "/" . urlencode($display_tag->name)) . "?show=" . $item->id); - $tag_album_breadcrumbs[3] = new Tag_Albums_Breadcrumb($item->title, ""); - $parent_url = url::site("tag_albums/tag/" . $display_tag->id . "/" . urlencode($display_tag->name)); - } - - // Increase the items view count. - $item->increment_view_count(); - - // Load the page. - if ($item->is_photo()) { - $template = new Theme_View("calpage.html", "item", "photo"); - $template->page_title = $item->title; - $template->set_global("children", Array()); - $template->set_global("item", $item); - $template->set_global("previous_item", $previous_item); - $template->set_global("next_item", $next_item); - $template->set_global("is_tagalbum_page", true); // used for grey dragon - $template->set_global("tag_id", $tag_id); // used for grey dragon - $template->set_global("album_id", $album_id); // used for grey dragon - $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. - $template->set_global("dynamic_siblings", $dynamic_siblings); // Used by Grey Dragon. - $template->set_global("children_count", 0); - $template->set_global("position", $position); - $template->set_global("sibling_count", $sibling_count); - $template->content = new View("photo.html"); - $template->content->title = $item->title; - $template->set_global("breadcrumbs", $tag_album_breadcrumbs); - print $template; - } elseif ($item->is_movie()) { - $template = new Theme_View("calpage.html", "item", "movie"); - $template->page_title = $item->title; - $template->set_global("children", Array()); - $template->set_global("item", $item); - $template->set_global("previous_item", $previous_item); - $template->set_global("next_item", $next_item); - $template->set_global("is_tagalbum_page", true); // used for grey dragon - $template->set_global("tag_id", $tag_id); // used for grey dragon - $template->set_global("album_id", $album_id); // used for grey dragon - $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. - $template->set_global("dynamic_siblings", $dynamic_siblings); // Used by Grey Dragon. - $template->set_global("children_count", 0); - $template->set_global("position", $position); - $template->set_global("sibling_count", $sibling_count); - $template->content = new View("movie.html"); - $template->content->title = $item->title; - $template->set_global("breadcrumbs", $tag_album_breadcrumbs); - print $template; - } else { - // If it's something we don't know how to deal with, just redirect to its real page. - url::redirect(url::abs_site("{$item->type}s/{$item->id}")); - } } private function _get_position($item_title, $item_id, $tag_ids, $sort_field, $sort_direction, $search_type, $include_albums) { From 21c5f518004a516b129a6bbfcf0c1bad2e4c2091 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Mon, 21 May 2012 21:08:52 -0400 Subject: [PATCH 4/5] Set some extra variables when viewing a photo from a virtual album, in order to distinguish how the user arrived at the page. This allows Tag Albums to create a menu option to make the photo the virtual album's thumbnail. --- 3.0/modules/tag_albums/controllers/tag_albums.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/3.0/modules/tag_albums/controllers/tag_albums.php b/3.0/modules/tag_albums/controllers/tag_albums.php index 5ece12e8..cf74663b 100644 --- a/3.0/modules/tag_albums/controllers/tag_albums.php +++ b/3.0/modules/tag_albums/controllers/tag_albums.php @@ -289,6 +289,9 @@ class tag_albums_Controller extends Controller { return array("position" => $position, "previous_item" => $previous_item, "next_item" => $next_item, + "tag_id" => $tag_id, + "album_id" => $album_id, + "is_tagalbum_page" => true, "sibling_count" => $sibling_count, "breadcrumbs" => $tag_album_breadcrumbs); } From e9bd604a6320238700cd7194ca283fcd3756b9ec Mon Sep 17 00:00:00 2001 From: rWatcher Date: Thu, 31 May 2012 00:05:33 -0400 Subject: [PATCH 5/5] Initial commit of Fotomoto rW module. --- .../controllers/admin_fotomotorw.php | 111 ++++++++++++++++++ .../fotomotorw/controllers/fotomotorw.php | 76 ++++++++++++ .../fotomotorw/helpers/fotomotorw_event.php | 30 +++++ .../helpers/fotomotorw_installer.php | 35 ++++++ .../fotomotorw/helpers/fotomotorw_theme.php | 71 +++++++++++ 3.0/modules/fotomotorw/module.info | 7 ++ .../views/admin_fotomotorw.html.php | 64 ++++++++++ .../views/fotomotorw_block.html.php | 15 +++ 8 files changed, 409 insertions(+) create mode 100644 3.0/modules/fotomotorw/controllers/admin_fotomotorw.php create mode 100644 3.0/modules/fotomotorw/controllers/fotomotorw.php create mode 100644 3.0/modules/fotomotorw/helpers/fotomotorw_event.php create mode 100644 3.0/modules/fotomotorw/helpers/fotomotorw_installer.php create mode 100644 3.0/modules/fotomotorw/helpers/fotomotorw_theme.php create mode 100644 3.0/modules/fotomotorw/module.info create mode 100644 3.0/modules/fotomotorw/views/admin_fotomotorw.html.php create mode 100644 3.0/modules/fotomotorw/views/fotomotorw_block.html.php diff --git a/3.0/modules/fotomotorw/controllers/admin_fotomotorw.php b/3.0/modules/fotomotorw/controllers/admin_fotomotorw.php new file mode 100644 index 00000000..f487b53a --- /dev/null +++ b/3.0/modules/fotomotorw/controllers/admin_fotomotorw.php @@ -0,0 +1,111 @@ +page_title = t("Fotomoto"); + $view->content = new View("admin_fotomotorw.html"); + + // Generate a form to allow the user to choose which links to display under photos. + $form = new Forge("admin/fotomotorw/savedisplay", "", "post", + array("id" => "g-fotomotorw-admin-display-prefs")); + + $display_links_group = $form->group("fotomoto_display_links_group"); + $link_options["fotomoto_buy_prints"] = array(t("Buy Prints"), module::get_var("fotomotorw", "fotomoto_buy_prints")); + $link_options["fotomoto_buy_cards"] = array(t("Buy Cards"), module::get_var("fotomotorw", "fotomoto_buy_cards")); + $link_options["fotomoto_buy_download"] = array(t("Download"), module::get_var("fotomotorw", "fotomoto_buy_download")); + $link_options["fotomoto_share_ecard"] = array(t("Send eCard"), module::get_var("fotomotorw", "fotomoto_share_ecard")); + $link_options["fotomoto_share_facebook"] = array(t("Share on Facebook"), module::get_var("fotomotorw", "fotomoto_share_facebook")); + $link_options["fotomoto_share_twitter"] = array(t("Share on Twitter"), module::get_var("fotomotorw", "fotomoto_share_twitter")); + $link_options["fotomoto_share_digg"] = array(t("Share on Digg"), module::get_var("fotomotorw", "fotomoto_share_digg")); + + // Turn the array into a series of checkboxes. + $display_links_group->checklist("fotomoto_display_links") + ->options($link_options); + + // Add a save button to the form. + $form->submit("SaveSettings")->value(t("Save")); + + $view->content->display_form = $form; + print $view; + } + + public function reset_private_key() { + // Generate a new (random) private key. + module::set_var("fotomotorw", "fotomoto_private_key", md5(random::hash() . access::private_key())); + message::success(t("Your Photomoto private key has been reset.")); + url::redirect("admin/fotomotorw"); + } + + public function savedisplay() { + // Save the admin's preferences for which fotomoto links to display under each photo. + + // Prevent Cross Site Request Forgery + access::verify_csrf(); + + // Figure out which boxes where checked + $linkOptions_array = Input::instance()->post("fotomoto_display_links"); + $buy_prints = false; + $buy_cards = false; + $buy_download = false; + $share_ecard = false; + $share_facebook = false; + $share_twitter = false; + $share_digg = false; + for ($i = 0; $i < count($linkOptions_array); $i++) { + if ($linkOptions_array[$i] == "fotomoto_buy_prints") { + $buy_prints = true; + } + if ($linkOptions_array[$i] == "fotomoto_buy_cards") { + $buy_cards = true; + } + if ($linkOptions_array[$i] == "fotomoto_buy_download") { + $buy_download = true; + } + if ($linkOptions_array[$i] == "fotomoto_share_ecard") { + $share_ecard = true; + } + if ($linkOptions_array[$i] == "fotomoto_share_facebook") { + $share_facebook = true; + } + if ($linkOptions_array[$i] == "fotomoto_share_twitter") { + $share_twitter = true; + } + if ($linkOptions_array[$i] == "fotomoto_share_digg") { + $share_digg = true; + } + } + + // Save Settings. + module::set_var("fotomotorw", "fotomoto_buy_prints", $buy_prints); + module::set_var("fotomotorw", "fotomoto_buy_cards", $buy_cards); + module::set_var("fotomotorw", "fotomoto_buy_download", $buy_download); + module::set_var("fotomotorw", "fotomoto_share_ecard", $share_ecard); + module::set_var("fotomotorw", "fotomoto_share_facebook", $share_facebook); + module::set_var("fotomotorw", "fotomoto_share_twitter", $share_twitter); + module::set_var("fotomotorw", "fotomoto_share_digg", $share_digg); + + // Display a success message and reload the admin page. + message::success(t("Your Settings Have Been Saved.")); + url::redirect("admin/fotomotorw"); + } +} diff --git a/3.0/modules/fotomotorw/controllers/fotomotorw.php b/3.0/modules/fotomotorw/controllers/fotomotorw.php new file mode 100644 index 00000000..1be2def0 --- /dev/null +++ b/3.0/modules/fotomotorw/controllers/fotomotorw.php @@ -0,0 +1,76 @@ +loaded()) { + throw new Kohana_404_Exception(); + } + + // If the resize file doesn't exist for some reason, display a 404 error. + if (!file_exists($item->resize_path())) { + throw new Kohana_404_Exception(); + } + + // Display the image. + header("Content-Type: {$item->mime_type}"); + Kohana::close_buffers(false); + $fd = fopen($item->resize_path(), "rb"); + fpassthru($fd); + fclose($fd); + } + + public function print_proxy($site_key, $file_id) { + // This function retrieves the full-sized image for fotomoto. + // As this function by-passes normal Gallery security, a private + // site-key is used to try and prevent people other then fotomoto + // from finding the URL. + + // If the site key doesn't match, display a 404 error. + if ($site_key != module::get_var("fotomotorw", "fotomoto_private_key")) { + throw new Kohana_404_Exception(); + } + + // Load the photo from the provided id. If the id# is invalid, display a 404 error. + $item = ORM::factory("item", $file_id); + if (!$item->loaded()) { + throw new Kohana_404_Exception(); + } + + // If the image file doesn't exist for some reason, display a 404 error. + if (!file_exists($item->file_path())) { + throw new Kohana_404_Exception(); + } + + // Display the image. + header("Content-Type: {$item->mime_type}"); + Kohana::close_buffers(false); + $fd = fopen($item->file_path(), "rb"); + fpassthru($fd); + fclose($fd); + } +} diff --git a/3.0/modules/fotomotorw/helpers/fotomotorw_event.php b/3.0/modules/fotomotorw/helpers/fotomotorw_event.php new file mode 100644 index 00000000..24bdc5f1 --- /dev/null +++ b/3.0/modules/fotomotorw/helpers/fotomotorw_event.php @@ -0,0 +1,30 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("fotomotorw_menu") + ->label(t("Fotomoto")) + ->url(url::site("admin/fotomotorw"))); + } +} diff --git a/3.0/modules/fotomotorw/helpers/fotomotorw_installer.php b/3.0/modules/fotomotorw/helpers/fotomotorw_installer.php new file mode 100644 index 00000000..b949b61a --- /dev/null +++ b/3.0/modules/fotomotorw/helpers/fotomotorw_installer.php @@ -0,0 +1,35 @@ +page_subtype == "photo") { + return html::script('http://widget.fotomoto.com/stores/script/' . module::get_var("fotomotorw", "fotomoto_site_key") . '.js?api=true'); + } + } + + static function resize_bottom($theme) { + // Generate an array of links to display below photos. + $block = new Block; + $block->css_id = "g-fotomoto"; + $block->anchor = "fotomoto"; + + $link_array = array(); + $counter = 0; + if (module::get_var("fotomotorw", "fotomoto_buy_prints")) { + $link_array[$counter] = array("100", "Buy Prints"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_buy_cards")) { + $link_array[$counter] = array("300", "Buy Cards"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_buy_download")) { + $link_array[$counter] = array("400", "Download"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_share_ecard")) { + $link_array[$counter] = array("200", "Send eCard"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_share_facebook")) { + $link_array[$counter] = array("201", "Share on Facebook"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_share_twitter")) { + $link_array[$counter] = array("202", "Share on Twitter"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_share_digg")) { + $link_array[$counter] = array("203", "Share on Digg"); + $counter++; + } + + $view = new View("fotomotorw_block.html"); + $view->details = $link_array; + $block->content = $view; + return $block; + } +} diff --git a/3.0/modules/fotomotorw/module.info b/3.0/modules/fotomotorw/module.info new file mode 100644 index 00000000..593ab7e3 --- /dev/null +++ b/3.0/modules/fotomotorw/module.info @@ -0,0 +1,7 @@ +name = "Fotomoto (rWatcher)" +description = "Sell photos on your site through Fotomoto" +version = 1 +author_name = "rWatcher" +author_url = "http://codex.gallery2.org/User:RWatcher" +info_url = "http://codex.gallery2.org/Gallery3:Modules:fotomotorw" +discuss_url = "http://gallery.menalto.com/node/106765" diff --git a/3.0/modules/fotomotorw/views/admin_fotomotorw.html.php b/3.0/modules/fotomotorw/views/admin_fotomotorw.html.php new file mode 100644 index 00000000..b8175472 --- /dev/null +++ b/3.0/modules/fotomotorw/views/admin_fotomotorw.html.php @@ -0,0 +1,64 @@ + + +
+

+
+ + + + + + + + +
+ " class="g-dialog-link"> + + + + + + +
+

(Log in to the Fotomoto Dashboard to get your Site Key.)

+ + + + + + + + +
+ +
+ + + + + + + + +
+ (">)
+
+
+
+ +
+

+ + Auto Pickup, or click here."); ?>
+
+
+ "
+
+
+ + +
diff --git a/3.0/modules/fotomotorw/views/fotomotorw_block.html.php b/3.0/modules/fotomotorw/views/fotomotorw_block.html.php new file mode 100644 index 00000000..f0f4b91a --- /dev/null +++ b/3.0/modules/fotomotorw/views/fotomotorw_block.html.php @@ -0,0 +1,15 @@ + +
+ 0): ?> + + + | + + + +
+