Full Site Integration

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10339
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: Full Site Integration

Post by Noxwizard » Wed Jan 28, 2009 12:03 am

_FILES doesn't have a replacement.
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.

Vespa
Registered User
Posts: 93
Joined: Sun Nov 03, 2002 10:25 am
Name: Federico Villa

Re: Full Site Integration

Post by Vespa » Wed Jan 28, 2009 7:09 am

So I can use as it is now...thanks for reply.

One more question, is there a way to retrieve from the PHPbb database the title of a thread starting from an URL like the following one?

Code: Select all

http://www.mysite.net/forums/viewtopic.php?f=26&t=969
I guess I have to parse the string, get the f and t value...and after that? What code to get the post's Title?

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10339
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: Full Site Integration

Post by Noxwizard » Wed Jan 28, 2009 5:18 pm

You can use preg_match_all() to pull out the numbers.

Code: Select all

$link = 'http://www.mysite.net/forums/viewtopic.php?f=26&t=969';
$matches = array();
preg_match_all('#([ft])=([0-9]+)#', $link, $matches);

$topic_id = 0;
if(sizeof($matches) == 3)
{
    if($matches[1][0] == 't')
    {
        $topic_id = $matches[2][0];
    }
    else
    {
        $topic_id = $matches[2][1];
    }
}

$sql = 'SELECT topic_title FROM ' . TOPICS_TABLE . ' WHERE topic_id = ' . (int)$topic_id;
$result = $db->sql_query_limit($sql, 1);
$title = $db->sql_fetchfield('topic_title');
$db->sql_freeresult($result); 
That's set up so that it accepts the f and t in any order.
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.

Vespa
Registered User
Posts: 93
Joined: Sun Nov 03, 2002 10:25 am
Name: Federico Villa

Re: Full Site Integration

Post by Vespa » Wed Jan 28, 2009 5:34 pm

Outstanding, your help is priceless...as usual. :)

Just a question...for what I understand in the code below, the result are stored into the $title array. Am I wrong?

Code: Select all

$title = $db->sql_fetchfield('topic_title');
Is it's true I can print the topic title parsing the array, correct?

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10339
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: Full Site Integration

Post by Noxwizard » Wed Jan 28, 2009 5:46 pm

Fetch_field grabs the data from the specified field, so $title is just a string.
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.

Vespa
Registered User
Posts: 93
Joined: Sun Nov 03, 2002 10:25 am
Name: Federico Villa

Re: Full Site Integration

Post by Vespa » Thu Jan 29, 2009 7:48 pm

Thanks Nox, I see.
I'm sorry but I didn't explain very well my trouble.
In my page there is a field form to pass a list of Threads links; the form field is a textarea field and user can insert several links in several lines. So the page forward to the cript a text field with the links separated by the new line code.

The first action I'll perform is to split the links with:

Code: Select all

$listLinks = explode('\n',$query_data[links])
I could iterate the $listLinks array and use tyour code above, right?

BTW, what does the following line mean?

Code: Select all

$db->sql_freeresult($result); 

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10339
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: Full Site Integration

Post by Noxwizard » Thu Jan 29, 2009 9:13 pm

Yes, you will need to iterate over the links and run that code on each one.
Noxwizard wrote:
X.Homer.X wrote:what does freeresult do?
It frees the memory associated with the SELECT statement you just ran.
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.

Moka2
Registered User
Posts: 141
Joined: Sun Sep 28, 2008 8:12 pm

Re: Full Site Integration

Post by Moka2 » Wed Feb 11, 2009 6:14 am

I think I posted this question but it might have gotten lost or something...I dunno.

Nox you gave me a function for submitting a post, and it works perfectly, but now I'm wondering...is there a function in phpBB in which you can edit a post?

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10339
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: Full Site Integration

Post by Noxwizard » Wed Feb 11, 2009 5:41 pm

Noxwizard wrote:
Moka2 wrote:But is there a function to edit a post? I need to do this outside of phpbb

Code: Select all

$data = generate_text_for_edit($text, $uid, $flags);
Where $uid is the post's bbcode_uid and $flags is:

Code: Select all

$flag = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
The message is stored in $data['text'].
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.

User avatar
Virtuality
QA Team
Posts: 109
Joined: Sat Dec 14, 2002 4:44 pm
Location: Stockholm, Sweden
Contact:

Re: Full Site Integration

Post by Virtuality » Thu Feb 12, 2009 8:27 pm

Hello everyone,

This thread is awesome and it has helped me a lot. But I must admit I have not read all the 72 pages, I found it late. :oops:

What I'm trying to do is; extract a specific post's/topic's content and then display it, BBCode parsed and all, outside of the forum.
I found one of Noxwizard's posts about this (you're the best, by the way!) and now I have this code:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

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

//
// Configuration
//
$forum_id = 7;        //Forum ID to pull posts from
$num_posts = 5;        //Number of posts to display

//
// Auth
//
$can_read_forum = $auth->acl_getf('f_read');    //Get the forums the user can read from
$forum_id_ary = array_keys($can_read_forum);    //Rework the array some
unset($can_read_forum);

//
// Recent posts
//
if(array_key_exists($forum_id, $forum_id_ary))    //See if the user is authed to read from that forum
{
    $sql = 'SELECT p.post_id, t.topic_id, p.post_subject, p.post_text, p.post_time, p.bbcode_bitfield, p.bbcode_uid, u.username
            FROM ' . TOPICS_TABLE . ' t 
                INNER JOIN ' . POSTS_TABLE . ' p ON (t.topic_id = p.topic_id)
                    INNER JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)
                        WHERE t.topic_approved = 1
                            AND p.post_approved = 1
                            AND p.forum_id = ' . $forum_id . ' 
                            AND p.post_id = t.topic_first_post_id
                        ORDER BY p.post_time DESC';

    $result = $db->sql_query_limit($sql, $num_posts);
    $row = $db->sql_fetchrowset($result);

    for($i = 0; $i < $num_posts; $i++)
    {
        $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&t=' . $row[$i]['topic_id'] . '&p=' . $row[$i]['post_id'] . 'p' . $row[$i]['post_id']);

        $uid = $bitfield = $options = '';
        $allow_bbcode = $allow_smilies = $allow_urls = true;
        $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);

        $message = generate_text_for_display($row[$i]['post_text'], $row[$i]['bbcode_uid'], $row[$i]['bbcode_bitfield'], $flags);

        echo '<div class="newsposts"><h4><a href="' . $post_url . '">' . censor_text($row[$i]['post_subject']) . '</a></h4>
              <h5>Posted: ' . $row[$i]['username'] . ' @ ' . date('D M d, Y g a', $row[$i]['post_time']) . '</h5>
              <p>' . $message . '</p>
                </div>';
    }

    $db->sql_freeresult($result);
}

// Assign index specific vars
$template->assign_vars(array(
	'TOTAL_POSTS'	=> sprintf($user->lang[$l_total_post_s], $total_posts),
	'TOTAL_TOPICS'	=> sprintf($user->lang[$l_total_topic_s], $total_topics),
	'TOTAL_USERS'	=> sprintf($user->lang[$l_total_user_s], $total_users),
	'NEWEST_USER'	=> sprintf($user->lang['NEWEST_USER'], get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])),

	'S_LOGIN_ACTION'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),

	'U_MARK_FORUMS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums') : '',
	'U_MCP'				=> ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=front', true, $user->session_id) : '')
);

// Output page
// www.phpBB-SEO.com SEO TOOLKIT BEGIN - META
$seo_meta->meta['meta_desc'] = $seo_meta->meta_filter_txt($config['sitename'] . ' : ' .  $config['site_desc']);
$seo_meta->meta['keywords'] = $seo_meta->make_keywords($seo_meta->meta['meta_desc']);
// www.phpBB-SEO.com SEO TOOLKIT END - META

page_header('xx);

$template->set_filenames(array(
    'body' => 'startpage_body.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
But it only results in:

Posted: @ Thu Jan 01, 1970 1 am
Posted: @ Thu Jan 01, 1970 1 am
Posted: @ Thu Jan 01, 1970 1 am
Posted: @ Thu Jan 01, 1970 1 am
Posted: @ Thu Jan 01, 1970 1 am

And yes, forum ID 7 has posts in it!

Thanks a lot for any help.
Jonathan “Virtuality” Gulbrandsen - phpBB 2.x & 3.x Swedish Translator
phpbb-se.com - phpBB på svenska! | Development board for the Swedish translation of phpBB3

Moka2
Registered User
Posts: 141
Joined: Sun Sep 28, 2008 8:12 pm

Re: Full Site Integration

Post by Moka2 » Thu Feb 12, 2009 10:10 pm

Lol, whoops sorry :oops:

Where can I find the $user->format_date() function? I need to put a specific date into the database, which happens to be before the board was made. I can't make sense of the numbers such as "1231830613" without seeing the function.

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10339
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: Full Site Integration

Post by Noxwizard » Fri Feb 13, 2009 9:09 am

@Virtuality: Where did you get that code? I'm trying to update them all as I find them, because part of it is incorrect. There's a slight problem with the auth check, and as you noticed, the post display if there's less than what you've specified. Use this:

Code: Select all

<?php
    //
    // Configuration
    //
    $forum_id = 23;        //Forum ID to pull posts from
    $num_posts = 10;        //Number of posts to display

    //
    // Auth
    //
    $can_read_forum = $auth->acl_getf('f_read');    //Get the forums the user can read from
    $forum_id_ary = array();
    foreach($can_read_forum as $key => $forum)
    {
        if($forum['f_read'] != 0)
        {
            $forum_id_ary[] = $key;
        }
    }    //Rework the array some
    unset($can_read_forum);

    //
    // Recent posts
    //
    if(sizeof($forum_id_ary))    //See if the user is authed to read from that forum
    {
        $sql = 'SELECT p.post_id, t.topic_id, p.post_subject, p.post_text, p.post_time, p.bbcode_bitfield, p.bbcode_uid, u.username
                FROM ' . TOPICS_TABLE . ' t 
                    INNER JOIN ' . POSTS_TABLE . ' p ON (t.topic_id = p.topic_id)
                        INNER JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)
                            WHERE p.forum_id = ' . $forum_id . ' 
                                AND p.post_id = t.topic_first_post_id
                            ORDER BY p.post_time DESC';
   
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrowset($result);

        foreach($row as $post)
        {
            $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&t=' . $post['topic_id'] . '&p=' . $post['post_id'] . 'p' . $post['post_id']);

            $uid = $bitfield = $options = '';
            $allow_bbcode = $allow_smilies = $allow_urls = true;
            $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);

            $message = generate_text_for_display($post['post_text'], $post['bbcode_uid'], $post['bbcode_bitfield'], $flags);

            echo '<div><span class="headline"> ' . censor_text($post['post_subject']) . '</span><br>
                  <span class="headlinedate">Posted: ' . date('D M d, Y', $post['post_time']) . '</span><br>
                    </div>';
        }

        $db->sql_freeresult($result); 
    }
    ?>
You'll need to add back the rest of your code.


@Moka2: The times are stored as a unix timestamp. If you need to generate a timestamp from a date, use mktime().
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.

User avatar
Virtuality
QA Team
Posts: 109
Joined: Sat Dec 14, 2002 4:44 pm
Location: Stockholm, Sweden
Contact:

Re: Full Site Integration

Post by Virtuality » Fri Feb 13, 2009 10:19 am

Noxwizard wrote:@Virtuality: Where did you get that code? I'm trying to update them all as I find them, because part of it is incorrect. There's a slight problem with the auth check, and as you noticed, the post display if there's less than what you've specified. Use this:

Code: Select all

<?php
    //
    // Configuration
    //
    $forum_id = 23;        //Forum ID to pull posts from
    $num_posts = 10;        //Number of posts to display

    //
    // Auth
    //
    $can_read_forum = $auth->acl_getf('f_read');    //Get the forums the user can read from
    $forum_id_ary = array();
    foreach($can_read_forum as $key => $forum)
    {
        if($forum['f_read'] != 0)
        {
            $forum_id_ary[] = $key;
        }
    }    //Rework the array some
    unset($can_read_forum);

    //
    // Recent posts
    //
    if(sizeof($forum_id_ary))    //See if the user is authed to read from that forum
    {
        $sql = 'SELECT p.post_id, t.topic_id, p.post_subject, p.post_text, p.post_time, p.bbcode_bitfield, p.bbcode_uid, u.username
                FROM ' . TOPICS_TABLE . ' t 
                    INNER JOIN ' . POSTS_TABLE . ' p ON (t.topic_id = p.topic_id)
                        INNER JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)
                            WHERE p.forum_id = ' . $forum_id . ' 
                                AND p.post_id = t.topic_first_post_id
                            ORDER BY p.post_time DESC';
   
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrowset($result);

        foreach($row as $post)
        {
            $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&t=' . $post['topic_id'] . '&p=' . $post['post_id'] . 'p' . $post['post_id']);

            $uid = $bitfield = $options = '';
            $allow_bbcode = $allow_smilies = $allow_urls = true;
            $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);

            $message = generate_text_for_display($post['post_text'], $post['bbcode_uid'], $post['bbcode_bitfield'], $flags);

            echo '<div><span class="headline"> ' . censor_text($post['post_subject']) . '</span><br>
                  <span class="headlinedate">Posted: ' . date('D M d, Y', $post['post_time']) . '</span><br>
                    </div>';
        }

        $db->sql_freeresult($result); 
    }
    ?>
You'll need to add back the rest of your code.
Hi Noxwizard,

Huge thanks, that code worked perfectly. I found the code that I was using previously in this thread, I'll try to find it in a bit.

One thing, is it possible to get this code to parse all BBCodes, including images? Because currently it makes it into a link. Attachments aren't too important, I guess that would be quite complicated. But images would be awesome. :)
Jonathan “Virtuality” Gulbrandsen - phpBB 2.x & 3.x Swedish Translator
phpbb-se.com - phpBB på svenska! | Development board for the Swedish translation of phpBB3

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10339
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: Full Site Integration

Post by Noxwizard » Fri Feb 13, 2009 6:02 pm

It seems to work here: http://theexiled.pwnageservers.com/late ... _posts.php

Your code does need a small change, another auth issue.
Change:

Code: Select all

if(sizeof($forum_id_ary))
to:

Code: Select all

if(array_key_exists($forum_id, $forum_id_ary))
That part was originally for pulling from every forum.

This happens on my portal MOD, but that's because I call strip_bbcode() on the text first.
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.

traxionn
Registered User
Posts: 27
Joined: Tue Jan 27, 2009 3:26 pm

Re: Full Site Integration

Post by traxionn » Sat Feb 14, 2009 5:28 pm

a small question

what is the generate bbcode function in phpbb ?

i would like to have the same bbcode (ubb) in and outside the forum

Code: Select all

[b]bold[/b] // bbcode
//to
<b>bold</b>//html code

Locked

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