Skip to content

Commit a7727d8

Browse files
committed
Install: Create installation page
1 parent a6d8342 commit a7727d8

16 files changed

Lines changed: 642 additions & 15 deletions

File tree

admin/install.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* This software is governed by the CeCILL-B license. If a copy of this license
4+
* is not distributed with this file, you can obtain one at
5+
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
6+
*
7+
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
8+
* Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
9+
*
10+
* =============================
11+
*
12+
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
13+
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
14+
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
15+
*
16+
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
17+
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
18+
*/
19+
20+
use Framadate\Services\InstallService;
21+
use Framadate\Utils;
22+
23+
// Define values in place of config.php (that does not exists yet)
24+
const NOMAPPLICATION = 'Framadate';
25+
const DEFAULT_LANGUAGE = 'fr';
26+
const IMAGE_TITRE = 'images/logo-framadate.png';
27+
const LOG_FILE = 'admin/stdout.log';
28+
$ALLOWED_LANGUAGES = [
29+
'fr' => 'Français',
30+
'en' => 'English',
31+
'es' => 'Español',
32+
'de' => 'Deutsch',
33+
'it' => 'Italiano',
34+
];
35+
36+
require_once '../app/inc/init.php';
37+
define('CONF_FILENAME', ROOT_DIR . '/app/inc/config.php');
38+
39+
if (file_exists(CONF_FILENAME)) {
40+
header(('Location: ' . Utils::get_server_name()));
41+
exit;
42+
}
43+
44+
$error = null;
45+
46+
if (!empty($_POST)) {
47+
$installService = new InstallService();
48+
$result = $installService->install($_POST, $smarty);
49+
50+
if ($result['status'] === 'OK') {
51+
header(('Location: ' . Utils::get_server_name() . '/admin/migration.php'));
52+
exit;
53+
} else {
54+
$error = __('Error', $result['code']);
55+
}
56+
}
57+
58+
$smarty->assign('error', $error);
59+
$smarty->assign('title', __('Admin', 'Installation'));
60+
$smarty->assign('logsAreReadable', is_readable('../' . LOG_FILE));
61+
$smarty->display('admin/install.tpl');
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
/**
3+
* This software is governed by the CeCILL-B license. If a copy of this license
4+
* is not distributed with this file, you can obtain one at
5+
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
6+
*
7+
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
8+
* Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
9+
*
10+
* =============================
11+
*
12+
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
13+
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
14+
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
15+
*
16+
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
17+
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
18+
*/
19+
namespace Framadate\Services;
20+
use Framadate\Utils;
21+
use Smarty;
22+
23+
/**
24+
* This class helps to clean all inputs from the users or external services.
25+
*/
26+
class InstallService {
27+
28+
private $fields = array(
29+
'General' =>
30+
array(
31+
'appName' => 'Framadate',
32+
'appMail' => '',
33+
'responseMail' => '',
34+
'defaultLanguage' => 'fr',
35+
'cleanUrl' => true
36+
),
37+
'Database configuration' =>
38+
array(
39+
'dbConnectionString' => 'mysql:host=HOST;dbname=SCHEMA;port=3306',
40+
'dbUser' => 'root',
41+
'dbPassword' => '',
42+
'dbPrefix' => 'fd_',
43+
'migrationTable' => 'framadate_migration'
44+
)
45+
);
46+
47+
function __construct() {}
48+
49+
public function install($data, Smarty &$smarty) {
50+
// Check values are present
51+
if (empty($data['appName']) || empty($data['appMail']) || empty($data['defaultLanguage']) || empty($data['dbConnectionString']) || empty($data['dbUser'])) {
52+
return $this->error('MISSING_VALUES');
53+
}
54+
55+
// Connect to database
56+
$connect = $this->connectTo($data['dbConnectionString'], $data['dbUser'], $data['dbPassword']);
57+
if (!$connect) {
58+
return $this->error('CANT_CONNECT_TO_DATABASE');
59+
}
60+
61+
// Create database schema
62+
$this->createDatabaseSchema($connect);
63+
64+
// Write configuration to conf.php file
65+
$this->writeConfiguration($data, $smarty);
66+
67+
return $this->ok();
68+
}
69+
70+
function connectTo($connectionString, $user, $password) {
71+
try {
72+
$pdo = @new \PDO($connectionString, $user, $password);
73+
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
74+
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
75+
return $pdo;
76+
} catch(\Exception $e) {
77+
return null;
78+
}
79+
}
80+
81+
function writeConfiguration($data, Smarty &$smarty) {
82+
foreach($this->fields as $groupKey=>$group) {
83+
foreach ($group as $field=>$value) {
84+
$smarty->assign($field, $data[$field]);
85+
}
86+
}
87+
88+
$content = $smarty->fetch('admin/config.tpl');
89+
90+
$this->writeToFile($content);
91+
}
92+
93+
/**
94+
* @param $content
95+
*/
96+
function writeToFile($content) {
97+
file_put_contents(CONF_FILENAME, $content);
98+
}
99+
100+
/**
101+
* Execute SQL installation scripts.
102+
*
103+
* @param \PDO $connect
104+
*/
105+
function createDatabaseSchema($connect) {
106+
$dir = opendir(ROOT_DIR . '/install/');
107+
while ($dir && ($file = readdir($dir)) !== false) {
108+
if ($file !== '.' && $file !== '..' && strpos($file, '.mysql.auto.sql')) {
109+
$statement = file_get_contents(ROOT_DIR . '/install/' . $file);
110+
$connect->exec($statement);
111+
}
112+
}
113+
}
114+
115+
/**
116+
* @return array
117+
*/
118+
function ok() {
119+
return array(
120+
'status' => 'OK',
121+
'msg' => __f('Installation', 'Ended', Utils::get_server_name())
122+
);
123+
}
124+
125+
/**
126+
* @param $msg
127+
* @return array
128+
*/
129+
function error($msg) {
130+
return array(
131+
'status' => 'ERROR',
132+
'code' => $msg
133+
);
134+
}
135+
136+
}

app/inc/XXconfig.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* This software is governed by the CeCILL-B license. If a copy of this license
4+
* is not distributed with this file, you can obtain one at
5+
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
6+
*
7+
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
8+
* Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
9+
*
10+
* =============================
11+
*
12+
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
13+
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
14+
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
15+
*
16+
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
17+
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
18+
*/
19+
20+
// Fully qualified domain name of your webserver.
21+
// If this is unset or empty, the servername is determined automatically.
22+
// You *have to set this* if you are running Framedate behind a reverse proxy.
23+
// const APP_URL = '<www.mydomain.fr>';
24+
25+
// Application name
26+
const NOMAPPLICATION = 'Développement OPZ';
27+
28+
// Database administrator email
29+
const ADRESSEMAILADMIN = 'framadate-dev@olivierperez.fr';
30+
31+
// Email for automatic responses (you should set it to "no-reply")
32+
const ADRESSEMAILREPONSEAUTO = 'no-reply@olivierperez.fr';
33+
34+
// Database user
35+
const DB_USER= 'dev_framadate';
36+
37+
// Database password
38+
const DB_PASSWORD = 'dev_framadate';
39+
40+
// Database server name, leave empty to use a socket
41+
const DB_CONNECTION_STRING = 'mysql:host=localhost;dbname=framadate_dev;port=3306';
42+
43+
// Name of the table that store migration script already executed
44+
const MIGRATION_TABLE = 'framadate_migration';
45+
46+
// Table name prefix
47+
const TABLENAME_PREFIX = 'fd_';
48+
49+
// Default Language using POSIX variant of BC P47 standard (choose in $ALLOWED_LANGUAGES)
50+
const DEFAULT_LANGUAGE = 'fr';
51+
52+
// List of supported languages, fake constant as arrays can be used as constants only in PHP >=5.6
53+
$ALLOWED_LANGUAGES = [
54+
'fr' => 'Français',
55+
'en' => 'English',
56+
'es' => 'Español',
57+
'de' => 'Deutsch',
58+
'it' => 'Italiano',
59+
];
60+
61+
// Nom et emplacement du fichier image contenant le titre
62+
const IMAGE_TITRE = 'images/logo-framadate.png';
63+
64+
// Clean URLs, boolean
65+
const URL_PROPRE = false;
66+
67+
// Use REMOTE_USER data provided by web server
68+
const USE_REMOTE_USER = true;
69+
70+
// Path to the log file
71+
const LOG_FILE = 'admin/stdout.log';
72+
73+
// Days (after expiration date) before purge a poll
74+
const PURGE_DELAY = 60;
75+
76+
// Config
77+
$config = [
78+
/* general config */
79+
'use_smtp' => false, // use email for polls creation/modification/responses notification
80+
/* home */
81+
'show_what_is_that' => true, // display "how to use" section
82+
'show_the_software' => true, // display technical information about the software
83+
'show_cultivate_your_garden' => true, // display "developpement and administration" information
84+
/* create_classic_poll.php / create_date_poll.php */
85+
'default_poll_duration' => 180, // default values for the new poll duration (number of days).
86+
/* create_classic_poll.php */
87+
'user_can_add_img_or_link' => true, // user can add link or URL when creating his poll.
88+
];

app/inc/config.template.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@
5858
'it' => 'Italiano',
5959
];
6060

61-
// Path to logo
62-
const LOGOBANDEAU = '<relative path to the logo file>';
63-
64-
// Path to logo in PDF export
65-
const LOGOLETTRE = '<relative path to the logo file for pdf>';
66-
6761
// Nom et emplacement du fichier image contenant le titre
6862
const IMAGE_TITRE = 'images/logo-framadate.png';
6963

app/inc/init.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434
define('ROOT_DIR', __DIR__ . '/../../');
3535

3636
require_once __DIR__ . '/constants.php';
37-
require_once __DIR__ . '/config.php';
37+
@include_once __DIR__ . '/config.php';
3838
require_once __DIR__ . '/i18n.php';
3939

4040
// Smarty
4141
require_once __DIR__ . '/smarty.php';
4242

4343
// Connection to database
44-
$connect = new FramaDB(DB_CONNECTION_STRING, DB_USER, DB_PASSWORD);
45-
RepositoryFactory::init($connect);
44+
if (is_file(__DIR__ . '/config.php')) {
45+
$connect = new FramaDB(DB_CONNECTION_STRING, DB_USER, DB_PASSWORD);
46+
RepositoryFactory::init($connect);
47+
}
4648
$err = 0;

buildlang.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
include_once __DIR__ . '/app/inc/init.php';
3+
?>
4+
<html>
5+
<head>
6+
<meta charset="utf-8"/>
7+
</head>
8+
<body><pre><?php
9+
10+
$goodLang = $_GET['good'];
11+
$otherLang = $_GET['other'];
12+
13+
$good = json_decode(file_get_contents(__DIR__ . '/locale/' . $goodLang . '.json'), true);
14+
$other = json_decode(file_get_contents(__DIR__ . '/locale/' . $otherLang . '.json'), true);
15+
16+
foreach ($good as $sectionName => $section) {
17+
foreach ($section as $key => $value) {
18+
$good[$sectionName][$key] = getFromOther($other, $key, $value, $otherLang);
19+
}
20+
}
21+
22+
echo json_encode($good, JSON_PRETTY_PRINT | ~(JSON_ERROR_UTF8 | JSON_HEX_QUOT | JSON_HEX_APOS));
23+
24+
function getFromOther($other, $goodKey, $default, $otherLang) {
25+
foreach ($other as $sectionName => $section) {
26+
foreach ($section as $key => $value) {
27+
if (
28+
strtolower($key) === strtolower($goodKey) ||
29+
strtolower(trim($key)) === strtolower($goodKey) ||
30+
strtolower(substr($key, 0, strlen($key) - 1)) === strtolower($goodKey) ||
31+
strtolower(trim(substr(trim($key), 0, strlen($key) - 1))) === strtolower($goodKey)
32+
) {
33+
return $value;
34+
}
35+
}
36+
}
37+
38+
echo '[-]' . $goodKey . "\n";
39+
40+
return strtoupper($otherLang) . '_' . $default;
41+
}
42+
43+
?>
44+
</pre>
45+
</body>
46+
</html>

0 commit comments

Comments
 (0)