From 90a1f9524e4bffa5d9d518d6dfb760f85a6c6d28 Mon Sep 17 00:00:00 2001 From: dj3c1t Date: Sat, 1 Dec 2012 12:36:01 +0100 Subject: [PATCH] import version 0.1 --- app/data/modules/sql/mw_data_pages.php | 156 ++++++++++++++++++++ app/data/modules/xml/mw_data_pages.php | 175 +++++++++++++++++++++++ app/mods/pages/admin.php | 178 +++++++++++++++++++++++ app/mods/pages/index.php | 12 ++ app/mods/pages/view.php | 42 ++++++ mw_pages.php | 252 +++++++++++++++++++++++++++++++++ out/dist/css/actions/pages_admin.css | 1 + out/dist/css/actions/pages_view.css | 29 ++++ out/dist/functions.php | 112 +++++++++++++++ out/dist/js/actions/pages_admin.js | 13 ++ out/dist/layouts/pages.xml | 16 +++ out/dist/page.php | 60 ++++++++ out/dist/views/pages/admin/add.php | 32 +++++ out/dist/views/pages/admin/edit.php | 32 +++++ out/dist/views/pages/admin/list.php | 78 ++++++++++ out/dist/views/pages/colonne.php | 10 ++ out/dist/views/pages/view/index.php | 0 out/dist/views/pages/view/page.php | 23 +++ 18 files changed, 1221 insertions(+) create mode 100644 app/data/modules/sql/mw_data_pages.php create mode 100644 app/data/modules/xml/mw_data_pages.php create mode 100644 app/mods/pages/admin.php create mode 100644 app/mods/pages/index.php create mode 100644 app/mods/pages/view.php create mode 100644 mw_pages.php create mode 100644 out/dist/css/actions/pages_admin.css create mode 100644 out/dist/css/actions/pages_view.css create mode 100644 out/dist/functions.php create mode 100644 out/dist/js/actions/pages_admin.js create mode 100644 out/dist/layouts/pages.xml create mode 100644 out/dist/page.php create mode 100644 out/dist/views/pages/admin/add.php create mode 100644 out/dist/views/pages/admin/edit.php create mode 100644 out/dist/views/pages/admin/list.php create mode 100644 out/dist/views/pages/colonne.php create mode 100644 out/dist/views/pages/view/index.php create mode 100644 out/dist/views/pages/view/page.php diff --git a/app/data/modules/sql/mw_data_pages.php b/app/data/modules/sql/mw_data_pages.php new file mode 100644 index 0000000..3ef0b6c --- /dev/null +++ b/app/data/modules/sql/mw_data_pages.php @@ -0,0 +1,156 @@ +page($id)) + { if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane); + $ariane[] = $page; + return $ariane; + } + return false; + } + + function pages($params = array()) + { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; + $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null; + $user = isset($params["user"]) ? $params["user"] : null; + $order_by = isset($params["order_by"]) ? $params["order_by"] : null; + $order = isset($params["order"]) ? $params["order"] : "ASC"; + $start = isset($params["start"]) ? $params["start"] : null; + $max = isset($params["max"]) ? $params["max"] : null; + $sgbd = $this->sgbd(); + $pages = array("list" => array(), "total" => 0); + $SELECT = "SELECT * FROM #--pages"; + $COUNT_SELECT = "SELECT count(*) as n FROM #--pages"; + $WHERE = ""; + $WHERE .= (isset($id_parent) ? ($WHERE ? " AND" : " WHERE")." id_parent".(strlen($id_parent) > 0 ? "=".$this->eq($id_parent) : " IS NULL") : ""); + $WHERE .= (isset($enabled) ? ($WHERE ? " AND" : " WHERE")." enabled=".$this->eq($enabled) : ""); + $WHERE .= (isset($user) ? ($WHERE ? " AND" : " WHERE")." user_creation=".$this->eq($user) : ""); + $ORDER_BY = + ( isset($order_by) ? + " ORDER BY ".$order_by.(isset($order) ? " ".$order : "") + : "" + ); + $LIMIT = isset($max) ? " LIMIT ".$max.(isset($start) ? " OFFSET ".$start : "") : ""; + $sql = $COUNT_SELECT.$WHERE; + $rst = $sgbd->query($sql); + if(!isset($rst)) return false; + if($v_rst = $sgbd->fetch_assoc($rst)) $pages["total"] = $v_rst["n"]; + $sgbd->free_result($rst); + if($pages["total"]) + { $sql = $SELECT.$WHERE.$ORDER_BY.$LIMIT; + $rst = $sgbd->query($sql); + if(!isset($rst)) return false; + while($v_rst = $sgbd->fetch_assoc($rst)) $pages["list"][$v_rst["id"]] = $v_rst; + $sgbd->free_result($rst); + } + return $pages; + } + + function pages_arbo($params = array()) + { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; + $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null; + $user = isset($params["user"]) ? $params["user"] : null; + $order_by = isset($params["order_by"]) ? $params["order_by"] : null; + $order = isset($params["order"]) ? $params["order"] : "ASC"; + $sgbd = $this->sgbd(); + $arbo = array(); + if(isset($id_parent)) + { if($parent = $this->page($id_parent)) $arbo = $parent; + else return false; + } + $arbo["subs"] = array(); + $SELECT = "SELECT id FROM #--pages"; + $WHERE = ""; + $WHERE .= ($WHERE ? " AND" : " WHERE")." id_parent".(isset($id_parent) && $id_parent ? "=".$this->eq($id_parent) : " IS NULL"); + $WHERE .= (isset($enabled) ? ($WHERE ? " AND" : " WHERE")." enabled=".$this->eq($enabled) : ""); + $WHERE .= (isset($user) ? ($WHERE ? " AND" : " WHERE")." user_creation=".$this->eq($user) : ""); + $ORDER_BY = + ( isset($order_by) ? + " ORDER BY ".$order_by.(isset($order) ? " ".$order : "") + : "" + ); + $sql = $SELECT.$WHERE.$ORDER_BY; + $rst = $sgbd->query($sql); + if(!isset($rst)) return false; + while($v_rst = $sgbd->fetch_assoc($rst)) + { $params["id_parent"] = $v_rst["id"]; + $arbo["subs"][] = $this->pages_arbo($params); + } + $sgbd->free_result($rst); + return $arbo; + } + + function page($id) + { $page = array(); + $sgbd = $this->sgbd(); + $sql = "SELECT * FROM #--pages WHERE id=".$this->eq($id); + $rst = $sgbd->query($sql); + if(!isset($rst)) return false; + if($v_rst = $sgbd->fetch_assoc($rst)) $page = $v_rst; + return $page; + } + + function add_page($params) + { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; + $title = isset($params["title"]) ? $params["title"] : null; + $content = isset($params["content"]) ? $params["content"] : null; + $user = isset($params["user"]) ? $params["user"] : null; + $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : 1; + $position = isset($params["position"]) ? $params["position"] : 0; + $sgbd = $this->sgbd(); + $sql = + "INSERT INTO #--pages" + ."(id_parent, title, content, date_creation, user_creation, date_last_update, user_last_update, enabled, position)" + ." VALUES" + ."( ".$this->eq($id_parent) + .", ".$this->eq($title) + .", ".$this->eq($content) + .", '".date("Y-m-d H:i:s")."'" + .", ".$this->eq($user) + .", '".date("Y-m-d H:i:s")."'" + .", ".$this->eq($user) + .", ".$this->eq($enabled) + .", ".$this->eq($position) + .")"; + if($sgbd->query($sql)) return $sgbd->insert_id(); + return false; + } + + function set_page($id, $params, $RAZ = false) + { if($page = $this->page($id)) + { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : ($RAZ ? null : $page["id_parent"]); + $title = isset($params["title"]) ? $params["title"] : ($RAZ ? null : $page["title"]); + $content = isset($params["content"]) ? $params["content"] : ($RAZ ? null : $page["content"]); + $user = isset($params["user"]) ? $params["user"] : null; + $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : ($RAZ ? 1 : $page["enabled"]); + $position = isset($params["position"]) ? $params["position"] : ($RAZ ? 0 : $page["position"]); + $sgbd = $this->sgbd(); + $sql = + "UPDATE #--pages SET" + ." id_parent=".$this->eq($id_parent) + .", title=".$this->eq($title) + .", content=".$this->eq($content) + .", date_last_update='".date("Y-m-d H:i:s")."'" + .", user_last_update=".$this->eq($user) + .", enabled=".$this->eq($enabled) + .", position=".$this->eq($position) + ." WHERE id=".$this->eq($id); + if($sgbd->query($sql)) return true; + } + return false; + } + + function del_page($id) + { $sgbd = $this->sgbd(); + if($sgbd->query("DELETE FROM #--pages WHERE id=".$this->eq($id))) + { return $sgbd->query("UPDATE #--pages SET id_parent=NULL WHERE id_parent=".$this->eq($id)) ? true : false; + } + return false; + } + + } + +?> \ No newline at end of file diff --git a/app/data/modules/xml/mw_data_pages.php b/app/data/modules/xml/mw_data_pages.php new file mode 100644 index 0000000..18a3613 --- /dev/null +++ b/app/data/modules/xml/mw_data_pages.php @@ -0,0 +1,175 @@ +page($id)) + { if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane); + $ariane[] = $page; + return $ariane; + } + return false; + } + + function pages($params = array()) + { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; + $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null; + $user = isset($params["user"]) ? $params["user"] : null; + $order_by = isset($params["order_by"]) ? $params["order_by"] : null; + $order = isset($params["order"]) ? $params["order"] : "ASC"; + $start = isset($params["start"]) ? $params["start"] : null; + $max = isset($params["max"]) ? $params["max"] : null; + $sgbd = $this->sgbd(); + $pages = array("list" => array(), "total" => 0); + $res = array(); + if($rst = $sgbd->open_data("pages")) + { while($v_rst = $sgbd->fetch_data($rst)) + { if(isset($v_rst)) $res[$v_rst["id"]] = $v_rst; + else + { $res = false; + break; + } + } + $sgbd->close_data($rst); + if($res !== false) + { if(isset($order_by)) $res = $this->ordonne($res, "position", isset($order) ? $order : "ASC"); + foreach($res as $id_res => $v_rst) + { $MATCH = true; + if(isset($id_parent)) + { $MATCH = + ( ($id_parent && isset($v_rst["id_parent"]) && ($id_parent == $v_rst["id_parent"])) + || ($id_parent == "" && !$v_rst["id_parent"]) + ); + } + if($MATCH) + { if(isset($enabled)) + { $MATCH = ($v_rst["enabled"] == $enabled); + } + } + if($MATCH) + { if(isset($user)) + { $MATCH = ($v_rst["user_creation"] == $user); + } + } + if($MATCH) + { $pages["total"]++; + $MATCH = !isset($start) || !$max || ($pages["total"] > $start && $pages["total"] <= ($start + $max)); + } + if($MATCH) $pages["list"][$v_rst["id"]] = $v_rst; + } + } + } + else return false; + return $pages; + } + + function pages_arbo($params = array()) + { $params["id_parent"] = isset($params["id_parent"]) ? $params["id_parent"] : ""; + $params["enabled"] = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null; + $params["user"] = isset($params["user"]) ? $params["user"] : null; + $params["order_by"] = isset($params["order_by"]) ? $params["order_by"] : null; + $params["order"] = isset($params["order"]) ? $params["order"] : "ASC"; + $sgbd = $this->sgbd(); + $arbo = array(); + if($params["id_parent"]) + { if($parent = $this->page($params["id_parent"])) $arbo = $parent; + else return false; + } + $arbo["subs"] = array(); + if(($subs = $this->pages($params)) !== false) + { foreach($subs["list"] as $id_sub => $sub) + { $params["id_parent"] = $sub["id"]; + $arbo["subs"][] = $this->pages_arbo($params); + } + } + return $arbo; + } + + function page($id) + { $sgbd = $this->sgbd(); + return ($page = $sgbd->get_data("pages", $id)) ? $page : false; + } + + function add_page($params) + { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; + $title = isset($params["title"]) ? $params["title"] : null; + $content = isset($params["content"]) ? $params["content"] : null; + $user = isset($params["user"]) ? $params["user"] : null; + $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : 1; + $position = isset($params["position"]) ? $params["position"] : 0; + $sgbd = $this->sgbd(); + return + ( ( $id_page = $sgbd->add_data + ( "pages", + array + ( "id_parent" => $id_parent, + "title" => $title, + "content" => $content, + "date_creation" => date("Y-m-d H:i:s"), + "user_creation" => $user, + "date_last_update" => date("Y-m-d H:i:s"), + "user_last_update" => $user, + "enabled" => $enabled, + "position" => $position + ) + ) + ) ? $id_page : false + ); + } + + function set_page($id, $params, $RAZ = false) + { if($page = $this->page($id)) + { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : ($RAZ ? null : $page["id_parent"]); + $title = isset($params["title"]) ? $params["title"] : ($RAZ ? null : $page["title"]); + $content = isset($params["content"]) ? $params["content"] : ($RAZ ? null : $page["content"]); + $user = isset($params["user"]) ? $params["user"] : null; + $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : ($RAZ ? 1 : $page["enabled"]); + $position = isset($params["position"]) ? $params["position"] : ($RAZ ? 0 : $page["position"]); + $sgbd = $this->sgbd(); + return $sgbd->set_data + ( "pages", + $id, + array + ( "id_parent" => $id_parent, + "title" => $title, + "content" => $content, + "date_creation" => $page["date_creation"], + "user_creation" => $page["user_creation"], + "date_last_update" => date("Y-m-d H:i:s"), + "user_last_update" => $user, + "enabled" => $enabled, + "position" => $position + ) + ); + } + return false; + } + + function del_page($id) + { $sgbd = $this->sgbd(); + if($sgbd->del_data("pages", $id)) + { $OK = true; + if($rst = $sgbd->open_data("pages")) + { while($v_rst = $sgbd->fetch_data($rst)) + { if(isset($v_rst)) + { if(isset($v_rst["id_parent"]) && isset($v_rst["id"]) && $v_rst["id_parent"] == $id) + { unset($v_rst["id_parent"]); + if(!$sgbd->set_data("pages", $v_rst["id"], $v_rst)) + { $OK = false; + break; + } + } + } + else $OK = false; + } + $sgbd->close_data($rst); + } + return $OK; + } + return false; + } + + } + +?> \ No newline at end of file diff --git a/app/mods/pages/admin.php b/app/mods/pages/admin.php new file mode 100644 index 0000000..48e4f89 --- /dev/null +++ b/app/mods/pages/admin.php @@ -0,0 +1,178 @@ +data(); + if(($arbo = $data->pages_arbo()) !== false) + { $env->set_out("arbo", $arbo); + $id_parent = isset($_GET[$env->param("parent")]) ? $_GET[$env->param("parent")] : null; + if + ( ( $pages = $data->pages + ( array + ( "id_parent" => $id_parent, + "order_by" => "position", + "order" => "ASC", + "start" => isset($_GET[$env->param("start")]) && $_GET[$env->param("start")] ? $_GET[$env->param("start")] : 0, + "max" => $env->config("max_list") + ) + ) + ) !== false + ) + { $env->set_out("pages", $pages); + $ariane = array(); + if($id_parent) + { if(($ariane = $data->page_ariane($id_parent)) === false) + { $env->erreur("impossible de lire le fil d'ariane"); + } + } + $env->set_out("ariane", $ariane); + } + else $env->erreur("impossible de lire la liste des pages"); + } + else $env->erreur("impossible de lire l'arborescence des pages"); + } + + function validate_POST_page(&$env, $page = null) + { $page = isset($page) ? $page : array(); + $_page = array(); + if(($user = $env->user()) && $user["id"]) + { if($_POST) + { $_page["id_parent"] = isset($_POST["id_parent"]) ? ($_POST["id_parent"] ? $_POST["id_parent"] : null) : ($page["id_parent"] ? $page["id_parent"] : null); + $_page["title"] = isset($_POST["title"]) ? $_POST["title"] : ($page["title"] ? $page["title"] : null); + $_page["content"] = isset($_POST["content"]) ? $_POST["content"] : ($page["content"] ? $page["content"] : null); + $_page["user"] = $user["id"]; + $_page["enabled"] = isset($_POST["enabled"]) ? $_POST["enabled"] : ($page["enabled"] ? $page["enabled"] : 1); + $_page["position"] = isset($_POST["position"]) ? $_POST["position"] : ($page["position"] ? $page["position"] : 0); + } + } + else $env->message("impossible de lire les informations de l'utilisateur"); + return $_page; + } + + function add(&$env) + { $data = $env->data(); + if(($arbo = $data->pages_arbo()) !== false) + { $env->set_out("arbo", $arbo); + $page = array(); + if($_POST) + { $page = $this->validate_POST_page($env); + if(!$env->messages()) + { if(($id_page = $data->add_page($page)) !== false) + { $env->redirect + ( $env->url("pages/admin"), + "la page a été ajoutée" + ); + } + else $env->erreur("impossible d'ajouter la page"); + } + } + $env->set_out("page", $page); + } + else $env->erreur("impossible de lire l'arborescence des pages"); + } + + function edit(&$env) + { $data = $env->data(); + if($page = $data->page($_GET[$env->param("id")])) + { if(($arbo = $data->pages_arbo()) !== false) + { $env->set_out("arbo", $arbo); + if($_POST) + { $page = $this->validate_POST_page($env, $page); + if(!$env->messages()) + { if($data->set_page($_GET[$env->param("id")], $page)) + { $env->redirect + ( $env->url("pages/admin"), + "la page a été modifiée" + ); + } + else $env->erreur("impossible de modifier la page"); + } + } + $env->set_out("page", $page); + } + else $env->erreur("impossible de lire l'arborescence des pages"); + } + else $env->erreur("impossible de lire les informations de la page"); + } + + function edit_pages(&$env) + { if(($user = $env->user()) && $user["id"]) + { if($_POST) + { $data = $env->data(); + $OK = true; + foreach($_POST as $key => $value) + { $OK = true; + if(substr($key, 0, 9) == "position_") + { $id_page = substr($key, 9); + $enabled = isset($_POST["enabled_".$id_page]) && $_POST["enabled_".$id_page] ? 1 : 0; + if(!$data->set_page($id_page, array("position" => $value, "enabled" => $enabled))) + { $env->erreur("impossible d'enregistrer la position"); + $OK = false; + $break; + } + } + } + if($OK) + { $env->redirect + ( $env->url("pages/admin"), + "Les informations des pages ont été enregistrées" + ); + } + } + else $env->erreur("donnees manquantes"); + } + else $env->erreur("impossible de lire les informations de l'utilisateur"); + } + + function set_accueil(&$env) + { if(($user = $env->user()) && $user["id"]) + { $data = $env->data(); + $start_action = ""; + $start_action_params = ""; + $id_page = $_POST["id"] ? $_POST["id"] : ""; + if($id_page) + { if($page = $data->page($id_page)) + { $start_action = "pages/view/page"; + $start_action_params = @serialize(array("id" => $id_page)); + } + else + { $start_action = false; + $env->erreur("impossible de lire les informations de la page"); + } + } + if($start_action !== false && $start_action_params !== false) + { if + ( $data->set_config("start_action", $start_action) + && $data->set_config("start_action_params", $start_action_params) + ) + { $data->set_config("plugins_pages_start_id", $id_page); + $env->redirect + ( $env->url("pages/admin"), + "La page d'accueil a été enregistrée" + ); + } + else $env->erreur("impossible d'enregistrer la page d'accueil dans la configuration"); + } + } + else $env->erreur("impossible de lire les informations de l'utilisateur"); + } + + function del(&$env) + { $data = $env->data(); + if($page = $data->page($_GET[$env->param("id")])) + { if($data->del_page($page["id"])) + { $env->redirect + ( $env->url("pages/admin"), + "la page a été supprimée" + ); + } + else $env->erreur("Impossible de supprimer la page"); + } + else $env->erreur("impossible de lire les informations de la page"); + } + + } + +?> \ No newline at end of file diff --git a/app/mods/pages/index.php b/app/mods/pages/index.php new file mode 100644 index 0000000..696b5c2 --- /dev/null +++ b/app/mods/pages/index.php @@ -0,0 +1,12 @@ +run("pages/view"); + } + + } + +?> \ No newline at end of file diff --git a/app/mods/pages/view.php b/app/mods/pages/view.php new file mode 100644 index 0000000..da382f0 --- /dev/null +++ b/app/mods/pages/view.php @@ -0,0 +1,42 @@ +data(); + if(($arbo = $data->pages_arbo(array("enabled" => 1))) !== false) + { $env->set_out("arbo", $arbo); + if(($page = $data->page($_GET[$env->param("id")])) && $page["enabled"]) + { $env->set_out("page", $page); + if + ( ( $pages = $data->pages + ( array + ( "id_parent" => $page["id"], + "enabled" => 1, + "order_by" => "position", + "order" => "ASC" + ) + ) + ) !== false + ) + { $env->set_out("pages", $pages); + if(($ariane = $data->page_ariane($page["id"])) !== false) + { $env->set_out("ariane", $ariane); + } + else $env->erreur("impossible de lire le fil d'ariane"); + } + else $env->erreur("impossible de lire la liste des pages"); + } + else $env->erreur("impossible de lire la page"); + } + else $env->erreur("impossible de lire l'arborescence des pages"); + } + + } + +?> \ No newline at end of file diff --git a/mw_pages.php b/mw_pages.php new file mode 100644 index 0000000..056efbc --- /dev/null +++ b/mw_pages.php @@ -0,0 +1,252 @@ +set_link("plugins/admin/mw_pages", $env->url("pages/admin"), "éditer les pages"); + $data = $env->data(); + if + ( ( $pages = $data->pages + ( array + ( "id_parent" => "", + "enabled" => 1, + "order_by" => "position", + "order" => "ASC" + ) + ) + ) !== false + ) + { foreach($pages["list"] as $id_page => $page) + { $env->set_link + ( "menu_top/mw_page_".$id_page, + $env->url("pages/view/page", array("id" => $id_page)), + $page["title"], + $page["position"] + ); + } + } + return true; + } + + function enable($env) + { $plugins_pages_start_id = $env->config("plugins_pages_start_id"); + if($plugins_pages_start_id) + { $data = $env->data(); + if + ( $data->set_config("start_action", "pages/view/page") + && $data->set_config("start_action_params", @serialize(array("id" => $plugins_pages_start_id))) + ) + { return true; + } + return false; + } + return true; + } + + function disable($env) + { $start_action = $env->config("start_action"); + if($start_action == "pages/view/page") + { $data = $env->data(); + if + ( $data->set_config("start_action", "") + && $data->set_config("start_action_params", "") + ) + { return true; + } + return false; + } + return true; + } + + // --------------------------------------------------------------------------------- + // install + // + + function install($env) + { if($env->bdd("sgbd") == "xml") return $this->install_xml($env); + if($env->bdd("sgbd") == "sqlite") return $this->install_sqlite($env); + if($env->bdd("sgbd") == "mysql") return $this->install_mysql($env); + } + + function install_xml($env) + { $data = $env->data(); + $sgbd = $data->sgbd(); + $EXISTS = $sgbd->data_exists("pages"); + if(!isset($EXISTS)) + { return "impossible de savoir si la table #--pages existe"; + } + if($EXISTS) + { return "la table #--pages existe deja"; + } + if(!$sgbd->create_data("pages")) + { return "imposible de creer la table #--pages"; + } + if(!$sgbd->add_data("action_status", array("action" => "pages/admin", "id_status" => "1"))) + { $sgbd->remove_data("pages"); + return "impossible d'ajouter un statut pour l'action pages/admin"; + } + return true; + } + + function install_sqlite($env) + { $data = $env->data(); + $sgbd = $data->sgbd(); + $EXISTS = $sgbd->table_exists("#--pages"); + if(!isset($EXISTS)) + { return "impossible de savoir si la table #--pages existe"; + } + if($EXISTS) + { return "la table #--pages existe deja"; + } + $sql = + "CREATE TABLE #--pages" + ."( id INTEGER NOT NULL PRIMARY KEY" + .", id_parent INTEGER NULL" + .", title VARCHAR NULL" + .", content TEXT NULL" + .", date_creation TEXT NOT NULL" + .", user_creation INTEGER NOT NULL" + .", date_last_update TEXT NOT NULL" + .", user_last_update INTEGER NOT NULL" + .", enabled INTEGER NOT NULL DEFAULT 1" + .", position INTEGER NOT NULL DEFAULT 0" + .")"; + if(!$sgbd->query($sql)) + { return "imposible de creer la table #--pages"; + } + if(!$sgbd->query("INSERT INTO #--action_status(action, id_status) VALUES('pages/admin', 1)")) + { $sgbd->query("DROP TABLE \"main\".\"#--pages\""); + return "impossible d'ajouter un statut pour l'action pages/admin"; + } + return true; + } + + function install_mysql($env) + { $data = $env->data(); + $sgbd = $data->sgbd(); + $EXISTS = $sgbd->table_exists("#--pages"); + if(!isset($EXISTS)) + { return "impossible de savoir si la table #--pages existe"; + } + if($EXISTS) + { return "la table #--pages existe deja"; + } + $sql = + "CREATE TABLE #--pages" + ."( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY" + .", id_parent INT(11) NULL" + .", title VARCHAR(255) NULL" + .", content TEXT NULL" + .", date_creation DATETIME NOT NULL" + .", user_creation INT(11) NOT NULL" + .", date_last_update DATETIME NOT NULL" + .", user_last_update INT(11) NOT NULL" + .", enabled TINYINT NOT NULL DEFAULT '1'" + .", position INT(11) NOT NULL DEFAULT '0'" + .") DEFAULT CHARSET=utf8"; + if(!$sgbd->query($sql)) + { return "imposible de creer la table #--pages"; + } + if(!$sgbd->query("INSERT INTO #--action_status(action, id_status) VALUES('pages/admin', 1)")) + { $sgbd->query("DROP TABLE #--pages"); + return "impossible d'ajouter un statut pour l'action pages/admin"; + } + return true; + } + + // --------------------------------------------------------------------------------- + // uninstall + // + + function uninstall($env) + { if($env->bdd("sgbd") == "xml") return $this->uninstall_xml($env); + if($env->bdd("sgbd") == "sqlite") return $this->uninstall_sqlite($env); + if($env->bdd("sgbd") == "mysql") return $this->uninstall_mysql($env); + } + + function uninstall_xml($env) + { $data = $env->data(); + $sgbd = $data->sgbd(); + if(!$this->disable($env)) return "impossible de desactiver le plugin"; + $data->del_config("plugins_pages_start_id"); + $EXISTS = $sgbd->data_exists("pages"); + if(!isset($EXISTS)) + { return "impossible de savoir si la table #--pages existe"; + } + if(!$EXISTS) + { // return "la table #--pages n'existe pas"; + } + elseif(!$sgbd->remove_data("pages")) + { return "imposible de supprimer la table #--pages"; + } + $ids = array(); + if($rst = $sgbd->open_data("action_status")) + { while($v_rst = $sgbd->fetch_data($rst)) + { if(isset($v_rst)) + { if(isset($v_rst["action"]) && isset($v_rst["id"]) && $v_rst["action"] == "pages/admin") + { $ids[] = $v_rst["id"]; + } + } + else $ids = false; + } + $sgbd->close_data($rst); + } + if($ids !== false) + { foreach($ids as $id) + { $sgbd->del_data("action_status", $id); + } + } + return true; + } + + function uninstall_sqlite($env) + { $data = $env->data(); + $sgbd = $data->sgbd(); + if(!$this->disable($env)) return "impossible de desactiver le plugin"; + $data->del_config("plugins_pages_start_id"); + $EXISTS = $sgbd->table_exists("#--pages"); + if(!isset($EXISTS)) + { return "impossible de savoir si la table #--pages existe"; + } + if(!$EXISTS) + { // return "la table #--pages n'existe pas"; + } + elseif(!$sgbd->query("DROP TABLE \"main\".\"#--pages\"")) + { return "imposible de supprimer la table #--pages"; + } + $sgbd->query("DELETE FROM #--action_status WHERE action='pages/admin'"); + return true; + } + + function uninstall_mysql($env) + { $data = $env->data(); + $sgbd = $data->sgbd(); + if(!$this->disable($env)) return "impossible de desactiver le plugin"; + $data->del_config("plugins_pages_start_id"); + $EXISTS = $sgbd->table_exists("#--pages"); + if(!isset($EXISTS)) + { return "impossible de savoir si la table #--pages existe"; + } + if(!$EXISTS) + { // return "la table #--pages n'existe pas"; + } + elseif(!$sgbd->query("DROP TABLE #--pages")) + { return "imposible de supprimer la table #--pages"; + } + $sgbd->query("DELETE FROM #--action_status WHERE action='pages/admin'"); + return true; + } + + } + + +?> \ No newline at end of file diff --git a/out/dist/css/actions/pages_admin.css b/out/dist/css/actions/pages_admin.css new file mode 100644 index 0000000..cb9a939 --- /dev/null +++ b/out/dist/css/actions/pages_admin.css @@ -0,0 +1 @@ +@import url("../../../../../../out/dist/css/actions/admin.css"); diff --git a/out/dist/css/actions/pages_view.css b/out/dist/css/actions/pages_view.css new file mode 100644 index 0000000..a358089 --- /dev/null +++ b/out/dist/css/actions/pages_view.css @@ -0,0 +1,29 @@ +ul.pages_menu +{ list-style-type: none; + margin: 5px 20px 5px 10px; + padding: 0; +} + +ul.pages_menu ul +{ list-style-type: none; + margin: 0 0 0 20px; + padding: 0; +} + +ul.pages_menu li +{ margin: 1px 0; + padding: 0; + border-bottom: solid 1px #e5e5e5; +} + +ul.pages_menu li a +{ display: block; + line-height: 2em; + padding: 0 1em; + background-color: #f5f5f5; +} + +ul.pages_menu li a:hover +{ color: #000066; + background-color: #f1f1f1; +} \ No newline at end of file diff --git a/out/dist/functions.php b/out/dist/functions.php new file mode 100644 index 0000000..eae629a --- /dev/null +++ b/out/dist/functions.php @@ -0,0 +1,112 @@ +url("pages/view/page", array("id" => $page["id"]))."\">".$page["title"]."\n"; + if($path_item["id"] == $page["id"]) + { if($sub_content = pages_arbo_navig_lis($env, $page, $ariane)) + { $content .= + "\n"; + } + } + } + } + else + { foreach($arbo["subs"] as $page) + { $content .= "
  • url("pages/view/page", array("id" => $page["id"]))."\">".$page["title"]."
  • \n"; + } + } + } + return $content; + } + endif; + + if(!function_exists("pages_arbo_edit_select_options")) : + function pages_arbo_edit_select_options($arbo, $id_page, $id_parent, $indent_increment = "", $indent = "") + { $arbo["id"] = $arbo["id"] ? $arbo["id"] : ""; + $content = + "" + .$indent.($arbo["id"] ? $arbo["title"] : "Aucune") + .""; + if($arbo["subs"]) + { $indent .= $indent_increment; + foreach($arbo["subs"] as $i => $sub) + { if(!isset($id_page) || $id_page != $sub["id"]) + { $content .= pages_arbo_edit_select_options($sub, $id_page, $id_parent, $indent_increment, $indent); + } + } + } + return $content; + } + endif; + + if(!function_exists("pages_arbo_list_select_options")) : + function pages_arbo_list_select_options($env, $etat, $arbo, $current_page_id, $indent_increment = "", $indent = "") + { $arbo["id"] = isset($arbo["id"]) ? $arbo["id"] : ""; + $content = + "url($etat, array("parent" => $arbo["id"]))."\"" + .(isset($current_page_id) && ($arbo["id"] == $current_page_id) ? " selected=\"selected\"" : "") + .">" + .$indent.($arbo["id"] ? $arbo["title"] : "Racine des pages") + .""; + if($arbo["subs"]) + { $indent .= $indent_increment; + foreach($arbo["subs"] as $i => $sub) + { $content .= pages_arbo_list_select_options($env, $etat, $sub, $current_page_id, $indent_increment, $indent); + } + } + return $content; + } + endif; + + if(!function_exists("pages_arbo_start_select_options")) : + function pages_arbo_start_select_options($env, $arbo, $current_start_action, $current_start_action_params, $indent_increment = "", $indent = "") + { $arbo["id"] = isset($arbo["id"]) ? $arbo["id"] : ""; + if($arbo["id"]) + { $content = + "" + .$indent.$arbo["title"] + .""; + } + if($arbo["subs"]) + { $indent .= $indent_increment; + $indent .= "  "; + foreach($arbo["subs"] as $i => $sub) + { $content .= pages_arbo_start_select_options($env, $sub, $current_start_action, $current_start_action_params, $indent_increment, $indent); + } + } + return $content; + } + endif; + +?> \ No newline at end of file diff --git a/out/dist/js/actions/pages_admin.js b/out/dist/js/actions/pages_admin.js new file mode 100644 index 0000000..a329012 --- /dev/null +++ b/out/dist/js/actions/pages_admin.js @@ -0,0 +1,13 @@ +$(document).ready +( function() + { init_tinymce(); + } +); + +function init_tinymce() +{ $(".tinymce").each + ( function() + { tinyMCE.execCommand("mceAddControl", true, $(this).attr("id")); + } + ); +} diff --git a/out/dist/layouts/pages.xml b/out/dist/layouts/pages.xml new file mode 100644 index 0000000..cf7ec4b --- /dev/null +++ b/out/dist/layouts/pages.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/dist/page.php b/out/dist/page.php new file mode 100644 index 0000000..cfb4e37 --- /dev/null +++ b/out/dist/page.php @@ -0,0 +1,60 @@ + + + + out_file("views/head.php"); ?> + + + + + + + +
    + +
    +
    + +out_config("colonne")) : ?> +
    +out_file("views/pages/colonne.php"); ?> +
    + + +
    out_config("colonne") ? "" : " class=\"no_colonne\"" ?>> +out_file("views/messages.php"); ?> +out_file_exists($layout["content"])) : + +?> + +out_file($layout["content"]); + endif; + +?> + +
    + +
    + +
    +
    + + + + + \ No newline at end of file diff --git a/out/dist/views/pages/admin/add.php b/out/dist/views/pages/admin/add.php new file mode 100644 index 0000000..1568493 --- /dev/null +++ b/out/dist/views/pages/admin/add.php @@ -0,0 +1,32 @@ +out_file("views/tinymce.init.js.php"); ?> + +

    Nouvelle page

    + + + +
    " method="post"> +
      +
    • +

      + Titre : + " /> +

      +
    • +
    • +

      + Page parente : + +

      +
    • +
    • + +
    • +
    • + +
    • +
    +
    \ No newline at end of file diff --git a/out/dist/views/pages/admin/edit.php b/out/dist/views/pages/admin/edit.php new file mode 100644 index 0000000..4eb8676 --- /dev/null +++ b/out/dist/views/pages/admin/edit.php @@ -0,0 +1,32 @@ +out_file("views/tinymce.init.js.php"); ?> + +

    Modifier une page

    + + + +
    $this->out["page"]["id"])) ?>" method="post"> +
      +
    • +

      + Titre : + " /> +

      +
    • +
    • +

      + Page parente : + +

      +
    • +
    • + +
    • +
    • + +
    • +
    +
    \ No newline at end of file diff --git a/out/dist/views/pages/admin/list.php b/out/dist/views/pages/admin/list.php new file mode 100644 index 0000000..a48ef7f --- /dev/null +++ b/out/dist/views/pages/admin/list.php @@ -0,0 +1,78 @@ +

    Pages

    + + + +
    " method="post"> +
      +
    • Page d'accueil du site
    • +
    • + +
    • +
    • + +
    • +
    +
    + +
      +
    • Page parente
    • +
    • + +
    • +
    + +out["pages"]["total"]) : ?> + +out["pages"]["total"] > $this->config("max_list")) : ?> + +out_file("views/navig.php"); ?> + + + +
    " method="post"> + + + + + + + + +out["pages"]["list"] as $id_page => $page) : ?> + + + + + + + + + + + + + + +
    titredate créationpositionactiveactions
    " /> /> + $id_page)) ?>" + class="admin_link" + title="modifier cette page">" /> + + $id_page)) ?>" + class="admin_link" + title="supprimer cette page">" + onclick="return confirm('Supprimer cette page ?')"/> +
      
    +
    + + +

    Aucune page pour le moment.

    + diff --git a/out/dist/views/pages/colonne.php b/out/dist/views/pages/colonne.php new file mode 100644 index 0000000..4145c3e --- /dev/null +++ b/out/dist/views/pages/colonne.php @@ -0,0 +1,10 @@ +out["arbo"]) : + $current_page_id = isset($_GET[$this->param("id")]) ? $_GET[$this->param("id")] : null; + +?> +
      +out["arbo"], $this->out["ariane"]); ?> +
    + diff --git a/out/dist/views/pages/view/index.php b/out/dist/views/pages/view/index.php new file mode 100644 index 0000000..e69de29 diff --git a/out/dist/views/pages/view/page.php b/out/dist/views/pages/view/page.php new file mode 100644 index 0000000..f0d299f --- /dev/null +++ b/out/dist/views/pages/view/page.php @@ -0,0 +1,23 @@ +

    +out["ariane"] as $page) : if($k < count($this->out["ariane"]) - 1) : ?> + 0) : ?> + » + + $page["id"])) ?>"> + + 0) : ?> + » + + out["page"]["title"] ?> +

    + +
    + out["page"]["content"] ?> +
    +out["pages"]["list"]) : ?> + + -- 2.1.4