Validate my script pleas?

Started by Leipe Po, December 03, 2005, 08:14:02 AM

Previous topic - Next topic

Leipe Po


<?php
/******************************************************************************
* newsIndex.php                                                              *
*******************************************************************************
* SMF: Simple Machines Forum                                                  *
* Open-Source Project Inspired by Zef Hemel ([email protected])                *
* =========================================================================== *
* Software Version:           SMF 1.0                                         *
* Software by:                Simple Machines (http://www.simplemachines.org) *
* Copyright 2001-2004 by:     Lewis Media (http://www.lewismedia.com)         *
* Support, News, Updates at:  http://www.simplemachines.org                   *
*******************************************************************************
* This program is free software; you may redistribute it and/or modify it     *
* under the terms of the provided license as published by Lewis Media.        *
*                                                                             *
* This program is distributed in the hope that it is and will be useful,      *
* but WITHOUT ANY WARRANTIES; without even any implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        *
*                                                                             *
* See the "license.txt" file for details of the Simple Machines license.      *
* The latest version can always be found at http://www.simplemachines.org.    *
******************************************************************************/
if (!defined('SMF'))
die('Hacking attempt...');


// Show the news!


function mainIndex()
{
global $txt, $scripturl, $db_prefix, $ID_MEMBER, $user_info, $sourcedir;
global $modSettings, $context, $settings;

// This loads the newsIndex.template.php
loadTemplate('newsIndex');

// Lets set the page title!
$context['page_title'] = $context['forum_name'] . ' - News Index';

// Lets also add this to the breadcrum
$context['linktree'][] = array(
'url' => $scripturl . '?action=news',
'name' => 'News Catagories'
);

// Find all news, as well as related information.
$result_news = db_query("
SELECT
id AS cid, title AS ctitle, discription AS cdisc,
news_count AS ncount, comment_count AS ccount
FROM
{$db_prefix}news_cats", __FILE__, __LINE__);


$context['news_cats'] = array();
while ($row_board = mysql_fetch_assoc($result_news))
{
// Haven't set this category yet.
if (empty($context['news_cats'][$row_board['cid']]))
{
$context['news_cats'][$row_board['cid']] = array(
'id' => $row_board['cid'],
'name' => $row_board['ctitle'],
'disc' => $row_board['cdisc'],
'post_count' => $row_board['ncount'],
'comment_count' => $row_board['ccount'],
'href' => $scripturl . '?action=ShowNews&news=' . $row_board['cid'],
);
$context['news_cats'][$row_board['cid']]['link'] = '<a name="' . $row_board['cid'] . '" href="' . $context['news_cats'][$row_board['cid']]['href'] . '">' . $row_board['ctitle'] . '</a>';
}

// Let's save some typing.  Climbing the array might be slower, anyhow.
$this_category = &$context['news_cats'][$row_board['cid']];

// Provide the href and link.
if ($row_board['ctitle'] != '')
{
$this_last_post['href'] = $scripturl . 'action=shownews&id' . $row_board['cid'];
$this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['cdisc'] . '">' . $row_board['ctitle'] . '</a>';
}
else
{
$this_last_post['href'] = '';
$this_last_post['link'] = $txt[470];
}



}
mysql_free_result($result_news);

}
?>


this is used for http://www.phpscripters.net/index.php?action=news,
onley catagory is now avalable, first want to know if this is good, it leaves no errors thoug, i wanted to here your info,

think ther is alot of useless stuff in there, but dont know, what is for what purpose coded,
so again pleas tell me

pleas tell me if i have anything crucial out and if this is done to your code guidlines? and info would be greatly appreciated
There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

Compuart

Appears to be pretty much within coding guidelines :) just a few small things

use lowercased actions:
'href' => $scripturl . '?action=shownews&news=' . $row_board['cid'],


This line:
$this_last_post['href'] = $scripturl . 'action=shownews&id' . $row_board['cid'];

Would probably be better like:
$this_last_post['href'] = $scripturl . '?action=shownews&id=' . $row_board['cid'];



This piece of code hasn't any function at the moment (though I assume you're still working on it)
// Let's save some typing.  Climbing the array might be slower, anyhow.
$this_category = &$context['news_cats'][$row_board['cid']];

// Provide the href and link.
if ($row_board['ctitle'] != '')
{
$this_last_post['href'] = $scripturl . 'action=shownews&id' . $row_board['cid'];
$this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['cdisc'] . '">' . $row_board['ctitle'] . '</a>';
}
else
{
$this_last_post['href'] = '';
$this_last_post['link'] = $txt[470];
}


Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Leipe Po

well glad to here its within coding guidelines, only thanks for bringing out the = in the URL, overseen that, but not bad for 20 minutes of coding in a board that i just used for 1 day(had used smf before but it was a much lower version), the script is still in development but hope its finished within this week, got allot of work to do on the site, my main goal is to make it a tutorial site, and offcource a nice community, also sorry for my bad English, but I'm dutch,

thanks for the reply, got only one more question:

is there a list of what does what in smf?

like $settings and how to use it in other scripts?

think i will figure it out while coding the script, but you guys/girls know better cause your the ones that made it,
so that will save me loads of time if you could explain some stuff,

i know $txt is used for language files, $scripturl is the url to the script, $db_prefix is the prefix set for the db when installing, $ID_MEMBER is the id of the member viewing the page(?), $sourcedir would be in my case http://www.phpscripters.net/.

so $user_info would be the stuff in this signature?
and what will $setting do and $modSettings,
$context is also not really clear to me what it does,

if somebody would like to clear that up for me, would be greatly appreciated,

Greetz, Leipe Po
There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

Compuart

$settings: theme specific settings (stored in the themes table)
$options: theme specific user options (these can be different for each user for each theme, also stored in the themes table)
$modSettings: forum settings (extracted from the settings table)
$user_info: An array with the most important stuff about the user that's currently viewing the page.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Leipe Po

ok well thanks a buntch, this will make it alot easyer to find and learn  :D

take care mate, and again thanks for all the info
There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

Oldiesmann

You can also use ; in place of & (so the query strings follow the same standard format that's used everywhere else in SMF).

Leipe Po

nice, i dont have to alter anything for that? it will pars it automaticly?
There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

Thantos

SMF will automatically breakup the data on & and ;
So as long as you stay inside the SMF sandbox you'll be ok.

Leipe Po

thanks for the great support on this, i really thought you would hate me for "hacking" the board to become a hole site, so this kinda suprises me  :D

if i would post that kinda thing on phpbb or so, i will get flamed with post saying: "we didn't designed it for that purpose", you guys are great, the forum is great, everything is great!!!

the news is comming along great on my localhost, i will post here when i updated the site, so you can let your critics loose on it, for better development,

again thanks alot!!!!, really your the best

There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

Compuart

We're trying to design it so that it's easy to modify, hence the extensive inline documentation.

Good luck with your news script :D
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Thantos

My personal feeling is that as long as it doesn't violate the license agreement do what you wish with your forum :)

Leipe Po

well this is made only for use on that particular website, i wanted to be in the guidelines cause, if i ever need to change host, it will be portable, if i had only the slightest intention to distribute this, i will first make contact with you guys for permission, but i don't know if i want it to be distributed, it will give to much headaches i think, and will take at least one year of developing, testing, beta testing, before any public release so, IF i have the intention YOU will be the first to know

(this is just to make it clear to those who thinks this will be a portal of smf, it is a portal, but not for distribution)
There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

Advertisement: