Skip to content

Commit

Permalink
Merge pull request #389 from codeigniter4projects/remove-news
Browse files Browse the repository at this point in the history
Remove News link from site
  • Loading branch information
kenjis authored Sep 1, 2023
2 parents 81e6507 + b160382 commit 23e7f4e
Show file tree
Hide file tree
Showing 11 changed files with 1,557 additions and 1,169 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');

/**
* --------------------------------------------------------------------
* Additional Routing
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
3 changes: 1 addition & 2 deletions app/Views/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
<div class="rnafp-name">Recent News</div>
<div class="clr"></div>

<?= view_cell('\App\Libraries\Blog::recentPostsWidget', 'limit=5, view=blog/_home_widget') ?>
<?= view_cell('\App\Libraries\Forums::news', 'limit=5') ?>
</div><!--recent-news-and-forum-posts here-->

<div class="recent-news-and-forum-posts">
Expand All @@ -236,4 +236,3 @@
<div class="clr"></div>

<?= $this->endSection() ?>

5 changes: 2 additions & 3 deletions app/Views/layouts/_footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<a href="/policies" class="footer-menu-item" >Policies</a>
<a href="/the-fine-print" class="footer-menu-item" >The Fine Print</a>
<a href="/security-disclosures" class="footer-menu-item" >Security Disclosures</a>
<a href="/news" class="footer-menu-item">News</a>
<a href="/discuss" class="footer-menu-item" >Discuss</a>
<a href="/contribute" class="footer-menu-item" >Contribute</a>
<a href="/download" class="footer-menu-item" >Download</a>
Expand Down Expand Up @@ -83,11 +82,11 @@
$('#menu-toggle button').click(function(){
$("#top-menu").slideToggle("slow");
});

$('#scroll-to-top').click(function(){
$("html").animate({ scrollTop: 0 }, "slow");
});

$("a[href$='https://github.com/apps/dependabot']").parent().css("display", "none");
$('#mode').click(function(){
if($('html').hasClass('dark-theme')){
Expand Down
2 changes: 0 additions & 2 deletions app/Views/layouts/_top_nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
</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 ?>">News</a>
<a href="/discuss" class="top-menu-item hidden <?php if (url_is('/discuss')) : ?>top-menu-item-active<?php endif ?>">Discuss</a>
<a href="/contribute" class="top-menu-item hidden <?php if (url_is('/contribute')) : ?>top-menu-item-active<?php endif ?>">Contribute</a>
<a href="/user_guide/index.html" class="top-menu-item hidden">Learn</a>
Expand Down
Loading

0 comments on commit 23e7f4e

Please sign in to comment.