Exemplo n.º 1
0
 /**
  * 发布文章
  *
  * @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));
         }
     }
 }
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
 /**
  * 入口函数,初始化路由器
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     /** 对变量赋值 */
     $options = $this->widget('Widget_Options');
     /** 开始会话 */
     @session_start();
     /** 初始化charset */
     Typecho_Common::$charset = $options->charset;
     /** 初始化exception */
     Typecho_Common::$exceptionHandle = 'Widget_ExceptionHandle';
     /** 设置路径 */
     if (defined('__TYPECHO_PATHINFO_ENCODING__')) {
         $pathInfo = $this->request->getPathInfo(__TYPECHO_PATHINFO_ENCODING__, $options->charset);
     } else {
         $pathInfo = $this->request->getPathInfo();
     }
     Typecho_Router::setPathInfo($pathInfo);
     /** 初始化路由器 */
     Typecho_Router::setRoutes($options->routingTable);
     /** 初始化插件 */
     Typecho_Plugin::init($options->plugins);
     /** 初始化回执 */
     $this->response->setCharset($options->charset);
     $this->response->setContentType($options->contentType);
     /** 默认时区 */
     if (!ini_get("date.timezone") && function_exists("date_default_timezone_set")) {
         @date_default_timezone_set('UTC');
     }
     /** 初始化时区 */
     Typecho_Date::setTimezoneOffset($options->timezone);
     /** 监听缓冲区 */
     ob_start();
 }
Exemplo n.º 4
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.º 5
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.º 6
0
 /**
  * 入口函数,初始化路由器
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     /** 对变量赋值 */
     $options = $this->widget('Widget_Options');
     /** 语言包初始化 */
     if ($options->lang && $options->lang != 'zh_CN') {
         $dir = defined('__TYPECHO_LANG_DIR__') ? __TYPECHO_LANG_DIR__ : __TYPECHO_ROOT_DIR__ . '/usr/langs';
         Typecho_I18n::setLang($dir . '/' . $options->lang . '.mo');
     }
     /** cookie初始化 */
     Typecho_Cookie::setPrefix($options->rootUrl);
     /** 初始化charset */
     Typecho_Common::$charset = $options->charset;
     /** 初始化exception */
     Typecho_Common::$exceptionHandle = 'Widget_ExceptionHandle';
     /** 设置路径 */
     if (defined('__TYPECHO_PATHINFO_ENCODING__')) {
         $pathInfo = $this->request->getPathInfo(__TYPECHO_PATHINFO_ENCODING__, $options->charset);
     } else {
         $pathInfo = $this->request->getPathInfo();
     }
     Typecho_Router::setPathInfo($pathInfo);
     /** 初始化路由器 */
     Typecho_Router::setRoutes($options->routingTable);
     /** 初始化插件 */
     Typecho_Plugin::init($options->plugins);
     /** 初始化回执 */
     $this->response->setCharset($options->charset);
     $this->response->setContentType($options->contentType);
     /** 默认时区 */
     if (function_exists("ini_get") && !ini_get("date.timezone") && function_exists("date_default_timezone_set")) {
         @date_default_timezone_set('UTC');
     }
     /** 初始化时区 */
     Typecho_Date::setTimezoneOffset($options->timezone);
     /** 开始会话, 减小负载只针对后台打开session支持 */
     // modified_by_jiangmuzi 2015.09.23
     // 开始会话
     @session_start();
     // end modified
     /** 监听缓冲区 */
     ob_start();
 }
Exemplo n.º 7
0
</a><a href="#" class="md-trigger" data-modal="modal-12"><i class="i-exlink"></i></a></td>
                                <td><?php 
        echo $post['author'];
        ?>
</td>
                                <td><?php 
        $categories = unserialize($post['category']);
        while ($category->next()) {
            if (in_array($category->mid, $categories)) {
                $category->name();
            }
        }
        ?>
</td>
                                <td><?php 
        $date = new Typecho_Date($post['created']);
        _e($date->word());
        ?>
</td>
                            </tr>
                            <?php 
    }
    ?>
                            <?php 
} else {
    ?>
                            <tr>
                                <td colspan="6"><h6 class="typecho-list-table-title"><?php 
    _e('没有任何稿件');
    ?>
</h6></td>
Exemplo n.º 8
0
                                    <label for="allowFeed"><?php 
_e('允许在聚合中出现');
?>
</label></li>
                                </ul>
                            </section>
                            
                            <?php 
Typecho_Plugin::factory('admin/write-page.php')->advanceOption($page);
?>
                        </div>
                        <?php 
if ($page->have()) {
    ?>
                        <?php 
    $modified = new Typecho_Date($page->modified);
    ?>
                        <section class="typecho-post-option">
                        <p class="description">
                            <br>&mdash;<br>
                            <?php 
    _e('本页面由 <a href="%s">%s</a> 创建', Typecho_Common::url('manage-pages.php?uid=' . $page->author->uid, $options->adminUrl), $page->author->screenName);
    ?>
<br>
                            <?php 
    _e('最后更新于 %s', $modified->word());
    ?>
                        </p>
                        </section>
                        <?php 
}
Exemplo n.º 9
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.º 10
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.º 11
0
 /**
  * 发布文章
  *
  * @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));
         }
     }
 }
Exemplo n.º 12
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.º 13
0
function timeZone($from)
{
    $now = new Typecho_Date(Typecho_Date::gmtTime());
    return $now->timeStamp - $from < 3 * 24 * 60 * 60 ? true : false;
}
Exemplo n.º 14
0
 /**
  * 获取GMT时间
  *
  * @access public
  * @return integer
  */
 public static function gmtTime()
 {
     return self::$gmtTimeStamp ? self::$gmtTimeStamp : (self::$gmtTimeStamp = @gmmktime());
 }
Exemplo n.º 15
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.º 16
0
                             <?php 
     echo '<a href="';
     $options->adminUrl('manage-posts.php?category=' . $val['mid'] . (isset($request->uid) ? '&uid=' . $request->uid : '') . (isset($request->status) ? '&status=' . $request->status : ''));
     echo '">' . $val['name'] . '</a>' . ($key < $length - 1 ? ', ' : '');
     ?>
                         <?php 
 }
 ?>
                         </td>
                         <td>
                         <?php 
 if ($posts->hasSaved) {
     ?>
                         <span class="description">
                         <?php 
     $modifyDate = new Typecho_Date($posts->modified);
     ?>
                         <?php 
     _e('保存于 %s', $modifyDate->word());
     ?>
                         </span>
                         <?php 
 } else {
     ?>
                         <?php 
     $posts->dateWord();
     ?>
                         <?php 
 }
 ?>
                         </td>
Exemplo n.º 17
0
$page->slug();
?>
" class="mini" /></p>
                            <p class="description"><?php 
_e('为这篇日志自定义链接地址, 有利于搜索引擎收录');
?>
</p>
                        </li>
                        <?php 
Typecho_Plugin::factory('admin/write-page.php')->option($page);
?>
                        <?php 
if ($page->have()) {
    ?>
                        <?php 
    $modified = new Typecho_Date($page->modified);
    ?>
                        <li>
                            <label class="typecho-label"><?php 
    _e('本页面由 %s 创建', $page->author->screenName);
    ?>
</label>
                            <p class="description"><?php 
    _e('最后修改于 %s', $modified->word());
    ?>
</p>
                        </li>
                        <?php 
}
?>
                    </ul>
Exemplo n.º 18
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.º 19
0
 /**
  * 访问邮件信息
  * @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;
 }
Exemplo n.º 20
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.º 21
0
 /**
  * 发布文章
  *
  * @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));
         }
     }
 }
Exemplo n.º 22
0
 /**
  * 获取格林尼治标准时间
  *
  * @access protected
  * @return integer
  */
 protected function ___gmtTime()
 {
     return Typecho_Date::gmtTime();
 }
Exemplo n.º 23
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.º 24
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.º 25
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();
         }
     }
 }