function show($view, $loc = null, $title = '') { global $user; global $db; $i18n = exponent_lang_loadFile('modules/calendarmodule/class.php'); $template = new template('calendarmodule', $view, $loc); $template->assign('moduletitle', $title); $canviewapproval = false; $inapproval = false; global $user; if ($user) { $canviewapproval = exponent_permissions_check("approve", $loc) || exponent_permissions_check("manage_approval", $loc); } if ($db->countObjects("calendar", "location_data='" . serialize($loc) . "' AND approved!=1")) { foreach ($db->selectObjects("calendar", "location_data='" . serialize($loc) . "' AND approved!=1") as $c) { if ($c->poster == $user->id) { $canviewapproval = true; } } $inapproval = true; } $time = isset($_GET['time']) ? $_GET['time'] : time(); $template->assign("time", $time); $viewconfig = $template->viewparams; if ($viewconfig === null) { $viewconfig = array("type" => "default"); } if (!defined("SYS_DATETIME")) { include_once BASE . "subsystems/datetime.php"; } if (!defined('SYS_SORTING')) { include_once BASE . 'subsystems/sorting.php'; } if (!function_exists("exponent_sorting_byEventStartAscending")) { function exponent_sorting_byEventStartAscending($a, $b) { return $a->eventstart < $b->eventstart ? -1 : 1; } } //Pathos Compatibility::this is deprecated if (@defined(PATHOS)) { if (!function_exists('pathos_sorting_byEventStartAscending')) { function pathos_sorting_byDateAscending($a, $b) { return exponent_sorting_byEventStartAscending($a, $b); } } } //End Pathos Compatibility if ($viewconfig['type'] == "minical") { $monthly = array(); $info = getdate(time()); $info = getdate(time()); // Grab non-day numbers only (before end of month) $week = 0; $currentweek = 0; $currentday = $info['mday']; $infofirst = getdate(mktime(12, 0, 0, $info['mon'], 1, $info['year'])); if ($infofirst['wday'] == 0) { $monthly[$week] = array(); } // initialize for non days for ($i = 0 - $infofirst['wday']; $i < 0; $i++) { $monthly[$week][$i] = array("number" => -1, "ts" => -1); } $weekday = $infofirst['wday']; // day number in grid. if 7+, switch weeks // Grab day counts (deprecated, handled by the php date function) // $endofmonth = exponent_datetime_endOfMonthDay(time()); $endofmonth = date('t', time()); for ($i = 1; $i <= $endofmonth; $i++) { $start = mktime(0, 0, 0, $info['mon'], $i, $info['year']); if ($i == $info['mday']) { $currentweek = $week; } $monthly[$week][$i] = array("ts" => $start, "number" => $db->countObjects("eventdate", "location_data='" . serialize($loc) . "' AND date = {$start}")); if ($weekday >= 6) { $week++; $monthly[$week] = array(); // allocate an array for the next week $weekday = 0; } else { $weekday++; } } // Grab non-day numbers only (after end of month) for ($i = 1; $weekday && $i <= 7 - $weekday; $i++) { $monthly[$week][$i + $endofmonth] = -1; } $template->assign("monthly", $monthly); $template->assign("currentweek", $currentweek); $template->assign("currentday", $currentday); $template->assign("now", time()); } else { if ($viewconfig['type'] == "byday") { $startperiod = 0; $totaldays = 0; if ($viewconfig['range'] == "week") { $startperiod = exponent_datetime_startOfWeekTimestamp($time); $totaldays = 7; } else { $startperiod = exponent_datetime_startOfMonthTimestamp($time); $totaldays = date('t', time()); } $template->assign("prev_timestamp", $startperiod - 3600); $template->assign("next_timestamp", $startperiod + $totaldays * 86400 + 3600); $days = array(); //added per Ignacio $endofmonth = date('t', $time); for ($i = 1; $i <= $endofmonth; $i++) { $info = getdate($time); $start = mktime(0, 0, 0, $info['mon'], $i, $info['year']); //for ($i = 0; $i < $totaldays; $i++) { // if( $i == 0 ) // { // $start = $startperiod + ($i*86400); // } else { // $start = $startperiod + ($i*86400)-3600; // } #$days[$start] = $db->selectObjects("calendar","location_data='".serialize($loc)."' AND (eventstart >= $start AND eventend <= " . ($start+86399) . ") AND approved!=0"); $edates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date = {$start}"); $days[$start] = calendarmodule::_getEventsForDates($edates); for ($j = 0; $j < count($days[$start]); $j++) { $thisloc = exponent_core_makeLocation($loc->mod, $loc->src, $days[$start][$j]->id); $days[$start][$j]->permissions = array("administrate" => exponent_permissions_check("administrate", $thisloc) || exponent_permissions_check("administrate", $loc), "edit" => exponent_permissions_check("edit", $thisloc) || exponent_permissions_check("edit", $loc), "delete" => exponent_permissions_check("delete", $thisloc) || exponent_permissions_check("delete", $loc)); } usort($days[$start], "exponent_sorting_byEventStartAscending"); } $template->assign("days", $days); } else { if ($viewconfig['type'] == "monthly") { $monthly = array(); $counts = array(); $info = getdate($time); $nowinfo = getdate(time()); if ($info['mon'] != $nowinfo['mon']) { $nowinfo['mday'] = -10; } // Grab non-day numbers only (before end of month) $week = 0; $currentweek = -1; $timefirst = mktime(12, 0, 0, $info['mon'], 1, $info['year']); $infofirst = getdate($timefirst); if ($infofirst['wday'] == 0) { $monthly[$week] = array(); // initialize for non days $counts[$week] = array(); } for ($i = 1 - $infofirst['wday']; $i < 1; $i++) { $monthly[$week][$i] = array(); $counts[$week][$i] = -1; } $weekday = $infofirst['wday']; // day number in grid. if 7+, switch weeks // Grab day counts (deprecated, handled by the date function) // $endofmonth = exponent_datetime_endOfMonthDay($time); $endofmonth = date('t', $time); for ($i = 1; $i <= $endofmonth; $i++) { $start = mktime(0, 0, 0, $info['mon'], $i, $info['year']); if ($i == $nowinfo['mday']) { $currentweek = $week; } #$monthly[$week][$i] = $db->selectObjects("calendar","location_data='".serialize($loc)."' AND (eventstart >= $start AND eventend <= " . ($start+86399) . ") AND approved!=0"); $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date = {$start}"); $monthly[$week][$i] = calendarmodule::_getEventsForDates($dates); $counts[$week][$i] = count($monthly[$week][$i]); if ($weekday >= 6) { $week++; $monthly[$week] = array(); // allocate an array for the next week $counts[$week] = array(); $weekday = 0; } else { $weekday++; } } // Grab non-day numbers only (after end of month) for ($i = 1; $weekday && $i < 8 - $weekday; $i++) { $monthly[$week][$i + $endofmonth] = array(); $counts[$week][$i + $endofmonth] = -1; } $template->assign("currentweek", $currentweek); $template->assign("monthly", $monthly); $template->assign("counts", $counts); $template->assign("nextmonth", $timefirst + 86400 * 45); $template->assign("prevmonth", $timefirst - 86400 * 15); $template->assign("now", $timefirst); } else { if ($viewconfig['type'] == "administration") { // Check perms and return if cant view if ($viewconfig['type'] == "administration" && !$user) { return; } $continue = exponent_permissions_check("administrate", $loc) || exponent_permissions_check("post", $loc) || exponent_permissions_check("edit", $loc) || exponent_permissions_check("delete", $loc) || exponent_permissions_check("approve", $loc) || exponent_permissions_check("manage_approval", $loc) ? 1 : 0; $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "'"); $items = calendarmodule::_getEventsForDates($dates); if (!$continue) { foreach ($items as $i) { $iloc = exponent_core_makeLocation($loc->mod, $loc->src, $i->id); if (exponent_permissions_check("edit", $iloc) || exponent_permissions_check("delete", $iloc) || exponent_permissions_check("administrate", $iloc)) { $continue = true; } } } if (!$continue) { return; } for ($i = 0; $i < count($items); $i++) { $thisloc = exponent_core_makeLocation($loc->mod, $loc->src, $items[$i]->id); if ($user && $items[$i]->poster == $user->id) { $canviewapproval = 1; } $items[$i]->permissions = array("administrate" => exponent_permissions_check("administrate", $thisloc) || exponent_permissions_check("administrate", $loc), "edit" => exponent_permissions_check("edit", $thisloc) || exponent_permissions_check("edit", $loc), "delete" => exponent_permissions_check("delete", $thisloc) || exponent_permissions_check("delete", $loc)); } usort($items, "exponent_sorting_byEventStartAscending"); $template->assign("items", $items); } else { if ($viewconfig['type'] == "default") { if (!isset($viewconfig['range'])) { $viewconfig['range'] = "all"; } $limit = ''; if (isset($template->viewconfig) && isset($template->viewconfig['num_events']) && $template->viewconfig['num_events'] != 0) { $limit = $db->limit($template->viewconfig['num_events'], 0); } $items = null; $dates = null; $day = exponent_datetime_startOfDayTimestamp(time()); $sort_asc = true; // For the getEventsForDates call switch ($viewconfig['range']) { case "all": $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "'"); break; case "upcoming": $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date > {$day} ORDER BY date ASC " . $limit); break; case "past": $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date < {$day} ORDER BY date DESC " . $limit); $sort_asc = false; break; case "today": $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date = {$day}"); break; case "next": $dates = array($db->selectObject("eventdate", "location_data='" . serialize($loc) . "' AND date >= {$day}")); break; case "month": $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date >= " . exponent_datetime_startOfMonthTimestamp(time()) . " AND date <= " . exponent_datetime_endOfMonthTimestamp(time())); break; } $items = calendarmodule::_getEventsForDates($dates, $sort_asc); for ($i = 0; $i < count($items); $i++) { $thisloc = exponent_core_makeLocation($loc->mod, $loc->src, $items[$i]->id); if ($user && $items[$i]->poster == $user->id) { $canviewapproval = 1; } $items[$i]->permissions = array('administrate' => exponent_permissions_check('administrate', $thisloc) || exponent_permissions_check('administrate', $loc), 'edit' => exponent_permissions_check('edit', $thisloc) || exponent_permissions_check('edit', $loc), 'delete' => exponent_permissions_check('delete', $thisloc) || exponent_permissions_check('delete', $loc)); } $template->assign('items', $items); } } } } } $template->assign('in_approval', $inapproval); $template->assign('canview_approval_link', $canviewapproval); $template->register_permissions(array('administrate', 'configure', 'post', 'edit', 'delete', 'manage_approval', 'manage_categories'), $loc); $cats = $db->selectObjectsIndexedArray("category", "location_data='" . serialize($loc) . "'"); $cats[0] = null; $cats[0]->name = '<i>' . $i18n['no_category'] . '</i>'; $cats[0]->color = "#000000"; $template->assign("categories", $cats); $config = $db->selectObject("calendarmodule_config", "location_data='" . serialize($loc) . "'"); if (!$config) { $config->enable_categories = 0; } $template->assign("modconfig", $config); $template->output(); }
function show($view, $loc = null, $title = '') { $template = new template('WeblogModule', $view, $loc); global $db; global $user; $user_id = $user ? $user->id : -1; $config = $db->selectObject('WeblogModule_config', "location_data='" . serialize($loc) . "'"); if ($config == null) { $config->allow_comments = 1; $config->items_per_page = 10; } $viewconfig = array('type' => 'default'); if (is_readable($template->viewdir . "/{$view}.config")) { $viewconfig = (include $template->viewdir . "/{$view}.config"); } $where = '(is_draft = 0 OR poster = ' . $user_id . ") AND location_data='" . serialize($loc) . "'"; if (!exponent_permissions_check('view_private', $loc)) { $where .= ' AND is_private = 0'; } if ($viewconfig['type'] == 'monthlist') { $months = array(); $min_date = $db->min('weblog_post', 'posted', 'location_data', $where); $max_date = $db->max('weblog_post', 'posted', 'location_data', $where); $months = array(); if (!defined('SYS_DATETIME')) { require_once BASE . 'subsystems/datetime.php'; } $start_month = exponent_datetime_startOfMonthTimestamp($min_date); $end_month = exponent_datetime_endOfMonthTimestamp($min_date) + 86399; do { $count = $db->countObjects('weblog_post', $where . ' AND posted >= ' . $start_month . ' AND posted <= ' . $end_month); if ($count) { $months[$start_month] = $count; } $start_month = $end_month + 1; $end_month = exponent_datetime_endOfMonthTimestamp($start_month) + 86399; } while ($start_month < $max_date); $template->assign('months', array_reverse($months, true)); } else { if ($viewconfig['type'] == 'calendar') { if (!defined('SYS_DATETIME')) { require_once BASE . 'subsystems/datetime.php'; } $month_days = exponent_datetime_monthlyDaysTimestamp(time()); for ($i = 0; $i < count($month_days); $i++) { foreach ($month_days[$i] as $mday => $timestamp) { if ($mday > 0) { // Got a valid one. Go with it. $month_days[$i][$mday] = array('number' => $db->countObjects('weblog_post', $where . ' AND posted >= ' . $timestamp . ' AND posted < ' . strtotime('+1 day', $timestamp)), 'ts' => $timestamp); } } } $template->assign('days', $month_days); $template->assign('now', time()); } else { $total = $db->countObjects('weblog_post', $where); $posts = $db->selectObjects('weblog_post', $where . ' ORDER BY posted DESC ' . $db->limit($config->items_per_page, 0)); if (!defined('SYS_SORTING')) { require_once BASE . 'subsystems/sorting.php'; } for ($i = 0; $i < count($posts); $i++) { $ploc = exponent_core_makeLocation($loc->mod, $loc->src, $posts[$i]->id); $posts[$i]->permissions = array('administrate' => exponent_permissions_check('administrate', $ploc), 'edit' => exponent_permissions_check('edit', $ploc), 'delete' => exponent_permissions_check('delete', $ploc), 'comment' => exponent_permissions_check('comment', $ploc), 'edit_comments' => exponent_permissions_check('edit_comments', $ploc), 'delete_comments' => exponent_permissions_check('delete_comments', $ploc), 'view_private' => exponent_permissions_check('view_private', $ploc)); $comments = $db->selectObjects('weblog_comment', 'parent_id=' . $posts[$i]->id); usort($comments, 'exponent_sorting_byPostedDescending'); $posts[$i]->comments = $comments; } usort($posts, 'exponent_sorting_byPostedDescending'); $template->assign('posts', $posts); $template->assign('total_posts', $total); } } $template->register_permissions(array('administrate', 'configure', 'post', 'edit', 'delete', 'comment', 'edit_comments', 'delete_comments', 'view_private'), $loc); $template->assign('config', $config); $template->assign('moduletitle', $title); $template->output(); }
# Software Foundation; either version 2 of the # License, or (at your option) any later version. # # GPL: http://www.gnu.org/licenses/gpl.txt # ################################################## if (!defined('EXPONENT')) { exit(''); } exponent_flow_set(SYS_FLOW_PUBLIC, SYS_FLOW_ACTION); if (!defined('SYS_DATETIME')) { require_once BASE . 'subsystems/datetime.php'; } $time = isset($_GET['month']) ? $_GET['month'] : time(); $start_month = exponent_datetime_startOfMonthTimestamp($time); $end_month = exponent_datetime_endOfMonthTimestamp($time); $where = "location_data='" . serialize($loc) . "' AND (is_draft = 0 OR poster = " . ($user ? $user->id : -1) . ") AND posted >= {$start_month} AND posted <= {$end_month}"; if (!exponent_permissions_check('view_private', $loc)) { $where .= ' AND is_private = 0'; } $config = $db->selectObject('WeblogModule_config', "location_data='" . serialize($loc) . "'"); if ($config == null) { $config->allow_comments = 1; } $posts = $db->selectObjects('weblog_post', $where); if (!defined('SYS_SORTING')) { require_once BASE . 'subsystems/sorting.php'; } for ($i = 0; $i < count($posts); $i++) { $ploc = exponent_core_makeLocation($loc->mod, $loc->src, $posts[$i]->id); $posts[$i]->permissions = array('administrate' => exponent_permissions_check('administrate', $ploc), 'edit' => exponent_permissions_check('edit', $ploc), 'delete' => exponent_permissions_check('delete', $ploc), 'comment' => exponent_permissions_check('comment', $ploc), 'edit_comments' => exponent_permissions_check('edit_comments', $ploc), 'delete_comments' => exponent_permissions_check('delete_comments', $ploc), 'view_private' => exponent_permissions_check('view_private', $ploc));