Here i will post a realization of a one little addon for forums,which is done in most other forum systems.I'll put out it as a core hack,but If someone wants he can make a plugin out of this.
The idea is to "stick" a random forum post in the topic(through out the topic pages).
Step 1.Adding 1 field to the DB.
We need to add a column in the forum_posts.For this just run:
ALTER TABLE `sed_forum_posts` ADD COLUMN `fs_poststicker` tinyint(1) NOT NULL]
Step 2.Adding a "Stick first post" option in the New topic.(File: posts.newtopic.inc.php)
Dont remember for what i'w put in this string,but:
$sticky = sed_import('stickypost','P','BOL');
Edit the sql_insert:
$sql = sed_sql_query("INSERT into $db_forum_topics
(ft_state,
ft_mode,
ft_sticky,
ft_sectionid,
ft_title,
ft_desc,
ft_preview,
ft_creationdate,
ft_updated,
ft_postcount,
ft_viewcount,
ft_firstposterid,
ft_firstpostername,
ft_lastposterid,
ft_lastpostername)
VALUES
(0,
".(int)$newprvtopic.",
0,
".(int)$s.",
'".sed_sql_prep($newtopictitle)."',
'".sed_sql_prep($newtopicdesc)."',
'".sed_sql_prep($newtopicpreview)."',
".(int)$sys['now_offset'].",
".(int)$sys['now_offset'].",
1,
0,
".(int)$usr['id'].",
'".sed_sql_prep($usr['name'])."',
".(int)$usr['id'].",
'".sed_sql_prep($usr['name'])."')");
The sticker option
$sticky = "<input type=\"checkbox\" name=\"stickypost\" value=\"1\">";
$t->assign(array(
"STICKY_POST" => $sticky,
));
Step 3.Adding a similar option to every post.(File: posts.editpost.inc.php)
if($usr['isadmin'])
{
$sqk = sed_sql_query("select fp_id,fs_poststicker from $db_forum_posts WHERE fp_id='$p' LIMIT 1");
$rows = sed_sql_fetcharray($sqk);
$checked = ($rows['fs_poststicker'])=='1' ? "checked=\"checked\"" : '';
$sticky = "<input type=\"checkbox\" name=\"stickypost\" value=\"1\" $checked>";
$t->assign(array(
"STICKY_POST" => $sticky,
));
$t->parse("MAIN.STICKY");
}
Step 4.Last.(File: posts.posts.inc.php)
The first thing is to add a sql_select for this posts(with a mark that it is sticky).
this part can be optimized ,but it should work fine without it:
$sqlr = sed_sql_query("SELECT p.*, u.user_text, u.user_maingrp, u.user_avatar, u.user_photo, u.user_signature,
u.user_country, u.user_occupation, u.user_location, u.user_website, u.user_email, u.user_hideemail, u.user_gender, u.user_birthdate,
u.user_postcount
FROM $db_forum_posts p,$db_users u
WHERE fp_topicid='$q'
AND u.user_id=p.fp_posterid
AND p.fs_poststicker = '1'
ORDER BY fp_id ");
while ($brow = sed_sql_fetcharray($sqlr))
{
$brow['fp_text'] = htmlspecialchars($brow['fp_text']);
$brow['fp_created'] = @date($cfg['dateformat'], $brow['fp_creation'] + $usr['timezone'] * 3600);
$brow['fp_updated_ago'] = sed_build_timegap($brow['fp_updated'], $sys['now_offset']);
$brow['fp_updated'] = @date($cfg['dateformat'], $brow['fp_updated'] + $usr['timezone'] * 3600);
$brow['user_text'] = ($fs_allowusertext) ? $brow['user_text'] : '';
$lastposterid = $brow['fp_posterid'];
$lastposterip = $brow['fp_posterip'];
$fp_num++;
$i = empty($id) ? $d + $fp_num : $id;
$browquote = ($usr['id']>0) ? "<a href=\"".sed_url('forums', "m=posts&s=".$s."&q=".$q.""e=".$brow['fp_id']."&n=last", "#np")."\">".$L['Quote']."</a>" : " ";
$browedit = (($usr['isadmin'] || $brow['fp_posterid']==$usr['id']) && $usr['id']>0) ? "<a href=\"".sed_url('forums', "m=editpost&s=".$s."&q=".$q."&p=".$brow['fp_id']."&".sed_xg())."\">".$L['Edit']."</a>" : '';
$browdelete = ($usr['id']>0 && ($usr['isadmin'] || $brow['fp_posterid']==$usr['id']) && !($post12[0]==$brow['fp_id'] && $post12[1]>0)) ? $L['Delete'].":[<a href=\"".sed_url('forums', "m=posts&a=delete&".sed_xg()."&s=".$s."&q=".$q."&p=".$brow['fp_id'])."\">x</a>]" : '';
$browdelete .= ($fp_num==$totalposts) ? "<a name=\"bottom\" id=\"bottom\"></a>" : '';
$sadminoptions = $browquote.' '.$browedit.' '.$browdelete;
if ($usr['id']>0 && $n=='unread' && !$unread_done && $brow['fp_creation']>$usr['lastvisit'])
{
$unread_done = TRUE;
$adminoptions .= "<a name=\"unread\" id=\"unread\"></a>";
}
$brow['fp_posterip'] = ($usr['isadmin']) ? sed_build_ipsearch($brow['fp_posterip']) : '';
if($cfg['parser_cache'])
{
if(empty($brow['fp_html']) && !empty($brow['fp_text']))
{
$brow['fp_html'] = sed_parse($brow['fp_text'], $cfg['parsebbcodeforums'] && $fs_allowbbcodes, $cfg['parsesmiliesforums'] && $fs_allowsmilies, 1);
sed_sql_query("UPDATE $db_forum_posts SET fp_html = '".sed_sql_prep($brow['fp_html'])."' WHERE fp_id = " . $row['fp_id']);
}
$brow['fp_text'] = sed_post_parse($brow['fp_html'], 'forums');
}
else
{
$brow['fp_text'] = sed_parse($brow['fp_text'], ($cfg['parsebbcodeforums'] && $fs_allowbbcodes), ($cfg['parsesmiliesforums'] && $fs_allowsmilies), 1);
$brow['fp_text'] = sed_post_parse($brow['fp_text'], 'forums');
}
$brow['fp_useronline'] = (sed_userisonline($brow['fp_posterid'])) ? "1" : "0";
$brow['fp_useronlinetitle'] = ($brow['fp_useronline']) ? $skinlang['forumspost']['Onlinestatus1'] : $skinlang['forumspost']['Onlinestatus0'];
if (!empty($row['fp_updater']))
{ $brow['fp_updatedby'] = sprintf($L['for_updatedby'], htmlspecialchars($brow['fp_updater']), $brow['fp_updated'], $brow['fp_updated_ago']); }
$brow['user_birthdate'] = sed_date2stamp($brow['user_birthdate']);
$brow['user_text'] = sed_build_usertext($brow['user_text']);
$brow['user_age'] = ($brow['user_birthdate']!=0) ? sed_build_age($brow['user_birthdate']) : '';
$t-> assign(array(
"FORUMS_POSTS_STICK_ID" => $brow['fp_id'],
"FORUMS_POSTS_STICK_POSTID" => 'post_'.$brow['fp_id'],
"FORUMS_POSTS_STICK_IDURL" => sed_url('forums', "m=posts&id=".$brow['fp_id']),
"FORUMS_POSTS_STICK_URL" => sed_url('forums', "m=posts&p=".$brow['fp_id'], "#".$brow['fp_id']),
"FORUMS_POSTS_STICK_CREATION" => $brow['fp_created'],
"FORUMS_POSTS_STICK_UPDATED" => $brow['fp_updated'],
"FORUMS_POSTS_STICK_UPDATER" => htmlspecialchars($brow['fp_updater']),
"FORUMS_POSTS_STICK_UPDATEDBY" => $brow['fp_updatedby'],
"FORUMS_POSTS_STICK_TEXT" => $brow['fp_text'],
"FORUMS_POSTS_STICK_POSTERNAME" => sed_build_user($brow['fp_posterid'], htmlspecialchars($brow['fp_postername'])),
"FORUMS_POSTS_STICK_POSTERID" => $brow['fp_posterid'],
"FORUMS_POSTS_STICK_MAINGRP" => sed_build_group($brow['user_maingrp']),
"FORUMS_POSTS_STICK_MAINGRPID" => $brow['user_maingrp'],
"FORUMS_POSTS_STICK_MAINGRPSTARS" => sed_build_stars($sed_groups[$brow['user_maingrp']]['level']),
"FORUMS_POSTS_STICK_MAINGRPICON" => sed_build_userimage($sed_groups[$brow['user_maingrp']]['icon']),
"FORUMS_POSTS_STICK_USERTEXT" => $brow['user_text'],
"FORUMS_POSTS_STICK_AVATAR" => sed_build_userimage($brow['user_avatar'], 'avatar'),
"FORUMS_POSTS_STICK_PHOTO" => sed_build_userimage($brow['user_photo'], 'photo'),
"FORUMS_POSTS_STICK_SIGNATURE" => sed_build_userimage($brow['user_signature'], 'sig'),
"FORUMS_POSTS_STICK_GENDER" => $brow['user_gender'] = ($row['user_gender']=='' || $brow['user_gender']=='U') ? '' : $L["Gender_".$row['user_gender']],
"FORUMS_POSTS_STICK_POSTERIP" => $brow['fp_posterip'],
"FORUMS_POSTS_STICK_USERONLINE" => $brow['fp_useronline'],
"FORUMS_POSTS_STICK_USERONLINETITLE" => $brow['fp_useronlinetitle'],
"FORUMS_POSTS_STICK_DELETE" => $rowdelete,
"FORUMS_POSTS_STICK_EDIT" => $rowedit,
"FORUMS_POSTS_STICK_QUOTE" => $rowquote,
"FORUMS_POSTS_STICK_ADMIN" => $adminoptions,
"FORUMS_POSTS_STICK_COUNTRY" => $sed_countries[$brow['user_country']],
"FORUMS_POSTS_STICK_COUNTRYFLAG" => sed_build_flag($brow['user_country']),
"FORUMS_POSTS_STICK_WEBSITE" => sed_build_url($brow['user_website'], 36),
"FORUMS_POSTS_STICK_WEBSITERAW" => $brow['user_website'],
"FORUMS_POSTS_STICK_EMAIL" => sed_build_email($brow['user_email'], $brow['user_hideemail']),
"FORUMS_POSTS_STICK_LOCATION" => htmlspecialchars($brow['user_location']),
"FORUMS_POSTS_STICK_OCCUPATION" => htmlspecialchars($brow['user_occupation']),
"FORUMS_POSTS_STICK_AGE" => $brow['user_age'],
"FORUMS_POSTS_STICK_POSTCOUNT" => $brow['user_postcount'],
));
$t->parse("MAIN.FORUMS_POSTS_STICKER");
}
and for convinience - edit the main sql_select,so it wouldn't show the posts with mark Sticky:
$sql = sed_sql_query("SELECT p.*, u.user_text, u.user_maingrp, u.user_avatar, u.user_photo, u.user_signature,
$user_extrafields
u.user_country, u.user_occupation, u.user_location, u.user_website, u.user_email, u.user_hideemail, u.user_gender, u.user_birthdate,
u.user_postcount
FROM $db_forum_posts AS p LEFT JOIN $db_users AS u ON u.user_id=p.fp_posterid
WHERE fp_topicid='$q'
AND p.fs_poststicker = '0'
ORDER BY fp_id LIMIT $d, ".$cfg['maxpostsperpage']);
After all of this add :
in forum.posts.tpl
<!-- BEGIN: FORUMS_POSTS_STICKER -->
{FORUMS_POSTS_STICK_TEXT} (use the same tags as in original post,but with _STICK_ )
<!-- END: FORUMS_POSTS_STICKER -->
in forum.newtopic.tpl
<!-- BEGIN: STICKY -->
{STICKY_POST}
<!-- END: STICKY -->
and in forum.editpost.tpl
<!-- BEGIN: STICKY -->
{STICKY_POST}
<!-- END: STICKY -->
[url=http://ka13.orgfree.com]KA13[/url] - The essence of creativity