Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix php8.1 + german translation #2

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
/vendor/
195 changes: 62 additions & 133 deletions Mattermost.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public function register() {
$this->description = plugin_lang_get('description');
$this->page = 'config_page';
$this->version = '1.0';
$this->requires = array('MantisCore' => '2.5.x');
$this->requires = ['MantisCore' => '2.5.x'];
$this->author = 'AA\'LA Solutions';
$this->contact = '[email protected]';
$this->url = 'http://aalasolutions.com';
$this->url = 'https://aalasolutions.com';
}

public function install() {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
plugin_error(ERROR_PHP_VERSION, ERROR);
return false;
}
Expand All @@ -46,30 +46,22 @@ public function install() {
}

public function config() {
return array(
'url_webhooks' => array(),
return [
'url_webhooks' => [],
'url_webhook' => '',
'bot_name' => 'mantis',
'bot_icon' => '',
'skip_bulk' => true,
'link_names' => false,
'channels' => array(),
'channels' => [],
'default_channel' => '#general',
'usernames' => array(),
'columns' => array(
'status',
'priority',
'handler_id',
'reporter_id',
'target_version',
'severity',
'description',
),
);
'usernames' => [],
'columns' => ['status', 'priority', 'handler_id', 'reporter_id', 'target_version', 'severity', 'description'],
];
}

public function hooks() {
return array(
return [
'EVENT_REPORT_BUG' => 'bug_report',
'EVENT_UPDATE_BUG' => 'bug_update',
'EVENT_BUG_DELETED' => 'bug_deleted',
Expand All @@ -78,7 +70,7 @@ public function hooks() {
'EVENT_BUGNOTE_EDIT' => 'bugnote_add_edit',
'EVENT_BUGNOTE_DELETED' => 'bugnote_deleted',
'EVENT_BUGNOTE_ADD_FORM' => 'bugnote_add_form',
);
];
}

public function bugnote_add_form($event, $bug_id) {
Expand Down Expand Up @@ -137,7 +129,7 @@ public function bug_deleted($event, $bug_id) {
$this->notify($msg, $this->get_webhook($project), $this->get_channel($project));
}

public function bugnote_add_edit($event, $bug_id, $bugnote_id) {
public function bugnote_add_edit($event, $bug_id, $bugnote_id, $files = null) {
$bug = bug_get($bug_id);
$bugnote = bugnote_get($bugnote_id);

Expand All @@ -155,8 +147,8 @@ public function bugnote_add_edit($event, $bug_id, $bugnote_id) {
}

public function get_text_attachment($text) {
$attachment = array('color' => '#3AA3E3', 'mrkdwn_in' => array('pretext', 'text', 'fields'));
$attachment['fallback'] = text . "\n";
$attachment = ['color' => '#3AA3E3', 'mrkdwn_in' => ['pretext', 'text', 'fields']];
$attachment['fallback'] = \TEXT."\n";
$attachment['text'] = $text;
return $attachment;
}
Expand All @@ -182,126 +174,63 @@ public function format_summary($bug) {

public function format_text($bug, $text) {
$t = string_display_line_links($this->bbcode_to_mattermost($text));
return strip_tags(html_entity_decode($t));

return strip_tags(html_entity_decode((string) $t));
}

public function get_attachment($bug) {
$attachment = array('fallback' => '', 'color' => '#3AA3E3', 'mrkdwn_in' => array('pretext', 'text', 'fields'));
$attachment = ['fallback' => '', 'color' => '#3AA3E3', 'mrkdwn_in' => ['pretext', 'text', 'fields']];
$t_columns = (array)plugin_config_get('columns');
foreach ($t_columns as $t_column) {
$title = column_get_title($t_column);
$value = $this->format_value($bug, $t_column);

if ($title && $value) {
$attachment['fallback'] .= $title . ': ' . $value . "\n";
$attachment['fields'][] = array(
'title' => $title,
'value' => $value,
'short' => !column_is_extended($t_column),
);
$attachment['fields'][] = ['title' => $title, 'value' => $value, 'short' => !column_is_extended($t_column)];
}
}
return $attachment;
}

public function format_value($bug, $field_name) {
$self = $this;
$values = array(
'id' => function ($bug) {
return sprintf('<%s|%s>', string_get_bug_view_url_with_fqdn($bug->id), $bug->id);
},
'project_id' => function ($bug) {
return project_get_name($bug->project_id);
},
'reporter_id' => function ($bug) {
return $this->get_user_name($bug->reporter_id);
},
'handler_id' => function ($bug) {
return empty($bug->handler_id) ? plugin_lang_get('no_user') : $this->get_user_name($bug->handler_id);
},
'duplicate_id' => function ($bug) {
return sprintf('<%s|%s>', string_get_bug_view_url_with_fqdn($bug->duplicate_id), $bug->duplicate_id);
},
'priority' => function ($bug) {
return get_enum_element('priority', $bug->priority);
},
'severity' => function ($bug) {
return get_enum_element('severity', $bug->severity);
},
'reproducibility' => function ($bug) {
return get_enum_element('reproducibility', $bug->reproducibility);
},
'status' => function ($bug) {
return get_enum_element('status', $bug->status);
},
'resolution' => function ($bug) {
return get_enum_element('resolution', $bug->resolution);
},
'projection' => function ($bug) {
return get_enum_element('projection', $bug->projection);
},
'category_id' => function ($bug) {
return category_full_name($bug->category_id, false);
},
'eta' => function ($bug) {
return get_enum_element('eta', $bug->eta);
},
'view_state' => function ($bug) {
return $bug->view_state == VS_PRIVATE ? lang_get('private') : lang_get('public');
},
'sponsorship_total' => function ($bug) {
return sponsorship_format_amount($bug->sponsorship_total);
},
'os' => function ($bug) {
return $bug->os;
},
'os_build' => function ($bug) {
return $bug->os_build;
},
'platform' => function ($bug) {
return $bug->platform;
},
'version' => function ($bug) {
return $bug->version;
},
'fixed_in_version' => function ($bug) {
return $bug->fixed_in_version;
},
'target_version' => function ($bug) {
return $bug->target_version;
},
'build' => function ($bug) {
return $bug->build;
},
'summary' => function ($bug) use ($self) {
return $self->format_summary($bug);
},
'last_updated' => function ($bug) {
return date(config_get('short_date_format'), $bug->last_updated);
},
'date_submitted' => function ($bug) {
return date(config_get('short_date_format'), $bug->date_submitted);
},
'due_date' => function ($bug) {
return date(config_get('short_date_format'), $bug->due_date);
},
'description' => function ($bug) use ($self) {
return $self->format_text($bug, $bug->description);
},
'steps_to_reproduce' => function ($bug) use ($self) {
return $self->format_text($bug, $bug->steps_to_reproduce);
},
'additional_information' => function ($bug) use ($self) {
return $self->format_text($bug, $bug->additional_information);
},
);
$values = [
'id' => fn($bug) => sprintf('<%s|%s>', string_get_bug_view_url_with_fqdn($bug->id), $bug->id),
'project_id' => fn($bug) => project_get_name($bug->project_id),
'reporter_id' => fn($bug) => $this->get_user_name($bug->reporter_id),
'handler_id' => fn($bug) => empty($bug->handler_id) ? plugin_lang_get('no_user') : $this->get_user_name($bug->handler_id),
'duplicate_id' => fn($bug) => sprintf('<%s|%s>', string_get_bug_view_url_with_fqdn($bug->duplicate_id), $bug->duplicate_id),
'priority' => fn($bug) => get_enum_element('priority', $bug->priority),
'severity' => fn($bug) => get_enum_element('severity', $bug->severity),
'reproducibility' => fn($bug) => get_enum_element('reproducibility', $bug->reproducibility),
'status' => fn($bug) => get_enum_element('status', $bug->status),
'resolution' => fn($bug) => get_enum_element('resolution', $bug->resolution),
'projection' => fn($bug) => get_enum_element('projection', $bug->projection),
'category_id' => fn($bug) => category_full_name($bug->category_id, false),
'eta' => fn($bug) => get_enum_element('eta', $bug->eta),
'view_state' => fn($bug) => $bug->view_state == VS_PRIVATE ? lang_get('private') : lang_get('public'),
'sponsorship_total' => fn($bug) => sponsorship_format_amount($bug->sponsorship_total),
'os' => fn($bug) => $bug->os,
'os_build' => fn($bug) => $bug->os_build,
'platform' => fn($bug) => $bug->platform,
'version' => fn($bug) => $bug->version,
'fixed_in_version' => fn($bug) => $bug->fixed_in_version,
'target_version' => fn($bug) => $bug->target_version,
'build' => fn($bug) => $bug->build,
'summary' => fn($bug) => $self->format_summary($bug),
'last_updated' => fn($bug) => date(config_get('short_date_format'), $bug->last_updated),
'date_submitted' => fn($bug) => date(config_get('short_date_format'), $bug->date_submitted),
'due_date' => fn($bug) => date(config_get('short_date_format'), $bug->due_date),
'description' => fn($bug) => $self->format_text($bug, $bug->description),
'steps_to_reproduce' => fn($bug) => $self->format_text($bug, $bug->steps_to_reproduce),
'additional_information' => fn($bug) => $self->format_text($bug, $bug->additional_information),
];
// Discover custom fields.
$t_related_custom_field_ids = custom_field_get_linked_ids($bug->project_id);
foreach ($t_related_custom_field_ids as $t_id) {
$t_def = custom_field_get_definition($t_id);
$values['custom_' . $t_def['name']] = function ($bug) use ($t_id) {
return custom_field_get_value($t_id, $bug->id);
};
$values['custom_'.$t_def['name']] = fn($bug) => custom_field_get_value($t_id, $bug->id);
}
if (isset($values[$field_name])) {
$func = $values[$field_name];
Expand Down Expand Up @@ -332,16 +261,16 @@ public function notify($msg, $webhook, $channel, $attachment = FALSE) {
return;
}

$url = sprintf('%s', trim($webhook));
$url = sprintf('%s', trim((string) $webhook));

$payload = array(
$payload = [
'channel' => $channel,
'username' => plugin_config_get('bot_name'),
'text' => $msg,
'text' => $msg,
'link_names' => plugin_config_get('link_names'),
);
];

$bot_icon = trim(plugin_config_get('bot_icon'));
$bot_icon = trim((string) plugin_config_get('bot_icon'));

if (empty($bot_icon)) {
$payload['icon_url'] = 'https://github.com/aalasolutions/MantisBT-Mattermost/blob/master/mantis_logo.png?raw=true';
Expand All @@ -352,13 +281,13 @@ public function notify($msg, $webhook, $channel, $attachment = FALSE) {
}

if ($attachment) {
$payload['attachments'] = array($attachment);
$payload['attachments'] = [$attachment];
}

$data = json_encode($payload);

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Expand All @@ -374,7 +303,7 @@ public function notify($msg, $webhook, $channel, $attachment = FALSE) {
}

public function bbcode_to_mattermost($bbtext) {
$bbtags = array(
$bbtags = [
'[b]' => '*',
'[/b]' => '* ',
'[i]' => '_',
Expand Down Expand Up @@ -402,11 +331,11 @@ public function bbcode_to_mattermost($bbtext) {
'[/center]' => '',
'[justify]' => '',
'[/justify]' => '',
);
];

$bbtext = str_ireplace(array_keys($bbtags), array_values($bbtags), $bbtext);
$bbtext = str_ireplace(array_keys($bbtags), array_values($bbtags), (string) $bbtext);

$bbextended = array(
$bbextended = [
"/\[code(.*?)\](.*?)\[\/code\]/is" => "```$2```",
"/\[color(.*?)\](.*?)\[\/color\]/is" => "$2",
"/\[size=(.*?)\](.*?)\[\/size\]/is" => "$2",
Expand All @@ -415,7 +344,7 @@ public function bbcode_to_mattermost($bbtext) {
"/\[url=(.*?)\](.*?)\[\/url\]/i" => "<$1|$2>",
"/\[email=(.*?)\](.*?)\[\/email\]/i" => "<mailto:$1|$2>",
"/\[img\]([^[]*)\[\/img\]/i" => "<$1>",
);
];

foreach ($bbextended as $match => $replacement) {
$bbtext = preg_replace($match, $replacement, $bbtext);
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ MantisBT-Mattermost
A [MantisBT](http://www.mantisbt.org/) plugin to send bug updates to [Mattermost](https://about.mattermost.com/)
channels.

It is only for Mantis 2.0.x, not backward compatible.
+ It is only for Mantis 2.0.x, not backward compatible.
+ This fork has minimal changes
+ German translation added
+ Fixed *Unknown named parameter $files* error for PHP >= 8.0


# Setup
Expand All @@ -28,4 +31,4 @@ configuration option is set to "All Users", with type "complex". Example value f
option for this purpose. Follow the instructions on the plugin configuration page.


_Heavily inspired by [MantisBT-Slack](https://github.com/infojunkie/MantisBT-Slack) Plugin._
_Heavily inspired by [MantisBT-Slack](https://github.com/infojunkie/MantisBT-Slack) Plugin._
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "aalasolutions-zz/mantisbt-mattermost",
"description": "A MantisBT plugin to send bug updates to Mattermost channels.",
"minimum-stability": "stable",
"license": "GPL-2.0-only",
"authors": [
{
"name": "Aamir Mahmood"
}
],
"config": {
"sort-packages": true
},
"require": {
"php": ">=8.1.0",
"ext-curl": "*"
},
"require-dev": {
"rector/rector": "^1.0"
}
}
Loading