l('admin/settings/avatar_gallery', 'admin/settings/avatar_gallery'))); } } /** * Implementation of hook_menu() * * @see hook_menu() */ function avatar_gallery_menu($may_cache) { if ($may_cache) { $items = array(); $items[] = array( 'path' => 'avatar_gallery/demo', 'title' => t('See avatar gallery'), 'callback' => 'avatar_gallery_demo', 'access' => user_access('access administration pages'), 'type' => MENU_NORMAL_ITEM); $items[] = array( 'path' => 'avatar_gallery/regenerate', 'title' => t('Regenerate avatar gallery'), 'callback' => 'avatar_gallery_regenerate_and_demo', 'access' => user_access('access administration pages'), 'type' => MENU_NORMAL_ITEM); } return $items; } /** * Implementation of hook_settings() * * @see hook_settings() */ function avatar_gallery_settings() { $output = ''; $group = form_textfield(t("Number of columns"), "avatar_gallery_num_cols", variable_get("avatar_gallery_num_cols", "6"), 10,70); $group .= form_textfield(t("Horizontal spacing"), "avatar_gallery_hspacing", variable_get("avatar_gallery_hspacing", "100"), 10,70); $group .= form_textfield(t("Vertical spacing"), "avatar_gallery_vspacing", variable_get("avatar_gallery_vspacing", "100"), 10,70); $group .= form_textfield(t("Margin"), "avatar_gallery_margin", variable_get("avatar_gallery_margin", "25"), 10,70); $group .= form_textfield(t("Thumbs max width"), "avatar_gallery_thumb_hsize", variable_get("avatar_gallery_thumb_hsize", "85"), 10,70); $group .= form_textfield(t("Thumbs max height"), "avatar_gallery_thumb_vsize", variable_get("avatar_gallery_thumb_vsize", "85"), 10,70); $group .= form_textfield(t("Background color R"), "avatar_gallery_bcolr", variable_get("avatar_gallery_bcolr", "255"), 10,70); $group .= form_textfield(t("Background color G"), "avatar_gallery_bcolg", variable_get("avatar_gallery_bcolg", "255"), 10,70); $group .= form_textfield(t("Background color B"), "avatar_gallery_bcolb", variable_get("avatar_gallery_bcolb", "255"), 10,70); $group .= form_textfield(t("Jpeg quality"), "avatar_gallery_quality", variable_get("avatar_gallery_quality", "80"), 10,70); $output .= form_group(t('Visual features'),$group); $group = form_checkbox(t("Show text"), "avatar_gallery_showtext", 1, variable_get("avatar_gallery_showtext", "0")==1); $group .= form_textfield(t("Text size"), "avatar_gallery_tsize", variable_get("avatar_gallery_tsize", "15"), 10,70); $group .= form_textfield(t("Text color R"), "avatar_gallery_tcolr", variable_get("avatar_gallery_tcolr", "0"), 10,70); $group .= form_textfield(t("Text color G"), "avatar_gallery_tcolg", variable_get("avatar_gallery_tcolg", "0"), 10,70); $group .= form_textfield(t("Text color B"), "avatar_gallery_tcolb", variable_get("avatar_gallery_tcolb", "0"), 10,70); $group .= form_textfield(t("Text .ttf font path (e.g: files/arial.ttf)"), "avatar_gallery_font", variable_get("avatar_gallery_font", ""), 50,70); $output .= form_group(t('Text features'),$group); $group = form_checkbox(t("Show users with no avatars"), "avatar_gallery_showall", 1, variable_get("avatar_gallery_showall", "0")==1); $group .= form_textfield(t("Image for missing avatars"), "avatar_gallery_miss_image", variable_get("avatar_gallery_miss_image", ""), 50,70); $group .= form_select(t('Ordering'), 'avatar_gallery_ordering', variable_get('avatar_gallery_ordering', "uid DESC"), array("uid DESC"=>"Newest first","name ASC"=>"By name"), t('How the users are ordered, left to right, then top to bottom.')); $output .= form_group(t('Misc'),$group); return $output; } /** * Implementation of hook_block(). */ function avatar_gallery_block($op = 'list', $delta = 0) { $menu = menu_get_menu(); if ($op == 'list') { $blocks[]=array("info"=>t("Avatar gallery")); return $blocks; } else if ($op == 'view') { $data['subject'] = t("Avatar gallery"); $result = db_fetch_object(db_query("SELECT COUNT(u.uid) as count FROM {users} u WHERE u.status < 3 and u.uid != 0")); $data['content'] .= '
'.t('There are %members of HomelessNation.org!', array('%members' => format_plural($result->count, '1 user', '%count users'))).'
'; $data['content'] .= _avatar_gallery_imagemap(); return $data; } } /** * Implementation of hook_user() * * On user creation or modification, regenerates the gallery */ function avatar_gallery_user($type, $edit, $user) { if ($type == "insert" || $type == "update") { if (isset($edit["picture"])) { avatar_gallery_regenerate(); } } } /** * regenerates the gallery and display it * * test callback useful for testing */ function avatar_gallery_regenerate_and_demo() { avatar_gallery_regenerate(); //avatar_gallery_demo(); drupal_goto("admin/settings/avatar_gallery"); } /** * simply echo the gallery, menu callback * * @see _avatar_gallery_imagemap() */ function avatar_gallery_demo() { echo _avatar_gallery_imagemap('/'); } /** * generate the HTML code necessary to display the image and the area map * * @args $root string the base url of links * @returns string generally an tag followed by a tag */ function _avatar_gallery_imagemap($root = '') { $img = theme_image($root. variable_get('file_directory_path', 'files').'/avatar_gallery.jpg', t('Avatar gallery'), t('Avatar gallery'), 'border="0" usemap="avatar_gallery_areamap"', FALSE) . _avatar_gallery_areamap_dyn($root); return $img; } /** * return the cached areamap generated by avatar_gallery_regenerate() * * unused function, replaced by _avatar_gallery_areamap_dyn() because * the cache had broken URLs * * to enable this function, call it from _avatar_gallery_imagemap() * and uncomment the code building the $amap array in * avatar_gallery_regenerate() (identified by "STATIC URLS" in * comments) * * @see _avatar_gallery_areamap_dyn() * @see avatar_gallery_regenerate() */ function _avatar_gallery_areamap() { $cache = cache_get("avatar_gallery_areamap"); return $cache->data; } /** * build an areamap from coordinates cached by avatar_gallery_regenerate() * * this will call avatar_gallery_regenerate() to recreate the cache if * missing or expired * * @arg $root string the base of urls * @returns string an named avatar_gallery_areamap * corresponding to the image created by avatar_gallery_regenerate() * @see avatar_gallery_regenerate() */ function _avatar_gallery_areamap_dyn($root = '') { if (!$cache = cache_get("avatar_gallery_coordinates")) { avatar_gallery_regenerate(); } $coords = unserialize($cache->data); $amap = ""; foreach ($coords as $uid => $coord) { $amap .= ''; } return '' . $amap . ""; } /** * regenerate the avatar gallery * * this is where most of the work is done. here the image is created * and the coordinates of the image map are computed and cached as * avatar_gallery_coordinates in the cache system. * * the image is created in $file_directory_path/avatar_gallery.jpg */ function avatar_gallery_regenerate() { $order = variable_get("avatar_gallery_ordering","uid DESC"); $items = array(); $result = db_query('SELECT uid,name,picture FROM {users} WHERE status != 0 and uid!=0 ORDER BY %s', $order); while ($account = db_fetch_object($result)) { $items[] = $account; } // create background $numcols = variable_get("avatar_gallery_num_cols",6); $hspacing = variable_get("avatar_gallery_hspacing",100); $vspacing = variable_get("avatar_gallery_vspacing",100); $margin = variable_get("avatar_gallery_margin",25); $bcolr = variable_get("avatar_gallery_bcolr",255); $bcolg = variable_get("avatar_gallery_bcolg",255); $bcolb = variable_get("avatar_gallery_bcolb",255); $new_w = variable_get("avatar_gallery_thumb_hsize",85); $new_h = variable_get("avatar_gallery_thumb_vsize",85); $textSize = variable_get("avatar_gallery_textsize",15); $showtext = variable_get("avatar_gallery_showtext",1); $tcolr = variable_get("avatar_gallery_tcolr",0); $tcolg = variable_get("avatar_gallery_tcolg",0); $tcolb = variable_get("avatar_gallery_tcolb",0); $font = variable_get("avatar_gallery_font",""); $quality = variable_get("avatar_gallery_quality",80); $show_miss = variable_get("avatar_gallery_showall",0); $miss_image = variable_get("avatar_gallery_miss_image",""); $maxx = $numcols * $hspacing + $margin * 2; $maxy = ceil(count($items) / $numcols) * $vspacing + $margin * 2; if ($maxy == 0) { $maxy = $vspacing; } $dst_img = ImageCreateTrueColor($maxx,$maxy); $bcol = imagecolorallocate($dst_img,$bcolr,$bcolg,$bcolb); imagefill($dst_img,0,0,$bcol); $tcol = imagecolorallocate($dst_img,$tcolr,$tcolg,$tcolb); if ($showtext) { $dimensions = imagettfbbox($textSize, 0, $font, "W"); $lineHeight = ($dimensions[1] - $dimensions[7]); // the height of a single line } $colnum=-1; $rownum=0; foreach ($items as $k => $v) { $picfile = $v->picture; if ($picfile != "" || $show_miss) { if ($picfile == "" || !file_exists($picfile)) { if ($miss_image == "") { drupal_set_message(t("the missing image file has not been specified")); } $picfile = $miss_image; } $colnum++; if ($colnum >= $numcols) { $rownum++; $colnum=0; } // we have a picture $image_data = @getimagesize($picfile); $image_type=$image_data[2]; if($image_type==1) { $src_img=imagecreatefromgif($picfile); } else if($image_type==2) { $src_img=imagecreatefromjpeg($picfile); } else { drupal_set_message(t("Bad image format: '$picfile'")); continue; } $old_x = imageSX($src_img); $old_y = imageSY($src_img); if (($old_x / $old_y) > ($new_w / $new_h)) { $thumb_w=$new_w; $thumb_h=$old_y * ($new_w/$old_x); } else if (($old_x / $old_y) < ($new_w / $new_h)) { $thumb_w=$old_x * ($new_h/$old_y); $thumb_h=$new_h; } else if (($old_x / $old_y) == ($new_w / $new_h)) { $thumb_w=$new_w; $thumb_h=$new_h; } $maxs = max($thumb_w,$thumb_h); $picx = ($maxs-$thumb_w)/2 + $colnum * $hspacing + $margin; $picy = ($maxs-$thumb_h)/2 + $rownum * $vspacing + $margin; imagecopyresampled($dst_img,$src_img, $picx, $picy, 0, 0, $thumb_w,$thumb_h, $old_x,$old_y); // STATIC URLs, faster but inexact, disabled // $amap.= 'uid).'" title="'.$v->name.'">'.chr(13); $coords[$v->uid] = $picx.",".$picy.",".($picx+$thumb_w).",".($picy+$thumb_h); // now write name of user under picture if ($showtext) { $dimensions = imagettfbbox($textSize, 0, $font, $v->name); $lineWidth = $dimensions[2] - $dimensions[0]; // get the length of this line, if the word is to be included $leftStart=-$lineWidth/2; imagettftext($dst_img, $textSize, 0, $colnum * $hspacing + $margin + $new_w / 2 + $leftStart, $rownum * $vspacing + $margin + $new_h + $lineHeight, $tcol, $font, $v->name); } // destroy thumbnail imagedestroy($src_img); } } imagejpeg($dst_img,variable_get('file_directory_path', 'files')."/avatar_gallery.jpg",$quality); imagedestroy($dst_img); // STATIC URLs, faster but inexact, disabled // cache_clear_all("avatar_gallery_areamap"); // cache_set("avatar_gallery_areamap","".chr(13).$amap."", CACHE_PERMANENT); cache_clear_all("avatar_gallery_coordinates"); cache_set("avatar_gallery_coordinates", serialize($coords), CACHE_PERMANENT); } ?>