/** * Sends a PM or Email notification with substitutions based off configuration * * @param int $type 1: Email, 2: PM, 3: Moderators, 4: Auto * @param UserTable|int|null $from * @param UserTable|int|string $to * @param string $subject * @param string $body * @param GroupTable $group * @param array $extra * @return bool */ static public function sendNotification( $type, $from, $to, $subject, $body, $group, $extra = array() ) { global $_CB_framework, $_PLUGINS; if ( ( ! $subject ) || ( ! $body ) || ( ! $group->get( 'id' ) ) || ( $group->get( 'published', 1 ) != 1 ) || ( ! $group->category()->get( 'published', 1 ) ) || ( ! $to ) ) { return false; } if ( $from instanceof UserTable ) { $fromUser = $from; } elseif ( is_int( $from ) ) { $fromUser = \CBuser::getUserDataInstance( $from ); } else { $fromUser = null; } if ( $to instanceof UserTable ) { $toUser = $to; } elseif ( is_int( $to ) ) { $toUser = \CBuser::getUserDataInstance( $to ); } else { $toUser = null; } if ( $fromUser && $toUser && ( $fromUser->get( 'id' ) == $toUser->get( 'id' ) ) ) { return false; } static $plugin = null; static $params = null; if ( ! $params ) { $plugin = $_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' ); $params = $_PLUGINS->getPluginParams( $plugin ); } $notifyBy = (int) $params->get( 'notifications_notifyby', 1 ); $fromName = $params->get( 'notifications_from_name', null ); $fromEmail = $params->get( 'notifications_from_address', null ); $cbUser = \CBuser::getInstance( ( $fromUser ? (int) $fromUser->get( 'id' ) : ( $toUser ? (int) $toUser->get( 'id' ) : 0 ) ), false ); $user = $cbUser->getUserData(); $extras = array( 'category_id' => (int) $group->category()->get( 'id' ), 'category_name' => ( $group->category()->get( 'id' ) ? CBTxt::T( $group->category()->get( 'name' ) ) : CBTxt::T( 'Uncategorized' ) ), 'category' => '<a href="' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'categories', 'func' => 'show', 'id' => (int) $group->get( 'category' ) ) ) . '">' . ( $group->category()->get( 'id' ) ? CBTxt::T( $group->category()->get( 'name' ) ) : CBTxt::T( 'Uncategorized' ) ) . '</a>', 'group_id' => (int) $group->get( 'id' ), 'group_name' => htmlspecialchars( CBTxt::T( $group->get( 'name' ) ) ), 'group' => '<a href="' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ) . '">' . htmlspecialchars( CBTxt::T( $group->get( 'name' ) ) ) . '</a>', 'user' => '<a href="' . $_CB_framework->viewUrl( 'userprofile', false, array( 'user' => (int) $user->get( 'id' ) ) ) . '">' . getNameFormat( $user->get( 'name' ), $user->get( 'username' ), Application::Config()->get( 'name_format', 3 ) ) . '</a>' ); if ( ! $toUser ) { $extras['email'] = $to; $extras['name'] = $to; $extras['username'] = $to; } $extras = array_merge( $extras, $extra ); $subject = $cbUser->replaceUserVars( $subject, true, false, $extras, false ); $body = $cbUser->replaceUserVars( $body, false, false, $extras, false ); if ( $type == 4 ) { $type = ( $notifyBy == 2 ? 2 : 1 ); } $notification = new \cbNotification(); if ( $type == 3 ) { // Moderator Notification: $notification->sendToModerators( $subject, $body, false, 1 ); } elseif ( ( $type == 2 ) && $toUser ) { // PM Notification: if ( ! $toUser->get( 'id' ) ) { return false; } $notification->sendUserPMSmsg( $toUser, 0, $subject, $body, true, false, 1, $extras ); } else { // Email Notification: if ( $toUser ) { if ( ! $toUser->get( 'id' ) ) { return false; } $notification->sendFromSystem( $toUser, $subject, $body, 1, 1, null, null, null, $extras, true, $fromName, $fromEmail ); } else { $userTo = new UserTable(); $userTo->set( 'email', $to ); $userTo->set( 'name', $to ); $userTo->set( 'username', $to ); $notification->sendFromSystem( $userTo, $subject, $body, 1, 1, null, null, null, $extras, true, $fromName, $fromEmail ); } } return true; }
function awUserActivated($user, $success) { global $_CB_framework, $ueConfig; if (!$success) return false; // get CBUser so we can use replaceUserVars() from CBAPI $awCBuser =& CBUser::getInstance((int) $user->id); $res_wpms = true; $res_wemail = true; $res_wconnect = true; $plugparams=$this->_awGetPlugParameters(); $testNotifications = new cbNotification(); if ($plugparams["awautomessageenable"]) { switch ($plugparams["awmessagemethod"]) { case 0: // PMS $cbawNotification = new cbNotification(); $res_wpms = $cbawNotification->sendUserPMSmsg((int) $user->id, $plugparams["awpmsfromuserid"], $awCBuser->replaceUserVars( $plugparams["awpmsmessagesubject"] ), $awCBuser->replaceUserVars( $plugparams["awpmsmessagebody"] ), true); if (!$res_wpms) { $this->_setErrorMSG("Auto-Welcome plugin failed to send PMS welcome message"); } break; case 1: // Email $cbawNotification = new cbNotification(); $res_wemail=$cbawNotification->sendUserEmail((int) $user->id, $plugparams["awemailfromuserid"], $awCBuser->replaceUserVars( $plugparams["awemailmessagesubject"] ), $awCBuser->replaceUserVars( $plugparams["awemailmessagebody"] ), $plugparams["awemailfromuserid"]); //reveal email if (!$res_wemail) { $this->_setErrorMSG("Auto-Welcome plugin failed to send Email welcome message"); } break; case 2: // Email and PMS $cbawNotification = new cbNotification(); $res_wpms = $cbawNotification->sendUserPMSmsg((int) $user->id, $plugparams["awpmsfromuserid"], $awCBuser->replaceUserVars( $plugparams["awpmsmessagesubject"] ), $awCBuser->replaceUserVars( $plugparams["awpmsmessagebody"] ), true); if (!$res_wpms) { $this->_setErrorMSG("Auto-Welcome plugin failed to send PMS welcome message"); } $res_wemail=$cbawNotification->sendUserEmail((int) $user->id, $plugparams["awemailfromuserid"], $awCBuser->replaceUserVars( $plugparams["awemailmessagesubject"] ), $awCBuser->replaceUserVars( $plugparams["awemailmessagebody"] ), $plugparams["awpmsfromuserid"]); //reveal email if (!$res_wemail) { $this->_setErrorMSG("Auto-Welcome plugin failed to send Email welcome message"); } break; default: break; } } if ($plugparams["awautoconnectenable"] && $ueConfig['allowConnections']) { $awkeyuserid_count = substr_count($plugparams["awkeyuserid"],','); $res_wconnect = true; $awkeyuserid_item = explode(",",$plugparams["awkeyuserid"]); if ($plugparams["awautoconnectdirection"]==0) { // connect new user to key users $cbawCon=new cbConnection( (int) $user->id); for ($aw_i=0;$aw_i<=$awkeyuserid_count;$aw_i++) { $res_wconnect = $res_wconnect && $cbawCon->addConnection((int) $awkeyuserid_item[$aw_i], $awCBuser->replaceUserVars( $plugparams["awautoconnectmessage"] )); } if (!$res_wconnect) { $this->_setErrorMSG("Auto-Welcome plugin failed to initiate auto-connection"); } unset($cbawCon); // cleanup } else { // connect key users to new user for ($aw_i=0;$aw_i<=$awkeyuserid_count;$aw_i++) { $cbawCon=new cbConnection((int) $awkeyuserid_item[$aw_i]); $res_wconnect = $res_wconnect && $cbawCon->addConnection((int) $user->id, $awCBuser->replaceUserVars( $plugparams["awautoconnectmessage"] )); unset($cbawCon); // cleanup } if (!$res_wconnect) { $this->_setErrorMSG("Auto-Welcome plugin failed to initiate auto-connection"); } } } if (!($res_wemail && $res_wpms && $res_wconnect)) { $this->raiseError(0); } return $res_wemail && $res_wpms && $res_wconnect; }