I'm mostly using FBSS as an api, doing all my display with Heartbeat module. However, I'm using the 'facebook_status' block in order to let users post statuses.

I want users to be able to post on other user's profiles, however I'm using content profile, not core profile module. So, essentially I'm trying to find a way to render the form, but manually pass in the context (which I'll get from the $node->uid of the node I'm viewing). How can/should I do this?

Essentially, I'm trying to get the same functionality that's offered 'out of the box' on core user profiles, but instead I need to set my target user (in the context) by passing in the node author....

thoughts?

Comments

icecreamyou’s picture

Yeah, I thought about making this into its own context when I was writing the default contexts. That's what you'll have to do -- you'll need to write a new module that adds this as a new context. Here's your .module file (sans closing ?>):


/**
 * @file
 *   Provides a node author context to the Facebook-style Statuses module.
 */

/**
 * Implementation of hook_facebook_status_context_info().
 */
function EXAMPLE_facebook_status_context_info() {
  $path = drupal_get_path('module', 'facebook_status');
  return array(
    'node_author' => array(
      'title' => t('Node author'),
      'description' => t('The stream belongs to the author currently viewed node, if applicable.'),
      'handler' => 'facebook_status_node_author_context',
      'view' => 'facebook_status_stream',
      'weight' => -2,
      'file' => $path .'/includes/utility/facebook_status.contexts.inc',
    ),
  );
}

/**
 * The node author context.
 */
class facebook_status_node_author_context extends facebook_status_user_context {
  function type() {
    return 'node_author';
  }
  function is_applicable() {
    return arg(0) == 'node' && is_numeric(arg(1));
  }
  function find_recipient() {
    return $this->is_applicable() ? $this->load_recipient(menu_get_object('node')->uid) : new stdClass();
  }
  function recipient_url($recipient) {
    return 'user/'. $this->recipient_id($recipient);
  }
}

If you need to use the status update form on other pages with other node types and you don't want this context to apply on them as well, you can either add a check to the is_applicable() method of the facebook_status_node_author_context class or you can edit the context's settings and change where it applies that way.

I'll think about making this available as a default context. For me to do that I would want a way to have contexts "disabled" by default so I'd need to add that feature first but I think it would be a good idea.

Rob_Feature’s picture

You rock :)

This is exactly what I need...however, I'm getting an error in the custom module which is:

Fatal error: Class 'facebook_status_user_context' not found in....[my module]

Thoughts? I'm not familiar 'extends' as in: extends facebook_status_user_context
so I'm not sure how to bugtest.

Rob_Feature’s picture

Tried adding
module_load_include('inc', 'facebook_status', 'includes/utility/facebook_status.contexts.inc');
without success...it seems like if I just include that file it should find the function?

icecreamyou’s picture

Oh, sorry. Yeah, unfortunately you need to add that line in the main body of the file to include FBSS' context file. You may also want to put the class in its own file (with the include of facebook_status.contexts.inc at the top).

Rob_Feature’s picture

Sorry, not sure I follow. I tried to do the module_load_include shown above, but it doesn't work. I still get the same error. Can you clarify what I should try next?

icecreamyou’s picture

Status: Active » Fixed

EXAMPLE.module:

/**
* @file
*   Provides a node author context to the Facebook-style Statuses module.
*/

/**
* Implementation of hook_facebook_status_context_info().
*/
function EXAMPLE_facebook_status_context_info() {
  return array(
    'node_author' => array(
      'title' => t('Node author'),
      'description' => t('The stream belongs to the author currently viewed node, if applicable.'),
      'handler' => 'facebook_status_node_author_context',
      'view' => 'facebook_status_stream',
      'weight' => -2,
      'file' => drupal_get_path('module', 'EXAMPLE') .'/EXAMPLE.contexts.inc',
    ),
  );
}

EXAMPLE.contexts.inc:


/**
 * @file
 *   Provides Facebook-style Statuses contexts for the EXAMPLE module.
 */

module_load_include('inc', 'facebook_status', 'includes/utility/facebook_status.contexts.inc');

/**
* The node author context.
*/
class facebook_status_node_author_context extends facebook_status_user_context {
  function type() {
    return 'node_author';
  }
  function is_applicable() {
    return arg(0) == 'node' && is_numeric(arg(1));
  }
  function find_recipient() {
    return $this->is_applicable() ? $this->load_recipient(menu_get_object('node')->uid) : new stdClass();
  }
  function recipient_url($recipient) {
    return 'user/'. $this->recipient_id($recipient);
  }
}
Rob_Feature’s picture

Thanks for going the extra mile on this...unfortunately I still get the same Class 'facebook_status_user_context' not found error when clicking configure next to the context, but I'll keep working to see if I can figure out why it's not finding that in the FBSS inc file...

Rob_Feature’s picture

Just doing some reading on "extends" (which I dont know anything about) and I think this error may be actually related to facebook_status_user_context() not being 'defined' before being extended. I'm not totally sure what that means (or how to define it) but I've read a few posts that if it's undefined it'll give a 'not found'....

This from php.net:

Classes must be defined before they are used! If you want the class Named_Cart to extend the class Cart, you will have to define the class Cart first. If you want to create another class called Yellow_named_cart based on the class Named_Cart you have to define Named_Cart first. To make it short: the order in which the classes are defined is important.

I'm going to see if I can figure out how to "define" that function before I extend it...

icecreamyou’s picture

It's a class, not a function: http://php.net/oop

And that *is* the reason for the error but I don't know why that class wouldn't be available if the correct file was included. Try using require_once instead of module_load_include().

Rob_Feature’s picture

it turns out the 'not found' was becuase my include was wrong. It should be
module_load_include('inc', 'facebook_status', 'includes/utility/facebook_status.contexts');
not

module_load_include('inc', 'facebook_status', 'includes/utility/facebook_status.contexts.inc');

(note the extra .inc at the end of the filename)

Although, now that I have no errors, posting on the content profile still doesn't give a target..hmmm....

icecreamyou’s picture

Just having the context in your system might not be enough -- you probably have to go to admin/settings/facebook_status/context and make sure that the new context takes priority over the User Profiles and Nodes contexts.

Rob_Feature’s picture

You, my friend, rock.

All good! The user profile must have been taking priority, it all works now. Thanks for your help and the great module!

icecreamyou’s picture

Category: support » feature
Priority: Normal » Minor
Status: Fixed » Reviewed & tested by the community

Cool. Glad it works.

I'm going to hold on to this then... will consider committing it.

icecreamyou’s picture

Project: Facebook-style Statuses (Microblog) » Statuses (Social Microblog)
Version: 6.x-3.x-dev » 7.x-1.x-dev
Component: Code - API » Code (Features)
capellic’s picture

I had the below all typed up when I discovered I forgot the change the path for my include path:

'file' => drupal_get_path('module', 'EXAMPLE') .'/fourh_fbss.contexts.inc',

But thought I'd post this anyway just in case somebody else had the problem.

---

When I try to save the configuration page and give the node author priority, I get the white screen of death with this error:

PHP Fatal error:  Class 'facebook_status_node_author_context' not found in sites/all/modules/facebook_status/facebook_status.module on line 620, referer: admin/settings/facebook_status/contexts

I went into the facebook_status_contexts table and manually changed the weights so that node_author is -3 and user is -4. Then the fatal error when away, but now I'm back to square one-- the context is never hit, user is taking priority.

I thought this might be a module weight issue-- but tried 100 and -100 with no luck.

capellic’s picture

I got this working, but since I'm using panels, Drupal does know about a path that isn't node/[nid] -- it's member/[name]. Here's the context include file code:

/**
 * @file
 *   Provides Facebook-style Statuses contexts for the EXAMPLE module.
 */

module_load_include('inc', 'facebook_status', 'includes/utility/facebook_status.contexts');

/**
* The node author context.
*/
class facebook_status_node_author_context extends facebook_status_user_context {
  function type() {
    return 'node_author';
  }
  function is_applicable() {
    return arg(0) == 'member';
  }
  function find_recipient() {
		$account = user_load(array('name' => check_plain(arg(1))));
    return $this->is_applicable() ? $this->load_recipient($account->uid) : new stdClass();
  }
  function recipient_url($recipient) {
    return 'user/'. $this->recipient_id($recipient);
  }
} 
icecreamyou’s picture

$account = user_load(array('name' => check_plain(arg(1))));

check_plain() and other filtering functions are only for use on output (i.e. when displaying information). Using it on input can sometimes cause incorrect results.

capellic’s picture

StatusFileSize
new83.82 KB

Thanks for the tip.

And I was wrong about needing to change the code-- your example syntax is fine. Long story. :-)

Please disregard the previous version of this comment that reported that the context configuration pages were always showing node author. I discovered I had some errant debugging code that was causing the problem. Sorry if you spent any time on this.

icecreamyou’s picture

Status: Reviewed & tested by the community » Needs work

Now that #1261720: Allow disabling contexts has landed we can finally look into getting this committed.

icecreamyou’s picture

Status: Needs work » Needs review
StatusFileSize
new1.44 KB

Untested patch attached. (Make sure to enable the new context before testing.)

icecreamyou’s picture

One thing I forgot to put into this patch is all the places Statuses checks for type = 'user' where it should now check for type IN ('user', 'node_author') (or $type == 'user' || $type == 'node_author'). While this mostly won't affect the user experience, we need to go through the many places this check exists and see if it needs changing (hook_user_delete() is one example). I'm okay with addressing this as a follow-up though.

icecreamyou’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new6.1 KB

Per #22, attached is a list of everywhere that might need changing.