本文整理汇总了PHP中Lib::helper方法的典型用法代码示例。如果您正苦于以下问题:PHP Lib::helper方法的具体用法?PHP Lib::helper怎么用?PHP Lib::helper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lib
的用法示例。
在下文中一共展示了Lib::helper方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
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);
}
示例2: populateSlackUsers
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;
}
示例3: send
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;
}