Issues (2128)

main/forum/reply.php (4 issues)

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * These files are a complete rework of the forum. The database structure is
6
 * based on phpBB but all the code is rewritten. A lot of new functionalities
7
 * are added:
8
 * - forum categories and forums can be sorted up or down, locked or made invisible
9
 * - consistent and integrated forum administration
10
 * - forum options:     are students allowed to edit their post?
11
 *                      moderation of posts (approval)
12
 *                      reply only forums (students cannot create new threads)
13
 *                      multiple forums per group
14
 * - sticky messages
15
 * - new view option: nested view
16
 * - quoting a message.
17
 *
18
 * @package chamilo.forum
19
 */
20
require_once __DIR__.'/../inc/global.inc.php';
21
22
$this_section = SECTION_COURSES;
23
24
api_protect_course_script(true);
25
26
$nameTools = get_lang('ForumCategories');
27
$origin = api_get_origin();
28
$_user = api_get_user_info();
29
30
require_once 'forumfunction.inc.php';
31
32
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
33
$threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
34
35
/* MAIN DISPLAY SECTION */
36
37
/* Retrieving forum and forum categorie information */
38
// We are getting all the information about the current forum and forum category.
39
// Note pcool: I tried to use only one sql statement (and function) for this,
40
// but the problem is that the visibility of the forum AND forum category are stored in the item_property table.
41
// Note: This has to be validated that it is an existing thread.
42
$current_thread = get_thread_information($forumId, $threadId);
43
// Note: This has to be validated that it is an existing forum.
44
$current_forum = get_forum_information($current_thread['forum_id']);
0 ignored issues
show
Deprecated Code introduced by
The function get_forum_information() has been deprecated: this functionality is now moved to get_forums($forum_id) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

44
$current_forum = /** @scrutinizer ignore-deprecated */ get_forum_information($current_thread['forum_id']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
45
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
46
47
/* Is the user allowed here? */
48
// The user is not allowed here if
49
// 1. the forumcategory, forum or thread is invisible (visibility==0
50
// 2. the forumcategory, forum or thread is locked (locked <>0)
51
// 3. if anonymous posts are not allowed
52
// The only exception is the course manager
53
// I have split this is several pieces for clarity.
54
if (!api_is_allowed_to_edit(false, true) &&
55
    (($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
0 ignored issues
show
Bug Best Practice introduced by
The expression $current_forum_category of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
56
) {
57
    api_not_allowed(true);
58
}
59
if (!api_is_allowed_to_edit(false, true) &&
60
    (($current_forum_category && $current_forum_category['locked'] != 0) ||
0 ignored issues
show
Bug Best Practice introduced by
The expression $current_forum_category of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
61
        $current_forum['locked'] != 0 || $current_thread['locked'] != 0)
62
) {
63
    api_not_allowed(true);
64
}
65
if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
66
    api_not_allowed(true);
67
}
68
69
if ($current_forum['forum_of_group'] != 0) {
70
    $show_forum = GroupManager::user_has_access(
71
        api_get_user_id(),
72
        $current_forum['forum_of_group'],
73
        GroupManager::GROUP_TOOL_FORUM
74
    );
75
    if (!$show_forum) {
76
        api_not_allowed();
77
    }
78
}
79
80
if (api_is_in_gradebook()) {
81
    $interbreadcrumb[] = [
82
        'url' => Category::getUrl(),
83
        'name' => get_lang('ToolGradebook'),
84
    ];
85
}
86
$groupId = api_get_group_id();
87
if (!empty($groupId)) {
88
    $group_properties = GroupManager::get_group_properties($groupId);
89
    $interbreadcrumb[] = [
90
        'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
91
        'name' => get_lang('Groups'),
92
    ];
93
94
    $interbreadcrumb[] = [
95
        'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
96
        'name' => get_lang('GroupSpace').' '.$group_properties['name'],
97
    ];
98
99
    $interbreadcrumb[] = [
100
        'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
101
        'name' => $current_forum['forum_title'],
102
    ];
103
    $interbreadcrumb[] = [
104
        'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
105
        'name' => $current_thread['thread_title'],
106
    ];
107
108
    $interbreadcrumb[] = [
109
        'url' => 'javascript: void(0);',
110
        'name' => get_lang('Reply'),
111
    ];
112
} else {
113
    $interbreadcrumb[] = [
114
        'url' => 'index.php?'.api_get_cidreq(),
115
        'name' => $nameTools,
116
    ];
117
    $interbreadcrumb[] = [
118
        'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
119
        'name' => $current_forum_category['cat_title'],
120
    ];
121
    $interbreadcrumb[] = [
122
        'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
123
        'name' => $current_forum['forum_title'],
124
    ];
125
    $interbreadcrumb[] = [
126
        'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
127
        'name' => $current_thread['thread_title'],
128
    ];
129
    $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Reply')];
130
}
131
132
/* Header */
133
$htmlHeadXtra[] = <<<JS
134
    <script>
135
    $(function() {
136
        $('#reply-add-attachment').on('click', function(e) {
137
            e.preventDefault();
138
139
            var newInputFile = $('<input>', {
140
                type: 'file',
141
                name: 'user_upload[]'
142
            });
143
144
            $('[name="user_upload[]"]').parent().append(newInputFile);
145
        });
146
    });
147
    </script>
148
JS;
149
150
/* End new display forum */
151
// The form for the reply
152
$my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
153
$my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
154
$my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
155
156
$logInfo = [
157
    'tool' => TOOL_FORUM,
158
    'tool_id' => $forumId,
159
    'tool_id_detail' => $threadId,
160
    'action' => !empty($my_action) ? $my_action : 'reply',
161
];
162
Event::registerLog($logInfo);
0 ignored issues
show
The method registerLog() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

162
Event::/** @scrutinizer ignore-call */ 
163
       registerLog($logInfo);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
163
164
$form = show_add_post_form(
165
    $current_forum,
166
    $my_action,
167
    $my_elements
168
);
169
170
if ($origin == 'learnpath') {
171
    Display::display_reduced_header();
172
} else {
173
    // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
174
    Display::display_header();
175
}
176
/* Action links */
177
178
if ($origin != 'learnpath') {
179
    echo '<div class="actions">';
180
    echo '<span style="float:right;">'.search_link().'</span>';
181
    echo '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId.'">';
182
    echo Display::return_icon(
183
        'back.png',
184
        get_lang('BackToThread'),
185
        '',
186
        ICON_SIZE_MEDIUM
187
    ).'</a>';
188
    echo '</div>';
189
}
190
/*New display forum div*/
191
echo '<div class="forum_title">';
192
echo '<h1>';
193
echo Display::url(
194
    prepare4display($current_forum['forum_title']),
195
    'viewforum.php?'.api_get_cidreq().'&'.http_build_query(['forum' => $current_forum['forum_id']]),
196
    ['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
197
);
198
echo '</h1>';
199
echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
200
echo '</div>';
201
if ($form) {
202
    $form->display();
203
}
204
205
if ($origin == 'learnpath') {
206
    Display::display_reduced_footer();
207
} else {
208
    Display::display_footer();
209
}
210