Skip to content

Commit

Permalink
fix bugs and upgrade to v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Saturn committed Apr 18, 2010
1 parent 1725cb8 commit b0a18f8
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 67 deletions.
2 changes: 1 addition & 1 deletion application/config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
define('ST_DB_CACHE_DIR', 'dbcache');
define('ST_NAME', 'STBlog');
define('ST_SALT_LENGTH', 9);
define('ST_VERSION', '0.1.1');
define('ST_VERSION', '0.1.2');
define('ST_AUTHOR', 'Saturn');
define('ST_AUTHOR_URL', 'http://www.cnsaturn.com/');
define('ST_CONTENT_BREAK', '[--break--]');
Expand Down
5 changes: 4 additions & 1 deletion application/controllers/admin/medias.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,12 @@ public function _exec_delete($pid)
@unlink($info['path']);

$this->posts_mdl->remove_post($pid);

//fix issue 3#2
return TRUE;
}

return TRUE;
return FALSE;
}

/**
Expand Down
72 changes: 70 additions & 2 deletions application/controllers/admin/posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,82 @@ public function write()
is_numeric($pid)?$this->_edit($pid):show_error('禁止访问:危险操作');
}
}

/**
* 批量操作文章
*
* @access private
* @return void
*/
public function operate()
{
/** 尝试get获取数据 */
$action = $this->input->post('do',TRUE);

switch($action)
{
case 'delete':
$this->_remove();
break;
case 'approved':
$this->_approved();
break;
default:
show_404();
break;
}
}

/**
* 批量审核文章
*
* @access private
* @return void
*/
private function _approved()
{
$posts = $this->input->post('pid',TRUE);
$approved = 0;

if($posts && is_array($posts))
{
foreach($posts as $post)
{
if(empty($post))
{
continue;
}

$content = $this->posts_mdl->get_post_by_id('pid', $post);

if($content && $this->auth->exceed('editor', TRUE))
{
if($this->posts_mdl->update_post($post, array('status' => 'publish')))
{
$approved++;
}
}

$content = NULL;
}

}

($approved > 0)
?$this->session->set_flashdata('success', '成功审核文章')
:$this->session->set_flashdata('error', '没有文章被审核');

go_back();

}

/**
* 批量删除文章
*
* @access public
* @access private
* @return void
*/
public function remove()
private function _remove()
{
$posts = $this->input->post('pid',TRUE);
$deleted = 0;
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function _add_user()
'password' => $this->input->post('password',TRUE),
'mail' => $this->input->post('mail',TRUE),
'url' => $this->input->post('url',TRUE),
'screenName'=> ($this->input->post('screenName'))?$this->input->post('screenName',TRUE):$this->input->post('name',TRUE),
'screenName'=> ($this->input->post('screenName'))?$this->input->post('screenName',TRUE):$this->input->post('uname',TRUE),
'created' => time(),
'activated' => 0,
'logged' => 0,
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ public function index($page = 1)
/** 分页参数 */
$this->_init_pagination($page);

$this->_posts = $this->posts_mdl->get_posts('post', 'published', NULL, $this->_limit, $this->_offset)->result();
$this->_total_count = $this->posts_mdl->get_posts('post', 'published', NULL, 10000, 0)->num_rows();
$this->_posts = $this->posts_mdl->get_posts('post', 'publish', NULL, $this->_limit, $this->_offset)->result();
$this->_total_count = $this->posts_mdl->get_posts('post', 'publish', NULL, 10000, 0)->num_rows();

if(!empty($this->_posts))
{
Expand Down
97 changes: 55 additions & 42 deletions application/libraries/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,50 +459,63 @@ public static function gravatar($email, $rating = 'X', $size = '80', $default =
*/
public static function dateWord($from, $now)
{
$between = $now - $from;

/** 如果是一天 */
if ($between < 86400 && idate('d', $from) == idate('d', $now))
{
/** 如果是一小时 */
if ($between < 3600 && idate('H', $from) == idate('H', $now))
{
/** 如果是一分钟 */
if ($between < 60 && idate('i', $from) == idate('i', $now))
{
$second = idate('s', $now) - idate('s', $from);
return sprintf('%d秒前',$second);
}

$min = idate('i', $now) - idate('i', $from);
return sprintf('%d分钟前', $min);
}

$hour = idate('H', $now) - idate('H', $from);
return sprintf( '%d小时前',$hour);
}

/** 如果是昨天 */
if ($between < 172800 && (idate('z', $from) + 1 == idate('z', $now) || idate('z', $from) > 2 + idate('z', $now)))
{
return sprintf('昨天 %s', date('H:i', $from));
}
//fix issue 3#6 by saturn, solution by zycbob

/** 如果是一个星期 */
if ($between < 604800 && idate('W', $from) == idate('W', $now))
{
$day = intval($between / (3600 * 24));
return sprintf('%d天前', $day);
}

/** 如果是一年内 */
if ($between < 31622400 && idate('Y', $from) == idate('Y', $now))
{
return date('n月j日', $from);
}
/** 如果不是同一年 */
if (idate('Y', $now) != idate('Y', $from))
{
return date('Y年m月d日', $from);
}

/**其他**/
return date('Y年m月d日', $from);
/** 以下操作同一年的日期 */
$seconds = $now - $from;
$days = idate('z', $now) - idate('z', $from);

/** 如果是同一天 */
if ($days == 0)
{
/** 如果是一小时内 */
if ($seconds < 3600)
{
/** 如果是一分钟内 */
if ($seconds < 60)
{
if (3 > $seconds)
{
return '刚刚';
}
else
{
return sprintf('%d秒前', $seconds);
}
}

return sprintf('%d分钟前', intval($seconds / 60));
}

return sprintf('%d小时前', idate('H', $now) - idate('H', $from));
}

/** 如果是昨天 */
if ($days == 1)
{
return sprintf('昨天 %s', date('H:i', $from));
}

/** 如果是前天 */
if ($days == 2)
{
return sprintf('前天 %s', date('H:i', $from));
}

/** 如果是7天内 */
if ($days < 7)
{
return sprintf('%d天前', $days);
}

/** 超过一周 */
return date('n月j日', $from);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion application/models/users_mdl.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public function check_exist($key = 'name',$value = '', $exclude_uid = 0)
{
if(in_array($key, $this->_unique_key) && !empty($value))
{
$this->db->select('uid')->from(self::TBL_USERS)->where($key, intval($value));
//fix issue 2
$this->db->select('uid')->from(self::TBL_USERS)->where($key, $value);

if(!empty($exclude_uid) && is_numeric($exclude_uid))
{
Expand Down
5 changes: 4 additions & 1 deletion application/views/admin/manage_posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<span class="operate-button typecho-table-select-none">不选</span>&nbsp;&nbsp;&nbsp;
选中项:
<span rel="delete" lang="你确认要删除这些文章吗" class="operate-button operate-delete typecho-table-select-submit">删除</span>
<?php if($this->auth->exceed('editor', true) && 'waiting' == $status): ?>
<span rel="approved" class="operate-button typecho-table-select-submit">通过审核</span>
<?php endif;?>
</p>
<p class="search">
<input type="text" value="请输入关键字" onclick="value='';name='keywords';" />
Expand All @@ -65,7 +68,7 @@
</form>
</div>

<form method="post" name="manage_posts" class="operate-form" action="<?php echo site_url('admin/posts/remove')?>">
<form method="post" name="manage_posts" class="operate-form" action="<?php echo site_url('admin/posts/operate')?>">
<table class="typecho-list-table">
<colgroup>
<col width="25"/>
Expand Down
6 changes: 3 additions & 3 deletions application/views/admin/metas_cate_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<label class="typecho-label" for="name-0-1">
分类名称*</label>
<?php echo form_error('name', '<p class="message error">', '</p>'); ?>
<input id="name-0-1" name="name" type="text" class="text" value="<?php echo set_value('name',(isset($name))?$name:''); ?>"/>
<input id="name-0-1" name="name" type="text" class="text" value="<?php echo set_value('name',(isset($name))?htmlspecialchars_decode($name):''); ?>"/>
</li>
</ul>
<ul class="typecho-option" id="typecho-option-item-slug-1">
<li>
<label class="typecho-label" for="slug-0-2">
分类缩略名</label>
<?php echo form_error('slug', '<p class="message error">', '</p>'); ?>
<input id="slug-0-2" name="slug" type="text" class="text" value="<?php echo set_value('slug',(isset($slug))?$slug:''); ?>"/>
<input id="slug-0-2" name="slug" type="text" class="text" value="<?php echo set_value('slug',(isset($slug))?htmlspecialchars_decode($slug):''); ?>"/>
<p class="description">
分类缩略名用于创建友好的链接形式,建议使用字母,数字,下划线和横杠.</p>
</li>
Expand All @@ -23,7 +23,7 @@

分类描述</label>
<?php echo form_error('description', '<p class="message error">', '</p>'); ?>
<textarea id="description-0-3" name="description"><?php echo set_value('description',(isset($description))?$description:''); ?>
<textarea id="description-0-3" name="description"><?php echo set_value('description',(isset($description))?htmlspecialchars_decode($description):''); ?>
</textarea>
<p class="description">
此文字用于描述分类,在有的主题中它会被显示.</p>
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/metas_tag_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<label class="typecho-label" for="name-0-1">
标签名称*</label>
<?php echo form_error('name', '<p class="message error">', '</p>'); ?>
<input id="name-0-1" name="name" type="text" class="text" value="<?php echo set_value('name',(isset($name))?$name:''); ?>"/>
<input id="name-0-1" name="name" type="text" class="text" value="<?php echo set_value('name',(isset($name))?htmlspecialchars_decode($name):''); ?>"/>
<p class="description">

这是标签在站点中显示的名称.可以使用中文,如"地球".</p>
Expand All @@ -15,7 +15,7 @@
<label class="typecho-label" for="slug-0-2">
标签缩略名</label>
<?php echo form_error('name', '<p class="message error">', '</p>'); ?>
<input id="slug-0-2" name="slug" type="text" class="text" value="<?php echo set_value('slug',(isset($slug))?$slug:''); ?>"/>
<input id="slug-0-2" name="slug" type="text" class="text" value="<?php echo set_value('slug',(isset($slug))?htmlspecialchars_decode($slug):''); ?>"/>
<p class="description">
标签缩略名用于创建友好的链接形式,如果留空则默认使用标签名称.</p>
</li>
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/write_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="column-18">
<label for="title" class="typecho-label">标题</label>
<?php echo form_error('title', '<p class="message error">', '</p>'); ?>
<p class="title"><input type="text" id="title" name="title" value="<?php echo set_value('title',(isset($title))?$title:''); ?>" class="text title" /></p>
<p class="title"><input type="text" id="title" name="title" value="<?php echo set_value('title',(isset($title))?htmlspecialchars_decode($title):''); ?>" class="text title" /></p>
<label for="text" class="typecho-label">内容
<!-- 使用wysiwyg编辑器时必需实现此方法 -->
<?php $this->plugin->trigger(ST_CORE_HOOK_EDITOR_INSERT_MORE);?>
Expand Down Expand Up @@ -98,7 +98,7 @@
<li>
<label for="slug" class="typecho-label">缩略名</label>
<?php echo form_error('slug', '<p class="message error">', '</p>'); ?>
<p><input type="text" id="slug" name="slug" value="<?php echo set_value('slug',(isset($slug))?$slug:''); ?>" class="mini" /></p>
<p><input type="text" id="slug" name="slug" value="<?php echo set_value('slug',(isset($slug))?htmlspecialchars_decode($slug):''); ?>" class="mini" /></p>
<p class="description">为这篇日志自定义链接地址, 有利于搜索引擎收录</p>
</li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions application/views/admin/write_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
<div class="column-18">
<label for="title" class="typecho-label">标题</label>
<?php echo form_error('title', '<p class="message error">', '</p>'); ?>
<p class="title"><input type="text" id="title" name="title" value="<?php echo set_value('title',(isset($title))?$title:''); ?>" class="text title" /></p>
<p class="title"><input type="text" id="title" name="title" value="<?php echo set_value('title',(isset($title))? htmlspecialchars_decode($title):''); ?>" class="text title" /></p>
<label for="text" class="typecho-label">内容
<!-- 使用wysiwyg编辑器时必需实现此方法 -->
<?php $this->plugin->trigger(ST_CORE_HOOK_EDITOR_INSERT_MORE);?>
</label>
<?php echo form_error('text', '<p class="message error">', '</p>'); ?>
<p><textarea style="height: 350px" id="text" name="text"><?php echo set_value('text',(isset($text))?$text:''); ?></textarea></p>
<label for="tags" class="typecho-label">标签</label>
<p><input id="tags" name="tags" type="text" value="<?php echo set_value('tags',(isset($tags))?$tags:''); ?>" class="text" /></p>
<p><input id="tags" name="tags" type="text" value="<?php echo set_value('tags',(isset($tags))?htmlspecialchars_decode($tags):''); ?>" class="text" /></p>

<p class="submit">
<span class="left">
Expand Down Expand Up @@ -114,7 +114,7 @@
<li>
<label for="slug" class="typecho-label">缩略名</label>
<?php echo form_error('slug', '<p class="message error">', '</p>'); ?>
<p><input type="text" id="slug" name="slug" value="<?php echo set_value('slug',(isset($slug))?$slug:''); ?>" class="mini" /></p>
<p><input type="text" id="slug" name="slug" value="<?php echo set_value('slug',(isset($slug))?htmlspecialchars_decode($slug):''); ?>" class="mini" /></p>
<p class="description">为这篇日志自定义链接地址, 有利于搜索引擎收录</p>
</li>
</ul>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions themes/default/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ function ReImgSize()
//IE
if(document.all)
{
if (document.images[i].width>600)
if (document.images[i].width>550)
{
document.images[i].width="600"
document.images[i].width="550"
try
{
document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
Expand All @@ -19,9 +19,9 @@ function ReImgSize()
//safari && opera && firefox
else
{
if (document.images[i].width>600)
if (document.images[i].width>550)
{
document.images[i].width="600"
document.images[i].width="500"
document.images[i].title="在新窗口打开图片"
document.images[i].style.cursor="pointer"
document.images[i].onclick=function(e){window.open(this.src)}
Expand Down
Loading

1 comment on commit b0a18f8

@fredwu
Copy link

@fredwu fredwu commented on b0a18f8 Apr 18, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我建议将来commit时,尽量把不同的commit分开。这样便于管理,有问题时revert起来更容易。:)

Please sign in to comment.