Skip to content

Commit

Permalink
update configuration and management
Browse files Browse the repository at this point in the history
  • Loading branch information
kraity committed Aug 12, 2021
1 parent 810254b commit f96eb7c
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 426 deletions.
82 changes: 80 additions & 2 deletions Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function ___deviceTag()
if (preg_match('/Nabo\/([^\s|;]+)/i', $this->agent, $regs)) {
return '南博 ' . $regs[1];
}
return $this->deviceInfo();
return $this->deviceInfo;
}

/**
Expand All @@ -184,7 +184,7 @@ public function ___deviceInfo()
if (preg_match('/\(.*;\s(.*)\sBuild.*\)/i', $this->agent, $regs)) {
return $regs[1];
}
return $this->deviceOs();
return $this->deviceOs;
}

/**
Expand Down Expand Up @@ -214,6 +214,7 @@ public function avatar($size = null, $rating = null, $default = null)

/**
* 动态创建时间
*
* @param null $format
*/
public function date($format = NULL)
Expand All @@ -223,6 +224,7 @@ public function date($format = NULL)

/**
* 动态创建时间
*
* @param null $format
*/
public function created($format = NULL)
Expand All @@ -232,6 +234,7 @@ public function created($format = NULL)

/**
* 动态更新时间
*
* @param null $format
*/
public function modified($format = NULL)
Expand All @@ -253,4 +256,79 @@ public function navigator($prev = '«', $next = '»', $splitPage = 3,
{
$this->archive->pageNav($prev, $next, $splitPage, $splitWord, $template);
}

/**
* @param Widget_Archive $archive
* @param Typecho_Db_Query $select
* @throws Typecho_Db_Exception
* @throws Typecho_Exception
*/
public static function archiveQuery($archive, $select)
{
$db = Typecho_Db::get();
if (strpos($archive->parameter->type, 'index') !== 0) {
$db->fetchAll($select, [$archive, 'push']);
return;
}

$option = Typecho_Widget::widget('Dynamics_Option');
if (empty($option->allowIndex)) {
$db->fetchAll($select, [$archive, 'push']);
return;
}

$dynamicNum = $db->fetchObject($db->select(array('COUNT(DISTINCT table.dynamics.did)' => 'num'))
->from('table.dynamics')
->where('table.dynamics.status = ?', 'publish')
->cleanAttribute('group'))->num;
if (empty($dynamicNum)) {
$db->fetchAll($select, [$archive, 'push']);
return;
}

$dynamicSize = 5;
$archive->parameter->pageSize += $dynamicSize;

$article = $select->prepare($select);
$dynamic = $db->select('table.dynamics.did as cid', 'null as title', 'null as slug', 'table.dynamics.created', 'table.dynamics.authorId',
'table.dynamics.modified', "'dynamic' as type", 'table.dynamics.status', 'table.dynamics.text', '0 as commentsNum', '0 as order',
'null as template', 'null as password', '0 as allowComment', '0 as allowPing', '0 as allowFeed', '0 as parent')
->from('table.dynamics')
->where('table.dynamics.status = ?', 'publish')
->order('table.dynamics.created', Typecho_Db::SORT_DESC)
->page(isset($archive->request->page) ? $archive->request->page : 1, $dynamicSize);
$dynamic = $dynamic->prepare($dynamic);

$articleNum = $db->fetchObject($archive->getCountSql()
->select(array('COUNT(DISTINCT table.contents.cid)' => 'num'))
->from('table.contents')
->cleanAttribute('group'))->num;
$archive->setTotal($articleNum + $dynamicNum);

$tags = array();
$categories = array([
'name' => '动态',
'permalink' => $option->homepage
]);

foreach ($db->fetchAll("($article) UNION ($dynamic) ORDER BY created DESC") as $value) {
if ($value['type'] == 'dynamic') {
$value['title'] = date('m月d日, Y年', $value['created']);
$value['tags'] = &$tags;
$value['categories'] = &$categories;
$value['permalink'] = $option->applyUrl($value['cid']);
$value['isMarkdown'] = true;

$value['date'] = new Typecho_Date($value['created']);
$value['year'] = $value['date']->year;
$value['month'] = $value['date']->month;
$value['day'] = $value['date']->day;

$archive->length++;
$archive->stack[] = $value;
} else {
$archive->push($value);
}
}
}
}
67 changes: 31 additions & 36 deletions Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class Dynamics_Action extends Dynamics_Abstract implements Widget_Interface_Do
{

/**
* 同步附件
*
Expand Down Expand Up @@ -90,10 +89,12 @@ public static function insertOf($uid, $dynamic)
$db = Typecho_Db::get();
$dynamic['authorId'] = $uid;
$dynamic['agent'] = $_SERVER['HTTP_USER_AGENT'];

$dynamic['did'] = $db->query($db
->insert('table.dynamics')
->rows($dynamic));
self::attachOf($dynamic['did'], $dynamic['text']);

return $dynamic;
}

Expand All @@ -110,11 +111,13 @@ public static function modifyOf($uid, $dynamic)
{
$db = Typecho_Db::get();
$dynamic['authorId'] = $uid;

$db->query($db
->update('table.dynamics')
->rows($dynamic)
->where('did = ?', $dynamic['did']));
self::attachOf($dynamic['did'], $dynamic['text']);

return $dynamic;
}

Expand All @@ -132,13 +135,15 @@ public static function deleteOf($uid, $list)
{
$db = Typecho_Db::get();
$deleteCount = 0;

foreach ($list as $did) {
if ($db->query($db->delete('table.dynamics')
->where('authorId', $uid)->where('did = ?', $did))) {
->where('table.dynamics.did = ?', $did))) {
$deleteCount++;
self::unAttachOf($did);
}
self::unAttachOf($did);
}

return $deleteCount;
}

Expand Down Expand Up @@ -166,18 +171,17 @@ public static function selectOf($uid, $status = null, $pageSize = 10, $currentPa
$select->order('created', Typecho_Db::SORT_DESC)
->page($currentPage, $pageSize);

$dynamicRough = $db->fetchAll($select);

$list = [];
$data = $db->fetchAll($select);
$option = Typecho_Widget::widget('Dynamics_Option');

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

return $list;
return $dynamics;
}

/**
Expand All @@ -186,15 +190,14 @@ public static function selectOf($uid, $status = null, $pageSize = 10, $currentPa
*/
public function addOf()
{
if (!$this->widget('Widget_User')->hasLogin()) {
$this->error('请登录后台后重试');
}

$dynamic['text'] = '滴滴打卡';
$dynamic['created'] = $date = time();
$dynamic['modified'] = $date;
$this->user->pass('editor');
$dynamic = array(
'text' => '滴滴打卡',
'created' => $date = time(),
'modified' => $date
);

$dynamic = Dynamics_Action::insertOf($this->user->uid, $dynamic);
$dynamic = self::insertOf($this->user->uid, $dynamic);
$dynamic['nickname'] = $this->user->screenName;

$this->success($this->filterParam($dynamic));
Expand All @@ -207,10 +210,7 @@ public function addOf()
*/
public function saveOf()
{
if (!$this->widget('Widget_User')->hasLogin()) {
$this->error('请登录后台后重试');
}

$this->user->pass('editor');
$dynamic = array(
'did' => $this->request->get('did', 0),
'text' => $this->request->get('text', '')
Expand All @@ -227,19 +227,16 @@ public function saveOf()
*/
public function listOf()
{
if (!$this->widget('Widget_User')->hasLogin()) {
$this->error('请登录后台后重试');
}
$lid = $this->request->get('lastDid', 0);
$size = 10;
$this->user->pass('editor');
$select = $this->db->select('table.dynamics.*, table.users.screenName as nickname')
->from('table.dynamics')
->join('table.users', 'table.dynamics.authorId = table.users.uid')
->where('uid = ?', $this->user->uid);
if ($lid) {
->join('table.users', 'table.dynamics.authorId = table.users.uid');

if ($lid = $this->request->get('lastDid', 0)) {
$select->where('table.dynamics.did < ? ', $lid);
}
$select->order('table.dynamics.did', Typecho_Db::SORT_DESC)->limit($size);

$select->order('table.dynamics.did', Typecho_Db::SORT_DESC)->limit(10);
$data = $this->db->fetchAll($select);

$dynamics = [];
Expand All @@ -256,15 +253,13 @@ public function listOf()
*/
public function removeOf()
{
if (!$this->widget('Widget_User')->hasLogin()) {
$this->error('请登录后台后重试');
}
$did = $this->request->get('did', 0);
if (empty($did)) {
$this->user->pass('editor');

if (empty($did = $this->request->get('did', 0))) {
$this->error('动态不存在');
}

if (self::deleteOf($this->user->uid, [$did])) {
if (self::deleteOf($this->user->uid, array($did))) {
$this->success();
} else {
$this->error('没有可以删除的动态');
Expand Down
9 changes: 0 additions & 9 deletions Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,4 @@ public function ___description()
{
return $this->description ?: $this->options->description;
}

/**
* 弃用
*
*/
public function dispatch()
{
$this->post();
}
}
10 changes: 4 additions & 6 deletions Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ public function __construct($request, $response, $params = NULL)
}

if ($this->followPath) {
$this->themesPath = '/';
$this->themesFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . $this->themesPath;
$this->themesUrl = Typecho_Common::url(__TYPECHO_THEME_DIR__ . "/{$this->themesPath}/", $this->options->index);
$this->themesFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/';
$this->themesUrl = Typecho_Common::url(__TYPECHO_THEME_DIR__ . '/', $this->options->index);
} else {
$this->themesPath = '/Dynamics/themes/';
$this->themesFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . $this->themesPath;
$this->themesUrl = Typecho_Common::url("{$this->themesPath}/", $this->options->pluginUrl);
$this->themesFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/Dynamics/themes/';
$this->themesUrl = Typecho_Common::url('/Dynamics/themes/', $this->options->pluginUrl);
}
$this->homepage = Typecho_Common::url(Dynamics_Plugin::DYNAMICS_ROUTE, $this->options->index);
}
Expand Down
Loading

0 comments on commit f96eb7c

Please sign in to comment.