News:

Follow us on Bluesky!

Main Menu

News Box Mod

Started by suser, December 06, 2006, 05:23:54 PM

Previous topic - Next topic

suser

I did a search of the forum and am not happy with the answers i found so maybe someone can enlighten me. I want to use a php script to read from a text file on the server and display its contents in the news box. One post i ran accross just said "its not allowed". I guess all i really need to know is what files contain the code for news box. Can anyone tell me at least that much if not more about doing this? thanks in advance

vbgamer45

The template that has the newsbox is in index.template.php of your theme folder.
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

suser

this is what i have for my code (this is just a snippet). Can anyone tell me why it causes my website not to work? The code in red is what i had added to try and get the contents of a text file to display in the news box.

<td width="262" style="padding-left: 5px;" valign="top">';

        // Show a random news item? (or you could pick one from news_lines...)
        if (!empty($settings['enable_news']))
                echo '
                                        <div class="headertitles" style="width: 260px;"><img src="', $settings['images_url'], '/blank.gif" height="12" alt="" /></div>
                                        <div class="headerbodies" style="width: 260px; position: relative; background-image: url(', $settings['images_url'], '/box_bg.gif); margin-bottom: 8px;">
                                                <img src="', $settings['images_url'], '/', $context['user']['language'], '/newsbox.gif" style="position: absolute; left: -1px; top: -16px;" alt="" />
                                                <div style="height: 50px; overflow: auto; padding: 5px;" class="smalltext">', $lines = file('test.txt');

foreach ($lines as $line_num => $line) {
   echo "Line #{$line_num} : " . htmlspecialchars($line) . "<br />\n";
, '</div>
                                        </div>';

vbgamer45

Its not good code should be something like



<td width="262" style="padding-left: 5px;" valign="top">';

        // Show a random news item? (or you could pick one from news_lines...)
        if (!empty($settings['enable_news']))
                echo '
                                        <div class="headertitles" style="width: 260px;"><img src="', $settings['images_url'], '/blank.gif" height="12" alt="" /></div>
                                        <div class="headerbodies" style="width: 260px; position: relative; background-image: url(', $settings['images_url'], '/box_bg.gif); margin-bottom: 8px;">
                                                <img src="', $settings['images_url'], '/', $context['user']['language'], '/newsbox.gif" style="position: absolute; left: -1px; top: -16px;" alt="" />
                                                <div style="height: 50px; overflow: auto; padding: 5px;" class="smalltext">';

$lines = file('test.txt');
foreach ($lines as $line_num => $line)
   echo "Line #{$line_num} : " . htmlspecialchars($line) . "<br />\n";

echo '</div>
                                        </div>';
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

suser

It doesnt like that either. I get the generic "Template Parse Error!" message.

suser

#5
I changed the code to the following and now my page displays but it doesnt display the text of my test.txt file. I added a simple "hello world" script just to make sure it was running the code.


<td width="262" style="padding-left: 5px;" valign="top">';

        // Show a random news item? (or you could pick one from news_lines...)
        if (!empty($settings['enable_news']))
                echo '
                                        <div class="headertitles" style="width: 260px;"><img src="', $settings['images_url'], '/blank.gif" height="12" alt="" /></div>
                                        <div class="headerbodies" style="width: 260px; position: relative; background-image: url(', $settings['images_url'], '/box_bg.gif); margin-bottom: 8px;">
                                                <img src="', $settings['images_url'], '/', $context['user']['language'], '/newsbox.gif" style="position: absolute; left: -1px; top: -16px;" alt="" />
                                                <div style="height: 50px; overflow: auto; padding: 5px;" class="smalltext">';





echo "hello world";

$handle = @fopen('test.txt', "r");
if ($handle) {
    while (!feof($handle)) {
        $lines[] = fgets($handle, 4096);
    }
    fclose($handle);
}


echo '</div>






                                        </div>';

vbgamer45

Were is the test.txt file located? try to use an exact path to the file. or relative path.
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

suser

i tried an exact path but it didnt work. any other suggestions?

vbgamer45

try using file_get_contents function instead
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

suser

Quote from: vbgamer45 on December 07, 2006, 05:17:05 PM
try using file_get_contents function instead

This worked, thank you so much for your help.

Advertisement: