Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hex-ci committed Sep 4, 2023
2 parents 6c688f7 + 7451f9c commit 79b8d40
Show file tree
Hide file tree
Showing 12 changed files with 2,725 additions and 2,337 deletions.
2 changes: 1 addition & 1 deletion app/Config/MyBB.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MyBB extends BaseConfig
* An array of user names to restrict our search for news articles to.
* This simply helps limit the work to do.
*/
public $newsUsernames = ['ciadmin', 'jlp', 'kilishan', 'Narf'];
public $newsUsernames = ['ciadmin', 'kilishan', 'kenjis', 'MGatner'];

/**
* --------------------------------------------------------------------------
Expand Down
5 changes: 0 additions & 5 deletions app/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@
$routes->get('the-fine-print', 'FinePrint::index');
$routes->get('security-disclosures', 'Disclosures::index');

// Blog
// $routes->get('news', 'Blog::index');
// $routes->get('news/c/(:segment)', 'Blog::category/$1');
// $routes->get('news/(:segment)', 'Blog::post/$1');

// Api
$routes->get('api/get-download-data', 'Api::getDownloadData');
$routes->get('api/get-contributors', 'Api::getContributors');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function up()
{
// fx_threads
$this->forge->addField([
'fid' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'autoincrement' => true],
'tid' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'autoincrement' => true],
'subject' => ['type' => 'varchar', 'constraint' => 255],
'username' => ['type' => 'varchar', 'constraint' => 255],
Expand Down
15 changes: 10 additions & 5 deletions app/Database/Seeds/ForumSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
class ForumSeeder extends Seeder
{
protected $threads = [
['subject' => 'Multi Table Select (Active Records)', 'username' => 'Han Solo', 'lastpost' => '1414737566', 'tid' => '407'],
['subject' => 'unexpected end of file', 'username' => 'Yoda', 'lastpost' => '1414567370', 'tid' => '413'],
['subject' => 'Status Enable & Disable Not Working', 'username' => 'Luke Skywalker', 'lastpost' => '1414567370', 'tid' => '403'],
['subject' => 'waiting for CI3.0 version', 'username' => 'Princess Leia', 'lastpost' => '1414567370', 'tid' => '4'],
['subject' => 'How i can select most common value with codeigniter', 'username' => 'Obi Wan Kenobi', 'lastpost' => '1414567370', 'tid' => '414'],
['subject' => 'Multi Table Select (Active Records)', 'username' => 'Han Solo', 'lastpost' => '1414737566', 'tid' => '407', 'fid' => 1],
['subject' => 'unexpected end of file', 'username' => 'Yoda', 'lastpost' => '1414567370', 'tid' => '408', 'fid' => 1],
['subject' => 'Status Enable & Disable Not Working', 'username' => 'Luke Skywalker', 'lastpost' => '1414567370', 'tid' => '409', 'fid' => 1],
['subject' => 'waiting for CI3.0 version', 'username' => 'Princess Leia', 'lastpost' => '1414567370', 'tid' => '410', 'fid' => 1],
['subject' => 'How i can select most common value with codeigniter', 'username' => 'Obi Wan Kenobi', 'lastpost' => '1414567370', 'tid' => '411', 'fid' => 1],
['subject' => 'CodeIgniter 4.3.7 released', 'username' => 'ciadmin', 'lastpost' => '1414737566', 'tid' => '412', 'fid' => 2],
['subject' => 'CodeIgniter 4.3.6 released', 'username' => 'ciadmin', 'lastpost' => '1414567370', 'tid' => '413', 'fid' => 2],
['subject' => 'Shield Authentication Library', 'username' => 'ciadmin', 'lastpost' => '1414567370', 'tid' => '414', 'fid' => 2],
['subject' => 'Settings Library released', 'username' => 'ciadmin', 'lastpost' => '1414567370', 'tid' => '415', 'fid' => 2],
['subject' => 'Tasks Library released', 'username' => 'ciadmin', 'lastpost' => '1414567370', 'tid' => '416', 'fid' => 2],
];

public function run()
Expand Down
25 changes: 25 additions & 0 deletions app/Libraries/Forums.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,29 @@ public function posts($params = [])

return view('forum/_drats');
}

public function news($params = [])
{
$limit = $params['limit'] ?? $this->limit;

// get the forum posts
if (! $items = cache('bb_news')) {
$items = $this->mybb->getRecentNews($limit);
$ttl = 60 * 60 * 4; // time to live s/b 4 hours
cache()->save('bb_news', $items, $ttl);
}

if (! empty($items) && is_array($items)) {
// massage the date formats
foreach ($items as &$item) {
$item['lastpost'] = date('Y.m.d', $item['lastpost']);
$item['mybb_forum_url'] = $this->forumUrl;
$item['subject'] = strip_tags($item['subject']); // fix #79
}

return view('forum/_posts', ['posts' => $items]);
}

return view('forum/_drats');
}
}
36 changes: 31 additions & 5 deletions app/Models/MyBBModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ class MyBBModel extends Model
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $allowedFields = [
'tid', 'subject', 'username', 'lastpost', 'lastposter', 'visible', 'deletetime',
'fid', 'tid', 'subject', 'username', 'lastpost', 'lastposter', 'visible', 'deletetime',
];

/**
* Grabs the most recently active threads from the forums.
*
* @param int $limit
* @param string $order
*
* @return array|null
*/
public function getRecentPosts($limit = 5, $order = 'desc')
public function getRecentPosts(int $limit = 5, string $order = 'desc')
{
$forumId = config('MyBB')->newsForumId;

$where = [
'visible' => 1,
'deletetime' => 0,
Expand All @@ -39,10 +38,37 @@ public function getRecentPosts($limit = 5, $order = 'desc')
$builder = $this->db->table('fx_threads');
$query = $builder->select('tid, subject, username, lastpost, lastposter')
->where($where)
->where('fid != ' . $forumId)
->limit($limit, 0)
->orderBy('lastpost', $order)
->get();

return $query->getResultArray();
}

/**
* Grabs the most recent announcements from the forums.
*
* @return array
*/
public function getRecentNews(int $limit = 5, string $order = 'desc')
{
$admins = config('MyBB')->newsUsernames;
$forumId = config('MyBB')->newsForumId;

$where = [
'fid' => $forumId,
'visible' => 1,
'deletetime' => 0,
];

$builder = $this->db->table('fx_threads');
$query = $builder->select('tid, subject, username, lastpost, lastposter')
->where($where)
->whereIn('username', $admins)
->orderBy('lastpost', $order)
->get();

return $query->getResultArray();
}
}
3 changes: 2 additions & 1 deletion app/Views/forum/_posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div class="rnapf-row">
<div class="rnapf-date"><?= esc($post['lastpost']) ?></div>
<div class="rnapf-title">
<a href="<?= esc($post['mybb_forum_url'], 'attr') ?>/thread-<?= esc($post['tid'], 'attr') ?>-lastpost.html" class="rnapf-title-link">
<a href="<?= esc($post['mybb_forum_url'], 'attr') ?>/thread-<?= esc($post['tid'], 'attr') ?>-lastpost.html" class="rnapf-title-link"
target="_blank">
<?= esc($post['subject']) ?>
</a>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/Views/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<div id="important-links-inner">
<a href="/download" class="important-link">
<div class="important-link-boxes">
<span class="boldy600 dark">下载 CodeIgniter</span>
<span class="dark boldy600">下载 CodeIgniter</span>
<br/>
查找所有版本
<br/><br/>
Expand All @@ -179,7 +179,7 @@

<a href="/user_guide/index.html" class="important-link">
<div class="important-link-boxes">
<span class="boldy600 dark">阅读用户手册</span>
<span class="dark boldy600">阅读用户手册</span>
<br/>
清晰完善的文档
<br/><br/>
Expand All @@ -192,7 +192,7 @@

<a href="/forums" class="important-link" target="_blank">
<div class="important-link-boxes">
<span class="boldy600 dark">到论坛讨论</span>
<span class="dark boldy600">到论坛讨论</span>
<br/>
加入我们的社区
<br/><br/>
Expand All @@ -202,7 +202,7 @@

<a href="https://github.com/codeigniter4/CodeIgniter4" class="important-link" target="_blank">
<div class="important-link-boxes">
<span class="boldy600 dark">GitHub开源社区</span>
<span class="dark boldy600">GitHub开源社区</span>
<br/>
帮助修复 BUG 或开发新功能
<br/><br/>
Expand Down
6 changes: 2 additions & 4 deletions app/Views/layouts/_top_nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
</div>

<div id="top-menu">
<!--<a href="discover.html" class="top-menu-item hidden" title="CodeIgniter.com">Discover</a>-->
<!--<a href="/news" class="top-menu-item hidden <?php if (url_is('/news*')) : ?>top-menu-item-active<?php endif ?>">新闻</a>-->
<a href="/discuss" class="top-menu-item hidden <?php if (url_is('/discuss')) : ?>top-menu-item-active<?php endif ?>">开发者社区</a>
<a href="/contribute" class="top-menu-item hidden <?php if (url_is('/contribute')) : ?>top-menu-item-active<?php endif ?>">贡献</a>
<a href="/discuss" class="top-menu-item hidden <?php if '/discuss')) : ?>top-menu-item-active<?php endif ?>">开发者社区</a>
<a href="/contribute" class="top-menu-item hidden <?php if '/contribute')) : ?>top-menu-item-active<?php endif ?>">贡献</a>
<a href="/user_guide/index.html" class="top-menu-item hidden">用户手册</a>
<a href="/download" class="top-menu-item-download">下载</a>
</div><!--top-menu ende-->
Expand Down
Loading

0 comments on commit 79b8d40

Please sign in to comment.