mise a jour pour mtweb.0.9.0
[mw_pages] / app / helpers / mw_helper_pages.php
diff --git a/app/helpers/mw_helper_pages.php b/app/helpers/mw_helper_pages.php
new file mode 100644 (file)
index 0000000..f6db62c
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+
+  class mw_helper_pages extends mw_helper{
+
+    function datetime2timestamp($string){
+      list($date, $time) = explode(" ", $string);
+      list($year, $month, $day) = explode("-", $date);
+      list($hour, $minute, $second) = explode(":", $time);
+      $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
+      return $timestamp;
+    }
+
+    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 .= "<li".($path_item["id"] == $page["id"] ? " class=\"current\"" : "")."><a href=\"".$env->url("pages/view/page", array("id" => $page["id"]))."\">".$page["title"]."</a></li>\n";
+            if($path_item["id"] == $page["id"]){
+              if($sub_content = $this->pages_arbo_navig_lis($env, $page, $ariane)){
+                $content .=
+                 "<ul>\n"
+                .$sub_content
+                ."</ul>\n";
+              }
+            }
+          }
+        }
+        else{
+          foreach($arbo["subs"] as $page){
+            $content .= "<li><a href=\"".$env->url("pages/view/page", array("id" => $page["id"]))."\">".$page["title"]."</a></li>\n";
+          }
+        }
+      }
+      return $content;
+    }
+
+    function pages_arbo_edit_select_options($arbo, $id_page, $id_parent, $indent_increment = "", $indent = ""){
+      $arbo["id"] = $arbo["id"] ? $arbo["id"] : "";
+      $content =
+       "<option"
+      ." value=\"".$arbo["id"]."\""
+      .(isset($id_parent) && ($arbo["id"] == $id_parent) ? " selected=\"selected\"" : "")
+      .">"
+      .$indent.($arbo["id"] ? $arbo["title"] : "Aucune")
+      ."</option>";
+      if($arbo["subs"]){
+        $indent .= $indent_increment;
+        foreach($arbo["subs"] as $i => $sub){
+          if(!isset($id_page) || $id_page != $sub["id"]){
+            $content .= $this->pages_arbo_edit_select_options($sub, $id_page, $id_parent, $indent_increment, $indent);
+          }
+        }
+      }
+      return $content;
+    }
+
+    function pages_arbo_list_select_options($env, $etat, $arbo, $current_page_id, $indent_increment = "", $indent = ""){
+      $arbo["id"] = isset($arbo["id"]) ? $arbo["id"] : "";
+      $content =
+       "<option"
+      ." value=\"".$env->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")
+      ."</option>";
+      if($arbo["subs"]){
+        $indent .= $indent_increment;
+        foreach($arbo["subs"] as $i => $sub){
+          $content .= $this->pages_arbo_list_select_options($env, $etat, $sub, $current_page_id, $indent_increment, $indent);
+        }
+      }
+      return $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"] : "";
+      $content = "";
+      if($arbo["id"]){
+        $content =
+         "<option"
+        ." value=\"".$arbo["id"]."\""
+        .(    isset($current_start_action)
+           && ($current_start_action == "pages/view/page")
+           && isset($current_start_action_params["id"])
+           && ($arbo["id"] == $current_start_action_params["id"])
+           ?
+             " selected=\"selected\""
+           : ""
+         )
+        .">"
+        .$indent.$arbo["title"]
+        ."</option>";
+      }
+      if($arbo["subs"]){
+        $indent .= $indent_increment;
+        $indent .= "&nbsp;&nbsp;";
+        foreach($arbo["subs"] as $i => $sub){
+          $content .= $this->pages_arbo_start_select_options($env, $sub, $current_start_action, $current_start_action_params, $indent_increment, $indent);
+        }
+      }
+      return $content;
+    }
+
+  }
+
+?>
\ No newline at end of file