og_groups = array( 1, 12, 123 ) ; * * however, og wants these values to have the gid as the key and value, eg * * $node->og_groups = array( * 1 => 1, * 12 => 12, * 123 => 123 * ) ; * * see http://drupal.org/node/136606#comment-1860524 */ function og_mailhandler_mailhandler($node, $result, $i, $header, $mailbox) { if ( isset($node->og_groups) && is_array($node->og_groups) ) { $node->og_groups = array_combine($node->og_groups, $node->og_groups); } return $node ; } /** * provide a method for identifying whether posts submitted via * mailhandler are acceptable based on the originating email address * and the corresponding user's membership of relevant OG groups * * see http://drupal.org/node/559524 */ function og_mailhandler_nodeapi(&$node, $op, $a3=NULL, $a4=NULL) { switch( $op ) { case 'validate' : //watchdog('og_mailhandler',t('In nodeapi for node !title.',array('!title'=>$node->title))); if ( og_is_group_post_type($node->type) ) { //watchdog('og_mailhandler','Is an OG Group Post Type'); if ( !isset($node->uid) || $node->uid == '0' ) { //watchdog('og_mailhandler','Anonymous submission'); form_set_error('',"Rejecting submission from unrecognised email address."); watchdog('og_mailhandler','Rejecting OG group post from unknown email via mailhandler.'); } else { $args['!uid'] = $node->uid ; //watchdog('og_mailhandler',t('Identifiable user (UID !uid)', array('!uid'=>$node->uid))); if ( isset($node->og_groups) ) { //watchdog('og_mailhandler','Has groups assigned. Groups are: '.print_r($node->og_groups,1)); $account = user_load($node->uid) ; //watchdog('og_mailhandler','User ID of poster is: '.print_r($node->uid,1)); foreach( $node->og_groups as $k => $gid ) { //watchdog('og_mailhandler','Group ID is: '.$gid); $args = array('!name'=>$account->name,'!gid'=>$gid) ; //watchdog('og_mailhandler','Args is: '.print_r($args,1)); if ( !og_is_group_member($gid, TRUE, $account->uid) ) { //watchdog('og_mailhandler','UID'.$user->uid.' is a not member of Group '.$gid); unset($node->og_groups[$k]) ; watchdog('og_mailhandler',t('Post by !name to OG Group !gid is not allowed',$args)); } } if ( empty($node->og_groups) ) { //watchdog('og_mailhandler','Groups for this node is empty, so will drop it.'); form_set_error('',t('Rejected post by !name',$args)); watchdog('og_mailhandler',t('Rejected post by !name',$args)); } } } } break ; } }