Developer's Manual  Writing SiteSupra Console Application

Writing SiteSupra Console Application

SiteSupra console application is PHP script that is accessible via browser as a regular page created using HTML or PHP. The difference between a "regular" page and console application is that the last can call any SiteSupra API function and refer to any SiteSupra variable or constant.

SiteSupra console applications are stored under SiteSupra folder (by defult it is /supra). The application name should start with "su", for example: su__rssnews.php.

When developing an application, there are two functions you have to think of. The first is suSQLConnect, which creates connection to SiteSupra databse and Class $suSQL. The second is suDebugLog, which outputs SiteSupra debugger window into the browser.

The example is included in the last SiteSupra demo site. If you do not have the latest version of demo site, just copy the below script into your editor and save under SiteSupra folder (by default it is /supra) as su__rssnews.php.

<?
/*

    This is example of SiteSupra VCS 3.0 console application.
    The script generates list of news articles in RSS format.
    To run the script open your browser and type the following URL:
    
    http://www.company.com/supra/_rssnews
    
    where http://www.company.com is your website address

*/

// Connecting to SiteSupra database using data from .htsupra file
suSQLConnect($suSQL);

/*
    Getting active news pages from folder News.
    Since a news page in SiteSupra demo site has path
    
    /news/year/month/newspage/
    
    and condition
    
        path LIKE '/news/%'
    
    will return years and months folders, we added additional condition
    
        AND LENGTH(path) - LENGTH(REPLACE(path, '/', '')) = 5
    
    to get newspages only.
    
*/
$query = "SELECT title, short AS description, CONCAT('" . suFBASE . "', path) AS link,
                DATE_FORMAT(date, '%a, %d %b %Y %H:%i:%s GMT') AS pubDate
            FROM pages_en0
            WHERE active = 1 AND path LIKE '/news/%' AND LENGTH(path) - LENGTH(REPLACE(path, '/', '')) = 5
            ORDER BY date DESC"
;
$data = $suSQL->queryData($query);

// Building a loop to prepare XML
$xml = array();
$xml[] = '<?xml version="1.0" ?>';
$xml[] = '<rss version="2.0">';
$xml[] = '<channel>';
$xml[] = '<title>SiteSupra Demo site news</title>';
$xml[] = '<link>http://www.company.com/supra/_rssnews</link>';
$xml[] = '<description>The latest information about SiteSupra.</description>';
$xml[] = '<language>en-us</language>';
$xml[] = '<ttl>1440</ttl>';

for(
$i = 0, $m = count($data); $i < $m; $i++)
{
    
$xml[] = '<item>';
    foreach(
$data[$i] as $key => $value)
        
$xml[] = '<' . $key . '>' . htmlspecialchars($value) . '</' . $key . '>';

    
$xml[] = '</item>';
}

$xml[] = '</channel>';
$xml[] = '</rss>';

header("Content-type: text/xml");
echo
join('', $xml);
?>
Please login to add comments.