/** * @param null|int $id * @param UserTable $user */ private function saveInviteEdit( $id, $user ) { global $_CB_framework, $_CB_database, $_PLUGINS; $inviteLimit = (int) $this->params->get( 'invite_limit', null ); $cbModerator = Application::User( (int) $user->get( 'id' ) )->isGlobalModerator(); $row = new cbinvitesInviteTable(); $row->load( (int) $id ); $canAccess = false; $inviteCount = 0; if ( ! $row->get( 'id' ) ) { if ( $cbModerator ) { $canAccess = true; } elseif ( $user->get( 'id' ) && Application::MyUser()->canViewAccessLevel( $this->params->get( 'invite_create_access', 2 ) ) ) { if ( $inviteLimit ) { $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_invites' ) . "\n WHERE " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . "\n AND ( " . $_CB_database->NameQuote( 'user' ) . " IS NULL OR " . $_CB_database->NameQuote( 'user' ) . " = " . $_CB_database->Quote( '' ) . " )"; $_CB_database->setQuery( $query ); $inviteCount = (int) $_CB_database->loadResult(); if ( $inviteCount < $inviteLimit ) { $canAccess = true; } } else { $canAccess = true; } } } elseif ( $cbModerator || ( $row->get( 'user_id' ) == $user->get( 'id' ) ) ) { $canAccess = true; } $profileUrl = $_CB_framework->userProfileUrl( $row->get( 'user_id', $user->get( 'id' ) ), false, 'cbinvitesTab' ); if ( $canAccess && ( ! $row->isAccepted() ) ) { $toArray = explode( ',', $this->input( 'post/to', null, GetterInterface::STRING ) ); if ( ( ! $this->params->get( 'invite_multiple', 1 ) ) && ( ! $cbModerator ) && ( count( $toArray ) > 1 ) ) { $this->showInviteEdit( $row->get( 'id' ), $user, CBTxt::T( 'Comma seperated lists are not supported! Please use a single To address.' ) ); return; } $sent = false; if ( ! empty( $toArray ) ) { foreach ( $toArray as $k => $to ) { if ( $k != 0 ) { $row->set( 'id', null ); $row->set( 'code', null ); } $orgTo = $row->get( 'to' ); $row->set( 'to', $to ); $row->set( 'subject', $this->input( 'post/subject', $row->get( 'subject' ), GetterInterface::STRING ) ); if ( $this->params->get( 'invite_editor', 2 ) >= 2 ) { $row->set( 'body', $this->input( 'post/body', $row->get( 'body' ), GetterInterface::HTML ) ); } else { $row->set( 'body', $this->input( 'post/body', $row->get( 'body' ), GetterInterface::STRING ) ); } $row->set( 'user_id', (int) $this->input( 'post/user_id', $row->get( 'user_id', $user->get( 'id' ) ), GetterInterface::INT ) ); if ( $cbModerator ) { $row->set( 'user', (int) $this->input( 'post/user', $row->get( 'user' ), GetterInterface::INT ) ); } if ( ! $row->get( 'code' ) ) { $row->set( 'code', md5( uniqid() ) ); } $new = ( $row->get( 'id' ) ? false : true ); if ( $new && $inviteLimit ) { $inviteCount++; if ( $inviteCount > $inviteLimit ) { cbRedirect( $profileUrl, CBTxt::T( 'Invite limit reached!' ), 'error' ); } } if ( ! $row->get( 'user' ) ) { $toUser = new UserTable(); $toUser->loadByEmail( $row->get( 'to' ) ); } else { $toUser = CBuser::getUserDataInstance( (int) $row->get( 'user' ) ); } if ( ! $row->get( 'to' ) ) { $row->setError( CBTxt::T( 'To address not specified.' ) ); } elseif ( ! cbIsValidEmail( $row->get( 'to' ) ) ) { $row->setError( CBTxt::T( 'INVITE_TO_ADDRESS_INVALID', 'To address not valid: [to_address]', array( '[to_address]' => $row->get( 'to' ) ) ) ); } elseif ( $toUser->id == $row->get( 'user_id' ) ) { $row->setError( CBTxt::T( 'You can not invite your self.' ) ); } elseif ( $toUser->id && ( $row->get( 'to' ) != $orgTo ) ) { $row->setError( CBTxt::T( 'To address is already a user.' ) ); } elseif ( ( ! $this->params->get( 'invite_duplicate', 0 ) ) && ( ! $cbModerator ) && $row->isDuplicate() ) { $row->setError( CBTxt::T( 'To address is already invited.' ) ); } elseif ( $this->params->get( 'invite_captcha', 0 ) && ( ! $row->get( 'id' ) ) && ( $k == 0 ) && ( ! $cbModerator ) ) { $_PLUGINS->loadPluginGroup( 'user' ); $_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() ); if ( $_PLUGINS->is_errors() ) { $row->setError( CBTxt::T( $_PLUGINS->getErrorMSG() ) ); } } $_PLUGINS->trigger( 'invites_onBeforeInvite', array( &$row, $user ) ); if ( $row->getError() || ( ! $row->store() ) ) { $this->showInviteEdit( $row->get( 'id' ), $user, CBTxt::T( 'INVITE_FAILED_SAVE_ERROR', 'Invite failed to save! Error: [error]', array( '[error]' => $row->getError() ) ) ); return; } if ( ( $new || ( ! $row->isSent() ) ) && ( ! $toUser->id ) ) { if ( ! $row->send() ) { $this->showInviteEdit( $row->get( 'id' ), $user, CBTxt::T( 'INVITE_FAILED_SEND_ERROR', 'Invite failed to send! Error: [error]', array( '[error]' => $row->getError() ) ) ); return; } else { $sent = true; } } $_PLUGINS->trigger( 'invites_onAfterInvite', array( $row, $sent, $user ) ); } cbRedirect( $profileUrl, ( $sent ? CBTxt::T( 'Invite sent successfully!' ) : CBTxt::T( 'Invite saved successfully!' ) ) ); } else { $this->showInviteEdit( $row->get( 'id' ), $user, CBTxt::T( 'To address not specified.' ) ); return; } } else { cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); } }
/** * @param cbinvitesInviteTable $row * @return bool */ static public function sendInvite( &$row ) { global $_CB_framework, $_PLUGINS; $plugin = $_PLUGINS->getLoadedPlugin( 'user', 'cbinvites' ); if ( ! $plugin ) { return false; } $params = $_PLUGINS->getPluginParams( $plugin ); $invitePrefix = CBTxt::T( $params->get( 'invite_prefix', '[sitename] - ' ) ); $inviteHeader = CBTxt::T( $params->get( 'invite_header', '<p>You have been invited by [username] to join [sitename]!</p><br>' ) ); $inviteFooter = CBTxt::T( $params->get( 'invite_footer', '<br><p>Invite Code - [code]<br>[sitename] - [site]<br>Registration - [register]<br>[username] - [profile]</p>' ) ); $cbUser = CBuser::getInstance( (int) $row->get( 'user_id' ), false ); $user = $cbUser->getUserData(); $extra = array( 'sitename' => $_CB_framework->getCfg( 'sitename' ), 'site' => $_CB_framework->getCfg( 'live_site' ), 'register' => $_CB_framework->viewUrl( 'registers', false, ( $row->get( 'code' ) ? array( 'invite_code' => $row->get( 'code' ) ) : array() ) ), 'profile' => $_CB_framework->viewUrl( 'userprofile', false, array( 'user' => (int) $row->get( 'user_id' ) ) ), 'code' => $row->get( 'code' ), 'to' => $row->get( 'to' ) ); $mailFromName = Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_from_name', null ), true, false, $extra ), GetterInterface::STRING ); $mailFromAddr = Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_from_address', null ), true, false, $extra ), GetterInterface::STRING ); $mailTo = Get::clean( $cbUser->replaceUserVars( $row->get( 'to' ), true, false, $extra ), GetterInterface::STRING ); $mailCC = Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_cc', null ), true, false, $extra ), GetterInterface::STRING ); $mailBCC = Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_bcc', null ), true, false, $extra ), GetterInterface::STRING ); $mailSubject = Get::clean( $cbUser->replaceUserVars( ( $invitePrefix . ( $row->get( 'subject' ) ? $row->get( 'subject' ) : CBTxt::T( 'Join Me!' ) ) ), true, false, $extra ), GetterInterface::STRING ); $mailBody = Get::clean( $cbUser->replaceUserVars( ( $inviteHeader . $row->get( 'body' ) . $inviteFooter ), false, false, $extra ), GetterInterface::HTML ); $mailAttachments = Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_attachments', null ), true, false, $extra ), GetterInterface::STRING ); if ( $mailTo ) { $mailTo = preg_split( ' *, *', $mailTo ); } if ( $mailCC ) { $mailCC = preg_split( ' *, *', $mailCC ); } if ( $mailBCC ) { $mailBCC = preg_split( ' *, *', $mailBCC ); } if ( $mailAttachments ) { $mailAttachments = preg_split( ' *, *', $mailAttachments ); } if ( $mailTo && $mailSubject && $mailBody ) { if ( ! $mailFromName ) { $mailFromName = $user->name; $replyToName = null; } else { $replyToName = $user->name; } if ( ! $mailFromAddr ) { $mailFromAddr = $user->email; $replyToAddr = null; } else { $replyToAddr = $user->email; } $error = null; $sent = comprofilerMail( $mailFromAddr, $mailFromName, $mailTo, $mailSubject, $mailBody, ( (int) $params->get( 'invite_editor', 2 ) >= 2 ? true : false ), $mailCC, $mailBCC, $mailAttachments, $replyToAddr, $replyToName, $error ); if ( $sent ) { return true; } else { $row->setError( ( $error ? $error : CBTxt::T( 'Mailer failed to send.' ) ) ); } } else { if ( ! $mailTo ) { $row->setError( CBTxt::T( 'To address missing.' ) ); } elseif ( ! $mailSubject ) { $row->setError( CBTxt::T( 'Subject missing.' ) ); } elseif ( ! $mailBody ) { $row->setError( CBTxt::T( 'Body missing.' ) ); } } return false; }