source: spip-zone/_plugins_/pgn4spip/trunk/modeles/pgn.html @ 90115

Last change on this file since 90115 was 90115, checked in by fil@…, 6 years ago

correction minimaliste du charset; on passe du coup les données converties directement, au lieu d'un lien vers le fichier dont le charset est tout-pourri

File size: 2.7 KB
Line 
1[(#REM)
2/**********************************************************************************
3 * @Subject pgn.html skeleton template to manage .pgn file attached to the SPIP article
4 * @package pgn4spip: Embed pgn4web Chessboard plugin for SPIP 2.x or 3.x
5 * @version 2.61.0
6 * @copyright copyright (c) 2012 Matt Chesstale
7 * @license GNU General Public License version 3
8 * @language SPIP loop embedding PHP
9 *
10 * @history
11 * 2.61.0: Initial version for SPIP 2.1
12 * @reference:  Using models:                   http://www.spip.net/en_article3512.html
13 *                              Utiliser les modèles :  http://www.spip.net/fr_article3454.html
14 * @Usage
15 * If <doc1> is the document of number 1 associated to the downloaded .pgn file,
16 * use in the article the syntax: <pgn1|option="prm1=value1 prm2=value2 ...">
17 *
18 * @Example In a SPIP article:
19 * Example 1: <pgn1>
20 * Example 2: <pgn1|option="movesDisplay=puzzle">
21 * Example 3: <pgn1|option="md=p">
22 *            with md = movesDisplay and p = puzzle
23 * @Caution the options eo = extendedoptions and pd = pgnData are not allowed
24 * @Return      HTML code of the iframe to run board.html with the indicated .pgn document
25 **********************************************************************************/
26]
27<BOUCLE_pgn(DOCUMENTS){id_document=#ENV{id}}{extension==pgn}{tout}>
28<?php
29define('PLUGIN_Name', "pgn4spip");
30define('PATH_Fonctions', PLUGIN_Name . '/' . PLUGIN_Name . '_fonctions.php');
31if (!function_exists('pgn4spip_prepropre')) require _DIR_PLUGINS . PATH_Fonctions;
32
33define('QUOTE_HTML', '&quot;'); // '"' in HTML
34define('LenQuote', 6);
35
36$UrlRoot = '[(#URL_SITE_SPIP)]'; // Absolute URL of the SPIP web site root
37$UrlPgn = '[(#URL_DOCUMENT)]'; // Unique document having the id given as parameter of template from the SPIP loop
38while ((strlen($UrlPgn) > 1) && ($UrlPgn[0] == '.'))
39                $UrlPgn = substr($UrlPgn, 1); // Remove relative dot
40               
41if ($UrlPgn[0] != '/') $UrlPgn = '/' . $UrlPgn;
42$option = '[(#ENV{option})]'; // Get the options after "|" in the template <pgn1|option=...>
43$lenOpt = strlen($option);
44if ($lenOpt > LenQuote * 2)
45{
46        if (substr($option, 0, LenQuote) == QUOTE_HTML)
47                $option = substr($option, LenQuote); // Remove first double quote coded in HTML
48        $lenOpt = $lenOpt - LenQuote;
49        if (($lenOpt > LenQuote) && (substr($option, $lenOpt- LenQuote, LenQuote) == QUOTE_HTML))
50        {
51                $lenOpt = $lenOpt - LenQuote;
52                $option = substr($option, 0, $lenOpt); // Remove last double quote
53        }
54}
55if ($lenOpt > 0) $option .= ' '; // Separator with the two last options
56$option .= 'eo=true'; // eo = extendedoptions
57
58        $pgndata = file_get_contents([(#FICHIER|_q)]);
59        include_spip('inc/charsets');
60        $pgndata = importer_charset($pgndata, is_utf8($pgndata) ? 'utf-8' : 'iso-8859-1');
61
62        echo pgn4spip_prepropre('[pgn ' . $option . ']' . $pgndata . '[/pgn]');
63?>
64</BOUCLE_pgn>
Note: See TracBrowser for help on using the repository browser.