[ Dev ] New's MOD 0.96

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
gatekeep2
Registered User
Posts: 173
Joined: Sat Feb 16, 2002 5:26 am
Location: /dev/null
Contact:

[ Dev ] New's MOD 0.96

Post by gatekeep2 »

I *modified* this MOD, and it works with phpBB 2.0.

EDIT: Ok this look's very messy as I had to turn off bbCode in this post!!!!

Create a file called newsfunc.php and put this code in it:

[code]
<?php
/************************************************************************
* MOD: Forum used as news management system.
* Version: 0.96
*
* This MOD will use a forum of your choosing to produce news output on
* your sites frontpage. News items can contain BBCode and will output
* correctly.
*
* Origional Code By: Derisor
* URL: http://www.fierce-honor.org
* Origional Post: http://phpbb.sourceforge.net/phpBB2/vie ... hp?p=12715
* Date: 11/15/2001
*
* Modifications By: LabRat
* URL: http://www.daocstats.com
*
* (Yet More) Modifications by: gatekeep2 (known as GateKeeper on CSEA)
* URL: http://www.circlesoftus.org:83/
*
* Version: 0.96
* Date: 4/11/2002
* 1. Removed XML formatting (heh, very confusing to edit this with it sorry LabRat)
* 2. Added Smilies
* 3. Fixed bbCode
* 4. Added HTML
*
* Version 0.95
* Date: 2/10/2002
* 1. News display now called with a function
* 2. Ability to show news random news items
* 3. News display templates
*
* Version 0.90
* Date: 1/31/2002
* 1. Select forum by name (Category and Forum)
* 2. Display Avatar
* 3. Show Number of Replies
* 4. Uses Table Prefix from config
* 5. XML Generation Added
*
* Version: 0.80
* Date: 1/25/2002
* 1. Added BBCode capabilities
* 2. Added Database Abstraction
* 3. Added Config Variables
* 4. Added Static Page Generation
*
***************************************************************************/

require($news_root . "/newsconfig.php");
require($news_root . "/newsbbcode.php");

//
// Get Forum ID by name
//
function showNews($news_forumId, $template, $news_items=5, $random="0", $file="0") {
global $news_template;

$news_item_html[0] = $news_template[$template];
$news = news_fetchNews($news_forumId,$news_items,$random);
$news_text = news_arrayInsert($news, $news_item_html);
$news_text = str_replace("<", "<", $news_text);
$news_text = str_replace(">", ">", $news_text);

if($file <> "0") {
$news_file = fopen( $file.".html", "w+" );
fwrite( $news_file, $news_text );
fclose( $news_file );
}
else {
echo ($news_text);
}
}

function getForumID($news_category, $news_forum){
global $db,$table_prefix;

$sql = "select cat_id from ".$table_prefix."categories where cat_title = '".$news_category."'";
$category_list = $db->sql_query($sql);
$category = $db->sql_fetchrow($category_list);
$sql2 = "select forum_id from ".$table_prefix."forums where forum_name='".$news_forum."' and cat_id=".$category[0];
$forum_list = $db->sql_query($sql2);
$forum_id = $db->sql_fetchrow($forum_list);
$news_forumId = $forum_id[0];

return $news_forumId;
}

/************************************************************************
* news_arrayInsert(array of arrays $source_array, string $html_text)
* Replaces the variables in the html text with the contents of each
* of the sub array elements. Positions in the html are indicated with
* the comment <!--X--> where X is the number of variable. The resulting
* output will be a concatenated string with the array elements replaced
* in the html one time for each row.
* Parameters:
* $source_array An array of arrays representing the rows and columns
* of data to use in replacements.
* $html_text The array of text in which to do the substitutions for each row.
* The function will cycle among the elements in the array.
* Returns:
* A fully expanded string containing all rows substituted completely.
***************************************************************************/
function news_arrayInsert($source_array, $html_text) {
$result_text = "";
$temp_text = "";
$row_count = count($source_array);
$col_count = -1;
$key = "<!--X-->";
$temp_key ="";
$text_num = 0;
$text_cycle_size = count($html_text);

for ($row = 0; $row < $row_count; $row++) {
$row_values = $source_array[$row];
$col_count = count($row_values);
$temp_text = $html_text[$text_num];

for ($col = 0; $col < $col_count; $col++) {
$temp_key = str_replace("X", $col, $key);
$temp_text = str_replace($temp_key, $row_values[$col], $temp_text);
}
$result_text = $result_text.$temp_text;
$text_num++;

if ($text_num >= $text_cycle_size) {
$text_num = 0;
}
}
return $result_text;
}

/************************************************************************
* news_smilies_pass(char $message) : Looks for smilies and insertes HTML
*
************************************************************************/
function news_smilies_pass($message) {
global $db, $board_config;
static $smilies;

if( empty($smilies) ) {
$sql = "SELECT code, smile_url
FROM " . SMILIES_TABLE;
if( !$result = $db->sql_query($sql) ) {
message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql);
}

if( !$db->sql_numrows($result) ) {
return $message;
}

$smilies = $db->sql_fetchrowset($result);
}

usort($smilies, 'news_smiley_sort');

for($i = 0; $i < count($smilies); $i++)
{
$orig[] = "/(?<=.\\W|\\W.|^\\W)" . phpbb_preg_quote($smilies[$i]['code'], "/") . "(?=.\\W|\\W.|\\W$)/";
$repl[] = '<img src="/forum/'. $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="Smiley!" border="0" />';
}

if( $i > 0 )
{
$message = preg_replace($orig, $repl, ' ' . $message . ' ');
$message = substr($message, 1, -1);
}

return $message;
}

function news_smiley_sort($a, $b)
{
if ( strlen($a['code']) == strlen($b['code']) )
{
return 0;
}

return ( strlen($a['code']) > strlen($b['code']) ) ? -1 : 1;
}

/************************************************************************
* news_fetchNews(int $forumID) : Fetches the news from the given forum.
* Queries the given forum and selects the first post
* from each topic and returns the array as an array of news items.
* Parameters:
* $forumID = The ID of the forum to use as the news forum.
* Returns:
* An array of news items.
* Column 0 = Post Time
* Column 1 = Poster Name
* Column 2 = Topic Title
* Column 3 = Content
* Column 4 = Post ID
* Column 5 = Topic ID
* Column 6 = URL of post
* Column 7 = Number of replies
* Column 8 = Avatar
***************************************************************************/
function news_fetchNews($forumID, $news_items, $random) {
global $db, $board_config, $userdata, $lang, $table_prefix, $news_site_address;

if ($random <> "0") {
$sql[0] = "SELECT DISTINCT(topic_id)
FROM ".$table_prefix."posts
WHERE forum_id=&?1?
ORDER BY RAND() LIMIT $news_items";
}
else
{
$sql[0] = "SELECT DISTINCT(topic_id)
FROM ".$table_prefix."posts
WHERE forum_id=&?1?
ORDER BY ".$table_prefix."posts.post_time DESC";
}

$sql[1] = "SELECT MIN(post_id)
FROM ".$table_prefix."posts
WHERE topic_id = &?1? ";

$sql[2] = "SELECT ".$table_prefix."posts.post_time, ".$table_prefix."users.username,
".$table_prefix."topics.topic_title, ".$table_prefix."posts_text.post_text,
".$table_prefix."posts.post_id, ".$table_prefix."posts.topic_id, ".$table_prefix."posts_text.bbcode_uid,
".$table_prefix."topics.topic_replies,".$table_prefix."users.user_avatar,".$table_prefix."users.user_avatar_type
FROM ".$table_prefix."posts_text, ".$table_prefix."posts, ".$table_prefix."users, ".$table_prefix."topics
WHERE ".$table_prefix."posts.post_id = &?1?
AND ".$table_prefix."posts_text.post_id = ".$table_prefix."posts.post_id
AND ".$table_prefix."posts.poster_id = ".$table_prefix."users.user_id
AND ".$table_prefix."topics.topic_id = ".$table_prefix."posts.topic_id";

$query_string = str_replace("&?1?", $forumID, $sql[0]);
$topic_ids = $db->sql_query($query_string)
or die ("ERROR: Topic Query Failed.");

$number_topics = $db->sql_numrows($topic_ids);

if ($number_topics >= $news_items) {
$number_topics = $news_items;
}

for ($ctr = 0; $ctr < $number_topics; $ctr++) {
// Grab the first post in the topic for each topic.
$topic = $db->sql_fetchrow($topic_ids);
$query_string = str_replace("&?1?", $topic[0], $sql[1]);
$post_ids = $db->sql_query($query_string);
$post = $db->sql_fetchrow($post_ids);

// Get the post text for the first post in each topic
$query_string = str_replace("&?1?", $post[0], $sql[2]);
$post_texts = $db->sql_query($query_string);
$whole_post = $db->sql_fetchrow($post_texts);

// bbCode
if ( $board_config['allow_bbcode'] ) {
$whole_post[3] = bbencode_second_pass($whole_post[3], $whole_post[6]);
}

// smilies
if ( $board_config['allow_smilies'] ) {
$whole_post[3] = news_smilies_pass($whole_post[3]);
}

// HTML
if ( !$board_config['allow_html'] ) {
$whole_post[3] = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $whole_post[3]);
}

$whole_post[3] = str_replace("\n", "\n<br>\n", $whole_post[3]);


// parse the date format (modified doesn't use phpBB's date method)
$whole_post[0] = create_date("D M d, Y", $whole_post[0], $userdata['user_timezone']);

// Build the url for the post
$whole_post[6] = $news_site_address."/viewtopic.php?t=$whole_post[5]";

if ( $whole_post[9] == 3 ) {
$whole_post[8] = "<img src =\"".$board_config['avatar_gallery_path']."/".$whole_post[8]."\">";
} else if ( $whole_post[9] == 2 ) {
$whole_post[8] = "<img src =\"".$whole_post[8]."\">";
} else if ( $whole_post[9] == 1 ) {
$whole_post[8] = "<img src =\"".$board_config['avatar_path']."/".$whole_post[8]."\">";
} else {
$whole_post[8] = "";
}

// add the news item to the array
$news[$ctr] = $whole_post;
}

return $news;
}
?>



Now I didn't use phpBB's bbcode.php file because I was getting error's that the templateing system wasn't working, so I modified phpBB's code.




Make a file called newsbbcode.php and put this code in it:
<?php
/************************************************************************
* MOD: Forum used as news management system.
* Version: 0.96
*
* This MOD will use a forum of your choosing to produce news output on
* your sites frontpage. News items can contain BBCode and will output
* correctly.
*
* Origional Code By: Derisor
* URL: http://www.fierce-honor.org
* Origional Post: http://phpbb.sourceforge.net/phpBB2/vie ... hp?p=12715
* Date: 11/15/2001
*
* Modifications By: LabRat
* URL: http://www.daocstats.com
*
* (Yet More) Modifications by: gatekeep2 (known as GateKeeper on CSEA)
* URL: http://www.circlesoftus.org:83/
*
* Version: 0.96
* Date: 4/11/2002
* 1. Removed XML formatting (heh, very confusing to edit this with it sorry LabRat)
* 2. Added Smilies
* 3. Fixed bbCode
* 4. Added HTML
*
* Version 0.95
* Date: 2/10/2002
* 1. News display now called with a function
* 2. Ability to show news random news items
* 3. News display templates
*
* Version 0.90
* Date: 1/31/2002
* 1. Select forum by name (Category and Forum)
* 2. Display Avatar
* 3. Show Number of Replies
* 4. Uses Table Prefix from config
* 5. XML Generation Added
*
* Version: 0.80
* Date: 1/25/2002
* 1. Added BBCode capabilities
* 2. Added Database Abstraction
* 3. Added Config Variables
* 4. Added Static Page Generation
*
***************************************************************************/

/***************************************************************************
* newsbbcode.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: bbcode.php,v 1.36 2002/03/25 12:41:41 psotfx Exp $
*
***************************************************************************/

/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
define('IN_PHPBB', true);

$phpbb_root_path = $DOCUMENT_ROOT . "/forum/";
include($phpbb_root_path . "extension.inc");
include($phpbb_root_path . "common.".$phpEx);

if ( !defined('IN_PHPBB') )
{
die("Hacking attempt");
}

define("BBCODE_UID_LEN", 10);

// global that holds loaded-and-prepared bbcode templates, so we only have to do
// that stuff once.

$bbcode_tpl = null;

// hehe, i pulled this code out of template.php cause it was causing strange
// Call to a member function on a non-object error's, i also modified it to
// work! Change the phpbb_ to what ever your table prefix is
function make_filename($filename)
{
global $db, $board_config, $template, $images, $phpbb_root_path;

$sql = "SELECT * FROM [b]phpbb[/b]_themes";

if ( !($result = $db->sql_query($sql)) )
{
die('Could not query database for theme info');
}

if ( !($row = $db->sql_fetchrow($result)) )
{
die("Could not get theme data for themes_id [$style]");
}

$template_path = 'templates/' ;
$template_name = $row['template_name'];

$root = $phpbb_root_path . $template_path . $template_name . "/";

// Check if it's an absolute or relative path.
if (substr($filename, 0, 1) != '/')
{
$filename = $root . '/' . $filename;
}

if (!file_exists($filename))
{
die("templating system: make_filename() - error file $filename does not exist");
}

return $filename;
}


/**
* Loads bbcode templates from the bbcode.tpl file of the current template set.
* Creates an array, keys are bbcode names like "b_open" or "url", values
* are the associated template.
* Probably pukes all over the place if there's something really screwed
* with the bbcode.tpl file.
*
* Nathan Codding, Sept 26 2001.
*/
function load_bbcode_template()
{
// $tpl_filename = "/usr/www/forum/templates/subSilver/bbcode.tpl";
$tpl_filename = make_filename("bbcode.tpl");
$tpl = fread(fopen($tpl_filename, 'r'), filesize($tpl_filename));

// replace \ with \\ and then ' with \'.
$tpl = str_replace('\\', '\\\\', $tpl);
$tpl = str_replace('\'', '\\\'', $tpl);

// strip newlines.
$tpl = str_replace("\n", '', $tpl);

// Turn template blocks into PHP assignment statements for the values of $bbcode_tpls..
$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . '$bbcode_tpls[\'\\1\'] = \'\\2\';', $tpl);

$bbcode_tpls = array();

eval($tpl);

return $bbcode_tpls;
}


/**
* Prepares the loaded bbcode templates for insertion into preg_replace()
* or str_replace() calls in the bbencode_second_pass functions. This
* means replacing template placeholders with the appropriate preg backrefs
* or with language vars. NOTE: If you change how the regexps work in
* bbencode_second_pass(), you MUST change this function.
*
* Nathan Codding, Sept 26 2001
*
*/
function prepare_bbcode_template($bbcode_tpl)
{
global $lang;

$bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']);

$bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']);

$bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']);

$bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']);

$bbcode_tpl['quote_username_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_username_open']);
$bbcode_tpl['quote_username_open'] = str_replace('{L_WROTE}', $lang['wrote'], $bbcode_tpl['quote_username_open']);
$bbcode_tpl['quote_username_open'] = str_replace('{USERNAME}', '\\1', $bbcode_tpl['quote_username_open']);

$bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']);

$bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']);

// We do URLs in several different ways..
$bbcode_tpl['url1'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['url']);
$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1\\2', $bbcode_tpl['url1']);

$bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);

$bbcode_tpl['url3'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['url']);
$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url3']);

$bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url4']);

$bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']);

define("BBCODE_TPL_READY", true);

return $bbcode_tpl;
}


/**
* Does second-pass bbencoding. This should be used before displaying the message in
* a thread. Assumes the message is already first-pass encoded, and we are given the
* correct UID as used in first-pass encoding.
*/
function bbencode_second_pass($text, $uid)
{
global $lang, $bbcode_tpl;

// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text;

// First: If there isn't a "[" and a "]" in the message, don't bother.
if (! (strpos($text, "[") && strpos($text, "]")) )
{
// Remove padding, return.
$text = substr($text, 1);
return $text;
}

// Only load the templates ONCE..
if (!defined("BBCODE_TPL_READY"))
{
// load templates from file into array.
$bbcode_tpl = load_bbcode_template();

// prepare array for use in regexps.
$bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
}

// [code] and [/code] for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);

// [list] and [list=x] for (un)ordered lists.
// unordered lists
$text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text);
// li tags
$text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text);
// ending tags
$text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text);
$text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text);
// Ordered lists
$text = preg_replace("/\[ list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text);

// colours
$text = preg_replace("/\[ color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text);
$text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text);

// size
$text = preg_replace("/\[size=([\-\+]?[1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text);
$text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text);

// [quote] and [/quote] for posting replies with quote, or just for quoting stuff.
$text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
$text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text);

// New one liner to deal with opening quotes with usernames...
// replaces the two line version that I had here before..
$text = preg_replace("/\[quote:$uid=(?:\"?([^\"]*)\"?)\]/si", $bbcode_tpl['quote_username_open'], $text);

// [b] and [/b] for bolding text.
$text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text);
$text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text);

// [u] and [/u] for underlining text.
$text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text);
$text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text);

// [i] and [/i] for italicizing text.
$text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text);
$text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text);

// [glow=red] and [/glow] for glowing text.
$text = preg_replace("/\[glow=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['glow_open'], $text);
$text = str_replace("[/glow:$uid]", $bbcode_tpl['glow_close'], $text);

// [shadow=red] and [/shadow] for shadowed text.
$text = preg_replace("/\[shadow=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['shadow_open'], $text);
$text = str_replace("[/shadow:$uid]", $bbcode_tpl['shadow_close'], $text);

// Patterns and replacements for URL and email tags..
$patterns = array();
$replacements = array();

// [img]image_url_here[/img] code..
// This one gets first-passed..
$patterns[0] = "#\[img:$uid\](.*?)\[/img:$uid\]#si";
$replacements[0] = $bbcode_tpl['img'];

// [url]xxxx://www.phpbb.com[/url] code..
$patterns[1] = "#\[url\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/url\]#si";
$replacements[1] = $bbcode_tpl['url1'];

// [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
$patterns[2] = "#\[url\]([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/url\]#si";
$replacements[2] = $bbcode_tpl['url2'];

// [url=xxxx://www.phpbb.com]phpBB[/url] code..
$patterns[3] = "#\[url=([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\](.*?)\[/url\]#si";
$replacements[3] = $bbcode_tpl['url3'];

// [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
$patterns[4] = "#\[url=([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\](.*?)\[/url\]#si";
$replacements[4] = $bbcode_tpl['url4'];

// [email]user@domain.tld[/email] code..
$patterns[5] = "#\[email\]([a-z0-9\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
$replacements[5] = $bbcode_tpl['email'];

// [flash width= height=] and [/flash] code..
$patterns[6] = "#\[flash width=([0-3]?[0-9]?[0-9]) height=([0-3]?[0-9]?[0-9]):$uid\](.*?)\[/flash:$uid\]#si";
$replacements[6] = $bbcode_tpl['flash'];

// [stream] and [/stream] for streaming audio.
// This one gets first-passed..
$patterns[7] = "#\[stream:$uid\](.*?)\[/stream:$uid\]#si";
$replacements[7] = $bbcode_tpl['stream'];

$text = preg_replace($patterns, $replacements, $text);

// Remove our padding from the string..
$text = substr($text, 1);

return $text;

} // bbencode_second_pass()

// Need to initialize the random numbers only ONCE
mt_srand( (double) microtime() * 1000000);

function make_bbcode_uid()
{
// Unique ID for this message..

$uid = md5(mt_rand());
$uid = substr($uid, 0, BBCODE_UID_LEN);

return $uid;
}

function bbencode_first_pass($text, $uid)
{
// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text;

// [code] and [/code] for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, '');

// [quote] and [/quote] for posting replies with quote, or just for quoting stuff.
$text = bbencode_first_pass_pda($text, $uid, '[quote]', '[/quote]', '', false, '');

$text = bbencode_first_pass_pda($text, $uid, '/\[quote=(\\\\".*?\\\\")\]/is', '[/quote]', '', false, '', "[quote:$uid=\\1]");

// [list] and [list=x] for (un)ordered lists.
$open_tag = array();
$open_tag[0] = "[list]";

// unordered..
$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems');

$open_tag[0] = "[list=1]";
$open_tag[1] = "[list=a]";

// ordered.
$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems');

// [color] and [/color] for setting text color
$text = preg_replace("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "[color=\\1:$uid]\\2[/color:$uid]", $text);

// [size] and [/size] for setting text size
$text = preg_replace("#\[size=([\-\+]?[1-2]?[0-9])\](.*?)\[/size\]#si", "[size=\\1:$uid]\\2[/size:$uid]", $text);

// [b] and [/b] for bolding text.
$text = preg_replace("#\[b\](.*?)\[/b\]#si", "[b:$uid]\\1[/b:$uid]", $text);

// [u] and [/u] for underlining text.
$text = preg_replace("#\[u\](.*?)\[/u\]#si", "[u:$uid]\\1[/u:$uid]", $text);

// [i] and [/i] for italicizing text.
$text = preg_replace("#\[i\](.*?)\[/i\]#si", "[i:$uid]\\1[/i:$uid]", $text);

// [img]image_url_here[/img] code..
$text = preg_replace("#\[img\](([a-z]+?)://([^ \n\r]+?))\[/img\]#si", "[img:$uid]\\1[/img:$uid]", $text);

// [flash width= heigth= loop=] and [/flash]
$text = preg_replace("#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash width=\\1 height=\\2\:$uid]\\3[/flash:$uid]", $text);

// [stream]image_url_here[/stream] code..
$text = preg_replace("#\[stream\](([a-z]+?)://([^, \n\r]+))\[/stream\]#si", "[stream:$uid]\\1[/stream:$uid]", $text);

// [glow=red] and [/glow] for glowing text.
$text = preg_replace("#\[glow=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/glow\]#si", "[glow=\\1:$uid]\\2[/glow:$uid]", $text);

// [shadow=red] and [/shadow] for glowing text.
$text = preg_replace("#\[shadow=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/shadow\]#si", "[shadow=\\1:$uid]\\2[/shadow:$uid]", $text);

// Remove our padding from the string..
$text = substr($text, 1);


return $text;

} // bbencode_first_pass()

/**
* $text - The text to operate on.
* $uid - The UID to add to matching tags.
* $open_tag - The opening tag to match. Can be an array of opening tags.
* $close_tag - The closing tag to match.
* $close_tag_new - The closing tag to replace with.
* $mark_lowest_level - boolean - should we specially mark the tags that occur
* at the lowest level of nesting? (useful for [code], because
* we need to match these tags first and transform HTML tags
* in their contents..
* $func - This variable should contain a string that is the name of a function.
* That function will be called when a match is found, and passed 2
* parameters: ($text, $uid). The function should return a string.
* This is used when some transformation needs to be applied to the
* text INSIDE a pair of matching tags. If this variable is FALSE or the
* empty string, it will not be executed.
* If open_tag is an array, then the pda will try to match pairs consisting of
* any element of open_tag followed by close_tag. This allows us to match things
* like [list=A]...[/list] and [list=1]...[/list] in one pass of the PDA.
*
* NOTES: - this function assumes the first character of $text is a space.
* - every opening tag and closing tag must be of the [...] format.
*/
function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_new, $mark_lowest_level, $func, $open_regexp_replace = false)
{
$open_tag_count = 0;

if (!$close_tag_new || ($close_tag_new == ''))
{
$close_tag_new = $close_tag;
}

$close_tag_length = strlen($close_tag);
$close_tag_new_length = strlen($close_tag_new);
$uid_length = strlen($uid);

$use_function_pointer = ($func && ($func != ''));

$stack = array();

if (is_array($open_tag))
{
if (0 == count($open_tag))
{
// No opening tags to match, so return.
return $text;
}
$open_tag_count = count($open_tag);
}
else
{
// only one opening tag. make it into a 1-element array.
$open_tag_temp = $open_tag;
$open_tag = array();
$open_tag[0] = $open_tag_temp;
$open_tag_count = 1;
}

$open_is_regexp = false;

if ($open_regexp_replace)
{
$open_is_regexp = true;
if (!is_array($open_regexp_replace))
{
$open_regexp_temp = $open_regexp_replace;
$open_regexp_replace = array();
$open_regexp_replace[0] = $open_regexp_temp;
}
}

if ($mark_lowest_level && $open_is_regexp)
{
message_die(GENERAL_ERROR, "Unsupported operation for bbcode_first_pass_pda().");
}


// Start at the 2nd char of the string, looking for opening tags.
$curr_pos = 1;
while ($curr_pos && ($curr_pos < strlen($text)))
{
$curr_pos = strpos($text, "[", $curr_pos);

// If not found, $curr_pos will be 0, and the loop will end.
if ($curr_pos)
{
// We found a [. It starts at $curr_pos.
// check if it's a starting or ending tag.
$found_start = false;
$which_start_tag = "";
$start_tag_index = -1;
for ($i = 0; $i < $open_tag_count; $i++)
{
// Grab everything until the first "]"...
$possible_start = substr($text, $curr_pos, strpos($text, "]", $curr_pos + 1) - $curr_pos + 1);

//
// We're going to try and catch usernames with "[' characters.
//
if( preg_match('/\[quote\=\\\\"/si', $possible_start) && !preg_match('/\[quote=\\\\"[^"]*\\\\"\]/si', $possible_start) )
{
//
// OK we are in a quote tag that probably contains a ] bracket.
// Grab a bit more of the string to hopefully get all of it..
//
$possible_start = substr($text, $curr_pos, strpos($text, "\"]", $curr_pos + 1) - $curr_pos + 2);
}
//
// Now compare, either using regexp or not.

if ($open_is_regexp)
{
$match_result = array();
// PREG regexp comparison.
if (preg_match($open_tag[$i], $possible_start, $match_result))
{
$found_start = true;
$which_start_tag = $match_result[0];
$start_tag_index = $i;
break;
}
}
else
{
// straightforward string comparison.
if (0 == strcasecmp($open_tag[$i], $possible_start))
{
$found_start = true;
$which_start_tag = $open_tag[$i];
$start_tag_index = $i;
break;
}
}
}

if ($found_start)
{
// We have an opening tag.
// Push its position, the text we matched, and its index in the open_tag array on to the stack, and then keep going to the right.
$match = array("pos" => $curr_pos, "tag" => $which_start_tag, "index" => $start_tag_index);
bbcode_array_push($stack, $match);
++$curr_pos;
}
else
{
// check for a closing tag..
$possible_end = substr($text, $curr_pos, $close_tag_length);
if (0 == strcasecmp($close_tag, $possible_end))
{
// We have an ending tag.
// Check if we've already found a matching starting tag.
if (sizeof($stack) > 0)
{
// There exists a starting tag.
$curr_nesting_depth = sizeof($stack);
// We need to do 2 replacements now.
$match = bbcode_array_pop($stack);
$start_index = $match['pos'];
$start_tag = $match['tag'];
$start_length = strlen($start_tag);
$start_tag_index = $match['index'];

if ($open_is_regexp)
{
$start_tag = preg_replace($open_tag[$start_tag_index], $open_regexp_replace[$start_tag_index], $start_tag);
}

// everything before the opening tag.
$before_start_tag = substr($text, 0, $start_index);

// everything after the opening tag, but before the closing tag.
$between_tags = substr($text, $start_index + $start_length, $curr_pos - $start_index - $start_length);

// Run the given function on the text between the tags..
if ($use_function_pointer)
{
$between_tags = $func($between_tags, $uid);
}

// everything after the closing tag.
$after_end_tag = substr($text, $curr_pos + $close_tag_length);

// Mark the lowest nesting level if needed.
if ($mark_lowest_level && ($curr_nesting_depth == 1))
{
$text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$curr_nesting_depth:$uid]";
$text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$curr_nesting_depth:$uid]";
}
else
{
if ($open_is_regexp)
{
$text = $before_start_tag . $start_tag;
}
else
{
$text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$uid]";
}
$text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$uid]";
}

$text .= $after_end_tag;

// Now.. we've screwed up the indices by changing the length of the string.
// So, if there's anything in the stack, we want to resume searching just after it.
// otherwise, we go back to the start.
if (sizeof($stack) > 0)
{
$match = bbcode_array_pop($stack);
$curr_pos = $match['pos'];
bbcode_array_push($stack, $match);
++$curr_pos;
}
else
{
$curr_pos = 1;
}
}
else
{
// No matching start tag found. Increment pos, keep going.
++$curr_pos;
}
}
else
{
// No starting tag or ending tag.. Increment pos, keep looping.,
++$curr_pos;
}
}
}
} // while

return $text;

} // bbencode_first_pass_pda()

/**
* Does second-pass bbencoding of the [code] tags. This includes
* running htmlspecialchars() over the text contained between
* any pair of [code] tags that are at the first level of
* nesting. Tags at the first level of nesting are indicated
* by this format: [code:1:$uid] ... [/code:1:$uid]
* Other tags are in this format: [code:$uid] ... [/code:$uid]
*/
function bbencode_second_pass_code($text, $uid, $bbcode_tpl)
{
global $lang;

$code_start_html = $bbcode_tpl['code_open'];
$code_end_html = $bbcode_tpl['code_close'];

// First, do all the 1st-level matches. These need an htmlspecialchars() run,
// so they have to be handled differently.
$match_count = preg_match_all("#\[code:1:$uid\](.*?)\[/code:1:$uid\]#si", $text, $matches);

for ($i = 0; $i < $match_count; $i++)
{
$before_replace = $matches[1][$i];
$after_replace = $matches[1][$i];

// Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
$after_replace = str_replace(" ", "&nbsp; ", $after_replace);
// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
$after_replace = str_replace(" ", " &nbsp;", $after_replace);

// Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
$after_replace = str_replace("\t", "&nbsp; &nbsp;", $after_replace);

$str_to_match = "[code:1:$uid]" . $before_replace . "[/code:1:$uid]";

$replacement = $code_start_html;
$replacement .= $after_replace;
$replacement .= $code_end_html;

$text = str_replace($str_to_match, $replacement, $text);
}

// Now, do all the non-first-level matches. These are simple.
$text = str_replace("[code:$uid]", $code_start_html, $text);
$text = str_replace("[/code:$uid]", $code_end_html, $text);

return $text;

} // bbencode_second_pass_code()

/**
* Rewritten by Nathan Codding - Feb 6, 2001.
* - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
* to that URL
* - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking
* to http://www.xxxx.yyyy[/zzzz]
* - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking
* to that email address
* - Only matches these 2 patterns either after a space, or at the beginning of a line
*
* Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe
* have it require something like xxxx@yyyy.zzzz or such. We'll see.
*/
function make_clickable($text)
{

// pad it with a space so we can match things at the start of the 1st line.
$ret = " " . $text;

// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, or comma.
$ret = preg_replace("#([\n ])([a-z]+?)://([^,\t \n\r]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $ret);

// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
// yyyy contains either alphanum, "-", or "."
// zzzz is optional.. will contain everything up to the first space, newline, or comma.
// This is slightly restrictive - it's not going to match stuff like "forums.foo.com"
// This is to keep it from getting annoying and matching stuff that's not meant to be a link.
$ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,\t \n\r]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $ret);

// matches an email@domain type address at the start of a line, or after a space.
// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
$ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);

// Remove our padding..
$ret = substr($ret, 1);

return($ret);
}

/**
* Nathan Codding - Feb 6, 2001
* Reverses the effects of make_clickable(), for use in editpost.
* - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs.
*
*/
function undo_make_clickable($text)
{
$text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text);
$text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text);

return $text;

}

/**
* Nathan Codding - August 24, 2000.
* Takes a string, and does the reverse of the PHP standard function
* htmlspecialchars().
*/
function undo_htmlspecialchars($input)
{
$input = preg_replace("/>/i", ">", $input);
$input = preg_replace("/</i", "<", $input);
$input = preg_replace("/"/i", "\"", $input);
$input = preg_replace("/&/i", "&", $input);

return $input;
}

/**
* This is used to change a [*] tag into a [*:$uid] tag as part
* of the first-pass bbencoding of [list] tags. It fits the
* standard required in order to be passed as a variable
* function into bbencode_first_pass_pda().
*/
function replace_listitems($text, $uid)
{
$text = str_replace("[*]", "[*:$uid]", $text);

return $text;
}

/**
* Escapes the "/" character with "\/". This is useful when you need
* to stick a runtime string into a PREG regexp that is being delimited
* with slashes.
*/
function escape_slashes($input)
{
$output = str_replace('/', '\/', $input);
return $output;
}

/**
* This function does exactly what the PHP4 function array_push() does
* however, to keep phpBB compatable with PHP 3 we had to come up with our own
* method of doing it.
*/
function bbcode_array_push(&$stack, $value)
{
$stack[] = $value;
return(sizeof($stack));
}

/**
* This function does exactly what the PHP4 function array_pop() does
* however, to keep phpBB compatable with PHP 3 we had to come up with our own
* method of doing it.
*/
function bbcode_array_pop(&$stack)
{
$arrSize = count($stack);
$x = 1;

while(list($key, $val) = each($stack))
{
if($x < count($stack))
{
$tmpArr[] = $val;
}
else
{
$return_val = $val;
}
$x++;
}
$stack = $tmpArr;

return($return_val);
}
?>




Make another file called newsconfig.php and put this code inside:
<?
/************************************************************************
* MOD: Forum used as news management system.
* Version: 0.96
*
* This MOD will use a forum of your choosing to produce news output on
* your sites frontpage. News items can contain BBCode and will output
* correctly.
*
* Origional Code By: Derisor
* URL: http://www.fierce-honor.org
* Origional Post: http://phpbb.sourceforge.net/phpBB2/vie ... hp?p=12715
* Date: 11/15/2001
*
* Modifications By: LabRat
* URL: http://www.daocstats.com
*
* (Yet More) Modifications by: gatekeep2 (known as GateKeeper on CSEA)
* URL: http://www.circlesoftus.org:83/
*
* Version: 0.96
* Date: 4/11/2002
* 1. Removed XML formatting (heh, very confusing to edit this with it sorry LabRat)
* 2. Added Smilies
* 3. Fixed bbCode
* 4. Added HTML
*
* Version 0.95
* Date: 2/10/2002
* 1. News display now called with a function
* 2. Ability to show news random news items
* 3. News display templates
*
* Version 0.90
* Date: 1/31/2002
* 1. Select forum by name (Category and Forum)
* 2. Display Avatar
* 3. Show Number of Replies
* 4. Uses Table Prefix from config
* 5. XML Generation Added
*
* Version: 0.80
* Date: 1/25/2002
* 1. Added BBCode capabilities
* 2. Added Database Abstraction
* 3. Added Config Variables
* 4. Added Static Page Generation
*
***************************************************************************/

$news_site_address = "CHANGE THIS TO THE URL TO YOUR FORUM"; // URL to the Forum

// News Output Templates

// site output
$news_template[0] = "
<table width=\"95%\" align=\"center\" cellspacing=\"1\" cellpadding=\"2\"
border=\"0\" bgcolor=\"#000000\">
<tr bgcolor=\"#FFFFFF\">
<td align=\"left\">
<font color=\"#000000\"><b><!--2--></b></font>
</td>
</tr>
<tr bgcolor=\"#EEEEEE\">
<td align=\"left\">
<!--3-->
</td>
</tr>
<tr bgcolor=\"#FFFFFF\">
<td>
<table align=\"center\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
<tr>
<td align=\"left\">
<small>
<a href=<!--6-->>Comment on this article (<!--7-->)</a>
</small>
</td>
<td align=\"right\">
<small>
<i>Posted by: <!--1--> : <!--0--></i>
</small>
</td>
</tr>
</table>
</td>
</tr>
</table><br>
";

To have the news display on what ever page you want to use for new's put this code: THIS IS AN EXAMPLE
<?php
$news_root = "includes/";
require($news_root . "newsfunc.php");
showNews(getForumID("Site News", "News"), 0);
?>
[/code]

And that *should* if you have any questions post them here and I'll get back to you sooner or later.
Please, do not conact me for phpBB support.

User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

i don't know what i've to do after i create this files ???

Can you explain me plz ???

Thx

gatekeep2
Registered User
Posts: 173
Joined: Sat Feb 16, 2002 5:26 am
Location: /dev/null
Contact:

Post by gatekeep2 »

ok after you create the files put this code in what ever page you want the news to show up (remeber to change $news_root to the the directory the files are in!)

Code: Select all

<?php 
$news_root = "includes/"; 
require($news_root . "newsfunc.php"); 
showNews(getForumID("Site News", "News"), 0); 
?> 
Please, do not conact me for phpBB support.

test12new
Registered User
Posts: 15
Joined: Thu Apr 04, 2002 9:43 pm

Post by test12new »

Don't forget..... newsbbcode.php

Code: Select all

$phpbb_root_path = $DOCUMENT_ROOT . "/forum/";
/forum/ in my case should be /phpbb2/


Thats not all, smilies not working......
http://www.test12.com/phpbb2/test.php c 4 your self


And bbcode results in a page containing only
"Could not query database for theme info"

Dessimat0r
Registered User
Posts: 50
Joined: Sat Apr 06, 2002 2:28 pm
Contact:

Post by Dessimat0r »

plz can you put code in [code] tags in future? ;)

mickelsn
Registered User
Posts: 16
Joined: Sat Apr 06, 2002 4:39 am
Location: Planet Earth
Contact:

[PRE-RELEASE] Fixes to News MOD

Post by mickelsn »

Howdy, all...

Based on the code above, I've created a code fork of the News MOD that I call News+. It fixes the similes problem, includes language files from templates to fully parse bbCode, and removes all hard-coded configuration from the code.

Please download the MOD from my forums, since this board doesn't have the File Attachment MOD. Let me know what you think...hope it helps. You can respond to this post, or share your thoughts at my News+ forum.

Enjoy! Neil

P.S. I'd really appreciate it if a good phpBB coder could figure out a way to avoid PHP errors when trying to use the includes/bbcode.php file from the phpBB2 installation. The cut-and-paste bastardization called news_bbcode.php required for this MOD can lead to problems if more bbCodes are added.

mickelsn
Registered User
Posts: 16
Joined: Sat Apr 06, 2002 4:39 am
Location: Planet Earth
Contact:

[PRE-RELEASE] Fixes to News MOD

Post by mickelsn »

Howdy, all...

Based on the code above, I've created a code fork of the News MOD that I call News+. It fixes the similes problem, includes language files from templates to fully parse bbCode, and removes all hard-coded configuration from the code.

Please download the MOD from my forums, since this board doesn't have the File Attachment MOD. Let me know what you think...hope it helps. You can respond to this post, or share your thoughts at my News+ forum.

Enjoy! Neil

P.S. I'd really appreciate it if a good phpBB coder could figure out a way to avoid PHP errors when trying to use the includes/bbcode.php file from the phpBB2 installation. The cut-and-paste bastardization called news_bbcode.php required for this MOD can lead to problems if more bbCodes are added.

_Street_Fighter
Registered User
Posts: 4
Joined: Sun Jan 27, 2002 7:32 pm
Location: cHiCaGo
Contact:

Re: [PRE-RELEASE] Fixes to News MOD

Post by _Street_Fighter »

mickelsn wrote: Howdy, all...

Based on the code above, I've created a code fork of the News MOD that I call News+. It fixes the similes problem, includes language files from templates to fully parse bbCode, and removes all hard-coded configuration from the code.

Please download the MOD from my forums, since this board doesn't have the File Attachment MOD. Let me know what you think...hope it helps. You can respond to this post, or share your thoughts at my News+ forum.

Enjoy! Neil

P.S. I'd really appreciate it if a good phpBB coder could figure out a way to avoid PHP errors when trying to use the includes/bbcode.php file from the phpBB2 installation. The cut-and-paste bastardization called news_bbcode.php required for this MOD can lead to problems if more bbCodes are added.


k i tried your news thing and it gave me 2 errors in news_func.php... when i ran the example, it couldnt reach the extension.inc file because it showed the server path 2 times (/home/domain.com/forums/home/domain.com/forums/extension.inc [something like that])

i dont know a lot about php, but the changed the following code in news_func.php and it works fine now:

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = $DOCUMENT_ROOT . $root_forum_path; 
require_once($phpbb_root_path . "extension.inc");
require_once($phpbb_root_path . "common.".$phpEx); 
to

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = $root_forum_path; 
require_once($phpbb_root_path . "extension.inc");
require_once($phpbb_root_path . "common.".$phpEx);
- SF

gatekeep2
Registered User
Posts: 173
Joined: Sat Feb 16, 2002 5:26 am
Location: /dev/null
Contact:

Post by gatekeep2 »

I have to commend mickelsn for a job well done, mickle im actually looking at your code now
Please, do not conact me for phpBB support.

mickelsn
Registered User
Posts: 16
Joined: Sat Apr 06, 2002 4:39 am
Location: Planet Earth
Contact:

Re: [PRE-RELEASE] Fixes to News MOD

Post by mickelsn »

_Street_Fighter wrote: k i tried your news thing and it gave me 2 errors in news_func.php... when i ran the example, it couldnt reach the extension.inc file because it showed the server path 2 times (/home/domain.com/forums/home/domain.com/forums/extension.inc [something like that])

i dont know a lot about php, but the changed the following code in news_func.php and it works fine now:

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = $DOCUMENT_ROOT . $root_forum_path; 
require_once($phpbb_root_path . "extension.inc");
require_once($phpbb_root_path . "common.".$phpEx); 
to

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = $root_forum_path; 
require_once($phpbb_root_path . "extension.inc");
require_once($phpbb_root_path . "common.".$phpEx);
- SF


SF--I've played around with my files a bit and can't seem to reproduce this error. Can you please PM me with the contents of your news_config.php and news_example.php file (or equivalent) so I can look at how you defined the various root variables? It's probably something there, which means that I should look at cleaning up some documentation to help prevent this.

Thanks...Neil

P.S. Thanks to gatekeep2 for the kind words... 8)

Dessimat0r
Registered User
Posts: 50
Joined: Sat Apr 06, 2002 2:28 pm
Contact:

Re: [PRE-RELEASE] Fixes to News MOD

Post by Dessimat0r »

mickelsn wrote: Howdy, all...

Based on the code above, I've created a code fork of the News MOD that I call News+. It fixes the similes problem, includes language files from templates to fully parse bbCode, and removes all hard-coded configuration from the code.

Please download the MOD from my forums, since this board doesn't have the File Attachment MOD. Let me know what you think...hope it helps. You can respond to this post, or share your thoughts at my News+ forum.

Enjoy! Neil

P.S. I'd really appreciate it if a good phpBB coder could figure out a way to avoid PHP errors when trying to use the includes/bbcode.php file from the phpBB2 installation. The cut-and-paste bastardization called news_bbcode.php required for this MOD can lead to problems if more bbCodes are added.


Is there any way you can fetch the fuctions from the orginal file, instead of duplicating them in this code?

i.e. the message formatting routienes, to convert bbcode. Its just that I don't want to have to edit 2 files when i want to add a new tag :)

Dessimat0r
Registered User
Posts: 50
Joined: Sat Apr 06, 2002 2:28 pm
Contact:

Post by Dessimat0r »

oic, you want to include it, but you get errors... :)

I'll try and fix them for you

Dessimat0r
Registered User
Posts: 50
Joined: Sat Apr 06, 2002 2:28 pm
Contact:

Post by Dessimat0r »

Actually, I have decided that this is beyond my grasp of PHP ;)

gatekeep2
Registered User
Posts: 173
Joined: Sat Feb 16, 2002 5:26 am
Location: /dev/null
Contact:

Post by gatekeep2 »

Dessimat0r, the reason the bbcode.php file isn't used (YET, i have to ask Neil, but, i'll probably help with the fork as it works better then my original code) because, there is a problem using the phpBB 2 templating system outside of phpBB 2.
Please, do not conact me for phpBB support.

mickelsn
Registered User
Posts: 16
Joined: Sat Apr 06, 2002 4:39 am
Location: Planet Earth
Contact:

Why Two Sets of bbCode?

Post by mickelsn »

gatekeep2 wrote: Dessimat0r, the reason the bbcode.php file isn't used (YET, i have to ask Neil, but, i'll probably help with the fork as it works better then my original code) because, there is a problem using the phpBB 2 templating system outside of phpBB 2.

Yep, I ran smack into the same problem that others (including gatekeep2) ran into when trying to add bbCode in earlier versions--the templating system chokes with a PHP error (something about invalid object). As I've had a grand total of about three days of using PHP--the sum total of my work is News+ and Calpeek+--so I'm certainly not qualified to try to figure it out. I tried including a raft of files that looked like they'd help, but I got absolutely no love back from my server... :cry:

Post Reply

Return to “[2.0.x] MODs in Development”