private function midWare($midwares) { foreach ($midwares as $name) { if ($midware = Dependency::MidWare($name)) { return $midware->run(); } else { Log::Error("Calling undefined midware: " . $name); return; } } }
public function messageEmail($msgId) { $messageModel = Model::make("Message"); if (!($msg = $messageModel->getMessageById($msgId))) { return; } $this->mail->addAddress("*****@*****.**", "root"); $this->mail->addReplyTo($msg->email, $msg->name); $this->mail->isHTML(TRUE); $this->mail->Subject = "您收到一条私信!"; $this->mail->Body = '<div style="width:1000px;">' . '<div style="width:100px; float:left;">' . '<img src="" style="width:60px;height:60px;borderr-radius:100%;"/>' . '</div><div style="width:900px;float:left;">' . $msg->name . " " . date("Y-m-d H:i:s") . "<br/>" . $msg->msgbody . '</div></div>'; if (!$this->mail->send()) { Log::error($this->mail->ErrorInfo); } }
public static function initCache() { if (is_file(APP_PATH . '/config/database.php')) { self::$database = (include APP_PATH . '/config/database.php'); $capsule = new Capsule(); // 创建链接 $capsule->addConnection(self::$database); // 设置全局静态可访问 $capsule->setAsGlobal(); // 启动Eloquent $capsule->bootEloquent(); } else { Log::Error(" Config file \"" . APP_PATH . "/config/database.php\" dose not exist!"); throw new \Exception("Database configure file dose not exist", 1); } }
public function makeHtml($html, $fileName) { $staticHtmlDir = Config::get("STATIC-HTML-DIR"); if (!is_dir($staticHtmlDir)) { $parentDir = dirname($staticHtmlDir); if (!is_writable($parentDir)) { Log::addWarning($parentDir . "目录不可写!"); return; } mkdir($staticHtmlDir); chmod($staticHtmlDir, "0777"); } else { if (!is_writable($staticHtmlDir)) { Log::addWarning("{$staticHtmlDir} 目录不可写"); } } file_put_contents($staticHtmlDir . '/' . $fileName . ".html", $html); }
public function resp() { if (!($cid = intval($this->post("cid")))) { return $this->renderJson(400, "Invalid input parameter:cid"); } if (!($content = strip_tags($this->post("resContent")))) { return $this->renderJson(400, "Invalid input response content!"); } $comment = $this->commentModel->getCommentById($cid); $post = $comment->post; $user = tSession::getLoginedUserInfo(); $resp = []; $resp['resp'] = $cid; $resp['postId'] = $post->id; $resp['name'] = $user->name; $resp['email'] = $user->email; $resp['gravatar'] = $user->avatar; $resp['content'] = $content; $resp['created_at'] = date("Y-m-d H:i:s"); $this->commentModel->insert($resp); /** * Send an email to original commentor; */ $site = $this->getSiteInfo(); $mail = Mailer::newInstance(); $mail->addAddress($comment->email, $comment->name); $mail->addReplyTo($user->email, $user->name); $mail->isHTML(TRUE); $mail->Subject = "来自{$user->name} 的回复!"; $mail->Body = "{$content}"; $mail->Body .= "<hr/>原文地址:<a href='http://{$site['site_domain']}/Blog/{$post->url}.html' target='_blank'>" . $post->title . "</a><br/>"; $mail->Body .= "您在{$comment->created_at}发表的评论:<br/>" . $comment->content; if (!$mail->send()) { Log::error($mail->ErrorInfo); } return $this->renderJson(200, "ok"); }
public function reply() { $mid = intVal($this->post("mid")); $resbody = nl2br(strip_tags($this->post("content"))); if (!($msg = $this->msgModel->getMessageById($mid))) { return $this->renderJson(401, "消息不存在!"); } $user = tSession::getLoginedUserInfo(); $Resp = []; $Resp['resp'] = $mid; $Resp['name'] = $user->name; $Resp['email'] = $user->email; $Resp['gravatar'] = $user->avatar; $Resp['msgbody'] = $resbody; $Resp['created_at'] = date("Y-m-d H:i:s"); $this->msgModel->insert($Resp); $mailer = Mailer::newInstance(); $mailer->addAddress($msg->email, $msg->name); $mailer->addReplyTo($user->email, $user->name); $mailer->isHTML(TRUE); $mailer->Subject = "来自 " . $this->siteInfo['site_name'] . " 的私信回复"; $mailer->Body = "<img src='" . $user->avatar . "' style='width:50px;height:50px;border-radius:100%;float:left; margin-right:1em;'/> " . $user->name . " " . date("Y-m-d H:i:s") . "<br/>" . $resbody . "<div style='width:100%;float:left;border-top:1px dashed #CCC;padding-top:1em;margin-top:1em;'>您在" . $msg->created_at . "发来的私信内容:<br/>" . $msg->msgbody . "</div>"; if (!$mailer->send()) { Log::error($mailer->ErrorInfo); } return $this->renderJson(200, "ok"); }