mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 07:53:39 +01:00
Api: Add {{share}} & {{share-files_only}} merge placeholders that create an external share link
This commit is contained in:
parent
3dbdbc0596
commit
eca2cc9d46
@ -578,30 +578,49 @@ abstract class Merge
|
|||||||
* Get share placeholder
|
* Get share placeholder
|
||||||
*
|
*
|
||||||
* If the placeholder is present in the content, the share will be automatically
|
* If the placeholder is present in the content, the share will be automatically
|
||||||
* created.
|
* created. Valid placeholders:
|
||||||
|
* $$share$$ - A link to the entry
|
||||||
|
* $$share-files$$ - A link to filemanager showing files of the entry
|
||||||
|
* $$share/writable$$ - An editable link to the entry, using current user's permission
|
||||||
|
* $$share-files/writable$$ - Link to filemanager with write access
|
||||||
*/
|
*/
|
||||||
protected function share_placeholder($app, $id, $prefix, &$content)
|
protected function share_placeholder($app, $id, $prefix, &$content)
|
||||||
{
|
{
|
||||||
$replacements = array();
|
$replacements = array();
|
||||||
|
|
||||||
// Skip if no content or content has no share placeholder
|
// Skip if no content or content has no share placeholder (fast check)
|
||||||
if(!$content || strpos($content, '$$share') === FALSE)
|
if(!$content || strpos($content, '$$' . $this->prefix($prefix, 'share')) === FALSE)
|
||||||
{
|
{
|
||||||
return $replacements;
|
return $replacements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = null;
|
||||||
|
preg_match_all('/\${2}' . $this->prefix($prefix, 'share') . '[^\$]*\${2}/', $content, $matches);
|
||||||
|
list($placeholders) = $matches;
|
||||||
|
|
||||||
if(!$GLOBALS['egw_info']['user']['apps']['stylite'])
|
if(!$GLOBALS['egw_info']['user']['apps']['stylite'])
|
||||||
{
|
{
|
||||||
$replacements['$$' . $prefix . 'share$$'] = lang('EPL Only');
|
foreach($placeholders as $p)
|
||||||
|
{
|
||||||
|
$replacements[$p] = lang('EPL Only');
|
||||||
|
}
|
||||||
return $replacements;
|
return $replacements;
|
||||||
}
|
}
|
||||||
|
foreach($placeholders as $index => $placeholder)
|
||||||
// Get or create the share
|
|
||||||
$share = $this->create_share($app, $id, $content);
|
|
||||||
|
|
||||||
if($share)
|
|
||||||
{
|
{
|
||||||
$replacements['$$' . $prefix . 'share$$'] = $link = Api\Sharing::share2link($share);
|
// Get or create the share
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$share = $this->create_share($app, $id, $placeholder);
|
||||||
|
|
||||||
|
$replacements[$placeholder] = $share ? Api\Sharing::share2link($share) : '';
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
_egw_log_exception($e, $headline);
|
||||||
|
$replacements[$placeholder] = lang('Error');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $replacements;
|
return $replacements;
|
||||||
@ -623,17 +642,26 @@ abstract class Merge
|
|||||||
$session = \EGroupware\Api\Cache::getSession(Api\Sharing::class, $path);
|
$session = \EGroupware\Api\Cache::getSession(Api\Sharing::class, $path);
|
||||||
if($session && $session['share_path'] == $path)
|
if($session && $session['share_path'] == $path)
|
||||||
{
|
{
|
||||||
|
Api\Cache::unsetSession(Api\Sharing::class, $path);
|
||||||
return $session;
|
return $session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = null;
|
||||||
|
preg_match_all('/\${2}([^\/\$]+\/)?share(-files(_only)?)?(\/writable)?\${2}/', $content, $matches);
|
||||||
|
list($placeholders, , $files, , $writable) = $matches;
|
||||||
|
|
||||||
// Need to create the share here.
|
// Need to create the share here.
|
||||||
// No way to know here if it should be writable, or who it's going to
|
// No way to know here if it should be writable, or who it's going to
|
||||||
$mode = /* ? ? Sharing::WRITABLE :*/
|
$mode = $writable[0] == "/writable" ? Api\Sharing::WRITABLE : Api\Sharing::READONLY;
|
||||||
Api\Sharing::READONLY;
|
$path = $files[0] !== '-files_only' ? $path : "/apps/$app/$id";
|
||||||
$recipients = array();
|
$recipients = array();
|
||||||
$extra = array();
|
$extra = array();
|
||||||
|
|
||||||
//$extra['share_writable'] |= ($mode == Sharing::WRITABLE ? 1 : 0);
|
if($files[0] == '-files')
|
||||||
|
{
|
||||||
|
$extra['include_files'] = true;
|
||||||
|
}
|
||||||
|
$extra['share_writable'] |= ($mode == Api\Sharing::WRITABLE ? 1 : 0);
|
||||||
|
|
||||||
return \EGroupware\Stylite\Link\Sharing::create('', $path, $mode, NULL, $recipients, $extra);
|
return \EGroupware\Stylite\Link\Sharing::create('', $path, $mode, NULL, $recipients, $extra);
|
||||||
}
|
}
|
||||||
@ -2989,40 +3017,51 @@ abstract class Merge
|
|||||||
*/
|
*/
|
||||||
public function get_common_replacements()
|
public function get_common_replacements()
|
||||||
{
|
{
|
||||||
return array(
|
$share_replacements = !$GLOBALS['egw_info']['user']['apps']['stylite'] ? [] : [
|
||||||
// Link to current entry
|
'share' => lang("Share this %1 via URL", lang('entry')),
|
||||||
'link' => lang('URL of current record'),
|
// We don't allow anonymous file access through entries - the links tab will be empty
|
||||||
'link/href' => lang('HTML link to the current record'),
|
// 'share-files' => lang("Share this %1 via URL", lang('entry')) . " " . lang("include access to any linked files (links tab)"),
|
||||||
'link/title' => lang('Link title of current record'),
|
'share-files_only' => lang('Share just the associated filemanager directory, not the %1', lang('entry')),
|
||||||
|
'share/writable' => lang("Share this %1 via URL", lang('entry')) . '. ' . lang('Allow anonymous editing'),
|
||||||
|
// 'share-files/writable' => lang("Share this %1 via URL", lang('entry')) . " " . lang("include access to any linked files (links tab)"),
|
||||||
|
'share-files_only/writable' => lang('Share just the associated filemanager directory, not the %1', lang('entry')) . '. ' . lang('Allow anonymous editing'),
|
||||||
|
];
|
||||||
|
|
||||||
// Link system - linked entries
|
return $share_replacements +
|
||||||
'links' => lang('Titles of any entries linked to the current record, excluding attached files'),
|
array(
|
||||||
'links/href' => lang('HTML links to any entries linked to the current record, excluding attached files'),
|
// Link to current entry
|
||||||
'links/url' => lang('URLs of any entries linked to the current record, excluding attached files'),
|
'link' => lang('URL of current record'),
|
||||||
'attachments' => lang('List of files linked to the current record'),
|
'link/href' => lang('HTML link to the current record'),
|
||||||
'links_attachments' => lang('Links and attached files'),
|
'link/title' => lang('Link title of current record'),
|
||||||
'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'),
|
|
||||||
|
|
||||||
// General information
|
// Link system - linked entries
|
||||||
'date' => lang('Date'),
|
'links' => lang('Titles of any entries linked to the current record, excluding attached files'),
|
||||||
'datetime' => lang('Date + time'),
|
'links/href' => lang('HTML links to any entries linked to the current record, excluding attached files'),
|
||||||
'time' => lang('Time'),
|
'links/url' => lang('URLs of any entries linked to the current record, excluding attached files'),
|
||||||
'user/n_fn' => lang('Name of current user, all other contact fields are valid too'),
|
'attachments' => lang('List of files linked to the current record'),
|
||||||
'user/account_lid' => lang('Username'),
|
'links_attachments' => lang('Links and attached files'),
|
||||||
|
'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'),
|
||||||
|
|
||||||
// Merge control
|
// General information
|
||||||
'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'),
|
'date' => lang('Date'),
|
||||||
'label' => lang('Use this tag for addresslabels. Put the content, you want to repeat, between two tags.'),
|
'datetime' => lang('Date + time'),
|
||||||
'labelplacement' => lang('Tag to mark positions for address labels'),
|
'time' => lang('Time'),
|
||||||
|
'user/n_fn' => lang('Name of current user, all other contact fields are valid too'),
|
||||||
|
'user/account_lid' => lang('Username'),
|
||||||
|
|
||||||
// Commands
|
// Merge control
|
||||||
'IF fieldname' => lang('Example {{IF n_prefix~Mr~Hello Mr.~Hello Ms.}} - search the field "n_prefix", for "Mr", if found, write Hello Mr., else write Hello Ms.'),
|
'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'),
|
||||||
'IF fieldname~EMPTY~True~False' => lang('Check for empty values in IF statements. Example {{IF url~EMPTY~~Website:}} - If url is not empty, writes "Website:"'),
|
'label' => lang('Use this tag for addresslabels. Put the content, you want to repeat, between two tags.'),
|
||||||
'NELF' => lang('Example {{NELF role}} - if field role is not empty, you will get a new line with the value of field role'),
|
'labelplacement' => lang('Tag to mark positions for address labels'),
|
||||||
'NENVLF' => lang('Example {{NENVLF role}} - if field role is not empty, set a LF without any value of the field'),
|
|
||||||
'LETTERPREFIX' => lang('Example {{LETTERPREFIX}} - Gives a letter prefix without double spaces, if the title is emty for example'),
|
// Commands
|
||||||
'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'),
|
'IF fieldname' => lang('Example {{IF n_prefix~Mr~Hello Mr.~Hello Ms.}} - search the field "n_prefix", for "Mr", if found, write Hello Mr., else write Hello Ms.'),
|
||||||
);
|
'IF fieldname~EMPTY~True~False' => lang('Check for empty values in IF statements. Example {{IF url~EMPTY~~Website:}} - If url is not empty, writes "Website:"'),
|
||||||
|
'NELF' => lang('Example {{NELF role}} - if field role is not empty, you will get a new line with the value of field role'),
|
||||||
|
'NENVLF' => lang('Example {{NENVLF role}} - if field role is not empty, set a LF without any value of the field'),
|
||||||
|
'LETTERPREFIX' => lang('Example {{LETTERPREFIX}} - Gives a letter prefix without double spaces, if the title is emty for example'),
|
||||||
|
'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3035,6 +3074,7 @@ abstract class Merge
|
|||||||
$placeholders = [
|
$placeholders = [
|
||||||
'URLs' => [],
|
'URLs' => [],
|
||||||
'Egroupware links' => [],
|
'Egroupware links' => [],
|
||||||
|
'Sharing' => [],
|
||||||
'General' => [],
|
'General' => [],
|
||||||
'Repeat' => [],
|
'Repeat' => [],
|
||||||
'Commands' => []
|
'Commands' => []
|
||||||
@ -3051,6 +3091,12 @@ abstract class Merge
|
|||||||
|
|
||||||
switch($name)
|
switch($name)
|
||||||
{
|
{
|
||||||
|
case 'share':
|
||||||
|
$group = 'Sharing';
|
||||||
|
break;
|
||||||
|
case 'link':
|
||||||
|
$group = "URLs";
|
||||||
|
break;
|
||||||
case 'links':
|
case 'links':
|
||||||
$group = 'Egroupware links';
|
$group = 'Egroupware links';
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user