supprimer_images(); $this->supprimer_documents(); parent::delete(); } //mots-clefs public function clefs(){ $t = $this->sql->select("articles_clefs","motclef","id_article = '{$this->id}'"); return $t; } public function associer_clefs($clefs){ $this->sql->delete("articles_clefs","id_article = '{$this->id}'"); $t = explode(",",$clefs); $t = array_map("trim",$t); foreach($t as $clef){ $this->sql->insert("articles_clefs","id_article='{$this->id}',motclef='$clef'"); } } public function supprimer_clefs(){ $this->sql->delete("articles_clefs","id_article = '{$this->id}'"); } //images public function images(){ $t = $this->sql->select('images', 'id_image,titre,type,fichier', "id_article = '{$this->id}'" ); return $t; } public function associer_image($type,$titre,$nom_temp){ $this->sql->insert("images","type = '$type', titre = '$titre', id_article = '{$this->id}'"); $id_ima = $this->sql->insert_id(); $lien = $this->sql->escape("article{$this->id}-image$id_ima.$type"); $this->sql->update("images","fichier='$lien'","id_image='$id_ima'"); $rep = IMG_DIR."/$type/"; $emplacement = $rep.$lien; $b = move_uploaded_file($nom_temp,$emplacement); return $b; } public function supprimer_image($id_ima){ $donnees_ima = $this->sql->select_one('images','fichier,type',"id_image= '$id_ima'"); $fichier = $donnees_ima['fichier']; $type = $donnees_ima['type']; @unlink(IMG_DIR."/$type/$fichier"); $this->sql->delete('images',"id_image = '$id_ima'"); } public function supprimer_images(){ $tab_ima = $this->images(); foreach($tab_ima as $ima){ $fichier = $ima['fichier']; $type = $ima['type']; @unlink(IMG_DIR."/$type/$fichier"); } // les lignes de la table 'images' seront supprimées par cascade } //documents public function documents($limite=0){ $nombre = ($limite != 0) ? " LIMIT $limite" : ""; $t = $this->sql->select('documents as d,documents_articles as da', 'd.id_document,d.titre,d.type,d.fichier,da.ordre', "da.id_article = '{$this->id}' AND d.id_document = da.id_document AND da.ordre != 0", "da.ordre ASC".$nombre ); $n = $limite - count($t); $nombre = ($limite != 0) ? " LIMIT $n" : ""; $u = $this->sql->select('documents as d,documents_articles as da', 'd.id_document,d.titre,d.type,d.fichier,da.ordre', "da.id_article = '{$this->id}' AND d.id_document = da.id_document AND (da.ordre = 0 OR ISNULL(da.ordre))", "da.id_document ASC".$nombre ); return array_merge($t,$u); } public function associer_document($titre,$nom_court,$nom_temp,$option=''){ $type = $this->type_fichier($nom_court); $doc = new Document($this->sql); $doc->type = $type; $doc->titre = $titre; $doc->parent = 'article'; $doc->id_parent = $this->id; $b = $doc->save($nom_temp,$option); return $b; } public function supprimer_documents(){ $tab_doc = $this->documents(); foreach($tab_doc as $row){ $id_doc = $row['id_document']; $doc = new Document($this->sql,$id_doc); $doc->delete(); } } //vidéos public function videos(){ $t = $this->sql->select('videos as v JOIN videos_articles as va ON v.id_video = va.id_video', 'v.id_video,v.titre,v.type,v.fichier', "va.id_article = '{$this->id}'" ); return $t; } public function associer_video($type,$titre,$nom_temp,$option=''){ $this->sql->insert("videos","type = '$type', titre = '$titre'"); $id_doc = $this->sql->insert_id(); $lien = $this->sql->escape("article{$this->id}-video$id_doc.$type"); $this->sql->update("videos","fichier = '$lien'","id_video = '$id_doc'"); $rep = VIDEO_DIR."/$type/"; $emplacement = $rep.$lien; if($option == ''){ $b = move_uploaded_file($nom_temp,$emplacement); } elseif($option == 'local'){ $b = copy($nom_temp,$emplacement); } $this->sql->insert("videos_articles","id_video = '$id_doc', id_article = '{$this->id}'"); return $b; } public function supprimer_video($id_vid){ $donnees_vid = $this->sql->select_one('videos','fichier,type',"id_video = '$id_vid'"); $fichier = $donnees_vid['fichier']; $type = $donnees_vid['type']; @unlink(VIDEO_DIR."/$type/$fichier"); $this->sql->delete('videos',"id_video = '$id_vid'"); } // VUE public function view($g="",$param=""){ $v = parent::view($g,$param); if($this->latex()){ $v->mathjax(); } return $v; } // formater le texte pour envoi vers le moteur de rendu public function latex(){ return substr($this->texte,0,7) == ""; } public function formater(){ $texte = $this->texte; if($texte !== null && $this->latex()){ $texte = substr($texte,7); } $doc = $this->documents(); $img = $this->images(); return $this->traitement_typo($texte,$doc,$img); } } ?>