boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Hacks] Sticky News Post

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Sat Sep 07, 2002 8:53 am    Post subject: [Hacks] Sticky News Post Reply with quote

I have created a sticky news post hack for B2, it still can be improved further. Just want to share it with you all. If you do not know php, I do not recommand you to try this. It involves hacking into b2 codes. It still contains bugs, and use it at your own risk

If you modify it, please remember to send me back the modified code. =)

Here goes :

Run This MYSQL Statement. I assumed that b2posts is ur table name for ur b2 posts.
Code:

ALTER TABLE b2posts ADD post_sticky tinyint(1) DEFAULT '0' NOT NULL


b2edit.php
[php:1:12dc7e4c8c]
Find
----
case "post":

$standalone = 1;
include_once("./b2header.php");

$post_autobr = $HTTP_POST_VARS["post_autobr"];
$content = format_to_post($HTTP_POST_VARS["content"]);
$content = balanceTags($content);
$post_title = addslashes($HTTP_POST_VARS["post_title"]);

Add Below
---------
$sticky = $HTTP_POST_VARS["sticky"];


Becomes
-------
case "post":

$standalone = 1;
include_once("./b2header.php");

$post_autobr = $HTTP_POST_VARS["post_autobr"];
$content = format_to_post($HTTP_POST_VARS["content"]);
$content = balanceTags($content);
$post_title = addslashes($HTTP_POST_VARS["post_title"]);
$sticky = $HTTP_POST_VARS["sticky"]; // Added This Line



Find
----
$query = "INSERT INTO $tableposts (ID, post_author, post_date, post_content, post_title, post_category) VALUES ('0','$user_ID','$now','$content','".$HTTP_POST_VARS["post_title"]."','".$HTTP_POST_VARS["post_category"]."')";

MODIFY
------
$query = "INSERT INTO $tableposts (ID, post_author, post_date, post_content, post_title, post_category, post_sticky) VALUES ('0','$user_ID','$now','$content','".$HTTP_POST_VARS["post_title"]."','".$HTTP_POST_VARS["post_category"]."','$sticky')";



Find
----
case "editpost":

$standalone = 1;
include_once("./b2header.php");

if ($user_level == 0)
die ("Cheatin' uh ?");

if (!isset($blog_ID)) {
$blog_ID = 1;
}
$post_ID = $HTTP_POST_VARS["post_ID"];
$post_category = $HTTP_POST_VARS["post_category"];
$post_autobr = $HTTP_POST_VARS["post_autobr"];
$content = balanceTags($HTTP_POST_VARS["content"]);
$content = format_to_post($content);
$post_title = addslashes($HTTP_POST_VARS["post_title"]);

Add Below
---------
$sticky = isset($HTTP_POST_VARS["sticky"]) ? $HTTP_POST_VARS["sticky"] : 0;

Becomes
-------
case "editpost":

$standalone = 1;
include_once("./b2header.php");

if ($user_level == 0)
die ("Cheatin' uh ?");

if (!isset($blog_ID)) {
$blog_ID = 1;
}
$post_ID = $HTTP_POST_VARS["post_ID"];
$post_category = $HTTP_POST_VARS["post_category"];
$post_autobr = $HTTP_POST_VARS["post_autobr"];
$content = balanceTags($HTTP_POST_VARS["content"]);
$content = format_to_post($content);
$post_title = addslashes($HTTP_POST_VARS["post_title"]);
$sticky = isset($HTTP_POST_VARS["sticky"]) ? $HTTP_POST_VARS["sticky"] : 0; // Added This Line



Find
----
$query = "UPDATE $tableposts SET post_content=\"$content\", post_title=\"$post_title\", post_category=\"$post_category\"".$datemodif." WHERE ID=$post_ID";

Modify
------
$query = "UPDATE $tableposts SET post_content=\"$content\", post_title=\"$post_title\", post_category=\"$post_category\"".$datemodif.", post_sticky=\"$sticky\" WHERE ID=$post_ID";
[/php:1:12dc7e4c8c]


blog.header.php
[php:1:12dc7e4c8c]
Find
----
$request = " SELECT $distinct * FROM $tableposts WHERE 1=1".$where." ORDER BY post_$orderby $limits";

Modify
------
$request = "SELECT $distinct * FROM $tableposts WHERE 1=1".$where." ORDER BY post_sticky DESC, post_$orderby $limits";
[/php:1:12dc7e4c8c]


b2functions.php
[php:1:12dc7e4c8c]
Find
----
function get_postdata2($postid=0) { // less flexible, but saves mysql queries
global $row;
$postdata = array (
"ID" => $row->ID,
"Author_ID" => $row->post_author,
"Date" => $row->post_date,
"Content" => $row->post_content,
"Title" => $row->post_title,
"Category" => $row->post_category,
# "Notify" => $row->post_notifycomments,
# "Clickable" => $row->post_make_clickable,
"Karma" => $row->post_karma // this isn't used yet
);
return($postdata);
}

Add
---
"Sticky" => $row->post_sticky,

Becomes
-------
function get_postdata2($postid=0) { // less flexible, but saves mysql queries
global $row;
$postdata = array (
"ID" => $row->ID,
"Author_ID" => $row->post_author,
"Date" => $row->post_date,
"Content" => $row->post_content,
"Title" => $row->post_title,
"Category" => $row->post_category,
"Sticky" => $row->post_sticky, // Added This Line
# "Notify" => $row->post_notifycomments,
# "Clickable" => $row->post_make_clickable,
"Karma" => $row->post_karma // this isn't used yet
);
return($postdata);
}
[/php:1:12dc7e4c8c]


b2template.functions.php
[php:1:12dc7e4c8c]
Find
----
function get_the_title() {
global $id,$postdata;
$output = stripslashes($postdata["Title"]);
return($output);
}

Add
---
function the_sticky() {
$issticky = get_the_sticky();
if($issticky == 1) echo "<i>Important</i>";
}
function get_the_sticky() {
global $id,$postdata;
$important = $postdata["Sticky"];
return($important);
}

Becomes
-------
function get_the_title() {
global $id,$postdata;
$output = stripslashes($postdata["Title"]);
return($output);
}
function the_sticky() {
$issticky = get_the_sticky();
if($issticky == 1) echo "- <i>Important</i>";
}
function get_the_sticky() {
global $id,$postdata;
$important = $postdata["Sticky"];
return($important);
}
[/php:1:12dc7e4c8c]


b2edit.form.php
[php:1:12dc7e4c8c]
Find
----
<?php if ( ($use_fileupload) && ($user_level >= $fileupload_minlevel) && ((ereg(" ".$user_login." ", $fileupload_allowedusers)) || (trim($fileupload_allowedusers)=="")) ) { ?>
<input type="button" value="upload a file/image" onclick="launchupload();" class="search" />
<?php } ?>

Add Below
---------
<input type="checkbox" value="1" name="sticky" />Sticky?

Becomes
-------
<?php if ( ($use_fileupload) && ($user_level >= $fileupload_minlevel) && ((ereg(" ".$user_login." ", $fileupload_allowedusers)) || (trim($fileupload_allowedusers)=="")) ) { ?>
<input type="button" value="upload a file/image" onclick="launchupload();" class="search" />
<?php } ?>
<input type="checkbox" value="1" name="sticky" />Sticky?
[/php:1:12dc7e4c8c]


Example
Quote:

In Your template add in <?php the_sticky(); ?> where you want the word "Important To Appear".

Important Post
--------------
GamerZ @ 13:59 - 06.09.2002 - Blogs - Important - Post A Comment?

Normal Post
-----------
GamerZ @ 14:00 - 07.09.2002 - Blogs - Post A Comment?

_________________

++ GamerZ.Per.Sg - Complex Simplicity


Last edited by GamerZ on Sun Jan 05, 2003 4:42 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Tanner



Joined: 06 Jul 2002
Posts: 55
Location: Germany

PostPosted: Mon Sep 16, 2002 12:12 pm    Post subject: Reply with quote

I modyfied Gamerz code a bit. Nothin special but usefuöö I think:

instead of that checkbox in b2edit.form.php I use radiobuttons

Code:
Sticky? 
<input name="sticky" type="radio" value="0" checked>no <input name="sticky" type="radio" value="1">yes


And a hint : You can use an image as sticky mark too!
Just insert an
Code:
<img>
Tag in b2template.functions.php
at the place where that
Code:
<i>Important!</i>
is.
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Sansnom



Joined: 31 Jan 2002
Posts: 94
Location: Paris

PostPosted: Tue May 13, 2003 4:42 am    Post subject: Reply with quote

It's a great hack !

I have got another idea.

Imagine a sticky system which is an agenda, a sticky system used to remain you things to do.
I mean that every post have a dead line date defined when you blog it. Until this date, it won't move from the top. After this dead line, it isn't sticky anymore... and goes in the archives !
The hard thing is that you must select posts by the dead line date when b2 rolls (to have the nearest dead line date on top, and the next under, and the next under...).
So at the end, the selection isn't based anymore on the blog date, but on the dead line date. It supposes custom fields and dates manipulations (the hardest thing !).

If someone know how to do this, please share it with me ! Very Happy
I'm trying on my corner, but I'm not so good... I keep trying...
_________________
http://www.sansfin.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Sansnom



Joined: 31 Jan 2002
Posts: 94
Location: Paris

PostPosted: Tue May 13, 2003 6:46 pm    Post subject: Reply with quote

In fact, I realise that it is a bad idea to alter the entire selection mode of b2. The best is to keep it like that and just add a dead line date to the sticky hack ! So when you want to stick a post until a day, you put the date in a field and it doesn't stick anymore when the day is come... but the rest of b2 running always like now.
The last question is to order the sticky posts by dead line date... which can be done I'm sure... Rendez-vous in one year
_________________
http://www.sansfin.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
.Chris



Joined: 30 Apr 2002
Posts: 186
Location: Hawaii

PostPosted: Sat May 17, 2003 9:37 pm    Post subject: Reply with quote

This might be a dumb question, but how do you unsticky? Just go to the sticky post and edit it and save it as a nonsticky?
_________________
this is my clone.
Back to top
View user's profile Send private message Visit poster's website
Sansnom



Joined: 31 Jan 2002
Posts: 94
Location: Paris

PostPosted: Sun May 18, 2003 2:40 am    Post subject: Reply with quote

Yes, but when you've got lots of posts, it takes many hours.
_________________
http://www.sansfin.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cjc



Joined: 24 Dec 2002
Posts: 146
Location: New York

PostPosted: Sun May 18, 2003 3:28 am    Post subject: Reply with quote

Sansnom wrote:
Yes, but when you've got lots of posts, it takes many hours.


But doesn't having a lot of sticky posts defeat the purpose of sticky posts?
Back to top
View user's profile Send private message Visit poster's website
Sansnom



Joined: 31 Jan 2002
Posts: 94
Location: Paris

PostPosted: Sun May 18, 2003 4:58 am    Post subject: Reply with quote

When you want to have only the title of 20 sticky posts (and nothong else) on index and when you know that these sticky posts are changing every day (diary), the meaning of sticky posts is intact...
_________________
http://www.sansfin.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
.Chris



Joined: 30 Apr 2002
Posts: 186
Location: Hawaii

PostPosted: Fri Jun 13, 2003 10:10 am    Post subject: Reply with quote

OK I just installed this today and I muse have done everything right because I can edit posts, delete posts and the sticky shows up where it should and I do not have any errors BUT I can not make a NEW post. It seems like it's posing it. The poof no post..

Any ideas?
_________________
this is my clone.
Back to top
View user's profile Send private message Visit poster's website
.Chris



Joined: 30 Apr 2002
Posts: 186
Location: Hawaii

PostPosted: Fri Jun 13, 2003 10:27 am    Post subject: Reply with quote

Ok I fixed it.

I had to change:
Code:
$query = "INSERT INTO $tableposts (ID, post_author, post_date, post_content, post_title, post_category, post_sticky) VALUES ('0','$user_ID','$now','$content','".$HTTP_POST_VARS["post_title"]."','".$HTTP_POST_VARS["post_category"]."','$sticky')";

to:
Code:
$query = "INSERT INTO $tableposts (ID, post_author, post_date, post_content, post_title, post_category,  post_sticky) VALUES ('0','$user_ID','$now','$content','".$post_title."','".$post_category."','$sticky')";

_________________
this is my clone.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group