Exemple #1
1
 /**
  * Do a batch send
  */
 function send($total = 100)
 {
     $mailqModel = CFactory::getModel('mailq');
     $userModel = CFactory::getModel('user');
     $mails = $mailqModel->get($total);
     $jconfig = JFactory::getConfig();
     $mailer = JFactory::getMailer();
     $config = CFactory::getConfig();
     $senderEmail = $jconfig->getValue('mailfrom');
     $senderName = $jconfig->getValue('fromname');
     if (empty($mails)) {
         return;
     }
     CFactory::load('helpers', 'string');
     foreach ($mails as $row) {
         // @rule: only send emails that is valid.
         // @rule: make sure recipient is not blocked!
         $userid = $userModel->getUserFromEmail($row->recipient);
         $user = CFactory::getUser($userid);
         if (!$user->isBlocked() && !JString::stristr($row->recipient, 'foo.bar')) {
             $mailer->setSender(array($senderEmail, $senderName));
             $mailer->addRecipient($row->recipient);
             $mailer->setSubject($row->subject);
             $tmpl = new CTemplate();
             $raw = isset($row->params) ? $row->params : '';
             $params = new JParameter($row->params);
             $base = $config->get('htmlemail') ? 'email.html' : 'email.text';
             if ($config->get('htmlemail')) {
                 $row->body = JString::str_ireplace(array("\r\n", "\r", "\n"), '<br />', $row->body);
                 $mailer->IsHTML(true);
             } else {
                 //@rule: Some content might contain 'html' tags. Strip them out since this mail should never contain html tags.
                 $row->body = CStringHelper::escape(strip_tags($row->body));
             }
             $tmpl->set('content', $row->body);
             $tmpl->set('template', rtrim(JURI::root(), '/') . '/components/com_community/templates/' . $config->get('template'));
             $tmpl->set('sitename', $config->get('sitename'));
             $row->body = $tmpl->fetch($base);
             // Replace any occurences of custom variables within the braces scoe { }
             if (!empty($row->body)) {
                 preg_match_all("/{(.*?)}/", $row->body, $matches, PREG_SET_ORDER);
                 foreach ($matches as $val) {
                     $replaceWith = $params->get($val[1], null);
                     //if the replacement start with 'index.php', we can CRoute it
                     if (strpos($replaceWith, 'index.php') === 0) {
                         $replaceWith = CRoute::getExternalURL($replaceWith);
                     }
                     if (!is_null($replaceWith)) {
                         $row->body = JString::str_ireplace($val[0], $replaceWith, $row->body);
                     }
                 }
             }
             unset($tmpl);
             $mailer->setBody($row->body);
             $mailer->send();
         }
         $mailqModel->markSent($row->id);
         $mailer->ClearAllRecipients();
     }
 }
Exemple #2
1
 private function _getAllEvents()
 {
     $mainframe = JFactory::getApplication();
     $rows = $this->model->getEvents();
     $items = array();
     foreach ($rows as $row) {
         $item = new stdClass();
         $table =& JTable::getInstance('Event', 'CTable');
         $table->bind($row);
         $table->thumbnail = $table->getThumbAvatar();
         $table->avatar = $table->getAvatar();
         $author = CFactory::getUser($table->creator);
         $item->id = $row->id;
         $item->created = $row->created;
         $item->creator = CStringHelper::escape($author->getDisplayname());
         $item->title = $row->title;
         $item->description = CStringHelper::escape($row->description);
         $item->location = CStringHelper::escape($row->location);
         $tiem->startdate = $row->startdate;
         $item->enddate = $row->enddate;
         $item->thumbnail = $table->thumbnail;
         $tiem->avatar = $table->avatar;
         $item->ticket = $row->ticket;
         $item->invited = $row->invitedcount;
         $item->confirmed = $row->confirmedcount;
         $item->declined = $row->declinedcount;
         $item->maybe = $row->maybecount;
         $item->latitude = $row->latitude;
         $item->longitude = $row->longitude;
         $items[] = $item;
     }
     return $items;
 }
Exemple #3
0
 public function ajaxSendMessage($title, $message, $limit = 1)
 {
     if (!$title || !$message) {
         $response = new JAXResponse();
         $response->addScriptCall("joms.jQuery('#error').remove();");
         $response->addScriptCall('joms.jQuery("#messaging-form").prepend("<p id=error style=color:red>Error:Title or Message cannot be empty</p>");');
         return $response->sendResponse();
     }
     $limitstart = $limit - 1;
     $model =& $this->getModel('users');
     $userId = $model->getSiteUsers($limitstart, 1);
     $response = new JAXResponse();
     $response->addScriptCall('joms.jQuery("#messaging-form").hide();');
     $response->addScriptCall('joms.jQuery("#messaging-result").show();');
     $user = CFactory::getUser($userId);
     $my =& JFactory::getUser();
     if (!empty($userId)) {
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'notification.php';
         CNotificationLibrary::add('etype_system_messaging', $my->id, $user->id, $title, $message);
         $response->addScriptCall('joms.jQuery("#no-progress").css("display","none");');
         $response->addScriptCall('joms.jQuery("#progress-status").append("<div>' . JText::sprintf('Sending message to <strong>%1$s</strong>', str_replace(array("\r", "\n"), ' ', $user->getDisplayname())) . '<span style=\\"color: green;margin-left: 5px;\\">' . JText::_('COM_COMMUNITY_SUCCESS') . '</span></div>");');
         $response->addScriptCall('sendMessage', $title, $message, $limit + 1);
     } else {
         $response->addScriptCall('joms.jQuery("#progress-status").append("<div style=\\"font-weight:700;\\">' . JText::_('COM_COMMUNITY_UPDATED') . '</div>");');
     }
     return $response->sendResponse();
 }
 function plgCommunityJreviews_myfavorites(&$subject, $config)
 {
     $this->_path = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_jreviews';
     $this->_user = CFactory::getActiveProfile();
     $this->_my = CFactory::getUser();
     parent::__construct($subject, $config);
 }
Exemple #5
0
 static function addPoints_jomsocial($action, $username, $course_id, $course_name)
 {
     if (file_exists(JPATH_ADMINISTRATOR . '/components/com_community/tables/cache.php')) {
         require_once JPATH_ADMINISTRATOR . 'components/com_community/tables/cache.php';
     }
     require_once JPATH_SITE . '/components/com_community/libraries/core.php';
     require_once JPATH_SITE . '/components/com_community/libraries/userpoints.php';
     if (class_exists('CFactory')) {
         $userPoint = CFactory::getModel('userpoints');
     } else {
         $userPoint = new CommunityModelUserPoints();
     }
     $upObj = $userPoint->getPointData($action);
     $published = $upObj->published;
     if ($published) {
         $points = $upObj->points;
     } else {
         $points = 0;
     }
     if ($points == 0) {
         return 0;
     }
     $user = CFactory::getUser($username);
     $points += $user->getKarmaPoint();
     $user->_points = $points;
     $user->save();
     return $points;
 }
 public static function _getMutualFriendsHTML($userid = null)
 {
     $my = CFactory::getUser();
     if ($my->id == $userid) {
         return;
     }
     $friendsModel = CFactory::getModel('Friends');
     $friends = $friendsModel->getFriends($userid, 'latest', false, 'mutual');
     $html = "<ul class='joms-list--friend single-column'>";
     if (sizeof($friends)) {
         foreach ($friends as $friend) {
             $html .= "<li class='joms-list__item'>";
             $html .= "<div class='joms-list__avatar'>";
             $html .= '<div class="joms-avatar ' . CUserHelper::onlineIndicator($friend) . '"><a href="' . CRoute::_('index.php?option=com_community&view=profile&userid=' . $friend->id) . '">';
             $html .= '<img src="' . $friend->getThumbAvatar() . '" data-author="' . $friend->id . '" />';
             $html .= "</a></div></div>";
             $html .= "<div class='joms-list__body'>";
             $html .= CFriendsHelper::getUserCog($friend->id, null, null, true);
             $html .= CFriendsHelper::getUserFriendDropdown($friend->id);
             $html .= '<a href="' . CRoute::_('index.php?option=com_community&view=profile&userid=' . $friend->id) . '">';
             $html .= '<h4 class="joms-text--username">' . $friend->getDisplayName() . '</h4></a>';
             $html .= '<span class="joms-text--title">' . JText::sprintf('COM_COMMUNITY_TOTAL_MUTUAL_FRIENDS', CFriendsHelper::getTotalMutualFriends($friend->id)) . '</span>';
             $html .= "</div></li>";
         }
         $html .= "</ul>";
     } else {
         $html .= JText::_('COM_COMMUNITY_NO_MUTUAL_FRIENDS');
     }
     return $html;
 }
Exemple #7
0
 /**
  * Check if 2 friends is connected or not
  * @param	int userid1
  * @param	int userid2
  * @return	bool  
  */
 public static function isConnected($id1, $id2)
 {
     // Static caching for this session
     static $isFriend = array();
     if (!empty($isFriend[$id1 . '-' . $id2])) {
         return $isFriend[$id1 . '-' . $id2];
     }
     if ($id1 == $id2 && $id1 != 0) {
         return true;
     }
     if ($id1 == 0 || $id2 == 0) {
         return false;
     }
     /*
     $db =& JFactory::getDBO();
     $sql = 'SELECT count(*) FROM ' . $db->nameQuote('#__community_connection')
     	  .' WHERE ' . $db->nameQuote('connect_from') .'=' . $db->Quote($id1) .' AND ' . $db->nameQuote('connect_to') .'=' . $db->Quote($id2)
     	  .' AND ' . $db->nameQuote('status') .' = ' . $db->Quote(1);
     	
     $db->setQuery($sql);
     $result = $db->loadResult();
     if($db->getErrorNum()) {
     	JError::raiseError( 500, $db->stderr());
     }
     
     $isFriend[$id1.'-'.$id2] = $result;
     */
     // change method to get connection since list friends stored in community_users as well
     $user = CFactory::getUser($id1);
     $isConnected = $user->isFriendWith($id2);
     return $isConnected;
 }
Exemple #8
0
 /**
  * Update the user status
  * 
  * @param	int		user id
  * @param	string	the message. Should be < 140 char (controller check)	 	 	 
  */
 function update($id, $status)
 {
     $db =& $this->getDBO();
     $my = CFactory::getUser();
     // @todo: posted_on should be constructed to make sure we take into account
     // of Joomla server offset
     // Current user and update id should always be the same
     CError::assert($my->id, $id, 'eq', __FILE__, __LINE__);
     // Trigger onStatusUpdate
     require_once COMMUNITY_COM_PATH . DS . 'libraries' . DS . 'apps.php';
     $appsLib =& CAppPlugins::getInstance();
     $appsLib->loadApplications();
     $args = array();
     $args[] = $my->id;
     // userid
     $args[] = $my->getStatus();
     // old status
     $args[] = $status;
     // new status
     $appsLib->triggerEvent('onProfileStatusUpdate', $args);
     $today =& JFactory::getDate();
     $data = new stdClass();
     $data->userid = $id;
     $data->status = $status;
     $data->posted_on = $today->toMySQL();
     $db->updateObject('#__community_users', $data, 'userid');
     if ($db->getErrorNum()) {
         JError::raiseError(500, $db->stderr());
     }
 }
Exemple #9
0
 public static function exceedDaily($view, $userId = null, $returnRemaining = false)
 {
     $my = CFactory::getUser($userId);
     // Guests shouldn't be even allowed here.
     if ($my->id == 0) {
         return true;
     }
     $view = JString::strtolower($view);
     // We need to include the model first before using ReflectionClass so that the model file is included.
     $model = CFactory::getModel($view);
     // Since the model will always return a CCachingModel which is a proxy,
     // for the real model, we can't really test what type of object it is.
     $modelClass = 'CommunityModel' . ucfirst($view);
     $reflection = new ReflectionClass($modelClass);
     if (!$reflection->implementsInterface('CLimitsInterface')) {
         return false;
     }
     $config = CFactory::getConfig();
     $total = $model->getTotalToday($my->id);
     $max = $config->getInt('limit_' . $view . '_perday');
     if ($returnRemaining) {
         return $max - $total;
     }
     return $total >= $max && $max != 0;
 }
Exemple #10
0
 public function onGroupJoin($group, $userId)
 {
     //@rule: Clear existing invites fromt he invitation table once the user joined the group
     $groupInvite =& JTable::getInstance('GroupInvite', 'CTable');
     if ($groupInvite->load($group->id, $userId)) {
         $groupInvite->delete();
     }
     $member =& JTable::getInstance('GroupMembers', 'CTable');
     $member->load($userId, $group->id);
     $params = $group->getParams();
     //@rule: Send notification when necessary
     if ($params->get('joinrequestnotification') || $params->get('newmembernotification')) {
         $user = CFactory::getUser($userId);
         $subject = JText::sprintf('CC NEW MEMBER JOIN EMAIL SUBJECT', $user->getDisplayName(), $group->name);
         if (!$member->approved) {
             $subject = JText::sprintf('CC NEW MEMBER REQUESTED TO JOIN GROUP EMAIL SUBJECT', $user->getDisplayName(), $group->name);
         }
         // Add notification
         CFactory::load('libraries', 'notification');
         $params = new JParameter('');
         $params->set('url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id);
         $params->set('group', $group->name);
         $params->set('user', $user->getDisplayName());
         $params->set('approved', $member->approved);
         CNotificationLibrary::add('groups.member.join', $user->id, $group->ownerid, $subject, '', 'groups.memberjoin', $params);
     }
 }
Exemple #11
0
 public function __construct($event)
 {
     $this->my = CFactory::getUser();
     $this->model = CFactory::getModel('events');
     $this->event = $event;
     $this->url = 'index.php?option=com_community&view=events&task=viewevent&eventid=' . $this->event->id;
 }
 /**
  * Method is called during the status update triggers.
  **/
 public function onProfileStatusUpdate($userid, $oldMessage, $newMessage)
 {
     $config = CFactory::getConfig();
     $my = CFactory::getUser();
     if ($config->get('fbconnectpoststatus')) {
         //CFactory::load( 'libraries' , 'facebook' );
         $facebook = new CFacebook();
         if ($facebook) {
             $fbuserid = $facebook->getUser();
             $connectModel = CFactory::getModel('Connect');
             $connectTable = JTable::getInstance('Connect', 'CTable');
             $connectTable->load($fbuserid);
             // Make sure the FB session match the user session
             if ($connectTable->userid == $my->id) {
                 /**
                  * Check post status to facebook settings
                  */
                 //echo "posting to facebook"; exit;
                 $targetUser = CFactory::getUser($my->id);
                 $userParams = $targetUser->getParams();
                 if ($userParams->get('postFacebookStatus')) {
                     $result = $facebook->postStatus($newMessage);
                     //print_r($result); exit;
                 }
             }
         }
     }
 }
 function deletewallpost($data)
 {
     require_once JPATH_SITE . '/components/com_community/libraries/core.php';
     $error_messages = array();
     $response = NULL;
     $validated = true;
     $db =& JFactory::getDBO();
     if ($data['wall_id'] == "" || $data['wall_id'] == "0") {
         $validated = false;
         $error_messages[] = array("id" => 1, "fieldname" => "wallid", "message" => "Wall id cannot be blank");
     }
     //@rule: Check if user is really allowed to remove the current wall
     $my = CFactory::getUser();
     $model =& CFactory::getModel('wall');
     $wall = $model->get($data['wall_id']);
     $groupModel =& CFactory::getModel('groups');
     $group =& JTable::getInstance('Group', 'CTable');
     $group->load($wall->contentid);
     $query = "SELECT contentid FROM #__community_wall WHERE id ='" . $data['wall_id'] . "' AND type = 'groups'";
     $db->setQuery($query);
     $contentid = $db->LoadResult();
     CFactory::load('helpers', 'owner');
     $query = "SELECT id FROM #__community_wall WHERE id ='" . $data['wall_id'] . "' AND type = 'groups'";
     $db->setQuery($query);
     $isdiscussion = $db->LoadResult();
     if (!$isdiscussion) {
         $error_messages[] = array("id" => 1, "fieldname" => "wallid", "message" => "wall id for type groups does not exists. Modify the wall_id field");
     } else {
         if (!$model->deletePost($data['wall_id'])) {
             $validated = false;
             //$error_messages[] = 'wall id does not exists. Modify the wall_id fields in request';
             $error_messages[] = array("id" => 1, "fieldname" => "wallid", "message" => "wall id does not exists. Modify the wall_id field");
         } else {
             if ($wall->post_by != 0) {
                 //add user points
                 CFactory::load('libraries', 'userpoints');
                 CUserPoints::assignPoint('wall.remove', $wall->post_by);
             }
         }
         //$groupModel->substractWallCount( $data['wall_id'] );
         // Substract the count
         $query = 'SELECT COUNT(*) FROM ' . $db->nameQuote('#__community_wall') . ' ' . 'WHERE contentid=' . $db->Quote($contentid) . ' ' . 'AND type="groups"';
         $db->setQuery($query);
         $wall_count = $db->loadResult();
         $wallcount = new stdClass();
         $wallcount->id = $contentid;
         $wallcount->wallcount = $wall_count;
         $db->updateObject('#__community_groups', $wallcount, 'id');
     }
     if (true == isset($error_messages) && 0 < sizeof($error_messages)) {
         $res = array();
         foreach ($error_messages as $key => $error_message) {
             $res[] = $error_message;
         }
         $response = array("id" => 0, 'errors' => $res);
     } else {
         $response = array('id' => $wall->id);
     }
     return $response;
 }
Exemple #14
0
	public function getProfileURL($userid, $task='', $xhtml = true) {
		// Make sure that user profile exist.
		if (!$userid || CFactory::getUser($userid) === null) {
			return false;
		}
		return CRoute::_('index.php?option=com_community&view=profile&userid=' . (int) $userid, $xhtml);
	}
 function plgCommunityPlg_RSMembership(&$subject, $config)
 {
     $this->_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_rsmembership' . DS . 'helpers' . DS . 'rsmembership.php';
     $this->_user =& CFactory::getActiveProfile();
     $this->_my =& CFactory::getUser();
     parent::__construct($subject, $config);
 }
Exemple #16
0
 /**
  * Return true if actor have access to target's item
  * @param type where the privacy setting should be extracted, {user, group, global, custom}
  * Site super admin waill always have access to all area	 
  */
 static function isAccessAllowed($actorId, $targetId, $type, $userPrivacyParam)
 {
     $actor = CFactory::getUser($actorId);
     $target = CFactory::getUser($targetId);
     CFactory::load('helpers', 'owner');
     CFactory::load('helpers', 'friends');
     // Load User params
     $params =& $target->getParams();
     // guest
     $relation = 10;
     // site members
     if ($actor->id != 0) {
         $relation = 20;
     }
     // friends
     if (CFriendsHelper::isConnected($actorId, $targetId)) {
         $relation = 30;
     }
     // mine, target and actor is the same person
     if (COwnerHelper::isMine($actor->id, $target->id)) {
         $relation = 40;
     }
     // @todo: respect privacy settings
     // If type is 'custom', then $userPrivacyParam will contain the exact
     // permission level
     $permissionLevel = $type == 'custom' ? $userPrivacyParam : $params->get($userPrivacyParam);
     if ($relation < $permissionLevel && !COwnerHelper::isCommunityAdmin($actorId)) {
         return false;
     }
     return true;
 }
Exemple #17
0
 public function getProfileLink($user_id, &$object, &$attribs = array())
 {
     $user = CFactory::getUser($user_id);
     //parameters
     $params = $this->params;
     if (!$user || $params->get('view_individual_link', '1') == 0) {
         return true;
     }
     JHTML::_('behavior.tooltip');
     $name = $user->getDisplayName();
     $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $user_id);
     switch ($params->get('view_individual_link', '1')) {
         case 2:
             $avatar = $user->getThumbAvatar();
             $text = '<img class="hasTip" src="' . $avatar . '" title="' . $name . '"/>';
             break;
         case 1:
         default:
             $text = JText::_('PLG_TRACKS_JOMSOCIAL_VIEW_USER_PROFILE');
             break;
     }
     $attribs = array_merge($attribs, array('alt' => $user->get('username')));
     $object->text = JHTML::link($url, $text, $attribs);
     return true;
 }
Exemple #18
0
 /**
  * add points to user based on the action.
  */
 function assignPoint($action, $userId = null)
 {
     //get the rule points
     //must use the JFactory::getUser to get the aid
     $juser =& JFactory::getUser($userId);
     if ($juser->id != 0) {
         $aid = $juser->aid;
         // if the aid is null, means this is not the current logged-in user.
         // so we need to manually get this aid for this user.
         if (is_null($aid)) {
             $aid = 0;
             //defautl to 0
             // Get an ACL object
             $acl =& JFactory::getACL();
             $grp = $acl->getAroGroup($juser->id);
             $group = 'USERS';
             if ($acl->is_group_child_of($grp->name, $group)) {
                 $aid = 1;
                 // Fudge Authors, Editors, Publishers and Super Administrators into the special access group
                 if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) {
                     $aid = 2;
                 }
             }
         }
         $points = CUserPoints::_getActionPoint($action, $aid);
         $user = CFactory::getUser($userId);
         $points += $user->getKarmaPoint();
         $user->_points = $points;
         $user->save();
     }
 }
 public function onGroupJoin($group, $userId)
 {
     //@rule: Clear existing invites fromt he invitation table once the user joined the group
     $groupInvite =& JTable::getInstance('GroupInvite', 'CTable');
     if ($groupInvite->load($group->id, $userId)) {
         $groupInvite->delete();
     }
     $member =& JTable::getInstance('GroupMembers', 'CTable');
     $member->load($userId, $group->id);
     $groupModel = CFactory::getModel('groups');
     $admins = $groupModel->getAdmins($group->id, null);
     $params = $group->getParams();
     //@rule: Send notification when necessary
     if ($params->get('joinrequestnotification') || $params->get('newmembernotification')) {
         $user = CFactory::getUser($userId);
         $subject = JText::sprintf('COM_COMMUNITY_GROUPS_EMAIL_NEW_MEMBER_JOINED_SUBJECT', $user->getDisplayName(), $group->name);
         if (!$member->approved) {
             $subject = JText::sprintf('COM_COMMUNITY_NEW_MEMBER_REQUESTED_TO_JOIN_GROUP_EMAIL_SUBJECT', $user->getDisplayName(), $group->name);
         }
         // Add notification
         CFactory::load('libraries', 'notification');
         $params = new CParameter('');
         $params->set('url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id);
         $params->set('group', $group->name);
         $params->set('user', $user->getDisplayName());
         $params->set('approved', $member->approved);
         foreach ($admins as $admin) {
             CNotificationLibrary::add('etype_groups_member_join', $user->id, $admin->id, $subject, '', 'groups.memberjoin', $params);
         }
     }
 }
Exemple #20
0
 public function blockUnregister($uri = null)
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     if ($my->id == 0) {
         $config = CFactory::getConfig();
         if (empty($uri)) {
             $uri = CRoute::getURI(false);
         }
         $uri = base64_encode($uri);
         $tmpl = new CTemplate();
         $fbHtml = '';
         if ($config->get('fbconnectkey') && $config->get('fbconnectsecret')) {
             CFactory::load('libraries', 'facebook');
             $facebook = new CFacebook(FACEBOOK_LOGIN_NOT_REQUIRED);
             $fbHtml = $facebook->getButtonHTML();
         }
         $tmpl->set('fbHtml', $fbHtml);
         $tmpl->set('return', $uri);
         $tmpl->set('config', $config);
         $html = $tmpl->fetch('guests.denied');
         echo $html;
         return true;
     }
     return false;
 }
Exemple #21
0
 /**
  * take an object with the send data
  * $recipient, $body, $subject, 	 
  */
 public function add($recipient, $subject, $body, $templateFile = '', $params = '', $status = 0, $email_type = '')
 {
     $my = CFactory::getUser();
     // A user should not be getting a notification email of his own action
     $bookmarkStr = explode('.', $templateFile);
     if ($my->id == $recipient && $bookmarkStr[1] != 'bookmarks') {
         return $this;
     }
     $db =& $this->getDBO();
     $date =& JFactory::getDate();
     $obj = new stdClass();
     $obj->recipient = $recipient;
     // This part does a url search in the email body for URL and automatically makes it a linked URL
     // pattern search must starts with www or protocal such as http or https
     $matchUrl = preg_match_all('/\\b(([\\w-]+:\\/\\/?|www[.])[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|\\/)))/', $body, $matching);
     if ($matchUrl !== false && $matchUrl > 0) {
         for ($i = 0; $i < $matchUrl; $i++) {
             $body = str_replace($matching[0][$i], '<a href="' . $matching[0][$i] . '">' . $matching[0][$i] . '</a>', $body);
         }
     }
     $obj->body = $body;
     $obj->subject = $subject;
     $obj->template = $templateFile;
     $obj->params = is_object($params) && method_exists($params, 'toString') ? $params->toString() : '';
     $obj->created = $date->toMySQL();
     $obj->status = $status;
     $obj->email_type = $email_type;
     $db->insertObject('#__community_mailq', $obj);
     return $this;
 }
Exemple #22
0
 public function showGroupMiniHeader($groupId)
 {
     CMiniHeader::load();
     $option = JRequest::getVar('option', '', 'REQUEST');
     JFactory::getLanguage()->load('com_community');
     CFactory::load('models', 'groups');
     $group =& JTable::getInstance('Group', 'CTable');
     $group->load($groupId);
     $my = CFactory::getUser();
     // @rule: Test if the group is unpublished, don't display it at all.
     if (!$group->published) {
         return '';
     }
     if (!empty($group->id) && $group->id != 0) {
         $isMember = $group->isMember($my->id);
         $config = CFactory::getConfig();
         $tmpl = new CTemplate();
         $tmpl->set('my', $my);
         $tmpl->set('group', $group);
         $tmpl->set('isMember', $isMember);
         $tmpl->set('config', $config);
         $showMiniHeader = $option == 'com_community' ? $tmpl->fetch('groups.miniheader') : '<div id="community-wrap" style="min-height:50px;">' . $tmpl->fetch('groups.miniheader') . '</div>';
         return $showMiniHeader;
     }
 }
Exemple #23
0
 /**
  * Add new notification
  * @return  true
  */
 public function add($from, $to, $content, $cmd = '', $type = '', $params = '')
 {
     jimport('joomla.utilities.date');
     $db = $this->getDBO();
     $date = JFactory::getDate();
     $config = CFactory::getConfig();
     $notification = JTable::getInstance('notification', 'CTable');
     //respect notification setting
     //filter result by cmd_type
     $validate = true;
     $user = CFactory::getUser($to);
     $user_params = $user->getParams();
     if (!empty($cmd)) {
         $validate = $user_params->get($cmd, $config->get($cmd)) == 1 ? true : false;
     }
     if ($validate) {
         $notification->actor = $from;
         $notification->target = $to;
         $notification->content = $content;
         $notification->created = $date->toSql();
         $notification->params = is_object($params) && method_exists($params, 'toString') ? $params->toString() : '';
         $notification->cmd_type = $cmd;
         $notification->type = $type;
         $notification->store();
     }
     $appsLib = CAppPlugins::getInstance();
     $appsLib->triggerEvent('onNotificationAdd', array($notification));
     //delete the oldest notification
     $this->deleteOldest($to);
     return true;
 }
Exemple #24
0
 public function insertFeaturedStream($activityId, $streamType, $targetId)
 {
     $my = CFactory::getUser();
     // current user
     $featuredTable = JTable::getInstance('Featured', 'CTable');
     //set the featured stream type
     $featuredType = '';
     switch ($streamType) {
         case 'profile':
         case 'profiles':
             $featuredType = 'stream.profile';
             break;
         case 'frontpage':
             $featuredType = 'stream.frontpage';
             break;
         case 'event':
         case 'events':
             $featuredType = 'stream.event';
             break;
         case 'group':
         case 'groups':
             $featuredType = 'stream.group';
             break;
         default:
             return false;
     }
     $featuredTable->cid = $activityId;
     $featuredTable->type = $featuredType;
     $featuredTable->target_id = $targetId;
     $featuredTable->created_by = $my->id;
     $featuredTable->created = JFactory::getDate()->toSql();
     return $featuredTable->store();
 }
Exemple #25
0
 public static function getAccessLevel($actorId, $targetId)
 {
     $actor = CFactory::getUser($actorId);
     $target = CFactory::getUser($targetId);
     //CFactory::load( 'helpers' , 'owner' );
     //CFactory::load( 'helpers' , 'friends' );
     // public guest
     $access = 0;
     // site members
     if ($actor->id > 0) {
         $access = 20;
     }
     // they are friends
     if ($target->id > 0 && CFriendsHelper::isConnected($actor->id, $target->id)) {
         $access = 30;
     }
     // mine, target and actor is the same person
     if ($target->id > 0 && COwnerHelper::isMine($actor->id, $target->id)) {
         $access = 40;
     }
     if (COwnerHelper::isCommunityAdmin()) {
         $access = 40;
     }
     return $access;
 }
Exemple #26
0
 /**
  * Check if a user can administer the community
  */
 public static function isCommunityAdmin($userid = null)
 {
     static $resultArr;
     if (isset($resultArr[$userid])) {
         return $resultArr[$userid];
     }
     //for Joomla 1.6 afterward checking
     $jUser = CFactory::getUser($userid);
     if ($jUser instanceof CUser && method_exists($jUser, 'authorise')) {
         // group 6 = manager, 7 = administrator
         if ($jUser->authorise('core.admin') || $jUser->authorise('core.manage')) {
             $resultArr[$userid] = true;
             return true;
         } else {
             $resultArr[$userid] = false;
             return false;
         }
     }
     //for joomla 1.5
     $my = CFactory::getUser($userid);
     $cacl = CACL::getInstance();
     $usergroup = $cacl->getGroupsByUserId($my->id);
     $admingroups = array(0 => 'Super Administrator', 1 => 'Administrator', 2 => 'Manager', 3 => 'Super Users');
     return in_array($usergroup, $admingroups);
     //return ( $my->usertype == 'Super Administrator' || $my->usertype == 'Administrator' || $my->usertype == 'Manager' );
 }
Exemple #27
0
 public function getavatar($filter)
 {
     // Get CUser object
     $user = CFactory::getUser($filter);
     $avatarUrl = $user->getThumbAvatar();
     return $avatarUrl;
 }
Exemple #28
0
 function _displayEditLayout($tpl)
 {
     // Load frontend language file.
     $lang =& JFactory::getLanguage();
     $lang->load('com_community', JPATH_ROOT);
     $userId = JRequest::getVar('id', '', 'REQUEST');
     $user = CFactory::getUser($userId);
     // Set the titlebar text
     JToolBarHelper::title($user->username, 'users');
     // Add the necessary buttons
     JToolBarHelper::back('Back', 'index.php?option=com_community&view=users');
     JToolBarHelper::divider();
     JToolBarHelper::cancel('removeavatar', JText::_('CC REMOVE AVATAR'));
     JToolBarHelper::save();
     $model = CFactory::getModel('Profile');
     $profile = $model->getEditableProfile($user->id, $user->getProfileType());
     $config =& CFactory::getConfig();
     $params = $user->getParams();
     $userDST = $params->get('daylightsavingoffset');
     $offset = !empty($userDST) ? $userDST : $config->get('daylightsavingoffset');
     $counter = -4;
     $options = array();
     for ($i = 0; $i <= 8; $i++, $counter++) {
         $options[] = JHTML::_('select.option', $counter, $counter);
     }
     $offsetList = JHTML::_('select.genericlist', $options, 'daylightsavingoffset', 'class="inputbox" size="1"', 'value', 'text', $offset);
     $user->profile =& $profile;
     $this->assignRef('user', $user);
     $this->assignRef('params', $user->getParameters(true));
     $this->assignRef('offsetList', $offsetList);
     parent::display($tpl);
 }
Exemple #29
0
 function display($data = null)
 {
     $mainframe = JFactory::getApplication();
     $config = CFactory::getConfig();
     $document =& JFactory::getDocument();
     $document->setTitle(JText::sprintf('CC FRONTPAGE TITLE', $config->get('sitename')));
     $document->setLink(CRoute::_('index.php?option=com_community'));
     $my = CFactory::getUser();
     CFactory::load('libraries', 'activities');
     CFactory::load('helpers', 'string');
     $act = new CActivityStream();
     $rows = $act->getFEED('', '', null, $mainframe->getCfg('feed_limit'));
     if ($config->get('showactivitystream') == COMMUNITY_SHOW || $config->get('showactivitystream') == COMMUNITY_MEMBERS_ONLY && $my->id != 0) {
         foreach ($rows->data as $row) {
             if ($row->type != 'title') {
                 // load individual item creator class
                 $item = new JFeedItem();
                 // cannot escape the title. it's already formated. we should
                 // escape it during CActivityStream::add
                 //$item->title 		= CStringHelper::escape($row->title);
                 $item->title = $row->title;
                 $item->link = CRoute::_('index.php?option=com_community&view=profile&userid=' . $row->actor);
                 $item->description = "<img src=\"{$row->favicon}\" alt=\"\"/>&nbsp;" . $row->title;
                 $item->date = $row->createdDate;
                 $item->category = '';
                 //$row->category;
                 // Make sure url is absolute
                 $item->description = JString::str_ireplace('href="/', 'href="' . JURI::base(), $item->description);
                 // loads item info into rss array
                 $document->addItem($item);
             }
         }
     }
 }
Exemple #30
0
 function getMembersData(&$params)
 {
     $model = CFactory::getModel('user');
     $db = JFactory::getDBO();
     $limit = $params->get('count', '5');
     $query = 'SELECT ' . $db->quoteName('userid') . ' FROM ' . $db->quoteName('#__community_users') . ' AS a ' . ' INNER JOIN ' . $db->quoteName('#__users') . ' AS b ON a.' . $db->quoteName('userid') . '=b.' . $db->quoteName('id') . ' WHERE ' . $db->quoteName('thumb') . '!=' . $db->Quote('components/com_community/assets/default_thumb.jpg') . ' ' . ' AND ' . $db->quoteName('block') . '=' . $db->Quote(0) . ' ' . ' ORDER BY ' . $db->quoteName('points') . ' DESC ' . ' LIMIT ' . $limit;
     $db->setQuery($query);
     $row = $db->loadObjectList();
     if ($db->getErrorNum()) {
         JError::raiseError(500, $db->stderr());
     }
     $_members = array();
     if (!empty($row)) {
         foreach ($row as $data) {
             $user = CFactory::getUser($data->userid);
             $_obj = new stdClass();
             $_obj->id = $data->userid;
             $_obj->name = $user->getDisplayName();
             $_obj->avatar = $user->getThumbAvatar();
             $CUserPoints = new CUserPoints();
             $_obj->karma = $CUserPoints->getPointsImage($user);
             $_obj->userpoints = $user->_points;
             $_obj->link = CRoute::_('index.php?option=com_community&view=profile&userid=' . $data->userid);
             $_members[] = $_obj;
         }
     }
     return $_members;
 }