diff --git a/start.php b/start.php index 5f45731..674082e 100644 --- a/start.php +++ b/start.php @@ -192,4 +192,11 @@ function community_theme_pagesetup() { $actions = __DIR__ . "/actions"; elgg_register_action('admin/flush_apc', "$actions/admin/flush_apc.php", 'admin'); + + elgg_register_plugin_hook_handler('route', 'discussion', function($hook, $type, $result, $params) { + if (!isset($params['segments'][0])) { + echo elgg_view_resource('discussion/index'); + return false; + } + }); }); diff --git a/views/default/resources/discussion/index.css b/views/default/resources/discussion/index.css new file mode 100644 index 0000000..62ffe01 --- /dev/null +++ b/views/default/resources/discussion/index.css @@ -0,0 +1,64 @@ +.actions { + align-items: center; + display: flex; + flex-direction: row; + white-space: nowrap; +} + +.header { + display: flex; + flex-direction: row; + padding: 0 12px; +} + +.listItem { + align-items: center; + display: flex; + flex-direction: row; + padding-left: 12px; +} + +.listItem:not(:last-child) { + border-bottom: 1px solid #ccc; +} + +.listItem--unread { + font-weight: bold; +} + +.listItem-author { + display: block; + + /* If we don't set this explicit, the div grows to be 46px???? */ + height: 40px; +} + +.listItem-body { + flex: 100%; + +} + +.listItem-metadata { + padding: 0 12px 8px; +} + +.listItem-title { + display: block; + font-size: larger; + padding: 8px 12px; +} + +.pagination { + display: flex; + padding: 8px 12px; +} + +.pagination > * { + flex: 1; + text-align: center; +} + +.title { + flex: 100%; + padding: .5em 0; +} diff --git a/views/default/resources/discussion/index.php b/views/default/resources/discussion/index.php new file mode 100644 index 0000000..6a23bbc --- /dev/null +++ b/views/default/resources/discussion/index.php @@ -0,0 +1,134 @@ + 'object', + 'subtype' => 'discussion', + 'order_by' => 'e.last_action desc', + 'limit' => $limit, + 'offset' => $offset, + 'preload_owners' => true, + 'preload_containers' => true, +]); + +$discussions = (object)[ + 'length' => elgg_get_entities([ + 'type' => 'object', + 'subtype' => 'discussion', + 'count' => true, + ]), + 'fields' => (object)[ + 'title' => (object)['label' => 'Title'], + 'replies_length' => (object)['label' => 'Replies'], + 'last_action' => (object)['label' => 'Last activity'], + ], + 'recently_active' => (object)[ + 'label' => 'Latest discussion', + 'next' => (object)['label' => 'Older »'], + 'prev' => (object)['label' => '« Newer'], + 'actions' => [ + (object)[ + 'label' => 'Start new discussion', + 'href' => elgg_get_site_url() . 'discussion/new', + ], + ], + 'items' => array_map(function($discussion) { + $owner = $discussion->getOwnerEntity(); + + return (object)[ + 'author' => (object)[ + 'name' => $owner->name, + 'url' => $owner->getUrl(), + 'avatar' => (object)[ + 'preview' => (new ElggUser())->getIconUrl('small'), + '40x40' => $owner->getIconUrl('small'), + '100x100' => $owner->getIconUrl('medium'), + ], + ], + 'is_unread' => false, + 'last_action' => $discussion->last_action, + 'title' => $discussion->title, + 'url' => $discussion->getUrl(), + 'replies_length' => elgg_get_entities(array( + 'type' => 'object', + 'subtype' => 'discussion_reply', + 'container_guid' => $discussion->getGUID(), + 'count' => true, + 'distinct' => false, + )), + ]; + }, $recentlyActive), + ], +]; + + +elgg_register_css('resources/discussion/index', elgg_get_simplecache_url('resources/discussion/index.css')); +elgg_load_css('resources/discussion/index'); +?> + + +
+
+

+ recently_active->label; ?> +

+ +
+
    + recently_active->items as $discussion): ?> +
  1. +
    + author->avatar; ?> + <?=$discussion->author->name?> +
    +
    + + title;?> + + +
    +
  2. + +
+ +
+ + +