Cestfait.ch

  • Home
  • Drupal
  • PHP 5
  • Jquery
  • Web Dev
  • Sys admin
  • Logiciels libres
  • Videos
  • Divers
  • Nous contacter
  • Mon c'est fait!
Home

Function utile pour Drupal 6

Submitted by yvan on Tue, 06/21/2011 - 17:37

Voilà déjà pas mal de temps que je travaille avec Drupal et à force on commence à se construire des outils qu'on utilise un peu partout sur tous les sites. Ici vous allez trouvez une des fonctions que j'utilise le plus, le

getImg
.

Cette fonction à placer dans le fichier template.php de votre theme permet de récupérer très facilement une image associée à un node grâce au module imafieldfield et de renvoyer toutes les informations nécessaires

<?php
function getImg($node, $preset = NULL, $attributes = NULL, $index = 0, $field = 'field_images') {
	if (!is_object($node) || !is_array($node->{$field})) {
		return FALSE;
	}
 
	$image = $node->{$field}[0];
	if (is_int($index) && $index > 0) {
		$image = $node->{$field}[$index];
	}
 
	if (!file_exists($image['filepath'])) {
		return FALSE;
	}
 
	$alt = $image['data']['alt'];
	$title = $image['data']['title'];
	$description = $image['data']['description'];
	$attributes = is_array($attributes) ? array_merge($attributes, $attributes) : array();
 
	if (!empty($preset)) {
		$src = theme('imagecache', $preset, $image['filepath'], $alt, $title, $attributes);
		$url = imagecache_create_url($preset, $image['filepath']);
	}
	else {
		$src = theme('image', $image['filepath'], $alt, $title, $attributes);
		url($GLOBALS['base_url'] . $image['filepath'], array('absolute' => TRUE));
	}
 
	return array(
		'alt' => $alt,
		'title' => $title,
		'description' => $description,
		'src' => $src,
		'url' => $url,
	);
}
?>
Si vous avez des suggestions, c'est la bienvenue.
0
Log in to vote
No votes yet
  • Login or register to post comments
  • Share this
Tags:
  • Drupal
  • drupal
  • function
  • protip
  • tool

User login

  • Create new account
  • Request new password
  • Sign in with Twitter

Translate

Sondage

Qu'elle version de drupal utilisez-vous ?

Submitted by Sir Squall on Tue, 04/10/2012 - 16:30
  • Login or register to post comments

Recent comments

  • Arf, je suis à l'armée!
    40 weeks 1 day ago
  • hahaha c'est juste! Il n'y a
    46 weeks 4 days ago
  • yeah comme sa fait plaisir de
    46 weeks 6 days ago
  • wouahou merciii :-) !
    50 weeks 5 days ago
  • J'y réponds aujourd'hui ici
    50 weeks 5 days ago
  • Salut, court article mais
    50 weeks 6 days ago
  • Oktoberfest power!!!
    1 year 3 weeks ago
  • yep je vais faire un petit
    1 year 5 weeks ago
  • It's regular approuved
    1 year 5 weeks ago
  • Pas d'exemple????
    1 year 5 weeks ago

Tags

cropping Divers drupal Drupal emacs firefox gmap Google Images Jquery jquery karmic koala La phrase du jour Lausanne Logiciels libres mysql PHP 5 RPG Sys admin ubuntu Web Dev yasnippet youtube Zend
more tags

Popular content

Today's:

  • Squall Beer Challenge '09
  • Boxxy likes Drupal
  • Trip to antwerpen !
  • 8ème Forum eCulture - ERACOM - 4 septembre 2009
  • viportuguese-shop.com
  • Emacs Transparent
  • Grep afficher les lignes avant et après
  • Drupal Mollom sa rox!
  • forcer le téléchargement
  • Tinymce styles sorted

All time:

  • Drupal 7 effet avec les jquery.ui.dialog sur Drupal 6 !
  • Dries Keynote DrupalCon Paris 2009
  • Drupal bridge zend yeah !!
  • Jquery slider c'est de la bonne !!!
  • Drupal and Zend, form validate :)
  • Jquery JSON en _POST
  • [Drupal] Lightbox avec une gmap! yeah
  • [Drupal] Domain Access & memcache sa donne quoi ?
  • viportuguese-shop.com
  • Node Import et Taxonomy CSV

Last viewed:

  • Full text search en MySQL
  • forcer le téléchargement
  • Firefox & Chrome
  • Firefox and windows
  • Firefox 64 bit
  • file_get_contents with proxy!
  • Feeds : Importer multiples images
  • Facebook et l'open source
  • Fabric, le déploiement avec Python
  • Evolution bug [?]

Twitter

Latest Articles

Derniers liens publiés

  • Get the list of all enabled module
    http://drupal.org/node/440962
  • Cloudflare et Dropbox nommés Technology pioneers
    http://techcrunch.com/2011/09/01/cloudflare-dropbox-palantir-and-kickstarter-named-technology-pioneers-by-the-world-economic-forum/
  • Apprend le javascript en t'amusant
    http://www.codecademy.com
  • EPSACrop sur Drupal 7
    http://www.aswissidea.org/
  • Drupal solr attachement intégration
    http://tika.apache.org/

Pub

Google gadget

Add to Google

Facebook page

jiwa

all good song

Partenaires

Cyber Warfare

Drupal Factory

Dev Factory

I love Smashing Magazine!
Fervens Drupal theme by Leow Kah Thong. Designed by Design Disease and brought to you by Smashing Magazine.