<?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