3 class mw_pages extends mw_plugin{
9 function description(){
10 return "Pour ajouter des pages, avec un éditeur dans l'administration du site";
14 $env->set_link("plugins/admin/mw_pages", $env->url("pages/admin"), "éditer les pages");
15 $env->set_link("admin/pages", $env->url("pages/admin"), "Pages", 40);
19 $arbo = $data->pages_arbo(
22 "order_by" => "position",
28 $this->_set_links($env, "menu_top", $arbo);
33 function _set_links($env, $parent, $arbo){
35 foreach($arbo["subs"] as $page){
37 $parent."/mw_page_".$page["id"],
38 $env->url("pages/view/page", array("id" => $page["id"])),
42 $this->_set_links($env, $parent."/mw_page_".$page["id"], $page);
47 function enable($env){
48 $plugins_pages_start_id = $env->config("plugins_pages_start_id");
49 if($plugins_pages_start_id){
52 $data->set_config("start_action", "pages/view/page")
53 && $data->set_config("start_action_params", @serialize(array("id" => $plugins_pages_start_id)))
62 function disable($env){
63 $start_action = $env->config("start_action");
64 if($start_action == "pages/view/page"){
67 $data->set_config("start_action", "")
68 && $data->set_config("start_action_params", "")
77 // ---------------------------------------------------------------------------------
81 function install($env){
82 if($env->bdd("sgbd") == "xml") return $this->install_xml($env);
83 if($env->bdd("sgbd") == "sqlite") return $this->install_sqlite($env);
84 if($env->bdd("sgbd") == "mysql") return $this->install_mysql($env);
87 function install_xml($env){
89 $sgbd = $data->sgbd();
90 $EXISTS = $sgbd->data_exists("pages");
92 return "impossible de savoir si la table #--pages existe";
95 return "la table #--pages existe deja";
97 if(!$sgbd->create_data("pages")){
98 return "imposible de creer la table #--pages";
100 if(!$sgbd->add_data("actions_roles", array("action" => "pages/admin", "id_role" => "1"))){
101 $sgbd->remove_data("pages");
102 return "impossible d'ajouter un statut pour l'action pages/admin";
107 function install_sqlite($env){
108 $data = $env->data();
109 $sgbd = $data->sgbd();
111 $EXISTS = $sgbd->table_exists("#--pages");
114 return "impossible de savoir si la table #--pages existe";
117 return "la table #--pages existe deja";
121 "CREATE TABLE #--pages"
122 ."( id INTEGER NOT NULL PRIMARY KEY"
123 .", id_parent INTEGER NULL"
124 .", title VARCHAR NULL"
125 .", content TEXT NULL"
126 .", date_creation TEXT NOT NULL"
127 .", user_creation INTEGER NOT NULL"
128 .", date_last_update TEXT NOT NULL"
129 .", user_last_update INTEGER NOT NULL"
130 .", enabled INTEGER NOT NULL DEFAULT 1"
131 .", position INTEGER NOT NULL DEFAULT 0"
136 return "imposible de creer la table #--pages";
138 $DELETE_TABLE = false;
140 $sgbd->query("INSERT INTO #--actions_roles(action, id_role) VALUES('pages/admin', 1)");
144 $sgbd->query("DROP TABLE \"main\".\"#--pages\"");
146 catch(Exception $e){}
147 return "impossible d'ajouter un statut pour l'action pages/admin";
152 function install_mysql($env){
153 $data = $env->data();
154 $sgbd = $data->sgbd();
156 $EXISTS = $sgbd->table_exists("#--pages");
159 return "impossible de savoir si la table #--pages existe";
162 return "la table #--pages existe deja";
166 "CREATE TABLE #--pages"
167 ."( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
168 .", id_parent INT(11) NULL"
169 .", title VARCHAR(255) NULL"
170 .", content TEXT NULL"
171 .", date_creation DATETIME NOT NULL"
172 .", user_creation INT(11) NOT NULL"
173 .", date_last_update DATETIME NOT NULL"
174 .", user_last_update INT(11) NOT NULL"
175 .", enabled TINYINT NOT NULL DEFAULT '1'"
176 .", position INT(11) NOT NULL DEFAULT '0'"
177 .") DEFAULT CHARSET=utf8";
181 return "imposible de creer la table #--pages";
184 $sgbd->query("INSERT INTO #--actions_roles(action, id_role) VALUES('pages/admin', 1)");
188 $sgbd->query("DROP TABLE #--pages");
190 catch(Exception $e){}
191 return "impossible d'ajouter un statut pour l'action pages/admin";
196 // ---------------------------------------------------------------------------------
200 function uninstall($env){
201 if($env->bdd("sgbd") == "xml") return $this->uninstall_xml($env);
202 if($env->bdd("sgbd") == "sqlite") return $this->uninstall_sqlite($env);
203 if($env->bdd("sgbd") == "mysql") return $this->uninstall_mysql($env);
206 function uninstall_xml($env){
207 $data = $env->data();
208 $sgbd = $data->sgbd();
209 if(!$this->disable($env)) return "impossible de desactiver le plugin";
210 $data->del_config("plugins_pages_start_id");
211 $EXISTS = $sgbd->data_exists("pages");
213 return "impossible de savoir si la table #--pages existe";
216 // return "la table #--pages n'existe pas";
218 elseif(!$sgbd->remove_data("pages")){
219 return "imposible de supprimer la table #--pages";
222 if($rst = $sgbd->open_data("actions_roles")){
223 while($v_rst = $sgbd->fetch_data($rst)){
225 if(isset($v_rst["action"]) && isset($v_rst["id"]) && $v_rst["action"] == "pages/admin"){
226 $ids[] = $v_rst["id"];
231 $sgbd->close_data($rst);
234 foreach($ids as $id){
235 $sgbd->del_data("actions_roles", $id);
241 function uninstall_sqlite($env){
242 $data = $env->data();
243 $sgbd = $data->sgbd();
244 if(!$this->disable($env)) return "impossible de desactiver le plugin";
245 $data->del_config("plugins_pages_start_id");
247 $EXISTS = $sgbd->table_exists("#--pages");
250 return "impossible de savoir si la table #--pages existe";
253 // return "la table #--pages n'existe pas";
257 $sgbd->query("DROP TABLE \"main\".\"#--pages\"");
260 return "imposible de supprimer la table #--pages";
264 $sgbd->query("DELETE FROM #--actions_roles WHERE action='pages/admin'");
268 "Le plugin a bien été désinstallé"
269 ." mais impossible d'enlever les droits pages/admin/* de la table actions_roles";
274 function uninstall_mysql($env){
275 $data = $env->data();
276 $sgbd = $data->sgbd();
277 if(!$this->disable($env)) return "impossible de desactiver le plugin";
278 $data->del_config("plugins_pages_start_id");
280 $EXISTS = $sgbd->table_exists("#--pages");
283 return "impossible de savoir si la table #--pages existe";
286 // return "la table #--pages n'existe pas";
290 $sgbd->query("DROP TABLE #--pages");
293 return "imposible de supprimer la table #--pages";
297 $sgbd->query("DELETE FROM #--actions_roles WHERE action='pages/admin'");
301 "Le plugin a bien été désinstallé"
302 ." mais impossible d'enlever les droits pages/admin/* de la table actions_roles";