tinymce enregistre les urls complettes des images
[mw_pages] / app / data / modules / sql / mw_data_pages.php
index 3ef0b6c..c7648d7 100644 (file)
@@ -1,19 +1,18 @@
 <?php
 
-  class mw_data_pages extends mw_data
-  {
+  class mw_data_pages extends mw_data{
 
-    function page_ariane($id, $ariane = array())
-    { if($page = $this->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;
       $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 : "")
         : ""
       );
       $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;
+      try{
         $rst = $sgbd->query($sql);
-        if(!isset($rst)) return false;
-        while($v_rst = $sgbd->fetch_assoc($rst)) $pages["list"][$v_rst["id"]] = $v_rst;
+        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);
+          while($v_rst = $sgbd->fetch_assoc($rst)) $pages["list"][$v_rst["id"]] = $v_rst;
+          $sgbd->free_result($rst);
+        }
       }
+      catch(Exception $e) { $pages = false; }
       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();
       $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"];
-        $arbo["subs"][] = $this->pages_arbo($params);
+      try{
+        $rst = $sgbd->query($sql);
+        while($v_rst = $sgbd->fetch_assoc($rst)){
+          $params["id_parent"] = $v_rst["id"];
+          $arbo["subs"][] = $this->pages_arbo($params);
+        }
+        $sgbd->free_result($rst);
       }
-      $sgbd->free_result($rst);
+      catch(Exception $e) { $arbo = false; }
       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);
-      if(!isset($rst)) return false;
-      if($v_rst = $sgbd->fetch_assoc($rst)) $page = $v_rst;
+      try{
+        $rst = $sgbd->query($sql);
+        if($v_rst = $sgbd->fetch_assoc($rst)) $page = $v_rst;
+        $sgbd->free_result($rst);
+      }
+      catch(Exception $e) { $page = false; }
       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;
       .", ".$this->eq($enabled)
       .", ".$this->eq($position)
       .")";
-      if($sgbd->query($sql)) return $sgbd->insert_id();
-      return false;
+      try{
+        $sgbd->query($sql);
+        $id_page = $sgbd->insert_id();
+      }
+      catch(Exception $e) { $id_page = false; }
+      return $id_page;
     }
 
-    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=".$this->eq($enabled)
         .", position=".$this->eq($position)
         ." WHERE id=".$this->eq($id);
-        if($sgbd->query($sql)) return true;
+        try{
+          $sgbd->query($sql);
+        }
+        catch(Exception $e) { return false; }
+        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;
+    function del_page($id){
+      $sgbd = $this->sgbd();
+      try{
+        $sgbd->query("UPDATE #--pages SET id_parent=NULL WHERE id_parent=".$this->eq($id));
+        $sgbd->query("DELETE FROM #--pages WHERE id=".$this->eq($id));
       }
-      return false;
+      catch(Exception $e) { return false; }
+      return true;
     }
 
   }