diff options
Diffstat (limited to 'mod/blog/blog_lib.php')
| -rw-r--r-- | mod/blog/blog_lib.php | 78 | 
1 files changed, 57 insertions, 21 deletions
| diff --git a/mod/blog/blog_lib.php b/mod/blog/blog_lib.php index 0fe1b80d4..993728dcc 100644 --- a/mod/blog/blog_lib.php +++ b/mod/blog/blog_lib.php @@ -16,54 +16,85 @@   * @param int $guid of a blog entity.   * @return string html   */ -function blog_get_page_content_read($owner_guid, $guid) { +function blog_get_page_content_read($owner_guid = NULL, $guid = NULL) { +	$content = elgg_view('page_elements/content_header', array('context' => $context, 'type' => 'blog')); +  	if ($guid) {  		$blog = get_entity($guid);  		if (!elgg_instanceof($blog, 'object', 'blog') && $blog->status == 'final') { -			$content = elgg_echo('blog:error:post_not_found'); +			$content .= elgg_echo('blog:error:post_not_found');  		} else {  			elgg_push_breadcrumb($blog->title, $blog->getURL()); -			$content = elgg_view_entity($blog, TRUE); +			$content .= elgg_view_entity($blog, TRUE);  		}  	} else { -		$content = elgg_list_entities_from_metadata(array( +		$options = array(  			'type' => 'object',  			'subtype' => 'blog', -			'owner_guid' => $owner_guid,  			'full_view' => FALSE, -			'metadata_name_value_pair' => array('name' => 'status', 'value' => 'final') -		)); +			'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int') +		); + +		if ($owner_guid) { +			$options['owner_guid'] = $owner_guid; +		} + +		// show all posts for admin or users looking at their own blogs +		// show only published posts for other users. +		if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) { +			$options['metadata_name_value_pairs'] = array( +				array('name' => 'status', 'value' => 'published'), +				array('name' => 'publish_date', 'operand' => '<', 'value' => time()) +			); +		} + +		$content .= elgg_list_entities_from_metadata($options);  	} -	return $content; +	return array('content' => $content);  }  /**   * Returns HTML to edit a blog post.   *   * @param int $guid + * @param int annotation id optional revision to edit   * @return string html   */ -function blog_get_page_content_edit($guid) { +function blog_get_page_content_edit($guid, $revision = NULL) {  	$vars = array();  	if ($guid) { -		$blog = get_entity($guid); -		$vars['entity'] = $blog; +		$blog = get_entity((int)$guid); + +		if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) { +			$vars['entity'] = $blog; + +			if ($revision) { +				$revision = get_annotation((int)$revision); +				$vars['revision'] = $revision; + +				if (!$revision || !($revision->entity_guid == $guid)) { +					$content = elgg_echo('blog:error:revision_not_found'); +				} +			} + +			elgg_push_breadcrumb($blog->title, $blog->getURL()); +			elgg_push_breadcrumb(elgg_echo('edit')); -		if (!elgg_instanceof($blog, 'object', 'blog') || !$blog->canEdit()) { +			$content = elgg_view('blog/forms/edit', $vars); +			$sidebar = elgg_view('blog/sidebar_revisions', array('entity' => $blog)); +			//$sidebar .= elgg_view('blog/sidebar_related'); +		} else {  			$content = elgg_echo('blog:error:post_not_found');  		} - -		elgg_push_breadcrumb($blog->title, $blog->getURL()); -		elgg_push_breadcrumb(elgg_echo('edit'));  	} else {  		elgg_push_breadcrumb(elgg_echo('blog:new')); +		$content = elgg_view('blog/forms/edit', $vars); +		//$sidebar = elgg_view('blog/sidebar_related');  	} -	$content = elgg_view('blog/forms/edit', $vars); - -	return $content; +	return array('content' => $content, 'sidebar' => $sidebar);  }  /** @@ -175,7 +206,12 @@ function blog_save_blog($info) {  	return $return;  } - -class ElggBlog extends ElggObject { - +/** + * Returns an appropriate excerpt for a blog. + * + * @param string $text + * @return string + */ +function blog_make_excerpt($text) { +	return substr(strip_tags($text), 0, 300);  }
\ No newline at end of file | 
