From 0ada6496e6c552c473a5816734b38896ccdd345b Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Sep 2013 22:52:53 +0200 Subject: [PATCH] ajout d'un installeur en ligne --- config.php | 84 ------- content/config/templates/mw_mysql.php | 19 ++ content/config/templates/mw_pdo_mysql.php | 19 ++ content/config/templates/mw_pdo_sqlite.php | 16 ++ content/config/templates/mw_xml.php | 14 ++ content/data/mysql/mtweb.sql | 153 ------------ content/data/xml/mw/actions_roles/.index | 1 - content/data/xml/mw/actions_roles/182.xml | 4 - content/data/xml/mw/actions_roles/187.xml | 4 - content/data/xml/mw/actions_roles/188.xml | 4 - content/data/xml/mw/actions_roles/189.xml | 4 - content/data/xml/mw/config/.index | 1 - content/data/xml/mw/config/1.xml | 4 - content/data/xml/mw/config/2.xml | 4 - content/data/xml/mw/config/21.xml | 4 - content/data/xml/mw/config/22.xml | 4 - content/data/xml/mw/config/34.xml | 4 - content/data/xml/mw/config/39.xml | 4 - content/data/xml/mw/config/40.xml | 4 - content/data/xml/mw/config/41.xml | 4 - content/data/xml/mw/config/55.xml | 4 - content/data/xml/mw/config/56.xml | 4 - content/data/xml/mw/config/57.xml | 4 - content/data/xml/mw/config/59.xml | 4 - content/data/xml/mw/roles/.index | 1 - content/data/xml/mw/roles/0.xml | 4 - content/data/xml/mw/roles/1.xml | 4 - content/data/xml/mw/roles/2.xml | 4 - content/data/xml/mw/roles/3.xml | 4 - content/data/xml/mw/users/.index | 1 - content/data/xml/mw/users/18.xml | 5 - content/data/xml/mw/users_roles/.index | 1 - content/data/xml/mw/users_roles/31.xml | 4 - content/data/xml/mw/users_roles/32.xml | 4 - content/data/xml/mw/users_roles/33.xml | 4 - index.php | 8 +- mw/app/controllers/install/index.php | 175 ++++++++++++++ mw/app/data/impl/mw_mysql.php | 14 +- mw/app/data/impl/mw_pdo_mysql.php | 14 +- mw/app/data/impl/mw_pdo_sqlite.php | 173 ++++++++++++++ mw/app/data/impl/mw_xml.php | 17 +- mw/app/data/impl/xml/mw_xml_data_handler.php | 4 +- mw/app/data/modules/share/mw_data_sgbds.php | 37 +++ mw/app/data/modules/sql/mw_data_sql_install.php | 138 +++++++++++ mw/app/data/modules/sql/mw_data_sqlite_install.php | 165 +++++++++++++ mw/app/data/modules/xml/mw_data_xml_install.php | 259 +++++++++++++++++++++ mw/app/data/mw_sgbd.php | 8 +- mw/app/init/0300_data.php | 68 +++--- mw/app/init/0400_config.php | 1 + mw/app/init/0500_users.php | 1 + mw/app/out/default/css/actions/install.css | 13 ++ mw/app/out/default/install.php | 36 +++ mw/app/out/default/js/actions/install.js | 15 ++ mw/app/out/default/layouts/install.xml | 8 + mw/app/out/default/layouts/users.xml | 2 +- mw/app/out/default/simple.php | 12 - mw/app/out/default/views/forms/contact/index.php | 2 +- mw/app/out/default/views/install/colonne.php | 0 mw/app/out/default/views/install/footer.php | 3 + mw/app/out/default/views/install/head.php | 42 ++++ mw/app/out/default/views/install/header.php | 1 + mw/app/out/default/views/install/index.php | 116 +++++++++ mw/env/modules/mw_env_data.php | 2 +- mw/env/modules/mw_env_out.php | 2 +- mw/env/modules/mw_env_plugins.php | 2 + mw/env/modules/mw_env_run.php | 3 +- mw/mw_app.php | 164 +++++++++++-- pathes.php | 33 +++ readme.txt | 39 +--- 69 files changed, 1524 insertions(+), 460 deletions(-) delete mode 100644 config.php create mode 100644 content/config/templates/mw_mysql.php create mode 100644 content/config/templates/mw_pdo_mysql.php create mode 100644 content/config/templates/mw_pdo_sqlite.php create mode 100644 content/config/templates/mw_xml.php delete mode 100644 content/data/mysql/mtweb.sql delete mode 100644 content/data/xml/mw/actions_roles/.index delete mode 100644 content/data/xml/mw/actions_roles/182.xml delete mode 100644 content/data/xml/mw/actions_roles/187.xml delete mode 100644 content/data/xml/mw/actions_roles/188.xml delete mode 100644 content/data/xml/mw/actions_roles/189.xml delete mode 100644 content/data/xml/mw/config/.index delete mode 100644 content/data/xml/mw/config/1.xml delete mode 100644 content/data/xml/mw/config/2.xml delete mode 100644 content/data/xml/mw/config/21.xml delete mode 100644 content/data/xml/mw/config/22.xml delete mode 100644 content/data/xml/mw/config/34.xml delete mode 100644 content/data/xml/mw/config/39.xml delete mode 100644 content/data/xml/mw/config/40.xml delete mode 100644 content/data/xml/mw/config/41.xml delete mode 100644 content/data/xml/mw/config/55.xml delete mode 100644 content/data/xml/mw/config/56.xml delete mode 100644 content/data/xml/mw/config/57.xml delete mode 100644 content/data/xml/mw/config/59.xml delete mode 100644 content/data/xml/mw/roles/.index delete mode 100644 content/data/xml/mw/roles/0.xml delete mode 100644 content/data/xml/mw/roles/1.xml delete mode 100644 content/data/xml/mw/roles/2.xml delete mode 100644 content/data/xml/mw/roles/3.xml delete mode 100644 content/data/xml/mw/users/.index delete mode 100644 content/data/xml/mw/users/18.xml delete mode 100644 content/data/xml/mw/users_roles/.index delete mode 100644 content/data/xml/mw/users_roles/31.xml delete mode 100644 content/data/xml/mw/users_roles/32.xml delete mode 100644 content/data/xml/mw/users_roles/33.xml create mode 100644 mw/app/controllers/install/index.php create mode 100644 mw/app/data/impl/mw_pdo_sqlite.php create mode 100644 mw/app/data/modules/share/mw_data_sgbds.php create mode 100644 mw/app/data/modules/sql/mw_data_sql_install.php create mode 100644 mw/app/data/modules/sql/mw_data_sqlite_install.php create mode 100644 mw/app/data/modules/xml/mw_data_xml_install.php create mode 100644 mw/app/out/default/css/actions/install.css create mode 100644 mw/app/out/default/install.php create mode 100644 mw/app/out/default/js/actions/install.js create mode 100644 mw/app/out/default/layouts/install.xml create mode 100644 mw/app/out/default/views/install/colonne.php create mode 100644 mw/app/out/default/views/install/footer.php create mode 100644 mw/app/out/default/views/install/head.php create mode 100644 mw/app/out/default/views/install/header.php create mode 100644 mw/app/out/default/views/install/index.php create mode 100644 pathes.php diff --git a/config.php b/config.php deleted file mode 100644 index 8753498..0000000 --- a/config.php +++ /dev/null @@ -1,84 +0,0 @@ - "/chemin/du/dossier" - // - // installation a la racine : - "web" => "/", - - // chemin HTTP du dossier "mw" - // absolu a partir de la racine HTTP du site - "mw_path" => "/mw", - - // chemin du dossier "mw" sur le systeme d'exploitation - // relatif au dossier de l'installation - // ou absolu dans le systeme de fichiers - "mw_dir" => "mw", - - // dossier des contenus editables par l'application - // relatif au dossier de l'installation - "content" => "content" - ); - - // -------------------------------------------------------------- - // base de donnees - // - - // mtweb propose deux modes de stockage des donnees - // - // - dans des fichiers XML - // - // - ou en utilisant un gestionnaire de base de donnees SQL - // - // ci-dessous deux exemples de configurations pour la connexion - // une pour XML (par defaut) et l'autre pour MySql (commentee) - - // --------------------------- XML - - $bdd = array( - // on utilise stockage de donnees dans des fichiers XML - "sgbd" => "xml", - // les fichiers XML sont enregistres dans le repertoire : - "host" => "content/data/xml", - // dans ce repertoire, la base de donnees est dans le dossier : - "base" => "mw" - ); - -/* - // --------------------------- MYSQL - // - // pour utiliser MySql, importez la base de donnees : - // - // mysql -u mysql_user -p < content/data/mysql/mtweb.sql - // - // et remplacez avec vos parametres de connexion : - - $bdd = array( - // on utilise MySql avec PDO (driver pdo_mysql) - "sgbd" => "pdo_mysql", - // hote du serveur MySql - "host" => "localhost", - // nom de la base de donnees - "base" => "mtweb", - // prefixe pour les noms des tables (*) - "table_prefix" => "mw_", - // identification pour la connexion sur le serveur MySql - "user" => "mysql_user", - "password" => "mysql_password" - ); - - // (*) le script mtweb.sql cree les tables avec le prefixe mw_ - // adaptez le script si vous utiliez un autre prefix -*/ - -?> \ No newline at end of file diff --git a/content/config/templates/mw_mysql.php b/content/config/templates/mw_mysql.php new file mode 100644 index 0000000..e4f5630 --- /dev/null +++ b/content/config/templates/mw_mysql.php @@ -0,0 +1,19 @@ + "mysql", + // hote du serveur MySql + "host" => "[bdd_host]", + // nom de la base de donnees + "base" => "[bdd_base]", + // prefixe pour les noms des tables (*) + "table_prefix" => "[bdd_prefix]", + // identification pour la connexion sur le serveur MySql + "user" => "[bdd_user]", + "password" => "[bdd_password]" + ); + +?> \ No newline at end of file diff --git a/content/config/templates/mw_pdo_mysql.php b/content/config/templates/mw_pdo_mysql.php new file mode 100644 index 0000000..e5cd2b5 --- /dev/null +++ b/content/config/templates/mw_pdo_mysql.php @@ -0,0 +1,19 @@ + "pdo_mysql", + // hote du serveur MySql + "host" => "[bdd_host]", + // nom de la base de donnees + "base" => "[bdd_base]", + // prefixe pour les noms des tables (*) + "table_prefix" => "[bdd_prefix]", + // identification pour la connexion sur le serveur MySql + "user" => "[bdd_user]", + "password" => "[bdd_password]" + ); + +?> \ No newline at end of file diff --git a/content/config/templates/mw_pdo_sqlite.php b/content/config/templates/mw_pdo_sqlite.php new file mode 100644 index 0000000..b09895a --- /dev/null +++ b/content/config/templates/mw_pdo_sqlite.php @@ -0,0 +1,16 @@ + "pdo_sqlite", + // repertoire contenant le fichier de base de donnees SQLite + "host" => "[bdd_host]", + // fichier de base de donnees SQLite + "base" => "[bdd_base]", + // prefixe pour les noms des tables + "table_prefix" => "[bdd_prefix]" + ); + +?> \ No newline at end of file diff --git a/content/config/templates/mw_xml.php b/content/config/templates/mw_xml.php new file mode 100644 index 0000000..4f5874a --- /dev/null +++ b/content/config/templates/mw_xml.php @@ -0,0 +1,14 @@ + "xml", + // les fichiers XML sont enregistres dans le repertoire : + "host" => "[bdd_host]", + // dans ce repertoire, la base de donnees est dans le dossier : + "base" => "[bdd_base]" + ); + +?> \ No newline at end of file diff --git a/content/data/mysql/mtweb.sql b/content/data/mysql/mtweb.sql deleted file mode 100644 index 0151c51..0000000 --- a/content/data/mysql/mtweb.sql +++ /dev/null @@ -1,153 +0,0 @@ --- phpMyAdmin SQL Dump --- version 3.3.2deb1ubuntu1 --- http://www.phpmyadmin.net --- --- Serveur: localhost --- Généré le : Dim 26 Mai 2013 à 15:46 --- Version du serveur: 5.1.69 --- Version de PHP: 5.3.2-1ubuntu4.19 - -SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; - --- --- Base de données: `mtweb` --- - --- -------------------------------------------------------- - --- --- Structure de la table `mw_actions_roles` --- - -CREATE TABLE IF NOT EXISTS `mw_actions_roles` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `action` varchar(255) NOT NULL, - `id_role` int(11) NOT NULL, - PRIMARY KEY (`id`), - KEY `id_role` (`id_role`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=21 ; - --- --- Contenu de la table `mw_actions_roles` --- - -INSERT INTO `mw_actions_roles` (`id`, `action`, `id_role`) VALUES -(13, 'admin', 1), -(14, 'users', 2), -(19, 'users/identification', 0), -(20, 'config', 3); - --- -------------------------------------------------------- - --- --- Structure de la table `mw_config` --- - -CREATE TABLE IF NOT EXISTS `mw_config` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `key` varchar(255) NOT NULL, - `value` text NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=38 ; - --- --- Contenu de la table `mw_config` --- - -INSERT INTO `mw_config` (`id`, `key`, `value`) VALUES -(1, 'site_name', 'mtweb'), -(2, 'max_list', '10'), -(3, 'description', ''), -(4, 'out', 'default'), -(5, 'start_action', ''), -(6, 'contact_form', '0'), -(8, 'email', ''), -(9, 'captcha', '0'), -(16, 'start_action_params', ''), -(20, 'out_navig_menu_top', 'on'), -(22, 'out_colonne', 'on'), -(29, 'default_allow', '1'); - --- -------------------------------------------------------- - --- --- Structure de la table `mw_roles` --- - -CREATE TABLE IF NOT EXISTS `mw_roles` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `nom` varchar(255) NOT NULL, - `intitule` varchar(255) NOT NULL, - KEY `id` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; - --- --- Contenu de la table `mw_roles` --- - -INSERT INTO `mw_roles` (`id`, `nom`, `intitule`) VALUES -(0, 'guest', 'invité'), -(1, 'admin', 'administrateur'), -(2, 'membre', 'membre'), -(3, 'webmaster', 'webmaster'); - --- -------------------------------------------------------- - --- --- Structure de la table `mw_users` --- - -CREATE TABLE IF NOT EXISTS `mw_users` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `login` varchar(255) NOT NULL, - `password` varchar(255) NOT NULL, - `email` varchar(255) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=20 ; - --- --- Contenu de la table `mw_users` --- - -INSERT INTO `mw_users` (`id`, `login`, `password`, `email`) VALUES -(19, 'admin', '25e4ee4e9229397b6b17776bfceaf8e7', 'admin@domain.tld'); - --- -------------------------------------------------------- - --- --- Structure de la table `mw_users_roles` --- - -CREATE TABLE IF NOT EXISTS `mw_users_roles` ( - `id_user` int(11) NOT NULL, - `id_role` int(11) NOT NULL, - PRIMARY KEY (`id_user`,`id_role`), - KEY `id_role` (`id_role`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Contenu de la table `mw_users_roles` --- - -INSERT INTO `mw_users_roles` (`id_user`, `id_role`) VALUES -(19, 1), -(19, 2), -(19, 3); - --- --- Contraintes pour les tables exportées --- --- DECOMMENTER POUR AJOUTER LES CONTRAINTES - --- --- Contraintes pour la table `mw_actions_roles` --- --- ALTER TABLE `mw_actions_roles` --- ADD CONSTRAINT `mw_actions_roles_ibfk_1` FOREIGN KEY (`id_role`) REFERENCES `mw_roles` (`id`); - --- --- Contraintes pour la table `mw_users_roles` --- --- ALTER TABLE `mw_users_roles` --- ADD CONSTRAINT `mw_users_roles_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `mw_users` (`id`), --- ADD CONSTRAINT `mw_users_roles_ibfk_2` FOREIGN KEY (`id_role`) REFERENCES `mw_roles` (`id`); diff --git a/content/data/xml/mw/actions_roles/.index b/content/data/xml/mw/actions_roles/.index deleted file mode 100644 index 66321c0..0000000 --- a/content/data/xml/mw/actions_roles/.index +++ /dev/null @@ -1 +0,0 @@ -189 \ No newline at end of file diff --git a/content/data/xml/mw/actions_roles/182.xml b/content/data/xml/mw/actions_roles/182.xml deleted file mode 100644 index 102f239..0000000 --- a/content/data/xml/mw/actions_roles/182.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/actions_roles/187.xml b/content/data/xml/mw/actions_roles/187.xml deleted file mode 100644 index 6f5c251..0000000 --- a/content/data/xml/mw/actions_roles/187.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/actions_roles/188.xml b/content/data/xml/mw/actions_roles/188.xml deleted file mode 100644 index 92faaf5..0000000 --- a/content/data/xml/mw/actions_roles/188.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/actions_roles/189.xml b/content/data/xml/mw/actions_roles/189.xml deleted file mode 100644 index 3794dfc..0000000 --- a/content/data/xml/mw/actions_roles/189.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/.index b/content/data/xml/mw/config/.index deleted file mode 100644 index fc9afb4..0000000 --- a/content/data/xml/mw/config/.index +++ /dev/null @@ -1 +0,0 @@ -59 \ No newline at end of file diff --git a/content/data/xml/mw/config/1.xml b/content/data/xml/mw/config/1.xml deleted file mode 100644 index 07d63e2..0000000 --- a/content/data/xml/mw/config/1.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/2.xml b/content/data/xml/mw/config/2.xml deleted file mode 100644 index 2b0c71f..0000000 --- a/content/data/xml/mw/config/2.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/21.xml b/content/data/xml/mw/config/21.xml deleted file mode 100644 index 64073f1..0000000 --- a/content/data/xml/mw/config/21.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/22.xml b/content/data/xml/mw/config/22.xml deleted file mode 100644 index e521aa4..0000000 --- a/content/data/xml/mw/config/22.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/34.xml b/content/data/xml/mw/config/34.xml deleted file mode 100644 index 56503ad..0000000 --- a/content/data/xml/mw/config/34.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/39.xml b/content/data/xml/mw/config/39.xml deleted file mode 100644 index cde73d8..0000000 --- a/content/data/xml/mw/config/39.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/40.xml b/content/data/xml/mw/config/40.xml deleted file mode 100644 index 9c7b4e4..0000000 --- a/content/data/xml/mw/config/40.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/41.xml b/content/data/xml/mw/config/41.xml deleted file mode 100644 index 36b4c19..0000000 --- a/content/data/xml/mw/config/41.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/55.xml b/content/data/xml/mw/config/55.xml deleted file mode 100644 index 30c5ac6..0000000 --- a/content/data/xml/mw/config/55.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/56.xml b/content/data/xml/mw/config/56.xml deleted file mode 100644 index 75dcdc3..0000000 --- a/content/data/xml/mw/config/56.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/57.xml b/content/data/xml/mw/config/57.xml deleted file mode 100644 index 5553e50..0000000 --- a/content/data/xml/mw/config/57.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/config/59.xml b/content/data/xml/mw/config/59.xml deleted file mode 100644 index db566d3..0000000 --- a/content/data/xml/mw/config/59.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/roles/.index b/content/data/xml/mw/roles/.index deleted file mode 100644 index 7813681..0000000 --- a/content/data/xml/mw/roles/.index +++ /dev/null @@ -1 +0,0 @@ -5 \ No newline at end of file diff --git a/content/data/xml/mw/roles/0.xml b/content/data/xml/mw/roles/0.xml deleted file mode 100644 index 4c10cf8..0000000 --- a/content/data/xml/mw/roles/0.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/roles/1.xml b/content/data/xml/mw/roles/1.xml deleted file mode 100644 index 59fc94b..0000000 --- a/content/data/xml/mw/roles/1.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/roles/2.xml b/content/data/xml/mw/roles/2.xml deleted file mode 100644 index 391bb4c..0000000 --- a/content/data/xml/mw/roles/2.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/roles/3.xml b/content/data/xml/mw/roles/3.xml deleted file mode 100644 index d711a8b..0000000 --- a/content/data/xml/mw/roles/3.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/users/.index b/content/data/xml/mw/users/.index deleted file mode 100644 index 25bf17f..0000000 --- a/content/data/xml/mw/users/.index +++ /dev/null @@ -1 +0,0 @@ -18 \ No newline at end of file diff --git a/content/data/xml/mw/users/18.xml b/content/data/xml/mw/users/18.xml deleted file mode 100644 index 91293cc..0000000 --- a/content/data/xml/mw/users/18.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/content/data/xml/mw/users_roles/.index b/content/data/xml/mw/users_roles/.index deleted file mode 100644 index dc7b54a..0000000 --- a/content/data/xml/mw/users_roles/.index +++ /dev/null @@ -1 +0,0 @@ -33 \ No newline at end of file diff --git a/content/data/xml/mw/users_roles/31.xml b/content/data/xml/mw/users_roles/31.xml deleted file mode 100644 index cb9fe04..0000000 --- a/content/data/xml/mw/users_roles/31.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/users_roles/32.xml b/content/data/xml/mw/users_roles/32.xml deleted file mode 100644 index b2b7d04..0000000 --- a/content/data/xml/mw/users_roles/32.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/content/data/xml/mw/users_roles/33.xml b/content/data/xml/mw/users_roles/33.xml deleted file mode 100644 index b16b47e..0000000 --- a/content/data/xml/mw/users_roles/33.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/index.php b/index.php index d75db99..3276947 100644 --- a/index.php +++ b/index.php @@ -1,10 +1,8 @@ init("config.php")){ - $app->run(); - $app->display(); - } + $app = new mw_app("pathes.php"); + if($app->init() && $app->run()) $app->display(); +// else $app->show_logs(); ?> \ No newline at end of file diff --git a/mw/app/controllers/install/index.php b/mw/app/controllers/install/index.php new file mode 100644 index 0000000..8407538 --- /dev/null +++ b/mw/app/controllers/install/index.php @@ -0,0 +1,175 @@ +env(); + $this->config_file = $env->path("content")."config/config.php"; + if(file_exists($this->config_file)) return "le site est deja installé"; + return true; + } + + function index(){ + $env = $this->env(); + $data = $env->data(); + $admin = array( + "login" => "", + "email" => "", + "password" => "" + ); + if(($sgbds = $data->sgbds()) === false){ + $env->erreur("impossible de lister les sgbds disponibles"); + return; + } + $table_prefix = isset($_POST["table_prefix"]) ? $_POST["table_prefix"] : "mw_"; + $env->add_table_prefix( + array( + "#--" => $table_prefix + ) + ); + $current_sgbd = "mw_pdo_sqlite"; + if($_POST){ + if(!isset($_POST["sgbd"])){ + $env->erreur("Parametre de SGBD manquant"); + return; + } + $current_sgbd = $_POST["sgbd"]; + $SGBD_FOUND = false; + foreach($sgbds as $class_name => $sgbd){ + if($current_sgbd == $class_name){ + $SGBD_FOUND = true; + break; + } + } + if(!$SGBD_FOUND){ + $env->erreur("SGBD inconnu: ".$current_sgbd); + return; + } + if(!file_exists($template_file = $env->path("content")."config/templates/".$current_sgbd.".php")){ + $env->erreur("le fichier de template pour la configuration avec ".$current_sgbd." n'existe pas"); + return; + } + $params = array( + "host" => isset($_POST[$current_sgbd."_host"]) ? $_POST[$current_sgbd."_host"] : "", + "base" => isset($_POST[$current_sgbd."_base"]) ? $_POST[$current_sgbd."_base"] : "", + "user" => isset($_POST[$current_sgbd."_user"]) ? $_POST[$current_sgbd."_user"] : "", + "password" => isset($_POST[$current_sgbd."_password"]) ? $_POST[$current_sgbd."_password"] : "" + ); + $admin = array( + "login" => trim($_POST["admin_login"]), + "email" => trim($_POST["admin_email"]), + "password" => $_POST["admin_password"] + ); + if(!$admin["login"]){ + $env->message("merci de choisir un login pour l'administrateur"); + } + if(!$admin["email"]){ + $env->message("merci de préciser l'email de l'administrateur"); + } + if($admin["password"]){ + if($admin["password"] != $_POST["admin_password_confirm"]){ + $env->message("la confirmation du mot de passe est incorrecte"); + } + } + else $env->message("merci de choisir un mot de passe pour l'administrateur"); + if(!$env->messages()){ + $sgbds[$current_sgbd] = null; + $impl = new $current_sgbd($params); + $sgbds[$current_sgbd] = $impl; + $data->set_sgbd( + new mw_sgbd( + $sgbds[$current_sgbd], + $env + ) + ); + $data->load_modules($env->path("mw_dir")."app/", "data/modules/".($current_sgbd == "mw_xml" ? "xml" : "sql")."/"); + if( + $current_sgbd == "mw_xml" + ){ + if(($res = $data->install_xml($params)) !== true){ + $env->message($res); + } + } + elseif( + $current_sgbd == "mw_mysql" + || $current_sgbd == "mw_pdo_mysql" + ){ + if(($res = $data->install_sql($params)) !== true){ + $env->message($res); + } + } + elseif( + $current_sgbd == "mw_pdo_sqlite" + ){ + if(($res = $data->install_sqlite($params)) !== true){ + $env->message($res); + } + } + } + if(!$env->messages()){ + if(($roles = $data->init_roles()) === false){ + $env->erreur("la base de données a été installée mais impossible de lire la liste des roles"); + return; + } + $admin_roles = array(); + foreach($roles as $id_role => $role){ + if( + ($role["nom"] == "admin") + || ($role["nom"] == "membre") + || ($role["nom"] == "webmaster") + ){ + $admin_roles[] = $id_role; + } + } + if(!$data->add_user($admin["login"], md5($admin["password"]), $admin["email"], $admin_roles)){ + $env->erreur("la base de données a été installée mais impossible d'ajouter l'administrateur"); + return; + } + } + if(!$env->messages()){ + if(!$content = @file_get_contents($template_file)){ + $env->erreur("impossible de lire le fichier de template pour la configuration avec ".$current_sgbd); + return; + } + if( + @file_put_contents( + $this->config_file, + str_replace( + array( + "[bdd_host]", + "[bdd_base]", + "[bdd_prefix]", + "[bdd_user]", + "[bdd_password]" + ), + array( + $params["host"], + $params["base"], + $table_prefix, + $params["user"], + $params["password"] + ), + $content + ) + ) === false + ){ + $env->erreur("impossible de créer le fichier de configuration"); + return; + } + $env->redirect( + $env->url(), + "le site a été installé" + ); + } + } + $env->set_out("sgbds", $sgbds); + $env->set_out("current_sgbd", $current_sgbd); + $env->set_out("table_prefix", $table_prefix); + $env->set_out("admin", $admin); + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/impl/mw_mysql.php b/mw/app/data/impl/mw_mysql.php index ba8f56a..3d146c4 100644 --- a/mw/app/data/impl/mw_mysql.php +++ b/mw/app/data/impl/mw_mysql.php @@ -13,11 +13,15 @@ function extention_ok(&$env) { return $this->EXTENTION_OK; } - function mw_mysql($host, $base, $user, $password){ - $this->host = $host; - $this->base = $base; - $this->user = $user; - $this->password = $password; + function authentication_required() { return true; } + + function sgbd_name() { return "MySql"; } + + function mw_mysql($params = array()){ + $this->host = isset($params["host"]) ? $params["host"] : "localhost"; + $this->base = isset($params["base"]) ? $params["base"] : "mtweb"; + $this->user = isset($params["user"]) ? $params["user"] : ""; + $this->password = isset($params["password"]) ? $params["password"] : ""; $this->EXTENTION_OK = function_exists("mysql_connect"); } diff --git a/mw/app/data/impl/mw_pdo_mysql.php b/mw/app/data/impl/mw_pdo_mysql.php index 283e50f..70f9876 100644 --- a/mw/app/data/impl/mw_pdo_mysql.php +++ b/mw/app/data/impl/mw_pdo_mysql.php @@ -17,11 +17,15 @@ function extention_ok(&$env) { return $this->EXTENTION_OK; } - function mw_pdo_mysql($host, $base, $user, $password){ - $this->host = $host; - $this->base = $base; - $this->user = $user; - $this->password = $password; + function authentication_required() { return true; } + + function sgbd_name() { return "PDO MySql"; } + + function mw_pdo_mysql($params = array()){ + $this->host = isset($params["host"]) ? $params["host"] : "localhost"; + $this->base = isset($params["base"]) ? $params["base"] : "mtweb"; + $this->user = isset($params["user"]) ? $params["user"] : ""; + $this->password = isset($params["password"]) ? $params["password"] : ""; $this->EXTENTION_OK = (extension_loaded("pdo") && extension_loaded("pdo_mysql")); } diff --git a/mw/app/data/impl/mw_pdo_sqlite.php b/mw/app/data/impl/mw_pdo_sqlite.php new file mode 100644 index 0000000..4ef1696 --- /dev/null +++ b/mw/app/data/impl/mw_pdo_sqlite.php @@ -0,0 +1,173 @@ +link; + } + + function extention_ok(&$env) { return $this->EXTENTION_OK; } + + function authentication_required() { return false; } + + function sgbd_name() { return "PDO SQLite"; } + + function mw_pdo_sqlite($params = array()){ + $this->host = isset($params["host"]) ? $params["host"] : "content/data/sqlite"; + $this->base = isset($params["base"]) ? $params["base"] : "mtweb.db"; + $this->user = isset($params["user"]) ? $params["user"] : ""; + $this->password = isset($params["password"]) ? $params["password"] : ""; + $this->EXTENTION_OK = (extension_loaded("pdo") && extension_loaded("pdo_sqlite")); + } + + function connect($host, $base, $user, $password){ + if($host) $host .= substr($host, -1) != "/" ? "/" : ""; + try{ + $this->link = null; + $this->link = new PDO("sqlite:".$host.$base); + $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->link->query("PRAGMA encoding = 'UTF-8'"); + } + catch(PDOException $e){ + throw new Exception($this->exception_out("Impossible d'etablir une connection au serveur")); + } + return true; + } + + function select_db($db_name){ + $this->base = $db_name; + return $this->connect($this->host, $this->base, $this->user, $this->password); + } + + function desc_table($table_name){ + $sql = "SELECT * from information_schema.columns where table_name='".$table_name."'"; + $rst = $this->query($sql); + $desc = array( + "name" => $table_name, + "attributs" => array() + ); + try{ + while($v_rst = $this->fetch_assoc($rst)){ + $desc["attributs"][$v_rst["COLUMN_NAME"]] = array( + "name" => $v_rst["COLUMN_NAME"], + "prymary_key" => $v_rst["COLUMN_KEY"] == "PRI" ? true : false, + "auto_increment" => $v_rst["EXTRA"] == "auto_increment" ? true : false + ); + } + $this->free_result($rst); + } + catch(Exception $e){ + throw new Exception($this->exception_out("Impossible de lire la description de la table")); + } + return $desc; + } + + function table_exists($table_name){ + if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); + $EXISTS = false; + try{ + $rst = $this->query("SELECT name FROM sqlite_master WHERE type='table'"); + while($v_rst = $rst->fetch()){ + if($v_rst[0] == $table_name){ + $EXISTS = true; + break; + } + } + $this->free_result($rst); + } + catch(Exception $e){ + throw new Exception($this->exception_out("Impossible de savoir si la table existe")); + } + return $EXISTS; + } + + function field_exists($table_name, $field_name){ + if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); + if(!($desc = $this->desc_table($table_name))){ + throw new Exception($this->exception_out("Impossible de lire la description de la table")); + } + $EXISTS = false; + foreach($desc["attributs"] as $attribut_name => $attribut){ + if($field_name == $attribut_name){ + $EXISTS = true; + break; + } + } + return $EXISTS; + } + + function query($query_string){ + if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); + if(!($result = $this->link->query($query_string))){ + throw new Exception($this->exception_out("Syntaxe invalide dans une requete")); + } + return $result; + } + + function fetch_assoc($rst){ + if(!$this->link){ + throw new Exception($this->exception_out("fetch_assoc sans connexion")); + } + if(!$rst){ + throw new Exception($this->exception_out("fetch_assoc sans result handler")); + } + try{ + $tuple = $rst->fetch(PDO::FETCH_ASSOC); + } + catch(Exception $e){ + throw new Exception($this->exception_out("erreur fetch_assoc")); + } + return $tuple; + } + + function insert_id(){ + if(!$this->link){ + throw new Exception($this->exception_out("insert_id sans connexion")); + } + try{ + $id = $this->link->lastInsertId(); + } + catch(Exception $e){ + throw new Exception($this->exception_out("erreur insert_id")); + } + return $id; + } + + function free_result($rst){ + if(!$this->link){ + throw new Exception($this->exception_out("free_result sans connexion")); + } + if(!$rst){ + throw new Exception($this->exception_out("free_result sans result handler")); + } + try{ + $rst->closeCursor(); + $rst = null; + } + catch(Exception $e){ + throw new Exception($this->exception_out("erreur free_result")); + } + return true; + } + + function close(){ + $this->link = null; + return true; + } + + function exception_out($message){ + return "[erreur] sqlite : ".$message; + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/impl/mw_xml.php b/mw/app/data/impl/mw_xml.php index 2691a99..335e974 100644 --- a/mw/app/data/impl/mw_xml.php +++ b/mw/app/data/impl/mw_xml.php @@ -14,8 +14,13 @@ var $data_handlers; var $last_data_handler; - function mw_xml($host, $base, $user, $password){ - $this->init_xml_env($host, $base, $user, $password); + function mw_xml($params = array()){ + $this->init_xml_env( + isset($params["host"]) ? $params["host"] : "content/data/xml", + isset($params["base"]) ? $params["base"] : "mw", + isset($params["user"]) ? $params["user"] : "", + isset($params["password"]) ? $params["password"] : "" + ); $this->EXTENTION_OK = true; } @@ -40,6 +45,10 @@ return $this->EXTENTION_OK; } + function authentication_required() { return false; } + + function sgbd_name() { return "XML"; } + function init_xml_env($host, $base, $user, $password){ $this->host = $host.($host && substr($host, -1) != "/" ? "/" : ""); $this->base = $base.($base && substr($base, -1) != "/" ? "/" : ""); @@ -106,11 +115,11 @@ return false; } - function add_data($data_path, $data){ + function add_data($data_path, $data, $index = null){ $dh = ++$this->last_data_handler; $this->data_handlers[$dh] = new mw_xml_data_handler($this->xml_data, $data_path); if($this->data_handlers[$dh]->open_data(false)){ - $res = $this->data_handlers[$dh]->add_data($data); + $res = $this->data_handlers[$dh]->add_data($data, $index); if($res) $res = $this->last_index($dh); $this->close_data($dh); return $res; diff --git a/mw/app/data/impl/xml/mw_xml_data_handler.php b/mw/app/data/impl/xml/mw_xml_data_handler.php index 446a264..6ed8206 100644 --- a/mw/app/data/impl/xml/mw_xml_data_handler.php +++ b/mw/app/data/impl/xml/mw_xml_data_handler.php @@ -73,8 +73,8 @@ return false; } - function add_data($data){ - $index = $this->inc_index(); + function add_data($data, $index = null){ + if(!isset($index)) $index = $this->inc_index(); if(isset($index)){ if(is_array($data)) return $this->xml_data->add_data($this->data_path, $index, $data); } diff --git a/mw/app/data/modules/share/mw_data_sgbds.php b/mw/app/data/modules/share/mw_data_sgbds.php new file mode 100644 index 0000000..db90855 --- /dev/null +++ b/mw/app/data/modules/share/mw_data_sgbds.php @@ -0,0 +1,37 @@ +env(); + $sgbds = array(); + $impls_dir = $env->app_file("data/impl"); + if(!file_exists($impls_dir) || !is_dir($impls_dir)){ + return false; + } + if($dh = opendir($impls_dir)){ + $OK = true; + while($OK && ($impl_file = readdir($dh)) !== false){ + if(substr($impl_file, 0 ,1) !== "." && substr($impl_file, -4) == ".php"){ + require_once $impls_dir."/".$impl_file; + if(class_exists($class_name = substr($impl_file, 0, -4))){ + if( + method_exists($class_name, "sgbd_name") + && method_exists($class_name, "extention_ok") + ){ + $impl = new $class_name(); + if($impl->extention_ok($env)) $sgbds[$class_name] = $impl; + } + } + } + } + } + else{ + return false; + } + return $sgbds; + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/modules/sql/mw_data_sql_install.php b/mw/app/data/modules/sql/mw_data_sql_install.php new file mode 100644 index 0000000..19a8a8d --- /dev/null +++ b/mw/app/data/modules/sql/mw_data_sql_install.php @@ -0,0 +1,138 @@ +env(); + $data = $env->data(); + $sgbd = $data->sgbd(); + $host = isset($params["host"]) ? $params["host"] : ""; + $base = isset($params["base"]) ? $params["base"] : ""; + $user = isset($params["user"]) ? $params["user"] : ""; + $password = isset($params["password"]) ? $params["password"] : ""; + try{ + $sgbd->connect( + $host, + $base, + $user, + $password + ); + $sgbd->select_db($base); + } + catch(Exception $e){ + return $e->getMessage(); + } + try{ + $EXISTS = + $sgbd->table_exists("#--actions_roles") + || $sgbd->table_exists("#--config") + || $sgbd->table_exists("#--roles") + || $sgbd->table_exists("#--users") + || $sgbd->table_exists("#--users_roles"); + } + catch(Exception $e){ + return "impossible de savoir si les tables existent deja"; + } + if($EXISTS){ + return "des tables a installer existent deja en base. installation annulee"; + } + try{ + + $sql = + "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\""; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--actions_roles(" + ." id int(11) NOT NULL AUTO_INCREMENT," + ." `action` varchar(255) NOT NULL," + ." id_role int(11) NOT NULL," + ." PRIMARY KEY (id)," + ." KEY id_role(id_role)" + .") DEFAULT CHARSET=utf8"; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--config(" + ." id int(11) NOT NULL AUTO_INCREMENT," + ." `key` varchar(255) NOT NULL," + ." `value` text NOT NULL," + ." PRIMARY KEY (id)" + .") DEFAULT CHARSET=utf8"; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--roles(" + ." id int(11) NOT NULL AUTO_INCREMENT," + ." nom varchar(255) NOT NULL," + ." intitule varchar(255) NOT NULL," + ." KEY id (id)" + .") DEFAULT CHARSET=utf8"; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--users(" + ." id int(11) NOT NULL AUTO_INCREMENT," + ." login varchar(255) NOT NULL," + ." password varchar(255) NOT NULL," + ." email varchar(255) NOT NULL," + ." PRIMARY KEY (id)" + .") DEFAULT CHARSET=utf8"; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--users_roles(" + ." id_user int(11) NOT NULL," + ." id_role int(11) NOT NULL," + ." PRIMARY KEY (id_user,id_role)," + ." KEY id_role(id_role)" + .") DEFAULT CHARSET=utf8"; + $sgbd->query($sql); + + } + catch(Exception $e){ + return "imposible de creer les tables en base"; + } + try{ + $sql = + "INSERT INTO #--actions_roles(`id`, `action`, `id_role`) VALUES" + ."(13, 'admin', 1)," + ."(14, 'users', 2)," + ."(19, 'users/identification', 0)," + ."(20, 'config', 3)"; + $sgbd->query($sql); + + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES" + ."(1, 'site_name', 'mtweb')," + ."(2, 'max_list', '10')," + ."(3, 'description', '')," + ."(4, 'out', 'default')," + ."(5, 'start_action', '')," + ."(6, 'contact_form', '0')," + ."(8, 'email', '')," + ."(9, 'captcha', '0')," + ."(16, 'start_action_params', '')," + ."(20, 'out_navig_menu_top', 'on')," + ."(22, 'out_colonne', 'on')," + ."(29, 'default_allow', '1')"; + $sgbd->query($sql); + + $sql = + "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES" + ."(0, 'guest', 'invité')," + ."(1, 'admin', 'administrateur')," + ."(2, 'membre', 'membre')," + ."(3, 'webmaster', 'webmaster')"; + $sgbd->query($sql); + + } + catch(Exception $e){ + return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut."; + } + return true; + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/modules/sql/mw_data_sqlite_install.php b/mw/app/data/modules/sql/mw_data_sqlite_install.php new file mode 100644 index 0000000..8c26638 --- /dev/null +++ b/mw/app/data/modules/sql/mw_data_sqlite_install.php @@ -0,0 +1,165 @@ +env(); + $data = $env->data(); + $sgbd = $data->sgbd(); + $host = isset($params["host"]) ? $params["host"] : ""; + $base = isset($params["base"]) ? $params["base"] : ""; + $user = isset($params["user"]) ? $params["user"] : ""; + $password = isset($params["password"]) ? $params["password"] : ""; + if(!$host || !$base) return "paramètres manquant pour la base SQLite"; + if(!is_dir($host)){ + $parent_dir = dirname($host); + if(is_dir($parent_dir)) @mkdir($host); + if(!is_dir($host)) return "impossible de créer le répertoire des données SQLite"; + } + try{ + $sgbd->connect( + $host, + $base, + $user, + $password + ); + $sgbd->select_db($base); + } + catch(Exception $e){ + return $e->getMessage(); + } + try{ + $EXISTS = + $sgbd->table_exists("#--actions_roles") + || $sgbd->table_exists("#--config") + || $sgbd->table_exists("#--roles") + || $sgbd->table_exists("#--users") + || $sgbd->table_exists("#--users_roles"); + } + catch(Exception $e){ + return "impossible de savoir si les tables existent deja"; + } + if($EXISTS){ + return "des tables a installer existent deja en base. installation annulee"; + } + try{ + + $sql = + "CREATE TABLE #--actions_roles(" + ." id INTEGER PRIMARY KEY AUTOINCREMENT," + ." `action` TEXT NOT NULL," + ." id_role INTEGER NOT NULL" + .")"; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--config(" + ." id INTEGER PRIMARY KEY AUTOINCREMENT," + ." `key` TEXT NOT NULL," + ." `value` TEXT NOT NULL" + .")"; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--roles(" + ." id INTEGER PRIMARY KEY AUTOINCREMENT," + ." nom TEXT NOT NULL," + ." intitule TEXT NOT NULL" + .")"; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--users(" + ." id INTEGER PRIMARY KEY AUTOINCREMENT," + ." login TEXT NOT NULL," + ." password TEXT NOT NULL," + ." email TEXT NOT NULL" + .")"; + $sgbd->query($sql); + + $sql = + "CREATE TABLE #--users_roles(" + ." id INTEGER PRIMARY KEY AUTOINCREMENT," + ." id_user INTEGER NOT NULL," + ." id_role INTEGER NOT NULL" + .")"; + $sgbd->query($sql); + + } + catch(Exception $e){ + return "imposible de creer les tables en base. ".$e->getMessage(); + } + try{ + $sql = + "INSERT INTO #--actions_roles (`id`, `action`, `id_role`) VALUES (13, 'admin', 1)"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--actions_roles (`id`, `action`, `id_role`) VALUES (14, 'users', 2)"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--actions_roles (`id`, `action`, `id_role`) VALUES (19, 'users/identification', 0)"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--actions_roles (`id`, `action`, `id_role`) VALUES (20, 'config', 3)"; + $sgbd->query($sql); + + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (1, 'site_name', 'mtweb')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (2, 'max_list', '10')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (3, 'description', '')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (4, 'out', 'default')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (5, 'start_action', '')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (6, 'contact_form', '0')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (8, 'email', '')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (9, 'captcha', '0')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (16, 'start_action_params', '')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (20, 'out_navig_menu_top', 'on')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (22, 'out_colonne', 'on')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--config(id, `key`, `value`) VALUES (29, 'default_allow', '1')"; + $sgbd->query($sql); + + $sql = + "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES (0, 'guest', 'invité')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES (1, 'admin', 'administrateur')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES (2, 'membre', 'membre')"; + $sgbd->query($sql); + $sql = + "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES (3, 'webmaster', 'webmaster')"; + $sgbd->query($sql); + + } + catch(Exception $e){ + return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut."; + } + return true; + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/modules/xml/mw_data_xml_install.php b/mw/app/data/modules/xml/mw_data_xml_install.php new file mode 100644 index 0000000..9bebcf9 --- /dev/null +++ b/mw/app/data/modules/xml/mw_data_xml_install.php @@ -0,0 +1,259 @@ +env(); + $data = $env->data(); + $sgbd = $data->sgbd(); + $host = isset($params["host"]) ? $params["host"] : ""; + $base = isset($params["base"]) ? $params["base"] : ""; + $user = isset($params["user"]) ? $params["user"] : ""; + $password = isset($params["password"]) ? $params["password"] : ""; + if(!$host || !$base) return "paramètres manquant pour la base XML"; + $host .= substr($host, -1) == "/" ? "" : "/"; + if(!is_dir($host)){ + $parent_dir = dirname($host); + if(is_dir($parent_dir)) @mkdir($host); + if(!is_dir($host)) return "impossible de créer le répertoire des données XML"; + } + $base_dir = $host.$base; + if(!is_dir($base_dir)) @mkdir($base_dir); + if(!is_dir($base_dir)) return "impossible de créer le dossier de la base XML"; + $base .= substr($base, -1) == "/" ? "" : "/"; + if( + !$sgbd->connect( + $host, + $base, + $user, + $password + ) + || !$sgbd->select_db($base) + ){ + return "impossible de se connecter à la base XML"; + } + $ERROR = false; + $EXISTS = false; + if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("actions_roles"); + $ERROR = !isset($EXISTS); + if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("config"); + $ERROR = !isset($EXISTS); + if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("roles"); + $ERROR = !isset($EXISTS); + if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("users"); + $ERROR = !isset($EXISTS); + if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("users_roles"); + $ERROR = !isset($EXISTS); + if($ERROR){ + return "impossible de savoir si les tables existent deja"; + } + if($EXISTS){ + return "des tables a installer existent deja en base. installation annulee"; + } + if(!$ERROR) if(!$sgbd->create_data("actions_roles")) $ERROR = true; + if(!$ERROR) if(!$sgbd->create_data("config")) $ERROR = true; + if(!$ERROR) if(!$sgbd->create_data("roles")) $ERROR = true; + if(!$ERROR) if(!$sgbd->create_data("users")) $ERROR = true; + if(!$ERROR) if(!$sgbd->create_data("users_roles")) $ERROR = true; + if($ERROR){ + return "imposible de creer les tables en base"; + } + + // ------------------------------------ actions_roles + if(!$ERROR) if( + !$sgbd->add_data( + "actions_roles", + array( + "action" => "admin", + "id_role" => 1 + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "actions_roles", + array( + "action" => "users", + "id_role" => 2 + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "actions_roles", + array( + "action" => "users/identification", + "id_role" => 0 + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "actions_roles", + array( + "action" => "config", + "id_role" => 3 + ) + ) + ) $ERROR = true; + + // ------------------------------------ config + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "site_name", + "value" => "mtweb" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "max_list", + "value" => "10" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "description", + "value" => "" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "out", + "value" => "default" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "start_action", + "value" => "" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "contact_form", + "value" => "0" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "email", + "value" => "" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "captcha", + "value" => "0" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "start_action_params", + "value" => "" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "out_navig_menu_top", + "value" => "on" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "out_colonne", + "value" => "on" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "config", + array( + "key" => "default_allow", + "value" => "1" + ) + ) + ) $ERROR = true; + + // ------------------------------------ roles + if(!$ERROR){ + $res = $sgbd->add_data( + "roles", + array( + "nom" => "guest", + "intitule" => "invité" + ), + 0 + ); + if(!isset($res)) $ERROR = true; + } + if(!$ERROR) if( + !$sgbd->add_data( + "roles", + array( + "nom" => "admin", + "intitule" => "administrateur" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "roles", + array( + "nom" => "membre", + "intitule" => "membre" + ) + ) + ) $ERROR = true; + if(!$ERROR) if( + !$sgbd->add_data( + "roles", + array( + "nom" => "webmaster", + "intitule" => "webmaster" + ) + ) + ) $ERROR = true; + + if($ERROR){ + return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut."; + } + + return true; + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/mw_sgbd.php b/mw/app/data/mw_sgbd.php index faf88e2..c3ca66e 100644 --- a/mw/app/data/mw_sgbd.php +++ b/mw/app/data/mw_sgbd.php @@ -14,6 +14,10 @@ return $this->sgbd_impl->extention_ok($this->env); } + function authentication_required(){ + return $this->sgbd_impl->authentication_required(); + } + function connect($host, $base, $user, $password){ return $this->sgbd_impl->connect($host, $base, $user, $password); } @@ -113,9 +117,9 @@ return $this->sgbd_impl->fetch_data($dh); } - function add_data($data_path, $data){ + function add_data($data_path, $data, $index = null){ if(!method_exists($this->sgbd_impl, "add_data")) return false; - return $this->sgbd_impl->add_data($data_path, $data); + return $this->sgbd_impl->add_data($data_path, $data, $index); } function last_index($dh){ diff --git a/mw/app/init/0300_data.php b/mw/app/init/0300_data.php index ea7ad71..9d5e2f9 100644 --- a/mw/app/init/0300_data.php +++ b/mw/app/init/0300_data.php @@ -2,40 +2,48 @@ if(!class_exists("mw_sgbd")) require_once $this->app_file("data/mw_sgbd.php"); if(!class_exists("mw_data")) require_once $this->app_file("data/mw_data.php"); - if($this->app_file_exists("data/impl/mw_".$this->bdd("sgbd").".php")){ + if(($plugins = $this->plugins("DESC")) === false){ + $this->erreur("Impossible de lire les plugins pour charger les modules de donnees", true); + } + $data = new mw_data(true); + if($this->bdd("sgbd")){ + if(!$this->app_file_exists("data/impl/mw_".$this->bdd("sgbd").".php")){ + $this->erreur("Impossible de trouver le fichier d'implementation du sgbd ".$this->bdd("sgbd"), true); + } $sgbd_impl = "mw_".$this->bdd("sgbd"); if(!class_exists($sgbd_impl)) require_once $this->app_file("data/impl/".$sgbd_impl.".php"); - if(class_exists($sgbd_impl)){ - if(($plugins = $this->plugins("DESC")) !== false){ - $data = new mw_data(true); - foreach($plugins as $plugin_name => $plugin){ - if($plugin["installed"] && $plugin["enabled"]){ - $data->load_modules($this->path("mw_dir")."plugins/".$plugin_name."/app/", "data/modules/share/"); - $data->load_modules($this->path("mw_dir")."plugins/".$plugin_name."/app/", "data/modules/".($this->bdd("sgbd") == "xml" ? "xml" : "sql")."/"); - } - } - $data->load_modules($this->path("mw_dir")."app/", "data/modules/share/"); - $data->load_modules($this->path("mw_dir")."app/", "data/modules/".($this->bdd("sgbd") == "xml" ? "xml" : "sql")."/"); - $sgbd = new mw_sgbd( - new $sgbd_impl( - $this->bdd("host"), - $this->bdd("base"), - $this->bdd("user"), - $this->bdd("password") - ), - $this - ); - if($sgbd->extention_ok()){ - $data->set_sgbd($sgbd); - $data->set_env($this); - $this->set_data($data); - } - else $this->erreur("L'extention php ".$this->bdd("sgbd")." n'est pas installée", true); + if(!class_exists($sgbd_impl)){ + $this->erreur("Impossible de trouver la classe d'implementation du sgbd ".$this->bdd("sgbd"), true); + } + $sgbd = new mw_sgbd( + new $sgbd_impl( + array( + "host" => $this->bdd("host"), + "base" => $this->bdd("base"), + "user" => $this->bdd("user"), + "password" => $this->bdd("password") + ) + ), + $this + ); + if(!$sgbd->extention_ok()){ + $this->erreur("L'extention php ".$this->bdd("sgbd")." n'est pas installée", true); + } + } + foreach($plugins as $plugin_name => $plugin){ + if($plugin["installed"] && $plugin["enabled"]){ + $data->load_modules($this->path("mw_dir")."plugins/".$plugin_name."/app/", "data/modules/share/"); + if($this->bdd("sgbd")){ + $data->load_modules($this->path("mw_dir")."plugins/".$plugin_name."/app/", "data/modules/".($this->bdd("sgbd") == "xml" ? "xml" : "sql")."/"); } - else $this->erreur("Impossible de lire les plugins pour charger les modules de donnees"); } - else $this->erreur("Impossible de trouver la classe d'implementation du sgbd ".$this->bdd("sgbd"), true); } - else $this->erreur("Impossible de trouver le fichier d'implementation du sgbd ".$this->bdd("sgbd"), true); + $data->load_modules($this->path("mw_dir")."app/", "data/modules/share/"); + if($this->bdd("sgbd")){ + $data->load_modules($this->path("mw_dir")."app/", "data/modules/".($this->bdd("sgbd") == "xml" ? "xml" : "sql")."/"); + $data->set_sgbd($sgbd); + } + $data->set_env($this); + $this->set_data($data); ?> \ No newline at end of file diff --git a/mw/app/init/0400_config.php b/mw/app/init/0400_config.php index ce7418f..e51eefb 100644 --- a/mw/app/init/0400_config.php +++ b/mw/app/init/0400_config.php @@ -1,5 +1,6 @@ bdd("sgbd")) return; if(($config = $data->config()) !== false){ $this->set_config($config); $start_action_params_config = diff --git a/mw/app/init/0500_users.php b/mw/app/init/0500_users.php index 9d91387..8d698ff 100644 --- a/mw/app/init/0500_users.php +++ b/mw/app/init/0500_users.php @@ -1,5 +1,6 @@ bdd("sgbd")) return; if($data->load_session() !== false){ if($data->init_roles() !== false){ if($data->init_actions_roles() === false){ diff --git a/mw/app/out/default/css/actions/install.css b/mw/app/out/default/css/actions/install.css new file mode 100644 index 0000000..46fee5f --- /dev/null +++ b/mw/app/out/default/css/actions/install.css @@ -0,0 +1,13 @@ +#sgbds .sgbd{ + display: none; +} + +#sgbds .sgbd.current{ + display: block; +} + +#colonne p{ + font-size: 1em; + color: #333333; + padding: 1em; +} \ No newline at end of file diff --git a/mw/app/out/default/install.php b/mw/app/out/default/install.php new file mode 100644 index 0000000..249fae9 --- /dev/null +++ b/mw/app/out/default/install.php @@ -0,0 +1,36 @@ + + + +out_file("views/install/head.php"); ?> + + + +
+
+out_file("views/install/header.php"); ?> +
+
+ +
+
+ +
+out_file("views/install/colonne.php"); ?> +
+ +
+out_file("views/messages.php"); ?> +out_file_exists($layout["content"])) require $this->out_file($layout["content"]); ?> +
+ +
+
+ + + + + diff --git a/mw/app/out/default/js/actions/install.js b/mw/app/out/default/js/actions/install.js new file mode 100644 index 0000000..c80723b --- /dev/null +++ b/mw/app/out/default/js/actions/install.js @@ -0,0 +1,15 @@ +$(document).ready( + function(){ + init_install(); + } +); + +function init_install(){ + $("#sgbd").change( + function(){ + var class_name = $(this).find("option:selected").val(); + $("#sgbds .sgbd").removeClass("current"); + $("#sgbd_" + class_name).addClass("current"); + } + ); +} diff --git a/mw/app/out/default/layouts/install.xml b/mw/app/out/default/layouts/install.xml new file mode 100644 index 0000000..03b2cd7 --- /dev/null +++ b/mw/app/out/default/layouts/install.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/mw/app/out/default/layouts/users.xml b/mw/app/out/default/layouts/users.xml index 60a93f3..3ea32a8 100644 --- a/mw/app/out/default/layouts/users.xml +++ b/mw/app/out/default/layouts/users.xml @@ -2,7 +2,7 @@ - + diff --git a/mw/app/out/default/simple.php b/mw/app/out/default/simple.php index 695f819..e19c659 100644 --- a/mw/app/out/default/simple.php +++ b/mw/app/out/default/simple.php @@ -5,12 +5,6 @@ -
-
-out_file("views/header.php"); ?> -
-
-
@@ -20,11 +14,5 @@
-
-
-out_file("views/footer.php"); ?> -
-
- diff --git a/mw/app/out/default/views/forms/contact/index.php b/mw/app/out/default/views/forms/contact/index.php index 659a7fb..a63ece6 100644 --- a/mw/app/out/default/views/forms/contact/index.php +++ b/mw/app/out/default/views/forms/contact/index.php @@ -21,7 +21,7 @@
  • - path("mw_path")."libs/"); ?>
    + path("web").$this->path("mw_path")."libs/"); ?>
  • diff --git a/mw/app/out/default/views/install/colonne.php b/mw/app/out/default/views/install/colonne.php new file mode 100644 index 0000000..e69de29 diff --git a/mw/app/out/default/views/install/footer.php b/mw/app/out/default/views/install/footer.php new file mode 100644 index 0000000..f1fb6f3 --- /dev/null +++ b/mw/app/out/default/views/install/footer.php @@ -0,0 +1,3 @@ + diff --git a/mw/app/out/default/views/install/head.php b/mw/app/out/default/views/install/head.php new file mode 100644 index 0000000..8c0b2bf --- /dev/null +++ b/mw/app/out/default/views/install/head.php @@ -0,0 +1,42 @@ + + + Mtweb - installation + + + + + js_files() as $js_file) : ?> + + + + css_files() as $css_file) : ?> + + + + out_file_exists("js/script.js")) : ?> + + + out_file_exists("js/actions/".$this->etat("mod").".js")) : ?> + + + out_file_exists("js/actions/".$this->etat("mod")."_".$this->etat("controller").".js")) : ?> + + + out_file_exists("js/actions/".$this->etat("mod")."_".$this->etat("controller")."_".$this->etat("action").".js")) : ?> + + + + out_file_exists("css/style.css")) : ?> + " /> + + out_file_exists("css/actions/".$this->etat("mod").".css")) : ?> + etat("mod").".css"); ?>" /> + + out_file_exists("css/actions/".$this->etat("mod")."_".$this->etat("controller").".css")) : ?> + etat("mod")."_".$this->etat("controller").".css"); ?>" /> + + out_file_exists("css/actions/".$this->etat("mod")."_".$this->etat("controller")."_".$this->etat("action").".css")) : ?> + etat("mod")."_".$this->etat("controller")."_".$this->etat("action").".css"); ?>" /> + \ No newline at end of file diff --git a/mw/app/out/default/views/install/header.php b/mw/app/out/default/views/install/header.php new file mode 100644 index 0000000..7ffb635 --- /dev/null +++ b/mw/app/out/default/views/install/header.php @@ -0,0 +1 @@ +

    Mtweb - installation

    \ No newline at end of file diff --git a/mw/app/out/default/views/install/index.php b/mw/app/out/default/views/install/index.php new file mode 100644 index 0000000..426ffcf --- /dev/null +++ b/mw/app/out/default/views/install/index.php @@ -0,0 +1,116 @@ +out["sgbds"]) : ?> + +
    " method="post"> +
    + Stockage des données +
      +
    • + +
      + +
      +
    • +
    + +
    + out["sgbds"] as $class_name => $sgbd) : ?> +
    " id="sgbd_"> +
      +
    • + +
      + " /> +
      +
    • +
    • + +
      + " /> +
      +
    • + authentication_required()) : ?> +
    • + +
      + " /> +
      +
    • +
    • + +
      + +
      +
    • + +
    +
    + +
    + +
      +
    • + +
      + " /> +
      +
    • +
    + +
    + +
    + Compte administrateur +

    + +

    +
      +
    • + +
      + " /> +
      +
    • +
    • + +
      + " /> +
      +
    • +
    • + +
      + +
      +
    • +
    • + +
      + +
      +
    • +
    +
    + +
    +
      +
    • +
      + +
      +
    • +
    +
    + +
    + + + +

    Aucune implémentation de SGBD trouvée

    + + \ No newline at end of file diff --git a/mw/env/modules/mw_env_data.php b/mw/env/modules/mw_env_data.php index 6e8caff..fb1a5bd 100644 --- a/mw/env/modules/mw_env_data.php +++ b/mw/env/modules/mw_env_data.php @@ -9,7 +9,7 @@ } function data(){ - return $this->data; + return isset($this->data) ? $this->data : false; } } diff --git a/mw/env/modules/mw_env_out.php b/mw/env/modules/mw_env_out.php index 1609dc6..998f489 100644 --- a/mw/env/modules/mw_env_out.php +++ b/mw/env/modules/mw_env_out.php @@ -112,7 +112,7 @@ function out_url($file, $PRIORITE = "DESC"){ $out_file = $this->_out_file($file, $PRIORITE); - return $out_file ? $this->path("mw_path").$out_file : $file; + return $out_file ? $this->path("web").$this->path("mw_path").$out_file : $file; } function _out_file($file, $PRIORITE = "DESC"){ diff --git a/mw/env/modules/mw_env_plugins.php b/mw/env/modules/mw_env_plugins.php index 153700b..6e3e6fb 100644 --- a/mw/env/modules/mw_env_plugins.php +++ b/mw/env/modules/mw_env_plugins.php @@ -159,6 +159,8 @@ } function set_plugin_data($plugin_name, $data){ + if(!is_dir($this->plugins_data_dir())) @mkdir($this->plugins_data_dir()); + if(!is_dir($this->plugins_data_dir())) return false; $data_file = $this->plugin_data_file($plugin_name); $content = serialize($data); $OK = false; diff --git a/mw/env/modules/mw_env_run.php b/mw/env/modules/mw_env_run.php index c0a97a2..f88acd3 100644 --- a/mw/env/modules/mw_env_run.php +++ b/mw/env/modules/mw_env_run.php @@ -6,7 +6,7 @@ var $controllers; function user(){ - $data = $this->data(); + if(!($data = $this->data())) return array(); return $data->get_session_user(); } @@ -82,6 +82,7 @@ } function action_allowed($etat, $CHECK_FORMAT = true){ + if(!$this->bdd("sgbd")) return false; $data = $this->data(); if($CHECK_FORMAT) $etat = $this->valid_etat($etat); if($etat === false){ diff --git a/mw/mw_app.php b/mw/mw_app.php index 044d711..b198197 100644 --- a/mw/mw_app.php +++ b/mw/mw_app.php @@ -3,6 +3,28 @@ class mw_app{ var $env; + var $path_file; + var $pathes; + var $config_file; + var $config; + var $bdd; + var $INITED; + var $logs; + var $DO_SETUP; + + function mw_app($path_file){ + + // executer le setup si le fichier de config est absent + $this->DO_SETUP = true; + + $this->path_file = $path_file; + $this->pathes = array(); + $this->config_file = ""; + $this->config = array(); + $this->bdd = array(); + $this->INITED = false; + $this->logs = array(); + } function set_env(&$env){ $this->env =& $env; @@ -12,17 +34,98 @@ return $this->env; } - function init($config_file){ - require $config_file; - $PATHES["mw_dir"] .= $PATHES["mw_dir"] && substr($PATHES["mw_dir"], -1) != "/" ? "/" : ""; - $PATHES["mw_path"] .= $PATHES["mw_path"] && substr($PATHES["mw_path"], -1) != "/" ? "/" : ""; - if(!isset($CONFIG)) $CONFIG = array(); + function init(){ + $this->INITED = + $this->init_pathes() + && $this->init_config() + && $this->init_env(); + if(!$this->INITED) return false; + if($this->config_file) return true; + $this->setup(); + return false; + } + + function init_pathes(){ + if(($n = strpos($_SERVER["REQUEST_URI"], "?")) !== false){ + $_SERVER["REQUEST_URI"] = substr($_SERVER["REQUEST_URI"], 0, $n); + } + $web_path = explode("/", preg_replace('#/+#','/',$_SERVER["REQUEST_URI"])); + $this->pathes["web"] = ""; + for($i = 0; $i < count($web_path) - 1; $i++) $this->pathes["web"] .= $web_path[$i]."/"; + if( + !$this->path_file + || !file_exists($this->path_file) + ){ + $this->log("path_file introuvable: ".$this->path_file); + return false; + } + require_once $this->path_file; + if( + !isset($PATHES) + || !is_array($PATHES) + ){ + $this->log("path_file: ".$this->path_file); + $this->log("variable PATHES non defini"); + return false; + } + foreach($PATHES as $path_name => $path_value){ + $this->pathes[$path_name] = $path_value; + $this->pathes[$path_name] .= $path_value && substr($path_value, -1) != "/" ? "/" : ""; + } + if( + !isset($this->pathes["mw_dir"]) + || !isset($this->pathes["mw_path"]) + || !isset($this->pathes["content"]) + ){ + $this->log("variable PATHES incomplete"); + return false; + } + if( + !file_exists($this->pathes["content"]) + || !is_dir($this->pathes["content"]) + ){ + $this->log("dossier content introuvable: ".$this->pathes["content"]); + return false; + } + if(!is_writable($this->pathes["content"])){ + $this->log("Php ne peut pas ecrire dans le dossier content: ".$this->pathes["content"]); + return false; + } + return true; + } + + function init_config(){ + if(file_exists($config_file = $this->pathes["content"]."config/config.php")){ + $this->config_file = $config_file; + require_once $this->config_file; + if( + isset($CONFIG) + && is_array($CONFIG) + ){ + foreach($CONFIG as $config_name => $config_value){ + $this->config[$config_name] = $config_value; + } + } + if( + isset($bdd) + && is_array($bdd) + ){ + foreach($bdd as $bdd_key => $bdd_value){ + $this->bdd[$bdd_key] = $bdd_value; + } + } + } + else $this->log("pas de fichier de config: ".$config_file); + return true; + } + + function init_env(){ $env = false; $this->set_env($env); if( - ($sxml_class_file = (file_exists($PATHES["mw_dir"]."libs/sxml.php") ? $PATHES["mw_dir"]."libs/sxml.php" : "")) - && ($empty_class_file = (file_exists($PATHES["mw_dir"]."libs/empty_class.php") ? $PATHES["mw_dir"]."libs/empty_class.php" : "")) - && ($env_class_file = (file_exists($PATHES["mw_dir"]."env/mw_env.php") ? $PATHES["mw_dir"]."env/mw_env.php" : "")) + ($sxml_class_file = (file_exists($this->pathes["mw_dir"]."libs/sxml.php") ? $this->pathes["mw_dir"]."libs/sxml.php" : "")) + && ($empty_class_file = (file_exists($this->pathes["mw_dir"]."libs/empty_class.php") ? $this->pathes["mw_dir"]."libs/empty_class.php" : "")) + && ($env_class_file = (file_exists($this->pathes["mw_dir"]."env/mw_env.php") ? $this->pathes["mw_dir"]."env/mw_env.php" : "")) ){ if(!class_exists("sxml")) require_once $sxml_class_file; if(!class_exists("empty_class")) require_once $empty_class_file; @@ -34,11 +137,11 @@ ){ $env = new mw_env(true); $this->set_env($env); - $env->load_modules($PATHES["mw_dir"], "env/modules/"); - $env->set_config_file($config_file); - $env->set_PATHES($PATHES); + $env->load_modules($this->pathes["mw_dir"], "env/modules/"); + $env->set_config_file($this->config_file); + $env->set_PATHES($this->pathes); $env->init_plugins(); - $env->load_config($bdd, $CONFIG); + $env->load_config($this->bdd, $this->config); $env->init(); } } @@ -46,9 +149,14 @@ } function run($etat = "", $params = array(), $valid_role = true){ - $env = $this->env(); - $etat = ($etat === false ? false : ($etat ? $etat : (isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : ""))); - if($etat !== false) $env->run($etat, $params, $valid_role); + if($this->INITED){ + $env = $this->env(); + $etat = ($etat === false ? false : ($etat ? $etat : (isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : ""))); + if($etat !== false) $env->run($etat, $params, $valid_role); + return true; + } + $this->log("run sans init. l'application ne s'est pas executee"); + return false; } function display(){ @@ -60,6 +168,32 @@ } } + function log($content){ + $this->logs[] = array( + "time" => date("Y-m-d H:i:s"), + "value" => $content + ); + } + + function setup(){ + if($this->DO_SETUP){ + $env = $this->env(); + $etat = isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : "install"; + $env->run($etat, array(), false); + $this->display(); + exit; + } + } + + function show_logs(){ + foreach($this->logs as $log_time => $log_value){ + $log_value = is_bool($log_value) ? "bool(".($log_value ? "true" : "false").")" : $log_value; + echo PHP_SAPI == "cli" ? + "\n".print_r($log_value, true)."\n" + : "
    ".htmlentities(print_r($log_value, true), ENT_QUOTES, "UTF-8")."
    "; + } + } + } ?> \ No newline at end of file diff --git a/pathes.php b/pathes.php new file mode 100644 index 0000000..fcc9a28 --- /dev/null +++ b/pathes.php @@ -0,0 +1,33 @@ + "content", + + // + // chemin HTTP du dossier "mw" + // relatif au dossier qui contient le fichier d'appel + // + "mw_path" => "mw", + + // + // chemin du dossier "mw" sur le systeme d'exploitation + // relatif au dossier qui contient le fichier d'appel + // ou absolu dans le systeme de fichiers + // + "mw_dir" => "mw" + + ); + +?> \ No newline at end of file diff --git a/readme.txt b/readme.txt index 3619ff5..6750a95 100644 --- a/readme.txt +++ b/readme.txt @@ -24,48 +24,15 @@ installation : -------------- - # installation rapide (*) : - - l'archive mtweb..tar.gz contient un dossier "mtweb" - - uploadez le contenu de ce dossier "mtweb" sur votre site - - Si vous faites l'installation ailleurs qu'a la racine du site - (si le fichier index.php n'est pas a la racine du site), adaptez - le fichier config.php pour y renseigner le chemin de l'installation - (plus de détails dans le fichier config.php) + - uploadez le contenu de ce dossier sur votre site - assurez-vous que Php a le droit d'ecrire dans le dossier "content" (et dans ses fichiers et sous-dossiers) - pour une premiere utilisation, vous pouvez vous identifier avec : - - - login: admin - - pass: adminpass - - - (*) avant de rendre votre installation publique : - - - changez le mot de passe de l'utilisateur "admin" - - - ou creez un autre utilisateur avec un role administrateur - puis supprimez l'utilisateur "admin" - - - # utiliser MySql : - - par defaut, mtweb stocke ses donnees dans des fichiers XML, dans le - dossier "content". - - pour utiliser le stockage de donnees MySql : - - - importez les tables avec le script "content/data/mysql/mtweb.sql" - - - dans le fichier "config.php" : - - commentez la partie relative aux donnees XML - - decommentez la partie relative aux donnees MySql - - et adaptez les parametres de connexion pour MySql - (plus de details dans le fichier config.php) + - rendez-vous, avec votre navigateur, sur le dossier uploadé et + suivez l'installation en ligne documentation : -- 2.1.4