Ejemplo n.º 1
0
 /**
  * Gets an account's collaborators as an array
  *
  * @return array
  */
 public function get_collaborators()
 {
     $collaborators = array();
     foreach ($this->account_collaborators->find_all() as $collaborator) {
         $collaborators[] = array('id' => $collaborator->user->id, 'name' => $collaborator->user->name, 'account_path' => $collaborator->user->account->account_path, 'collaborator_active' => $collaborator->collaborator_active, 'avatar' => Swiftriver_Users::gravatar($collaborator->user->email, 40));
     }
     return $collaborators;
 }
Ejemplo n.º 2
0
 /**
  * @return	void
  */
 public function action_index()
 {
     $this->template->header->title = $this->page_title;
     $this->template->content = View::factory('pages/bucket/discussion')->bind('settings_url', $settings_url)->bind('fetch_url', $fetch_url)->bind('bucket_url', $this->bucket_base_url)->bind('page_title', $this->page_title)->bind('owner', $this->owner)->bind('user', $this->user)->bind('user_avatar', $user_avatar);
     $this->template->content->collaborators = $this->bucket->get_collaborators(TRUE);
     $user_avatar = Swiftriver_Users::gravatar($this->user->email, 80);
     // Links to ajax rendered menus
     $settings_url = $this->bucket_base_url . '/settings';
     $fetch_url = $this->bucket_base_url . '/discussion/comments';
 }
Ejemplo n.º 3
0
 /**
  * List all the users
  *
  * @return	void
  */
 public function action_index()
 {
     $this->template->header->title = __('Users');
     $this->settings_content = View::factory('pages/settings/users')->bind('fetch_url', $fetch_url)->bind('users_list', $users_list);
     $this->active = 'users';
     $fetch_url = URL::site() . 'settings/users/manage';
     $users = array();
     foreach (ORM::factory('User')->where('username', '<>', 'admin')->find_all() as $user) {
         $users[] = array("id" => $user->id, "name" => $user->name, "user_avatar" => Swiftriver_Users::gravatar($user->email, 45), "user_url" => URL::site() . $user->account->account_path);
     }
     $users_list = json_encode($users);
 }
Ejemplo n.º 4
0
<article class="<?php 
echo $template_type;
?>
">
	<div class="center page-title cf">
		<hgroup class="edit user">
			<img src="<?php 
echo Swiftriver_Users::gravatar($user->email, 80);
?>
" />
			<h1><span class="edit-trigger" title="dashboard" id="edit_<?php 
echo $user->id;
?>
" onclick=""><?php 
echo $user->name;
?>
</span></h1>
		</hgroup>
	</div>


	<div class="center canvas cf">
		<section class="panel">		
			<nav class="cf">
				<ul class="views">
					<li <?php 
if ($active == 'buckets') {
    echo 'class="active"';
}
?>
>
Ejemplo n.º 5
0
 /**
  * Gets a river's collaborators as an array
  *
  * @return array
  */
 public function get_collaborators($active_only = FALSE)
 {
     $collaborators = array();
     foreach ($this->river_collaborators->find_all() as $collaborator) {
         if ($active_only and !(bool) $collaborator->collaborator_active) {
             continue;
         }
         $collaborators[] = array('id' => $collaborator->user->id, 'name' => $collaborator->user->name, 'account_path' => $collaborator->user->account->account_path, 'collaborator_active' => $collaborator->collaborator_active, 'read_only' => (bool) $collaborator->read_only, 'avatar' => Swiftriver_Users::gravatar($collaborator->user->email, 40));
     }
     return $collaborators;
 }
Ejemplo n.º 6
0
 /**
  * Get a list of users whose name/email begins with the provided string
  *
  * @param $search_string
  * @return array
  */
 public static function get_like($search_string, $exclude_ids = array(), $limit = 10)
 {
     $users = array();
     $search_string = strtolower(trim($search_string));
     $users_query = ORM::factory('user')->where('username', '!=', 'public')->where_open()->where(DB::expr('lower(email)'), 'like', "{$search_string}%")->or_where(DB::expr('lower(name)'), 'like', "{$search_string}%")->or_where(DB::expr('lower(name)'), 'like', "% {$search_string}%")->where_close();
     if (!empty($exclude_ids)) {
         $users_query->and_where('id', 'not in', $exclude_ids);
     }
     $users_query->limit($limit);
     $users_orm = $users_query->find_all();
     foreach ($users_orm as $user) {
         $users[] = array('id' => $user->id, 'name' => $user->name, 'account_path' => $user->account->account_path, 'avatar' => Swiftriver_Users::gravatar($user->email, 40));
     }
     return $users;
 }
Ejemplo n.º 7
0
 /**
  *
  * @param int $droplet_id Database ID of the drop
  * @param int $last_id Pagination reference point
  * @param boolean $newer Flag to get newer drops than last_id when true
  * @return array
  */
 public static function get_comments($drop_id, $last_id = PHP_INT_MAX, $newer = FALSE)
 {
     $query = DB::select(array('droplet_comments.id', 'id'), array('droplet_comments.droplet_id', 'droplet_id'), 'comment_text', 'deleted', array('users.id', 'identity_user_id'), array('users.name', 'identity_name'), array('users.email', 'identity_email'), array(DB::expr('DATE_FORMAT(date_added, "%b %e, %Y %H:%i UTC")'), 'date_added'))->from('droplet_comments')->join('users', 'INNER')->on('droplet_comments.user_id', '=', 'users.id')->where('droplet_comments.droplet_id', '=', $drop_id)->limit(20);
     if ($newer) {
         $query->where('droplet_comments.id', '>', $last_id);
         $query->order_by('droplet_comments.id', 'ASC');
     } else {
         $query->where('droplet_comments.id', '<', $last_id);
         $query->order_by('droplet_comments.id', 'DESC');
     }
     // Group the comments per droplet
     $comments = $query->execute()->as_array();
     foreach ($comments as &$comment) {
         $comment['identity_avatar'] = Swiftriver_Users::gravatar($comment['identity_email'], 80);
         $comment['deleted'] = (bool) $comment['deleted'];
         if ($comment['deleted']) {
             $comment['comment_text'] = __('This comment has been removed.');
         }
     }
     return $comments;
 }
Ejemplo n.º 8
0
<hgroup class="user-title <?php 
if ($owner) {
    echo 'dashboard';
}
?>
 cf">
	<div class="center">
		<div class="user-summary col_9">
			<a class="avatar-wrap" href="<?php 
echo URL::site() . $account->account_path;
?>
">
				<img src="<?php 
echo Swiftriver_Users::gravatar($account->user->email, 131);
?>
" class="avatar"/>
			</a>
			<h1><?php 
echo $account->user->name;
?>
</h1>
			<h2 class="label"><?php 
echo $account->account_path;
?>
</h2>
		</div>
		<div id="follow_section" class="follow-summary col_3">
			<p class="follow-count">
				<a id="follower_count" href="<?php 
echo URL::site() . $account->account_path . '/followers';
?>
Ejemplo n.º 9
0
			<li class="user popover">
				<a href="#" class="popover-trigger">
					<span class="icon-arrow-down"></span>
					<span class="avatar-wrap">
						<?php 
    if ($num_notifications) {
        ?>
							<span class="notification"><?php 
        echo $num_notifications;
        ?>
</span>
						<?php 
    }
    ?>
						<img src="<?php 
    echo Swiftriver_Users::gravatar($user['owner']['email'], 80);
    ?>
" />
					</span>
					<span class="nodisplay">Account Name</span>
				</a>
				<ul class="popover-window base header-toolbar">
					<li>
						<a href="<?php 
    echo URL::site($user['account_path']);
    ?>
">
							<?php 
    echo __('Your Activity');
    if ($num_notifications) {
        echo ' (' . $num_notifications . ')';
Ejemplo n.º 10
0
 /**
  * Displays the users being followed
  */
 public function action_following()
 {
     $this->template->header->title = __("Following");
     $this->sub_content = View::factory('pages/user/followers')->bind('owner', $this->owner)->bind('follower_list', $follower_list)->bind('fetch_url', $fetch_url)->bind('account_owner', $account_owner)->bind('user', $this->user);
     $this->sub_content->header_title = __("Following");
     $this->sub_content->following_mode = TRUE;
     $account_owner = $this->visited_account->user->name;
     $following = $this->owner ? $this->user->get_following() : $this->visited_account->user->get_following();
     foreach ($following as &$follow) {
         $follow['user_avatar'] = Swiftriver_Users::gravatar($follow['username'], 35);
         $follow['user_url'] = URL::site() . $follow['account_path'];
         $follow['subscribed'] = TRUE;
         $follow['type'] = "user";
     }
     $follower_list = json_encode($following);
     $fetch_url = URL::site() . $this->visited_account->account_path . '/user/followers/manage';
 }
Ejemplo n.º 11
0
 /**
  * @test
  * @dataProvider provider_gravatar
  */
 public function test_gravatar($email, $s, $d, $r, $img, $atts, $expected)
 {
     $url = Swiftriver_Users::gravatar($email, $s, $d, $r, $img, $atts);
     $parts = explode('/', $url);
     $this->assertEquals($expected, array_pop($parts));
 }
Ejemplo n.º 12
0
 /**
  * Replies restful api
  */
 public function action_reply()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     $droplet_id = intval($this->request->param('id', 0));
     switch ($this->request->method()) {
         case "GET":
             $params = $this->request->query();
             if (isset($params['since_id'])) {
                 $since_id = intval($this->request->query('since_id'));
                 $comments = Model_Droplet::get_comments($droplet_id, $since_id, TRUE);
             } else {
                 $last_id = $this->request->query('last_id') ? intval($this->request->query('last_id')) : PHP_INT_MAX;
                 $comments = Model_Droplet::get_comments($droplet_id, $last_id);
                 if (empty($comments)) {
                     throw new HTTP_Exception_404('The requested page was not found on this server.');
                 }
             }
             echo json_encode($comments);
             break;
         case "POST":
             // Is the logged in user an owner?
             if (!$this->owner) {
                 throw new HTTP_Exception_403();
             }
             // Get the POST data
             $body = json_decode($this->request->body(), TRUE);
             $comment = ORM::factory('droplet_comment');
             $comment->comment_text = $body['comment_text'];
             $comment->droplet_id = intval($this->request->param('id', 0));
             $comment->user_id = $this->user->id;
             $comment->save();
             if ($comment->loaded()) {
                 echo json_encode(array('id' => $comment->id, 'droplet_id' => $comment->droplet_id, 'comment_text' => $comment->comment_text, 'identity_user_id' => $this->user->id, 'identity_name' => $this->user->name, 'identity_avatar' => Swiftriver_Users::gravatar($this->user->email, 80), 'deleted' => FALSE, 'date_added' => date_format(date_create($comment->date_added), 'M d, Y H:i') . ' UTC'));
             } else {
                 $this->response->status(400);
             }
             break;
         case "PUT":
             $comment_id = intval($this->request->param('id2', 0));
             $comment = ORM::factory('droplet_comment', $comment_id);
             // Does the comment exist?
             if (!$comment->loaded()) {
                 throw new HTTP_Exception_404();
             }
             // Is owner of the comment logged in?
             if ($comment->user->id != $this->user->id) {
                 throw new HTTP_Exception_403();
             }
             $comment->deleted = TRUE;
             $comment->save();
             break;
     }
 }
Ejemplo n.º 13
0
 /**
  * Gets actions and notification for the user's follows or the user's activities
  *
  * @param    int $user_id Visited user ID
  * @param    int $visitor_id ID of the user viewing the profile
  * @param    boolean $self If TRUE, only get the specified user_id's actions otherwise that of his following
  * @return   array
  */
 public static function get_activity_stream($user_id, $visitor_id = NULL, $self = FALSE)
 {
     // Notifications
     $query = DB::select('id', array(DB::expr('DATE_FORMAT(action_date_add, "%b %e, %Y %H:%i UTC")'), 'action_date'), 'user_id', 'user_name', 'user_email', 'action', 'action_on', 'action_on_id', 'action_on_name', 'action_to_name', 'action_to_id', 'confirmed', array(DB::expr("IF(action_to_id={$user_id}, 1, 0)"), 'action_to_self'))->from('activity_stream');
     if ($self) {
         // Get the specified user_id's actions
         $query->where('user_id', '=', $user_id);
     } else {
         // Get the actions of the users user_id is following
         $query->where('user_id', 'IN', DB::expr("(SELECT user_id FROM user_followers WHERE follower_id = {$user_id})"))->or_where('action_to_id', '=', $user_id);
     }
     $query->order_by('action_date_add', 'DESC');
     $results = $query->execute()->as_array();
     // Tracks the action target and the corresponding users
     $actions = array();
     // List of action initiatators
     $initiators = array();
     foreach ($results as $result) {
         // Set action url
         $action_on_url = "";
         $action_on_name = "";
         $action_on = $result['action_on'];
         $action_on_id = $result["action_on_id"];
         // Whether to leave out the current activity feed item
         // from the final result
         // An item is left out when:
         //    action_on item is private
         //    visitor does not own action_on item and action_to_self = 0
         $skip_activity_item = FALSE;
         if ($action_on == "account") {
             $action_on_url = URL::site() . $result["action_on_name"];
         } elseif ($action_on == "river") {
             $river_orm = ORM::factory("river", $action_on_id);
             if (!$river_orm->river_public) {
                 $is_owner = $river_orm->is_owner($visitor_id);
                 if (!$is_owner and $result['action_to_self'] == 1 or $is_owner) {
                     $skip_activity_item = FALSE;
                 } else {
                     $skip_activity_item = TRUE;
                 }
             }
             $action_on_name = $river_orm->river_name;
             $action_on_url = URL::site() . $river_orm->account->account_path . '/river/' . $river_orm->river_name_url;
         } elseif ($action_on == "bucket") {
             $bucket_orm = ORM::factory("bucket", $action_on_id);
             if (!$bucket_orm->bucket_publish) {
                 $is_owner = $bucket_orm->is_owner($visitor_id);
                 if (!$is_owner and $result['action_to_self'] == 1 or $is_owner) {
                     $skip_activity_item = FALSE;
                 } else {
                     $skip_activity_item = TRUE;
                 }
             }
             $action_on_name = $bucket_orm->bucket_name;
             $action_on_url = URL::site() . $bucket_orm->account->account_path . '/bucket/' . $bucket_orm->bucket_name_url;
         }
         // Leave out current activity feed item?
         if ($skip_activity_item) {
             continue;
         }
         // Condense the activity stream data
         $user_id = $result['user_id'];
         if (!array_key_exists($result['user_id'], $actions)) {
             $actions[$user_id] = array();
             // Set the user's url
             $user_orm = ORM::factory('user', $result["user_id"]);
             // Populate the initiators array
             $initiators[$user_id] = array('name' => $user_id === $visitor_id ? __('You') : $result["user_name"], 'avatar' => Swiftriver_Users::gravatar($result["user_email"]), 'url' => $result["user_url"] = URL::site() . $user_orm->account->account_path);
         }
         $action_name = $result['action'];
         if (!array_key_exists($action_name, $actions[$user_id])) {
             $actions[$user_id][$action_name] = array();
         }
         // Timestamp for the action date
         $action_timestamp = strtotime(strftime("%a %b %e, %Y", strtotime($result['action_date'])));
         if ($result['action_to_self'] == 1 and $result['confirmed'] == 0) {
             // Modify the timestamp of the action
             $action_timestamp = strtotime($result['action_date']);
         }
         if (!array_key_exists($action_timestamp, $actions[$user_id][$action_name])) {
             $actions[$user_id][$action_name][$action_timestamp] = array();
         }
         // Generate a unique action key (user_id, action_name, timestamp)
         // Use the memory address to avoid having to set the
         // key to the mod'd value
         $action_key =& $actions[$user_id][$action_name][$action_timestamp];
         // Target of the action
         if (!array_key_exists($action_on, $action_key)) {
             $action_key[$action_on] = array('targets' => array());
         }
         // Action targets + users
         if (!array_key_exists($action_on_id, $action_key[$action_on]['targets'])) {
             $action_key[$action_on]['targets'][$action_on_id] = array('action_on_url' => $action_on_url, 'action_on_name' => $action_on_name, 'users' => array());
         }
         // Target user id and name
         $action_to_data = array('action_id' => $result['id'], 'action_date' => $result['action_date'], 'action_to_self' => $result['action_to_self'], 'confirmed' => $result['confirmed'], 'action_to_id' => $result['action_to_id'], 'action_to_name' => $result['action_to_self'] == 1 ? __('you') : $result['action_to_name']);
         // Grouping step - Add to the targeted user id to the action target
         array_push($action_key[$action_on]['targets'][$action_on_id]['users'], $action_to_data);
     }
     // Garbage collection
     unset($result);
     // Pack the data for convenient JSON traversal
     $packed = array();
     foreach ($actions as $user_id => $data) {
         $entry = array('user_id' => $user_id, 'user_name' => $initiators[$user_id]['name'], 'user_avatar' => $initiators[$user_id]['avatar'], 'user_url' => $initiators[$user_id]['url'], 'actions' => array());
         foreach ($data as $action => $action_data) {
             $action_entry = array('action_name' => $action, 'action_data' => array());
             foreach ($action_data as $timestamp => $target_data) {
                 foreach (array_keys($target_data) as $action_on) {
                     $action_on_id = array_keys($target_data[$action_on]['targets']);
                     $action_entry['action_data'][] = array('timestamp' => $timestamp, 'timestamp_date_str' => gmstrftime("%a %b %e, %Y UTC", $timestamp), 'action_on' => $action_on, 'action_on_id' => $action_on_id[0], 'action_on_target' => $target_data[$action_on]['targets'][$action_on_id[0]]);
                 }
             }
             $entry['actions'][] = $action_entry;
         }
         $packed[] = $entry;
     }
     return $packed;
 }
Ejemplo n.º 14
0
 /**
  * Notify bucket owners and followers of a new comment
  * 
  * @return	void
  */
 public static function notify_new_bucket_comment($comment, $bucket)
 {
     $html = View::factory('emails/html/comment');
     $text = View::factory('emails/text/comment');
     $html->is_drop = $text->is_drop = FALSE;
     $html->from_name = $text->from_name = $comment->user->name;
     $html->avatar = Swiftriver_Users::gravatar($comment->user->email, 80);
     $html->from_link = URL::site($comment->user->account->account_path, TRUE);
     $html->asset = $text->asset = 'bucket';
     $html->asset_name = $text->asset_name = $bucket->bucket_name;
     $html->asset_link = $text->asset_link = URL::site($bucket->get_base_url(), TRUE);
     $html->link = $text->link = URL::site($bucket->get_base_url() . '/discussion#comment-' . $comment->id, TRUE);
     $text->comment = $comment->comment_content;
     $html->comment = Markdown::instance()->transform($comment->comment_content);
     $subject = __(':from commented on the ":name" bucket.', array(":from" => $comment->user->name, ":name" => $bucket->bucket_name));
     // Add owner of the bucket first
     $emails = array($bucket->user->email);
     // Then collaborators
     foreach ($bucket->get_collaborators(TRUE) as $collaborator) {
         $emails[] = $collaborator['email'];
     }
     // Then followers
     foreach ($bucket->subscriptions->find_all() as $follower) {
         $emails[] = $follower->email;
     }
     $text_body = $text->render();
     $html_body = $html->render();
     $site_email = Swiftriver_Mail::get_default_address();
     $from = '"' . $comment->user->name . '" <notifications@' . Swiftriver_Mail::get_email_domain() . '>';
     $token_data = array('bucket_id' => $comment->bucket_id);
     $token = Model_Auth_Token::create_token('bucket-comment', $token_data);
     $reply_to = 'bucket-comment-' . $token->token . '@' . Swiftriver_Mail::get_comments_email_domain();
     foreach ($emails as $email) {
         if ($email != $comment->user->email) {
             Swiftriver_Mail::send($email, $subject, $text_body, $html_body, $from, array('Reply-To' => $reply_to));
         }
     }
 }