public function more($content, $post) { $more_text = 'Read the rest →'; $max_paragraphs = 3; $showmore = false; $matches = preg_split( '//is', $content, 2, PREG_SPLIT_NO_EMPTY ); if ( count($matches) > 1 ) { $summary = $matches[0]; $remainder = $matches[1]; if(trim($remainder) != '') { $showmore = true; } } else { $ht = new HtmlTokenizer($content, false); $set = $ht->parse(); $stack = array(); $para = 0; $token = $set->current(); $summary = new HTMLTokenSet(false); $remainder = new HTMLTokenSet(false); for($token = $set->current(); $token = $set->next(); ) { if($token['type'] == HTMLTokenizer::NODE_TYPE_ELEMENT_OPEN) { $stack[$token['name']] = $token['name']; } if($para < $max_paragraphs) { $summary[] = $token; } if($para >= $max_paragraphs) { $remainder[] = $token; $showmore = true; } if($token['type'] == HTMLTokenizer::NODE_TYPE_ELEMENT_CLOSE) { if(isset($stack[$token['name']])) { while(end($stack) != $token['name']) { array_pop($stack); } array_pop($stack); } if(count($stack) == 0) { $para++; } } } } if ( $post->slug == Controller::get_var('slug') ) { $content = $summary . '
'. 'Continues here →' .'
' . $remainder; } elseif( $showmore == true ) { $content = $summary . '

' . $more_text . '

'; } else { $content = $summary . $remainder; } return $content; }