Parse Attachments

Discussion forum for MOD Writers regarding MOD Development.
Locked
EAnushan
Registered User
Posts: 17
Joined: Fri Aug 15, 2008 1:53 pm

Parse Attachments

Post by EAnushan »

Recently I've been trying to pull a post from my forum and turn it into an html page for my website. After a bit of work, I got all that to work except for one thing.

Most bbcode gets parsed correctly, except for attachments. Attachments just show up like this:
attachmentparse.JPG
attachmentparse.JPG (60.28 KiB) Viewed 832 times
I'm wondering how to get this to display properly with my php file. I use php and then an html page for the template. I've attached both below.

page.php

Code: Select all

<?php
/*
*
* @package phpBB3 Portal  a.k.a canverPortal  ( www.phpbb3portal.com )
* @version $Id: portal.php,v 1.11 2008/02/09 08:18:13 angelside Exp $
* @copyright (c) Canver Software - www.canversoft.net
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

// Note: If you would like to have the portal in a different location than in the main phpBB3 directory
// You must change the following variable, and change the 'U_PORTAL' template variable in functions.php
define('IN_PHPBB', true);
define('IN_PORTAL', true);
define('PHPBB_ROOT_PATH', './');
define('PORTAL_ROOT_PATH','./portal/');

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$portal_root_path = (defined('PORTAL_ROOT_PATH')) ? PORTAL_ROOT_PATH : './portal/';

$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($portal_root_path . '/includes/functions.'.$phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('portal');

$forum = $_GET['forum'];
$topic = $_GET['topic'];

// show login box and user menu

//  acp de aç/kapa yok, dil dosyasýna ek: hiç doðumgünü yoksa evet seçili olsa bile blok görünmez.
// SQL bilgisi yok -  - SQL eklenirse dil deðiþkeni de eklenmeli
//if ($config['portal_user_menu'])
//{
	// only registered user see user menu
	if ($user->data['is_registered'])
	{
		include($portal_root_path . '/block/user_menu.'.$phpEx);
	}
	else
	{
		include($portal_root_path . '/block/login_box.'.$phpEx);
	}
//}

if ($config['portal_attachments'])
{
	include($portal_root_path . '/block/attachments.'.$phpEx);
}

if ($config['portal_recent']) 
{ 
	include($portal_root_path . '/block/recent.'.$phpEx);
}

if ($config['portal_advanced_stat'])
{
	include($portal_root_path . '/block/statistics.'.$phpEx);
}

if ($config['portal_minicalendar'])
{
	include($portal_root_path . '/block/mini_cal.'.$phpEx);
}

if ($config['portal_link_us'])
{
	include($portal_root_path . '/block/link_us.'.$phpEx);
}

if ($config['portal_leaders'])
{
	include($portal_root_path . '/block/leaders.'.$phpEx);
}

if ($config['portal_wordgraph'])
{
	include($portal_root_path . '/block/wordgraph.'.$phpEx);
}

if ( $config['portal_poll_topic'] && $config['portal_poll_topic'] != "" )
{
	include($portal_root_path . '/block/poll.'.$phpEx);
}

if ($config['portal_load_last_visited_bots'])
{
	include($portal_root_path . '/block/latest_bots.'.$phpEx);
}

if ($config['portal_top_posters'])
{
	include($portal_root_path . '/block/top_posters.'.$phpEx);
}

if ($config['portal_latest_members'])
{
	include($portal_root_path . '/block/latest_members.'.$phpEx);
}

if ($config['portal_random_member'])
{
	include($portal_root_path . '/block/random_member.'.$phpEx);
}

if ($config['portal_clock'])
{
	$template->assign_vars(array(
		'S_DISPLAY_CLOCK' => true,
	));
}

if ($config['portal_links'])
{
//	include($portal_root_path . '/block/links.'.$phpEx);
	$template->assign_vars(array(
		'S_DISPLAY_LINKS' => true,
	));
}

if ($config['portal_welcome'])
{
	$template->assign_vars(array(
		'S_DISPLAY_WELCOME' 	=> true,
		'PORTAL_WELCOME_INTRO'	=> $config['portal_welcome_intro'],
	));
}

if ($config['portal_announcements'])
{
	include($portal_root_path . '/block/announcements.'.$phpEx);
	$template->assign_vars(array(
		'S_ANNOUNCE_COMPACT' => ($config['portal_announcements_style']) ? true : false,
	));
}

if ($config['portal_news'])
{
	include($portal_root_path . '/block/news.'.$phpEx);
	$template->assign_vars(array(
		'S_NEWS_COMPACT' => ($config['portal_news_style']) ? true : false,
	));
}

if ($config['portal_pay_s_block'] or $config['portal_pay_c_block'])
{
	include($portal_root_path . '/block/donate.'.$phpEx);
}


if ($config['portal_ads_small'])
{
	$template->assign_vars(array(
		'S_ADS_SMALL' 	=> ($config['portal_ads_small_box']) ? true : false,
		'ADS_SMALL_BOX'	=> $config['portal_ads_small_box'],
	));
}

if ($config['portal_ads_center'])
{
	$template->assign_vars(array(
		'S_ADS_CENTER' 		=> ($config['portal_ads_center_box']) ? true : false,
		'ADS_CENTER_BOX'	=> $config['portal_ads_center_box'],
	));
}


// acp de aç/kapa yok - SQL bilgisi yok - SQL eklenirse dil deðiþkeni de eklenmeli
if ($user->data['is_registered']/* and $config['portal_friends']*/)
{
	include($portal_root_path . '/block/friends.'.$phpEx);
}

// acp de aç/kapa yok - SQL bilgisi yok - SQL eklenirse dil deðiþkeni de eklenmeli
// dil dosyasýna ek: hiç doðumgünü yoksa evet seçili olsa bile blok görünmez.
//if ($config['show_birthdays'])
//{
	include($portal_root_path . '/block/birthday_list.'.$phpEx);
//}

// acp de aç/kapa yok - SQL bilgisi yok - SQL eklenirse dil deðiþkeni de eklenmeli
//if ($config['show_whois_online'])
//{
	include($portal_root_path . '/block/whois_online.'.$phpEx);
//}

// acp de aç/kapa yok - SQL bilgisi yok - SQL eklenirse dil deðiþkeni de eklenmeli
//if ($config['show_search'])
//{
	include($portal_root_path . '/block/search.'.$phpEx);
//}

// acp de aç/kapa yok - SQL bilgisi yok - SQL eklenirse dil deðiþkeni de eklenmeli
//if ($config['change_style'])
//{
//	include($portal_root_path . '/block/change_style.'.$phpEx); // stil seçince hata veriyor
//}


        //-- Fetch the data from the specified fora
        $bbcode = new bbcode();
        $news_fora_id = array( $forum ); // Change in the fora id's you need
		$news_topic_id = array( $topic );
        $topic_count = '10'; // Change in the number of topics you want to show.
	
        $query = "
                SELECT p.topic_id, p.forum_id, p.post_time, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, u.user_id, u.username, u.user_rank, u.user_colour, user_type,  t.topic_replies, t.topic_title, t.topic_views,
                      (
                            SELECT COUNT( post_id )
                            FROM " . POSTS_TABLE . "
                                WHERE topic_id = p.topic_id
                      ) AS aantal_posts
                FROM " . POSTS_TABLE . " AS p, " . USERS_TABLE . " AS u, " . TOPICS_TABLE . " AS t
                    WHERE " . $db->sql_in_set( 'p.forum_id', $news_fora_id ) . " AND " . $db->sql_in_set( 't.topic_id', $news_topic_id ) . "
                        AND u.user_id = p.poster_id
                        AND t.topic_id = p.topic_id
                GROUP BY topic_id
                ORDER BY topic_id DESC
                LIMIT 0, {$topic_count}
                ";
      
        //die('<pre>' . $query );
    $result = $db->sql_query( $query );

    if( $row = $db->sql_fetchrow($result) )
    {
            // Parse the message and subject
            $message = censor_text($row['post_text']);

            // Second parse bbcode here
            if ($row['bbcode_bitfield'])
            {
                $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
            }

            $message = bbcode_nl2br($message); 
            $message = smiley_text($message);
			
			$userprofile = (($row['user_type'] == USER_NORMAL || $row['user_type'] == USER_FOUNDER) && $row['user_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $row['user_id']) : '';
             
            // Send data to output var
        $output .= "<table class=\"tablebg\" cellspacing=\"1\" width=\"100%\">";
 		$output .= "<tr>";
		$output .= "<td class=\"cat\"><a href=\"" . $phpbb_root_path . "viewtopic.php?f={$row['forum_id']}&t={$row['topic_id']}\" title=\""  . censor_text($row['post_subject']) . "\"><strong>".censor_text($row['post_subject'])."</strong></a></td>";		
					
		$output .= "</tr>";

		$output .= "<tr class=\"row1\">";
		$output .= "<td>";
		
		$output .= "<span class=\"gensmall\" style=\"float: left;\">Poster: <strong><a href=\"" . $userprofile . "\"><b style=\"color:#" . $row[user_colour] ."\">" . $row['username'] . "</b></a></strong>";
		$output .= "</span>";
		$output .= "<span class=\"gensmall\" style=\"float: right;\">" . date("D M d, Y g:i a",  $row['post_time']);
		$output .= "</span>";
		$output .= "<br />";
		$output .= "<br />";
		
        $output .= "<div class=\"postbody\">";
		
        $output .= $message;
        $output .= "<br />";
		$output .= "<br />";
		

        $output .= "</div>";
       
        $output .= "</td>";
		$output .= "</tr>";
		
		
		$output .= "<tr class=\"row1\">";
		$output .= "<td>";
		
		$output .= "<span style=\"float: left;\">";
		
		$output .= "Views: " . $row['topic_views'];
		
		$output .= " &nbsp;&bull;&nbsp; <a href=\"/Community/Forum/" . "viewtopic.php?f={$row['forum_id']}&t={$row['topic_id']}\" title=\"View comments\">"; 
        $output .= "Comments: ";
        $output .= $row['topic_replies'];
        $output .= "</a>";
		
		$output .= " &nbsp;&bull;&nbsp; <a href=\"/Community/Forum/" . "posting.php?mode=reply&f={$row['forum_id']}&t={$row['topic_id']}\" title=\""  . censor_text($row['post_subject']) . "\">"; 
        $output .= "Write comments";
        $output .= "</a>";
		
		$output .= "</span>";
		
		$output .= "<span style=\"float: right;\">";
		$output .= "<a href=\"#wrapheader\" class=\"top\" title=\"Top\">Top</a>";
		$output .= "</span>";
		
		$output .= "</td>";
		$output .= "</tr>";
		
        $output .= "</table>";
		$output .= "<br />";
		
    }
	else{
	$output .= "<table class=\"tablebg\" cellspacing=\"1\" width=\"100%\">";
	 		$output .= "<tr>";
			$output .= "<th>Information</th>";		
						
			$output .= "</tr>";

			$output .= "<tr class=\"row1\">";
			$output .= "<td>";
			$output .= "<center>The requested topic does not exist.</center>";
			$output .= "</td>";
			$output .= "</tr>";
			$output .= "</table>";
			
			$output .= "<br />";
	}


$template->assign_vars(array(
	'S_DISPLAY_JUMPBOX' 	=> true, // SQL + ACP eklenecek
	'PORTAL_LEFT_COLLUMN' 	=> $config['portal_left_collumn_width'],
	'PORTAL_RIGHT_COLLUMN' 	=> $config['portal_right_collumn_width'],
	'OUTPUT'				=> $output,
));

// output page
page_header($user->lang['PORTAL']);
//page_header($config['sitename']);

$template->set_filenames(array(
	'body' => 'portal/page_body.html'
));

// SQL + ACP eklenecek
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

page_footer();

?>
page_body.html

Code: Select all

<!-- INCLUDE portal/leftblockarea.html -->

<!-- [+] center block area -->
	<td valign="top">	
		<!-- IF S_USER_LOGGED_IN -->
		    {OUTPUT}
		<!-- ENDIF -->
		
		<!-- IF S_DISPLAY_WORDGRAPH -->
			<!-- INCLUDE portal/block/wordgraph.html -->
		<!-- ENDIF -->
		
		<!-- IF S_DISPLAY_JUMPBOX -->
			<!-- INCLUDE portal/block/jumpbox.html -->
		<!-- ENDIF -->	

	</td>
<!-- [-] center block area -->

<!-- INCLUDE portal/rightblockarea.html -->
I saw a function called parse_attachments in the functions_content.php file, but I couldn't get it to work. Is there a fix to get attachments to show up?

Thanks for any help :)
User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 52724
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Parse Attachments

Post by stevemaury »

This is more of a custom MOD question or custom web writing question, than a phpbb support question. I am moving this to MOD Writer's Discussion, where I think you will get better help.
I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)
EAnushan
Registered User
Posts: 17
Joined: Fri Aug 15, 2008 1:53 pm

Re: Parse Attachments

Post by EAnushan »

I got the solution

Find

Code: Select all

            $message = bbcode_nl2br($message); 
            $message = smiley_text($message);
Add after

Code: Select all

 // Parse inline attachments
                            $sql_attach = 'SELECT *
                                    FROM ' . ATTACHMENTS_TABLE . '
                                    WHERE ' . $db->sql_in_set('post_msg_id', $row['topic_first_post_id']) . '
                                            AND in_message = 0
                                    ORDER BY filetime DESC, post_msg_id ASC';

                            $result_attach = $db->sql_query($sql_attach);

                            while ($row_attach = $db->sql_fetchrow($result_attach))
                            {
                                    $attachments[$row_attach['post_msg_id']][] = $row_attach;
                            }
                            $db->sql_freeresult($result_attach);

                            if (!empty($attachments[$row['topic_first_post_id']]))
                            {
                                    parse_attachments($forum_id, $message, $attachments[$row['topic_first_post_id']], $update_count);
                            }
I got it from this thread: http://www.phpbb3portal.com/viewtopic.p ... t&start=10
Locked

Return to “[3.0.x] MOD Writers Discussion”