function getDayAgo($date) { $d = new Typecho_Date(Typecho_Date::gmtTime()); $now = $d->format('Y-m-d H:i:s'); $t = strtotime($now) - strtotime($date); if ($t < 60) { return $t . '秒前'; } if ($t < 3600) { return floor($t / 60) . '分钟前'; } if ($t < 86400) { return floor($t / 3670) . '小时前'; } if ($t < 604800) { return floor($t / 86400) . '天前'; } if ($t < 2419200) { return floor($t / 604800) . '周前'; } if ($t < 31536000) { return floor($t / 2592000) . '月前'; } return floor($t / 31536000) . '年前'; }
/** * 发布文章 * * @access public * @return void */ public function writePage() { $contents = $this->request->from('text', 'template', 'allowComment', 'allowPing', 'allowFeed', 'slug', 'order'); $contents['type'] = 'page'; $contents['title'] = $this->request->get('title', _t('未命名页面')); $contents['created'] = $this->getCreated(); $contents = $this->pluginHandle()->write($contents, $this); if ($this->request->is('do=publish')) { /** 重新发布已经存在的文章 */ $this->publish($contents); /** 发送ping */ $this->widget('Widget_Service')->sendPing($this->cid); /** 设置提示信息 */ $this->widget('Widget_Notice')->set(_t('页面 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title), NULL, 'success'); /** 设置高亮 */ $this->widget('Widget_Notice')->highlight($this->theId); /** 页面跳转 */ $this->response->redirect(Typecho_Common::url('manage-pages.php?', $this->options->adminUrl)); } else { /** 保存文章 */ $this->save($contents); if ($this->request->isAjax()) { $created = new Typecho_Date($this->options->gmtTime); $this->response->throwJson(array('success' => 1, 'message' => _t('文章保存于 %s', $created->format('H:i A')), 'cid' => $this->cid)); } else { /** 设置提示信息 */ $this->widget('Widget_Notice')->set(_t('草稿 "%s" 已经被保存', $this->title), NULL, 'success'); /** 返回原页面 */ $this->response->redirect(Typecho_Common::url('write-page.php?cid=' . $this->cid, $this->options->adminUrl)); } } }
/** * 获取邮件内容 * * @access public * @param $comment 调用参数 * @return void */ public static function parseComment($comment) { $options = Typecho_Widget::widget('Widget_Options'); $cfg = array('siteTitle' => $options->title, 'timezone' => $options->timezone, 'cid' => $comment->cid, 'coid' => $comment->coid, 'created' => $comment->created, 'author' => $comment->author, 'authorId' => $comment->authorId, 'ownerId' => $comment->ownerId, 'mail' => $comment->mail, 'ip' => $comment->ip, 'title' => $comment->title, 'text' => $comment->text, 'permalink' => $comment->permalink, 'status' => $comment->status, 'parent' => $comment->parent, 'manage' => $options->siteUrl . "admin/manage-comments.php"); self::$_isMailLog = in_array('to_log', Helper::options()->plugin('CommentToMail')->other) ? true : false; //是否接收邮件 if (isset($_POST['banmail']) && 'stop' == $_POST['banmail']) { $cfg['banMail'] = 1; } else { $cfg['banMail'] = 0; } $fileName = Typecho_Common::randString(7); $cfg = (object) $cfg; file_put_contents(dirname(__FILE__) . '/cache/' . $fileName, serialize($cfg)); $url = $options->rewrite ? $options->siteUrl : $options->siteUrl . 'index.php'; $url = rtrim($url, '/') . '/action/' . self::$action . '?send=' . $fileName; $date = new Typecho_Date(Typecho_Date::gmtTime()); $time = $date->format('Y-m-d H:i:s'); self::saveLog("{$time} 开始发送请求:{$url}\n"); self::asyncRequest($url); }
/** * 发布文章 * * @access public * @return void */ public function writePost() { $contents = $this->request->from('password', 'allowComment', 'allowPing', 'allowFeed', 'slug', 'tags', 'text', 'visibility'); $contents['category'] = $this->request->getArray('category'); $contents['title'] = $this->request->get('title', _t('未命名文档')); $contents['created'] = $this->getCreated(); if ($this->request->markdown && $this->options->markdown) { $contents['text'] = '<!--markdown-->' . $contents['text']; } $contents = $this->pluginHandle()->write($contents, $this); if ($this->request->is('do=publish')) { /** 重新发布已经存在的文章 */ $contents['type'] = 'post'; $this->publish($contents); // 完成发布插件接口 $this->pluginHandle()->finishPublish($contents, $this); /** 发送ping */ $trackback = array_unique(preg_split("/(\r|\n|\r\n)/", trim($this->request->trackback))); $this->widget('Widget_Service')->sendPing($this->cid, $trackback); /** 设置提示信息 */ $this->widget('Widget_Notice')->set('post' == $this->type ? _t('文章 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title) : _t('文章 "%s" 等待审核', $this->title), 'success'); /** 设置高亮 */ $this->widget('Widget_Notice')->highlight($this->theId); /** 获取页面偏移 */ $pageQuery = $this->getPageOffsetQuery($this->created); /** 页面跳转 */ $this->response->redirect(Typecho_Common::url('manage-posts.php?' . $pageQuery, $this->options->adminUrl)); } else { /** 保存文章 */ $contents['type'] = 'post_draft'; $this->save($contents); // 完成保存插件接口 $this->pluginHandle()->finishSave($contents, $this); if ($this->request->isAjax()) { $created = new Typecho_Date($this->options->gmtTime); $this->response->throwJson(array('success' => 1, 'time' => $created->format('H:i:s A'), 'cid' => $this->cid)); } else { /** 设置提示信息 */ $this->widget('Widget_Notice')->set(_t('草稿 "%s" 已经被保存', $this->title), 'success'); /** 返回原页面 */ $this->response->redirect(Typecho_Common::url('write-post.php?cid=' . $this->cid, $this->options->adminUrl)); } } }
/** * 访问邮件信息 * @return $this */ public function guestMail() { $this->_email->toName = $this->_email->originalAuthor ? $this->_email->originalAuthor : $this->_email->siteTitle; $date = new Typecho_Date($this->_email->created); $time = $date->format('Y-m-d H:i:s'); $search = array('{siteTitle}', '{title}', '{author_p}', '{author}', '{permalink}', '{text}', '{contactme}', '{text_p}', '{time}'); $replace = array($this->_email->siteTitle, $this->_email->title, $this->_email->originalAuthor, $this->_email->author, $this->_email->permalink, $this->_email->text, $this->_email->contactme, $this->_email->originalText, $time); $this->_email->msgHtml = str_replace($search, $replace, $this->getTemplate('guest')); $this->_email->subject = str_replace($search, $replace, $this->_email->titleForGuest); $this->_email->altBody = "作者:" . $this->_email->author . "\r\n链接:" . $this->_email->permalink . "\r\n评论:\r\n" . $this->_email->text; return $this; }
/** * 发布文章 * * @access public * @return void */ public function writePage() { $contents = $this->request->from('text', 'template', 'allowComment', 'allowPing', 'allowFeed', 'slug', 'order', 'visibility'); $contents['category'] = $this->request->getArray('category'); $contents['title'] = $this->request->get('title', _t('未命名页面')); $contents['created'] = $this->getCreated(); $contents['visibility'] = 'hidden' == $contents['visibility'] ? 'hidden' : 'publish'; if ($this->request->markdown && $this->options->markdown) { $contents['text'] = '<!--markdown-->' . $contents['text']; } $contents = $this->pluginHandle()->write($contents, $this); if ($this->request->is('do=publish')) { /** 重新发布已经存在的文章 */ $contents['type'] = 'page'; $this->publish($contents); // 完成发布插件接口 $this->pluginHandle()->finishPublish($contents, $this); /** 发送ping */ $this->widget('Widget_Service')->sendPing($this->cid); /** 设置提示信息 */ $this->widget('Widget_Notice')->set(_t('页面 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title), 'success'); /** 设置高亮 */ $this->widget('Widget_Notice')->highlight($this->theId); /** 页面跳转 */ $this->response->redirect(Typecho_Common::url('manage-pages.php?', $this->options->adminUrl)); } else { /** 保存文章 */ $contents['type'] = 'page_draft'; $this->save($contents); // 完成发布插件接口 $this->pluginHandle()->finishSave($contents, $this); if ($this->request->isAjax()) { $created = new Typecho_Date($this->options->gmtTime); $this->response->throwJson(array('success' => 1, 'time' => $created->format('H:i:s A'), 'cid' => $this->cid)); } else { /** 设置提示信息 */ $this->widget('Widget_Notice')->set(_t('草稿 "%s" 已经被保存', $this->title), 'success'); /** 返回原页面 */ $this->response->redirect(Typecho_Common::url('write-page.php?cid=' . $this->cid, $this->options->adminUrl)); } } }