Exemple #1
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;
 }
Exemple #2
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;
 }
Exemple #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();
 }
Exemple #4
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));
 }
Exemple #5
0
 public function ajaxCheckUserName($param = '')
 {
     // $param pending filter
     $objResponse = new JAXResponse();
     $username = $param;
     $ipaddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
     $model =& $this->getModel('register');
     $isInvalid = false;
     $msg = '';
     CFactory::load('helpers', 'validate');
     if (!empty($username)) {
         if (!CValidateHelper::username($username)) {
             $isInvalid = true;
             $msg = JText::_('COM_COMMUNITY_IMPROPER_USERNAME');
         }
     }
     if (!empty($username) && !$isInvalid) {
         $isInvalid = $model->isUserNameExists(array('username' => $username, 'ip' => $ipaddress));
         $msg = JText::sprintf('COM_COMMUNITY_USERNAME_EXIST', $username);
     }
     if ($isInvalid) {
         $objResponse->addScriptCall('joms.jQuery("#jsusername").addClass("invalid");');
         $objResponse->addScriptCall('joms.jQuery("#errjsusernamemsg").show();');
         $objResponse->addScriptCall('joms.jQuery("#errjsusernamemsg").html("<br/>' . $msg . '");');
         $objResponse->addScriptCall('joms.jQuery("#usernamepass").val("N");');
         $objResponse->addScriptCall('joms.jQuery(cvalidate.customMessage = "' . $msg . '");');
         $objResponse->addScriptCall('false;');
     } else {
         $objResponse->addScriptCall('joms.jQuery("#jsusername").removeClass("invalid");');
         $objResponse->addScriptCall('joms.jQuery("#errjsusernamemsg").html("&nbsp");');
         $objResponse->addScriptCall('joms.jQuery("#errjsusernamemsg").hide();');
         $objResponse->addScriptCall('joms.jQuery("#usernamepass").val("' . $username . '");');
         $objResponse->addScriptCall('joms.jQuery(cvalidate.customMessage = "");');
         $objResponse->addScriptCall('true;');
     }
     return $objResponse->sendResponse();
 }
 /**
  * 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;
 }
Exemple #7
0
 private function _validVanityURL($alias, $userId)
 {
     $model = CFactory::getModel('Profile');
     $user = CFactory::getUser($userId);
     if (!$model->aliasExists($alias, $userId) && CValidateHelper::alias($alias)) {
         return true;
     }
     return false;
 }
Exemple #8
0
 /**
  * 	Checks the validity of the username via AJAX calls
  *
  * 	@params	$username	String	The username that is passed.
  * */
 public function ajaxCheckUsername($username)
 {
     $response = new JAXResponse();
     $filter = JFilterInput::getInstance();
     $username = $filter->clean($username, 'string');
     //CFactory::load( 'helpers' , 'validate' );
     $valid = CValidateHelper::username($username);
     if (!$valid && !empty($username) || empty($username)) {
         $response->addScriptCall('joms.jQuery("#newusername").addClass("invalid");');
         $response->addScriptCall('joms.jQuery("#error-newusername").show();');
         $response->addScriptCall('joms.jQuery("#error-newusername").html("' . JText::sprintf('COM_COMMUNITY_INVALID_USERNAME', htmlspecialchars($username)) . '");');
         return $response->sendResponse();
     }
     $model = CFactory::getModel('register');
     $exists = $model->isUserNameExists(array('username' => $username));
     if ($exists) {
         $response->addScriptCall('joms.jQuery("#newusername").addClass("invalid");');
         $response->addScriptCall('joms.jQuery("#error-newusername").show();');
         $response->addScriptCall('joms.jQuery("#error-newusername").html("' . JText::sprintf('COM_COMMUNITY_USERNAME_EXISTS', htmlspecialchars($username)) . '");');
         return $response->sendResponse();
     }
     $response->addScriptCall('joms.jQuery("#newusername").removeClass("invalid");');
     $response->addScriptCall('joms.jQuery("#error-newusername").html("&nbsp");');
     $response->addScriptCall('joms.jQuery("#error-newusername").hide();');
     return $response->sendResponse();
 }
Exemple #9
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;
 }
Exemple #10
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');
 }
Exemple #11
0
 /**
  * Deprecated since 1.8
  */
 function isValidInetAddress($data, $strict = false)
 {
     return CValidateHelper::email($data, $strict);
 }
Exemple #12
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);
         }
     }
 }
Exemple #13
0
 public function isEmailDenied($email)
 {
     $config = CFactory::getConfig();
     CFactory::load('helpers', 'validate');
     $denied_domains = $config->get('denieddomains');
     if (!empty($denied_domains)) {
         $delimiter = ';';
         $blacklists = explode($delimiter, $denied_domains);
         if (count($blacklists) > 0) {
             foreach ($blacklists as $domain) {
                 if (CValidateHelper::domain($email, $domain)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemple #14
0
 public function ajaxCheckUserName($username = '', $current = '')
 {
     $json = array();
     $isInvalid = false;
     $msg = '';
     if (!empty($current) && !empty($username) && $username == $current) {
         $json['success'] = true;
         die(json_encode($json));
     }
     if (!empty($username)) {
         if (!CValidateHelper::username($username)) {
             $json['error'] = JText::_('COM_COMMUNITY_IMPROPER_USERNAME');
             die(json_encode($json));
         }
         $model = $this->getModel('register');
         $ipaddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
         if ($model->isUserNameExists(array('username' => $username, 'ip' => $ipaddress))) {
             $json['error'] = JText::sprintf('COM_COMMUNITY_USERNAME_EXIST', $username);
             die(json_encode($json));
         }
     }
     $json['success'] = true;
     die(json_encode($json));
 }
Exemple #15
0
 /**
  * Deprecated since 1.8
  */
 function cValidatePhone($phone)
 {
     return CValidateHelper::phone($phone);
 }
Exemple #16
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;
 }
Exemple #17
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();
 }
Exemple #18
0
 public function ajaxCheckUserName($param = '')
 {
     // $param pending filter
     $objResponse = new JAXResponse();
     $username = $param;
     $ipaddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
     $model = $this->getModel('register');
     $isInvalid = false;
     $msg = '';
     if (!empty($username)) {
         if (!CValidateHelper::username($username)) {
             $isInvalid = true;
             $msg = JText::_('COM_COMMUNITY_IMPROPER_USERNAME');
         }
     }
     if (!empty($username) && !$isInvalid) {
         $isInvalid = $model->isUserNameExists(array('username' => $username, 'ip' => $ipaddress));
         $msg = JText::sprintf('COM_COMMUNITY_USERNAME_EXIST', $username);
     }
     $json = array();
     if ($isInvalid) {
         $json['error'] = $msg;
     } else {
         $json['success'] = true;
     }
     die(json_encode($json));
 }
Exemple #19
0
 function isValid($value, $required)
 {
     CFactory::load('helpers', 'validate');
     $isValid = CValidateHelper::url($value);
     $url = parse_url($value);
     $host = isset($url['host']) ? $url['host'] : '';
     if (!$isValid && $required) {
         return false;
     } else {
         if (!empty($host) && !$isValid) {
             return false;
         }
     }
     return true;
 }
Exemple #20
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();
 }
Exemple #21
0
 public function isValid($value, $required)
 {
     //CFactory::load( 'helpers' , 'validate' );
     $isValid = CValidateHelper::url($value);
     $url = parse_url($value);
     $host = isset($url['host']) ? $url['host'] : '';
     /* this field is required OR user entered something */
     if ($required || $value != '') {
         /* it must be valid AND NOT empty host AND validLength*/
         return $isValid && !empty($host) && $this->validLength($value);
     }
     /* no required and user no entered anything than of course VALID */
     return true;
 }
Exemple #22
0
 private function _validVanityURL($alias, $userId)
 {
     $model = CFactory::getModel('Profile');
     $user = CFactory::getUser($userId);
     $alias = JFilterOutput::stringURLSafe(urlencode($alias));
     CFactory::load('helpers', 'validate');
     if (!$model->aliasExists($alias, $userId) && CValidateHelper::alias($alias)) {
         return true;
     }
     return false;
 }
Exemple #23
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');
 }
Exemple #24
0
/**
 * Deprecated since 1.8
 * Use CValidateHelper::username instead. 
 */
function cValidUsername($username)
{
    CFactory::load('helpers', 'validate');
    return CValidateHelper::username($username);
}
Exemple #25
0
 public function isValid($value, $required)
 {
     CFactory::load('helpers', 'validate');
     $isValid = CValidateHelper::url($value);
     $url = parse_url($value);
     $host = isset($url['host']) ? $url['host'] : '';
     //validate url format
     if (!$isValid && $required) {
         return false;
     } else {
         if (!empty($host) && !$isValid) {
             return false;
         }
     }
     //validate length
     if (!$this->validLength($value)) {
         return false;
     }
     return true;
 }