Skip to content

Commit 8a21d41

Browse files
committed
Add config value admin_chamilo_announcements_disable #2796
Disable Chamilo.org announcements at the top of the admin page
1 parent 5cac117 commit 8a21d41

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

main/inc/ajax/admin.ajax.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use Chamilo\CoreBundle\Entity\BranchSync;
55
use Chamilo\CoreBundle\Entity\Repository\BranchSyncRepository;
6+
use GuzzleHttp\Client;
67

78
/**
89
* Responses to AJAX calls.
@@ -72,6 +73,16 @@
7273

7374
echo file_get_contents("{$newUrlDir}{$blockName}_extra.html");
7475
break;
76+
case 'get_latest_news':
77+
if (api_get_configuration_value('admin_chamilo_announcements_disable') === true) {
78+
break;
79+
}
80+
81+
$latestNews = getLatestNews();
82+
$latestNews = json_decode($latestNews, true);
83+
84+
echo Security::remove_XSS($latestNews['text'], COURSEMANAGER);
85+
break;
7586
}
7687

7788
/**
@@ -225,3 +236,34 @@ function check_system_version()
225236

226237
return '<span style="color:red">'.get_lang('ImpossibleToContactVersionServerPleaseTryAgain').'</span>';
227238
}
239+
240+
/**
241+
* Display the latest news from the Chamilo Association for admins
242+
*
243+
* @throws \GuzzleHttp\Exception\GuzzleException
244+
*
245+
* @return string|void
246+
*/
247+
function getLatestNews()
248+
{
249+
global $language_interface;
250+
251+
$url = 'https://version.chamilo.org/news/latest.php';
252+
253+
$client = new Client();
254+
$response = $client->request(
255+
'GET',
256+
$url,
257+
[
258+
'query' => [
259+
'language' => $language_interface,
260+
],
261+
]
262+
);
263+
264+
if ($response->getStatusCode() !== 200) {
265+
return;
266+
}
267+
268+
return $response->getBody()->getContents();
269+
}

main/install/configuration.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,9 @@
10931093
// Default selected row in jqgrid/sortable tables
10941094
//$_configuration['table_default_row'] = 50;
10951095

1096+
// Disable Chamilo.org announcements at the top of the admin page
1097+
//$_configuration['admin_chamilo_announcements_disable'] = false;
1098+
10961099
// ------ Custom DB changes (keep this at the end)
10971100
// Add user activation by confirmation email
10981101
// This option prevents the new user to login in the platform if your account is not confirmed via email

main/template/default/admin/settings_index.tpl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% set admin_chamilo_announcements_disable = 'admin_chamilo_announcements_disable'|api_get_configuration_value %}
2+
13
<script>
24
$(document).ready(function () {
35
$.ajax({
@@ -35,10 +37,34 @@
3537
});
3638
});
3739
})(window.CKEDITOR);
40+
41+
{% if not admin_chamilo_announcements_disable %}
42+
$
43+
.ajax('{{ web_admin_ajax_url }}?a=get_latest_news')
44+
.then(function (response) {
45+
$('#chamilo-news').removeClass('hidden');
46+
$('#chamilo-news-content').html(response);
47+
});
48+
{% endif %}
3849
{% endif %}
3950
});
4051
</script>
4152

53+
{% if not admin_chamilo_announcements_disable %}
54+
<section id="chamilo-news" class="row hidden">
55+
<div class="col-xs-12">
56+
<div class="alert alert-info">
57+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
58+
<span aria-hidden="true">&times;</span>
59+
</button>
60+
<div id="chamilo-news-content">
61+
62+
</div>
63+
</div>
64+
</div>
65+
</section>
66+
{% endif %}
67+
4268
<section id="settings" class="row">
4369
{% set columns = 2 %}
4470
{% for block_item in blocks %}

0 commit comments

Comments
 (0)