From 0bc8fc91006307718a27f71e7b7f8c9866501049 Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 6 Oct 2020 10:56:08 -0600 Subject: [PATCH] Api: Move list of common merge placeholders into parent class to reduce duplication, add link/ options --- api/src/Storage/Merge.php | 40 +++++++++++++++++++++ calendar/inc/class.calendar_merge.inc.php | 19 +--------- infolog/inc/class.infolog_merge.inc.php | 21 +---------- timesheet/inc/class.timesheet_merge.inc.php | 19 +--------- 4 files changed, 43 insertions(+), 56 deletions(-) diff --git a/api/src/Storage/Merge.php b/api/src/Storage/Merge.php index 7767a034d8..6b1901bdb1 100644 --- a/api/src/Storage/Merge.php +++ b/api/src/Storage/Merge.php @@ -2342,4 +2342,44 @@ abstract class Merge } return Api\Etemplate::number_format($number,$num_decimal_places); } + + /** + * Get a list of common replacements available to all applications + * + * @return array + */ + public function get_common_replacements() + { + return array( + // Link to current entry + 'link' => lang('URL of current record'), + 'link/href' => lang('HTML link to the current record'), + 'link/title' => lang('Link title of current record'), + + // Link system - linked entries + 'links' => lang('Titles of any entries linked to the current record, excluding attached files'), + 'links/href' => lang('HTML links to any entries linked to the current record, excluding attached files'), + 'links/url' => lang('URLs of any entries linked to the current record, excluding attached files'), + 'attachments' => lang('List of files linked to the current record'), + 'links_attachments' => lang('Links and attached files'), + 'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'), + + // General information + 'date' => lang('Date'), + 'user/n_fn' => lang('Name of current user, all other contact fields are valid too'), + 'user/account_lid' => lang('Username'), + + // Merge control + 'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'), + 'label' => lang('Use this tag for addresslabels. Put the content, you want to repeat, between two tags.'), + 'labelplacement' => lang('Tag to mark positions for address labels'), + + // Commands + '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.'), + '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'), + ); + } } diff --git a/calendar/inc/class.calendar_merge.inc.php b/calendar/inc/class.calendar_merge.inc.php index 35d04574d6..a34d5a0eec 100644 --- a/calendar/inc/class.calendar_merge.inc.php +++ b/calendar/inc/class.calendar_merge.inc.php @@ -933,24 +933,7 @@ class calendar_merge extends Api\Storage\Merge echo '{{day/birthdays}}'.lang('Birthdays').''; echo '

'.lang('General fields:')."

"; - foreach(array( - 'link' => lang('HTML link to the current record'), - 'links' => lang('Titles of any entries linked to the current record, excluding attached files'), - 'attachments' => lang('List of files linked to the current record'), - 'links_attachments' => lang('Links and attached files'), - 'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'), - 'date' => lang('Date'), - 'user/n_fn' => lang('Name of current user, all other contact fields are valid too'), - 'user/account_lid' => lang('Username'), - 'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'), - 'label' => lang('Use this tag for addresslabels. Put the content, you want to repeat, between two tags.'), - 'labelplacement' => lang('Tag to mark positions for address labels'), - '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.'), - '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'), - ) as $name => $label) + foreach($this->get_common_replacements() as $name => $label) { echo '{{'.$name.'}}'.$label."\n"; } diff --git a/infolog/inc/class.infolog_merge.inc.php b/infolog/inc/class.infolog_merge.inc.php index e8d16e15b6..dab6a067fb 100644 --- a/infolog/inc/class.infolog_merge.inc.php +++ b/infolog/inc/class.infolog_merge.inc.php @@ -238,26 +238,7 @@ class infolog_merge extends Api\Storage\Merge } echo '

'.lang('General fields:')."

"; - foreach(array( - 'link' => lang('HTML link to the current record'), - 'links' => lang('Titles of any entries linked to the current record, excluding attached files'), - 'attachments' => lang('List of files linked to the current record'), - 'links_attachments' => lang('Links and attached files'), - 'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'), - 'links/href' => lang('Links wrapped in an HREF tag with download link'), - 'links/link' => lang('Download url for links'), - 'date' => lang('Date'), - 'user/n_fn' => lang('Name of current user, all other contact fields are valid too'), - 'user/account_lid' => lang('Username'), - 'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'), - 'label' => lang('Use this tag for addresslabels. Put the content, you want to repeat, between two tags.'), - 'labelplacement' => lang('Tag to mark positions for address labels'), - '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.'), - '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'), - ) as $name => $label) + foreach($this->get_common_replacements() as $name => $label) { echo '{{'.$name.'}}'.$label."\n"; } diff --git a/timesheet/inc/class.timesheet_merge.inc.php b/timesheet/inc/class.timesheet_merge.inc.php index 1095caeaff..975799e58c 100644 --- a/timesheet/inc/class.timesheet_merge.inc.php +++ b/timesheet/inc/class.timesheet_merge.inc.php @@ -204,24 +204,7 @@ class timesheet_merge extends Api\Storage\Merge } echo '

'.lang('General fields:')."

"; - foreach(array( - 'link' => lang('HTML link to the current record'), - 'links' => lang('Titles of any entries linked to the current record, excluding attached files'), - 'attachments' => lang('List of files linked to the current record'), - 'links_attachments' => lang('Links and attached files'), - 'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'), - 'date' => lang('Date'), - 'user/n_fn' => lang('Name of current user, all other contact fields are valid too'), - 'user/account_lid' => lang('Username'), - 'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'), - 'label' => lang('Use this tag for addresslabels. Put the content, you want to repeat, between two tags.'), - 'labelplacement' => lang('Tag to mark positions for address labels'), - '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.'), - '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 empty for example'), - 'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'), - ) as $name => $label) + foreach($this->get_common_replacements() as $name => $label) { echo '{{'.$name.'}}'.$label."\n"; }