Jump to content

Recommended Posts

Posted
1 hour ago, Niko Belger said:

how do I send a private message in IPB4? In IPB3 there were some functions for it but didn't find them in IPB4 yet

One example I use:

	/**
	 * Send pm
	 */      
	public function messageMembersSend( $member, $subject, $content )
	{
		/* Setup pm title and msg */
		$msgTitle = $subject;
		$msgPost  = $content;
		\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $msgTitle );        
		\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $msgPost );  

		/* Set the receiver */
		try
		{
			$member = \IPS\Member::load( $member );
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		}

		/* Set pm sender */
		try
		{
			$pmSender = \IPS\Member::loggedIn();
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		} 

		/* Valid sender? */
		if( !$pmSender->member_id )
		{
			return;
		}

		/* Create conversation */        
		$conversation = \IPS\core\Messenger\Conversation::createItem( $pmSender, $pmSender->ip_address, \IPS\DateTime::ts( time() ) );
		$conversation->title 		= $msgTitle;
		$conversation->to_member_id = $member->member_id;
		$conversation->save();
        
		/* Add message */ 
		$message = \IPS\core\Messenger\Message::create( $conversation, $msgPost, TRUE, NULL, NULL, $pmSender );
		$conversation->first_msg_id = $message->id;
		$conversation->save(); 

		/* Authorize everyone */       
		$conversation->authorize( $member );
		$conversation->authorize( $pmSender );

		/* Send notification */ 
		$notification = new \IPS\Notification( \IPS\Application::load('core'), 'private_message_added', $conversation, array( $conversation, $pmSender ) );
		$notification->send();                      
	}

 

  • 3 years later...
Posted
On 9/16/2017 at 10:16 AM, Adriano Faria said:

One example I use:

	/**
	 * Send pm
	 */      
	public function messageMembersSend( $member, $subject, $content )
	{
		/* Setup pm title and msg */
		$msgTitle = $subject;
		$msgPost  = $content;
		\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $msgTitle );        
		\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $msgPost );  

		/* Set the receiver */
		try
		{
			$member = \IPS\Member::load( $member );
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		}

		/* Set pm sender */
		try
		{
			$pmSender = \IPS\Member::loggedIn();
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		} 

		/* Valid sender? */
		if( !$pmSender->member_id )
		{
			return;
		}

		/* Create conversation */        
		$conversation = \IPS\core\Messenger\Conversation::createItem( $pmSender, $pmSender->ip_address, \IPS\DateTime::ts( time() ) );
		$conversation->title 		= $msgTitle;
		$conversation->to_member_id = $member->member_id;
		$conversation->save();
        
		/* Add message */ 
		$message = \IPS\core\Messenger\Message::create( $conversation, $msgPost, TRUE, NULL, NULL, $pmSender );
		$conversation->first_msg_id = $message->id;
		$conversation->save(); 

		/* Authorize everyone */       
		$conversation->authorize( $member );
		$conversation->authorize( $pmSender );

		/* Send notification */ 
		$notification = new \IPS\Notification( \IPS\Application::load('core'), 'private_message_added', $conversation, array( $conversation, $pmSender ) );
		$notification->send();                      
	}

 

How could I set the $pmSender as the same as receiver $member?

I have tried:

public function messageMembersSend( $member, $subject, $content )
	{
		/* Setup pm title and msg */
		$msgTitle = $subject;
		$msgPost  = $content;
		\IPS\Member::load( $member )->language()->parseOutputForDisplay( $msgTitle );        
		\IPS\Member::load( $member )->language()->parseOutputForDisplay( $msgPost );  

		/* Set the receiver */
		try
		{
			$member = \IPS\Member::load( $member );
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		}

		/* Set pm sender */
		try
		{
			$pmSender = \IPS\Member::load( $member );
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		} 

		/* Valid sender? */
		if( !$pmSender->member_id )
		{
			return;
		}

		/* Create conversation */        
		$conversation = \IPS\core\Messenger\Conversation::createItem( $pmSender, $pmSender->ip_address, \IPS\DateTime::ts( time() ) );
		$conversation->title 		= $msgTitle;
		$conversation->to_member_id = $member->member_id;
		$conversation->save();
        
		/* Add message */ 
		$message = \IPS\core\Messenger\Message::create( $conversation, $msgPost, TRUE, NULL, NULL, $pmSender );
		$conversation->first_msg_id = $message->id;
		$conversation->save(); 

		/* Authorize everyone */       
		$conversation->authorize( $member );
		$conversation->authorize( $pmSender );

		/* Send notification */ 
		$notification = new \IPS\Notification( \IPS\Application::load('core'), 'private_message_added', $conversation, array( $conversation, $pmSender ) );
		$notification->send();                      
	}

But I get an error: 4C124/6 Illegal offset type in isset or empty

I am trying to send an error message to myself on a plugin.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...