Source

azhar / includes / api / integrate.php

<?php

/*
 * Azhŕr, faeries intranet
 * (c) 2009-2010, Wolfćym, some rights reserved
 * Released under BSD license
 *
 * API integrate module
 *
 * Allows to integrate other applications and Azhŕr.
 *
 * Functions:
 * 
 *  /integrate/footer
 *      Get footer, customized for specified user
 *        - ?username=  username, e.g. to load My page
 *        - ?credits=   custom credits line
 *
 *  /integrate/header
 *      Get header
 *
 *  /integrate/wall
 *      Get a wall message
 *        - ?format=    <preview|php|wddx|json|xml>
 *
 */

//Initializes Smarty
$defaultSkin = 'VacuumCleanerBridge';
define('THEME', $defaultSkin);
require_once('includes/Smarty/Smarty.class.php');
$smarty = new Smarty();
$current_dir = '.';
$smarty->template_dir = $current_dir . '/skins/' . THEME;
$smarty->compile_dir = $current_dir . '/cache/compiled';
$smarty->cache_dir = $current_dir . '/cache';
$smarty->config_dir = $current_dir;

//Loads toponymy
require_once('includes/toponymy.php');

/*
 * Method controller
 */

switch ($method = $url[1]) {
    case '':
        //Nothing to do
        //TODO: document available methods
        break;
    
    case 'wall':
        $sql = 'SELECT u.username, u.user_longname as name, m.motd_text FROM ' . TABLE_USERS . ' u, ' . TABLE_MOTD . ' m WHERE u.user_id = m.user_id ORDER BY rand() LIMIT 1';
        if (!$result = $db->sql_query($sql)) message_die(SQL_ERROR, "Can't get wall message", '', __LINE__, __FILE__, $sql);
        $row = $db->sql_fetchrow($result);
        $wall->text = $row['motd_text'];
        $wall->username = $row['username'];
        $wall->author = $row['name'];
        $wall->URL = join('/', array(
                                     URL,
                                     $Config['Toponymy']['user'],
                                     $row['username']
                               )
                         );
        api_output($wall, 'Wall');
        break;
    
    case 'footer':
        if ($_GET['username']) {
            //Fills user object with minimal properties
            
            $user->username = $_GET['username'];
            
            //haveAdminAccess?
            $username = $db->sql_escape($user->username);
            $sql = 'SELECT haveAdminAccess FROM ' . TABLE_USERS . " WHERE username LIKE '$username'";
            $user->haveAdminAccess = $db->sql_query_express($sql);
            
            $smarty->assign('CurrentUser', $user);        
        }
        $smarty->assign('FOOTER_ONLY', true);
        $smarty->assign('CREDITS', $_GET['credits']);
        include('controllers/footer.php');
        break;
                
    case 'header':
        $smarty->assign('HEADER_ONLY', true);
        include('controllers/header.php');
        break;
    
    default:
        echo "Not defined method: $method";
        break;
}

?>