web/wp-content/themes/IRI-Theme/functions.php
branchwordpress
changeset 123 561aa6d282f6
parent 109 03b0d1493584
child 125 6d47ba214f30
equal deleted inserted replaced
112:fb7cd02b9848 123:561aa6d282f6
     1 <?php
     1 <?php
       
     2 
       
     3 require( "lib/zip.lib.php" ) ; //indiquez le chemin d'accès à la lib
       
     4 
       
     5 //error_reporting(E_ALL);
     2 
     6 
     3 function getPost($post = NULL) {
     7 function getPost($post = NULL) {
     4 	include('post.php');
     8 	include('post.php');
     5 }
     9 }
     6 
    10 
    60           'after_title' => '</h2>',
    64           'after_title' => '</h2>',
    61         )
    65         )
    62     );   
    66     );   
    63 }
    67 }
    64 
    68 
    65 
       
    66 
       
    67 # Displays a list of categories
       
    68 function cy_list_categories($Eparam='') {
       
    69 
       
    70 	$categories = get_categories('hide_empty=1'.$Eparam);
       
    71 	$first = true; $count = 0;
       
    72 	foreach ($categories as $category) {
       
    73 		$count++; if ($count>6) break; // limit to 5
       
    74 		if ($category->parent<1) {
       
    75 			if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
       
    76 			
       
    77 			echo ('<li '.$f.'>');
       
    78 			echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' '.$raquo.'</a>');
       
    79 			
       
    80 			
       
    81 				echo '<ul>';
       
    82 				 $category_posts=get_posts('category='.$category->cat_ID);
       
    83 				 $count2=0;
       
    84 					foreach($category_posts as $post) {
       
    85 						$count2++; if ($count2>6) break;
       
    86 						echo '<li><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
       
    87 					};
       
    88                 echo "</ul></li>";
       
    89 
       
    90 			
       
    91 		}
       
    92 	}
       
    93 }
       
    94 
       
    95 # Displays a list of categories
    69 # Displays a list of categories
    96 function dp_list_categories($Eparam='') {
    70 function dp_list_categories($Eparam='') {
    97 
    71 
    98 	$categories = get_categories('hide_empty=1'.$Eparam);
    72 	$categories = get_categories('hide_empty=1'.$Eparam);
    99 	$first = true; $count = 0;
    73 	$first = true;
       
    74 	$count = 0;
       
    75 	
   100 	foreach ($categories as $category) {
    76 	foreach ($categories as $category) {
   101 		$count++; if ($count>6) break; // limit to 5
    77 
   102 		if ($category->parent<1) {
    78 		if ($category->parent<1) {
   103 			// if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
    79 						
   104 			
       
   105 			echo ('<li class="menu-h-li">');
    80 			echo ('<li class="menu-h-li">');
   106 			echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' '.$raquo.'</a>');
    81 			echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' </a>');
   107 			
    82 			echo '<ul>';
   108 			
    83 			
   109 				echo '<ul>';
    84 			$category_posts = get_posts('numberposts=15&category='.$category->cat_ID);
   110 				 $category_posts=get_posts('category='.$category->cat_ID);
    85 			$count2=0;
   111 				 $count2=0;
    86 				 //echo("<!-- ".sizeof($category_posts)." -->");
   112 					foreach($category_posts as $post) {
    87 					foreach($category_posts as $post) {
   113 						$count2++; if ($count2>6) break;
    88 						
   114 						echo '<li class="menu-h-li2"><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
    89 						echo '<li class="menu-h-li2" title="'.cache_cutter($post->post_title).'"><a href="'.$post->guid.'">'.text_cutter($post->post_title,200).'</a></li>';
       
    90 						//echo '<li class="menu-h-li2" title="'.$count2.'"><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
       
    91 						$count2++; //if ($count2>6) break;
   115 					};
    92 					};
   116                 echo "</ul></li>";
    93 				echo "</ul></li>";
   117 
       
   118 			
    94 			
   119 		}
    95 		}
   120 	}
    96 		$count++; //if ($count>6) break; // limit to 5
   121 }
    97 		
       
    98 	}
       
    99 }
       
   100 
       
   101 # Display the list of movies
       
   102 function listeMyLdt(){
       
   103 
       
   104 	$MyLdtDataBase 	= "lignesIRI";
       
   105 	$MyWPDataBase 	= "wordpress";
       
   106 	$MyLdtTable 	= "Lignes";
       
   107 	$MyLdtconnexion = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
       
   108 	$MyLdtListe		= "";
       
   109 	//$WP_db_selected    = mysql_select_db();
       
   110 	
       
   111 	if (!$MyLdtconnexion) {
       
   112 	   echo "Impossible de se connecter à la base de données : " . mysql_error();
       
   113 	   exit;
       
   114 	}
       
   115 
       
   116 	if (!mysql_select_db($MyLdtDataBase)) {
       
   117 	   echo "Impossible de sélectionner la base mydbname : " . mysql_error();
       
   118 	   exit;
       
   119 	}
       
   120 
       
   121 	$MyLdtSql = "SELECT * FROM  ".$MyLdtTable."";// WHERE `NomFichier` NOT LIKE ''";
       
   122 
       
   123 	$result = mysql_query($MyLdtSql);
       
   124 
       
   125 	if (!$result) {
       
   126 	   echo "Impossible d'exécuter la requête ($MyLdtSql) dans la base : " . mysql_error();
       
   127 	   exit;
       
   128 	}
       
   129 
       
   130 	if (mysql_num_rows($result) == 0) {
       
   131 	   echo "Aucune ligne trouvée, rien à afficher.";
       
   132 	   exit;
       
   133 	}
       
   134 	$MyLdtTable="";
       
   135 	while ($row = mysql_fetch_assoc($result)) {
       
   136 	   $MyLdtLineTemplate = "<tr class='rollover'>
       
   137 							 <td>".$row['Auteur']."</td> <td>".$row['Titre']."</td>  <td>".$row['Contributeur']."</td> ";
       
   138 							 
       
   139 		if ($row['NomFichier']!="") {
       
   140 			$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>";
       
   141 		}else {
       
   142 			$MyLdtLineTemplate .= "<td> <a href='#' nicetitle='Fichier non disponible'> <img src='".get_bloginfo('stylesheet_directory')."/images/help.png'/> </a> </td> </tr>";
       
   143 		}
       
   144 		
       
   145 	   $MyLdtTable .=  $MyLdtLineTemplate."\n";
       
   146 	   
       
   147 	}
       
   148 	
       
   149 	//  tableau
       
   150 	$MyLdtOutPut = "
       
   151 	<div class='box'>
       
   152 		<table style='width:100%;'>
       
   153 			<thead>
       
   154 				<tr>
       
   155 					<td class='thead'> <b>Auteur</b></td>
       
   156 					<td class='thead'> <b>Titre</b> </td>
       
   157 					<td class='thead'> <b>Contributeur(s)</b> </td>
       
   158 					<td class='thead'> </td>
       
   159 				</tr> 
       
   160 			</thead>
       
   161 			".$MyLdtTable."
       
   162 		</table></div>";
       
   163 	
       
   164 	echo($MyLdtOutPut);
       
   165 	
       
   166 	mysql_free_result($result);
       
   167 	mysql_select_db($MyWPDataBase);
       
   168 	//mysql_select_db($WP_db_selected);
       
   169 }
       
   170 
       
   171 # Create the  LDT's ZIP to download IT 
       
   172 function createMyLdtProject($fichierIRI){
       
   173 
       
   174 	$MyRoot   	= "/iridata/users/hurons/public_html/DOCUMENT/_LDT";
       
   175 	$MyRootRel  = "non-classe/telecharger/?URL=DOCUMENT/_LDT";
       
   176 	$MyCache	= "/CACHE";
       
   177 	$MyExemple 	= "/EXEMPLE_zip";
       
   178 	$MyPattern  = "X_NOMPROJET_X";
       
   179 	$MyLdtName 	= "projet_".$MyPattern.".ldt";
       
   180 	$MyReadMeName="LISEZ_MOI_READ_ME.txt";
       
   181 	$MySoundExt = "_audio.xml";
       
   182 	$Return 	= "";
       
   183 	
       
   184 	$end 		= strrpos($fichierIRI,"."); 
       
   185 	$FileName	= substr($fichierIRI, 0, $end);
       
   186 	$ext		= substr($fichierIRI, $end, strlen($FileName));
       
   187 	
       
   188 	
       
   189 	// cette fontion n'est utilisé que sur les .IRI
       
   190 	if ($ext==".iri"){
       
   191 	
       
   192 		// Vérifie si le cache éxiste déja
       
   193 		if (file_exists($MyCache."/".$FileName.".zip")){
       
   194 			//echo ($MyCache.$FileName.".zip"." is in cache");
       
   195 			// ensuite envoyer vers la redirection.
       
   196 			redirectionDWL($MyRootRel.$MyCache."/".$FileName.".zip");
       
   197 			
       
   198 		} else {
       
   199 		
       
   200 			echo ("Le fichier ".$FileName.".zip est en cours de compression, veuillez patientez un instant.");
       
   201 					
       
   202 			// Créer le .LDT à partir de l'exemple
       
   203 			$MyLdtExemple = implode(file($MyRoot.$MyExemple."/".$MyLdtName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
       
   204 			$MyFuturLdt = str_replace($MyPattern, $FileName, $MyLdtExemple);
       
   205 		
       
   206 			// Créer le read me 
       
   207 			$MyReadMeExemple = implode(file($MyRoot.$MyExemple."/".$MyPattern."/".$MyReadMeName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
       
   208 			$MyFuturReadMe = str_replace($MyPattern, $FileName, $MyReadMeExemple);
       
   209 			
       
   210 			// ZIP l'ensemble est met dans le cache
       
   211 			$Zipfilename = $MyRoot.$MyCache."/".$FileName.".zip";
       
   212 			$zip = new ZipArchive();
       
   213 			if ($zip->open($Zipfilename, ZIPARCHIVE::CREATE)!==TRUE) {
       
   214 				exit("Impossible d'ouvrir <$filename>\n");
       
   215 			}		
       
   216 			// ZIP - ajouter le .LDT 
       
   217 			$MyLdtNewName = str_replace($MyPattern, $FileName, $MyLdtName);
       
   218 			$zip->addFromString($MyLdtNewName, $MyFuturLdt); //$zip->addFile($MyFuturLdtName, $FileName);
       
   219 			// ZIP - ajouter le .IRI 
       
   220 			$zip->addFile($MyRoot."/".$fichierIRI, $FileName."/".$fichierIRI); 
       
   221 			// ZIP - ajouter le ReadMe
       
   222 			$zip->addFromString($FileName."/".$MyReadMeName, $MyFuturReadMe); //$zip->addFile($MyRoot.$MyTemp."/".$FileName."/".$MyReadMeName, $FileName."/".$MyReadMeName); 
       
   223 			// ZIP - ajouter le audio si il y a 
       
   224 			$fileAudio	= $MyRoot."/".$FileName.$MySoundExt ;
       
   225 			if (file_exists($fileAudio)){
       
   226 				$zip->addFile($fileAudio, $FileName."/".$FileName.$MySoundExt); 
       
   227 			}
       
   228 			$zip->close();
       
   229 			
       
   230 			// mettre a jour la bdd ? pour vider le cache quand c'est un nouveau fichier ? 
       
   231 			
       
   232 			// ensuite envoyer vers la redirection.
       
   233 			redirectionDWL($MyRootRel.$MyCache."/".$FileName.".zip");
       
   234 		}
       
   235 	}
       
   236 }
       
   237 
       
   238 # Javascript DWL redirection 
       
   239 function redirectionDWL ($url) {
       
   240 
       
   241      $URL = get_bloginfo('url')."/".$url; 
       
   242 	 
       
   243 	 echo("Le téléchargement est en cours... <br/>\n
       
   244     Si le téléchargement ne démarre pas automatiquement, veuillez cliquez <a href=".$URL.">ici</a>.<br/>\n");
       
   245 	 
       
   246      echo("<script  language=\"javascript\" type=\"text/javascript\"> \n");
       
   247      echo("     <!--\n");
       
   248      echo("    document.location.href = \"".$URL."\";\n ");
       
   249      echo("    window.location = \"".$URL."\";\n ");
       
   250      echo("     //-->\n");
       
   251      echo("</script>\n");
       
   252 	 
       
   253 }
       
   254 
       
   255 # Text cutter
       
   256 function text_cutter($text,$length){
       
   257 	$symbole="<!-- cut -->";
       
   258 	
       
   259 	$lastpos = strrpos($text,$symbole); 
       
   260 	
       
   261 	if($lastpos!=FALSE){
       
   262 	
       
   263 		return (substr($text, 0, $lastpos));
       
   264 	
       
   265 	} else {
       
   266 	
       
   267 		if(strlen($text)>$length){
       
   268 			return (substr($text, 0, $length)."[...]");
       
   269 		} else {
       
   270 			return ($text);
       
   271 		}
       
   272 	}
       
   273 }
       
   274 
       
   275 # Cache cutter
       
   276 function cache_cutter($text){
       
   277 	return (str_replace( "<!-- cut -->", "", $text));
       
   278 }
       
   279 
   122 
   280 
   123 function dp_list_posts($Eparam='') {
   281 function dp_list_posts($Eparam='') {
   124 
   282 
   125 		$category_posts = get_posts($Eparam);
   283 		$category_posts = get_posts($Eparam);
   126 		
   284