set_config($config); } /** * Sets the config variables. * @param array $config */ public function set_config($config) { $this->calendarWidth = $config['calendarWidth'] ? $config['calendarWidth'] : "500px"; $this->calendarHeight = $config['calendarHeight'] ? $config['calendarHeight'] : "840px"; $this->useModal = $config['useModal'] ? $config['useModal'] : "true"; $this->showExtras = $config['showExtras'] ? $config['showExtras'] : "false"; $this->enableSnow = $config['enableSnow'] ? $config['enableSnow'] : "false"; } /** * Adds a new entry to the calendar. * @param array $entry */ public function set_entry($entry) { if ($this->validate_entry($entry)) { $this->entries[] = $entry; } } /** * Checks if an entry can be added to the calendar. * @param array $entry */ public function validate_entry($entry) { if ( !array_key_exists('unlockDate', $entry) || !array_key_exists('positionTop', $entry) || !array_key_exists('positionLeft', $entry) || (!array_key_exists('doorImageLeft', $entry) && !array_key_exists('doorImageRight', $entry)) || !array_key_exists('url', $entry) ) { return false; } return true; } /** * Loads a calendar from a json string. * @param string $json */ public function load_from_json($json) { $data = json_decode($json, true); $this->set_config($data['config']); foreach ($data['entries'] as $entry) { $this->set_entry($entry); } } /** * Renders the HTML for the calendar. * @param boolean $return if set to TRUE, returns the output rather than print it. */ public function render($return = false) { $now = time(); $output = ""; $output .= '
'; foreach ($this->entries as $entry) { if ($entry['doorImageLeft'] && $entry['doorImageRight']) { $totalwidth = $entry['doorWidth'] * 2; } else { $totalwidth = $entry['doorWidth']; } if (time() >= strtotime($entry['unlockDate'])) { //print(__DIR__.'/_gifts/'.$entry['url'].'.php'); require_once (__DIR__.'/_gifts/'.$entry['url'].'.php'); $output .= ''; if ($entry['backgroundImage']) { $output .= ''; } if ($entry['doorImageLeft']) { $output .= '
'; } if ($entry['doorImageRight']) { $output .= '
'; } $output .= '
'; } else { $output .= '
'; if ($entry['doorImageLeft']) { $output .= '
'; } if ($entry['doorImageRight']) { $output .= '
'; } $output .= '
'; } } $output .= '
'; if ($return) { return $output; } else { print $output; } } }