diff --git a/app/Config/MyBB.php b/app/Config/MyBB.php index 58c71985..a0b43940 100644 --- a/app/Config/MyBB.php +++ b/app/Config/MyBB.php @@ -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']; /** * -------------------------------------------------------------------------- diff --git a/app/Config/Routes.php b/app/Config/Routes.php index fa885a04..36a3f5b2 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -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'); - /** * -------------------------------------------------------------------- * Additional Routing diff --git a/app/Database/Migrations/2020-10-29-035422_CreateForumsTable.php b/app/Database/Migrations/2020-10-29-035422_CreateForumsTable.php index 6e20e499..c8f9da28 100644 --- a/app/Database/Migrations/2020-10-29-035422_CreateForumsTable.php +++ b/app/Database/Migrations/2020-10-29-035422_CreateForumsTable.php @@ -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], diff --git a/app/Database/Seeds/ForumSeeder.php b/app/Database/Seeds/ForumSeeder.php index cc065728..209895ad 100644 --- a/app/Database/Seeds/ForumSeeder.php +++ b/app/Database/Seeds/ForumSeeder.php @@ -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() diff --git a/app/Libraries/Forums.php b/app/Libraries/Forums.php index 205fd05a..1ceca357 100644 --- a/app/Libraries/Forums.php +++ b/app/Libraries/Forums.php @@ -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'); + } } diff --git a/app/Models/MyBBModel.php b/app/Models/MyBBModel.php index 6af122d5..86d864c8 100644 --- a/app/Models/MyBBModel.php +++ b/app/Models/MyBBModel.php @@ -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, @@ -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(); + } } diff --git a/app/Views/forum/_posts.php b/app/Views/forum/_posts.php index 1391133c..45e0b4fa 100644 --- a/app/Views/forum/_posts.php +++ b/app/Views/forum/_posts.php @@ -2,7 +2,8 @@