author | ymh@caf4f556-3d62-0410-8435-a86758001935 |
Fri, 12 Feb 2010 21:30:10 +0000 | |
changeset 146 | 8d4c66d892cf |
parent 144 | df0ebfb22f63 |
child 170 | 8e3a5a6fc63e |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
||
3 |
require( "lib/zip.lib.php" ) ; //indiquez le chemin d'accès à la lib |
|
4 |
||
5 |
//error_reporting(E_ALL); |
|
6 |
||
7 |
function getPost($post = NULL) { |
|
8 |
include('post.php'); |
|
9 |
} |
|
10 |
||
11 |
function getSearch($q = NULL) { |
|
12 |
include('searchform.php'); |
|
13 |
} |
|
14 |
||
15 |
if ( function_exists('register_sidebar') ) |
|
16 |
{ |
|
17 |
register_sidebar |
|
18 |
( array |
|
19 |
( |
|
20 |
'name' => 'Sidebar-Single', |
|
21 |
'before_widget' => '<div class="bottombar">', |
|
22 |
'after_widget' => '</div>', |
|
23 |
'before_title' => '<h2 class="widgettitle">', |
|
24 |
'after_title' => '</h2>', |
|
25 |
) |
|
26 |
); |
|
27 |
register_sidebar |
|
28 |
( array |
|
29 |
( |
|
30 |
'name' => 'Sidebar-Single-home', |
|
31 |
'before_widget' => '<div class="bottombar">', |
|
32 |
'after_widget' => '</div>', |
|
33 |
'before_title' => '<h2 class="widgettitle">', |
|
34 |
'after_title' => '</h2>', |
|
35 |
) |
|
36 |
); |
|
37 |
register_sidebar |
|
38 |
( array |
|
39 |
( |
|
40 |
'name' => 'Bottom-Left', |
|
41 |
'before_widget' => '<div class="bottombar">', |
|
42 |
'after_widget' => '</div>', |
|
43 |
'before_title' => '<h2 class="widgettitle">', |
|
44 |
'after_title' => '</h2>', |
|
45 |
) |
|
46 |
); |
|
47 |
register_sidebar |
|
48 |
( array |
|
49 |
( |
|
50 |
'name' => 'Bottom-Middle', |
|
51 |
'before_widget' => '<div class="bottombar">', |
|
52 |
'after_widget' => '</div>', |
|
53 |
'before_title' => '<h2 class="widgettitle">', |
|
54 |
'after_title' => '</h2>', |
|
55 |
) |
|
56 |
); |
|
57 |
register_sidebar |
|
58 |
( array |
|
59 |
( |
|
60 |
'name' => 'Bottom-Right', |
|
61 |
'before_widget' => '<div class="bottombar">', |
|
62 |
'after_widget' => '</div>', |
|
63 |
'before_title' => '<h2 class="widgettitle">', |
|
64 |
'after_title' => '</h2>', |
|
65 |
) |
|
66 |
); |
|
67 |
} |
|
68 |
||
69 |
# Displays a list of categories |
|
70 |
function dp_list_categories($Eparam='') { |
|
71 |
||
72 |
$categories = get_categories('hide_empty=1'.$Eparam); |
|
73 |
$first = true; |
|
74 |
$count = 0; |
|
75 |
||
76 |
foreach ($categories as $category) { |
|
77 |
||
78 |
if ($category->parent<1) { |
|
79 |
||
80 |
echo ('<li class="menu-h-li">'); |
|
81 |
echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' </a>'); |
|
82 |
echo '<ul>'; |
|
83 |
||
84 |
||
85 |
$category_posts = get_posts('numberposts=15&category='.$category->cat_ID); |
|
86 |
$count2 = 0; |
|
87 |
//echo("<!-- ".sizeof($category_posts)." -->"); |
|
88 |
foreach($category_posts as $post) { |
|
89 |
||
90 |
echo '<li class="menu-h-li2" title="'.cache_cutter($post->post_title).'"><a href="'.$post->guid.'">'.text_cutter($post->post_title,200).'</a></li>'; |
|
91 |
//echo '<li class="menu-h-li2" title="'.$count2.'"><a href="'.$post->guid.'">'.$post->post_title.'</a></li>'; |
|
92 |
$count2++; //if ($count2>6) break; |
|
93 |
}; |
|
94 |
||
95 |
||
96 |
echo "</ul></li>"; |
|
97 |
||
98 |
} |
|
99 |
$count++; //if ($count>6) break; // limit to 5 |
|
100 |
||
101 |
} |
|
102 |
} |
|
103 |
||
104 |
# Display the list of movies |
|
105 |
function listeMyLdt(){ |
|
106 |
||
142
f6e6b46f8260
Correct iri + missing pdf
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
136
diff
changeset
|
107 |
$MyLdtDataBase = DB_NAME; |
f6e6b46f8260
Correct iri + missing pdf
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
136
diff
changeset
|
108 |
$MyWPDataBase = DB_NAME; |
144
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
109 |
$MyLdtTable = LDT_DB; |
136 | 110 |
$MyLdtconnexion = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); |
111 |
$MyLdtListe = ""; |
|
112 |
//$WP_db_selected = mysql_select_db(); |
|
113 |
||
114 |
if (!$MyLdtconnexion) { |
|
115 |
echo "Impossible de se connecter à la base de données : " . mysql_error(); |
|
116 |
exit; |
|
117 |
} |
|
118 |
||
119 |
if (!mysql_select_db($MyLdtDataBase)) { |
|
120 |
echo "Impossible de sélectionner la base mydbname : " . mysql_error(); |
|
121 |
exit; |
|
122 |
} |
|
123 |
||
124 |
$MyLdtSql = "SELECT * FROM ".$MyLdtTable." ORDER BY `Lignes`.`Auteur` ASC";// WHERE `NomFichier` NOT LIKE ''"; |
|
125 |
||
126 |
$result = mysql_query($MyLdtSql); |
|
127 |
||
128 |
if (!$result) { |
|
129 |
echo "Impossible d'exécuter la requête ($MyLdtSql) dans la base : " . mysql_error(); |
|
130 |
exit; |
|
131 |
} |
|
132 |
||
133 |
if (mysql_num_rows($result) == 0) { |
|
134 |
echo "Aucune ligne trouvée, rien à afficher."; |
|
135 |
exit; |
|
136 |
} |
|
137 |
$MyLdtTable=""; |
|
138 |
while ($row = mysql_fetch_assoc($result)) { |
|
139 |
$MyLdtLineTemplate = "<tr class='rollover'> |
|
140 |
<td>".$row['Auteur']."</td> <td>".$row['Titre']."</td> <td>".$row['Contributeur']."</td> "; |
|
141 |
||
142 |
if ($row['NomFichier']!="") { |
|
143 |
$MyLdtLineTemplate .= "<td> <a href='?URL=".$row['NomFichier']."' title='Cliquez ici pour télécharger le projet".$row['NomFichier']."'> <img src='".get_bloginfo('stylesheet_directory')."/images/get.png'/> </a> </td> </tr>"; |
|
144 |
}else { |
|
145 |
$MyLdtLineTemplate .= "<td> <a href='#' title='Fichier non disponible'> <img src='".get_bloginfo('stylesheet_directory')."/images/help.png'/> </a> </td> </tr>"; |
|
146 |
} |
|
147 |
||
148 |
$MyLdtTable .= $MyLdtLineTemplate."\n"; |
|
149 |
||
150 |
} |
|
151 |
||
152 |
// tableau |
|
153 |
$MyLdtOutPut = " |
|
154 |
<div class='box'> |
|
155 |
<table style='width:100%;'> |
|
156 |
<thead> |
|
157 |
<tr> |
|
158 |
<td class='thead'> <b>Auteur</b></td> |
|
159 |
<td class='thead'> <b>Titre</b> </td> |
|
160 |
<td class='thead'> <b>Contributeur(s)</b> </td> |
|
161 |
<td class='thead'> </td> |
|
162 |
</tr> |
|
163 |
</thead> |
|
164 |
".$MyLdtTable." |
|
165 |
</table></div>"; |
|
166 |
||
167 |
echo($MyLdtOutPut); |
|
168 |
||
169 |
mysql_free_result($result); |
|
170 |
mysql_select_db($MyWPDataBase); |
|
171 |
//mysql_select_db($WP_db_selected); |
|
172 |
} |
|
173 |
||
174 |
# Create the LDT's ZIP to download IT |
|
175 |
function createMyLdtProject($fichierIRI){ |
|
176 |
||
144
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
177 |
$MyLDTRoot = ABSPATH; |
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
178 |
$MyDocPath = LDT_PATH; |
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
179 |
$MyRootRel = DWL_PAGE; |
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
180 |
$MyCache = LDT_CACHE; |
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
181 |
$MyExemple = LDT_TEMPLATE; |
136 | 182 |
$MyPattern = "X_NOMPROJET_X"; |
183 |
$MyLdtName = "projet_".$MyPattern.".ldt"; |
|
184 |
$MyReadMeName="LISEZ_MOI_READ_ME.txt"; |
|
185 |
$MySoundExt = "_audio.xml"; |
|
186 |
$Return = ""; |
|
187 |
||
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
188 |
$end = strrpos($fichierIRI,"."); |
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
189 |
$FileName = substr($fichierIRI, 0, $end); |
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
190 |
$ext = substr($fichierIRI, $end, strlen($FileName)); |
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
191 |
$Zipfilename = $MyLDTRoot.$MyCache."/".$FileName.".zip"; |
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
192 |
$ZipfilenameRedir = $MyRootRel.$MyCache."/".$FileName.".zip"; |
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
193 |
$baseExemplePath = $MyLDTRoot.$MyExemple; |
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
194 |
$baseDocPath = $MyLDTRoot.$MyDocPath; |
136 | 195 |
|
196 |
// cette fontion n'est utilisé que sur les .IRI |
|
197 |
if ($ext==".iri"){ |
|
198 |
||
199 |
// Vérifie si le cache éxiste déja |
|
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
200 |
if (file_exists($Zipfilename)){ |
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
201 |
echo ($Zipfilename." is in cache "); |
136 | 202 |
// ensuite envoyer vers la redirection. |
144
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
203 |
echo ("Veuillez patientez un instant..."); |
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
204 |
redirectionDWL($ZipfilenameRedir); |
136 | 205 |
|
206 |
} else { |
|
207 |
||
144
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
208 |
echo ("Le fichier ".$FileName.".zip est en cours de compression, veuillez patientez un instant..."); |
136 | 209 |
|
210 |
// Créer le .LDT à partir de l'exemple |
|
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
211 |
$MyLdtExemple = implode(file($baseExemplePath."/".$MyLdtName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); |
136 | 212 |
$MyFuturLdt = str_replace($MyPattern, $FileName, $MyLdtExemple); |
213 |
||
214 |
// Créer le read me |
|
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
215 |
$MyReadMeExemple = implode(file($baseExemplePath."/".$MyPattern."/".$MyReadMeName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); |
136 | 216 |
$MyFuturReadMe = str_replace($MyPattern, $FileName, $MyReadMeExemple); |
217 |
||
144
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
218 |
// ZIP l'ensemble est mis dans le cache |
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
219 |
|
136 | 220 |
$zip = new ZipArchive(); |
221 |
if ($zip->open($Zipfilename, ZIPARCHIVE::CREATE)!==TRUE) { |
|
222 |
exit("Impossible d'ouvrir <$filename>\n"); |
|
223 |
} |
|
224 |
// ZIP - ajouter le .LDT |
|
225 |
$MyLdtNewName = str_replace($MyPattern, $FileName, $MyLdtName); |
|
226 |
$zip->addFromString($MyLdtNewName, $MyFuturLdt); //$zip->addFile($MyFuturLdtName, $FileName); |
|
227 |
// ZIP - ajouter le .IRI |
|
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
228 |
$zip->addFile($baseDocPath."/".$fichierIRI, $FileName."/".$fichierIRI); |
136 | 229 |
// ZIP - ajouter le ReadMe |
230 |
$zip->addFromString($FileName."/".$MyReadMeName, $MyFuturReadMe); //$zip->addFile($MyRoot.$MyTemp."/".$FileName."/".$MyReadMeName, $FileName."/".$MyReadMeName); |
|
231 |
// ZIP - ajouter le audio si il y a |
|
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
232 |
$fileAudio = $baseDocPath."/".$FileName.$MySoundExt ; |
136 | 233 |
if (file_exists($fileAudio)){ |
234 |
$zip->addFile($fileAudio, $FileName."/".$FileName.$MySoundExt); |
|
235 |
} |
|
236 |
$zip->close(); |
|
237 |
||
238 |
// mettre a jour la bdd ? pour vider le cache quand c'est un nouveau fichier ? |
|
239 |
||
240 |
// ensuite envoyer vers la redirection. |
|
146
8d4c66d892cf
Correct iri project download
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
144
diff
changeset
|
241 |
redirectionDWL($ZipfilenameRedir); |
144
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
242 |
//echo ('<br/> DWL : '.$FileDWL); |
136 | 243 |
} |
244 |
} |
|
245 |
} |
|
246 |
||
247 |
# Javascript DWL redirection |
|
248 |
function redirectionDWL ($url) { |
|
249 |
||
250 |
$URL = get_bloginfo('url')."/".$url; |
|
251 |
||
252 |
echo("Le téléchargement est en cours... <br/>\n |
|
253 |
Si le téléchargement ne démarre pas automatiquement, veuillez cliquez <a href=".$URL.">ici</a>.<br/>\n"); |
|
254 |
||
255 |
echo("<script language=\"javascript\" type=\"text/javascript\"> \n"); |
|
256 |
echo(" <!--\n"); |
|
144
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
257 |
echo(" jQuery(document).ready(function($) {"); |
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
258 |
echo(" $(location).attr('href','".$URL."');"); |
df0ebfb22f63
- Added Path variable in the config file for the LDT's donwloader script (functions.php)
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
142
diff
changeset
|
259 |
echo(" });"); |
136 | 260 |
echo(" //-->\n"); |
261 |
echo("</script>\n"); |
|
262 |
||
263 |
} |
|
264 |
||
265 |
# Text cutter |
|
266 |
function text_cutter($text,$length){ |
|
267 |
$symbole="<!-- cut -->"; |
|
268 |
||
269 |
$lastpos = strrpos($text,$symbole); |
|
270 |
||
271 |
if($lastpos!=FALSE){ |
|
272 |
||
273 |
return (substr($text, 0, $lastpos)); |
|
274 |
||
275 |
} else { |
|
276 |
||
277 |
if(strlen($text)>$length){ |
|
278 |
return (substr($text, 0, $length)."[...]"); |
|
279 |
} else { |
|
280 |
return ($text); |
|
281 |
} |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
# Cache cutter |
|
286 |
function cache_cutter($text){ |
|
287 |
return (str_replace( "<!-- cut -->", "", $text)); |
|
288 |
} |
|
289 |
||
290 |
||
291 |
function dp_list_posts($Eparam='') { |
|
292 |
||
293 |
$category_posts = get_posts($Eparam); |
|
294 |
||
295 |
foreach($category_posts as $post) { |
|
296 |
echo '<li><a href="'.$post->guid.'">'.$post->post_title.'</a></li>'; |
|
297 |
}; |
|
298 |
} |
|
299 |
||
300 |
||
301 |
/* |
|
302 |
Plugin Name: Get The Image |
|
303 |
Plugin URI: http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin |
|
304 |
Description: This is a highly intuitive script that gets an image either by custom field input or post attachment. |
|
305 |
Version: 0.1 Beta |
|
306 |
Author: Justin Tadlock |
|
307 |
Author URI: http://justintadlock.com |
|
308 |
License: GPL |
|
309 |
*/ |
|
310 |
||
311 |
/*********************************************************** |
|
312 |
Catchall function for getting images |
|
313 |
***********************************************************/ |
|
314 |
function get_the_image($arr = false, $default_size = 'medium', $default_img = false) { |
|
315 |
global $post; |
|
316 |
$cf_array = load_the_image($arr, $post, $default_size); |
|
317 |
$image = display_the_image($cf_array, $post, $default_size, $default_img); |
|
318 |
if($image == false) $image = '<!-- No images were added to this post. -->'; |
|
319 |
return $image; |
|
320 |
} |
|
321 |
||
322 |
/*********************************************************** |
|
323 |
Catchall function for getting images with a link |
|
324 |
***********************************************************/ |
|
325 |
function get_the_image_link($arr = false, $default_size = 'medium', $default_img = false) { |
|
326 |
global $post; |
|
327 |
$cf_array = load_the_image($arr, $post, $default_size); |
|
328 |
$image = display_the_image($cf_array, $post, $default_size, $default_img); |
|
329 |
||
330 |
if($image == false) : |
|
331 |
$image_link = '<!-- No images were added to this post. -->'; |
|
332 |
else : |
|
333 |
$post_perm = get_permalink($post->ID); |
|
334 |
$image_link = "<a href=\"$post_perm\" title=\"$post->post_title\">$image</a>"; |
|
335 |
endif; |
|
336 |
return $image_link; |
|
337 |
} |
|
338 |
||
339 |
/*********************************************************** |
|
340 |
Function for loading an image |
|
341 |
***********************************************************/ |
|
342 |
function load_the_image($custom_fields = false, $en_post, $default_size) { |
|
343 |
||
344 |
// Checks only if there are custom fields to check for |
|
345 |
if(isset($custom_fields)) { |
|
346 |
||
347 |
// Loop through the custom fields, checking for images or video |
|
348 |
$i = 0; |
|
349 |
while(strcmp($image[0],'') == 0 && $i <= sizeof($custom_fields)) { |
|
350 |
||
351 |
// Check custom field values for image, image alt text, and image class |
|
352 |
$image = get_post_custom_values($key = $custom_fields[$i]); |
|
353 |
$image_alt = get_post_custom_values($key = $custom_fields[$i] . ' Alt'); |
|
354 |
$image_class = get_post_custom_values($key = $custom_fields[$i] . ' Class'); |
|
355 |
// Convert custom field key name to image class |
|
356 |
$img_class = $custom_fields[$i]; |
|
357 |
$img_class = strtolower($img_class); |
|
358 |
$img_class = str_replace (" ", "-", $img_class); |
|
359 |
||
360 |
// Add space to image class if user inputs an extra class |
|
361 |
if($image_class == true) $image_class .= ' '; |
|
362 |
||
363 |
// Add user image class to default image classes |
|
364 |
if($default_size == 'thumbnail' && $img_class == 'thumbnail') $image_class .= $default_size; |
|
365 |
elseif($default_size == 'medium' && $img_class == 'medium') $image_class .= $default_size; |
|
366 |
elseif($default_size == 'full' && $img_class == 'full') $image_class .= $default_size; |
|
367 |
else $image_class .= $img_class . ' ' . $default_size; |
|
368 |
||
369 |
$i++; |
|
370 |
} // End while loop |
|
371 |
} // End check for custom field image |
|
372 |
||
373 |
// If there is no image set through custom fields, check post attachments |
|
374 |
if($image == false && $default_size == true) { |
|
375 |
$img_att_arr = find_attachment_image($custom_fields[0], $en_post, $default_size); |
|
376 |
if(strcmp($image_att_arr[0],'') == 0) : |
|
377 |
$image = $img_att_arr[0]; |
|
378 |
$image_class = $img_att_arr[1]; |
|
379 |
$image_alt = false; |
|
380 |
else : |
|
381 |
$image = false; $image_alt = false; $image_class = false; |
|
382 |
endif; |
|
383 |
} |
|
384 |
||
385 |
// Return array with an image, image alt, and image class |
|
386 |
return array($image, $image_alt, $image_class); |
|
387 |
} |
|
388 |
||
389 |
/*********************************************************** |
|
390 |
Function for displaying an image |
|
391 |
***********************************************************/ |
|
392 |
function display_the_image($cf_array = false, $en_post = false, $default_size = false, $default_img = false) { |
|
393 |
||
394 |
// Set nice names for image info |
|
395 |
if($cf_array[0] == false && $default_img == true) : |
|
396 |
$image[0] = $default_img; |
|
397 |
$image_class = $default_size; |
|
398 |
else : |
|
399 |
$image = $cf_array[0]; |
|
400 |
$image_alt = $cf_array[1]; |
|
401 |
$image_class = $cf_array[2]; |
|
402 |
endif; |
|
403 |
||
404 |
// If there's any kind of image for this post |
|
405 |
if(isset($image[0]) && strcmp($image[0],'') != 0) : |
|
406 |
// Open img tag |
|
407 |
$output = '<img src="'.$image[0].'"'; |
|
408 |
$output .= ' alt="'; |
|
409 |
// Image alt text |
|
410 |
if(isset($image_alt[0]) && strcmp($image_alt[0],'') != 0) $output .= $image_alt[0]; |
|
411 |
else $output .= $en_post->post_title; |
|
412 |
// Image class |
|
413 |
$output .= '" class="'; |
|
414 |
if(isset($image_class[0])) $output .= $image_class; |
|
415 |
else $output .= 'left'; |
|
416 |
// Close img tag |
|
417 |
$output .= '" />'; |
|
418 |
// If there's no image |
|
419 |
else : |
|
420 |
$output = false; |
|
421 |
endif; |
|
422 |
// Return the image |
|
423 |
return $output; |
|
424 |
} |
|
425 |
||
426 |
/*********************************************************** |
|
427 |
Function for finding an attachment image. |
|
428 |
Only called if no custom field images are set. |
|
429 |
***********************************************************/ |
|
430 |
function find_attachment_image($custom_fields = false, $en_post = false, $default_size = 'medium') { |
|
431 |
||
432 |
$custom = $custom_fields; |
|
433 |
$custom = strtolower($custom); |
|
434 |
$custom = str_replace (" ", "-", $custom); |
|
435 |
// Don't repeat the same class name |
|
436 |
if($custom == 'thumbnail' || $custom == 'medium' || $custom == 'full') $img_class = $default_size; |
|
437 |
else $img_class = $custom . ' ' . $default_size; |
|
438 |
||
439 |
$attachments = get_children("post_parent=$en_post->ID&post_type=attachment&post_mime_type=image&orderby=\"menu_order ASC, ID ASC\"&numberposts=1"); |
|
440 |
if($attachments == true) : |
|
441 |
foreach($attachments as $id => $attachment) : |
|
442 |
$img = wp_get_attachment_image_src($id, $default_size); |
|
443 |
$img_arr[0] = $img; |
|
444 |
endforeach; |
|
445 |
$img_arr[1] = $img_class; |
|
446 |
else : |
|
447 |
$img_arr = false; |
|
448 |
endif; |
|
449 |
return $img_arr; |
|
450 |
} |
|
451 |
?> |