public static function updateUserPoints($result, $referrerid, $assignpoints, $now, $referraluserpoints, $autoapproved, $rule_plugin = '', $rule_id = '', $rule_name = '', $datareference = '', $frontmessage = '') { $app = JFactory::getApplication(); $lang = JFactory::getLanguage(); $lang->load('com_alphauserpoints', JPATH_SITE); $user = JFactory::getUser(); $username = $user->id ? $user->username : ''; $displaymsg = $result->displaymsg; $msg = str_replace('{username}', $username, $result->msg); $method = $result->method; $db = JFactory::getDBO(); // get params definitions $params = JComponentHelper::getParams('com_alphauserpoints'); $query = "SELECT id FROM #__alpha_userpoints WHERE `referreid`='{$referrerid}'"; $db->setQuery($query); $referrerUser = $db->loadResult(); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables'); $row = JTable::getInstance('userspoints'); // update points into alpha_userpoints table $row->load(intval($referrerUser)); $referraluser = $row->referraluser; $newtotal = !$referraluserpoints ? $row->points + $assignpoints : $row->points + $referraluserpoints; $row->last_update = $now; $checkWinner = 0; if ($row->max_points >= 1 && $newtotal > $row->max_points) { // Max total was reached ! //$newtotal = $row->max_points; if (AlphaUserPointsHelper::checkRuleEnabled('sysplgaup_winnernotification', 0, $referrerid)) { // get email admins in rule $query = "SELECT `content_items` FROM #__alpha_userpoints_rules WHERE `plugin_function`='sysplgaup_winnernotification'"; $db->setQuery($query); $emailadmins = $db->loadResult(); if ($autoapproved || $referraluserpoints) { AlphaUserPointsHelper::sendwinnernotification($referrerid, $assignpoints, $newtotal, $emailadmins); // Uddeim notification integration if ($params->get('sendMsgUddeim', 0)) { AlphaUserPointsHelper::sendUddeimWinnerNotification($referrerid, $assignpoints, $newtotal); } $checkWinner = 1; } } } if ($autoapproved) { if ($rule_plugin == 'sysplgaup_invitewithsuccess') { $row->referrees = $row->referrees + 1; } $row->points = $newtotal; $db->updateObject('#__alpha_userpoints', $row, 'id'); } if ($displaymsg && !$referraluserpoints) { $realcurrentreferrerid = AlphaUserPointsHelper::getAnyUserReferreID($user->id); switch ($rule_plugin) { case 'sysplgaup_bonuspoints': case 'sysplgaup_recommend': case 'sysplgaup_reader2author': case 'sysplgaup_buypointswithpaypal': case 'sysplgaup_invite': // No need congratulation... break; case 'sysplgaup_invitewithsuccess': // number points in message = assign points to new user $numpoints = AlphaUserPointsHelper::getPointsRule('sysplgaup_newregistered'); if ($numpoints && $user->id) { if ($msg != '') { $msg = str_replace('{points}', AlphaUserPointsHelper::getFPoints($numpoints), JText::_($msg)); $msg = str_replace('{newtotal}', AlphaUserPointsHelper::getFPoints($newtotal), $msg); $app->enqueueMessage($msg); } else { $app->enqueueMessage(sprintf(JText::_('AUP_CONGRATULATION'), AlphaUserPointsHelper::getFPoints($numpoints))); } } break; default: if ($referrerid == $realcurrentreferrerid && $user->id) { if ($assignpoints > 0) { if ($msg != '') { $msg = str_replace('{points}', AlphaUserPointsHelper::getFPoints($assignpoints), JText::_($msg)); $msg = str_replace('{newtotal}', AlphaUserPointsHelper::getFPoints($newtotal), $msg); $app->enqueueMessage($msg); } else { $app->enqueueMessage(sprintf(JText::_('AUP_CONGRATULATION'), AlphaUserPointsHelper::getFPoints($assignpoints))); if ($rule_plugin == 'sysplgaup_happybirthday') { $frontmessage = JText::_('AUP_HAPPYBIRTHDAY'); } } } elseif ($assignpoints < 0) { if ($msg != '') { $msg = str_replace('{points}', AlphaUserPointsHelper::getFPoints(abs($assignpoints)), JText::_($msg)); $msg = str_replace('{newtotal}', AlphaUserPointsHelper::getFPoints($newtotal), $msg); $app->enqueueMessage($msg); } else { $app->enqueueMessage(sprintf(JText::_('AUP_X_POINTS_HAS_BEEN_DEDUCTED_FROM_YOUR_ACCOUNT'), AlphaUserPointsHelper::getFPoints(abs($assignpoints)))); } } } } } if ($rule_plugin == 'sysplgaup_custom' && $datareference) { $rule_name = JText::_($datareference); } // email notification if ($result->notification && !$checkWinner) { $result->datareference = JText::_($datareference); AlphaUserPointsHelper::sendnotification($referrerid, $assignpoints, $newtotal, $result); // load external plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('alphauserpoints'); $results = $dispatcher->trigger('onSendNotificationAlphaUserPoints', array(&$result, $rule_name, $assignpoints, $newtotal, $referrerid, $user->id)); } // Uddeim notification integration if ($params->get('sendMsgUddeim', 0) && !$checkWinner) { AlphaUserPointsHelper::sendUddeimNotification($referrerid, $assignpoints, $newtotal, $rule_name); } // load external plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('alphauserpoints'); $results = $dispatcher->trigger('onUpdateAlphaUserPoints', array(&$result, $rule_name, $assignpoints, $referrerid, $user->id)); // checking rank and medals and update if necessary if ($rule_id == '') { $rule_id = AlphaUserPointsHelper::getRuleID($rule_plugin); } AlphaUserPointsHelper::checkRankMedal($referrerid, $rule_id); // referral points rule if ($referraluser != '' && $rule_plugin != 'sysplgaup_buypointswithpaypal' && $rule_plugin != 'sysplgaup_raffle' && $assignpoints > 0) { // if not already assigned $query = "SELECT * FROM #__alpha_userpoints_rules WHERE `plugin_function`='sysplgaup_referralpoints' AND `published`='1' AND (`rule_expire`>'{$now}' OR `rule_expire`='0000-00-00 00:00:00')"; $db->setQuery($query); $referralpoints = $db->loadObjectList(); if ($referralpoints) { $referraluserpoints = round($assignpoints * $referralpoints[0]->points / 100, 2); if ($referraluserpoints > 0) { AlphaUserPointsHelper::userpoints('sysplgaup_referralpoints', $referraluser, $referraluserpoints); } } } // check change user group rule //if ( $rule_plugin!='sysplgaup_changelevel1' && $rule_plugin!='sysplgaup_changelevel2' && $rule_plugin!='sysplgaup_changelevel3' ) //{ AlphaUserPointsHelper::checkChangeLevel($referrerid, AlphaUserPointsHelper::getCurrentTotalPoints($referrerid)); //} if ($frontmessage != '') { AlphaUserPointsHelper::displayMessageSystem($frontmessage); } // load external plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('alphauserpoints'); $results = $dispatcher->trigger('onAfterUpdateAlphaUserPoints', array(&$result, $rule_name, $assignpoints, $referrerid, $user->id)); // link up rule if ($result->linkup) { $plugin_function_linkup = AlphaUserPointsHelper::getPluginFunction($result->linkup); AlphaUserPointsHelper::newpoints($plugin_function_linkup, $referrerid); } }
public function sendinvite() { $app = JFactory::getApplication(); JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // active user $user = JFactory::getUser(); $db = JFactory::getDBO(); jimport('joomla.mail.helper'); $model = $this->getModel('alphauserpoints'); $view = $this->getView('invite', 'html'); $SiteName = $app->getCfg('sitename'); $MailFrom = $app->getCfg('mailfrom'); $FromName = $app->getCfg('fromname'); $jnow = JFactory::getDate(); $now = $jnow->toSql(); $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'host', 'port')); $params = $model->_getParamsAUP(); $cparams = JComponentHelper::getParams('com_alphauserpoints'); $referrerid = $model->_getReferreid(); if ($referrerid) { $link = getLinkToInvite($referrerid, $cparams->get('systemregistration')); } else { $link = $base . JRoute::_(''); } if ($params->get('userecaptcha') == 1 || $params->get('userecaptcha') == 2 && !$user->id) { require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'assets' . DS . 'recaptcha' . DS . 'recaptchalib.php'; $privatekey = $params->get('privkey'); // the response from reCAPTCHA $resp = null; // the error code from reCAPTCHA, if any $error = null; // was there a reCAPTCHA response? $recaptcha_response_field = JFactory::getApplication()->input->get('recaptcha_response_field', '', 'string'); //if ($_POST["recaptcha_response_field"]) { if ($recaptcha_response_field) { $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $recaptcha_response_field); if (!$resp->is_valid) { // set the error code so that we can display it $error = $resp->error; JError::raiseWarning(0, $error); return $this->display(); } } else { JError::raiseWarning(0, 'Captcha'); return $this->display(); } } // An array of e-mail headers we do not want to allow as input $headers = array('Content-Type:', 'MIME-Version:', 'Content-Transfer-Encoding:', 'bcc:', 'cc:'); // An array of the input fields to scan for injected headers $fields = array('mailto', 'sender', 'from', 'subject'); /* * Here is the meat and potatoes of the header injection test. We * iterate over the array of form input and check for header strings. * If we fine one, send an unauthorized header and die. */ foreach ($fields as $field) { foreach ($headers as $header) { if (strpos(@$_POST[$field], $header) !== false) { JError::raiseError(403, ''); } } } /* * Free up memory */ unset($headers, $fields); $imported_emails = $_POST['importedemails']; $other_emails = JRequest::getString('other_recipients', '', 'post'); $sender = JRequest::getString('sender', '', 'post'); // Check for a valid to address $errorMail = false; // build list emails if ($imported_emails == '' && $other_emails != '') { $emails = $other_emails; } elseif ($other_emails == '' && $imported_emails != '') { $emails = $imported_emails; } elseif ($imported_emails != '' && $other_emails != '') { $emails = $imported_emails . "," . $other_emails; } else { $emails = ""; $errorMail = JText::_('AUP_EMAIL_INVALID'); JError::raiseWarning(0, $errorMail); } $emails = @explode(',', $emails); // Check for a valid from address if (!$MailFrom || !JMailHelper::isEmailAddress($MailFrom)) { $errorMail = JText::sprintf('AUP_EMAIL_INVALID', $MailFrom); JError::raiseWarning(0, $errorMail); } if ($errorMail) { return $this->display(); } // Build the message to send $msg = JText::_('AUP_EMAIL_MSG_INVITE'); $custommessage = JRequest::getString('custommessage', '', 'post'); $formatMail = '0'; $bcc2admin = '0'; if ($params->get('templateinvite', 0)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables'); $row = JTable::getInstance('template_invite'); $row->load(intval($params->get('templateinvite'))); $subject = $row->emailsubject; $body = $row->emailbody; $body = str_replace('{name}', $sender, $body); $body = str_replace('{custom}', $custommessage, $body); $body = str_replace('{link}', $link, $body); $bcc2admin = $row->bcc2admin; $formatMail = $row->emailformat; } else { $subject = JText::_('AUP_YOUAREINVITEDTOREGISTERON') . " " . $SiteName; $body = sprintf($msg, $SiteName, $sender, $link) . " \n" . $custommessage; } // Clean the email data $subject = JMailHelper::cleanSubject($subject); //$body = JMailHelper::cleanBody($body); require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; // Limit $max = $params->get('maxemailperinvite'); $maxperday = $params->get('maxinvitesperday'); $delay = intval($params->get('delaybetweeninvites')); $counter = 0; $rule_ID = $model->_getRuleID('sysplgaup_invite'); $refer_ID = AlphaUserPointsHelper::getAnyUserReferreID($user->id); $numpoints4invite = AlphaUserPointsHelper::getPointsRule('sysplgaup_invite'); $totalpointsearned = 0; $currentmaxperday = $model->_checkCurrentMaxPerDay($rule_ID, $user->id, $referrerid, $_SERVER["REMOTE_ADDR"]); $checkdelay = 1; if ($delay) { $checkdelay = $model->_checkLastInviteForDelay($rule_ID, $user->id, $referrerid, $_SERVER["REMOTE_ADDR"], $delay); } if (!$checkdelay) { $errorTime = JText::_('AUP_DELAY_BETWEEN_INVITES_INVALID'); JError::raiseWarning(0, $errorTime); return $this->display(); } if ($currentmaxperday < $maxperday) { $mailer = JFactory::getMailer(); foreach ($emails as $email) { $aEmails[0] = $model->_extractEmailsFromString($email); $email = $aEmails[0][0]; if (JMailHelper::isEmailAddress($email)) { $mailer->setSender(array($MailFrom, $FromName)); $mailer->setSubject($subject); $mailer->isHTML((bool) $formatMail); $mailer->CharSet = "utf-8"; $mailer->setBody($body); $mailer->addRecipient($email); if ($bcc2admin) { // get all users allowed to receive e-mail system $query = "SELECT email" . " FROM #__users" . " WHERE sendEmail='1' AND block='0'"; $db->setQuery($query); $rowsAdmins = $db->loadObjectList(); foreach ($rowsAdmins as $rowsAdmin) { $mailer->addBCC($rowsAdmin->email); } } if ($mailer->Send() === true) { if ($user->id) { if (AlphaUserPointsHelper::checkRuleEnabled('sysplgaup_invite')) { // insert email for tracking $email2 = str_replace("@", " [at] ", $email); // change @ because can be display on frontend in latest activity $keyreference = AlphaUserPointsHelper::buildKeyreference('sysplgaup_invite', $email); AlphaUserPointsHelper::userpoints('sysplgaup_invite', $refer_ID, 0, $keyreference, $email2); $totalpointsearned = $totalpointsearned + $numpoints4invite; } } else { // guest user : Insert IP and email fortracking JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables'); $row = JTable::getInstance('userspointsdetails'); $row->id = NULL; $row->referreid = 'GUEST'; $row->points = 0; $row->insert_date = $now; $row->expire_date = ''; $row->rule = $rule_ID; $row->approved = 1; $row->status = 1; $row->keyreference = $_SERVER["REMOTE_ADDR"]; $row->datareference = $email; if (!$row->store()) { JError::raiseError(500, $row->getError()); } } $counter++; $currentmaxperday++; } if ($counter == $max || $currentmaxperday == $maxperday) { break; } } } if ($totalpointsearned) { $app->enqueueMessage(sprintf(JText::_('AUP_CONGRATULATION'), $totalpointsearned)); } } else { $maxperdaylimit = JText::_('AUP_MAXINVITESPERDAY') . " " . $maxperday; $app->enqueueMessage($maxperdaylimit); } switch ($counter) { case '0': $message = JText::_('AUP_NO_EMAIL_HAS_BEEN_SENT'); break; case '1': $message = JText::_('AUP_EMAIL_SENT'); break; default: $message = JText::_('AUP_EMAILS_SENT'); $message = sprintf($message, $counter); break; } $app->enqueueMessage($message); $this->setRedirect('index.php?option=com_alphauserpoints&view=invite&Itemid=' . JFactory::getApplication()->input->get('Itemid', '')); $this->redirect(); }