Skip to content

Commit

Permalink
#1385 Add icon option for forums
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick committed Oct 10, 2015
1 parent 0461de3 commit 699f700
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 14 deletions.
14 changes: 12 additions & 2 deletions backstage/board.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
$parent_id = intval($_POST['parent_id']);
$cat_id = intval($_POST['cat_id']);
$sort_by = intval($_POST['sort_by']);
$icon = luna_trim($_POST['icon']);
$color = luna_trim($_POST['color']);
$solved = isset($_POST['solved']) ? '1' : '0';

Expand All @@ -148,7 +149,7 @@

$forum_desc = ($forum_desc != '') ? '\''.$db->escape($forum_desc).'\'' : 'NULL';

$db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$db->escape($forum_name).'\', forum_desc='.$forum_desc.', parent_id='.$parent_id.', sort_by='.$sort_by.', cat_id='.$cat_id.', color=\''.$color.'\', solved='.$solved.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$db->escape($forum_name).'\', forum_desc='.$forum_desc.', parent_id='.$parent_id.', sort_by='.$sort_by.', cat_id='.$cat_id.', icon=\''.$db->escape($icon).'\', color=\''.$color.'\', solved='.$solved.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $db->error());

// Now let's deal with the permissions
if (isset($_POST['read_forum_old'])) {
Expand Down Expand Up @@ -195,7 +196,7 @@
}

// Fetch forum info
$result = $db->query('SELECT id, forum_name, forum_desc, parent_id, num_topics, sort_by, cat_id, color, solved FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT id, forum_name, forum_desc, parent_id, num_topics, sort_by, cat_id, icon, color, solved FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

if (!$db->num_rows($result))
message_backstage(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'), false, '404 Not Found');
Expand Down Expand Up @@ -292,6 +293,15 @@
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"><?php _e('Icon', 'luna') ?><span class="help-block"><?php printf(__('The Font Awesome icon you want to show next to the title, for a full overview, see the %s', 'luna'), '<a href="http://fortawesome.github.io/Font-Awesome/icons/">'.__('Font Awesome icon guide', 'luna').'</a>') ?></span></label>
<div class="col-sm-9">
<div class="input-group">
<span class="input-group-addon">fa fa-fw fa-</span>
<input type="text" class="form-control" name="icon" maxlength="50" value="<?php echo luna_htmlspecialchars($cur_forum['icon']) ?>" tabindex="1" />
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"><?php _e('Forum color', 'luna') ?></label>
<div class="col-sm-9">
Expand Down
3 changes: 2 additions & 1 deletion db_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ function stripslashes_array($array) {

// Luna 1.2 upgrade support
$db->add_field('users', 'enforce_accent', 'TINYINT(1)', false, 0) or error('Unable to add enforce_accent field', __FILE__, __LINE__, $db->error());
$db->add_field('forums', 'solved', 'INT', true, 1) or error('Unable to add solved field', __FILE__, __LINE__, $db->error());
$db->add_field('forums', 'solved', 'TINYINT(1)', false, 1) or error('Unable to add solved field', __FILE__, __LINE__, $db->error());
$db->add_field('forums', 'icon', 'VARCHAR(50)', TRUE, NULL) or error('Unable to add icon field', __FILE__, __LINE__, $db->error());

break;

Expand Down
5 changes: 5 additions & 0 deletions include/class/luna_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ public static function create_database($db_type, $db_host, $db_name, $db_usernam
'datatype' => 'TINYINT(1)',
'allow_null' => false,
'default' => '1'
),
'icon' => array(
'datatype' => 'VARCHAR(50)',
'allow_null' => true,
'default' => NULL
)
),
'PRIMARY KEY' => array('id')
Expand Down
14 changes: 12 additions & 2 deletions include/draw_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function draw_forum_list($forum_object_name = 'forum.php', $use_cat = 0, $cat_ob
global $db, $luna_config, $luna_user, $id, $new_topics;

// Print the categories and forums
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.parent_id, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster_id, f.color, u.username AS username, t.subject AS subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'users AS u ON f.last_poster_id=u.id LEFT JOIN '.$db->prefix.'topics AS t ON t.last_post_id=f.last_post_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.parent_id, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster_id, f.icon, f.color, u.username AS username, t.subject AS subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'users AS u ON f.last_poster_id=u.id LEFT JOIN '.$db->prefix.'topics AS t ON t.last_post_id=f.last_post_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

$cur_category = 0;
$cat_count = 0;
Expand Down Expand Up @@ -366,6 +366,11 @@ function draw_forum_list($forum_object_name = 'forum.php', $use_cat = 0, $cat_ob
$forum_field_new = '<span class="newtext">[ <a href="search.php?action=show_new&amp;fid='.$cur_forum['fid'].'">'.__('New', 'luna').'</a> ]</span>';
$icon_type = 'icon icon-new';
}

if ($cur_forum['icon'] != NULL)
$faicon = '<span class="fa fa-fw fa-'.$cur_forum['icon'].'"></span> ';
else
$faicon = '';

$forum_field = '<a href="viewforum.php?id='.$cur_forum['fid'].'">'.luna_htmlspecialchars($cur_forum['forum_name']).'</a>'.(!empty($forum_field_new) ? ' '.$forum_field_new : '');

Expand Down Expand Up @@ -415,7 +420,7 @@ function draw_subforum_list($object_name = 'forum.php') {
$subforum_parent_id = $cur_parent['parent_id'];

// Print the categories and forums
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.parent_id, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster_id, f.color, u.username AS username, t.subject AS subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'users AS u ON f.last_poster_id=u.id LEFT JOIN '.$db->prefix.'topics AS t ON t.last_post_id=f.last_post_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.parent_id='.$subforum_parent_id.' ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.parent_id, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster_id, f.icon, f.color, u.username AS username, t.subject AS subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'users AS u ON f.last_poster_id=u.id LEFT JOIN '.$db->prefix.'topics AS t ON t.last_post_id=f.last_post_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.parent_id='.$subforum_parent_id.' ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

$cur_category = 0;
$cat_count = 0;
Expand All @@ -440,6 +445,11 @@ function draw_subforum_list($object_name = 'forum.php') {
$forum_field_new = '<span class="newtext">[ <a href="search.php?action=show_new&amp;fid='.$cur_forum['fid'].'">'.__('New', 'luna').'</a> ]</span>';
$icon_type = 'icon icon-new';
}

if ($cur_forum['icon'] != NULL)
$faicon = '<span class="fa fa-fw fa-'.$cur_forum['icon'].'"></span> ';
else
$faicon = '';

$forum_field = '<a href="viewforum.php?id='.$cur_forum['fid'].'">'.luna_htmlspecialchars($cur_forum['forum_name']).'</a>'.(!empty($forum_field_new) ? ' '.$forum_field_new : '');

Expand Down
4 changes: 2 additions & 2 deletions include/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
class Version {
// See http://getluna.org/docs/version.php for more info
const FORUM_VERSION = '1.2-alpha.4';
const FORUM_CORE_VERSION = '1.2.5005';
const FORUM_CORE_VERSION = '1.2.5009';
const LUNA_CORE_REVISION = '120a4';

// The Luna Core code name
const LUNA_CODE_NAME = 'cornflowserblue';
const LUNA_CODE_NAME_SEM = 'Cornflower Blue';

// The database version number, every change in the database requires this number to go one up
const FORUM_DB_VERSION = '89.05';
const FORUM_DB_VERSION = '89.10';

// The parser version number, every change to the parser requires this number to go one up
const FORUM_PARSER_VERSION = '11.2.0';
Expand Down
2 changes: 1 addition & 1 deletion themes/Fifteen/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<div class="jumbotron">
<div class="container">
<h2 class="forum-title"><?php echo luna_htmlspecialchars($cur_forum['forum_name']) ?></h2><span class="pull-right naviton"><?php echo $paging_links ?><?php echo $post_link ?></span>
<h2 class="forum-title"><?php echo $faicon.luna_htmlspecialchars($cur_forum['forum_name']) ?></h2><span class="pull-right naviton"><?php echo $paging_links ?><?php echo $post_link ?></span>
<div class="forum-desc"><?php echo $cur_forum['forum_desc'] ?></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/Fifteen/objects/forum.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<a href="viewforum.php?id=<?php echo $cur_forum['fid'] ?>" class="list-group-item <?php echo $item_status ?>">
<?php echo luna_htmlspecialchars($cur_forum['forum_name']) ?>
<?php echo $faicon.luna_htmlspecialchars($cur_forum['forum_name']) ?>
</a>
2 changes: 1 addition & 1 deletion themes/Sunrise/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<div class="jumbotron">
<div class="container">
<h2 class="forum-title"><?php echo luna_htmlspecialchars($cur_forum['forum_name']) ?></h2><span class="pull-right"><?php echo $post_link ?><?php echo $paging_links ?></span>
<h2 class="forum-title"><?php echo $faicon.luna_htmlspecialchars($cur_forum['forum_name']) ?></h2><span class="pull-right naviton"><?php echo $paging_links ?><?php echo $post_link ?></span>
<div class="forum-desc"><?php echo $cur_forum['forum_desc'] ?></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/Sunrise/objects/forum.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="row forum-entry <?php echo $item_status ?>">
<div class="col-sm-6 col-xs-6">
<strong><a href="viewforum.php?id=<?php echo $cur_forum['fid'] ?>"><?php echo luna_htmlspecialchars($cur_forum['forum_name']) ?></a></strong><br />
<strong><a href="viewforum.php?id=<?php echo $cur_forum['fid'] ?>"><?php echo $faicon.luna_htmlspecialchars($cur_forum['forum_name']) ?></a></strong><br />
<?php echo $forum_desc ?>
</div>
<div class="col-sm-1 hidden-xs text-center">
Expand Down
2 changes: 1 addition & 1 deletion themes/Sunrise/objects/subforum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
if ($current_id == $cur_forum['fid'])
?>
<a href="<?php echo $page ?>?id=<?php echo $cur_forum['fid'] ?>" class="list-group-item <?php echo $item_status ?>">
<?php echo luna_htmlspecialchars($cur_forum['forum_name']) ?>
<?php echo $faicon.luna_htmlspecialchars($cur_forum['forum_name']) ?>
</a>
10 changes: 8 additions & 2 deletions viewforum.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

// Fetch some info about the forum
if (!$luna_user['is_guest'])
$result = $db->query('SELECT f.forum_name, f.forum_desc, f.moderators, f.num_topics, f.sort_by, f.color, f.solved, fp.post_topics, s.user_id AS is_subscribed FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_subscriptions AS s ON (f.id=s.forum_id AND s.user_id='.$luna_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT f.forum_name, f.forum_desc, f.moderators, f.num_topics, f.sort_by, f.icon, f.color, f.solved, fp.post_topics, s.user_id AS is_subscribed FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_subscriptions AS s ON (f.id=s.forum_id AND s.user_id='.$luna_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
else
$result = $db->query('SELECT f.forum_name, f.forum_desc, f.moderators, f.num_topics, f.sort_by, f.color, f.solved, fp.post_topics, 0 AS is_subscribed FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT f.forum_name, f.forum_desc, f.moderators, f.num_topics, f.sort_by, f.icon, f.color, f.solved, fp.post_topics, 0 AS is_subscribed FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$luna_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

if (!$db->num_rows($result))
message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'), false, '404 Not Found');
Expand Down Expand Up @@ -64,6 +64,12 @@
$p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
$start_from = $luna_user['disp_topics'] * ($p - 1);

// Get the icon
if ($cur_forum['icon'] != NULL)
$faicon = '<span class="fa fa-fw fa-'.$cur_forum['icon'].'"></span> ';
else
$faicon = '';

// Generate paging links
$paging_links = paginate($num_pages, $p, 'viewforum.php?id='.$id);

Expand Down

0 comments on commit 699f700

Please sign in to comment.