private function getPublished($year, $month) { //Getting the start date is easy. Getting the end date is a bit complex. Leap years and all that. //Easiest way is to get the start of the next month and subract a second. //Ensure permissions are loaded $hash = self::getMyHash($year, $month); if (!($articles = vB_Cache::instance()->read($hash, true, false))) { $offset = vBCms_ContentManager::getTimeOffset(vB::$vbulletin->userinfo); $start = gmmktime (0, 0, 0, $month, 1, $year); $weekday = gmdate('w', $start); $start -= $offset; $end = gmmktime (0, 0, 0, ($month == 12 ? 1 : $month + 1 ), 1, ($month == 12 ? $year + 1 : $year )) - $offset - 1; $articles = array(); $rst = vB::$vbulletin->db->query_read($sql = "SELECT node.nodeid, node.publishdate, node.setpublish FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = node.nodeid WHERE node.setpublish > 0 AND node.publishdate BETWEEN $start AND $end AND node.contenttypeid <> " . vB_Types::instance()->getContentTypeID("vBCms_Section") . " AND " . vBCMS_Permissions::getPermissionString() . " AND hidden = 0 ORDER BY node.publishdate LIMIT 5000" ); $nextday = $start + 86400; $dom = 1; $articles[1] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); //Now we want to end with an array of day => array('data ' => array, 'time' => unixtime) //So we need to build the array as we go. while($record = vB::$vbulletin->db->fetch_array($rst)) { //see if we need to advance to a new date if (intval($record['publishdate']) > $nextday) { while (intval($record['publishdate']) > $nextday) { $nextday += 86400; $start += 86400; $dom ++; $weekday = ($weekday == 6 ? 0 : ($weekday + 1)); $articles[$dom] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); } } if ($record['setpublish']) { $articles[$dom]['data'][] = $record; } } //we may have some days at the end without articles. while($end > $start + 86400 ) { $dom++; $weekday = ($weekday == 6 ? 0 : ($weekday + 1)); $articles[$dom] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); $start += 86400; } vB_Cache::instance()->write($hash , $articles, 1440, array('cms_calendar_published', 'sections_updated')); } //Now we want to turn this into an array of week=>(array(1-7); $week = 1; $calendar = array(1 => array()); //Pad the start with empty records as needed if ($articles[1]['wday'] != 0) { for ($i = 0; $i < $articles[1]['wday']; $i++) { $calendar[1][$i] = array('count' => 0, 'url' => '', 'day' => ''); } } $monthday = 1; $route = new vBCms_Route_List; while($monthday <= count($articles)) { //If we've filled a week, we need to advance $count = 0; foreach ($articles[$monthday]['data'] as $record) { $count = 1; $url = $route->getCurrentUrl(array('type' =>'day', 'value' => $articles[$monthday]['time'])) ; break; } $calendar[$week][$articles[$monthday]['wday']] = array('count' => $count, 'url' => $url, 'day' =>($monthday ? $monthday : '') ); if (($articles[$monthday]['wday'] == 6) AND ($monthday < count($articles))) { $week++; $calendar[$week] = array(); } $monthday++; } //We need to fill out a full week. Note that monthday is now one past the last day of the month if ($articles[$monthday - 1]['wday'] < 6) { for ($i = $articles[$monthday - 1]['wday'] + 1; $i <= 6 ; $i++) $calendar[$week][$i] = array('count' => 0, 'url' => '', 'day' => ''); } unset($route); return $calendar; }