Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kraity committed Jul 12, 2021
1 parent 8484309 commit fd00141
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 75 deletions.
82 changes: 32 additions & 50 deletions Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Dynamics_Action extends Dynamics_Abstract implements Widget_Interface_Do
* @return mixed
* @throws Typecho_Db_Exception
*/
public static function dynamicsAdd($uid, $dynamic)
public static function insertOf($uid, $dynamic)
{
$db = Typecho_Db::get();
$dynamic['authorId'] = $uid;
Expand All @@ -30,7 +30,7 @@ public static function dynamicsAdd($uid, $dynamic)
* @return mixed
* @throws Typecho_Db_Exception
*/
public static function dynamicsAlter($uid, $dynamic)
public static function modifyOf($uid, $dynamic)
{
$db = Typecho_Db::get();
$dynamic['authorId'] = $uid;
Expand All @@ -50,7 +50,7 @@ public static function dynamicsAlter($uid, $dynamic)
* @return int
* @throws Typecho_Db_Exception
*/
public static function dynamicsRemove($uid, $list)
public static function deleteOf($uid, $list)
{
$db = Typecho_Db::get();
$deleteCount = 0;
Expand All @@ -75,37 +75,38 @@ public static function dynamicsRemove($uid, $list)
* @throws Typecho_Db_Exception
* @throws Typecho_Exception
*/
public static function dynamicsGain($uid, $status = null, $pageSize = 10, $currentPage = 1)
public static function selectOf($uid, $status = null, $pageSize = 10, $currentPage = 1)
{
$db = Typecho_Db::get();
$select = $db->select()->from('table.dynamics')
->where('authorId = ?', $uid);

if (isset($status) && $status != "all") {
if (isset($status) && $status != 'total') {
$select->where('status = ?', $status);
}

$select->order('created', Typecho_Db::SORT_DESC)
->page($currentPage, $pageSize);

$dynamicRough = $db->fetchAll($select);
$list = [];

$list = [];
$option = Typecho_Widget::widget('Dynamics_Option');

foreach ($dynamicRough as $dynamic) {
$dynamic["title"] = date("m月d日, Y年", $dynamic["created"]);
$dynamic["permalink"] = $option->applyUrl($dynamic["did"]);
$dynamic['title'] = date("m月d日, Y年", $dynamic["created"]);
$dynamic['permalink'] = $option->applyUrl($dynamic["did"]);
$list[] = $dynamic;
}

return $list;
}

/**
* 新增
* @throws Typecho_Db_Exception|Typecho_Exception
*/
public function addDynamics()
public function addOf()
{
if (!$this->hasLogin) {
$this->error('请登录后台后重试');
Expand All @@ -116,7 +117,7 @@ public function addDynamics()
$dynamic['created'] = $date;

/** 插入数据 */
$result = Dynamics_Action::dynamicsAdd($this->user->uid, $dynamic);
$result = Dynamics_Action::insertOf($this->user->uid, $dynamic);
$this->success($this->filterParam($result));
}

Expand All @@ -125,7 +126,7 @@ public function addDynamics()
*
* @throws Typecho_Db_Exception|Typecho_Exception
*/
public function saveDynamics()
public function saveOf()
{
if (!$this->hasLogin) {
$this->error('请登录后台后重试');
Expand All @@ -136,27 +137,27 @@ public function saveDynamics()
];

/** 保存数据 */
$result = Dynamics_Action::dynamicsAlter($this->user->uid, $dynamic);
$result = Dynamics_Action::modifyOf($this->user->uid, $dynamic);
$this->success($this->filterParam($result));
}

/**
* 列表
* @throws Typecho_Exception
*/
public function listDynamics()
public function listOf()
{
if (!$this->hasLogin) {
$this->error('请登录后台后重试');
}
$lastid = $this->request->get('lastdid', 0);
$lid = $this->request->get('lastDid', 0);
$size = 10;
$select = $this->db->select('table.dynamics.*, table.users.screenName author_name')
->from('table.dynamics')
->join('table.users', 'table.dynamics.authorId = table.users.uid')
->where('uid = ?', $this->user->uid);
if ($lastid) {
$select->where('table.dynamics.did < ? ', $lastid);
if ($lid) {
$select->where('table.dynamics.did < ? ', $lid);
}
$select->order('table.dynamics.did', Typecho_Db::SORT_DESC)->limit($size);
$data = $this->db->fetchAll($select);
Expand All @@ -172,7 +173,7 @@ public function listDynamics()
/**
* 删除
*/
public function deleteDynamics()
public function removeOf()
{
if (!$this->hasLogin) {
$this->error('请登录后台后重试');
Expand Down Expand Up @@ -250,7 +251,7 @@ public function configTheme()
$isExists = false;
if (file_exists($configFile)) {
require_once $configFile;
if (function_exists('themeConfig')) {
if (function_exists('_themeConfig')) {
$isExists = true;
}
}
Expand All @@ -261,7 +262,7 @@ public function configTheme()

// 已经载入了外观函数
$form = new Typecho_Widget_Helper_Form(NULL, Typecho_Widget_Helper_Form::POST_METHOD);
themeConfig($form);
_themeConfig($form);

/** 验证表单 */
if ($form->validate()) {
Expand Down Expand Up @@ -320,49 +321,30 @@ private function success($data = [], $message = '')
*/
private function filterParam($dynamic)
{
$statusName = "";
if ($dynamic["status"] == "private") {
$statusName = "[私密] ";
} else if ($dynamic["status"] == "hidden") {
$statusName = "[隐藏] ";
$statusName = '';
if ($dynamic["status"] == 'private') {
$statusName = '[私密] ';
} else if ($dynamic["status"] == 'hidden') {
$statusName = '[隐藏] ';
}

$option = Typecho_Widget::widget('Dynamics_Option');

$dynamic["title"] = $statusName . date("m月d日, Y年", $dynamic["created"]);
$dynamic["url"] = $option->applyUrl($dynamic["did"]);
$dynamic["desc"] = mb_substr(strip_tags($dynamic["text"]), 0, 20, 'utf-8');
$dynamic['title'] = $statusName . date("m月d日, Y年", $dynamic["created"]);
$dynamic['url'] = $option->applyUrl($dynamic["did"]);
$dynamic['desc'] = mb_substr(strip_tags($dynamic["text"]), 0, 20, 'utf-8');
return $dynamic;
}

/**
* Dynamics_Action::getDynamics()
* 弃用
*/
public static function getDynamics()
{
return null;
}

/**
* Dynamics_Action::getDynamic()
* 弃用
*
*/
public static function getDynamic()
{
return null;
}

/**
* 行动
*/
public function action()
{
$this->on($this->request->is('do=addDynamics'))->addDynamics();
$this->on($this->request->is('do=saveDynamics'))->saveDynamics();
$this->on($this->request->is('do=listDynamics'))->listDynamics();
$this->on($this->request->is('do=deleteDynamics'))->deleteDynamics();
$this->on($this->request->is('do=add'))->addOf();
$this->on($this->request->is('do=save'))->saveOf();
$this->on($this->request->is('do=list'))->listOf();
$this->on($this->request->is('do=remove'))->removeOf();

$this->on($this->request->is('do=changeTheme'))->changeTheme($this->request->filter('slug')->change);
$this->on($this->request->is('do=editorTheme'))
Expand Down
14 changes: 7 additions & 7 deletions Manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function initMarkdown() {
});

$(document).on('click', '#dynamic-btn-box .adds', function () {
$.get('<?php Helper::options()->index("action/dynamics?do=addDynamics");?>', {}, function (data) {
$.get('<?php Helper::options()->index("action/dynamics?do=add");?>', {}, function (data) {
if (data.result) {
notedata['key_' + data.data.did] = data.data;

Expand Down Expand Up @@ -529,7 +529,7 @@ function initMarkdown() {

$(document).on('click', '#dynamic-btn-box .save', function () {
if (selectId) {
$.get('<?php Helper::options()->index("action/dynamics?do=saveDynamics");?>', {
$.get('<?php Helper::options()->index("action/dynamics?do=save");?>', {
did: selectId,
title: $('.dynamic-right .title').val(),
text: $('#text').val(),
Expand All @@ -548,7 +548,7 @@ function initMarkdown() {
$(document).on('click', '#dynamic-btn-box .delete', function () {
if (confirm('确定删除该动态')) {
if (selectId) {
$.get('<?php Helper::options()->index("action/dynamics?do=deleteDynamics");?>', {
$.get('<?php Helper::options()->index("action/dynamics?do=remove");?>', {
did: selectId
}, function (data) {
if (data.result) {
Expand All @@ -570,13 +570,13 @@ function initMarkdown() {
}
});

var lastdid = 0;
var lastDid = 0;
var selectId = 0;
var notedata = [];

function loadDynamics() {
$.get('<?php Helper::options()->index("action/dynamics?do=listDynamics");?>', {
lastdid: lastdid
$.get('<?php Helper::options()->index("action/dynamics?do=list");?>', {
lastDid: lastDid
}, function (data) {
if (data.result) {
var len = data.data.length;
Expand All @@ -585,7 +585,7 @@ function loadDynamics() {
$('.dynamic-left .dynamic-loadmore').hide();
$('.dynamic-left .dynamic-nomore').show();
} else {
lastdid = data.data[len - 1].did;
lastDid = data.data[len - 1].did;
var note_item_tpl = '';
for (var i = 0; i < len; i++) {
notedata['key_' + data.data[i].did] = data.data[i];
Expand Down
6 changes: 4 additions & 2 deletions Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public function __construct($request, $response, $params = NULL)
parent::__construct($request, $response, $params);
$this->options = $this->widget('Widget_Options');

$config = unserialize($this->options->{"plugin:Dynamics"});
$config = array_merge($config, unserialize($config['themeConfig']));
$config = unserialize($this->options->{'plugin:Dynamics'});
if (is_array($themeConfig = unserialize($config['themeConfig']))) {
$config = array_merge($config, $themeConfig);
}
unset($config['themeConfig']);
foreach ($config as $name => $value) {
$this->{$name} = $value;
Expand Down
19 changes: 7 additions & 12 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* 我的动态 - 南博助手
* @package Dynamics
* @author 权那他,尚寂新
* @version 2.0
* @author 陆之岇,尚寂新
* @version 2.0.1
* @link https://github.com/krait-team/Dynamics-typecho
*/
class Dynamics_Plugin implements Typecho_Plugin_Interface
Expand All @@ -21,7 +21,7 @@ class Dynamics_Plugin implements Typecho_Plugin_Interface
public static function activate()
{
$packageName = basename(dirname(__FILE__));
if ($packageName != "Dynamics") {
if ($packageName != 'Dynamics') {
throw new Typecho_Plugin_Exception(_t('插件目录名必须为 Dynamics'));
}

Expand Down Expand Up @@ -68,15 +68,10 @@ public static function activate()
throw new Typecho_Plugin_Exception(_t('你的适配器为%s,目前只支持Mysql和SQLite', $adapterName));
}

Typecho_Plugin::factory('Widget_XmlRpc')->dynamicsAdd = ['Dynamics_Action', 'dynamicsAdd'];
Typecho_Plugin::factory('Widget_XmlRpc')->dynamicsAlter = ['Dynamics_Action', 'dynamicsAlter'];
Typecho_Plugin::factory('Widget_XmlRpc')->dynamicsRemove = ['Dynamics_Action', 'dynamicsRemove'];
Typecho_Plugin::factory('Widget_XmlRpc')->dynamicsGain = ['Dynamics_Action', 'dynamicsGain'];

Typecho_Plugin::factory('Nabo_XmlRpc')->dynamicsAdd = ['Dynamics_Action', 'dynamicsAdd'];
Typecho_Plugin::factory('Nabo_XmlRpc')->dynamicsAlter = ['Dynamics_Action', 'dynamicsAlter'];
Typecho_Plugin::factory('Nabo_XmlRpc')->dynamicsRemove = ['Dynamics_Action', 'dynamicsRemove'];
Typecho_Plugin::factory('Nabo_XmlRpc')->dynamicsGain = ['Dynamics_Action', 'dynamicsGain'];
Typecho_Plugin::factory('Nabo_Dynamics')->insert = ['Dynamics_Action', 'insertOf'];
Typecho_Plugin::factory('Nabo_Dynamics')->modify = ['Dynamics_Action', 'modifyOf'];
Typecho_Plugin::factory('Nabo_Dynamics')->delete = ['Dynamics_Action', 'deleteOf'];
Typecho_Plugin::factory('Nabo_Dynamics')->select = ['Dynamics_Action', 'selectOf'];

Helper::addPanel(3, 'Dynamics/Manage.php', '我的动态', '动态列表', 'administrator');
Helper::addPanel(1, 'Dynamics/Themes.php', '动态外观', '动态主题列表', 'administrator');
Expand Down
2 changes: 1 addition & 1 deletion themes/AlphaPure/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 主题配置
* @param $form
*/
function themeConfig($form)
function _themeConfig($form)
{
$radio = new Typecho_Widget_Helper_Form_Element_Text(
'timeFormat', null, 'n\月j\日,Y H:i:s',
Expand Down
4 changes: 2 additions & 2 deletions themes/default/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* 主题配置
* @param $form
*/
function themeConfig($form)
function _themeConfig($form)
{
// 头像图
$logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL, "https://gravatar.loli.net/avatar/4e4559eceb7fbd4bca7925710592b1b9?s=100&r=G&d=mm", _t('头像图'), _t('这里填写 URL 地址,最好能走cdn或者oss,毕竟带宽小'));
$form->addInput($logoUrl);

// 你的名字
$yourName = new Typecho_Widget_Helper_Form_Element_Text('yourName', NULL, "权那他", _t('你的名字'), _t('在左上角头向下面,太长会自动...省略'));
$yourName = new Typecho_Widget_Helper_Form_Element_Text('yourName', NULL, "陆之岇", _t('你的名字'), _t('在左上角头向下面,太长会自动...省略'));
$form->addInput($yourName);

// 座右铭好
Expand Down
2 changes: 1 addition & 1 deletion themes/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*
* @package default
* @author 权那他
* @author 陆之岇
* @version 1.2
* @dependence Dynamics
* @link https://github.com/krait-team/Dynamics-typecho
Expand Down

0 comments on commit fd00141

Please sign in to comment.