• Avail guidance to develop Drupal modules & Drupal themes
  • Share and get review of your code
  • Get Access to free CodeBooks and ThemeBooks
  • Drupal 5, 6 and 7 covered

Userpoints Meter

0 Points /1000 Points

Drupal profile picture

in Project codes

This CodeLet allows you to set any image that you have uploaded on your Drupal website as your profile picture. However, you need to modify this CodeLet according to your requirements.
Dependencies & prerequisites
- There are no known dependencies.
- User picture should be enabled.

<?php
//$Id$

/**
* @file
*
* Set an image as profile picture
*
* @author Beautifulmind <http://twitter.com/bhavinhjoshi>
*/


/**
* Implementation of hook_menu
*
* @author Beautifulmind <http://twitter.com/bhavinhjoshi>
*/
function upcoming_events_menu() {
   
$item = array();
   
$item['picture/set/%node'] = array(
     
'type' => MENU_CALLBACK,
     
'page callback' => 'upcoming_events_picture',
     
'page arguments' => array(2),
     
'access callback' => 'upcoming_events_validate',
     
'access arguments' => array(2),
    );
   
    return
$item;
}


/**
* upcoming_events_validate
*
* Check if user is the author of the node
*
* @param object $node
* @author Beautifulmind <http://twitter.com/bhavinhjoshi>
*/
function upcoming_events_validate($node) {
    global
$user;
    return (
$user->uid == $node->uid) ? TRUE : FALSE;
}


/**
* Implementation of hook_nodeapi
*
* @param $node
* @param $op
* @param $a3
* @param $a4
* @author Beautifulmind <http://twitter.com/bhavinhjoshi>
*/
function upcoming_events_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
    global
$user;
    switch (
$op) {
        case
'view':
            if (
$node->type == 'gallery') {
               
$node->content['addimages'] = array(
                 
'#type' => 'item',
                 
'#value' => l(t('Upload photos'), "node/add/gallery-image", array('query' => "edit[field_album][nid][nid]=". $node->nid)),
                 
'#weight' => 10,
                );
            }
            if (
$node->type == 'galleryimage') {
               
$destination = drupal_get_destination();
               
$node->content['set_profile_image'] = array(
         
'#type' => 'item',
         
'#value' => l(t('Set as my profile picture'), 'picture/set/'. $node->nid, array('query' => $destination)),
         
'#weight' => 0,
        );
       
               
$node->content['addimages'] = array(
         
'#type' => 'item',
         
'#value' => l(t('Upload more photos'), "node/add/gallery-image"),
         
'#weight' => 10,
        );
            }
            break;
    }
}



/**
* upcoming_events_picture
*
* @param unknown_type $variables
* @author Beautifulmind <http://twitter.com/bhavinhjoshi>
*/
function upcoming_events_picture($node) {
    global
$user;
   
db_query("UPDATE {users} set picture = '%s' WHERE uid = %d", $node->field_gallery_image[0]['filepath'], $user->uid);
   
drupal_set_message(t('Picture has been set as your profile picture'));
   
drupal_goto($_GET['destination']);
}
?>

5
Your rating: None Average: 5 (3 votes)
Syndicate content

Recent comments