$body = '';
$mostrecentdate = 0;
// Get $charset (atamyrat@gmail.com)
if (defined('_CHARSET') && _CHARSET != '') {
    $charset = _CHARSET;
} else {
    $charset = 'ISO-8859-1';
}
// get the short urls extensions
$urlsok = pnModGetVar('Xanthia', 'shorturlsok');
$urlextension = pnModGetVar('Xanthia', 'shorturlsextension');
$baseurl = pnGetBaseURL();
// get the language
$newlang = pnVarCleanFromInput('newlang');
$backendlang = pnConfigGetVar('backend_language');
$backendlangs = cnvlanguagelist();
if ((!isset($newlang) || empty($newlang)) && isset($backendlangs[$backendlang])) {
    $lang = $backendlangs[$backendlang];
} else {
    $lang = $newlang;
}
// get any filters
$topicid = pnVarCleanFromInput('topicid');
$catid = pnVarCleanFromInput('catid');
// Base query
$storiescolumn = $pntable['stories_column'];
$storiescatcolumn = $pntable['stories_cat_column'];
$topicscolumn = $pntable['topics_column'];
$query = "SELECT {$storiescolumn['aid']} AS \"aid\",\n                 {$storiescolumn['catid']} AS \"cid\",\n                 {$storiescatcolumn['title']} AS \"cattitle\",\n                 {$storiescolumn['sid']} AS \"sid\",\n                 {$topicscolumn['topicid']} AS \"tid\",\n                 {$storiescolumn['title']} AS \"title\",\n                 {$topicscolumn['topicname']} AS \"topicname\",\n                 {$topicscolumn['topictext']} AS \"topictext\",\n\t\t\t\t {$storiescolumn['hometext']} AS \"hometext\",\n\t\t\t\t {$storiescolumn['time']} AS \"time\"\n          FROM \t {$pntable['stories']}";
$query .= " LEFT JOIN {$pntable['stories_cat']} ON {$storiescolumn['catid']} = {$storiescatcolumn['catid']}\n\t\t\tLEFT JOIN {$pntable['topics']} ON {$storiescolumn['topic']} = {$topicscolumn['topicid']}";
$query .= " WHERE {$storiescolumn['ihome']} = 0 AND ({$storiescolumn['language']} = '" . pnVarPrepForStore($lang) . "' OR {$storiescolumn['language']} = '') ";
/**
 * Load language files for the current language
 * 
 * @return void
 */
function pnLangLoad()
{
    // See if a language update is required for ml-enviroments
    $newlang = pnVarCleanFromInput('newlang');
    if (!empty($newlang) && pnConfigGetVar('multilingual') == 1) {
        $langlist = languagelist();
        if (file_exists('language/' . pnVarPrepForOS($newlang) . '/global.php') && isset($langlist[$newlang])) {
            // newlang is valid and exists
            $lang = $newlang;
            pnSessionSetVar('lang', $newlang);
        } else {
            // newlang is either not valid or doesn't exist - restore default values
            $lang = pnConfigGetVar('language');
            pnSessionSetVar('lang', $lang);
        }
    } else {
        $detectlang = pnConfigGetVar('language_detect');
        $defaultlang = pnConfigGetVar('language');
        switch ($detectlang) {
            case 1:
                // Detect Browser Language
                $cnvlanguage = cnvlanguagelist();
                $currentlang = '';
                $langs = split('[,;]', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
                foreach ($langs as $lang) {
                    if (isset($cnvlanguage[$lang]) && file_exists('language/' . pnVarPrepForOS($cnvlanguage[$lang]) . '/global.php')) {
                        $currentlang = $cnvlanguage[$lang];
                        break;
                    }
                }
                if ($currentlang == '') {
                    $currentlang = $defaultlang;
                }
                break;
            default:
                $currentlang = $defaultlang;
        }
        $lang = pnSessionGetVar('lang');
    }
    // Load global language defines
    // these are deprecated and will be moved to the relevant modules
    // with .8x
    if (isset($lang) && file_exists('language/' . pnVarPrepForOS($lang) . '/global.php')) {
        $currentlang = $lang;
    } else {
        $currentlang = pnConfigGetVar('language');
        pnSessionSetVar('lang', $currentlang);
    }
    $oscurrentlang = pnVarPrepForOS($currentlang);
    if (file_exists('language/' . $oscurrentlang . '/global.php')) {
        include 'language/' . $oscurrentlang . '/global.php';
    }
    // load the languge language file
    if (file_exists('language/languages.php')) {
        include 'language/languages.php';
    }
    // load the core language file
    if (file_exists('language/' . $oscurrentlang . '/core.php')) {
        include 'language/' . $oscurrentlang . '/core.php';
    }
    // set the correct locale
    // note: windows has different requires for the setlocale funciton to other OS's
    // See: http://uk.php.net/setlocale
    if (stristr(getenv('OS'), 'windows')) {
        // for windows we either use the _LOCALEWIN define or the existing language code
        if (defined('_LOCALEWIN')) {
            setlocale(LC_ALL, _LOCALEWIN);
        } else {
            setlocale(LC_ALL, $currentlang);
        }
    } else {
        // for other OS's we use the _LOCALE define
        setlocale(LC_ALL, _LOCALE);
    }
}
function sniff_user_language()
{
    if (file_exists('system/Sniffer/pnincludes/phpSniff.class.php')) {
        include_once 'system/Sniffer/pnincludes/phpSniff.class.php';
    } else {
        if (file_exists('modules/Sniffer/pnincludes/phpSniff.class.php')) {
            include_once 'modules/Sniffer/pnincludes/phpSniff.class.php';
        } else {
            return false;
        }
    }
    // sniff process
    $client =& new phpSniff();
    $languages = explode(',', $client->property('language'));
    include_once 'includes/pnLang.php';
    $alllanguages = cnvlanguagelist();
    foreach ($languages as $language) {
        if (array_key_exists($language, $alllanguages)) {
            return $alllanguages[$language];
        }
    }
    // nothing found - default is eng
    return 'eng';
}