|
1 <?php |
|
2 /** |
|
3 * @package WP-ldt-downloader |
|
4 * @author Samuel Huron |
|
5 * @version 0.1 |
|
6 */ |
|
7 /* |
|
8 Plugin Name: WP-ldt-downloader |
|
9 Plugin URI: http://www.iri.centrepompidou.fr |
|
10 Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page. |
|
11 Author: Samuel Huron |
|
12 Version: 0.1 |
|
13 Author URI: http://www.cybunk.com |
|
14 */ |
|
15 |
|
16 // replace tag in content with tag cloud (non-shortcode version for WP 2.3.x) |
|
17 function WP-ldt-downloader_init($content){ |
|
18 if( strpos($content, '[WP-LDT-DWL]') === false ){ |
|
19 return $content; |
|
20 } else { |
|
21 $code = WP-ldt-Template-Liste(); |
|
22 $content = str_replace( '[WP-LDT-DWL]', $code, $content ); |
|
23 return $content; |
|
24 } |
|
25 } |
|
26 |
|
27 function WP-ldt-Template-Liste(){ |
|
28 |
|
29 // HTML TR |
|
30 $MyLdtLineTemplate = "<tr> |
|
31 <td>"."X_row['Auteur']_X"."</td> |
|
32 <td>"."X_row['Titre']_X"."</td> |
|
33 <td>"."X_row['Fond']_X"."</td> |
|
34 <td> <a href='?URL="."X_row['NomFichier']_X"."' nicetitle='Cliquez ici pour télécharger le projet"."X_row['NomFichier']_X"."'> |
|
35 <img src='".get_bloginfo('stylesheet_directory')."/images/get.png'/> </a> </td> |
|
36 </tr>"; |
|
37 |
|
38 |
|
39 // GET the DB informations |
|
40 $MyListe = listeMyLdt($MyLdtLineTemplate); |
|
41 |
|
42 // HTML table |
|
43 $MyLdtOutPut = " |
|
44 <div class='box'> |
|
45 <table style='width:100%;'> |
|
46 <thead> |
|
47 <tr> |
|
48 <td class='thead'> <b>Auteur</b></td> |
|
49 <td class='thead'> <b>Titre</b> </td> |
|
50 <td class='thead'> <b>Fond</b> </td> |
|
51 <td class='thead'> </td> |
|
52 </tr> |
|
53 </thead> |
|
54 ".$MyListe." |
|
55 </table></div>"; |
|
56 |
|
57 echo ($MyLdtOutPut); |
|
58 |
|
59 } |
|
60 |
|
61 function WP-ldt-downloader(){ |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 } |
|
68 |
|
69 # Display the list of movies |
|
70 function WP-ldt-listeMyLdt($template){ |
|
71 |
|
72 $MyLdtDataBase = "lignesIRI"; |
|
73 $MyLdtTable = "Lignes"; |
|
74 $MyLdtconnexion = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); |
|
75 $MyLdtListe = ""; |
|
76 //$WP_db_selected = mysql_select_db(); |
|
77 |
|
78 if (!$MyLdtconnexion) { |
|
79 echo "Impossible de se connecter à la base de données : " . mysql_error(); |
|
80 exit; |
|
81 } |
|
82 |
|
83 if (!mysql_select_db($MyLdtDataBase)) { |
|
84 echo "Impossible de sélectionner la base mydbname : " . mysql_error(); |
|
85 exit; |
|
86 } |
|
87 |
|
88 $MyLdtSql = "SELECT * FROM ".$MyLdtTable." WHERE `NomFichier` NOT LIKE ''"; |
|
89 |
|
90 $result = mysql_query($MyLdtSql); |
|
91 |
|
92 if (!$result) { |
|
93 echo "Impossible d'exécuter la requête ($MyLdtSql) dans la base : " . mysql_error(); |
|
94 exit; |
|
95 } |
|
96 |
|
97 if (mysql_num_rows($result) == 0) { |
|
98 echo "Aucune ligne trouvée, rien à afficher."; |
|
99 exit; |
|
100 } |
|
101 |
|
102 $MyLdtTable=""; |
|
103 |
|
104 while ($row = mysql_fetch_assoc($result)) { |
|
105 $MyLdtLineTemplate = str_replace( "X_row['Auteur']_X", $row['Auteur'], $template ); |
|
106 $MyLdtLineTemplate = str_replace( "X_row['Auteur']_X", $row['Titre'], $MyLdtLineTemplate ); |
|
107 $MyLdtLineTemplate = str_replace( "X_row['Auteur']_X", $row['Fond'], $MyLdtLineTemplate ); |
|
108 $MyLdtLineTemplate = str_replace( "X_row['Auteur']_X", $row['NomFichier'], $MyLdtLineTemplate ); |
|
109 /* |
|
110 "<tr onClick='?URL=".$row['NomFichier']."'> |
|
111 <td>".$row['Auteur']."</td> <td>".$row['Titre']."</td> <td>".$row['Fond']."</td> |
|
112 <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>"; |
|
113 */ |
|
114 $MyLdtTable .= $MyLdtLineTemplate."\n"; |
|
115 |
|
116 } |
|
117 |
|
118 return ($MyLdtTable); |
|
119 |
|
120 mysql_free_result($result); |
|
121 //mysql_select_db($WP_db_selected); |
|
122 } |
|
123 |
|
124 # Create the LDT's ZIP to download IT |
|
125 function WP-ldt-createMyLdtProject($fichierIRI){ |
|
126 |
|
127 $MyRoot = "/iridata/users/hurons/public_html/DOCUMENT/_LDT"; |
|
128 $MyRootRel = "non-classe/telecharger/?URL=DOCUMENT/_LDT"; |
|
129 $MyCache = "/CACHE"; |
|
130 $MyExemple = "/EXEMPLE_zip"; |
|
131 $MyPattern = "X_NOMPROJET_X"; |
|
132 $MyLdtName = "projet_".$MyPattern.".ldt"; |
|
133 $MyReadMeName="LISEZ_MOI_READ_ME.txt"; |
|
134 $MySoundExt = "_audio.xml"; |
|
135 $Return = ""; |
|
136 |
|
137 $end = strrpos($fichierIRI,"."); |
|
138 $FileName = substr($fichierIRI, 0, $end); |
|
139 $ext = substr($fichierIRI, $end, strlen($FileName)); |
|
140 |
|
141 |
|
142 // cette fontion n'est utilisé que sur les .IRI |
|
143 if ($ext==".iri"){ |
|
144 |
|
145 // Vérifie si le cache éxiste déja |
|
146 if (file_exists($MyCache."/".$FileName.".zip")){ |
|
147 //echo ($MyCache.$FileName.".zip"." is in cache"); |
|
148 // ensuite envoyer vers la redirection. |
|
149 redirectionDWL($MyRootRel.$MyCache."/".$FileName.".zip"); |
|
150 |
|
151 } else { |
|
152 |
|
153 echo ("Le fichier ".$FileName.".zip est en cours de compression, veuillez patientez un instant."); |
|
154 |
|
155 // Créer le .LDT à partir de l'exemple |
|
156 $MyLdtExemple = implode(file($MyRoot.$MyExemple."/".$MyLdtName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); |
|
157 $MyFuturLdt = str_replace($MyPattern, $FileName, $MyLdtExemple); |
|
158 |
|
159 // Créer le read me |
|
160 $MyReadMeExemple = implode(file($MyRoot.$MyExemple."/".$MyPattern."/".$MyReadMeName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); |
|
161 $MyFuturReadMe = str_replace($MyPattern, $FileName, $MyReadMeExemple); |
|
162 |
|
163 // ZIP l'ensemble est met dans le cache |
|
164 $Zipfilename = $MyRoot.$MyCache."/".$FileName.".zip"; |
|
165 $zip = new ZipArchive(); |
|
166 if ($zip->open($Zipfilename, ZIPARCHIVE::CREATE)!==TRUE) { |
|
167 exit("Impossible d'ouvrir <$filename>\n"); |
|
168 } |
|
169 // ZIP - ajouter le .LDT |
|
170 $MyLdtNewName = str_replace($MyPattern, $FileName, $MyLdtName); |
|
171 $zip->addFromString($MyLdtNewName, $MyFuturLdt); //$zip->addFile($MyFuturLdtName, $FileName); |
|
172 // ZIP - ajouter le .IRI |
|
173 $zip->addFile($MyRoot."/".$fichierIRI, $FileName."/".$fichierIRI); |
|
174 // ZIP - ajouter le ReadMe |
|
175 $zip->addFromString($FileName."/".$MyReadMeName, $MyFuturReadMe); //$zip->addFile($MyRoot.$MyTemp."/".$FileName."/".$MyReadMeName, $FileName."/".$MyReadMeName); |
|
176 // ZIP - ajouter le audio si il y a |
|
177 $fileAudio = $MyRoot."/".$FileName.$MySoundExt ; |
|
178 if (file_exists($fileAudio)){ |
|
179 $zip->addFile($fileAudio, $FileName."/".$FileName.$MySoundExt); |
|
180 } |
|
181 $zip->close(); |
|
182 |
|
183 // mettre a jour la bdd ? pour vider le cache quand c'est un nouveau fichier ? |
|
184 |
|
185 // ensuite envoyer vers la redirection. |
|
186 redirectionDWL($MyRootRel.$MyCache."/".$FileName.".zip"); |
|
187 } |
|
188 } |
|
189 } |
|
190 |
|
191 # Javascript DWL redirection |
|
192 function WP-ldt-redirectionDWL ($url) { |
|
193 |
|
194 $URL = get_bloginfo('url')."/".$url; |
|
195 |
|
196 echo("Le téléchargement est en cours... <br/>\n |
|
197 Si le téléchargement ne démarre pas automatiquement, veuillez cliquez <a href=".$URL.">ici</a>.<br/>\n"); |
|
198 |
|
199 echo("<script language=\"javascript\" type=\"text/javascript\"> \n"); |
|
200 echo(" <!--\n"); |
|
201 echo(" document.location.href = \"".$URL."\";\n "); |
|
202 echo(" window.location = \"".$URL."\";\n "); |
|
203 echo(" //-->\n"); |
|
204 echo("</script>\n"); |
|
205 |
|
206 } |
|
207 |
|
208 |
|
209 //______________________ |
|
210 |
|
211 |
|
212 |
|
213 function hello_dolly_get_lyric() { |
|
214 /** These are the lyrics to Hello Dolly */ |
|
215 $lyrics = "Hello, Dolly |
|
216 Well, hello, Dolly |
|
217 It's so nice to have you back where you belong |
|
218 You're lookin' swell, Dolly |
|
219 I can tell, Dolly |
|
220 You're still glowin', you're still crowin' |
|
221 You're still goin' strong |
|
222 We feel the room swayin' |
|
223 While the band's playin' |
|
224 One of your old favourite songs from way back when |
|
225 So, take her wrap, fellas |
|
226 Find her an empty lap, fellas |
|
227 Dolly'll never go away again |
|
228 Hello, Dolly |
|
229 Well, hello, Dolly |
|
230 It's so nice to have you back where you belong |
|
231 You're lookin' swell, Dolly |
|
232 I can tell, Dolly |
|
233 You're still glowin', you're still crowin' |
|
234 You're still goin' strong |
|
235 We feel the room swayin' |
|
236 While the band's playin' |
|
237 One of your old favourite songs from way back when |
|
238 Golly, gee, fellas |
|
239 Find her a vacant knee, fellas |
|
240 Dolly'll never go away |
|
241 Dolly'll never go away |
|
242 Dolly'll never go away again"; |
|
243 |
|
244 // Here we split it into lines |
|
245 $lyrics = explode("\n", $lyrics); |
|
246 |
|
247 // And then randomly choose a line |
|
248 return wptexturize( $lyrics[ mt_rand(0, count($lyrics) - 1) ] ); |
|
249 } |
|
250 |
|
251 // This just echoes the chosen line, we'll position it later |
|
252 function hello_dolly() { |
|
253 $chosen = hello_dolly_get_lyric(); |
|
254 echo "<p id='dolly'>$chosen</p>"; |
|
255 } |
|
256 |
|
257 // Now we set that function up to execute when the admin_footer action is called |
|
258 add_action('admin_footer', 'hello_dolly'); |
|
259 |
|
260 // We need some CSS to position the paragraph |
|
261 function dolly_css() { |
|
262 // This makes sure that the posinioning is also good for right-to-left languages |
|
263 $x = ( 'rtl' == get_bloginfo( 'text_direction' ) ) ? 'left' : 'right'; |
|
264 |
|
265 echo " |
|
266 <style type='text/css'> |
|
267 #dolly { |
|
268 position: absolute; |
|
269 top: 4.5em; |
|
270 margin: 0; |
|
271 padding: 0; |
|
272 $x: 215px; |
|
273 font-size: 11px; |
|
274 } |
|
275 </style> |
|
276 "; |
|
277 } |
|
278 |
|
279 add_action('admin_head', 'dolly_css'); |
|
280 |
|
281 ?> |