Skip to content

Commit

Permalink
More notifications and buddy systems code
Browse files Browse the repository at this point in the history
  • Loading branch information
MissAllSunday committed Mar 13, 2012
1 parent 68ccd3a commit 925d03a
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 54 deletions.
24 changes: 24 additions & 0 deletions Breeze/Breeze.php
Expand Up @@ -151,6 +151,30 @@ public static function ProfileInfo(&$profile_areas)
), ),
); );


/* Buddies page */
/* if $some_check here */
$profile_areas['breeze_profile']['areas']['breezebuddies'] = array(
'label' => $s->GetText('user_buddysettings_name'),
'file' => Breeze::$BreezeFolder .'Breeze_User.php',
'function' => 'Breeze_Wrapper_BuddyRequest',
'permission' => array(
'own' => 'profile_view_own',
'any' => 'profile_view_any',
),
);

/* Notifications admin page */
/* if $some_check here */
$profile_areas['breeze_profile']['areas']['breezenoti'] = array(
'label' => $s->GetText('user_notisettings_name'),
'file' => Breeze::$BreezeFolder .'Breeze_User.php',
'function' => 'Breeze_Wrapper_Notifications',
'permission' => array(
'own' => 'profile_view_own',
'any' => 'profile_view_any',
),
);

/* Done with the hacking... */ /* Done with the hacking... */
} }


Expand Down
43 changes: 41 additions & 2 deletions Breeze/Breeze_Buddy.php
Expand Up @@ -44,7 +44,7 @@ public function __construct(){}


public static function Buddy() public static function Buddy()
{ {
global $user_info; global $user_info, $scripturl;


checkSession('get'); checkSession('get');


Expand All @@ -54,10 +54,18 @@ public static function Buddy()
Breeze::Load(array( Breeze::Load(array(
'Settings', 'Settings',
'Globals', 'Globals',
'Notifications',
'UserInfo',
'Query'
)); ));


/* We need all this stuff */
$sa = new Breeze_Globals('get'); $sa = new Breeze_Globals('get');
$notification = new Breeze_Notification();
$setings = Breeze_Settings::getInstance();



/* There's gotta be an user... */
if ($sa->Validate('u') == false) if ($sa->Validate('u') == false)
fatal_lang_error('no_access', false); fatal_lang_error('no_access', false);


Expand All @@ -73,13 +81,44 @@ public static function Buddy()
/* Before anything else, let's ask the user shall we? */ /* Before anything else, let's ask the user shall we? */
elseif ($user_info['id'] != $sa->Raw('u')) elseif ($user_info['id'] != $sa->Raw('u'))
{ {
/* Load the users link */
$user_asking = Breeze_UserInfo::Profile($user_info['id']);
$user_receiving = Breeze_UserInfo::Profile($sa->Raw('u'));

$params = array(
'user' => $sa->Raw('u'),
'time' => time(),
'read' => 0,
'content' => array(
'title' => $settings->GetText('noti_buddy_title'),
'message' => sprintf($settings->GetText('noti_buddy_message'), $context['Breeze']['user_info']['link'][$user_info['id']]),
'url' => $scripturl .'?action=profile;area=breezebuddies;u='. $sa->Raw('u')
)
);

/* Notification here */ /* Notification here */
$notification->Create('buddy', $params);


$user_info['buddies'][] = (int) $sa->Raw('u'); $user_info['buddies'][] = (int) $sa->Raw('u');


/* Show a nice message saying the user must approve the friendship request */ /* Show a nice message saying the user must approve the friendship request */
redirectexit('action=profile;sa=buddymessage;u=' . $sa->Raw('u')); redirectexit('action=profile;area=breezebuddies;u=' . $sa->Raw('u'));
} }


} }

public function ShowBuddyRequests($user)
{
$query = Breeze_Query::getInstance();

/* Load all buddy request for this user */
$query->GetNotificationByType($user);

/* We only want the notification for this user... */


/* Return the notifications */


}
} }
69 changes: 24 additions & 45 deletions Breeze/Breeze_Notifications.php
Expand Up @@ -40,19 +40,21 @@


class Breeze_Notifications class Breeze_Notifications
{ {
$types = array(); protected $types = array();
$params = array(); protected $params = array();
$user = 0; private $user = 0;
$settings = ''; private $settings = '';
$query = ''; private $query = '';
private $ReturnArray = array();


function __construct() function __construct()
{ {
$this->types = array( $this->types = array(
'comment', 'comment',
'status', 'status',
'like', 'like',
'buddy' 'buddy',
'mention'
); );


Breeze::Load(array( Breeze::Load(array(
Expand All @@ -70,62 +72,39 @@ public function Create($type, $params)
if (in_array($type, $this->types) && !empty($params)) if (in_array($type, $this->types) && !empty($params))
{ {
$this->params = $params; $this->params = $params;
$this->type = $type;
$this->params['type'] = $this->type;


switch ($type) $this->query->InsertNotification($this->params);
{
case 'comment':
$this->NewComment();
break;
case 'status':
$this->NewStatus();
break;
case 'like':
$this->NewLike();
case 'buddy':
$this->NewBuddy();
break;
}
} }
}

protected function NewComment()
{

}

protected function NewStatus()
{


else
return false;
} }


protected function NewLike() protected function GetByUser($user)
{

}

protected function NewBuddy()
{

}

public function GetByUser($user)
{ {
/* Dont even bother... */ /* Dont even bother... */
if (empty($user)) if (empty($user))
return; return;


$this->user = $user; $user = (int) $user;


return $this->query->GetNotificationByUser($user);
} }


public function Stream() public function Stream($user)
{ {

return $this->GetByUser($user);
} }


protected function Delete() protected function Delete($id)
{ {
$this->query->DeleteNotification($id);
}



protected function MarkAsRead($id)
{
$this->query->MarkAsReadNotification($id);
} }
} }
20 changes: 19 additions & 1 deletion Breeze/Breeze_Parser.php
Expand Up @@ -41,11 +41,16 @@


class Breeze_Parser class Breeze_Parser
{ {
private $notification;

function __construct() function __construct()
{ {
Breeze::Load(array( Breeze::Load(array(
'Subs' 'Subs',
'Notifications'
)); ));

$this->notification = new Breeze_Notifications();
} }


function Display($string) function Display($string)
Expand Down Expand Up @@ -90,6 +95,19 @@ private function Mention($s)
{ {
$context['Breeze']['user_info'][$user[0]] = Breeze_UserInfo::Profile($user[0], true); $context['Breeze']['user_info'][$user[0]] = Breeze_UserInfo::Profile($user[0], true);
$s = str_replace($matches[0], '@'.$context['Breeze']['user_info']['link'][$user[0]], $s); $s = str_replace($matches[0], '@'.$context['Breeze']['user_info']['link'][$user[0]], $s);

/* Does this user wants to be notificated? */
/* Some if check here */
{
/* Build the params */
$params = array(
/* Params here */
);

/* Create the notification */
$this->notification->Create('mention', $params);
}

} }
else else
$s = str_replace($matches[0], '@'.$m, $s); $s = str_replace($matches[0], '@'.$m, $s);
Expand Down
27 changes: 24 additions & 3 deletions Breeze/Breeze_Query.php
Expand Up @@ -55,7 +55,7 @@ class Breeze_Query
private $valid = false; private $valid = false;
private $global_settings; private $global_settings;


private function __construct() protected function __construct()
{ {
Breeze::Load(array( Breeze::Load(array(
'DB', 'DB',
Expand Down Expand Up @@ -402,10 +402,9 @@ public function GetStatusByID($id)
*/ */
public function GetStatusByUser($id) public function GetStatusByUser($id)
{ {
return $this->GetReturn('status', 'status_id', $id); return $this->GetReturn('status', 'status_user', $id);
} }



/* Methods for comments */ /* Methods for comments */


/* /*
Expand Down Expand Up @@ -962,6 +961,23 @@ public function InsertNotification($array)
$this->Query('notifications')->InsertData($data, $array, $indexes); $this->Query('notifications')->InsertData($data, $array, $indexes);
} }


public function MarkAsReadNotification($id)
{
/* Delete! */
$params = array(
'set' => 'read = {int:read}',
'where' => 'id = {int:id}'
);

$data = array(
'read' => 1,
'id' => $id
);

$this->Query('notifications')->Params($params, $data);
$this->Query('notifications')->UpdateData();
}

public function DeleteNotification($id) public function DeleteNotification($id)
{ {
/* Delete! */ /* Delete! */
Expand All @@ -981,6 +997,11 @@ public function GetNotificationByUser($user)
{ {
return $this->GetReturn('notifications', 'user', $user); return $this->GetReturn('notifications', 'user', $user);
} }

public function GetNotificationByType($user)
{
return $this->GetReturn('notifications', 'type', $user);
}
} }


/* /*
Expand Down
2 changes: 1 addition & 1 deletion Breeze/Breeze_User.php
Expand Up @@ -42,7 +42,7 @@
function Breeze_Wrapper_Wall(){Breeze_User::Wall();} function Breeze_Wrapper_Wall(){Breeze_User::Wall();}
function Breeze_Wrapper_Settings(){Breeze_User::Settings();} function Breeze_Wrapper_Settings(){Breeze_User::Settings();}
function Breeze_Wrapper_BuddyRequest(){Breeze_User::BuddyRequest();} function Breeze_Wrapper_BuddyRequest(){Breeze_User::BuddyRequest();}
function Breeze_Wrapper_BuddyMessage(){Breeze_User::BuddyMessage();} function Breeze_Wrapper_Notifications(){Breeze_User::Notifications();}


class Breeze_User class Breeze_User
{ {
Expand Down
7 changes: 5 additions & 2 deletions languages/Breeze.english.php
Expand Up @@ -58,6 +58,8 @@
/* User Individual Settings */ /* User Individual Settings */
$txt['BreezeMod_profile'] = 'Wall Settings'; $txt['BreezeMod_profile'] = 'Wall Settings';
$txt['BreezeMod_user_settings_name'] = 'Wall Settings'; $txt['BreezeMod_user_settings_name'] = 'Wall Settings';
$txt['BreezeMod_user_buddysettings_name'] = 'Buddy Requests';
$txt['BreezeMod_user_notisettings_name'] = 'Notifications';
$txt['BreezeMod_user_settings_wall_limit'] = 'How many status per page to show?'; $txt['BreezeMod_user_settings_wall_limit'] = 'How many status per page to show?';
$txt['BreezeMod_user_settings_wall_limit_sub'] = 'This will be the number of status to show by default, max value is 30, if set it will create a pagination with the rest of your status.'; $txt['BreezeMod_user_settings_wall_limit_sub'] = 'This will be the number of status to show by default, max value is 30, if set it will create a pagination with the rest of your status.';
$txt['BreezeMod_user_settings_kick_ignored'] = 'Do not show my wall to users in my ignore list'; $txt['BreezeMod_user_settings_kick_ignored'] = 'Do not show my wall to users in my ignore list';
Expand Down Expand Up @@ -172,6 +174,7 @@
$txt['BreezeMod_pag_first'] = 'First'; $txt['BreezeMod_pag_first'] = 'First';
$txt['BreezeMod_pag_last'] = 'Last'; $txt['BreezeMod_pag_last'] = 'Last';



/* Notifications */ /* Notifications */
$txt['BreezeMod_noti_title'] = 'Notifications'; $txt['BreezeMod_noti_title'] = 'Notifications';
$txt['BreezeMod_noti_buddy_title'] = 'Buddy notification';
$txt['BreezeMod_noti_buddy_message'] = 'The user %1$s has added you as his/her buddy, please confirm this request.';

0 comments on commit 925d03a

Please sign in to comment.