更新markdown,加上nofollow,修正链接自动识别

更新消息机制,将后台cookie识别改为前台js cookie识别
更新session机制
This commit is contained in:
joyqi
2013-11-22 12:34:00 +08:00
parent b7d24401f0
commit c86c007dca
27 changed files with 173 additions and 252 deletions
+30 -10
View File
@@ -5,18 +5,29 @@
<script>
(function () {
$(document).ready(function() {
<?php if ($notice->highlight): ?>
//增加高亮效果
$('#<?php echo $notice->highlight; ?>').effect('highlight', 1000);
<?php endif; ?>
//增加淡出效果
// 处理消息机制
(function () {
var p = $('.popup');
var prefix = '<?php echo Typecho_Cookie::getPrefix(); ?>',
cookies = {
notice : $.cookie(prefix + '__typecho_notice'),
noticeType : $.cookie(prefix + '__typecho_notice_type'),
highlight : $.cookie(prefix + '__typecho_notice_highlight')
},
path = '<?php $parts = parse_url($options->siteUrl);
echo empty($parts['path']) ? '/' : $parts['path']; ?>';
if (p.length > 0) {
var head = $('.typecho-head-nav'),
offset = head.length > 0 ? head.outerHeight() : 0;
if (!!cookies.notice && 'success|notice|error'.indexOf(cookies.noticeType) >= 0) {
var head = $('.typecho-head-nav'),
p = $('<div class="message popup ' + cookies.noticeType + '">'
+ '<ul><li>' + $.parseJSON(cookies.notice).join('</li><li>')
+ '</li></ul></div>'), offset = 0;
if (head.length > 0) {
p.insertAfter(head);
offset = head.outerHeight();
} else {
p.prependTo(document.body);
}
function checkScroll () {
if ($(window).scrollTop() >= offset) {
@@ -52,6 +63,15 @@
$(this).remove();
});
});
$.cookie(prefix + '__typecho_notice', null, {path : path});
$.cookie(prefix + '__typecho_notice_type', null, {path : path});
}
if (cookies.highlight) {
$('#' + cookies.highlight).effect('highlight', 1000);
$.cookie(prefix + '__typecho_notice_highlight', null, {path : path});
}
})();
+2 -3
View File
@@ -17,7 +17,6 @@ Typecho_Plugin::factory('admin/common.php')->begin();
Typecho_Widget::widget('Widget_Options')->to($options);
Typecho_Widget::widget('Widget_User')->to($user);
Typecho_Widget::widget('Widget_Notice')->to($notice);
Typecho_Widget::widget('Widget_Menu')->to($menu);
/** 初始化上下文 */
@@ -48,9 +47,9 @@ if (!$user->logged && !Typecho_Cookie::get('__typecho_first_run') && !empty($cur
if ($mustUpgrade && 'upgrade.php' != $adminFile) {
$response->redirect(Typecho_Common::url('upgrade.php', $options->adminUrl));
} else if (!$mustUpgrade && 'upgrade.php' == $adminFile) {
$response->redirect(Typecho_Common::url('index.php', $options->adminUrl));
$response->redirect($options->adminUrl);
} else if (!$mustUpgrade && 'welcome.php' == $adminFile && $user->logged) {
$response->redirect(Typecho_Common::url('index.php', $options->adminUrl));
$response->redirect($options->adminUrl);
}
}
+6 -23
View File
@@ -1,26 +1,14 @@
<?php
include 'common.php';
include 'header.php';
if ($user->hasLogin()) {
$response->redirect($options->adminUrl);
}
$rememberName = Typecho_Cookie::get('__typecho_remember_name');
Typecho_Cookie::delete('__typecho_remember_name');
?>
<?php if(!$user->hasLogin()): ?>
<?php if($notice->have() && in_array($notice->noticeType, array('success', 'notice', 'error'))): ?>
<div class="message <?php $notice->noticeType(); ?> popup">
<ul>
<?php $notice->lists(); ?>
</ul>
</div>
<?php endif; ?>
<?php else: ?>
<div class="message notice popup">
<ul>
<li><?php _e('您已经登录到%s', $options->title); ?></li>
</ul>
</div>
<?php endif; ?>
include 'header.php';
?>
<div class="typecho-login">
<h1>Typecho</h1>
@@ -42,12 +30,7 @@ Typecho_Cookie::delete('__typecho_remember_name');
<p class="more-link">
<a href="<?php $options->siteUrl(); ?>"><?php _e('返回首页'); ?></a>
<?php if($user->hasLogin()): ?>
<!-- &bull;
<a href=""><?php _e('忘记密码'); ?></a> -->
&bull;
<a href="<?php $options->adminUrl(); ?>"><?php _e('后台管理'); ?></a>
<?php elseif($options->allowRegister): ?>
<?php if($options->allowRegister): ?>
&bull;
<a href="<?php $options->registerUrl(); ?>"><?php _e('用户注册'); ?></a>
<?php endif; ?>
-7
View File
@@ -8,10 +8,3 @@
</div>
</div>
<?php if($notice->have() && in_array($notice->noticeType, array('success', 'notice', 'error'))): ?>
<div class="message <?php $notice->noticeType(); ?> popup">
<ul>
<?php $notice->lists(); ?>
</ul>
</div>
<?php endif; ?>
+5 -39
View File
@@ -1,42 +1,16 @@
<?php
include 'common.php';
include 'header.php';
if ($user->hasLogin() || !$options->allowRegister) {
$response->redirect($options->siteUrl);
}
$rememberName = Typecho_Cookie::get('__typecho_remember_name');
$rememberMail = Typecho_Cookie::get('__typecho_remember_mail');
Typecho_Cookie::delete('__typecho_remember_name');
Typecho_Cookie::delete('__typecho_remember_mail');
?>
<?php if(!$user->hasLogin() && $options->allowRegister): ?>
<?php if($notice->have() && in_array($notice->noticeType, array('success', 'notice', 'error'))): ?>
<div class="message <?php $notice->noticeType(); ?> popup">
<ul>
<?php $notice->lists(); ?>
</ul>
</div>
<?php endif; ?>
<?php elseif (!$options->allowRegister): ?>
<div class="message error popup">
<ul>
<li><?php _e('网站注册已关闭'); ?></li>
</ul>
</div>
<?php else: ?>
<?php if($notice->have() && in_array($notice->noticeType, array('success', 'notice', 'error'))): ?>
<div class="message <?php $notice->noticeType(); ?> popup">
<ul>
<?php $notice->lists(); ?>
</ul>
</div>
<?php else: ?>
<div class="message notice popup">
<ul>
<li><?php _e('您已经登录到 %s', $options->title); ?></li>
</ul>
</div>
<?php endif; ?>
<?php endif; ?>
include 'header.php';
?>
<div class="typecho-login">
<h1>Typecho</h1>
@@ -50,22 +24,14 @@ Typecho_Cookie::delete('__typecho_remember_mail');
<input type="email" id="mail" name="mail" placeholder="<?php _e('Email'); ?>" value="<?php echo $rememberMail; ?>" class="text-l w-100" />
</p>
<p class="submit">
<!-- <label for="remember"><input type="checkbox" name="remember" class="checkbox" value="1" id="remember" /> <?php _e('记住我'); ?></label> -->
<button type="submit" class="btn-l w-100 primary"><?php _e('注册'); ?></button>
</p>
</form>
<p class="more-link">
<a href="<?php $options->siteUrl(); ?>"><?php _e('返回首页'); ?></a>
<!-- &bull;
<a href=""><?php _e('忘记密码'); ?></a> -->
<?php if($user->hasLogin()): ?>
&bull;
<a href="<?php $options->adminUrl(); ?>"><?php _e('后台管理'); ?></a>
<?php else: ?>
&bull;
<a href="<?php $options->adminUrl('login.php'); ?>"><?php _e('用户登录'); ?></a>
<?php endif; ?>
</p>
</div>
<?php
+47 -6
View File
@@ -1259,8 +1259,10 @@ class Markdown {
protected function doAutoLinks($text) {
$text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i',
$text = preg_replace_callback('/(="|<)?\b(https?|ftp)(:\/\/[-A-Z0-9+&@#\/%?=~_|\[\]\(\)!:,\.;]*[-A-Z0-9+&@#\/%=~_|\[\])])(?=$|\W)/i',
array(&$this, '_doAutoLinks_url_callback'), $text);
$text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i',
array(&$this, '_doAutoLinks_url_callback_replace'), $text);
# Email addresses: <address@domain.foo>
$text = preg_replace_callback('{
@@ -1285,10 +1287,49 @@ class Markdown {
return $text;
}
protected function _doAutoLinks_url_callback_replace($matches) {
$url = $this->encodeAttribute($matches[1]);
$link = "<a rel=\"nofollow\" href=\"$url\">$url</a>";
return $this->hashPart($link);
}
protected function _doAutoLinks_url_callback($matches) {
$url = $this->encodeAttribute($matches[1]);
$link = "<a href=\"$url\">$url</a>";
return $this->hashPart($link);
list ($wholeMatch, $lookbehind, $protocol, $link) = $matches;
if ($lookbehind) {
return $wholeMatch;
}
if ($link[strlen($link) - 1] != ')') {
return '<' . $protocol . $link . '>';
}
$level = 0;
if (preg_match_all("/[()]/", $link, $matches)) {
foreach ($matches[0] as $op) {
if ('(' == $op) {
if ($level <= 0) {
$level = 1;
} else {
$level ++;
}
} else {
$level --;
}
}
}
$tail = '';
if ($level < 0) {
$link = preg_replace("/\){1," . (- $level) . "}$/", $link, function ($matches) use (&$tail) {
$tail = $matches[0];
return '';
});
}
$url = $this->encodeAttribute($matches[2] . $matches[3]);
$link = "<a rel=\"nofollow\" href=\"$url\">$url</a>";
return '<' . $protocol . $link . '>' . $tail;
}
protected function _doAutoLinks_email_callback($matches) {
$address = $matches[1];
@@ -2258,7 +2299,7 @@ class MarkdownExtra extends Markdown {
$url = $this->urls[$link_id];
$url = $this->encodeAttribute($url);
$result = "<a href=\"$url\"";
$result = "<a rel=\"nofollow\" href=\"$url\"";
if ( isset( $this->titles[$link_id] ) ) {
$title = $this->titles[$link_id];
$title = $this->encodeAttribute($title);
@@ -2286,7 +2327,7 @@ class MarkdownExtra extends Markdown {
$url = $this->encodeAttribute($url);
$result = "<a href=\"$url\"";
$result = "<a rel=\"nofollow\" href=\"$url\"";
if (isset($title)) {
$title = $this->encodeAttribute($title);
$result .= " title=\"$title\"";
+9 -11
View File
@@ -12,9 +12,6 @@
/** Typecho_Widget_Helper_Layout */
require_once 'Typecho/Widget/Helper/Layout.php';
/** Typecho_Request */
require_once 'Typecho/Cookie.php';
/** Typecho_Validate */
require_once 'Typecho/Validate.php';
@@ -239,11 +236,11 @@ class Typecho_Widget_Helper_Form extends Typecho_Widget_Helper_Layout
$error = $validator->run($formData, $rules);
if ($error) {
/** 利用cookie记录错误 */
Typecho_Cookie::set('__typecho_form_message_' . $id, $error);
/** 利用session记录错误 */
$_SESSION['__typecho_form_message_' . $id] = $error;
/** 利用cookie记录表单值 */
Typecho_Cookie::set('__typecho_form_record_' . $id, $formData);
/** 利用session记录表单值 */
$_SESSION['__typecho_form_record_' . $id] = $formData;
}
return $error;
@@ -260,8 +257,9 @@ class Typecho_Widget_Helper_Form extends Typecho_Widget_Helper_Layout
$id = md5(implode('"', array_keys($this->_inputs)));
/** 恢复表单值 */
if ($record = Typecho_Cookie::get('__typecho_form_record_' . $id)) {
$message = Typecho_Cookie::get('__typecho_form_message_' . $id);
if (isset($_SESSION['__typecho_form_record_' . $id])) {
$record = $_SESSION['__typecho_form_record_' . $id];
$message = $_SESSION['__typecho_form_message_' . $id];
foreach ($this->_inputs as $name => $input) {
$input->value(isset($record[$name]) ? $record[$name] : $input->value);
@@ -271,10 +269,10 @@ class Typecho_Widget_Helper_Form extends Typecho_Widget_Helper_Layout
}
}
Typecho_Cookie::delete('__typecho_form_record_' . $id);
unset($_SESSION['__typecho_form_record_' . $id]);
}
parent::render();
Typecho_Cookie::delete('__typecho_form_message_' . $id);
unset($_SESSION['__typecho_form_message_' . $id]);
}
}
+5 -5
View File
@@ -89,7 +89,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
}
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被标记为待审核') : _t('没有评论被标记为待审核'), NULL,
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被标记为待审核') : _t('没有评论被标记为待审核'),
$updateRows > 0 ? 'success' : 'notice');
/** 返回原网页 */
@@ -114,7 +114,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
}
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被标记为垃圾') : _t('没有评论被标记为垃圾'), NULL,
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被标记为垃圾') : _t('没有评论被标记为垃圾'),
$updateRows > 0 ? 'success' : 'notice');
/** 返回原网页 */
@@ -139,7 +139,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
}
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被通过') : _t('没有评论被通过'), NULL,
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被通过') : _t('没有评论被通过'),
$updateRows > 0 ? 'success' : 'notice');
/** 返回原网页 */
@@ -191,7 +191,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
} else {
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($deleteRows > 0 ? _t('评论已经被删除') : _t('没有评论被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteRows > 0 ? _t('评论已经被删除') : _t('没有评论被删除'),
$deleteRows > 0 ? 'success' : 'notice');
/** 返回原网页 */
@@ -220,7 +220,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($deleteRows > 0 ?
_t('所有垃圾评论已经被删除') : _t('没有垃圾评论被删除'), NULL,
_t('所有垃圾评论已经被删除') : _t('没有垃圾评论被删除'),
$deleteRows > 0 ? 'success' : 'notice');
/** 返回原网页 */
+2 -2
View File
@@ -196,7 +196,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
/** 提示信息 */
$this->widget('Widget_Notice')->set('publish' == $this->status ?
_t('文件 <a href="%s">%s</a> 已经被更新', $this->permalink, $this->title) :
_t('未归档文件 %s 已经被更新', $this->title), NULL, 'success');
_t('未归档文件 %s 已经被更新', $this->title), 'success');
}
@@ -250,7 +250,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
: array('code' => 500, 'message' => _t('没有文件被删除')));
} else {
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('文件已经被删除') : _t('没有文件被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('文件已经被删除') : _t('没有文件被删除'),
$deleteCount > 0 ? 'success' : 'notice');
/** 返回原网页 */
+4 -5
View File
@@ -81,8 +81,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
$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')->set(_t('页面 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title), 'success');
/** 设置高亮 */
$this->widget('Widget_Notice')->highlight($this->theId);
@@ -103,7 +102,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
));
} else {
/** 设置提示信息 */
$this->widget('Widget_Notice')->set(_t('草稿 "%s" 已经被保存', $this->title), NULL, 'success');
$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));
@@ -158,7 +157,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
}
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('页面已经被删除') : _t('没有页面被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('页面已经被删除') : _t('没有页面被删除'),
$deleteCount > 0 ? 'success' : 'notice');
/** 返回原网页 */
@@ -196,7 +195,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
}
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('草稿已经被删除') : _t('没有草稿被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('草稿已经被删除') : _t('没有草稿被删除'),
$deleteCount > 0 ? 'success' : 'notice');
/** 返回原网页 */
+4 -4
View File
@@ -581,7 +581,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
/** 设置提示信息 */
$this->widget('Widget_Notice')->set('post' == $this->type ?
_t('文章 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title) :
_t('文章 "%s" 等待审核', $this->title), NULL, 'success');
_t('文章 "%s" 等待审核', $this->title), 'success');
/** 设置高亮 */
$this->widget('Widget_Notice')->highlight($this->theId);
@@ -605,7 +605,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
));
} else {
/** 设置提示信息 */
$this->widget('Widget_Notice')->set(_t('草稿 "%s" 已经被保存', $this->title), NULL, 'success');
$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));
@@ -671,7 +671,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
}
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('文章已经被删除') : _t('没有文章被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('文章已经被删除') : _t('没有文章被删除'),
$deleteCount > 0 ? 'success' : 'notice');
/** 返回原网页 */
@@ -709,7 +709,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
}
/** 设置提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('草稿已经被删除') : _t('没有草稿被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('草稿已经被删除') : _t('没有草稿被删除'),
$deleteCount > 0 ? 'success' : 'notice');
/** 返回原网页 */
+4 -2
View File
@@ -25,8 +25,10 @@ class Widget_Init extends Typecho_Widget
/** 对变量赋值 */
$options = $this->widget('Widget_Options');
/** 开始会话 */
@session_start();
/** 开始会话, 减小负载只针对后台打开session支持 */
if ($this->widget('Widget_User')->hasLogin()) {
@session_start();
}
/** cookie初始化 */
Typecho_Cookie::setPrefix($options->siteUrl);
+1 -1
View File
@@ -60,7 +60,7 @@ class Widget_Login extends Widget_Abstract_Users implements Widget_Interface_Do
$this->request->password, 1 == $this->request->remember);
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
$this->widget('Widget_Notice')->set(_t('用户名或密码无效'), NULL, 'error');
$this->widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error');
$this->response->goBack('?referer=' . urlencode($this->request->referer));
}
+1
View File
@@ -30,5 +30,6 @@ class Widget_Logout extends Widget_Abstract_Users implements Widget_Interface_Do
$this->user->logout();
$this->pluginHandle()->logout();
$this->response->goBack(NULL, $this->options->index);
@session_destroy();
}
}
+10 -10
View File
@@ -225,7 +225,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('分类 <a href="%s">%s</a> 已经被增加',
$this->permalink, $this->name), NULL, 'success');
$this->permalink, $this->name), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('manage-metas.php', $this->options->adminUrl));
@@ -258,7 +258,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('分类 <a href="%s">%s</a> 已经被更新',
$this->permalink, $this->name), NULL, 'success');
$this->permalink, $this->name), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('manage-metas.php', $this->options->adminUrl));
@@ -285,7 +285,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
}
/** 提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('分类已经删除') : _t('没有分类被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('分类已经删除') : _t('没有分类被删除'),
$deleteCount > 0 ? 'success' : 'notice');
/** 转向原页 */
@@ -306,7 +306,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
$validator->addRule('merge', array($this, 'categoryExists'), _t('请选择需要合并的分类'));
if ($validator->run($this->request->from('merge'))) {
$this->widget('Widget_Notice')->set($e->getMessages(), NULL, 'error');
$this->widget('Widget_Notice')->set($e->getMessages(), 'error');
$this->response->goBack();
}
@@ -317,9 +317,9 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
$this->merge($merge, 'category', $categories);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('分类已经合并'), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('分类已经合并'), 'success');
} else {
$this->widget('Widget_Notice')->set(_t('没有选择任何分类'), NULL, 'notice');
$this->widget('Widget_Notice')->set(_t('没有选择任何分类'), 'notice');
}
/** 转向原页 */
@@ -361,9 +361,9 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
$this->refreshCountByTypeAndStatus($category, 'post', 'publish');
}
$this->widget('Widget_Notice')->set(_t('分类刷新已经完成'), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('分类刷新已经完成'), 'success');
} else {
$this->widget('Widget_Notice')->set(_t('没有选择任何分类'), NULL, 'notice');
$this->widget('Widget_Notice')->set(_t('没有选择任何分类'), 'notice');
}
/** 转向原页 */
@@ -384,7 +384,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
$validator->addRule('mid', array($this, 'categoryExists'), _t('分类不存在'));
if ($error = $validator->run($this->request->from('mid'))) {
$this->widget('Widget_Notice')->set($error, NULL, 'error');
$this->widget('Widget_Notice')->set($error, 'error');
} else {
$this->db->query($this->db->update('table.options')
@@ -399,7 +399,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('<a href="%s">%s</a> 已经被设为默认分类',
$this->permalink, $this->name), NULL, 'success');
$this->permalink, $this->name), 'success');
}
/** 转向原页 */
+9 -9
View File
@@ -218,7 +218,7 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('标签 <a href="%s">%s</a> 已经被增加',
$this->permalink, $this->name), NULL, 'success');
$this->permalink, $this->name), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('manage-metas.php?type=tag', $this->options->adminUrl));
@@ -250,7 +250,7 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('标签 <a href="%s">%s</a> 已经被更新',
$this->permalink, $this->name), NULL, 'success');
$this->permalink, $this->name), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('manage-metas.php?type=tag', $this->options->adminUrl));
@@ -277,7 +277,7 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
}
/** 提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('标签已经删除') : _t('没有标签被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('标签已经删除') : _t('没有标签被删除'),
$deleteCount > 0 ? 'success' : 'notice');
/** 转向原页 */
@@ -293,13 +293,13 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
public function mergeTag()
{
if (empty($this->request->merge)) {
$this->widget('Widget_Notice')->set(_t('请填写需要合并到的标签'), NULL, 'notice');
$this->widget('Widget_Notice')->set(_t('请填写需要合并到的标签'), 'notice');
$this->response->goBack();
}
$merge = $this->scanTags($this->request->merge);
if (empty($merge)) {
$this->widget('Widget_Notice')->set(_t('合并到的标签名不合法'), NULL, 'error');
$this->widget('Widget_Notice')->set(_t('合并到的标签名不合法'), 'error');
$this->response->goBack();
}
@@ -309,9 +309,9 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
$this->merge($merge, 'tag', $tags);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('标签已经合并'), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('标签已经合并'), 'success');
} else {
$this->widget('Widget_Notice')->set(_t('没有选择任何标签'), NULL, 'notice');
$this->widget('Widget_Notice')->set(_t('没有选择任何标签'), 'notice');
}
/** 转向原页 */
@@ -332,9 +332,9 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
$this->refreshCountByTypeAndStatus($tag, 'post', 'publish');
}
$this->widget('Widget_Notice')->set(_t('标签刷新已经完成'), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('标签刷新已经完成'), 'success');
} else {
$this->widget('Widget_Notice')->set(_t('没有选择任何标签'), NULL, 'notice');
$this->widget('Widget_Notice')->set(_t('没有选择任何标签'), 'notice');
}
/** 转向原页 */
+7 -87
View File
@@ -14,14 +14,6 @@
*/
class Widget_Notice extends Typecho_Widget
{
/**
* 提示类型
*
* @access public
* @var string
*/
public $noticeType = 'notice';
/**
* 提示高亮
*
@@ -30,66 +22,6 @@ class Widget_Notice extends Typecho_Widget
*/
public $highlight;
/**
* 执行函数
*
* @access public
* @return void
*/
public function execute()
{
if (NULL !== Typecho_Cookie::get('__typecho_notice')) {
$this->noticeType = Typecho_Cookie::get('__typecho_notice_type');
$this->push(Typecho_Cookie::get('__typecho_notice'));
Typecho_Cookie::delete('__typecho_notice', $this->widget('Widget_Options')->siteUrl);
Typecho_Cookie::delete('__typecho_notice_type', $this->widget('Widget_Options')->siteUrl);
}
if (NULL !== Typecho_Cookie::get('__typecho_notice_highlight')) {
$this->highlight = Typecho_Cookie::get('__typecho_notice_highlight');
Typecho_Cookie::delete('__typecho_notice_highlight', $this->widget('Widget_Options')->siteUrl);
}
}
/**
* 输出提示类型
*
* @access public
* @return void
*/
public function noticeType()
{
echo $this->noticeType;
}
/**
* 列表显示所有提示内容
*
* @access public
* @param string $tag 列表html标签
* @return void
*/
public function lists($tag = 'li')
{
foreach ($this->row as $row) {
echo "<$tag>" . $row . "</$tag>";
}
}
/**
* 显示相应提示字段
*
* @access public
* @param string $name 字段名称
* @param string $format 字段格式
* @return void
*/
public function display($name, $format = '%s')
{
echo empty($this->row[$name]) ? NULL :
((false === strpos($format, '%s')) ? $format : sprintf($format, $this->row[$name]));
}
/**
* 高亮相关元素
*
@@ -119,31 +51,19 @@ class Widget_Notice extends Typecho_Widget
/**
* 设定堆栈每一行的值
*
* @param string $name 值对应的键值
* @param mixed $name 相应的值
* @param string $value 值对应的键值
* @param string $type 提示类型
* @param string $typeFix 兼容老插件
* @return array
*/
public function set($name, $value = NULL, $type = 'notice')
public function set($value, $type = 'notice', $typeFix = 'notice')
{
$notice = array();
if (is_array($name)) {
foreach ($name as $key => $row) {
$notice[$key] = $row;
}
} else {
if (empty($value)) {
$notice[] = $name;
} else {
$notice[$name] = $value;
}
$notice = is_array($value) ? array_values($value) : array($value);
if (empty($type) && $typeFix) {
$type = $typeFix;
}
$this->noticeType = $type;
$this->push($notice);
Typecho_Cookie::set('__typecho_notice', $notice,
Typecho_Cookie::set('__typecho_notice', json_encode($notice),
$this->widget('Widget_Options')->gmtTime + $this->widget('Widget_Options')->timezone + 86400,
$this->widget('Widget_Options')->siteUrl);
Typecho_Cookie::set('__typecho_notice_type', $type,
+1 -1
View File
@@ -213,7 +213,7 @@ class Widget_Options_Discussion extends Widget_Abstract_Options implements Widge
$this->update(array('value' => $value), $this->db->sql()->where('name = ?', $name));
}
$this->widget('Widget_Notice')->set(_t("设置已经保存"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
$this->response->goBack();
}
+1 -1
View File
@@ -162,7 +162,7 @@ class Widget_Options_General extends Widget_Abstract_Options implements Widget_I
$this->update(array('value' => $value), $this->db->sql()->where('name = ?', $name));
}
$this->widget('Widget_Notice')->set(_t("设置已经保存"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
$this->response->goBack();
}
+3 -3
View File
@@ -307,9 +307,9 @@ RewriteRule . {$basePath}index.php [L]
}
if ($patternValid) {
$this->widget('Widget_Notice')->set(_t("设置已经保存"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
} else {
$this->widget('Widget_Notice')->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."), NULL, 'notice');
$this->widget('Widget_Notice')->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."), 'notice');
}
$this->response->goBack();
}
@@ -324,7 +324,7 @@ RewriteRule . {$basePath}index.php [L]
{
$this->update(array('value' => 1), $this->db->sql()->where('name = ?', 'rewrite'));
$this->widget('Widget_Notice')->set(_t("设置已经保存"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
$this->response->goBack();
}
+1 -1
View File
@@ -196,7 +196,7 @@ class Widget_Options_Reading extends Widget_Options_Permalink
$this->update(array('value' => $value), $this->db->sql()->where('name = ?', $name));
}
$this->widget('Widget_Notice')->set(_t("设置已经保存"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
$this->response->goBack();
}
+7 -7
View File
@@ -102,7 +102,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
$this->db->sql()->where('name = ?', 'plugins'));
} catch (Typecho_Plugin_Exception $e) {
/** 截获异常 */
$this->widget('Widget_Notice')->set($e->getMessage(), NULL, 'error');
$this->widget('Widget_Notice')->set($e->getMessage(), 'error');
$this->response->goBack();
}
@@ -133,9 +133,9 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
$this->widget('Widget_Notice')->highlight('plugin-' . $pluginName);
if (isset($result) && is_string($result)) {
$this->widget('Widget_Notice')->set($result, NULL, 'notice');
$this->widget('Widget_Notice')->set($result, 'notice');
} else {
$this->widget('Widget_Notice')->set(_t('插件已经被启用'), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('插件已经被启用'), 'success');
}
$this->response->goBack();
}
@@ -184,7 +184,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
$result = call_user_func(array($className, 'deactivate'));
} catch (Typecho_Plugin_Exception $e) {
/** 截获异常 */
$this->widget('Widget_Notice')->set($e->getMessage(), NULL, 'error');
$this->widget('Widget_Notice')->set($e->getMessage(), 'error');
$this->response->goBack();
}
@@ -200,9 +200,9 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
$this->delete($this->db->sql()->where('name = ?', '_plugin:' . $pluginName));
if (isset($result) && is_string($result)) {
$this->widget('Widget_Notice')->set($result, NULL, 'notice');
$this->widget('Widget_Notice')->set($result, 'notice');
} else {
$this->widget('Widget_Notice')->set(_t('插件已经被禁用'), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('插件已经被禁用'), 'success');
}
$this->response->goBack();
}
@@ -232,7 +232,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
$this->widget('Widget_Notice')->highlight('plugin-' . $pluginName);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t("插件设置已经保存"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("插件设置已经保存"), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('plugins.php', $this->options->adminUrl));
+1 -2
View File
@@ -77,8 +77,7 @@ class Widget_Register extends Widget_Abstract_Users implements Widget_Interface_
Typecho_Cookie::delete('__typecho_remember_name');
Typecho_Cookie::delete('__typecho_remember_mail');
$this->widget('Widget_Notice')->set('message',
_t('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $this->screenName, $generatedPassword), 'success');
$this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $this->screenName, $generatedPassword), 'success');
$this->response->goBack();
}
}
+4 -4
View File
@@ -62,7 +62,7 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
}
$this->widget('Widget_Notice')->highlight('theme-' . $theme);
$this->widget('Widget_Notice')->set(_t("外观已经改变"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("外观已经改变"), 'success');
$this->response->goBack();
} else {
throw new Typecho_Widget_Exception(_t('您选择的风格不存在'));
@@ -85,9 +85,9 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
$handle = fopen($path, 'wb');
if ($handle && fwrite($handle, $this->request->content)) {
fclose($handle);
$this->widget('Widget_Notice')->set(_t("文件 %s 的更改已经保存", $file), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("文件 %s 的更改已经保存", $file), 'success');
} else {
$this->widget('Widget_Notice')->set(_t("文件 %s 无法被写入", $file), NULL, 'error');
$this->widget('Widget_Notice')->set(_t("文件 %s 无法被写入", $file), 'error');
}
$this->response->goBack();
} else {
@@ -131,7 +131,7 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
$this->widget('Widget_Notice')->highlight('theme-' . $theme);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t("外观设置已经保存"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("外观设置已经保存"), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('options-theme.php', $this->options->adminUrl));
+2 -2
View File
@@ -84,7 +84,7 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
$message[] = $result;
}
} catch (Typecho_Exception $e) {
$this->widget('Widget_Notice')->set($e->getMessage(), NULL, 'error');
$this->widget('Widget_Notice')->set($e->getMessage(), 'error');
$this->response->goBack();
return;
}
@@ -108,7 +108,7 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
Typecho_Cookie::delete('__typecho_check_version');
$this->widget('Widget_Notice')->set(empty($message) ? _t("升级已经完成") : $message,
NULL, empty($message) ? 'success' : 'notice');
empty($message) ? 'success' : 'notice');
}
/**
+3 -3
View File
@@ -217,7 +217,7 @@ class Widget_Users_Edit extends Widget_Abstract_Users implements Widget_Interfac
$this->widget('Widget_Notice')->highlight('user-' . $user['uid']);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('用户 %s 已经被增加', $user['screenName']), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('用户 %s 已经被增加', $user['screenName']), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('manage-users.php', $this->options->adminUrl));
@@ -251,7 +251,7 @@ class Widget_Users_Edit extends Widget_Abstract_Users implements Widget_Interfac
$this->widget('Widget_Notice')->highlight('user-' . $this->request->uid);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('用户 %s 已经被更新', $user['screenName']), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('用户 %s 已经被更新', $user['screenName']), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('manage-users.php?' .
@@ -282,7 +282,7 @@ class Widget_Users_Edit extends Widget_Abstract_Users implements Widget_Interfac
}
/** 提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('用户已经删除') : _t('没有用户被删除'), NULL,
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('用户已经删除') : _t('没有用户被删除'),
$deleteCount > 0 ? 'success' : 'notice');
/** 转向原页 */
+4 -4
View File
@@ -259,7 +259,7 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
$this->widget('Widget_Notice')->highlight('user-' . $this->user->uid);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('您的档案已经更新'), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('您的档案已经更新'), 'success');
/** 转向原页 */
$this->response->goBack();
@@ -299,7 +299,7 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
}
}
$this->widget('Widget_Notice')->set(_t("设置已经保存"), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
$this->response->goBack();
}
@@ -326,7 +326,7 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
$this->widget('Widget_Notice')->highlight('user-' . $this->user->uid);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('密码已经成功修改'), NULL, 'success');
$this->widget('Widget_Notice')->set(_t('密码已经成功修改'), 'success');
/** 转向原页 */
$this->response->goBack();
@@ -383,7 +383,7 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
}
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t("%s 设置已经保存", $info['title']), NULL, 'success');
$this->widget('Widget_Notice')->set(_t("%s 设置已经保存", $info['title']), 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('profile.php', $this->options->adminUrl));