help with this

 
Post new topic   Reply to topic    Deceptive Logic Forum Index -> PHP, Javascript, ASP, etc...
View previous topic :: View next topic  
Author Message
santosh_iit32
newbie
newbie



Member No.: 90
Joined: 19 Nov 2006
Posts: 21
Location: India

PostPosted: Sat Dec 30, 2006 3:15 pm   Post subject: help with this Reply with quote

I'm going to use these two script for my index page. could anyone help me sort out those unecessary junk codes and help me understand how to integrate this two scripts. thank you.

here's the topic grabber Mod:
Code:
<?php

$limit_count = 5;
$date_time_format = "%e %b %I:%M %p";    // e.x. 20 Feb 12:29 am
$phpbb_root_path = "forum/";

if(!defined("IN_PHPBB"))
{
  define("IN_PHPBB", true);
  include($phpbb_root_path . "extension.inc");
  include($phpbb_root_path . "common.".$phpEx);
  include($phpbb_root_path . "config.".$phpEx);
}

if($db)     
{

    $topics_query = $db->sql_query("
        SELECT
            {$table_prefix}topics.topic_title,
            {$table_prefix}users.username AS poster_name,
            {$table_prefix}topics.topic_time,
            {$table_prefix}posts_text.post_text AS topic_text,
            {$table_prefix}topics.topic_views,
            {$table_prefix}topics.topic_replies,
            {$table_prefix}topics.topic_id,
            {$table_prefix}posts_text.post_id,
            {$table_prefix}topics.topic_poster AS poster_id
        FROM
            {$table_prefix}topics,
            {$table_prefix}users,
            {$table_prefix}posts_text
        WHERE
            {$table_prefix}topics.forum_id = {$forum_id} AND
            {$table_prefix}users.user_id =
                {$table_prefix}topics.topic_poster AND
            {$table_prefix}posts_text.post_id =
                {$table_prefix}topics.topic_first_post_id
        ORDER BY topic_time DESC
        LIMIT {$limit_count};");
   
    if($topics_query && mysql_num_rows($topics_query))
    {
        while($topic_entry = $db->sql_fetchrow($topics_query))
        {

           
            $topic_title = $topic_entry["topic_title"];
            $poster_name = $topic_entry["poster_name"];
            $topic_time = strftime($date_time_format, $topic_entry["topic_time"]);
            $topic_text = $topic_entry["topic_text"];
            $topic_views = $topic_entry["topic_views"];
            $topic_replies = $topic_entry["topic_replies"];
            $topic_id = $topic_entry["topic_id"];
            $post_id = $topic_entry["post_id"];
            $poster_id = $topic_entry["poster_id"];
            $view_link = "{$phpbb_root_path}viewtopic.{$phpEx}?p={$post_id}";
            $reply_link = "{$phpbb_root_path}posting.{$phpEx}?mode=reply&t={$topic_id}";
            $poster_link = "{$phpbb_root_path}profile.{$phpEx}?mode=viewprofile&u={$poster_id}";
           
            $topic_text = preg_replace("/\:[0-9a-z\:]+\]/si", "]", $topic_text);
            // Bold
            $topic_text = str_replace("[b]", "<B>", $topic_text);
            $topic_text = str_replace("[/b]", "</B>", $topic_text);
            // Italics
            $topic_text = str_replace("[i]", "<I>", $topic_text);
            $topic_text = str_replace("[/i]", "</I>", $topic_text);
            // Underline
            $topic_text = str_replace("[u]", "<U>", $topic_text);
            $topic_text = str_replace("[/u]", "</U>", $topic_text);
            // Quote (style #1)
            $topic_text = preg_replace("/\[quote=(.*)\](.*)\[\/quote\]/Usi", "<DIV STYLE=\"padding: 7px\">$2</DIV>", $topic_text);
            // Quote (style #2)
            $topic_text = str_replace("[quote]", "<B>Quote:</B><BR><I>", $topic_text);
            $topic_text = str_replace("[/quote]", "</I>", $topic_text);
            // Code
            $topic_text = str_replace("[code]", "<B>Code:</B><BR><I>", $topic_text);
            $topic_text = str_replace("[/code]", "</I>", $topic_text);
            // List
            $topic_text = preg_replace("/\[list\](.*)\[\/list\]/si", "<DIV STYLE=\"padding: 7px\">$1</DIV>", $topic_text);
            $topic_text = preg_replace("/\[list=(.*)\](.*)\[\/list\]/si", "<DIV STYLE=\"padding: 7px\">$1</DIV>", $topic_text);
            // Image
            $topic_text = str_replace("[img]", "<IMG SRC="" ALT="Image\">", $topic_text);
            // URL
            $topic_text = preg_replace("/\[url\](.*)\[\/url\]/Usi", "<A HREF=\"$1\" TARGET=\"_blank\">$1</A>", $topic_text);
            $topic_text = preg_replace("/\[url=(.*)\](.*)\[\/url\]/Usi", "<A HREF=\"$2\" TARGET=\"_blank\">$2</A>", $topic_text);
            // Endlines
            $topic_text = str_replace("\n", "<BR>\n", $topic_text);
            // Head banner (poster, date)
            echo("<HR>\n");
            echo("\"{$topic_title}\", posted by <A HREF=\"{$poster_link}\" TARGET=\"_blank\">{$poster_name}</A> on {$topic_time}<BR>\n");
            // Content (topic text)
            echo("<HR>\n");
            echo("{$topic_text}\n");
            // Footer banner (link to view & reply, # of views & replies)
            echo("<HR>\n");
            echo("| <A HREF=\"{$view_link}\" TARGET=\"_blank\">View</A> | <A HREF=\"{$reply_link}\" TARGET=\"_blank\">Reply</A> | Viewed {$topic_views} times, with {$topic_replies} ");
            if($topic_replies != 1)
                echo("replies. |<BR>\n");
            else   
                echo("reply. |<BR>\n");
            echo("<HR>\n");
            echo("<P>\n");
        }
    }
    else
    {
        echo("<P>No topics exist in the forum.<BR>\n");
    }
}
?>


and here's the login script:
Code:

<?php
define('IN_PHPBB', true);
$phpbb_root_path = 'forum/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length);
init_userprefs($userdata);
if(!$userdata['session_logged_in']) {
echo ' ';
?>
<form method="post" action="forum/login.php">
Name: <input class="post" type="text" name="username" size="12" />
Pass: <input class="post" type="password" name="password" size="12" />
Auto :<input class="text" type="checkbox" name="autologin" />
<input type="submit" class="mainoption" name="login" value="Log in" />

<font size="1" face="verdana, Arial, Helvetica, sans-serif">
<img src="images/icon_mini_search.gif" border="0" align="middle">&nbsp;<a href="forum/search.php">Search</a>
 &nbsp;
<img src="images/icon_mini_register.gif" border="0" align="middle">&nbsp;<a href="forum/profile.php?mode=register">Register</a></font>
   </form>
   

</font>


Thank you. I'm a newbie in php.

i mean the use of this function:
Code:
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
and other misc codes in both the script so that it is called only once.
Back to top
View user's profile Send private message
rc69
Site Admin
Site Admin



Member No.: 1
Joined: 05 Aug 2004
Posts: 152

PostPosted: Sun Dec 31, 2006 7:53 pm   Post subject: Reply with quote

In a well developed script, include() will probably be called multiple times. In this particular case, include() is including the functions neccessary to run the page.

Unfortunately, it looks like you copied that code from a tutorial and not phpBBs source. So the best help i can offer is to say, ask the original creator.

But i will say this, just from looking at it, it doesn't look like any of that code can be removed.
_________________
Current user reading this: Anonymous


Mind the gap.
Back to top
View user's profile Send private message Visit poster's website
santosh_iit32
newbie
newbie



Member No.: 90
Joined: 19 Nov 2006
Posts: 21
Location: India

PostPosted: Mon Jan 01, 2007 2:28 am   Post subject: Reply with quote

ok if thats the case. thank you so much.

I thought like in your script, parts of it could be removed if i'm using 2 mods from your site like the:

Code:
# Database info, or include a config.php file
$db_host = 'localhost'; # Change to your host
$db_user = 'anonymous'; # Change to your user name
$db_password = ''; # Change to your password
$db_name = 'forum'; # Change to your db name

mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());


which is the same. anyways thank you so much. i'll go ahead and use the script.
Back to top
View user's profile Send private message
santosh_iit32
newbie
newbie



Member No.: 90
Joined: 19 Nov 2006
Posts: 21
Location: India

PostPosted: Thu Jan 11, 2007 1:14 am   Post subject: Reply with quote

never mind about this coz i have use another script.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Deceptive Logic Forum Index -> PHP, Javascript, ASP, etc... All times are GMT
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 © 2001, 2005 phpBB Group