Pastoid

New Habari More Function

The page you are looking at now is at this URL: http://pastoid.com/av5

This paste was last updated on April 19, 2009 at 11:08 am.

To replace Format::more()?raw

	public function more($content, $post)
	{
		$more_text = 'Read the rest →';
		$max_paragraphs = 3;
 
		$showmore = false;
		$matches = preg_split( '/<!--\s*more\s*-->/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 . '<div id="more" class="moreanchor">'. 'Continues here &#8594;' .'</div>' . $remainder;
		}
		elseif( $showmore == true ) {
			$content = $summary . '<p class="more"><a href="' . $post->permalink . '#more">' . $more_text . '</a></p>';
		}
		else {
			$content = $summary . $remainder;
		}
		return $content;
	}
 
 

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 9
mibbit.com 1
search.live.com 1
drunkenmonkey.org 1
Is this paste spam?
<Hide