« Utilisateur:Akela NDE/sw index.php » : différence entre les versions

De Scoutopedia
mAucun résumé des modifications
m (Remplacement de texte — « <[bB][rR]> » par « <br /> »)
 
Ligne 445 : Ligne 445 :
  <tr>
  <tr>
   <td width="33%"><a class="minilien" href="http://media.scoutwiki.org/w/Main_page">ScoutMedia</a><br /><i>International media sharing wiki.</i></td>
   <td width="33%"><a class="minilien" href="http://media.scoutwiki.org/w/Main_page">ScoutMedia</a><br /><i>International media sharing wiki.</i></td>
   <td width="34%"><a class="minilien" href="http://forum.scoutwiki.org/">Forum</a><br><i>The place to talk !</i></td>
   <td width="34%"><a class="minilien" href="http://forum.scoutwiki.org/">Forum</a><br /><i>The place to talk !</i></td>
   <td width="33%"><a class="minilien" href="http://asso.scoutwiki.org/">Association Wiki</a><br><i>The home of the SWN Association</i></td>
   <td width="33%"><a class="minilien" href="http://asso.scoutwiki.org/">Association Wiki</a><br /><i>The home of the SWN Association</i></td>
  </tr>
  </tr>
</table>
</table>

Dernière version du 28 novembre 2015 à 15:23

<?php
 
/*
 * ScoutWiki frontpage tool set -- shows search box for ScoutWiki wikis and redirects
 *  queries to the correct wikis search page and shows stats about different ScoutWikis.
 * Version 1.6.1
 * Copyright (C) 2007 Jyri-Petteri "ZeiP" Paloposki <jyri-petteri.paloposki@iki.fi,
 *  jyri-petteri.paloposki@scoutwiki.org>
 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 * Version history:
 * 1 thru 1.2: Jyri-Petteri "ZeiP" Paloposki, 5.9.2007 -- initial release and subsequent
 *  bugfixes.
 * 1.3 thru 1.4: Jyri-Petteri "ZeiP" Paloposki, 5.9.2007 -- changed to also contain other related
 *  functionality.
 * 1.5: Jyri-Petteri "ZeiP" Paloposki, 5.9.2007 -- GOT THE ARABIAN STATS URL! (Yes, it really
 *  was that hard...)
 * 1.6: Jyri-Petteri "ZeiP" Paloposki, 14.9.2007 -- caching of article counts.
 * 1.6.1: Jyri-Petteri "ZeiP" Paloposki, 14.9.2007 -- removing the temp file
 * 1.6.2: Jeoire de Buretel de Chassey, 16.9.2007  -- adding translation of the ScoutWiki motto, including html.
 */
 
$searches = array(
    'fi' => array(
        'text' => 'Suomi',
        'searchurl' => 'http://wiki.partio.net/Toiminnot:Haku?search=%s',
        'statsurl' => 'http://wiki.partio.net/Toiminnot:Tilastot?action=raw'),
    'nl' => array(
        'text' => 'Nederlands',
        'searchurl' => 'http://www.scoutpedia.nl/index.php/Speciaal:Search?search=%s',
        'statsurl' => 'http://www.scoutpedia.nl/index.php/Speciaal:Statistics?action=raw'),
    'de' => array(
        'text' => 'Deutsch',
        'searchurl' => 'http://www.pfadiwiki.ch/index.php/Spezial:Search?search=%s',
        'statsurl' => 'http://www.pfadiwiki.ch/index.php/Spezial:Statistics?action=raw'),
    'fr' => array(
        'text' => 'Fran&ccedil;ais',
        'searchurl' => 'http://www.scoutopedia.net/w/Special:Search?search=%s',
        'statsurl' => 'http://www.scoutopedia.net/w/Special:Statistics?action=raw'),
    'en' => array(
        'text' => 'English',
        'searchurl' => 'http://en.scoutwiki.org/index.php?title=Special:Search&search=%s',
        'statsurl' => 'http://en.scoutwiki.org/index.php?title=Special:Statistics&action=raw'),
    'es' => array(
        'text' => 'Espa&ntilde;ol',
        'searchurl' => 'http://wiki.larocadelconsejo.net/?title=Especial:Search&search=%s',
        'statsurl' => 'http://wiki.larocadelconsejo.net/index.php?title=Especial:Statistics&action=raw'),
    'sv' => array(
        'text' => 'Svenska',
        'searchurl' => 'http://sv.scoutwiki.org/Special:Search?search=%s',
        'statsurl' => 'http://sv.scoutwiki.org/Special:Statistics?action=raw'),
    'eo' => array(
        'text' => 'Esperanto',
        'searchurl' => 'http://eo.scoutwiki.org/w/Speciala:Search?search=%s',
        'statsurl' => 'http://eo.scoutwiki.org/w/Speciala:Statistics?action=raw'),
    'ar' => array(
        'text' => '&#1575;&#1604;&#1593;&#1585;&#1576;&#1610;&#1577;',
        'searchurl' => 'http://ar.scoutwiki.org/index.php?title=%D8%AE%D8%A7%D8%B5:%D8%A8%D8%AD%D8%AB&search=%s',
        'statsurl' => 'http://ar.scoutwiki.org/index.php?title=%D8%AE%D8%A7%D8%B5:%D8%A7%D8%AD%D8%B5%D8%A7%D8%A1%D8%A7%D8%AA&action=raw'),
    'it' => array(
        'text' => 'Italiano',
        'searchurl' => 'http://it.scoutwiki.org/w/Speciale:Ricerca?search=%s',
        'statsurl' => 'http://it.scoutwiki.org/w/Speciale:Statistiche?action=raw'),
    );
 
//intro & other : automatic translations to improve.
$locales = array(
    'fi' => array(
        'search' => 'Hae',
        ),
    'en' => array(
        'search' => 'Search',
        'intro' => 'ScoutWiki, the international network of scouting wikies.',
        'other' => 'Other ScoutWiki websites:',
        ),
    'de' => array(
        'search' => 'Suche',
        'intro' => 'ScoutWiki, das internationale Netz von Enzyklopädien der Pfadfinderbewegung.',
        'other' => 'Anderen ScoutWiki websites:',
        ),
    'fr' => array(
        'search' => 'Rechercher',
        'intro' => 'ScoutWiki, le r&eacute;seau international d\'encyclop&eacute;dies du scoutisme.',
        'other' => 'Autres sites du r&eacute;seau ScoutWiki :',
        ),
    'nl' => array(
        'search' => 'Zoeken',
        'intro' => 'ScoutWiki, het internationale netwerk van scouting encyclopedie&#235;n.',
        'other' => 'Andere ScoutWiki websites:',
        ),
    'es' => array(
        'search' => 'Buscar',
        'intro' => 'ScoutWiki, la red internacional de enciclopedias del escultismo.',
        'other' => 'Otros lugares de la red ScoutWiki:',
        ),
    'ar' => array(
        'search' => 'بحث',
        ),
    'eo' => array(
        'search' => 'Serĉu',
        ),
    'sv' => array(
        'search' => 'Sök',
        ),
    'it' => array(
        'search' => 'Ricerca',
        'intro' => 'ScoutWiki, la rete internazionale di enciclopedie dell\'scoutismo.',
        'other' => 'Altre site del ScoutWiki :',
        ),
    );
 
function parse_preferred_langs($str)
{
    // Make them simple (sv-fi is just sv etc.)
    $simplize = TRUE;
 
    $languages = explode(',', $str);
    $langs = array();
    foreach ($languages as $lang)
    {
        $temp = explode(';', $lang);
        $temp2 = $temp;
        unset($temp2[0]);
        if (!empty($temp2))
        {
            $params = array();
            foreach ($temp2 as $parametre)
            {
                $param = explode('=', $parametre);
                $params[$param[0]] = $param[1];
            }
        }
        if ($simplize)
        {
            $temp2 = explode('-', $temp[0]);
            $temp[0] = $temp2[0];
        }
        $langs[$temp[0]] = $params;
    }
    return $langs;
}
 
function get_defaults()
{
    $searches = $GLOBALS['searches'];
    $locales = parse_preferred_langs($_SERVER['HTTP_ACCEPT_LANGUAGE']);
    $strings = $GLOBALS['locales'];
 
    $lang = NULL;
    $search = NULL;
    foreach (array_keys($locales) as $locale)
    {
        if (isset($searches[$locale]) && $search === NULL)
        {
            $search = $locale;
        }
        if (isset($strings[$locale]) && $lang === NULL)
        {
            $lang = $locale;
        }
        if ($lang !== NULL && $search !== NULL)
        {
            break;
        }
    }
    return array('site' => $search, 'texts' => $lang);
}
 
function translate($strname)
{
    $strings = $GLOBALS['locales'];
    $lang = $GLOBALS['defaults']['texts'];
 
    return ((!empty($strings[$lang][$strname])) ? $strings[$lang][$strname] :
        $strings['en'][$strname]);
}
 
function fetch_stats_to_cache($cachefile)
{
    $searches = $GLOBALS['searches'];
 
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_HEADER, 0);
    $stats = array();
 
    $tmpfile = '/tmp/temp.txt';
 
    foreach ($searches as $key => $value)
    {
        if (empty($value['statsurl']))
        {
            continue;
        }
 
        if (!$file = fopen($tmpfile, 'w')) {
            return FALSE;
        }
 
        curl_setopt($handle, CURLOPT_URL, $value['statsurl']);
        curl_setopt($handle, CURLOPT_FILE, $file);
        curl_exec($handle);
        fclose($file);
 
        $fdata = explode(';', file_get_contents($tmpfile));
        $data = array();
        foreach ($fdata as $row)
        {
            list($name, $value) = explode('=', $row);
            $data[$name] = $value;
        }
        $stats[$key] = $data;
    }
 
    curl_close($handle);
    unlink($tmpfile);
 
    if (!$file = fopen($cachefile, 'w')) {
        return FALSE;
    }
    if (fwrite($file, serialize($stats)) === FALSE) {
        return FALSE;
    }
    fclose($file);
    return TRUE;
}
 
function prepare_cache()
{
    $cachefile = '/tmp/sw_cache.txt';
    // Is the cache readable...
    if (is_readable($cachefile))
    {
        $mtime = filemtime($cachefile);
        $age = time() - $mtime;
        $permitted_age = 60 * 60 * 24; // One day
        // ... and new enough?
        if (($mtime !== FALSE) && ($age <= $permitted_age))
        {
            return $cachefile;
        }
    }
    // Cache not existing or too old -- renew.
    if (fetch_stats_to_cache($cachefile))
    {
        return $cachefile;
    }
    return FALSE;
}
 
function fetch_stats($cachefile)
{
    $stats = unserialize(file_get_contents($cachefile));
    return $stats;
}
 
$cachefile = prepare_cache();
 
if ($cachefile === FALSE)
{
    echo '<p class="alert">File error.</p>';
    return;
}
 
$stats = fetch_stats($cachefile);
 
foreach ($stats as $key => $value)
{
    $article[$key]=$value['good'];
}
//Then we begin the html display
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
 
  <title>ScoutWiki</title>
 
  <meta name="description" content="Main portal of ScoutWiki, the international network of scouting encyclopedias" />
  <meta name="keywords" content="scoutwiki, scoutpedia, scoutopedia, partiowiki, pfadiwiki, wikiscout, international, scouting, wiki, encyclopedia, encyclopedie, eclaireur, scoutisme, partio, pfadfinder, verkenner," />
  <meta name="subject" content="ScoutWiki : free scouting encyclopedias in various languages." />
  <meta name="robots" content="index, follow" />
  <meta name="revisit-after" content="20 days" />
  <meta name="author" content="Jeoire de Buretel de Chassey"/>
  <meta name="reply-to" content="contact@scoutwiki.org"/>
  <meta name="identifier-url" content="http://www.scoutwiki.org" />
  <meta name="expires" content="never" />
  <meta name="rating" content="general" />
  <meta name="Date-Creation-ddmmyyyy" content="28112006" />
  <meta name="Date-Revision-ddmmyyyy" content="16092007" />
  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
  <meta http-equiv="imagetoolbar" content="no" />
 
  <link rel="icon" type="image/png" href="/favicon.png" />
  <link rel="stylesheet" type="text/css" href="images/scoutwiki.css" />
 
</head>
<body>
<!--Original idea and bits of code : www.wikipedia.org-->
<div style="text-align: center; vertical-align: middle; max-width: 100%; width: 800px; margin: 20 auto 0 auto; height: 26em; position: relative;">
 
<div align="center"><img src="images/logo.gif" /></div>
 
<!--Top left : PartioWiki -->
<div style="position: absolute; top: 0%; right: 62%;" lang="fi" xml:lang="fi">
<a class ="wiki" href="http://fi.scoutwiki.org/Etusivu">Suomi</a><br />
<span class="texte">PartioWiki</span><br />
 
<small><?php echo $article['fi']; ?> artikkelia</small></div>
 
<!--Top right : Scoutopedia -->
<div style="position: absolute; top: 0%; left: 62%;" lang="fr" xml:lang="fr">
<a class ="wiki" href="http://www.scoutopedia.net/w/Accueil">Fran&ccedil;ais</a><br />
<span class="texte">Scoutopedia</span><br />
 
<small><?php echo $article['fr']; ?> articles</small></div>
 
<!--3rd floor left : Scoutpedia.nl -->
<div style="position: absolute; top: 16%; right: 68%;" lang="nl" xml:lang="nl">
<a class ="wiki" href="http://www.scoutpedia.nl/index.php/Hoofdpagina">Nederlands</a><br />
<span class="texte">Scoutpedia</span><br />
 
<small><?php echo $article['nl']; ?> artikelen</small></div>
 
<!--3rd floor right : SW English -->
<div style="position: absolute; top: 16%; left: 68%;" lang="en" xml:lang="en">
<a class ="wiki" href="http://en.scoutwiki.org/index.php?title=Main_Page">English</a><br />
<span class="texte">ScoutWiki</span><br />
 
<small><?php echo $article['en']; ?> articles</small></div>
 
<!--2nd floor left : WikiRoca -->
<div style="position: absolute; top: 32%; right: 74%;" lang="es" xml:lang="es">
<a class ="wiki" href="http://wiki.larocadelconsejo.net/index.php?title=Portada">Espa&ntilde;ol</a><br />
<span class="texte">WikiRoca</span><br />
 
<small><?php echo $article['es']; ?> articulos</small></div>
 
<!--2nd floor right : PfadiWiki -->
<div style="position: absolute; top: 32%; left: 74%;" lang="de" xml:lang="de">
<a class ="wiki" href="http://www.pfadiwiki.ch/index.php/Hauptseite">Deutsch</a><br />
<span class="texte">PfadiWiki</span><br />
 
<small><?php echo $article['de']; ?> artikeln</small></div>
 
<!--1st floor left : SV ScoutWiki -->
<div style="position: absolute; top: 49%; right: 80%;" lang="sv" xml:lang="sv">
<a class ="wiki" href="http://sv.scoutwiki.org/Huvudsida">Svenska</a><br />
<span class="texte">ScoutWiki</span><br />
 
<small><?php echo $article['sv']; ?> artiklar</small></div>
 
<!--1st floor right : IT ScoutWiki -->
<div style="position: absolute; top: 49%; left: 80%;" lang="it" xml:lang="it">
<a class ="wiki" href="http://it.scoutwiki.org/w/Pagina_principale">Italiano</a><br />
<span class="texte">ScoutWiki</span><br />
 
<small><?php echo $article['it']; ?> voci</small></div>
 
<!--Bottom left : SkoltVikio -->
<div style="position: absolute; top: 66%; right: 86%;" lang="eo" xml:lang="eo">
<a class ="wiki" href="http://eo.scoutwiki.org/w/%C4%88efpa%C4%9Do">Esperanto</a><br />
<span class="texte">SkoltVikio</span><br />
 
<small><?php echo $article['eo']; ?> artikoloj</small></div>
 
<!--Bottom right : AR ScoutWiki -->
<div style="position: absolute; top: 66%; left: 86%;" lang="ar" xml:lang="ar">
<a class ="wiki" href="http://ar.scoutwiki.org/index.php?title=%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9">&#1575;&#1604;&#1593;&#1585;&#1576;&#1610;&#1577;</a><br />
<span class="texte">ScoutWiki</span><br />
 
<small><?php echo $article['ar']; ?> &#1575;&#1604;&#1605;&#1575;&#1583;&#1577;</small></div>
</div>
<div align="center">
<?php
//displaying the ScoutWiki motto
echo translate ('intro');
 
//search engine
ksort($searches);
$defaults = get_defaults();
 
if (empty($_REQUEST['q']) || empty($_REQUEST['wiki']))
{
    echo print_scoutwiki_search_form($searches, $defaults['site']);
}
else
{
    redirect_to_search($_REQUEST['wiki'], $_REQUEST['q'], $searches);
}
 
function print_scoutwiki_search_form($searches, $default)
{
    $return = '<form method="get" action="">
        <input type="hidden" name="action" value="search_scoutwikis" />
 
        <p class="textfield">
            <input type="text" name="q" />
            <select name="wiki">';
    foreach ($searches as $key => $value)
    {
        $return.= '<option value="' . $key . '"';
        if ($key == $default)
        {
            $return.= ' selected="selected"';
        }
        $return.= '>' . $value['text'] . '</option>' . "\n";
    }
    $return.= '</select>
        </p>
 
        <p class="buttons">
            <input type="submit" value="' . translate('search') . '" />
        </p>';
    return $return;
}
 
function redirect_to_search($wiki, $q, $searches)
{
    if (!isset($searches[$wiki]) || !is_array($searches[$wiki]))
    {
        return FALSE;
    }
    $url = $searches[$wiki]['searchurl'];
    $url = str_replace('%s', urlencode($q), $url);
    header('Location: ' . $url);
    exit;
}
?>
<!--Other SWN links-->
<p class="texte"><?php echo translate ('other'); ?></p>
 
<table class="texte" style="margin-bottom:20px;">
 <tr>
  <td width="33%"><a class="minilien" href="http://media.scoutwiki.org/w/Main_page">ScoutMedia</a><br /><i>International media sharing wiki.</i></td>
  <td width="34%"><a class="minilien" href="http://forum.scoutwiki.org/">Forum</a><br /><i>The place to talk !</i></td>
  <td width="33%"><a class="minilien" href="http://asso.scoutwiki.org/">Association Wiki</a><br /><i>The home of the SWN Association</i></td>
 </tr>
</table>
</div>
<div align="right"><a class="minilien" href="http://mail.scoutwiki.org/" style="font-size:50%;" title="Private webmail access">Webmail access</a></div>
<!--Gogole analytics-->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-129623-7";
urchinTracker();
</script>
</body>
</html>