/** * @see \wcf\system\dashboard\box\IDashboardBox::init() */ public function init(DashboardBox $box, IPage $page) { parent::init($box, $page); // get current date $currentDay = DateUtil::format(null, 'm-d'); $date = explode('-', DateUtil::format(null, 'Y-n-j')); // get user ids $userIDs = UserBirthdayCache::getInstance()->getBirthdays($date[1], $date[2]); if (!empty($userIDs)) { $userOptions = UserOptionCacheBuilder::getInstance()->getData(array(), 'options'); if (isset($userOptions['birthday'])) { $birthdayUserOption = $userOptions['birthday']; $userProfileList = new UserProfileList(); $userProfileList->setObjectIDs($userIDs); $userProfileList->readObjects(); $i = 0; foreach ($userProfileList as $userProfile) { if ($i == 10) { break; } $birthdayUserOption->setUser($userProfile->getDecoratedObject()); if (!$userProfile->isProtected() && $birthdayUserOption->isVisible() && substr($userProfile->birthday, 5) == $currentDay) { $this->userProfiles[] = $userProfile; $i++; } } } } $this->fetched(); }
/** * @see \wcf\system\dashboard\box\IDashboardBox::init() */ public function init(DashboardBox $box, IPage $page) { parent::init($box, $page); // get current date $currentDay = DateUtil::format(null, 'm-d'); $date = explode('-', DateUtil::format(null, 'Y-n-j')); // get user ids $userIDs = UserBirthdayCache::getInstance()->getBirthdays($date[1], $date[2]); $userIDs = array_intersect($userIDs, WCF::getUserProfileHandler()->getFollowingUsers()); if (!empty($userIDs)) { $userProfileList = new UserProfileList(); $userProfileList->setObjectIDs($userIDs); $userProfileList->readObjects(); $i = 0; foreach ($userProfileList as $userProfile) { if ($i == 10) { break; } if (!$userProfile->isProtected() && substr($userProfile->birthday, 5) == $currentDay) { $this->userProfiles[] = $userProfile; $i++; } } } $this->fetched(); }
/** * @see \wcf\system\option\user\IUserOptionOutput::getOutput() */ public function getOutput(User $user, UserOption $option, $value) { if (empty($value) || $value == '0000-00-00') { return ''; } $date = self::splitDate($value); return DateUtil::format(DateUtil::getDateTimeByTimestamp(gmmktime(12, 1, 1, $date['month'], $date['day'], $date['year'])), $this->dateFormat); }
/** * @see wcf\system\template\IModifierTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { $timestamp = intval($tagArgs[0]); $dateTimeObject = DateUtil::getDateTimeByTimestamp($timestamp); $date = DateUtil::format($dateTimeObject, DateUtil::DATE_FORMAT); $time = DateUtil::format($dateTimeObject, DateUtil::TIME_FORMAT); $dateTime = str_replace('%time%', $time, str_replace('%date%', $date, WCF::getLanguage()->get('wcf.date.dateTimeFormat'))); return '<time datetime="'.DateUtil::format($dateTimeObject, 'c').'" class="datetime" data-timestamp="'.$timestamp.'" data-date="'.$date.'" data-time="'.$time.'" data-offset="'.$dateTimeObject->getOffset().'">'.$dateTime.'</time>'; }
/** * @see \wcf\system\template\IModifierTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { return DateUtil::format(DateUtil::getDateTimeByTimestamp($tagArgs[0]), !empty($tagArgs[1]) ? $tagArgs[1] : DateUtil::DATE_FORMAT); }
/** * Executes cronjobs. */ public function execute() { $return = array(); foreach ($this->objects as $key => $cronjob) { // skip jobs that are already being processed if ($cronjob->state == Cronjob::PENDING || $cronjob->state == Cronjob::EXECUTING) { unset($this->objects[$key]); continue; } // mark them as pending $cronjob->update(array('state' => Cronjob::PENDING)); } foreach ($this->objects as $cronjob) { // it now time for executing $cronjob->update(array('state' => Cronjob::EXECUTING)); $className = $cronjob->className; $executable = new $className(); // execute cronjob $error = ''; try { $executable->execute(new Cronjob($cronjob->cronjobID)); } catch (\Exception $e) { $error = $e->getMessage(); } CronjobLogEditor::create(array('cronjobID' => $cronjob->cronjobID, 'execTime' => TIME_NOW, 'success' => (int) ($error == ''), 'error' => $error)); // calculate next exec-time $nextExec = $cronjob->getNextExec(); $cronjob->update(array('nextExec' => $nextExec, 'afterNextExec' => $cronjob->getNextExec($nextExec + 120))); // build the return value $dateTime = DateUtil::getDateTimeByTimestamp($nextExec); $return[$cronjob->cronjobID] = array('time' => $nextExec, 'formatted' => str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat')))); // we are finished $cronjob->update(array('state' => Cronjob::READY)); } return $return; }
/** * @see \wcf\system\template\IModifierTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { $dateTime = DateUtil::getDateTimeByTimestamp($tagArgs[0]); return str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat'))); }
/** * Gets the list of results. */ protected function readUsers() { // get user ids $userIDs = array(); $sql = "SELECT\t\tuser_table.userID\n\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t" . (isset($this->options[$this->sortField]) ? "LEFT JOIN wcf" . WCF_N . "_user_option_value user_option_value ON (user_option_value.userID = user_table.userID)" : '') . "\n\t\t\t" . $this->conditions . "\n\t\t\tORDER BY\t" . ($this->sortField != 'email' && isset($this->options[$this->sortField]) ? 'user_option_value.userOption' . $this->options[$this->sortField]['optionID'] : $this->sortField) . " " . $this->sortOrder; $statement = WCF::getDB()->prepareStatement($sql, $this->itemsPerPage, ($this->pageNo - 1) * $this->itemsPerPage); $statement->execute($this->conditions->getParameters()); while ($row = $statement->fetchArray()) { $userIDs[] = $row['userID']; } // get user data if (count($userIDs)) { $userToGroups = array(); // get group ids $conditions = new PreparedStatementConditionBuilder(); $conditions->add("user_table.userID IN (?)", array($userIDs)); $sql = "SELECT\tuserID, groupID\n\t\t\t\tFROM\twcf" . WCF_N . "_user_to_group user_table\n\t\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($row = $statement->fetchArray()) { $userToGroups[$row['userID']][] = $row['groupID']; } $sql = "SELECT\t\toption_value.*, user_table.*\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t" . $conditions . "\n\t\t\t\tORDER BY\t" . ($this->sortField != 'email' && isset($this->options[$this->sortField]) ? 'option_value.userOption' . $this->options[$this->sortField]['optionID'] : 'user_table.' . $this->sortField) . " " . $this->sortOrder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($row = $statement->fetchArray()) { $row['groupIDs'] = implode(',', $userToGroups[$row['userID']]); $accessible = UserGroup::isAccessibleGroup($userToGroups[$row['userID']]); $row['accessible'] = $accessible; $row['deletable'] = $accessible && WCF::getSession()->getPermission('admin.user.canDeleteUser') && $row['userID'] != WCF::getUser()->userID ? 1 : 0; $row['editable'] = $accessible && WCF::getSession()->getPermission('admin.user.canEditUser') ? 1 : 0; $row['isMarked'] = intval(in_array($row['userID'], $this->markedUsers)); $this->users[] = new User(null, $row); } // get special columns foreach ($this->users as $key => $user) { foreach ($this->columns as $column) { switch ($column) { case 'email': $this->columnValues[$user->userID][$column] = '<a href="mailto:' . StringUtil::encodeHTML($user->email) . '">' . StringUtil::encodeHTML($user->email) . '</a>'; break; case 'registrationDate': $this->columnValues[$user->userID][$column] = DateUtil::format(DateUtil::getDateTimeByTimestamp($user->{$column}), DateUtil::DATE_FORMAT); break; default: if (isset($this->options[$column])) { if ($this->options[$column]->outputClass) { $this->options[$column]->setOptionValue($user); $outputObj = $this->options[$column]->getOutputObject(); $this->columnValues[$user->userID][$column] = $outputObj->getOutput($user, $this->options[$column]->getDecoratedObject(), $user->{$column}); } else { $this->columnValues[$user->userID][$column] = StringUtil::encodeHTML($user->{$column}); } } break; } } } } }
/** * Returns the readable period matching this notification. * * @return string */ public function getPeriod() { if (empty(self::$periods)) { $date = DateUtil::getDateTimeByTimestamp(TIME_NOW); $date->setTimezone(WCF::getUser()->getTimeZone()); $date->setTime(0, 0, 0); self::$periods[$date->getTimestamp()] = WCF::getLanguage()->get('wcf.date.period.today'); // 1 day back $date->modify('-1 day'); self::$periods[$date->getTimestamp()] = WCF::getLanguage()->get('wcf.date.period.yesterday'); // 2-6 days back for ($i = 0; $i < 6; $i++) { $date->modify('-1 day'); self::$periods[$date->getTimestamp()] = DateUtil::format($date, 'l'); } } foreach (self::$periods as $time => $period) { if ($this->notification->time >= $time) { return $period; } } return WCF::getLanguage()->get('wcf.date.period.older'); }
/** * Executes cronjobs. */ public function execute() { $return = array(); foreach ($this->objects as $key => $cronjob) { // mark them as pending $cronjob->update(array('state' => Cronjob::PENDING)); } foreach ($this->objects as $cronjob) { // it now time for executing $cronjob->update(array('state' => Cronjob::EXECUTING)); $className = $cronjob->className; $executable = new $className(); // execute cronjob $exception = null; try { $executable->execute(new Cronjob($cronjob->cronjobID)); } catch (\Exception $exception) { } CronjobLogEditor::create(array('cronjobID' => $cronjob->cronjobID, 'execTime' => TIME_NOW, 'success' => $exception ? 0 : 1, 'error' => $exception ? $exception->getMessage() : '')); // calculate next exec-time $nextExec = $cronjob->getNextExec(); $data = array('lastExec' => TIME_NOW, 'nextExec' => $nextExec, 'afterNextExec' => $cronjob->getNextExec($nextExec + 120)); // cronjob failed if ($exception) { if ($cronjob->failCount < Cronjob::MAX_FAIL_COUNT) { $data['failCount'] = $cronjob->failCount + 1; } // cronjob failed too often: disable it if ($cronjob->failCount + 1 == Cronjob::MAX_FAIL_COUNT) { $data['isDisabled'] = 1; } } else { $data['failCount'] = 0; // if cronjob has been disabled because of too many // failed executions, enable it again if ($cronjob->failCount == Cronjob::MAX_FAIL_COUNT && $cronjob->isDisabled) { $data['isDisabled'] = 0; } } $cronjob->update($data); // build the return value if ($exception === null && !$cronjob->isDisabled) { $dateTime = DateUtil::getDateTimeByTimestamp($nextExec); $return[$cronjob->cronjobID] = array('time' => $nextExec, 'formatted' => str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat')))); } // we are finished $cronjob->update(array('state' => Cronjob::READY)); // throw exception again to show error message if ($exception) { throw $exception; } } return $return; }
/** * Formats dates. * * @param integer $timestamp * @return string */ public static function formatDate($timestamp) { return DateUtil::format(DateUtil::getDateTimeByTimestamp($timestamp), DateUtil::DATE_FORMAT); }
public function getWeeklyVisitorArray() { $currentMonth = DateUtil::format(DateUtil::getDateTimeByTimestamp(TIME_NOW), 'n'); $currentYear = DateUtil::format(DateUtil::getDateTimeByTimestamp(TIME_NOW), 'Y'); $currentDay = DateUtil::format(DateUtil::getDateTimeByTimestamp(TIME_NOW), 'j'); $visitors = array(); $year = $currentYear; $month = $currentMonth; $day = $currentDay; for ($i = 1; $i <= 7; $i++) { $months = $this->getMonths(); $visitors[$i] = array('string' => $day . '. ' . $months[$month - 1] . ' ' . $year, 'visitors' => $this->getDailyVisitors($day, $month, $year)); $day--; if ($day == 0) { $month--; if (in_array($month, array(1, 3, 5, 7, 8, 10, 12))) { $day = 31; } if ($month == 2) { $day = 28; } else { $day = 30; } } if ($month == 0) { $month = 12; $year = $currentYear - 1; } } return array_reverse($visitors); }