Exemplo n.º 1
0
function isNewPost($a)
{
    $now = new Typecho_Date(Typecho_Date::gmtTime());
    if ($now->timeStamp - $a->date->timeStamp < 24 * 60 * 60) {
        echo '<span class="new"></span>';
    }
}
Exemplo n.º 2
0
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) . '年前';
}
Exemplo n.º 3
0
 /**
  * 读取缓存文件内容
  */
 public function process($comment, $token)
 {
     $this->init();
     // 验证 url 中的 token 和设置的 token 是否一致
     if (strcmp($token, Helper::options()->plugin('CommentToMail')->token)) {
         exit;
     }
     //获取评论内容
     $this->_email = $comment;
     //如果本次评论设置了拒收邮件,把coid加入拒收列表
     if ($this->_email->banMail) {
         $this->ban($this->_email->coid, true);
     }
     //发件人邮箱
     $this->_email->from = $this->_cfg->user;
     //发件人名称
     $this->_email->fromName = $this->_cfg->fromName ? $this->_cfg->fromName : $this->_email->siteTitle;
     //向博主发邮件的标题格式
     $this->_email->titleForOwner = $this->_cfg->titleForOwner;
     //向访客发邮件的标题格式
     $this->_email->titleForGuest = $this->_cfg->titleForGuest;
     //验证博主是否接收自己的邮件
     $toMe = in_array('to_me', $this->_cfg->other) && $this->_email->ownerId == $this->_email->authorId ? true : false;
     //向博主发信
     if (in_array($this->_email->status, $this->_cfg->status) && in_array('to_owner', $this->_cfg->other) && ($toMe || $this->_email->ownerId != $this->_email->authorId) && 0 == $this->_email->parent) {
         if (empty($this->_cfg->mail)) {
             Typecho_Widget::widget('Widget_Users_Author@temp' . $this->_email->cid, array('uid' => $this->_email->ownerId))->to($user);
             $this->_email->to = $user->mail;
         } else {
             $this->_email->to = $this->_cfg->mail;
         }
         $this->authorMail()->sendMail();
     }
     //向访客发信
     if (0 != $this->_email->parent && 'approved' == $this->_email->status && in_array('to_guest', $this->_cfg->other) && !$this->ban($this->_email->parent)) {
         //如果联系我的邮件地址为空,则使用文章作者的邮件地址
         if (empty($this->_email->contactme)) {
             if (!isset($user) || !$user) {
                 Typecho_Widget::widget('Widget_Users_Author@temp' . $this->_email->cid, array('uid' => $this->_email->ownerId))->to($user);
             }
             $this->_email->contactme = $user->mail;
         } else {
             $this->_email->contactme = $this->_cfg->contactme;
         }
         $original = $this->_db->fetchRow($this->_db->select('author', 'mail', 'text')->from('table.comments')->where('coid = ?', $this->_email->parent));
         if (in_array('to_me', $this->_cfg->other) || $this->_email->mail != $original['mail']) {
             $this->_email->to = $original['mail'];
             $this->_email->originalText = $original['text'];
             $this->_email->originalAuthor = $original['author'];
             $this->guestMail()->sendMail();
         }
     }
     $date = new Typecho_Date(Typecho_Date::gmtTime());
     $time = $date->format('Y-m-d H:i:s');
     $this->mailLog(false, $time . " 邮件发送完毕!\r\n");
 }
Exemplo n.º 4
0
function readerWall($db, $options)
{
    $html = "";
    $time = Typecho_Date::gmtTime() - 31536000;
    $result = $db->fetchAll($db->select('author, mail, url, count(author) as cnt')->from('table.comments')->where('status = ?', 'approved')->where('created >= ?', $time)->where('ownerId <> authorId')->group('author')->limit(3)->order('cnt', Typecho_Db::SORT_DESC));
    if (!empty($result)) {
        $html = "<div class=\"dearreaders\"><h3>评论先锋队</h3><div>";
        if (isset($result[1])) {
            $html .= "<a rel=\"external nofollow\" href=\"" . (empty($result[1]['url']) ? "#" : $result[1]['url']) . "\" target=\"_blank\"><img alt=\"\" src=\"" . getAvatar(60, $result[1]["mail"]) . "\" class=\"lazy avatar\" height=\"60\" width=\"60\" /><b class=\"name\">" . htmlspecialchars($result[1]["author"]) . "</b><i class=\"count\">2nd</i></a>";
        }
        $html .= "<a rel=\"external nofollow\" href=\"" . (empty($result[0]['url']) ? "#" : $result[0]['url']) . "\" target=\"_blank\"><img alt=\"\" src=\"" . getAvatar(80, $result[0]["mail"]) . "\" class=\"lazy avatar\" height=\"80\" width=\"80\" /><b class=\"name\">" . htmlspecialchars($result[0]["author"]) . "</b><i class=\"count\">1st</i></a>";
        if (isset($result[2])) {
            $html .= "<a rel=\"external nofollow\" href=\"" . (empty($result[2]['url']) ? "#" : $result[2]['url']) . "\" target=\"_blank\"><img alt=\"\" src=\"" . getAvatar(60, $result[2]["mail"]) . "\" class=\"lazy avatar\" height=\"60\" width=\"60\" /><b class=\"name\">" . htmlspecialchars($result[2]["author"]) . "</b><i class=\"count\">3rd</i></a>";
        }
        $html .= "</div></div>";
    }
    return $html;
}
Exemplo n.º 5
0
 /**
  * 获取格林尼治标准时间
  *
  * @access protected
  * @return integer
  */
 protected function ___gmtTime()
 {
     return Typecho_Date::gmtTime();
 }
Exemplo n.º 6
0
 /**
  * 获取邮件内容
  *
  * @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);
 }
Exemplo n.º 7
0
 /**
  * 构建SQL语句
  *
  * @access public
  * @param  array $tables 数据表数组
  * @return string $sql SQL语句
  */
 public function getSql(array $tables)
 {
     // 数据库对象
     $db = Typecho_Db::get();
     // SQL语句
     $sql = '-- Typecho Backup SQL' . "\r\n" . '-- 程序版本: ' . Typecho_Common::VERSION . "\r\n" . '--' . "\r\n" . '-- 备份工具: Export' . "\r\n" . '-- 插件作者: ShingChi' . "\r\n" . '-- 主页链接: http://lcz.me' . "\r\n" . '-- 生成日期: ' . date('Y 年 m 月 d 日', Typecho_Date::gmtTime()) . "\r\n\r\n";
     // 循环构建每张表的SQL语句
     foreach ($tables as $table) {
         // 创建表语句
         $createSql = '';
         // 插入记录语句
         $insertSql = '';
         // 创建表注释
         $createSql .= '-- --------------------------------------------------------' . "\r\n\r\n" . '--' . "\r\n" . '-- 表的结构 `' . $table . "`\r\n" . '--' . "\r\n\r\n";
         /* 表结构 */
         $dropTable = "DROP TABLE IF EXISTS `{$table}`;\r\n";
         $showTable = $db->fetchRow($db->query('SHOW CREATE TABLE ' . $table));
         $createTable = $showTable['Create Table'] . ";\r\n\r\n";
         $createSql .= $dropTable . $createTable;
         /* 表记录 */
         $rows = $db->fetchAll($db->select()->from($table));
         if ($rows) {
             // 字段组合SQL语句
             $fieldText = '';
             // 值的组合SQL语句
             $recordText = '';
             // 所有记录
             $records = array();
             // 插入注释
             $insertSql .= '--' . "\r\n" . '-- 转存表中的数据 `' . $table . "`\r\n" . '--' . "\r\n\r\n";
             // 组合字段语句
             foreach ($rows[0] as $key => $value) {
                 $fieldText .= '`' . $key . '`, ';
             }
             $fieldText = rtrim($fieldText, ', ');
             $insertSql .= 'INSERT INTO ' . $table . ' (' . $fieldText . ') VALUES' . "\r\n";
             // 组合一条记录的语法
             foreach ($rows as $k => $row) {
                 $records[$k] = '';
                 foreach ($row as $record) {
                     $records[$k] .= isset($record) ? '\'' . mysql_escape_string($record) . '\', ' : 'NULL, ';
                 }
                 $records[$k] = rtrim($records[$k], ', ');
             }
             // 组合所有记录的语法
             foreach ($records as $val) {
                 $recordText .= '(' . $val . '),' . "\r\n";
             }
             $recordText = rtrim($recordText, ",\r\n") . ";\r\n\r\n";
             $insertSql .= $recordText;
         }
         $sql .= $createSql . $insertSql;
     }
     return $sql;
 }
Exemplo n.º 8
0
 public static function selectHandle($archive)
 {
     $user = Typecho_Widget::widget('Widget_User');
     if ('post' == $archive->parameter->type || 'page' == $archive->parameter->type) {
         if ($user->hasLogin()) {
             $select = $archive->select()->where('table.contents.status = ? OR table.contents.status = ? OR
                     (table.contents.status = ? AND table.contents.authorId = ?)', 'publish', 'hidden', 'private', $user->uid);
         } else {
             $select = $archive->select()->where('table.contents.status = ? OR table.contents.status = ?', 'publish', 'hidden');
         }
     } else {
         if ($user->hasLogin()) {
             $select = $archive->select()->where('table.contents.status = ? OR
                     (table.contents.status = ? AND table.contents.authorId = ?)', 'publish', 'private', $user->uid);
         } else {
             $select = $archive->select()->where('table.contents.status = ?', 'publish');
         }
     }
     $select->where('table.contents.created < ?', Typecho_Date::gmtTime());
     $select->cleanAttribute('fields');
     return $select;
 }
Exemplo n.º 9
0
    ?>
</option>
                                    <?php 
}
?>
                                </select>
                            </li>
                        </ul>
                        <ul class="typecho-option" id="typecho-option-item-filename-1">
                            <li>
                                <label class="typecho-label" for="filename-0-1"><?php 
_e('备份文件名');
?>
</label>
                                <input id="filename-0-1" name="fileName" type="text" class="w-100" value="<?php 
echo 'typecho_' . date('YmdHi', Typecho_Date::gmtTime() + (Typecho_Date::$timezoneOffset - Typecho_Date::$serverTimezoneOffset)) . '_' . sprintf('%u', crc32(uniqid())) . '.sql';
?>
">
                                <p class="description"><?php 
_e('备份文件默认生成在插件的 backup 文件夹下');
?>
</p>
                            </li>
                        </ul>
                        <ul class="typecho-option" id="typecho-option-item-bakplace-2">
                            <li>
                                <label class="typecho-label"><?php 
_e('备份保存');
?>
</label>
                                <span>
Exemplo n.º 10
0
            $installDb->query($installDb->insert('table.options')->rows(array('name' => 'routingTable', 'user' => 0, 'value' => 'a:25:{s:5:"index";a:3:{s:3:"url";s:1:"/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:7:"archive";a:3:{s:3:"url";s:6:"/blog/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:2:"do";a:3:{s:3:"url";s:22:"/action/[action:alpha]";s:6:"widget";s:9:"Widget_Do";s:6:"action";s:6:"action";}s:4:"post";a:3:{s:3:"url";s:24:"/archives/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"attachment";a:3:{s:3:"url";s:26:"/attachment/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"category";a:3:{s:3:"url";s:17:"/category/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:3:"tag";a:3:{s:3:"url";s:12:"/tag/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"author";a:3:{s:3:"url";s:22:"/author/[uid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"search";a:3:{s:3:"url";s:19:"/search/[keywords]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"index_page";a:3:{s:3:"url";s:21:"/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_page";a:3:{s:3:"url";s:26:"/blog/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"category_page";a:3:{s:3:"url";s:32:"/category/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"tag_page";a:3:{s:3:"url";s:27:"/tag/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"author_page";a:3:{s:3:"url";s:37:"/author/[uid:digital]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"search_page";a:3:{s:3:"url";s:34:"/search/[keywords]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_year";a:3:{s:3:"url";s:18:"/[year:digital:4]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"archive_month";a:3:{s:3:"url";s:36:"/[year:digital:4]/[month:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"archive_day";a:3:{s:3:"url";s:52:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:17:"archive_year_page";a:3:{s:3:"url";s:38:"/[year:digital:4]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:18:"archive_month_page";a:3:{s:3:"url";s:56:"/[year:digital:4]/[month:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:16:"archive_day_page";a:3:{s:3:"url";s:72:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"comment_page";a:3:{s:3:"url";s:53:"[permalink:string]/comment-page-[commentPage:digital]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:4:"feed";a:3:{s:3:"url";s:20:"/feed[feed:string:0]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:4:"feed";}s:8:"feedback";a:3:{s:3:"url";s:31:"[permalink:string]/[type:alpha]";s:6:"widget";s:15:"Widget_Feedback";s:6:"action";s:6:"action";}s:4:"page";a:3:{s:3:"url";s:12:"/[slug].html";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}}')));
            $installDb->query($installDb->insert('table.options')->rows(array('name' => 'actionTable', 'user' => 0, 'value' => 'a:0:{}')));
            $installDb->query($installDb->insert('table.options')->rows(array('name' => 'panelTable', 'user' => 0, 'value' => 'a:0:{}')));
            $installDb->query($installDb->insert('table.options')->rows(array('name' => 'attachmentTypes', 'user' => 0, 'value' => '@image@')));
            /** 初始分类 */
            $installDb->query($installDb->insert('table.metas')->rows(array('name' => _t('默认分类'), 'slug' => 'default', 'type' => 'category', 'description' => _t('只是一个默认分类'), 'count' => 1, 'order' => 1)));
            /** 初始关系 */
            $installDb->query($installDb->insert('table.relationships')->rows(array('cid' => 1, 'mid' => 1)));
            /** 初始内容 */
            $installDb->query($installDb->insert('table.contents')->rows(array('title' => _t('欢迎使用 Typecho'), 'slug' => 'start', 'created' => Typecho_Date::gmtTime(), 'modified' => Typecho_Date::gmtTime(), 'text' => _t('<!--markdown-->如果您看到这篇文章,表示您的 blog 已经安装成功.'), 'authorId' => 1, 'type' => 'post', 'status' => 'publish', 'commentsNum' => 1, 'allowComment' => 1, 'allowPing' => 1, 'allowFeed' => 1, 'parent' => 0)));
            $installDb->query($installDb->insert('table.contents')->rows(array('title' => _t('关于'), 'slug' => 'start-page', 'created' => Typecho_Date::gmtTime(), 'modified' => Typecho_Date::gmtTime(), 'text' => _t('<!--markdown-->本页面由 Typecho 创建, 这只是个测试页面.'), 'authorId' => 1, 'order' => 0, 'type' => 'page', 'status' => 'publish', 'commentsNum' => 0, 'allowComment' => 1, 'allowPing' => 1, 'allowFeed' => 1, 'parent' => 0)));
            /** 初始评论 */
            $installDb->query($installDb->insert('table.comments')->rows(array('cid' => 1, 'created' => Typecho_Date::gmtTime(), 'author' => 'Typecho', 'ownerId' => 1, 'url' => 'http://typecho.org', 'ip' => '127.0.0.1', 'agent' => $options->generator, 'text' => '欢迎加入 Typecho 大家族', 'type' => 'comment', 'status' => 'approved', 'parent' => 0)));
            /** 初始用户 */
            $password = empty($config['userPassword']) ? substr(uniqid(), 7) : $config['userPassword'];
            $installDb->query($installDb->insert('table.users')->rows(array('name' => $config['userName'], 'password' => Typecho_Common::hash($password), 'mail' => $config['userMail'], 'url' => 'http://www.typecho.org', 'screenName' => $config['userName'], 'group' => 'administrator', 'created' => Typecho_Date::gmtTime())));
            unset($_SESSION['typecho']);
            Typecho_Cookie::delete('__typecho_config');
            header('Location: ./install.php?finish&user='******'userName']) . '&password='******'安装失败!');
            ?>
</h1>
                <div class="typecho-install-body">
                    <form method="post" action="?start" name="check">
<?php 
            if ('Mysql' == $type && (1050 == $code || '42S01' == $code) || 'SQLite' == $type && ('HY000' == $code || 1 == $code) || 'Pgsql' == $type && '42P07' == $code) {
Exemplo n.º 11
0
 /**
  * 读取缓存文件内容
  */
 public function process($fileName)
 {
     $this->init();
     //获取评论内容
     $file = $this->_dir . '/cache/' . $fileName;
     if (file_exists($file)) {
         $this->_email = unserialize(file_get_contents($file));
         @unlink($file);
         if (!$this->_user->simpleLogin($this->_email->ownerId)) {
             $this->widget('Widget_Archive@404', 'type=404')->render();
             exit;
         }
     } else {
         $this->widget('Widget_Archive@404', 'type=404')->render();
         exit;
     }
     //如果本次评论设置了拒收邮件,把coid加入拒收列表
     if ($this->_email->banMail) {
         $this->ban($this->_email->coid, true);
     }
     //发件人邮箱
     $this->_email->from = $this->_cfg->user;
     //发件人名称
     $this->_email->fromName = $this->_cfg->fromName ? $this->_cfg->fromName : $this->_email->siteTitle;
     //向博主发邮件的标题格式
     $this->_email->titleForOwner = $this->_cfg->titleForOwner;
     //向访客发邮件的标题格式
     $this->_email->titleForGuest = $this->_cfg->titleForGuest;
     //验证博主是否接收自己的邮件
     $toMe = in_array('to_me', $this->_cfg->other) && $this->_email->ownerId == $this->_email->authorId ? true : false;
     //向博主发信
     if (in_array($this->_email->status, $this->_cfg->status) && in_array('to_owner', $this->_cfg->other) && ($toMe || $this->_email->ownerId != $this->_email->authorId) && 0 == $this->_email->parent) {
         if (empty($this->_cfg->mail)) {
             Typecho_Widget::widget('Widget_Users_Author@temp' . $this->_email->cid, array('uid' => $this->_email->ownerId))->to($user);
             $this->_email->to = $user->mail;
         } else {
             $this->_email->to = $this->_cfg->mail;
         }
         $this->authorMail()->sendMail();
     }
     //向访客发信
     if (0 != $this->_email->parent && 'approved' == $this->_email->status && in_array('to_guest', $this->_cfg->other) && !$this->ban($this->_email->parent)) {
         //如果联系我的邮件地址为空,则使用文章作者的邮件地址
         if (empty($this->_email->contactme)) {
             if (!isset($user) || !$user) {
                 Typecho_Widget::widget('Widget_Users_Author@temp' . $this->_email->cid, array('uid' => $this->_email->ownerId))->to($user);
             }
             $this->_email->contactme = $user->mail;
         } else {
             $this->_email->contactme = $this->_cfg->contactme;
         }
         $original = $this->_db->fetchRow($this->_db->select('author', 'mail', 'text')->from('table.comments')->where('coid = ?', $this->_email->parent));
         if (in_array('to_me', $this->_cfg->other) || $this->_email->mail != $original['mail']) {
             $this->_email->to = $original['mail'];
             $this->_email->originalText = $original['text'];
             $this->_email->originalAuthor = $original['author'];
             $this->guestMail()->sendMail();
         }
     }
     $date = new Typecho_Date(Typecho_Date::gmtTime());
     $time = $date->format('Y-m-d H:i:s');
     $this->mailLog(false, $time . " 邮件发送完毕!\r\n");
 }
Exemplo n.º 12
0
 /**
  * 插件实现方法
  * 
  * @access public
  * @return void
  */
 public static function render($contents, $inst)
 {
     $db = Typecho_Db::get();
     $options = Typecho_Widget::widget('Widget_Options');
     $configs = Helper::options()->plugin('AutoBackup');
     $current = Typecho_Date::gmtTime();
     //当前时间
     $config_file = dirname(__FILE__) . '/config.xml';
     $xml = simplexml_load_file($config_file);
     $lasttime = intval($xml->lasttime);
     $file_path = dirname(__FILE__) . "/backupfiles/TypechoAutoBackup" . date("Ymd", $current) . ".sql";
     if (file_exists($file_path) || $lasttime < 0 || $current - $lasttime < $configs->circle * 24 * 60 * 60) {
         //如果已经存在当日的备份文件,则直接返回
         return $contents;
     } else {
         $tables = $configs->tables;
         $tables = explode(",", $tables);
         $sql = self::creat_sql($tables);
         //获取备份语句
         file_put_contents($file_path, $sql);
         $xml->lasttime = $current;
         $xml = $xml->asXML();
         $fp = fopen($config_file, 'wb');
         fwrite($fp, $xml);
         fclose($fp);
         //将备份文件发送至设置的邮箱
         if ($configs->tomail[0]) {
             $smtp = array();
             $smtp['site'] = $options->title;
             $smtp['attach'] = $file_path;
             $smtp['attach_name'] = "TypechoAutoBackup" . date("Ymd", $current) . ".sql";
             $smtp['mode'] = $configs->mode;
             //获取SMTP设置
             $smtp['user'] = $configs->user;
             $smtp['pass'] = $configs->pass;
             $smtp['host'] = $configs->host;
             $smtp['port'] = $configs->port;
             //获取验证信息
             if (is_array($configs->validate)) {
                 if (in_array('validate', $configs->validate)) {
                     $smtp['validate'] = true;
                 }
                 if (in_array('ssl', $configs->validate)) {
                     $smtp['ssl'] = true;
                 }
             }
             $format = "format";
             $smtp['AltBody'] = "这是从" . $smtp['site'] . "由Typecho AutoBackup插件自动发送的数据库备份文件";
             $smtp['body'] = "该邮件由您的Typecho博客<a href=\"{$options->siteUrl}\">" . $smtp['site'] . "</a>使用的插件AutoBackup发出<br />\n\t\t\t\t\t\t\t\t如果你没有做相关设置,请联系邮件来源地址" . $smtp['user'] . "<br />\n\t\t\t\t\t\t\t\t发现插件bug请联系i@zhoumiao.com或访问插件<a href=\"http://www.zhoumiao.com/archives/automatic-database-backup-plug-in-for-typecho-0-8\">更新地址</a>";
             if ($configs->subject != "") {
                 $smtp['subject'] = date("Ymd") . '-' . $configs->subject . '-数据库备份文件';
             } else {
                 $smtp['subject'] = date("Ymd") . '-' . $options->title . '-数据库备份文件';
             }
             if ($configs->mail != "") {
                 $email_to = $configs->mail;
             } else {
                 $select = Typecho_Widget::widget('Widget_Abstract_Users')->select()->where('uid', 1);
                 $result = $db->query($select);
                 $row = $db->fetchRow($result);
                 $email_to = $row['mail'];
             }
             $smtp['to'] = $email_to;
             $smtp['from'] = $email_to;
             $issend = self::SendMail($smtp);
             if ($issend) {
                 unlink($file_path);
             }
             return $contents;
         } else {
             return $contents;
         }
     }
 }
Exemplo n.º 13
0
    /**
     * 导出xml
     *
     * @access public
     * @return void
     */
    public function doExport()
    {
        $options = Helper::options();
        // execution
        $authors_list = $this->wxr_authors_list();
        $cats_list = $this->wxr_cats_list();
        $tags_list = $this->wxr_tags_list();
        $posts_list = $this->wxr_posts_list($options);
        // 备份文件名
        $fileName = 'wordpress.' . date('Y-m-d') . '.xml';
        //header('Content-Description: File Transfer');
        header('Content-Type: text/xml');
        header('Content-Disposition: attachment; filename=' . $fileName);
        if (preg_match("/MSIE ([0-9].[0-9]{1,2})/", $_SERVER['HTTP_USER_AGENT'])) {
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
        } else {
            header('Pragma: no-cache');
            header('Last-Modified: ' . gmdate('D, d M Y H:i:s', Typecho_Date::gmtTime() + (Typecho_Date::$timezoneOffset - Typecho_Date::$serverTimezoneOffset)) . ' GMT');
        }
        header('Expires: ' . gmdate('D, d M Y H:i:s', Typecho_Date::gmtTime() + (Typecho_Date::$timezoneOffset - Typecho_Date::$serverTimezoneOffset)) . ' GMT');
        echo '<?xml version="1.0" encoding="' . $options->charset . '" ?>' . "\n";
        echo <<<EOT
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->

<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
<!-- 3. Install the "WordPress" importer from the list. -->
<!-- 4. Activate & Run Importer. -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. You will first be asked to map the authors in this export file to users -->
<!--    on the site. For each author, you may choose to map to an -->
<!--    existing user on the site or to create a new user. -->
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!--    contained in this file into your site. -->
<rss version="2.0"
\txmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
\txmlns:content="http://purl.org/rss/1.0/modules/content/"
\txmlns:wfw="http://wellformedweb.org/CommentAPI/"
\txmlns:dc="http://purl.org/dc/elements/1.1/"
\txmlns:wp="http://wordpress.org/export/1.2/"
>
<channel>
    <title>{$options->title}</title>
    <link>{$options->siteUrl}</link>
\t<description>{$options->description}</description>
\t<pubDate>Wed, 19 Nov 2014 06:15:10 +0000</pubDate>
\t<language>{$options->lang}</language>
\t<wp:wxr_version>1.2</wp:wxr_version>
\t<wp:base_site_url>{$options->siteUrl}</wp:base_site_url>
\t<wp:base_blog_url>{$options->siteUrl}</wp:base_blog_url>
\t{$authors_list}
\t{$cats_list}
\t{$tags_list}
\t<generator>http://wordpress.org/?v=4.0</generator>
\t{$posts_list}
</channel>
</rss>
EOT;
    }
Exemplo n.º 14
0
 /**
  * 构建SQL语句
  *
  * @access public
  * @param  array $tables 数据表数组
  * @return string $sql SQL语句
  */
 public function sqlBuild(array $tables)
 {
     // 数据库对象
     $db = Typecho_Db::get();
     // SQL语句
     $sql = "-- Typecho Backup SQL\r\n" . "-- version: " . Typecho_Common::VERSION . "\r\n" . "--\r\n" . "-- generator: DbManager\r\n" . "-- author: ShingChi <http://lcz.me>\r\n" . "-- date: " . date('F jS, Y', Typecho_Date::gmtTime()) . "\r\n\r\n";
     foreach ($tables as $table) {
         $sql .= "\r\n-- ----------------------------------" . "----------------------\r\n\r\n" . "--\r\n" . "-- 数据表 {$table}\r\n" . "--\r\n\r\n";
         $sql .= "DROP TABLE IF EXISTS `{$table}`;\r\n";
         $createSql = $db->fetchRow($db->query("SHOW CREATE TABLE {$table}"));
         $sql .= $createSql['Create Table'] . ";\r\n\r\n";
         $resource = $db->query($db->select()->from($table));
         while ($row = $db->fetchRow($resource)) {
             foreach ($row as $key => $value) {
                 $keys[] = "`" . $key . "`";
                 $values[] = "'" . mysql_escape_string($value) . "'";
             }
             $sql .= "INSERT INTO `" . $table . "` (" . implode(", ", $keys) . ") VALUES (" . implode(", ", $values) . ");\r\n";
             unset($keys);
             unset($values);
         }
     }
     return $sql;
 }
Exemplo n.º 15
0
function timeZone($from)
{
    $now = new Typecho_Date(Typecho_Date::gmtTime());
    return $now->timeStamp - $from < 3 * 24 * 60 * 60 ? true : false;
}
Exemplo n.º 16
0
 /**
  * 插件实现方法
  */
 public static function baseInit()
 {
     self::$_time = Typecho_Date::gmtTime();
     self::$_options = Typecho_Widget::widget("Widget_Options");
     self::$_cache_file = __TYPECHO_ROOT_DIR__ . "/usr/mytypechotheme.json.php";
     if (file_exists(self::$_cache_file)) {
         self::$_cache = @Json::decode(@substr(@file_get_contents(self::$_cache_file), strlen(self::SAFETY_HEAD)), true);
         if (self::$_cache === false) {
             self::$_cache = array();
         }
     }
 }