Forums / Cotonti / Core Labs / Sticky post

SunChase
#1 2009-11-20 00:44
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:

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
pieter
#2 2009-11-20 02:41
Can' this be done with a plugin?
... can we help you ...
SunChase
#3 2009-11-20 03:28
I'll put out it as a core hack,but If someone wants he can make a plugin out of this.

it can be done as a plugin,but when i asked for help on making a plugin out of this i got no answer...
[url=http://ka13.orgfree.com]KA13[/url] - The essence of creativity