Example #1
0
         $calendar_year = $year;
     } else {
         if ($day > $num_days && $calendar_month != $prev_month['month']) {
             $in_month = 0;
             $calendar_month = $next_month['month'];
             $calendar_year = $next_month['year'];
             $day = 1;
             if ($calendar_month == $month) {
                 $in_month = 1;
             }
         }
     }
 }
 if ($weekday_id == 0) {
     $week_stamp = gmmktime(0, 0, 0, $calendar_month, $day, $calendar_year);
     $week_link = get_calendar_week_link($calendar['cid'], $week_stamp);
 }
 if ($weekday_id == 0 && $calendar_month == $next_month['month']) {
     break;
 }
 // Any events on this specific day?
 if (is_array($events_cache) && array_key_exists("{$day}-{$calendar_month}-{$calendar_year}", $events_cache)) {
     $total_events = count($events_cache["{$day}-{$calendar_month}-{$calendar_year}"]);
     if ($total_events > $calendar['eventlimit'] && $calendar['eventlimit'] != 0) {
         if ($total_events > 1) {
             $day_events = "<div style=\"margin-bottom: 4px;\"><a href=\"" . get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day) . "\" class=\"smalltext\">{$total_events} {$lang->events}</a></div>\n";
         } else {
             $day_events = "<div style=\"margin-bottom: 4px;\"><a href=\"" . get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day) . "\" class=\"smalltext\">1 {$lang->event}</a></div>\n";
         }
     } else {
         foreach ($events_cache["{$day}-{$calendar_month}-{$calendar_year}"] as $event) {
/**
 * Build a mini calendar for a specific month
 *
 * @param array The calendar array for the calendar
 * @param int The month of the year
 * @param int The year
 * @param array Optional events cache for this calendar
 * @return string The built mini calendar
 */
function build_mini_calendar($calendar, $month, $year, &$events_cache)
{
    global $events_cache, $mybb, $templates, $theme, $monthnames;
    // Incoming month/year?
    if (!$year || $year > my_date("Y") + 5) {
        $year = my_date("Y");
    }
    // Then the month
    if ($month < 1 || $month > 12) {
        $month = my_date("n");
    }
    $weekdays = fetch_weekday_structure($calendar['startofweek']);
    $calendar_permissions = get_calendar_permissions($calendar['cid']);
    $month_link = get_calendar_link($calendar['cid'], $year, $month);
    $next_month = get_next_month($month, $year);
    $prev_month = get_prev_month($month, $year);
    $month_start_weekday = gmdate("w", gmmktime(0, 0, 0, $month, $calendar['startofweek'] + 1, $year));
    if ($month_start_weekday != $weekdays[0] || $calendar['startofweek'] != 0) {
        $day = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
        $day -= array_search($month_start_weekday, $weekdays);
        $day += $calendar['startofweek'] + 1;
        $calendar_month = $prev_month['month'];
        $calendar_year = $prev_month['year'];
        if ($day > 31 && $calendar['startofweek'] == 1 && $prev_month_days == 30) {
            // We need to fix it for these days
            $day = 25;
        }
    } else {
        $day = $calendar['startofweek'] + 1;
        $calendar_month = $month;
        $calendar_year = $year;
    }
    $prev_month_days = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
    // So now we fetch events for this month
    $start_timestamp = gmmktime(0, 0, 0, $calendar_month, $day, $year);
    $num_days = gmdate("t", gmmktime(0, 0, 0, $month, 1, $year));
    $end_timestamp = gmmktime(23, 59, 59, $month, $num_days, $year);
    if (!$events_cache) {
        $events_cache = get_events($calendar, $start_timestamp, $end_timestamp, $calendar_permissions['canmoderateevents']);
    }
    $today = my_date("dnY");
    // Build weekday headers
    $weekday_headers = '';
    foreach ($weekdays as $weekday) {
        $weekday_name = fetch_weekday_name($weekday, true);
        eval("\$weekday_headers .= \"" . $templates->get("calendar_mini_weekdayheader") . "\";");
    }
    $in_month = 0;
    $day_bits = $calendar_rows = '';
    for ($row = 0; $row < 6; ++$row) {
        foreach ($weekdays as $weekday_id => $weekday) {
            // Current month always starts on 1st row
            if ($row == 0 && $day == $calendar['startofweek'] + 1) {
                $in_month = 1;
                $calendar_month = $month;
                $calendar_year = $year;
            } else {
                if ($calendar_month == $prev_month['month'] && $day > $prev_month_days) {
                    $day = 1;
                    $in_month = 1;
                    $calendar_month = $month;
                    $calendar_year = $year;
                } else {
                    if ($day > $num_days && $calendar_month != $prev_month['month']) {
                        $in_month = 0;
                        $calendar_month = $next_month['month'];
                        $calendar_year = $next_month['year'];
                        $day = 1;
                        if ($calendar_month == $month) {
                            $in_month = 1;
                        }
                    }
                }
            }
            if ($weekday_id == 0) {
                $week_stamp = gmmktime(0, 0, 0, $calendar_month, $day, $calendar_year);
                $week_link = get_calendar_week_link($calendar['cid'], $week_stamp);
            }
            if ($weekday_id == 0 && $calendar_month == $next_month['month']) {
                break;
            }
            $link_to_day = false;
            // Any events on this specific day?
            if (@count($events_cache["{$day}-{$calendar_month}-{$calendar_year}"]) > 0) {
                $link_to_day = true;
            }
            // Is the current day
            if ($day . $calendar_month . $year == $today && $month == $calendar_month) {
                $day_class = "trow_sep";
            } else {
                if ($in_month == 0) {
                    $day_class = "trow1";
                } else {
                    $day_class = "trow2";
                }
            }
            if ($link_to_day) {
                $day_link = "<a href=\"" . get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day) . "\">{$day}</a>";
            } else {
                $day_link = $day;
            }
            eval("\$day_bits .= \"" . $templates->get("calendar_mini_weekrow_day") . "\";");
            ++$day;
        }
        if ($day_bits) {
            eval("\$calendar_rows .= \"" . $templates->get("calendar_mini_weekrow") . "\";");
        }
        $day_bits = "";
    }
    eval("\$mini_calendar = \"" . $templates->get("calendar_mini") . "\";");
    return $mini_calendar;
}
Example #3
0
/**
 * Redirect if necessary.
 *
 */
function google_seo_redirect_hook()
{
    global $db, $mybb, $settings, $plugins, $google_seo_redirect;
    if ($mybb->request_method == "post") {
        // Never touch posts.
        return;
    }
    // Build the target URL we should be at:
    switch (THIS_SCRIPT) {
        case 'forumdisplay.php':
            $fid = (int) $mybb->input['fid'];
            $page = (int) $mybb->input['page'];
            if ($fid) {
                // forum as index tweak
                if ($fid == $settings['google_seo_tweak_index_fid']) {
                    $target = "";
                    if ($page > 1) {
                        $target = "?page={$page}";
                    }
                } else {
                    $target = get_forum_link($fid, $page);
                }
                $kill['fid'] = '';
                $kill['page'] = '';
                $kill['google_seo_forum'] = '';
                $kill['google_seo'] = '';
            }
            break;
        case 'showthread.php':
            // pid overrules tid, so we must check pid first,
            // even at the cost of an additional query.
            if ((int) $mybb->input['pid']) {
                $tid = google_seo_tid((int) $mybb->input['pid'], (int) $mybb->input['tid'], $settings['google_seo_redirect_posts']);
                $target = get_post_link((int) $mybb->input['pid'], $tid);
                $kill['pid'] = '';
                $kill['tid'] = '';
                $kill['google_seo_thread'] = '';
                $kill['google_seo'] = '';
            } else {
                if ((int) $mybb->input['tid']) {
                    $target = get_thread_link((int) $mybb->input['tid'], (int) $mybb->input['page'], (string) $mybb->input['action']);
                    $kill['tid'] = '';
                    $kill['action'] = '';
                    $kill['google_seo_thread'] = '';
                    $kill['google_seo'] = '';
                    if ($mybb->input['page'] != 'last') {
                        $kill['page'] = '';
                    }
                }
            }
            break;
        case 'announcements.php':
            if ((int) $mybb->input['aid']) {
                $target = get_announcement_link((int) $mybb->input['aid']);
                $kill['aid'] = '';
                $kill['google_seo_announcement'] = '';
                $kill['google_seo'] = '';
            }
            break;
        case 'member.php':
            if ((int) $mybb->input['uid']) {
                if ($settings['google_seo_redirect_litespeed'] && $mybb->input['action'] != 'profile') {
                    // Work around rewrite bug in LiteSpeed (double action conflict).
                    break;
                }
                $target = get_profile_link((int) $mybb->input['uid']);
                $kill['uid'] = '';
                $kill['google_seo_user'] = '';
                $kill['google_seo'] = '';
                if ($mybb->input['action'] == 'profile') {
                    $kill['action'] = '';
                }
            }
            break;
        case 'calendar.php':
            if ((int) $mybb->input['eid']) {
                if ($settings['google_seo_redirect_litespeed'] && $mybb->input['action'] != 'profile') {
                    // Work around rewrite bug in LiteSpeed (double action conflict).
                    break;
                }
                $target = get_event_link((int) $mybb->input['eid']);
                $kill['eid'] = '';
                $kill['google_seo_event'] = '';
                $kill['google_seo'] = '';
                if ($mybb->input['action'] == 'event') {
                    $kill['action'] = '';
                }
            } else {
                if (!(int) $mybb->input['calendar']) {
                    // Special case: Default calendar.
                    // Code taken from calendar.php
                    $query = $db->simple_select("calendars", "cid", "", array('order_by' => 'disporder', 'limit' => 1));
                    $cid = $db->fetch_field($query, "cid");
                    $mybb->input['calendar'] = $cid;
                }
                if ($mybb->input['action'] == "weekview") {
                    $target = get_calendar_week_link((int) $mybb->input['calendar'], (int) str_replace('n', '-', $mybb->input['week']));
                    $kill['calendar'] = '';
                    $kill['week'] = '';
                    $kill['action'] = '';
                    $kill['google_seo_calendar'] = '';
                    $kill['google_seo'] = '';
                } else {
                    $target = get_calendar_link((int) $mybb->input['calendar'], (int) $mybb->input['year'], (int) $mybb->input['month'], (int) $mybb->input['day']);
                    $kill['calendar'] = '';
                    $kill['year'] = '';
                    $kill['month'] = '';
                    $kill['day'] = '';
                    $kill['google_seo_calendar'] = '';
                    $kill['google_seo'] = '';
                }
            }
            break;
    }
    // Verify that we are already at the target.
    if (isset($target)) {
        $target = $settings['bburl'] . '/' . urldecode($target);
        $current = google_seo_redirect_current_url();
        // Not identical (although it may only be the query string).
        if ($current != $target) {
            // Parse current and target
            $target_parse = explode("?", $target, 2);
            $current_parse = explode("?", $current, 2);
            // Location
            $location_target = $target_parse[0];
            $location_current = $current_parse[0];
            // Fix broken query strings (e.g. search.php)
            $broken_query = preg_replace("/\\?([^&?=]+)([=&])/u", '&$1$2', $current_parse[1]);
            if ($current_parse[1] != $broken_query) {
                $change = 1;
                $current_parse[2] = $current_parse[1];
                $current_parse[1] = $broken_query;
            }
            // Query
            $current_dynamic = google_seo_dynamic('?' . $current_parse[1]);
            $target_dynamic = google_seo_dynamic('?' . $target_parse[1]);
            parse_str(htmlspecialchars_decode($target_parse[1]), $query_target);
            parse_str($current_parse[1], $query_current);
            if (@get_magic_quotes_gpc()) {
                // Dear PHP, I don't need magic, thank you very much.
                $mybb->strip_slashes_array($query_target);
                $mybb->strip_slashes_array($query_current);
            }
            $query = $query_current;
            // Kill query string elements that already are part of the URL.
            if (!$query[$target_dynamic]) {
                unset($query[$target_dynamic]);
                unset($query_current[$target_dynamic]);
                unset($query_target[$target_dynamic]);
            }
            if (!$query[$current_dynamic]) {
                unset($query[$current_dynamic]);
                unset($query_current[$current_dynamic]);
                unset($query_target[$current_dynamic]);
            }
            foreach ($kill as $k => $v) {
                unset($query[$k]);
            }
            // Final query, current parameters retained
            $query = array_merge($query_target, $query);
            if (count($query) != count($query_current)) {
                $change = 2;
            } else {
                if ($current_dynamic != $target_dynamic) {
                    $change = 3;
                } else {
                    foreach ($query as $k => $v) {
                        if ($query_current[$k] != $v) {
                            $change = 4;
                        }
                    }
                }
            }
            // Definitely not identical?
            if ($change || $location_target != $location_current) {
                // Check if redirect debugging is enabled.
                if ($settings['google_seo_redirect_debug'] && $mybb->usergroup['cancp'] == 1) {
                    if ($query['google_seo_redirect']) {
                        // print out information about this redirect and return
                        header("Content-type: text/html; charset=UTF-8");
                        echo "<pre style=\"text-align: left\">";
                        echo "Google SEO Redirect Debug Information:\n";
                        echo "!!! WARNING: This may contain cookie authentication data. Don't post debug info in public. !!!\n";
                        echo htmlspecialchars(print_r(array('THIS_SCRIPT' => THIS_SCRIPT, '_SERVER' => array_merge($_SERVER, array('HTTP_COOKIE' => '')), 'mybb->input' => $mybb->input, 'kill' => $kill, 'target' => $target, 'current' => $current, 'target_parse' => $target_parse, 'current_parse' => $current_parse, 'target_dynamic' => $target_dynamic, 'current_dynamic' => $current_dynamic, 'location_target' => $location_target, 'location_current' => $location_current, 'broken_query' => $broken_query, 'change' => $change, 'query_target' => $query_target, 'query_current' => $query_current, 'query' => $query), true), ENT_COMPAT, "UTF-8");
                        echo "</pre>";
                        return;
                    } else {
                        $query['google_seo_redirect'] = "debug";
                    }
                }
                // Redirect but retain query.
                if ($target_dynamic) {
                    $querystr[] = google_seo_encode($target_dynamic);
                }
                foreach ($query as $k => $v) {
                    $querystr[] = urlencode($k) . "=" . urlencode($v);
                }
                $location_target = google_seo_encode($location_target);
                if (sizeof($querystr)) {
                    $location_target .= "?" . implode("&", $querystr);
                }
                $google_seo_redirect = $location_target;
                if ($settings['google_seo_redirect_permission'] && THIS_SCRIPT != "member.php") {
                    // Leave permission checks to the current page.
                    // Add hooks to issue redirect later on.
                    $plugins->add_hook("forumdisplay_end", "google_seo_redirect_header", 2);
                    $plugins->add_hook("postbit", "google_seo_redirect_header", 2);
                    $plugins->add_hook("postbit_announcement", "google_seo_redirect_header", 2);
                    $plugins->add_hook("calendar_editevent_end", "google_seo_redirect_header", 2);
                    $plugins->add_hook("calendar_event_end", "google_seo_redirect_header", 2);
                    $plugins->add_hook("calendar_end", "google_seo_redirect_header", 2);
                    $plugins->add_hook("pre_output_page", "google_seo_redirect_header", 2);
                    // Except on error.
                    $plugins->add_hook("error", "google_seo_redirect_remove_hooks", 2);
                    $plugins->add_hook("no_permission", "google_seo_redirect_remove_hooks", 2);
                } else {
                    google_seo_redirect_header();
                }
            }
        }
    }
}