Page 1 of 1

MNN News

Posted: Sun Oct 25, 2009 10:44 am
by Ari Rahikkala
Well, Iain gave me the idea, so I figured I might give it a try. I quickly hacked up a display of the MNN News And Comment feed. Updated hourly. I'm not particularly happy with its positioning on the page though... I keep confusing it with the forum-related links above it... but didn't really have any better ideas where to put it. But maybe someone else does?

Re: MNN News

Posted: Sun Oct 25, 2009 11:25 am
by Jonas
It isn't bad! But maybe next to the banner (at the left to avoid confusion). :document

Re: MNN News

Posted: Sun Oct 25, 2009 1:12 pm
by Iskander Mirkdale
Ooh, thank you. Yes the positioning question is a good one, as the Malarbox does give Shireroth a unique header layout. I don't know if a horizontal ticker of sorts would look better, but that's what I had envisaged would work reasonably well with most forum header layouts.

Re: MNN News

Posted: Sun Oct 25, 2009 6:51 pm
by Erik Mortis
Could we add Harvey's thing?

Re: MNN News

Posted: Sun Oct 25, 2009 7:07 pm
by Harvey Steffke
Harvey's thing is with the rest of the links "Calendar - Wiki - Bank - Aurora - MCS - Chat"

Also, the MNN feed will display my stories when I write something current. In fact, it's displaying one of them now.

Re: MNN News

Posted: Sun Oct 25, 2009 10:12 pm
by Erik Mortis
Well then.. Goodo.

Re: MNN News

Posted: Sat Oct 31, 2009 3:27 pm
by Jonas
Ari, can you send me the code of the MNN Newsbox? Batavia wants to use it. :angel

Re: MNN News

Posted: Sat Oct 31, 2009 4:06 pm
by Ari Rahikkala
To be honest it's one of those things that consist of a lot of glue and little complicated code, so there's going to be almost as much work in integrating it as there was in writing it in the first place. But if you really want to know...

First, there's a script, called snarf_mnn.php, placed in my home directory at my hosting account:

Code: Select all

<?php

$xml = simplexml_load_file ("http://www.xfruits.com/micronations/?id=67998");

if (!$xml)
	die ("Couldn't fetch MNN RSS XML");

$str = "<ul>";

$n = 5;

for ($i = 0; $i < $n && $xml->channel->item[$i]; $i++) {
  $str .= "<li><a href=\"" . $xml->channel->item[$i]->link . "\">" . $xml->channel->item[$i]->title . "</a></li>";
}

$str .= "</ul>";

file_put_contents ("public_html/shireroth/forum/mnn_update.txt", $str);

?>
Very straightforward as you can see. Just fetches the micronations.net RSS, and outputs a list of the first five items. There's a reason it's called Really Simple Syndication, you know. Also in the straightforwardness department it'll break if there are less than five items in the stream, but I'm assuming that will never happen :p.

It's called hourly from cron - how to call things from cron is completely host-dependent, for instance on Bluehost there's a "cron jobs" option in the control panel, and the program for running PHP scripts is called php5-cli. But you don't really have a choice other than to know how to run scheduled jobs if you want to make any use of this script.

Anyways, as you can see it creates a file named mnn_update.txt, conveniently right there in the forum directory. This file is then read in includes/functions.php, in the function page_header():

Code: Select all

$mnn_text = file_get_contents ($phpbb_root_path . "mnn_update.txt");
^ goes anywhere in that function before the big assign_vars block

Code: Select all

'MNN' => $mnn_text,
^ goes inside the big assign_vars block... come to think of it you don't even need the variable there...

Anyways, now the template variable "MNN" contains the list of links to the newest news at the MNN. For instance in the Malarbor template it's added in as simply as putting in this in the appropriate place:

Code: Select all

            <div style="border: 2px solid black; background-color: #000066; margin-top: 5em;">
            <center>MNN news</center>
              {MNN}
            </div>


So, yeah, basically. In so many words, if you already are competent know your php and phpBB and how to configure stuff at your webhost, most of this code is not of much help since you already know how to write it, and if you aren't, you won't be able to integrate it. So it's not really all that useful altogether. But I figured that the best way of explaining why you don't really want to see the code would be to show the code and explain why you didn't really want to see it :p