--- a/web/wp-content/themes/IRI-Theme/functions.php Tue Jan 05 09:59:49 2010 +0000
+++ b/web/wp-content/themes/IRI-Theme/functions.php Mon Feb 01 09:51:57 2010 +0000
@@ -1,5 +1,9 @@
<?php
+require( "lib/zip.lib.php" ) ; //indiquez le chemin d'accès à la lib
+
+//error_reporting(E_ALL);
+
function getPost($post = NULL) {
include('post.php');
}
@@ -62,64 +66,218 @@
);
}
-
-
# Displays a list of categories
-function cy_list_categories($Eparam='') {
+function dp_list_categories($Eparam='') {
$categories = get_categories('hide_empty=1'.$Eparam);
- $first = true; $count = 0;
+ $first = true;
+ $count = 0;
+
foreach ($categories as $category) {
- $count++; if ($count>6) break; // limit to 5
+
if ($category->parent<1) {
- if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
+
+ echo ('<li class="menu-h-li">');
+ echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' </a>');
+ echo '<ul>';
- echo ('<li '.$f.'>');
- echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' '.$raquo.'</a>');
-
+ $category_posts = get_posts('numberposts=15&category='.$category->cat_ID);
+ $count2=0;
+ //echo("<!-- ".sizeof($category_posts)." -->");
+ foreach($category_posts as $post) {
+
+ echo '<li class="menu-h-li2" title="'.cache_cutter($post->post_title).'"><a href="'.$post->guid.'">'.text_cutter($post->post_title,200).'</a></li>';
+ //echo '<li class="menu-h-li2" title="'.$count2.'"><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
+ $count2++; //if ($count2>6) break;
+ };
+ echo "</ul></li>";
- echo '<ul>';
- $category_posts=get_posts('category='.$category->cat_ID);
- $count2=0;
- foreach($category_posts as $post) {
- $count2++; if ($count2>6) break;
- echo '<li><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
- };
- echo "</ul></li>";
+ }
+ $count++; //if ($count>6) break; // limit to 5
+
+ }
+}
+
+# Display the list of movies
+function listeMyLdt(){
+
+ $MyLdtDataBase = "lignesIRI";
+ $MyWPDataBase = "wordpress";
+ $MyLdtTable = "Lignes";
+ $MyLdtconnexion = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
+ $MyLdtListe = "";
+ //$WP_db_selected = mysql_select_db();
+
+ if (!$MyLdtconnexion) {
+ echo "Impossible de se connecter à la base de données : " . mysql_error();
+ exit;
+ }
+
+ if (!mysql_select_db($MyLdtDataBase)) {
+ echo "Impossible de sélectionner la base mydbname : " . mysql_error();
+ exit;
+ }
+
+ $MyLdtSql = "SELECT * FROM ".$MyLdtTable."";// WHERE `NomFichier` NOT LIKE ''";
+
+ $result = mysql_query($MyLdtSql);
+
+ if (!$result) {
+ echo "Impossible d'exécuter la requête ($MyLdtSql) dans la base : " . mysql_error();
+ exit;
+ }
+ if (mysql_num_rows($result) == 0) {
+ echo "Aucune ligne trouvée, rien à afficher.";
+ exit;
+ }
+ $MyLdtTable="";
+ while ($row = mysql_fetch_assoc($result)) {
+ $MyLdtLineTemplate = "<tr class='rollover'>
+ <td>".$row['Auteur']."</td> <td>".$row['Titre']."</td> <td>".$row['Contributeur']."</td> ";
+
+ if ($row['NomFichier']!="") {
+ $MyLdtLineTemplate .= "<td> <a href='?URL=".$row['NomFichier']."' nicetitle='Cliquez ici pour télécharger le projet".$row['NomFichier']."'> <img src='".get_bloginfo('stylesheet_directory')."/images/get.png'/> </a> </td> </tr>";
+ }else {
+ $MyLdtLineTemplate .= "<td> <a href='#' nicetitle='Fichier non disponible'> <img src='".get_bloginfo('stylesheet_directory')."/images/help.png'/> </a> </td> </tr>";
+ }
+
+ $MyLdtTable .= $MyLdtLineTemplate."\n";
+
+ }
+
+ // tableau
+ $MyLdtOutPut = "
+ <div class='box'>
+ <table style='width:100%;'>
+ <thead>
+ <tr>
+ <td class='thead'> <b>Auteur</b></td>
+ <td class='thead'> <b>Titre</b> </td>
+ <td class='thead'> <b>Contributeur(s)</b> </td>
+ <td class='thead'> </td>
+ </tr>
+ </thead>
+ ".$MyLdtTable."
+ </table></div>";
+
+ echo($MyLdtOutPut);
+
+ mysql_free_result($result);
+ mysql_select_db($MyWPDataBase);
+ //mysql_select_db($WP_db_selected);
+}
+
+# Create the LDT's ZIP to download IT
+function createMyLdtProject($fichierIRI){
+
+ $MyRoot = "/iridata/users/hurons/public_html/DOCUMENT/_LDT";
+ $MyRootRel = "non-classe/telecharger/?URL=DOCUMENT/_LDT";
+ $MyCache = "/CACHE";
+ $MyExemple = "/EXEMPLE_zip";
+ $MyPattern = "X_NOMPROJET_X";
+ $MyLdtName = "projet_".$MyPattern.".ldt";
+ $MyReadMeName="LISEZ_MOI_READ_ME.txt";
+ $MySoundExt = "_audio.xml";
+ $Return = "";
+
+ $end = strrpos($fichierIRI,".");
+ $FileName = substr($fichierIRI, 0, $end);
+ $ext = substr($fichierIRI, $end, strlen($FileName));
+
+
+ // cette fontion n'est utilisé que sur les .IRI
+ if ($ext==".iri"){
+
+ // Vérifie si le cache éxiste déja
+ if (file_exists($MyCache."/".$FileName.".zip")){
+ //echo ($MyCache.$FileName.".zip"." is in cache");
+ // ensuite envoyer vers la redirection.
+ redirectionDWL($MyRootRel.$MyCache."/".$FileName.".zip");
+ } else {
+
+ echo ("Le fichier ".$FileName.".zip est en cours de compression, veuillez patientez un instant.");
+
+ // Créer le .LDT à partir de l'exemple
+ $MyLdtExemple = implode(file($MyRoot.$MyExemple."/".$MyLdtName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
+ $MyFuturLdt = str_replace($MyPattern, $FileName, $MyLdtExemple);
+
+ // Créer le read me
+ $MyReadMeExemple = implode(file($MyRoot.$MyExemple."/".$MyPattern."/".$MyReadMeName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
+ $MyFuturReadMe = str_replace($MyPattern, $FileName, $MyReadMeExemple);
+
+ // ZIP l'ensemble est met dans le cache
+ $Zipfilename = $MyRoot.$MyCache."/".$FileName.".zip";
+ $zip = new ZipArchive();
+ if ($zip->open($Zipfilename, ZIPARCHIVE::CREATE)!==TRUE) {
+ exit("Impossible d'ouvrir <$filename>\n");
+ }
+ // ZIP - ajouter le .LDT
+ $MyLdtNewName = str_replace($MyPattern, $FileName, $MyLdtName);
+ $zip->addFromString($MyLdtNewName, $MyFuturLdt); //$zip->addFile($MyFuturLdtName, $FileName);
+ // ZIP - ajouter le .IRI
+ $zip->addFile($MyRoot."/".$fichierIRI, $FileName."/".$fichierIRI);
+ // ZIP - ajouter le ReadMe
+ $zip->addFromString($FileName."/".$MyReadMeName, $MyFuturReadMe); //$zip->addFile($MyRoot.$MyTemp."/".$FileName."/".$MyReadMeName, $FileName."/".$MyReadMeName);
+ // ZIP - ajouter le audio si il y a
+ $fileAudio = $MyRoot."/".$FileName.$MySoundExt ;
+ if (file_exists($fileAudio)){
+ $zip->addFile($fileAudio, $FileName."/".$FileName.$MySoundExt);
+ }
+ $zip->close();
+
+ // mettre a jour la bdd ? pour vider le cache quand c'est un nouveau fichier ?
+
+ // ensuite envoyer vers la redirection.
+ redirectionDWL($MyRootRel.$MyCache."/".$FileName.".zip");
}
}
}
-# Displays a list of categories
-function dp_list_categories($Eparam='') {
+# Javascript DWL redirection
+function redirectionDWL ($url) {
+
+ $URL = get_bloginfo('url')."/".$url;
+
+ echo("Le téléchargement est en cours... <br/>\n
+ Si le téléchargement ne démarre pas automatiquement, veuillez cliquez <a href=".$URL.">ici</a>.<br/>\n");
+
+ echo("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ echo(" <!--\n");
+ echo(" document.location.href = \"".$URL."\";\n ");
+ echo(" window.location = \"".$URL."\";\n ");
+ echo(" //-->\n");
+ echo("</script>\n");
+
+}
- $categories = get_categories('hide_empty=1'.$Eparam);
- $first = true; $count = 0;
- foreach ($categories as $category) {
- $count++; if ($count>6) break; // limit to 5
- if ($category->parent<1) {
- // if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
-
- echo ('<li class="menu-h-li">');
- echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' '.$raquo.'</a>');
-
-
- echo '<ul>';
- $category_posts=get_posts('category='.$category->cat_ID);
- $count2=0;
- foreach($category_posts as $post) {
- $count2++; if ($count2>6) break;
- echo '<li class="menu-h-li2"><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
- };
- echo "</ul></li>";
-
-
+# Text cutter
+function text_cutter($text,$length){
+ $symbole="<!-- cut -->";
+
+ $lastpos = strrpos($text,$symbole);
+
+ if($lastpos!=FALSE){
+
+ return (substr($text, 0, $lastpos));
+
+ } else {
+
+ if(strlen($text)>$length){
+ return (substr($text, 0, $length)."[...]");
+ } else {
+ return ($text);
}
}
}
+# Cache cutter
+function cache_cutter($text){
+ return (str_replace( "<!-- cut -->", "", $text));
+}
+
+
function dp_list_posts($Eparam='') {
$category_posts = get_posts($Eparam);