forked from atutor/ATutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.php
320 lines (267 loc) · 11.2 KB
/
content.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
/****************************************************************/
/* ATutor */
/****************************************************************/
/* Copyright (c) 2002-2009 */
/* Inclusive Design Institute */
/* http://atutor.ca */
/* */
/* This program is free software. You can redistribute it and/or*/
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation. */
/****************************************************************/
// $Id$
define('AT_INCLUDE_PATH', 'include/');
require(AT_INCLUDE_PATH.'vitals.inc.php');
$cid = $_GET['cid'] = intval($_GET['cid']);
if ($cid == 0) {
header('Location: '.$_base_href.'index.php');
exit;
}
tool_origin('off');
/* show the content page */
$rows_content = $contentManager->getContentPage($cid);
foreach($rows_content as $content_row){
if (!$content_row) {
$_pages['content.php']['title_var'] = 'missing_content';
$_pages['content.php']['parent'] = 'index.php';
$_pages['content.php']['ignore'] = true;
require(AT_INCLUDE_PATH.'header.inc.php');
$msg->addError('PAGE_NOT_FOUND');
$msg->printAll();
require (AT_INCLUDE_PATH.'footer.inc.php');
exit;
}
}/* else: */
if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE === TRUE) {
$course_base_href = 'get.php/';
} else {
$course_base_href = 'content/' . $_SESSION['course_id'] . '/';
}
/* the "heading navigation": */
$path = $contentManager->getContentPath($cid);
if ($content_row['content_path']) {
$content_base_href = $content_row['content_path'].'/';
}
$parent_headings = '';
$num_in_path = count($path);
/* the page title: */
$page_title = '';
$page_title .= $content_row['title'];
$content_keywords = $content_row['keywords'];
$content_description = preg_replace('/\s\s+/', ' ',substr(str_replace(' ', ' ',str_replace('"', '', strip_tags($content_row['text']))), 0, 350));
for ($i=0; $i<$num_in_path; $i++) {
$content_info = $path[$i];
if ($_SESSION['prefs']['PREF_NUMBERING']) {
if ($contentManager->_menu_info[$content_info['content_id']]['content_parent_id'] == 0) {
$top_num = $contentManager->_menu_info[$content_info['content_id']]['ordering'];
$parent_headings .= $top_num;
} else {
$top_num = $top_num.'.'.$contentManager->_menu_info[$content_info['content_id']]['ordering'];
$parent_headings .= $top_num;
}
if ($_SESSION['prefs']['PREF_NUMBERING']) {
$path[$i]['content_number'] = $top_num . ' ';
}
$parent_headings .= ' ';
}
}
if ($_SESSION['prefs']['PREF_NUMBERING']) {
if ($top_num != '') {
$top_num = $top_num.'.'.$content_row['ordering'];
$page_title .= $top_num.' ';
} else {
$top_num = $content_row['ordering'];
$page_title .= $top_num.' ';
}
}
$parent = 0;
foreach ($path as $i=>$page) {
// When login is a student, remove content folder from breadcrumb path as content folders are
// just toggles for students. Keep content folder in breadcrumb path for instructors as they
// can edit content folder title.
if (!authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN) &&
$contentManager->_menu_info[$page['content_id']]['content_type'] == CONTENT_TYPE_FOLDER) {
unset($path[$i]);
continue;
}
if ($contentManager->_menu_info[$page['content_id']]['content_type'] == CONTENT_TYPE_FOLDER)
$content_url = 'mods/_core/editor/edit_content_folder.php?cid='.$page['content_id'];
else
$content_url = 'content.php?cid='.$page['content_id'];
if (!$parent) {
$_pages[$content_url]['title'] = $page['content_number'] . $page['title'];
$_pages[$content_url]['parent'] = 'index.php';
} else {
$_pages[$content_url]['title'] = $page['content_number'] . $page['title'];
$_pages[$content_url]['parent'] = 'mods/_core/editor/edit_content_folder.php?cid='.$parent;
}
$_pages[$content_url]['ignore'] = true;
$parent = $page['content_id'];
}
$last_page = array_pop($_pages);
$_pages['content.php'] = $last_page;
reset($path);
$first_page = current($path);
/* the content test extension page */
$content_test_ids = array(); //the html
$content_test_rs = $contentManager->getContentTestsAssoc($cid);
foreach($content_test_rs as $content_test_row){
$content_test_ids[] = $content_test_row;
}
/*TODO***************BOLOGNA***************REMOVE ME**********/
/* the content forums extension page*/
$content_forum_ids = array(); //the html
$content_forum_rs = $contentManager->getContentForumsAssoc($cid);
foreach($content_forum_rs as $content_forum_row){
$content_forum_ids[] = $content_forum_row;
}
// use any styles that were part of the imported document, except on the mobile theme.
// $_custom_css = $_base_href.'headstuff.php?cid='.$cid.SEP.'path='.urlEncode($_base_href.$course_base_href.$content_base_href);
if (is_mobile_device() == false) {
if ($content_row['use_customized_head'] && strlen($content_row['head']) > 0)
{
$_custom_head .= "\n".$content_row['head'];
}
}
global $_custom_head;
$_custom_head .= '
<script type="text/javascript">
//<!--
jQuery(".tooltip").tooltip();
//-->
</script>
';
save_last_cid($cid);
if (isset($top_num) && $top_num != (int) $top_num) {
$top_num = substr($top_num, 0, strpos($top_num, '.'));
}
// used by header.inc.php
$_tool_shortcuts = $contentManager->getToolShortcuts($content_row);
/* if i'm an admin then let me see content, otherwise only if released */
$released_status = $contentManager->isReleased($cid);
if ($released_status === TRUE || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
//if it has test and forum associated with it, still display it even if the content is empty
if ($content_row['text'] == '' && (empty($content_test_ids) && empty($content_forum_ids))){
$msg->addInfo('NO_PAGE_CONTENT');
$savant->assign('body', '');
} else {
if ($released_status !== TRUE) {
/* show the instructor that this content hasn't been released yet */
$infos = array('NOT_RELEASED', AT_date(_AT('announcement_date_format'), $released_status, AT_DATE_UNIX_TIMESTAMP));
$msg->addInfo($infos);
unset($infos);
}
$pre_test_id = $contentManager->getPretest($cid);
if (intval($pre_test_id) > 0)
{
if (authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
$msg->addInfo('PRETEST');
}
else {
header('Location: '.url_rewrite('mods/_standard/tests/test_intro.php?tid='.$pre_test_id.SEP.'cid='.$cid, AT_PRETTY_URL_IS_HEADER));
exit;
}
}
// if one of the prerequisite test(s) has expired, student cannot view the content
if (intval($pre_test_id) != -1 || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN))
{
// find whether the body has alternatives defined
list($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative)
= provide_alternatives($cid, $content_row['text'], true);
// apply alternatives
if (intval($_GET['alternative']) > 0) {
$content = provide_alternatives($cid, $content_row['text'], false, intval($_GET['alternative']));
} else {
$content = provide_alternatives($cid, $content_row['text']);
}
$content = format_content($content, $content_row['formatting'], $glossary);
$content_array = get_content_table($content);
// Create the array of alternative information for generating the AFA tool bar
$alt_infos = array();
$pause_image = find_image("pause.png");
if($has_text_alternative){
$alt_infos['has_text_alternative'] = array('3', _AT('apply_text_alternatives'), _AT('stop_apply_text_alternatives'), $pause_image, find_image('text_alternative.png'));
}
if($has_audio_alternative){
$alt_infos['has_audio_alternative'] = array('1', _AT('apply_audio_alternatives'), _AT('stop_apply_audio_alternatives'), $pause_image, find_image('audio_alternative.png'));
}
if($has_visual_alternative){
$alt_infos['has_visual_alternative'] = array('4', _AT('apply_visual_alternatives'), _AT('stop_apply_visual_alternatives'), $pause_image, find_image('visual_alternative.png'));
}
if($has_sign_lang_alternative){
$alt_infos['has_sign_lang_alternative'] = array('2', _AT('apply_sign_lang_alternatives'), _AT('stop_apply_sign_lang_alternatives'), $pause_image, find_image('sign_lang_alternative.png'));
}
$savant->assign('content_table', $content_array[0]);
$savant->assign('body', stripslashes($content_array[1]));
$savant->assign('cid', $cid);
$savant->assign('alt_infos', $alt_infos);
//assign test pages if there are tests associated with this content page
if (!empty($content_test_ids)){
$savant->assign('test_message', $content_row['test_message']);
$savant->assign('test_ids', $content_test_ids);
} else {
$savant->assign('test_message', '');
$savant->assign('test_ids', array());
}
/*TODO***************BOLOGNA***************REMOVE ME**********/
//assign forum pages if there are forums associated with this content page
if (!empty($content_forum_ids)){
$savant->assign('forum_message','');
$savant->assign('forum_ids', $content_forum_ids);
} else {
$savant->assign('forum_message', '');
$savant->assign('forum_ids', array());
}
// get the content that the standard and add-on modules want to display on the content page
$module_status_bits = AT_MODULE_STATUS_ENABLED;
$module_type_bits = AT_MODULE_TYPE_STANDARD + AT_MODULE_TYPE_EXTRA;
$module_list = $moduleFactory->getModules($module_status_bits, $module_type_bits, $sort = TRUE);
$module_contents = '';
foreach($module_list as $key=>$obj) {
$module_content = $obj->getContent($cid);
if (!empty($module_content)){
$module_contents .= '<div id="'.str_replace('/', '-', $key).'" class="content-from-module">'.$module_content.'</div>';
}
}
if ($module_contents <> '') $savant->assign('module_contents', $module_contents);
}
}
} else {
$infos = array('NOT_RELEASED', AT_date(_AT('announcement_date_format'), $released_status, AT_DATE_UNIX_TIMESTAMP));
$msg->addInfo($infos);
unset($infos);
}
$savant->assign('content_info', _AT('page_info', AT_date(_AT('inbox_date_format'), $content_row['last_modified'], AT_DATE_MYSQL_DATETIME), $content_row['revision'], AT_date(_AT('inbox_date_format'), $content_row['release_date'], AT_DATE_MYSQL_DATETIME)));
require(AT_INCLUDE_PATH.'header.inc.php');
//
// Mauro Donadio
//
$fp = @file_get_contents($content_row['text']);
// just for AContent content
if(strstr($fp, 'AContentXX')){
//$fp = str_ireplace('<head>','<MAURO>',$fp);
//<base href="http://www.w3schools.com/images/" target="_blank" />
// a new dom object
$dom = new DomDocument();
libxml_use_internal_errors(TRUE);
// load the html into the object
$dom->loadHTML($fp);
libxml_use_internal_errors(FALSE);
$doc->formatOutput = TRUE;
//discard white space
$dom->preserveWhiteSpace = false;
$node = $dom->getElementById('content-text');
// row commented because of the old version of PHP
//$content = $dom->saveHTML($node);
$content = $dom->saveXML($node, LIBXML_NOEMPTYTAG);
// overwrite the original content with the filtered one
$savant->assign('body', stripslashes($content));
$savant->assign('module_contents', '');
}
$savant->display('content.tmpl.php');
// --
//save last visit page.
$_SESSION['last_visited_page'] = $server_protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
require (AT_INCLUDE_PATH.'footer.inc.php');
?>