This commit is contained in:
114
PostsCategoryChange/Action.php
Normal file
114
PostsCategoryChange/Action.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
|
||||
class PostsCategoryChange_Action extends Typecho_Widget implements Widget_Interface_Do
|
||||
{
|
||||
private $db;
|
||||
private $prefix;
|
||||
|
||||
public function action()
|
||||
{
|
||||
$user = Typecho_Widget::widget('Widget_User');
|
||||
$user->pass('administrator');
|
||||
$this->options = Typecho_Widget::widget('Widget_Options');
|
||||
$this->db = Typecho_Db::get();
|
||||
$this->prefix = $this->db->getPrefix();
|
||||
$this->on($this->request->is('do=change-category'))->makeChange();
|
||||
$this->on($this->request->is('do=change-status'))->changeStatus();
|
||||
exit;
|
||||
}
|
||||
|
||||
public function makeChange()
|
||||
{
|
||||
$cids = $this->request->filter('int')->getArray('cid');
|
||||
$mid = $this->request->filter('int')->get('mid');
|
||||
if(empty($cids)) {
|
||||
echo json_encode(['code'=>-1,'msg'=>'大佬,至少选择一篇文章!']);
|
||||
return;
|
||||
} else if(empty($mid)) {
|
||||
echo json_encode(['code'=>-1,'msg'=>'大佬,请选择一个分类!']);
|
||||
return;
|
||||
} else {
|
||||
$cid = implode(',',$cids);
|
||||
$select = 'SELECT cid FROM '.$this->prefix.'contents where cid in('.$cid.') and type="post"';
|
||||
$res = $this->db->fetchAll($this->db->query($select));
|
||||
if(empty($res)) {
|
||||
echo json_encode(['code'=>-1,'msg'=>'f**k,别特么瞎jb搞!']);
|
||||
return;
|
||||
} else {
|
||||
$post_cid = '';
|
||||
foreach ($res as $value) {
|
||||
$post_cid .= $value['cid'].',';
|
||||
}
|
||||
$post_cid = trim($post_cid,',');
|
||||
|
||||
$select = 'SELECT mid,type FROM '.$this->prefix.'metas where type="category"';
|
||||
|
||||
$res = $this->db->fetchAll($this->db->query($select));
|
||||
|
||||
$category_mid = '';
|
||||
foreach ($res as $value) {
|
||||
$category_mid .= $value['mid'].',';
|
||||
}
|
||||
$category_mid = trim($category_mid,',');
|
||||
|
||||
$res = $this->db->fetchAll($this->db->query($select));
|
||||
|
||||
$update = $this->db->update($this->prefix.'relationships')->rows(array('mid'=>$mid))->where('cid in ('.$post_cid.') AND mid IN ('.$category_mid.')');
|
||||
$row = @$this->db->query($update);
|
||||
if($row) {
|
||||
echo json_encode(['code'=>1,'msg'=>'本次成功更新'.$row.'篇文章!']);
|
||||
return;
|
||||
} else {
|
||||
echo json_encode(['code'=>-1,'msg'=>'更新失败']);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function changeStatus()
|
||||
{
|
||||
$cids = $this->request->filter('int')->getArray('cid');
|
||||
$status = $this->request->filter('int')->get('status');
|
||||
if(empty($cids)) {
|
||||
echo json_encode(['code'=>-1,'msg'=>'大佬,至少选择一篇文章!']);
|
||||
return;
|
||||
} else if(empty($status)) {
|
||||
echo json_encode(['code'=>-1,'msg'=>'大佬,请选择一个文章状态!']);
|
||||
return;
|
||||
} else {
|
||||
$status_arr = [
|
||||
'1'=>'publish',
|
||||
'2'=>'hidden',
|
||||
'3'=>'private'
|
||||
];
|
||||
if(!array_key_exists($status,$status_arr)) {
|
||||
echo json_encode(['code'=>-1,'msg'=>'f**k,别特么瞎jb搞!']);
|
||||
return ;
|
||||
} else {
|
||||
$status = $status_arr[$status];
|
||||
}
|
||||
$cid = implode(',',$cids);
|
||||
$select = 'SELECT cid,status FROM '.$this->prefix.'contents where cid in('.$cid.') and type="post"';
|
||||
$res = $this->db->fetchAll($this->db->query($select));
|
||||
if(empty($res)) {
|
||||
echo json_encode(['code'=>-1,'msg'=>'f**k,别特么瞎jb搞!']);
|
||||
return;
|
||||
} else {
|
||||
$count = 0;
|
||||
foreach ($res as $value) {
|
||||
$update = $this->db->update($this->prefix.'contents')->rows(array('status'=>$status))->where('cid in ('.$value['cid'].')');
|
||||
@$this->db->query($update) && $count ++;
|
||||
}
|
||||
if($count>0) {
|
||||
echo json_encode(['code'=>1,'msg'=>'本次成功更新'.$count.'篇文章!']);
|
||||
return;
|
||||
} else {
|
||||
echo json_encode(['code'=>-1,'msg'=>'更新失败']);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
PostsCategoryChange/LICENSE
Normal file
21
PostsCategoryChange/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 fuzqing
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
245
PostsCategoryChange/Plugin.php
Normal file
245
PostsCategoryChange/Plugin.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 批量更改文章分类、状态(公开|隐藏|私密)
|
||||
*
|
||||
* @package PostsCategoryChange
|
||||
* @author Fuzqing
|
||||
* @version 0.0.4
|
||||
* @link https://huangweitong.com
|
||||
*/
|
||||
class PostsCategoryChange_Plugin implements Typecho_Plugin_Interface
|
||||
{
|
||||
/**
|
||||
* 插件版本号
|
||||
* @var string
|
||||
*/
|
||||
const _VERSION = '0.0.4';
|
||||
/**
|
||||
* 激活插件方法,如果激活失败,直接抛出异常
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function activate()
|
||||
{
|
||||
Helper::addAction('imanage-posts', 'PostsCategoryChange_Action');
|
||||
Typecho_Plugin::factory('admin/footer.php')->end = array(__CLASS__, 'render');
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用插件方法,如果禁用失败,直接抛出异常
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function deactivate()
|
||||
{
|
||||
Helper::removeAction('imanage-posts');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form 配置面板
|
||||
* @return void
|
||||
*/
|
||||
public static function config(Typecho_Widget_Helper_Form $form){}
|
||||
|
||||
/**
|
||||
* 个人用户的配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form
|
||||
* @return void
|
||||
*/
|
||||
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
|
||||
|
||||
/**
|
||||
* 插件实现方法
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public static function render()
|
||||
{
|
||||
$url = $_SERVER['REQUEST_URI'];
|
||||
$filename = substr( $url , strrpos($url , '/')+1);
|
||||
if (empty($filename) || strpos($filename,'manage-posts.php') === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Typecho_Db::get();
|
||||
|
||||
$prefix = $db->getPrefix();
|
||||
|
||||
$options = Typecho_Widget::widget('Widget_Options');
|
||||
|
||||
$category_list = $db->fetchAll($db->select()->from($prefix.'metas')->where('type = ?', 'category'));
|
||||
//批量更改文章分类接收的action地址
|
||||
$makeChange_url = Typecho_Common::url('/index.php/action/imanage-posts?do=change-category', $options->siteUrl);
|
||||
//批量更改文章分类接收的action地址
|
||||
$changeStatus_url = Typecho_Common::url('/index.php/action/imanage-posts?do=change-status', $options->siteUrl);
|
||||
|
||||
$category_html = '<select name="icategory" id="category" style="width: 100%">';
|
||||
|
||||
$category_html .= '<option value="0">请选择一个分类</option>';
|
||||
|
||||
foreach ($category_list as $category) {
|
||||
|
||||
$category_html .= "<option value=\"{$category['mid']}\">{$category['name']}</option>";
|
||||
|
||||
}
|
||||
$category_html .= '</select>';
|
||||
|
||||
$status_html = '<select name="status" id="status" style="width: 100%">';
|
||||
$status_html .= '<option value="0">请选择文章状态</option>';
|
||||
$status_html .= '<option value="1">公开</option>';
|
||||
$status_html .= '<option value="2">隐藏</option>';
|
||||
$status_html .= '<option value="3">私密</option>';
|
||||
$status_html .= '</select>';
|
||||
|
||||
$script = <<<SCRIPT
|
||||
<script src="//cdn.bootcss.com/layer/3.1.0/layer.js"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
var html = '<li><a id="make-change" href="#">移动</a></li>';
|
||||
|
||||
html += '<li><a id="change-status" href="#">公开|隐藏|私密</a></li>';
|
||||
|
||||
$(".dropdown-menu").append(html);
|
||||
|
||||
$("#make-change").click(function() {
|
||||
|
||||
var params = $("form[name='manage_posts']").serialize();
|
||||
|
||||
if(!params) {
|
||||
layer.msg('至少选择一篇文章', function(){});
|
||||
return false;
|
||||
} else {
|
||||
mid = 0;
|
||||
layer.open({
|
||||
type: 1,
|
||||
title:'移动到',
|
||||
closeBtn: 0,
|
||||
shadeClose: true,
|
||||
btn: ['确定', '取消'],
|
||||
content: '{$category_html}',
|
||||
yes:function(index, layero) {
|
||||
layer.close(index);
|
||||
if(mid == undefined || mid == 0) {
|
||||
layer.msg('请选择分类', function(){});
|
||||
return false;
|
||||
} else {
|
||||
params = params + '&mid=' + mid;
|
||||
var load_index = layer.load(2, {time: 10*1000});
|
||||
$.post("{$makeChange_url}", params,function(data) {
|
||||
layer.close(load_index);
|
||||
if(data.code== -1) {
|
||||
layer.msg(data.msg, function(){});
|
||||
} else if(data.code == 1) {
|
||||
layer.msg(data.msg, function(){
|
||||
window.location.reload();
|
||||
});
|
||||
} else {
|
||||
console.log(data);
|
||||
}
|
||||
},"json");
|
||||
}
|
||||
},
|
||||
cancel: function(index, layero){
|
||||
|
||||
mid = 0;
|
||||
|
||||
layer.close(index)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
$("#category").change(function(){
|
||||
mid = $("#category").val();
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
$("#change-status").click(function() {
|
||||
var params = $("form[name='manage_posts']").serialize();
|
||||
if(!params) {
|
||||
layer.msg('至少选择一篇文章', function(){});
|
||||
return false;
|
||||
} else {
|
||||
status = 0;
|
||||
layer.open({
|
||||
type: 1,
|
||||
title:'设置文章状态',
|
||||
closeBtn: 0,
|
||||
shadeClose: true,
|
||||
btn: ['确定', '取消'],
|
||||
content: '{$status_html}',
|
||||
yes:function(index, layero) {
|
||||
layer.close(index);
|
||||
if(status == undefined || status == 0) {
|
||||
layer.msg('请选择状态', function(){});
|
||||
return false;
|
||||
} else {
|
||||
params = params + '&status=' + status;
|
||||
var load_index = layer.load(2, {time: 10*1000});
|
||||
$.post("{$changeStatus_url}", params,function(data) {
|
||||
layer.close(load_index);
|
||||
if(data.code== -1) {
|
||||
layer.msg(data.msg, function(){});
|
||||
} else if(data.code == 1) {
|
||||
layer.msg(data.msg, function(){
|
||||
window.location.reload();
|
||||
});
|
||||
} else {
|
||||
console.log(data);
|
||||
}
|
||||
},"json");
|
||||
}
|
||||
},
|
||||
cancel: function(index, layero){
|
||||
|
||||
status = 0;
|
||||
|
||||
layer.close(index)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
$("#status").change(function(){
|
||||
status = $("#status").val();
|
||||
});
|
||||
/**
|
||||
var load_index = layer.load(2, {time: 10*1000});
|
||||
$.post("{$changeStatus_url}", params,function(data) {
|
||||
layer.close(load_index);
|
||||
if(data.code== -1) {
|
||||
layer.msg(data.msg, function(){});
|
||||
} else if(data.code == 1) {
|
||||
layer.msg(data.msg, function() {
|
||||
window.location.reload();
|
||||
});
|
||||
} else {
|
||||
console.log(data);
|
||||
}
|
||||
},"json");
|
||||
*/
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
SCRIPT;
|
||||
echo $script;
|
||||
}
|
||||
|
||||
}
|
||||
39
PostsCategoryChange/README.md
Normal file
39
PostsCategoryChange/README.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Typecho 批量更改文章分类状态插件 PostsCategoryChange
|
||||
|
||||
## 插件简介
|
||||
|
||||
批量更新文章分类、状态(公开|隐藏|私密)
|
||||
|
||||
## 注意(灰常重要)
|
||||
|
||||
* 在批量更新文章分类的时候,请先确认**被操作的文章是否都只有一个分类。**
|
||||
* 如果有个别文章存在多个分类的请手工修改分类,不要使用本插件。
|
||||
|
||||
## 安装方法
|
||||
|
||||
* 至[releases](https://github.com/fuzqing/PostsCategoryChange/releases)中下载最新版本插件;
|
||||
* 将下载的压缩包进行解压,文件夹重命名为`PostsCategoryChange`,上传至`Typecho`插件目录中;
|
||||
* 后台激活插件。
|
||||
|
||||
## 使用方法
|
||||
|
||||
* 到文章管理界面选择你要修改分类的文章 -> 选中项 -> 移动 -> 选择一个分类。
|
||||

|
||||
* 到文章管理界面选择你要修改分类的文章 -> 选中项 -> 设置状态
|
||||

|
||||
|
||||
## 更新日志
|
||||
|
||||
### 2018.7.6
|
||||
|
||||
* 增加批量修改文章状态为私密(蜜汁尴尬,之前不知道有这个状态,没注意)
|
||||
|
||||
### 2018.7.3
|
||||
|
||||
* 修复了在后台首页waring的报错
|
||||
|
||||
### 2018.6.22
|
||||
|
||||
* 更新了批量修改文章状态(公开|隐藏|私密)
|
||||
* 不用增加钩子也能用了 By benzBrake
|
||||
|
||||
Reference in New Issue
Block a user