aboutsummaryrefslogtreecommitdiff
path: root/mod/blog/start.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/blog/start.php')
-rw-r--r--mod/blog/start.php501
1 files changed, 223 insertions, 278 deletions
diff --git a/mod/blog/start.php b/mod/blog/start.php
index c2ccb1902..bbae1eb6c 100644
--- a/mod/blog/start.php
+++ b/mod/blog/start.php
@@ -1,278 +1,223 @@
-<?php
-
- /**
- * Elgg blog plugin
- **/
-
- function blog_init() {
-
- // Load system configuration
- global $CONFIG;
-
- // Set up menu for logged in users
- if (isloggedin()) {
-
- add_menu(elgg_echo('blog:yours'), $CONFIG->wwwroot . "pg/blog/" . $_SESSION['user']->username);
-
- // And for logged out users
- } else {
- add_menu(elgg_echo('blog'), $CONFIG->wwwroot . "mod/blog/everyone.php",array(
- ));
- }
-
- // Extend system CSS with our own styles, which are defined in the blog/css view
- extend_view('css','blog/css');
-
- // Extend hover-over menu
- extend_view('profile/menu/links','blog/menu');
-
- // Register a page handler, so we can have nice URLs
- register_page_handler('blog','blog_page_handler');
-
- // Register a URL handler for blog posts
- register_entity_url_handler('blog_url','object','blog');
-
- // Register this plugin's object for sending pingbacks
- register_plugin_hook('pingback:object:subtypes', 'object', 'blog_pingback_subtypes');
-
- // Register granular notification for this type
- if (is_callable('register_notification_object'))
- register_notification_object('object', 'blog', elgg_echo('blog:newpost'));
-
- // Listen to notification events and supply a more useful message
- register_plugin_hook('notify:entity:message', 'object', 'blog_notify_message');
-
- // Add a new blog widget
- add_widget_type('blog',elgg_echo("blog"),elgg_echo("blog:widget:description"),'profile, dashboard');
-
- // Listen for new pingbacks
- register_elgg_event_handler('create', 'object', 'blog_incoming_ping');
-
- // Register entity type
- register_entity_type('object','blog');
-
- // Register an annotation handler for comments etc
- register_plugin_hook('entity:annotate', 'object', 'blog_annotate_comments');
-
- // Add group menu option
- add_group_tool_option('blog',elgg_echo('blog:enableblog'),true);
- }
-
- function blog_pagesetup() {
-
- global $CONFIG;
-
- //add submenu options
- if (get_context() == "blog") {
- $page_owner = page_owner_entity();
-
- if ((page_owner() == $_SESSION['guid'] || !page_owner()) && isloggedin()) {
- add_submenu_item(elgg_echo('blog:your'),$CONFIG->wwwroot."pg/blog/" . $_SESSION['user']->username);
- add_submenu_item(elgg_echo('blog:friends'),$CONFIG->wwwroot."pg/blog/" . $_SESSION['user']->username . "/friends/");
- add_submenu_item(elgg_echo('blog:everyone'),$CONFIG->wwwroot."mod/blog/everyone.php");
-
- } else if (page_owner()) {
- add_submenu_item(sprintf(elgg_echo('blog:user'),$page_owner->name),$CONFIG->wwwroot."pg/blog/" . $page_owner->username);
- if ($page_owner instanceof ElggUser) { // Sorry groups, this isn't for you.
- add_submenu_item(sprintf(elgg_echo('blog:user:friends'),$page_owner->name),$CONFIG->wwwroot."pg/blog/" . $page_owner->username . "/friends/");
- }
- add_submenu_item(elgg_echo('blog:everyone'),$CONFIG->wwwroot."mod/blog/everyone.php");
- } else {
- add_submenu_item(elgg_echo('blog:everyone'),$CONFIG->wwwroot."mod/blog/everyone.php");
- }
-
- if (can_write_to_container(0, page_owner()) && isloggedin())
- add_submenu_item(elgg_echo('blog:addpost'),$CONFIG->wwwroot."pg/blog/{$page_owner->username}/new/");
-
- if (!defined('everyoneblog') && page_owner()) {
-
- if ($dates = get_entity_dates('object','blog',page_owner())) {
- foreach($dates as $date) {
- $timestamplow = mktime(0,0,0,substr($date,4,2),1,substr($date,0,4));
- $timestamphigh = mktime(0,0,0,((int) substr($date,4,2)) + 1,1,substr($date,0,4));
- if (!isset($page_owner)) $page_owner = page_owner_entity();
- $link = $CONFIG->wwwroot . 'pg/blog/' . $page_owner->username . '/archive/' . $timestamplow . '/' . $timestamphigh;
- add_submenu_item(sprintf(elgg_echo('date:month:'.substr($date,4,2)),substr($date,0,4)),$link,'filter');
- }
- }
-
- }
-
- }
-
- // Group submenu
- $page_owner = page_owner_entity();
-
- if ($page_owner instanceof ElggGroup && get_context() == 'groups') {
- if($page_owner->blog_enable != "no"){
- add_submenu_item(sprintf(elgg_echo("blog:group"),$page_owner->name), $CONFIG->wwwroot . "pg/blog/" . $page_owner->username );
- }
- }
- }
-
- /**
- * Blog page handler; allows the use of fancy URLs
- *
- * @param array $page From the page_handler function
- * @return true|false Depending on success
- */
- function blog_page_handler($page) {
-
- // The first component of a blog URL is the username
- if (isset($page[0])) {
- set_input('username',$page[0]);
- }
-
- // In case we have further input
- if (isset($page[2])) {
- set_input('param2',$page[2]);
- }
- // In case we have further input
- if (isset($page[3])) {
- set_input('param3',$page[3]);
- }
-
- // The second part dictates what we're doing
- if (isset($page[1])) {
- switch($page[1]) {
- case "read": set_input('blogpost',$page[2]);
- include(dirname(__FILE__) . "/read.php"); return true;
- break;
- case "archive": include(dirname(__FILE__) . "/archive.php"); return true;
- break;
- case "friends": include(dirname(__FILE__) . "/friends.php"); return true;
- break;
- case "new": include(dirname(__FILE__) . "/add.php"); return true;
- break;
-
- }
- // If the URL is just 'blog/username', or just 'blog/', load the standard blog index
- } else {
- @include(dirname(__FILE__) . "/index.php");
- return true;
- }
-
- return false;
-
- }
-
- /**
- * Hook into the framework and provide comments on blog entities.
- *
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params
- * @return unknown
- */
- function blog_annotate_comments($hook, $entity_type, $returnvalue, $params)
- {
- $entity = $params['entity'];
- $full = $params['full'];
-
- if (
- ($entity instanceof ElggEntity) && // Is the right type
- ($entity->getSubtype() == 'blog') && // Is the right subtype
- ($entity->comments_on!='Off') && // Comments are enabled
- ($full) // This is the full view
- )
- {
- // Display comments
- return elgg_view_comments($entity);
- }
-
- }
-
- /**
- * Returns a more meaningful message
- *
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params
- */
- function blog_notify_message($hook, $entity_type, $returnvalue, $params)
- {
- $entity = $params['entity'];
- $to_entity = $params['to_entity'];
- $method = $params['method'];
- if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'blog'))
- {
- $descr = $entity->description;
- $title = $entity->title;
- if ($method == 'sms') {
- $owner = $entity->getOwnerEntity();
- return $owner->username . ' via blog: ' . $title;
- }
- if ($method == 'email') {
- $owner = $entity->getOwnerEntity();
- return $owner->username . ' via blog: ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
- }
- }
- return null;
- }
-
-
- /**
- * Populates the ->getUrl() method for blog objects
- *
- * @param ElggEntity $blogpost Blog post entity
- * @return string Blog post URL
- */
- function blog_url($blogpost) {
-
- global $CONFIG;
- $title = $blogpost->title;
- $title = friendly_title($title);
- return $CONFIG->url . "pg/blog/" . $blogpost->getOwnerEntity()->username . "/read/" . $blogpost->getGUID() . "/" . $title;
-
- }
-
- /**
- * This function adds 'blog' to the list of objects which will be looked for pingback urls.
- *
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params
- * @return unknown
- */
- function blog_pingback_subtypes($hook, $entity_type, $returnvalue, $params)
- {
- $returnvalue[] = 'blog';
-
- return $returnvalue;
- }
-
- /**
- * Listen to incoming pings, this parses an incoming target url - sees if its for me, and then
- * either passes it back or prevents it from being created and attaches it as an annotation to a given
- *
- * @param unknown_type $event
- * @param unknown_type $object_type
- * @param unknown_type $object
- */
- function blog_incoming_ping($event, $object_type, $object)
- {
- // TODO: Get incoming ping object, see if its a ping on a blog and if so attach it as a comment
- }
-
- /**
- * remove the more link in the blog text
- **/
- function remove_more($body){
- $text = str_replace("{{more}}", " ", $body);
- return $text;
- }
-
- // Make sure the blog initialisation function is called on initialisation
- register_elgg_event_handler('init','system','blog_init');
- register_elgg_event_handler('pagesetup','system','blog_pagesetup');
-
- // Register actions
- global $CONFIG;
- register_action("blog/add",false,$CONFIG->pluginspath . "blog/actions/add.php");
- register_action("blog/edit",false,$CONFIG->pluginspath . "blog/actions/edit.php");
- register_action("blog/delete",false,$CONFIG->pluginspath . "blog/actions/delete.php");
-
-?> \ No newline at end of file
+<?php
+/**
+ * Blogs
+ *
+ * @package Blog
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2010
+ * @link http://elgg.org/
+ *
+ * @todo
+ *
+ * Show all your drafts
+ * Show revision history
+ *
+ * Show your blog posts
+ * Show friends blog posts
+ *
+ * Group blogs
+ * Forward to container instead of owner
+ * GROUPS SUCK.
+ *
+ * Pingbacks
+ * Notifications
+ */
+
+/**
+ * Init blog plugin.
+ *
+ * @return TRUE
+ */
+function blog_init() {
+ global $CONFIG;
+ require_once dirname(__FILE__) . '/blog_lib.php';
+
+ // Set up menus
+ add_menu(elgg_echo('blog'), "{$CONFIG->wwwroot}pg/blog/", array());
+
+ extend_view('css', 'blog/css');
+
+ register_page_handler('blog', 'blog_page_handler');
+ register_page_handler('blog_ajax', 'blog_ajax_page_handler');
+
+ register_entity_url_handler('blog_url_handler', 'object', 'blog');
+
+ // notifications
+ register_notification_object('object', 'blog', elgg_echo('blog:newpost'));
+ register_plugin_hook('notify:entity:message', 'object', 'blog_notify_message');
+
+ // pingbacks
+ //register_elgg_event_handler('create', 'object', 'blog_incoming_ping');
+ //register_plugin_hook('pingback:object:subtypes', 'object', 'blog_pingback_subtypes');
+
+ // Register for search.
+ register_entity_type('object','blog');
+
+ //add_group_tool_option('blog', elgg_echo('blog:enableblog'), true);
+ add_widget_type('blog', elgg_echo('blog'), elgg_echo('blog:widget:description'), 'profile, dashboard');
+
+ $action_path = dirname(__FILE__) . '/actions/blog';
+
+ register_action('blog/save', FALSE, "$action_path/save.php");
+ register_action('blog/delete', FALSE, "$action_path/delete.php");
+}
+
+/**
+ * Dispatches blog pages.
+ * To maintain URL backward compatibility, expects old-style URLs like:
+ * pg/blog/[username/[read|edit|archive|new/[time_start|guid/[time_end|title]]]]
+ *
+ * Without a username, show all blogs
+ * Without an action (read|edit|archive|new), forward to pg/blog/username/read.
+ * Without a guid, show all post for that user.
+ * Title is ignored
+ *
+ * If archive, uses time_start/end
+ *
+ * @todo There is no way to say "show me archive view for all blog posts" with the
+ * current URL scheme because $param[0] is the username instead of an action.
+ * Could do something hideous like make '*' mean "all users" (since a username can't be *).
+ * Can't change the URL scheme because of URL compatibility.
+ *
+ * @param array $page
+ * @return NULL
+ */
+function blog_page_handler($page) {
+ global $CONFIG;
+
+ elgg_push_breadcrumb(elgg_echo('blog:blogs'), "{$CONFIG->site->url}pg/blog");
+
+ // see if we're showing all or just a user's
+ if (isset($page[0]) && !empty($page[0])) {
+ $username = $page[0];
+
+ // forward away if invalid user.
+ if (!$user = get_user_by_username($username)) {
+ register_error('blog:error:unknown_username');
+ forward($_SERVER['HTTP_REFERER']);
+ }
+
+ set_page_owner($user->getGUID());
+ $crumbs_title = sprintf(elgg_echo('blog:owned_blogs'), $user->name);
+ $crumbs_url = "{$CONFIG->site->url}pg/blog/$username/read";
+ elgg_push_breadcrumb($crumbs_title, $crumbs_url);
+
+ $action = isset($page[1]) ? $page[1] : FALSE;
+ // yeah these are crap names, but they're used for different things.
+ $page2 = isset($page[2]) ? $page[2] : FALSE;
+ $page3 = isset($page[3]) ? $page[3] : FALSE;
+
+ switch ($action) {
+ case 'read':
+ $title = sprintf(elgg_echo('blog:title:user_blogs'), $user->name);
+ $content = elgg_view('page_elements/content_header', array('context' => $content, 'type' => 'blog'));
+ $content .= blog_get_page_content_read($user->getGUID(), $page2);
+ break;
+
+ case 'new':
+ case 'edit':
+ $content = blog_get_page_content_edit($page2);
+ break;
+
+ case 'archives':
+ $content = elgg_view('page_elements/content_header', array('context' => $content, 'type' => 'blog'));
+ $content .= blog_get_page_content_archive($user->getGUID(), $page2, $page3);
+ break;
+
+ case 'friends':
+ $content = elgg_view('page_elements/content_header', array('context' => $content, 'type' => 'blog'));
+ $content .= blog_get_page_content_archive($user->getGUID());
+ break;
+
+ default:
+ forward("pg/blog/{$username}/read/");
+ break;
+ }
+ } else {
+ $title = elgg_echo('blog:title:all_blogs');
+ $content = elgg_view('page_elements/content_header', array('context' => $content, 'type' => 'blog'));
+ $content .= elgg_list_entities_from_metadata(array(
+ 'type' => 'object',
+ 'subtype' => 'blog',
+ 'full_view' => FALSE,
+ 'metadata_name_value_pair' => array('name' => 'status', 'value' => 'final')
+ ));
+ }
+
+ $sidebar = elgg_view('blog/sidebar_menu');
+ $content = elgg_view('navigation/breadcrumbs') . $content;
+
+ $body = elgg_view_layout('one_column_with_sidebar', $content, $sidebar);
+
+ page_draw($title, $body);
+}
+
+/**
+ * Handles ajax calls for blog.
+ *
+ * @param array $page
+ */
+function blog_ajax_page_handler($page) {
+ $action = isset($page[0]) ? $page[0] : FALSE;
+
+ var_dump($page);
+
+ switch ($action) {
+ case 'save_draft':
+ // @todo recycle the save action
+ $values = array(
+ 'title' => '',
+ 'description' => '',
+ 'status' => 'draft',
+ 'access_id' => ACCESS_DEFAULT,
+ 'comments_on' => 'On',
+ 'excerpt' => '',
+ 'tags' => '',
+ 'container_guid' => '',
+ 'guid' => ''
+ );
+
+ foreach ($values as $name => $default) {
+ $values[$name] = get_input($name, $default);
+ }
+
+
+
+ /*
+ If a title and body, create a blog post marked as a draft and update the
+ GUID
+ */
+ break;
+
+ default:
+ $content = 0;
+ break;
+ }
+
+ exit;
+}
+
+
+/**
+ * Format and return the correct URL for blogs.
+ *
+ * @param ElggObject $entity
+ * @return string URL of blog.
+ */
+function blog_url_handler($entity) {
+ global $CONFIG;
+
+ if (!$user = get_entity($entity->owner_guid)) {
+ // default to a standard view if no owner.
+ return FALSE;
+ }
+
+ $friendly_title = friendly_title($entity->title);
+
+ $url = "{$CONFIG->site->url}pg/blog/{$user->username}/read/{$entity->getGUID()}/$friendly_title";
+ return $url;
+}
+
+
+register_elgg_event_handler('init', 'system', 'blog_init'); \ No newline at end of file