nouveaux noms d'elements dans les fichiers XML des sources sourceml.1.0.0
authordj3c1t <dj3c1t@free.fr>
Sat, 26 Oct 2013 13:26:11 +0000 (15:26 +0200)
committerdj3c1t <dj3c1t@free.fr>
Sat, 26 Oct 2013 13:26:11 +0000 (15:26 +0200)
app/controllers/users/morceaux.php
app/data/modules/share/sml_data_sources_xml_format.php
app/data/modules/sql/sml_data_source_groupes.php
app/out/default/css/sourceml_accounts.css
app/out/default/views/content/sources/xml_form.php
app/out/default/views/sources/source/header.php

index 93cf57f..75414bc 100644 (file)
             ),
             isset($_POST["use_edit_reference_content"]) ? true : false
           );
+          $morceau["licence"]["id"] = 0;
         }
         else{
           if(!($morceau["titre"] = trim($_POST["titre"]))){
index 1916bea..320ecee 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
-  class sml_data_sources_xml_format extends mw_data
-  {
+  class sml_data_sources_xml_format extends mw_data{
 
     var $status; // classes de sources - table sml_classes
     var $source;
     #                                                                            data vers XML
     #
 
-    function source_xml_content($id, $params = array())
-    { $env = $this->env();
+    function source_xml_content($id, $params = array()){
+      $env = $this->env();
       $content = false;
       $this->status = isset($this->status) ? $this->status : $this->source_status();
-      if($this->status !== false)
-      { $this->source = isset($params["source"]) ? $params["source"] : $this->source($id, true);
-        if($this->source !== false)
-        { if($this->source["groupes"]) $this->groupes = $this->source["groupes"];
+      if($this->status !== false){
+        $this->source = isset($params["source"]) ? $params["source"] : $this->source($id, true);
+        if($this->source !== false){
+          if($this->source["groupes"]) $this->groupes = $this->source["groupes"];
           if(isset($params["groupes"])) $this->groupes = $params["groupes"];
           if(!isset($this->groupes)) $this->groupes = $this->source_groupes($id);
-          if($this->groupes !== false)
-          { $this->licence = isset($params["licence"]) ? $params["licence"] : $this->licence($this->source["licence"]["id"]);
-            if($this->licence !== false)
-            { if(($this->sources = $this->source_compositions(array("id_composition" => $id))) !== false)
-              { $content = "<source>\n";
-                if($this->source["derivations"])
-                { foreach($this->source["derivations"] as $id_derivation => $derivation)
-                  { $content .= "  <derivation><![CDATA[".$derivation["xml"]["url"]."]]></derivation>\n";
+          if($this->groupes !== false){
+            $this->licence = isset($params["licence"]) ? $params["licence"] : $this->licence($this->source["licence"]["id"]);
+            if($this->licence !== false){
+              if(($this->sources = $this->source_compositions(array("id_composition" => $id))) !== false){
+                $content = "<source>\n";
+                if($this->source["derivations"]){
+                  foreach($this->source["derivations"] as $id_derivation => $derivation){
+                    $content .= "  <derivated_from href=\"".$derivation["xml"]["url"]."\" />\n";
                   }
                 }
-                if($this->source["reference"]) $content .= "  <reference><![CDATA[".$this->source["reference"]["xml"]["url"]."]]></reference>\n";
-                else
-                { $content .=
-                   "  <titre><![CDATA[".$this->source["titre"]."]]></titre>\n"
-                  ."  <from><![CDATA[http://".$_SERVER["SERVER_NAME"].$env->url("sources/".$this->status[$this->source["status"]]["nom"]."/view", array($this->status[$this->source["status"]]["nom"] => $id))."]]></from>\n";
+                if($this->source["reference"]) $content .= "  <reference href=\"".$this->source["reference"]["xml"]["url"]."\" />\n";
+                else{
+                  $content .=
+                   "  <title><![CDATA[".$this->source["titre"]."]]></title>\n"
+                  ."  <link href=\"http://".$_SERVER["SERVER_NAME"].$env->url("sources/".$this->status[$this->source["status"]]["nom"]."/view", array($this->status[$this->source["status"]]["nom"] => $id))."\" />\n";
+                  if(isset($this->source["image_uri"]) && $this->source["image_uri"]){
+                    $content .=
+                    "  <image src=\""."http://".$_SERVER["SERVER_NAME"].$env->path("web").$this->source["image_uri"]."\" />\n";
+                  }
+                  if(isset($this->source["date_creation"]) && $this->source["date_creation"]){
+                    $content .=
+                    "  <date>".$this->source["date_creation"]."</date>\n";
+                  }
+                  if(isset($this->source["description"]) && $this->source["description"]){
+                    $content .=
+                    "  <description><![CDATA[".$this->source["description"]."]]></description>\n";
+                  }
                   $HAS_AUTHOR = false;
-                  foreach($this->groupes as $id_groupe => $groupe)
-                  { if($groupe["nom"] && $groupe["id_groupe_status"])
-                    { if
-                      (    $groupe["id_groupe_status"] == $this->id_groupe_status_admin()
+                  foreach($this->groupes as $id_groupe => $groupe){
+                    if($groupe["nom"] && $groupe["id_groupe_status"]){
+                      if(
+                           $groupe["id_groupe_status"] == $this->id_groupe_status_admin()
                         || $groupe["id_groupe_status"] == $this->id_groupe_status_editeur()
-                      )
-                      { $content .= "  <auteur><![CDATA[".$groupe["nom"]."]]></auteur>\n";
+                      ){
+                        $content .= "  <author><![CDATA[".$groupe["nom"]."]]></author>\n";
                         $HAS_AUTHOR = true;
                       }
                     }
                     else return false;
                   }
                   if(!$HAS_AUTHOR) return false;
-                  foreach($this->source["documents"] as $id_document => $document)
-                  { $content .=
-                     "  <document>\n"
-                    ."    <nom><![CDATA[".$document["nom"]."]]></nom>\n"
-                    ."    <url><![CDATA[".$document["url"]."]]></url>\n"
+                  foreach($this->source["documents"] as $id_document => $document){
+                    $content .=
+                     "  <document src=\"".$document["url"]."\">\n"
+                    ."    <![CDATA[".$document["nom"]."]]>\n"
                     ."  </document>\n";
                   }
-                  if($this->licence)
-                  { $content .=
-                     "  <licence url=\"".$this->licence["url"]."\"><![CDATA[".$this->licence["nom"]."]]></licence>\n";
+                  if($this->licence){
+                    $content .=
+                     "  <licence href=\"".$this->licence["url"]."\"><![CDATA[".$this->licence["nom"]."]]></licence>\n";
                   }
-                  if(isset($this->sources[$id]))
-                  { foreach($this->sources[$id] as $id_source)
-                    { $content .= "  <source src=\"".$this->source_xml_url($id_source)."\" />\n";
+                  if(isset($this->sources[$id])){
+                    foreach($this->sources[$id] as $id_source){
+                      $content .= "  <source src=\"".$this->source_xml_url($id_source)."\" />\n";
                     }
                   }
                 }
     #                                                                            XML vers data
     #
 
-    function parse_source_xml($xml_content)
-    { if(!isset($this->sxml)) $this->sxml = new sxml();
+    function parse_source_xml($xml_content){
+      if(!isset($this->sxml)) $this->sxml = new sxml();
       $this->sxml->parse($xml_content);
       return isset($this->sxml->data["source"][0]);
     }
 
-    function empty_source($params = array())
-    { $source = array
-      ( "groupes" => array(),
+    function empty_source($params = array()){
+      $source = array(
+        "groupes" => array(),
         "titre" => "",
+        "date_creation" => "",
         "from" => "",
-        "licence" => array
-        ( "nom" => "",
+        "licence" => array(
+          "nom" => "",
           "url" => ""
         ),
         "documents" => array(),
         "derivations" => array(),
         "reference" => array(),
-        "xml" => array
-        ( "url" => "",
+        "xml" => array(
+          "url" => "",
           "content" => "",
           "use_edit_content" => false
         )
       return $source;
     }
 
-    function source_xml_read($url, $xml_content = null)
-    { $source = $this->empty_source();
-      if($this->xml_content = (isset($xml_content) ? $xml_content : $this->get_source_xml_from_url($url)))
-      { if($this->xml_content === -1) $this->xml_content = $this->get_source_xml_from_url($url, true);
-        $source["xml"] = array
-        ( "url" => $url,
-          "content" => $this->xml_content,
-          "use_edit_content" => false
-        );
-        if($this->parse_source_xml($this->xml_content))
-        { $this->buffer = $this->sxml->data["source"][0];
-          foreach($this->buffer["subs"] as $key => $value)
-          { if($key == "auteur")
-            { $source["groupes"][] = array
-              ( "nom" => $value[0]["data"]
-              );
-            }
-            elseif($key == "document")
-            { foreach($value as $id_document => $document)
-              { $source["documents"][$id_document] = array
-                ( "nom" => $document["subs"]["nom"][0]["data"],
-                  "url" => $document["subs"]["url"][0]["data"]
-                );
-              }
-            }
-            elseif($key == "derivation")
-            { $source["derivations"][] = array
-              ( "xml" => array
-                ( "url" => $value[0]["data"],
-                  "content" => "",
-                  "use_edit_content" => false
-                )
-              );
-            }
-            elseif($key == "reference")
-            { $source["reference"] = array
-              ( "xml" => array
-                ( "url" => $value[0]["data"],
-                  "content" => "",
-                  "use_edit_content" => false
-                )
-              );
-            }
-            elseif($key == "licence")
-            { $source["licence"] = array
-              ( "nom" => $value[0]["data"],
-                "url" => $value[0]["attrs"]["url"]
-              );
-            }
-            else
-            { if(isset($value[0]["data"])) $source[$key] = $value[0]["data"];
-            }
+    function source_xml_read($url, $xml_content = null){
+      $source = $this->empty_source();
+      if($this->xml_content = (isset($xml_content) ? $xml_content : $this->get_source_xml_from_url($url))){
+        if($this->xml_content === -1) $this->xml_content = $this->get_source_xml_from_url($url, true);
+        if($this->parse_source_xml($this->xml_content)){
+          $source["xml"] = array(
+            "url" => $url,
+            "content" => $this->xml_content,
+            "use_edit_content" => false
+          );
+          $this->buffer = $this->sxml->data["source"][0];
+          if($source_xml_version = $this->get_source_buffer_xml_version()){
+            $source = $this->parse_source_buffer($source_xml_version, $source);
           }
-          $source["auteur"] = "";
-          foreach($source["groupes"] as $auteur) $source["auteur"] .= ($source["auteur"] ? ", " : "").$auteur["nom"];
+          else return false;
         }
         else return false;
       }
       return $source;
     }
 
+    function parse_source_buffer($source_xml_version, $default_source = null){
+      if(method_exists($this, $method_name = "parse_source_buffer_".$source_xml_version)){
+        return $this->$method_name($default_source);
+      }
+      return false;
+    }
+
+    function get_source_buffer_xml_version(){
+      if(!isset($this->buffer["subs"])) return false;
+      foreach($this->buffer["subs"] as $key => $value){
+        if($key == "titre" || $key == "auteur"){
+          return "v1";
+        }
+        if($key == "title" || $key == "author"){
+          return "v2";
+        }
+      }
+    }
+
+    // -------------------------------------- source XML v2
+
+    function parse_source_buffer_v2($default_source = null){
+      if(isset($default_source)) $source = $default_source;
+      else $source = $this->empty_source();
+      if(!isset($this->buffer["subs"])) return $source;
+      foreach($this->buffer["subs"] as $key => $value){
+        if($key == "title"){
+          $source["titre"] = $value[0]["data"];
+        }
+        elseif($key == "link"){
+          $source["from"] = $value[0]["attrs"]["href"];
+        }
+        elseif($key == "image"){
+          $source["image"] = $value[0]["attrs"]["src"];
+        }
+        elseif($key == "author"){
+          foreach($value as $author){
+            $source["groupes"][] = array(
+              "nom" => $author["data"],
+              "id_groupe_status" => 0
+            );
+          }
+        }
+        elseif($key == "date"){
+          $source["date_creation"] = $value[0]["data"];
+        }
+        elseif($key == "document"){
+          foreach($value as $id_document => $document){
+            $source["documents"][$id_document] = array(
+              "nom" => $document["data"],
+              "url" => $document["attrs"]["src"]
+            );
+          }
+        }
+        elseif($key == "derivated_from"){
+          $source["derivations"][] = array(
+            "xml" => array(
+              "url" => $value[0]["attrs"]["href"],
+              "content" => "",
+              "use_edit_content" => false
+            )
+          );
+        }
+        elseif($key == "reference"){
+          $source["reference"] = array(
+            "xml" => array(
+              "url" => $value[0]["attrs"]["href"],
+              "content" => "",
+              "use_edit_content" => false
+            )
+          );
+        }
+        elseif($key == "licence"){
+          $source["licence"] = array(
+            "id" => 0,
+            "nom" => $value[0]["data"],
+            "url" => $value[0]["attrs"]["href"]
+          );
+        }
+        else{
+          if(isset($value[0]["data"])) $source[$key] = $value[0]["data"];
+        }
+      }
+      $source["auteur"] = "";
+      foreach($source["groupes"] as $auteur) $source["auteur"] .= ($source["auteur"] ? ", " : "").$auteur["nom"];
+      return $source;
+    }
+
+    // -------------------------------------- source XML v1
+
+    function parse_source_buffer_v1($default_source = null){
+      if(isset($default_source)) $source = $default_source;
+      else $source = $this->empty_source();
+      if(!isset($this->buffer["subs"])) return $source;
+      foreach($this->buffer["subs"] as $key => $value){
+        if($key == "auteur"){
+          $source["groupes"][] = array(
+            "nom" => $value[0]["data"]
+          );
+        }
+        elseif($key == "document"){
+          foreach($value as $id_document => $document){
+            $source["documents"][$id_document] = array(
+              "nom" => $document["subs"]["nom"][0]["data"],
+              "url" => $document["subs"]["url"][0]["data"]
+            );
+          }
+        }
+        elseif($key == "derivation"){
+          $source["derivations"][] = array(
+            "xml" => array(
+              "url" => $value[0]["data"],
+              "content" => "",
+              "use_edit_content" => false
+            )
+          );
+        }
+        elseif($key == "reference"){
+          $source["reference"] = array(
+            "xml" => array(
+              "url" => $value[0]["data"],
+              "content" => "",
+              "use_edit_content" => false
+            )
+          );
+        }
+        elseif($key == "licence"){
+          $source["licence"] = array(
+            "nom" => $value[0]["data"],
+            "url" => $value[0]["attrs"]["url"]
+          );
+        }
+        else{
+          if(isset($value[0]["data"])) $source[$key] = $value[0]["data"];
+        }
+      }
+      $source["auteur"] = "";
+      foreach($source["groupes"] as $auteur) $source["auteur"] .= ($source["auteur"] ? ", " : "").$auteur["nom"];
+      return $source;
+    }
+
   }
 
 ?>
\ No newline at end of file
index 45d07b1..e2fb23f 100644 (file)
 
     function get_editor_groupes($groupes){
       $editor_groupes = array();
-      if(is_array($groupes)) foreach($groupes as $source_groupe)
-      { if(
+      if(is_array($groupes)) foreach($groupes as $source_groupe){
+        if(
               $source_groupe["id_groupe_status"] == $this->id_groupe_status_admin()
           ||  $source_groupe["id_groupe_status"] == $this->id_groupe_status_editeur()
         ){
index 1354534..e435031 100644 (file)
@@ -49,14 +49,22 @@ ul.xml_infos li
   color: #c0c0c0;
 }
 
-.admin_source_infos ul.admin_source_head
-{ list-style-type: none;
+.admin_source_infos p.logo_source{
+  float: left;
+}
+
+.admin_source_infos ul.admin_source_head{
+  float: right;
+  list-style-type: none;
   margin: 0px 0px 0px 0px;
   text-align: right;
   padding-bottom: 10px;
   padding-top: 5px;
 }
 
+.admin_source_infos .admin_source_url{
+  margin-top: 10px;
+}
 
 #documents .document
 { border: solid 1px #c0c0c0;
index 3b01a82..faa21c2 100644 (file)
   <?php endif; ?>
 
   <div>
+    <?php
+
+      if(
+            (isset($source["xml"]) && $source["xml"])
+        &&  (isset($source["image"]) && $source["image"])
+        &&  ($img_size = $data->img_size($source["image"], 150, 150)) !== false
+      ) :
+
+    ?>
+    <p class="logo_source">
+      <a href="<?php echo $source["from"] ?>">
+        <img src="<?php echo $source["image"]; ?>"
+             width="<?php echo $img_size["width"] ?>"
+             height="<?php echo $img_size["height"] ?>"
+             alt="" />
+      </a>
+    </p>
+    <?php endif; ?>
     <ul class="admin_source_head">
     <?php if(isset($source["xml"]) && $source["xml"]) : ?>
       <li class="admin_form_title"><?php echo $xml_label ?><a href="<?php echo $source["from"] ?>"><strong><?php echo $source["titre"] ?></strong></a></li>
+      <?php foreach($source["groupes"] as $groupe) : ?>
+      <li class="admin_form_title"><?php echo $groupe["nom"] ?></li>
+      <?php endforeach; ?>
     <?php endif; ?>
     <?php if($xml_maj_url && $this->config("cache_actif")) : ?>
       <li><a href="<?php echo $xml_maj_url ?>">Recharger</a></li>
@@ -30,6 +51,7 @@
       <li><a href="#" onclick="del_sml_xf('<?php echo $xml_name ?>_infos<?php echo $xml_id_suffix ?>'); return false;">Enlever</a></li>
     <?php endif; ?>
     </ul>
+    <div class="clear"><!-- --></div>
     <div class="admin_source_url">URL du fichier XML
     : <input type="text" id="<?php echo $xml_name ?><?php echo $xml_id_suffix ?>" name="<?php echo $xml_name ?><?php echo $xml_id_suffix ?>" size="40" value="<?php echo isset($source["xml"]["url"]) ? $source["xml"]["url"] : "" ?>" />
     </div>
index b32a289..31e1adf 100644 (file)
@@ -1,7 +1,18 @@
 <?php
 
-  $groupes = $data->get_editor_groupes($source["reference"] ? $source["reference"]["groupes"] : $source["groupes"]);
-  foreach($groupes as $k => $groupe) $groupes[$k]["url"] = $this->url("sources/groupe/view", array("id" => $groupe["id"]));
+  if($source["reference"]){
+    $groupes = array();
+    foreach($source["reference"]["groupes"] as $groupe){
+      $groupes[] = array(
+        "nom" => $groupe["nom"],
+        "url" => $source["reference"] ? $source["reference"]["from"] : $source["url"]
+      );
+    }
+  }
+  else{
+    $groupes = $data->get_editor_groupes($source["reference"] ? $source["reference"]["groupes"] : $source["groupes"]);
+    foreach($groupes as $k => $groupe) $groupes[$k]["url"] = $this->url("sources/groupe/view", array("id" => $groupe["id"]));
+  }
 
 ?>
 <header>
   <?php
   
     $HAS_IMAGE = false;
-    if
-    (    $source["image_uri"]
-      && file_exists($source["image_uri"])
-      && ($img_size = $data->img_size($source["image_uri"], 100, 100)) !== false
-    ) :
-    $source_image_uri = $this->path("web").$source["image_uri"];
-    $HAS_IMAGE = true;
+    if($source["reference"]){
+      if
+      (    $source["reference"]["image"]
+        && ($img_size = $data->img_size($source["reference"]["image"], 100, 100)) !== false
+      ){
+        $HAS_IMAGE = true;
+        $source_image_uri = $source["reference"]["image"];
+      }
+    }
+    else{
+      if
+      (    $source["image_uri"]
+        && file_exists($source["image_uri"])
+        && ($img_size = $data->img_size($source["image_uri"], 100, 100)) !== false
+      ){
+        $HAS_IMAGE = true;
+        $source_image_uri = $this->path("web").$source["image_uri"];
+      }
+    }
+    if($HAS_IMAGE) :
 
   ?>
   <p class="logo_source">