From 75128e8f68e829ad9e3670dac82f075d9632dba4 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sat, 7 May 2016 23:05:48 +0200 Subject: make editblock use status_editor() --- Zotlabs/Module/Blocks.php | 8 ++-- Zotlabs/Module/Editblock.php | 100 +++++++++++++------------------------------ Zotlabs/Module/Editpost.php | 1 + include/conversation.php | 25 +++++------ 4 files changed, 44 insertions(+), 90 deletions(-) diff --git a/Zotlabs/Module/Blocks.php b/Zotlabs/Module/Blocks.php index 192a4aded..ed702befb 100644 --- a/Zotlabs/Module/Blocks.php +++ b/Zotlabs/Module/Blocks.php @@ -82,11 +82,7 @@ class Blocks extends \Zotlabs\Web\Controller { } $mimetype = (($_REQUEST['mimetype']) ? $_REQUEST['mimetype'] : get_pconfig($owner,'system','page_mimetype')); - - if(! $mimetype) { - $mimetype = 'choose'; - } - + $x = array( 'webpage' => ITEM_TYPE_BLOCK, 'is_owner' => true, @@ -96,6 +92,8 @@ class Blocks extends \Zotlabs\Web\Controller { 'showacl' => false, 'visitor' => true, 'mimetype' => $mimetype, + 'mimeselect' => true, + 'hide_location' => true, 'ptlabel' => t('Block Name'), 'profile_uid' => intval($owner), 'expanded' => true, diff --git a/Zotlabs/Module/Editblock.php b/Zotlabs/Module/Editblock.php index 0204d0994..a79962033 100644 --- a/Zotlabs/Module/Editblock.php +++ b/Zotlabs/Module/Editblock.php @@ -3,6 +3,7 @@ namespace Zotlabs\Module; require_once('include/identity.php'); require_once('include/acl_selectors.php'); +require_once('include/conversation.php'); class Editblock extends \Zotlabs\Web\Controller { @@ -95,81 +96,38 @@ class Editblock extends \Zotlabs\Web\Controller { return; } - $plaintext = true; - - $mimeselect = ''; $mimetype = $itm[0]['mimetype']; - if($mimetype != 'text/bbcode') - $plaintext = true; - - if(get_config('system','page_mimetype')) - $mimeselect = ''; - else - $mimeselect = mimetype_select($itm[0]['uid'],$mimetype); - - \App::$page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( - '$baseurl' => z_root(), - '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), - '$pretext' => '', - '$ispublic' => ' ', // t('Visible to everybody'), - '$geotag' => '', - '$nickname' => $channel['channel_address'], - '$confirmdelete' => t('Delete block?'), - '$bbco_autocomplete'=> (($mimetype == 'text/bbcode') ? 'bbcode' : 'comanche-block') - )); - - $tpl = get_markup_template("jot.tpl"); - - $jotplugins = ''; - $jotnets = ''; - - call_hooks('jot_tool', $jotplugins); - call_hooks('jot_networks', $jotnets); - $rp = 'blocks/' . $channel['channel_address']; - $editor = replace_macros($tpl,array( - '$return_path' => $rp, - '$action' => 'item', - '$webpage' => ITEM_TYPE_BLOCK, - '$share' => t('Edit'), - '$bold' => t('Bold'), - '$italic' => t('Italic'), - '$underline' => t('Underline'), - '$quote' => t('Quote'), - '$code' => t('Code'), - '$writefiles' => (($mimetype == 'text/bbcode') ? perm_is_allowed($owner, get_observer_hash(), 'write_storage') : false), - '$attach' => t('Attach file'), - '$weblink' => (($mimetype == 'text/bbcode') ? t('Insert web link') : false), - '$setloc' => false, - '$noloc' => false, - '$permset' => t('Permission settings'), - '$ptyp' => $itm[0]['type'], - '$mimeselect' => $mimeselect, - '$content' => undo_post_tagging($itm[0]['body']), - '$post_id' => $post_id, - '$baseurl' => z_root(), - '$defloc' => $channel['channel_location'], - '$visitor' => true, - '$public' => t('Public post'), - '$jotnets' => $jotnets, - '$title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'), - '$placeholdertitle' => t('Title (optional)'), - '$pagetitle' => $block_title, - '$category' => '', - '$placeholdercategory' => t('Categories (optional, comma-separated list)'), - '$emtitle' => t('Example: bob@example.com, mary@example.com'), - '$lockstate' => $lockstate, - '$acl' => '', - '$bang' => '', - '$profile_uid' => (intval($channel['channel_id'])), - '$preview' => t('Preview'), - '$jotplugins' => $jotplugins, - '$sourceapp' => $itm[0]['app'], - '$defexpire' => '', - '$bbcode' => (($mimetype == 'text/bbcode') ? true : false) - )); + $x = array( + 'nickname' => $channel['channel_address'], + 'bbco_autocomplete'=> (($mimetype == 'text/bbcode') ? 'bbcode' : 'comanche-block'), + 'return_path' => $rp, + 'webpage' => ITEM_TYPE_BLOCK, + 'ptlabel' => t('Block Name'), + 'button' => t('Edit'), + 'writefiles' => (($mimetype == 'text/bbcode') ? perm_is_allowed($owner, get_observer_hash(), 'write_storage') : false), + 'weblink' => (($mimetype == 'text/bbcode') ? t('Insert web link') : false), + 'hide_voting' => true, + 'hide_future' => true, + 'hide_location' => true, + 'hide_expire' => true, + 'showacl' => false, + 'ptyp' => $itm[0]['type'], + 'mimeselect' => true, + 'mimetype' => $itm[0]['mimetype'], + 'body' => undo_post_tagging($itm[0]['body']), + 'post_id' => $post_id, + 'visitor' => true, + 'title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'), + 'placeholdertitle' => t('Title (optional)'), + 'pagetitle' => $block_title, + 'profile_uid' => (intval($channel['channel_id'])), + 'bbcode' => (($mimetype == 'text/bbcode') ? true : false) + ); + + $editor = status_editor($a, $x); $o .= replace_macros(get_markup_template('edpost_head.tpl'), array( '$title' => t('Edit Block'), diff --git a/Zotlabs/Module/Editpost.php b/Zotlabs/Module/Editpost.php index 25ba1a39a..43edf2c00 100644 --- a/Zotlabs/Module/Editpost.php +++ b/Zotlabs/Module/Editpost.php @@ -85,6 +85,7 @@ class Editpost extends \Zotlabs\Web\Controller { 'hide_voting' => true, 'hide_future' => true, 'hide_location' => true, + 'mimetype' => $itm[0]['mimetype'], 'ptyp' => $itm[0]['obj_type'], 'body' => undo_post_tagging($itm[0]['body']), 'post_id' => $post_id, diff --git a/include/conversation.php b/include/conversation.php index ea5be221f..32a613eab 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1138,25 +1138,22 @@ function status_editor($a, $x, $popup = false) { if(x($x, 'hide_location')) $geotag = $setloc = $clearloc = ''; - $weblink = t('Insert web link'); + $mimetype = ((x($x,'mimetype')) ? $x['mimetype'] : 'text/bbcode'); + + $mimeselect = ((x($x,'mimeselect')) ? $x['mimeselect'] : false); + if($mimeselect) + $mimeselect = mimetype_select($x['profile_uid'], $mimetype); + else + $mimeselect = ''; + + $weblink = (($mimetype === 'text/bbcode') ? t('Insert web link') : false); if(x($x, 'hide_weblink')) - $weblink = ''; + $weblink = false; - $writefiles = perm_is_allowed($x['profile_uid'], get_observer_hash(), 'write_storage'); + $writefiles = (($mimetype === 'text/bbcode') ? perm_is_allowed($x['profile_uid'], get_observer_hash(), 'write_storage') : false); if(x($x, 'hide_attach')) $writefiles = false; - $mimeselect = ''; - if(array_key_exists('mimetype', $x) && $x['mimetype']) { - if($x['mimetype'] != 'text/bbcode') - $plaintext = true; - if($x['mimetype'] === 'choose') { - $mimeselect = mimetype_select($x['profile_uid']); - } - else - $mimeselect = ''; - } - $layoutselect = ''; if(array_key_exists('layout', $x) && $x['layout']) { if($x['layout'] === 'choose') { -- cgit v1.2.3 From e7a65c1f8d97b92e311beb064a7094216e23b119 Mon Sep 17 00:00:00 2001 From: Treer Date: Sun, 8 May 2016 20:44:30 +1000 Subject: improve non-ACL option description in ACL dialog --- boot.php | 17 ++-- include/PermissionDescription.php | 167 ++++++++++++++++++++++++++++++++++++++ include/acl_selectors.php | 27 +++++- view/theme/redbasic/css/style.css | 7 ++ view/tpl/acl_selector.tpl | 8 +- 5 files changed, 212 insertions(+), 14 deletions(-) create mode 100644 include/PermissionDescription.php diff --git a/boot.php b/boot.php index bc92778d4..a93e09405 100755 --- a/boot.php +++ b/boot.php @@ -313,15 +313,14 @@ define ( 'PERMS_A_REPUBLISH', 0x10000); define ( 'PERMS_W_LIKE', 0x20000); // General channel permissions - -define ( 'PERMS_PUBLIC' , 0x0001 ); -define ( 'PERMS_NETWORK' , 0x0002 ); -define ( 'PERMS_SITE' , 0x0004 ); -define ( 'PERMS_CONTACTS' , 0x0008 ); -define ( 'PERMS_SPECIFIC' , 0x0080 ); -define ( 'PERMS_AUTHED' , 0x0100 ); -define ( 'PERMS_PENDING' , 0x0200 ); - + // 0 = Only you +define ( 'PERMS_PUBLIC' , 0x0001 ); // anybody +define ( 'PERMS_NETWORK' , 0x0002 ); // anybody in this network +define ( 'PERMS_SITE' , 0x0004 ); // anybody on this site +define ( 'PERMS_CONTACTS' , 0x0008 ); // any of my connections +define ( 'PERMS_SPECIFIC' , 0x0080 ); // only specific connections +define ( 'PERMS_AUTHED' , 0x0100 ); // anybody authenticated (could include visitors from other networks) +define ( 'PERMS_PENDING' , 0x0200 ); // any connections including those who haven't yet been approved // Address book flags diff --git a/include/PermissionDescription.php b/include/PermissionDescription.php new file mode 100644 index 000000000..d5a3a972c --- /dev/null +++ b/include/PermissionDescription.php @@ -0,0 +1,167 @@ +global_perm = $global_perm; + $this->channel_perm = $channel_perm; + + $this->fallback_description = ($description == '') ? t('Visible to your default audience') : $description; + } + + /** + * If the interpretation of an empty ACL can't be summarised with a global default permission + * or a specific permission setting then use this method and describe what it means instead. + * + * @param string $description - the caption for the no-ACL option in the ACL dialog. + * @return a new instance of PermissionDescription + */ + public static function fromDescription($description) { + return new PermissionDescription('', 0x80000, $description); + } + + + /** + * Use this method only if the interpretation of an empty ACL doesn't fall back to a global + * default permission. You should pass one of the constants from boot.php - PERMS_PUBLIC, PERMS_NETWORK etc. + * + * @param integer $perm - a single enumerated constant permission - PERMS_PUBLIC, PERMS_NETWORK etc. + * @return a new instance of PermissionDescription + */ + public static function fromStandalonePermission($perm) { + + $result = new PermissionDescription('', $perm); + + $checkPerm = $this->get_permission_description(); + if ($checkPerm == $this->fallback_description) { + $result = null; + logger('null PermissionDescription from unknown standalone permission: ' . $perm ,LOGGER_DEBUG, LOG_ERROR); + } + + return $result; + } + + /** + * This is the preferred way to create a PermissionDescription, as it provides the most details. + * Use this method if you know an empty ACL will result in one of the global default permissions + * being used, such as channel_r_stream (for which you would pass 'view_stream'). + * + * @param string $permname - a key for the global perms array from get_perms() in permissions.php, + * e.g. 'view_stream', 'view_profile', etc. + * @return a new instance of PermissionDescription + */ + public static function fromGlobalPermission($permname) { + + $result = null; + + $global_perms = get_perms(); + + if (array_key_exists($permname, $global_perms)) { + + $permDetails = $global_perms[$permname]; + $channelPerm = \App::$channel[$permDetails[0]]; + $result = new PermissionDescription($permDetails[1], $channelPerm); + } else { + // The acl dialog can handle null arguments, but it shouldn't happen + logger('null PermissionDescription from unknown global permission: ' . $permname ,LOGGER_DEBUG, LOG_ERROR); + } + return $result; + } + + + /** + * Gets a localized description of the permission, or a generic message if the permission + * is unknown. + * + * @return string description + */ + public function get_permission_description() { + + switch($this->channel_perm) { + + case 0: return t('Only me'); + case PERMS_PUBLIC: return t('Public'); + case PERMS_NETWORK: return t('Anybody in the $Projectname network'); + case PERMS_SITE: return sprintf(t('Any account on %s'), \App::get_hostname()); + case PERMS_CONTACTS: return t('Any of my connections'); + case PERMS_SPECIFIC: + // Because we're describing the permissions of an item with an empty ACL, + // the owner will be the only person able to see it if the permissions are + // set to "only specified connections". + return t('Only me (only specified contacts and me)'); + case PERMS_AUTHED: return t('Anybody authenticated (could include visitors from other networks)'); + case PERMS_PENDING: return t('Any connections including those who haven\'t yet been approved'); + default: return $this->fallback_description; + } + } + + /** + * Returns an icon css class name if an appropriate one is available, e.g. "fa-globe" for Public, + * otherwise returns empty string. + * + * @return string icon css class name (often FontAwesome) + */ + public function get_permission_icon() { + + switch($this->channel_perm) { + + case 0:/* only me */ return 'fa-eye-slash'; + case PERMS_PUBLIC: return 'fa-globe'; + case PERMS_NETWORK: return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use + case PERMS_SITE: return 'fa-sitemap'; + case PERMS_CONTACTS: return 'fa-group'; + case PERMS_SPECIFIC: + // Because we're describing the permissions of an item with an empty ACL, + // the owner will be the only person able to see it if the permissions are + // set to "only specified connections". + return 'fa-eye-slash'; + case PERMS_AUTHED: return ''; + case PERMS_PENDING: return ''; + default: return ''; + } + } + + + /** + * Returns a localized description of where the permission came from, if this is known. + * If it's not know, or if the permission is standalone and didn't come from a default + * permission setting, then empty string is returned. + * + * @return string description or empty string + */ + public function get_permission_origin_description() { + + switch($this->global_perm) { + + case PERMS_R_STREAM: return t('This is your default setting for the audience of your normal stream, and posts.'); + case PERMS_R_PROFILE: return t('This is your default setting for who can view your default channel profile'); + case PERMS_R_ABOOK: return t('This is your default setting for who can view your connections'); + case PERMS_R_STORAGE: return t('This is your default setting for who can view your file storage and photos'); + case PERMS_R_PAGES: return t('This is your default setting for the audience of your webpages'); + default: return ''; + } + } + +} diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 4cc01d15b..ce0a32798 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -6,6 +6,9 @@ /** * @package acl_selectors */ + +require_once("include/PermissionDescription.php"); + function group_select($selname,$selclass,$preselected = false,$size = 4) { $a = get_app(); @@ -215,20 +218,34 @@ function fixacl(&$item) { * * @param array $default Optional access control list for the initial state of the dialog. * @param boolean $show_jotnets Whether plugins for federated networks should be included in the permissions dialog -* @param string $showall_caption An optional caption to describe the scope of an unrestricted post. e.g. "Public" +* @param PermissionDescription $emptyACL_description - An optional description for the permission implied by selecting an empty ACL. Preferably an instance of PermissionDescription. * @param string $dialog_description Optional message to include at the top of the dialog. E.g. "Warning: Post permissions cannot be changed once sent". * @param string $context_help Allows the dialog to present a help icon. E.g. "acl_dialog_post" * @param boolean $readonly Not implemented yet. When implemented, the dialog will use acl_readonly.tpl instead, so that permissions may be viewed for posts that can no longer have their permissions changed. * * @return string html modal dialog built from acl_selector.tpl */ -function populate_acl($defaults = null,$show_jotnets = true, $showall_caption = '', $dialog_description = '', $context_help = '', $readonly = false) { +function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_description = '', $dialog_description = '', $context_help = '', $readonly = false) { $allow_cid = $allow_gid = $deny_cid = $deny_gid = false; + $showall_origin = ''; + $showall_icon = 'fa-globe'; - if(! $showall_caption) + + if(! $emptyACL_description) { $showall_caption = t('Visible to your default audience'); + } else if (is_a($emptyACL_description, 'PermissionDescription')) { + $showall_caption = $emptyACL_description->get_permission_description(); + $showall_origin = $emptyACL_description->get_permission_origin_description(); + $showall_icon = $emptyACL_description->get_permission_icon(); + + } else { + // For backwards compatibility we still accept a string... for now! + $showall_caption = $emptyACL_description; + } + + if(is_array($defaults)) { $allow_cid = ((strlen($defaults['allow_cid'])) ? explode('><', $defaults['allow_cid']) : array() ); @@ -252,6 +269,8 @@ function populate_acl($defaults = null,$show_jotnets = true, $showall_caption = $tpl = get_markup_template("acl_selector.tpl"); $o = replace_macros($tpl, array( '$showall' => $showall_caption, + '$showallOrigin' => $showall_origin, + '$showallIcon' => $showall_icon, '$showlimited' => t("Limit access:"), '$showlimitedDesc' => t('Select "Show" to allow viewing. "Don\'t show" lets you override and limit the scope of "Show".'), '$show' => t("Show"), @@ -278,7 +297,7 @@ function populate_acl($defaults = null,$show_jotnets = true, $showall_caption = * populate_acl() call for wall posts or network posts. * * This string is needed in 3 different files, and our .po translation system currently -* cannot be used as a string table (because the value is always the key is english) so +* cannot be used as a string table (because the value is always the key in english) so * I've centralized the value here (making this function name the "key") until we have a * better way. * diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css index 547fe9ec3..ebabd68e4 100644 --- a/view/theme/redbasic/css/style.css +++ b/view/theme/redbasic/css/style.css @@ -1046,6 +1046,13 @@ a.rconnect:hover, a.rateme:hover, div.rateme:hover { font-size: 140%; } +#acl-info-icon, +#acl-info-icon:active { + font-size: 110%; + color: $link_colour; + text-decoration: none; +} + #acl-showall-caption { margin-left: 0.35em; } diff --git a/view/tpl/acl_selector.tpl b/view/tpl/acl_selector.tpl index 0df72747a..050417257 100755 --- a/view/tpl/acl_selector.tpl +++ b/view/tpl/acl_selector.tpl @@ -25,8 +25,12 @@
+ {{if $showallOrigin}} +   + {{/if}}