MyBB Community Forums

Full Version: Displaying News on your homepage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
This is my code

<?php

    $fid = 4;
    $limit = 5;
    $forumpath = 'forums/';

    chdir($forumpath);
    define("IN_MYBB", 1);
    require('http://sparkonline.net/forums/global.php');
    require_once('http://sparkonline.net/forums/inc/class_parser.php');
    $parser = new postParser;
    chdir('http://sparkonline.net/');
?>
<?php
    
    $query = $db->simple_select(TABLE_PREFIX.'threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select(TABLE_PREFIX.'posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);
            
            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => 'no', 
                            'filter_badwords' => 'yes', 
                            'allow_mycode' => 'yes', 
                            'allow_smilies' => 'yes', 
                            'nl2br' => 'yes', 
                            'me_username' => 'yes'
                            );
            $message = $parser->parse_message($row2['message'], $options);
            
            echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
            echo("{$message}<br /><br />");
            echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
        }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>

This is my error:

Quote:Direct initialization of this file is not allowed.

Please make sure IN_MYBB is defined.
Fatal error: Class 'postParser' not found in /home1/sparkonl/public_html/frog/app/frontend/classes/Page.php(192) : eval()'d code on line 11

Any ideas? I use FrogCMS as my CMS system.
try this:
<?php

    $fid = 4;
    $limit = 5;
    $forumpath = 'forums/';

//    chdir($forumpath);
    define("IN_MYBB", 1);
    require($forumpath . 'global.php');
    require_once($forumpath . 'inc/class_parser.php');
    $parser = new postParser;
//    chdir('http://sparkonline.net/');
?>
<?php
    
    $query = $db->simple_select('threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select('posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);
            
            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => 'no', 
                            'filter_badwords' => 'yes', 
                            'allow_mycode' => 'yes', 
                            'allow_smilies' => 'yes', 
                            'nl2br' => 'yes', 
                            'me_username' => 'yes'
                            );
            $message = $parser->parse_message($row2['message'], $options);
            
            echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
            echo("{$message}<br /><br />");
            echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
        }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>
I get this:

Quote:Fatal error: Call to a member function simple_select() on a non-object in /home1/sparkonl/public_html/forums/inc/class_datacache.php on line 72
it works whit me, but try this:
<?php

    $fid = 4;
    $limit = 5;
    $forumpath = 'forums/';

    define("IN_MYBB", 1);
    require($forumpath . 'global.php');
    require_once($forumpath . 'inc/class_parser.php');
    $parser = new postParser;

    $query = $db->simple_select('threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select('posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);

            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => 'no',
                            'filter_badwords' => 'yes',
                            'allow_mycode' => 'yes',
                            'allow_smilies' => 'yes',
                            'nl2br' => 'yes',
                            'me_username' => 'yes'
                            );
            $message = $parser->parse_message($row2['message'], $options);

            echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> -
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
            echo("{$message}<br /><br />");
            echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
        }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>
I'm looking for a small customization of the current code I'm using (which is already a little bit tweaked by MrD.). My current code is customized to pull posts from the forum only if the subject contains a certain text, in my case the text it needs to contain in order to show on the front page is [ARMA].

The only problem is that the script will also count those threads that don't have that specific line in the subject. So if my script is set to show only the first 6 posts, and 5 of those posts don't have [ARMA] in the subject line, the script will only show 1 post on the front page.

So basically what I'm trying to accomplish is that the script pulls the first 6 posts containing the [ARMA] tag, ignoring all other posts in reaching the post limit (of 6 in this case), so that it simply shows the first 6 posts containing [ARMA] tag.

I really hope somebody can help, because this is a crucial thing for me.

This is the complete code:

  <?php

    $fid = 2;
    $limit = 6;
    $forumpath = '../forum/';

    chdir($forumpath);
    define("IN_MYBB", 1);
    require('./global.php');
    require_once MYBB_ROOT."inc/class_parser.php";
    $parser = new postParser;
    chdir('../');
?>
  <span class="forumtext">
<?php

$outputtedCount = 0;
$query = $db->simple_select('threads', '*', "fid='2' ORDER BY tid DESC LIMIT {$limit}");
if($db->num_rows($query) > 0)
{
    while($row = $db->fetch_array($query))
    {
        if(strpos($row['subject'], '[ARMA]') !== FALSE)
        {
            $query2 = $db->simple_select('posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);

            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                        'allow_html' => '1',
                        'filter_badwords' => '1',
                        'allow_mycode' => '1',
                        'allow_smilies' => '1',
                        'nl2br' => '1',
                        'me_username' => '1'
                        );
            $message = $parser->parse_message($row2['message'], $options);
	    $subject = str_replace('[ARMA]', '', $row['subject']);
	    echo("<br><br><img src=core_images/icon_intel.jpg>&nbsp;<a href=\"http://www.tangodown.nl/forum/showthread.php?tid={$row['tid']}\">{$subject}</a><br>
            {$date} {$time} door <a href=\"http://www.tangodown.nl/forum/member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br><br><br>");
            echo("{$message}<br><br><br>");
            echo("<img src=core_images/icon_replies2.jpg>&nbsp;<a href=\"http://www.tangodown.nl/forum/showthread.php?tid={$row['tid']}\">{$row['replies']} Reacties</a><br><br><br><hr />");
            
            ++$outputtedCount;
        }
    }
}
if($outputtedCount == 0)
{
    echo 'Nothing to display.';
}
?>
try this one:
<?php

    $fid = 2;
    $limit = 6;
    $forumpath = '../forum/';

    chdir($forumpath);
    define("IN_MYBB", 1);
    require('./global.php');
    require_once MYBB_ROOT."inc/class_parser.php";
    $parser = new postParser;
    chdir('../');
?>
  <span class="forumtext">
<?php

$outputtedCount = 0;
$query = $db->simple_select('threads', '*', "fid='2' AND subject LIKE '%[ARMA]%' ORDER BY tid DESC LIMIT {$limit}");
if($db->num_rows($query) > 0)
{
    while($row = $db->fetch_array($query))
    {
        if(strpos($row['subject'], '[ARMA]') !== FALSE)
        {
            $query2 = $db->simple_select('posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);

            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                        'allow_html' => '1',
                        'filter_badwords' => '1',
                        'allow_mycode' => '1',
                        'allow_smilies' => '1',
                        'nl2br' => '1',
                        'me_username' => '1'
                        );
            $message = $parser->parse_message($row2['message'], $options);
        $subject = str_replace('[ARMA]', '', $row['subject']);
        echo("<br><br><img src=core_images/icon_intel.jpg>&nbsp;<a href=\"http://www.tangodown.nl/forum/showthread.php?tid={$row['tid']}\">{$subject}</a><br>
            {$date} {$time} door <a href=\"http://www.tangodown.nl/forum/member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br><br><br>");
            echo("{$message}<br><br><br>");
            echo("<img src=core_images/icon_replies2.jpg>&nbsp;<a href=\"http://www.tangodown.nl/forum/showthread.php?tid={$row['tid']}\">{$row['replies']} Reacties</a><br><br><br><hr />");

            ++$outputtedCount;
        }
    }
}
if($outputtedCount == 0)
{
    echo 'Nothing to display.';
}
?>
(2009-03-15, 02:48 PM)bombo Wrote: [ -> ]try this one:
Wow, thanks!! I just tested it and it seems to work correctly. You really helped me with a serious bottleneck that was holding me back, thanks! Big Grin
I got one other question about the chdir() command. The current command
chdir('../');
I assume refers to the root of the hosting account (or is it just moving one folder higher?)? Reason I'm asking is the following:

I'm running an add-on domain within a subfolder of my primary hosting account, something like /public_html/domain.nl/index.php

After I used the command to get to the forum that is running on the primary domain or in the root of the public_html folder
$forumpath = '../forum/';


I want to go back to that particular add-on domain folder. Should I set something like
chdir('../domain.nl/');
or is the command something else to go back?
the last chdir() must be pointing to the folder where the script stands.
(2009-03-15, 06:41 PM)bombo Wrote: [ -> ]the last chdir() must be pointing to the folder where the script stands.
Yeah, that's what I thought. But I'm not completely sure how to navigate exactly to the folder. Does "../" mean "up 1 folder" or does it mean "up to the root folder". I assume you can continue the path in the chdir command something like "../path/to/script/"?
chdir('../') means that it goes up just one folder.
However, chdir is not required to include the global file. An exact location of the global.php file is sufficient. Just use include/require to do so.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33