function loadCalendar($position = 'module', $itemId = '0', $size = 'small', $type = 'blog', $timestamp = '') { $my = JFactory::getUser(); $ajax = new Ejax(); $config = EasyBlogHelper::getConfig(); $tpl = new CodeThemes(); $model = new EasyBlogModelArchive(); $allowed = array('module', 'component'); if (!in_array($position, $allowed)) { return; } if (!empty($itemId)) { JRequest::setVar('Itemid', $itemId); } //get date. $date = EasyBlogCalendarHelper::processDate($timestamp); //get the required data to build the calendar. $data = EasyBlogCalendarHelper::prepareData($date); //get the postcount //$postCount = $model->getArchivePostCountByMonth($date['month'], $date['year']); $postData = $model->getArchivePostByMonth($date['month'], $date['year']); switch ($position) { case 'module': $namespace = 'mod_easyblogcalendar'; $preFix = 'mod_easyblog'; $ajax->script('mod_easyblogcalendar.calendar.setItemId("' . $itemId . '");'); break; case 'component': $namespace = 'eblog'; $preFix = 'com_easyblog'; break; } $previous = $namespace . '.calendar.reload( \'archive\' , \'loadCalendar\', \'' . $position . '\', \'' . $itemId . '\', \'' . $size . '\', \'' . $type . '\', \'' . $data->previous . '\');'; $next = $namespace . '.calendar.reload( \'archive\' , \'loadCalendar\', \'' . $position . '\', \'' . $itemId . '\', \'' . $size . '\', \'' . $type . '\', \'' . $data->next . '\');'; $tpl->set('calendar', $data); $tpl->set('date', $date); $tpl->set('postData', $postData); $tpl->set('previous', $previous); $tpl->set('next', $next); $tpl->set('namespace', $namespace); $tpl->set('preFix', $preFix); $tpl->set('itemId', $itemId); $layout = $tpl->fetch('calendar.' . $size . '.php'); $ajax->assign('easyblogcalendar-' . $position . '-wrapper', $layout); $ajax->send(); return; }
public static function prepareData($date = array()) { if (empty($date)) { $date = EasyBlogCalendarHelper::processDate(''); } $calendar = new stdClass(); //Here we generate the first day of the month $calendar->first_day = mktime(0, 0, 0, $date['month'], 1, $date['year']); //This gets us the month name $calendar->title = date('F', $calendar->first_day); //Here we find out what day of the week the first day of the month falls on $calendar->day_of_week = date('D', $calendar->first_day); //previous month $calendar->previous = strtotime('-1 month', $calendar->first_day); //next month $calendar->next = strtotime('+1 month', $calendar->first_day); //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero switch ($calendar->day_of_week) { case "Sun": $calendar->blank = 0; break; case "Mon": $calendar->blank = 1; break; case "Tue": $calendar->blank = 2; break; case "Wed": $calendar->blank = 3; break; case "Thu": $calendar->blank = 4; break; case "Fri": $calendar->blank = 5; break; case "Sat": $calendar->blank = 6; break; } //We then determine how many days are in the current month $calendar->days_in_month = cal_days_in_month(0, $date['month'], $date['year']); return $calendar; }