diff options
Diffstat (limited to 'modules/calendarview')
| -rw-r--r-- | modules/calendarview/controllers/calendarview.php | 296 | ||||
| -rw-r--r-- | modules/calendarview/css/calendarview_calendar.css | 59 | ||||
| -rw-r--r-- | modules/calendarview/css/calendarview_menu.css | 3 | ||||
| -rw-r--r-- | modules/calendarview/helpers/calendarview.php | 48 | ||||
| -rw-r--r-- | modules/calendarview/helpers/calendarview_block.php | 72 | ||||
| -rw-r--r-- | modules/calendarview/helpers/calendarview_event.php | 99 | ||||
| -rw-r--r-- | modules/calendarview/helpers/calendarview_installer.php | 40 | ||||
| -rw-r--r-- | modules/calendarview/helpers/calendarview_theme.php | 25 | ||||
| -rw-r--r-- | modules/calendarview/images/ico-view-calendarview.png | bin | 0 -> 4191 bytes | |||
| -rw-r--r-- | modules/calendarview/libraries/PHPCalendar.php | 87 | ||||
| -rw-r--r-- | modules/calendarview/module.info | 7 | ||||
| -rw-r--r-- | modules/calendarview/views/calendarview_sidebar.html.php | 9 | ||||
| -rw-r--r-- | modules/calendarview/views/calendarview_year.html.php | 95 | ||||
| -rw-r--r-- | modules/calendarview/views/user_profile_calendarview.html.php | 86 |
14 files changed, 926 insertions, 0 deletions
diff --git a/modules/calendarview/controllers/calendarview.php b/modules/calendarview/controllers/calendarview.php new file mode 100644 index 0000000..b1bae80 --- /dev/null +++ b/modules/calendarview/controllers/calendarview.php @@ -0,0 +1,296 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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 CalendarView_Controller extends Controller { + public function calendar($display_year="", $display_user="-1") { + // Draw a calendar for the year specified by $display_year. + + // Display the current year by default if a year wasn't provided. + if ($display_year == "") { + $display_year = date('Y'); + } + + // Draw the page. + $root = item::root(); + $template = new Theme_View("page.html", "other", "CalendarView"); + $template->set_global( + array("calendar_user" => $display_user, + "breadcrumbs" => array( + Breadcrumb::instance($root->title, $root->url())->set_first(), + Breadcrumb::instance($display_year, url::site("calendarview/calendar/" . $display_year))->set_last()))); + $template->page_title = t("Gallery :: Calendar"); + $template->content = new View("calendarview_year.html"); + $template->content->calendar_year = $display_year; + $template->content->calendar_user = $display_user; + $template->content->calendar_user_year_form = $this->_get_calenderprefs_form($display_year, $display_user); + $template->content->title = t("Calendar") . ": " . $display_year; + print $template; + } + + public function day($display_year, $display_user, $display_month, $display_day) { + // Display all images for the specified 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)); + + // 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); + $page = (int) Input::instance()->get("page", "1"); + $offset = ($page-1) * $page_size; + $max_pages = max(ceil($day_count / $page_size), 1); + + // Make sure that the page references a valid offset + if (($page < 1) || ($page > $max_pages)) { + throw new Kohana_404_Exception(); + } + + // Figure out which photos go on this page. + $children = calendarview::get_items($page_size, $offset, $where); + + // Create and display the page. + $root = item::root(); + $template = new Theme_View("page.html", "collection", "CalendarDayView"); + $template->set_global( + array("page" => $page, + "max_pages" => $max_pages, + "page_size" => $page_size, + "children" => $children, + "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))->set_last()), + "children_count" => $day_count)); + $template->page_title = t("Gallery :: Calendar"); + $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. + + // 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); + $page = (int) Input::instance()->get("page", "1"); + $offset = ($page-1) * $page_size; + $max_pages = max(ceil($day_count / $page_size), 1); + + // Make sure that the page references a valid offset + if (($page < 1) || ($page > $max_pages)) { + throw new Kohana_404_Exception(); + } + + // Figure out which photos go on this page. + $children = calendarview::get_items($page_size, $offset, $where); + + // Create and display the page. + $root = item::root(); + $template = new Theme_View("page.html", "collection", "CalendarMonthView"); + $template->set_global( + array("page" => $page, + "max_pages" => $max_pages, + "page_size" => $page_size, + "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))->set_last()), + "children" => $children, + "children_count" => $day_count)); + $template->page_title = t("Gallery :: Calendar"); + $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) { + // Generate a form to allow the visitor to select a year and a gallery photo owner. + $calendar_group = new Forge("calendarview/setprefs", "", "post", + array("id" => "g-view-calendar-form")); + + // Generate a list of all Gallery users who have uploaded photos. + $valid_users[-1] = "(All Users)"; + $gallery_users = ORM::factory("user")->find_all(); + foreach ($gallery_users as $one_user) { + $count = ORM::factory("item") + ->viewable() + ->where("owner_id", "=", $one_user->id) + ->where("type", "!=", "album") + ->where("captured", "!=", "") + ->find_all() + ->count(); + if ($count > 0) { + $valid_users[$one_user->id] = $one_user->full_name; + } + } + + // Generate a list of years, starting with the year the earliest photo was + // taken, and ending with the year of the most recent photo. + $valid_years = Array(); + if ($display_user == -1) { + $all_photos = ORM::factory("item") + ->viewable() + ->where("type", "!=", "album") + ->where("captured", "!=", "") + ->order_by("captured", "DESC") + ->find_all(); + $counter = date('Y', $all_photos[count($all_photos)-1]->captured); + while ($counter <= date('Y', $all_photos[0]->captured)) { + $valid_years[$counter] = $counter; + $counter++; + } + } else { + $all_photos = ORM::factory("item") + ->viewable() + ->where("type", "!=", "album") + ->where("captured", "!=", "") + ->where("owner_id", "=", $display_user) + ->order_by("captured", "DESC") + ->find_all(); + $counter = date('Y', $all_photos[count($all_photos)-1]->captured); + while ($counter <= date('Y', $all_photos[0]->captured)) { + $valid_years[$counter] = $counter; + $counter++; + } + } + + // Create the form. + $calendar_group->dropdown('cal_user') + ->label(t("Display Photos From User: ")) + ->id('cal_user') + ->options($valid_users) + ->selected($display_user); + $calendar_group->dropdown('cal_year') + ->label(t("For Year: ")) + ->id('cal_year') + ->options($valid_years) + ->selected($display_year); + + // Add a save button to the form. + $calendar_group->submit("SaveSettings")->value(t("Go"))->id('cal_go'); + + // Return the newly generated form. + return $calendar_group; + } + + public function setprefs() { + // Change the calendar year and / or user. + + // Prevent Cross Site Request Forgery + access::verify_csrf(); + + // Get user specified settings. + $str_user_id = Input::instance()->post("cal_user"); + $str_year_id = Input::instance()->post("cal_year"); + + // redirect to the currect page. + url::redirect(url::site("calendarview/calendar/" . $str_year_id . "/" . $str_user_id, request::protocol())); + } +} diff --git a/modules/calendarview/css/calendarview_calendar.css b/modules/calendarview/css/calendarview_calendar.css new file mode 100644 index 0000000..82dfaa9 --- /dev/null +++ b/modules/calendarview/css/calendarview_calendar.css @@ -0,0 +1,59 @@ +/* Grid view ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#g-calendar-grid { + position: relative; + align: center; + float: left; + width: 200px; + height: 220px; + margin: 10px 10px 10px 10px; +} + +#g-calendar-profile-grid { + position: relative; + align: center; + float: left; + width: 200px; + height: 145px; + margin: 10px 10px 10px 10px; +} + +/* Search form ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#cal_user { + top: 0px; + left: 60px; + display: inline; +} +#cal_year { + top: 0px; + left: 240px; + display: inline; +} +#cal_go { + top: 0px; + left: 328px; + display: inline; +} + +/* Content ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +table.calendar { + text-align: center; +} + +table.calendar caption { + font-size: 1.5em; + padding: 0.2em; +} + +table.calendar th, table.calendar td { + padding: 0.2em; + border: 0px; +} + +table.calendar td:hover { + background: #ddf; +} + +/* For RTL Languages ~~~~~~~~~~~~~~~~~~~~~~~ */ +.rtl #g-calendar-grid { + float: right; +} diff --git a/modules/calendarview/css/calendarview_menu.css b/modules/calendarview/css/calendarview_menu.css new file mode 100644 index 0000000..600cc15 --- /dev/null +++ b/modules/calendarview/css/calendarview_menu.css @@ -0,0 +1,3 @@ +#g-view-menu #g-calendarview-link { + background-image: url('../images/ico-view-calendarview.png'); +} diff --git a/modules/calendarview/helpers/calendarview.php b/modules/calendarview/helpers/calendarview.php new file mode 100644 index 0000000..4807bc0 --- /dev/null +++ b/modules/calendarview/helpers/calendarview.php @@ -0,0 +1,48 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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 calendarview_Core { + static function get_items_count($where=array()) { + // Returns the number of viewable items identified by $where. + return ORM::factory("item") + ->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(); + } +} diff --git a/modules/calendarview/helpers/calendarview_block.php b/modules/calendarview/helpers/calendarview_block.php new file mode 100644 index 0000000..05e470d --- /dev/null +++ b/modules/calendarview/helpers/calendarview_block.php @@ -0,0 +1,72 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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 calendarview_block_Core { + static function get_site_list() { + return array("calendarview_photo" => t("More Photos From This Date")); + } + + static function get($block_id, $theme) { + $block = ""; + + // Make sure the current page belongs to an item. + if (!$theme->item()) { + return; + } + $item = $theme->item; + + $display_date = ""; + if (isset($item->captured)) { + $display_date = $item->captured; + }elseif (isset($item->created)) { + $display_date = $item->created; + } + + // Make sure there are photo's to display. + $day_count = ORM::factory("item") + ->viewable() + ->where("type", "!=", "album") + ->where("captured", ">=", mktime(0, 0, 0, date("n", $display_date), date("j", $display_date), date("Y", $display_date))) + ->where("captured", "<", mktime(0, 0, 0, date("n", $display_date), date("j", $display_date)+1, date("Y", $display_date))) + ->find_all() + ->count(); + $month_count = ORM::factory("item") + ->viewable() + ->where("type", "!=", "album") + ->where("captured", ">=", mktime(0, 0, 0, date("n", $display_date), 1, date("Y", $display_date))) + ->where("captured", "<", mktime(0, 0, 0, date("n", $display_date)+1, 1, date("Y", $display_date))) + ->find_all() + ->count(); + + switch ($block_id) { + case "calendarview_photo": + if ( ($display_date != "") && (($day_count > 0) || ($month_count > 0)) ) { + $block = new Block(); + $block->css_id = "g-calendarview-sidebar"; + $block->title = t("Calendar"); + $block->content = new View("calendarview_sidebar.html"); + $block->content->date = $display_date; + $block->content->day_count = $day_count; + $block->content->month_count = $month_count; + } + break; + } + return $block; + } +} diff --git a/modules/calendarview/helpers/calendarview_event.php b/modules/calendarview/helpers/calendarview_event.php new file mode 100644 index 0000000..e98415c --- /dev/null +++ b/modules/calendarview/helpers/calendarview_event.php @@ -0,0 +1,99 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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 calendarview_event_Core { + static function photo_menu($menu, $theme) { + $menu->append(Menu::factory("link") + ->id("calendarview") + ->label(t("View Calendar")) + ->url(url::site("calendarview/calendar/")) + ->css_id("g-calendarview-link")); + } + + static function movie_menu($menu, $theme) { + $menu->append(Menu::factory("link") + ->id("calendarview") + ->label(t("View Calendar")) + ->url(url::site("calendarview/calendar/")) + ->css_id("g-calendarview-link")); + } + + static function album_menu($menu, $theme) { + $menu->append(Menu::factory("link") + ->id("calendarview") + ->label(t("View Calendar")) + ->url(url::site("calendarview/calendar/")) + ->css_id("g-calendarview-link")); + } + + static function tag_menu($menu, $theme) { + $menu->append(Menu::factory("link") + ->id("calendarview") + ->label(t("View Calendar")) + ->url(url::site("calendarview/calendar/")) + ->css_id("g-calendarview-link")); + } + + static function pre_deactivate($data) { + // If the admin is about to deactivate EXIF, warn them that this module requires it. + if ($data->module == "exif") { + $data->messages["warn"][] = t("The CalendarView module requires the EXIF module."); + } + } + + static function module_change($changes) { + // If EXIF is deactivated, display a warning that it is required for this module to function properly. + if (!module::is_active("exif") || in_array("exif", $changes->deactivate)) { + site_status::warning( + t("The CalendarView module requires the EXIF module. " . + "<a href=\"%url\">Activate the EXIF module now</a>", + array("url" => html::mark_clean(url::site("admin/modules")))), + "calendarview_needs_exif"); + } else { + site_status::clear("calendarview_needs_exif"); + } + } + + static function show_user_profile($data) { + // Display a few months on the user profile screen. + $v = new View("user_profile_calendarview.html"); + $v->user_id = $data->user->id; + + // Figure out what month the users newest photo was taken it. + // Make that the last month to display. + // If a user hasn't uploaded anything, make the current month + // the last to be displayed. + $latest_photo = ORM::factory("item") + ->viewable() + ->where("type", "!=", "album") + ->where("captured", "!=", "") + ->where("owner_id", "=", $data->user->id) + ->order_by("captured", "DESC") + ->find_all(1); + if (count($latest_photo) > 0) { + $v->user_year = date('Y', $latest_photo[0]->captured); + $v->user_month = date('n', $latest_photo[0]->captured); + } else { + $v->user_year = date('Y'); + $v->user_month = date('n'); + } + + $data->content[] = (object) array("title" => t("User calendar"), "view" => $v); + } +} diff --git a/modules/calendarview/helpers/calendarview_installer.php b/modules/calendarview/helpers/calendarview_installer.php new file mode 100644 index 0000000..986a13f --- /dev/null +++ b/modules/calendarview/helpers/calendarview_installer.php @@ -0,0 +1,40 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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 calendarview_installer { + static function install() { + module::set_version("calendarview", 1); + } + + static function deactivate() { + site_status::clear("calendarview_needs_exif"); + } + + static function can_activate() { + $messages = array(); + if (!module::is_active("exif")) { + $messages["warn"][] = t("The CalendarView module requires the EXIF module."); + } + return $messages; + } + + static function uninstall() { + module::delete("calendarview"); + } +} diff --git a/modules/calendarview/helpers/calendarview_theme.php b/modules/calendarview/helpers/calendarview_theme.php new file mode 100644 index 0000000..d299bf3 --- /dev/null +++ b/modules/calendarview/helpers/calendarview_theme.php @@ -0,0 +1,25 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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 calendarview_theme_Core { + static function head($theme) { + return $theme->css("calendarview_calendar.css") . + $theme->css("calendarview_menu.css"); + } +} diff --git a/modules/calendarview/images/ico-view-calendarview.png b/modules/calendarview/images/ico-view-calendarview.png Binary files differnew file mode 100644 index 0000000..5e564b8 --- /dev/null +++ b/modules/calendarview/images/ico-view-calendarview.png diff --git a/modules/calendarview/libraries/PHPCalendar.php b/modules/calendarview/libraries/PHPCalendar.php new file mode 100644 index 0000000..2d1df2b --- /dev/null +++ b/modules/calendarview/libraries/PHPCalendar.php @@ -0,0 +1,87 @@ +<?php defined('SYSPATH') OR die('No direct access allowed.'); + +class PHPCalendar_Core { + // Month and year to use for calendaring + protected $month; + protected $year; + protected $month_url; + + // First Day of the Week (0 = Sunday or 1 = Monday). + protected $week_start = 0; + + // Events for the current month. + protected $event_data = Array(); + + public function __construct($month = NULL, $year = NULL, $url = NULL) + { + empty($month) and $month = date('n'); // Current month + empty($year) and $year = date('Y'); // Current year + + // Set the month and year + $this->month = (int) $month; + $this->year = (int) $year; + $this->month_url = $url; + } + + public function event($day_of_the_week, $event_url = NULL, $css_id = NULL, $custom_text = NULL) + { + $this->event_data += Array($day_of_the_week => Array($event_url, $css_id, $custom_text)); + } + + public function render() + { + return $this->generate_calendar($this->year, $this->month, $this->event_data, 2, $this->month_url, $this->week_start, NULL); + } + + # PHP Calendar (version 2.3), written by Keith Devens + # http://keithdevens.com/software/php_calendar + # see example at http://keithdevens.com/weblog + # License: http://keithdevens.com/software/license + function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()) + { + $first_of_month = gmmktime(0,0,0,$month,1,$year); + #remember that mktime will automatically correct if invalid dates are entered + # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998 + # this provides a built in "rounding" feature to generate_calendar() + + if ($first_day == 0) $day_names = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); + if ($first_day == 1) $day_names = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); + + list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month)); + $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day + $title = t(date("F", mktime(0, 0, 0, $month, 1, $year))) . ' ' . $year; + + #Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03 + @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable + if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> '; + if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>'; + $calendar = '<table class="calendar" id="g-calendar-month">'."\n". + '<td class="title" colspan="7" align="center">'.$p.($month_href ? '<a href="'. ($month_href) .'">'.$title.'</a>' : $title).$n."</td></tr>\n<tr>"; + + if($day_name_length){ #if the day names should be shown ($day_name_length > 0) + #if day_name_length is >3, the full name of the day will be printed + foreach($day_names as $d) + $calendar .= '<th abbr="' . $d .'">'.t($day_name_length < 4 ? substr($d,0,$day_name_length) : $d) . '</th>'; + $calendar .= "</tr>\n<tr>"; + } + + if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'"> </td>'; #initial 'empty' days + for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){ + if($weekday == 7){ + $weekday = 0; #start a new week + $calendar .= "</tr>\n<tr>"; + } + if(isset($days[$day]) and is_array($days[$day])){ + @list($link, $classes, $content) = $days[$day]; + if(is_null($content)) $content = $day; + $calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>'). + ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>'; + } + else $calendar .= "<td class=\"day\">$day</td>"; + } + if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days + + return $calendar."</tr>\n</table>\n"; + } +} +?>
\ No newline at end of file diff --git a/modules/calendarview/module.info b/modules/calendarview/module.info new file mode 100644 index 0000000..f51f162 --- /dev/null +++ b/modules/calendarview/module.info @@ -0,0 +1,7 @@ +name = "CalendarView" +description = "View your photos by the date they were taken." +version = 1 +author_name = "rWatcher" +author_url = "http://codex.gallery2.org/User:RWatcher" +info_url = "http://codex.gallery2.org/Gallery3:Modules:calendarview" +discuss_url = "http://gallery.menalto.com/node/92405" diff --git a/modules/calendarview/views/calendarview_sidebar.html.php b/modules/calendarview/views/calendarview_sidebar.html.php new file mode 100644 index 0000000..b4f1f6f --- /dev/null +++ b/modules/calendarview/views/calendarview_sidebar.html.php @@ -0,0 +1,9 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<ul> + <? if ($day_count > 0): ?> + <li><a href="<?=url::site("calendarview/day/" . date("Y", $date) . "/-1/" . date("n", $date) . "/" . date("j", $date)); ?>"><?=t("More from"); ?> <?=date("F", $date); ?> <?=date("j", $date); ?><?=date("S", $date); ?></a></li> + <? endif ?> + <? if ($month_count > 0): ?> + <li><a href="<?=url::site("calendarview/month/" . date("Y", $date) . "/-1/" . date("n", $date)); ?>"><?=t("More from"); ?> <?=date("F", $date); ?></a></li> + <? endif ?> +</ul>
\ No newline at end of file diff --git a/modules/calendarview/views/calendarview_year.html.php b/modules/calendarview/views/calendarview_year.html.php new file mode 100644 index 0000000..b40d7d5 --- /dev/null +++ b/modules/calendarview/views/calendarview_year.html.php @@ -0,0 +1,95 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<div id="g-album-header"> + <div id="g-album-header-buttons"> + <?= $theme->dynamic_top() ?> + </div> + <h1><?= html::clean($title) ?></h1> +</div> + +<br/><?= $calendar_user_year_form ?><br /><br /> + +<? + // Search the db for all photos that were taken during the selected year. + if ($calendar_user == "-1") { + $items_for_year = ORM::factory("item") + ->viewable() + ->where("type", "!=", "album") + ->where("captured", ">=", mktime(0, 0, 0, 1, 1, $calendar_year)) + ->where("captured", "<", mktime(0, 0, 0, 1, 1, ($calendar_year + 1))) + ->order_by("captured") + ->find_all(); + } else { + $items_for_year = ORM::factory("item") + ->viewable() + ->where("owner_id", "=", $calendar_user) + ->where("type", "!=", "album") + ->where("captured", ">=", mktime(0, 0, 0, 1, 1, $calendar_year)) + ->where("captured", "<", mktime(0, 0, 0, 1, 1, ($calendar_year + 1))) + ->order_by("captured") + ->find_all(); + } + + // Set up some initial variables. + $counter_months = 1; + $counter_days = 0; + $counter = 0; + + // Set up the January Calendar. + // Check and see if any photos were taken in January, + // If so, make the month title into a clickable link. + print "<div id=\"g-calendar-grid\">"; + if ((count($items_for_year) > 0) && (date("n", $items_for_year[$counter]->captured) == 1)) { + $month_url = url::site("calendarview/month/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/"); + } else { + $month_url = ""; + } + $calendar = new PHPCalendar($counter_months, $calendar_year, $month_url); + + // Loop through each photo taken during this year, and see what month and day they were taken on. + // Make the corresponding dates on the calendars into clickable links. + while ($counter < (count($items_for_year))) { + + // Check and see if we've switched to a new month. + // If so, render the current calendar and set up a new one. + while (date("n", $items_for_year[$counter]->captured) > $counter_months) { + echo $calendar->render(); + print "</div>"; + $counter_months++; + $counter_days = 0; + print "<div id=\"g-calendar-grid\">"; + if (date("n", $items_for_year[$counter]->captured) == $counter_months) { + $month_url = url::site("calendarview/month/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/"); + } else { + $month_url = ""; + } + $calendar = new PHPCalendar($counter_months, $calendar_year, $month_url); + } + + // If the day of the current photo is different then the day of the previous photo, + // then add a link to the calendar for this date and set the current day to this day. + if (date("j", $items_for_year[$counter]->captured) > $counter_days) { + $counter_days = date("j", $items_for_year[$counter]->captured); + $calendar->event($counter_days, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $counter_days)); + } + + // Move onto the next photo. + $counter++; + } + + // Print out the last calendar to be generated. + echo $calendar->render(); + print "</div>"; + $counter_months++; + + // If the calendar that was previously rendered was not December, + // then print out a few empty months for the rest of the year. + while ($counter_months < 13) { + print "<div id=\"g-calendar-grid\">"; + $month_url = ""; + $calendar = new PHPCalendar($counter_months, $calendar_year, $month_url); + echo $calendar->render(); + print "</div>"; + $counter_months++; + } +?> +<?= $theme->dynamic_bottom() ?> diff --git a/modules/calendarview/views/user_profile_calendarview.html.php b/modules/calendarview/views/user_profile_calendarview.html.php new file mode 100644 index 0000000..4d9d68a --- /dev/null +++ b/modules/calendarview/views/user_profile_calendarview.html.php @@ -0,0 +1,86 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<? + // Generate a list of items within the specified 3 month time-frame. + $items = ORM::factory("item") + ->viewable() + ->where("owner_id", "=", $user_id) + ->where("type", "!=", "album") + ->where("captured", ">=", mktime(0, 0, 0, $user_month-2, 1, $user_year)) + ->where("captured", "<", mktime(0, 0, 0, $user_month+1, 1, ($user_year))) + ->order_by("captured") + ->find_all(); + + // Set up some initial variables. + $calendar_year = $user_year; + $counter_months = $user_month - 2; + if ($counter_months < 1) { + $counter_months += 12; + $calendar_year--; + } + $counter_days = 0; + $counter = 0; + + // Print the first month. + print "<div id=\"g-calendar-profile-grid\">"; + if ((count($items) > 0) && (date("n", $items[$counter]->captured) == $counter_months)) { + $month_url = url::site("calendarview/month/" . $calendar_year . "/" . $user_id . "/" . $counter_months . "/"); + } else { + $month_url = ""; + } + $calendar = new PHPCalendar($counter_months, $calendar_year, $month_url); + + // Loop through each photo taken during the 3 month time frame, and see what month and day they were taken on. + // Make the corresponding dates on the calendars into clickable links. + while ($counter < (count($items))) { + + // Check and see if we've switched to a new month. + // If so, render the current calendar and set up a new one. + // Continue printing empty months until we reach the next photo or the last month. + while (date("n", $items[$counter]->captured) != $counter_months) { + echo $calendar->render(); + print "</div>"; + $counter_months++; + if ($counter_months == 13) { + $counter_months = 1; + $calendar_year++; + } + $counter_days = 0; + print "<div id=\"g-calendar-profile-grid\">"; + if (date("n", $items[$counter]->captured) == $counter_months) { + $month_url = url::site("calendarview/month/" . $calendar_year . "/" . $user_id . "/" . $counter_months . "/"); + } else { + $month_url = ""; + } + $calendar = new PHPCalendar($counter_months, $calendar_year, $month_url); + } + + // If the day of the current photo is different then the day of the previous photo, + // then add a link to the calendar for this date and set the current day to this day. + if (date("j", $items[$counter]->captured) > $counter_days) { + $counter_days = date("j", $items[$counter]->captured); + $calendar->event($counter_days, url::site("calendarview/day/" . $calendar_year . "/" . $user_id . "/" . $counter_months . "/" . $counter_days)); + } + + // Move onto the next photo. + $counter++; + } + + // Print out the last calendar to be generated. + echo $calendar->render(); + print "</div>"; + $counter_months++; + + // If the calendar that was previously rendered was not the final month, + // then print out a few empty months to fill the remaining space. + while ($counter_months < $user_month + 1) { + print "<div id=\"g-calendar-profile-grid\">"; + $month_url = ""; + $calendar = new PHPCalendar($counter_months, $calendar_year, $month_url); + echo $calendar->render(); + print "</div>"; + $counter_months++; + } + +?> +<br clear="all" /><br /><br /> +<div align="right"><a href="<?=url::site("calendarview/calendar/{$user_year}/{$user_id}"); ?>"><?=t("View full calendar"); ?> >></a></div> |
