From 45a6dd3372d573176aaf5d3e2232091ba3173e04 Mon Sep 17 00:00:00 2001 From: dj3c1t Date: Sat, 8 Dec 2012 18:46:03 +0100 Subject: [PATCH] maj syntaxe accolades et correction param manquant --- app/config.xml | 8 ++ app/data/modules/sql/mw_data_pages.php | 59 +++++----- app/data/modules/xml/mw_data_pages.php | 118 ++++++++++---------- app/mods/pages/admin.php | 150 ++++++++++++------------- app/mods/pages/index.php | 7 +- app/mods/pages/view.php | 35 +++--- mw_pages.php | 198 ++++++++++++++++----------------- out/dist/css/actions/pages_view.css | 22 ++-- out/dist/functions.php | 70 ++++++------ out/dist/js/actions/pages_admin.js | 14 +-- out/dist/views/pages/view/page.php | 7 +- 11 files changed, 347 insertions(+), 341 deletions(-) create mode 100644 app/config.xml diff --git a/app/config.xml b/app/config.xml new file mode 100644 index 0000000..8f740ca --- /dev/null +++ b/app/config.xml @@ -0,0 +1,8 @@ + + + + + parent + + + \ No newline at end of file diff --git a/app/data/modules/sql/mw_data_pages.php b/app/data/modules/sql/mw_data_pages.php index 3ef0b6c..e6fec6f 100644 --- a/app/data/modules/sql/mw_data_pages.php +++ b/app/data/modules/sql/mw_data_pages.php @@ -1,19 +1,18 @@ page($id)) - { if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane); + function page_ariane($id, $ariane = array()){ + if($page = $this->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; + 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; @@ -28,8 +27,8 @@ $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 = ( + isset($order_by) ? " ORDER BY ".$order_by.(isset($order) ? " ".$order : "") : "" ); @@ -39,8 +38,8 @@ 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; + 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; @@ -49,16 +48,16 @@ return $pages; } - function pages_arbo($params = array()) - { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; + 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; + if(isset($id_parent)){ + if($parent = $this->page($id_parent)) $arbo = $parent; else return false; } $arbo["subs"] = array(); @@ -67,24 +66,24 @@ $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 = ( + 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"]; + 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(); + function page($id){ + $page = array(); $sgbd = $this->sgbd(); $sql = "SELECT * FROM #--pages WHERE id=".$this->eq($id); $rst = $sgbd->query($sql); @@ -93,8 +92,8 @@ return $page; } - function add_page($params) - { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; + 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; @@ -119,9 +118,9 @@ 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"]); + 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; @@ -143,10 +142,10 @@ 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; + 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; } diff --git a/app/data/modules/xml/mw_data_pages.php b/app/data/modules/xml/mw_data_pages.php index 18a3613..9ea3f70 100644 --- a/app/data/modules/xml/mw_data_pages.php +++ b/app/data/modules/xml/mw_data_pages.php @@ -1,19 +1,18 @@ page($id)) - { if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane); + function page_ariane($id, $ariane = array()){ + if($page = $this->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; + 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; @@ -23,37 +22,37 @@ $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; + 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"])) + 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($enabled)){ + $MATCH = ($v_rst["enabled"] == $enabled); } } - if($MATCH) - { if(isset($user)) - { $MATCH = ($v_rst["user_creation"] == $user); + if($MATCH){ + if(isset($user)){ + $MATCH = ($v_rst["user_creation"] == $user); } } - if($MATCH) - { $pages["total"]++; + if($MATCH){ + $pages["total"]++; $MATCH = !isset($start) || !$max || ($pages["total"] > $start && $pages["total"] <= ($start + $max)); } if($MATCH) $pages["list"][$v_rst["id"]] = $v_rst; @@ -64,44 +63,45 @@ return $pages; } - function pages_arbo($params = array()) - { $params["id_parent"] = isset($params["id_parent"]) ? $params["id_parent"] : ""; + 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; + 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"]; + 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(); + 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; + 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", + return ( + ( + $id_page = $sgbd->add_data( + "pages", array ( "id_parent" => $id_parent, "title" => $title, @@ -118,20 +118,20 @@ ); } - 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"]); + 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", + return $sgbd->set_data( + "pages", $id, - array - ( "id_parent" => $id_parent, + array( + "id_parent" => $id_parent, "title" => $title, "content" => $content, "date_creation" => $page["date_creation"], @@ -146,17 +146,17 @@ 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; + 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; } } diff --git a/app/mods/pages/admin.php b/app/mods/pages/admin.php index 48e4f89..3498dca 100644 --- a/app/mods/pages/admin.php +++ b/app/mods/pages/admin.php @@ -1,17 +1,17 @@ data(); - if(($arbo = $data->pages_arbo()) !== false) - { $env->set_out("arbo", $arbo); + function index(&$env){ + $data = $env->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, + 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, @@ -19,12 +19,12 @@ ) ) ) !== false - ) - { $env->set_out("pages", $pages); + ){ + $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"); + 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); @@ -34,12 +34,12 @@ else $env->erreur("impossible de lire l'arborescence des pages"); } - function validate_POST_page(&$env, $page = null) - { $page = isset($page) ? $page : array(); + 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); + 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"]; @@ -51,17 +51,17 @@ return $_page; } - function add(&$env) - { $data = $env->data(); - if(($arbo = $data->pages_arbo()) !== false) - { $env->set_out("arbo", $arbo); + 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"), + 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/edit", array("id" => $id_page)), "la page a été ajoutée" ); } @@ -73,17 +73,17 @@ 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"), + 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/edit", array("id" => $_GET[$env->param("id")])), "la page a été modifiée" ); } @@ -97,26 +97,26 @@ 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(); + 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); + 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"); + 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"), + if($OK){ + $env->redirect( + $env->url("pages/admin"), "Les informations des pages ont été enregistrées" ); } @@ -126,30 +126,30 @@ else $env->erreur("impossible de lire les informations de l'utilisateur"); } - function set_accueil(&$env) - { if(($user = $env->user()) && $user["id"]) - { $data = $env->data(); + 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"; + 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; + 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) + 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"), + ){ + $data->set_config("plugins_pages_start_id", $id_page); + $env->redirect( + $env->url("pages/admin"), "La page d'accueil a été enregistrée" ); } @@ -159,12 +159,12 @@ 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"), + 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" ); } diff --git a/app/mods/pages/index.php b/app/mods/pages/index.php index 696b5c2..3ba9151 100644 --- a/app/mods/pages/index.php +++ b/app/mods/pages/index.php @@ -1,10 +1,9 @@ run("pages/view"); + function index(&$env){ + $env->run("pages/view"); } } diff --git a/app/mods/pages/view.php b/app/mods/pages/view.php index da382f0..cb94a99 100644 --- a/app/mods/pages/view.php +++ b/app/mods/pages/view.php @@ -1,32 +1,31 @@ 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"], + function page(&$env){ + $data = $env->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); + ){ + $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"); } diff --git a/mw_pages.php b/mw_pages.php index 056efbc..19119b9 100644 --- a/mw_pages.php +++ b/mw_pages.php @@ -1,33 +1,34 @@ set_link("plugins/admin/mw_pages", $env->url("pages/admin"), "éditer les pages"); + function init($env){ + $env->set_link("plugins/admin/mw_pages", $env->url("pages/admin"), "éditer les pages"); + $env->set_link("admin/pages", $env->url("pages/admin"), "Pages", 40); $data = $env->data(); - if - ( ( $pages = $data->pages - ( array - ( "id_parent" => "", + 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, + ){ + 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"] @@ -37,30 +38,30 @@ 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") + 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 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", "") + 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 true; } return false; } @@ -71,41 +72,41 @@ // install // - function install($env) - { if($env->bdd("sgbd") == "xml") return $this->install_xml($env); + 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(); + 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(!isset($EXISTS)){ + return "impossible de savoir si la table #--pages existe"; } - if($EXISTS) - { return "la table #--pages existe deja"; + if($EXISTS){ + return "la table #--pages existe deja"; } - if(!$sgbd->create_data("pages")) - { return "imposible de creer la table #--pages"; + 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"); + 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(); + 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(!isset($EXISTS)){ + return "impossible de savoir si la table #--pages existe"; } - if($EXISTS) - { return "la table #--pages existe deja"; + if($EXISTS){ + return "la table #--pages existe deja"; } $sql = "CREATE TABLE #--pages" @@ -120,25 +121,25 @@ .", 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($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\""); + 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(); + 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(!isset($EXISTS)){ + return "impossible de savoir si la table #--pages existe"; } - if($EXISTS) - { return "la table #--pages existe deja"; + if($EXISTS){ + return "la table #--pages existe deja"; } $sql = "CREATE TABLE #--pages" @@ -153,11 +154,11 @@ .", 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($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"); + 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; @@ -167,80 +168,80 @@ // uninstall // - function uninstall($env) - { if($env->bdd("sgbd") == "xml") return $this->uninstall_xml($env); + 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(); + 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(!isset($EXISTS)){ + return "impossible de savoir si la table #--pages existe"; } - if(!$EXISTS) - { // return "la table #--pages n'existe pas"; + if(!$EXISTS){ + // return "la table #--pages n'existe pas"; } - elseif(!$sgbd->remove_data("pages")) - { return "imposible de supprimer la table #--pages"; + 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"]; + 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); + if($ids !== false){ + foreach($ids as $id){ + $sgbd->del_data("action_status", $id); } } return true; } - function uninstall_sqlite($env) - { $data = $env->data(); + 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(!isset($EXISTS)){ + return "impossible de savoir si la table #--pages existe"; } - if(!$EXISTS) - { // return "la table #--pages n'existe pas"; + if(!$EXISTS){ + // return "la table #--pages n'existe pas"; } - elseif(!$sgbd->query("DROP TABLE \"main\".\"#--pages\"")) - { return "imposible de supprimer la table #--pages"; + 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(); + 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(!isset($EXISTS)){ + return "impossible de savoir si la table #--pages existe"; } - if(!$EXISTS) - { // return "la table #--pages n'existe pas"; + if(!$EXISTS){ + // return "la table #--pages n'existe pas"; } - elseif(!$sgbd->query("DROP TABLE #--pages")) - { return "imposible de supprimer la table #--pages"; + 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; @@ -248,5 +249,4 @@ } - ?> \ No newline at end of file diff --git a/out/dist/css/actions/pages_view.css b/out/dist/css/actions/pages_view.css index a358089..bf1b915 100644 --- a/out/dist/css/actions/pages_view.css +++ b/out/dist/css/actions/pages_view.css @@ -1,29 +1,29 @@ -ul.pages_menu -{ list-style-type: none; +ul.pages_menu{ + list-style-type: none; margin: 5px 20px 5px 10px; padding: 0; } -ul.pages_menu ul -{ list-style-type: none; +ul.pages_menu ul{ + list-style-type: none; margin: 0 0 0 20px; padding: 0; } -ul.pages_menu li -{ margin: 1px 0; +ul.pages_menu li{ + margin: 1px 0; padding: 0; border-bottom: solid 1px #e5e5e5; } -ul.pages_menu li a -{ display: block; +ul.pages_menu li a{ + display: block; line-height: 2em; padding: 0 1em; background-color: #f5f5f5; } -ul.pages_menu li a:hover -{ color: #000066; +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 index eae629a..f96e4b8 100644 --- a/out/dist/functions.php +++ b/out/dist/functions.php @@ -1,8 +1,8 @@ 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 .= + function pages_arbo_navig_lis($env, $arbo, $ariane = array()){ + $content = ""; + if($arbo["subs"]){ + if($path_item = array_shift($ariane)){ + foreach($arbo["subs"] as $page){ + $content .= "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"; @@ -27,9 +27,9 @@ } } } - else - { foreach($arbo["subs"] as $page) - { $content .= "
  • url("pages/view/page", array("id" => $page["id"]))."\">".$page["title"]."
  • \n"; + else{ + foreach($arbo["subs"] as $page){ + $content .= "
  • url("pages/view/page", array("id" => $page["id"]))."\">".$page["title"]."
  • \n"; } } } @@ -38,8 +38,8 @@ 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"] : ""; + 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); + 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); } } } @@ -60,8 +60,8 @@ 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"] : ""; + 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"]))."\"" @@ -69,10 +69,10 @@ .">" .$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); + 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; @@ -80,10 +80,10 @@ 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 = + 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 = ""; } - if($arbo["subs"]) - { $indent .= $indent_increment; + 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); + 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; diff --git a/out/dist/js/actions/pages_admin.js b/out/dist/js/actions/pages_admin.js index a329012..0f05d4f 100644 --- a/out/dist/js/actions/pages_admin.js +++ b/out/dist/js/actions/pages_admin.js @@ -1,13 +1,13 @@ -$(document).ready -( function() - { init_tinymce(); +$(document).ready( + function(){ + init_tinymce(); } ); -function init_tinymce() -{ $(".tinymce").each - ( function() - { tinyMCE.execCommand("mceAddControl", true, $(this).attr("id")); +function init_tinymce(){ + $(".tinymce").each( + function(){ + tinyMCE.execCommand("mceAddControl", true, $(this).attr("id")); } ); } diff --git a/out/dist/views/pages/view/page.php b/out/dist/views/pages/view/page.php index f0d299f..f6413ef 100644 --- a/out/dist/views/pages/view/page.php +++ b/out/dist/views/pages/view/page.php @@ -11,9 +11,6 @@ out["page"]["title"] ?> -
    - out["page"]["content"] ?> -
    out["pages"]["list"]) : ?>
      out["pages"]["list"] as $page) : ?> @@ -21,3 +18,7 @@
    + +
    + out["page"]["content"] ?> +
    -- 2.1.4