PDA

View Full Version : [RELEASE v2.x] OPNews v1.0 << Not just another 'news' script.


merk
27 Aug 2001, 12:03
Well, after finding 'PluhNews', i thought to myself, why not create something that uses templates, and the $DB_site class?

Well, after a bit of twiddling, i reduced the querys to just one, and Got it working, took a while tho D:

First off, youll need to create 2 templates.

newsbit:

Posted By <a href="$forumspath/member.php?s=&action=getinfo&userid=$newsarray[postuserid]"><b>$newsarray[postusername]</b></a> at <i>$dateposted</i>
</center>

<blockquote></a>$cookedthread</blockquote><center><a href="$forumspath/showthread.php?s=&threadid=$newsarray[threadid]"><b>$newsarray[replycount]</b> $commenttext</a> Last comment was by <b>$newsarray[lastposter]</b></a></center>

<hr noshade height="1" width="60%">

This is just example code, basically the same as PluhNews' Code, i dont have time to make it a bit mroe spicey, but im sure you can work it out.

shownews:

Your Header Code Here

$newsbits

Your Footercode here.


And finally, create news.php in the forum root directory, and put this in it:

<?
error_reporting(7);
$templatesused='header,headinclude,phpheader,newsbit,shownews';
$loadbirthdays=1;
$loadmaxusers=1;

//Configuration Options
//What is the ID of your News forum?
$newsforums = 107;

//How many news items should be displayed?
$newsitems = 10;

//Path to your forums directory (leave out trailing slash)
$forumspath = "/forum";

require('./global.php');

$newsquery = "SELECT thread.*, post.*";
$newsquery .= " FROM thread,post";
$newsquery .= " WHERE post.threadid=thread.threadid";
$newsquery .= " AND thread.forumid=$newsforums";
$newsquery .= " GROUP BY thread.threadid";
$newsquery .= " ORDER BY thread.dateline DESC";

$news=$DB_site->query($newsquery);

while ($newsarray=$DB_site->fetch_array($news)) {

$dateposted = vbdate("jS F Y, H:i",$newsarray[dateline]);

if ($newsarray[replycount]==1) {
$commenttext = "Comment";
}
else {
$commenttext = "Comments";
}

$cookedthread=bbcodeparse2($newsarray[pagetext],"1","1","1","1");
$test1 .= "test";
eval("\$newsbits .= \"".gettemplate("newsbit")."\";");

}

eval("dooutput(\"".gettemplate("shownews")."\");");

?>


Thats basically it really!.

Im sure there are a few little errors in my coding, im a bit rusty with PHP :(

Next i plan on making a 'column' system(ie http://fortress.challenge-au.com) And actually, its for that site :)

<edit>
Im not sure if this supports multiple forums. Some feedback maybe?

Also- maybe there may be some point in using replacment variables in this, but hey, i couldnt be bothered ;)
</edit>

jasoncorn
27 Aug 2001, 16:00
Thank you! This is perfect. Installs in 1 minute and works well. Exactly what I needed. :)

JJR512
27 Aug 2001, 19:56
Can we see a demo site?

DjSao
27 Aug 2001, 21:31
very nice hack, it works perfectly

merk
27 Aug 2001, 23:42
Excuse the content of the actual posts..

(Nothing bad, but nothing thats really useful :)


http://www.opticpower.net/forum/news.php

JJR512
28 Aug 2001, 08:14
OK, how can I make it so the newest thread is at the top, rather than the bottom?

DjSao
28 Aug 2001, 08:15
Hey just wondering about one thing, i added the threads title to the newspage, but i'm wondering if its possible to make the title capital letters only, like some kind of line of code that replaces all letters in the title to capitals.

merk
28 Aug 2001, 10:04
Originally posted by JJR512
OK, how can I make it so the newest thread is at the top, rather than the bottom?

I get this already-

However, i think i forgot to add a touch of code.

To change it, you need to modify the code block:

$newsquery = "SELECT thread.*, post.*";
$newsquery .= " FROM thread,post";
$newsquery .= " WHERE post.threadid=thread.threadid";
$newsquery .= " AND thread.forumid=107";
$newsquery .= " GROUP BY thread.threadid";


to


$newsquery = "SELECT thread.*, post.*";
$newsquery .= " FROM thread,post";
$newsquery .= " WHERE post.threadid=thread.threadid";
$newsquery .= " AND thread.forumid=107";
$newsquery .= " GROUP BY thread.threadid";
$newsquery .= " ORDER BY thread.dateline DESC";

merk
28 Aug 2001, 10:07
Originally posted by DjSao
Hey just wondering about one thing, i added the threads title to the newspage, but i'm wondering if its possible to make the title capital letters only, like some kind of line of code that replaces all letters in the title to capitals.

In the While statment,

Add BEFORE (about line 41)

eval("\$newsbits .= \"".gettemplate("newsbit")."\";");



$uppercasenews = strtoupper($newsarray[title]);


Then, to reference the uppercase title, instead of using $newsarray[title] in the newsbit template, change it to $uppercasenews.

Btw, i havent tested this, but it should work in theory

DjSao
28 Aug 2001, 11:26
thanks, worked great.

DjSao
28 Aug 2001, 12:05
One more thing, the posting date is screwed up, it shows the posted date but only server time, the timezeone offset doesnt work.

merk
28 Aug 2001, 12:44
Ill look into it, i dont really have that problem, 90% of my members are in the servers timezone :o

merk
28 Aug 2001, 13:49
I have gotten the Date to show, as the users setting.

You need to replace, at line 43

$dateposted = date("jS F Y, H:i",$newsarray[dateline]);


with


$dateposted = vbdate("jS F Y, H:i",$newsarray[dateline]);



Thanks Kier ;)

DjSao
28 Aug 2001, 14:39
Thanx again, ill be here with more work for you as soon as i figure out what other stuff should be added :)

DjSao
28 Aug 2001, 15:12
$newsitems = 1;

this line doesn't do anything, you havent put out a limit that referrs to $newsitems.

Mega
28 Aug 2001, 15:38
lol

I guess you have to

add this:

$newsquery .= "LIMIT $newsitems";


right after:

$newsquery = "SELECT thread.*, post.*";
$newsquery .= " FROM thread,post";
$newsquery .= " WHERE post.threadid=thread.threadid";
$newsquery .= " AND thread.forumid=107";
$newsquery .= " GROUP BY thread.threadid";
$newsquery .= " ORDER BY thread.dateline DESC";


NOT sure... my SQL is a bit rusty :)

DjSao
28 Aug 2001, 15:43
Nope that didnt work, i gave it a try and added the limit thingie myself

Replace:

$newsquery .= " ORDER BY thread.dateline DESC";

With this:

$newsquery .= " ORDER BY thread.dateline DESC LIMIT $newsitems";


Now, how bout adding a pagenav at the bottom, so that you can see older news

JJR512
28 Aug 2001, 18:01
OK, this little request is going to throw a major complication into the works, I know, but I just have to ask.

Instead of limiting the number of news items that show up to a fixed number (with $newsitems), could there be a way to show news items during the past certain amount of time? For example, show all from the past two days, or something like that (the time limit would be a admin-set variable, just like $newsitems).

merk
29 Aug 2001, 00:22
Whoops :)

Forgot to add the LIMIT SQL bit back in after testing ;)



<?
error_reporting(7);
$templatesused='header,headinclude,phpheader,newsbit,shownews';
$loadbirthdays=1;
$loadmaxusers=1;

//Configuration Options
//What is the ID of your News forum?
$newsforums = 107;

//How many news items should be displayed?
$newsitems = 10;

//Path to your forums directory (leave out trailing slash)
$forumspath = "/forum";

require('./global.php');

$newsquery = "SELECT thread.*, post.*";
$newsquery .= " FROM thread,post";
$newsquery .= " WHERE post.threadid=thread.threadid";
$newsquery .= " AND thread.forumid=$newsforums";
$newsquery .= " GROUP BY thread.threadid";
$newsquery .= " ORDER BY thread.dateline DESC";
$newsquery .= " LIMIT $newsitems"

$news=$DB_site->query($newsquery);

while ($newsarray=$DB_site->fetch_array($news)) {

$dateposted = vbdate("jS F Y, H:i",$newsarray[dateline]);

if ($newsarray[replycount]==1) {
$commenttext = "Comment";
}
else {
$commenttext = "Comments";
}

$cookedthread=bbcodeparse2($newsarray[pagetext],"1","1","1","1");
$test1 .= "test";
eval("\$newsbits .= \"".gettemplate("newsbit")."\";");

}

eval("dooutput(\"".gettemplate("shownews")."\");");

?>


Im not actually sure if this works, im at work at the moment, and i dont have access to my database to test it.

Basically i just added the last line to $newsquery.


Watch out for v1.5 soon!
Itll have more features! (who knows what at the moment :))
I plan on adding multiple forum support, which ive done in my version, but its only basic, and you need to know the forumid(any forumid works atm, gotta fix that)
Maybe news headlines, just like PluhNews, i like that feature.

Im also working on OPColumns, which will do similar features to here (http://fortress.challenge-au.com).

If you can sugest any more features you would like, ill try work on them :)

merk
29 Aug 2001, 00:24
Originally posted by Mega
lol

I guess you have to

add this:

$newsquery .= "LIMIT $newsitems";


right after:

$newsquery = "SELECT thread.*, post.*";
$newsquery .= " FROM thread,post";
$newsquery .= " WHERE post.threadid=thread.threadid";
$newsquery .= " AND thread.forumid=107";
$newsquery .= " GROUP BY thread.threadid";
$newsquery .= " ORDER BY thread.dateline DESC";


NOT sure... my SQL is a bit rusty :)


Your ALMOST right. just you need to add a SPACE before the start of limit, just my coding style ;)

merk
29 Aug 2001, 00:26
Originally posted by JJR512
OK, this little request is going to throw a major complication into the works, I know, but I just have to ask.

Instead of limiting the number of news items that show up to a fixed number (with $newsitems), could there be a way to show news items during the past certain amount of time? For example, show all from the past two days, or something like that (the time limit would be a admin-set variable, just like $newsitems).

There very well should be. Give me a few hours on this one, ill try think up a method, but i may not be able to get it all done straight away.

However, its starting to get past my SQL knowledge, however i have a few buddies who can help ;)

JJR512
29 Aug 2001, 05:51
This isn't a problem or anything, but just some thinking out loud, so please bear with me.

My website is mainly about computers, or at least, that's how it's supposed to be. Computer hardware and software, tips and tutorials, stuff like that (although most of it is in development).

I have a forum on my board for sports, another for entertainment (movies, music, etc.), another for cars, and several computer-related forums.

I would like news from all of these very different types of topics to show up on the home page of the website. But in order to get news to show up there, it has to be posted in one specific forum, and not the forum it actually belongs in. Sure, with some of the other news hacks, I could specify to pull from multiple forums, but then everything from those forums gets pulled.

The problem with putting everything in one forum is that it then means two forums for people to check if they want the latest entertainment news, for example. Because a lot of people just come straight to the board, not to the home page of the site. Or if they want to see the comments that people make, it means going to two forums.

So what I'm thinking is that a completely different way of getting news on another page is needed. This is, I believe, a completely new idea. The old way is pulling all threads out of one specified forum. My idea is that you post news in the appropriate forum for that type of news (like putting movie news in the entertainment forum), and when you post, there would be an option, a checkbox, to make it a news item. Checking that checkbox, like the one to make a thread a poll, would flag that thread as one that should be displayed on the separate news page. Only Admins, or maybe Admins and Mods, would be able to use that checkbox.

This could even be taken a step further. Because news items can now be posted in all forums, the forum becomes like a category. For example, news items I post in my Entertainment forum are categorized as Entertainment news, and news items I post in my Sports forums are categorized as Sports news. This could be part of a search and sort feature on the separate news page. A user could click a link to show all the Sports news, or to search for something based on category.

All of this is just something to think about. I'm posting it in this thread because I think that of all the news page hacks I've seen so far, this one is the best. I realize it would be quite a lot of work to do something like this. But this is just to give you (merk), or anyone, something to think about, and maybe if you feel it's a good idea, work on doing sometime. :)

merk
29 Aug 2001, 07:01
Excelent idea.

I have quite a use for a similar system.

Im thinking, that the best method of what you sugest, is that once you check that check box, it becomes duplicated in 2 forums.

This probably isnt desirable, because if you edit the post in the forum, nothing will happen to the news post. Also with the comments.

Another option, would be to create a completly different table in the database, which stores the postid of each news post, and the details needed.

At the moment, such a system isnt so urgently needed by myself- however, the system i do need, is 'columns' as mentioned above for OPNews v1.5, or columns, cant remember what i called it :)

Your welcome to come to my board to discuss it all(*pimp* need more hits D: *pimp*)

So yer, atm im working on a columns system, which details are still fuzzy, and after releasing that ill help you out with this one, cause i can use it too(and i can imagine that they would be similar).

Give me about another 24/48 hours and i should be well underway!

merk
29 Aug 2001, 09:35
Updated:

http://www.vbulletin.com/forum/showthread.php?s=&threadid=26792

JJR512
29 Aug 2001, 19:27
How do you get the thread subject to show up on the news page, as you seem to have in your demo link above?

merk
29 Aug 2001, 23:04
If its not there, you need to add

$newsarray[title] to the newsbit template.

I cant imagine why its not there- i remember adding it, but who knows, i might have spelt it wrong :/