Пример #1
0
 function isValid($value, $required)
 {
     CFactory::load('helpers', 'validate');
     $isValid = CValidateHelper::email($value);
     if (!empty($value) && $isValid) {
         return true;
     } else {
         if (empty($value) && !$required) {
             return true;
         }
     }
     return false;
 }
Пример #2
0
 /**
  * Replaces a given link be it email or hyperlink and return the proper
  * counterparts.
  *
  * @param    $url    A valid url
  *
  * return    $link    HTML formatted codes that links to given email
  */
 public static function getHyperLink($url)
 {
     $link = JString::trim($url);
     //CFactory::load( 'helpers' , 'validate' );
     if (CValidateHelper::email($link)) {
         return self::getEmailURL($link);
     }
     if (CValidateHelper::url($link)) {
         return self::getURL($link);
     }
     // Since the link is really not a link, we just return the original format.
     return $link;
 }
Пример #3
0
 public function ajaxEmailPage($uri, $emails, $message = '')
 {
     $filter = JFilterInput::getInstance();
     $uri = $filter->clean($uri, 'string');
     $emails = $filter->clean($emails, 'string');
     $message = $filter->clean($message, 'string');
     $message = stripslashes($message);
     $mainframe =& JFactory::getApplication();
     $bookmarks = CFactory::getBookmarks($uri);
     $mailqModel = CFactory::getModel('mailq');
     $config = CFactory::getConfig();
     $response = new JAXResponse();
     if (empty($emails)) {
         $content = '<div>' . JText::_('COM_COMMUNITY_SHARE_INVALID_EMAIL') . '</div>';
         $actions = '<input type="button" class="button" onclick="joms.bookmarks.show(\'' . $uri . '\');" value="' . JText::_('COM_COMMUNITY_GO_BACK_BUTTON') . '"/>';
     } else {
         $emails = explode(',', $emails);
         $errors = array();
         // Add notification
         CFactory::load('libraries', 'notification');
         foreach ($emails as $email) {
             $email = JString::trim($email);
             CFactory::load('helpers', 'validate');
             if (!empty($email) && CValidateHelper::email($email)) {
                 $params = new CParameter('');
                 $params->set('uri', $uri);
                 $params->set('message', $message);
                 CNotificationLibrary::add('etype_system_bookmarks_email', '', $email, JText::sprintf('COM_COMMUNITY_SHARE_EMAIL_SUBJECT', $config->get('sitename')), '', 'bookmarks', $params);
             } else {
                 // If there is errors with email, inform the user.
                 $errors[] = $email;
             }
         }
         if ($errors) {
             $content = '<div>' . JText::_('COM_COMMUNITY_EMAILS_ARE_INVALID') . '</div>';
             foreach ($errors as $error) {
                 $content .= '<div style="font-weight:700;color: red;">' . $error . '</span>';
             }
             $actions = '<input type="button" class="button" onclick="joms.bookmarks.show(\'' . $uri . '\');" value="' . JText::_('COM_COMMUNITY_GO_BACK_BUTTON') . '"/>';
         } else {
             $content = '<div>' . JText::_('COM_COMMUNITY_EMAIL_SENT_TO_RECIPIENTS') . '</div>';
             $actions = '<input type="button" class="button" onclick="cWindowHide();" value="' . JText::_('COM_COMMUNITY_DONE_BUTTON') . '"/>';
         }
     }
     $response->addAssign('cwin_logo', 'innerHTML', JText::_('COM_COMMUNITY_SHARE_THIS'));
     $response->addScriptCall('cWindowAddContent', $content, $actions);
     return $response->sendResponse();
 }
Пример #4
0
 public function isValid($value, $required)
 {
     CFactory::load('helpers', 'validate');
     $isValid = CValidateHelper::email($value);
     if (!empty($value) && !$isValid) {
         return false;
     }
     //validate string length
     if (!$this->validLength($value)) {
         return false;
     }
     //validate allowed domain
     if (isset($this->params)) {
         $allowed = $this->params->get('allowed');
         if ($allowed) {
             $delimiter = ';';
             $allowed_list = explode($delimiter, $allowed);
             $valid = false;
             if (count($allowed_list) > 0) {
                 foreach ($allowed_list as $domain) {
                     if (CValidateHelper::domain($value, $domain)) {
                         $valid = true;
                     }
                 }
             }
             if (!$valid) {
                 return false;
             }
         }
     }
     //validate backlist domain
     if (isset($this->params)) {
         $blacklist = $this->params->get('blacklist');
         if ($blacklist) {
             $delimiter = ';';
             $blacklists = explode($delimiter, $blacklist);
             if (count($blacklists) > 0) {
                 foreach ($blacklists as $domain) {
                     if (CValidateHelper::domain($value, $domain)) {
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
Пример #5
0
 public function ajaxEmailPage($uri, $emails, $message = '')
 {
     $filter = JFilterInput::getInstance();
     $uri = $filter->clean($uri, 'string');
     $emails = $filter->clean($emails, 'string');
     $message = $filter->clean($message, 'string');
     $message = stripslashes($message);
     $mainframe = JFactory::getApplication();
     $bookmarks = CFactory::getBookmarks($uri);
     $mailqModel = CFactory::getModel('mailq');
     $config = CFactory::getConfig();
     $response = new JAXResponse();
     $json = array();
     if (empty($emails)) {
         $json['error'] = JText::_('COM_COMMUNITY_SHARE_INVALID_EMAIL');
     } else {
         $emails = explode(',', $emails);
         $errors = array();
         // Add notification
         //CFactory::load( 'libraries' , 'notification' );
         foreach ($emails as $email) {
             $email = JString::trim($email);
             if (!empty($email) && CValidateHelper::email($email)) {
                 $params = new CParameter('');
                 $params->set('uri', $uri);
                 $params->set('message', $message);
                 CNotificationLibrary::add('system_bookmarks_email', '', $email, JText::sprintf('COM_COMMUNITY_SHARE_EMAIL_SUBJECT', $config->get('sitename')), '', 'bookmarks', $params);
             } else {
                 // If there is errors with email, inform the user.
                 $errors[] = $email;
             }
         }
         if ($errors) {
             $content = '<div>' . JText::_('COM_COMMUNITY_EMAILS_ARE_INVALID') . '</div>';
             foreach ($errors as $error) {
                 $content .= '<div style="font-weight:bold; color:red;">' . $error . '</div>';
             }
             $json['error'] = $content;
         } else {
             $content = JText::_('COM_COMMUNITY_EMAIL_SENT_TO_RECIPIENTS');
             $json['message'] = $content;
         }
     }
     die(json_encode($json));
 }
Пример #6
0
 public function save()
 {
     // Check for request forgeries
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN'));
     JFactory::getLanguage()->load(COM_USER_NAME);
     $user = JFactory::getUser();
     $userid = $jinput->post->get('id', 0, 'int');
     // preform security checks
     if ($user->get('id') == 0 || $userid == 0 || $userid != $user->get('id')) {
         echo $this->blockUnregister();
         return;
     }
     $username = $user->get('username');
     //if joomla settings allow change login name
     if (JComponentHelper::getParams('com_users')->get('change_login_name')) {
         $username = $jinput->get('username');
     }
     //clean request
     $post = JRequest::get('post');
     $post['username'] = $username;
     $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
     //check email
     $post['email'] = $post['jsemail'];
     $email = $post['email'];
     $emailPass = $post['emailpass'];
     $modelReg = $this->getModel('register');
     //CFactory::load( 'helpers', 'validate' );
     if (!CValidateHelper::email($email)) {
         $msg = JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_INVALID', $email);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     if (!empty($email) && $email != $emailPass && $modelReg->isEmailExists(array('email' => $email))) {
         $msg = JText::sprintf('COM_COMMUNITY_EMAIL_EXIST', $email);
         $msg = stripslashes($msg);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     // get the redirect
     $return = CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false);
     // do a password safety check
     $changePassword = false;
     if (JString::strlen($post['jspassword']) || JString::strlen($post['jspassword2'])) {
         // so that "0" can be used as password e.g.
         if ($post['jspassword'] != $post['jspassword2']) {
             $msg = JText::_('PASSWORDS_DO_NOT_MATCH');
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
             return false;
         } else {
             $changePassword = true;
             //Jooomla 3.2.0 fix. TO be remove in future
             if (version_compare(JVERSION, '3.2.0', '>=')) {
                 $salt = JUserHelper::genRandomPassword(32);
                 $crypt = JUserHelper::getCryptedPassword($post['jspassword'], $salt);
                 $password = $crypt . ':' . $salt;
             } else {
                 // Don't re-encrypt the password
                 // JUser bind has encrypted the password
                 if (class_exists(JUserHelper) && method_exists(JUserHelper, 'hashpassword')) {
                     $password = JUserHelper::hashPassword($post['jspassword']);
                 } else {
                     $password = $post['jspassword'];
                 }
             }
         }
     }
     // Handle the two factor authentication setup
     $data = $post['jform'];
     if (array_key_exists('twofactor', $data)) {
         if (!class_exists('UsersModelUser')) {
             require JPATH_ROOT . '/administrator/components/com_users/models/user.php';
         }
         $model = new UsersModelUser();
         $twoFactorMethod = $data['twofactor']['method'];
         $userId = CFactory::getUser()->id;
         // Get the current One Time Password (two factor auth) configuration
         $otpConfig = $model->getOtpConfig($userId);
         if ($twoFactorMethod != 'none') {
             // Run the plugins
             FOFPlatform::getInstance()->importPlugin('twofactorauth');
             $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($twoFactorMethod));
             // Look for a valid reply
             foreach ($otpConfigReplies as $reply) {
                 if (!is_object($reply) || empty($reply->method) || $reply->method != $twoFactorMethod) {
                     continue;
                 }
                 $otpConfig->method = $reply->method;
                 $otpConfig->config = $reply->config;
                 break;
             }
             // Save OTP configuration.
             $model->setOtpConfig($userId, $otpConfig);
             // Generate one time emergency passwords if required (depleted or not set)
             if (empty($otpConfig->otep)) {
                 $oteps = $model->generateOteps($userId);
             }
         } else {
             $otpConfig->method = 'none';
             $otpConfig->config = array();
             $model->setOtpConfig($userId, $otpConfig);
         }
         // Unset the raw data
         unset($data['twofactor']);
     }
     // we don't want users to edit certain fields so we will unset them
     unset($post['gid']);
     unset($post['block']);
     unset($post['usertype']);
     unset($post['registerDate']);
     unset($post['activation']);
     //update CUser param 1st so that the new value will not be replace wif the old one.
     $my = CFactory::getUser();
     $params = $my->getParams();
     $postvars = $post['daylightsavingoffset'];
     $params->set('daylightsavingoffset', $postvars);
     // Store FB prefernce o ly FB connect data
     $connectModel = CFactory::getModel('Connect');
     if ($connectModel->isAssociated($user->id)) {
         $postvars = !empty($post['postFacebookStatus']) ? 1 : 0;
         $my->_cparams->set('postFacebookStatus', $postvars);
     }
     if ($changePassword) {
         $my->set('password', $password);
     }
     /* Save for CUser */
     $my->save();
     $model = CFactory::getModel('profile');
     $editSuccess = true;
     $msg = JText::_('COM_COMMUNITY_SETTINGS_SAVED');
     $jUser = JFactory::getUser();
     // Bind the form fields to the user table
     if (!$jUser->bind($post)) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     // Store the web link table to the database
     if (!$jUser->save()) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     if ($editSuccess) {
         /* Update Joomla! User session */
         $session = JFactory::getSession();
         $session->set('user', $jUser);
         // User with FB Connect, store post preference
         //execute the trigger
         $appsLib = CAppPlugins::getInstance();
         $appsLib->loadApplications();
         $userRow = array();
         $userRow[] = $jUser;
         $appsLib->triggerEvent('onUserDetailsUpdate', $userRow);
     }
     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=edit', false), $msg);
 }
Пример #7
0
 /**
  * 	Checks the validity of the email via AJAX calls
  * */
 public function ajaxCheckEmail($email)
 {
     $response = new JAXResponse();
     $model = $this->getModel('user');
     $filter = JFilterInput::getInstance();
     $email = $filter->clean($email, 'string');
     // @rule: Check email format
     //CFactory::load( 'helpers' , 'validate' );
     $valid = CValidateHelper::email($email);
     if (!$valid && !empty($email) || empty($email)) {
         $response->addScriptCall('joms.jQuery("#newemail").addClass("invalid");');
         $response->addScriptCall('joms.jQuery("#error-newemail").show();');
         $response->addScriptCall('joms.jQuery("#error-newemail").html("' . JText::sprintf('COM_COMMUNITY_INVALID_FB_EMAIL', htmlspecialchars($email)) . '");');
         return $response->sendResponse();
     }
     $exists = $model->userExistsbyEmail($email);
     if ($exists) {
         $response->addScriptCall('joms.jQuery("#newemail").addClass("invalid");');
         $response->addScriptCall('joms.jQuery("#error-newemail").show();');
         $response->addScriptCall('joms.jQuery("#error-newemail").html("' . JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_EXIST', htmlspecialchars($email)) . '");');
         return $response->sendResponse();
     }
     $response->addScriptCall('joms.jQuery("#newemail").removeClass("invalid");');
     $response->addScriptCall('joms.jQuery("#error-newemail").html("&nbsp");');
     $response->addScriptCall('joms.jQuery("#error-newemail").hide();');
     return $response->sendResponse();
 }
Пример #8
0
 public function save()
 {
     // Check for request forgeries
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN'));
     JFactory::getLanguage()->load(COM_USER_NAME);
     $user = JFactory::getUser();
     $userid = $jinput->post->get('id', 0, 'int');
     // preform security checks
     if ($user->get('id') == 0 || $userid == 0 || $userid != $user->get('id')) {
         echo $this->blockUnregister();
         return;
     }
     $username = $user->get('username');
     //clean request
     $post = JRequest::get('post');
     $post['username'] = $username;
     $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
     //check email
     $post['email'] = $post['jsemail'];
     $email = $post['email'];
     $emailPass = $post['emailpass'];
     $modelReg = $this->getModel('register');
     //CFactory::load( 'helpers', 'validate' );
     if (!CValidateHelper::email($email)) {
         $msg = JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_INVALID', $email);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     if (!empty($email) && $email != $emailPass && $modelReg->isEmailExists(array('email' => $email))) {
         $msg = JText::sprintf('COM_COMMUNITY_EMAIL_EXIST', $email);
         $msg = stripslashes($msg);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     // get the redirect
     $return = CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false);
     // do a password safety check
     $changePassword = false;
     if (JString::strlen($post['jspassword']) || JString::strlen($post['jspassword2'])) {
         // so that "0" can be used as password e.g.
         if ($post['jspassword'] != $post['jspassword2']) {
             $msg = JText::_('PASSWORDS_DO_NOT_MATCH');
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
             return false;
         } else {
             $changePassword = true;
             //Jooomla 3.2.0 fix. TO be remove in future
             if (version_compare(JVERSION, '3.2.0', '>=')) {
                 $salt = JUserHelper::genRandomPassword(32);
                 $crypt = JUserHelper::getCryptedPassword($post['jspassword'], $salt);
                 $password = $crypt . ':' . $salt;
             } else {
                 // Don't re-encrypt the password
                 // JUser bind has encrypted the password
                 if (class_exists(JUserHelper) && method_exists(JUserHelper, 'hashpassword')) {
                     $password = JUserHelper::hashPassword($post['jspassword']);
                 } else {
                     $password = $post['jspassword'];
                 }
             }
         }
     }
     // we don't want users to edit certain fields so we will unset them
     unset($post['gid']);
     unset($post['block']);
     unset($post['usertype']);
     unset($post['registerDate']);
     unset($post['activation']);
     //update CUser param 1st so that the new value will not be replace wif the old one.
     $my = CFactory::getUser();
     $params = $my->getParams();
     $postvars = $post['daylightsavingoffset'];
     $params->set('daylightsavingoffset', $postvars);
     // Store FB prefernce o ly FB connect data
     $connectModel = CFactory::getModel('Connect');
     if ($connectModel->isAssociated($user->id)) {
         $postvars = !empty($post['postFacebookStatus']) ? 1 : 0;
         $my->_cparams->set('postFacebookStatus', $postvars);
     }
     if ($changePassword) {
         $my->set('password', $password);
     }
     /* Save for CUser */
     $my->save();
     $model = CFactory::getModel('profile');
     $editSuccess = true;
     $msg = JText::_('COM_COMMUNITY_SETTINGS_SAVED');
     $jUser = JFactory::getUser();
     // Bind the form fields to the user table
     if (!$jUser->bind($post)) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     // Store the web link table to the database
     if (!$jUser->save()) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     if ($editSuccess) {
         /* Update Joomla! User session */
         $session = JFactory::getSession();
         $session->set('user', $jUser);
         // User with FB Connect, store post preference
         //execute the trigger
         $appsLib = CAppPlugins::getInstance();
         $appsLib->loadApplications();
         $userRow = array();
         $userRow[] = $jUser;
         $appsLib->triggerEvent('onUserDetailsUpdate', $userRow);
     }
     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=edit', false), $msg);
 }
Пример #9
0
 /**
  * Return the 'about us' html block
  */
 function _getProfileHTML(&$profile)
 {
     $tmpl = new CTemplate();
     $profileModel = CFactory::getModel('profile');
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $userid = JRequest::getVar('userid', $my->id);
     $user = CFactory::getUser($userid);
     $profileField =& $profile['fields'];
     CFactory::load('helpers', 'linkgenerator');
     CFactory::load('helpers', 'validate');
     // Allow search only on profile with type text and not empty
     foreach ($profileField as $key => $val) {
         foreach ($profileField[$key] as $pKey => $pVal) {
             $field =& $profileField[$key][$pKey];
             // Remove this info if we don't want empty field displayed
             if (!$config->get('showemptyfield') && (empty($field['value']) && $field['value'] != "0")) {
                 unset($profileField[$key][$pKey]);
             } else {
                 if (!empty($field['value']) || $field['value'] == "0") {
                     switch ($field['type']) {
                         case 'text':
                             if (CValidateHelper::email($field['value'])) {
                                 $profileField[$key][$pKey]['value'] = CLinkGeneratorHelper::getEmailURL($field['value']);
                             } else {
                                 if (CValidateHelper::url($field['value'])) {
                                     $profileField[$key][$pKey]['value'] = CLinkGeneratorHelper::getHyperLink($field['value']);
                                 } else {
                                     if (!CValidateHelper::phone($field['value']) && !empty($field['fieldcode'])) {
                                         $profileField[$key][$pKey]['searchLink'] = CRoute::_('index.php?option=com_community&view=search&task=field&' . $field['fieldcode'] . '=' . urlencode($field['value']));
                                     }
                                 }
                             }
                             break;
                         case 'select':
                         case 'singleselect':
                         case 'radio':
                         case 'checkbox':
                             $profileField[$key][$pKey]['searchLink'] = array();
                             $checkboxArray = explode(',', $field['value']);
                             foreach ($checkboxArray as $item) {
                                 if (!empty($item)) {
                                     $profileField[$key][$pKey]['searchLink'][$item] = CRoute::_('index.php?option=com_community&view=search&task=field&' . $field['fieldcode'] . '=' . urlencode($item) . '&type=checkbox');
                                 }
                             }
                             break;
                         case 'country':
                             $profileField[$key][$pKey]['searchLink'] = CRoute::_('index.php?option=com_community&view=search&task=field&' . $field['fieldcode'] . '=' . urlencode($field['value']));
                             break;
                         default:
                             break;
                     }
                 }
             }
         }
     }
     CFactory::load('libraries', 'profile');
     $tmpl->set('profile', $profile);
     $tmpl->set('isMine', COwnerHelper::isMine($my->id, $user->id));
     return $tmpl->fetch('profile.about');
 }
Пример #10
0
 /**
  *	Adds notification data into the mailq table
  **/
 public function add($command, $actorId, $recipients, $subject, $body, $templateFile = '', $mailParams = '', $sendEmail = true, $favicon = '')
 {
     CFactory::load('helpers', 'validate');
     // Need to make sure actor is NULL, so default user will be returned
     // from getUser
     if (empty($actorId)) {
         $actorId = null;
     }
     $mailq = CFactory::getModel('Mailq');
     $actor = CFactory::getUser($actorId);
     $config = CFactory::getConfig();
     if (!is_array($recipients)) {
         $recipientsArray = array();
         $recipientsArray[] = $recipients;
     } else {
         $recipientsArray = $recipients;
     }
     $contents = '';
     // If template file is given, we shall extract the email from the template file.
     if (!empty($templateFile)) {
         $tmpl = new CTemplate();
         preg_match('/email/i', $templateFile, $matches);
         if (empty($matches)) {
             $templateFile = 'email.' . $templateFile;
             $templateFile .= $config->get('htmlemail') ? '.html' : '.text';
         }
         if (is_object($mailParams)) {
             $dataArray = $mailParams->toArray();
             foreach ($dataArray as $key => $value) {
                 $tmpl->set($key, $value);
             }
         } elseif (is_array($mailParams)) {
             foreach ($mailParams as $key => $val) {
                 $tmpl->set($key, $val);
             }
         }
         $contents = $tmpl->fetch($templateFile);
     } else {
         $contents = $body;
     }
     $cmdData = explode('.', $command);
     // check for privacy setting for each user
     foreach ($recipientsArray as $recipient) {
         //we process the receipient emails address differently from the receipient id.
         $recipientEmail = '';
         $recipientName = '';
         $sendIt = false;
         if (CValidateHelper::email($recipient)) {
             // Check if the recipient email same with actor email
             $self = self::filterActor($actorId, $recipient);
             // If same, skip to next email
             if ($self) {
                 continue;
             }
             $recipientName = '';
             $sendIt = true;
             $recipientEmail = $recipient;
         } else {
             $userTo = CFactory::getUser($recipient);
             // Check if the recipient email same with actor email
             $self = self::filterActor($actorId, $userTo->email);
             // If same, skip to next email
             if ($self) {
                 continue;
             }
             $params = $userTo->getParams();
             $recipientName = $userTo->getDisplayName();
             $recipientEmail = $userTo->email;
             $sendIt = false;
             switch ($cmdData[0]) {
                 case 'inbox':
                 case 'photos':
                 case 'groups':
                 case 'events':
                 case 'friends':
                 case 'profile':
                     $sendIt = $params->get('notifyEmailSystem');
                     break;
                 case 'system':
                 default:
                     $sendIt = true;
                     break;
             }
         }
         if ($sendIt) {
             // Porcess the message and title
             $search = array('{actor}', '{target}');
             $replace = array($actor->getDisplayName(), $recipientName);
             $subject = JString::str_ireplace($search, $replace, $subject);
             $body = JString::str_ireplace($search, $replace, $contents);
             $mailq->add($recipientEmail, $subject, $body, $templateFile, $mailParams);
         }
     }
 }
Пример #11
0
 public function save()
 {
     // Check for request forgeries
     $mainframe =& JFactory::getApplication();
     JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN'));
     JFactory::getLanguage()->load(COM_USER_NAME);
     $user =& JFactory::getUser();
     $userid = JRequest::getVar('id', 0, 'post', 'int');
     // preform security checks
     if ($user->get('id') == 0 || $userid == 0 || $userid != $user->get('id')) {
         echo $this->blockUnregister();
         return;
     }
     $username = $user->get('username');
     //clean request
     $post = JRequest::get('post');
     $post['username'] = $username;
     $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
     //check email
     $email = $post['email'];
     $emailPass = $post['emailpass'];
     $modelReg =& $this->getModel('register');
     CFactory::load('helpers', 'validate');
     if (!CValidateHelper::email($email)) {
         $msg = JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_INVALID', $email);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     if (!empty($email) && $email != $emailPass && $modelReg->isEmailExists(array('email' => $email))) {
         $msg = JText::sprintf('COM_COMMUNITY_EMAIL_EXIST', $email);
         $msg = stripslashes($msg);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     // get the redirect
     $return = CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false);
     // do a password safety check
     if (JString::strlen($post['password']) || JString::strlen($post['password2'])) {
         // so that "0" can be used as password e.g.
         if ($post['password'] != $post['password2']) {
             $msg = JText::_('PASSWORDS_DO_NOT_MATCH');
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
             return false;
         }
     }
     // we don't want users to edit certain fields so we will unset them
     unset($post['gid']);
     unset($post['block']);
     unset($post['usertype']);
     unset($post['registerDate']);
     unset($post['activation']);
     //update CUser param 1st so that the new value will not be replace wif the old one.
     $my = CFactory::getUser();
     $params =& $my->getParams();
     $postvars = $post['daylightsavingoffset'];
     $params->set('daylightsavingoffset', $postvars);
     // Store FB prefernce o ly FB connect data
     $connectModel = CFactory::getModel('Connect');
     if ($connectModel->isAssociated($user->id)) {
         $postvars = !empty($post['postFacebookStatus']) ? 1 : 0;
         $my->_cparams->set('postFacebookStatus', $postvars);
     }
     $jConfig =& JFactory::getConfig();
     $model = CFactory::getModel('profile');
     $editSuccess = true;
     $msg = JText::_('COM_COMMUNITY_SETTINGS_SAVED');
     $jUser =& JFactory::getUser();
     $my->save('params');
     //print_r($my);exit;
     // Bind the form fields to the user table
     if (!$jUser->bind($post)) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     //this is silly, in Joomla 1.6, in order to preserve the user group, we need to change the JUser's Groups array to contain group ID instead of name
     if (property_exists($jUser, 'groups')) {
         foreach ($jUser->groups as $groupid => $groupname) {
             $jUser->groups[$groupid] = $groupid;
         }
     }
     // Store the web link table to the database
     if (!$jUser->save()) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     if ($editSuccess) {
         $session =& JFactory::getSession();
         $session->set('user', $jUser);
         // User with FB Connect, store post preference
         //execute the trigger
         $appsLib =& CAppPlugins::getInstance();
         $appsLib->loadApplications();
         $userRow = array();
         $userRow[] = $jUser;
         $appsLib->triggerEvent('onUserDetailsUpdate', $userRow);
     }
     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg);
 }
Пример #12
0
 /**
  *	Checks the validity of the email via AJAX calls
  **/
 public function ajaxCheckEmail($email)
 {
     $response = new JAXResponse();
     $model =& $this->getModel('user');
     // @rule: Check email format
     CFactory::load('helpers', 'validate');
     $valid = CValidateHelper::email($email);
     if (!$valid && !empty($email) || empty($email)) {
         $response->addScriptCall('joms.jQuery("#newemail").addClass("invalid");');
         $response->addScriptCall('joms.jQuery("#error-newemail").show();');
         $response->addScriptCall('joms.jQuery("#error-newemail").html("' . JText::sprintf('CC INVALID FB EMAIL', htmlspecialchars($email)) . '");');
         return $response->sendResponse();
     }
     $exists = $model->userExistsbyEmail($email);
     if ($exists) {
         $response->addScriptCall('joms.jQuery("#newemail").addClass("invalid");');
         $response->addScriptCall('joms.jQuery("#error-newemail").show();');
         $response->addScriptCall('joms.jQuery("#error-newemail").html("' . JText::sprintf('CC INVITE EMAIL EXIST', htmlspecialchars($email)) . '");');
         return $response->sendResponse();
     }
     $response->addScriptCall('joms.jQuery("#newemail").removeClass("invalid");');
     $response->addScriptCall('joms.jQuery("#error-newemail").html("&nbsp");');
     $response->addScriptCall('joms.jQuery("#error-newemail").hide();');
     return $response->sendResponse();
 }
Пример #13
0
 /**
  * Return the 'about us' html block
  */
 private function _getProfileHTML(&$profile)
 {
     $tmpl = new CTemplate();
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $profileModel = CFactory::getModel('profile');
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $userid = $jinput->get('userid', $my->id, 'INT');
     $user = CFactory::getUser($userid);
     $profileField = $profile['fields'];
     $isAdmin = COwnerHelper::isCommunityAdmin();
     // Allow search only on profile with type text and not empty
     foreach ($profileField as $key => $val) {
         foreach ($profileField[$key] as $pKey => $pVal) {
             $field = $profileField[$key][$pKey];
             //check for admin only fields
             if (!$isAdmin && $field['visible'] == 2) {
                 unset($profileField[$key][$pKey]);
             } else {
                 // Remove this info if we don't want empty field displayed
                 if (!$config->get('showemptyfield') && (empty($field['value']) && $field['value'] != "0")) {
                     unset($profileField[$key][$pKey]);
                 } else {
                     if ((!empty($field['value']) || $field['value'] == "0") && $field['searchable']) {
                         switch ($field['type']) {
                             case 'birthdate':
                                 $params = new CParameter($field['params']);
                                 $format = $params->get('display');
                                 if ($format == 'age') {
                                     $profileField[$key][$pKey]['name'] = JText::_('COM_COMMUNITY_AGE');
                                 }
                                 break;
                             case 'text':
                                 if (CValidateHelper::email($field['value'])) {
                                     $profileField[$key][$pKey]['value'] = CLinkGeneratorHelper::getEmailURL($field['value']);
                                 } else {
                                     if (CValidateHelper::url($field['value'])) {
                                         $profileField[$key][$pKey]['value'] = CLinkGeneratorHelper::getHyperLink($field['value']);
                                     } else {
                                         if (!CValidateHelper::phone($field['value']) && !empty($field['fieldcode'])) {
                                             $profileField[$key][$pKey]['searchLink'] = CRoute::_('index.php?option=com_community&view=search&task=field&' . $field['fieldcode'] . '=' . urlencode($field['value']));
                                         }
                                     }
                                 }
                                 break;
                             case 'select':
                             case 'singleselect':
                                 $profileField[$key][$pKey]['searchLink'] = CRoute::_('index.php?option=com_community&view=search&task=field&' . $field['fieldcode'] . '=' . urlencode($field['value']) . '&type=' . $field['type']);
                                 $profileField[$key][$pKey]['value'] = JText::_($field['value']);
                                 break;
                             case 'radio':
                             case 'checkbox':
                                 $profileField[$key][$pKey]['searchLink'] = array();
                                 $checkboxArray = explode(',', $field['value']);
                                 foreach ($checkboxArray as $item) {
                                     if (!empty($item)) {
                                         $profileField[$key][$pKey]['searchLink'][$item] = CRoute::_('index.php?option=com_community&view=search&task=field&' . $field['fieldcode'] . '=' . urlencode($item) . '&type=' . $field['type']);
                                     }
                                 }
                                 break;
                             case 'country':
                                 $lang = JFactory::getLanguage();
                                 $lang->load('com_community.country');
                                 $profileField[$key][$pKey]['searchLink'] = CRoute::_('index.php?option=com_community&view=search&task=field&' . $field['fieldcode'] . '=' . urlencode(JText::_($field['value'])));
                                 $profileField[$key][$pKey]['value'] = JText::_($field['value']);
                                 break;
                             case 'gender':
                                 $profileField[$key][$pKey]['searchLink'] = CRoute::_('index.php?option=com_community&view=search&task=field&' . $field['fieldcode'] . '=' . urlencode($field['value']));
                                 break;
                             default:
                                 break;
                         }
                     }
                 }
             }
         }
     }
     $profile['fields'] = $profileField;
     $html = $tmpl->set('profile', $profile)->set('isMine', COwnerHelper::isMine($my->id, $user->id))->fetch('profile.about');
     return $html;
 }
Пример #14
0
 /**
  * 	Adds notification data into the mailq table
  * */
 public static function addMultiple($command, $actorId, $recipients, $subject, $body, $templateFile = '', $mailParams = '', $sendEmail = true, $favicon = '')
 {
     //CFactory::load( 'helpers' , 'validate' );
     // Need to make sure actor is NULL, so default user will be returned
     // from getUser
     if (empty($actorId)) {
         $actorId = null;
     }
     $mailq = CFactory::getModel('Mailq');
     $actor = CFactory::getUser($actorId);
     $config = CFactory::getConfig();
     if (!is_array($recipients)) {
         $recipientsArray = array();
         $recipientsArray[] = $recipients;
     } else {
         $recipientsArray = $recipients;
     }
     $contents = '';
     // If template file is given, we shall extract the email from the template file.
     if (!empty($templateFile)) {
         $tmpl = new CTemplate();
         preg_match('/email/i', $templateFile, $matches);
         if (empty($matches)) {
             $templateFile = 'email.' . $templateFile;
             $templateFile .= $config->get('htmlemail') ? '.html' : '.text';
         }
         if (is_object($mailParams)) {
             $dataArray = $mailParams->toArray();
             foreach ($dataArray as $key => $value) {
                 $tmpl->set($key, $value);
             }
         } elseif (is_array($mailParams)) {
             foreach ($mailParams as $key => $val) {
                 $tmpl->set($key, $val);
             }
         }
         $contents = $tmpl->fetch($templateFile);
     } else {
         $contents = $body;
     }
     $cmdData = explode('_', $command);
     //check and add some default tags to params
     if (is_object($mailParams)) {
         if (is_null($mailParams->get('actor', null))) {
             $mailParams->set('actor', $actor->getDisplayName());
         }
         if (is_null($mailParams->get('actor_url', null))) {
             $mailParams->set('actor_url', 'index.php?option=com_community&view=profile&userid=' . $actor->id);
         }
     }
     $notificationTypes = new CNotificationTypes();
     if (empty($recipientsArray)) {
         return;
     }
     //prevent sending duplicate notification to the same users
     $recipientsArray = array_unique($recipientsArray);
     // check for privacy setting for each user
     foreach ($recipientsArray as $recipient) {
         //we process the receipient emails address differently from the receipient id.
         $recipientEmail = '';
         $recipientName = '';
         $sendIt = false;
         if (CValidateHelper::email($recipient)) {
             // Check if the recipient email same with actor email
             $self = self::filterActor($actorId, $recipient);
             // If same, skip to next email
             if ($self) {
                 continue;
             }
             $recipientName = '';
             $sendIt = true;
             $recipientEmail = $recipient;
         } else {
             $userTo = CFactory::getUser($recipient);
             // Check if the recipient email same with actor email
             $self = self::filterActor($actorId, $userTo->email);
             // If same, skip to next email
             if ($self) {
                 continue;
             }
             $params = $userTo->getParams();
             $recipientName = $userTo->getDisplayName();
             $recipientEmail = $userTo->email;
             $sendIt = false;
             if (isset($cmdData[1])) {
                 switch ($cmdData[0]) {
                     case 'inbox':
                     case 'photos':
                     case 'groups':
                     case 'events':
                     case 'friends':
                     case 'profile':
                         //							$sendIt	= $params->get('notifyEmailSystem');
                         //							break;
                     //							$sendIt	= $params->get('notifyEmailSystem');
                     //							break;
                     case 'system':
                     default:
                         $sendIt = true;
                         break;
                 }
             }
             //add global notification
             $notifType = $notificationTypes->getType('', $command);
             $type = $notifType->requiredAction ? '1' : '0';
             $model = CFactory::getModel('Notification');
             $model->add($actorId, $recipient, $subject, CNotificationTypesHelper::convertNotifId($command), $type, $mailParams);
         }
         if ($sendIt) {
             // Porcess the message and title
             $search = array('{actor}', '{target}');
             $replace = array($actor->getDisplayName(), $recipientName);
             $emailSubject = CString::str_ireplace($search, $replace, $subject);
             $body = CString::str_ireplace($search, $replace, $contents);
             //inject params value to subject
             $params = is_object($mailParams) && method_exists($mailParams, 'toString') ? $mailParams->toString() : '';
             $emailSubject = CContentHelper::injectTags($emailSubject, $params, false);
             $mailq->addMultiple($recipientEmail, $emailSubject, $body, $templateFile, $mailParams, 0, CNotificationTypesHelper::convertEmailId($command));
         }
     }
     /* have done adding multiple than now do send */
     $mailq->send();
 }
Пример #15
0
 /**
  * Search for people
  * @param query	string	people's name to seach for
  */
 public function searchPeople($query, $avatarOnly = '', $friendId = 0)
 {
     $db = $this->getDBO();
     $config = CFactory::getConfig();
     $filter = array();
     $data = array();
     $isEmail = false;
     //select only non empty field
     foreach ($query as $key => $value) {
         if (!empty($query[$key])) {
             $data[$key] = $value;
         }
     }
     // build where condition
     $filterField = array();
     if (isset($data['q'])) {
         $value = $data['q'];
         //CFactory::load( 'helpers' , 'validate' );
         if (CValidateHelper::email(JString::trim($value))) {
             $isEmail = true;
             if ($config->get('privacy_search_email') != 2) {
                 $filter[] = $db->quoteName('email') . '=' . $db->Quote($value);
             }
         } else {
             $nameType = $db->quoteName($config->get('displayname'));
             $filter[] = 'UCASE(' . $nameType . ') LIKE UCASE(' . $db->Quote('%' . $value . '%') . ')';
         }
     }
     $limit = $this->getState('limit');
     $limitstart = $this->getState('limitstart');
     $finalResult = array();
     $total = 0;
     if (count($filter) > 0 || count($filterField > 0)) {
         // Perform the simple search
         $basicResult = null;
         if (!empty($filter) && count($filter) > 0) {
             if ($friendId != 0) {
                 $query = 'SELECT b.' . $db->quoteName('friends') . ' FROM ' . $db->quoteName('#__community_users') . ' b';
                 $query .= ' WHERE b.' . $db->quoteName('userid') . ' = ' . $db->Quote($friendId);
                 $db->setQuery($query);
                 $friendListId = $db->loadResult();
                 $friendListQuery = ' AND ' . $db->quoteName('id') . ' IN (' . $friendListId . ')';
             }
             $filterquery = '';
             if (!$config->get('privacy_show_admins')) {
                 $userModel = CFactory::getModel('User');
                 $tmpAdmins = $userModel->getSuperAdmins();
                 $admins = array();
                 $filterquery .= ' AND b.' . $db->quoteName('id') . ' NOT IN(';
                 for ($i = 0; $i < count($tmpAdmins); $i++) {
                     $admin = $tmpAdmins[$i];
                     $filterquery .= $db->Quote($admin->id);
                     $filterquery .= $i < count($tmpAdmins) - 1 ? ',' : '';
                 }
                 $filterquery .= ')';
             }
             $query = 'SELECT distinct b.' . $db->quoteName('id') . ' FROM ' . $db->quoteName('#__users') . ' b';
             $query .= ' INNER JOIN ' . $db->quoteName('#__community_users') . ' AS c ON b.' . $db->quoteName('id') . '=c.' . $db->quoteName('userid');
             if (!empty($friendListQuery)) {
                 $query .= $friendListQuery;
             }
             // @rule: Only fetch users that is configured to be searched via email.
             if ($isEmail && $config->get('privacy_search_email') == 1) {
                 $query .= ' AND c.' . $db->quoteName('search_email') . '=' . $db->Quote(1);
             }
             if ($avatarOnly) {
                 $query .= ' AND c.' . $db->quoteName('thumb') . ' != ' . $db->Quote('');
                 $query .= ' AND c.' . $db->quoteName('thumb') . ' != ' . $db->Quote('components/com_community/assets/default_thumb.jpg');
             }
             $query .= ' WHERE b.' . $db->quoteName('block') . ' = ' . $db->Quote('0') . ' AND ' . implode(' AND ', $filter) . $filterquery;
             $queryCnt = 'SELECT COUNT(1) FROM (' . $query . ') AS z';
             $db->setQuery($queryCnt);
             $total = $db->loadResult();
             $query .= " LIMIT " . $limitstart . "," . $limit;
             $db->setQuery($query);
             $finalResult = $db->loadColumn();
             if ($db->getErrorNum()) {
                 JError::raiseError(500, $db->stderr());
             }
         }
         // Appy pagination
         if (empty($this->_pagination)) {
             $this->_pagination = new JPagination($total, $limitstart, $limit);
         }
     }
     if (empty($finalResult)) {
         $finalResult = array(0);
     }
     $id = implode(",", $finalResult);
     $where = array("`id` IN (" . $id . ")");
     $result = $this->getFiltered($where);
     return $result;
 }
Пример #16
0
 public function ajaxSubmitInvitation($callback, $cid, $values)
 {
     //CFactory::load( 'helpers' , 'validate' );
     $filter = JFilterInput::getInstance();
     $callback = $filter->clean($callback, 'string');
     $cid = $filter->clean($cid, 'int');
     $values = $filter->clean($values, 'array');
     $objResponse = new JAXResponse();
     $my = CFactory::getUser();
     $methods = explode(',', $callback);
     $emails = array();
     $recipients = array();
     $users = '';
     $message = $values['message'];
     $values['friends'] = isset($values['friends']) ? $values['friends'] : array();
     if (!is_array($values['friends'])) {
         $values['friends'] = array($values['friends']);
     }
     // This is where we process external email addresses
     if (!empty($values['emails'])) {
         $emails = explode(',', $values['emails']);
         foreach ($emails as $email) {
             if (!CValidateHelper::email($email)) {
                 $objResponse->addAssign('invitation-error', 'innerHTML', JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_INVALID', $email));
                 return $objResponse->sendResponse();
             }
             $recipients[] = $email;
         }
     }
     // This is where we process site members that are being invited
     if (!empty($values['friends'][0])) {
         $users = explode(',', $values['friends'][0]);
         foreach ($users as $id) {
             $recipients[] = $id;
         }
     }
     if (!empty($recipients)) {
         $arguments = array($cid, $recipients, $emails, $message);
         if (is_array($methods) && $methods[0] != 'plugins') {
             $controller = JString::strtolower(basename($methods[0]));
             $function = $methods[1];
             require_once JPATH_ROOT . '/components/com_community/controllers/controller.php';
             $file = JPATH_ROOT . '/components/com_community/controllers' . '/' . $controller . '.php';
             if (JFile::exists($file)) {
                 require_once $file;
                 $controller = JString::ucfirst($controller);
                 $controller = 'Community' . $controller . 'Controller';
                 $controller = new $controller();
                 if (method_exists($controller, $function)) {
                     $inviteMail = call_user_func_array(array($controller, $function), $arguments);
                 } else {
                     $objResponse->addAssign('invitation-error', 'innerHTML', JText::_('COM_COMMUNITY_INVITE_EXTERNAL_METHOD_ERROR'));
                     return $objResponse->sendResponse();
                 }
             } else {
                 $objResponse->addAssign('invitation-error', 'innerHTML', JText::_('COM_COMMUNITY_INVITE_EXTERNAL_METHOD_ERROR'));
                 return $objResponse->sendResponse();
             }
         } else {
             if (is_array($methods) && $methods[0] == 'plugins') {
                 // Load 3rd party applications
                 $element = JString::strtolower(basename($methods[1]));
                 $function = $methods[2];
                 $file = CPluginHelper::getPluginPath('community', $element) . '/' . $element . '.php';
                 if (JFile::exists($file)) {
                     require_once $file;
                     $className = 'plgCommunity' . JString::ucfirst($element);
                     if (method_exists($controller, $function)) {
                         $inviteMail = call_user_func_array(array($className, $function), $arguments);
                     } else {
                         $objResponse->addAssign('invitation-error', 'innerHTML', JText::_('COM_COMMUNITY_INVITE_EXTERNAL_METHOD_ERROR'));
                         return $objResponse->sendResponse();
                     }
                 } else {
                     $objResponse->addAssign('invitation-error', 'innerHTML', JText::_('COM_COMMUNITY_INVITE_EXTERNAL_METHOD_ERROR'));
                     return $objResponse->sendResponse();
                 }
             }
         }
         //CFactory::load( 'libraries' , 'invitation' );
         // If the responsible method returns a false value, we should know that they want to stop the invitation process.
         if ($inviteMail instanceof CInvitationMail) {
             if ($inviteMail->hasError()) {
                 $objResponse->addAssign('invitation-error', 'innerHTML', $inviteMail->getError());
                 return $objResponse->sendResponse();
             } else {
                 // Once stored, we need to store selected user so they wont be invited again
                 $invitation = JTable::getInstance('Invitation', 'CTable');
                 $invitation->load($callback, $cid);
                 if (!empty($values['friends'])) {
                     if (!$invitation->id) {
                         // If the record doesn't exists, we need add them into the
                         $invitation->cid = $cid;
                         $invitation->callback = $callback;
                     }
                     $invitation->users = empty($invitation->users) ? implode(',', $values['friends']) : $invitation->users . ',' . implode(',', $values['friends']);
                     $invitation->store();
                 }
                 // Add notification
                 //CFactory::load( 'libraries' , 'notification' );
                 CNotificationLibrary::add($inviteMail->getCommand(), $my->id, $recipients, $inviteMail->getTitle(), $inviteMail->getContent(), '', $inviteMail->getParams());
             }
         } else {
             $objResponse->addScriptCall(JText::_('COM_COMMUNITY_INVITE_INVALID_RETURN_TYPE'));
             return $objResponse->sendResponse();
         }
     } else {
         $objResponse->addAssign('invitation-error', 'innerHTML', JText::_('COM_COMMUNITY_INVITE_NO_SELECTION'));
         return $objResponse->sendResponse();
     }
     $actions = '<input type="button" class="btn" onclick="cWindowHide();" value="' . JText::_('COM_COMMUNITY_BUTTON_CLOSE_BUTTON') . '"/>';
     $html = JText::_('COM_COMMUNITY_INVITE_SENT');
     $objResponse->addAssign('cwin_logo', 'innerHTML', JText::_('COM_COMMUNITY_INVITE_FRIENDS'));
     $objResponse->addScriptCall('cWindowAddContent', $html, $actions);
     return $objResponse->sendResponse();
 }
Пример #17
0
 public function save()
 {
     // Check for request forgeries
     $mainframe =& JFactory::getApplication();
     JRequest::checkToken() or jexit(JText::_('CC INVALID TOKEN'));
     $lang =& JFactory::getLanguage();
     $lang->load('com_user');
     $user =& JFactory::getUser();
     $userid = JRequest::getVar('id', 0, 'post', 'int');
     // preform security checks
     if ($user->get('id') == 0 || $userid == 0 || $userid != $user->get('id')) {
         echo $this->blockUnregister();
         return;
     }
     $username = $user->get('username');
     //clean request
     $post = JRequest::get('post');
     $post['username'] = $username;
     $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
     //check email
     $email = $post['email'];
     $emailPass = $post['emailpass'];
     $modelReg =& $this->getModel('register');
     CFactory::load('helpers', 'validate');
     if (!CValidateHelper::email($email)) {
         $msg = JText::sprintf('CC INVITE EMAIL INVALID', $email);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     if (!empty($email) && $email != $emailPass && $modelReg->isEmailExists(array('email' => $email))) {
         $msg = JText::sprintf('CC EMAIL EXIST', $email);
         $msg = stripslashes($msg);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     // get the redirect
     $return = CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false);
     // do a password safety check
     if (JString::strlen($post['password']) || JString::strlen($post['password2'])) {
         // so that "0" can be used as password e.g.
         if ($post['password'] != $post['password2']) {
             $msg = JText::_('PASSWORDS_DO_NOT_MATCH');
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
             return false;
         }
     }
     // we don't want users to edit certain fields so we will unset them
     unset($post['gid']);
     unset($post['block']);
     unset($post['usertype']);
     unset($post['registerDate']);
     unset($post['activation']);
     //update CUser param 1st so that the new value will not be replace wif the old one.
     $my = CFactory::getUser();
     $params =& $my->getParams();
     $postvars = $post['daylightsavingoffset'];
     $params->set('daylightsavingoffset', $postvars);
     $jConfig =& JFactory::getConfig();
     $model = CFactory::getModel('profile');
     $editSuccess = true;
     $msg = JText::_('CC SETTINGS SAVED');
     $jUser =& JFactory::getUser();
     // Bind the form fields to the user table
     if (!$jUser->bind($post)) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     $my->save('params');
     // Store the web link table to the database
     if (!$jUser->save()) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     if ($editSuccess) {
         $session =& JFactory::getSession();
         $session->set('user', $jUser);
         //execute the trigger
         $appsLib =& CAppPlugins::getInstance();
         $appsLib->loadApplications();
         $userRow = array();
         $userRow[] = $jUser;
         $appsLib->triggerEvent('onUserDetailsUpdate', $userRow);
     }
     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg);
 }
Пример #18
0
 /**
  * Show the user invite window
  */
 public function invite()
 {
     $view = CFactory::getView('friends');
     $validated = false;
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     if (JRequest::getVar('action', '', 'POST') == 'invite') {
         $mainframe =& JFactory::getApplication();
         CFactory::load('libraries', 'apps');
         $appsLib =& CAppPlugins::getInstance();
         $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-friends-invite'));
         if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
             $validated = true;
             $emailExistError = array();
             $emailInvalidError = array();
             $emails = JRequest::getVar('emails', '', 'POST');
             if (empty($emails)) {
                 $validated = false;
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_FRIENDS_EMAIL_CANNOT_BE_EMPTY'), 'error');
             } else {
                 $emails = explode(',', $emails);
                 $userModel = CFactory::getModel('user');
                 // Do simple email validation
                 // make sure user is not a member yet
                 // check for duplicate emails
                 // make sure email is valid
                 // make sure user is not already on the system
                 CFactory::load('helpers', 'validate');
                 $actualEmails = array();
                 for ($i = 0; $i < count($emails); $i++) {
                     //trim the value
                     $emails[$i] = JString::trim($emails[$i]);
                     if (!empty($emails[$i]) && (bool) CValidateHelper::email($emails[$i])) {
                         //now if the email already exist in system, alert the user.
                         if (!$userModel->userExistsbyEmail($emails[$i])) {
                             $actualEmails[$emails[$i]] = true;
                         } else {
                             $emailExistError[] = $emails[$i];
                         }
                     } else {
                         // log the error and display to user.
                         if (!empty($emails[$i])) {
                             $emailInvalidError[] = $emails[$i];
                         }
                     }
                 }
                 $emails = array_keys($actualEmails);
                 unset($actualEmails);
                 if (count($emails) <= 0) {
                     $validated = false;
                 }
                 if (count($emailInvalidError) > 0) {
                     for ($i = 0; $i < count($emailInvalidError); $i++) {
                         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_INVALID', $emailInvalidError[$i]), 'error');
                     }
                     $validated = false;
                 }
                 if (count($emailExistError) > 0) {
                     for ($i = 0; $i < count($emailExistError); $i++) {
                         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_EXIST', $emailExistError[$i]), 'error');
                     }
                     $validated = false;
                 }
             }
             $message = JRequest::getVar('message', '', 'POST');
             $config = CFactory::getConfig();
             if ($validated) {
                 CFactory::load('libraries', 'notification');
                 for ($i = 0; $i < count($emails); $i++) {
                     $emails[$i] = JString::trim($emails[$i]);
                     $params = new CParameter('');
                     $params->set('url', 'index.php?option=com_community&view=profile&userid=' . $my->id . '&invite=' . $my->id);
                     $params->set('message', $message);
                     CNotificationLibrary::add('etype_friends_invite_users', $my->id, $emails[$i], JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_SUBJECT', $my->getDisplayName(), $config->get('sitename')), '', 'friends.invite', $params);
                 }
                 $mainframe->enqueueMessage(JText::sprintf(CStringHelper::isPlural(count($emails)) ? 'COM_COMMUNITY_INVITE_EMAIL_SENT_MANY' : 'COM_COMMUNITY_INVITE_EMAIL_SENT', count($emails)));
                 //add user points - friends.invite removed @ 20090313
                 //clear the post value.
                 JRequest::setVar('emails', '');
                 JRequest::setVar('message', '');
             } else {
                 // Display error message
             }
         }
     }
     echo $view->get('invite');
 }
Пример #19
0
 /**
  * Deprecated since 1.8
  */
 function isValidInetAddress($data, $strict = false)
 {
     return CValidateHelper::email($data, $strict);
 }