<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Content_Event extends vB_Api_Content_Text { protected $contenttype = 'vBForum_Event'; protected $textRequired = false; protected function __construct() { parent::__construct(); $this->library = vB_Library::instance('Content_Event'); } public function add($data, $options = []) { $parent = vB_Library::instance('node')->getNodeBare($data['parentid']); $channelTypeId = vB_Types::instance()->getContentTypeID('vBForum_Channel'); if ($parent['contenttypeid'] != $channelTypeId) { throw new vB_Exception_Api('event_node_not_starter'); } $data = $this->library->checkEventData($data); return parent::add($data, $options); } public function update($nodeid, $data) { $existing = vB_Library::instance('node')->getNode($nodeid, false, true); if ($existing['starter'] != $nodeid) { throw new vB_Exception_Api('event_node_not_starter'); } $data = $this->library->checkEventData($data, $existing); return parent::update($nodeid, $data); } public function cleanInput($data, $nodeid = false) { $data = parent::cleanInput($data, $nodeid); $unclean = $data; $clean = vB::getCleaner()->cleanArray($unclean, [ 'location' => vB_Cleaner::TYPE_STR, 'eventstartdate' => vB_Cleaner::TYPE_UNIXTIME, 'eventenddate' => vB_Cleaner::TYPE_UNIXTIME, 'eventhighlightid' => vB_Cleaner::TYPE_UINT, ]); if ($clean['eventhighlightid'] > 0) { $eventhighlights = vB_Api::instance('eventhighlight')->getEventHighlightsUser(); $found = false; foreach ($eventhighlights AS $eventhighlight) { if ($eventhighlight['eventhighlightid'] == $clean['eventhighlightid']) { $found = true; break; } } if (!$found) { $clean['eventhighlightid'] = 0; } } if ($nodeid) { if (isset($data['location'])) { $data['location'] = trim($clean['location']); } if (isset($data['eventstartdate'])) { $data['eventstartdate'] = $clean['eventstartdate']; } if (isset($data['eventenddate'])) { $data['eventenddate'] = $clean['eventenddate']; } if (isset($data['eventhighlightid'])) { $data['eventhighlightid'] = $clean['eventhighlightid']; } } else { $data['location'] = trim($clean['location']); $data['eventstartdate'] = $clean['eventstartdate']; $data['eventenddate'] = $clean['eventenddate']; $data['eventhighlightid'] = $clean['eventhighlightid']; } return $data; } public function getDefaultEventTimestamps() { $timenow = vB::getRequest()->getTimeNow(); $secondsPastTheHour = $timenow % 3600; $nextEvenHour = $timenow - $secondsPastTheHour + 3600; return [ 'start_timestamp' => $nextEvenHour, 'end_timestamp' => $nextEvenHour + 3600, ]; } public function splitUnixtimestamp($timestamp = '', $ampm = false, $userid = false, $skipOffset = false, $ignoreDST = true) { if (empty($timestamp)) { $timestamp = vB::getRequest()->getTimeNow(); } $timestamp = intval($timestamp); if (!$skipOffset) { if (empty($userid)) { $userid = false; } $offset = vB_Api::instanceInternal('user')->fetchTimeOffset($userid, $ignoreDST); $timestamp += $offset; } $splitarray = [ 'year' => gmdate("Y", $timestamp), 'month' => gmdate("m", $timestamp), 'day' => gmdate("d", $timestamp), 'hour' => gmdate("H", $timestamp), 'minute' => gmdate("i", $timestamp), 'second' => gmdate("s", $timestamp), 'datepickerstr' => gmdate("m/d/Y H:i", $timestamp), ]; if ($ampm) { $splitarray['hour'] = gmdate("h", $timestamp); $splitarray['ampm'] = gmdate("a", $timestamp); } return ['datetime' => $splitarray]; } public function getEventDateTimeStr($timestamp, $allday, $ignoreDST) { $userAPI = vB_Api::instance("user"); $userinfo = $userAPI->fetchCurrentUserinfo(); $options = vB::getDatastore()->getValue('options'); $useLocale = false; if ($userinfo['lang_dateoverride'] != '') { $dateformat = $userinfo['lang_dateoverride']; $useLocale = true; } else { $dateformat = $options['dateformat']; } $timeformat = ""; if (!$allday) { if ($userinfo['lang_timeoverride'] != '') { $timeformat = $userinfo['lang_timeoverride']; $useLocale = true; } else { $timeformat = $options['timeformat']; } $timeformat = " " . $timeformat; } $format = $dateformat . $timeformat; $userid = isset($userinfo['userid']) ? $userinfo['userid'] : false; $locale = ''; if ($useLocale AND !empty($userinfo['lang_locale'])) { $locale = $userinfo['lang_locale']; } return $userAPI->unixtimestampToUserDateString($timestamp, $userid, $format, $ignoreDST, $locale); } public function getEndOfDayUnixtime($timestamp, $userid = false, $hmsString = "11:59:59 PM", $ignoreDST = true) { return [ "unixtime" => $this->library->getEndOfDayUnixtime($timestamp, $userid, $hmsString, $ignoreDST), ]; } } 