/** * Creates a matrix with 7 columns, one per day of week, and as many rows (weeks) as necessary. * Every cell contains a dictionary with the wotd, the definition and other info. */ function createCalendar($year, $month) { $days = listDaysOfMonth($year, $month); $today = date('Y-m-d'); $calendar = array(); // Pad beginning $startDow = date('N', strtotime("{$year}-{$month}-01")); for ($i = 1; $i < $startDow; $i++) { $calendar[] = array(); } // Create a record per day foreach ($days as $i => $date) { $wotd = WordOfTheDay::get_by_displayDate($date); $wotdr = $wotd ? WordOfTheDayRel::get_by_wotdId($wotd->id) : null; $def = $wotdr ? Definition::get_by_id($wotdr->refId) : null; $visible = $def && ($date <= $today || util_isModerator(PRIV_WOTD)); $calendar[] = array('wotd' => $wotd, 'def' => $def, 'visible' => $visible, 'dayOfMonth' => $i + 1); } // Pad end while (count($calendar) % 7 != 0) { $calendar[] = array(); } // Wrap 7 records per line $weeks = array(); while (count($calendar)) { $weeks[] = array_splice($calendar, 0, 7); } return $weeks; }
exit; } $today = date('Y-m-d', time()); $timestamp = $date ? strtotime($date) : time(); $mysqlDate = date("Y-m-d", $timestamp); if ($mysqlDate < WOTD_BIG_BANG || $mysqlDate > $today) { util_redirect(util_getWwwRoot() . 'cuvantul-zilei'); } $wotd = WordOfTheDay::get_by_displayDate($mysqlDate); if (!$wotd) { // We shouldn't have missing words since the Big Bang. if ($mysqlDate != $today) { util_redirect(util_getWwwRoot() . 'cuvantul-zilei'); } WordOfTheDay::updateTodaysWord(); $wotd = WordOfTheDay::get_by_displayDate($mysqlDate); } $archive = WordOfTheDay::getArchiveWotD(date('Y', $timestamp), date('m', $timestamp)); $defId = WordOfTheDayRel::getRefId($wotd->id); $def = Definition::get_by_id($defId); $searchResults = SearchResult::mapDefinitionArray(array($def)); setlocale(LC_ALL, 'ro_RO'); $roDate = strftime("%e %B %Y", $timestamp); $pageTitle = sprintf("Cuvântul zilei: %s (%s)", $def->lexicon, $roDate); if ($mysqlDate > WOTD_BIG_BANG) { smarty_assign('prevday', date('Y/m/d', $timestamp - 86400)); } if ($mysqlDate < $today) { smarty_assign('nextday', date('Y/m/d', $timestamp + 86400)); } smarty_assign('imageUrl', $wotd->getImageUrl());