Wiki source for WikkaBlog2


Show raw source

====WikkaBlog====
{{lastedit show="3"}}
Blogs (or web-logs) are currently immensely popular and there are countless web programs to run both individual and collections of blogs. This action is designed to provide blog-functionality (pagination and commenting) to wikka users...essentially allowing wikka to be used as a blog farm if so desired. Use requires two mysql tables, an action script, and an included class (to drive the pagination). Blog submissions have limited wikka formatting (listed under the submit window). This action complements the free-form editing in wikka and the structured thread discussions in WikkaForum.

The two mysql tables are structured as follows.....(replace "wakka_" with whatever your database prefix is)
%%(sql)
CREATE TABLE `wakka_blogcomments` (
`id` int(11) NOT NULL auto_increment,
`blogid` tinyint(4) NOT NULL default '0',
`time` datetime default NULL,
`commentowner` text NOT NULL,
`comment` text NOT NULL,
UNIQUE KEY `id` (`id`)
) TYPE=MyISAM;

CREATE TABLE `wakka_blogs` (
`id` int(11) NOT NULL auto_increment,
`pagename` text NOT NULL,
`time` datetime default NULL,
`name` text NOT NULL,
`blogname` text,
`ownername` text,
`topic` text NOT NULL,
`message` text NOT NULL,
UNIQUE KEY `id` (`id`)
) TYPE=MyISAM;
%%

The following file should be saved in the ##actions## directory as ##blog.php##....
%%(php)
<?php
/* VERSION 1.0e (adding permissions feature to comments)
@filename: blog.php
@author: GMBowen (with contributions by Mark Kasper & Joel Goguen) for a SSHRC research project
@email: gmbowen@yahoo.com
@date: 12 May 2005
@license: GPL

@description: this file requires you are running wikka wiki
and that you've inserted 2 tables into the wikka MYSQL database.
AND **REQUIRES** a pagination class file (page.inc.php) in the wikka root directory "scripts"
// config vars //
numrec= : how many pages are going to be displayed in the list. (optional, default=5)
share= : list of users who can contribute to blog (optional, default = owner)
caption= : Header text for blog (optional, default is null)
NOTE: Comments feature use ACLS permissions to determine who can contribute
@usage: insert {{blog}} anywhere in a wikka wiki page.
*/
//Set BadWordFilter="true" if you want cuss words filtered out (requires edit of wakka.php to add BadWord function), else set "false"
$badwordfilter="true"; // code below compensates if set at true & function doesn't exist, so default is "true"

// establishing number of records to show at once
if (empty($numrec)) {$record_per_page=5;} else {$record_per_page=$numrec;}

// includes functions for doing pagination
include_once("scripts/page.inc.php");

// determining variable values
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
$username = $this->GetUserName();
$blogowner = $this->GetPageOwner();
$pagename = $this->MiniHref($method, $tag);
if($blogname == ''){ $blogname = $pagename; }// if no blog name specified, sets to pagename (but made to lower case)
$username = $this->GetUserName();
$action = $_POST['action'];
$whichblog = $_POST[whichblog];
$blogcmnt = $_GET[blogcmnt];
$blogpage= $_GET[page];

// breaks apart the share string for each userto determine a restricted list of users to add to the blog
$tok = strtok($share, " \n\t");
while ($tok) {
if($tok == $this->GetUserName() || $tok == "ALL") { $use = 'true';}
$tok = strtok(" \n\t");
}
if(strtoupper($this->GetUserName()) == strtoupper($this->GetPageOwner())){ $use = 'true';}

?>
<script>
<!--
function clearTextbox(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = "";
}
//-->
</script>

<?php
// to do commenting on a blog entry
if (!empty($blogcmnt)){
if ($action == "sendcmnt") {
if (!($_POST['comment'] == "enter comment here")) {
$comment_timestamp = date("Y-m-d H:i:s",mktime());

// Bad Word Filter For Comments - parameter set at top....
if ($badwordfilter=="true") {
if (function_exists(BadWordFunc)) {$_POST[comment] = BadWordFunc($_POST[comment]);}
}
$comment = ($_POST[comment]);
$comment = addslashes($comment);
$query = "INSERT INTO ".$this->config['table_prefix']."blogcomments (`id`,`blogid`,`time`,`commentowner`,`comment`) VALUES ('', '$blogcmnt', '$comment_timestamp', '$username', '$comment');";
mysql_query($query);
}
}

$blogpage = $_GET[pg];

$query = "SELECT name,message,topic,time,id FROM ".$this->config['table_prefix']."blogs WHERE id = '$blogcmnt'";
$result = mysql_query($query);
$blogrow = mysql_fetch_array($result,MYSQL_ASSOC);
echo "<div align='center'>";
$blogrow['topic'] = stripslashes($blogrow['topic']);
$printtext = (stripslashes($blogrow['message']));
//to remove formatting not desired in blog submissions
$brackets = Array ('/{{/i', '/}}/i');
$changeto = '|.|';
$printtext = preg_replace($brackets, $changeto, $printtext);
$remove = array('#%', '======', '=====', '====', '===', '==', '[[', ']]', '||', '%| %', '<<', '>>', '::c::', '""');
$printtext = str_replace($remove, '', $printtext);
$printtext = $this->format($printtext);

echo "<br /><TABLE class='box' width='500' border='1' CELLSPACING='0' BGCOLOR='#DDccbb' CELLPADDING='0'>";
echo "<TR BGCOLOR='#DDDDDD'><TD valign='top' ALIGN='left'><em><strong><font size='-1'> ".$blogrow['topic']." </font></strong></em></TD></TR>";
echo "<TR BGCOLOR='#FFFFFF'><TD valign='top' ALIGN='left'> ".$printtext." </TD></TR>";
echo "<TR BGCOLOR='#DDDDDD'><td valign='top' align='left'><TABLE width='100%' border='0'><TR><TD ALIGN='left'><small><strong>   ".$blogrow['time']." by ".$blogrow['name']."</strong></small></TD><TD><small><a href=".$link."&page=".$blogpage.">Return</a></small></TD></TR></TABLE></TD></TR>";
echo "</table>";
echo "<center><B>Comments by readers...</B></center>";
// output of comments
$query = "SELECT * FROM ".$this->config['table_prefix']."blogcomments WHERE blogid = ".$blogcmnt;
$result = mysql_query($query);
if (mysql_num_rows($result)==0) {echo "<em>There are no comments on this blog entry yet.</em>";}
while($row=mysql_fetch_array($result)) {
$row['comment'] = stripslashes($row['comment']);
echo "<TABLE class='box' width='495' border='0' CELLSPACING='0' BGCOLOR='#DDccbb' CELLPADDING='0'>";
echo "<TR BGCOLOR='#FFFFFF'><TD valign='top' ALIGN='left'> ".$row['comment']." </TD></TR>";
echo "<TR BGCOLOR='#DDDDDD'><td valign='top' align='left'><small><strong>   ".$row['time']." by ".$row['commentowner']."</strong></small></TD></TR>";
echo "</table>";
}
// Comment entry form, for registered & logged-in users & those designated in the Comment ACLS list as being able to leave comments
if ($user = $this->GetUser() && $this->HasAccess('comment'))
{
echo "<TABLE BORDER='0' CELLSPACING='2'>";
echo " <TR>";
echo " <TD><FORM ACTION=\"\" METHOD=POST name=\"\">";
echo " <INPUT TYPE=hidden NAME=action VALUE=sendcmnt>";
echo " <INPUT TYPE=hidden NAME=blogid VALUE=$id>";
echo " <P><TEXTAREA NAME=comment ROWS=5 COLS=67 WRAP=virtual onfocus=\"clearTextbox(this)\" class=box>enter comment here</TEXTAREA><br />";
echo " <INPUT TYPE=submit NAME=Submit VALUE='Submit Comment' class=box>";
echo "</form>";
echo " </TD>";
echo " </TR><TR><TD><small>There is <strong>no</strong> formatting for the comments.</small></TD></TR>";
echo "</TABLE>";
}
else
{
if ($this->HasAccess('comment')){
print("<br /><em>You need to be registered and logged-in to submit a comment to a blog.</em></p>");
} else {
print("<br /><em>The blog owner has not given you permission to leave comments.</em></p>");
}
}

echo "</div>";
}
else
{
if ($action == "send" && $whichblog == $blogname) {
if (!($_POST['topic'] == "topic")) {
if (!($_POST['message'] == "blog entry")) {
$blog_timestamp = date("Y-m-d H:i:s",mktime());

// Bad Word Filter For Messages & Topics - parameter set at top....
if ($badwordfilter=="true") {
if (function_exists(BadWordFunc)) {$_POST[message] = BadWordFunc($_POST[message]);}
}
$_POST[message] = addslashes($_POST[message]);
if ($badwordfilter=="true") {
if (function_exists(BadWordFunc)) {$_POST[topic] = BadWordFunc($_POST[topic]);}
}
$_POST[topic] = addslashes($_POST[topic]);
if ($_POST[topic] != '')
{
$query = "INSERT INTO ".$this->config['table_prefix']."blogs (`id`,`pagename`,`time`,`name`,`blogname`,`ownername`,`topic`,`message`) VALUES ('', '$pagename', '$blog_timestamp', '$username', '$blogname', '$blogowner', '$_POST[topic]', '$_POST[message]');";
mysql_query($query);
}
}
}
}
$query = "SELECT name,message,topic,time,id FROM ".$this->config['table_prefix']."blogs WHERE pagename = '$pagename' AND blogname='$blogname' ORDER BY id DESC";
$result = mysql_query($query);
$total_records=@mysql_num_rows($result);
if ($numrec<=3) {$scroll=3;} else {$scroll=$numrec;}
$page=new Page(); ///creating new instance of Class Page
$page->set_page_data($link,$total_records,$record_per_page,$scroll,true,true,true);
$result=@mysql_query($page->get_limit_query($query));

echo "<div align='center'>";
// show the caption
echo "<Font size='+1'><center><strong>".$caption."</strong></center></font>";
// to paginate the blog entries
echo $page->get_page_nav();
// to output blog entries
while($row=mysql_fetch_array($result)) {
$query2 = "SELECT * FROM ".$this->config['table_prefix']."blogcomments WHERE blogid = ".$row['id'];
$result2 = mysql_query($query2);
$cmntcount=mysql_num_rows($result2);
$row['topic'] = stripslashes($row['topic']);
$printtext = (stripslashes($row['message']));
$brackets = Array ('/{{/i', '/}}/i');
$changeto = '|.|';
$printtext = preg_replace($brackets, $changeto, $printtext);
$remove = array('#%', '======', '=====', '====', '===', '==', '[[', ']]', '||', '%|%', '<<', '>>', '::c::', '""');
$printtext = str_replace($remove, '', $printtext);
$printtext = $this->format($printtext);
echo "<br /><TABLE class='box' width='500' border='1' CELLSPACING='0' BGCOLOR='#DDccbb' CELLPADDING='0'>";
echo "<TR BGCOLOR='#DDDDDD'><TD valign='top' ALIGN='left'><em><strong><font size='-1'> ".$row['topic']." </font></strong></em></TD></TR>";
echo "<TR BGCOLOR='#FFFFFF'><TD valign='top' ALIGN='left'> ".$printtext." </TD></TR>";
echo "<TR BGCOLOR='#DDDDDD'><td valign='top' align='left'><TABLE width='100%' border='0'><TR><TD ALIGN='left'><small><strong>   ".$row['time']." by ".$row['name']."</strong></small></TD>";
echo "<TD><small><a href=".$link."&blogcmnt=".$row['id']."&pg=".$blogpage.">Comments</a> (".$cmntcount.")</small></TD></TR></TABLE></TD></TR>";
echo "</table>";
}
// to paginate the blog entries
echo $page->get_page_nav();
// if it is the front page of the blog then show entry box
if ($_GET[page]==0){
// if user is registered and logged in
if ($user = $this->GetUser())
{
// if user has permission to write to the blog then the following form will be shown.
if ($use == 'true')
{
echo "<TABLE BORDER='1' CELLSPACING='2'>";
echo " <TR>";
echo " <TD><FORM ACTION=\"\" METHOD=POST name=\"\">";
echo " <INPUT TYPE=hidden NAME=action VALUE=send>";
echo " <INPUT TYPE=hidden NAME=whichblog VALUE=$blogname>";
echo " <b>Topic: </b> <INPUT TYPE=text NAME=topic SIZE=30 MAXLENGTH=40 class=box title=topic><INPUT TYPE=submit NAME=Submit VALUE='Send' class=box>";
echo " <P><TEXTAREA NAME=message ROWS=5 COLS=67 WRAP=virtual onfocus=\"clearTextbox(this)\" class=box>blog entry</TEXTAREA></P>";
echo "</form>";
echo " </TD>";
echo " </TR><TR><TD><small>In the body text several wiki formatting codes (bold(<bold>**</bold>), italics(<strong>//</strong>), underline(<strong>__</strong>),<br /> strikethrough(<strong>++</strong>), highlight (two single quotes...<strong>''</strong>), centering (<strong>@@</strong>) and bulleted lists(<strong>~-</strong>) <br />(and other lists)) are active. Headings, actions, tables, and external linking are not activated. </small></TD></TR>";
echo "</TABLE>";
echo "</div>";
}
}
else
{
print("<br /><em>You need to be registered and logged-in to contribute to the blogs.</em></p>");
}
}
else
{
print("<br /><em>New blog entries are made on the first page of the blog.</em></p>");
}
}
?>
%%
(**without the | between the double percents of course**....which is necessary for placing the code on the page....so you must replace the %|% with double percent signs in two places)

The following file should be saved as ##page.inc.php## in a directory called ##scripts## in the wikka root....
%%(php)
<?php


/*
###############################################
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
###############################################

*/
// Original class script obtained from http://www.phpclasses.org/browse/package/2012.html distributed as "Freeware"
// Modifications (Ver 1.0b) by GmBowen so that script useable with wikka wiki to support a "blog" action developed for the wiki.
// Throughout this class "?page" was changed to "&page" as well as other minor modifications throughout the script.

class Page
{
var $total_records=1; ///Total Records returned by sql query
var $records_per_page=1; ///how many records would be displayed at a time
var $page_name=""; ///page name on which the class is called
var $start=0;
var $page=0;
var $total_page=0;
var $current_page;
var $remain_page;
var $show_prev_next=true;
var $show_scroll_prev_next=false;
var $show_first_last=false;
var $show_disabled_links=true;
var $scroll_page=0;
var $qry_str="";
var $link_para="&";

/* returns boolean value if it is last page or not*/
function is_last_page()
{
return $this->page>=$this->total_page-1?true:false;
}
/* param : Void
returns boolean value if it is first page or not*/
function is_first_page()
{
return $this->page==0?true:false;
}
function current_page()
{
return $this->page+1;
}
function total_page()
{
return $this->total_page==0?1:$this->total_page;
}

//@param : $show = if you want to show disabled links on navigation links.
//
function show_disabled_links($show=TRUE)
{
$this->show_disabled_links=$show;
}
//@param : $link_para = if you want to pass any parameter to link
//
function set_link_parameter($link_para)
{
$this->link_para=$link_para;
}
function set_page_name($page_name)
{
$this->page_name=$page_name;
}
//@param : str= query string you want to pass to links.
function set_qry_string($str="")
{
$this->qry_str="&".$str;
}
function set_scroll_page($scroll_num=0)
{
if($scroll_num!=0)
$this->scroll_page=$scroll_num;
else
$this->scroll_page=$this->total_records;

}
function set_total_records($total_records)
{
if($total_records<0)
$total_records=0;
$this->total_records=$total_records;
}
function set_records_per_page($records_per_page)
{
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
}
/* @params
* $page_name = Page name on which class is integrated. i.e. $_SERVER['PHP_SELF']
* $total_records=Total records returnd by sql query.
* $records_per_page=How many projects would be displayed at a time
* $scroll_num= How many pages scrolled if we click on scroll page link.
* i.e if we want to scroll 6 pages at a time then pass argument 6.
* $show_prev_next= boolean(true/false) to show prev Next Link
* $show_scroll_prev_next= boolean(true/false) to show scrolled prev Next Link
* $show_first_last= boolean(true/false) to show first last Link to move first and last page.
*/

function set_page_data($page_name,$total_records,$records_per_page=1,$scroll_num=0,$show_prev_next=true,$show_scroll_prev_next=false,$show_first_last=false)
{
$this->set_total_records($total_records);
$this->set_records_per_page($records_per_page);
$this->set_scroll_page($scroll_num);
$this->set_page_name($page_name);
$this->show_prev_next=$show_prev_next;
$this->show_scroll_prev_next=$show_scroll_prev_next;
$this->show_first_last=$show_first_last;
}
/* @params
* $user_link= if you want to display your link i.e if you want to user '>>' instead of [first] link then use
Page::get_first_page_nav(">>") OR for image
Page::get_first_page_nav("<img src='' alt='first'>")
$link_para: link parameters i.e if you want ot use another parameters such as class.
Page::get_first_page_nav(">>","class=myStyleSheetClass")
*/
function get_first_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="««  ";
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_last_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="  »»";
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_next_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link=" »";
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
}
function get_prev_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="« ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
}
function get_scroll_prev_page_nav($user_link="",$link_para="")
{

if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[-$this->scroll_page]";
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}
function get_scroll_next_page_nav($user_link="",$link_para="")
{
if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[+$this->scroll_page]";
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}

function get_number_page_nav($link_para="")
{
$j=0;
$scroll_page=$this->scroll_page;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;

if($j<0)
$i=0;
else
$i=$j;

for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
{
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
}

function get_page_nav()
{
if($this->total_records<=0)
{
//echo "No Records Found";
// return false;
}
$this->calculate();
$this->get_first_page_nav("",$this->link_para);
$this->get_scroll_prev_page_nav("",$this->link_para);
$this->get_prev_page_nav("",$this->link_para);
$this->get_number_page_nav($this->link_para);
$this->get_next_page_nav("",$this->link_para);
$this->get_scroll_next_page_nav("",$this->link_para);
$this->get_last_page_nav("",$this->link_para);
// return true;
}
function calculate()
{
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
}
function get_limit_query($qry="")
{
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
}
}
?>
%%

----
The blog.php action on this page can use a "bad word function" that should be placed **in** the wikka.php file in the wiki root directory. The following code needs to be placed in the wikka.php file (just after the microtime function which starts "function getmicrotime" and ends with a "}". This code is placed immediately after the "}".

%%(php)
//GMB remove bad word filter
function BadWordFunc($RemoveBadWordText) {
$RemoveBadWordText = eregi_replace("fuc?k|[kc]unt|motherfucker|cocksucker|bitch|son of a bitch|asshole|shit|fag|wank|dick|pu[zs]?[zs][yi]|bastard|s[kc]rew|mole[zs]ter|mole[sz]t|coc?k", "", $RemoveBadWordText);
return $RemoveBadWordText;
%%
The main entry page looks like this....
http://gmbtst.msvu.ca/wikitest/wikkablog1.jpg
and the comment page, which shows one blog entry box and then the listed comments, looks like.....
http://gmbtst.msvu.ca/wikitest/wikkablog2.jpg

~& Changed wakka.php to wikka.php in instructions for badword filter - JoelCant
~& (moved from WikkaBugs) This is about WikkaBlog2. --- I find that noone is allowed to post blog comments (i.e. not the wikka page std comments). All ACLs are '*'; I even blanked all, or have the page owned by nobody, and still no rights; I suppose ""HasAccess""('comment') fails. (see [[http://cativan.com/VisitingIdeas this page]]) -- CatIvan
~& Is this a good solution? in blog.pgp, line 112 "if ( /*$user = $this->""GetUser""() &&*/ $this->""HasAccess""('comment'))" -- the 1st test condition fails for anonymous users; it seems to me the 2nd statement (ACL based) is sufficient. -- CatIvan


----
CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki