Project:Riffly - realtime audio and video comments on your site
Version:6.x-1.0-rc1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Situation
I create a view using fields and add a Comment:Body field.

Result

The comment body is displayed, however the [Riffly] tokens are not filtered.

Desired Result

The [Riffly] tokens are filtered in the View, so that a Riffly video or audio file is displayed.

Notes

If I choose 'Comment' for the row style then the Riffly tokens are being displayed appropriately. The Riffly module doesn't seem to be hooking into the Views module when it is displaying fields.

Comments

#1

I've just solved the problem for my particular needs. The following post is very hard to follow, I realize this. If you have any questions then respond and I'll do my best to answer or point you in the right direction.

The first step is to pass the comment body into the riffly_comment function.

To pass the comment body into the riffly_comment function you first need to create a custom views theme template for this field so that you can alter the output yourself. See this for an overview: http://views-help.doc.logrus.com/help/views/using-theme

For example, I've copied and pasted views-view-field.tpl.php from the modules/views/themes folder and then copied it to my working themes directory and then changed it to read:

$output = riffly_comment($output, 'view');
print $output;

The riffly_comment function in the Riffly module then needs to be altered:

function riffly_comment(&$arg, $op) {
  switch($op) {
    case 'insert': //Get the riffly comments and insert into our db
      //do nothing embed comments in the comment text for now.
      break;

    case 'view':  //filter riffly comments and save..
    <strong>  if(is_object($arg)){
      $comment = $arg->comment;
} else {$comment = $arg;}

</strong>

      $pattern = '/\[riffly_video\](.*)\[\/riffly_video\]/';

      if (user_access('view video comment')) {
preg_match_all($pattern, $comment, $matches);

foreach ($matches[1] as $riffly_id) {
  $comment_id = $arg->cid;
  $pattern = '/\[riffly_video\]' . $riffly_id . '\[\/riffly_video\]/';
  $replacement = riffly_video_display($comment_id, $riffly_id);
  $comment = preg_replace($pattern, $replacement, $comment);
}
      }
      else {
$comment = preg_replace($pattern, '', $comment);
      }

      $pattern = '/\[riffly_audio\](.*)\[\/riffly_audio\]/';
      if (user_access('view audio comment')) {
preg_match_all($pattern, $comment, $matches);

foreach ($matches[1] as $riffly_id) {
  $comment_id = $arg->cid;
  $pattern = '/\[riffly_audio\]' . $riffly_id . '\[\/riffly_audio\]/';
  $replacement = riffly_audio_display($comment_id, $riffly_id);
  $comment = preg_replace($pattern, $replacement, $comment);
}
      }
      else {
$comment = preg_replace($pattern, '', $comment);
      }
<strong>
      if(is_object($arg)){
      $arg->comment = $comment;
      } else {
return $comment;
}</strong>
      break;
  }

}