Create sequence of slides by inserting breaks at the end of each paragraph

nickvidal - May 14, 2008 - 12:40
Project:S5 presentation player
Version:5.x-1.x-dev
Component:Code - s5_book
Category:feature request
Priority:normal
Assigned:nickvidal
Status:needs review
Description

My book pages were somewhat long and I wanted to break each one into multiple slides. The following code inserts a break at the end of each paragraph:

File: s5_book.module
Function: s5_book_node_display

<?php
/**
* Book recursion function
* Flattens the book structure, immediately closing slides for every node
*/
function s5_book_node_display($node, $depth, $nid) {

 
// Let the content hook take action (taken from book.module)
 
if (node_hook($node, 'content')) {
   
$node = node_invoke($node, 'content');
  }

 
// Enclose slide in wrapper (you can have handout info on slide)
 
if ($node->body) {

   
// Create sequence of slides by inserting breaks at the end of each paragraph
   
$sequence = "";
   
$slides = $node->body;
   
$slides = preg_replace("(<\/p>)","</p><!--slidebreak-->",$slides);
   
$slides = explode("<!--slidebreak-->",$slides);
   
   
// Iterate through the slides
   
foreach($slides as $slide) {
      
$slide = rtrim($slide);

      
// Remove empty slides, adding the valid ones to the sequence
      
if ($slide != "")
          
$sequence .= '<div class="slide"><h1>'. check_plain($node->title) ."</h1>\n". check_markup($slide, $node->format, FALSE) .'</div>';
    }

   
// Returning the sequence of slides
   
return $sequence;
  }
}
?>

#1

nickvidal - May 14, 2008 - 12:42
Status:active» needs review

#2

greggles - May 14, 2008 - 12:54
Status:needs review» active

Could you provide this as a patch? http://drupal.org/patch

You may also want to use the s5_textfield module which works on a syntax more like what you propose.

#3

nickvidal - May 14, 2008 - 14:07

Hi Greggles,

First of all, thank you for this great module!

Before submitting a patch, I'll add a break paragraphs automatically option to the configuration form so users can select whether they want this feature or not. I think that would be more appropriate.

I had a quick look at the s5_texfield module but did not sympathize much with the approach because I wanted the module to automatically insert the breaks instead of having the user to explicitly indicate where to break using a special syntax. The advantage is that slideshows could be created on the fly from content that was not necessarily tailored towards this goal.

I'll get back to you as soon as possible.

Best regards,
Nick Vidal

#4

greggles - May 16, 2008 - 23:50

That makes complete sense as to why you chose this route and I appreciate the idea of making it optional. I'm looking forward to the patch.

PS It was Gabor who wrote the first version so be sure to thank him as well :)

#5

nickvidal - June 4, 2008 - 21:16
Status:active» needs review

Hi greggles,

I've attached the patch!

Best regards,
Nick Vidal

AttachmentSize
s5_book_break_paragraphs.patch 1.79 KB

#6

nickvidal - June 4, 2008 - 21:43

Instructions

On the S5 Book Settings, set the checkbox Break paragraphs into sequence of slides.

This will break paragraphs into a sequence of slides automatically.

It will also look for explicit breaks, which may be added by the user like this:

<!--pagebreak-->

#7

Dave Cohen - August 19, 2008 - 21:30

Hey I like the idea of splitting my slides into multiple book pages, but in some cases, I wanted to create multiple slides in a single node. So I made a hybrid in which the book nodes also observed <!--pagebreak--> and optionally <!--titlebreak-->. I did this before discovering this issue, but I think the attached patch will do what you need. And frankly, I think <!--pagebreak--> makes more sense than using paragraphs.

AttachmentSize
s5_pagebreak.diff 1.23 KB

#8

greggles - August 19, 2008 - 21:52

@Dave Cohen - interesting point, that you could have presentations inside a single node and then also chain them together by making them a book...

Thinking about this more I feel that it would really make sense to merge the s5_book and s5_textfield together. As I worked on them the other day I thought about what a shame it was that they share so much code...

#9

Dave Cohen - August 20, 2008 - 05:31

Right. I'm making a slide show and several slides in a row have the same title, but a different image. And it makes much more sense to have those live in a single node.

#10

greggles - August 20, 2008 - 17:14

Well...that strikes me as behavior that would be confusing to use the same title as the parent node sometimes but not all of the time...

Sadly I think we will have to force people to copy and paste, although that's something that seems common in creating presentations regardless of the presentation format.

 
 

Drupal is a registered trademark of Dries Buytaert.