public function main() { $this->set('backgroundPattern', '1001000110010111011001101100110111110000010101111101111111001011011001100100'); $this->set('hideHeader', true); $this->set('pagetitle', 'Hello World'); $twitterHelper = Lib::helper('twitter'); $tweet = $twitterHelper->getLatestTweet('jasonkeorey'); $this->set('tweet', $tweet); $now = new DateTime(); $currentDay = (int) $now->format('j'); $currentMonth = (int) $now->format('n'); $startYear = $endYear = $currentYear = (int) $now->format('Y'); if ($currentMonth < 7 || $currentMonth === 7 && $currentDay < 10) { $startYear = $currentYear - 1; } else { $endYear = $currentYear + 1; } $startDate = new DateTime($startYear . '-07-10'); $endDate = new DateTime($endYear . '-07-10'); $totalDays = ($endDate->format('U') - $startDate->format('U')) / (60 * 60 * 24); $elapsedDays = floor(($now->format('U') - $startDate->format('U')) / (60 * 60 * 24)); $expPercentage = floor($elapsedDays / $totalDays * 100); $level = $currentYear - 1988; $this->set('expPercentage', $expPercentage); $this->set('level', $level); }
public function populateSlackUsers() { $identifier = Lib::cookie(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); if (!$isLoggedIn || $user->role != USER_ROLE_ADMIN) { echo 'You are not authorized'; exit; } $helper = Lib::helper('slack'); $users = $helper->getUsers(); if ($users === false) { echo $helper->error; exit; } foreach ($users as $user) { $table = Lib::table('slackuser'); $table->load(array('slack_id' => $user->id)); $table->team_id = $user->team_id; $table->name = $user->name; $table->email = $user->email; $table->store(); } echo 'Imported ' . count($users) . ' users.'; exit; }
public static function send($data) { if (!$data['to'] || !$data['text']) { return false; } $slackTable = Lib::table('slackuser'); if ($slackTable->load(['email' => $data['to']])) { // Send slack $slackMessage = Lib::helper('slack')->newMessage(); $slackMessage->channel = '@' . $slackTable->name; $slackMessage->text = $data['text']; $messageKeys = ['username', 'icon_emoji']; foreach ($messageKeys as $mKey) { if (!empty($data[$mKey])) { $slackMessage->{$mKey} = $data[$mKey]; } } if (!empty($data['attachments'])) { $attachmentKeys = ['fallback', 'color', 'title', 'title_link', 'text']; foreach ($data['attachments'] as $attach) { $attachment = $slackMessage->newAttachment(); foreach ($attachmentKeys as $aKey) { if (!empty($attach[$aKey])) { $attachment->{$aKey} = $attach[$aKey]; } } if (!empty($attach['fields'])) { foreach ($attach['fields'] as $fieldKey => $fieldValue) { $attachment->newField($fieldKey, $fieldValue); } } } } $slackMessage->send(); } else { // Send email $mail = Lib::helper('mail')->newMessage(); $mail->recipientEmail = $data['to']; $mail->subject = 'Report Notification'; $mail->body = '<p>' . $data['text'] . '</p>'; $attachments = ''; foreach ($data['attachments'] as $attach) { if (empty($attach['title']) || empty($attach['title_link'])) { continue; } $attachments .= '<p><a href="' . $attach['title_link'] . '">' . $attach['title'] . '</a></p>'; } if (!empty($attachments)) { $mail->body .= '<p><strong><u>Attachments</u></strong></p>'; $mail->body .= $attachments; } $mail->body .= '<p style="font-size: 10px;">Do not reply to this email.</p>'; $mail->send(); } return true; }