diff --git a/CONFIGURE b/CONFIGURE index 285ccd11b3..c5fac78730 100644 --- a/CONFIGURE +++ b/CONFIGURE @@ -859,3 +859,12 @@ performance high: if you need high performance, or if you're seeing bad performance, set this to true. It will turn off some high-intensity code from the site. + +oldschool +--------- + +enabled: enable certain old-style user settings options, like stream-only mode, + conversation trees, and nicknames in streams. Off by default, and + may not be well supported in future versions. + + diff --git a/actions/all.php b/actions/all.php index a987ebbadb..6e6dae5d16 100644 --- a/actions/all.php +++ b/actions/all.php @@ -1,7 +1,7 @@ user, Profile::current()); + $user = common_current_user(); + + if (!empty($user) && $user->streamModeOnly()) { + $stream = new InboxNoticeStream($this->user, Profile::current()); + } else { + $stream = new ThreadingInboxNoticeStream($this->user, Profile::current()); + } $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); @@ -176,7 +182,11 @@ class AllAction extends ProfileAction $profile = $current_user->getProfile(); } - $nl = new ThreadedNoticeList($this->notice, $this, $profile); + if (!empty($current_user) && $current_user->streamModeOnly()) { + $nl = new NoticeList($this->notice, $this); + } else { + $nl = new ThreadedNoticeList($this->notice, $this, $profile); + } $cnt = $nl->show(); diff --git a/actions/conversation.php b/actions/conversation.php index 637e86e4b2..aa2539d213 100644 --- a/actions/conversation.php +++ b/actions/conversation.php @@ -123,9 +123,15 @@ class ConversationAction extends Action */ function showContent() { - $tnl = new FullThreadedNoticeList($this->notices, $this, $this->userProfile); + $user = common_current_user(); - $cnt = $tnl->show(); + if (!empty($user) && $user->conversationTree()) { + $nl = new ConversationTree($this->notices, $this); + } else { + $nl = new FullThreadedNoticeList($this->notices, $this, $this->userProfile); + } + + $cnt = $nl->show(); } function isReadOnly() @@ -162,3 +168,4 @@ class ConversationAction extends Action _('Conversation feed (Activity Streams JSON)'))); } } + diff --git a/actions/oldschoolsettings.php b/actions/oldschoolsettings.php new file mode 100644 index 0000000000..74c6c05cda --- /dev/null +++ b/actions/oldschoolsettings.php @@ -0,0 +1,228 @@ +. + * + * @category Oldschool + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + // This check helps protect against security problems; + // your code file can't be executed directly from the web. + exit(1); +} + +/** + * Old-school settings + * + * @category Oldschool + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +class OldschoolsettingsAction extends SettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + function title() + { + // TRANS: Page title for profile settings. + return _('Old school UI settings'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + function getInstructions() + { + // TRANS: Usage instructions for profile settings. + return _('If you like it "the old way", you can set that here.'); + } + + /** + * For initializing members of the class. + * + * @param array $argarray misc. arguments + * + * @return boolean true + */ + + function prepare($argarray) + { + if (!common_config('oldschool', 'enabled')) { + throw new ClientException("Old-school settings not enabled."); + } + parent::prepare($argarray); + return true; + } + + /** + * Handler method + * + * @param array $argarray is ignored since it's now passed in in prepare() + * + * @return void + */ + + function handlePost() + { + $user = common_current_user(); + + $osp = Old_school_prefs::staticGet('user_id', $user->id); + $orig = null; + + if (!empty($osp)) { + $orig = clone($osp); + } else { + $osp = new Old_school_prefs(); + $osp->user_id = $user->id; + $osp->created = common_sql_now(); + } + + $osp->stream_mode_only = $this->boolean('stream_mode_only'); + $osp->conversation_tree = $this->boolean('conversation_tree'); + $osp->stream_nicknames = $this->boolean('stream_nicknames'); + $osp->modified = common_sql_now(); + + if (!empty($orig)) { + $osp->update($orig); + } else { + $osp->insert(); + } + + // TRANS: Confirmation shown when user profile settings are saved. + $this->showForm(_('Settings saved.'), true); + + return; + } + + function showContent() + { + $user = common_current_user(); + $form = new OldSchoolForm($this, $user); + $form->show(); + } +} + +class OldSchoolForm extends Form +{ + var $user; + + function __construct($out, $user) + { + parent::__construct($out); + $this->user = $user; + } + + /** + * Visible or invisible data elements + * + * Display the form fields that make up the data of the form. + * Sub-classes should overload this to show their data. + * + * @return void + */ + + function formData() + { + $this->elementStart('fieldset'); + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->checkbox('stream_mode_only', _('Only stream mode (no conversations) in timelines'), + $this->user->streamModeOnly()); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('conversation_tree', _('Show conversation page as hierarchical trees'), + $this->user->conversationTree()); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('stream_nicknames', _('Show nicknames (not full names) in timelines'), + $this->user->streamNicknames()); + $this->elementEnd('li'); + $this->elementEnd('fieldset'); + $this->elementEnd('ul'); + } + + /** + * Buttons for form actions + * + * Submit and cancel buttons (or whatever) + * Sub-classes should overload this to show their own buttons. + * + * @return void + */ + + function formActions() + { + $this->submit('submit', _('Save')); + } + + /** + * ID of the form + * + * Should be unique on the page. Sub-classes should overload this + * to show their own IDs. + * + * @return int ID of the form + */ + + function id() + { + return 'form_oldschool'; + } + + /** + * Action of the form. + * + * URL to post to. Should be overloaded by subclasses to give + * somewhere to post to. + * + * @return string URL to post to + */ + + function action() + { + return common_local_url('oldschoolsettings'); + } + + /** + * Class of the form. May include space-separated list of multiple classes. + * + * @return string the form's class + */ + + function formClass() + { + return 'form_settings'; + } +} diff --git a/actions/public.php b/actions/public.php index 75217cb229..cf732fe464 100644 --- a/actions/public.php +++ b/actions/public.php @@ -88,7 +88,13 @@ class PublicAction extends Action $this->userProfile = Profile::current(); - $stream = new ThreadingPublicNoticeStream($this->userProfile); + $user = common_current_user(); + + if (!empty($user) && $user->streamModeOnly()) { + $stream = new PublicNoticeStream($this->userProfile); + } else { + $stream = new ThreadingPublicNoticeStream($this->userProfile); + } $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); @@ -213,7 +219,13 @@ class PublicAction extends Action */ function showContent() { - $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile); + $user = common_current_user(); + + if (!empty($user) && $user->streamModeOnly()) { + $nl = new NoticeList($this->notice, $this); + } else { + $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile); + } $cnt = $nl->show(); diff --git a/actions/showgroup.php b/actions/showgroup.php index 9d4051bd89..2449ea1db7 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -97,10 +97,15 @@ class ShowgroupAction extends GroupAction $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - $this->userProfile = Profile::current(); - $stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile); + $user = common_current_user(); + + if (!empty($user) && $user->streamModeOnly()) { + $stream = new GroupNoticeStream($this->group, $this->userProfile); + } else { + $stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile); + } $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); @@ -140,7 +145,14 @@ class ShowgroupAction extends GroupAction */ function showGroupNotices() { - $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile); + $user = common_current_user(); + + if (!empty($user) && $user->streamModeOnly()) { + $nl = new NoticeList($this->notice, $this); + } else { + $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile); + } + $cnt = $nl->show(); $this->pagination($this->page > 1, diff --git a/classes/Old_school_prefs.php b/classes/Old_school_prefs.php new file mode 100644 index 0000000000..29e13ddc74 --- /dev/null +++ b/classes/Old_school_prefs.php @@ -0,0 +1,88 @@ +. + * + * @category UI + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + // This check helps protect against security problems; + // your code file can't be executed directly from the web. + exit(1); +} + +/** + * Separate table for storing UI preferences + * + * @category UI + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +class Old_school_prefs extends Managed_DataObject +{ + public $__table = 'old_school_prefs'; // table name + public $user_id; + public $stream_mode_only; + public $conversation_tree; + public $stream_nicknames; + public $created; + public $modified; + + public static function schemaDef() + { + return array( + 'fields' => array( + 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'), + 'stream_mode_only' => array('type' => 'int', + 'size' => 'tiny', + 'default' => 1, + 'description' => 'No conversation streams'), + 'conversation_tree' => array('type' => 'int', + 'size' => 'tiny', + 'default' => 1, + 'description' => 'Hierarchical tree view for conversations'), + 'stream_nicknames' => array('type' => 'int', + 'size' => 'tiny', + 'default' => 1, + 'description' => 'Show nicknames for authors and addressees in streams'), + 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), + 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'), + ), + 'primary key' => array('user_id'), + 'foreign keys' => array( + 'old_school_prefs_user_id_fkey' => array('user', array('user_id' => 'id')), + ), + ); + } + + function staticGet($k,$v=NULL) { + return Memcached_DataObject::staticGet('Old_school_prefs',$k,$v); + } +} diff --git a/classes/Profile.php b/classes/Profile.php index f61803dcd0..7f45031f66 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -1420,14 +1420,18 @@ class Profile extends Managed_DataObject { $ids = array(); foreach ($profiles as $profile) { - $ids[] = $profile->id; + if (!empty($profile)) { + $ids[] = $profile->id; + } } $avatars = Avatar::pivotGet('profile_id', $ids, array('width' => $width, 'height' => $width)); foreach ($profiles as $profile) { - $profile->_fillAvatar($width, $avatars[$profile->id]); + if (!empty($profile)) { // ??? + $profile->_fillAvatar($width, $avatars[$profile->id]); + } } } diff --git a/classes/User.php b/classes/User.php index 7289a17b69..65bc0485bf 100644 --- a/classes/User.php +++ b/classes/User.php @@ -1145,4 +1145,39 @@ class User extends Managed_DataObject // TRANS: Subject for password recovery e-mail. mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address); } + + function streamModeOnly() + { + if (common_config('oldschool', 'enabled')) { + $osp = Old_school_prefs::staticGet('user_id', $this->id); + if (!empty($osp)) { + return $osp->stream_mode_only; + } + } + + return false; + } + + function conversationTree() + { + if (common_config('oldschool', 'enabled')) { + $osp = Old_school_prefs::staticGet('user_id', $this->id); + if (!empty($osp)) { + return $osp->conversation_tree; + } + } + + return false; + } + + function streamNicknames() + { + if (common_config('oldschool', 'enabled')) { + $osp = Old_school_prefs::staticGet('user_id', $this->id); + if (!empty($osp)) { + return $osp->stream_nicknames; + } + } + return false; + } } diff --git a/db/core.php b/db/core.php index c484c8c785..b7881a7dc0 100644 --- a/db/core.php +++ b/db/core.php @@ -86,6 +86,7 @@ $classes = array('Profile', 'Local_group', 'User_urlshortener_prefs', 'Schema_version', + 'Old_school_prefs', ); foreach ($classes as $cls) { diff --git a/lib/conversationtree.php b/lib/conversationtree.php new file mode 100644 index 0000000000..49ed48af20 --- /dev/null +++ b/lib/conversationtree.php @@ -0,0 +1,215 @@ +. + * + * @category Widget + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + // This check helps protect against security problems; + // your code file can't be executed directly from the web. + exit(1); +} + +/** + * Conversation tree + * + * The widget class for displaying a hierarchical list of notices. + * + * @category Widget + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ +class ConversationTree extends NoticeList +{ + var $tree = null; + var $table = null; + + /** + * Show the tree of notices + * + * @return void + */ + function show() + { + $cnt = $this->_buildTree(); + + $this->out->elementStart('div', array('id' =>'notices_primary')); + // TRANS: Header on conversation page. Hidden by default (h2). + $this->out->element('h2', null, _('Notices')); + $this->out->elementStart('ol', array('class' => 'notices xoxo')); + + if (array_key_exists('root', $this->tree)) { + $rootid = $this->tree['root'][0]; + $this->showNoticePlus($rootid); + } + + $this->out->elementEnd('ol'); + $this->out->elementEnd('div'); + + return $cnt; + } + + function _buildTree() + { + $cnt = 0; + + $this->tree = array(); + $this->table = array(); + + while ($this->notice->fetch()) { + + $cnt++; + + $id = $this->notice->id; + $notice = clone($this->notice); + + $this->table[$id] = $notice; + + if (is_null($notice->reply_to)) { + $this->tree['root'] = array($notice->id); + } else if (array_key_exists($notice->reply_to, $this->tree)) { + $this->tree[$notice->reply_to][] = $notice->id; + } else { + $this->tree[$notice->reply_to] = array($notice->id); + } + } + + return $cnt; + } + + /** + * Shows a notice plus its list of children. + * + * @param integer $id ID of the notice to show + * + * @return void + */ + function showNoticePlus($id) + { + $notice = $this->table[$id]; + + $this->out->elementStart('li', array('class' => 'hentry notice', + 'id' => 'notice-' . $id)); + + $item = $this->newListItem($notice); + $item->show(); + + if (array_key_exists($id, $this->tree)) { + $children = $this->tree[$id]; + + $this->out->elementStart('ol', array('class' => 'notices')); + + sort($children); + + foreach ($children as $child) { + $this->showNoticePlus($child); + } + + $this->out->elementEnd('ol'); + } + + $this->out->elementEnd('li'); + } + + /** + * Override parent class to return our preferred item. + * + * @param Notice $notice Notice to display + * + * @return NoticeListItem a list item to show + */ + function newListItem($notice) + { + return new ConversationTreeItem($notice, $this->out); + } +} + +/** + * Conversation tree list item + * + * Special class of NoticeListItem for use inside conversation trees. + * + * @category Widget + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ +class ConversationTreeItem extends NoticeListItem +{ + /** + * start a single notice. + * + * The default creates the
  • ; we skip, since the ConversationTree + * takes care of that. + * + * @return void + */ + function showStart() + { + return; + } + + /** + * finish the notice + * + * The default closes the
  • ; we skip, since the ConversationTree + * takes care of that. + * + * @return void + */ + function showEnd() + { + return; + } + + /** + * show link to notice conversation page + * + * Since we're only used on the conversation page, we skip this + * + * @return void + */ + function showContext() + { + return; + } + + /** + * show people this notice is in reply to + * + * Tree context shows this, so we skip it. + * + * @return void + */ + function showAddressees() + { + return; + } +} diff --git a/lib/default.php b/lib/default.php index 8748b64580..673c94769a 100644 --- a/lib/default.php +++ b/lib/default.php @@ -352,5 +352,6 @@ $default = array('cache' => true), // whether to cache the router object. Defaults to true, turn off for devel 'discovery' => array('cors' => false), // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.) - 'performance' => array('high' => false) // disable some features for higher performance; default false + 'performance' => array('high' => false), // disable some features for higher performance; default false + 'oldschool' => array('enabled' => false) // enable users to use old-style UI ); diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index 0231f3a57f..a8506aa46e 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -219,8 +219,14 @@ class NoticeListItem extends Widget $this->out->elementStart('a', $attrs); $this->showAvatar(); $this->out->text(' '); - $this->out->element('span',array('class' => 'fn'), - $this->profile->getBestName()); + $user = common_current_user(); + if (!empty($user) && $user->streamNicknames()) { + $this->out->element('span',array('class' => 'fn'), + $this->profile->nickname); + } else { + $this->out->element('span',array('class' => 'fn'), + $this->profile->getBestName()); + } $this->out->elementEnd('a'); $this->out->elementEnd('span'); @@ -262,11 +268,15 @@ class NoticeListItem extends Widget $groups = $this->getGroups(); + $user = common_current_user(); + + $streamNicknames = !empty($user) && $user->streamNicknames(); + foreach ($groups as $group) { $ga[] = array('href' => $group->homeUrl(), 'title' => $group->nickname, 'class' => 'addressee group', - 'text' => $group->getBestName()); + 'text' => ($streamNicknames) ? $group->nickname : $group->getBestName()); } return $ga; @@ -283,11 +293,15 @@ class NoticeListItem extends Widget $replies = $this->getReplyProfiles(); + $user = common_current_user(); + + $streamNicknames = !empty($user) && $user->streamNicknames(); + foreach ($replies as $reply) { $pa[] = array('href' => $reply->profileurl, 'title' => $reply->nickname, 'class' => 'addressee account', - 'text' => $reply->getBestName()); + 'text' => ($streamNicknames) ? $reply->nickname : $reply->getBestName()); } return $pa; diff --git a/lib/router.php b/lib/router.php index 1fb5165621..b0124375de 100644 --- a/lib/router.php +++ b/lib/router.php @@ -184,6 +184,10 @@ class Router $m->connect('settings/'.$s, array('action' => $s.'settings')); } + if (common_config('oldschool', 'enabled')) { + $m->connect('settings/oldschool', array('action' => 'oldschoolsettings')); + } + $m->connect('settings/oauthapps/show/:id', array('action' => 'showapplication'), array('id' => '[0-9]+') diff --git a/lib/settingsnav.php b/lib/settingsnav.php index 67d5c35314..8b664fbae6 100644 --- a/lib/settingsnav.php +++ b/lib/settingsnav.php @@ -150,6 +150,15 @@ class SettingsNav extends Menu _('Authorized connected applications'), $actionName == 'oauthconnectionsettings'); + if (common_config('oldschool', 'enabled')) { + $this->action->menuItem(common_local_url('oldschoolsettings'), + // TRANS: Menu item in settings navigation panel. + _m('MENU','Old school'), + // TRANS: Menu item title in settings navigation panel. + _('UI tweaks for old-school users'), + $actionName == 'oldschoolsettings'); + } + Event::handle('EndConnectSettingsNav', array(&$this->action)); }