Before you begin building an add-on or modification, understanding of the purpose of each sNews function is ideally the place to start. A change made in one function or the structure of a new function made from scratch may ‘break’ or cause other functions within the snews.php file to produce unexpected results.
The following is a list of the default functions contained in the snews.php file of sNews 1.5.4 release, along with a short description of its purpose.
/*** CONFIGURATION VARIABLES ***/
// DATABASE VARIABLES
This function holds the essential variables required for snews to operate. We often refer to these as the Configuration Settings, and we input their values manually when we set up the site.
// LANGUAGE VARIABLES
This is a list of words and phrases that appear by default in the sNews site. These variable names are inserted using $variable in of the other functions. If the site’s language variable is not set to EN (for english), these default variables will be bypassed, and an external language file (once installed) will be used.
/*** END OF SETTINGS & VARIABLES, EDIT BELOW THIS LINE ONLY IF YOU KNOW WHAT YOU’RE DOING ***/
// INFO LINE TAGS (readmore, comments, date)
This outputs the basic html for the information lines usually seen following articles and at the head of comments. The output needs to be processed to become meaningful.
// SITE SETTINGS – grab site settings from database
This retrieves variables, when they are required, from the settings table in the database.
// SESSION TOKEN
generates a token (like a wildcard) that is used in security measures.
Initiates site db connection, and is the processing point for snews login.
Generates and outputs html for the title and meta lines that are added to the source code for all displayed pages.
Generates the breadcrumb navigation line, usually displayed above the main article content.
// LOGIN LOGOUT LINK
Generates html for both Login, and (if logged in) Admin links.
// DISPLAY CATEGORIES
Outputs a list of name-links for all active categories.
// DISPLAY PAGES
Called in index.php, produces the top menu in the default install. Makes links to page type articles plus hardcoded Home, Sitemap, Archive and Contact links.
function extra($styleit = 0, $classname = ”, $idname= ”)
Called in index.php, produces the extra content block in the default install, for articles assigned as extra content in article admin. Output controlled by the 3 variables.
$styleit controls the wrapping of the extra content with a <div> – values 1 = activate, 0 = deactivate. $classname supplies a class to the <div> and $idname supplies the id to the <div>
function paginator($category, $pageNum, $maxPage, $article, $pagePrefix)
Outputs a pagination line when site content setting to show pagination is set in the administration area.
Generates the main body of the site.
This function handles the display and processing of article comments.
Generates the Archive page.
Generates the Sitemap page.
function notification($error, $errNote, $link)
Used to display any messages (primarily error messages) that are required if conditions call for them.
// CONTACT FORM
Generates the Contact page, and processes the submitted form.
// MENU ARTICLES
function menu_articles($start, $size)
Called from index.php, this displays a list of articles. Number of articles determined by $size, and start point set by $start (0 is most recent).
// NEW COMMENTS
function new_comments($number, $stringlen)
Called from index.php, this displays a list of recent comments. Number of comments determined by $number, and the visible part of the comment is limited by $stringlen (number of visible characters).
// SEARCH FORM
Generates the Search form.
Processes the submission from the search form
// RSS FEED
Outputs RSS feed.
// PREPARING ARTICLE FOR XML
Removes all non-textual contents from the article ([include], , XHTMLtags etc.)
/*** ADMINISTRATIVE FUNCTIONS ***/
Generates the login form if not logged in, otherwise if logged in, generates the logout link.
function stats($field, $position)
Generates a simple contents statistics used in admin pane.
// FORM GENERATOR
function html_input($type, $name, $id, $value, $label, $css, $script1, $script2, $script3, $checked, $rows, $cols, $method, $action, $legend)
Form generation routine responsible for most of the form elements throughout the site.
// ADMINISTRATION FORM
Generates the main administration pane.
// SETTINGS FORM
Generates the settings form in the admin area.
// CATEGORIES FORM
Generates the categories form in the admin area.
// ARTICLES – POSTING TIME
This function generates the series of dropdowns used in the article Publish Date section of the article administration area.
// ARTICLES FORM
Generates the administration form for the new/selected article.
// ARTICLES – ADMIN LIST
Produces the listing of types of articles in sNews (Pages, Articles, Extra Content).
//CATEGORIES – ADMIN LIST
Produces the listing of categories.
// COMMENTS – EDIT
This function is for editing comments.
/*** PROCESSING (CATEGORIES, CONTENTS, COMMENTS) ***/
This function is the main administration processing area; forms data fetching and database manipulation.
/*** FILES ***/
This function controls file upload and deletion. It includes the means to prevent uploads of selected files and file types using the web interface
// FILELIST FUNCTION
function filelist($mode, $path, $depth = 0)
Outputs the file list in the administration area.
// CONNECT TO DATABASE
This function, when called, makes the connection to the database, enabling database access to all functions that need to retrieve items from the database.
// SMART RETRIEVE FUNCTION
function retrieve($column, $table, $field, $value)
This function is a quick fetching routine which retrieves a single item from the database, depending on parameters used.
// FIND CATEGORY’S SEF TITLE THROUGH ARTICLE’S CATEGORY ID
Retrieves category SEF (search engine friendly) title used when creating links to articles.
// CLEAN – cleaning query
MySQL input data cleaning routine.
// USER/PASS CHECK
Validation routine used in login procedure.
// MATH CAPTCHA
Outputs a simple arithmetic sum required for completion of forms. This is an anti-spam measure.
// XSS CLEAN
Anti-XSS (Cross site scripting) measure. Source from http://quickwired.com/kallahar/smallprojects/php_xss_filter_function.php
// CLEAN – WORD FILTER
When clean words filter is named and activated in the admin, this function compares the content of the word list and the submitted text, replacing any words that match.
// CHECK IF UNIQUE
function check_if_unique($what, $text, $not_id = ‘x’)
This function checks article seftitle/title, and category seftitle/name for uniqueness.
// GET ID
This function checks all the parameters inside link and generates categories/articles/comments SEF titles respectively.
Category uniqueness check used when building sNews navigation.
function file_include($text, $shorten)
Processes any editor [include] tags, and replaces the tags and the file location between them with the file to be included.
// ARTICLES – FUTURE POSTING
Checks the articles date field and published level. If the article had been set to be published at a date after entry and that date has arrived, this function will alter the published level, and make the article user accessible.
// MAKE A CLEAN SEF URL
Removes all non-URL friendly characters from article title.
Additional routine used in category checking function.
Learn How to Work with Mods:
sNews requires PHP, MySQL and mod rewrite. If your server meets those requirements, get started and learn how to install sNews on your website in 3 easy steps.
Browse through our help center and learn about template tags and how to simply create your own theme. Dig into sNews and customize it to behave the way you want.
sNews can be a simple blog tool and a full blown CMS. Customize it with addons, mods or play with different themes.
Talk about sNews on our Forum and share your expirience