3 class sml_data_sources_xml extends mw_data{
5 public function get_source_xml_from_url($url, $IGNORE_UPDATE = false){
7 if($env->config("cache_actif")) return $this->get_source_xml_from_cache($url, $IGNORE_UPDATE);
8 else return @file_get_contents($url);
11 # ----------------------------------------------------------------------------------------
15 public function set_source_xml($id, $params = array()){
18 if(strlen($id) > 0 && ($fh = @fopen($this->source_xml_path($id), "wb")) !== false){
19 if(($content = $this->source_xml_content($id, $params)) !== false){
20 if(@fwrite($fh, $content)) $OK = true;
27 public function maj_source_xml_groupe($groupe){
29 if($groupe !== false){
30 $sgbd = $this->sgbd();
32 if(($sources = $this->sources(array("id_groupe" => $groupe["id"]))) !== false){
33 foreach($sources["list"] as $id_source => $source){
34 if(!$this->set_source_xml($source["id"], array("source" => $source))){
46 public function maj_source_xml_licence($licence){
48 if($licence !== false){
49 $sgbd = $this->sgbd();
51 if(($sources = $this->sources(array("id_licence" => $licence["id"]))) !== false){
52 foreach($sources["list"] as $id_source => $source){
53 if(!$this->set_source_xml($source["id"], array("source" => $source))){
65 public function maj_source_xml_all(){
67 $sgbd = $this->sgbd();
69 if(($sources = $this->sources(array())) !== false){
70 foreach($sources["list"] as $id_source => $source){
71 if(!$this->set_source_xml($source["id"], array("source" => $source))){
81 public function get_source_xml($id_source){
82 $source_file = $this->source_xml_path($id_source);
83 if(file_exists($source_file)){
84 return @file_get_contents($source_file);
89 public function del_source_xml($id_source){
91 if(file_exists($this->source_xml_path($id_source))){
93 $this->del_edit_derivations(array("id_source" => $id_source))
94 && $this->del_edit_reference_content($id_source)
95 && @unlink($this->source_xml_path($id_source));
100 # ----------------------------------------------------------------------------------------
101 # edition XML derivation
104 public function set_edit_derivation_content($id_source, $id_source_derivation, $content){
106 $derivations_dir = $this->derivations_edit_xml_dir_path();
107 if(!file_exists($derivations_dir) || !is_dir($derivations_dir)) @mkdir($derivations_dir);
108 if(file_exists($derivations_dir) && is_dir($derivations_dir)){
109 $derivations_dir = $this->derivations_edit_xml_dir_path($id_source);
110 if(!file_exists($derivations_dir) || !is_dir($derivations_dir)) @mkdir($derivations_dir);
111 if(file_exists($derivations_dir) && is_dir($derivations_dir)){
112 if($fh = @fopen($this->derivation_edit_xml_path($id_source, $id_source_derivation), "w+")){
113 if(@fwrite($fh, $content)){
124 public function get_edit_derivation_content($id_source, $id_source_derivation){
126 $derivation_file = $this->derivation_edit_xml_path($id_source, $id_source_derivation);
127 $derivation_content = "";
128 if(file_exists($derivation_file)){
129 $derivation_content = @file_get_contents($derivation_file);
131 return $derivation_content;
134 public function del_edit_derivation_content($id_source, $id_source_derivation){
136 $derivation_file = $this->derivation_edit_xml_path($id_source, $id_source_derivation);
138 if(file_exists($derivation_file)){
139 $OK = @unlink($derivation_file);
144 public function del_edit_derivations($id_source){
146 $derivations_dir = $this->derivations_edit_xml_dir_path($id_source);
148 if(is_dir($derivations_dir)){
149 if($dh = opendir($derivations_dir)){
150 while($OK && (($file = readdir($dh)) !== false)){
151 if(preg_match("/^.+\.xml$/", $file)){
152 $OK = @unlink($derivations_dir.$file) && $OK;
156 // $OK = @rmdir($derivations_dir) && $OK;
157 @rmdir($derivations_dir);
164 # ----------------------------------------------------------------------------------------
165 # edition XML reference
168 public function set_edit_reference_content($id_source, $content){
170 $references_dir = $this->reference_edit_xml_dir_path();
171 if(!file_exists($references_dir) || !is_dir($references_dir)) @mkdir($references_dir);
172 if(file_exists($references_dir) && is_dir($references_dir)){
173 if($fh = @fopen($this->reference_edit_xml_path($id_source), "w+")){
174 if(@fwrite($fh, $content)){
184 public function get_edit_reference_content($id_source){
186 $reference_file = $this->reference_edit_xml_path($id_source);
187 $reference_content = "";
188 if(file_exists($reference_file)){
189 $reference_content = @file_get_contents($reference_file);
191 return $reference_content;
194 public function del_edit_reference_content($id_source){
196 $reference_file = $this->reference_edit_xml_path($id_source);
198 if(file_exists($reference_file)){
199 $OK = @unlink($reference_file);