diff options
author | polo-pc-greta <ordipolo@gmx.fr> | 2025-03-27 10:13:03 +0100 |
---|---|---|
committer | polo-pc-greta <ordipolo@gmx.fr> | 2025-03-27 10:13:03 +0100 |
commit | df3612ed7e6691530503f79483d2fdbc032d01b8 (patch) | |
tree | 56d1c68fdc8625f5dad1937a654299d45142c79a /src/controller/installation.php | |
download | cms-df3612ed7e6691530503f79483d2fdbc032d01b8.zip |
mise en ligne github
Diffstat (limited to 'src/controller/installation.php')
-rw-r--r-- | src/controller/installation.php | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/src/controller/installation.php b/src/controller/installation.php new file mode 100644 index 0000000..a692618 --- /dev/null +++ b/src/controller/installation.php | |||
@@ -0,0 +1,144 @@ | |||
1 | <?php | ||
2 | // src/controller/installation.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | use App\Entity\Page; | ||
7 | use App\Entity\Node; | ||
8 | use App\Entity\NodeData; | ||
9 | use App\Entity\Image; | ||
10 | use Doctrine\Common\Collections\ArrayCollection; | ||
11 | use Doctrine\ORM\EntityManager; | ||
12 | |||
13 | function installation(): void | ||
14 | { | ||
15 | /* -- extensions PHP -- */ | ||
16 | $extensions = []; | ||
17 | foreach($extensions as $extension){ | ||
18 | if(!extension_loaded($extension)) | ||
19 | { | ||
20 | echo("l'extension " . $extension . ' est manquante<br>'); | ||
21 | } | ||
22 | } | ||
23 | if(!extension_loaded('imagick') && !extension_loaded('gd')){ | ||
24 | echo("il manque une de ces extensions au choix: imagick (de préférence) ou gd<br>"); | ||
25 | } | ||
26 | |||
27 | /* -- droits des fichiers et dossiers -- */ | ||
28 | $droits_dossiers = 0700; | ||
29 | $droits_fichiers = 0600; | ||
30 | |||
31 | // accès interdit en HTTP | ||
32 | if(!file_exists('../config/.htaccess')){ | ||
33 | $contenu = <<< HTACCESS | ||
34 | <Files "config.ini"> | ||
35 | Order Allow,Deny | ||
36 | Deny from all | ||
37 | </Files> | ||
38 | HTACCESS; | ||
39 | |||
40 | $fichier = fopen('../config/.htaccess', 'w'); | ||
41 | fputs($fichier, $contenu); | ||
42 | fclose($fichier); | ||
43 | chmod('../config/.htaccess', $droits_fichiers); | ||
44 | //echo("danger<br>pas de .htaccess dans config<br>prévenez le respondable du site"); | ||
45 | //die; | ||
46 | } | ||
47 | |||
48 | // accès limité en local (600) pour config.ini | ||
49 | if(substr(sprintf('%o', fileperms('../config/config.ini')), -4) != 600){ | ||
50 | chmod('../config/config.ini', $droits_fichiers); | ||
51 | } | ||
52 | |||
53 | // création de data et sous-dossiers | ||
54 | if(!file_exists('../data')){ | ||
55 | mkdir('../data/'); | ||
56 | chmod('../data/', $droits_dossiers); | ||
57 | } | ||
58 | if(!touch('../data')){ | ||
59 | echo("dossier data non autorisé en écriture"); | ||
60 | die; | ||
61 | } | ||
62 | $sous_dossiers = array('images', 'images-mini', 'videos'); | ||
63 | foreach ($sous_dossiers as $sous_dossier){ | ||
64 | if(!file_exists('../data/' . $sous_dossier)){ | ||
65 | mkdir('../data/' . $sous_dossier); | ||
66 | chmod('../data/' . $sous_dossier, $droits_dossiers); | ||
67 | } | ||
68 | if(!touch('../data/' . $sous_dossier)){ | ||
69 | echo("dossier data non autorisé en écriture"); | ||
70 | die; | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | // création de la page d'accueil à la toute 1ère visite du site | ||
76 | // les informations ici ne sont pas demandées à l'utilisateur pour l'instant (on verra ça plus tard) | ||
77 | function makeStartPage(EntityManager $entityManager){ | ||
78 | /* -- table page -- */ | ||
79 | // paramètres: name_page, end_of_path, reachable, in_menu, parent | ||
80 | $accueil = new Page('Accueil', 'accueil', true, true, NULL); | ||
81 | $connection = new Page('Connexion', 'connexion', true, false, NULL); | ||
82 | $article = new Page('Article', 'article', true, false, NULL); | ||
83 | $edit_page = new Page("Modification d'une page", 'modif_page', true, false, NULL); | ||
84 | $new_page = new Page('Nouvelle page', 'nouvelle_page', true, false, NULL); | ||
85 | $edit_paths = new Page("Menu et chemins", 'menu_chemins', true, false, NULL); | ||
86 | |||
87 | /* -- table node -- */ | ||
88 | // paramètres: name_node, article_timestamp, attributes, position, parent, page, article | ||
89 | $head_accueil = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'main', 'foot'], 'js_array' => ['main']], 1, NULL, $accueil, NULL); | ||
90 | $header = new Node('header', NULL, [], 2, NULL, NULL, NULL); | ||
91 | $nav = new Node('nav', NULL, [], 1, $header, NULL, NULL); | ||
92 | $main = new Node('main', NULL, [], 3, NULL, NULL, NULL); | ||
93 | $footer = new Node('footer', NULL, [], 4, NULL, NULL, NULL); | ||
94 | $breadcrumb = new Node('breadcrumb', NULL, [], 1, $footer, NULL, NULL); | ||
95 | $head_login = new Node('head', NULL, ["stop" => true, 'css_array' => ['body', 'head', 'nav', 'main'], 'js_array' => ['main']], 1, NULL, $connection, NULL); | ||
96 | $login = new Node('login', NULL, [], 1, $main, $connection, NULL); | ||
97 | $head_article = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'main', 'foot'], 'js_array' => ['main']], 1, NULL, $article, NULL); | ||
98 | |||
99 | /* -- table image -- */ | ||
100 | // paramètres: file_name, file_path, file_path_mini, mime_type, alt | ||
101 | $favicon = new Image("favicon48x48.png", NULL, "assets/favicon48x48.png", "image/png", "favicon"); | ||
102 | $logo = new Image("logo-120x75.jpg", NULL, "assets/logo-120x75.jpg", "image/png", "head_logo"); | ||
103 | $facebook = new Image("facebook.svg", NULL, "assets/facebook.svg", "image/svg+xml", "facebook"); | ||
104 | $instagram = new Image("instagram.svg", NULL, "assets/instagram.svg", "image/svg+xml", "instagram"); | ||
105 | $fond_piscine = new Image("fond-piscine.jpg", "assets/fond-piscine.jpg", NULL, "images/jpg", "fond-piscine"); | ||
106 | |||
107 | /* -- table node_data -- */ | ||
108 | // paramètres: data, node | ||
109 | $head_accueil_data = new NodeData(["description" => "Club, École de natation et Perfectionnement", "title" => "Les Nageurs Bigoudens"], $head_accueil, new ArrayCollection([$favicon])); | ||
110 | $header_data = new NodeData(["description" => "Club, École de natation et Perfectionnement", "title" => "Les Nageurs Bigoudens", "facebook_link" => "https://www.facebook.com/nageursbigoudens29120", "instagram_link" => "https://www.instagram.com/nageursbigoudens/"], $header, new ArrayCollection([$logo, $facebook, $instagram, $fond_piscine])); | ||
111 | $footer_data = new NodeData(["adresse" => "17, rue Raymonde Folgoas Guillou, 29120 Pont-l’Abbé", "contact_nom" => "Les Nageurs Bigoudens", "e_mail" => "nb.secretariat@orange.fr"], $footer); | ||
112 | $head_login_data = new NodeData(["description" => "Connexion", "title" => "Connexion"], $head_login, new ArrayCollection([$favicon])); | ||
113 | $head_article_data = new NodeData(["description" => "", "title" => ""], $head_article, new ArrayCollection([$favicon])); | ||
114 | |||
115 | $entityManager->persist($accueil); | ||
116 | $entityManager->persist($connection); | ||
117 | $entityManager->persist($article); | ||
118 | $entityManager->persist($edit_page); | ||
119 | $entityManager->persist($new_page); | ||
120 | $entityManager->persist($edit_paths); | ||
121 | $entityManager->persist($head_accueil); | ||
122 | $entityManager->persist($header); | ||
123 | $entityManager->persist($nav); | ||
124 | $entityManager->persist($main); | ||
125 | $entityManager->persist($footer); | ||
126 | $entityManager->persist($breadcrumb); | ||
127 | $entityManager->persist($head_login); | ||
128 | $entityManager->persist($login); | ||
129 | $entityManager->persist($head_article); | ||
130 | $entityManager->persist($favicon); | ||
131 | $entityManager->persist($logo); | ||
132 | $entityManager->persist($facebook); | ||
133 | $entityManager->persist($instagram); | ||
134 | $entityManager->persist($fond_piscine); | ||
135 | $entityManager->persist($head_accueil_data); | ||
136 | $entityManager->persist($header_data); | ||
137 | $entityManager->persist($footer_data); | ||
138 | $entityManager->persist($head_login_data); | ||
139 | $entityManager->persist($head_article_data); | ||
140 | $entityManager->flush(); | ||
141 | |||
142 | header('Location: ' . new URL); | ||
143 | die; | ||
144 | } \ No newline at end of file | ||