Location: PHPKode > scripts > Noostr > style/default/functions.php
<?php defined('SYSPATH') OR die('No direct access to this file is allowed.');

function show_story($story, $i = null, $class = null) {
	global $ns;
	$url = '';
	$pluralvotes = 's';
	$pluralcomments = 's';
	$target = '/story/'.$story['uid'];
	$comments = $target;
	$edit = $target.'/edit';
	$delete = $target.'/delete';
	$flag = $target.'/flag';
	$timestamp = time_to_words($story['publishDate']);
	if ($story['url'] != '') {
		$target = $story['url'];
		$end = strpos($story['url'], '/', 7);
		if ($end === false) {
			$end = strlen($story['url']);
		}
		$url .= ' <em>(';
		$url .= substr($story['url'], strpos($story['url'], '//') + 2, $end - strpos($story['url'], '//') - 2);
		$url .= ')</em>';
	}
	if ($story['votes'] == 1) {
		$pluralvotes = '';
	}
	if ($story['children'] == 1) {
		$pluralcomments = '';
	}
	if (isset($class) && $class != '') {
		$class = ' '.$class;
	}
?>
<div class="nodewrap<?php echo $class; ?>"><?php if (isset($i)) { ?><span class="counter"><?php echo $i; ?>.</span><?php } ?><span class="voters"><?php show_vote($story, 'story'); ?></span><h4><a href="<?php echo $target; ?>" class="node"><?php echo $story['title']; ?></a><?php echo $url; ?></h4><span class="meta"><?php echo $story['votes']; ?> point<?php echo $pluralvotes; ?> | submitted by <a href="/user/<?php echo $story['userid']; ?>" class="userlink" rel="author"><?php echo $story['nick']; ?></a> <?php echo $timestamp; ?> | <a href="<?php echo $comments; ?>" class="commentlink"><?php echo $story['children']; ?> comment<?php echo $pluralcomments; ?></a><?php if(($story['userid'] == $ns->user['uid'] && has_right('editOwnStory')) || has_right('editStory')) { ?> | <a href="<?php echo $edit; ?>" class="moderatorlink">Edit</a><?php } ?><?php if(($story['userid'] == $ns->user['uid'] && has_right('editOwnStory')) || has_right('editStory')) { ?> | <a href="<?php echo $delete; ?>" class="moderatorlink">Delete</a><?php } ?><?php if(has_right('flagStory') && $ns->user['karma'] >= $ns->site['karmaflagthreshhold'] && $story['userid'] != $ns->user['uid'] && $story['flagid'] == null) { ?> | <a href="<?php echo $flag; ?>" class="moderatorlink">Flag</a><?php } ?></span></div>
<?php
}

function show_body($story) {
	$return = '<p>'.str_replace(array("\r\n", "\n", "\r"), '</p><p>', $story['description']).'</p>';
	echo str_replace('<p></p>', '', $return);
}

function show_comment($comment, $class = null) {
	global $ns;
	$pluralvotes = 's';
	if ($comment['votes'] == 1) {
		$pluralvotes = '';
	}
	if (isset($class) && $class != '') {
		$class = ' '.$class;
	}
	$timestamp = time_to_words($comment['publishDate']);
	$target = '/comment/'.$comment['uid'];
	$edit = $target.'/edit';
	$delete = $target.'/delete';
	$flag = $target.'/flag';
?><div class="nodewrap<?php echo $class; ?>"><span class="voters"><?php show_vote($comment, 'comment'); ?></span><span class="meta"><?php echo $comment['votes']; ?> point<?php echo $pluralvotes; ?> | submitted by <a href="/user/<?php echo $comment['userid']; ?>" class="userlink" rel="author"><?php echo $comment['nick']; ?></a> <?php echo $timestamp; ?> | <a href="<?php echo $target; ?>" class="userlink">Link</a><?php if(($comment['userid'] == $ns->user['uid'] && has_right('editOwnComment')) || has_right('editComment')) { ?> | <a href="<?php echo $edit; ?>" class="moderatorlink">Edit</a><?php } ?><?php if(($comment['userid'] == $ns->user['uid'] && has_right('editOwnComment')) || has_right('editComment')) { ?> | <a href="<?php echo $delete; ?>" class="moderatorlink">Delete</a><?php } ?><?php if(has_right('flagStory') && $ns->user['karma'] >= $ns->site['karmaflagthreshhold'] && $comment['userid'] != $ns->user['uid'] && $comment['flagid'] == null) { ?> | <a href="<?php echo $flag; ?>" class="moderatorlink">Flag</a><?php } ?></span><div class="content"><?php show_body($comment); ?></div><span class="commentreply"><a href="/comment/<?php echo $comment['uid']; ?>">Reply</a></span><?php
	if (is_array($comment['children'])) {
		for ($i = 0, $c = count($comment['children']); $i < $c; $i++) {
			show_comment($comment['children'][$i], 'nodechild');
		}
	}
?></div><?php
}

function show_vote($node, $path) {
	global $ns;
	$direction = $node['direction'];
	$url = '/'.$path.'/'.$node['uid'];
	if ($direction == '' || $direction == null) {
		$direction == 0;
	}
	$return = '';
	switch (vote($node['userid'], $direction)) {
		case 'owner':
			$return = '<span class="owner">*</span>';
			break;
		case 'show':
			$return = '<a href="'.$url.'/voteup" class="vote"><img src="'.$ns->site['stylepath'].'/images/grayup.gif" alt="Vote Up!" /></a>';
			$return .= '<br />';
			if ($ns->user['karma'] >= $ns->site['karmavotethreshhold_story'] || is_null($ns->user['uid'])) {
				$return .= '<a href="'.$url.'/votedown" class="vote"><img src="'.$ns->site['stylepath'].'/images/graydown.gif" alt="Vote Down!" /></a>';
			} else {
				$return .= '<br />';
			}
			break;
		case 'hide':
		default:
			$return = '<br /><br /><br />';
			break;
	}
	echo $return;
}

function time_to_words($then, $now = null) {
	global $timerstart;
	$return = '';
	if ($now == null) {
		$now = $timerstart;
	}
	$return = 'a few seconds ago';
	$diff = $now - $then;
	$int = 0;
	if ($diff >= 15 && $diff < 60) {
		// 60 seconds
		$return = 'less than a minute ago';
	}
	if ($diff >= 60 && $diff < 3600) {
		// 60 minutes
		$int = floor($diff / 60);
		$return = $int;
		if ($diff <= 120) {
			$return .= ' minute ';
		} else {
			$return .= ' minutes ';
		}
		$return .= 'ago';
	}
	if ($diff >= 3600 && $diff < 86400) {
		// 24 hours
		$int = floor($diff / 3600);
		$return = 'about ';
		if ($diff < 7200) {
			$return .= 'an ';
		}
		$return .= $int;
		if ($diff < 7200) {
			$return .= ' hour ';
		} else {
			$return .= ' hours ';
		}
		$return .= 'ago';
	}
	if ($diff >= 86400 && $diff < 5184000) {
		// 60 days
		$int = floor($diff / 3600 / 24);
		$return = 'about ';
		if ($diff < 172800) {
			$return .= 'a ';
		}
		$return .= $int;
		if ($diff < 172800) {
			$return .= ' day ';
		} else {
			$return .= ' days ';
		}
		$return .= 'ago';
	}
	if ($diff >= 5184000 && $diff < 63072000) {
		// 2 years
		$int = floor($diff / 86400 / 31);
		$return = 'about ';
		if ($diff < 2592000) {
			$return .= 'a ';
		}
		$return .= $int;
		if ($diff < 2592000) {
			$return .= ' month ';
		} else {
			$return .= ' months ';
		}
		$return .= 'ago';
	}
	if ($diff >= 63072000) {
		// years and years and years
		$int = floor($diff / 86400 / 365);
		$return = 'about ';
		if ($diff < 31536000) {
			$return .= 'a ';
		}
		$return .= $int;
		if ($diff < 31536000) {
			$return .= ' year ';
		} else {
			$return .= ' years ';
		}
		$return .= 'ago';
	}
	return $return;
}
Return current item: Noostr