Overview
SHA1:163573d69f9cd0c9c0779547663d5682917dc37d
Date: 2016-04-25 13:52:30
User: bohwaz
Comment:Patch de @freepius ré-adapté pour permettre la réinitialisation des squelettes modifiés
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2016-04-25
14:37
[85db5abb1b] Cacher les membres des catégories cachées dans la liste des cotisations (user: bohwaz, tags: trunk)
13:52
[163573d69f] Patch de @freepius ré-adapté pour permettre la réinitialisation des squelettes modifiés (user: bohwaz, tags: trunk)
13:08
[88db127d21] Patch de @freepius pour rester en mode plein écran après enregistrement sur l'édition de squelette (user: bohwaz, tags: trunk)
Changes

Modified src/include/lib/Garradin/Squelette.php from [65f564084a] to [67661ea4c3].

889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
...
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
...
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
...
959
960
961
962
963
964
965
966





967
968
969
970
971
972
973
974
975
976
977
        {
            return null;
        }
    }

    static public function getSource($template)
    {
        if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!', $template))
            return false;

        $path = file_exists(DATA_ROOT . '/www/squelettes/' . $template)
            ? DATA_ROOT . '/www/squelettes/' . $template
            : ROOT . '/www/squelettes-dist/' . $template;

        if (!file_exists($path))
................................................................................
            return false;

        return file_get_contents($path);
    }

    static public function editSource($template, $content)
    {
        if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!', $template))
            return false;

        $path = DATA_ROOT . '/www/squelettes/' . $template;

        return file_put_contents($path, $content);
    }

    static public function resetSource($template)
    {
        if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!', $template))
            return false;

        if (file_exists(DATA_ROOT . '/www/squelettes/' . $template))
        {
            unlink(DATA_ROOT . '/www/squelettes/' . $template);
        }

        return true;
    }

    static public function listSources()
    {
        if (!file_exists(DATA_ROOT . '/www/squelettes'))
        {
            mkdir(DATA_ROOT . '/www/squelettes');
................................................................................
        while ($file = $dir->read())
        {
            if ($file[0] == '.')
                continue;

            if (!preg_match('/\.(?:css|x?html?|atom|rss|xml|svg|txt)$/i', $file))
                continue;
            
            $sources[] = $file;
        }

        $dir->close();

        $dir = dir(DATA_ROOT . '/www/squelettes');

        while ($file = $dir->read())
................................................................................
        {
            if ($file[0] == '.')
                continue;

            if (!preg_match('/\.(?:css|x?html?|atom|rss|xml|svg|txt)$/i', $file))
                continue;

            $sources[] = $file;





        }

        $dir->close();

        $sources = array_unique($sources);
        sort($sources);

        return $sources;
    }

}







|







 







|









|




|


|







 







|
|







 







|
>
>
>
>
>




<
|





889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
...
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
...
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
...
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975

976
977
978
979
980
981
        {
            return null;
        }
    }

    static public function getSource($template)
    {
        if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!i', $template))
            return false;

        $path = file_exists(DATA_ROOT . '/www/squelettes/' . $template)
            ? DATA_ROOT . '/www/squelettes/' . $template
            : ROOT . '/www/squelettes-dist/' . $template;

        if (!file_exists($path))
................................................................................
            return false;

        return file_get_contents($path);
    }

    static public function editSource($template, $content)
    {
        if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!i', $template))
            return false;

        $path = DATA_ROOT . '/www/squelettes/' . $template;

        return file_put_contents($path, $content);
    }

    static public function resetSource($template)
    {
        if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!i', $template))
            return false;

        if (file_exists(DATA_ROOT . '/www/squelettes/' . $template))
        {
            return unlink(DATA_ROOT . '/www/squelettes/' . $template);
        }

        return false;
    }

    static public function listSources()
    {
        if (!file_exists(DATA_ROOT . '/www/squelettes'))
        {
            mkdir(DATA_ROOT . '/www/squelettes');
................................................................................
        while ($file = $dir->read())
        {
            if ($file[0] == '.')
                continue;

            if (!preg_match('/\.(?:css|x?html?|atom|rss|xml|svg|txt)$/i', $file))
                continue;

            $sources[$file] = false;
        }

        $dir->close();

        $dir = dir(DATA_ROOT . '/www/squelettes');

        while ($file = $dir->read())
................................................................................
        {
            if ($file[0] == '.')
                continue;

            if (!preg_match('/\.(?:css|x?html?|atom|rss|xml|svg|txt)$/i', $file))
                continue;

            $sources[$file] = [
                // Est-ce que le fichier fait partie de la distribution de Garradin?
                // (Si non pas possible de faire un reset)
                'dist'  =>  array_key_exists($file, $sources),
                'mtime' =>  filemtime($dir->path.'/'.$file),
            ];
        }

        $dir->close();


        ksort($sources);

        return $sources;
    }

}

Modified src/templates/admin/config/site.tpl from [3d710490c2] to [75296b729d].

37
38
39
40
41
42
43
44


















45
46








47







48


49
50
51
52
    var skel_list = {$sources_json};
    var skel_current = "{$edit.file|escape}";
    </script>
    <script type="text/javascript" src="{$admin_url}static/scripts/skel_editor.js"></script>
{else}
    <div class="templatesList">
        <h3>Squelettes du site</h3>
        <ul>


















        {foreach from=$sources item="source"}
            <li><a href="?edit={$source|escape:'url'}">{$source|escape}</a></li>








        {/foreach}







        </ul>


    </div>
{/if}

{include file="admin/_foot.tpl"}







<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
|
>
>




37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    var skel_list = {$sources_json};
    var skel_current = "{$edit.file|escape}";
    </script>
    <script type="text/javascript" src="{$admin_url}static/scripts/skel_editor.js"></script>
{else}
    <div class="templatesList">
        <h3>Squelettes du site</h3>


        {if $reset_ok}
        <p class="confirm">
            Réinitialisation effectuée. Les squelettes ont été remis à jour
        </p>
        {/if}

        <form method="post" action="{$self_url|escape}">
            <table class="list">
                <thead>
                    <tr>
                        <td class="check"></td>
                        <th>Fichier</th>
                        <td>Dernière modification</td>
                        <td></td>
                    </tr>
                </thead>
                <tbody>
                {foreach from=$sources key="source" item="local"}

                    <tr>
                        <td>{if $local && $local.dist}<input type="checkbox" name="select[]" value="{$source|escape}" />{/if}</td>
                        <th><a href="{$admin_url}config/site.php?edit={$source|escape:'url'}" title="Éditer">{$source|escape}</a></th>
                        <td>{if $local}{$local.mtime|date_fr:'d/m/Y à H:i:s'}{else}<em>(fichier non modifié)</em>{/if}</td>
                        <td class="actions">
                            <a class="icn" href="{$admin_url}config/site.php?edit={$source|escape:'url'}" title="Éditer">✎</a>
                        </td>
                    </tr>
                {/foreach}
                </tbody>
            </table>

            <p class="actions">
                Pour les squelettes sélectionnés&nbsp;:
                <input type="submit" name="reset" value="Réinitialiser" onclick="return confirm('Effacer toute modification locale et restaurer les squelettes d\'installation ?');" />
                {csrf_field key="squelettes"}
            </p>
        </form>

    </div>
{/if}

{include file="admin/_foot.tpl"}

Modified src/www/admin/config/site.php from [44d976285c] to [0869dac1c0].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
28
29
30
31
32
33
34



























35
36
37
38
39
40
41
..
69
70
71
72
73
74
75

76
77
78
79
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$error = false;

if (isset($_GET['ok']))
{
    $error = 'OK';
}

if (!empty($_POST['save']))
{
    if (!Utils::CSRF_check('config_site'))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
................................................................................
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}




























if (Utils::get('edit'))
{
    $source = Squelette::getSource(Utils::get('edit'));

    if (!$source)
    {
................................................................................
    $tpl->assign('sources_json', json_encode(Squelette::listSources()));
}
else
{
    $tpl->assign('sources', Squelette::listSources());
}


$tpl->assign('error', $error);
$tpl->display('admin/config/site.tpl');

?>







<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>


<
<
1
2
3
4
5
6
7





8
9
10
11
12
13
14
..
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
..
91
92
93
94
95
96
97
98
99
100


<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$error = false;






if (!empty($_POST['save']))
{
    if (!Utils::CSRF_check('config_site'))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
................................................................................
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

if (Utils::post('select') && Utils::post('reset'))
{
    if (!Utils::CSRF_check('squelettes'))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try {
            foreach (Utils::post('select') as $source)
            {
                if (!Squelette::resetSource($source))
                {
                    throw new UserException('Impossible de réinitialiser le squelette.');
                }
            }
        
            Utils::redirect('/admin/config/site.php?reset_ok');
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}


if (Utils::get('edit'))
{
    $source = Squelette::getSource(Utils::get('edit'));

    if (!$source)
    {
................................................................................
    $tpl->assign('sources_json', json_encode(Squelette::listSources()));
}
else
{
    $tpl->assign('sources', Squelette::listSources());
}

$tpl->assign('reset_ok', Utils::get('reset_ok'));
$tpl->assign('error', $error);
$tpl->display('admin/config/site.tpl');


Modified src/www/admin/static/scripts/skel_editor.js from [f59b7095aa] to [0e1522caf5].

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
		sel.onchange = code.loadFile;

		for (var i in skel_list)
		{
			if (!skel_list.hasOwnProperty(i))
				continue;

			var skel = skel_list[i];
			var opt = document.createElement('option');
			opt.value = skel;
			opt.innerHTML = skel;
			opt.selected = (skel == skel_current) ? true : false;
			sel.appendChild(opt);
		}








|







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
		sel.onchange = code.loadFile;

		for (var i in skel_list)
		{
			if (!skel_list.hasOwnProperty(i))
				continue;

			var skel = i;
			var opt = document.createElement('option');
			opt.value = skel;
			opt.innerHTML = skel;
			opt.selected = (skel == skel_current) ? true : false;
			sel.appendChild(opt);
		}