-
Notifications
You must be signed in to change notification settings - Fork 33
/
renderer.php
1352 lines (1226 loc) · 55.9 KB
/
renderer.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Moodle renderer used to display special elements of the ouwiki module
*
* @package mod
* @subpackage ouwiki
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/mod/ouwiki/locallib.php');
class mod_ouwiki_renderer extends plugin_renderer_base {
// Hold some parameters locally.
public $params;
/**
* Print the main page content
*
* @param object $subwiki For details of user/group and ID so that
* we can make links
* @param object $cm Course-module object (again for making links)
* @param object $pageversion Data from page and version tables.
* @param bool $gewgaws A decorator indicator.
* @param string $page Page type
* @param int $showwordcount
* @param bool $hideannotations If true, adds extra class to hide annotations
* @return string HTML content for page
*/
public function ouwiki_print_page($subwiki, $cm, $pageversion, $gewgaws = null,
$page = 'history', $showwordcount = 0, $hideannotations = false) {
global $CFG, $ouwikiinternalre;
require_once($CFG->libdir . '/filelib.php');
$output = '';
$modcontext = context_module::instance($cm->id);
$title = $pageversion->title === '' ? get_string('startpage', 'ouwiki') :
htmlspecialchars($pageversion->title);
// Get annotations - only if using annotation system. Prevents unnecessary db access.
if ($subwiki->annotation) {
$annotations = ouwiki_get_annotations($pageversion);
} else {
$annotations = '';
}
// Count words before convert content.
$totalcountnumber = ouwiki_count_words($pageversion->xhtml);
// Setup annotations according to the page we are on.
if ($page == 'view') {
if ($subwiki->annotation && count($annotations)) {
$pageversion->xhtml =
ouwiki_highlight_existing_annotations($pageversion->xhtml, $annotations, 'view');
}
} else if ($page == 'annotate') {
$pageversion->xhtml = ouwiki_setup_annotation_markers($pageversion->xhtml);
$pageversion->xhtml =
ouwiki_highlight_existing_annotations($pageversion->xhtml, $annotations, 'annotate');
}
// Must rewrite plugin urls AFTER doing annotations because they depend on byte position.
$pageversion->xhtml = file_rewrite_pluginfile_urls($pageversion->xhtml, 'pluginfile.php',
$modcontext->id, 'mod_ouwiki', 'content', $pageversion->versionid);
$pageversion->xhtml = ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm, null,
$pageversion->xhtmlformat);
// Get files here so we have them for the portfolio button addition as well.
$fs = get_file_storage();
$files = $fs->get_area_files($modcontext->id, 'mod_ouwiki', 'attachment',
$pageversion->versionid, "timemodified", false);
// Start gathering output.
$output .= html_writer::start_tag('div', array('class' => 'ouwiki-content' .
($hideannotations ? ' ouwiki-hide-annotations' : '')));
$output .= $this->get_topheading_section($title, $gewgaws, $pageversion, $annotations, $files);
// List of recent changes.
if ($gewgaws && $pageversion->recentversions) {
$output .= html_writer::start_tag('div', array('class' => 'ouw_recentchanges'));
$output .= get_string('recentchanges', 'ouwiki').': ';
$output .= html_writer::start_tag('span', array('class' => 'ouw_recentchanges_list'));
$first = true;
foreach ($pageversion->recentversions as $recentversion) {
if ($first) {
$first = false;
} else {
$output .= '; ';
}
$output .= ouwiki_recent_span($recentversion->timecreated);
$output .= ouwiki_nice_date($recentversion->timecreated);
$output .= html_writer::end_tag('span');
$output .= ' (';
$recentversion->id = $recentversion->userid; // So it looks like a user object.
$output .= ouwiki_display_user($recentversion, $cm->course, false);
$output .= ')';
}
$output .= '; ';
$pagestr = '';
if (strtolower(trim($title)) !== strtolower(get_string('startpage', 'ouwiki'))) {
$pagestr = '&page='.$title;
}
$output .= html_writer::tag('a', get_string('seedetails', 'ouwiki'),
array('href' => $CFG->wwwroot.'/mod/ouwiki/history.php?id='.
$cm->id . $pagestr));
$output .= html_writer::end_tag('span');
$output .= html_writer::end_tag('div');
}
$output .= $this->get_new_annotations_section($gewgaws, $pageversion, $annotations, $files);
$output .= html_writer::end_tag('div');
// Main content of page.
$output .= html_writer::start_tag('div', array('class' => 'ouw_belowmainhead'));
$output .= html_writer::start_tag('div', array('class' => 'ouw_topspacer'));
$output .= html_writer::end_tag('div');
$output .= $pageversion->xhtml;
if ($gewgaws) {
// Add in links around headings.
$ouwikiinternalre = new stdClass();
$ouwikiinternalre->pagename = $pageversion->title;
$ouwikiinternalre->subwiki = $subwiki;
$ouwikiinternalre->cm = $cm;
$ouwikiinternalre->annotations = $annotations;
$ouwikiinternalre->locked = $pageversion->locked;
$ouwikiinternalre->pageversion = $pageversion;
$ouwikiinternalre->files = $files;
$output = preg_replace_callback(
'|<h([1-9]) id="ouw_s([0-9]+_[0-9]+)">(.*?)(<br\s*/>)?</h[1-9]>|s',
'ouwiki_internal_re_heading', $output);
}
$output .= html_writer::tag('div', '', array('class' => 'clearer'));
$output .= html_writer::end_tag('div'); // End of ouw_belowmainhead.
// Add wordcount.
if ($showwordcount) {
if ($totalcountnumber == $pageversion->wordcount) {
$output .= $this->ouwiki_render_wordcount($pageversion->wordcount);
} else {
// Apply for legacy data with total count number is wrong.
$output .= $this->ouwiki_render_wordcount($totalcountnumber);
}
}
$output .= html_writer::end_tag('div'); // End of ouwiki-content.
// Add attached files.
$output .= $this->get_attached_files($files, $modcontext, $pageversion);
// Pages that link to this page.
if ($gewgaws) {
$links = ouwiki_get_links_to($pageversion->pageid);
if (count($links) > 0) {
$output .= $this->get_links_to($links);
}
}
// Display the orphaned annotations.
if ($subwiki->annotation && $annotations && $page != 'history') {
$orphaned = '';
foreach ($annotations as $annotation) {
if ($annotation->orphaned) {
$orphaned .= $this->ouwiki_print_hidden_annotation($annotation);
}
}
if ($orphaned !== '') {
$output .= html_writer::start_div('ouw-orphaned-annotations');
$output .= html_writer::tag('h3', get_string('orphanedannotations', 'ouwiki'));
$output .= $orphaned;
$output .= html_writer::end_div();
} else {
$output = $output;
}
}
$output .= $this->get_new_buttons_section($gewgaws, $pageversion);
return array($output, $annotations);
}
/**
* Returns html for a replaceable topheading section.
*
* @param string $title
* @param bool $gewgaws A decorator indicator.
* @param object $pageversion
* @param object $annotations
* @param array $files
* @return string
*/
public function get_topheading_section($title, $gewgaws, $pageversion, $annotations, $files) {
$subwiki = $this->params->subwiki;
$cm = $this->params->cm;
$output = html_writer::start_tag('div', array('class' => 'ouw_topheading'));
$output .= html_writer::start_tag('div', array('class' => 'ouw_heading'));
$output .= html_writer::tag('h2', format_string($title),
array('class' => 'ouw_topheading'));
if ($gewgaws) {
$output .= $this->render_heading_bit(1, $pageversion->title, $subwiki,
$cm, null, $annotations, $pageversion->locked, $files,
$pageversion->pageid);
} else {
$output .= html_writer::end_tag('div');
}
return $output;
}
/**
* Returns empty string.
*
* @param bool $gewgaws A decorator indicator.
* @param object $pageversion
* @param object $annotations
* @param array $files
* @return string
*/
public function get_new_annotations_section($gewgaws, $pageversion, $annotations, $files) {
return '';
}
/**
* Returns html for attached files.
*
* @param array $files
* @param object $modcontext
* @param object $pageversion
* @return string
*/
public function get_attached_files($files, $modcontext, $pageversion) {
global $CFG;
$output = '';
if ($files) {
$output .= html_writer::start_tag('div', array('class' => 'ouwiki-post-attachments'));
$output .= html_writer::tag('h3', get_string('attachments', 'ouwiki'),
array('class' => 'ouw_topheading'));
$output .= html_writer::start_tag('ul');
foreach ($files as $file) {
$output .= html_writer::start_tag('li');
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$iconimage = html_writer::empty_tag('img',
array('src' => $this->output->image_url(file_mimetype_icon($mimetype)),
'alt' => $mimetype, 'class' => 'icon'));
$path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $modcontext->id .
'/mod_ouwiki/attachment/' . $pageversion->versionid . '/' . $filename);
$output .= html_writer::tag('a', $iconimage, array('href' => $path));
$output .= html_writer::tag('a', s($filename), array('href' => $path));
$output .= html_writer::end_tag('li');
}
$output .= html_writer::end_tag('ul');
$output .= html_writer::end_tag('div');
}
return $output;
}
/**
* Returns html for the linked from links.
*
* @param array $links
* @return string
*/
public function get_links_to($links) {
global $CFG;
$output = html_writer::start_tag('div', array('class'=>'ouw_linkedfrom'));
$output .= html_writer::tag('h3', get_string(
count($links) == 1 ? 'linkedfromsingle' : 'linkedfrom', 'ouwiki'),
array('class'=>'ouw_topheading'));
$output .= html_writer::start_tag('ul');
$first = true;
foreach ($links as $link) {
$output .= html_writer::start_tag('li');
if ($first) {
$first = false;
} else {
$output .= '• ';
}
$linktitle = ($link->title) ? htmlspecialchars($link->title) :
get_string('startpage', 'ouwiki');
$output .= html_writer::tag('a', $linktitle,
array('href' => $CFG->wwwroot . '/mod/ouwiki/view.php?' .
ouwiki_display_wiki_parameters(
$link->title, $this->params->subwiki, $this->params->cm, OUWIKI_PARAMS_URL)));
$output .= html_writer::end_tag('li');
}
$output .= html_writer::end_tag('ul');
$output .= html_writer::end_tag('div');
return $output;
}
/**
* Returns empty string.
*
* @param bool $gewgaws A decorator indicator.
* @param object $pageversion
* @return string
*/
public function get_new_buttons_section($gewgaws, $pageversion) {
return '';
}
public function render_heading_bit($headingnumber, $pagename, $subwiki, $cm,
$xhtmlid, $annotations, $locked, $files, $pageid) {
global $CFG;
$output = '';
$output .= html_writer::start_tag('div', array('class' => 'ouw_byheading'));
// Add edit link for page or section
if ($subwiki->canedit && !$locked) {
$str = $xhtmlid ? 'editsection' : 'editpage';
$output .= $this->ouwiki_get_edit_link($str, $pagename, $subwiki, $cm, $xhtmlid);
}
// output the annotate link if using annotation system, only for page not section
if (!$xhtmlid && $subwiki->annotation) {
// Add annotate link
if ($subwiki->canannotate) {
$output .= $this->ouwiki_get_annotate_link($pagename, $subwiki, $cm);
}
// 'Expand/collapse all' and 'Show/hide all' annotation controls
if ($annotations != false) {
$orphancount = 0;
foreach ($annotations as $annotation) {
if ($annotation->orphaned == 1) {
$orphancount++;
}
}
if (count($annotations) > $orphancount) {
// Show and hide annotation icon links. Visibility controlled by CSS.
$output .= html_writer::start_tag('span', array('id' => 'showhideannotationicons'));
$output .= ' '.html_writer::tag('a', get_string('showannotationicons', 'ouwiki'),
array('href' => 'hideannotations.php?hide=0&' . ouwiki_display_wiki_parameters(
$pagename, $subwiki, $cm, OUWIKI_PARAMS_URL) . '&sesskey=' . sesskey(),
'id' => 'showannotationicons'));
$output .= html_writer::tag('a', get_string('hideannotationicons', 'ouwiki'),
array('href' => 'hideannotations.php?hide=1&' . ouwiki_display_wiki_parameters(
$pagename, $subwiki, $cm, OUWIKI_PARAMS_URL) . '&sesskey=' . sesskey(),
'id' => 'hideannotationicons'));
$output .= html_writer::end_tag('span');
// Expand and collapse annotations links.
$output .= html_writer::start_tag('span', array('id' => 'expandcollapseannotations'));
$output .= ' '.html_writer::tag('a', get_string('expandallannotations', 'ouwiki'),
array(
'href' => 'javascript:M.mod_ouwiki_view.ouwikiShowAllAnnotations("block")',
'id' => 'expandallannotations'
));
$output .= html_writer::tag('a', get_string('collapseallannotations', 'ouwiki'),
array(
'href' => 'javascript:M.mod_ouwiki_view.ouwikiShowAllAnnotations("none")',
'id' => 'collapseallannotations'
));
$output .= html_writer::end_tag('span');
}
}
}
// On main page, add export button
if (!$xhtmlid && $CFG->enableportfolios && !isguestuser()) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
$button->set_callback_options('ouwiki_page_portfolio_caller',
array('pageid' => $pageid), 'mod_ouwiki');
if (empty($files)) {
$button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
} else {
$button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
}
$output .= ' ' . $button->to_html(PORTFOLIO_ADD_TEXT_LINK).' ';
}
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('div');
return $output;
}
/**
* Renders the 'export entire wiki' link.
*
* @param object $subwiki Subwiki data object
* @param bool $anyfiles True if any page of subwiki contains files
* @param array $wikiparamsarray associative array
* @return string HTML content of list item with link, or nothing if none
*/
public function render_export_all_li($subwiki, $anyfiles, $wikiparamsarray) {
global $CFG;
if (!$CFG->enableportfolios) {
return '';
}
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
$button->set_callback_options('ouwiki_all_portfolio_caller',
$wikiparamsarray, 'mod_ouwiki');
if ($anyfiles) {
$button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
} else {
$button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
}
return html_writer::tag('li', $button->to_html(PORTFOLIO_ADD_TEXT_LINK));
}
public function ouwiki_internal_re_heading_bits($matches) {
global $ouwikiinternalre;
$tag = "h$matches[1]";
$output = '';
$output .= html_writer::start_tag('div', array('class' => 'ouw_heading ouw_heading'.
$matches[1]));
$output .= html_writer::tag($tag, $matches[3], array('id' => 'ouw_s'.$matches[2]));
$output .= $this->render_heading_bit($matches[1],
$ouwikiinternalre->pagename, $ouwikiinternalre->subwiki,
$ouwikiinternalre->cm, $matches[2], $ouwikiinternalre->annotations,
$ouwikiinternalre->locked, $ouwikiinternalre->files,
$ouwikiinternalre->pageversion->pageid);
return $output;
}
public function ouwiki_print_preview($content, $page, $subwiki, $cm, $contentformat) {
global $CFG;
// Convert content.
$content = ouwiki_convert_content($content, $subwiki, $cm, null, $contentformat);
// Need to replace brokenfile.php with draftfile.php since switching off filters
// will switch off all filter.
$content = str_replace("\"$CFG->wwwroot/brokenfile.php#",
"\"$CFG->wwwroot/draftfile.php", $content);
// Create output to be returned for printing.
$output = html_writer::tag('p', get_string('previewwarning', 'ouwiki'),
array('class' => 'ouw_warning'));
$output .= html_writer::start_tag('div', array('class' => 'ouw_preview'));
$output .= $this->output->box_start("generalbox boxaligncenter");
// Title & content of page.
$title = $page !== null && $page !== '' ? htmlspecialchars($page) :
get_string('startpage', 'ouwiki');
$output .= html_writer::tag('h1', $title);
$output .= $content;
$output .= html_writer::end_tag('div');
$output .= $this->output->box_end();
return $output;
}
/**
* Format the diff content for rendering
*
* @param v1 object version one of the page
* @param v2 object version two of the page
* @return output
*/
public function ouwiki_print_diff($v1, $v2) {
$output = '';
// left: v1
$output .= html_writer::start_tag('div', array('class' => 'ouw_left'));
$output .= html_writer::start_tag('div', array('class' => 'ouw_versionbox'));
$output .= html_writer::tag('h1', $v1->version, array('class' => 'accesshide'));
$output .= html_writer::tag('div', $v1->date, array('class' => 'ouw_date'));
$output .= html_writer::tag('div', $v1->savedby, array('class' => 'ouw_person'));
$output .= html_writer::end_tag('div');
$output .= html_writer::start_tag('div', array('class' => 'ouw_diff ouwiki_content'));
$output .= $v1->content;
$output .= html_writer::tag('h3', get_string('attachments', 'ouwiki'), array());
$output .= html_writer::tag('div', $v1->attachments,
array('class' => 'ouwiki_attachments'));
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('div');
// right: v2
$output .= html_writer::start_tag('div', array('class' => 'ouw_right'));
$output .= html_writer::start_tag('div', array('class' => 'ouw_versionbox'));
$output .= html_writer::tag('h1', $v2->version, array('class' => 'accesshide'));
$output .= html_writer::tag('div', $v2->date, array('class' => 'ouw_date'));
$output .= html_writer::tag('div', $v2->savedby, array('class' => 'ouw_person'));
$output .= html_writer::end_tag('div');
$output .= html_writer::start_tag('div', array('class' => 'ouw_diff ouwiki_content'));
$output .= $v2->content;
$output .= html_writer::tag('h3', get_string('attachments', 'ouwiki'), array());
$output .= html_writer::tag('div', $v2->attachments,
array('class' => 'ouwiki_attachments'));
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('div');
// clearer
$output .= html_writer::tag('div', ' ', array('class' => 'clearer'));
return $output;
}
/**
* Format the compared file for rendering as part of the diff
*
* @param file object
* @param action string
* @return output
*/
public function ouwiki_print_attachment_diff($file, $action = 'none') {
global $OUTPUT, $CFG;
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$iconimage = html_writer::empty_tag('img',
array('src' => $OUTPUT->image_url(file_mimetype_icon($mimetype)),
'alt' => $mimetype, 'class' => 'icon'));
if ($action === 'add') {
$addedstart = html_writer::empty_tag('img', array(
'src' => $OUTPUT->image_url('diff_added_begins', 'ouwiki'),
'alt' => get_string('addedbegins', 'ouwiki'),
'class' => 'icon')
);
$addedend = html_writer::empty_tag('img', array(
'src' => $OUTPUT->image_url('diff_added_ends', 'ouwiki'),
'alt' => get_string('addedends', 'ouwiki'),
'class' => 'icon')
);
$output = html_writer::start_tag('li');
$output .= $addedstart;
$output .= html_writer::tag('span', " $iconimage $filename ",
array('class' => 'ouw_added'));
$output .= $addedend;
$output .= html_writer::end_tag('li');
} else if ($action === 'delete') {
$deletedstart = html_writer::empty_tag('img' , array(
'src' => $OUTPUT->image_url('diff_deleted_begins', 'ouwiki'),
'alt' => get_string('deletedbegins', 'ouwiki'),
'class' => 'icon')
);
$deletedend = html_writer::empty_tag('img', array(
'src' => $OUTPUT->image_url('diff_deleted_ends', 'ouwiki'),
'alt' => get_string('deletedends', 'ouwiki'),
'class' => 'icon')
);
$output = html_writer::start_tag('li');
$output .= $deletedstart;
$output .= html_writer::tag('span', " $iconimage $filename ",
array('class' => 'ouw_deleted'));
$output .= $deletedend;
$output .= html_writer::end_tag('li');
} else {
// default case; no change in file
$output = html_writer::tag('li', "$iconimage $filename");
}
return $output;
}
/**
* Format the hidden annotations for rendering
*
* @param annotation object
* @return output
*/
public function ouwiki_print_hidden_annotation($annotation) {
global $DB, $COURSE, $OUTPUT;
$author = $DB->get_record('user', array('id' => $annotation->userid), '*', MUST_EXIST);
$picture = null;
$size = 0;
$return = true;
$classname = ($annotation->orphaned) ? 'ouwiki-orphaned-annotation' : 'ouwiki-annotation';
$output = html_writer::start_tag('span',
array('class' => $classname, 'id' => 'annotationbox'.$annotation->id));
$output .= $OUTPUT->user_picture($author, array('courseid' => $COURSE->id));
$output .= get_accesshide(get_string('startannotation', 'ouwiki'));
$output .= html_writer::start_tag('span', array('class' => 'ouwiki-annotation-content'));
$output .= html_writer::tag('span', fullname($author),
array('class' => 'ouwiki-annotation-content-title'));
$output .= $annotation->content;
$output .= html_writer::end_tag('span');
$output .= html_writer::tag('span', get_string('endannotation', 'ouwiki'),
array('class' => 'accesshide'));
$output .= html_writer::end_tag('span');
return $output;
}
/**
* Format the annotations for portfolio export
*
* @param annotation object
* @return output
*/
public function ouwiki_print_portfolio_annotation($annotation) {
global $DB, $COURSE, $OUTPUT;
$author = $DB->get_record('user', array('id' => $annotation->userid), '*', MUST_EXIST);
$output = '[';
$output .= html_writer::start_tag('i');
$output .= html_writer::tag('span', $annotation->content, array('style' => 'colour: red'));
$output .= ' - '. fullname($author) . ', ' . userdate($annotation->timemodified);
$output .= html_writer::end_tag('i');
$output .= '] ';
return $output;
}
/**
* Prints the header and (if applicable) group selector.
*
* @param object $ouwiki Wiki object
* @param object $cm Course-modules object
* @param object $course
* @param object $subwiki Subwiki objecty
* @param string $pagename Name of page
* @param object $context Context object
* @param string $afterpage If included, extra content for navigation string after page link
* @param bool $hideindex If true, doesn't show the index/recent pages links
* @param bool $notabs If true, prints the after-tabs div here
* @param string $head Things to include inside html head
* @param string $title
* @param string $querytext for use when changing groups against search criteria
*/
public function ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context,
$afterpage = null, $hideindex = null, $notabs = null, $head = '', $title='', $querytext = '') {
$output = '';
if ($pagename == null) {
$pagename = '';
}
ouwiki_print_header($ouwiki, $cm, $subwiki, $pagename, $afterpage, $head, $title);
$canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm);
$page = basename($_SERVER['PHP_SELF']);
// Gather params for later use - saves passing as attributes within the renderer.
$this->params = new StdClass();
$this->params->ouwiki = $ouwiki;
$this->params->cm = $cm;
$this->params->subwiki = $subwiki;
$this->params->course = $course;
$this->params->pagename = $pagename;
$this->params->hideindex = $hideindex;
$this->params->canview = $canview;
$this->params->page = $page;
// Add wiki name header.
$output .= $this->get_wiki_heading_text();
// Add group/user selector.
$showselector = true;
if (($page == 'userparticipation.php' && $canview != OUWIKI_MY_PARTICIPATION)
|| $page == 'participation.php'
&& (int)$ouwiki->subwikis == OUWIKI_SUBWIKIS_INDIVIDUAL) {
$showselector = false;
}
if ($showselector) {
$selector = ouwiki_display_subwiki_selector($subwiki, $ouwiki, $cm,
$context, $course, $page, $querytext);
$output .= $selector;
}
// Add index links.
list($content, $participationstr) = $this->ouwiki_get_links();
$output .= $content;
// Add page heading.
$output .= $this->ouwiki_get_page_heading($participationstr);
$output .= html_writer::div('', 'clearer');
if ($notabs) {
$extraclass = $selector ? ' ouwiki_gotselector' : '';
$output .= html_writer::div('', 'ouwiki_notabs' . $extraclass,
array('id' => 'ouwiki_belowtabs'));
}
return $output;
}
/**
* Returns empty string.
*
* @return string
*/
public function get_wiki_heading_text() {
return '';
}
/**
* Returns page heading (if required).
*
* @param string $participationstr Page heading title.
* @return string
*/
public function ouwiki_get_page_heading($participationstr) {
$output = '';
if ($this->params->page == 'participation.php' ||
$this->params->page == 'userparticipation.php') {
$output .= $this->output->heading($participationstr);
}
return $output;
}
/**
* Returns html for the links (wiki index etc.), and a participation string.
*
* @return array
*/
public function ouwiki_get_links() {
$output = '';
$participationstr = '';
if (!$this->params->hideindex) {
$output .= html_writer::start_tag('div', array('id' => 'ouwiki_indexlinks'));
list($content, $participationstr) = $this->ouwiki_get_links_content();
$output .= $content;
$output .= html_writer::end_tag('div');
} else {
$output .= html_writer::start_tag('div', array('id' => 'ouwiki_noindexlink'));
$output .= html_writer::end_tag('div');
}
return array($output, $participationstr);
}
/**
* Returns html for the content of the links, and a participation string.
*
* @return array
*/
public function ouwiki_get_links_content() {
global $USER;
$output = html_writer::start_tag('ul');
if ($this->params->page == 'wikiindex.php') {
$output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_index'));
$output .= html_writer::start_tag('span');
$output .= get_string('index', 'ouwiki');
$output .= html_writer::end_tag('span');
$output .= html_writer::end_tag('li');
} else {
$output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_index'));
$output .= html_writer::tag('a', get_string('index', 'ouwiki'),
array('href' => 'wikiindex.php?'.
ouwiki_display_wiki_parameters('', $this->params->subwiki,
$this->params->cm, OUWIKI_PARAMS_URL),
'class' => 'osep-smallbutton'));
$output .= html_writer::end_tag('li');
}
if ($this->params->page == 'wikihistory.php') {
$output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_history'));
$output .= html_writer::start_tag('span');
$output .= get_string('wikirecentchanges', 'ouwiki');
$output .= html_writer::end_tag('span');
$output .= html_writer::end_tag('li');
} else {
$output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_history'));
$output .= html_writer::tag('a', get_string('wikirecentchanges', 'ouwiki'),
array('href' => 'wikihistory.php?'.
ouwiki_display_wiki_parameters('', $this->params->subwiki,
$this->params->cm, OUWIKI_PARAMS_URL),
'class' => 'osep-smallbutton'));
$output .= html_writer::end_tag('li');
}
// Check for mod setting and ability to edit that enables this link.
if (($this->params->subwiki->canedit) && ($this->params->ouwiki->allowimport)) {
$output .= html_writer::start_tag('li', array('id' => 'ouwiki_import_pages'));
if ($this->params->page == 'import.php') {
$output .= html_writer::tag('span', get_string('import', 'ouwiki'));
} else {
$importlink = new moodle_url('/mod/ouwiki/import.php',
ouwiki_display_wiki_parameters($this->params->pagename,
$this->params->subwiki, $this->params->cm, OUWIKI_PARAMS_ARRAY));
$output .= html_writer::link($importlink, get_string('import', 'ouwiki'),
array('class' => 'osep-smallbutton'));
}
$output .= html_writer::end_tag('li');
}
$participationstr = '';
if ($this->params->canview == OUWIKI_USER_PARTICIPATION) {
$participationstr = get_string('participationbyuser', 'ouwiki');
$participationpage = 'participation.php?' .
ouwiki_display_wiki_parameters('', $this->params->subwiki, $this->params->cm,
OUWIKI_PARAMS_URL);
} else if ($this->params->canview == OUWIKI_MY_PARTICIPATION) {
$participationstr = get_string('myparticipation', 'ouwiki');
$participationpage = 'userparticipation.php?' .
ouwiki_display_wiki_parameters('', $this->params->subwiki, $this->params->cm,
OUWIKI_PARAMS_URL);
$participationpage .= '&user=' . $USER->id;
}
if ($this->params->canview > OUWIKI_NO_PARTICIPATION) {
if (($this->params->cm->groupmode != 0) && isset($this->params->subwiki->groupid)) {
$participationpage .= '&group=' . $this->params->subwiki->groupid;
}
if ($this->params->page == 'participation.php' ||
$this->params->page == 'userparticipation.php') {
$output .= html_writer::start_tag('li',
array('id' => 'ouwiki_nav_participation'));
$output .= html_writer::start_tag('span');
$output .= $participationstr;
$output .= html_writer::end_tag('span');
$output .= html_writer::end_tag('li');
} else {
$output .= html_writer::start_tag('li',
array('id' => 'ouwiki_nav_participation'));
$output .= html_writer::tag('a', $participationstr,
array('href' => $participationpage, 'class' => 'osep-smallbutton'));
$output .= html_writer::end_tag('li');
}
}
$output .= html_writer::end_tag('ul');
return array($output, $participationstr);
}
/**
* Format the wordcount for display.
*
* @param string $wordcount
* @return output
*/
public function ouwiki_render_wordcount($wordcount) {
$output = html_writer::start_tag('div', array('class' => 'ouw_wordcount'));
$output .= html_writer::tag('span', get_string('numwords', 'ouwiki', $wordcount));
$output .= html_writer::end_tag('div');
return $output;
}
/**
* Print all user participation records for display
*
* @param object $cm
* @param object $course
* @param string $pagename
* @param int $groupid
* @param object $ouwiki
* @param object $subwiki
* @param string $download (csv)
* @param int $page flexible_table pagination page
* @param bool $grading_info gradebook grade information
* @param array $participation mixed array of user participation values
* @param object $context
* @param bool $viewfullnames
* @param string groupname
*/
public function ouwiki_render_participation_list($cm, $course, $pagename, $groupid, $ouwiki,
$subwiki, $download, $page, $grading_info, $participation, $context, $viewfullnames,
$groupname) {
global $DB, $CFG, $OUTPUT;
require_once($CFG->dirroot.'/mod/ouwiki/participation_table.php');
$perpage = OUWIKI_PARTICIPATION_PERPAGE;
// filename for downloading setup
$filename = "$course->shortname-".format_string($ouwiki->name, true);
if (!empty($groupname)) {
$filename .= '-'.format_string($groupname, true);
}
$table = new ouwiki_participation_table($cm, $course, $ouwiki,
$pagename, $groupid, $groupname, $grading_info);
$table->setup($download);
$table->is_downloading($download, $filename, get_string('participation', 'ouwiki'));
// participation doesn't need standard ouwiki tabs so we need to
// add this one div in manually
if (!$table->is_downloading()) {
echo html_writer::start_tag('div', array('id' => 'ouwiki_belowtabs'));
}
if (!empty($participation)) {
if (!$table->is_downloading()) {
if ($perpage > count($participation)) {
$perpage = count($participation);
}
$table->pagesize($perpage, count($participation));
$offset = $page * $perpage;
$endposition = $offset + $perpage;
} else {
// always export all users
$endposition = count($participation);
$offset = 0;
}
$currentposition = 0;
foreach ($participation as $user) {
if ($currentposition == $offset && $offset < $endposition) {
$fullname = fullname($user, $viewfullnames);
// control details link
$details = false;
// pages
$pagecreates = 0;
if (isset($user->pagecreates)) {
$pagecreates = $user->pagecreates;
$details = true;
}
$pageedits = 0;
if (isset($user->pageedits)) {
$pageedits = $user->pageedits;
$details = true;
}
// words
$wordsadded = 0;
$wordsdeleted = 0;
if ($ouwiki->enablewordcount) {
if (isset($user->wordsadded)) {
$wordsadded = $user->wordsadded;
$details = true;
}
if (isset($user->wordsdeleted)) {
$wordsdeleted = $user->wordsdeleted;
$details = true;
}
}
// Allow import.
$imports = 0;
if ($ouwiki->allowimport) {
if (isset($user->pageimports)) {
$imports = count($user->pageimports);
$details = true;
}
}
// grades
if ($grading_info) {
if (!$table->is_downloading()) {
$attributes = array('userid' => $user->id);
if (!isset($grading_info->items[0]->grades[$user->id]->grade)) {
$user->grade = -1;
} else {
$user->grade = $grading_info->items[0]->grades[$user->id]->grade;
$user->grade = abs($user->grade);
}
$menu = html_writer::select(make_grades_menu($ouwiki->grade),
'menu['.$user->id.']', $user->grade,
array(-1 => get_string('nograde')), $attributes);
$gradeitem = '<div id="gradeuser'.$user->id.'">'. $menu .'</div>';
} else {
if (!isset($grading_info->items[0]->grades[$user->id]->grade)) {
$gradeitem = get_string('nograde');
} else {
$gradeitem = $grading_info->items[0]->grades[$user->id]->grade;
}
}
}
// user details
if (!$table->is_downloading()) {
$picture = $OUTPUT->user_picture($user);
$userurl = new moodle_url('/user/view.php?',
array('id' => $user->id, 'course' => $course->id));
$userdetails = html_writer::link($userurl, $fullname);
if ($details) {
$detailparams = array('id' => $cm->id, 'pagename' => $pagename,
'user' => $user->id, 'group' => $groupid);
$detailurl = new moodle_url('/mod/ouwiki/userparticipation.php',
$detailparams);
$accesshidetext = get_string('userdetails', 'ouwiki', $fullname);
$detaillink = html_writer::start_tag('small');
$detaillink .= ' (';
$detaillink .= html_writer::tag('span', $accesshidetext,
array('class' => 'accesshide'));
$detaillink .= html_writer::link($detailurl,
get_string('detail', 'ouwiki'));
$detaillink .= ')';
$detaillink .= html_writer::end_tag('small');
$userdetails .= $detaillink;
}
}
// add row
if (!$table->is_downloading()) {
if ($ouwiki->enablewordcount) {
$row = array($picture, $userdetails, $pagecreates,
$pageedits, $wordsadded, $wordsdeleted);
} else {
$row = array($picture, $userdetails, $pagecreates, $pageedits);
}
} else {
$row = array($fullname, $pagecreates, $pageedits,